From a82d69d12ab328c74bd471439552885017223f83 Mon Sep 17 00:00:00 2001 From: Nischal Sheth Date: Tue, 14 Jul 2015 11:47:09 -0700 Subject: [PATCH] Fix minor issues in introspect for BGP paths Following changes are implemented: - Rename remote_bgp_id_ to peer_bgp_id_ - Initialize BgpPeer members in constructor initialization list - Remove unused preference and metric fields from ShowRoutePath - Fill in protocol as Local if appropriate - Fill in local AS, peer AS and peer router id for BGP paths Change-Id: Iac6ed81cc615d604c3a4ec91d1f33bd6d00ff15f Closes-Bug: 1474158 --- src/bgp/bgp_peer.cc | 21 +++++++++++---------- src/bgp/bgp_peer.h | 3 ++- src/bgp/bgp_peer.sandesh | 2 -- src/bgp/bgp_route.cc | 7 +++++++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/bgp/bgp_peer.cc b/src/bgp/bgp_peer.cc index 1fcc73d7e09..a03576782aa 100644 --- a/src/bgp/bgp_peer.cc +++ b/src/bgp/bgp_peer.cc @@ -366,7 +366,9 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, vpn_tables_registered_(false), local_as_(config->local_as()), peer_as_(config_->peer_as()), - remote_bgp_id_(0), + local_bgp_id_(config->local_identifier()), + peer_bgp_id_(0), + configured_families_(config->address_families()), peer_type_((peer_as_ == local_as_) ? BgpProto::IBGP : BgpProto::EBGP), policy_(peer_type_, RibExportPolicy::BGP, peer_as_, -1, 0), peer_close_(new PeerClose(this)), @@ -384,11 +386,7 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, peer_basename_ = peer_name_; } - boost::system::error_code ec; - local_bgp_id_ = config->local_identifier(); - refcount_ = 0; - configured_families_ = config->address_families(); sort(configured_families_.begin(), configured_families_.end()); BOOST_FOREACH(string family, configured_families_) { Address::Family fmly = Address::FamilyFromString(family); @@ -406,7 +404,6 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, peer_info.set_local_id(local_bgp_id_); if (!config->address_families().empty()) peer_info.set_configured_families(config->address_families()); - peer_info.set_peer_address(peer_key_.endpoint.address().to_string()); BGPPeerInfo::Send(peer_info); } @@ -671,7 +668,11 @@ bool BgpPeer::IsXmppPeer() const { } uint32_t BgpPeer::bgp_identifier() const { - return ntohl(remote_bgp_id_); + return ntohl(peer_bgp_id_); +} + +string BgpPeer::bgp_identifier_string() const { + return Ip4Address(ntohl(peer_bgp_id_)).to_string(); } // @@ -985,7 +986,7 @@ void BgpPeer::SendNotification(BgpSession *session, } void BgpPeer::SetCapabilities(const BgpProto::OpenMessage *msg) { - remote_bgp_id_ = htonl(msg->identifier); + peer_bgp_id_ = htonl(msg->identifier); capabilities_.clear(); std::vector::const_iterator it; for (it = msg->opt_params.begin(); it < msg->opt_params.end(); ++it) { @@ -996,7 +997,7 @@ void BgpPeer::SetCapabilities(const BgpProto::OpenMessage *msg) { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); - peer_info.set_peer_id(remote_bgp_id_); + peer_info.set_peer_id(peer_bgp_id_); std::vector families; std::vector::iterator cap_it; @@ -1715,7 +1716,7 @@ void BgpPeer::FillNeighborInfo(BgpSandeshContext *bsc, nbr.set_deleted(IsDeleted()); nbr.set_deleted_at(UTCUsecToString(deleter_->delete_time_stamp_usecs())); nbr.set_peer_address(peer_key_.endpoint.address().to_string()); - nbr.set_peer_id(Ip4Address(ntohl(remote_bgp_id_)).to_string()); + nbr.set_peer_id(bgp_identifier_string()); nbr.set_peer_asn(peer_as()); nbr.set_encoding("BGP"); nbr.set_peer_type(PeerType() == BgpProto::IBGP ? "internal" : "external"); diff --git a/src/bgp/bgp_peer.h b/src/bgp/bgp_peer.h index d254d46a628..555e11d96d2 100644 --- a/src/bgp/bgp_peer.h +++ b/src/bgp/bgp_peer.h @@ -123,6 +123,7 @@ class BgpPeer : public IPeer { // The BGP Identifier in host byte order. virtual uint32_t bgp_identifier() const; + std::string bgp_identifier_string() const; const AddressFamilyList &families() const { return family_; @@ -329,8 +330,8 @@ class BgpPeer : public IPeer { std::vector capabilities_; as_t local_as_; as_t peer_as_; - uint32_t remote_bgp_id_; // network order uint32_t local_bgp_id_; // network order + uint32_t peer_bgp_id_; // network order AddressFamilyList family_; std::vector configured_families_; std::vector negotiated_families_; diff --git a/src/bgp/bgp_peer.sandesh b/src/bgp/bgp_peer.sandesh index 20a9e5810ba..6fd1c926b75 100644 --- a/src/bgp/bgp_peer.sandesh +++ b/src/bgp/bgp_peer.sandesh @@ -120,9 +120,7 @@ struct ShowPmsiTunnel { struct ShowRoutePath { 1: string protocol; - 2: u32 preference; 3: string last_modified; - 4: u32 metric; 5: u32 local_preference; 6: u32 local_as; 7: u32 peer_as; diff --git a/src/bgp/bgp_route.cc b/src/bgp/bgp_route.cc index ce37d6d625a..31d41419d8b 100644 --- a/src/bgp/bgp_route.cc +++ b/src/bgp/bgp_route.cc @@ -401,6 +401,13 @@ void BgpRoute::FillRouteInfo(const BgpTable *table, srp.set_protocol("Local"); } + const BgpPeer *bgp_peer = dynamic_cast(peer); + if (bgp_peer) { + srp.set_local_as(bgp_peer->local_as()); + srp.set_peer_as(bgp_peer->peer_as()); + srp.set_peer_router_id(bgp_peer->bgp_identifier_string()); + } + const BgpAttr *attr = path->GetAttr(); if (attr->as_path() != NULL) srp.set_as_path(attr->as_path()->path().ToString());