-
Notifications
You must be signed in to change notification settings - Fork 390
/
bgp_table_export_test.cc
964 lines (846 loc) · 26.2 KB
/
bgp_table_export_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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_factory.h"
#include "bgp/scheduling_group.h"
#include "bgp/routing-instance/rtarget_group_mgr.h"
#include "bgp/test/bgp_server_test_util.h"
#include "bgp/xmpp_message_builder.h"
#include "control-node/control_node.h"
#include "net/community_type.h"
using namespace std;
//
// OVERVIEW
//
// This is the test suite for BgpTable::Export method for inet and inetvpn
// tables. Since the method is called for one RibOut and one BgpRoute at a
// time, the test also uses a single RibOut and BgpRoute.
//
// The tests are parameterized by the table_name and the type (internal or
// external) of peer that added the best path for the BgpRoute.
//
// TEST STEPS
//
// 1. The Setup method for the parameterized tests extracts the table_name
// and the peer type and then invokes Setup for BgpTableExportTest.
// 2. The Setup method for BgpTableExportTest then creates a BgpTestPeer, a
// suitable BgpAttr based on the peer type and finds the right BgpTable.
// 3. Each test creates a RibOut with the right peer type and AS number.
// 4. The test updates the default BgpAttr created in step 2 by calling the
// SetAttr* methods.
// 5. The Export method is invoked.
// 6. The export result (accept or reject) is verified.
// 7. In cases where the export result is accept, the RibOutAttr is verified
// by calling the VerifyAttr* methods.
//
// CONVENTIONS
//
// 1. If source of the path is eBGP we use an AS Path of 100.
// 2. Our AS number is 200.
// 3. The RibOut peer type is eBGP and the AS number for it is 300.
//
class BgpTestPeer : public IPeer {
public:
BgpTestPeer(bool internal) : internal_(internal) { }
virtual ~BgpTestPeer() { }
virtual std::string ToString() const {
return internal_ ? "TestPeerInt" : "TestPeerExt";
}
virtual std::string ToUVEKey() const {
return internal_ ? "TestPeerInt" : "TestPeerExt";
}
virtual bool SendUpdate(const uint8_t *msg, size_t msgsize) { return true; }
virtual BgpServer *server() { return NULL; }
virtual IPeerClose *peer_close() { return NULL; }
virtual IPeerDebugStats *peer_stats() { return NULL; }
virtual const IPeerDebugStats *peer_stats() const { return NULL; }
virtual bool IsReady() const { return true; }
virtual bool IsXmppPeer() const { return false; }
virtual void Close() { }
BgpProto::BgpPeerType PeerType() const {
return internal_ ? BgpProto::IBGP : BgpProto::EBGP;
}
virtual uint32_t bgp_identifier() const { return 0; }
virtual const std::string GetStateName() const { return ""; }
virtual void UpdateRefCount(int count) const { }
virtual tbb::atomic<int> GetRefCount() const {
tbb::atomic<int> count;
count = 0;
return count;
}
virtual void UpdatePrimaryPathCount(int count) const { }
virtual int GetPrimaryPathCount() const { return 0; }
private:
bool internal_;
};
class BgpRouteMock : public BgpRoute {
public:
virtual std::string ToString() const { return ""; }
virtual int CompareTo(const Route &rhs) const { return 0; }
virtual void SetKey(const DBRequestKey *key) { }
virtual KeyPtr GetDBRequestKey() const { return KeyPtr(NULL); }
virtual bool IsLess(const DBEntry &rhs) const { return true; }
virtual u_int16_t Afi() const { return 0; }
virtual u_int8_t Safi() const { return 0; }
};
class RTargetGroupMgrTest : public RTargetGroupMgr {
public:
RTargetGroupMgrTest(BgpServer *server) : RTargetGroupMgr(server) {
}
virtual void GetRibOutInterestedPeers(RibOut *ribout,
const ExtCommunity *ext_community,
const RibPeerSet &peerset, RibPeerSet *new_peerset) {
*new_peerset = peerset;
}
};
class BgpTableExportTest : public ::testing::Test {
protected:
BgpTableExportTest()
: server_(&evm_, "Local"),
internal_(false),
local_as_is_different_(false),
table_name_(NULL),
table_(NULL),
ribout_(NULL),
result_(false) {
server_.set_autonomous_system(200);
active_peerset_.set(1);
active_peerset_.set(3);
active_peerset_.set(5);
}
virtual void SetUp() {
std::cout << "Table: " << table_name_
<< " Source: " << (internal_ ? "IBGP" : "EBGP")
<< " Local AS: " << (local_as_is_different_ ? 201 : 200)
<< std::endl;
if (local_as_is_different_) {
server_.set_local_autonomous_system(201);
} else {
server_.set_local_autonomous_system(200);
}
CreatePeer();
CreateAttr();
FindTable();
}
virtual void TearDown() {
rt_.RemovePath(peer_.get());
table_->RibOutDelete(ribout_->ExportPolicy());
server_.Shutdown();
task_util::WaitForIdle();
}
as_t AsNumber() {
return server_.autonomous_system();
}
as_t LocalAsNumber() {
return server_.local_autonomous_system();
}
bool PeerIsInternal() {
return internal_;
}
void CreatePeer() {
peer_.reset(new BgpTestPeer(internal_));
}
void CreateAttr() {
BgpAttrSpec attr_spec;
BgpAttrOrigin origin(BgpAttrOrigin::IGP);
attr_spec.push_back(&origin);
BgpAttrNextHop nexthop(0x01010101);
attr_spec.push_back(&nexthop);
AsPathSpec path_spec;
BgpAttrLocalPref local_pref(100);
BgpAttrMultiExitDisc med(100);
if (internal_) {
attr_spec.push_back(&path_spec);
attr_spec.push_back(&local_pref);
attr_spec.push_back(&med);
} else {
AsPathSpec::PathSegment *path_seg = new AsPathSpec::PathSegment;
path_seg->path_segment_type = AsPathSpec::PathSegment::AS_SEQUENCE;
path_seg->path_segment.push_back(100);
path_spec.path_segments.push_back(path_seg);
attr_spec.push_back(&path_spec);
attr_spec.push_back(&med);
}
attr_ptr_ = server_.attr_db()->Locate(attr_spec);
}
void FindTable() {
ASSERT_TRUE(table_name_ != NULL);
DB *db = server_.database();
table_ = static_cast<BgpTable *>(db->FindTable(table_name_));
ASSERT_TRUE(table_ != NULL);
}
void CreateRibOut(BgpProto::BgpPeerType type,
RibExportPolicy::Encoding encoding, as_t as_number = 0) {
RibExportPolicy policy(type, encoding, as_number, -1, 0);
ribout_ = table_->RibOutLocate(&mgr_, policy);
}
void SetAttrAsPath(as_t as_number) {
BgpAttr *attr = new BgpAttr(*attr_ptr_);
const AsPathSpec &path_spec = attr_ptr_->as_path()->path();
AsPathSpec *path_spec_ptr = path_spec.Add(as_number);
attr->set_as_path(path_spec_ptr);
delete path_spec_ptr;
attr_ptr_ = server_.attr_db()->Locate(attr);
}
void ResetAttrAsPath() {
BgpAttr *attr = new BgpAttr(*attr_ptr_);
attr->set_as_path(NULL);
attr_ptr_ = server_.attr_db()->Locate(attr);
}
void SetAttrCommunity(uint32_t comm_value) {
BgpAttr *attr = new BgpAttr(*attr_ptr_);
CommunitySpec community;
community.communities.push_back(comm_value);
attr->set_community(&community);
attr_ptr_ = server_.attr_db()->Locate(attr);
}
void SetAttrExtCommunity(uint32_t identifier) {
BgpAttr *attr = new BgpAttr(*attr_ptr_);
ostringstream oss;
oss << "target:" << AsNumber() << ":" << identifier;
RouteTarget rt(RouteTarget::FromString(oss.str()));
ExtCommunitySpec extcomm;
extcomm.communities.push_back(
get_value(rt.GetExtCommunity().begin(), 8));
attr->set_ext_community(&extcomm);
attr_ptr_ = server_.attr_db()->Locate(attr);
}
void SetAttrLocalPref(uint32_t local_pref) {
BgpAttr *attr = new BgpAttr(*attr_ptr_);
attr->set_local_pref(local_pref);
attr_ptr_ = server_.attr_db()->Locate(attr);
}
void SetAttrMed(uint32_t med) {
BgpAttr *attr = new BgpAttr(*attr_ptr_);
attr->set_med(med);
attr_ptr_ = server_.attr_db()->Locate(attr);
}
void AddPath() {
BgpPath *path =
new BgpPath(peer_.get(), BgpPath::BGP_XMPP, attr_ptr_, 0, 0);
rt_.InsertPath(path);
}
void AddInfeasiblePath() {
BgpPath *path =
new BgpPath(peer_.get(), BgpPath::BGP_XMPP, attr_ptr_,
BgpPath::AsPathLooped, 0);
rt_.InsertPath(path);
}
void RunExport() {
result_ = table_->Export(ribout_, &rt_, active_peerset_, uinfo_slist_);
}
void VerifyExportReject() {
EXPECT_TRUE(false == result_);
EXPECT_EQ(0, uinfo_slist_->size());
}
void VerifyExportAccept() {
EXPECT_TRUE(true == result_);
EXPECT_EQ(1, uinfo_slist_->size());
const UpdateInfo &uinfo = uinfo_slist_->front();
EXPECT_EQ(active_peerset_, uinfo.target);
}
void VerifyAttrNoChange() {
const UpdateInfo &uinfo = uinfo_slist_->front();
const BgpAttr *attr = uinfo.roattr.attr();
EXPECT_EQ(attr_ptr_.get(), attr);
}
void VerifyAttrLocalPref(uint32_t local_pref) {
const UpdateInfo &uinfo = uinfo_slist_->front();
const BgpAttr *attr = uinfo.roattr.attr();
EXPECT_EQ(local_pref, attr->local_pref());
}
void VerifyAttrMed(uint32_t med) {
const UpdateInfo &uinfo = uinfo_slist_->front();
const BgpAttr *attr = uinfo.roattr.attr();
EXPECT_EQ(med, attr->med());
}
void VerifyAttrAsPrepend() {
const UpdateInfo &uinfo = uinfo_slist_->front();
const BgpAttr *attr = uinfo.roattr.attr();
const AsPath *as_path = attr->as_path();
as_t my_as = server_.autonomous_system();
as_t my_local_as = server_.local_autonomous_system();
EXPECT_TRUE(as_path->path().AsLeftMostMatch(my_local_as));
if (my_as != my_local_as)
EXPECT_FALSE(as_path->path().AsLeftMostMatch(my_as));
}
void VerifyAttrNoAsPrepend() {
const UpdateInfo &uinfo = uinfo_slist_->front();
const BgpAttr *attr = uinfo.roattr.attr();
const AsPath *as_path = attr->as_path();
as_t my_as = server_.autonomous_system();
as_t my_local_as = server_.local_autonomous_system();
EXPECT_FALSE(as_path->path().AsLeftMostMatch(my_as));
EXPECT_FALSE(as_path->path().AsLeftMostMatch(my_local_as));
}
void VerifyAttrExtCommunity(bool is_null) {
const UpdateInfo &uinfo = uinfo_slist_->front();
const BgpAttr *attr = uinfo.roattr.attr();
EXPECT_EQ(is_null, attr->ext_community() == NULL);
}
EventManager evm_;
BgpServerTest server_;
SchedulingGroupManager mgr_;
bool internal_;
bool local_as_is_different_;
const char *table_name_;
BgpTable *table_;
RibOut *ribout_;
std::auto_ptr<BgpTestPeer> peer_;
RibPeerSet active_peerset_;
BgpRouteMock rt_;
BgpAttrPtr attr_ptr_;
UpdateInfoSList uinfo_slist_;
bool result_;
};
// Parameterize table name, peer type and local AS.
typedef std::tr1::tuple<const char *, bool, bool> TestParams1;
class BgpTableExportParamTest1 :
public BgpTableExportTest,
public ::testing::WithParamInterface<TestParams1> {
virtual void SetUp() {
table_name_ = std::tr1::get<0>(GetParam());
internal_ = std::tr1::get<1>(GetParam());
local_as_is_different_ = std::tr1::get<2>(GetParam());
BgpTableExportTest::SetUp();
}
virtual void TearDown() {
BgpTableExportTest::TearDown();
}
};
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: iBGP
// Intent: Route without a best path is rejected.
//
TEST_P(BgpTableExportParamTest1, NoBestPath) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
RunExport();
VerifyExportReject();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: iBGP
// Intent: Route with an infeasible best path is rejected.
//
TEST_P(BgpTableExportParamTest1, NoFeasiblePath) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
AddInfeasiblePath();
RunExport();
VerifyExportReject();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Route with NoAdvertise community is rejected for eBGP.
//
TEST_P(BgpTableExportParamTest1, CommunityNoAdvertise1) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrCommunity(CommunityType::NoAdvertise);
AddPath();
RunExport();
VerifyExportReject();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: iBGP
// Intent: Route with NoAdvertise community is rejected for iBGP.
//
TEST_P(BgpTableExportParamTest1, CommunityNoAdvertise2) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrCommunity(CommunityType::NoAdvertise);
AddPath();
RunExport();
VerifyExportReject();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Route with NoExport community is rejected for eBGP.
//
TEST_P(BgpTableExportParamTest1, CommunityNoExport) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrCommunity(CommunityType::NoExport);
AddPath();
RunExport();
VerifyExportReject();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Route with NoExportSubconfed community is rejected for eBGP.
//
TEST_P(BgpTableExportParamTest1, CommunityNoExportSubconfed) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrCommunity(CommunityType::NoExportSubconfed);
AddPath();
RunExport();
VerifyExportReject();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: LocalPref is cleared for eBGP.
//
TEST_P(BgpTableExportParamTest1, EBgpNoLocalPref) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Our AS is prepended to AsPath for eBGP.
// Note: Current AsPath is non-NULL.
//
TEST_P(BgpTableExportParamTest1, EBgpAsPrepend1) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrAsPrepend();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Our AS is prepended to AsPath for eBGP.
// Note: Current AsPath is NULL.
//
TEST_P(BgpTableExportParamTest1, EBgpAsPrepend2) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
ResetAttrAsPath();
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrAsPrepend();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Route with AsPath loop is rejected.
//
TEST_P(BgpTableExportParamTest1, AsPathLoop) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrAsPath(300);
AddPath();
RunExport();
VerifyExportReject();
}
INSTANTIATE_TEST_CASE_P(Instance, BgpTableExportParamTest1,
::testing::Combine(
::testing::Values("inet.0", "bgp.l3vpn.0"),
::testing::Bool(),
::testing::Bool()));
// Parameterize table name and fix peer type to internal.
class BgpTableExportParamTest2 :
public BgpTableExportTest,
public ::testing::WithParamInterface<const char *> {
virtual void SetUp() {
table_name_ = GetParam();
internal_ = true;
BgpTableExportTest::SetUp();
}
virtual void TearDown() {
BgpTableExportTest::TearDown();
}
};
//
// Table : inet.0, bgp.l3vpn.0
// Source: iBGP
// RibOut: iBGP
// Intent: Split Horizon check rejects export.
//
TEST_P(BgpTableExportParamTest2, IBgpSplitHorizon) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
AddPath();
RunExport();
VerifyExportReject();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: iBGP (effectively XMPP since AsPath is NULL)
// RibOut: eBGP
// Intent: Med is retained if AsPath is NULL.
//
TEST_P(BgpTableExportParamTest2, EBgpRetainMed1) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
ResetAttrAsPath();
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrMed(100);
VerifyAttrAsPrepend();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: iBGP
// RibOut: eBGP
// Intent: Med is retained if AsPath is non-NULL but empty.
//
TEST_P(BgpTableExportParamTest2, EBgpRetainMed2) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrMed(100);
VerifyAttrAsPrepend();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: iBGP
// RibOut: eBGP
// Intent: Med is not retained since AsPath is non-empty.
//
TEST_P(BgpTableExportParamTest2, EBgpNoRetainMed) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrAsPath(100);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrMed(0);
VerifyAttrAsPrepend();
}
INSTANTIATE_TEST_CASE_P(Instance, BgpTableExportParamTest2,
::testing::Values("inet.0", "bgp.l3vpn.0"));
// Fix peer type to external and parameterize table name and local AS.
typedef std::tr1::tuple<const char *, bool> TestParams3;
class BgpTableExportParamTest3 :
public BgpTableExportTest,
public ::testing::WithParamInterface<TestParams3> {
virtual void SetUp() {
table_name_ = std::tr1::get<0>(GetParam());
internal_ = false;
local_as_is_different_ = std::tr1::get<1>(GetParam());
BgpTableExportTest::SetUp();
}
virtual void TearDown() {
BgpTableExportTest::TearDown();
}
};
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: iBGP
// Intent: Route with NoExport community is accepted for iBGP.
//
TEST_P(BgpTableExportParamTest3, CommunityNoExport) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrCommunity(CommunityType::NoExport);
AddPath();
RunExport();
VerifyExportAccept();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: iBGP
// Intent: Route with NoExportSubconfed community is accepted for iBGP.
//
TEST_P(BgpTableExportParamTest3, CommunityNoExportSubconfed) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrCommunity(CommunityType::NoExportSubconfed);
AddPath();
RunExport();
VerifyExportAccept();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: iBGP
// Intent: LocalPref should be set to default value.
//
TEST_P(BgpTableExportParamTest3, IBgpLocalPref) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
AddPath();
RunExport();
VerifyAttrLocalPref(100);
VerifyAttrMed(100);
VerifyExportAccept();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: iBGP
// Intent: Our AS is not prepended when sending to iBGP.
// Note: Current AsPath is non-NULL.
//
TEST_P(BgpTableExportParamTest3, IBgpNoAsPrepend1) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(100);
VerifyAttrMed(100);
VerifyAttrNoAsPrepend();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: iBGP
// Intent: Our AS is not prepended when sending to iBGP.
// Note: Current AsPath is NULL.
//
TEST_P(BgpTableExportParamTest3, IBgpNoAsPrepend2) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
ResetAttrAsPath();
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(100);
VerifyAttrMed(100);
VerifyAttrNoAsPrepend();
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: iBGP
// Intent: LocalPref should not be overwritten if it's already set.
//
TEST_P(BgpTableExportParamTest3, IBgpNoOverwriteLocalPref) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrLocalPref(50);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(50);
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: iBGP
// Intent: Med should not be overwritten.
//
TEST_P(BgpTableExportParamTest3, IBgpNoOverwriteMed) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrMed(100);
}
//
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP
// RibOut: eBGP
// Intent: Med is not retained since AsPath is non-empty.
//
TEST_P(BgpTableExportParamTest3, EBgpNoRetainMed) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrMed(0);
VerifyAttrAsPrepend();
}
INSTANTIATE_TEST_CASE_P(Instance, BgpTableExportParamTest3,
::testing::Combine(
::testing::Values("inet.0", "bgp.l3vpn.0"),
::testing::Bool()));
// Fix table name to inet.0 and parameterize peer type and local AS.
typedef std::tr1::tuple<bool, bool> TestParams4a;
class BgpTableExportParamTest4a :
public BgpTableExportTest,
public ::testing::WithParamInterface<TestParams4a> {
virtual void SetUp() {
table_name_ = "inet.0";
internal_ = std::tr1::get<0>(GetParam());
local_as_is_different_ = std::tr1::get<1>(GetParam());
BgpTableExportTest::SetUp();
}
virtual void TearDown() {
BgpTableExportTest::TearDown();
}
};
//
// Table : inet.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Extended communities are stripped on export.
//
TEST_P(BgpTableExportParamTest4a, StripExtendedCommunity1) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrExtCommunity(12345);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrExtCommunity(true);
}
//
// Table : inet.0
// Source: eBGP, iBGP
// RibOut: iBGP
// Intent: Extended communities are stripped on export.
//
TEST_P(BgpTableExportParamTest4a, StripExtendedCommunity2) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrExtCommunity(12345);
AddPath();
RunExport();
if (PeerIsInternal()) {
VerifyExportReject();
} else {
VerifyExportAccept();
VerifyAttrExtCommunity(true);
}
}
INSTANTIATE_TEST_CASE_P(Instance, BgpTableExportParamTest4a,
::testing::Combine(
::testing::Bool(),
::testing::Bool()));
// Parameterize peer type and fix table name to inet.0.
// RibOut encoding is XMPP.
class BgpTableExportParamTest4b :
public BgpTableExportTest,
public ::testing::WithParamInterface<bool> {
virtual void SetUp() {
table_name_ = "inet.0";
internal_ = GetParam();
BgpTableExportTest::SetUp();
CreateRibOut(BgpProto::XMPP, RibExportPolicy::XMPP);
}
virtual void TearDown() {
BgpTableExportTest::TearDown();
}
};
//
// Table : inet.0
// Source: eBGP, iBGP
// RibOut: XMPP
// Intent: Attribute manipulations are skipped if RibOut is XMPP.
//
TEST_P(BgpTableExportParamTest4b, AttrNoChange) {
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrNoChange();
}
//
// Table : inet.0
// Source: eBGP, iBGP
// RibOut: XMPP
// Intent: NoAdvertise community is ignored if RibOut is XMPP.
//
TEST_P(BgpTableExportParamTest4b, CommunityNoAdvertise) {
SetAttrCommunity(CommunityType::NoAdvertise);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrNoChange();
}
//
// Table : inet.0
// Source: eBGP, iBGP
// RibOut: XMPP
// Intent: NoExport community is ignored if RibOut is XMPP.
//
TEST_P(BgpTableExportParamTest4b, CommunityNoExport) {
SetAttrCommunity(CommunityType::NoExport);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrNoChange();
}
//
// Table : inet.0
// Source: eBGP, iBGP
// RibOut: XMPP
// Intent: NoExportSubconfed community is ignored if RibOut is XMPP.
//
TEST_P(BgpTableExportParamTest4b, CommunityNoExportSubconfed) {
SetAttrCommunity(CommunityType::NoExportSubconfed);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrNoChange();
}
INSTANTIATE_TEST_CASE_P(Instance, BgpTableExportParamTest4b,
::testing::Bool());
// Fix table name to bgp.l3vpn.0 and parameterize peer type and local AS.
typedef std::tr1::tuple<bool, bool> TestParams5;
class BgpTableExportParamTest5 :
public BgpTableExportTest,
public ::testing::WithParamInterface<TestParams5> {
virtual void SetUp() {
table_name_ = "bgp.l3vpn.0";
internal_ = std::tr1::get<0>(GetParam());
local_as_is_different_ = std::tr1::get<1>(GetParam());
BgpTableExportTest::SetUp();
}
virtual void TearDown() {
BgpTableExportTest::TearDown();
}
};
//
// Table : bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: Extended communities are not stripped on export.
//
TEST_P(BgpTableExportParamTest5, NoStripExtendedCommunity1) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrExtCommunity(12345);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrExtCommunity(false);
}
//
// Table : bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: iBGP
// Intent: Extended communities are not stripped on export.
//
TEST_P(BgpTableExportParamTest5, NoStripExtendedCommunity2) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrExtCommunity(12345);
AddPath();
RunExport();
if (PeerIsInternal()) {
VerifyExportReject();
} else {
VerifyExportAccept();
VerifyAttrExtCommunity(false);
}
}
INSTANTIATE_TEST_CASE_P(Instance, BgpTableExportParamTest5,
::testing::Combine(
::testing::Bool(),
::testing::Bool()));
static void SetUp() {
bgp_log_test::init();
ControlNode::SetDefaultSchedulingPolicy();
BgpServerTest::GlobalSetUp();
BgpObjectFactory::Register<RTargetGroupMgr>(
boost::factory<RTargetGroupMgrTest *>());
BgpObjectFactory::Register<BgpXmppMessageBuilder>(
boost::factory<BgpXmppMessageBuilder *>());
}
static void TearDown() {
task_util::WaitForIdle();
TaskScheduler *scheduler = TaskScheduler::GetInstance();
scheduler->Terminate();
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
SetUp();
int result = RUN_ALL_TESTS();
TearDown();
return result;
}