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