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