Skip to content

Commit

Permalink
Fix minor issues in introspect for BGP paths
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Nischal Sheth committed Jul 14, 2015
1 parent 68af269 commit a903fb1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
21 changes: 11 additions & 10 deletions src/bgp/bgp_peer.cc
Expand Up @@ -365,7 +365,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)),
Expand All @@ -383,11 +385,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);
Expand All @@ -405,7 +403,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);
}
Expand Down Expand Up @@ -670,7 +667,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();
}

//
Expand Down Expand Up @@ -986,7 +987,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<BgpProto::OpenMessage::OptParam *>::const_iterator it;
for (it = msg->opt_params.begin(); it < msg->opt_params.end(); ++it) {
Expand All @@ -997,7 +998,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<std::string> families;
std::vector<BgpProto::OpenMessage::Capability *>::iterator cap_it;
Expand Down Expand Up @@ -1716,7 +1717,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");
Expand Down
6 changes: 2 additions & 4 deletions src/bgp/bgp_peer.h
Expand Up @@ -123,9 +123,7 @@ class BgpPeer : public IPeer {

// The BGP Identifier in host byte order.
virtual uint32_t bgp_identifier() const;

// TODO: remove
// uint32_t remote_bgp_id() const { return remote_bgp_id_; }
std::string bgp_identifier_string() const;

const AddressFamilyList &families() const {
return family_;
Expand Down Expand Up @@ -325,8 +323,8 @@ class BgpPeer : public IPeer {
std::vector<BgpProto::OpenMessage::Capability *> 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<std::string> configured_families_;
std::vector<std::string> negotiated_families_;
Expand Down
2 changes: 0 additions & 2 deletions src/bgp/bgp_peer.sandesh
Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions src/bgp/bgp_route.cc
Expand Up @@ -388,14 +388,24 @@ void BgpRoute::FillRouteInfo(const BgpTable *table,
}

if (path->GetSource() == BgpPath::BGP_XMPP) {
if (peer)
if (peer) {
srp.set_protocol(peer->IsXmppPeer() ? "XMPP" : "BGP");
else
srp.set_protocol("Local");
} else {
srp.set_protocol("None");
}
} else if (path->GetSource() == BgpPath::ServiceChain) {
srp.set_protocol("ServiceChain");
} else if (path->GetSource() == BgpPath::StaticRoute) {
srp.set_protocol("StaticRoute");
} else if (path->GetSource() == BgpPath::Local) {
srp.set_protocol("Local");
}

const BgpPeer *bgp_peer = dynamic_cast<const BgpPeer *>(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();
Expand Down

0 comments on commit a903fb1

Please sign in to comment.