Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #include "bgp/bgp_show_handler.h"
6 :
7 : #include <boost/assign/list_of.hpp>
8 : #include <boost/foreach.hpp>
9 :
10 : #include "base/regex.h"
11 : #include "bgp/bgp_config.h"
12 : #include "bgp/bgp_config_ifmap.h"
13 : #include "bgp/bgp_peer_internal_types.h"
14 : #include "bgp/bgp_server.h"
15 :
16 : using boost::assign::list_of;
17 : using contrail::regex;
18 : using contrail::regex_match;
19 : using contrail::regex_search;
20 : using std::string;
21 : using std::vector;
22 :
23 : //
24 : // Fill in information for an instance.
25 : //
26 220 : static void FillBgpInstanceConfigInfo(ShowBgpInstanceConfig *sbic,
27 : const BgpSandeshContext *bsc, const BgpInstanceConfig *instance) {
28 220 : sbic->set_name(instance->name());
29 220 : sbic->set_virtual_network(instance->virtual_network());
30 220 : sbic->set_virtual_network_index(instance->virtual_network_index());
31 220 : sbic->set_vxlan_id(instance->vxlan_id());
32 :
33 220 : vector<string> import_list;
34 834 : for (auto rt : instance->import_list()) {
35 614 : import_list.push_back(rt);
36 614 : }
37 220 : sbic->set_import_target(import_list);
38 220 : vector<string> export_list;
39 426 : for (auto rt : instance->export_list()) {
40 206 : export_list.push_back(rt);
41 206 : }
42 220 : sbic->set_export_target(export_list);
43 220 : sbic->set_has_pnf(instance->has_pnf());
44 220 : sbic->set_allow_transit(instance->virtual_network_allow_transit());
45 220 : sbic->set_pbb_evpn_enable(instance->virtual_network_pbb_evpn_enable());
46 220 : sbic->set_last_change_at(UTCUsecToString(instance->last_change_at()));
47 :
48 : vector<string> neighbors(
49 220 : instance->neighbor_list().begin(), instance->neighbor_list().end());
50 220 : sbic->set_neighbors(neighbors);
51 :
52 220 : vector<ShowBgpServiceChainConfig> sbscc_list;
53 220 : for (const auto &sc_config :
54 442 : instance->service_chain_list()) {
55 2 : ShowBgpServiceChainConfig sbscc;
56 : Address::Family family =
57 2 : SCAddress::SCFamilyToAddressFamily(sc_config.family);
58 2 : sbscc.set_family(Address::FamilyToString(family));
59 2 : sbscc.set_routing_instance(sc_config.routing_instance);
60 2 : sbscc.set_service_instance(sc_config.service_instance);
61 2 : sbscc.set_chain_address(sc_config.service_chain_address);
62 2 : sbscc.set_prefixes(sc_config.prefix);
63 2 : sbscc_list.push_back(sbscc);
64 2 : }
65 220 : sbic->set_service_chain_infos(sbscc_list);
66 :
67 220 : vector<ShowBgpStaticRouteConfig> static_route_list;
68 220 : vector<Address::Family> families = list_of(Address::INET)(Address::INET6);
69 660 : for (auto family : families) {
70 440 : for (const auto &static_rt_config :
71 883 : instance->static_routes(family)) {
72 3 : ShowBgpStaticRouteConfig sbsrc;
73 3 : string prefix = static_rt_config.address.to_string() + "/";
74 3 : prefix += integerToString(static_rt_config.prefix_length);
75 3 : sbsrc.set_prefix(prefix);
76 3 : sbsrc.set_nexthop(static_rt_config.nexthop.to_string());
77 3 : sbsrc.set_targets(static_rt_config.communities);
78 3 : sbsrc.set_targets(static_rt_config.route_targets);
79 3 : static_route_list.push_back(sbsrc);
80 3 : }
81 : }
82 220 : if (!static_route_list.empty())
83 1 : sbic->set_static_routes(static_route_list);
84 :
85 220 : vector<ShowBgpRouteAggregateConfig> aggregate_route_list;
86 660 : for (auto family : families) {
87 440 : for (const auto &aggregate_rt_config :
88 883 : instance->aggregate_routes(family)) {
89 3 : ShowBgpRouteAggregateConfig sbarc;
90 3 : string prefix = aggregate_rt_config.aggregate.to_string() + "/";
91 3 : prefix += integerToString(aggregate_rt_config.prefix_length);
92 3 : sbarc.set_prefix(prefix);
93 3 : sbarc.set_nexthop(aggregate_rt_config.nexthop.to_string());
94 3 : aggregate_route_list.push_back(sbarc);
95 3 : }
96 : }
97 220 : if (!aggregate_route_list.empty())
98 1 : sbic->set_aggregate_routes(aggregate_route_list);
99 :
100 220 : vector<ShowBgpInstanceRoutingPolicyConfig> routing_policy_list;
101 220 : for (const auto &policy_config :
102 442 : instance->routing_policy_list()) {
103 2 : ShowBgpInstanceRoutingPolicyConfig sbirpc;
104 2 : sbirpc.set_policy_name(policy_config.routing_policy_);
105 2 : sbirpc.set_sequence(policy_config.sequence_);
106 2 : routing_policy_list.push_back(sbirpc);
107 2 : }
108 220 : if (!routing_policy_list.empty())
109 2 : sbic->set_routing_policies(routing_policy_list);
110 220 : }
111 :
112 : //
113 : // Specialization of BgpShowHandler<>::CallbackCommon.
114 : //
115 : template <>
116 48 : bool BgpShowHandler<ShowBgpInstanceConfigReq, ShowBgpInstanceConfigReqIterate,
117 : ShowBgpInstanceConfigResp, ShowBgpInstanceConfig>::CallbackCommon(
118 : const BgpSandeshContext *bsc, Data *data) {
119 48 : uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
120 48 : uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
121 48 : const BgpConfigManager *bcm = bsc->bgp_server->config_manager();
122 :
123 48 : regex search_expr(data->search_string);
124 : BgpConfigManager::InstanceMapRange range =
125 48 : bcm->InstanceMapItems(data->next_entry);
126 48 : BgpConfigManager::InstanceMap::const_iterator it = range.first;
127 48 : BgpConfigManager::InstanceMap::const_iterator it_end = range.second;
128 312 : for (uint32_t iter_count = 0; it != it_end; ++it, ++iter_count) {
129 289 : const BgpInstanceConfig *instance = it->second;
130 289 : if (!regex_search(instance->name(), search_expr))
131 69 : continue;
132 220 : ShowBgpInstanceConfig sbic;
133 220 : FillBgpInstanceConfigInfo(&sbic, bsc, instance);
134 220 : data->show_list.push_back(sbic);
135 220 : if (data->show_list.size() >= page_limit)
136 13 : break;
137 207 : if (iter_count >= iter_limit)
138 12 : break;
139 220 : }
140 :
141 : // All done if we've looked at all instances.
142 48 : if (it == it_end || ++it == it_end)
143 26 : return true;
144 :
145 : // Return true if we've reached the page limit, false if we've reached the
146 : // iteration limit.
147 22 : bool done = data->show_list.size() >= page_limit;
148 22 : SaveContextToData(it->second->name(), done, data);
149 22 : return done;
150 48 : }
151 :
152 : //
153 : // Specialization of BgpShowHandler<>::FillShowList.
154 : //
155 : template <>
156 32 : void BgpShowHandler<ShowBgpInstanceConfigReq, ShowBgpInstanceConfigReqIterate,
157 : ShowBgpInstanceConfigResp, ShowBgpInstanceConfig>::FillShowList(
158 : ShowBgpInstanceConfigResp *resp,
159 : const vector<ShowBgpInstanceConfig> &show_list) {
160 32 : resp->set_instances(show_list);
161 32 : }
162 :
163 : //
164 : // Handler for ShowBgpInstanceConfigReq.
165 : //
166 23 : void ShowBgpInstanceConfigReq::HandleRequest() const {
167 23 : RequestPipeline::PipeSpec ps(this);
168 23 : RequestPipeline::StageSpec s1;
169 23 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
170 :
171 23 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
172 : s1.cbFn_ = boost::bind(&BgpShowHandler<
173 : ShowBgpInstanceConfigReq,
174 : ShowBgpInstanceConfigReqIterate,
175 : ShowBgpInstanceConfigResp,
176 23 : ShowBgpInstanceConfig>::Callback, _1, _2, _3, _4, _5);
177 : s1.allocFn_ = BgpShowHandler<
178 : ShowBgpInstanceConfigReq,
179 : ShowBgpInstanceConfigReqIterate,
180 : ShowBgpInstanceConfigResp,
181 23 : ShowBgpInstanceConfig>::CreateData;
182 23 : s1.instances_.push_back(0);
183 23 : ps.stages_.push_back(s1);
184 23 : RequestPipeline rp(ps);
185 23 : }
186 :
187 : //
188 : // Handler for ShowBgpInstanceConfigReqIterate.
189 : //
190 16 : void ShowBgpInstanceConfigReqIterate::HandleRequest() const {
191 16 : RequestPipeline::PipeSpec ps(this);
192 16 : RequestPipeline::StageSpec s1;
193 16 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
194 :
195 16 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
196 : s1.cbFn_ = boost::bind(&BgpShowHandler<
197 : ShowBgpInstanceConfigReq,
198 : ShowBgpInstanceConfigReqIterate,
199 : ShowBgpInstanceConfigResp,
200 16 : ShowBgpInstanceConfig>::CallbackIterate, _1, _2, _3, _4, _5);
201 : s1.allocFn_ = BgpShowHandler<
202 : ShowBgpInstanceConfigReq,
203 : ShowBgpInstanceConfigReqIterate,
204 : ShowBgpInstanceConfigResp,
205 16 : ShowBgpInstanceConfig>::CreateData;
206 16 : s1.instances_.push_back(0);
207 16 : ps.stages_.push_back(s1);
208 16 : RequestPipeline rp(ps);
209 16 : }
210 :
211 : //
212 : // Fill in information for an routing policy.
213 : //
214 2 : static void FillBgpRoutingPolicyInfo(ShowBgpRoutingPolicyConfig *sbrpc,
215 : const BgpSandeshContext *bsc, const BgpRoutingPolicyConfig *policy) {
216 2 : sbrpc->set_name(policy->name());
217 2 : std::vector<ShowBgpRoutingPolicyTermConfig> terms_list;
218 7 : for (const auto &term : policy->terms()) {
219 5 : ShowBgpRoutingPolicyTermConfig sbrptc;
220 5 : sbrptc.set_match(term.match.ToString());
221 5 : sbrptc.set_action(term.action.ToString());
222 5 : terms_list.push_back(sbrptc);
223 5 : }
224 2 : sbrpc->set_terms(terms_list);
225 2 : }
226 :
227 : //
228 : // Specialization of BgpShowHandler<>::CallbackCommon.
229 : //
230 : template <>
231 2 : bool BgpShowHandler<ShowBgpRoutingPolicyConfigReq,
232 : ShowBgpRoutingPolicyConfigReqIterate, ShowBgpRoutingPolicyConfigResp,
233 : ShowBgpRoutingPolicyConfig>::CallbackCommon(
234 : const BgpSandeshContext *bsc, Data *data) {
235 2 : uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
236 2 : uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
237 2 : const BgpConfigManager *bcm = bsc->bgp_server->config_manager();
238 :
239 2 : regex search_expr(data->search_string);
240 : BgpConfigManager::RoutingPolicyMapRange range =
241 2 : bcm->RoutingPolicyMapItems(data->next_entry);
242 2 : BgpConfigManager::RoutingPolicyMap::const_iterator it = range.first;
243 2 : BgpConfigManager::RoutingPolicyMap::const_iterator it_end = range.second;
244 4 : for (uint32_t iter_count = 0; it != it_end; ++it, ++iter_count) {
245 2 : const BgpRoutingPolicyConfig *policy = it->second;
246 2 : if (!regex_search(policy->name(), search_expr))
247 0 : continue;
248 2 : ShowBgpRoutingPolicyConfig sbrpc;
249 2 : FillBgpRoutingPolicyInfo(&sbrpc, bsc, policy);
250 2 : data->show_list.push_back(sbrpc);
251 2 : if (data->show_list.size() >= page_limit)
252 0 : break;
253 2 : if (iter_count >= iter_limit)
254 0 : break;
255 2 : }
256 :
257 : // All done if we've looked at all policies.
258 2 : if (it == it_end || ++it == it_end)
259 2 : return true;
260 :
261 : // Return true if we've reached the page limit, false if we've reached the
262 : // iteration limit.
263 0 : bool done = data->show_list.size() >= page_limit;
264 0 : SaveContextToData(it->second->name(), done, data);
265 0 : return done;
266 2 : }
267 :
268 : //
269 : // Specialization of BgpShowHandler<>::FillShowList.
270 : //
271 : template <>
272 2 : void BgpShowHandler<ShowBgpRoutingPolicyConfigReq,
273 : ShowBgpRoutingPolicyConfigReqIterate, ShowBgpRoutingPolicyConfigResp,
274 : ShowBgpRoutingPolicyConfig>::FillShowList(
275 : ShowBgpRoutingPolicyConfigResp *resp,
276 : const vector<ShowBgpRoutingPolicyConfig> &show_list) {
277 2 : resp->set_routing_policies(show_list);
278 2 : }
279 :
280 :
281 : //
282 : // Handler for ShowBgpRoutingPolicyConfigReq.
283 : //
284 2 : void ShowBgpRoutingPolicyConfigReq::HandleRequest() const {
285 2 : RequestPipeline::PipeSpec ps(this);
286 2 : RequestPipeline::StageSpec s1;
287 2 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
288 :
289 2 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
290 : s1.cbFn_ = boost::bind(&BgpShowHandler<
291 : ShowBgpRoutingPolicyConfigReq,
292 : ShowBgpRoutingPolicyConfigReqIterate,
293 : ShowBgpRoutingPolicyConfigResp,
294 2 : ShowBgpRoutingPolicyConfig>::Callback, _1, _2, _3, _4, _5);
295 : s1.allocFn_ = BgpShowHandler<
296 : ShowBgpRoutingPolicyConfigReq,
297 : ShowBgpRoutingPolicyConfigReqIterate,
298 : ShowBgpRoutingPolicyConfigResp,
299 2 : ShowBgpRoutingPolicyConfig>::CreateData;
300 2 : s1.instances_.push_back(0);
301 2 : ps.stages_.push_back(s1);
302 2 : RequestPipeline rp(ps);
303 2 : }
304 :
305 : //
306 : // Handler for ShowBgpRoutingPolicyConfigReqIterate.
307 : //
308 0 : void ShowBgpRoutingPolicyConfigReqIterate::HandleRequest() const {
309 0 : RequestPipeline::PipeSpec ps(this);
310 0 : RequestPipeline::StageSpec s1;
311 0 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
312 :
313 0 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
314 : s1.cbFn_ = boost::bind(&BgpShowHandler<
315 : ShowBgpRoutingPolicyConfigReq,
316 : ShowBgpRoutingPolicyConfigReqIterate,
317 : ShowBgpRoutingPolicyConfigResp,
318 0 : ShowBgpRoutingPolicyConfig>::CallbackIterate, _1, _2, _3, _4, _5);
319 : s1.allocFn_ = BgpShowHandler<
320 : ShowBgpRoutingPolicyConfigReq,
321 : ShowBgpRoutingPolicyConfigReqIterate,
322 : ShowBgpRoutingPolicyConfigResp,
323 0 : ShowBgpRoutingPolicyConfig>::CreateData;
324 0 : s1.instances_.push_back(0);
325 0 : ps.stages_.push_back(s1);
326 0 : RequestPipeline rp(ps);
327 0 : }
328 :
329 : //
330 : // Fill in information for a neighbor.
331 : //
332 5 : static void FillBgpNeighborConfigInfo(ShowBgpNeighborConfig *sbnc,
333 : const BgpSandeshContext *bsc, const BgpNeighborConfig *neighbor) {
334 5 : sbnc->set_instance_name(neighbor->instance_name());
335 5 : sbnc->set_name(neighbor->name());
336 5 : sbnc->set_admin_down(neighbor->admin_down());
337 5 : sbnc->set_passive(neighbor->passive());
338 5 : sbnc->set_as_override(neighbor->as_override());
339 : const BgpNeighborConfig::OriginOverrideConfig &route_origin =
340 5 : neighbor->origin_override();
341 5 : sbnc->set_origin_override(route_origin.origin_override);
342 5 : if (route_origin.origin_override) {
343 0 : sbnc->set_route_origin(route_origin.origin);
344 : } else {
345 5 : sbnc->set_route_origin("-");
346 : }
347 5 : sbnc->set_private_as_action(neighbor->private_as_action());
348 5 : sbnc->set_router_type(neighbor->router_type());
349 5 : sbnc->set_local_identifier(neighbor->local_identifier_string());
350 5 : sbnc->set_local_as(neighbor->local_as());
351 5 : sbnc->set_autonomous_system(neighbor->peer_as());
352 5 : sbnc->set_identifier(neighbor->peer_identifier_string());
353 5 : sbnc->set_address(neighbor->peer_address().to_string());
354 5 : sbnc->set_cluster_id(Ip4Address(neighbor->cluster_id()).to_string());
355 5 : sbnc->set_source_port(neighbor->source_port());
356 5 : sbnc->set_address_families(neighbor->GetAddressFamilies());
357 5 : sbnc->set_hold_time(neighbor->hold_time());
358 5 : sbnc->set_loop_count(neighbor->loop_count());
359 5 : sbnc->set_last_change_at(UTCUsecToString(neighbor->last_change_at()));
360 5 : sbnc->set_auth_type(neighbor->auth_data().KeyTypeToString());
361 5 : if (bsc->test_mode()) {
362 0 : sbnc->set_auth_keys(neighbor->auth_data().KeysToStringDetail());
363 : }
364 :
365 5 : vector<ShowBgpNeighborFamilyConfig> sbnfc_list;
366 5 : for (const auto& family_config :
367 20 : neighbor->family_attributes_list()) {
368 10 : ShowBgpNeighborFamilyConfig sbnfc;
369 10 : sbnfc.set_family(family_config.family);
370 10 : sbnfc.set_loop_count(family_config.loop_count);
371 10 : sbnfc.set_prefix_limit(family_config.prefix_limit);
372 10 : sbnfc.set_idle_timeout(family_config.idle_timeout);
373 10 : sbnfc.set_default_tunnel_encap_list(
374 10 : family_config.default_tunnel_encap_list);
375 10 : if (family_config.family == "inet") {
376 5 : IpAddress address = neighbor->gateway_address(Address::INET);
377 5 : if (!address.is_unspecified())
378 0 : sbnfc.set_gateway_address(address.to_string());
379 5 : } else if (family_config.family == "inet6") {
380 2 : IpAddress address = neighbor->gateway_address(Address::INET6);
381 2 : if (!address.is_unspecified())
382 0 : sbnfc.set_gateway_address(address.to_string());
383 : }
384 10 : sbnfc_list.push_back(sbnfc);
385 10 : }
386 5 : sbnc->set_family_attributes_list(sbnfc_list);
387 5 : }
388 :
389 : //
390 : // Specialization of BgpShowHandler<>::CallbackCommon.
391 : //
392 : template <>
393 2 : bool BgpShowHandler<ShowBgpNeighborConfigReq, ShowBgpNeighborConfigReqIterate,
394 : ShowBgpNeighborConfigResp, ShowBgpNeighborConfig>::CallbackCommon(
395 : const BgpSandeshContext *bsc, Data *data) {
396 2 : uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
397 2 : uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
398 2 : const BgpConfigManager *bcm = bsc->bgp_server->config_manager();
399 :
400 2 : regex search_expr(data->search_string);
401 : BgpConfigManager::InstanceMapRange range =
402 2 : bcm->InstanceMapItems(data->next_entry);
403 2 : BgpConfigManager::InstanceMap::const_iterator it = range.first;
404 2 : BgpConfigManager::InstanceMap::const_iterator it_end = range.second;
405 8 : for (uint32_t iter_count = 0; it != it_end; ++it, ++iter_count) {
406 6 : const BgpInstanceConfig *instance = it->second;
407 16 : BOOST_FOREACH(BgpConfigManager::NeighborMap::value_type value,
408 : bcm->NeighborMapItems(instance->name())) {
409 5 : const BgpNeighborConfig *neighbor = value.second;
410 5 : if (!regex_search(neighbor->name(), search_expr))
411 0 : continue;
412 5 : ShowBgpNeighborConfig sbnc;
413 5 : FillBgpNeighborConfigInfo(&sbnc, bsc, neighbor);
414 5 : data->show_list.push_back(sbnc);
415 10 : }
416 6 : if (data->show_list.size() >= page_limit)
417 0 : break;
418 6 : if (iter_count >= iter_limit)
419 0 : break;
420 : }
421 :
422 : // All done if we've looked at all instances.
423 2 : if (it == it_end || ++it == it_end)
424 2 : return true;
425 :
426 : // Return true if we've reached the page limit, false if we've reached the
427 : // iteration limit.
428 0 : bool done = data->show_list.size() >= page_limit;
429 0 : SaveContextToData(it->second->name(), done, data);
430 0 : return done;
431 2 : }
432 :
433 : //
434 : // Specialization of BgpShowHandler<>::FillShowList.
435 : //
436 : template <>
437 2 : void BgpShowHandler<ShowBgpNeighborConfigReq, ShowBgpNeighborConfigReqIterate,
438 : ShowBgpNeighborConfigResp, ShowBgpNeighborConfig>::FillShowList(
439 : ShowBgpNeighborConfigResp *resp,
440 : const vector<ShowBgpNeighborConfig> &show_list) {
441 2 : resp->set_neighbors(show_list);
442 2 : }
443 :
444 : //
445 : // Handler for ShowBgpNeighborConfigReq.
446 : //
447 2 : void ShowBgpNeighborConfigReq::HandleRequest() const {
448 2 : RequestPipeline::PipeSpec ps(this);
449 2 : RequestPipeline::StageSpec s1;
450 2 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
451 :
452 2 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
453 : s1.cbFn_ = boost::bind(&BgpShowHandler<
454 : ShowBgpNeighborConfigReq,
455 : ShowBgpNeighborConfigReqIterate,
456 : ShowBgpNeighborConfigResp,
457 2 : ShowBgpNeighborConfig>::Callback, _1, _2, _3, _4, _5);
458 : s1.allocFn_ = BgpShowHandler<
459 : ShowBgpNeighborConfigReq,
460 : ShowBgpNeighborConfigReqIterate,
461 : ShowBgpNeighborConfigResp,
462 2 : ShowBgpNeighborConfig>::CreateData;
463 2 : s1.instances_.push_back(0);
464 2 : ps.stages_.push_back(s1);
465 2 : RequestPipeline rp(ps);
466 2 : }
467 :
468 : //
469 : // Handler for ShowBgpNeighborConfigReqIterate.
470 : //
471 0 : void ShowBgpNeighborConfigReqIterate::HandleRequest() const {
472 0 : RequestPipeline::PipeSpec ps(this);
473 0 : RequestPipeline::StageSpec s1;
474 0 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
475 :
476 0 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
477 : s1.cbFn_ = boost::bind(&BgpShowHandler<
478 : ShowBgpNeighborConfigReq,
479 : ShowBgpNeighborConfigReqIterate,
480 : ShowBgpNeighborConfigResp,
481 0 : ShowBgpNeighborConfig>::CallbackIterate, _1, _2, _3, _4, _5);
482 : s1.allocFn_ = BgpShowHandler<
483 : ShowBgpNeighborConfigReq,
484 : ShowBgpNeighborConfigReqIterate,
485 : ShowBgpNeighborConfigResp,
486 0 : ShowBgpNeighborConfig>::CreateData;
487 0 : s1.instances_.push_back(0);
488 0 : ps.stages_.push_back(s1);
489 0 : RequestPipeline rp(ps);
490 0 : }
491 :
492 : //
493 : // Handler for ShowBgpPeeringConfigReq.
494 : //
495 3 : void ShowBgpPeeringConfigReq::HandleRequest() const {
496 3 : BgpSandeshContext *bsc = static_cast<BgpSandeshContext *>(client_context());
497 3 : bsc->PeeringShowReqHandler(this);
498 3 : }
499 :
500 : //
501 : // Handler for ShowBgpPeeringConfigReqIterate.
502 : //
503 0 : void ShowBgpPeeringConfigReqIterate::HandleRequest() const {
504 0 : BgpSandeshContext *bsc = static_cast<BgpSandeshContext *>(client_context());
505 0 : bsc->PeeringShowReqIterateHandler(this);
506 0 : }
507 :
508 : //
509 : // Fill in information for an instance.
510 : //
511 1 : static void FillBgpGlobalSystemConfigInfo(ShowBgpGlobalSystemConfig *sbgc,
512 : const BgpSandeshContext *bsc, const BgpGlobalSystemConfig *bgsc) {
513 :
514 1 : sbgc->set_gr_time(bgsc->gr_time());
515 1 : sbgc->set_llgr_time(bgsc->llgr_time());
516 1 : sbgc->set_last_change_at(bgsc->last_change_at());
517 1 : sbgc->set_end_of_rib_timeout(bgsc->end_of_rib_timeout());
518 1 : sbgc->set_gr_bgp_helper(bgsc->gr_bgp_helper());
519 1 : sbgc->set_gr_xmpp_helper(bgsc->gr_xmpp_helper());
520 1 : sbgc->set_gr_enable(bgsc->gr_enable());
521 1 : sbgc->set_always_compare_med(bgsc->always_compare_med());
522 1 : sbgc->set_rd_cluster_seed(bgsc->rd_cluster_seed());
523 1 : sbgc->set_bgpaas_port_start(bgsc->bgpaas_port_start());
524 1 : sbgc->set_bgpaas_port_end(bgsc->bgpaas_port_end());
525 1 : sbgc->set_all_tags_are_global(bgsc->all_tags_are_global());
526 1 : }
527 :
528 : //
529 : //Specialization of BgpShowHandler<>::ConvertReqToData
530 : //
531 : template <>
532 1 : void BgpShowHandler<ShowBgpGlobalSystemConfigReq,
533 : ShowBgpGlobalSystemConfigReqIterate,
534 : ShowBgpGlobalSystemConfigResp,
535 : ShowBgpGlobalSystemConfig>::ConvertReqToData(
536 : const ShowBgpGlobalSystemConfigReq *req, Data *data) {
537 :
538 1 : data->initialized = true;
539 1 : }
540 :
541 : //
542 : // Specialization of BgpShowHandler<>::CallbackCommon.
543 : //
544 : template <>
545 1 : bool BgpShowHandler<ShowBgpGlobalSystemConfigReq,
546 : ShowBgpGlobalSystemConfigReqIterate,
547 : ShowBgpGlobalSystemConfigResp,
548 : ShowBgpGlobalSystemConfig>::CallbackCommon(
549 : const BgpSandeshContext *bsc, Data *data) {
550 :
551 1 : const BgpGlobalSystemConfig *bgsc = bsc->bgp_server->global_config();
552 :
553 1 : ShowBgpGlobalSystemConfig sbgc;
554 1 : FillBgpGlobalSystemConfigInfo(&sbgc, bsc, bgsc);
555 1 : data->show_list.push_back(sbgc);
556 :
557 1 : return true;
558 1 : }
559 :
560 : //
561 : // Specialization of BgpShowHandler<>::FillShowList.
562 : //
563 : template <>
564 1 : void BgpShowHandler<ShowBgpGlobalSystemConfigReq,
565 : ShowBgpGlobalSystemConfigReqIterate,
566 : ShowBgpGlobalSystemConfigResp,
567 : ShowBgpGlobalSystemConfig>::FillShowList(
568 : ShowBgpGlobalSystemConfigResp *resp,
569 : const vector<ShowBgpGlobalSystemConfig> &show_list) {
570 1 : resp->set_global_instances(show_list);
571 1 : }
572 :
573 : //
574 : // Handler for ShowBgpGlobalSystemConfigReq.
575 : //
576 1 : void ShowBgpGlobalSystemConfigReq::HandleRequest() const {
577 1 : RequestPipeline::PipeSpec ps(this);
578 1 : RequestPipeline::StageSpec s1;
579 1 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
580 :
581 1 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
582 : s1.cbFn_ = boost::bind(&BgpShowHandler<
583 : ShowBgpGlobalSystemConfigReq,
584 : ShowBgpGlobalSystemConfigReqIterate,
585 : ShowBgpGlobalSystemConfigResp,
586 1 : ShowBgpGlobalSystemConfig>::Callback, _1, _2, _3, _4, _5);
587 :
588 : s1.allocFn_ = BgpShowHandler<
589 : ShowBgpGlobalSystemConfigReq,
590 : ShowBgpGlobalSystemConfigReqIterate,
591 : ShowBgpGlobalSystemConfigResp,
592 1 : ShowBgpGlobalSystemConfig>::CreateData;
593 :
594 1 : s1.instances_.push_back(0);
595 1 : ps.stages_.push_back(s1);
596 1 : RequestPipeline rp(ps);
597 1 : }
598 :
599 : //
600 : // Handler for ShowBgpGlobalSystemConfigReqIterate.
601 : //
602 0 : void ShowBgpGlobalSystemConfigReqIterate::HandleRequest() const {
603 0 : RequestPipeline::PipeSpec ps(this);
604 0 : RequestPipeline::StageSpec s1;
605 0 : TaskScheduler *scheduler = TaskScheduler::GetInstance();
606 :
607 0 : s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
608 : s1.cbFn_ = boost::bind(&BgpShowHandler<
609 : ShowBgpGlobalSystemConfigReq,
610 : ShowBgpGlobalSystemConfigReqIterate,
611 : ShowBgpGlobalSystemConfigResp,
612 0 : ShowBgpGlobalSystemConfig>::CallbackIterate, _1, _2, _3, _4, _5);
613 :
614 : s1.allocFn_ = BgpShowHandler<
615 : ShowBgpGlobalSystemConfigReq,
616 : ShowBgpGlobalSystemConfigReqIterate,
617 : ShowBgpGlobalSystemConfigResp,
618 0 : ShowBgpGlobalSystemConfig>::CreateData;
619 :
620 0 : s1.instances_.push_back(0);
621 0 : ps.stages_.push_back(s1);
622 0 : RequestPipeline rp(ps);
623 0 : }
|