From 331927c467e9e2536b80e1f427f26a833ab8f995 Mon Sep 17 00:00:00 2001 From: Nischal Sheth Date: Fri, 3 Feb 2017 17:24:24 -0800 Subject: [PATCH] Add origin and originator_id fields to route introspect Change-Id: Ib38da04cbb6ba69cf653945781fee51d4f90be16 Closes-Bug: 1661801 --- src/bgp/bgp_attr.cc | 15 +++++++++++++++ src/bgp/bgp_attr.h | 1 + src/bgp/bgp_peer.sandesh | 2 ++ src/bgp/bgp_route.cc | 5 +++++ src/bgp/test/bgp_attr_test.cc | 36 +++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/src/bgp/bgp_attr.cc b/src/bgp/bgp_attr.cc index 6a70ed711e5..e82794dd906 100644 --- a/src/bgp/bgp_attr.cc +++ b/src/bgp/bgp_attr.cc @@ -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; diff --git a/src/bgp/bgp_attr.h b/src/bgp/bgp_attr.h index 4c329943b35..1ae34d12d25 100644 --- a/src/bgp/bgp_attr.h +++ b/src/bgp/bgp_attr.h @@ -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_; } diff --git a/src/bgp/bgp_peer.sandesh b/src/bgp/bgp_peer.sandesh index d5e3e8806d5..fd597c2935e 100644 --- a/src/bgp/bgp_peer.sandesh +++ b/src/bgp/bgp_peer.sandesh @@ -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 secondary_tables; @@ -196,6 +197,7 @@ struct ShowRoutePath { 21: ShowPmsiTunnel pmsi_tunnel; 22: ShowLoadBalance load_balance; 23: list cluster_list; + 27: string originator_id; } struct ShowRoute { diff --git a/src/bgp/bgp_route.cc b/src/bgp/bgp_route.cc index 45c5d02aecd..42b2f87dd0c 100644 --- a/src/bgp/bgp_route.cc +++ b/src/bgp/bgp_route.cc @@ -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()); @@ -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); diff --git a/src/bgp/test/bgp_attr_test.cc b/src/bgp/test/bgp_attr_test.cc index 52aa533c582..fcbcf32b98d 100644 --- a/src/bgp/test/bgp_attr_test.cc +++ b/src/bgp/test/bgp_attr_test.cc @@ -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);