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