/
bgp_config_listener_test.cc
2244 lines (1902 loc) · 91 KB
/
bgp_config_listener_test.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 <fstream>
#include "base/task_annotations.h"
#include "base/test/task_test_util.h"
#include "bgp/bgp_config_ifmap.h"
#include "bgp/bgp_config_listener.h"
#include "bgp/bgp_config_parser.h"
#include "bgp/bgp_factory.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_server.h"
#include "control-node/control_node.h"
#include "db/db_graph.h"
#include "db/test/db_test_util.h"
#include "ifmap/ifmap_dependency_tracker.h"
#include "ifmap/ifmap_link_table.h"
#include "ifmap/ifmap_node.h"
#include "ifmap/test/ifmap_test_util.h"
#include "schema/bgp_schema_types.h"
#include "schema/vnc_cfg_types.h"
using namespace std;
//
// OVERVIEW
//
// This is the test suite for BgpConfigListener class and DependencyTracker
// nested class. The BgpConfigData that gets populated in BgpConfigManager
// does not trigger the creation of any operational state since there's no
// BgpConfigManager::Observers registered.
//
// A BgpConfigListenerMock class is used. It's GetChangeList method doesn't
// do anything when processing is disabled.
//
// In addition to testing the common code in the BgpConfigListener and the
// DependencyTracker, the tests also cover each of the terms in the policy
// that's specified via the listener's Initialize method. New tests should
// be added as and when the policy is modified.
//
// TEST STEPS
//
// 1. Setup creates all the IFMap tables and initialize BgpConfigManager.
// 2. Each test creates the desired configuration by parsing a test config.
// 3. Some tests create additional configuration using the ifmap_test_util
// infrastructure.
// 4. Wait for all configuration to be processed and reach steady state.
// 5. Disable propagation to the change list in the BgpConfigListenerMock.
// 6. Trigger the appropriate IFMapNode and/or IFMapLink events using the
// ifmap_test_util infrastructure.
// 7. Verify number of entries on the ChangeList in the BgpConfigListener
// and number of entries in the NodeList and EdgeDescriptorList in the
// DependencyTracker.
// 8. Ask the BgpConfigListener to process the items in the NodeList and in
// the EdgeDescriptorList and propagate the changes into the ChangeList.
// 9. Verify total number entries on the ChangeList and number of entries
// of each identifier type.
// 10. Enable propagation to the change list in BgpConfigListenerMock and
// trigger the BgpConfigManager to process the change list.
// 11. TearDown terminates BgpConfigManager and cleans up all IFMap state.
//
static string ReadFile(const string &filename) {
ifstream file(filename.c_str());
string content((istreambuf_iterator<char>(file)),
istreambuf_iterator<char>());
return content;
}
class BgpConfigListenerMock : public BgpConfigListener {
public:
BgpConfigListenerMock(BgpIfmapConfigManager *manager)
: BgpConfigListener(manager), no_processing_(false) {
}
virtual ~BgpConfigListenerMock() {
}
virtual void GetChangeList(ChangeList *change_list) {
if (no_processing_)
return;
BgpConfigListener::GetChangeList(change_list);
}
void set_no_processing() { no_processing_ = true; }
void clear_no_processing() { no_processing_ = false; }
private:
bool no_processing_;
};
class BgpConfigListenerTest : public ::testing::Test {
protected:
typedef BgpConfigListener::ChangeList ChangeList;
typedef IFMapDependencyTracker::NodeList NodeList;
typedef IFMapDependencyTracker::EdgeDescriptorList EdgeList;
BgpConfigListenerTest()
: db_(TaskScheduler::GetInstance()->GetTaskId("db::IFMapTable")),
server_(&evm_), tracker_(NULL), parser_(&db_) {
config_manager_ = static_cast<BgpIfmapConfigManager *>(
server_.config_manager());
listener_ = new BgpConfigListenerMock(config_manager_);
config_manager_->listener_.reset(listener_);
change_list_ = &listener_->change_list_;
}
virtual void SetUp() {
IFMapLinkTable_Init(&db_, &graph_);
vnc_cfg_Server_ModuleInit(&db_, &graph_);
bgp_schema_Server_ModuleInit(&db_, &graph_);
config_manager_->Initialize(&db_, &graph_, "local");
tracker_ = listener_->tracker_.get();
}
virtual void TearDown() {
server_.Shutdown();
task_util::WaitForIdle();
db_util::Clear(&db_);
}
void PauseChangeListPropagation() {
task_util::WaitForIdle();
listener_->set_no_processing();
}
void PerformChangeListPropagation() {
task_util::WaitForIdle();
ConcurrencyScope scope("bgp::Config");
ChangeList change_list;
listener_->BgpConfigListener::GetChangeList(&change_list);
change_list.swap(*change_list_);
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
}
void ResumeChangeListPropagation() {
task_util::WaitForIdle();
ConcurrencyScope scope("db::IFMapTable");
listener_->clear_no_processing();
listener_->manager_->OnChange();
task_util::WaitForIdle();
}
size_t GetChangeListCount() {
return change_list_->size();
}
size_t GetChangeListCount(const string &id_type) {
size_t count = 0;
for (ChangeList::const_iterator it =
change_list_->begin(); it != change_list_->end(); ++it) {
if (it->id_type == id_type)
count++;
}
return count;
}
size_t GetNodeListCount() {
return tracker_->node_list().size();
}
size_t GetNodeListCount(const string &id_type) {
size_t count = 0;
for (NodeList::const_iterator it = tracker_->node_list().begin();
it != tracker_->node_list().end(); ++it) {
if (it->first == id_type)
count++;
}
return count;
}
size_t GetEdgeListCount() {
return tracker_->edge_list().size();
}
size_t GetEdgeListCount(const string &metadata) {
size_t count = 0;
for (EdgeList::const_iterator it = tracker_->edge_list().begin();
it != tracker_->edge_list().end(); ++it) {
if (it->metadata == metadata)
count++;
}
return count;
}
EventManager evm_;
DB db_;
DBGraph graph_;
BgpServer server_;
BgpConfigListenerMock *listener_;
IFMapDependencyTracker *tracker_;
ChangeList *change_list_;
BgpIfmapConfigManager *config_manager_;
BgpConfigParser parser_;
};
//
// Verify test infrastructure which pauses, performs and resumes propagation
// to the change list.
//
TEST_F(BgpConfigListenerTest, Basic) {
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
PauseChangeListPropagation();
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_NE(0, GetNodeListCount());
TASK_UTIL_EXPECT_NE(0, GetEdgeListCount());
TASK_UTIL_EXPECT_NE(0, GetChangeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
TASK_UTIL_EXPECT_NE(0, GetChangeListCount());
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Node event for an object in table that is not relevant to Bgp is ignored.
// Even though the IFMapNode is updated, it doesn't get added to the change
// list or the node list.
//
TEST_F(BgpConfigListenerTest, IrrelevantNodeEvent) {
ifmap_test_util::IFMapMsgNodeAdd(&db_, "route-target", "target:1:1");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
ifmap_test_util::IFMapNodeNotify(&db_, "route-target", "target:1:1");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Multiple node events for same node should cause it to get on the change
// list multiple times.
//
TEST_F(BgpConfigListenerTest, DuplicateNodeEvent) {
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
string id_name = string(BgpConfigManager::kMasterInstance) + ":local";
ifmap_test_util::IFMapNodeNotify(&db_, "bgp-router", id_name);
task_util::WaitForIdle();
ifmap_test_util::IFMapNodeNotify(&db_, "bgp-router", id_name);
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(2, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(2, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(5, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(2, GetChangeListCount("bgp-router"));
TASK_UTIL_EXPECT_EQ(3, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Delete event for a node for which the configuration keeps no state. This
// should get filtered in the BgpConfigListener itself. Thus the node will
// not get on the change list or the node list.
//
TEST_F(BgpConfigListenerTest, DeletedNodeEvent1) {
ifmap_test_util::IFMapMsgNodeAdd(&db_, "virtual-network", "red");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
ifmap_test_util::IFMapMsgNodeDelete(&db_, "virtual-network", "red");
task_util::WaitForIdle();
IFMapNode *node =
ifmap_test_util::IFMapNodeLookup(&db_, "virtual-network", "red");
TASK_UTIL_EXPECT_TRUE(node == NULL);
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Delete event for a node for which the configuration does keeps state.
// Thus the node will get on the change list but not on the node list.
//
TEST_F(BgpConfigListenerTest, DeletedNodeEvent2) {
string content_a = ReadFile("controller/src/bgp/testdata/config_listener_test_6a.xml");
EXPECT_TRUE(parser_.Parse(content_a));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
string content_b = ReadFile("controller/src/bgp/testdata/config_listener_test_6b.xml");
EXPECT_TRUE(parser_.Parse(content_b));
task_util::WaitForIdle();
IFMapNode *node =
ifmap_test_util::IFMapNodeLookup(&db_, "routing-instance", "red");
TASK_UTIL_EXPECT_TRUE(node->IsDeleted());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Delete event for a node which is already on the change list and the node
// list. The node should be marked deleted when propagating the node list
// and hence will be ignored.
//
TEST_F(BgpConfigListenerTest, DeletedNodeEvent3) {
ifmap_test_util::IFMapMsgNodeAdd(&db_, "virtual-network", "red");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
ifmap_test_util::IFMapNodeNotify(&db_, "virtual-network", "red");
task_util::WaitForIdle();
ifmap_test_util::IFMapMsgNodeDelete(&db_, "virtual-network", "red");
task_util::WaitForIdle();
IFMapNode *node =
ifmap_test_util::IFMapNodeLookup(&db_, "virtual-network", "red");
TASK_UTIL_EXPECT_TRUE(node->IsDeleted());
TASK_UTIL_EXPECT_EQ(2, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(2, GetChangeListCount());
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for an uninteresting link should not cause any edges to be
// added to the edge list.
//
TEST_F(BgpConfigListenerTest, UninterestingLinkEvent) {
ifmap_test_util::IFMapMsgLink(&db_, "domain", "default-domain",
"project", "default-project", "domain-project");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
ifmap_test_util::IFMapLinkNotify(&db_, &graph_, "domain-project",
"domain", "default-domain", "project", "default-project");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Multiple link events for the same link should cause the component edges
// to get added to the edge list multiple times per current implementation.
//
TEST_F(BgpConfigListenerTest, DuplicateLinkEvent) {
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_12.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify virtual-network-routing-instance link 3 times.
PauseChangeListPropagation();
for (int idx = 0; idx < 3; ++idx) {
ifmap_test_util::IFMapLinkNotify(&db_, &graph_, "virtual-network-routing-instance",
"virtual-network", "red-vn", "routing-instance", "red");
task_util::WaitForIdle();
}
// Edge list should have 3 entries. Note that virtual-network doesn't have
// a RectionMap entry for virtual-network-routing-instance.
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(3, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for a link whose associated node(s) have already been deleted.
// The associated edge(s) should not get on the edge list.
//
// In this case, the routing-instance is deleted so the edge with metadata
// virtual-network-routing-instance is ignored. The reverse edge from the
// virtual-network is not in the reaction-map anyway.
//
TEST_F(BgpConfigListenerTest, DeletedLinkEvent1) {
string content_a = ReadFile("controller/src/bgp/testdata/config_listener_test_13a.xml");
EXPECT_TRUE(parser_.Parse(content_a));
ifmap_test_util::IFMapMsgLink(&db_, "virtual-network", "red-vn",
"routing-instance", "red", "virtual-network-routing-instance");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
string content_b = ReadFile("controller/src/bgp/testdata/config_listener_test_13b.xml");
EXPECT_TRUE(parser_.Parse(content_b));
ifmap_test_util::IFMapMsgUnlink(&db_, "virtual-network", "red-vn",
"routing-instance", "red", "virtual-network-routing-instance");
task_util::WaitForIdle();
IFMapNode *node =
ifmap_test_util::IFMapNodeLookup(&db_, "routing-instance", "red");
TASK_UTIL_EXPECT_TRUE(node->IsDeleted());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance"));
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for a link whose associated node(s) have already been deleted
// and where the associated edge(s) are already on the edge list. When the
// edge list is processed, they won't be propagated since the associated
// nodes are marked as deleted.
//
// In this case, the routing-instance is deleted so the edge with metadata
// virtual-network-routing-instance is ignored during propagation. The reverse
// edge from the virtual-network is not in the reaction-map and so will not
// be in the edge list to begin with.
//
TEST_F(BgpConfigListenerTest, DeletedLinkEvent2) {
string content_a = ReadFile("controller/src/bgp/testdata/config_listener_test_13a.xml");
EXPECT_TRUE(parser_.Parse(content_a));
ifmap_test_util::IFMapMsgLink(&db_, "virtual-network", "red-vn",
"routing-instance", "red", "virtual-network-routing-instance");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
PauseChangeListPropagation();
ifmap_test_util::IFMapLinkNotify(&db_, &graph_, "virtual-network-routing-instance",
"virtual-network", "red-vn", "routing-instance", "red");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(1, GetEdgeListCount());
string content_b = ReadFile("controller/src/bgp/testdata/config_listener_test_13b.xml");
EXPECT_TRUE(parser_.Parse(content_b));
ifmap_test_util::IFMapMsgUnlink(&db_, "virtual-network", "red-vn",
"routing-instance", "red", "virtual-network-routing-instance");
task_util::WaitForIdle();
IFMapNode *node =
ifmap_test_util::IFMapNodeLookup(&db_, "routing-instance", "red");
TASK_UTIL_EXPECT_TRUE(node->IsDeleted());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance"));
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(1, GetEdgeListCount());
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Node event for a bgp-peering object that involves the local router.
//
TEST_F(BgpConfigListenerTest, BgpPeeringChange1) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify bgp-peering node between local and remote1.
PauseChangeListPropagation();
string id_first = string(BgpConfigManager::kMasterInstance) + ":local";
string id_second = string(BgpConfigManager::kMasterInstance) + ":remote1";
string id_name = string("attr") + "(" + id_first + "," + id_second + ")";
ifmap_test_util::IFMapNodeNotify(&db_, "bgp-peering", id_name);
task_util::WaitForIdle();
// The bgp-peering should be on the change list but not on the node list
// since there's no entry for self in the reaction map.
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
// Perform propagation and verify change list.
// Nothing else should get added since the node and edge lists are empty.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Node event for a bgp-peering object that does not involve the local router.
//
TEST_F(BgpConfigListenerTest, BgpPeeringChange2) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify bgp-peering node between remote2 and remote3.
PauseChangeListPropagation();
string id_first = string(BgpConfigManager::kMasterInstance) + ":remote2";
string id_second = string(BgpConfigManager::kMasterInstance) + ":remote3";
string id_name = string("attr") + "(" + id_first + "," + id_second + ")";
ifmap_test_util::IFMapNodeNotify(&db_, "bgp-peering", id_name);
task_util::WaitForIdle();
// The bgp-peering should be on the change list but not on the node list
// since there's no entry for self in the reaction map.
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
// Perform propagation and verify change list.
// Nothing else should get added since the node and edge lists are empty.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for bgp-peering link of a bgp-peering object that involves the
// local router.
//
TEST_F(BgpConfigListenerTest, BgpPeeringBgpPeeringChange1) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify bgp-peering link between local and remote1.
PauseChangeListPropagation();
string id_first = string(BgpConfigManager::kMasterInstance) + ":local";
string id_second = string(BgpConfigManager::kMasterInstance) + ":remote1";
string id_name = string("attr") + "(" + id_first + "," + id_second + ")";
ifmap_test_util::IFMapLinkNotify(&db_, &graph_, "bgp-peering",
"bgp-peering", id_name, "bgp-router", id_first);
task_util::WaitForIdle();
// Only one edge should get added to the edge list.
// This will be the bgp-peering edge from the bgp-peering object.
// The bgp-peering edge from the bgp-router is not interesting since the
// reaction map for bgp-router doesn't have an entry for bgp-peering.
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(1, GetEdgeListCount());
// Perform propagation and verify change list.
// The bgp-peering should be on the change list because the propagate
// list contains self.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for a bgp-peering link of a bgp-peering object that does not
// involve the local router.
//
TEST_F(BgpConfigListenerTest, BgpPeeringBgpPeeringChange2) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify bgp-peering link between remote1 and remote2.
PauseChangeListPropagation();
string id_first = string(BgpConfigManager::kMasterInstance) + ":remote1";
string id_second = string(BgpConfigManager::kMasterInstance) + ":remote2";
string id_name = string("attr") + "(" + id_first + "," + id_second + ")";
ifmap_test_util::IFMapLinkNotify(&db_, &graph_, "bgp-peering",
"bgp-peering", id_name, "bgp-router", id_first);
task_util::WaitForIdle();
// Only one edge should get added to the edge list.
// This will be the bgp-peering edge from the bgp-peering object.
// The bgp-peering edge from the bgp-router is not interesting since the
// reaction map for bgp-router doesn't have an entry for bgp-peering.
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(1, GetEdgeListCount());
// Perform propagation and verify change list.
// The bgp-peering should be on the change list because the propagate
// list contains self.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for an uninteresting link of the bgp-peering object. There's
// no such links since the bgp-peering object is a middle node that has no
// links other than bgp-peering.
//
TEST_F(BgpConfigListenerTest, BgpPeeringUninterestingLinkChange) {
}
//
// Node event for the local bgp-router object.
//
TEST_F(BgpConfigListenerTest, BgpRouterChange1) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify bgp-router local.
PauseChangeListPropagation();
string id_name = string(BgpConfigManager::kMasterInstance) + ":local";
ifmap_test_util::IFMapNodeNotify(&db_, "bgp-router", id_name);
// The bgp-router should be on the change list and on the node list
// since there's an entry for self in the reaction map.
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
// Perform propagation and verify change list.
// The 3 bgp-peerings should be on the change list because the propagate
// list for bgp-router contains bgp-peering.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(4, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("bgp-router"));
TASK_UTIL_EXPECT_EQ(3, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Node event for a remote bgp-router object.
//
TEST_F(BgpConfigListenerTest, BgpRouterChange2) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify bgp-router remote1.
PauseChangeListPropagation();
string id_name = string(BgpConfigManager::kMasterInstance) + ":remote1";
ifmap_test_util::IFMapNodeNotify(&db_, "bgp-router", id_name);
// The bgp-router should be on the change list and on the node list
// since there's an entry for self in the reaction map.
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
// Perform propagation and verify change list.
// The 3 bgp-peerings should be on the change list because the propagate
// list for bgp-router contains bgp-peering.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(4, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("bgp-router"));
TASK_UTIL_EXPECT_EQ(3, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for the instance-bgp-router link of a bgp-router object.
//
TEST_F(BgpConfigListenerTest, BgpRouterInstanceLinkChange) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
string instance(BgpConfigManager::kMasterInstance);
string router = instance + ":local";
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", instance,
"bgp-router", router, "instance-bgp-router");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify instance-bgp-router link between bgp-router
// and routing-instance.
PauseChangeListPropagation();
ifmap_test_util::IFMapLinkNotify(&db_, &graph_, "instance-bgp-router",
"bgp-router", router, "routing-instance", instance);
task_util::WaitForIdle();
// Only one edge should get added to the edge list.
// This is the instance-bgp-router edge from bgp-router.
// The instance-bgp-router edge from the routing-instance is not
// interesting since the reaction map for routing-instance doesn't
// have an entry for instance-bgp-router.
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(1, GetEdgeListCount());
// Perform propagation and verify change list.
// The bgp-routers are on the change list since the propagate list for
// instance-bgp-router in bgp-router contains bgp-peering.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(3, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(3, GetChangeListCount("bgp-peering"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Node event for a routing-instance object without any connections.
//
TEST_F(BgpConfigListenerTest, RoutingInstanceChange1) {
// Initialize config with local router and 3 remote routers.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_1.xml");
EXPECT_TRUE(parser_.Parse(content));
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify routing-instance master.
PauseChangeListPropagation();
string id_name(BgpConfigManager::kMasterInstance);
ifmap_test_util::IFMapNodeNotify(&db_, "routing-instance", id_name);
// The routing-instance should be on the change list but not on the node
// list since there's no entry for self in the reaction map.
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
// Perform propagation and verify change list.
// Nothing else should get added since the node and edge lists are empty.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Node event for a routing-instance object with connections.
//
TEST_F(BgpConfigListenerTest, RoutingInstanceChange2) {
// Initialize config with 3 routing-instances - red, blue and green.
// Add connections between (red, blue) and (red, green).
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_4.xml");
EXPECT_TRUE(parser_.Parse(content));
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"routing-instance", "blue", "connection");
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"routing-instance", "green", "connection");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, notify routing-instance red.
PauseChangeListPropagation();
string id_name("red");
ifmap_test_util::IFMapNodeNotify(&db_, "routing-instance", id_name);
// The routing-instance should be on the change list but not on the node
// list since there's no entry for self in the reaction map.
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(0, GetEdgeListCount());
// Perform propagation and verify change list.
// Nothing else should get added since the node and edge lists are empty.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(1, GetChangeListCount("routing-instance"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for a instance-target link of a routing-instance object. The
// routing-instance is connected to all other routing-instances.
//
TEST_F(BgpConfigListenerTest, RoutingInstanceTargetChange1) {
// Initialize config with 3 routing-instances - red, blue and green.
// Add connections between (red, blue) and (red, green).
// Also add a route-target target:1:100.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_4.xml");
EXPECT_TRUE(parser_.Parse(content));
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"routing-instance", "blue", "connection");
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"routing-instance", "green", "connection");
ifmap_test_util::IFMapMsgNodeAdd(&db_, "route-target", "target:1:100");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, add link between routing-instance red and the
// route-target target:1:100.
//
// Note that instance-target is a link with attributes so a middle node
// called instance-target will get created. There will be instance-target
// links from the instance-target to routing-instance and route-target.
PauseChangeListPropagation();
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"route-target", "target:1:100", "instance-target");
task_util::WaitForIdle();
// Only one edge should get added to the edge list.
// This will be the instance-target edge from the routing-instance object
// as the routing-instance reaction map has an entry for instance-target.
//
// The instance-target node is not interesting since event policy doesn't
// have an entry for instance-target.
// The instance-target edges from the instance-target are not interesting
// as the event policy doesn't have an entry for instance-target.
// The instance-target edge from the route-target is not interesting as
// the event policy doesn't have an entry for route-target.
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(1, GetEdgeListCount());
// Perform propagation and verify change list.
// All three routing-instances will be on the change list because the
// routing-instance propagate list for instance-target has self and
// connection. The red instance gets added because of self and the other
// instances get added because of further propagation via the connection.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(4, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(4, GetChangeListCount("routing-instance"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for a instance-target link of a routing-instance object. The
// routing-instance is connected to some but not all other routing-instances.
//
TEST_F(BgpConfigListenerTest, RoutingInstanceTargetChange2) {
// Initialize config with 3 routing-instances - red, blue and green.
// Add connection between (red, blue).
// Also add a route-target target:1:100.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_4.xml");
EXPECT_TRUE(parser_.Parse(content));
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"routing-instance", "blue", "connection");
ifmap_test_util::IFMapMsgNodeAdd(&db_, "route-target", "target:1:100");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, add link between routing-instance red and the
// route-target target:1:100.
//
// Note that instance-target is a link with attributes so a middle node
// called instance-target will get created. There will be instance-target
// links from the instance-target to routing-instance and route-target.
PauseChangeListPropagation();
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"route-target", "target:1:100", "instance-target");
task_util::WaitForIdle();
// Only one edge should get added to the edge list.
// This will be the instance-target edge from the routing-instance object
// as the routing-instance reaction map has an entry for instance-target.
//
// The instance-target node is not interesting since event policy doesn't
// have an entry for instance-target.
// The instance-target edges from the instance-target are not interesting
// as the event policy doesn't have an entry for instance-target.
// The instance-target edge from the route-target is not interesting as
// the event policy doesn't have an entry for route-target.
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(0, GetNodeListCount());
TASK_UTIL_EXPECT_EQ(1, GetEdgeListCount());
// Perform propagation and verify change list.
// The red and blue routing-instances will be on the change list since the
// routing-instance propagate list for instance-target has self and
// connection. The red instance gets added because of self and the blue
// instance gets added because of further propagation via the connection.
// The green instance doesn't get added to the change list.
PerformChangeListPropagation();
TASK_UTIL_EXPECT_EQ(3, GetChangeListCount());
TASK_UTIL_EXPECT_EQ(3, GetChangeListCount("routing-instance"));
ResumeChangeListPropagation();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
}
//
// Link event for a instance-target link of a routing-instance object. The
// routing-instance is connected to another routing-instance which in turn
// is connected to a third routing-instance.
//
// Intent is to verify that we do no propagate the change transitively to
// the third routing-instance.
//
TEST_F(BgpConfigListenerTest, RoutingInstanceTargetChange3) {
// Initialize config with 3 routing-instances - red, blue and green.
// Add connections between (red, blue) and (blue, green).
// Also add a route-target target:1:100.
string content = ReadFile("controller/src/bgp/testdata/config_listener_test_4.xml");
EXPECT_TRUE(parser_.Parse(content));
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"routing-instance", "blue", "connection");
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "blue",
"routing-instance", "green", "connection");
ifmap_test_util::IFMapMsgNodeAdd(&db_, "route-target", "target:1:100");
task_util::WaitForIdle();
TASK_UTIL_EXPECT_EQ(0, GetChangeListCount());
// Pause propagation, add link between routing-instance red and the
// route-target target:1:100.
//
// Note that instance-target is a link with attributes so a middle node
// called instance-target will get created. There will be instance-target
// links from the instance-target to routing-instance and route-target.
PauseChangeListPropagation();
ifmap_test_util::IFMapMsgLink(&db_, "routing-instance", "red",
"route-target", "target:1:100", "instance-target");
task_util::WaitForIdle();
// Only one edge should get added to the edge list.
// This will be the instance-target edge from the routing-instance object