OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
show_path_resolver.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"
13 
14 using contrail::regex;
17 using std::string;
18 using std::vector;
19 
20 //
21 // Fill in information for list of path resolvers.
22 //
23 // Allows regular and summary introspect to share code.
24 //
26  bool summary, uint32_t page_limit, uint32_t iter_limit,
27  const string &start_instance, const string &search_string,
28  vector<ShowPathResolver> *spr_list, string *next_instance) {
29  regex search_expr(search_string);
32  rim->name_clower_bound(start_instance);
33  for (uint32_t iter_count = 0; it1 != rim->name_cend();
34  ++it1, ++iter_count) {
35  const RoutingInstance *rtinstance = it1->second;
36  for (RoutingInstance::RouteTableList::const_iterator it2 =
37  rtinstance->GetTables().begin();
38  it2 != rtinstance->GetTables().end(); ++it2, ++iter_count) {
39  const BgpTable *table = it2->second;
40  if ((!regex_search(table->name(), search_expr)) &&
41  (search_string != "deleted" || !table->IsDeleted())) {
42  continue;
43  }
44  const PathResolver *path_resolver = table->path_resolver();
45  if (!path_resolver)
46  continue;
47  ShowPathResolver spr;
48  path_resolver->FillShowInfo(&spr, summary);
49  if (spr.get_path_count() == 0 &&
50  spr.get_modified_path_count() == 0 &&
51  spr.get_nexthop_count() == 0 &&
52  spr.get_modified_nexthop_count() == 0)
53  continue;
54  spr_list->push_back(spr);
55  }
56  if (spr_list->size() >= page_limit)
57  break;
58  if (iter_count >= iter_limit)
59  break;
60  }
61 
62  // All done if we've looked at all instances.
63  if (it1 == rim->name_cend() || ++it1 == rim->name_end())
64  return true;
65 
66  // Return true if we've reached the page limit, false if we've reached the
67  // iteration limit.
68  bool done = spr_list->size() >= page_limit;
69  *next_instance = it1->second->name();
70  return done;
71 }
72 
73 //
74 // Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
75 //
76 template <>
77 bool BgpShowHandler<ShowPathResolverReq, ShowPathResolverReqIterate,
78  ShowPathResolverResp, ShowPathResolver>::CallbackCommon(
79  const BgpSandeshContext *bsc, Data *data) {
80  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
81  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
82  string next_instance;
83  bool done = FillPathResolverInfoList(bsc, false, page_limit, iter_limit,
84  data->next_entry, data->search_string, &data->show_list,
85  &next_instance);
86  if (!next_instance.empty())
87  SaveContextToData(next_instance, done, data);
88  return done;
89 }
90 
91 //
92 // Specialization of BgpShowHandler<>::FillShowList for regular introspect.
93 //
94 template <>
95 void BgpShowHandler<ShowPathResolverReq,
96  ShowPathResolverReqIterate, ShowPathResolverResp,
97  ShowPathResolver>::FillShowList(ShowPathResolverResp *resp,
98  const vector<ShowPathResolver> &show_list) {
99  resp->set_resolvers(show_list);
100 }
101 
102 //
103 // Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
104 //
105 template <>
106 bool BgpShowHandler<ShowPathResolverSummaryReq,
107  ShowPathResolverSummaryReqIterate, ShowPathResolverSummaryResp,
108  ShowPathResolver>::CallbackCommon(
109  const BgpSandeshContext *bsc, Data *data) {
110  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
111  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
112  string next_instance;
113  bool done = FillPathResolverInfoList(bsc, true, page_limit, iter_limit,
114  data->next_entry, data->search_string, &data->show_list,
115  &next_instance);
116  if (!next_instance.empty())
117  SaveContextToData(next_instance, done, data);
118  return done;
119 }
120 
121 //
122 // Specialization of BgpShowHandler<>::FillShowList for summary introspect.
123 //
124 template <>
125 void BgpShowHandler<ShowPathResolverSummaryReq,
126  ShowPathResolverSummaryReqIterate, ShowPathResolverSummaryResp,
127  ShowPathResolver>::FillShowList(ShowPathResolverSummaryResp *resp,
128  const vector<ShowPathResolver> &show_list) {
129  resp->set_resolvers(show_list);
130 }
131 
132 //
133 // Handler for ShowPathResolverReq.
134 //
135 void ShowPathResolverReq::HandleRequest() const {
136  RequestPipeline::PipeSpec ps(this);
139 
140  s1.taskId_ = scheduler->GetTaskId("bgp::ResolverNexthop");
141  s1.cbFn_ = boost::bind(&BgpShowHandler<
142  ShowPathResolverReq,
143  ShowPathResolverReqIterate,
144  ShowPathResolverResp,
145  ShowPathResolver>::Callback, _1, _2, _3, _4, _5);
147  ShowPathResolverReq,
148  ShowPathResolverReqIterate,
149  ShowPathResolverResp,
150  ShowPathResolver>::CreateData;
151  s1.instances_.push_back(0);
152  ps.stages_.push_back(s1);
153  RequestPipeline rp(ps);
154 }
155 
156 //
157 // Handler for ShowPathResolverReqIterate.
158 //
159 void ShowPathResolverReqIterate::HandleRequest() const {
160  RequestPipeline::PipeSpec ps(this);
163 
164  s1.taskId_ = scheduler->GetTaskId("bgp::ResolverNexthop");
165  s1.cbFn_ = boost::bind(&BgpShowHandler<
166  ShowPathResolverReq,
167  ShowPathResolverReqIterate,
168  ShowPathResolverResp,
169  ShowPathResolver>::CallbackIterate, _1, _2, _3, _4, _5);
171  ShowPathResolverReq,
172  ShowPathResolverReqIterate,
173  ShowPathResolverResp,
174  ShowPathResolver>::CreateData;
175  s1.instances_.push_back(0);
176  ps.stages_.push_back(s1);
177  RequestPipeline rp(ps);
178 }
179 
180 //
181 // Handler for ShowPathResolverSummaryReq.
182 //
183 void ShowPathResolverSummaryReq::HandleRequest() const {
184  RequestPipeline::PipeSpec ps(this);
187 
188  s1.taskId_ = scheduler->GetTaskId("bgp::ResolverNexthop");
189  s1.cbFn_ = boost::bind(&BgpShowHandler<
190  ShowPathResolverSummaryReq,
191  ShowPathResolverSummaryReqIterate,
192  ShowPathResolverSummaryResp,
193  ShowPathResolver>::Callback, _1, _2, _3, _4, _5);
195  ShowPathResolverSummaryReq,
196  ShowPathResolverSummaryReqIterate,
197  ShowPathResolverSummaryResp,
198  ShowPathResolver>::CreateData;
199  s1.instances_.push_back(0);
200  ps.stages_.push_back(s1);
201  RequestPipeline rp(ps);
202 }
203 
204 //
205 // Handler for ShowPathResolverSummaryReqIterate.
206 //
207 void ShowPathResolverSummaryReqIterate::HandleRequest() const {
208  RequestPipeline::PipeSpec ps(this);
211 
212  s1.taskId_ = scheduler->GetTaskId("bgp::ResolverNexthop");
213  s1.cbFn_ = boost::bind(&BgpShowHandler<
214  ShowPathResolverSummaryReq,
215  ShowPathResolverSummaryReqIterate,
216  ShowPathResolverSummaryResp,
217  ShowPathResolver>::CallbackIterate, _1, _2, _3, _4, _5);
219  ShowPathResolverSummaryReq,
220  ShowPathResolverSummaryReqIterate,
221  ShowPathResolverSummaryResp,
222  ShowPathResolver>::CreateData;
223  s1.instances_.push_back(0);
224  ps.stages_.push_back(s1);
225  RequestPipeline rp(ps);
226 }
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
void FillShowInfo(ShowPathResolver *spr, bool summary) const
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
bool IsDeleted() const
Definition: bgp_table.h:143
static bool FillPathResolverInfoList(const BgpSandeshContext *bsc, bool summary, uint32_t page_limit, uint32_t iter_limit, const string &start_instance, const string &search_string, vector< ShowPathResolver > *spr_list, string *next_instance)
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
name_iterator name_end()
PathResolver * path_resolver()
Definition: bgp_table.h:153