Skip to content

Commit

Permalink
Display list of secondary tables for a primary path
Browse files Browse the repository at this point in the history
Change-Id: I88f099d0eb2491879d24b88feee98159e9d18091
Closes-Bug: 1496698
  • Loading branch information
Nischal Sheth committed Jan 27, 2016
1 parent 0223722 commit 6635abf
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/bgp/bgp_peer.sandesh
Expand Up @@ -145,6 +145,7 @@ struct ShowRoutePath {
12: u32 label;
13: bool replicated;
14: string primary_table (link="ShowRouteReq");
24: list<string> secondary_tables;
15: list<string> communities;
16: string origin_vn;
17: u32 flags;
Expand Down
9 changes: 9 additions & 0 deletions src/bgp/bgp_route.cc
Expand Up @@ -14,6 +14,7 @@
#include "bgp/extended-community/mac_mobility.h"
#include "bgp/extended-community/site_of_origin.h"
#include "bgp/origin-vn/origin_vn.h"
#include "bgp/routing-instance/routepath_replicator.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/security_group/security_group.h"
#include "bgp/tunnel_encap/tunnel_encap.h"
Expand Down Expand Up @@ -462,6 +463,14 @@ void BgpRoute::FillRouteInfo(const BgpTable *table,
srp.set_primary_table(replicated->src_table()->name());
} else {
srp.set_replicated(false);
Address::Family vpn_family =
Address::VpnFamilyFromFamily(table->family());
const RoutePathReplicator *replicator =
table->server()->replicator(vpn_family);
if (replicator) {
srp.set_secondary_tables(
replicator->GetReplicatedTableNameList(table, this, path));
}
}
if (attr->cluster_list()) {
FillRoutePathClusterListInfo(attr->cluster_list(), &srp);
Expand Down
13 changes: 11 additions & 2 deletions src/bgp/bgp_server.h
Expand Up @@ -119,8 +119,17 @@ class BgpServer {
return ermvpn_replicator_.get();
if (family == Address::INET6VPN)
return inet6vpn_replicator_.get();

assert(false);
return NULL;
}
const RoutePathReplicator *replicator(Address::Family family) const {
if (family == Address::INETVPN)
return inetvpn_replicator_.get();
if (family == Address::EVPN)
return evpn_replicator_.get();
if (family == Address::ERMVPN)
return ermvpn_replicator_.get();
if (family == Address::INET6VPN)
return inet6vpn_replicator_.get();
return NULL;
}

Expand Down
41 changes: 39 additions & 2 deletions src/bgp/routing-instance/routepath_replicator.cc
Expand Up @@ -20,6 +20,7 @@ using std::ostringstream;
using std::make_pair;
using std::pair;
using std::string;
using std::vector;

//
// RoutePathReplication trace macro. Optionally logs the server name as well for
Expand Down Expand Up @@ -134,6 +135,25 @@ void RtReplicated::DeleteRouteInfo(BgpTable *table, BgpRoute *rt,
replicate_list_.erase(it);
}

//
// Return the list of secondary table names for the given primary path.
// We go through all SecondaryRouteInfos and skip the ones that don't
// match the primary path.
//
vector<string> RtReplicated::GetTableNameList(const BgpPath *path) const {
vector<string> table_list;
BOOST_FOREACH(const SecondaryRouteInfo &rinfo, replicate_list_) {
if (rinfo.peer_ != path->GetPeer())
continue;
if (rinfo.path_id_ != path->GetPathId())
continue;
if (rinfo.src_ != path->GetSource())
continue;
table_list.push_back(rinfo.table_->name());
}
return table_list;
}

RoutePathReplicator::RoutePathReplicator(BgpServer *server,
Address::Family family)
: server_(server),
Expand Down Expand Up @@ -206,8 +226,10 @@ TableState *RoutePathReplicator::FindTableState(BgpTable *table) {
return (loc != table_state_list_.end() ? loc->second : NULL);
}

const TableState *RoutePathReplicator::FindTableState(BgpTable *table) const {
TableStateList::const_iterator loc = table_state_list_.find(table);
const TableState *RoutePathReplicator::FindTableState(
const BgpTable *table) const {
TableStateList::const_iterator loc =
table_state_list_.find(const_cast<BgpTable *>(table));
return (loc != table_state_list_.end() ? loc->second : NULL);
}

Expand Down Expand Up @@ -628,6 +650,21 @@ const RtReplicated *RoutePathReplicator::GetReplicationState(
return dbstate;
}

//
// Return the list of secondary table names for the given primary path.
//
vector<string> RoutePathReplicator::GetReplicatedTableNameList(
const BgpTable *table, const BgpRoute *rt, const BgpPath *path) const {
const TableState *ts = FindTableState(table);
if (!ts)
return vector<string>();
const RtReplicated *dbstate = static_cast<const RtReplicated *>(
rt->GetState(table, ts->listener_id()));
if (!dbstate)
return vector<string>();
return dbstate->GetTableNameList(path);
}

void RoutePathReplicator::DeleteSecondaryPath(BgpTable *table, BgpRoute *rt,
const RtReplicated::SecondaryRouteInfo &rtinfo) {
BgpRoute *rt_secondary = rtinfo.rt_;
Expand Down
6 changes: 5 additions & 1 deletion src/bgp/routing-instance/routepath_replicator.h
Expand Up @@ -194,6 +194,7 @@ class RtReplicated : public DBState {

const ReplicatedRtPathList &GetList() const { return replicate_list_; }
ReplicatedRtPathList *GetMutableList() { return &replicate_list_; }
std::vector<std::string> GetTableNameList(const BgpPath *path) const;

private:
RoutePathReplicator *replicator_;
Expand Down Expand Up @@ -269,6 +270,9 @@ class RoutePathReplicator {

const RtReplicated *GetReplicationState(BgpTable *table,
BgpRoute *rt) const;
std::vector<std::string> GetReplicatedTableNameList(const BgpTable *table,
const BgpRoute *route, const BgpPath *path) const;

SandeshTraceBufferPtr trace_buffer() const { return trace_buf_; }

private:
Expand All @@ -290,7 +294,7 @@ class RoutePathReplicator {
void DeleteTableState(BgpTable *table);
void UnregisterTableState(BgpTable *table);
TableState *FindTableState(BgpTable *table);
const TableState *FindTableState(BgpTable *table) const;
const TableState *FindTableState(const BgpTable *table) const;

void JoinVpnTable(RtGroup *group);
void LeaveVpnTable(RtGroup *group);
Expand Down
13 changes: 11 additions & 2 deletions src/bgp/routing-instance/static_route.cc
Expand Up @@ -14,6 +14,7 @@
#include "bgp/bgp_log.h"
#include "bgp/inet6vpn/inet6vpn_route.h"
#include "bgp/l3vpn/inetvpn_route.h"
#include "bgp/routing-instance/routepath_replicator.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/static_route_types.h"
#include "net/community_type.h"
Expand Down Expand Up @@ -245,10 +246,11 @@ template <typename T>
void StaticRoute<T>::FillShowInfo(StaticRouteInfo *info) const {
BgpTable *table = bgp_table();
RouteT rt_key(static_route_prefix_);
BgpRoute *route = static_cast<BgpRoute *>(table->Find(&rt_key));
const BgpRoute *route = static_cast<const BgpRoute *>(table->Find(&rt_key));
const BgpPath *path = route ? route->FindPath(BgpPath::StaticRoute) : NULL;

info->set_prefix(static_route_prefix_.ToString());
info->set_static_rt(route ? true : false);
info->set_static_rt(path ? true : false);
info->set_nexthop(nexthop_.to_string());
if (nexthop_route_) {
ShowRouteBrief show_route;
Expand All @@ -262,6 +264,13 @@ void StaticRoute<T>::FillShowInfo(StaticRouteInfo *info) const {
route_target_list.push_back(it->ToString());
}
info->set_route_target_list(route_target_list);

if (path) {
const RoutePathReplicator *replicator = table->server()->replicator(
Address::VpnFamilyFromFamily(GetFamily()));
info->set_secondary_tables(
replicator->GetReplicatedTableNameList(table, route, path));
}
}

// Match function called from BgpConditionListener
Expand Down
3 changes: 2 additions & 1 deletion src/bgp/routing-instance/static_route.sandesh
Expand Up @@ -9,8 +9,9 @@ struct StaticRouteInfo {
1: string prefix;
2: bool static_rt;
3: string nexthop;
4: bgp_peer.ShowRouteBrief nexthop_rt;
5: list<string> route_target_list;
6: list<string> secondary_tables;
4: bgp_peer.ShowRouteBrief nexthop_rt;
}

struct StaticRouteEntriesInfo {
Expand Down
18 changes: 18 additions & 0 deletions src/net/address.cc
Expand Up @@ -106,6 +106,24 @@ std::string Address::FamilyToTableString(Address::Family family) {
return toTableName.find(family)->second;
}

Address::Family Address::VpnFamilyFromFamily(Address::Family family) {
switch (family) {
case Address::INET:
case Address::INETVPN:
return Address::INETVPN;
case Address::INET6:
case Address::INET6VPN:
return Address::INET6VPN;
case Address::EVPN:
return Address::EVPN;
case Address::ERMVPN:
return Address::ERMVPN;
default:
return Address::UNSPEC;
}
return Address::UNSPEC;
}

static int CountDots(const string &str) {
int count = 0;
size_t pos = 0;
Expand Down
1 change: 1 addition & 0 deletions src/net/address.h
Expand Up @@ -44,6 +44,7 @@ class Address {
static std::string FamilyToString(Family fmly);
static Family FamilyFromRoutingTableName(const std::string &name);
static std::string FamilyToTableString(Family family);
static Family VpnFamilyFromFamily(Family family);
static Ip4Address V4FromV4MappedV6(const Ip6Address &v6_address);
static Ip4Address GetIp4SubnetAddress(const Ip4Address &prefix,
uint16_t plen);
Expand Down

0 comments on commit 6635abf

Please sign in to comment.