Skip to content

Commit

Permalink
Extend introspect for config peering/neighbors to all instances
Browse files Browse the repository at this point in the history
Since BGPaaS configures peerings and neighbors in non-master instances,
extend introspect for config peerings and neighbors to show objects in
all instances.

Highlights:

- Fix syntax error in ShowBgpNeighborFamily sandesh definition
- Move code for neighbors to bgp_show_config.cc
- Move code for peerings to bgp_show_ifmap_peering_config.cc
- Add level of indirection to avoid linking issues for peering show
command.  This is needed because YAML config does not have notion of
peering.
- Paginate output for peerings and neighbors while we're at it
- Tweak tests so that they pass with the new code

Change-Id: Ic5dc47a7684e80ac693aea1e2660abff783ce681
Partial-Bug: 1518047
  • Loading branch information
Nischal Sheth committed Nov 24, 2015
1 parent 87a0293 commit 355b88a
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 150 deletions.
2 changes: 2 additions & 0 deletions src/bgp/SConscript
Expand Up @@ -82,6 +82,8 @@ libbgp_ifmap_config = env.Library('bgp_ifmap_config',
'bgp_config_ifmap.cc',
'bgp_config_listener.cc',
'bgp_config_parser.cc',
'bgp_ifmap_sandesh.cc',
'bgp_show_ifmap_peering_config.cc',
])

libbgp_xmpp = env.Library('bgp_xmpp',
Expand Down
6 changes: 3 additions & 3 deletions src/bgp/bgp_config_ifmap.h
Expand Up @@ -81,6 +81,7 @@ class BgpIfmapPeeringConfig {

const IFMapNode *node() const { return node_proxy_.node(); }
BgpIfmapInstanceConfig *instance() { return instance_; }
const BgpIfmapInstanceConfig *instance() const { return instance_; }
std::string name() const { return name_; }
size_t size() const { return neighbors_.size(); }
const autogen::BgpPeering *bgp_peering() const {
Expand Down Expand Up @@ -208,9 +209,8 @@ class BgpIfmapInstanceConfig {

BgpConfigManager::NeighborMapRange NeighborMapItems() const;

const NeighborMap &neighbors() const {
return neighbors_;
}
const NeighborMap &neighbors() const { return neighbors_; }
const PeeringMap &peerings() const { return peerings_; }

void AddPeering(BgpIfmapPeeringConfig *peering);
void DeletePeering(BgpIfmapPeeringConfig *peering);
Expand Down
22 changes: 22 additions & 0 deletions src/bgp/bgp_ifmap_sandesh.cc
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
#include "bgp/bgp_ifmap_sandesh.h"

#include "bgp/bgp_sandesh.h"

class ShowBgpPeeringConfigReq;
class ShowBgpPeeringConfigReqIterate;

extern void ShowBgpIfmapPeeringConfigReqHandler(
const BgpSandeshContext *bsc,
const ShowBgpPeeringConfigReq *req);
extern void ShowBgpIfmapPeeringConfigReqIterateHandler(
const BgpSandeshContext *bsc,
const ShowBgpPeeringConfigReqIterate *req_iterate);

void RegisterSandeshShowIfmapHandlers(BgpSandeshContext *bsc) {
bsc->SetPeeringShowHandlers(
ShowBgpIfmapPeeringConfigReqHandler,
ShowBgpIfmapPeeringConfigReqIterateHandler);
}
8 changes: 8 additions & 0 deletions src/bgp/bgp_ifmap_sandesh.h
@@ -0,0 +1,8 @@
#ifndef BGP__BGP_IFMAP_SANDESH_H__
#define BGP__BGP_IFMAP_SANDESH_H__

struct BgpSandeshContext;

extern void RegisterSandeshShowIfmapHandlers(BgpSandeshContext *);

#endif // BGP__BGP_IFMAP_SANDESH_H__
19 changes: 16 additions & 3 deletions src/bgp/bgp_peer.sandesh
Expand Up @@ -40,9 +40,9 @@ struct BgpNeighborRoutingTable {
}

struct ShowBgpNeighborFamily {
string family;
u32 loop_count;
u32 prefix_limit;
1: string family;
2: u32 loop_count;
3: u32 prefix_limit;
}

struct BgpNeighborResp {
Expand Down Expand Up @@ -440,6 +440,16 @@ struct ShowBgpPeeringConfig {
4: list<ShowBgpSessionConfig> sessions;
}

response sandesh ShowBgpPeeringConfigResp {
1: list<ShowBgpPeeringConfig> peerings;
2: optional string next_batch (link="ShowBgpPeeringConfigReqIterate",
link_title="next_batch");
}

request sandesh ShowBgpPeeringConfigReq {
1: string search_string;
}

struct ShowBgpNeighborFamilyConfig {
1: string family;
2: i32 loop_count;
Expand Down Expand Up @@ -468,9 +478,12 @@ struct ShowBgpNeighborConfig {

response sandesh ShowBgpNeighborConfigResp {
1: list<ShowBgpNeighborConfig> neighbors;
2: optional string next_batch (link="ShowBgpNeighborConfigReqIterate",
link_title="next_batch");
}

request sandesh ShowBgpNeighborConfigReq {
1: string search_string;
}

struct BgpPeerInfoData {
Expand Down
9 changes: 5 additions & 4 deletions src/bgp/bgp_peer_internal.sandesh
Expand Up @@ -94,9 +94,10 @@ request sandesh ShowBgpInstanceConfigReqIterate {
1: string iterate_info;
}

response sandesh ShowBgpPeeringConfigResp {
1: list<bgp_peer.ShowBgpPeeringConfig> peerings;
request sandesh ShowBgpPeeringConfigReqIterate {
1: string iterate_info;
}

request sandesh ShowBgpPeeringConfigReq {
}
request sandesh ShowBgpNeighborConfigReqIterate {
1: string iterate_info;
}
160 changes: 27 additions & 133 deletions src/bgp/bgp_sandesh.cc
Expand Up @@ -377,139 +377,6 @@ void ShowRouteVrfReq::HandleRequest() const {
RequestPipeline rp(ps);
}

class ShowBgpPeeringConfigHandler {
public:
static bool CallbackS1(const Sandesh *sr,
const RequestPipeline::PipeSpec ps,
int stage, int instNum,
RequestPipeline::InstData *data) {
const ShowBgpPeeringConfigReq *req =
static_cast<const ShowBgpPeeringConfigReq *>(ps.snhRequest_.get());
BgpSandeshContext *bsc =
static_cast<BgpSandeshContext *>(req->client_context());
BgpConfigManager *bcm = bsc->bgp_server->config_manager();

vector<ShowBgpPeeringConfig> peering_list;
typedef std::pair<std::string, const BgpNeighborConfig *> pair_t;
BOOST_FOREACH(pair_t item, bcm->NeighborMapItems(
BgpConfigManager::kMasterInstance)) {
ShowBgpPeeringConfig peering;
const BgpNeighborConfig *neighbor = item.second;
peering.set_instance_name(neighbor->instance_name());
peering.set_name(neighbor->name());
peering.set_neighbor_count(1);

vector<ShowBgpSessionConfig> session_list;
ShowBgpSessionConfig session;
session.set_uuid(neighbor->uuid());
vector<ShowBgpSessionAttributesConfig> attribute_list;
ShowBgpSessionAttributesConfig attribute;
attribute.set_address_families(neighbor->GetAddressFamilies());
attribute_list.push_back(attribute);
session.set_attributes(attribute_list);
session_list.push_back(session);
peering.set_sessions(session_list);
peering_list.push_back(peering);
}

ShowBgpPeeringConfigResp *resp = new ShowBgpPeeringConfigResp;
resp->set_peerings(peering_list);
resp->set_context(req->context());
resp->Response();
return true;
}
};

void ShowBgpPeeringConfigReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);

// Request pipeline has single stage to collect peering config info
// and respond to the request
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
s1.cbFn_ = ShowBgpPeeringConfigHandler::CallbackS1;
s1.instances_.push_back(0);
ps.stages_ = list_of(s1);
RequestPipeline rp(ps);
}

class ShowBgpNeighborConfigHandler {
public:
static bool CallbackS1(const Sandesh *sr,
const RequestPipeline::PipeSpec ps,
int stage, int instNum,
RequestPipeline::InstData *data) {
const ShowBgpNeighborConfigReq *req =
static_cast<const ShowBgpNeighborConfigReq *>(ps.snhRequest_.get());
BgpSandeshContext *bsc =
static_cast<BgpSandeshContext *>(req->client_context());
BgpConfigManager *bcm = bsc->bgp_server->config_manager();

vector<ShowBgpNeighborConfig> nbr_list;

typedef std::pair<std::string, const BgpNeighborConfig *> pair_t;
BOOST_FOREACH(pair_t item, bcm->NeighborMapItems(
BgpConfigManager::kMasterInstance)) {
const BgpNeighborConfig *neighbor = item.second;
ShowBgpNeighborConfig nbr;
nbr.set_instance_name(neighbor->instance_name());
nbr.set_name(neighbor->name());
nbr.set_admin_down(neighbor->admin_down());
nbr.set_passive(neighbor->passive());
Ip4Address localid(ntohl(neighbor->local_identifier()));
nbr.set_local_identifier(localid.to_string());
nbr.set_local_as(neighbor->local_as());
nbr.set_autonomous_system(neighbor->peer_as());
Ip4Address peerid(ntohl(neighbor->peer_identifier()));
nbr.set_identifier(peerid.to_string());
nbr.set_address(neighbor->peer_address().to_string());
nbr.set_address_families(neighbor->GetAddressFamilies());
nbr.set_hold_time(neighbor->hold_time());
nbr.set_loop_count(neighbor->loop_count());
nbr.set_last_change_at(
UTCUsecToString(neighbor->last_change_at()));
nbr.set_auth_type(neighbor->auth_data().KeyTypeToString());
if (bsc->test_mode()) {
nbr.set_auth_keys(neighbor->auth_data().KeysToStringDetail());
}

vector<ShowBgpNeighborFamilyConfig> family_attributes_list;
BOOST_FOREACH(const BgpFamilyAttributesConfig family_config,
neighbor->family_attributes_list()) {
ShowBgpNeighborFamilyConfig family_attributes;
family_attributes.family = family_config.family;
family_attributes.loop_count = family_config.loop_count;
family_attributes.prefix_limit = family_config.prefix_limit;
family_attributes_list.push_back(family_attributes);
}
nbr.set_family_attributes_list(family_attributes_list);

nbr_list.push_back(nbr);
}

ShowBgpNeighborConfigResp *resp = new ShowBgpNeighborConfigResp;
resp->set_neighbors(nbr_list);
resp->set_context(req->context());
resp->Response();
return true;
}
};

void ShowBgpNeighborConfigReq::HandleRequest() const {
RequestPipeline::PipeSpec ps(this);

// Request pipeline has single stage to collect neighbor config info
// and respond to the request
RequestPipeline::StageSpec s1;
TaskScheduler *scheduler = TaskScheduler::GetInstance();
s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
s1.cbFn_ = ShowBgpNeighborConfigHandler::CallbackS1;
s1.instances_.push_back(0);
ps.stages_ = list_of(s1);
RequestPipeline rp(ps);
}

class ShowBgpServerHandler {
public:
static bool CallbackS1(const Sandesh *sr,
Expand Down Expand Up @@ -580,3 +447,30 @@ void BgpSandeshContext::ShowNeighborStatisticsExtension(
return;
show_neighbor_statistics_ext_(count, this, req);
}

void BgpSandeshContext::SetPeeringShowHandlers(
const PeeringReqHandler &show_peering_req_handler,
const PeeringReqIterateHandler &show_peering_req_iterate_handler) {
show_peering_req_handler_ = show_peering_req_handler;
show_peering_req_iterate_handler_ = show_peering_req_iterate_handler;
}

void BgpSandeshContext::PeeringShowReqHandler(
const ShowBgpPeeringConfigReq *req) {
if (show_peering_req_handler_) {
show_peering_req_handler_(this, req);
} else {
ShowBgpPeeringConfigResp *resp = new ShowBgpPeeringConfigResp;
resp->Response();
}
}

void BgpSandeshContext::PeeringShowReqIterateHandler(
const ShowBgpPeeringConfigReqIterate *req_iterate) {
if (show_peering_req_iterate_handler_) {
show_peering_req_iterate_handler_(this, req_iterate);
} else {
ShowBgpPeeringConfigResp *resp = new ShowBgpPeeringConfigResp;
resp->Response();
}
}
17 changes: 17 additions & 0 deletions src/bgp/bgp_sandesh.h
Expand Up @@ -14,6 +14,8 @@ class BgpNeighborResp;
class BgpNeighborReq;
class ShowBgpNeighborSummaryReq;
class ShowNeighborStatisticsReq;
class ShowBgpPeeringConfigReq;
class ShowBgpPeeringConfigReqIterate;

struct BgpSandeshContext : public SandeshContext {
typedef boost::function<bool(const BgpSandeshContext *, bool,
Expand All @@ -23,12 +25,21 @@ struct BgpSandeshContext : public SandeshContext {
typedef boost::function<void(size_t *, const BgpSandeshContext *,
const ShowNeighborStatisticsReq *)> NeighborStatisticsExtension;

typedef boost::function<void(const BgpSandeshContext *,
const ShowBgpPeeringConfigReq *)> PeeringReqHandler;
typedef boost::function<void(const BgpSandeshContext *,
const ShowBgpPeeringConfigReqIterate *)> PeeringReqIterateHandler;

BgpSandeshContext();

void SetNeighborShowExtensions(
const NeighborListExtension &show_neighbor,
const NeighborStatisticsExtension &show_neighbor_statistics);

void SetPeeringShowHandlers(
const PeeringReqHandler &show_peering_req_handler,
const PeeringReqIterateHandler &show_peering_req_iterate_handler);

BgpServer *bgp_server;
BgpXmppChannelManager *xmpp_peer_manager;

Expand All @@ -39,6 +50,10 @@ struct BgpSandeshContext : public SandeshContext {
void ShowNeighborStatisticsExtension(size_t *count,
const ShowNeighborStatisticsReq *req) const;

void PeeringShowReqHandler(const ShowBgpPeeringConfigReq *req);
void PeeringShowReqIterateHandler(
const ShowBgpPeeringConfigReqIterate *req_iterate);

// For testing.
bool test_mode() const { return test_mode_; }
void set_test_mode(bool test_mode) { test_mode_ = test_mode; }
Expand All @@ -53,6 +68,8 @@ struct BgpSandeshContext : public SandeshContext {
uint32_t iter_limit_;
NeighborListExtension show_neighbor_ext_;
NeighborStatisticsExtension show_neighbor_statistics_ext_;
PeeringReqHandler show_peering_req_handler_;
PeeringReqIterateHandler show_peering_req_iterate_handler_;
};

#endif /* BGP_SANDESH_H_ */

0 comments on commit 355b88a

Please sign in to comment.