-
Notifications
You must be signed in to change notification settings - Fork 390
/
show_route_aggregate.cc
227 lines (205 loc) · 7.88 KB
/
show_route_aggregate.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
/*
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_show_handler.h"
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>
#include "bgp/bgp_server.h"
#include "bgp/bgp_show_handler.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/route_aggregator.h"
#include "bgp/routing-instance/route_aggregate_internal_types.h"
#include "bgp/routing-instance/route_aggregate_types.h"
using boost::assign::list_of;
using std::string;
using std::vector;
static bool FillRouteAggregateInfoList(const BgpSandeshContext *bsc,
bool summary, uint32_t page_limit, uint32_t iter_limit,
const string &start_instance, const string &search_string,
vector<AggregateRouteEntriesInfo> *are_list, string *next_instance) {
RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();
RoutingInstanceMgr::const_name_iterator it =
rim->name_clower_bound(start_instance);
for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
RoutingInstance *rtinstance = it->second;
vector<Address::Family> families =
list_of(Address::INET)(Address::INET6);
BOOST_FOREACH(Address::Family family, families) {
const BgpTable *table =
static_cast<const BgpTable *>(rtinstance->GetTable(family));
if (!table)
continue;
if (!search_string.empty() &&
(table->name().find(search_string) == string::npos) &&
(search_string != "deleted" || !table->IsDeleted())) {
continue;
}
IRouteAggregator *iroute_aggregator =
rtinstance->route_aggregator(family);
if (!iroute_aggregator)
continue;
AggregateRouteEntriesInfo info;
if (!iroute_aggregator->FillAggregateRouteInfo(&info, summary))
continue;
are_list->push_back(info);
}
if (are_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 = are_list->size() >= page_limit;
*next_instance = it->second->name();
return done;
}
//
// Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
//
template <>
bool BgpShowHandler<ShowRouteAggregateReq,
ShowRouteAggregateReqIterate, ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::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_instance;
bool done = FillRouteAggregateInfoList(bsc, false, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_instance);
if (!next_instance.empty())
SaveContextToData(next_instance, done, data);
return done;
}
//
// Specialization of BgpShowHandler<>::FillShowList for regular introspect.
//
template <>
void BgpShowHandler<ShowRouteAggregateReq,
ShowRouteAggregateReqIterate, ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::FillShowList(
ShowRouteAggregateResp *resp,
const vector<AggregateRouteEntriesInfo> &show_list) {
resp->set_aggregate_route_entries(show_list);
}
//
// Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
//
template <>
bool BgpShowHandler<ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate, ShowRouteAggregateSummaryResp,
AggregateRouteEntriesInfo>::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_instance;
bool done = FillRouteAggregateInfoList(bsc, true, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_instance);
if (!next_instance.empty())
SaveContextToData(next_instance, done, data);
return done;
}
//
// Specialization of BgpShowHandler<>::FillShowList for summary introspect.
//
template <>
void BgpShowHandler<ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate, ShowRouteAggregateSummaryResp,
AggregateRouteEntriesInfo>::FillShowList(
ShowRouteAggregateSummaryResp *resp,
const vector<AggregateRouteEntriesInfo> &show_list) {
resp->set_aggregate_route_entries(show_list);
}
//
// Handler for ShowRouteAggregateReq.
//
void ShowRouteAggregateReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRouteAggregateReqIterate.
//
void ShowRouteAggregateReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRouteAggregateReq,
ShowRouteAggregateReqIterate,
ShowRouteAggregateResp,
AggregateRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRouteAggregateSummaryReq.
//
void ShowRouteAggregateSummaryReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate,
ShowRouteAggregateSummaryResp,
AggregateRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate,
ShowRouteAggregateSummaryResp,
AggregateRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowRouteAggregateSummaryReqIterate.
//
void ShowRouteAggregateSummaryReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::RouteAggregate");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate,
ShowRouteAggregateSummaryResp,
AggregateRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowRouteAggregateSummaryReq,
ShowRouteAggregateSummaryReqIterate,
ShowRouteAggregateSummaryResp,
AggregateRouteEntriesInfo>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}