Skip to content

Commit

Permalink
Merge "Retain MED when advertising XMPP originated routes to eBGP pee…
Browse files Browse the repository at this point in the history
…rs" into R2.20
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Oct 20, 2015
2 parents c6e6c43 + f77e848 commit 1dd6a54
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/bgp/bgp_table.cc
Expand Up @@ -213,9 +213,14 @@ UpdateInfo *BgpTable::GetUpdateInfo(RibOut *ribout, BgpRoute *route,
if (attr->local_pref())
clone->set_local_pref(0);

// Reset Med if the path was not learnt from XMPP.
if (attr->med() && (!peer || peer->PeerType() != BgpProto::XMPP))
// Reset Med if the path did not originate from an xmpp peer.
// The AS path is NULL if the originating xmpp peer is locally
// connected. It's non-NULL but empty if the originating xmpp
// peer is connected to another bgp speaker in the iBGP mesh.
if (attr->med() && attr->as_path() &&
!attr->as_path()->path().path_segments.empty()) {
clone->set_med(0);
}

// Prepend the local AS to AsPath.
as_t local_as =
Expand Down
73 changes: 68 additions & 5 deletions src/bgp/test/bgp_table_export_test.cc
Expand Up @@ -191,6 +191,7 @@ class BgpTableExportTest : public ::testing::Test {
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;
Expand Down Expand Up @@ -462,15 +463,14 @@ TEST_P(BgpTableExportParamTest1, CommunityNoExportSubconfed) {
// Table : inet.0, bgp.l3vpn.0
// Source: eBGP, iBGP
// RibOut: eBGP
// Intent: LocalPref and Med are cleared for eBGP.
// Intent: LocalPref is cleared for eBGP.
//
TEST_P(BgpTableExportParamTest1, EBgpNoLocalPrefMed) {
TEST_P(BgpTableExportParamTest1, EBgpNoLocalPref) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
AddPath();
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrMed(0);
}

//
Expand All @@ -486,7 +486,6 @@ TEST_P(BgpTableExportParamTest1, EBgpAsPrepend1) {
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrMed(0);
VerifyAttrAsPrepend();
}

Expand All @@ -504,7 +503,6 @@ TEST_P(BgpTableExportParamTest1, EBgpAsPrepend2) {
RunExport();
VerifyExportAccept();
VerifyAttrLocalPref(0);
VerifyAttrMed(0);
VerifyAttrAsPrepend();
}

Expand Down Expand Up @@ -558,6 +556,55 @@ TEST_P(BgpTableExportParamTest2, IBgpSplitHorizon) {
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"));

Expand Down Expand Up @@ -688,6 +735,22 @@ TEST_P(BgpTableExportParamTest3, IBgpNoOverwriteMed) {
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"),
Expand Down

0 comments on commit 1dd6a54

Please sign in to comment.