OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
show_route_aggregate.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <boost/foreach.hpp>
6 #include <boost/assign/list_of.hpp>
7 
8 #include "base/regex.h"
9 #include "bgp/bgp_server.h"
10 #include "bgp/bgp_show_handler.h"
13 #include "bgp/routing-instance/route_aggregate_internal_types.h"
14 #include "bgp/routing-instance/route_aggregate_types.h"
15 
16 using boost::assign::list_of;
17 using contrail::regex;
20 using std::string;
21 using std::vector;
22 
24  bool summary, uint32_t page_limit, uint32_t iter_limit,
25  const string &start_instance, const string &search_string,
26  vector<AggregateRouteEntriesInfo> *are_list, string *next_instance) {
27  regex search_expr(search_string);
30  rim->name_clower_bound(start_instance);
31  for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
32  RoutingInstance *rtinstance = it->second;
33 
34  vector<Address::Family> families =
35  list_of(Address::INET)(Address::INET6);
36  BOOST_FOREACH(Address::Family family, families) {
37  const BgpTable *table =
38  static_cast<const BgpTable *>(rtinstance->GetTable(family));
39  if (!table)
40  continue;
41  if ((!regex_search(table->name(), search_expr)) &&
42  (search_string != "deleted" || !table->IsDeleted())) {
43  continue;
44  }
45 
46  IRouteAggregator *iroute_aggregator =
47  rtinstance->route_aggregator(family);
48  if (!iroute_aggregator)
49  continue;
50  AggregateRouteEntriesInfo info;
51  if (!iroute_aggregator->FillAggregateRouteInfo(&info, summary))
52  continue;
53  are_list->push_back(info);
54  }
55 
56  if (are_list->size() >= page_limit)
57  break;
58  if (iter_count >= iter_limit)
59  break;
60  }
61 
62  // All done if we've looked at all instances.
63  if (it == rim->name_cend() || ++it == rim->name_cend())
64  return true;
65 
66  // Return true if we've reached the page limit, false if we've reached the
67  // iteration limit.
68  bool done = are_list->size() >= page_limit;
69  *next_instance = it->second->name();
70  return done;
71 }
72 
73 //
74 // Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
75 //
76 template <>
77 bool BgpShowHandler<ShowRouteAggregateReq,
78  ShowRouteAggregateReqIterate, ShowRouteAggregateResp,
79  AggregateRouteEntriesInfo>::CallbackCommon(
80  const BgpSandeshContext *bsc, Data *data) {
81  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
82  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
83  string next_instance;
84  bool done = FillRouteAggregateInfoList(bsc, false, page_limit, iter_limit,
85  data->next_entry, data->search_string, &data->show_list,
86  &next_instance);
87  if (!next_instance.empty())
88  SaveContextToData(next_instance, done, data);
89  return done;
90 }
91 
92 //
93 // Specialization of BgpShowHandler<>::FillShowList for regular introspect.
94 //
95 template <>
96 void BgpShowHandler<ShowRouteAggregateReq,
97  ShowRouteAggregateReqIterate, ShowRouteAggregateResp,
98  AggregateRouteEntriesInfo>::FillShowList(
99  ShowRouteAggregateResp *resp,
100  const vector<AggregateRouteEntriesInfo> &show_list) {
101  resp->set_aggregate_route_entries(show_list);
102 }
103 
104 //
105 // Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
106 //
107 template <>
108 bool BgpShowHandler<ShowRouteAggregateSummaryReq,
109  ShowRouteAggregateSummaryReqIterate, ShowRouteAggregateSummaryResp,
110  AggregateRouteEntriesInfo>::CallbackCommon(
111  const BgpSandeshContext *bsc, Data *data) {
112  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
113  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
114  string next_instance;
115  bool done = FillRouteAggregateInfoList(bsc, true, page_limit, iter_limit,
116  data->next_entry, data->search_string, &data->show_list,
117  &next_instance);
118  if (!next_instance.empty())
119  SaveContextToData(next_instance, done, data);
120  return done;
121 }
122 
123 //
124 // Specialization of BgpShowHandler<>::FillShowList for summary introspect.
125 //
126 template <>
127 void BgpShowHandler<ShowRouteAggregateSummaryReq,
128  ShowRouteAggregateSummaryReqIterate, ShowRouteAggregateSummaryResp,
129  AggregateRouteEntriesInfo>::FillShowList(
130  ShowRouteAggregateSummaryResp *resp,
131  const vector<AggregateRouteEntriesInfo> &show_list) {
132  resp->set_aggregate_route_entries(show_list);
133 }
134 
135 //
136 // Handler for ShowRouteAggregateReq.
137 //
138 void ShowRouteAggregateReq::HandleRequest() const {
139  RequestPipeline::PipeSpec ps(this);
142 
143  s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
144  s1.cbFn_ = boost::bind(&BgpShowHandler<
145  ShowRouteAggregateReq,
146  ShowRouteAggregateReqIterate,
147  ShowRouteAggregateResp,
148  AggregateRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
150  ShowRouteAggregateReq,
151  ShowRouteAggregateReqIterate,
152  ShowRouteAggregateResp,
153  AggregateRouteEntriesInfo>::CreateData;
154  s1.instances_.push_back(0);
155  ps.stages_.push_back(s1);
156  RequestPipeline rp(ps);
157 }
158 
159 //
160 // Handler for ShowRouteAggregateReqIterate.
161 //
162 void ShowRouteAggregateReqIterate::HandleRequest() const {
163  RequestPipeline::PipeSpec ps(this);
166 
167  s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
168  s1.cbFn_ = boost::bind(&BgpShowHandler<
169  ShowRouteAggregateReq,
170  ShowRouteAggregateReqIterate,
171  ShowRouteAggregateResp,
172  AggregateRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
174  ShowRouteAggregateReq,
175  ShowRouteAggregateReqIterate,
176  ShowRouteAggregateResp,
177  AggregateRouteEntriesInfo>::CreateData;
178  s1.instances_.push_back(0);
179  ps.stages_.push_back(s1);
180  RequestPipeline rp(ps);
181 }
182 
183 //
184 // Handler for ShowRouteAggregateSummaryReq.
185 //
186 void ShowRouteAggregateSummaryReq::HandleRequest() const {
187  RequestPipeline::PipeSpec ps(this);
190 
191  s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
192  s1.cbFn_ = boost::bind(&BgpShowHandler<
193  ShowRouteAggregateSummaryReq,
194  ShowRouteAggregateSummaryReqIterate,
195  ShowRouteAggregateSummaryResp,
196  AggregateRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
198  ShowRouteAggregateSummaryReq,
199  ShowRouteAggregateSummaryReqIterate,
200  ShowRouteAggregateSummaryResp,
201  AggregateRouteEntriesInfo>::CreateData;
202  s1.instances_.push_back(0);
203  ps.stages_.push_back(s1);
204  RequestPipeline rp(ps);
205 }
206 
207 //
208 // Handler for ShowRouteAggregateSummaryReqIterate.
209 //
210 void ShowRouteAggregateSummaryReqIterate::HandleRequest() const {
211  RequestPipeline::PipeSpec ps(this);
214 
215  s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
216  s1.cbFn_ = boost::bind(&BgpShowHandler<
217  ShowRouteAggregateSummaryReq,
218  ShowRouteAggregateSummaryReqIterate,
219  ShowRouteAggregateSummaryResp,
220  AggregateRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
222  ShowRouteAggregateSummaryReq,
223  ShowRouteAggregateSummaryReqIterate,
224  ShowRouteAggregateSummaryResp,
225  AggregateRouteEntriesInfo>::CreateData;
226  s1.instances_.push_back(0);
227  ps.stages_.push_back(s1);
228  RequestPipeline rp(ps);
229 }
std::vector< int > instances_
BgpTable * GetTable(Address::Family fmly)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
BgpServer * bgp_server
Definition: bgp_sandesh.h:46
Family
Definition: address.h:24
const_name_iterator name_cend()
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:102
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)
int GetTaskId(const std::string &name)
Definition: task.cc:856
static bool regex_match(const std::string &input, const regex &regex)
Definition: regex.h:34
bool IsDeleted() const
Definition: bgp_table.h:143
IRouteAggregator * route_aggregator(Address::Family family) const
static TaskScheduler * GetInstance()
Definition: task.cc:547
uint32_t iter_limit() const
Definition: bgp_sandesh.h:65
RoutingInstanceList::const_iterator const_name_iterator
const_name_iterator name_clower_bound(const std::string &name)
std::vector< ShowT > show_list
const std::string & name() const
Definition: db_table.h:110
static bool regex_search(const std::string &input, const regex &regex)
Definition: regex.h:25
uint32_t page_limit() const
Definition: bgp_sandesh.h:63
virtual bool FillAggregateRouteInfo(AggregateRouteEntriesInfo *info, bool summary) const =0