/
bgp_show_neighbor.cc
221 lines (199 loc) · 7.58 KB
/
bgp_show_neighbor.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
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_show_handler.h"
#include "bgp/bgp_peer.h"
#include "bgp/bgp_peer_internal_types.h"
#include "bgp/bgp_server.h"
#include "bgp/routing-instance/peer_manager.h"
#include "bgp/routing-instance/routing_instance.h"
using std::string;
using std::vector;
//
// Build the list of BgpPeers in one shot for now. Look at the master instance
// and at all peers in the BgpServer's EndpointToBgpPeerList. The latter is the
// list of all bgpaas peers in non-master instances.
//
static bool FillBgpNeighborInfoList(const BgpSandeshContext *bsc,
bool summary, uint32_t page_limit, uint32_t iter_limit,
const string &start_neighbor, const string &search_string,
vector<BgpNeighborResp> *show_list, string *next_instance) {
const RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();
const RoutingInstance *rtinstance = rim->GetDefaultRoutingInstance();
rtinstance->peer_manager()->FillBgpNeighborInfo(
bsc, show_list, search_string, summary);
const BgpPeer *peer = bsc->bgp_server->FindNextPeer();
while (peer) {
if (search_string.empty() ||
(peer->peer_basename().find(search_string) != string::npos) ||
(peer->peer_address_string().find(search_string) != string::npos) ||
(search_string == "deleted" && peer->IsDeleted())) {
BgpNeighborResp bnr;
peer->FillNeighborInfo(bsc, &bnr, summary);
show_list->push_back(bnr);
}
peer = bsc->bgp_server->FindNextPeer(peer->endpoint());
}
return true;
}
//
// Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
//
// Note that we don't both paginating bgp neighbors since the list should be
// pretty small. We always add at least one xmpp neighbor to the list and then
// paginate the xmpp neighbors as needed.
//
template <>
bool BgpShowHandler<BgpNeighborReq, BgpNeighborReqIterate,
BgpNeighborListResp, BgpNeighborResp>::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;
// Build the list of BgpPeers in one shot for now.
if (data->next_entry.empty()) {
FillBgpNeighborInfoList(bsc, false, page_limit, iter_limit, string(),
data->search_string, &data->show_list, NULL);
}
// Add xmpp neighbors.
string next_neighbor;
bool done = bsc->ShowNeighborExtension(bsc, false, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_neighbor);
if (!next_neighbor.empty())
SaveContextToData(next_neighbor, done, data);
return done;
}
//
// Specialization of BgpShowHandler<>::FillShowList for regular introspect.
//
template <>
void BgpShowHandler<BgpNeighborReq, BgpNeighborReqIterate,
BgpNeighborListResp, BgpNeighborResp>::FillShowList(
BgpNeighborListResp *resp, const vector<BgpNeighborResp> &show_list) {
resp->set_neighbors(show_list);
}
//
// Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
//
// Note that we don't both paginating bgp neighbors since the list should be
// pretty small. We always add at least one xmpp neighbor to the list and then
// paginate the xmpp neighbors as needed.
//
template <>
bool BgpShowHandler<ShowBgpNeighborSummaryReq, ShowBgpNeighborSummaryReqIterate,
ShowBgpNeighborSummaryResp, BgpNeighborResp>::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;
// Build the list of BgpPeers in one shot for now.
if (data->next_entry.empty()) {
FillBgpNeighborInfoList(bsc, true, page_limit, iter_limit, string(),
data->search_string, &data->show_list, NULL);
}
// Add xmpp neighbors.
string next_neighbor;
bool done = bsc->ShowNeighborExtension(bsc, true, page_limit, iter_limit,
data->next_entry, data->search_string, &data->show_list,
&next_neighbor);
if (!next_neighbor.empty())
SaveContextToData(next_neighbor, done, data);
return done;
}
//
// Specialization of BgpShowHandler<>::FillShowList for summary introspect.
//
template <>
void BgpShowHandler<ShowBgpNeighborSummaryReq, ShowBgpNeighborSummaryReqIterate,
ShowBgpNeighborSummaryResp, BgpNeighborResp>::FillShowList(
ShowBgpNeighborSummaryResp *resp,
const vector<BgpNeighborResp> &show_list) {
resp->set_neighbors(show_list);
}
//
// Handler for BgpNeighborReq.
//
void BgpNeighborReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
s1.cbFn_ = boost::bind(&BgpShowHandler<
BgpNeighborReq,
BgpNeighborReqIterate,
BgpNeighborListResp,
BgpNeighborResp>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
BgpNeighborReq,
BgpNeighborReqIterate,
BgpNeighborListResp,
BgpNeighborResp>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for BgpNeighborReqIterate.
//
void BgpNeighborReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
s1.cbFn_ = boost::bind(&BgpShowHandler<
BgpNeighborReq,
BgpNeighborReqIterate,
BgpNeighborListResp,
BgpNeighborResp>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
BgpNeighborReq,
BgpNeighborReqIterate,
BgpNeighborListResp,
BgpNeighborResp>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowBgpNeighborSummaryReq.
//
void ShowBgpNeighborSummaryReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowBgpNeighborSummaryReq,
ShowBgpNeighborSummaryReqIterate,
ShowBgpNeighborSummaryResp,
BgpNeighborResp>::Callback, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowBgpNeighborSummaryReq,
ShowBgpNeighborSummaryReqIterate,
ShowBgpNeighborSummaryResp,
BgpNeighborResp>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}
//
// Handler for ShowBgpNeighborSummaryReqIterate.
//
void ShowBgpNeighborSummaryReqIterate::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
s1.cbFn_ = boost::bind(&BgpShowHandler<
ShowBgpNeighborSummaryReq,
ShowBgpNeighborSummaryReqIterate,
ShowBgpNeighborSummaryResp,
BgpNeighborResp>::CallbackIterate, _1, _2, _3, _4, _5);
s1.allocFn_ = BgpShowHandler<
ShowBgpNeighborSummaryReq,
ShowBgpNeighborSummaryReqIterate,
ShowBgpNeighborSummaryResp,
BgpNeighborResp>::CreateData;
s1.instances_.push_back(0);
ps.stages_.push_back(s1);
RequestPipeline rp(ps);
}