OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_show_evpn_table.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_evpn.h"
9 #include "bgp/bgp_peer_internal_types.h"
10 #include "bgp/bgp_server.h"
11 #include "bgp/evpn/evpn_table.h"
13 
14 using contrail::regex;
17 using std::string;
18 using std::vector;
19 
20 //
21 // Used by EvpnManager::FillShowInfo for sorting.
22 // Note that the declaration is auto-generated by sandesh compiler.
23 //
24 bool ShowEvpnMcastLeaf::operator<(const ShowEvpnMcastLeaf &rhs) const {
25  return get_address() < rhs.get_address();
26 }
27 
28 //
29 // Fill in information for an evpn table.
30 //
31 static void FillEvpnTableInfo(ShowEvpnTable *sevt,
32  const BgpSandeshContext *bsc, const EvpnTable *table, bool summary) {
33  sevt->set_name(table->name());
34  sevt->set_deleted(table->IsDeleted());
35  sevt->set_deleted_at(
37  sevt->set_mac_routes(table->mac_route_count());
38  sevt->set_unique_mac_routes(table->unique_mac_route_count());
39  sevt->set_im_routes(table->im_route_count());
40  sevt->set_ip_routes(table->ip_route_count());
41 
42  if (summary || table->IsVpnTable() || !table->GetEvpnManager())
43  return;
44  table->GetEvpnManager()->FillShowInfo(sevt);
45 }
46 
47 //
48 // Fill in information for list of evpn tables.
49 //
50 // Allows regular and summary introspect to share code.
51 //
53  bool summary, uint32_t page_limit, uint32_t iter_limit,
54  const string &start_instance, const string &search_string,
55  vector<ShowEvpnTable> *sevt_list, string *next_instance) {
56  regex search_expr(search_string);
59  rim->name_clower_bound(start_instance);
60  for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
61  const RoutingInstance *rtinstance = it->second;
62  const EvpnTable *table =
63  static_cast<const EvpnTable *>(rtinstance->GetTable(Address::EVPN));
64  if (!table)
65  continue;
66  if ((!regex_search(table->name(), search_expr)) &&
67  (search_string != "deleted" || !table->IsDeleted())) {
68  continue;
69  }
70  ShowEvpnTable sevt;
71  FillEvpnTableInfo(&sevt, bsc, table, summary);
72  sevt_list->push_back(sevt);
73  if (sevt_list->size() >= page_limit)
74  break;
75  if (iter_count >= iter_limit)
76  break;
77  }
78 
79  // All done if we've looked at all instances.
80  if (it == rim->name_cend() || ++it == rim->name_end())
81  return true;
82 
83  // Return true if we've reached the page limit, false if we've reached the
84  // iteration limit.
85  bool done = sevt_list->size() >= page_limit;
86  *next_instance = it->second->name();
87  return done;
88 }
89 
90 //
91 // Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
92 //
93 template <>
94 bool BgpShowHandler<ShowEvpnTableReq, ShowEvpnTableReqIterate,
95  ShowEvpnTableResp, ShowEvpnTable>::CallbackCommon(
96  const BgpSandeshContext *bsc, Data *data) {
97  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
98  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
99  string next_instance;
100  bool done = FillEvpnTableInfoList(bsc, false, page_limit, iter_limit,
101  data->next_entry, data->search_string, &data->show_list,
102  &next_instance);
103  if (!next_instance.empty())
104  SaveContextToData(next_instance, done, data);
105  return done;
106 }
107 
108 //
109 // Specialization of BgpShowHandler<>::FillShowList for regular introspect.
110 //
111 template <>
112 void BgpShowHandler<ShowEvpnTableReq, ShowEvpnTableReqIterate,
113  ShowEvpnTableResp, ShowEvpnTable>::FillShowList(
114  ShowEvpnTableResp *resp, const vector<ShowEvpnTable> &show_list) {
115  resp->set_tables(show_list);
116 }
117 
118 //
119 // Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
120 //
121 template <>
122 bool BgpShowHandler<ShowEvpnTableSummaryReq, ShowEvpnTableSummaryReqIterate,
123  ShowEvpnTableSummaryResp, ShowEvpnTable>::CallbackCommon(
124  const BgpSandeshContext *bsc, Data *data) {
125  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
126  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
127  string next_instance;
128  bool done = FillEvpnTableInfoList(bsc, true, page_limit, iter_limit,
129  data->next_entry, data->search_string, &data->show_list,
130  &next_instance);
131  if (!next_instance.empty())
132  SaveContextToData(next_instance, done, data);
133  return done;
134 }
135 
136 //
137 // Specialization of BgpShowHandler<>::FillShowList for summary introspect.
138 //
139 template <>
140 void BgpShowHandler<ShowEvpnTableSummaryReq, ShowEvpnTableSummaryReqIterate,
141  ShowEvpnTableSummaryResp, ShowEvpnTable>::FillShowList(
142  ShowEvpnTableSummaryResp *resp, const vector<ShowEvpnTable> &show_list) {
143  resp->set_tables(show_list);
144 }
145 
146 //
147 // Handler for ShowEvpnTableReq.
148 // Schedules the callback to run in Task ("db::DBTable", 0) so that multicast
149 // data structures in EvpnManager can be accessed safely.
150 //
151 void ShowEvpnTableReq::HandleRequest() const {
152  RequestPipeline::PipeSpec ps(this);
155 
156  s1.taskId_ = scheduler->GetTaskId("db::DBTable");
157  s1.cbFn_ = boost::bind(&BgpShowHandler<
158  ShowEvpnTableReq,
159  ShowEvpnTableReqIterate,
160  ShowEvpnTableResp,
161  ShowEvpnTable>::Callback, _1, _2, _3, _4, _5);
163  ShowEvpnTableReq,
164  ShowEvpnTableReqIterate,
165  ShowEvpnTableResp,
166  ShowEvpnTable>::CreateData;
167  s1.instances_.push_back(0);
168  ps.stages_.push_back(s1);
169  RequestPipeline rp(ps);
170 }
171 
172 //
173 // Handler for ShowEvpnTableReqIterate.
174 // Schedules the callback to run in Task ("db::DBTable", 0) so that multicast
175 // data structures in EvpnManager can be accessed safely.
176 //
177 void ShowEvpnTableReqIterate::HandleRequest() const {
178  RequestPipeline::PipeSpec ps(this);
181 
182  s1.taskId_ = scheduler->GetTaskId("db::DBTable");
183  s1.cbFn_ = boost::bind(&BgpShowHandler<
184  ShowEvpnTableReq,
185  ShowEvpnTableReqIterate,
186  ShowEvpnTableResp,
187  ShowEvpnTable>::CallbackIterate, _1, _2, _3, _4, _5);
189  ShowEvpnTableReq,
190  ShowEvpnTableReqIterate,
191  ShowEvpnTableResp,
192  ShowEvpnTable>::CreateData;
193  s1.instances_.push_back(0);
194  ps.stages_.push_back(s1);
195  RequestPipeline rp(ps);
196 }
197 
198 //
199 // Handler for ShowEvpnTableSummaryReq.
200 // Schedules the callback to run in Task ("db::DBTable", 0) so that multicast
201 // data structures in EvpnManager can be accessed safely. This is not really
202 // necessary for summary requests, but we do this for consistency with regular
203 // requests.
204 //
205 void ShowEvpnTableSummaryReq::HandleRequest() const {
206  RequestPipeline::PipeSpec ps(this);
209 
210  s1.taskId_ = scheduler->GetTaskId("db::DBTable");
211  s1.cbFn_ = boost::bind(&BgpShowHandler<
212  ShowEvpnTableSummaryReq,
213  ShowEvpnTableSummaryReqIterate,
214  ShowEvpnTableSummaryResp,
215  ShowEvpnTable>::Callback, _1, _2, _3, _4, _5);
217  ShowEvpnTableSummaryReq,
218  ShowEvpnTableSummaryReqIterate,
219  ShowEvpnTableSummaryResp,
220  ShowEvpnTable>::CreateData;
221  s1.instances_.push_back(0);
222  ps.stages_.push_back(s1);
223  RequestPipeline rp(ps);
224 }
225 
226 //
227 // Handler for ShowEvpnTableSummaryReqIterate.
228 // Schedules the callback to run in Task ("db::DBTable", 0) so that multicast
229 // data structures in EvpnManager can be accessed safely. This is not really
230 // necessary for summary requests, but we do this for consistency with regular
231 // requests.
232 //
233 void ShowEvpnTableSummaryReqIterate::HandleRequest() const {
234  RequestPipeline::PipeSpec ps(this);
237 
238  s1.taskId_ = scheduler->GetTaskId("db::DBTable");
239  s1.cbFn_ = boost::bind(&BgpShowHandler<
240  ShowEvpnTableSummaryReq,
241  ShowEvpnTableSummaryReqIterate,
242  ShowEvpnTableSummaryResp,
243  ShowEvpnTable>::CallbackIterate, _1, _2, _3, _4, _5);
245  ShowEvpnTableSummaryReq,
246  ShowEvpnTableSummaryReqIterate,
247  ShowEvpnTableSummaryResp,
248  ShowEvpnTable>::CreateData;
249  s1.instances_.push_back(0);
250  ps.stages_.push_back(s1);
251  RequestPipeline rp(ps);
252 }
std::vector< int > instances_
bool operator<(const WaterMarkInfo &lhs, const WaterMarkInfo &rhs)
Definition: watermark.h:32
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
static bool FillEvpnTableInfoList(const BgpSandeshContext *bsc, bool summary, uint32_t page_limit, uint32_t iter_limit, const string &start_instance, const string &search_string, vector< ShowEvpnTable > *sevt_list, string *next_instance)
BgpServer * bgp_server
Definition: bgp_sandesh.h:46
const_name_iterator name_cend()
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:102
EvpnManager * GetEvpnManager()
Definition: evpn_table.cc:360
static void FillEvpnTableInfo(ShowEvpnTable *sevt, const BgpSandeshContext *bsc, const EvpnTable *table, bool summary)
int GetTaskId(const std::string &name)
Definition: task.cc:856
uint64_t unique_mac_route_count() const
Definition: evpn_table.h:63
static bool regex_match(const std::string &input, const regex &regex)
Definition: regex.h:34
bool IsDeleted() const
Definition: bgp_table.h:143
virtual bool IsVpnTable() const
Definition: evpn_table.h:36
static TaskScheduler * GetInstance()
Definition: task.cc:547
uint32_t iter_limit() const
Definition: bgp_sandesh.h:65
uint64_t im_route_count() const
Definition: evpn_table.h:64
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
void FillShowInfo(ShowEvpnTable *sevt) const
Fill information for introspect command. Note that all IM routes are always in partition 0...
Definition: bgp_evpn.cc:1629
uint32_t page_limit() const
Definition: bgp_sandesh.h:63
LifetimeActor * deleter()
Definition: bgp_table.cc:1108
name_iterator name_end()
uint64_t mac_route_count() const
Definition: evpn_table.h:62
const uint64_t delete_time_stamp_usecs() const
Definition: lifetime.h:138
uint64_t ip_route_count() const
Definition: evpn_table.h:65
static std::string UTCUsecToString(uint64_t tstamp)
Definition: time_util.h:54