-
Notifications
You must be signed in to change notification settings - Fork 390
/
bgp_show_rtarget_group.cc
307 lines (279 loc) · 9.94 KB
/
bgp_show_rtarget_group.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_show_handler.h"
#include <boost/bind.hpp>
#include "bgp/bgp_peer_internal_types.h"
#include "bgp/bgp_peer_types.h"
#include "bgp/bgp_server.h"
#include "bgp/routing-instance/rtarget_group.h"
#include "bgp/routing-instance/rtarget_group_mgr.h"
using std::string;
using std::vector;
//
// Fill in information for list of rtarget groups.
//
// Allows regular, summary and peer introspect to share code.
// Assumes that search_string is the peer name if match_peer is true.
//
static bool FillRtGroupInfoList(const BgpSandeshContext *bsc,
bool summary, bool match_peer, uint32_t page_limit, uint32_t iter_limit,
const string &start_rtarget_str, const string &search_string,
vector<ShowRtGroupInfo> *srtg_list, string *next_rtarget_str) {
RouteTarget rtarget;
// Bail if start_rtarget_str is bad.
if (!start_rtarget_str.empty()) {
rtarget = RouteTarget::FromString(start_rtarget_str);
if (rtarget.IsNull())
return true;
}
// Bail if there's no peer specified when doing a peer introspect.
if (match_peer && search_string.empty())
return true;
const RTargetGroupMgr *rtgroup_mgr = bsc->bgp_server->rtarget_group_mgr();
RTargetGroupMgr::const_iterator it = rtgroup_mgr->lower_bound(rtarget);
for (uint32_t iter_count = 0; it != rtgroup_mgr->end();
++it, ++iter_count) {
const RtGroup *rtgroup = it->second;
if (!match_peer && !search_string.empty() &&
(rtgroup->ToString().find(search_string) == string::npos)) {
continue;
}
ShowRtGroupInfo srtg;
if (match_peer) {
if (!rtgroup->HasInterestedPeer(search_string))
continue;
rtgroup->FillShowPeerInfo(&srtg);
} else if (summary) {
rtgroup->FillShowSummaryInfo(&srtg);
} else {
rtgroup->FillShowInfo(&srtg);
}
srtg_list->push_back(srtg);
if (srtg_list->size() >= page_limit)
break;
if (iter_count >= iter_limit)
break;
}
// All done if we've looked at all rtarget groups.
if (it == rtgroup_mgr->end() || ++it == rtgroup_mgr->end())
return true;
// Return true if we've reached the page limit, false if we've reached the
// iteration limit.
bool done = srtg_list->size() >= page_limit;
*next_rtarget_str = it->second->ToString();
return done;
}
//
// Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
//
template <>
bool BgpShowHandler<ShowRtGroupReq, ShowRtGroupReqIterate,
ShowRtGroupResp, ShowRtGroupInfo>::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;
string next_rtarget_str;
bool done = FillRtGroupInfoList(bsc, false, false, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_rtarget_str);
if (!next_rtarget_str.empty())
SaveContextToData(next_rtarget_str, done, data);
return done;
}
//
// Specialization of BgpShowHandler<>::FillShowList for regular introspect.
//
template <>
void BgpShowHandler<ShowRtGroupReq, ShowRtGroupReqIterate,
ShowRtGroupResp, ShowRtGroupInfo>::FillShowList(
ShowRtGroupResp *resp,
const vector<ShowRtGroupInfo> &show_list) {
resp->set_rtgroup_list(show_list);
}
//
// Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
//
template <>
bool BgpShowHandler<ShowRtGroupSummaryReq, ShowRtGroupSummaryReqIterate,
ShowRtGroupSummaryResp, ShowRtGroupInfo>::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;
string next_rtarget_str;
bool done = FillRtGroupInfoList(bsc, true, false, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_rtarget_str);
if (!next_rtarget_str.empty())
SaveContextToData(next_rtarget_str, done, data);
return done;
}
//
// Specialization of BgpShowHandler<>::FillShowList for summary introspect.
//
template <>
void BgpShowHandler<ShowRtGroupSummaryReq, ShowRtGroupSummaryReqIterate,
ShowRtGroupSummaryResp, ShowRtGroupInfo>::FillShowList(
ShowRtGroupSummaryResp *resp,
const vector<ShowRtGroupInfo> &show_list) {
resp->set_rtgroup_list(show_list);
}
//
// Specialization of BgpShowHandler<>::CallbackCommon for peer introspect.
//
template <>
bool BgpShowHandler<ShowRtGroupPeerReq, ShowRtGroupPeerReqIterate,
ShowRtGroupPeerResp, ShowRtGroupInfo>::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;
string next_rtarget_str;
bool done = FillRtGroupInfoList(bsc, false, true, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_rtarget_str);
if (!next_rtarget_str.empty())
SaveContextToData(next_rtarget_str, done, data);
return done;
}
//
// Specialization of BgpShowHandler<>::FillShowList for peer introspect.
//
template <>
void BgpShowHandler<ShowRtGroupPeerReq, ShowRtGroupPeerReqIterate,
ShowRtGroupPeerResp, ShowRtGroupInfo>::FillShowList(
ShowRtGroupPeerResp *resp,
const vector<ShowRtGroupInfo> &show_list) {
resp->set_rtgroup_list(show_list);
}
//
// Handler for ShowRtGroupReq.
//
void ShowRtGroupReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RTFilter");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRtGroupReq,
ShowRtGroupReqIterate,
ShowRtGroupResp,
ShowRtGroupInfo>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRtGroupReq,
ShowRtGroupReqIterate,
ShowRtGroupResp,
ShowRtGroupInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRtGroupReqIterate.
//
void ShowRtGroupReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RTFilter");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRtGroupReq,
ShowRtGroupReqIterate,
ShowRtGroupResp,
ShowRtGroupInfo>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRtGroupReq,
ShowRtGroupReqIterate,
ShowRtGroupResp,
ShowRtGroupInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRtGroupSummaryReq.
//
void ShowRtGroupSummaryReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RTFilter");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRtGroupSummaryReq,
ShowRtGroupSummaryReqIterate,
ShowRtGroupSummaryResp,
ShowRtGroupInfo>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRtGroupSummaryReq,
ShowRtGroupSummaryReqIterate,
ShowRtGroupSummaryResp,
ShowRtGroupInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRtGroupSummaryReqIterate.
//
void ShowRtGroupSummaryReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RTFilter");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRtGroupSummaryReq,
ShowRtGroupSummaryReqIterate,
ShowRtGroupSummaryResp,
ShowRtGroupInfo>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRtGroupSummaryReq,
ShowRtGroupSummaryReqIterate,
ShowRtGroupSummaryResp,
ShowRtGroupInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRtGroupPeerReq.
//
void ShowRtGroupPeerReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RTFilter");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRtGroupPeerReq,
ShowRtGroupPeerReqIterate,
ShowRtGroupPeerResp,
ShowRtGroupInfo>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRtGroupPeerReq,
ShowRtGroupPeerReqIterate,
ShowRtGroupPeerResp,
ShowRtGroupInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRtGroupPeerReqIterate.
//
void ShowRtGroupPeerReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RTFilter");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRtGroupPeerReq,
ShowRtGroupPeerReqIterate,
ShowRtGroupPeerResp,
ShowRtGroupInfo>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRtGroupPeerReq,
ShowRtGroupPeerReqIterate,
ShowRtGroupPeerResp,
ShowRtGroupInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}