Skip to content

Commit

Permalink
Add ShowRouteAggregateSummaryReq introspect command
Browse files Browse the repository at this point in the history
Change-Id: Ib633b018798e19c7fc73f4bebaef10283aef1a89
Related-bug: 1500698
  • Loading branch information
Nischal Sheth committed Feb 18, 2016
1 parent 5f0acaa commit 666d868
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 77 deletions.
4 changes: 2 additions & 2 deletions src/bgp/routing-instance/iroute_aggregator.h
Expand Up @@ -23,8 +23,8 @@ 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;
virtual bool FillAggregateRouteInfo(AggregateRouteEntriesInfo *info,
bool summary) const = 0;

private:
friend class RouteAggregatorTest;
Expand Down
16 changes: 13 additions & 3 deletions src/bgp/routing-instance/route_aggregate.sandesh
Expand Up @@ -9,15 +9,25 @@ struct AggregateRouteInfo {
1: string prefix;
2: bgp_peer.ShowRouteBrief aggregate_rt;
3: string nexthop;
4: list<string> contributors;
5: bool deleted;
4: bool deleted;
5: optional list<string> contributors;
}

struct AggregateRouteEntriesInfo {
1: string ri_name;
1: string name (link="ShowRouteAggregateReq");
2: list<AggregateRouteInfo> aggregate_route_list;
}

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

request sandesh ShowRouteAggregateSummaryReq {
1: string search_string;
}

response sandesh ShowRouteAggregateResp {
1: list<AggregateRouteEntriesInfo> aggregate_route_entries;
2: optional string next_batch (link="ShowRouteAggregateReqIterate",
Expand Down
5 changes: 5 additions & 0 deletions src/bgp/routing-instance/route_aggregate_internal.sandesh
@@ -1,6 +1,11 @@
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/

request sandesh ShowRouteAggregateReqIterate {
1: string iterate_info;
}

request sandesh ShowRouteAggregateSummaryReqIterate {
1: string iterate_info;
}
24 changes: 14 additions & 10 deletions src/bgp/routing-instance/route_aggregator.cc
Expand Up @@ -236,7 +236,7 @@ class AggregateRoute : public ConditionMatch {
return contributors_[part_id].empty();
}

void FillShowInfo(AggregateRouteInfo *info) const;
void FillShowInfo(AggregateRouteInfo *info, bool summary) const;

private:
RoutingInstance *routing_instance_;
Expand Down Expand Up @@ -481,7 +481,8 @@ void AggregateRoute<T>::set_aggregate_route(BgpRoute *aggregate) {
}

template <typename T>
void AggregateRoute<T>::FillShowInfo(AggregateRouteInfo *info) const {
void AggregateRoute<T>::FillShowInfo(AggregateRouteInfo *info,
bool summary) const {
BgpTable *table = bgp_table();
info->set_deleted(deleted());
info->set_prefix(aggregate_route_prefix_.ToString());
Expand All @@ -493,6 +494,9 @@ void AggregateRoute<T>::FillShowInfo(AggregateRouteInfo *info) const {

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

if (summary)
return;

std::vector<string> contributor_list;
BOOST_FOREACH(const RouteList &list, contribute_route_list()) {
BOOST_FOREACH(BgpRoute *rt, list) {
Expand Down Expand Up @@ -688,18 +692,18 @@ bool RouteAggregator<T>::IsContributingRoute(const BgpRoute *route) const {
}

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());
bool RouteAggregator<T>::FillAggregateRouteInfo(AggregateRouteEntriesInfo *info,
bool summary) const {
if (aggregate_route_map().empty())
return false;

for (typename AggregateRouteMap::const_iterator it = aggregate_route_map_.begin();
it != aggregate_route_map_.end(); it++) {
info->set_name(rtinstance_->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);
aggregate->FillShowInfo(&aggregate_info, summary);
info->aggregate_route_list.push_back(aggregate_info);
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/bgp/routing-instance/route_aggregator.h
Expand Up @@ -199,8 +199,8 @@ 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;
virtual bool FillAggregateRouteInfo(AggregateRouteEntriesInfo *info,
bool summary) const;

private:
class DeleteActor;
Expand Down
190 changes: 144 additions & 46 deletions src/bgp/routing-instance/show_route_aggregate.cc
Expand Up @@ -4,59 +4,54 @@

#include "bgp/bgp_show_handler.h"

#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>

#include "bgp/bgp_server.h"
#include "bgp/bgp_show_handler.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/route_aggregator.h"
#include "bgp/routing-instance/route_aggregate_internal_types.h"
#include "bgp/routing-instance/route_aggregate_types.h"

using boost::assign::list_of;
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;
static bool FillRouteAggregateInfoList(const BgpSandeshContext *bsc,
bool summary, uint32_t page_limit, uint32_t iter_limit,
const string &start_instance, const string &search_string,
vector<AggregateRouteEntriesInfo> *are_list, string *next_instance) {
RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();

RoutingInstanceMgr::const_name_iterator it =
rim->name_clower_bound(data->next_entry);
rim->name_clower_bound(start_instance);
for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
RoutingInstance *rinstance = it->second;
AggregateRouteEntriesInfo info;
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);
RoutingInstance *rtinstance = it->second;

vector<Address::Family> families =
list_of(Address::INET)(Address::INET6);
BOOST_FOREACH(Address::Family family, families) {
const BgpTable *table =
static_cast<const BgpTable *>(rtinstance->GetTable(family));
if (!table)
continue;
if (!search_string.empty() &&
(table->name().find(search_string) == string::npos) &&
(search_string != "deleted" || !table->IsDeleted())) {
continue;
}

IRouteAggregator *iroute_aggregator =
rtinstance->route_aggregator(family);
if (!iroute_aggregator)
continue;
AggregateRouteEntriesInfo info;
if (!iroute_aggregator->FillAggregateRouteInfo(&info, summary))
continue;
are_list->push_back(info);
}

if (data->show_list.size() >= page_limit)
if (are_list->size() >= page_limit)
break;
if (iter_count >= iter_limit)
break;
Expand All @@ -68,21 +63,76 @@ bool BgpShowHandler<ShowRouteAggregateReq, ShowRouteAggregateReqIterate,

// 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);
bool done = are_list->size() >= page_limit;
*next_instance = it->second->name();
return done;
}

// Specialization of BgpShowHandler<>::FillShowList.
//
// Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
//
template <>
void BgpShowHandler<ShowRouteAggregateReq, ShowRouteAggregateReqIterate,
ShowRouteAggregateResp, AggregateRouteEntriesInfo>::FillShowList(
ShowRouteAggregateResp *resp,
const vector<AggregateRouteEntriesInfo> &show_list) {
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;
string next_instance;
bool done = FillRouteAggregateInfoList(bsc, false, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_instance);
if (!next_instance.empty())
SaveContextToData(next_instance, done, data);
return done;
}

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

//
// Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
//
template <>
bool BgpShowHandler<ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate, ShowRouteAggregateSummaryResp,
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;
string next_instance;
bool done = FillRouteAggregateInfoList(bsc, true, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_instance);
if (!next_instance.empty())
SaveContextToData(next_instance, done, data);
return done;
}

//
// Specialization of BgpShowHandler<>::FillShowList for summary introspect.
//
template <>
void BgpShowHandler<ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate, ShowRouteAggregateSummaryResp,
AggregateRouteEntriesInfo>::FillShowList(
ShowRouteAggregateSummaryResp *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;
Expand Down Expand Up @@ -127,3 +177,51 @@ void ShowRouteAggregateReqIterate::HandleRequest() const {
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}

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

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

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

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

0 comments on commit 666d868

Please sign in to comment.