-
Notifications
You must be signed in to change notification settings - Fork 390
/
test_ecmp.cc
2387 lines (2107 loc) · 102 KB
/
test_ecmp.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include "test/test_cmn_util.h"
#include "test_pkt_util.h"
#include "pkt/flow_proto.h"
#define AGE_TIME 10*1000
void RouterIdDepInit(Agent *agent) {
}
struct PortInfo input1[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 2, 1},
};
//virtual IP VM
struct PortInfo input2[] = {
{"vnet2", 2, "2.1.1.1", "00:00:00:01:01:01", 2, 2},
{"vnet3", 3, "2.1.1.1", "00:00:00:02:02:01", 2, 3},
{"vnet4", 4, "2.1.1.1", "00:00:00:02:02:01", 2, 4},
};
struct PortInfo input3[] = {
{"vnet5", 5, "3.1.1.1", "00:00:00:01:01:01", 3, 5},
{"vnet6", 6, "3.1.1.2", "00:00:00:02:02:01", 3, 6},
{"vnet7", 7, "3.1.1.3", "00:00:00:02:02:01", 3, 7},
};
struct PortInfo input4[] = {
{"vnet8", 8, "4.1.1.1", "00:00:00:01:01:01", 4, 8},
};
class EcmpTest : public ::testing::Test {
virtual void SetUp() {
agent_ = Agent::GetInstance();
flow_proto_ = agent_->pkt()->get_flow_proto();
// -<vnet2, vrf2>----<vnet5,vrf3>
// <vnet1, vrf1>----<vnet3, vrf2>----<vnet6,vrf3>----<vnet8, vrf4>
// -<vnet4, vrf2>----<vnet7,vrf3>
CreateVmportWithEcmp(input1, 1);
CreateVmportWithEcmp(input2, 3);
CreateVmportFIpEnv(input3, 3);
CreateVmportFIpEnv(input4, 1);
client->WaitForIdle();
for (uint32_t i = 1; i < 9; i++) {
EXPECT_TRUE(VmPortActive(i));
}
boost::system::error_code ec;
bgp_peer = CreateBgpPeer(Ip4Address::from_string("0.0.0.1", ec),
"xmpp channel");
client->WaitForIdle();
//Add floating IP for vrf2 interface to talk to
//vrf3
AddFloatingIpPool("fip-pool1", 1);
AddFloatingIp("fip1", 1, "3.1.1.100");
AddLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
AddLink("floating-ip-pool", "fip-pool1", "virtual-network",
"default-project:vn3");
AddLink("virtual-machine-interface", "vnet2", "floating-ip", "fip1");
AddLink("virtual-machine-interface", "vnet3", "floating-ip", "fip1");
AddLink("virtual-machine-interface", "vnet4", "floating-ip", "fip1");
client->WaitForIdle();
Ip4Address ip = Ip4Address::from_string("3.1.1.100");
InetUnicastRouteEntry *rt = RouteGet("default-project:vn3:vn3", ip, 32);
EXPECT_TRUE(rt != NULL);
EXPECT_TRUE(rt->GetActiveNextHop()->GetType() == NextHop::COMPOSITE);
mpls_label_1 = rt->GetActiveLabel();
ip = Ip4Address::from_string("2.1.1.1");
rt = RouteGet("vrf2", ip, 32);
EXPECT_TRUE(rt != NULL);
EXPECT_TRUE(rt->GetActiveNextHop()->GetType() == NextHop::COMPOSITE);
mpls_label_2 = rt->GetActiveLabel();
//Add floating IP for vrf3 interfaces to talk vrf4
AddFloatingIpPool("fip-pool2", 2);
AddFloatingIp("fip2", 2, "4.1.1.100");
AddLink("floating-ip", "fip2", "floating-ip-pool", "fip-pool2");
AddLink("floating-ip-pool", "fip-pool2", "virtual-network",
"default-project:vn4");
AddLink("virtual-machine-interface", "vnet5", "floating-ip", "fip2");
AddLink("virtual-machine-interface", "vnet6", "floating-ip", "fip2");
AddLink("virtual-machine-interface", "vnet7", "floating-ip", "fip2");
client->WaitForIdle();
ip = Ip4Address::from_string("4.1.1.100");
rt = RouteGet("default-project:vn4:vn4", ip, 32);
EXPECT_TRUE(rt != NULL);
EXPECT_TRUE(rt->GetActiveNextHop()->GetType() == NextHop::COMPOSITE);
mpls_label_3 = rt->GetActiveLabel();
//Populate ethernet interface id
eth_intf_id_ = EthInterfaceGet("vnet0")->id();
remote_vm_ip1_ = Ip4Address::from_string("2.2.2.2");
remote_vm_ip2_ = Ip4Address::from_string("3.3.3.3");
remote_vm_ip3_ = Ip4Address::from_string("4.4.4.4");
remote_server_ip_ = Ip4Address::from_string("10.10.1.1");
//Add couple of remote VM routes for generating packet
Inet4TunnelRouteAdd(bgp_peer, "vrf2", remote_vm_ip1_, 32,
remote_server_ip_, TunnelType::GREType(),
30, "vn2", SecurityGroupList(),
PathPreference());
Inet4TunnelRouteAdd(bgp_peer, "default-project:vn3:vn3",
remote_vm_ip2_, 32,
remote_server_ip_, TunnelType::GREType(),
30, "default-project:vn3", SecurityGroupList(),
PathPreference());
Inet4TunnelRouteAdd(bgp_peer, "default-project:vn4:vn4",
remote_vm_ip3_, 32,
remote_server_ip_, TunnelType::GREType(),
30, "default-project:vn4", SecurityGroupList(),
PathPreference());
client->WaitForIdle();
}
virtual void TearDown() {
DelLink("virtual-machine-interface", "vnet2", "floating-ip", "fip1");
DelLink("virtual-machine-interface", "vnet3", "floating-ip", "fip1");
DelLink("virtual-machine-interface", "vnet4", "floating-ip", "fip1");
DelLink("floating-ip-pool", "fip-pool1", "virtual-network",
"default-project:vn3");
client->WaitForIdle();
DelLink("virtual-machine-interface", "vnet5", "floating-ip", "fip2");
DelLink("virtual-machine-interface", "vnet6", "floating-ip", "fip2");
DelLink("virtual-machine-interface", "vnet7", "floating-ip", "fip2");
DelLink("floating-ip-pool", "fip-pool2", "virtual-network",
"default-project:vn4");
client->WaitForIdle();
DeleteVmportEnv(input1, 1, false);
DeleteVmportEnv(input2, 3, true);
DeleteVmportFIpEnv(input3, 3, true);
DeleteVmportFIpEnv(input4, 1, true);
Agent::GetInstance()->fabric_inet4_unicast_table()->DeleteReq(bgp_peer,
"vrf2", remote_vm_ip1_, 32, new ControllerVmRoute(bgp_peer));
Agent::GetInstance()->fabric_inet4_unicast_table()->DeleteReq(bgp_peer,
"default-project:vn3:vn3", remote_vm_ip2_, 32,
new ControllerVmRoute(bgp_peer));
Agent::GetInstance()->fabric_inet4_unicast_table()->DeleteReq(bgp_peer,
"default-project:vn4:vn4", remote_vm_ip3_, 32,
new ControllerVmRoute(bgp_peer));
client->WaitForIdle();
DeleteBgpPeer(bgp_peer);
EXPECT_FALSE(VrfFind("vrf1", true));
EXPECT_FALSE(VrfFind("vrf2", true));
EXPECT_FALSE(VrfFind("default-project:vn3:vn3", true));
EXPECT_FALSE(VrfFind("default-project:vn4:vn4", true));
}
public:
FlowProto *get_flow_proto() const { return flow_proto_; }
uint32_t GetServiceVlanNH(uint32_t intf_id, std::string vrf_name) const {
const VmInterface *vm_intf = VmInterfaceGet(intf_id);
const VrfEntry *vrf = VrfGet(vrf_name.c_str());
uint32_t label = vm_intf->GetServiceVlanLabel(vrf);
int nh_id = Agent::GetInstance()->mpls_table()->
FindMplsLabel(label)->nexthop()->id();
return nh_id;
}
void AddRemoteEcmpRoute(const string vrf_name, const string ip,
uint32_t plen, const string vn, int count,
ComponentNHKeyList local_list,
bool same_label = false) {
//If there is a local route, include that always
Ip4Address vm_ip = Ip4Address::from_string(ip);
ComponentNHKeyList comp_nh_list = local_list;
int remote_server_ip = 0x0A0A0A0A;
int label = 16;
SecurityGroupList sg_id_list;
for(int i = 0; i < count; i++) {
ComponentNHKeyPtr comp_nh(new ComponentNHKey(
label, Agent::GetInstance()->fabric_vrf_name(),
Agent::GetInstance()->router_id(),
Ip4Address(remote_server_ip++),
false, TunnelType::GREType()));
comp_nh_list.push_back(comp_nh);
if (!same_label) {
label++;
}
}
EcmpTunnelRouteAdd(bgp_peer, vrf_name, vm_ip, plen,
comp_nh_list, -1, vn, sg_id_list,
PathPreference());
}
void AddLocalVmRoute(const string vrf_name, const string ip, uint32_t plen,
const string vn, uint32_t intf_uuid) {
const VmInterface *vm_intf = static_cast<const VmInterface *>
(VmPortGet(intf_uuid));
VmInterfaceKey intf_key(AgentKey::ADD_DEL_CHANGE, MakeUuid(intf_uuid), "");
VnListType vn_list;
vn_list.insert(vn);
ControllerLocalVmRoute *local_vm_route =
new ControllerLocalVmRoute(intf_key, vm_intf->label(),
VxLanTable::kInvalidvxlan_id, false, vn_list,
InterfaceNHFlags::INET4, SecurityGroupList(),
PathPreference(), ControllerPeerPath::kInvalidPeerIdentifier,
EcmpLoadBalance(),
NULL);
InetUnicastAgentRouteTable *rt_table =
agent_->vrf_table()->GetInet4UnicastRouteTable(vrf_name);
rt_table->AddLocalVmRouteReq(bgp_peer, vrf_name,
Ip4Address::from_string(ip), plen,
static_cast<LocalVmRoute *>(local_vm_route));
}
void AddRemoteVmRoute(const string vrf_name, const string ip, uint32_t plen,
const string vn) {
const Ip4Address addr = Ip4Address::from_string(ip);
VnListType vn_list;
vn_list.insert(vn);
ControllerVmRoute *data =
ControllerVmRoute::MakeControllerVmRoute(bgp_peer,
agent_->fabric_vrf_name(), agent_->router_id(),
vrf_name, addr, TunnelType::GREType(), 16,
vn_list, SecurityGroupList(),
PathPreference(), false, EcmpLoadBalance());
InetUnicastAgentRouteTable::AddRemoteVmRouteReq(bgp_peer,
vrf_name, addr, plen, data);
}
void DeleteRemoteRoute(const string vrf_name, const string ip,
uint32_t plen) {
Ip4Address server_ip = Ip4Address::from_string(ip);
agent_->fabric_inet4_unicast_table()->DeleteReq(bgp_peer,
vrf_name, server_ip, plen, new ControllerVmRoute(bgp_peer));
}
uint32_t eth_intf_id_;
Ip4Address remote_vm_ip1_;
Ip4Address remote_vm_ip2_;
Ip4Address remote_vm_ip3_;
Ip4Address remote_server_ip_;
uint32_t mpls_label_1;
uint32_t mpls_label_2;
uint32_t mpls_label_3;
Peer *bgp_peer;
Agent *agent_;
FlowProto *flow_proto_;
AgentXmppChannel *channel;
};
//Ping from vrf1 to vrf2(which has ECMP vip)
TEST_F(EcmpTest, EcmpTest_1) {
TxIpPacket(VmPortGetId(1), "1.1.1.1", "2.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"1.1.1.1", "2.1.1.1", 1, 0, 0, GetFlowKeyNH(1));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
}
//Ping from vrf2(vip and floating IP ECMP) to vrf3
TEST_F(EcmpTest, EcmpTest_2) {
TxIpPacket(VmPortGetId(4), "2.1.1.1", "3.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"2.1.1.1", "3.1.1.1", 1, 0, 0, GetFlowKeyNH(4));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::NatFlow) == true);
//Reverse flow should be set and should also be ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse component index point to right interface
Ip4Address ip = Ip4Address::from_string("2.1.1.1");
const CompositeNH *comp_nh = static_cast<const CompositeNH *>
(RouteGet("vrf2", ip, 32)->GetActiveNextHop());
const InterfaceNH *intf_nh = static_cast<const InterfaceNH *>
(comp_nh->Get(rev_entry->data().component_nh_idx)->nh());
EXPECT_TRUE(intf_nh->GetInterface()->name() == "vnet4");
}
//Ping from vrf3(floating IP is ECMP) to vrf4
TEST_F(EcmpTest, EcmpTest_3) {
TxIpPacket(VmPortGetId(5), "3.1.1.1", "4.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("default-project:vn3:vn3")->vrf_id(),
"3.1.1.1", "4.1.1.1", 1, 0, 0, GetFlowKeyNH(5));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::NatFlow) == true);
//Reverse flow should be set and should also be ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse component index point to right interface
Ip4Address ip = Ip4Address::from_string("4.1.1.100");
const CompositeNH *comp_nh = static_cast<const CompositeNH *>
(RouteGet("default-project:vn4:vn4", ip, 32)->GetActiveNextHop());
const InterfaceNH *intf_nh = static_cast<const InterfaceNH *>
(comp_nh->Get(rev_entry->data().component_nh_idx)->nh());
EXPECT_TRUE(intf_nh->GetInterface()->name() == "vnet5");
}
//Ping from vrf3(floating IP is ECMP) to vrf4
TEST_F(EcmpTest, EcmpTest_7) {
TxIpPacket(VmPortGetId(6), "3.1.1.2", "4.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("default-project:vn3:vn3")->vrf_id(),
"3.1.1.2", "4.1.1.1", 1, 0, 0, GetFlowKeyNH(6));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::NatFlow) == true);
//Reverse flow should be set and should also be ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse component index point to right interface
Ip4Address ip = Ip4Address::from_string("4.1.1.100");
const CompositeNH *comp_nh = static_cast<const CompositeNH *>
(RouteGet("default-project:vn4:vn4", ip, 32)->GetActiveNextHop());
const InterfaceNH *intf_nh = static_cast<const InterfaceNH *>
(comp_nh->Get(rev_entry->data().component_nh_idx)->nh());
EXPECT_TRUE(intf_nh->GetInterface()->name() == "vnet6");
}
//Ping from external world to ECMP vip
TEST_F(EcmpTest, EcmpTest_4) {
//VIP of vrf2 interfaces
char vm_ip[80] = "2.1.1.1";
char router_id[80];
char remote_server_ip[80];
char remote_vm_ip[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
strcpy(remote_server_ip, remote_server_ip_.to_string().c_str());
strcpy(remote_vm_ip, remote_vm_ip1_.to_string().c_str());
TxIpMplsPacket(eth_intf_id_, remote_server_ip, router_id, mpls_label_2,
remote_vm_ip, vm_ip, 1, 10);
client->WaitForIdle();
int nh_id = GetActiveLabel(MplsLabel::VPORT_NH, mpls_label_2)->nexthop()->id();
FlowEntry *entry = FlowGet(VrfGet("vrf2")->vrf_id(),
remote_vm_ip, vm_ip, 1, 0, 0, nh_id);
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Reverse flow should be set and should also be ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
}
//Ping from external world to ECMP fip
TEST_F(EcmpTest, EcmpTest_5) {
//FIP of vrf3 interfaces
char vm_ip[80] = "4.1.1.100";
char router_id[80];
char remote_server_ip[80];
char remote_vm_ip[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
strcpy(remote_server_ip, remote_server_ip_.to_string().c_str());
strcpy(remote_vm_ip, remote_vm_ip3_.to_string().c_str());
TxIpMplsPacket(eth_intf_id_, remote_server_ip, router_id, mpls_label_3,
remote_vm_ip, vm_ip, 1, 10);
client->WaitForIdle();
int nh_id = GetActiveLabel(MplsLabel::VPORT_NH, mpls_label_3)->nexthop()->id();
FlowEntry *entry = FlowGet(VrfGet("default-project:vn4:vn4")->vrf_id(),
remote_vm_ip, vm_ip, 1, 0, 0, nh_id);
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::NatFlow) == true);
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
}
//Ping from vrf3(floating IP is ECMP) to vrf4
TEST_F(EcmpTest, EcmpTest_6) {
TxIpPacket(VmPortGetId(8), "4.1.1.1", "4.1.1.100", 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("default-project:vn4:vn4")->vrf_id(),
"4.1.1.1", "4.1.1.100", 1, 0, 0,
GetFlowKeyNH(8));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::NatFlow) == true);
//Reverse flow should be set and should also be ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
}
TEST_F(EcmpTest, EcmpTest_8) {
Ip4Address ip = Ip4Address::from_string("30.30.30.0");
ComponentNHKeyList comp_nh;
Ip4Address server_ip1 = Ip4Address::from_string("15.15.15.15");
Ip4Address server_ip2 = Ip4Address::from_string("15.15.15.16");
Ip4Address server_ip3 = Ip4Address::from_string("15.15.15.17");
ComponentNHKeyPtr comp_nh_data1(new ComponentNHKey(
16, Agent::GetInstance()->fabric_vrf_name(),
Agent::GetInstance()->router_id(), server_ip1, false,
TunnelType::GREType()));
comp_nh.push_back(comp_nh_data1);
ComponentNHKeyPtr comp_nh_data2(new ComponentNHKey(
17, Agent::GetInstance()->fabric_vrf_name(),
Agent::GetInstance()->router_id(),
server_ip2, false, TunnelType::GREType()));
comp_nh.push_back(comp_nh_data2);
ComponentNHKeyPtr comp_nh_data3(new ComponentNHKey(
18, Agent::GetInstance()->fabric_vrf_name(),
Agent::GetInstance()->router_id(),
server_ip3, false, TunnelType::GREType()));
comp_nh.push_back(comp_nh_data3);
SecurityGroupList sg_list;
EcmpTunnelRouteAdd(bgp_peer, "vrf2", ip, 24, comp_nh, -1, "vn2", sg_list,
PathPreference());
client->WaitForIdle();
//VIP of vrf2 interfaces
char vm_ip[80] = "1.1.1.1";
char router_id[80];
char remote_server_ip[80];
char remote_vm_ip[80];
strcpy(router_id, Agent::GetInstance()->router_id().to_string().c_str());
strcpy(remote_server_ip, "15.15.15.16");
strcpy(remote_vm_ip, "30.30.30.1");
const VmInterface *vintf =
static_cast<const VmInterface *>(VmPortGet(1));
TxIpMplsPacket(eth_intf_id_, remote_server_ip, router_id, vintf->label(),
remote_vm_ip, vm_ip, 1, 10);
client->WaitForIdle();
int nh_id = GetActiveLabel(MplsLabel::VPORT_NH, vintf->label())->
nexthop()->id();
FlowEntry *entry = FlowGet(VrfGet("vrf2")->vrf_id(),
remote_vm_ip, vm_ip, 1, 0, 0, nh_id);
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
//Reverse flow should be set and should also be ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().component_nh_idx == 1);
Agent::GetInstance()->fabric_inet4_unicast_table()->DeleteReq(bgp_peer,
"vrf2", ip, 24,
new ControllerVmRoute(bgp_peer));
client->WaitForIdle();
}
//Ping from a interface with ECMP FIP to remote machine
TEST_F(EcmpTest, EcmpTest_9) {
char remote_vm_ip[80];
strcpy(remote_vm_ip, remote_vm_ip3_.to_string().c_str());
TxIpPacket(VmPortGetId(5), "3.1.1.1", remote_vm_ip, 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("default-project:vn3:vn3")->vrf_id(),
"3.1.1.1", remote_vm_ip, 1, 0, 0,
GetFlowKeyNH(5));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::NatFlow) == true);
EXPECT_TRUE(entry->data().vrf ==
VrfGet("default-project:vn3:vn3")->vrf_id());
EXPECT_TRUE(entry->data().dest_vrf ==
VrfGet("default-project:vn4:vn4")->vrf_id());
std::string vn_name("default-project:vn4");
EXPECT_TRUE(VnMatch(entry->data().source_vn_list, vn_name));
EXPECT_TRUE(VnMatch(entry->data().dest_vn_list, vn_name));
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(rev_entry->data().vrf == VrfGet("default-project:vn4:vn4")->vrf_id());
EXPECT_TRUE(rev_entry->data().dest_vrf == VrfGet("default-project:vn3:vn3")->vrf_id());
EXPECT_TRUE(VnMatch(rev_entry->data().source_vn_list, vn_name));
EXPECT_TRUE(VnMatch(rev_entry->data().dest_vn_list, vn_name));
}
//Ping from vip to ECMP VIP with ingress vrf and egress VRF having
//different order of component NH
TEST_F(EcmpTest, EcmpTest_10) {
struct PortInfo input1[] = {
{"vnet9", 9, "9.1.1.1", "00:00:00:01:01:01", 9, 9},
};
CreateVmportWithEcmp(input1, 1);
client->WaitForIdle();
//Leak route for 2.1.1.1 in vrf9 and
Ip4Address vm_ip = Ip4Address::from_string("2.1.1.1");
InetUnicastRouteEntry *rt = RouteGet("vrf2", vm_ip, 32);
EXPECT_TRUE(rt != NULL);
const CompositeNH *composite_nh = static_cast<const CompositeNH *>(
rt->GetActiveNextHop());
ComponentNHKeyList comp_nh_list = composite_nh->component_nh_key_list();
std::reverse(comp_nh_list.begin(), comp_nh_list.end());
AddRemoteEcmpRoute("vrf9", "2.1.1.1", 32, "vn2", 0, comp_nh_list);
AddLocalVmRoute("vrf2", "9.1.1.1", 32, "vn9", 9);
client->WaitForIdle();
rt = RouteGet("vrf9", vm_ip, 32);
EXPECT_TRUE(rt != NULL);
composite_nh = static_cast<const CompositeNH *>(
rt->GetActiveNextHop());
TxIpPacket(VmPortGetId(2), "2.1.1.1", "9.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"2.1.1.1", "9.1.1.1", 1, 0, 0, GetFlowKeyNH(2));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse flow packet is destined to vnet2
const InterfaceNH *nh = static_cast<const InterfaceNH *>(
composite_nh->GetNH(rev_entry->data().component_nh_idx));
EXPECT_TRUE(nh->GetInterface()->name() == "vnet2");
EXPECT_TRUE(rev_entry->is_flags_set(FlowEntry::ShortFlow) == false);
TxIpPacket(VmPortGetId(3), "2.1.1.1", "9.1.1.1", 1);
client->WaitForIdle();
entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"2.1.1.1", "9.1.1.1", 1, 0, 0, GetFlowKeyNH(3));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
//Reverse flow is no ECMP
rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse flow packet is destined to vnet3
nh = static_cast<const InterfaceNH *>(
composite_nh->GetNH(rev_entry->data().component_nh_idx));
EXPECT_TRUE(nh->GetInterface()->name() == "vnet3");
EXPECT_TRUE(rev_entry->is_flags_set(FlowEntry::ShortFlow) == false);
TxIpPacket(VmPortGetId(4), "2.1.1.1", "9.1.1.1", 1);
client->WaitForIdle();
entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"2.1.1.1", "9.1.1.1", 1, 0, 0, GetFlowKeyNH(4));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
//Reverse flow is no ECMP
rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse flow packet is destined to vnet4
nh = static_cast<const InterfaceNH *>(
composite_nh->GetNH(rev_entry->data().component_nh_idx));
EXPECT_TRUE(nh->GetInterface()->name() == "vnet4");
EXPECT_TRUE(rev_entry->is_flags_set(FlowEntry::ShortFlow) == false);
DeleteVmportEnv(input1, 1, true);
DeleteRemoteRoute("vrf2", "9.1.1.1", 32);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
EXPECT_FALSE(VrfFind("vrf9"));
}
//Ping from vip to ECMP FIP with ingress vrf and egress VRF having
//different order of component NH
TEST_F(EcmpTest, EcmpTest_11) {
//Add service VRF and VN
struct PortInfo input1[] = {
{"vnet9", 9, "9.1.1.1", "00:00:00:01:01:01", 9, 9},
};
CreateVmportWithEcmp(input1, 1);
client->WaitForIdle();
//Leak route for 2.1.1.1 in vrf9 and
Ip4Address vm_ip = Ip4Address::from_string("3.1.1.100");
InetUnicastRouteEntry *rt = RouteGet("default-project:vn3:vn3", vm_ip, 32);
EXPECT_TRUE(rt != NULL);
const CompositeNH *composite_nh = static_cast<const CompositeNH *>(
rt->GetActiveNextHop());
ComponentNHKeyList comp_nh_list = composite_nh->component_nh_key_list();
std::reverse(comp_nh_list.begin(), comp_nh_list.end());
AddRemoteEcmpRoute("vrf9", "3.1.1.100", 32, "default-project:vn3", 0,
comp_nh_list);
AddLocalVmRoute("default-project:vn3:vn3", "9.1.1.1", 32, "vn9", 9);
client->WaitForIdle();
Ip4Address vm_src_ip = Ip4Address::from_string("2.1.1.1");
rt = RouteGet("vrf2", vm_src_ip, 32);
EXPECT_TRUE(rt != NULL);
composite_nh = static_cast<const CompositeNH *>(
rt->GetActiveNextHop());
TxIpPacket(VmPortGetId(2), "2.1.1.1", "9.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"2.1.1.1", "9.1.1.1", 1, 0, 0, GetFlowKeyNH(2));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
//Reverse flow is no ECMP
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse flow packet is destined to vnet2
const InterfaceNH *nh = static_cast<const InterfaceNH *>(
composite_nh->GetNH(rev_entry->data().component_nh_idx));
EXPECT_TRUE(nh->GetInterface()->name() == "vnet2");
EXPECT_TRUE(rev_entry->is_flags_set(FlowEntry::ShortFlow) == false);
TxIpPacket(VmPortGetId(3), "2.1.1.1", "9.1.1.1", 1);
client->WaitForIdle();
entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"2.1.1.1", "9.1.1.1", 1, 0, 0, GetFlowKeyNH(3));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
//Reverse flow is no ECMP
rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse flow packet is destined to vnet3
nh = static_cast<const InterfaceNH *>(
composite_nh->GetNH(rev_entry->data().component_nh_idx));
EXPECT_TRUE(nh->GetInterface()->name() == "vnet3");
EXPECT_TRUE(rev_entry->is_flags_set(FlowEntry::ShortFlow) == false);
TxIpPacket(VmPortGetId(4), "2.1.1.1", "9.1.1.1", 1);
client->WaitForIdle();
entry = FlowGet(VrfGet("vrf2")->vrf_id(),
"2.1.1.1", "9.1.1.1", 1, 0, 0, GetFlowKeyNH(4));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx ==
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
//Reverse flow is no ECMP
rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
//Make sure reverse flow packet is destined to vnet4
nh = static_cast<const InterfaceNH *>(
composite_nh->GetNH(rev_entry->data().component_nh_idx));
EXPECT_TRUE(nh->GetInterface()->name() == "vnet4");
EXPECT_TRUE(rev_entry->is_flags_set(FlowEntry::ShortFlow) == false);
DeleteVmportEnv(input1, 1, true);
DeleteRemoteRoute("default-project:vn3:vn3", "9.1.1.1", 32);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (get_flow_proto()->FlowCount() == 0));
EXPECT_FALSE(VrfFind("vrf9"));
}
TEST_F(EcmpTest, EcmpTest_12) {
struct PortInfo input1[] = {
{"vnet9", 9, "9.1.1.1", "00:00:00:01:01:01", 9, 9},
};
CreateVmportWithEcmp(input1, 1);
client->WaitForIdle();
VmInterface *intf = static_cast<VmInterface *>(VmPortGet(9));
uint32_t label = intf->label();
AddVn("default-project:vn10", 10);
AddVrf("default-project:vn10:vn10", 10);
AddLink("virtual-network", "default-project:vn10",
"routing-instance", "default-project:vn10:vn10");
AddFloatingIpPool("fip-pool9", 10);
AddFloatingIp("fip9", 10, "10.10.10.2");
AddLink("floating-ip", "fip9", "floating-ip-pool", "fip-pool9");
AddLink("floating-ip-pool", "fip-pool9", "virtual-network",
"default-project:vn10");
AddLink("virtual-machine-interface", "vnet9", "floating-ip", "fip9");
client->WaitForIdle();
Ip4Address gw_rt = Ip4Address::from_string("0.0.0.0");
Ip4Address remote_server_ip1 = Ip4Address::from_string("10.10.10.100");
Ip4Address remote_server_ip2 = Ip4Address::from_string("10.10.10.101");
Agent *agent = Agent::GetInstance();
ComponentNHKeyPtr nh_data1(new ComponentNHKey(30, agent->fabric_vrf_name(),
agent->router_id(),
remote_server_ip1,
false,
TunnelType::DefaultType()));
ComponentNHKeyPtr nh_data2(new ComponentNHKey(20, agent->fabric_vrf_name(),
agent->router_id(),
remote_server_ip2,
false,
TunnelType::DefaultType()));
ComponentNHKeyList comp_nh_list;
comp_nh_list.push_back(nh_data1);
comp_nh_list.push_back(nh_data2);
EcmpTunnelRouteAdd(bgp_peer, "default-project:vn10:vn10", gw_rt, 0,
comp_nh_list, -1, "default-project:vn10",
SecurityGroupList(), PathPreference());
client->WaitForIdle();
TxIpPacket(VmPortGetId(9), "9.1.1.1", "10.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry;
entry = FlowGet(VrfGet("default-project:vn10:vn10")->vrf_id(),
"9.1.1.1", "10.1.1.1", 1, 0, 0, GetFlowKeyNH(9));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
uint32_t reverse_index = entry->reverse_flow_entry()->flow_handle();
if (entry->data().component_nh_idx == 0) {
TxIpMplsPacket(eth_intf_id_, "10.10.10.101",
agent->router_id().to_string().c_str(),
label, "10.1.1.1", "10.10.10.2", 1, reverse_index);
client->WaitForIdle();
EXPECT_TRUE(entry->data().component_nh_idx == 1);
} else {
TxIpMplsPacket(eth_intf_id_, "10.10.10.100",
agent->router_id().to_string().c_str(),
label, "10.1.1.1", "10.10.10.2", 1, reverse_index);
client->WaitForIdle();
EXPECT_TRUE(entry->data().component_nh_idx == 0);
}
DeleteVmportEnv(input1, 1, true);
DeleteRemoteRoute("default-project:vn10:vn10", "0.0.0.0", 0);
DelLink("floating-ip", "fip9", "floating-ip-pool", "fip-pool9");
DelLink("floating-ip-pool", "fip-pool9",
"virtual-network", "default-project:vn10");
DelLink("virtual-machine-interface", "vnet9", "floating-ip", "fip9");
DelFloatingIp("fip9");
DelFloatingIpPool("fip-pool9");
client->WaitForIdle();
DelVrf("default-project:vn10:vn10");
DelVn("default-project:vn10");
client->WaitForIdle();
WAIT_FOR(100, 1000, VrfFind("default-project:vn10:vn10", true) == false);
client->WaitForIdle();
EXPECT_TRUE(get_flow_proto()->FlowCount() == 0);
EXPECT_FALSE(VrfFind("vrf9", true));
}
//Add a test case to check if rpf NH of flow using floating IP
//is set properly upon nexthop change of from 2 destination to 3
//destinations
TEST_F(EcmpTest, EcmpTest_13) {
struct PortInfo input1[] = {
{"vnet9", 9, "9.1.1.1", "00:00:00:01:01:01", 9, 9},
};
CreateVmportWithEcmp(input1, 1);
client->WaitForIdle();
VmInterface *intf = static_cast<VmInterface *>(VmPortGet(9));
uint32_t label = intf->label();
AddVn("default-project:vn10", 10);
AddVrf("default-project:vn10:vn10", 10);
AddLink("virtual-network", "default-project:vn10",
"routing-instance", "default-project:vn10:vn10");
AddFloatingIpPool("fip-pool9", 10);
AddFloatingIp("fip9", 10, "10.10.10.2");
AddLink("floating-ip", "fip9", "floating-ip-pool", "fip-pool9");
AddLink("floating-ip-pool", "fip-pool9", "virtual-network",
"default-project:vn10");
AddLink("virtual-machine-interface", "vnet9", "floating-ip", "fip9");
client->WaitForIdle();
Ip4Address gw_rt = Ip4Address::from_string("0.0.0.0");
Ip4Address remote_server_ip1 = Ip4Address::from_string("10.10.10.100");
Ip4Address remote_server_ip2 = Ip4Address::from_string("10.10.10.101");
Ip4Address remote_server_ip3 = Ip4Address::from_string("10.10.10.102");
Agent *agent = Agent::GetInstance();
ComponentNHKeyPtr nh_data1(new ComponentNHKey(30, agent->fabric_vrf_name(),
agent->router_id(),
remote_server_ip1,
false,
TunnelType::DefaultType()));
ComponentNHKeyPtr nh_data2(new ComponentNHKey(20, agent->fabric_vrf_name(),
agent->router_id(),
remote_server_ip2,
false,
TunnelType::DefaultType()));
ComponentNHKeyList comp_nh_list;
comp_nh_list.push_back(nh_data1);
comp_nh_list.push_back(nh_data2);
EcmpTunnelRouteAdd(bgp_peer, "default-project:vn10:vn10", gw_rt, 0,
comp_nh_list, false, "default-project:vn10",
SecurityGroupList(), PathPreference());
client->WaitForIdle();
TxIpPacket(VmPortGetId(9), "9.1.1.1", "10.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry;
entry = FlowGet(VrfGet("default-project:vn10:vn10")->vrf_id(),
"9.1.1.1", "10.1.1.1", 1, 0, 0, GetFlowKeyNH(9));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
uint32_t index;
uint32_t reverse_index = entry->reverse_flow_entry()->flow_handle();
if (entry->data().component_nh_idx == 0) {
TxIpMplsPacket(eth_intf_id_, "10.10.10.101",
agent->router_id().to_string().c_str(),
label, "10.1.1.1", "10.10.10.2", 1, reverse_index);
client->WaitForIdle();
EXPECT_TRUE(entry->data().component_nh_idx == 1);
index = 1;
} else {
TxIpMplsPacket(eth_intf_id_, "10.10.10.100",
agent->router_id().to_string().c_str(),
label, "10.1.1.1", "10.10.10.2", 1, reverse_index);
client->WaitForIdle();
EXPECT_TRUE(entry->data().component_nh_idx == 0);
index = 0;
}
//Update the route to make the composite NH point to new nexthop
ComponentNHKeyPtr nh_data3(new ComponentNHKey(20, agent->fabric_vrf_name(),
agent->router_id(),
remote_server_ip3,
false,
TunnelType::DefaultType()));
comp_nh_list.push_back(nh_data3);
EcmpTunnelRouteAdd(bgp_peer, "default-project:vn10:vn10", gw_rt, 0,
comp_nh_list, false, "default-project:vn10",
SecurityGroupList(), PathPreference());
client->WaitForIdle();
EXPECT_TRUE(entry->data().component_nh_idx == index);
//Make sure flow has the right nexthop set.
InetUnicastRouteEntry *rt = RouteGet("default-project:vn10:vn10", gw_rt, 0);
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->nh() == rt->GetActiveNextHop());
DeleteVmportEnv(input1, 1, true);
DeleteRemoteRoute("default-project:vn10:vn10", "0.0.0.0", 0);
DelLink("floating-ip", "fip9", "floating-ip-pool", "fip-pool9");
DelLink("floating-ip-pool", "fip-pool9",
"virtual-network", "default-project:vn10");
DelLink("virtual-machine-interface", "vnet9", "floating-ip", "fip9");
DelFloatingIp("fip9");
DelFloatingIpPool("fip-pool9");
client->WaitForIdle();
DelVrf("default-project:vn10:vn10");
DelVn("default-project:vn10");
client->WaitForIdle();
WAIT_FOR(100, 1000, VrfFind("default-project:vn10:vn10", true) == false);
client->WaitForIdle();
EXPECT_TRUE(get_flow_proto()->FlowCount() == 0);
EXPECT_FALSE(VrfFind("vrf9", true));
}
//Add a test case to check if rpf NH of flow using floating IP
//gets properly upon nexthop change from ecmp to unicast
TEST_F(EcmpTest, EcmpTest_14) {
struct PortInfo input1[] = {
{"vnet9", 9, "9.1.1.1", "00:00:00:01:01:01", 9, 9},
};
CreateVmportWithEcmp(input1, 1);
client->WaitForIdle();
AddVn("default-project:vn10", 10);
AddVrf("default-project:vn10:vn10", 10);
AddLink("virtual-network", "default-project:vn10",
"routing-instance", "default-project:vn10:vn10");
AddFloatingIpPool("fip-pool9", 10);
AddFloatingIp("fip9", 10, "10.10.10.2");
AddLink("floating-ip", "fip9", "floating-ip-pool", "fip-pool9");
AddLink("floating-ip-pool", "fip-pool9", "virtual-network",
"default-project:vn10");
AddLink("virtual-machine-interface", "vnet9", "floating-ip", "fip9");
client->WaitForIdle();
Ip4Address gw_rt = Ip4Address::from_string("0.0.0.0");
Ip4Address remote_server_ip1 = Ip4Address::from_string("10.10.10.100");
Ip4Address remote_server_ip2 = Ip4Address::from_string("10.10.10.101");
Agent *agent = Agent::GetInstance();
ComponentNHKeyPtr nh_data1(new ComponentNHKey(30, agent->fabric_vrf_name(),
agent->router_id(),
remote_server_ip1,
false,
TunnelType::DefaultType()));
ComponentNHKeyPtr nh_data2(new ComponentNHKey(20, agent->fabric_vrf_name(),
agent->router_id(),
remote_server_ip2,
false,
TunnelType::DefaultType()));
ComponentNHKeyList comp_nh_list;
comp_nh_list.push_back(nh_data1);
comp_nh_list.push_back(nh_data2);
EcmpTunnelRouteAdd(bgp_peer, "default-project:vn10:vn10", gw_rt, 0,
comp_nh_list, false, "default-project:vn10",
SecurityGroupList(), PathPreference());
client->WaitForIdle();
TxIpPacket(VmPortGetId(9), "9.1.1.1", "10.1.1.1", 1);
client->WaitForIdle();
FlowEntry *entry;
entry = FlowGet(VrfGet("default-project:vn10:vn10")->vrf_id(),
"9.1.1.1", "10.1.1.1", 1, 0, 0, GetFlowKeyNH(9));
EXPECT_TRUE(entry != NULL);
EXPECT_TRUE(entry->data().component_nh_idx !=
CompositeNH::kInvalidComponentNHIdx);
EXPECT_TRUE(entry->is_flags_set(FlowEntry::ShortFlow) == false);
//Update the route to make the remote destination unicast
Inet4TunnelRouteAdd(bgp_peer, "default-project:vn10:vn10", gw_rt, 0,
Ip4Address::from_string("8.8.8.8"),
TunnelType::ComputeType(TunnelType::MplsType()),
100, "default-project:vn10", SecurityGroupList(),
PathPreference());
client->WaitForIdle();
//Make sure flow has the right nexthop set.
InetUnicastRouteEntry *rt = RouteGet("default-project:vn10:vn10", gw_rt, 0);
FlowEntry *rev_entry = entry->reverse_flow_entry();
EXPECT_TRUE(rev_entry->nh() == rt->GetActiveNextHop());
DeleteVmportEnv(input1, 1, true);
DeleteRemoteRoute("default-project:vn10:vn10", "0.0.0.0", 0);
DelLink("floating-ip", "fip9", "floating-ip-pool", "fip-pool9");
DelLink("floating-ip-pool", "fip-pool9",
"virtual-network", "default-project:vn10");
DelLink("virtual-machine-interface", "vnet9", "floating-ip", "fip9");
DelFloatingIp("fip9");
DelFloatingIpPool("fip-pool9");
client->WaitForIdle();
DelVrf("default-project:vn10:vn10");
DelVn("default-project:vn10");
client->WaitForIdle();
WAIT_FOR(100, 1000, VrfFind("default-project:vn10:vn10", true) == false);
client->WaitForIdle();
EXPECT_TRUE(get_flow_proto()->FlowCount() == 0);
EXPECT_FALSE(VrfFind("vrf9", true));
}
TEST_F(EcmpTest, EcmpTest_15) {
struct PortInfo input1[] = {
{"vnet9", 9, "9.1.1.1", "00:00:00:01:01:01", 9, 9},
};
CreateVmportWithEcmp(input1, 1);
client->WaitForIdle();
Ip4Address gw_rt = Ip4Address::from_string("0.0.0.0");
Ip4Address remote_server_ip1 = Ip4Address::from_string("10.10.10.100");
Ip4Address remote_server_ip2 = Ip4Address::from_string("10.10.10.101");
Agent *agent = Agent::GetInstance();
ComponentNHKeyPtr nh_data1(new ComponentNHKey(30, agent->fabric_vrf_name(),