/
test_interface_uve.cc
984 lines (815 loc) · 32.9 KB
/
test_interface_uve.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
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
#include "base/os.h"
#include <cfg/cfg_init.h>
#include <cfg/cfg_interface.h>
#include <oper/operdb_init.h>
#include <controller/controller_init.h>
#include <pkt/pkt_init.h>
#include <services/services_init.h>
#include <vrouter/ksync/ksync_init.h>
#include <cmn/agent_cmn.h>
#include <base/task.h>
#include <io/event_manager.h>
#include <base/util.h>
#include <ifmap/ifmap_agent_parser.h>
#include <ifmap/ifmap_agent_table.h>
#include <oper/vn.h>
#include <oper/vm.h>
#include <oper/interface_common.h>
#include <oper/interface.h>
#include <oper/interface.h>
#include <oper/mirror_table.h>
#include <uve/agent_uve.h>
#include "testing/gunit.h"
#include "test/test_cmn_util.h"
#include "pkt/test/test_flow_util.h"
#include "pkt/test/flow_table_test.h"
#include "ksync/ksync_sock_user.h"
#include "vr_types.h"
#include <uve/test/interface_uve_table_test.h>
#include "uve/test/test_uve_util.h"
using namespace std;
#define vm1_ip "11.1.1.1"
#define vm2_ip "11.1.1.2"
#define vm4_ip "14.1.1.1"
#define vm1_fip "14.1.1.100"
#define vm_a_ip "15.0.0.1"
#define vm_b_ip "16.0.0.1"
#define vm_c_ip "17.0.0.1"
#define vm_c_fip1 "17.0.0.10"
#define vm_c_fip2 "17.0.0.11"
#define remote_vm_fip "14.1.1.101"
#define remote_router_ip "10.1.1.2"
struct PortInfo input[] = {
{"flow0", 6, vm1_ip, "00:00:00:01:01:01", 5, 1},
{"flow1", 7, vm2_ip, "00:00:00:01:01:02", 5, 2},
};
struct PortInfo input2[] = {
{"flow2", 8, vm4_ip, "00:00:00:01:01:06", 4, 3},
};
struct PortInfo fip_input1[] = {
{"flowa", 3, vm_a_ip, "00:00:00:02:01:01", 6, 6},
{"flowb", 4, vm_b_ip, "00:00:00:02:01:02", 7, 7},
};
struct PortInfo fip_input2[] = {
{"flowc", 5, vm_c_ip, "00:00:00:02:01:03", 8, 8},
};
VmInterface *flow0;
VmInterface *flow1;
VmInterface *flow2;
VmInterface *flowa;
VmInterface *flowb;
VmInterface *flowc;
void RouterIdDepInit(Agent *agent) {
}
class InterfaceUveTest : public ::testing::Test {
public:
InterfaceUveTest() : util_(), peer_(NULL), agent_(Agent::GetInstance()) {
}
void FlowSetUp() {
EXPECT_EQ(0U, Agent::GetInstance()->pkt()->flow_table()->Size());
client->Reset();
CreateVmportEnv(input, 2, 1);
client->WaitForIdle(5);
CreateVmportFIpEnv(input2, 1, 0);
client->WaitForIdle(5);
EXPECT_TRUE(VmPortActive(input, 0));
EXPECT_TRUE(VmPortActive(input, 1));
EXPECT_TRUE(VmPortPolicyEnable(input, 0));
EXPECT_TRUE(VmPortPolicyEnable(input, 1));
EXPECT_TRUE(VmPortActive(input2, 0));
flow0 = VmInterfaceGet(input[0].intf_id);
assert(flow0);
flow1 = VmInterfaceGet(input[1].intf_id);
assert(flow1);
flow2 = VmInterfaceGet(input2[0].intf_id);
assert(flow2);
// Configure Floating-IP
AddFloatingIpPool("fip-pool1", 1);
AddFloatingIp("fip1", 1, vm1_fip);
AddLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
AddLink("floating-ip-pool", "fip-pool1", "virtual-network", "default-project:vn4");
AddLink("virtual-machine-interface", "flow0", "floating-ip", "fip1");
client->WaitForIdle();
EXPECT_TRUE(flow0->HasFloatingIp());
}
void FlowTearDown() {
FlushFlowTable();
client->Reset();
DeleteVmportEnv(input, 2, true, 1);
client->WaitForIdle(3);
client->PortDelNotifyWait(2);
EXPECT_FALSE(VmPortFind(input, 0));
EXPECT_FALSE(VmPortFind(input, 1));
client->Reset();
DeleteVmportFIpEnv(input2, 1, true);
client->WaitForIdle(3);
client->PortDelNotifyWait(1);
EXPECT_FALSE(VmPortFind(input2, 0));
}
void FlowTearDown2() {
FlushFlowTable();
client->Reset();
DeleteVmportEnv(fip_input1, 2, true, 1);
client->WaitForIdle(3);
client->PortDelNotifyWait(2);
EXPECT_FALSE(VmPortFind(fip_input1, 0));
EXPECT_FALSE(VmPortFind(fip_input1, 1));
client->Reset();
DeleteVmportFIpEnv(fip_input2, 1, true);
client->WaitForIdle(3);
client->PortDelNotifyWait(1);
EXPECT_FALSE(VmPortFind(fip_input2, 0));
}
void FlowSetUp2() {
EXPECT_EQ(0U, Agent::GetInstance()->pkt()->flow_table()->Size());
client->Reset();
CreateVmportEnv(fip_input1, 2, 1);
client->WaitForIdle(5);
CreateVmportFIpEnv(fip_input2, 1, 0);
client->WaitForIdle(5);
EXPECT_TRUE(VmPortActive(fip_input1, 0));
EXPECT_TRUE(VmPortActive(fip_input1, 1));
EXPECT_TRUE(VmPortPolicyEnable(fip_input1, 0));
EXPECT_TRUE(VmPortPolicyEnable(fip_input1, 1));
EXPECT_TRUE(VmPortActive(fip_input2, 0));
flowa = VmInterfaceGet(fip_input1[0].intf_id);
assert(flowa);
flowb = VmInterfaceGet(fip_input1[1].intf_id);
assert(flowb);
flowc = VmInterfaceGet(fip_input2[0].intf_id);
assert(flowc);
// Configure Floating-IP
AddFloatingIpPool("fip-poolc", 1);
AddFloatingIp("fipc1", 1, vm_c_fip1);
AddFloatingIp("fipc2", 1, vm_c_fip2);
AddLink("floating-ip", "fipc1", "floating-ip-pool", "fip-poolc");
AddLink("floating-ip", "fipc2", "floating-ip-pool", "fip-poolc");
AddLink("floating-ip-pool", "fip-poolc", "virtual-network", "default-project:vn8");
AddLink("virtual-machine-interface", "flowa", "floating-ip", "fipc1");
AddLink("virtual-machine-interface", "flowb", "floating-ip", "fipc2");
client->WaitForIdle();
EXPECT_TRUE(flowa->HasFloatingIp());
EXPECT_TRUE(flowb->HasFloatingIp());
}
void RemoveFipConfig() {
DelLink("virtual-machine-interface", "flow0", "floating-ip", "fip1");
DelLink("floating-ip", "fip1", "floating-ip-pool", "fip-pool1");
DelLink("floating-ip-pool", "fip-pool1",
"virtual-network", "default-project:vn4");
DelFloatingIp("fip1");
DelFloatingIpPool("fip-pool1");
client->WaitForIdle(3);
}
void RemoveFipConfig2() {
DelLink("virtual-machine-interface", "flowa", "floating-ip", "fipc1");
DelLink("virtual-machine-interface", "flowb", "floating-ip", "fipc2");
DelLink("floating-ip-pool", "fip-poolc",
"virtual-network", "default-project:vn8");
DelLink("floating-ip", "fipc1", "floating-ip-pool", "fip-poolc");
DelLink("floating-ip", "fipc2", "floating-ip-pool", "fip-poolc");
DelFloatingIp("fipc1");
DelFloatingIp("fipc2");
DelFloatingIpPool("fip-poolc");
client->WaitForIdle(3);
}
void CreatePeer() {
boost::system::error_code ec;
peer_ = CreateBgpPeer(Ip4Address::from_string("0.0.0.1", ec),
"xmpp channel");
}
void DeletePeer() {
DeleteBgpPeer(peer_);
}
Agent *agent() {return agent_;}
TestUveUtil util_;
BgpPeer *peer_;
Agent *agent_;
};
TEST_F(InterfaceUveTest, VmIntfAddDel_1) {
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
};
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
//Add VN
util_.VnAdd(input[0].vn_id);
// Nova Port add message
util_.NovaPortAdd(input);
// Config Port add
util_.ConfigPortAdd(input);
//Add VM
util_.VmAdd(input[0].vm_id);
client->WaitForIdle();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify send_count after VM addition
EXPECT_TRUE((vmut->send_count() > 0));
uint32_t send_count = vmut->send_count();
//Add necessary objects and links to make vm-intf active
util_.VrfAdd(input[0].vn_id);
AddLink("virtual-network", "vn1", "routing-instance", "vrf1");
client->WaitForIdle();
AddLink("virtual-network", "vn1", "virtual-machine-interface", "vnet1");
client->WaitForIdle();
AddLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1");
client->WaitForIdle();
AddVmPortVrf("vnet1", "", 0);
client->WaitForIdle();
AddInstanceIp("instance0", input[0].vm_id, input[0].addr);
AddLink("virtual-machine-interface", input[0].name,
"instance-ip", "instance0");
client->WaitForIdle();
AddLink("virtual-machine-interface-routing-instance", "vnet1",
"routing-instance", "vrf1");
client->WaitForIdle();
AddLink("virtual-machine-interface-routing-instance", "vnet1",
"virtual-machine-interface", "vnet1");
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(input, 0));
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify UVE
const VmInterface *vmi = VmInterfaceGet(input[0].intf_id);
EXPECT_TRUE(vmi != NULL);
const UveVMInterfaceAgent uve1 = vmut->last_sent_uve();
EXPECT_TRUE((vmut->send_count() > send_count));
//Verify interface config name
std::string intf_entry = uve1.get_name();
string cfg_name = vmi->cfg_name();
EXPECT_STREQ(cfg_name.c_str(), intf_entry.c_str());
// Delete virtual-machine-interface to vrf link attribute
DelLink("virtual-machine-interface-routing-instance", "vnet1",
"routing-instance", "vrf1");
DelLink("virtual-machine-interface-routing-instance", "vnet1",
"virtual-machine-interface", "vnet1");
client->WaitForIdle();
//other cleanup
util_.VnDelete(input[0].vn_id);
DelLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1");
DelLink("virtual-network", "vn1", "virtual-machine-interface", "vnet1");
client->WaitForIdle();
DelLink("virtual-machine-interface", input[0].name,
"instance-ip", "instance0");
DelLink("virtual-network", "vn1", "routing-instance", "vrf1");
DelNode("virtual-machine-interface-routing-instance", "vnet1");
DelNode("virtual-machine", "vm1");
DelNode("routing-instance", "vrf1");
DelNode("virtual-network", "vn1");
DelNode("virtual-machine-interface", "vnet1");
DelInstanceIp("instance0");
client->WaitForIdle();
IntfCfgDel(input, 0);
client->WaitForIdle();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
//Verify UVE
EXPECT_EQ(1U, vmut->delete_count());
//clear counters at the end of test case
client->Reset();
vmut->ClearCount();
}
/* Vm Dissassociation from VMI, VM Delete --> Vm Add, Vm Reassociation */
TEST_F(InterfaceUveTest, VmIntfAddDel_2) {
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
};
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
//Add VN
util_.VnAdd(input[0].vn_id);
// Nova Port add message
util_.NovaPortAdd(input);
// Config Port add
util_.ConfigPortAdd(input);
//Add VM
util_.VmAdd(input[0].vm_id);
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify send_count after VM addition
EXPECT_EQ(1U, vmut->send_count());
//Add necessary objects and links to make vm-intf active
util_.VrfAdd(input[0].vn_id);
AddLink("virtual-network", "vn1", "routing-instance", "vrf1");
client->WaitForIdle();
AddLink("virtual-network", "vn1", "virtual-machine-interface", "vnet1");
client->WaitForIdle();
AddLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1");
client->WaitForIdle();
AddVmPortVrf("vnet1", "", 0);
client->WaitForIdle();
AddInstanceIp("instance0", input[0].vm_id, input[0].addr);
AddLink("virtual-machine-interface", input[0].name,
"instance-ip", "instance0");
client->WaitForIdle();
AddLink("virtual-machine-interface-routing-instance", "vnet1",
"routing-instance", "vrf1");
client->WaitForIdle();
AddLink("virtual-machine-interface-routing-instance", "vnet1",
"virtual-machine-interface", "vnet1");
client->WaitForIdle();
EXPECT_TRUE(VmPortActive(input, 0));
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify UVE
EXPECT_EQ(2U, vmut->send_count());
//Disassociate VM from VMI and delete the VM
DelLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1");
util_.VmDelete(input[0].vm_id);
client->WaitForIdle();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify that no additional interface UVEs are sent
EXPECT_TRUE((vmut->send_count() == 3U));
EXPECT_EQ(0U, vmut->delete_count());
//Add the VM back and re-associate it with same VMI
util_.VmAdd(input[0].vm_id);
AddLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1");
client->WaitForIdle();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify UVE
EXPECT_TRUE((vmut->send_count() >= 4U));
// Delete virtual-machine-interface to vrf link attribute
DelLink("virtual-machine-interface-routing-instance", "vnet1",
"routing-instance", "vrf1");
DelLink("virtual-machine-interface-routing-instance", "vnet1",
"virtual-machine-interface", "vnet1");
client->WaitForIdle();
//Verify that the port is inactive
EXPECT_TRUE(VmPortInactive(input, 0));
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify UVE
EXPECT_TRUE((vmut->send_count() >= 5U));
//Activate the interface again
AddLink("virtual-machine-interface-routing-instance", "vnet1",
"routing-instance", "vrf1");
AddLink("virtual-machine-interface-routing-instance", "vnet1",
"virtual-machine-interface", "vnet1");
client->WaitForIdle();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify UVE
EXPECT_TRUE((vmut->send_count() >= 6U));
// Delete virtual-machine-interface to vrf link attribute
DelLink("virtual-machine-interface-routing-instance", "vnet1",
"routing-instance", "vrf1");
DelLink("virtual-machine-interface-routing-instance", "vnet1",
"virtual-machine-interface", "vnet1");
client->WaitForIdle();
//Verify that the port is inactive
EXPECT_TRUE(VmPortInactive(input, 0));
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify UVE
EXPECT_TRUE((vmut->send_count() >= 7U));
//other cleanup
util_.VnDelete(input[0].vn_id);
DelLink("virtual-machine", "vm1", "virtual-machine-interface", "vnet1");
DelLink("virtual-network", "vn1", "virtual-machine-interface", "vnet1");
client->WaitForIdle();
EXPECT_TRUE(VmPortInactive(input, 0));
DelLink("virtual-machine-interface", input[0].name,
"instance-ip", "instance0");
DelLink("virtual-network", "vn1", "routing-instance", "vrf1");
DelNode("virtual-machine-interface-routing-instance", "vnet1");
DelNode("virtual-machine", "vm1");
DelNode("routing-instance", "vrf1");
DelNode("virtual-network", "vn1");
DelNode("virtual-machine-interface", "vnet1");
DelInstanceIp("instance0");
client->WaitForIdle();
IntfCfgDel(input, 0);
client->WaitForIdle();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
//Verify UVE
EXPECT_EQ(1U, vmut->delete_count());
//clear counters at the end of test case
client->Reset();
vmut->ClearCount();
}
TEST_F(InterfaceUveTest, VmIntfAddDel_3) {
struct PortInfo input[] = {
{"vnet1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1},
};
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
// Nova Port add message
util_.NovaPortAdd(input);
//Verify that entry for interface is not added to our tree until config is
//received.
EXPECT_EQ(0U, vmut->InterfaceUveCount());
// Config Port add
util_.ConfigPortAdd(input);
client->WaitForIdle();
//Verify that entry for interface is added to our tree after config is
//received.
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 1U)));
EXPECT_EQ(1U, vmut->InterfaceUveCount());
// Config Port delete
DelNode("virtual-machine-interface", "vnet1");
client->WaitForIdle();
//Verify that on deletion of interface config, the entry is marked for
//delete in our tree.
InterfaceUveTable::UveInterfaceEntry* entry = vmut->GetUveInterfaceEntry
("vnet1");
EXPECT_TRUE(entry->deleted_);
// Nova port delete
IntfCfgDel(input, 0);
client->WaitForIdle();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
//clear counters at the end of test case
client->Reset();
vmut->ClearCount();
}
TEST_F(InterfaceUveTest, FipStats_1) {
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
FlowSetUp();
FlowStatsCollector *fsc = Agent::GetInstance()->flow_stats_collector();
TestFlow flow[] = {
{
TestFlowPkt(Address::INET, vm1_ip, vm4_ip, 1, 0, 0, "vrf5",
flow0->id(), 1),
{
new VerifyNat(vm4_ip, vm1_fip, 1, 0, 0)
}
}
};
CreateFlow(flow, 1);
EXPECT_EQ(2U, Agent::GetInstance()->pkt()->flow_table()->Size());
//Verify Floating IP flows are created.
const FlowEntry *f1 = flow[0].pkt_.FlowFetch();
const FlowEntry *rev = f1->reverse_flow_entry();
EXPECT_TRUE(FlowGet(VrfGet("vrf5")->vrf_id(), vm1_ip, vm4_ip, 1, 0, 0,
flow0->flow_key_nh()->id()));
EXPECT_TRUE(FlowGet(VrfGet("default-project:vn4:vn4")->vrf_id(), vm4_ip,
vm1_fip, 1, 0, 0, rev->key().nh));
//Verify that stats FIP entry is absent until flow stats are updated
EXPECT_EQ(0U, vmut->GetVmIntfFipCount(flow0));
//Update FIP stats which resuts in creation of stats FIP entry
fsc->UpdateFloatingIpStats(f1, 300, 3);
fsc->UpdateFloatingIpStats(rev, 300, 3);
//Verify that stats FIP entry is created
EXPECT_EQ(1U, vmut->GetVmIntfFipCount(flow0));
//Fetch stats FIP entry and verify its statistics
const InterfaceUveTable::FloatingIp *fip = vmut->GetVmIntfFip(flow0,
vm1_fip, "default-project:vn4");
EXPECT_EQ(3U, fip->in_packets_);
EXPECT_EQ(3U, fip->out_packets_);
EXPECT_EQ(300U, fip->in_bytes_);
EXPECT_EQ(300U, fip->out_bytes_);
//cleanup
FlowTearDown();
RemoveFipConfig();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
vmut->ClearCount();
}
// Delete FIP config and verify stats entry for that FIP is removed from
// our data-structures
TEST_F(InterfaceUveTest, FipStats_2) {
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
FlowSetUp();
FlowStatsCollector *fsc = Agent::GetInstance()->flow_stats_collector();
TestFlow flow[] = {
{
TestFlowPkt(Address::INET, vm1_ip, vm4_ip, 1, 0, 0, "vrf5",
flow0->id(), 1),
{
new VerifyNat(vm4_ip, vm1_fip, 1, 0, 0)
}
}
};
CreateFlow(flow, 1);
EXPECT_EQ(2U, Agent::GetInstance()->pkt()->flow_table()->Size());
//Verify Floating IP flows are created.
const FlowEntry *f1 = flow[0].pkt_.FlowFetch();
const FlowEntry *rev = f1->reverse_flow_entry();
EXPECT_TRUE(FlowGet(VrfGet("vrf5")->vrf_id(), vm1_ip, vm4_ip, 1, 0, 0,
flow0->flow_key_nh()->id()));
EXPECT_TRUE(FlowGet(VrfGet("default-project:vn4:vn4")->vrf_id(), vm4_ip,
vm1_fip, 1, 0, 0, rev->key().nh));
//Verify that stats FIP entry is absent until flow stats are updated
EXPECT_EQ(0U, vmut->GetVmIntfFipCount(flow0));
//Update FIP stats which resuts in creation of stats FIP entry
fsc->UpdateFloatingIpStats(f1, 300, 3);
fsc->UpdateFloatingIpStats(rev, 300, 3);
//Verify that stats FIP entry is created
EXPECT_EQ(1U, vmut->GetVmIntfFipCount(flow0));
//Remove floating-IP configuration
RemoveFipConfig();
//Verify that stats FIP entry is created
EXPECT_EQ(0U, vmut->GetVmIntfFipCount(flow0));
//cleanup
FlowTearDown();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
vmut->ClearCount();
}
// Update FIP stats and verify dispatched VM Stats UVE has the expected stats
TEST_F(InterfaceUveTest, FipStats_3) {
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
FlowSetUp();
FlowStatsCollector *fsc = Agent::GetInstance()->flow_stats_collector();
TestFlow flow[] = {
{
TestFlowPkt(Address::INET, vm1_ip, vm4_ip, 1, 0, 0, "vrf5",
flow0->id(), 1),
{
new VerifyNat(vm4_ip, vm1_fip, 1, 0, 0)
}
}
};
CreateFlow(flow, 1);
EXPECT_EQ(2U, Agent::GetInstance()->pkt()->flow_table()->Size());
EXPECT_EQ(3U, vmut->InterfaceUveCount());
//Send the required UVEs which clears changed flag set on UVE objects.
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
vmut->ClearCount();
//Verify Floating IP flows are created.
const FlowEntry *f1 = flow[0].pkt_.FlowFetch();
const FlowEntry *rev = f1->reverse_flow_entry();
EXPECT_TRUE(FlowGet(VrfGet("vrf5")->vrf_id(), vm1_ip, vm4_ip, 1, 0, 0,
flow0->flow_key_nh()->id()));
EXPECT_TRUE(FlowGet(VrfGet("default-project:vn4:vn4")->vrf_id(), vm4_ip,
vm1_fip, 1, 0, 0, rev->key().nh));
//Verify that stats FIP entry is absent until flow stats are updated
EXPECT_EQ(0U, vmut->GetVmIntfFipCount(flow0));
//Update FIP stats which resuts in creation of stats FIP entry
fsc->UpdateFloatingIpStats(f1, 300, 3);
fsc->UpdateFloatingIpStats(rev, 300, 3);
client->WaitForIdle();
//Verify that stats FIP entry is created
EXPECT_EQ(1U, vmut->GetVmIntfFipCount(flow0));
//Fetch stats FIP entry and verify its statistics
const InterfaceUveTable::FloatingIp *fip = vmut->GetVmIntfFip(flow0,
vm1_fip, "default-project:vn4");
EXPECT_EQ(3U, fip->in_packets_);
EXPECT_EQ(3U, fip->out_packets_);
EXPECT_EQ(300U, fip->in_bytes_);
EXPECT_EQ(300U, fip->out_bytes_);
//Trigger Interface UVE send
vmut->ClearCount();
vmut->SendInterfaceStats();
EXPECT_EQ(3U, vmut->send_count());
EXPECT_EQ(0U, vmut->delete_count());
//Verify UVE
UveVMInterfaceAgent *uve1 = vmut->InterfaceUveObject(flow0);
EXPECT_EQ(1U, uve1->get_fip_agg_stats().size());
//Verify stats values in UVE
const VmFloatingIPStats &stats = uve1->get_fip_agg_stats().front();
EXPECT_EQ(3U, stats.get_in_pkts());
EXPECT_EQ(3U, stats.get_out_pkts());
EXPECT_EQ(300U, stats.get_in_bytes());
EXPECT_EQ(300U, stats.get_out_bytes());
//cleanup
FlowTearDown();
RemoveFipConfig();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
vmut->ClearCount();
}
// Update FIP stats and verify dispatched VM Stats UVE has the expected stats.
// The VMs representing source and destination IP of flow should have a FIP each
// assigned from a common third VN's floating IP pool. Both VMs are part of same
// compute node (Local Flow case)
TEST_F(InterfaceUveTest, FipStats_4) {
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
FlowSetUp2();
FlowStatsCollector *fsc = Agent::GetInstance()->flow_stats_collector();
TestFlow flow[] = {
{
TestFlowPkt(Address::INET, vm_a_ip, vm_c_fip2, 1, 0, 0, "vrf6",
flowa->id(), 1),
{
new VerifyNat(vm_b_ip, vm_c_fip1, 1, 0, 0)
}
}
};
CreateFlow(flow, 1);
EXPECT_EQ(2U, Agent::GetInstance()->pkt()->flow_table()->Size());
//Verify Floating IP flows are created.
const FlowEntry *f1 = flow[0].pkt_.FlowFetch();
const FlowEntry *rev = f1->reverse_flow_entry();
EXPECT_TRUE(FlowGet(VrfGet("vrf6")->vrf_id(), vm_a_ip, vm_c_fip2, 1, 0, 0,
flowa->flow_key_nh()->id()));
EXPECT_TRUE(FlowGet(VrfGet("vrf7")->vrf_id(), vm_b_ip, vm_c_fip1, 1, 0, 0,
rev->key().nh));
//Verify that stats FIP entry is absent until flow stats are updated
EXPECT_EQ(0U, vmut->GetVmIntfFipCount(flowa));
//Update FIP stats which resuts in creation of stats FIP entry
fsc->UpdateFloatingIpStats(f1, 300, 3);
fsc->UpdateFloatingIpStats(rev, 300, 3);
//Verify that stats FIP entry is created
EXPECT_EQ(1U, vmut->GetVmIntfFipCount(flowa));
//Fetch stats FIP entry and verify its statistics
const InterfaceUveTable::FloatingIp *fip = vmut->GetVmIntfFip(flowa,
vm_c_fip1, "default-project:vn8");
EXPECT_EQ(3U, fip->in_packets_);
EXPECT_EQ(3U, fip->out_packets_);
EXPECT_EQ(300U, fip->in_bytes_);
EXPECT_EQ(300U, fip->out_bytes_);
//Trigger VM UVE send
vmut->ClearCount();
vmut->SendInterfaceStats();
EXPECT_EQ(3U, vmut->send_count());
EXPECT_EQ(0U, vmut->delete_count());
//Verify UVE
UveVMInterfaceAgent *uve1 = vmut->InterfaceUveObject(flowa);
EXPECT_EQ(1U, uve1->get_fip_agg_stats().size());
//Verify stats values in UVE
const VmFloatingIPStats &stats = uve1->get_fip_agg_stats().front();
EXPECT_EQ(3U, stats.get_in_pkts());
EXPECT_EQ(3U, stats.get_out_pkts());
EXPECT_EQ(300U, stats.get_in_bytes());
EXPECT_EQ(300U, stats.get_out_bytes());
//cleanup
FlowTearDown2();
RemoveFipConfig2();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
vmut->ClearCount();
EXPECT_EQ(0U, vmut->GetVmIntfFipCount(flowa));
}
// Update FIP stats and verify dispatched VM Stats UVE has the expected stats.
// The VMs representing source and destination IP of flow should have a FIP each
// assigned from a common third VN's floating IP pool. The destination VM is in
// different compute node. (Non Local flow case)
TEST_F(InterfaceUveTest, FipStats_5) {
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
FlowSetUp();
FlowStatsCollector *fsc = Agent::GetInstance()->flow_stats_collector();
CreatePeer();
util_.CreateRemoteRoute("default-project:vn4:vn4", remote_vm_fip,
remote_router_ip, 30, "default-project:vn4", peer_);
client->WaitForIdle();
TestFlow flow[] = {
{
TestFlowPkt(Address::INET, vm1_ip, remote_vm_fip, 1, 0, 0, "vrf5",
flow0->id(), 1001),
{}
}
};
CreateFlow(flow, 1);
EXPECT_EQ(2U, Agent::GetInstance()->pkt()->flow_table()->Size());
//Verify Floating IP flows are created.
const FlowEntry *f1 = flow[0].pkt_.FlowFetch();
const FlowEntry *rev = f1->reverse_flow_entry();
EXPECT_TRUE(FlowGet(VrfGet("vrf5")->vrf_id(), vm1_ip, remote_vm_fip, 1, 0, 0,
flow0->flow_key_nh()->id()));
EXPECT_TRUE(FlowGet(VrfGet("vrf5")->vrf_id(), remote_vm_fip, vm1_fip, 1, 0, 0,
rev->key().nh));
//Verify that stats FIP entry is absent until flow stats are updated
EXPECT_EQ(0U, vmut->GetVmIntfFipCount(flow0));
//Update FIP stats which resuts in creation of stats FIP entry
fsc->UpdateFloatingIpStats(f1, 300, 3);
fsc->UpdateFloatingIpStats(rev, 300, 3);
//Verify that stats FIP entry is created
EXPECT_EQ(1U, vmut->GetVmIntfFipCount(flow0));
//Fetch stats FIP entry and verify its statistics
const InterfaceUveTable::FloatingIp *fip = vmut->GetVmIntfFip(flow0,
vm1_fip, "default-project:vn4");
EXPECT_EQ(3U, fip->in_packets_);
EXPECT_EQ(3U, fip->out_packets_);
EXPECT_EQ(300U, fip->in_bytes_);
EXPECT_EQ(300U, fip->out_bytes_);
//Trigger VM UVE send
vmut->ClearCount();
vmut->SendInterfaceStats();
WAIT_FOR(1000, 500, (3U == vmut->send_count()));
EXPECT_EQ(0U, vmut->delete_count());
//Verify UVE
UveVMInterfaceAgent *uve1 = vmut->InterfaceUveObject(flow0);
EXPECT_EQ(1U, uve1->get_fip_agg_stats().size());
//Verify stats values in UVE
const VmFloatingIPStats &stats = uve1->get_fip_agg_stats().front();
EXPECT_EQ(3U, stats.get_in_pkts());
EXPECT_EQ(3U, stats.get_out_pkts());
EXPECT_EQ(300U, stats.get_in_bytes());
EXPECT_EQ(300U, stats.get_out_bytes());
//cleanup
FlowTearDown();
util_.DeleteRemoteRoute("default-project:vn4:vn4", remote_vm_fip, peer_);
RemoveFipConfig();
DeletePeer();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
vmut->ClearCount();
}
/* Verify that VM name is not NULL-string in the interface UVE sent as part of
* VM UVE */
TEST_F(InterfaceUveTest, VmNameInInterfaceList) {
InterfaceUveTableTest *vmut = static_cast<InterfaceUveTableTest *>
(Agent::GetInstance()->uve()->interface_uve_table());
vmut->ClearCount();
EXPECT_EQ(0U, vmut->InterfaceUveCount());
struct PortInfo input[] = {
{"vmi1", 1, "1.1.1.1", "00:00:00:01:01:01", 1, 1}
};
//Add physical-device and physical-interface and add their association
util_.VmAdd(input[0].vm_id);
AddPhysicalDevice("prouter1", 1);
AddPhysicalInterface("pi1", 1, "pid1");
AddLogicalInterface("li1", 1, "lid1");
AddPort("vmi1", 1);
AddLink("physical-router", "prouter1", "physical-interface", "pi1");
AddLink("physical-interface", "pi1", "logical-interface", "li1");
AddLink("virtual-machine-interface", "vmi1", "logical-interface", "li1");
AddLink("virtual-machine-interface", "vmi1", "virtual-machine", "vm1");
client->WaitForIdle();
WAIT_FOR(1000, 500, (PhysicalDeviceGet(1) != NULL));
WAIT_FOR(1000, 500, (PhysicalInterfaceGet("pi1") != NULL));
WAIT_FOR(1000, 500, (LogicalInterfaceGet(1, "li1") != NULL));
WAIT_FOR(1000, 500, (VmInterfaceGet(1) != NULL));
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
//Verify UVE
VmEntry *vm = VmGet(input[0].vm_id);
EXPECT_TRUE(vm != NULL);
VmInterface *vmi = VmInterfaceGet(input[0].intf_id);
EXPECT_TRUE(vmi != NULL);
EXPECT_TRUE(vmi->vm() != NULL);
EXPECT_TRUE(vmi->vm() == vm);
EXPECT_TRUE(!vm->GetCfgName().empty());
UveVMInterfaceAgent uve1 = vmut->last_sent_uve();
//Verify that VMI does not have VM Name set
//EXPECT_TRUE((vmi->vm_name() == agent_->NullString()));
EXPECT_TRUE((vmi->vm_name().empty()));
//Verify that UVE has sent VM name for VMI
EXPECT_TRUE((uve1.get_vm_name() == vm->GetCfgName()));
//cleanup
DelLink("virtual-machine-interface", "vmi1", "virtual-machine", "vm1");
DelNode("virtual-machine", "vm1");
//Disassociate VMI from logical-interface
DelLink("virtual-machine-interface", "vmi1", "logical-interface", "li1");
//Disassociate logical-interface from physical_interface
DelLink("physical-interface", "pi1", "logical-interface", "li1");
//Disassociate physical-device from physical-interface
DelLink("physical-router", "prouter1", "physical-interface", "pi1");
//Delete physical-device and physical-interface
DelPort("vmi1");
DeleteLogicalInterface("li1");
DeletePhysicalInterface("pi1");
DeletePhysicalDevice("prouter1");
client->WaitForIdle();
WAIT_FOR(1000, 500, (PhysicalInterfaceGet("pi1") == NULL));
WAIT_FOR(1000, 500, (PhysicalDeviceGet(1) == NULL));
WAIT_FOR(1000, 500, (LogicalInterfaceGet(1, "li1") == NULL));
//clear counters at the end of test case
client->Reset();
util_.EnqueueSendVmiUveTask();
client->WaitForIdle();
WAIT_FOR(1000, 500, ((vmut->InterfaceUveCount() == 0U)));
vmut->ClearCount();
}
TEST_F(InterfaceUveTest, PhysicalIntfAddDel_1) {
}
TEST_F(InterfaceUveTest, LogicalIntfAddDel_1) {
}
int main(int argc, char **argv) {
GETUSERARGS();
client = TestInit(init_file, ksync_init, true, false, true,
(10 * 60 * 1000), (10 * 60 * 1000), true, true,
(10 * 60 * 1000));
usleep(10000);
int ret = RUN_ALL_TESTS();
client->WaitForIdle();
TestShutdown();
delete client;
return ret;
}