OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_show_ribout_statistics.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "bgp/bgp_show_handler.h"
6 
7 #include "base/regex.h"
8 #include "bgp/bgp_peer_internal_types.h"
9 #include "bgp/bgp_server.h"
10 #include "bgp/bgp_table.h"
12 
13 using contrail::regex;
16 using std::string;
17 using std::vector;
18 
19 //
20 // Specialization of BgpShowHandler<>::CallbackCommon.
21 //
22 // Note that we check the page and iteration limits only after examining all
23 // ribouts in all tables for a given routing instance. This simplifies things
24 // and requires to only keep track of the next instance rather than the next
25 // instance and next table.
26 //
27 template <>
28 bool BgpShowHandler<ShowRibOutStatisticsReq, ShowRibOutStatisticsReqIterate,
29  ShowRibOutStatisticsResp, ShowRibOutStatistics>::CallbackCommon(
30  const BgpSandeshContext *bsc, Data *data) {
31  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
32  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
34 
35  regex search_expr(data->search_string);
37  rim->name_clower_bound(data->next_entry);
38  for (uint32_t iter_count = 0; it1 != rim->name_cend(); ++it1) {
39  const RoutingInstance *rtinstance = it1->second;
40  for (RoutingInstance::RouteTableList::const_iterator it2 =
41  rtinstance->GetTables().begin();
42  it2 != rtinstance->GetTables().end(); ++it2, ++iter_count) {
43  const BgpTable *table = it2->second;
44  if (!regex_search(table->name(), search_expr))
45  continue;
46  table->FillRibOutStatisticsInfo(&data->show_list);
47  }
48  if (data->show_list.size() >= page_limit)
49  break;
50  if (iter_count >= iter_limit)
51  break;
52  }
53 
54  // All done if we've looked at all instances.
55  if (it1 == rim->name_cend() || ++it1 == rim->name_end())
56  return true;
57 
58  // Return true if we've reached the page limit, false if we've reached the
59  // iteration limit.
60  bool done = data->show_list.size() >= page_limit;
61  SaveContextToData(it1->second->name(), done, data);
62  return done;
63 }
64 
65 //
66 // Specialization of BgpShowHandler<>::FillShowList.
67 //
68 template <>
69 void BgpShowHandler<ShowRibOutStatisticsReq, ShowRibOutStatisticsReqIterate,
70  ShowRibOutStatisticsResp, ShowRibOutStatistics>::FillShowList(
71  ShowRibOutStatisticsResp *resp,
72  const vector<ShowRibOutStatistics> &show_list) {
73  resp->set_ribouts(show_list);
74 }
75 
76 //
77 // Handler for ShowRibOutStatisticsReq.
78 //
79 void ShowRibOutStatisticsReq::HandleRequest() const {
83 
84  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
85  s1.cbFn_ = boost::bind(&BgpShowHandler<
86  ShowRibOutStatisticsReq,
87  ShowRibOutStatisticsReqIterate,
88  ShowRibOutStatisticsResp,
89  ShowRibOutStatistics>::Callback, _1, _2, _3, _4, _5);
91  ShowRibOutStatisticsReq,
92  ShowRibOutStatisticsReqIterate,
93  ShowRibOutStatisticsResp,
94  ShowRibOutStatistics>::CreateData;
95  s1.instances_.push_back(0);
96  ps.stages_.push_back(s1);
97  RequestPipeline rp(ps);
98 }
99 
100 //
101 // Handler for ShowRibOutStatisticsReqIterate.
102 //
103 void ShowRibOutStatisticsReqIterate::HandleRequest() const {
104  RequestPipeline::PipeSpec ps(this);
107 
108  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
109  s1.cbFn_ = boost::bind(&BgpShowHandler<
110  ShowRibOutStatisticsReq,
111  ShowRibOutStatisticsReqIterate,
112  ShowRibOutStatisticsResp,
113  ShowRibOutStatistics>::CallbackIterate, _1, _2, _3, _4, _5);
115  ShowRibOutStatisticsReq,
116  ShowRibOutStatisticsReqIterate,
117  ShowRibOutStatisticsResp,
118  ShowRibOutStatistics>::CreateData;
119  s1.instances_.push_back(0);
120  ps.stages_.push_back(s1);
121  RequestPipeline rp(ps);
122 }
std::vector< int > instances_
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
const_name_iterator name_cend()
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:102
int GetTaskId(const std::string &name)
Definition: task.cc:856
RouteTableList & GetTables()
static bool regex_match(const std::string &input, const regex &regex)
Definition: regex.h:34
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
void FillRibOutStatisticsInfo(std::vector< ShowRibOutStatistics > *sros_list) const
Definition: bgp_table.cc:1146
name_iterator name_end()