Skip to content

Commit

Permalink
Add origin and originator_id fields to route introspect
Browse files Browse the repository at this point in the history
Change-Id: Ib38da04cbb6ba69cf653945781fee51d4f90be16
Closes-Bug: 1661801
  • Loading branch information
Nischal Sheth committed Feb 4, 2017
1 parent a5fb550 commit 331927c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/bgp/bgp_attr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,21 @@ void BgpAttr::set_leaf_olist(const BgpOListSpec *leaf_olist_spec) {
}
}

std::string BgpAttr::origin_string() const {
switch (origin()) {
case BgpAttrOrigin::IGP:
return "igp";
break;
case BgpAttrOrigin::EGP:
return "egp";
break;
case BgpAttrOrigin::INCOMPLETE:
return "incomplete";
break;
}
return "unknown";
}

Address::Family BgpAttr::nexthop_family() const {
if (nexthop_.is_v6()) {
return Address::INET6;
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ class BgpAttr {
friend std::size_t hash_value(BgpAttr const &attr);

BgpAttrOrigin::OriginType origin() const { return origin_; }
std::string origin_string() const;
const IpAddress &nexthop() const { return nexthop_; }
Address::Family nexthop_family() const;
uint32_t med() const { return med_; }
Expand Down
2 changes: 2 additions & 0 deletions src/bgp/bgp_peer.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ struct ShowRoutePath {
10: string as_path;
11: string next_hop;
12: u32 label;
26: string origin;
13: bool replicated;
14: string primary_table (link="ShowRouteReq");
24: list<string> secondary_tables;
Expand All @@ -196,6 +197,7 @@ struct ShowRoutePath {
21: ShowPmsiTunnel pmsi_tunnel;
22: ShowLoadBalance load_balance;
23: list<string> cluster_list;
27: string originator_id;
}

struct ShowRoute {
Expand Down
5 changes: 5 additions & 0 deletions src/bgp/bgp_route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ void BgpRoute::FillRouteInfo(const BgpTable *table,
}

const BgpAttr *attr = path->GetAttr();
srp.set_origin(attr->origin_string());
if (attr->as_path() != NULL)
srp.set_as_path(attr->as_path()->path().ToString());
srp.set_local_preference(attr->local_pref());
Expand Down Expand Up @@ -504,6 +505,10 @@ void BgpRoute::FillRouteInfo(const BgpTable *table,
bool label_is_vni = extcomm && extcomm->ContainsTunnelEncapVxlan();
FillPmsiTunnelInfo(attr->pmsi_tunnel(), label_is_vni, &srp);
}
if (attr->originator_id().to_ulong()) {
srp.set_originator_id(attr->originator_id().to_string());
}

show_route_paths.push_back(srp);
}
show_route->set_paths(show_route_paths);
Expand Down
36 changes: 36 additions & 0 deletions src/bgp/test/bgp_attr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ TEST_F(BgpAttrTest, UnknownCode) {
EXPECT_EQ(1729, attr->local_pref());
}

TEST_F(BgpAttrTest, Origin1) {
BgpAttrSpec spec;
BgpAttrOrigin origin(BgpAttrOrigin::IGP);
spec.push_back(&origin);
BgpAttrPtr attr = attr_db_->Locate(spec);
EXPECT_EQ(BgpAttrOrigin::IGP, attr->origin());
EXPECT_EQ("igp", attr->origin_string());
}

TEST_F(BgpAttrTest, Origin2) {
BgpAttrSpec spec;
BgpAttrOrigin origin(BgpAttrOrigin::EGP);
spec.push_back(&origin);
BgpAttrPtr attr = attr_db_->Locate(spec);
EXPECT_EQ(BgpAttrOrigin::EGP, attr->origin());
EXPECT_EQ("egp", attr->origin_string());
}

TEST_F(BgpAttrTest, Origin3) {
BgpAttrSpec spec;
BgpAttrOrigin origin(BgpAttrOrigin::INCOMPLETE);
spec.push_back(&origin);
BgpAttrPtr attr = attr_db_->Locate(spec);
EXPECT_EQ(BgpAttrOrigin::INCOMPLETE, attr->origin());
EXPECT_EQ("incomplete", attr->origin_string());
}

TEST_F(BgpAttrTest, Origin4) {
BgpAttrSpec spec;
BgpAttrOrigin origin(255);
spec.push_back(&origin);
BgpAttrPtr attr = attr_db_->Locate(spec);
EXPECT_EQ(255, attr->origin());
EXPECT_EQ("unknown", attr->origin_string());
}

TEST_F(BgpAttrTest, MultiExitDiscCompare) {
BgpAttrMultiExitDisc med1(100);
BgpAttrMultiExitDisc med2(200);
Expand Down

0 comments on commit 331927c

Please sign in to comment.