-
Notifications
You must be signed in to change notification settings - Fork 390
/
show_static_route.cc
129 lines (113 loc) · 4.41 KB
/
show_static_route.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_show_handler.h"
#include "bgp/bgp_show_handler.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/static_route.h"
#include "bgp/routing-instance/static_route_types.h"
using std::string;
using std::vector;
static bool FillStaticRouteInfo(Address::Family family,
const string search_string,
StaticRouteEntriesInfo &info,
RoutingInstance *rtinstance) {
const BgpTable *table =
static_cast<const BgpTable *>(rtinstance->GetTable(family));
if (!table)
return false;
if (!search_string.empty() &&
(table->name().find(search_string) == string::npos) &&
(search_string != "deleted" || !table->IsDeleted())) {
return false;
}
IStaticRouteMgr *imanager = rtinstance->static_route_mgr(family);
if (!imanager)
return false;
return imanager->FillStaticRouteInfo(rtinstance, &info);
}
// Specialization of BgpShowHandler<>::CallbackCommon.
template <>
bool BgpShowHandler<ShowStaticRouteReq, ShowStaticRouteReqIterate,
ShowStaticRouteResp, StaticRouteEntriesInfo>::CallbackCommon(
const BgpSandeshContext *bsc, Data *data) {
uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();
RoutingInstanceMgr::const_name_iterator it =
rim->name_clower_bound(data->next_entry);
for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
RoutingInstance *rinstance = it->second;
StaticRouteEntriesInfo info;
if (FillStaticRouteInfo(Address::INET, data->search_string, info,
rinstance)) {
data->show_list.push_back(info);
}
if (FillStaticRouteInfo(Address::INET6, data->search_string, info,
rinstance)) {
data->show_list.push_back(info);
}
if (data->show_list.size() >= page_limit)
break;
if (iter_count >= iter_limit)
break;
}
// All done if we've looked at all instances.
if (it == rim->name_cend() || ++it == rim->name_cend())
return true;
// Return true if we've reached the page limit, false if we've reached the
// iteration limit.
bool done = data->show_list.size() >= page_limit;
SaveContextToData(it->second->name(), done, data);
return done;
}
// Specialization of BgpShowHandler<>::FillShowList.
template <>
void BgpShowHandler<ShowStaticRouteReq, ShowStaticRouteReqIterate,
ShowStaticRouteResp, StaticRouteEntriesInfo>::FillShowList(
ShowStaticRouteResp *resp,
const vector<StaticRouteEntriesInfo> &show_list) {
resp->set_static_route_entries(show_list);
}
// Handler for ShowStaticRouteReq.
void ShowStaticRouteReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::StaticRoute");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowStaticRouteReq,
ShowStaticRouteReqIterate,
ShowStaticRouteResp,
StaticRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowStaticRouteReq,
ShowStaticRouteReqIterate,
ShowStaticRouteResp,
StaticRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowStaticRouteReqIterate.
//
void ShowStaticRouteReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::StaticRoute");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowStaticRouteReq,
ShowStaticRouteReqIterate,
ShowStaticRouteResp,
StaticRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowStaticRouteReq,
ShowStaticRouteReqIterate,
ShowStaticRouteResp,
StaticRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}