OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
show_static_route.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "base/regex.h"
6 #include "bgp/bgp_config.h"
7 #include "bgp/bgp_server.h"
8 #include "bgp/bgp_show_handler.h"
9 #include "bgp/bgp_table.h"
12 #include "bgp/routing-instance/static_route_types.h"
13 
14 using contrail::regex;
17 using std::string;
18 using std::vector;
19 
21  const string &search_string,
22  const regex &search_expr,
23  StaticRouteEntriesInfo &info,
24  RoutingInstance *rtinstance) {
25  const BgpTable *table =
26  static_cast<const BgpTable *>(rtinstance->GetTable(family));
27  if (!table)
28  return false;
29  if ((!regex_search(table->name(), search_expr)) &&
30  (search_string != "deleted" || !table->IsDeleted())) {
31  return false;
32  }
33 
34  IStaticRouteMgr *imanager = rtinstance->static_route_mgr(family);
35  if (!imanager)
36  return false;
37  return imanager->FillStaticRouteInfo(rtinstance, &info);
38 }
39 
40 // Specialization of BgpShowHandler<>::CallbackCommon.
41 template <>
42 bool BgpShowHandler<ShowStaticRouteReq, ShowStaticRouteReqIterate,
43  ShowStaticRouteResp, StaticRouteEntriesInfo>::CallbackCommon(
44  const BgpSandeshContext *bsc, Data *data) {
45  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
46  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
48 
49  regex search_expr(data->search_string);
51  rim->name_clower_bound(data->next_entry);
52  for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
53  RoutingInstance *rinstance = it->second;
54  StaticRouteEntriesInfo info;
56  search_expr, info, rinstance)) {
57  data->show_list.push_back(info);
58  }
60  search_expr, info, rinstance)) {
61  data->show_list.push_back(info);
62  }
63 
64  if (data->show_list.size() >= page_limit)
65  break;
66  if (iter_count >= iter_limit)
67  break;
68  }
69 
70  // All done if we've looked at all instances.
71  if (it == rim->name_cend() || ++it == rim->name_cend())
72  return true;
73 
74  // Return true if we've reached the page limit, false if we've reached the
75  // iteration limit.
76  bool done = data->show_list.size() >= page_limit;
77  SaveContextToData(it->second->name(), done, data);
78  return done;
79 }
80 
81 // Specialization of BgpShowHandler<>::FillShowList.
82 template <>
83 void BgpShowHandler<ShowStaticRouteReq, ShowStaticRouteReqIterate,
84  ShowStaticRouteResp, StaticRouteEntriesInfo>::FillShowList(
85  ShowStaticRouteResp *resp,
86  const vector<StaticRouteEntriesInfo> &show_list) {
87  resp->set_static_route_entries(show_list);
88 }
89 
90 // Handler for ShowStaticRouteReq.
91 void ShowStaticRouteReq::HandleRequest() const {
95 
96  s1.taskId_ = scheduler->GetTaskId("bgp::StaticRoute");
97  s1.cbFn_ = boost::bind(&BgpShowHandler<
98  ShowStaticRouteReq,
99  ShowStaticRouteReqIterate,
100  ShowStaticRouteResp,
101  StaticRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
103  ShowStaticRouteReq,
104  ShowStaticRouteReqIterate,
105  ShowStaticRouteResp,
106  StaticRouteEntriesInfo>::CreateData;
107  s1.instances_.push_back(0);
108  ps.stages_.push_back(s1);
109  RequestPipeline rp(ps);
110 }
111 
112 //
113 // Handler for ShowStaticRouteReqIterate.
114 //
115 void ShowStaticRouteReqIterate::HandleRequest() const {
116  RequestPipeline::PipeSpec ps(this);
119 
120  s1.taskId_ = scheduler->GetTaskId("bgp::StaticRoute");
121  s1.cbFn_ = boost::bind(&BgpShowHandler<
122  ShowStaticRouteReq,
123  ShowStaticRouteReqIterate,
124  ShowStaticRouteResp,
125  StaticRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
127  ShowStaticRouteReq,
128  ShowStaticRouteReqIterate,
129  ShowStaticRouteResp,
130  StaticRouteEntriesInfo>::CreateData;
131  s1.instances_.push_back(0);
132  ps.stages_.push_back(s1);
133  RequestPipeline rp(ps);
134 }
std::vector< int > instances_
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
BgpServer * bgp_server
Definition: bgp_sandesh.h:46
Family
Definition: address.h:24
const_name_iterator name_cend()
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:102
virtual bool FillStaticRouteInfo(RoutingInstance *rtinstance, StaticRouteEntriesInfo *info) const =0
int GetTaskId(const std::string &name)
Definition: task.cc:856
static bool regex_match(const std::string &input, const regex &regex)
Definition: regex.h:34
bool IsDeleted() const
Definition: bgp_table.h:143
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
static bool FillStaticRouteInfo(Address::Family family, const string &search_string, const regex &search_expr, StaticRouteEntriesInfo &info, RoutingInstance *rtinstance)
uint32_t page_limit() const
Definition: bgp_sandesh.h:63
IStaticRouteMgr * static_route_mgr(Address::Family family)