Skip to content

Commit

Permalink
Add admin_down configuration for bgp router and neighbor
Browse files Browse the repository at this point in the history
Highlights:

- Add admin-down to BgpRouterParams and BgpSessionAttributes in schema
- BgpPeer is admin down if it's configured to be admin down
- BgpPeer is admin down if local or remote bgp-router is admin down
- Add admin down state to BgpServer
- Reuse existing admin down functionality in BgpPeer and StateMachine
- Include admin down in introspect, tracing, logging and UVEs
- Don't publish to discovery is the bgp-router is admin down
- Bring down all xmpp connections if bgp-router is admin down
- Don't accept xmpp connections if bgp-router is admin down
- Add tests to exercise the new code

Change-Id: I2eae401902f1af6132ddddd28605482eef29de21
Closes-Bug: 1514670
  • Loading branch information
Nischal Sheth committed Nov 12, 2015
1 parent 24e067f commit 2e42ea8
Show file tree
Hide file tree
Showing 18 changed files with 720 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/bgp/bgp_config.cc
Expand Up @@ -138,6 +138,7 @@ std::vector<std::string> AuthenticationData::KeysToStringDetail() const {

BgpNeighborConfig::BgpNeighborConfig()
: type_(UNSPECIFIED),
admin_down_(false),
peer_as_(0),
identifier_(0),
port_(BgpConfigManager::kDefaultPort),
Expand All @@ -151,6 +152,7 @@ void BgpNeighborConfig::CopyValues(const BgpNeighborConfig &rhs) {
instance_name_ = rhs.instance_name_;
group_name_ = rhs.group_name_;
type_ = rhs.type_;
admin_down_ = rhs.admin_down_;
peer_as_ = rhs.peer_as_;
identifier_ = rhs.identifier_;
address_ = rhs.address_;
Expand All @@ -167,6 +169,7 @@ int BgpNeighborConfig::CompareTo(const BgpNeighborConfig &rhs) const {
KEY_COMPARE(uuid_, rhs.uuid_);
KEY_COMPARE(instance_name_, rhs.instance_name_);
KEY_COMPARE(type_, rhs.type_);
KEY_COMPARE(admin_down_, rhs.admin_down_);
KEY_COMPARE(peer_as_, rhs.peer_as_);
KEY_COMPARE(identifier_, rhs.identifier_);
KEY_COMPARE(address_, rhs.address_);
Expand Down Expand Up @@ -202,6 +205,7 @@ std::vector<std::string> BgpNeighborConfig::AuthKeysToString() const {

BgpProtocolConfig::BgpProtocolConfig(const std::string &instance_name)
: instance_name_(instance_name),
admin_down_(false),
autonomous_system_(0),
local_autonomous_system_(0),
identifier_(0),
Expand All @@ -212,6 +216,7 @@ BgpProtocolConfig::BgpProtocolConfig(const std::string &instance_name)

int BgpProtocolConfig::CompareTo(const BgpProtocolConfig &rhs) const {
KEY_COMPARE(instance_name_, rhs.instance_name_);
KEY_COMPARE(admin_down_, rhs.admin_down_);
KEY_COMPARE(autonomous_system_, rhs.autonomous_system_);
KEY_COMPARE(identifier_, rhs.identifier_);
KEY_COMPARE(port_, rhs.port_);
Expand Down
11 changes: 10 additions & 1 deletion src/bgp/bgp_config.h
Expand Up @@ -159,7 +159,10 @@ class BgpNeighborConfig {

Type peer_type() const { return type_; }
void set_peer_type(Type type) { type_ = type; }


bool admin_down() const { return admin_down_; }
void set_admin_down(bool admin_down) { admin_down_ = admin_down; }

uint32_t peer_as() const { return peer_as_; }
void set_peer_as(uint32_t peer_as) { peer_as_ = peer_as; }

Expand Down Expand Up @@ -220,6 +223,7 @@ class BgpNeighborConfig {
std::string instance_name_;
std::string group_name_;
Type type_;
bool admin_down_;
uint32_t peer_as_;
uint32_t identifier_;
IpAddress address_;
Expand Down Expand Up @@ -339,8 +343,12 @@ class BgpProtocolConfig {

int CompareTo(const BgpProtocolConfig &rhs) const;

bool admin_down() const { return admin_down_; }
void set_admin_down(bool admin_down) { admin_down_ = admin_down; }

uint32_t identifier() const { return identifier_; }
void set_identifier(uint32_t identifier) { identifier_ = identifier; }

uint32_t autonomous_system() const { return autonomous_system_; }
void set_autonomous_system(uint32_t autonomous_system) {
autonomous_system_ = autonomous_system;
Expand All @@ -364,6 +372,7 @@ class BgpProtocolConfig {

private:
std::string instance_name_;
bool admin_down_;
uint32_t autonomous_system_;
uint32_t local_autonomous_system_;
uint32_t identifier_;
Expand Down
15 changes: 15 additions & 0 deletions src/bgp/bgp_config_ifmap.cc
Expand Up @@ -168,6 +168,9 @@ static void NeighborSetSessionAttributes(
attributes = local;
}
if (attributes != NULL) {
if (attributes->admin_down) {
neighbor->set_admin_down(true);
}
if (attributes->hold_time) {
neighbor->set_hold_time(attributes->hold_time);
}
Expand Down Expand Up @@ -199,6 +202,9 @@ static BgpNeighborConfig *MakeBgpNeighborConfig(
// Store a copy of the remote bgp-router's autogen::BgpRouterParams and
// derive the autogen::BgpSessionAttributes for the session.
const autogen::BgpRouterParams &params = remote_router->parameters();
if (params.admin_down) {
neighbor->set_admin_down(true);
}
if (params.local_autonomous_system) {
neighbor->set_peer_as(params.local_autonomous_system);
} else {
Expand Down Expand Up @@ -232,6 +238,9 @@ static BgpNeighborConfig *MakeBgpNeighborConfig(
const BgpIfmapProtocolConfig *protocol = instance->protocol_config();
if (protocol && protocol->bgp_router()) {
const autogen::BgpRouterParams &params = protocol->router_params();
if (params.admin_down) {
neighbor->set_admin_down(true);
}
Ip4Address localid = Ip4Address::from_string(params.identifier, err);
if (err == 0) {
neighbor->set_local_identifier(IpAddressToBgpIdentifier(localid));
Expand Down Expand Up @@ -464,6 +473,7 @@ void BgpIfmapProtocolConfig::Update(BgpIfmapConfigManager *manager,
const autogen::BgpRouter *router) {
bgp_router_.reset(router);
const autogen::BgpRouterParams &params = router->parameters();
data_.set_admin_down(params.admin_down);
data_.set_autonomous_system(params.autonomous_system);
data_.set_local_autonomous_system(params.local_autonomous_system);
boost::system::error_code err;
Expand Down Expand Up @@ -793,6 +803,7 @@ void BgpIfmapInstanceConfig::AddNeighbor(BgpConfigManager *manager,
BGP_CONFIG_LOG_NEIGHBOR(
Create, manager->server(), neighbor, SandeshLevel::SYS_DEBUG,
BGP_LOG_FLAG_ALL,
neighbor->admin_down(),
BgpIdentifierToString(neighbor->local_identifier()),
neighbor->local_as(),
neighbor->peer_address().to_string(), neighbor->peer_as(),
Expand All @@ -814,6 +825,7 @@ void BgpIfmapInstanceConfig::ChangeNeighbor(BgpConfigManager *manager,
BGP_CONFIG_LOG_NEIGHBOR(
Update, manager->server(), neighbor,
SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
neighbor->admin_down(),
BgpIdentifierToString(neighbor->local_identifier()),
neighbor->local_as(),
neighbor->peer_address().to_string(), neighbor->peer_as(),
Expand Down Expand Up @@ -1147,6 +1159,7 @@ void BgpIfmapConfigManager::DefaultConfig() {
BGP_CONFIG_LOG_PROTOCOL(
Create, server(), protocol,
SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
protocol->router_params().admin_down,
protocol->router_params().autonomous_system,
protocol->router_params().identifier,
protocol->router_params().address,
Expand Down Expand Up @@ -1340,6 +1353,7 @@ void BgpIfmapConfigManager::ProcessBgpProtocol(const BgpConfigDelta &delta) {
if (event == BgpConfigManager::CFG_ADD) {
BGP_CONFIG_LOG_PROTOCOL(Create, server(), protocol,
SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
protocol->router_params().admin_down,
protocol->router_params().autonomous_system,
protocol->router_params().identifier,
protocol->router_params().address,
Expand All @@ -1348,6 +1362,7 @@ void BgpIfmapConfigManager::ProcessBgpProtocol(const BgpConfigDelta &delta) {
} else {
BGP_CONFIG_LOG_PROTOCOL(Update, server(), protocol,
SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_ALL,
protocol->router_params().admin_down,
protocol->router_params().autonomous_system,
protocol->router_params().identifier,
protocol->router_params().address,
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_config_ifmap.h
Expand Up @@ -134,6 +134,7 @@ class BgpIfmapProtocolConfig {
const BgpIfmapInstanceConfig *instance() { return instance_; }

const BgpProtocolConfig *protocol_config() const { return &data_; }

private:
BgpIfmapInstanceConfig *instance_;
IFMapNodeProxy node_proxy_;
Expand Down
16 changes: 16 additions & 0 deletions src/bgp/bgp_log.sandesh
Expand Up @@ -121,6 +121,8 @@ systemlog sandesh BgpConfigInstanceUpdateLog {
trace sandesh BgpConfigNeighborCreateTrace {
1: "Neighbor";
2: string name;
16: "AdminDown";
17: bool admin_down;
9: "Local Identifier";
10: string local_identifier;
11: "Local AS";
Expand All @@ -139,6 +141,8 @@ trace sandesh BgpConfigNeighborCreateTrace {
systemlog sandesh BgpConfigNeighborCreateLog {
1: "Neighbor";
2: string name;
16: "AdminDown";
17: bool admin_down;
9: "Local Identifier";
10: string local_identifier;
11: "Local AS";
Expand Down Expand Up @@ -167,6 +171,8 @@ systemlog sandesh BgpConfigNeighborDeleteLog {
trace sandesh BgpConfigNeighborUpdateTrace {
1: "Neighbor";
2: string name;
16: "AdminDown";
17: bool admin_down;
9: "Local Identifier";
10: string local_identifier;
11: "Local AS";
Expand All @@ -185,6 +191,8 @@ trace sandesh BgpConfigNeighborUpdateTrace {
systemlog sandesh BgpConfigNeighborUpdateLog {
1: "Neighbor";
2: string name;
16: "AdminDown";
17: bool admin_down;
9: "Local Identifier";
10: string local_identifier;
11: "Local AS";
Expand Down Expand Up @@ -233,6 +241,8 @@ systemlog sandesh BgpConfigPeeringUpdateLog {
trace sandesh BgpConfigProtocolCreateTrace {
1: "Routing Instance";
2: string name;
13: "AdminDown";
14: bool admin_down;
3: "Local AS";
4: i32 as_number;
5: "Router ID";
Expand All @@ -248,6 +258,8 @@ trace sandesh BgpConfigProtocolCreateTrace {
systemlog sandesh BgpConfigProtocolCreateLog {
1: "Routing Instance";
2: string name;
13: "AdminDown";
14: bool admin_down;
3: "Local AS";
4: i32 as_number;
5: "Router ID";
Expand All @@ -273,6 +285,8 @@ systemlog sandesh BgpConfigProtocolDeleteLog {
trace sandesh BgpConfigProtocolUpdateTrace {
1: "Routing Instance";
2: string name;
13: "AdminDown";
14: bool admin_down;
3: "Local AS";
4: i32 as_number;
5: "Router ID";
Expand All @@ -288,6 +302,8 @@ trace sandesh BgpConfigProtocolUpdateTrace {
systemlog sandesh BgpConfigProtocolUpdateLog {
1: "Routing Instance";
2: string name;
13: "AdminDown";
14: bool admin_down;
3: "Local AS";
4: i32 as_number;
5: "Router ID";
Expand Down
16 changes: 12 additions & 4 deletions src/bgp/bgp_peer.cc
Expand Up @@ -352,7 +352,7 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance,
TaskScheduler::GetInstance()->GetTaskId("bgp::StateMachine"),
GetIndex())),
send_ready_(true),
admin_down_(false),
admin_down_(config->admin_down()),
state_machine_(BgpObjectFactory::Create<StateMachine>(this)),
membership_req_pending_(0),
defer_close_(false),
Expand Down Expand Up @@ -390,8 +390,9 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance,

BgpPeerInfoData peer_info;
peer_info.set_name(ToUVEKey());
peer_info.set_peer_type(PeerType() == BgpProto::IBGP ?
"internal" : "external");
peer_info.set_admin_down(admin_down_);
peer_info.set_peer_type(
PeerType() == BgpProto::IBGP ? "internal" : "external");
peer_info.set_local_asn(local_as_);
peer_info.set_peer_asn(peer_as_);
peer_info.set_local_id(local_bgp_id_);
Expand All @@ -413,7 +414,8 @@ BgpPeer::~BgpPeer() {
}

void BgpPeer::Initialize() {
state_machine_->Initialize();
if (!admin_down_)
state_machine_->Initialize();
}

void BgpPeer::BindLocalEndpoint(BgpSession *session) {
Expand Down Expand Up @@ -553,6 +555,11 @@ void BgpPeer::ConfigUpdate(const BgpNeighborConfig *config) {
BgpPeerInfoData peer_info;
peer_info.set_name(ToUVEKey());

if (admin_down_ != config->admin_down()) {
SetAdminState(config->admin_down());
peer_info.set_admin_down(admin_down_);
}

// Check if there is any change in the peer address.
// If the peer address is changing, remove the key for the older address.
// Update with the new peer address and then process the key chain info
Expand Down Expand Up @@ -1579,6 +1586,7 @@ void BgpPeer::FillNeighborInfo(const BgpSandeshContext *bsc,
nbr.set_peer(peer_basename_);
nbr.set_deleted(IsDeleted());
nbr.set_deleted_at(UTCUsecToString(deleter_->delete_time_stamp_usecs()));
nbr.set_admin_down(admin_down_);
nbr.set_peer_address(peer_key_.endpoint.address().to_string());
nbr.set_peer_id(bgp_identifier_string());
nbr.set_peer_asn(peer_as());
Expand Down
5 changes: 4 additions & 1 deletion src/bgp/bgp_peer.sandesh
Expand Up @@ -43,6 +43,7 @@ struct BgpNeighborResp {
1: string peer (link="BgpNeighborReq"); // Peer name
36: bool deleted; // Deletion in progress
43: string deleted_at;
47: bool admin_down;
2: string peer_address (link="BgpNeighborReq");
25: string peer_id;
3: u32 peer_asn;
Expand Down Expand Up @@ -434,6 +435,7 @@ struct ShowBgpPeeringConfig {
struct ShowBgpNeighborConfig {
1: string instance_name;
2: string name;
13: bool admin_down;
8: string local_identifier;
9: i32 local_as;
3: string vendor;
Expand All @@ -456,7 +458,8 @@ request sandesh ShowBgpNeighborConfigReq {

struct BgpPeerInfoData {
1: string name (key="ObjectBgpPeer"); // RoutingInstance:RemoteEnd:LocalEnd
2: optional bool deleted
2: optional bool deleted
23: optional bool admin_down
3: optional string peer_type; // internal/external
20: optional string peer_address;
4: optional u32 local_asn;
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_sandesh.cc
Expand Up @@ -455,6 +455,7 @@ class ShowBgpNeighborConfigHandler {
ShowBgpNeighborConfig nbr;
nbr.set_instance_name(neighbor->instance_name());
nbr.set_name(neighbor->name());
nbr.set_admin_down(neighbor->admin_down());
Ip4Address localid(ntohl(neighbor->local_identifier()));
nbr.set_local_identifier(localid.to_string());
nbr.set_local_as(neighbor->local_as());
Expand Down

0 comments on commit 2e42ea8

Please sign in to comment.