Skip to content

Commit

Permalink
Include ORIGIN and MED in ECMP decision
Browse files Browse the repository at this point in the history
Note that this changes ecmp behavior from older releases, but this is
deemed to be fine since the new behavior is what most users will expect
by default.

Change-Id: Iff5834710153e1315269f58662d58e647be6c9ce
Closes-Bug: 1586873
  • Loading branch information
Nischal Sheth committed May 30, 2016
1 parent df96ef5 commit f3fe98c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/bgp/bgp_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ int BgpPath::PathCompare(const BgpPath &rhs, bool allow_ecmp) const {

KEY_COMPARE(attr_->as_path_count(), rattr->as_path_count());

// For ECMP paths, above checks should suffice.
if (allow_ecmp)
return 0;

KEY_COMPARE(attr_->origin(), rattr->origin());

// Compare med if both paths are learnt from the same neighbor as.
if (attr_->neighbor_as() && attr_->neighbor_as() == rattr->neighbor_as())
KEY_COMPARE(attr_->med(), rattr->med());

// For ECMP paths, above checks should suffice.
if (allow_ecmp)
return 0;

// Prefer locally generated routes over bgp and xmpp routes.
BOOL_COMPARE(peer_ == NULL, rhs.peer_ == NULL);

Expand Down
12 changes: 12 additions & 0 deletions src/bgp/test/bgp_route_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ TEST_F(BgpRouteTest, PathCompareClusterList2) {

//
// Path with lower med is better.
// Paths with different MEDs are not considered ECMP.
//
TEST_F(BgpRouteTest, PathCompareMed1) {
boost::system::error_code ec;
Expand Down Expand Up @@ -422,12 +423,15 @@ TEST_F(BgpRouteTest, PathCompareMed1) {

EXPECT_EQ(-1, path1.PathCompare(path2, false));
EXPECT_EQ(1, path2.PathCompare(path1, false));
EXPECT_EQ(-1, path1.PathCompare(path2, true));
EXPECT_EQ(1, path2.PathCompare(path1, true));
}

//
// Paths with different neighbor as are not compared w.r.t med.
// Path with higher med happens to win since it has lower router id.
// Both paths have as paths, but the leftmost as is different.
// Paths with different MEDs are considered ECMP as leftmost AS is different.
//
TEST_F(BgpRouteTest, PathCompareMed2) {
boost::system::error_code ec;
Expand Down Expand Up @@ -463,12 +467,15 @@ TEST_F(BgpRouteTest, PathCompareMed2) {

EXPECT_EQ(1, path1.PathCompare(path2, false));
EXPECT_EQ(-1, path2.PathCompare(path1, false));
EXPECT_EQ(0, path1.PathCompare(path2, true));
EXPECT_EQ(0, path2.PathCompare(path1, true));
}

//
// Paths with different neighbor as are not compared w.r.t med.
// Path with higher med happens to win since it has lower router id.
// Both paths have nil as path.
// Paths with different MEDs are considered ECMP as leftmost AS is 0.
//
TEST_F(BgpRouteTest, PathCompareMed3) {
boost::system::error_code ec;
Expand All @@ -494,12 +501,15 @@ TEST_F(BgpRouteTest, PathCompareMed3) {

EXPECT_EQ(1, path1.PathCompare(path2, false));
EXPECT_EQ(-1, path2.PathCompare(path1, false));
EXPECT_EQ(0, path1.PathCompare(path2, true));
EXPECT_EQ(0, path2.PathCompare(path1, true));
}

//
// Paths with 0 neighbor as are not compared w.r.t med.
// Path with higher med happens to win since it has lower router id.
// First segment in both paths is an AS_SET.
// Paths with different MEDs are considered ECMP as leftmost AS is 0.
//
TEST_F(BgpRouteTest, PathCompareMed4) {
boost::system::error_code ec;
Expand Down Expand Up @@ -535,6 +545,8 @@ TEST_F(BgpRouteTest, PathCompareMed4) {

EXPECT_EQ(1, path1.PathCompare(path2, false));
EXPECT_EQ(-1, path2.PathCompare(path1, false));
EXPECT_EQ(0, path1.PathCompare(path2, true));
EXPECT_EQ(0, path2.PathCompare(path1, true));
}

static void SetUp() {
Expand Down

0 comments on commit f3fe98c

Please sign in to comment.