OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_show_multicast_manager.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_peer_internal_types.h"
9 #include "bgp/bgp_multicast.h"
10 #include "bgp/bgp_server.h"
13 
14 using contrail::regex;
17 using std::string;
18 using std::vector;
19 
20 //
21 // Fill in information for an ermvpn table.
22 //
23 static void FillMulticastManagerInfo(ShowMulticastManager *smm,
24  const BgpSandeshContext *bsc, const ErmVpnTable *table) {
25  smm->set_name(table->name());
26  const McastTreeManager *manager = table->GetTreeManager();
27  if (!manager)
28  return;
29 
30  smm->set_deleted(manager->deleted());
31  smm->set_deleted_at(
33 
34  uint32_t total_trees = 0;
35  for (McastTreeManager::const_iterator it = manager->begin();
36  it != manager->end(); ++it) {
37  const McastManagerPartition *partition = *it;
38  total_trees += partition->size();
39  }
40  smm->set_total_trees(total_trees);
41 }
42 
43 //
44 // Specialization of BgpShowHandler<>::CallbackCommon.
45 //
46 template <>
47 bool BgpShowHandler<ShowMulticastManagerReq, ShowMulticastManagerReqIterate,
48  ShowMulticastManagerResp, ShowMulticastManager>::CallbackCommon(
49  const BgpSandeshContext *bsc, Data *data) {
50  uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
51  uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
53 
54  regex search_expr(data->search_string);
56  rim->name_clower_bound(data->next_entry);
57  for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
58  const RoutingInstance *rtinstance = it->second;
59  const ErmVpnTable *table = static_cast<const ErmVpnTable *>(
60  rtinstance->GetTable(Address::ERMVPN));
61  if (!table)
62  continue;
63  if ((!regex_search(table->name(), search_expr)) &&
64  (data->search_string != "deleted" || !table->IsDeleted())) {
65  continue;
66  }
67  ShowMulticastManager smm;
68  FillMulticastManagerInfo(&smm, bsc, table);
69  data->show_list.push_back(smm);
70  if (data->show_list.size() >= page_limit)
71  break;
72  if (iter_count >= iter_limit)
73  break;
74  }
75 
76  // All done if we've looked at all instances.
77  if (it == rim->name_cend() || ++it == rim->name_cend())
78  return true;
79 
80  // Return true if we've reached the page limit, false if we've reached the
81  // iteration limit.
82  bool done = data->show_list.size() >= page_limit;
83  SaveContextToData(it->second->name(), done, data);
84  return done;
85 }
86 
87 //
88 // Specialization of BgpShowHandler<>::FillShowList.
89 //
90 template <>
91 void BgpShowHandler<ShowMulticastManagerReq, ShowMulticastManagerReqIterate,
92  ShowMulticastManagerResp, ShowMulticastManager>::FillShowList(
93  ShowMulticastManagerResp *resp,
94  const vector<ShowMulticastManager> &show_list) {
95  resp->set_managers(show_list);
96 }
97 
98 //
99 // Handler for ShowMulticastManagerReq.
100 //
101 void ShowMulticastManagerReq::HandleRequest() const {
102  RequestPipeline::PipeSpec ps(this);
105 
106  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
107  s1.cbFn_ = boost::bind(&BgpShowHandler<
108  ShowMulticastManagerReq,
109  ShowMulticastManagerReqIterate,
110  ShowMulticastManagerResp,
111  ShowMulticastManager>::Callback, _1, _2, _3, _4, _5);
113  ShowMulticastManagerReq,
114  ShowMulticastManagerReqIterate,
115  ShowMulticastManagerResp,
116  ShowMulticastManager>::CreateData;
117  s1.instances_.push_back(0);
118  ps.stages_.push_back(s1);
119  RequestPipeline rp(ps);
120 }
121 
122 //
123 // Handler for ShowMulticastManagerReqIterate.
124 //
125 void ShowMulticastManagerReqIterate::HandleRequest() const {
126  RequestPipeline::PipeSpec ps(this);
129 
130  s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
131  s1.cbFn_ = boost::bind(&BgpShowHandler<
132  ShowMulticastManagerReq,
133  ShowMulticastManagerReqIterate,
134  ShowMulticastManagerResp,
135  ShowMulticastManager>::CallbackIterate, _1, _2, _3, _4, _5);
137  ShowMulticastManagerReq,
138  ShowMulticastManagerReqIterate,
139  ShowMulticastManagerResp,
140  ShowMulticastManager>::CreateData;
141  s1.instances_.push_back(0);
142  ps.stages_.push_back(s1);
143  RequestPipeline rp(ps);
144 }
std::vector< int > instances_
bool deleted() const
BgpTable * GetTable(Address::Family fmly)
PartitionList::const_iterator const_iterator
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
const_name_iterator name_cend()
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:102
const_iterator end() 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
McastTreeManager * GetTreeManager()
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
const_iterator begin() const
uint32_t page_limit() const
Definition: bgp_sandesh.h:63
static void FillMulticastManagerInfo(ShowMulticastManager *smm, const BgpSandeshContext *bsc, const ErmVpnTable *table)
const uint64_t delete_time_stamp_usecs() const
Definition: lifetime.h:138
LifetimeActor * deleter()
size_t size() const
static std::string UTCUsecToString(uint64_t tstamp)
Definition: time_util.h:54