Skip to content

Commit

Permalink
Introspect support for route aggregation
Browse files Browse the repository at this point in the history
Enhanced UT cases to invoke route-aggregation introspect

Change-Id: Ib244faf3b30323c5b032fd4f079410e94da3ce81
Related-bug: #1500698
  • Loading branch information
bailkeri committed Jan 25, 2016
1 parent 25954b4 commit 73211b7
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/bgp/bgp_config.cc
Expand Up @@ -341,7 +341,7 @@ std::string RoutingPolicyMatchConfig::ToString() const {
return oss.str();
}

static void PutCommunityMatch(ostringstream &oss, const CommunityList &list) {
static void PutCommunityList(ostringstream &oss, const CommunityList &list) {
copy(list.begin(), list.end(), ostream_iterator<string>(oss,","));
oss.seekp(-1, oss.cur);
}
Expand All @@ -351,17 +351,17 @@ string RoutingPolicyActionConfig::ToString() const {
oss << "then {" << std::endl;
if (!update.community_set.empty()) {
oss << " community set [ ";
PutCommunityMatch(oss, update.community_set);
PutCommunityList(oss, update.community_set);
oss << " ]" << std::endl;
}
if (!update.community_add.empty()) {
oss << " community add [ ";
PutCommunityMatch(oss, update.community_add);
PutCommunityList(oss, update.community_add);
oss << " ]" << std::endl;
}
if (!update.community_remove.empty()) {
oss << " community remove [ ";
PutCommunityMatch(oss, update.community_remove);
PutCommunityList(oss, update.community_remove);
oss << " ]" << std::endl;
}
if (update.local_pref) {
Expand Down
2 changes: 1 addition & 1 deletion src/bgp/bgp_show_config.cc
Expand Up @@ -245,7 +245,7 @@ bool BgpShowHandler<ShowBgpRoutingPolicyConfigReq,
break;
}

// All done if we've looked at all instances.
// All done if we've looked at all policies.
if (it == it_end || ++it == it_end)
return true;

Expand Down
3 changes: 3 additions & 0 deletions src/bgp/routing-instance/SConscript
Expand Up @@ -18,6 +18,8 @@ SandeshGenFiles += env.SandeshGenCpp('service_chaining.sandesh')
SandeshGenFiles += env.SandeshGenOnlyCpp('service_chaining_internal.sandesh')
SandeshGenFiles += env.SandeshGenCpp('static_route.sandesh')
SandeshGenFiles += env.SandeshGenOnlyCpp('static_route_internal.sandesh')
SandeshGenFiles += env.SandeshGenCpp('route_aggregate.sandesh')
SandeshGenFiles += env.SandeshGenOnlyCpp('route_aggregate_internal.sandesh')
SandeshGenSrcs = env.ExtractCpp(SandeshGenFiles)

librouting_instance = env.Library('routing_instance', SandeshGenSrcs +
Expand All @@ -29,6 +31,7 @@ librouting_instance = env.Library('routing_instance', SandeshGenSrcs +
'rtarget_group.cc',
'rtarget_group_mgr.cc',
'service_chaining.cc',
'show_route_aggregate.cc',
'show_service_chaining.cc',
'show_static_route.cc',
'static_route.cc'])
Expand Down
5 changes: 5 additions & 0 deletions src/bgp/routing-instance/iroute_aggregator.h
Expand Up @@ -9,6 +9,7 @@

class BgpRoute;
class RoutingInstance;
class AggregateRouteEntriesInfo;

class IRouteAggregator {
public:
Expand All @@ -21,6 +22,10 @@ class IRouteAggregator {

virtual bool IsAggregateRoute(const BgpRoute *route) const = 0;
virtual bool IsContributingRoute(const BgpRoute *route) const = 0;

virtual bool FillAggregateRouteInfo(RoutingInstance *ri,
AggregateRouteEntriesInfo *info) const = 0;

private:
friend class RouteAggregationTest;

Expand Down
43 changes: 43 additions & 0 deletions src/bgp/routing-instance/route_aggregate.cc
Expand Up @@ -14,6 +14,7 @@
#include "base/task_annotations.h"
#include "bgp/routing-instance/path_resolver.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/route_aggregate_types.h"

using std::make_pair;
using std::string;
Expand Down Expand Up @@ -228,6 +229,8 @@ class AggregateRoute : public ConditionMatch {
return contributors_[part_id].empty();
}

void FillShowInfo(AggregateRouteInfo *info) const;

private:
RoutingInstance *routing_instance_;
AggregateRouteMgrT *manager_;
Expand Down Expand Up @@ -460,6 +463,28 @@ void AggregateRoute<T>::set_aggregate_route(BgpRoute *aggregate) {
aggregate_route_ = aggregate;
}

template <typename T>
void AggregateRoute<T>::FillShowInfo(AggregateRouteInfo *info) const {
BgpTable *table = bgp_table();
info->set_deleted(deleted());
info->set_prefix(aggregate_route_prefix_.ToString());
if (aggregate_route_) {
ShowRouteBrief show_route;
aggregate_route_->FillRouteInfo(table, &show_route);
info->set_aggregate_rt(show_route);
}

info->set_nexthop(nexthop_.to_string());

std::vector<string> contributor_list;
BOOST_FOREACH(const RouteList &list, contribute_route_list()) {
BOOST_FOREACH(BgpRoute *rt, list) {
contributor_list.push_back(rt->ToString());
}
}
info->set_contributors(contributor_list);
}

template <typename T>
class RouteAggregator<T>::DeleteActor : public LifetimeActor {
public:
Expand Down Expand Up @@ -672,6 +697,24 @@ bool RouteAggregator<T>::IsContributingRoute(const BgpRoute *route) const {
return false;
}

template <typename T>
bool RouteAggregator<T>::FillAggregateRouteInfo(RoutingInstance *ri,
AggregateRouteEntriesInfo *info) const {
if (aggregate_route_map().empty()) return false;

info->set_ri_name(ri->name());

for (typename AggregateRouteMap::const_iterator it = aggregate_route_map_.begin();
it != aggregate_route_map_.end(); it++) {
AggregateRouteT *aggregate =
static_cast<AggregateRouteT *>(it->second.get());
AggregateRouteInfo aggregate_info;
aggregate->FillShowInfo(&aggregate_info);
info->aggregate_route_list.push_back(aggregate_info);
}
return true;
}

template <typename T>
void RouteAggregator<T>::LocateAggregateRoutePrefix(const AggregateRouteConfig
&cfg) {
Expand Down
3 changes: 3 additions & 0 deletions src/bgp/routing-instance/route_aggregate.h
Expand Up @@ -198,6 +198,9 @@ class RouteAggregator : public IRouteAggregator {
virtual bool IsAggregateRoute(const BgpRoute *route) const;
virtual bool IsContributingRoute(const BgpRoute *route) const;

virtual bool FillAggregateRouteInfo(RoutingInstance *ri,
AggregateRouteEntriesInfo *info) const;

private:
friend class RouteAggregationTest;
class DeleteActor;
Expand Down
29 changes: 29 additions & 0 deletions src/bgp/routing-instance/route_aggregate.sandesh
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/

include "bgp/bgp_peer.sandesh"
include "bgp/routing-instance/route_aggregate_internal.sandesh"

struct AggregateRouteInfo {
1: string prefix;
2: bgp_peer.ShowRouteBrief aggregate_rt;
3: string nexthop;
4: list<string> contributors;
5: bool deleted;
}

struct AggregateRouteEntriesInfo {
1: string ri_name;
2: list<AggregateRouteInfo> aggregate_route_list;
}

response sandesh ShowRouteAggregateResp {
1: list<AggregateRouteEntriesInfo> aggregate_route_entries;
2: optional string next_batch (link="ShowRouteAggregateReqIterate",
link_title="next_batch");
}

request sandesh ShowRouteAggregateReq {
1: string search_string;
}
6 changes: 6 additions & 0 deletions src/bgp/routing-instance/route_aggregate_internal.sandesh
@@ -0,0 +1,6 @@
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
request sandesh ShowRouteAggregateReqIterate {
1: string iterate_info;
}
129 changes: 129 additions & 0 deletions src/bgp/routing-instance/show_route_aggregate.cc
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
*/

#include "bgp/bgp_show_handler.h"


#include "bgp/bgp_show_handler.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/route_aggregate.h"
#include "bgp/routing-instance/route_aggregate_types.h"

using std::string;
using std::vector;

static bool FillRouteAggregateInfo(Address::Family family,
const string search_string,
AggregateRouteEntriesInfo &info,
RoutingInstance *rtinstance) {
const BgpTable *table =
static_cast<const BgpTable *>(rtinstance->GetTable(family));
if (!table)
return false;
if (!search_string.empty() &&
(table->name().find(search_string) == string::npos) &&
(search_string != "deleted" || !table->IsDeleted())) {
return false;
}

IRouteAggregator *iroute_aggregator = rtinstance->route_aggregator(family);
if (!iroute_aggregator)
return false;
return iroute_aggregator->FillAggregateRouteInfo(rtinstance, &info);
}

// Specialization of BgpShowHandler<>::CallbackCommon.
template <>
bool BgpShowHandler<ShowRouteAggregateReq, ShowRouteAggregateReqIterate,
ShowRouteAggregateResp, AggregateRouteEntriesInfo>::CallbackCommon(
const BgpSandeshContext *bsc, Data *data) {
uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();

RoutingInstanceMgr::const_name_iterator it =
rim->name_clower_bound(data->next_entry);
AggregateRouteEntriesInfo info;
for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
RoutingInstance *rinstance = it->second;
if (FillRouteAggregateInfo(Address::INET, data->search_string, info,
rinstance)) {
data->show_list.push_back(info);
}
if (FillRouteAggregateInfo(Address::INET6, data->search_string, info,
rinstance)) {
data->show_list.push_back(info);
}

if (data->show_list.size() >= page_limit)
break;
if (iter_count >= iter_limit)
break;
}

// All done if we've looked at all instances.
if (it == rim->name_cend() || ++it == rim->name_cend())
return true;

// Return true if we've reached the page limit, false if we've reached the
// iteration limit.
bool done = data->show_list.size() >= page_limit;
SaveContextToData(it->second->name(), done, data);
return done;
}

// Specialization of BgpShowHandler<>::FillShowList.
template <>
void BgpShowHandler<ShowRouteAggregateReq, ShowRouteAggregateReqIterate,
ShowRouteAggregateResp, AggregateRouteEntriesInfo>::FillShowList(
ShowRouteAggregateResp *resp,
const vector<AggregateRouteEntriesInfo> &show_list) {
resp->set_aggregate_route_entries(show_list);
}

// Handler for ShowRouteAggregateReq.
void ShowRouteAggregateReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();

s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}

//
// Handler for ShowRouteAggregateReqIterate.
//
void ShowRouteAggregateReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();

s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}

0 comments on commit 73211b7

Please sign in to comment.