OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_show_route_summary.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 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 // Fill in information for a table.
21 //
22 static void FillRouteTableSummaryInfo(ShowRouteTableSummary *srts,
23  const BgpSandeshContext *bsc, const BgpTable *table) {
24  srts->set_name(table->name());
25  srts->set_deleted(table->IsDeleted());
26  srts->set_deleted_at(
28  srts->set_prefixes(table->Size());
29  srts->set_primary_paths(table->GetPrimaryPathCount());
30  srts->set_secondary_paths(table->GetSecondaryPathCount());
31  srts->set_infeasible_paths(table->GetInfeasiblePathCount());
32  srts->set_stale_paths(table->GetStalePathCount());
33  srts->set_llgr_stale_paths(table->GetLlgrStalePathCount());
34  srts->set_paths(srts->get_primary_paths() + srts->get_secondary_paths());
35  srts->set_walk_requests(table->walk_request_count());
36  srts->set_walk_again_requests(table->walk_again_count());
37  srts->set_actual_walks(table->walk_count());
38  srts->set_walk_completes(table->walk_complete_count());
39  srts->set_walk_cancels(table->walk_cancel_count());
40  size_t markers = 0;
41  srts->set_pending_updates(table->GetPendingRiboutsCount(&markers));
42  srts->set_markers(markers);
43  srts->set_listeners(table->GetListenerCount());
44  srts->set_walkers(table->walker_count());
45 }
46 
47 //
48 // Specialization of BgpShowHandler<>::CallbackCommon.
49 //
50 // Note that we check the page and iteration limits only after examining all
51 // tables for a given routing instance. This simplifies things and requires
52 // to only keep track of the next instance rather than the next instance and
53 // next table.
54 //
55 template <>
56 bool BgpShowHandler<ShowRouteSummaryReq, ShowRouteSummaryReqIterate,
57  ShowRouteSummaryResp, ShowRouteTableSummary>::CallbackCommon(
58  const BgpSandeshContext *bsc, Data *data) {
59  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
60  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
62 
63  regex search_expr(data->search_string);
65  rim->name_clower_bound(data->next_entry);
66  for (uint32_t iter_count = 0; it1 != rim->name_cend(); ++it1) {
67  const RoutingInstance *rtinstance = it1->second;
68  for (RoutingInstance::RouteTableList::const_iterator it2 =
69  rtinstance->GetTables().begin();
70  it2 != rtinstance->GetTables().end(); ++it2, ++iter_count) {
71  const BgpTable *table = it2->second;
72  if ((!regex_search(table->name(), search_expr)) &&
73  (data->search_string != "deleted" || !table->IsDeleted())) {
74  continue;
75  }
76  ShowRouteTableSummary srts;
77  FillRouteTableSummaryInfo(&srts, bsc, table);
78  data->show_list.push_back(srts);
79  }
80  if (data->show_list.size() >= page_limit)
81  break;
82  if (iter_count >= iter_limit)
83  break;
84  }
85 
86  // All done if we've looked at all instances.
87  if (it1 == rim->name_cend() || ++it1 == rim->name_end())
88  return true;
89 
90  // Return true if we've reached the page limit, false if we've reached the
91  // iteration limit.
92  bool done = data->show_list.size() >= page_limit;
93  SaveContextToData(it1->second->name(), done, data);
94  return done;
95 }
96 
97 //
98 // Specialization of BgpShowHandler<>::FillShowList.
99 //
100 template <>
101 void BgpShowHandler<ShowRouteSummaryReq, ShowRouteSummaryReqIterate,
102  ShowRouteSummaryResp, ShowRouteTableSummary>::FillShowList(
103  ShowRouteSummaryResp *resp,
104  const vector<ShowRouteTableSummary> &show_list) {
105  resp->set_tables(show_list);
106 }
107 
108 //
109 // Handler for ShowRouteSummaryReq.
110 //
111 void ShowRouteSummaryReq::HandleRequest() const {
112  RequestPipeline::PipeSpec ps(this);
115 
116  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
117  s1.cbFn_ = boost::bind(&BgpShowHandler<
118  ShowRouteSummaryReq,
119  ShowRouteSummaryReqIterate,
120  ShowRouteSummaryResp,
121  ShowRouteTableSummary>::Callback, _1, _2, _3, _4, _5);
123  ShowRouteSummaryReq,
124  ShowRouteSummaryReqIterate,
125  ShowRouteSummaryResp,
126  ShowRouteTableSummary>::CreateData;
127  s1.instances_.push_back(0);
128  ps.stages_.push_back(s1);
129  RequestPipeline rp(ps);
130 }
131 
132 //
133 // Handler for ShowRouteSummaryReqIterate.
134 //
135 void ShowRouteSummaryReqIterate::HandleRequest() const {
136  RequestPipeline::PipeSpec ps(this);
139 
140  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
141  s1.cbFn_ = boost::bind(&BgpShowHandler<
142  ShowRouteSummaryReq,
143  ShowRouteSummaryReqIterate,
144  ShowRouteSummaryResp,
145  ShowRouteTableSummary>::CallbackIterate, _1, _2, _3, _4, _5);
147  ShowRouteSummaryReq,
148  ShowRouteSummaryReqIterate,
149  ShowRouteSummaryResp,
150  ShowRouteTableSummary>::CreateData;
151  s1.instances_.push_back(0);
152  ps.stages_.push_back(s1);
153  RequestPipeline rp(ps);
154 }
uint64_t walk_again_count() const
Definition: db_table.h:136
std::vector< int > instances_
uint64_t walk_request_count() const
Definition: db_table.h:133
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
uint64_t walk_count() const
Definition: db_table.h:137
BgpServer * bgp_server
Definition: bgp_sandesh.h:46
const uint64_t GetLlgrStalePathCount() const
Definition: bgp_table.h:169
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
bool IsDeleted() const
Definition: bgp_table.h:143
uint64_t walk_complete_count() const
Definition: db_table.h:134
virtual size_t Size() const
Definition: db_table.cc:507
const uint64_t GetInfeasiblePathCount() const
Definition: bgp_table.h:165
static TaskScheduler * GetInstance()
Definition: task.cc:547
uint32_t iter_limit() const
Definition: bgp_sandesh.h:65
uint64_t walk_cancel_count() const
Definition: db_table.h:135
RoutingInstanceList::const_iterator const_name_iterator
const_name_iterator name_clower_bound(const std::string &name)
std::vector< ShowT > show_list
static void FillRouteTableSummaryInfo(ShowRouteTableSummary *srts, const BgpSandeshContext *bsc, const BgpTable *table)
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
size_t GetPendingRiboutsCount(size_t *markers) const
Definition: bgp_table.cc:1088
const uint64_t GetPrimaryPathCount() const
Definition: bgp_table.h:161
uint32_t page_limit() const
Definition: bgp_sandesh.h:63
size_t GetListenerCount() const
Definition: db_table.cc:238
LifetimeActor * deleter()
Definition: bgp_table.cc:1108
name_iterator name_end()
uint64_t walker_count() const
Definition: db_table.h:129
const uint64_t delete_time_stamp_usecs() const
Definition: lifetime.h:138
const uint64_t GetStalePathCount() const
Definition: bgp_table.h:168
const uint64_t GetSecondaryPathCount() const
Definition: bgp_table.h:162
static std::string UTCUsecToString(uint64_t tstamp)
Definition: time_util.h:54