From 40de43080f177b88c0bd6defd1da0eaf86135877 Mon Sep 17 00:00:00 2001 From: Nischal Sheth Date: Tue, 1 Dec 2015 11:14:23 -0800 Subject: [PATCH] Further progress on BGPaaS implementation Highlights: - Schema updates for BGPaaS - Do not use BgpAsAServiceParameters as it's being removed - Use the port number from the remote bgp-router - Update unit tests based on above changes - Do not export routes to BgpPeers in non-master instances - Add router type and port fields to ShowBgpNeighborConfig - Add router type, peer port and transport address to BgpNeighborResp - Cosmetic changes to BgpNeighborResp related methods - Add couple of paranoid checks to RibOut and PeerRibMembershipManager Change-Id: Id9c06579549f648996e22bf07bd4f79fd47768fa Partial-Bug: 1518047 --- src/bgp/bgp_config.cc | 2 - src/bgp/bgp_config.h | 5 - src/bgp/bgp_config_ifmap.cc | 23 --- src/bgp/bgp_config_parser.cc | 4 +- src/bgp/bgp_peer.cc | 113 ++++++----- src/bgp/bgp_peer.h | 14 +- src/bgp/bgp_peer.sandesh | 13 +- src/bgp/bgp_peer_membership.cc | 11 +- src/bgp/bgp_ribout.cc | 5 +- src/bgp/bgp_server.cc | 8 +- src/bgp/bgp_session_manager.cc | 17 +- src/bgp/bgp_show_config.cc | 2 + src/bgp/bgp_show_neighbor.cc | 6 +- src/bgp/bgp_table.cc | 6 + src/bgp/bgp_xmpp_channel.cc | 23 ++- src/bgp/bgp_xmpp_channel.h | 7 +- src/bgp/bgp_xmpp_sandesh.cc | 3 +- src/bgp/routing-instance/peer_manager.cc | 7 +- src/bgp/routing-instance/peer_manager.h | 2 +- src/bgp/test/bgp_config_test.cc | 136 ++++--------- src/bgp/test/bgp_ifmap_config_manager_test.cc | 185 ++++++------------ src/bgp/testdata/config_test_36a.xml | 2 + src/bgp/testdata/config_test_36c.xml | 71 +++++++ src/bgp/testdata/config_test_36d.xml | 71 +++++++ src/schema/bgp_schema.xsd | 8 - src/schema/vnc_cfg.xsd | 8 +- 26 files changed, 397 insertions(+), 355 deletions(-) create mode 100644 src/bgp/testdata/config_test_36c.xml create mode 100644 src/bgp/testdata/config_test_36d.xml diff --git a/src/bgp/bgp_config.cc b/src/bgp/bgp_config.cc index 7ce6270e388..1ab6146c3a0 100644 --- a/src/bgp/bgp_config.cc +++ b/src/bgp/bgp_config.cc @@ -160,7 +160,6 @@ void BgpNeighborConfig::CopyValues(const BgpNeighborConfig &rhs) { identifier_ = rhs.identifier_; address_ = rhs.address_; port_ = rhs.port_; - remote_endpoint_ = rhs.remote_endpoint_; hold_time_ = rhs.hold_time_; loop_count_ = rhs.loop_count_; local_as_ = rhs.local_as_; @@ -180,7 +179,6 @@ int BgpNeighborConfig::CompareTo(const BgpNeighborConfig &rhs) const { KEY_COMPARE(identifier_, rhs.identifier_); KEY_COMPARE(address_, rhs.address_); KEY_COMPARE(port_, rhs.port_); - KEY_COMPARE(remote_endpoint_, rhs.remote_endpoint_); KEY_COMPARE(hold_time_, rhs.hold_time_); KEY_COMPARE(loop_count_, rhs.loop_count_); KEY_COMPARE(local_as_, rhs.local_as_); diff --git a/src/bgp/bgp_config.h b/src/bgp/bgp_config.h index 444a3ec300d..1d9514b359b 100644 --- a/src/bgp/bgp_config.h +++ b/src/bgp/bgp_config.h @@ -185,11 +185,6 @@ class BgpNeighborConfig { int port() const { return port_; } void set_port(int port) { port_ = port; } - TcpSession::Endpoint remote_endpoint() const { return remote_endpoint_; } - void set_remote_endpoint(TcpSession::Endpoint remote_endpoint) { - remote_endpoint_ = remote_endpoint; - } - std::string router_type() const { return router_type_; } void set_router_type(const std::string &router_type) { router_type_ = router_type; diff --git a/src/bgp/bgp_config_ifmap.cc b/src/bgp/bgp_config_ifmap.cc index 000e2ffbc14..2fb8324a403 100644 --- a/src/bgp/bgp_config_ifmap.cc +++ b/src/bgp/bgp_config_ifmap.cc @@ -302,29 +302,6 @@ static BgpNeighborConfig *MakeBgpNeighborConfig( NeighborSetSessionAttributes(neighbor, local_name, session); } - // Get remote endpoint information for bgpaas-clients if appropriate. - if (params.router_type == "bgpaas-client" && - remote_router->IsPropertySet( - autogen::BgpRouter::BGP_AS_A_SERVICE_PARAMETERS)) { - const autogen::BgpAsAServiceParameters &bgpaas_params = - remote_router->bgp_as_a_service_parameters(); - Ip4Address vrouter_address = - Ip4Address::from_string(bgpaas_params.vrouter_ip_address, err); - if (err) { - BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_WARN, BGP_LOG_FLAG_ALL, - "Invalid bgpaas-client vrouter ip address " << - bgpaas_params.vrouter_ip_address << - " for neighbor " << neighbor->name()); - } - if (bgpaas_params.port < 0 || bgpaas_params.port > 65535) { - BGP_LOG_STR(BgpConfig, SandeshLevel::SYS_WARN, BGP_LOG_FLAG_ALL, - "Invalid bgpaas-client port " << bgpaas_params.port << - " for neighbor " << neighbor->name()); - } - neighbor->set_remote_endpoint(TcpSession::Endpoint(vrouter_address, - static_cast(bgpaas_params.port))); - } - // Get the local identifier and local as from the master protocol config. const BgpIfmapProtocolConfig *master_protocol = master_instance->protocol_config(); diff --git a/src/bgp/bgp_config_parser.cc b/src/bgp/bgp_config_parser.cc index 128fab6d4d0..b1dc4c98d17 100644 --- a/src/bgp/bgp_config_parser.cc +++ b/src/bgp/bgp_config_parser.cc @@ -369,10 +369,10 @@ static bool ParseBgpRouter(const string &instance, const xml_node &node, } if (add_change) { - MapObjectSetProperty("bgp-router", fqname, - "bgp-router-parameters", property.release(), requests); MapObjectLink("routing-instance", instance, "bgp-router", fqname, "instance-bgp-router", requests); + MapObjectSetProperty("bgp-router", fqname, + "bgp-router-parameters", property.release(), requests); } else { MapObjectClearProperty("bgp-router", fqname, "bgp-router-parameters", requests); diff --git a/src/bgp/bgp_peer.cc b/src/bgp/bgp_peer.cc index 494f38fe8f6..1123a8d21c3 100644 --- a/src/bgp/bgp_peer.cc +++ b/src/bgp/bgp_peer.cc @@ -343,7 +343,6 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, : server_(server), rtinstance_(instance), peer_key_(config), - remote_endpoint_(config->remote_endpoint()), peer_name_(config->name()), router_type_(config->router_type()), config_(config), @@ -394,6 +393,7 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, refcount_ = 0; primary_path_count_ = 0; + ProcessEndpointConfig(config); ProcessAuthKeyChainConfig(config); ProcessFamilyAttributesConfig(config); @@ -550,6 +550,14 @@ bool BgpPeer::ProcessFamilyAttributesConfig(const BgpNeighborConfig *config) { return (ret != 0); } +void BgpPeer::ProcessEndpointConfig(const BgpNeighborConfig *config) { + if (config->router_type() == "bgpaas-client") { + endpoint_ = TcpSession::Endpoint(Ip4Address(), config->port()); + } else { + endpoint_ = TcpSession::Endpoint(); + } +} + void BgpPeer::ConfigUpdate(const BgpNeighborConfig *config) { if (IsDeleted()) return; @@ -596,6 +604,7 @@ void BgpPeer::ConfigUpdate(const BgpNeighborConfig *config) { peer_info.set_peer_address(peer_key_.endpoint.address().to_string()); clear_session = true; } + ProcessEndpointConfig(config); ProcessAuthKeyChainConfig(config); // Check if there is any change in the configured address families. @@ -604,11 +613,6 @@ void BgpPeer::ConfigUpdate(const BgpNeighborConfig *config) { clear_session = true; } - if (remote_endpoint_ != config->remote_endpoint()) { - remote_endpoint_ = config->remote_endpoint(); - clear_session = true; - } - BgpProto::BgpPeerType old_type = PeerType(); if (local_as_ != config->local_as()) { local_as_ = config->local_as(); @@ -724,6 +728,15 @@ string BgpPeer::bgp_identifier_string() const { return Ip4Address(ntohl(peer_bgp_id_)).to_string(); } +string BgpPeer::transport_address_string() const { + TcpSession::Endpoint endpoint; + ostringstream oss; + if (session_) + endpoint = session_->remote_endpoint(); + oss << endpoint; + return oss.str(); +} + // // Customized close routing for BgpPeers. // @@ -1605,45 +1618,45 @@ static void FillSocketStats(const IPeerDebugStats::SocketStats &socket_stats, } } -void BgpPeer::FillBgpNeighborDebugState(BgpNeighborResp &resp, +void BgpPeer::FillBgpNeighborDebugState(BgpNeighborResp *bnr, const IPeerDebugStats *peer_state) { - resp.set_last_state(peer_state->last_state()); - resp.set_last_event(peer_state->last_event()); - resp.set_last_error(peer_state->last_error()); - resp.set_last_state_at(peer_state->last_state_change_at()); - resp.set_flap_count(peer_state->num_flaps()); - resp.set_flap_time(peer_state->last_flap()); + bnr->set_last_state(peer_state->last_state()); + bnr->set_last_event(peer_state->last_event()); + bnr->set_last_error(peer_state->last_error()); + bnr->set_last_state_at(peer_state->last_state_change_at()); + bnr->set_flap_count(peer_state->num_flaps()); + bnr->set_flap_time(peer_state->last_flap()); IPeerDebugStats::ProtoStats stats; PeerProtoStats proto_stats; peer_state->GetRxProtoStats(&stats); FillProtoStats(stats, proto_stats); - resp.set_rx_proto_stats(proto_stats); + bnr->set_rx_proto_stats(proto_stats); peer_state->GetTxProtoStats(&stats); FillProtoStats(stats, proto_stats); - resp.set_tx_proto_stats(proto_stats); + bnr->set_tx_proto_stats(proto_stats); IPeerDebugStats::UpdateStats update_stats; PeerUpdateStats rt_stats; peer_state->GetRxRouteUpdateStats(&update_stats); FillRouteUpdateStats(update_stats, rt_stats); - resp.set_rx_update_stats(rt_stats); + bnr->set_rx_update_stats(rt_stats); peer_state->GetTxRouteUpdateStats(&update_stats); FillRouteUpdateStats(update_stats, rt_stats); - resp.set_tx_update_stats(rt_stats); + bnr->set_tx_update_stats(rt_stats); IPeerDebugStats::SocketStats socket_stats; PeerSocketStats peer_socket_stats; peer_state->GetRxSocketStats(&socket_stats); FillSocketStats(socket_stats, peer_socket_stats); - resp.set_rx_socket_stats(peer_socket_stats); + bnr->set_rx_socket_stats(peer_socket_stats); peer_state->GetTxSocketStats(&socket_stats); FillSocketStats(socket_stats, peer_socket_stats); - resp.set_tx_socket_stats(peer_socket_stats); + bnr->set_tx_socket_stats(peer_socket_stats); } void BgpPeer::FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const { @@ -1664,43 +1677,43 @@ void BgpPeer::FillBgpNeighborFamilyAttributes(BgpNeighborResp *nbr) const { } void BgpPeer::FillNeighborInfo(const BgpSandeshContext *bsc, - vector *nbr_list, bool summary) const { - BgpNeighborResp nbr; - 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_passive(passive_); - nbr.set_peer_address(peer_key_.endpoint.address().to_string()); - nbr.set_peer_id(bgp_identifier_string()); - nbr.set_peer_asn(peer_as()); - nbr.set_encoding("BGP"); - nbr.set_peer_type(PeerType() == BgpProto::IBGP ? "internal" : "external"); - nbr.set_state(state_machine_->StateName()); - nbr.set_local_address(server_->ToString()); - nbr.set_local_id(Ip4Address(ntohl(local_bgp_id_)).to_string()); - nbr.set_local_asn(local_as()); - nbr.set_negotiated_hold_time(state_machine_->hold_time()); - nbr.set_primary_path_count(GetPrimaryPathCount()); - nbr.set_auth_type(AuthenticationData::KeyTypeToString(inuse_authkey_type_)); + BgpNeighborResp *bnr, bool summary) const { + bnr->set_peer(peer_basename_); + bnr->set_deleted(IsDeleted()); + bnr->set_deleted_at(UTCUsecToString(deleter_->delete_time_stamp_usecs())); + bnr->set_admin_down(admin_down_); + bnr->set_passive(passive_); + bnr->set_peer_address(peer_address_string()); + bnr->set_peer_id(bgp_identifier_string()); + bnr->set_peer_asn(peer_as()); + bnr->set_peer_port(peer_port()); + bnr->set_transport_address(transport_address_string()); + bnr->set_encoding("BGP"); + bnr->set_peer_type(PeerType() == BgpProto::IBGP ? "internal" : "external"); + bnr->set_router_type(router_type_); + bnr->set_state(state_machine_->StateName()); + bnr->set_local_address(server_->ToString()); + bnr->set_local_id(Ip4Address(ntohl(local_bgp_id_)).to_string()); + bnr->set_local_asn(local_as()); + bnr->set_negotiated_hold_time(state_machine_->hold_time()); + bnr->set_primary_path_count(GetPrimaryPathCount()); + bnr->set_auth_type( + AuthenticationData::KeyTypeToString(inuse_authkey_type_)); if (bsc->test_mode()) { - nbr.set_auth_keys(auth_data_.KeysToStringDetail()); + bnr->set_auth_keys(auth_data_.KeysToStringDetail()); } - if (summary) { - nbr_list->push_back(nbr); + if (summary) return; - } - nbr.set_configured_address_families(configured_families_); - nbr.set_negotiated_address_families(negotiated_families_); - nbr.set_configured_hold_time(state_machine_->GetConfiguredHoldTime()); - FillBgpNeighborFamilyAttributes(&nbr); - FillBgpNeighborDebugState(nbr, peer_stats_.get()); + bnr->set_configured_address_families(configured_families_); + bnr->set_negotiated_address_families(negotiated_families_); + bnr->set_configured_hold_time(state_machine_->GetConfiguredHoldTime()); + FillBgpNeighborFamilyAttributes(bnr); + FillBgpNeighborDebugState(bnr, peer_stats_.get()); PeerRibMembershipManager *mgr = server_->membership_mgr(); - mgr->FillPeerMembershipInfo(this, &nbr); - nbr.set_routing_instances(vector()); - nbr_list->push_back(nbr); + mgr->FillPeerMembershipInfo(this, bnr); + bnr->set_routing_instances(vector()); } void BgpPeer::inc_rx_open() { diff --git a/src/bgp/bgp_peer.h b/src/bgp/bgp_peer.h index 396db36f1c9..74a2c8341d9 100644 --- a/src/bgp/bgp_peer.h +++ b/src/bgp/bgp_peer.h @@ -137,10 +137,12 @@ class BgpPeer : public IPeer { return peer_key_.endpoint.address().to_string(); } const BgpPeerKey &peer_key() const { return peer_key_; } - TcpSession::Endpoint remote_endpoint() const { return remote_endpoint_; } + uint16_t peer_port() const { return peer_key_.endpoint.port(); } + std::string transport_address_string() const; const std::string &peer_name() const { return peer_name_; } const std::string &peer_basename() const { return peer_basename_; } std::string router_type() const { return router_type_; } + TcpSession::Endpoint endpoint() const { return endpoint_; } StateMachine::State GetState() const; virtual const std::string GetStateName() const; @@ -184,8 +186,8 @@ class BgpPeer : public IPeer { const BgpNeighborConfig *config() const { return config_; } virtual void SetDataCollectionKey(BgpPeerInfo *peer_info) const; - void FillNeighborInfo(const BgpSandeshContext *bsc, - std::vector *nbr_list, bool summary) const; + void FillNeighborInfo(const BgpSandeshContext *bsc, BgpNeighborResp *bnr, + bool summary) const; // thread-safe bool IsDeleted() const; @@ -256,7 +258,8 @@ class BgpPeer : public IPeer { uint64_t get_open_error() const; uint64_t get_update_error() const; - static void FillBgpNeighborDebugState(BgpNeighborResp &resp, const IPeerDebugStats *peer); + static void FillBgpNeighborDebugState(BgpNeighborResp *bnr, + const IPeerDebugStats *peer); bool ResumeClose(); void MembershipRequestCallback(IPeer *ipeer, BgpTable *table); @@ -325,6 +328,7 @@ class BgpPeer : public IPeer { void ResetInuseAuthKeyInfo(); bool ProcessFamilyAttributesConfig(const BgpNeighborConfig *config); + void ProcessEndpointConfig(const BgpNeighborConfig *config); void PostCloseRelease(); void CustomClose(); @@ -336,8 +340,8 @@ class BgpPeer : public IPeer { BgpServer *server_; // Backpointer to routing instance RoutingInstance *rtinstance_; + TcpSession::Endpoint endpoint_; BgpPeerKey peer_key_; - TcpSession::Endpoint remote_endpoint_; std::string peer_name_; std::string peer_basename_; std::string router_type_; // bgp_schema.xsd:BgpRouterType diff --git a/src/bgp/bgp_peer.sandesh b/src/bgp/bgp_peer.sandesh index 761bf7fe58c..60d2bc49478 100644 --- a/src/bgp/bgp_peer.sandesh +++ b/src/bgp/bgp_peer.sandesh @@ -21,10 +21,6 @@ traceobject sandesh BgpPeerObjectTrace { 1: BgpPeerInfo peer; } -request sandesh BgpNeighborReq { - 1: string search_string; -} - struct BgpNeighborRoutingInstance { 1: string name; 2: string state; @@ -54,8 +50,11 @@ struct BgpNeighborResp { 2: string peer_address (link="BgpNeighborReq"); 25: string peer_id; 3: u32 peer_asn; + 50: u32 peer_port; + 51: string transport_address; 6: string encoding; // BGP/XMPP 7: string peer_type // internal/external + 52: string router_type; // bgp_schema.xsd:BgpRouterType 8: string state; 4: string local_address; // local ip address and port 26: string local_id; @@ -92,6 +91,10 @@ response sandesh BgpNeighborListResp { link_title="next_batch"); } +request sandesh BgpNeighborReq { + 1: string search_string; +} + response sandesh ShowBgpNeighborSummaryResp { 1: list neighbors; 2: optional string next_batch (link="ShowBgpNeighborSummaryReqIterate", @@ -461,12 +464,14 @@ struct ShowBgpNeighborConfig { 2: string name; 13: bool admin_down; 15: bool passive; + 18: string router_type; 8: string local_identifier; 9: i32 local_as; 3: string vendor; 4: i32 autonomous_system; 5: string identifier; 6: string address; + 19: u32 port; 14: i32 hold_time; 16: i32 loop_count; 10: string last_change_at; diff --git a/src/bgp/bgp_peer_membership.cc b/src/bgp/bgp_peer_membership.cc index f5cdeb2d6c4..0cba1c64f02 100644 --- a/src/bgp/bgp_peer_membership.cc +++ b/src/bgp/bgp_peer_membership.cc @@ -294,10 +294,17 @@ void IPeerRib::RibOutLeave(DBTablePartBase *root, DBEntryBase *db_entry, if (!(action_mask & MembershipRequest::RIBOUT_DELETE)) { return; } + if (!ribout_registered_) { + return; + } - RibPeerSet lmask; - lmask.set(ribout_->GetPeerIndex(ipeer_)); + int index = ribout_->GetPeerIndex(ipeer_); + if (index < 0) { + return; + } + RibPeerSet lmask; + lmask.set(index); ribout_->bgp_export()->Leave(root, lmask, db_entry); } diff --git a/src/bgp/bgp_ribout.cc b/src/bgp/bgp_ribout.cc index ecad6c3d878..ecb9d122e49 100644 --- a/src/bgp/bgp_ribout.cc +++ b/src/bgp/bgp_ribout.cc @@ -307,7 +307,8 @@ void RibOut::Deactivate(IPeerUpdate *peer) { } bool RibOut::IsActive(IPeerUpdate *peer) const { - return active_peerset_.test(GetPeerIndex(peer)); + int index = GetPeerIndex(peer); + return (index < 0 ? false : active_peerset_.test(index)); } // Return the number of peers this route has been advertised to. @@ -387,5 +388,5 @@ IPeerUpdate *RibOut::GetPeer(int index) const { // int RibOut::GetPeerIndex(IPeerUpdate *peer) const { PeerState *ps = state_map_.Find(peer); - return ps->index; + return (ps ? ps->index : -1); } diff --git a/src/bgp/bgp_server.cc b/src/bgp/bgp_server.cc index af7c9486a07..e936daae6dd 100644 --- a/src/bgp/bgp_server.cc +++ b/src/bgp/bgp_server.cc @@ -177,13 +177,13 @@ class BgpServer::ConfigUpdater { if (event == BgpConfigManager::CFG_ADD || event == BgpConfigManager::CFG_CHANGE) { BgpPeer *peer = peer_manager->PeerLocate(server_, neighbor_config); - server_->RemovePeer(peer->remote_endpoint(), peer); + server_->RemovePeer(peer->endpoint(), peer); peer->ConfigUpdate(neighbor_config); - server_->InsertPeer(peer->remote_endpoint(), peer); + server_->InsertPeer(peer->endpoint(), peer); } else if (event == BgpConfigManager::CFG_DELETE) { BgpPeer *peer = peer_manager->TriggerPeerDeletion(neighbor_config); if (peer) { - server_->RemovePeer(peer->remote_endpoint(), peer); + server_->RemovePeer(peer->endpoint(), peer); } } } @@ -382,7 +382,7 @@ BgpPeer *BgpServer::FindPeer(const string &name) { } void BgpServer::InsertPeer(TcpSession::Endpoint remote, BgpPeer *peer) { - if (!remote.port() || remote.address().is_unspecified()) + if (!remote.port() && remote.address().is_unspecified()) return; EndpointToBgpPeerList::iterator loc = endpoint_peer_list_.find(remote); diff --git a/src/bgp/bgp_session_manager.cc b/src/bgp/bgp_session_manager.cc index 9a3fe8ba362..30b279003c5 100644 --- a/src/bgp/bgp_session_manager.cc +++ b/src/bgp/bgp_session_manager.cc @@ -95,16 +95,21 @@ bool BgpSessionManager::ProcessWriteReady(TcpSessionPtr tcp_session) { // // Search for a matching BgpPeer. -// First look for an exact match in the EndpointToBgpPeerList in BgpServer. -// Then look for a matching address in the master instance. +// First look for a matching address in the master instance. +// Then look for a matching port in the EndpointToBgpPeerList in BgpServer. // BgpPeer *BgpSessionManager::FindPeer(Endpoint remote) { - BgpPeer *peer = server_->FindPeer(remote); - if (peer) - return peer; + BgpPeer *peer = NULL; const RoutingInstance *instance = server_->routing_instance_mgr()->GetDefaultRoutingInstance(); - return (instance ? instance->peer_manager()->PeerLookup(remote) : NULL); + if (instance) { + peer = instance->peer_manager()->PeerLookup(remote); + } + if (!peer) { + peer = server_->FindPeer( + TcpSession::Endpoint(Ip4Address(), remote.port())); + } + return peer; } // diff --git a/src/bgp/bgp_show_config.cc b/src/bgp/bgp_show_config.cc index 50663737f04..b4b6e6e2627 100644 --- a/src/bgp/bgp_show_config.cc +++ b/src/bgp/bgp_show_config.cc @@ -181,11 +181,13 @@ static void FillBgpNeighborConfigInfo(ShowBgpNeighborConfig *sbnc, sbnc->set_name(neighbor->name()); sbnc->set_admin_down(neighbor->admin_down()); sbnc->set_passive(neighbor->passive()); + sbnc->set_router_type(neighbor->router_type()); sbnc->set_local_identifier(neighbor->local_identifier_string()); sbnc->set_local_as(neighbor->local_as()); sbnc->set_autonomous_system(neighbor->peer_as()); sbnc->set_identifier(neighbor->peer_identifier_string()); sbnc->set_address(neighbor->peer_address().to_string()); + sbnc->set_port(neighbor->port()); sbnc->set_address_families(neighbor->GetAddressFamilies()); sbnc->set_hold_time(neighbor->hold_time()); sbnc->set_loop_count(neighbor->loop_count()); diff --git a/src/bgp/bgp_show_neighbor.cc b/src/bgp/bgp_show_neighbor.cc index ea888503e2c..868814d5b03 100644 --- a/src/bgp/bgp_show_neighbor.cc +++ b/src/bgp/bgp_show_neighbor.cc @@ -32,9 +32,11 @@ static bool FillBgpNeighborInfoList(const BgpSandeshContext *bsc, (peer->peer_basename().find(search_string) != string::npos) || (peer->peer_address_string().find(search_string) != string::npos) || (search_string == "deleted" && peer->IsDeleted())) { - peer->FillNeighborInfo(bsc, show_list, summary); + BgpNeighborResp bnr; + peer->FillNeighborInfo(bsc, &bnr, summary); + show_list->push_back(bnr); } - peer = bsc->bgp_server->FindNextPeer(peer->remote_endpoint()); + peer = bsc->bgp_server->FindNextPeer(peer->endpoint()); } return true; } diff --git a/src/bgp/bgp_table.cc b/src/bgp/bgp_table.cc index db5fc4e7045..3ff9f34a2b0 100644 --- a/src/bgp/bgp_table.cc +++ b/src/bgp/bgp_table.cc @@ -187,6 +187,12 @@ UpdateInfo *BgpTable::GetUpdateInfo(RibOut *ribout, BgpRoute *route, attr_ptr = attr->attr_db()->Locate(clone); attr = attr_ptr.get(); } else if (ribout->peer_type() == BgpProto::EBGP) { + // Don't advertise any routes from non-master instances. + // The ribout can only be for bgpaas-clients since that's + // the only case with bgp peers in non-master instance. + if (!rtinstance_->IsDefaultRoutingInstance()) + return NULL; + // Sender side AS path loop check. if (attr->as_path() && attr->as_path()->path().AsPathLoop(ribout->peer_as())) { diff --git a/src/bgp/bgp_xmpp_channel.cc b/src/bgp/bgp_xmpp_channel.cc index 7dd2eaf740d..e9b08336500 100644 --- a/src/bgp/bgp_xmpp_channel.cc +++ b/src/bgp/bgp_xmpp_channel.cc @@ -52,6 +52,7 @@ using pugi::xml_node; using std::auto_ptr; using std::make_pair; using std::numeric_limits; +using std::ostringstream; using std::pair; using std::set; using std::string; @@ -395,7 +396,7 @@ class BgpXmppChannel::XmppPeer : public IPeer { } virtual uint32_t bgp_identifier() const { - const boost::asio::ip::tcp::endpoint &remote = parent_->endpoint(); + const TcpSession::Endpoint &remote = parent_->endpoint(); if (remote.address().is_v4()) { return remote.address().to_v4().to_ulong(); } @@ -741,7 +742,7 @@ const IPeer *BgpXmppChannel::Peer() const { return peer_.get(); } -boost::asio::ip::tcp::endpoint BgpXmppChannel::endpoint() const { +TcpSession::Endpoint BgpXmppChannel::endpoint() const { return channel_->connection()->endpoint(); } @@ -2439,23 +2440,33 @@ void BgpXmppChannel::Close() { // // Return connection's remote tcp endpoint if available // -boost::asio::ip::tcp::endpoint BgpXmppChannel::remote_endpoint() const { +TcpSession::Endpoint BgpXmppChannel::remote_endpoint() const { const XmppSession *session = GetSession(); if (session) { return session->remote_endpoint(); } - return boost::asio::ip::tcp::endpoint(); + return TcpSession::Endpoint(); } // // Return connection's local tcp endpoint if available // -boost::asio::ip::tcp::endpoint BgpXmppChannel::local_endpoint() const { +TcpSession::Endpoint BgpXmppChannel::local_endpoint() const { const XmppSession *session = GetSession(); if (session) { return session->local_endpoint(); } - return boost::asio::ip::tcp::endpoint(); + return TcpSession::Endpoint(); +} + +// +// Return connection's remote tcp endpoint string. +// +string BgpXmppChannel::transport_address_string() const { + TcpSession::Endpoint endpoint = remote_endpoint(); + ostringstream oss; + oss << endpoint; + return oss.str(); } // diff --git a/src/bgp/bgp_xmpp_channel.h b/src/bgp/bgp_xmpp_channel.h index 272b326532a..4fb4e44bfda 100644 --- a/src/bgp/bgp_xmpp_channel.h +++ b/src/bgp/bgp_xmpp_channel.h @@ -80,13 +80,14 @@ class BgpXmppChannel { void Close(); IPeer *Peer(); const IPeer *Peer() const; - virtual boost::asio::ip::tcp::endpoint endpoint() const; + virtual TcpSession::Endpoint endpoint() const; std::string ToString() const; std::string ToUVEKey() const; std::string StateName() const; - boost::asio::ip::tcp::endpoint remote_endpoint() const; - boost::asio::ip::tcp::endpoint local_endpoint() const; + TcpSession::Endpoint remote_endpoint() const; + TcpSession::Endpoint local_endpoint() const; + std::string transport_address_string() const; void set_peer_deleted(); // For unit testing only. bool peer_deleted() const; diff --git a/src/bgp/bgp_xmpp_sandesh.cc b/src/bgp/bgp_xmpp_sandesh.cc index b2dd451f993..7808d3f83f8 100644 --- a/src/bgp/bgp_xmpp_sandesh.cc +++ b/src/bgp/bgp_xmpp_sandesh.cc @@ -33,6 +33,7 @@ static void FillXmppNeighborInfo(BgpNeighborResp *bnr, bool summary) { bnr->set_peer(bx_channel->ToString()); bnr->set_peer_address(bx_channel->remote_endpoint().address().to_string()); + bnr->set_transport_address(bx_channel->transport_address_string()); bnr->set_deleted(bx_channel->peer_deleted()); bnr->set_deleted_at(UTCUsecToString(bx_channel->peer_deleted_at())); bnr->set_local_address(bx_channel->local_endpoint().address().to_string()); @@ -55,7 +56,7 @@ static void FillXmppNeighborInfo(BgpNeighborResp *bnr, bx_channel->FillTableMembershipInfo(bnr); bx_channel->FillInstanceMembershipInfo(bnr); - BgpPeer::FillBgpNeighborDebugState(*bnr, bx_channel->Peer()->peer_stats()); + BgpPeer::FillBgpNeighborDebugState(bnr, bx_channel->Peer()->peer_stats()); } static bool ShowXmppNeighbor(const BgpSandeshContext *bsc, bool summary, diff --git a/src/bgp/routing-instance/peer_manager.cc b/src/bgp/routing-instance/peer_manager.cc index b36301fd65e..936bdcf3922 100644 --- a/src/bgp/routing-instance/peer_manager.cc +++ b/src/bgp/routing-instance/peer_manager.cc @@ -7,6 +7,7 @@ #include "base/task_annotations.h" #include "bgp/bgp_factory.h" #include "bgp/bgp_log.h" +#include "bgp/bgp_peer_types.h" #include "bgp/routing-instance/routing_instance_log.h" struct BgpSandeshContext; @@ -238,7 +239,7 @@ const BgpPeer *PeerManager::NextPeer(BgpPeerKey &peer_key) const { } void PeerManager::FillBgpNeighborInfo(const BgpSandeshContext *bsc, - vector *nbr_list, const string &search_string, + vector *bnr_list, const string &search_string, bool summary) const { BgpPeerKey key = BgpPeerKey(); while (const BgpPeer *peer = NextPeer(key)) { @@ -246,7 +247,9 @@ void PeerManager::FillBgpNeighborInfo(const BgpSandeshContext *bsc, (peer->peer_basename().find(search_string) != string::npos) || (peer->peer_address_string().find(search_string) != string::npos) || (search_string == "deleted" && peer->IsDeleted())) { - peer->FillNeighborInfo(bsc, nbr_list, summary); + BgpNeighborResp bnr; + peer->FillNeighborInfo(bsc, &bnr, summary); + bnr_list->push_back(bnr); } } } diff --git a/src/bgp/routing-instance/peer_manager.h b/src/bgp/routing-instance/peer_manager.h index d56b48863c8..efbd83f70df 100644 --- a/src/bgp/routing-instance/peer_manager.h +++ b/src/bgp/routing-instance/peer_manager.h @@ -42,7 +42,7 @@ class PeerManager { virtual const BgpPeer *NextPeer(BgpPeerKey &key) const; void FillBgpNeighborInfo(const BgpSandeshContext *bsc, - std::vector *nbr_list, + std::vector *sbnr_list, const std::string &search_string, bool summary) const; size_t GetNeighborCount(std::string up_or_down); diff --git a/src/bgp/test/bgp_config_test.cc b/src/bgp/test/bgp_config_test.cc index 4be085abc7c..cbd48ee4e49 100644 --- a/src/bgp/test/bgp_config_test.cc +++ b/src/bgp/test/bgp_config_test.cc @@ -359,6 +359,7 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors1) { TASK_UTIL_EXPECT_EQ("192.168.1.2", peer2->local_bgp_identifier_string()); TASK_UTIL_EXPECT_TRUE(GetPeerResolvePaths(peer2)); + // Cleanup. content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); boost::replace_all(content, "", ""); boost::replace_all(content, "", ""); @@ -381,56 +382,31 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors2) { TASK_UTIL_EXPECT_TRUE( rti->peer_manager()->PeerLookup("test:vm1:0") != NULL); BgpPeer *peer1 = rti->peer_manager()->PeerLookup("test:vm1:0"); - TASK_UTIL_EXPECT_EQ("0.0.0.0", - peer1->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(0, peer1->remote_endpoint().port()); + TASK_UTIL_EXPECT_EQ(1024, peer1->peer_port()); TASK_UTIL_EXPECT_TRUE(GetPeerResolvePaths(peer1)); TASK_UTIL_EXPECT_TRUE( rti->peer_manager()->PeerLookup("test:vm2:0") != NULL); BgpPeer *peer2 = rti->peer_manager()->PeerLookup("test:vm2:0"); - TASK_UTIL_EXPECT_EQ("0.0.0.0", - peer2->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(0, peer2->remote_endpoint().port()); + TASK_UTIL_EXPECT_EQ(1025, peer2->peer_port()); TASK_UTIL_EXPECT_TRUE(GetPeerResolvePaths(peer2)); - // Set BgpAsAServiceParameters for router test:vm1. - autogen::BgpAsAServiceParameters *bgpaas_params1 = - new autogen::BgpAsAServiceParameters; - bgpaas_params1->vrouter_ip_address = "172.16.1.99"; - bgpaas_params1->port = 1024; - ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters", bgpaas_params1); + // Update port numbers. + content = FileRead("controller/src/bgp/testdata/config_test_36d.xml"); + EXPECT_TRUE(parser_.Parse(content)); task_util::WaitForIdle(); - // Verify that the vrouter ip address and port are updated for test:vm1. - TASK_UTIL_EXPECT_EQ("172.16.1.99", - peer1->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(1024, peer1->remote_endpoint().port()); - TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->remote_endpoint())); + // Verify that the port is updated for test:vm1. + TASK_UTIL_EXPECT_EQ(1025, peer1->peer_port()); + TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->endpoint())); TASK_UTIL_EXPECT_TRUE(GetPeerResolvePaths(peer1)); - // Set BgpAsAServiceParameters for router test:vm2. - autogen::BgpAsAServiceParameters *bgpaas_params2 = - new autogen::BgpAsAServiceParameters; - bgpaas_params2->vrouter_ip_address = "172.16.1.99"; - bgpaas_params2->port = 1025; - ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters", bgpaas_params2); - task_util::WaitForIdle(); - - // Verify that the vrouter ip address and port are updated for test:vm2. - TASK_UTIL_EXPECT_EQ("172.16.1.99", - peer2->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(1025, peer2->remote_endpoint().port()); - TASK_UTIL_EXPECT_EQ(peer2, server_.FindPeer(peer2->remote_endpoint())); + // Verify that the port is updated for test:vm2. + TASK_UTIL_EXPECT_EQ(1024, peer2->peer_port()); + TASK_UTIL_EXPECT_EQ(peer2, server_.FindPeer(peer2->endpoint())); TASK_UTIL_EXPECT_TRUE(GetPeerResolvePaths(peer2)); - ifmap_test_util::IFMapMsgPropertyDelete(&config_db_, - "bgp-router", "test:vm1", "bgp-as-a-service-parameters"); - ifmap_test_util::IFMapMsgPropertyDelete(&config_db_, - "bgp-router", "test:vm2", "bgp-as-a-service-parameters"); - content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); + // Cleanup. boost::replace_all(content, "", ""); boost::replace_all(content, "", ""); EXPECT_TRUE(parser_.Parse(content)); @@ -442,24 +418,6 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors3) { string content; content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); EXPECT_TRUE(parser_.Parse(content)); - - // Set BgpAsAServiceParameters for router test:vm1. - autogen::BgpAsAServiceParameters *bgpaas_params1 = - new autogen::BgpAsAServiceParameters; - bgpaas_params1->vrouter_ip_address = "172.16.1.99"; - bgpaas_params1->port = 1024; - ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters", bgpaas_params1); - - // Set BgpAsAServiceParameters for router test:vm2. - autogen::BgpAsAServiceParameters *bgpaas_params2 = - new autogen::BgpAsAServiceParameters; - bgpaas_params2->vrouter_ip_address = "172.16.1.99"; - bgpaas_params2->port = 1025; - ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters", bgpaas_params2); - - // Wait for configs to be updated. task_util::WaitForIdle(); RoutingInstance *rti = @@ -467,75 +425,55 @@ TEST_F(BgpConfigTest, BGPaaSNeighbors3) { TASK_UTIL_ASSERT_TRUE(rti != NULL); TASK_UTIL_EXPECT_EQ(2, rti->peer_manager()->size()); - // Verify that the vrouter ip address and port are set for test:vm1. + // Verify that the port is set for test:vm1. TASK_UTIL_EXPECT_TRUE( rti->peer_manager()->PeerLookup("test:vm1:0") != NULL); BgpPeer *peer1 = rti->peer_manager()->PeerLookup("test:vm1:0"); - TASK_UTIL_EXPECT_EQ("172.16.1.99", - peer1->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(1024, peer1->remote_endpoint().port()); - TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->remote_endpoint())); + TASK_UTIL_EXPECT_EQ(1024, peer1->peer_port()); + TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->endpoint())); - // Verify that the vrouter ip address and port are set for test:vm2. + // Verify that the port is set for test:vm2. TASK_UTIL_EXPECT_TRUE( rti->peer_manager()->PeerLookup("test:vm2:0") != NULL); BgpPeer *peer2 = rti->peer_manager()->PeerLookup("test:vm2:0"); - TASK_UTIL_EXPECT_EQ("172.16.1.99", - peer2->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(1025, peer2->remote_endpoint().port()); - TASK_UTIL_EXPECT_EQ(peer2, server_.FindPeer(peer2->remote_endpoint())); + TASK_UTIL_EXPECT_EQ(1025, peer2->peer_port()); + TASK_UTIL_EXPECT_EQ(peer2, server_.FindPeer(peer2->endpoint())); - // Save the old remote endpoint for peer1. - TcpSession::Endpoint old_peer1_remote_endpoint = peer1->remote_endpoint(); + // Save the old endpoint for peer1. + TcpSession::Endpoint old_peer1_endpoint = peer1->endpoint(); // Set test::vm1 port to be same as port for test:vm2. - bgpaas_params1 = new autogen::BgpAsAServiceParameters; - bgpaas_params1->vrouter_ip_address = "172.16.1.99"; - bgpaas_params1->port = 1025; - ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters", bgpaas_params1); + content = FileRead("controller/src/bgp/testdata/config_test_36c.xml"); + EXPECT_TRUE(parser_.Parse(content)); task_util::WaitForIdle(); - // Verify that the vrouter ip address and port are updated for test:vm1. - TASK_UTIL_EXPECT_EQ("172.16.1.99", - peer1->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(1025, peer1->remote_endpoint().port()); + // Verify that the port is updated for test:vm1. + TASK_UTIL_EXPECT_EQ(1025, peer1->peer_port()); - // Verify that the vrouter ip address and port are identical for test:vm2. - TASK_UTIL_EXPECT_EQ("172.16.1.99", - peer2->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(1025, peer2->remote_endpoint().port()); + // Verify that the port is identical for test:vm2. + TASK_UTIL_EXPECT_EQ(1025, peer2->peer_port()); // Verify that test:vm1 is inserted into BgpServer::EndpointToBgpPeerList. // Verify that there's no entry for the old remote endpoint for test:vm1. // Note that test:vm2 is removed from BgpServer::EndpointToBgpPeerList when // test:vm1 is inserted with the same remote endpoint. - TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->remote_endpoint())); - TASK_UTIL_EXPECT_TRUE(server_.FindPeer(old_peer1_remote_endpoint) == NULL); + TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->endpoint())); + TASK_UTIL_EXPECT_TRUE(server_.FindPeer(old_peer1_endpoint) == NULL); - // Set test::vm2 port to be same as old port for test:vm2. - bgpaas_params2 = new autogen::BgpAsAServiceParameters; - bgpaas_params2->vrouter_ip_address = "172.16.1.99"; - bgpaas_params2->port = 1024; - ifmap_test_util::IFMapMsgPropertyAdd(&config_db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters", bgpaas_params2); + // Set test::vm2 port to be same as old port for test:vm1. + content = FileRead("controller/src/bgp/testdata/config_test_36d.xml"); + EXPECT_TRUE(parser_.Parse(content)); task_util::WaitForIdle(); - // Verify that the vrouter ip address and port are updated for test:vm2. - TASK_UTIL_EXPECT_EQ("172.16.1.99", - peer2->remote_endpoint().address().to_string()); - TASK_UTIL_EXPECT_EQ(1024, peer2->remote_endpoint().port()); + // Verify that the port is updated for test:vm2. + TASK_UTIL_EXPECT_EQ(1024, peer2->peer_port()); // Verify that test:vm1 is inserted into BgpServer::EndpointToBgpPeerList. // Verify that test:vm2 is inserted into BgpServer::EndpointToBgpPeerList. - TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->remote_endpoint())); - TASK_UTIL_EXPECT_EQ(peer2, server_.FindPeer(peer2->remote_endpoint())); + TASK_UTIL_EXPECT_EQ(peer1, server_.FindPeer(peer1->endpoint())); + TASK_UTIL_EXPECT_EQ(peer2, server_.FindPeer(peer2->endpoint())); - ifmap_test_util::IFMapMsgPropertyDelete(&config_db_, - "bgp-router", "test:vm1", "bgp-as-a-service-parameters"); - ifmap_test_util::IFMapMsgPropertyDelete(&config_db_, - "bgp-router", "test:vm2", "bgp-as-a-service-parameters"); - content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); + // Cleanup. boost::replace_all(content, "", ""); boost::replace_all(content, "", ""); EXPECT_TRUE(parser_.Parse(content)); diff --git a/src/bgp/test/bgp_ifmap_config_manager_test.cc b/src/bgp/test/bgp_ifmap_config_manager_test.cc index 436576d1ff9..ab78204aec9 100644 --- a/src/bgp/test/bgp_ifmap_config_manager_test.cc +++ b/src/bgp/test/bgp_ifmap_config_manager_test.cc @@ -1327,8 +1327,7 @@ TEST_F(BgpIfmapConfigManagerTest, BGPaaSNeighbors1) { EXPECT_EQ("192.168.1.1", nbr_config1->local_identifier_string()); EXPECT_EQ(65001, nbr_config1->peer_as()); EXPECT_EQ("10.0.0.1", nbr_config1->peer_address_string()); - EXPECT_EQ("0.0.0.0", nbr_config1->remote_endpoint().address().to_string()); - EXPECT_EQ(0, nbr_config1->remote_endpoint().port()); + EXPECT_EQ(1024, nbr_config1->port()); const BgpNeighborConfig *nbr_config2; nbr_config2 = config_manager_->FindNeighbor("test", "test:vm2:0"); @@ -1338,8 +1337,7 @@ TEST_F(BgpIfmapConfigManagerTest, BGPaaSNeighbors1) { EXPECT_EQ("192.168.1.1", nbr_config2->local_identifier_string()); EXPECT_EQ(65002, nbr_config2->peer_as()); EXPECT_EQ("10.0.0.2", nbr_config2->peer_address_string()); - EXPECT_EQ("0.0.0.0", nbr_config2->remote_endpoint().address().to_string()); - EXPECT_EQ(0, nbr_config2->remote_endpoint().port()); + EXPECT_EQ(1025, nbr_config2->port()); // Change asn and identifier for master. content = FileRead("controller/src/bgp/testdata/config_test_36b.xml"); @@ -1356,6 +1354,7 @@ TEST_F(BgpIfmapConfigManagerTest, BGPaaSNeighbors1) { EXPECT_EQ(64513, nbr_config2->local_as()); EXPECT_EQ("192.168.1.2", nbr_config1->local_identifier_string()); + // Cleanup. content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); boost::replace_all(content, "", ""); boost::replace_all(content, "", ""); @@ -1376,142 +1375,30 @@ TEST_F(BgpIfmapConfigManagerTest, BGPaaSNeighbors2) { EXPECT_TRUE(rti != NULL); EXPECT_EQ(2, config_manager_->NeighborCount("test")); - // Verify that the vrouter ip address and port are not set for test:vm1. + // Verify that the port is set for test:vm1. const BgpNeighborConfig *nbr_config1; nbr_config1 = config_manager_->FindNeighbor("test", "test:vm1:0"); - EXPECT_TRUE(nbr_config1 != NULL); - EXPECT_EQ("bgpaas-client", nbr_config1->router_type()); - EXPECT_EQ("0.0.0.0", nbr_config1->remote_endpoint().address().to_string()); - EXPECT_EQ(0, nbr_config1->remote_endpoint().port()); + EXPECT_EQ(1024, nbr_config1->port()); - // Verify that the vrouter ip address and port are not set for test:vm2. + // Verify that the port is set for test:vm2. const BgpNeighborConfig *nbr_config2; nbr_config2 = config_manager_->FindNeighbor("test", "test:vm2:0"); - EXPECT_TRUE(nbr_config2 != NULL); - EXPECT_EQ("bgpaas-client", nbr_config2->router_type()); - EXPECT_EQ("0.0.0.0", nbr_config2->remote_endpoint().address().to_string()); - EXPECT_EQ(0, nbr_config2->remote_endpoint().port()); - - // Set BgpAsAServiceParameters for router test:vm1. - autogen::BgpAsAServiceParameters *bgpaas_params1 = - new autogen::BgpAsAServiceParameters; - bgpaas_params1->vrouter_ip_address = "172.16.1.99"; - bgpaas_params1->port = 1024; - ifmap_test_util::IFMapMsgPropertyAdd(&db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters", bgpaas_params1); - task_util::WaitForIdle(); - - // Verify that the vrouter ip address and port are updated for test:vm1. - nbr_config1 = config_manager_->FindNeighbor("test", "test:vm1:0"); - EXPECT_EQ("172.16.1.99", - nbr_config1->remote_endpoint().address().to_string()); - EXPECT_EQ(1024, nbr_config1->remote_endpoint().port()); - - // Set BgpAsAServiceParameters for router test:vm2. - autogen::BgpAsAServiceParameters *bgpaas_params2 = - new autogen::BgpAsAServiceParameters; - bgpaas_params2->vrouter_ip_address = "172.16.1.99"; - bgpaas_params2->port = 1025; - ifmap_test_util::IFMapMsgPropertyAdd(&db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters", bgpaas_params2); - task_util::WaitForIdle(); + EXPECT_EQ(1025, nbr_config2->port()); - // Verify that the vrouter ip address and port are updated for test:vm2. - nbr_config2 = config_manager_->FindNeighbor("test", "test:vm2:0"); - EXPECT_EQ("172.16.1.99", - nbr_config2->remote_endpoint().address().to_string()); - EXPECT_EQ(1025, nbr_config2->remote_endpoint().port()); - - // Cleanup. - ifmap_test_util::IFMapMsgPropertyDelete(&db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters"); - ifmap_test_util::IFMapMsgPropertyDelete(&db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters"); - content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); - boost::replace_all(content, "", ""); - boost::replace_all(content, "", ""); + // Update port numbers. + content = FileRead("controller/src/bgp/testdata/config_test_36d.xml"); EXPECT_TRUE(parser_.Parse(content)); task_util::WaitForIdle(); - TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size()); - TASK_UTIL_EXPECT_EQ(0, config_manager_->NeighborCount("test")); - TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count()); -} -TEST_F(BgpIfmapConfigManagerTest, BGPaaSNeighbors3) { - string content; - content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); - EXPECT_TRUE(parser_.Parse(content)); - - // Set BgpAsAServiceParameters for router test:vm1. - autogen::BgpAsAServiceParameters *bgpaas_params1 = - new autogen::BgpAsAServiceParameters; - bgpaas_params1->vrouter_ip_address = "172.16.1.99"; - bgpaas_params1->port = 1024; - ifmap_test_util::IFMapMsgPropertyAdd(&db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters", bgpaas_params1); - - // Set BgpAsAServiceParameters for router test:vm2. - autogen::BgpAsAServiceParameters *bgpaas_params2 = - new autogen::BgpAsAServiceParameters; - bgpaas_params2->vrouter_ip_address = "172.16.1.99"; - bgpaas_params2->port = 1025; - ifmap_test_util::IFMapMsgPropertyAdd(&db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters", bgpaas_params2); - - task_util::WaitForIdle(); - const BgpInstanceConfig *rti = FindInstanceConfig("test"); - EXPECT_TRUE(rti != NULL); - EXPECT_EQ(2, config_manager_->NeighborCount("test")); - - // Verify that the vrouter ip address and port are set for test:vm1. - const BgpNeighborConfig *nbr_config1; + // Verify that the port is updated for test:vm1. nbr_config1 = config_manager_->FindNeighbor("test", "test:vm1:0"); - EXPECT_EQ("172.16.1.99", - nbr_config1->remote_endpoint().address().to_string()); - EXPECT_EQ(1024, nbr_config1->remote_endpoint().port()); + EXPECT_EQ(1025, nbr_config1->port()); - // Verify that the vrouter ip address and port are set for test:vm2. - const BgpNeighborConfig *nbr_config2; + // Verify that the port is updated for test:vm2. nbr_config2 = config_manager_->FindNeighbor("test", "test:vm2:0"); - EXPECT_EQ("172.16.1.99", - nbr_config2->remote_endpoint().address().to_string()); - EXPECT_EQ(1025, nbr_config2->remote_endpoint().port()); - - // Update BgpAsAServiceParameters for router test:vm1. - bgpaas_params1 = new autogen::BgpAsAServiceParameters; - bgpaas_params1->vrouter_ip_address = "172.16.1.99"; - bgpaas_params1->port = 1025; - ifmap_test_util::IFMapMsgPropertyAdd(&db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters", bgpaas_params1); - - // Update BgpAsAServiceParameters for router test:vm2. - bgpaas_params2 = new autogen::BgpAsAServiceParameters; - bgpaas_params2->vrouter_ip_address = "172.16.1.99"; - bgpaas_params2->port = 1024; - ifmap_test_util::IFMapMsgPropertyAdd(&db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters", bgpaas_params2); - - // Wait for the configs to get updated. - task_util::WaitForIdle(); - - // Verify that the vrouter ip address and port are updated for test:vm1. - nbr_config1 = config_manager_->FindNeighbor("test", "test:vm1:0"); - EXPECT_EQ("172.16.1.99", - nbr_config1->remote_endpoint().address().to_string()); - EXPECT_EQ(1025, nbr_config1->remote_endpoint().port()); - - // Verify that the vrouter ip address and port are updated for test:vm2. - nbr_config2 = config_manager_->FindNeighbor("test", "test:vm2:0"); - EXPECT_EQ("172.16.1.99", - nbr_config2->remote_endpoint().address().to_string()); - EXPECT_EQ(1024, nbr_config2->remote_endpoint().port()); + EXPECT_EQ(1024, nbr_config2->port()); // Cleanup. - ifmap_test_util::IFMapMsgPropertyDelete(&db_, "bgp-router", "test:vm1", - "bgp-as-a-service-parameters"); - ifmap_test_util::IFMapMsgPropertyDelete(&db_, "bgp-router", "test:vm2", - "bgp-as-a-service-parameters"); - content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); boost::replace_all(content, "", ""); boost::replace_all(content, "", ""); EXPECT_TRUE(parser_.Parse(content)); @@ -1744,6 +1631,52 @@ TEST_F(BgpIfmapConfigManagerShowTest, ShowNeighbors) { TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count()); } +TEST_F(BgpIfmapConfigManagerShowTest, ShowBGPaaSNeighbors) { + string content = FileRead("controller/src/bgp/testdata/config_test_36a.xml"); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); + + BgpSandeshContext sandesh_context; + sandesh_context.bgp_server = &server_; + Sandesh::set_client_context(&sandesh_context); + + const char *neighbor_name_list[] = { "vm1:0", "vm2:0" }; + vector neighbor_list; + BOOST_FOREACH(const char *neighbor_name, neighbor_name_list) { + string full_name("test"); + full_name += ":"; + full_name += neighbor_name; + const BgpNeighborConfig *config = + config_manager_->FindNeighbor("test", full_name); + ASSERT_TRUE(config != NULL); + ShowBgpNeighborConfig neighbor; + neighbor.set_name(config->name()); + neighbor.set_instance_name("test"); + neighbor.set_autonomous_system(config->peer_as()); + neighbor.set_identifier(config->peer_identifier_string()); + neighbor.set_address(config->peer_address_string()); + neighbor_list.push_back(neighbor); + } + + bool validate_done = false; + Sandesh::set_response_callback( + boost::bind(ValidateShowNeighborResponse, _1, &validate_done, + neighbor_list)); + + ShowBgpNeighborConfigReq *show_req = new ShowBgpNeighborConfigReq; + show_req->HandleRequest(); + show_req->Release(); + task_util::WaitForIdle(); + TASK_UTIL_EXPECT_TRUE(validate_done); + + boost::replace_all(content, "", ""); + boost::replace_all(content, "", ""); + EXPECT_TRUE(parser_.Parse(content)); + task_util::WaitForIdle(); + TASK_UTIL_EXPECT_EQ(1, config_manager_->config()->instances().size()); + TASK_UTIL_EXPECT_EQ(0, db_graph_.vertex_count()); +} + TEST_F(BgpIfmapConfigManagerShowTest, ShowPeerings1) { string content = FileRead("controller/src/bgp/testdata/config_test_27.xml"); EXPECT_TRUE(parser_.Parse(content)); diff --git a/src/bgp/testdata/config_test_36a.xml b/src/bgp/testdata/config_test_36a.xml index 2f03f57e251..b930a6b7780 100644 --- a/src/bgp/testdata/config_test_36a.xml +++ b/src/bgp/testdata/config_test_36a.xml @@ -37,6 +37,7 @@ bgpaas-client 65001
10.0.0.1
+ 1024 inet @@ -53,6 +54,7 @@ bgpaas-client 65002
10.0.0.2
+ 1025 inet diff --git a/src/bgp/testdata/config_test_36c.xml b/src/bgp/testdata/config_test_36c.xml new file mode 100644 index 00000000000..b5711d9dc0e --- /dev/null +++ b/src/bgp/testdata/config_test_36c.xml @@ -0,0 +1,71 @@ + + + +
192.168.1.1
+ 64512 + 192.168.1.1 +
+ + target:64512:1 + + bgpaas-server + 64512 + + + inet + + + inet6 + + + inet-vpn + + + + + inet + + + inet6 + + + inet-vpn + + + + + bgpaas-client + 65001 +
10.0.0.1
+ 1025 + + + inet + + + inet6 + + + inet-vpn + + +
+ + bgpaas-client + 65002 +
10.0.0.2
+ 1025 + + + inet + + + inet6 + + + inet-vpn + + +
+
+
diff --git a/src/bgp/testdata/config_test_36d.xml b/src/bgp/testdata/config_test_36d.xml new file mode 100644 index 00000000000..92587db3aa5 --- /dev/null +++ b/src/bgp/testdata/config_test_36d.xml @@ -0,0 +1,71 @@ + + + +
192.168.1.1
+ 64512 + 192.168.1.1 +
+ + target:64512:1 + + bgpaas-server + 64512 + + + inet + + + inet6 + + + inet-vpn + + + + + inet + + + inet6 + + + inet-vpn + + + + + bgpaas-client + 65001 +
10.0.0.1
+ 1025 + + + inet + + + inet6 + + + inet-vpn + + +
+ + bgpaas-client + 65002 +
10.0.0.2
+ 1024 + + + inet + + + inet6 + + + inet-vpn + + +
+
+
diff --git a/src/schema/bgp_schema.xsd b/src/schema/bgp_schema.xsd index fce1687e612..29bf459fa93 100644 --- a/src/schema/bgp_schema.xsd +++ b/src/schema/bgp_schema.xsd @@ -69,14 +69,6 @@ - - - - - - - diff --git a/src/schema/vnc_cfg.xsd b/src/schema/vnc_cfg.xsd index 8b85fd2752c..74b437eb21b 100644 --- a/src/schema/vnc_cfg.xsd +++ b/src/schema/vnc_cfg.xsd @@ -1289,8 +1289,12 @@ targetNamespace="http://www.contrailsystems.com/2012/VNC-CONFIG/0"> + Link('project-bgpaas', 'project', 'bgp-as-a-service', ['has']) --> + +