OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_show_mvpn_project_manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "bgp/bgp_show_handler.h"
6 
7 #include <boost/foreach.hpp>
8 
9 #include <base/regex.h>
11 #include "bgp/bgp_peer_internal_types.h"
12 #include "bgp/bgp_mvpn.h"
13 #include "bgp/bgp_server.h"
14 #include "bgp/mvpn/mvpn_table.h"
16 
17 using contrail::regex;
20 using std::string;
21 using std::vector;
22 
23 //
24 // Fill in information for an ermvpn table.
25 //
26 static void FillMvpnProjectManagerInfo(ShowMvpnProjectManager *smm,
27  const BgpSandeshContext *bsc, const ErmVpnTable *table) {
28  smm->set_name(table->name());
29  const MvpnProjectManager *manager = table->mvpn_project_manager();
30  if (!manager)
31  return;
32 
33  size_t total_sg_states = 0;
34  BOOST_FOREACH(MvpnProjectManagerPartition *pm_partition,
35  manager->partitions()) {
36  total_sg_states += pm_partition->states().size();
37  }
38  smm->set_total_sg_states(total_sg_states);
39  smm->set_total_managers(table->routing_instance()->manager()->
40  GetMvpnProjectManagerCount(table->routing_instance()->name()));
41  smm->set_deleted(manager->deleted());
42  smm->set_deleted_at(
44 }
45 
46 //
47 // Specialization of BgpShowHandler<>::CallbackCommon.
48 //
49 template <>
50 bool BgpShowHandler<ShowMvpnProjectManagerReq, ShowMvpnProjectManagerReqIterate,
51  ShowMvpnProjectManagerResp, ShowMvpnProjectManager>::CallbackCommon(
52  const BgpSandeshContext *bsc, Data *data) {
53  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
54  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
56 
57  regex search_expr(data->search_string);
59  rim->name_clower_bound(data->next_entry);
60  for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
61  const RoutingInstance *rtinstance = it->second;
62  const ErmVpnTable *table = static_cast<const ErmVpnTable *>(
63  rtinstance->GetTable(Address::ERMVPN));
64  if (!table)
65  continue;
66  if ((!regex_search(table->name(), search_expr)) &&
67  (data->search_string != "deleted" || !table->IsDeleted())) {
68  continue;
69  }
70  ShowMvpnProjectManager smm;
71  FillMvpnProjectManagerInfo(&smm, bsc, table);
72  data->show_list.push_back(smm);
73  if (data->show_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_cend())
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 = data->show_list.size() >= page_limit;
86  SaveContextToData(it->second->name(), done, data);
87  return done;
88 }
89 
90 //
91 // Specialization of BgpShowHandler<>::FillShowList.
92 //
93 template <>
94 void BgpShowHandler<ShowMvpnProjectManagerReq, ShowMvpnProjectManagerReqIterate,
95  ShowMvpnProjectManagerResp, ShowMvpnProjectManager>::FillShowList(
96  ShowMvpnProjectManagerResp *resp,
97  const vector<ShowMvpnProjectManager> &show_list) {
98  resp->set_managers(show_list);
99 }
100 
101 //
102 // Handler for ShowMvpnProjectManagerReq.
103 //
104 void ShowMvpnProjectManagerReq::HandleRequest() const {
105  RequestPipeline::PipeSpec ps(this);
108 
109  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
110  s1.cbFn_ = boost::bind(&BgpShowHandler<
111  ShowMvpnProjectManagerReq,
112  ShowMvpnProjectManagerReqIterate,
113  ShowMvpnProjectManagerResp,
114  ShowMvpnProjectManager>::Callback, _1, _2, _3, _4, _5);
116  ShowMvpnProjectManagerReq,
117  ShowMvpnProjectManagerReqIterate,
118  ShowMvpnProjectManagerResp,
119  ShowMvpnProjectManager>::CreateData;
120  s1.instances_.push_back(0);
121  ps.stages_.push_back(s1);
122  RequestPipeline rp(ps);
123 }
124 
125 //
126 // Handler for ShowMvpnProjectManagerReqIterate.
127 //
128 void ShowMvpnProjectManagerReqIterate::HandleRequest() const {
129  RequestPipeline::PipeSpec ps(this);
132 
133  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
134  s1.cbFn_ = boost::bind(&BgpShowHandler<
135  ShowMvpnProjectManagerReq,
136  ShowMvpnProjectManagerReqIterate,
137  ShowMvpnProjectManagerResp,
138  ShowMvpnProjectManager>::CallbackIterate, _1, _2, _3, _4, _5);
140  ShowMvpnProjectManagerReq,
141  ShowMvpnProjectManagerReqIterate,
142  ShowMvpnProjectManagerResp,
143  ShowMvpnProjectManager>::CreateData;
144  s1.instances_.push_back(0);
145  ps.stages_.push_back(s1);
146  RequestPipeline rp(ps);
147 }
std::vector< int > instances_
const MvpnState::StatesMap & states() const
Definition: bgp_mvpn.h:377
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
const PartitionList & partitions() const
Definition: bgp_mvpn.h:439
BgpServer * bgp_server
Definition: bgp_sandesh.h:46
RoutingInstance * routing_instance()
Definition: bgp_table.h:148
MvpnProjectManager * mvpn_project_manager()
Definition: ermvpn_table.h:68
const_name_iterator name_cend()
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:102
const std::string & name() const
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
const LifetimeActor * deleter() const
Definition: bgp_mvpn.cc:110
RoutingInstanceList::const_iterator const_name_iterator
const_name_iterator name_clower_bound(const std::string &name)
std::vector< ShowT > show_list
static void FillMvpnProjectManagerInfo(ShowMvpnProjectManager *smm, const BgpSandeshContext *bsc, const ErmVpnTable *table)
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
const RoutingInstanceMgr * manager() const
uint32_t page_limit() const
Definition: bgp_sandesh.h:63
bool deleted() const
Definition: bgp_mvpn.cc:161
const uint64_t delete_time_stamp_usecs() const
Definition: lifetime.h:138
static std::string UTCUsecToString(uint64_t tstamp)
Definition: time_util.h:54