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 e6e07d4 commit a82d69d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/bgp/bgp_peer.cc
Expand Up @@ -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)),
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}

//
Expand Down Expand Up @@ -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<BgpProto::OpenMessage::OptParam *>::const_iterator it;
for (it = msg->opt_params.begin(); it < msg->opt_params.end(); ++it) {
Expand All @@ -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<std::string> families;
std::vector<BgpProto::OpenMessage::Capability *>::iterator cap_it;
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/bgp/bgp_peer.h
Expand Up @@ -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_;
Expand Down Expand Up @@ -329,8 +330,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
7 changes: 7 additions & 0 deletions src/bgp/bgp_route.cc
Expand Up @@ -401,6 +401,13 @@ void BgpRoute::FillRouteInfo(const BgpTable *table,
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();
if (attr->as_path() != NULL)
srp.set_as_path(attr->as_path()->path().ToString());
Expand Down

0 comments on commit a82d69d

Please sign in to comment.