From 3a3fc3121a36da021ee619db7522cfac8f8cbd71 Mon Sep 17 00:00:00 2001 From: Ananth Suryanarayana Date: Tue, 15 Mar 2016 18:29:18 -0700 Subject: [PATCH] Add BGP Peers to graceful_restart_test o Tests follow semantics of existing agents' based test o To add more entropy, where ever agents are active, corresponding bgp peers are also introduced in the same test o Make many attributes data private where ever appropriate o Cleanup BGP Peer deletion code and rename certain variables from close_ to delete_ o Commonize BGPPeerInfo::Send() so that it can be disabled during testing o Commonize XMPPPeerInfo::Send() so that it can be disabled during testing o Prevent a potential freed memory access in BgpTable::Input() Change-Id: Ie97a7bb1681191e01cc81bc4777bc559cd889b51 Partial-Bug: #1537933 --- src/bgp/bgp_attr.cc | 26 +- src/bgp/bgp_attr.h | 26 +- src/bgp/bgp_attr_base.h | 2 +- src/bgp/bgp_evpn.cc | 8 +- src/bgp/bgp_origin_vn_path.h | 7 +- src/bgp/bgp_peer.cc | 87 +- src/bgp/bgp_peer.h | 13 +- src/bgp/bgp_route.cc | 2 +- src/bgp/bgp_server.cc | 4 +- src/bgp/bgp_server.h | 12 +- src/bgp/bgp_table.cc | 3 +- src/bgp/bgp_xmpp_channel.cc | 11 +- src/bgp/bgp_xmpp_channel.h | 4 +- src/bgp/community.h | 32 +- src/bgp/evpn/evpn_route.cc | 8 +- src/bgp/state_machine.cc | 18 +- src/bgp/state_machine.h | 6 +- src/bgp/test/bgp_attr_test.cc | 30 +- src/bgp/test/bgp_evpn_manager_test.cc | 28 +- src/bgp/test/bgp_multicast_test.cc | 4 +- src/bgp/test/bgp_server_test_util.cc | 3 +- src/bgp/test/bgp_server_test_util.h | 23 + src/bgp/test/graceful_restart_test.cc | 1171 ++++++++++++++--- src/bgp/test/static_route_test.cc | 4 +- src/bgp/xmpp_message_builder.cc | 6 +- src/control-node/main.cc | 16 +- src/control-node/sandesh/control_node.sandesh | 4 +- src/xmpp/xmpp_connection.cc | 16 +- 28 files changed, 1220 insertions(+), 354 deletions(-) diff --git a/src/bgp/bgp_attr.cc b/src/bgp/bgp_attr.cc index 35d16cb7b84..38119d0b39d 100644 --- a/src/bgp/bgp_attr.cc +++ b/src/bgp/bgp_attr.cc @@ -332,10 +332,10 @@ PmsiTunnel::PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db, : pmsi_tunnel_db_(pmsi_tunnel_db), pmsi_spec_(pmsi_spec) { refcount_ = 0; - tunnel_flags = pmsi_spec_.tunnel_flags; - tunnel_type = pmsi_spec_.tunnel_type; - label = pmsi_spec_.label; - identifier = pmsi_spec_.GetIdentifier(); + tunnel_flags_ = pmsi_spec_.tunnel_flags; + tunnel_type_ = pmsi_spec_.tunnel_type; + label_ = pmsi_spec_.label; + identifier_ = pmsi_spec_.GetIdentifier(); } void PmsiTunnel::Remove() { @@ -684,13 +684,13 @@ BgpOList::BgpOList(BgpOListDB *olist_db, const BgpOListSpec &olist_spec) olist_spec_.elements.begin(); it != olist_spec_.elements.end(); ++it) { BgpOListElem *elem = new BgpOListElem(*it); sort(elem->encap.begin(), elem->encap.end()); - elements.push_back(elem); + elements_.push_back(elem); } - sort(elements.begin(), elements.end(), BgpOListElemCompare()); + sort(elements_.begin(), elements_.end(), BgpOListElemCompare()); } BgpOList::~BgpOList() { - STLDeleteValues(&elements); + STLDeleteValues(&elements_); } struct BgpOListElementCompare { @@ -702,8 +702,8 @@ struct BgpOListElementCompare { int BgpOList::CompareTo(const BgpOList &rhs) const { KEY_COMPARE(olist().subcode, rhs.olist().subcode); - int result = STLSortedCompare(elements.begin(), elements.end(), - rhs.elements.begin(), rhs.elements.end(), + int result = STLSortedCompare(elements().begin(), elements().end(), + rhs.elements().begin(), rhs.elements().end(), BgpOListElementCompare()); return result; } @@ -1017,12 +1017,12 @@ std::size_t hash_value(BgpAttr const &attr) { } if (attr.olist_) { - boost::hash_range(hash, attr.olist_->elements.begin(), - attr.olist_->elements.end()); + boost::hash_range(hash, attr.olist_->elements().begin(), + attr.olist_->elements().end()); } if (attr.leaf_olist_) { - boost::hash_range(hash, attr.leaf_olist_->elements.begin(), - attr.leaf_olist_->elements.end()); + boost::hash_range(hash, attr.leaf_olist_->elements().begin(), + attr.leaf_olist_->elements().end()); } if (attr.as_path_) boost::hash_combine(hash, *attr.as_path_); diff --git a/src/bgp/bgp_attr.h b/src/bgp/bgp_attr.h index 03ebe4bbc05..3f2b9255bba 100644 --- a/src/bgp/bgp_attr.h +++ b/src/bgp/bgp_attr.h @@ -199,6 +199,7 @@ class ClusterList { friend int intrusive_ptr_add_ref(const ClusterList *ccluster_list); friend int intrusive_ptr_del_ref(const ClusterList *ccluster_list); friend void intrusive_ptr_release(const ClusterList *ccluster_list); + friend class ClusterListDB; mutable tbb::atomic refcount_; ClusterListDB *cluster_list_db_; @@ -332,7 +333,7 @@ class PmsiTunnel { const PmsiTunnelSpec &pmsi_tunnel() const { return pmsi_spec_; } uint32_t GetLabel(bool is_vni = false) const { - return (is_vni ? label : label >> 4); + return (is_vni ? label_ : label_ >> 4); } friend std::size_t hash_value(const PmsiTunnel &pmsi_tunnel) { @@ -341,16 +342,21 @@ class PmsiTunnel { return hash; } - uint8_t tunnel_flags; - uint8_t tunnel_type; - Ip4Address identifier; + const uint8_t tunnel_flags() const { return tunnel_flags_; } + const uint8_t tunnel_type() const { return tunnel_type_; } + const Ip4Address identifier() const { return identifier_; } + const uint32_t label() const { return label_; } private: friend int intrusive_ptr_add_ref(const PmsiTunnel *cpmsi_tunnel); friend int intrusive_ptr_del_ref(const PmsiTunnel *cpmsi_tunnel); friend void intrusive_ptr_release(const PmsiTunnel *cpmsi_tunnel); + friend class PmsiTunnelDB; - uint32_t label; + uint8_t tunnel_flags_; + uint8_t tunnel_type_; + Ip4Address identifier_; + uint32_t label_; mutable tbb::atomic refcount_; PmsiTunnelDB *pmsi_tunnel_db_; PmsiTunnelSpec pmsi_spec_; @@ -453,6 +459,7 @@ class EdgeDiscovery { friend int intrusive_ptr_add_ref(const EdgeDiscovery *ediscovery); friend int intrusive_ptr_del_ref(const EdgeDiscovery *ediscovery); friend void intrusive_ptr_release(const EdgeDiscovery *ediscovery); + friend class EdgeDiscoveryDB; mutable tbb::atomic refcount_; EdgeDiscoveryDB *edge_discovery_db_; @@ -559,6 +566,7 @@ class EdgeForwarding { friend int intrusive_ptr_add_ref(const EdgeForwarding *ceforwarding); friend int intrusive_ptr_del_ref(const EdgeForwarding *ceforwarding); friend void intrusive_ptr_release(const EdgeForwarding *ceforwarding); + friend class EdgeForwardingDB; mutable tbb::atomic refcount_; EdgeForwardingDB *edge_forwarding_db_; @@ -665,13 +673,16 @@ class BgpOList { } typedef std::vector Elements; - Elements elements; + + const Elements &elements() const { return elements_; } private: friend int intrusive_ptr_add_ref(const BgpOList *colist); friend int intrusive_ptr_del_ref(const BgpOList *colist); friend void intrusive_ptr_release(const BgpOList *colist); + friend class BgpOListDB; + Elements elements_; mutable tbb::atomic refcount_; BgpOListDB *olist_db_; BgpOListSpec olist_spec_; @@ -769,8 +780,8 @@ class BgpAttr { explicit BgpAttr(const BgpAttr &rhs); BgpAttr(BgpAttrDB *attr_db, const BgpAttrSpec &spec); virtual ~BgpAttr() { } - virtual void Remove(); + int CompareTo(const BgpAttr &rhs) const; void set_origin(BgpAttrOrigin::OriginType org) { origin_ = org; } @@ -844,6 +855,7 @@ class BgpAttr { private: friend class BgpAttrDB; + friend class BgpAttrTest; friend int intrusive_ptr_add_ref(const BgpAttr *cattrp); friend int intrusive_ptr_del_ref(const BgpAttr *cattrp); friend void intrusive_ptr_release(const BgpAttr *cattrp); diff --git a/src/bgp/bgp_attr_base.h b/src/bgp/bgp_attr_base.h index 0c3241765b0..b360c6ef197 100644 --- a/src/bgp/bgp_attr_base.h +++ b/src/bgp/bgp_attr_base.h @@ -223,7 +223,7 @@ class BgpPathAttributeDB { } // Decrement the counter bumped up above as we can't use this entry - // which is above to be deleted. Instead, retry inserting the passed + // which is about to be deleted. Instead, retry inserting the passed // entry again, into the database. intrusive_ptr_del_ref(*ret.first); } diff --git a/src/bgp/bgp_evpn.cc b/src/bgp/bgp_evpn.cc index 255e4c20170..bfaea6840e4 100644 --- a/src/bgp/bgp_evpn.cc +++ b/src/bgp/bgp_evpn.cc @@ -85,10 +85,10 @@ bool EvpnMcastNode::UpdateAttributes(EvpnRoute *route) { const PmsiTunnel *pmsi_tunnel = attr_->pmsi_tunnel(); uint8_t ar_type = - pmsi_tunnel->tunnel_flags & PmsiTunnelSpec::AssistedReplicationType; + pmsi_tunnel->tunnel_flags() & PmsiTunnelSpec::AssistedReplicationType; bool edge_replication_not_supported = false; - if ((pmsi_tunnel->tunnel_flags & + if ((pmsi_tunnel->tunnel_flags() & PmsiTunnelSpec::EdgeReplicationSupported) == 0) { edge_replication_not_supported = true; } @@ -117,8 +117,8 @@ bool EvpnMcastNode::UpdateAttributes(EvpnRoute *route) { address_ = path->GetAttr()->nexthop().to_v4(); changed = true; } - if (replicator_address_ != pmsi_tunnel->identifier) { - replicator_address_ = pmsi_tunnel->identifier; + if (replicator_address_ != pmsi_tunnel->identifier()) { + replicator_address_ = pmsi_tunnel->identifier(); changed = true; } diff --git a/src/bgp/bgp_origin_vn_path.h b/src/bgp/bgp_origin_vn_path.h index b2a1c1844bd..c3c5fa7dd9b 100644 --- a/src/bgp/bgp_origin_vn_path.h +++ b/src/bgp/bgp_origin_vn_path.h @@ -50,9 +50,8 @@ class OriginVnPath { explicit OriginVnPath(OriginVnPathDB *ovnpath_db, const OriginVnPathSpec spec); virtual ~OriginVnPath() { } - virtual void Remove(); - void Prepend(const OriginVnValue &value); + bool Contains(const OriginVnValue &value) const; int CompareTo(const OriginVnPath &rhs) const; @@ -71,6 +70,10 @@ class OriginVnPath { friend int intrusive_ptr_add_ref(const OriginVnPath *covnpath); friend int intrusive_ptr_del_ref(const OriginVnPath *covnpath); friend void intrusive_ptr_release(const OriginVnPath *covnpath); + friend class OriginVnPathDB; + friend class BgpAttrTest; + + void Prepend(const OriginVnValue &value); mutable tbb::atomic refcount_; OriginVnPathDB *ovnpath_db_; diff --git a/src/bgp/bgp_peer.cc b/src/bgp/bgp_peer.cc index bc2dbe7d54b..d7615000e74 100644 --- a/src/bgp/bgp_peer.cc +++ b/src/bgp/bgp_peer.cc @@ -44,15 +44,21 @@ class BgpPeer::PeerClose : public IPeerClose { public: explicit PeerClose(BgpPeer *peer) : peer_(peer), - is_closed_(false), - manager_(BgpObjectFactory::Create(peer_)) { - } + manager_(BgpObjectFactory::Create(peer_)) { } - virtual ~PeerClose() { - } + virtual ~PeerClose() { } + virtual string ToString() const { return peer_->ToString(); } + virtual void CustomClose() { return peer_->CustomClose(); } + virtual void GracefulRestartStale() { } + virtual void GracefulRestartSweep() { } + virtual PeerCloseManager *close_manager() { return manager_.get(); } + void Close() { manager_->Close(); } - virtual string ToString() const { - return peer_->ToString(); + virtual void Delete() { + if (peer_->IsDeleted()) + peer_->RetryDelete(); + else + CloseComplete(); } // If the peer is deleted or administratively held down, do not attempt @@ -60,45 +66,20 @@ class BgpPeer::PeerClose : public IPeerClose { virtual bool IsCloseGraceful() { if (peer_->IsDeleted() || peer_->IsAdminDown()) return false; + if (peer_->server()->IsDeleted()) + return false; return peer_->server()->IsPeerCloseGraceful(); } - virtual void CustomClose() { return peer_->CustomClose(); } - virtual void GracefulRestartStale() { } - virtual void GracefulRestartSweep() { } - - // CloseComplete - // // Close process for this peer is complete. Restart the state machine and // attempt to bring up session with the neighbor - // virtual void CloseComplete() { - peer_->server()->decrement_closing_count(); - if (!peer_->IsAdminDown()) + if (!peer_->IsDeleted() && !peer_->IsAdminDown()) peer_->state_machine_->Initialize(); } - virtual void Delete() { - if (!peer_->IsDeleted()) { - CloseComplete(); - return; - } - peer_->server()->decrement_closing_count(); - peer_->deleter()->RetryDelete(); - is_closed_ = true; - } - - bool IsClosed() const { return is_closed_; } - virtual PeerCloseManager *close_manager() { return manager_.get(); } - - void Close() { - if (!manager_->IsCloseInProgress()) - peer_->server()->increment_closing_count(); - manager_->Close(); - } private: BgpPeer *peer_; - bool is_closed_; boost::scoped_ptr manager_; }; @@ -214,7 +195,7 @@ class BgpPeer::DeleteActor : public LifetimeActor { virtual bool MayDelete() const { CHECK_CONCURRENCY("bgp::Config"); - if (!peer_->peer_close_->IsClosed()) + if (peer_->IsCloseInProgress()) return false; if (!peer_->state_machine_->IsQueueEmpty()) return false; @@ -229,6 +210,7 @@ class BgpPeer::DeleteActor : public LifetimeActor { virtual void Destroy() { CHECK_CONCURRENCY("bgp::Config"); peer_->PostCloseRelease(); + peer_->server()->decrement_deleting_count(); peer_->rtinstance_->peer_manager()->DestroyIPeer(peer_); } @@ -310,6 +292,10 @@ void BgpPeer::SendEndOfRIB(Address::Family family) { " size " << msgsize); } +void BgpPeer::BGPPeerInfoSend(BgpPeerInfoData &peer_info) { + BGPPeerInfo::Send(peer_info); +} + // // Callback from PeerRibMembershipManager. // Update pending membership request count and send EndOfRib for the family @@ -332,7 +318,7 @@ void BgpPeer::MembershipRequestCallback(IPeer *ipeer, BgpTable *table) { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("in sync"); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); SendEndOfRIB(table->family()); } @@ -342,7 +328,7 @@ bool BgpPeer::ResumeClose() { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("not advertising"); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); return true; } @@ -417,7 +403,7 @@ BgpPeer::BgpPeer(BgpServer *server, RoutingInstance *instance, peer_info.set_local_id(local_bgp_id_); peer_info.set_configured_families(config->GetAddressFamilies()); peer_info.set_peer_address(peer_key_.endpoint.address().to_string()); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } BgpPeer::~BgpPeer() { @@ -427,7 +413,7 @@ BgpPeer::~BgpPeer() { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_deleted(true); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); BGP_LOG_PEER(Event, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL, BGP_PEER_DIR_NA, "Deleted"); } @@ -686,7 +672,7 @@ void BgpPeer::ConfigUpdate(const BgpNeighborConfig *config) { // Send the UVE as appropriate. if (admin_down_changed || clear_session) { - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } } @@ -794,7 +780,7 @@ void BgpPeer::Close() { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("not advertising"); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } IPeerClose *BgpPeer::peer_close() { @@ -890,7 +876,7 @@ void BgpPeer::RegisterAllTables() { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("not advertising"); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); vector family_list = list_of (Address::INET)(Address::INET6); @@ -1048,7 +1034,7 @@ bool BgpPeer::SendUpdate(const uint8_t *msg, size_t msgsize) { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("not in sync"); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } return send_ready_; } @@ -1108,7 +1094,7 @@ void BgpPeer::SetCapabilities(const BgpProto::OpenMessage *msg) { sort(negotiated_families_.begin(), negotiated_families_.end()); peer_info.set_negotiated_families(negotiated_families_); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } // Reset capabilities stored inside peer structure. @@ -1124,7 +1110,7 @@ void BgpPeer::ResetCapabilities() { peer_info.set_families(families); vector negotiated_families = vector(); peer_info.set_negotiated_families(negotiated_families); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } bool BgpPeer::MpNlriAllowed(uint16_t afi, uint8_t safi) { @@ -1445,7 +1431,7 @@ void BgpPeer::SetSendReady() { BgpPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("in sync"); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void BgpPeer::set_session(BgpSession *session) { @@ -1609,8 +1595,11 @@ BgpAttrPtr BgpPeer::GetMpNlriNexthop(BgpMpNlri *nlri, BgpAttrPtr attr) { } void BgpPeer::ManagedDelete() { + if (deleter_->IsDeleted()) + return; BGP_LOG_PEER(Config, this, SandeshLevel::SYS_INFO, BGP_LOG_FLAG_ALL, BGP_PEER_DIR_NA, "Received request for deletion"); + server()->increment_deleting_count(); deleter_->Delete(); } @@ -1938,7 +1927,7 @@ void BgpPeer::increment_flap_count() { flap_info.set_flap_count(flap_count_); flap_info.set_flap_time(last_flap_); peer_info.set_flap_info(flap_info); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void BgpPeer::reset_flap_count() { @@ -1949,5 +1938,5 @@ void BgpPeer::reset_flap_count() { peer_info.set_name(ToUVEKey()); PeerFlapInfo flap_info; peer_info.set_flap_info(flap_info); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } diff --git a/src/bgp/bgp_peer.h b/src/bgp/bgp_peer.h index 3a51d7aa4b5..596dce8dae0 100644 --- a/src/bgp/bgp_peer.h +++ b/src/bgp/bgp_peer.h @@ -30,13 +30,13 @@ class BgpNeighborConfig; class BgpPeerInfo; +class BgpPeerInfoData; class BgpServer; class BgpSession; -class RoutingInstance; class BgpSession; -class BgpPeerInfo; class BgpNeighborResp; class BgpSandeshContext; +class RoutingInstance; // // This contains per address family attributes. @@ -291,6 +291,12 @@ class BgpPeer : public IPeer { void ClearListenSocketAuthKey(); void SetSessionSocketAuthKey(TcpSession *session); +protected: + std::vector &negotiated_families() { + return negotiated_families_; + } + void SendEndOfRIB(Address::Family family); + private: friend class BgpConfigTest; friend class BgpPeerTest; @@ -311,13 +317,14 @@ class BgpPeer : public IPeer { RibExportPolicy BuildRibExportPolicy(Address::Family family) const; void ReceiveEndOfRIB(Address::Family family, size_t msgsize); - void SendEndOfRIB(Address::Family family); void StartEndOfRibTimer(); bool EndOfRibTimerExpired(); void EndOfRibTimerErrorHandler(std::string error_name, std::string error_message); virtual void BindLocalEndpoint(BgpSession *session); + void UnregisterAllTables(); + void BGPPeerInfoSend(BgpPeerInfoData &peer_info); uint32_t GetPathFlags(Address::Family family, const BgpAttr *attr) const; virtual bool MpNlriAllowed(uint16_t afi, uint8_t safi); diff --git a/src/bgp/bgp_route.cc b/src/bgp/bgp_route.cc index 72b32081a86..7d6b3a0d926 100644 --- a/src/bgp/bgp_route.cc +++ b/src/bgp/bgp_route.cc @@ -395,7 +395,7 @@ static void FillPmsiTunnelInfo(const PmsiTunnel *pmsi_tunnel, bool label_is_vni, ShowPmsiTunnel spt; spt.set_type(pmsi_tunnel->pmsi_tunnel().GetTunnelTypeString()); spt.set_ar_type(pmsi_tunnel->pmsi_tunnel().GetTunnelArTypeString()); - spt.set_identifier(pmsi_tunnel->identifier.to_string()); + spt.set_identifier(pmsi_tunnel->identifier().to_string()); spt.set_label(pmsi_tunnel->GetLabel(label_is_vni)); spt.set_flags(pmsi_tunnel->pmsi_tunnel().GetTunnelFlagsStrings()); show_path->set_pmsi_tunnel(spt); diff --git a/src/bgp/bgp_server.cc b/src/bgp/bgp_server.cc index 7109f7a36bf..1fb96d04e98 100644 --- a/src/bgp/bgp_server.cc +++ b/src/bgp/bgp_server.cc @@ -323,12 +323,12 @@ BgpServer::BgpServer(EventManager *evm) config_mgr_(BgpObjectFactory::Create(this)), updater_(new ConfigUpdater(this)) { num_up_peer_ = 0; - closing_count_ = 0; + deleting_count_ = 0; message_build_error_ = 0; } BgpServer::~BgpServer() { - assert(closing_count_ == 0); + assert(deleting_count_ == 0); assert(srt_manager_list_.empty()); } diff --git a/src/bgp/bgp_server.h b/src/bgp/bgp_server.h index 7b063edb06b..84a403fbe4d 100644 --- a/src/bgp/bgp_server.h +++ b/src/bgp/bgp_server.h @@ -174,11 +174,11 @@ class BgpServer { return (peer_bmap_.size() - peer_bmap_.count()); } - uint32_t num_closing_bgp_peer() const { return closing_count_; } - void increment_closing_count() { closing_count_++; } - void decrement_closing_count() { - assert(closing_count_ > 0); - closing_count_--; + uint32_t num_deleting_bgp_peer() const { return deleting_count_; } + void increment_deleting_count() { deleting_count_++; } + void decrement_deleting_count() { + assert(deleting_count_ > 0); + deleting_count_--; } uint32_t get_output_queue_depth() const; @@ -251,7 +251,7 @@ class BgpServer { DB db_; boost::dynamic_bitset<> peer_bmap_; tbb::atomic num_up_peer_; - tbb::atomic closing_count_; + tbb::atomic deleting_count_; BgpPeerList peer_list_; EndpointToBgpPeerList endpoint_peer_list_; diff --git a/src/bgp/bgp_table.cc b/src/bgp/bgp_table.cc index 935e5e9db67..8ee31d2a11f 100644 --- a/src/bgp/bgp_table.cc +++ b/src/bgp/bgp_table.cc @@ -411,8 +411,7 @@ void BgpTable::Input(DBTablePartition *root, DBClient *client, } path = rt->FindPath(BgpPath::BGP_XMPP, peer, path_id); - if (path && req->oper != DBRequest::DB_ENTRY_DELETE) - deleted_paths.erase(path); + deleted_paths.erase(path); if (data->attrs() && count > 0) { BgpAttr *clone = new BgpAttr(*data->attrs()); diff --git a/src/bgp/bgp_xmpp_channel.cc b/src/bgp/bgp_xmpp_channel.cc index 67840219276..1e2bbf03dc9 100644 --- a/src/bgp/bgp_xmpp_channel.cc +++ b/src/bgp/bgp_xmpp_channel.cc @@ -340,7 +340,6 @@ class BgpXmppChannel::PeerStats : public IPeerDebugStats { BgpXmppChannel *peer_; }; - class BgpXmppChannel::XmppPeer : public IPeer { public: XmppPeer(BgpServer *server, BgpXmppChannel *channel) @@ -437,7 +436,7 @@ class BgpXmppChannel::XmppPeer : public IPeer { XmppPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("in sync"); - XMPPPeerInfo::Send(peer_info); + parent_->XMPPPeerInfoSend(peer_info); } BgpServer *server_; @@ -474,7 +473,7 @@ bool BgpXmppChannel::XmppPeer::SendUpdate(const uint8_t *msg, size_t msgsize) { XmppPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_send_state("not in sync"); - XMPPPeerInfo::Send(peer_info); + parent_->XMPPPeerInfoSend(peer_info); } return send_ready_; } else { @@ -534,6 +533,10 @@ BgpXmppChannel::~BgpXmppChannel() { channel_->UnRegisterReceive(peer_id_); } +void BgpXmppChannel::XMPPPeerInfoSend(XmppPeerInfoData &peer_info) { + XMPPPeerInfo::Send(peer_info); +} + const XmppSession *BgpXmppChannel::GetSession() const { if (channel_ && channel_->connection()) { return channel_->connection()->session(); @@ -2483,7 +2486,7 @@ void BgpXmppChannelManager::XmppHandleChannelEvent(XmppChannel *channel, XmppPeerInfoData peer_info; peer_info.set_name(bgp_xmpp_channel->Peer()->ToUVEKey()); peer_info.set_send_state("not advertising"); - XMPPPeerInfo::Send(peer_info); + bgp_xmpp_channel->XMPPPeerInfoSend(peer_info); } } diff --git a/src/bgp/bgp_xmpp_channel.h b/src/bgp/bgp_xmpp_channel.h index aa1cc9a29ff..5d10ccd97cd 100644 --- a/src/bgp/bgp_xmpp_channel.h +++ b/src/bgp/bgp_xmpp_channel.h @@ -33,6 +33,7 @@ class XmppServer; class BgpXmppChannelMock; class BgpXmppChannelManager; class BgpXmppChannelManagerMock; +class XmppPeerInfoData; class XmppSession; class BgpXmppChannel { @@ -109,6 +110,7 @@ class BgpXmppChannel { void FillCloseInfo(BgpNeighborResp *resp) const; void StaleCurrentSubscriptions(); void SweepCurrentSubscriptions(); + void XMPPPeerInfoSend(XmppPeerInfoData &peer_info); const XmppChannel *channel() const { return channel_; } @@ -306,7 +308,7 @@ class BgpXmppChannelManager { return channel_map_.size(); } - uint32_t closing_count() const { return deleting_count_; } + uint32_t deleting_count() const { return deleting_count_; } void increment_deleting_count() { deleting_count_++; } void decrement_deleting_count() { deleting_count_--; } diff --git a/src/bgp/community.h b/src/bgp/community.h index c4e50b909d9..bfeefa2eca3 100644 --- a/src/bgp/community.h +++ b/src/bgp/community.h @@ -53,12 +53,8 @@ class Community { } explicit Community(CommunityDB *comm_db, const CommunitySpec spec); virtual ~Community() { } - - void Append(uint32_t value); - void Append(const std::vector &communities); - void Set(const std::vector &communities); - void Remove(const std::vector &communities); virtual void Remove(); + int CompareTo(const Community &rhs) const; bool ContainsValue(uint32_t value) const; void BuildStringList(std::vector *list) const; @@ -76,6 +72,13 @@ class Community { friend int intrusive_ptr_add_ref(const Community *ccomm); friend int intrusive_ptr_del_ref(const Community *ccomm); friend void intrusive_ptr_release(const Community *ccomm); + friend class CommunityDB; + friend class BgpAttrTest; + + void Append(uint32_t value); + void Append(const std::vector &communities); + void Set(const std::vector &communities); + void Remove(const std::vector &communities); mutable tbb::atomic refcount_; CommunityDB *comm_db_; @@ -160,15 +163,7 @@ class ExtCommunity { virtual void Remove(); int CompareTo(const ExtCommunity &rhs) const; - void Append(const ExtCommunityValue &value); - void Append(const ExtCommunityList &list); bool ContainsOriginVn(const ExtCommunityValue &val) const; - void RemoveRTarget(); - void RemoveSGID(); - void RemoveSiteOfOrigin(); - void RemoveOriginVn(); - void RemoveTunnelEncapsulation(); - void RemoveLoadBalance(); // Return vector of communities const ExtCommunityList &communities() const { @@ -280,6 +275,17 @@ class ExtCommunity { friend int intrusive_ptr_add_ref(const ExtCommunity *cextcomm); friend int intrusive_ptr_del_ref(const ExtCommunity *cextcomm); friend void intrusive_ptr_release(const ExtCommunity *cextcomm); + friend class ExtCommunityDB; + friend class BgpAttrTest; + + void Append(const ExtCommunityValue &value); + void Append(const ExtCommunityList &list); + void RemoveRTarget(); + void RemoveSGID(); + void RemoveSiteOfOrigin(); + void RemoveOriginVn(); + void RemoveTunnelEncapsulation(); + void RemoveLoadBalance(); mutable tbb::atomic refcount_; ExtCommunityDB *extcomm_db_; diff --git a/src/bgp/evpn/evpn_route.cc b/src/bgp/evpn/evpn_route.cc index ac30ff9bf5a..f442769cc1c 100644 --- a/src/bgp/evpn/evpn_route.cc +++ b/src/bgp/evpn/evpn_route.cc @@ -211,8 +211,8 @@ int EvpnPrefix::FromProtoPrefix(BgpServer *server, prefix->ReadIpAddress(proto_prefix, ip_offset, ip_size); const PmsiTunnel *pmsi_tunnel = attr ? attr->pmsi_tunnel() : NULL; if (pmsi_tunnel && - (pmsi_tunnel->tunnel_type == PmsiTunnelSpec::IngressReplication || - pmsi_tunnel->tunnel_type == + (pmsi_tunnel->tunnel_type() == PmsiTunnelSpec::IngressReplication || + pmsi_tunnel->tunnel_type() == PmsiTunnelSpec::AssistedReplicationContrail)) { const ExtCommunity *extcomm = attr ? attr->ext_community() : NULL; if (extcomm && extcomm->ContainsTunnelEncapVxlan()) { @@ -715,8 +715,8 @@ bool EvpnRoute::IsValid() const { const PmsiTunnel *pmsi_tunnel = attr->pmsi_tunnel(); if (!pmsi_tunnel) return false; - uint8_t tunnel_type = pmsi_tunnel->tunnel_type; - uint8_t tunnel_flags = pmsi_tunnel->tunnel_flags; + uint8_t tunnel_type = pmsi_tunnel->tunnel_type(); + uint8_t tunnel_flags = pmsi_tunnel->tunnel_flags(); uint8_t ar_type = tunnel_flags & PmsiTunnelSpec::AssistedReplicationType; if (tunnel_type == PmsiTunnelSpec::IngressReplication) { diff --git a/src/bgp/state_machine.cc b/src/bgp/state_machine.cc index 866cf6919aa..b212d575251 100644 --- a/src/bgp/state_machine.cc +++ b/src/bgp/state_machine.cc @@ -1673,6 +1673,10 @@ int StateMachine::GetConfiguredHoldTime() const { return kHoldTime; } +void StateMachine::BGPPeerInfoSend(BgpPeerInfoData &peer_info) { + BGPPeerInfo::Send(peer_info); +} + void StateMachine::set_last_event(const std::string &event) { last_event_ = event; last_event_at_ = UTCTimestampUsec(); @@ -1687,7 +1691,7 @@ void StateMachine::set_last_event(const std::string &event) { event_info.set_last_event(last_event_); event_info.set_last_event_at(last_event_at_); peer_info.set_event_info(event_info); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void StateMachine::set_last_notification_out(int code, int subcode, @@ -1701,7 +1705,7 @@ void StateMachine::set_last_notification_out(int code, int subcode, peer_info.set_notification_out_at(last_notification_out_at_); peer_info.set_notification_out(BgpProto::Notification::toString( static_cast(code), subcode)); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void StateMachine::set_last_notification_in(int code, int subcode, @@ -1715,7 +1719,7 @@ void StateMachine::set_last_notification_in(int code, int subcode, peer_info.set_notification_in_at(last_notification_in_at_); peer_info.set_notification_in(BgpProto::Notification::toString( static_cast(code), subcode)); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void StateMachine::set_state(State state) { @@ -1729,7 +1733,7 @@ void StateMachine::set_state(State state) { state_info.set_last_state(LastStateName()); state_info.set_last_state_at(last_state_change_at_); peer_info.set_state_info(state_info); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void StateMachine::set_hold_time(int hold_time) { @@ -1738,7 +1742,7 @@ void StateMachine::set_hold_time(int hold_time) { BgpPeerInfoData peer_info; peer_info.set_name(peer()->ToUVEKey()); peer_info.set_hold_time(hold_time_); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void StateMachine::reset_hold_time() { @@ -1747,7 +1751,7 @@ void StateMachine::reset_hold_time() { BgpPeerInfoData peer_info; peer_info.set_name(peer()->ToUVEKey()); peer_info.set_hold_time(hold_time_); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } void StateMachine::reset_last_info() { @@ -1774,5 +1778,5 @@ void StateMachine::reset_last_info() { event_info.set_last_event(last_event_); event_info.set_last_event_at(last_event_at_); peer_info.set_event_info(event_info); - BGPPeerInfo::Send(peer_info); + BGPPeerInfoSend(peer_info); } diff --git a/src/bgp/state_machine.h b/src/bgp/state_machine.h index 8a33f8c8722..1e84a94db14 100644 --- a/src/bgp/state_machine.h +++ b/src/bgp/state_machine.h @@ -21,6 +21,7 @@ namespace sc = boost::statechart; class BgpPeer; class BgpSession; class BgpPeerInfo; +class BgpPeerInfoData; class BgpMessage; class StateMachine; @@ -127,7 +128,7 @@ class StateMachine : public sc::state_machine { void DeleteSession(BgpSession *session); void AssignSession(bool active); - void OnSessionEvent(TcpSession *session, TcpSession::Event event); + virtual void OnSessionEvent(TcpSession *session, TcpSession::Event event); bool PassiveOpen(BgpSession *session); void OnMessage(BgpSession *session, BgpProto::BgpMessage *msg, @@ -178,6 +179,7 @@ class StateMachine : public sc::state_machine { void reset_last_info(); void LogEvent(std::string event_name, std::string msg, SandeshLevel::type log_level = SandeshLevel::SYS_DEBUG); + bool HoldTimerExpired(); private: friend class StateMachineTest; @@ -192,13 +194,13 @@ class StateMachine : public sc::state_machine { void FireConnectTimer(); bool OpenTimerExpired(); void FireOpenTimer(); - bool HoldTimerExpired(); void FireHoldTimer(); bool IdleHoldTimerExpired(); void FireIdleHoldTimer(); void TimerErrorHanlder(std::string name, std::string error) { } void DeleteAllTimers(); + void BGPPeerInfoSend(BgpPeerInfoData &peer_info); template bool Enqueue(const Ev &event); bool DequeueEvent(EventContainer ec); diff --git a/src/bgp/test/bgp_attr_test.cc b/src/bgp/test/bgp_attr_test.cc index d4eebb0f041..9c6e2d162b8 100644 --- a/src/bgp/test/bgp_attr_test.cc +++ b/src/bgp/test/bgp_attr_test.cc @@ -51,6 +51,16 @@ class BgpAttrTest : public ::testing::Test { task_util::WaitForIdle(); } + void AppendExtendedCommunity(ExtCommunity &comm, + const ExtCommunity::ExtCommunityList &list) { + comm.Append(list); + } + + void PrependOriginVpn(OriginVnPath &path, + const OriginVnPath::OriginVnValue &value) { + path.Prepend(value); + } + EventManager evm_; BgpServer server_; BgpAttrDB *attr_db_; @@ -545,7 +555,7 @@ TEST_F(BgpAttrTest, ExtCommunityAppend1) { put_value(comm.data(), comm.size(), 100 * idx); list.push_back(comm); } - extcomm1.Append(list); + AppendExtendedCommunity(extcomm1, list); ExtCommunitySpec spec2; for (int idx = 1; idx < 9; idx++) @@ -567,7 +577,7 @@ TEST_F(BgpAttrTest, ExtCommunityAppend2) { put_value(comm.data(), comm.size(), 100 * idx); list.push_back(comm); } - extcomm1.Append(list); + AppendExtendedCommunity(extcomm1, list); ExtCommunitySpec spec2; for (int idx = 1; idx < 5; idx++) @@ -652,7 +662,7 @@ TEST_F(BgpAttrTest, OriginVnPathPrepend) { for (int idx = 4; idx >= 1; idx--) { OriginVn origin_vn(64512, 100 * idx); - ovnpath1.Prepend(origin_vn.GetExtCommunity()); + PrependOriginVpn(ovnpath1, origin_vn.GetExtCommunity()); } OriginVnPathSpec spec2; @@ -685,7 +695,7 @@ TEST_F(BgpAttrTest, OriginVnPathContains) { for (int idx = 8; idx > 0; idx -= 2) { OriginVn origin_vn(64512, 100 * idx); - ovnpath.Prepend(origin_vn.GetExtCommunity()); + PrependOriginVpn(ovnpath, origin_vn.GetExtCommunity()); } for (int idx = 1; idx <= 9; idx++) { @@ -1195,11 +1205,11 @@ TEST_F(BgpAttrTest, PmsiTunnel4a) { const PmsiTunnel *pmsi_tunnel = attr->pmsi_tunnel(); EXPECT_EQ(PmsiTunnelSpec::EdgeReplicationSupported, - pmsi_tunnel->tunnel_flags); + pmsi_tunnel->tunnel_flags()); EXPECT_EQ(PmsiTunnelSpec::IngressReplication, - pmsi_tunnel->tunnel_type); + pmsi_tunnel->tunnel_type()); EXPECT_EQ(10000, pmsi_tunnel->GetLabel()); - EXPECT_EQ("10.1.1.1", pmsi_tunnel->identifier.to_string()); + EXPECT_EQ("10.1.1.1", pmsi_tunnel->identifier().to_string()); } TEST_F(BgpAttrTest, PmsiTunnel4b) { @@ -1216,11 +1226,11 @@ TEST_F(BgpAttrTest, PmsiTunnel4b) { const PmsiTunnel *pmsi_tunnel = attr->pmsi_tunnel(); EXPECT_EQ(PmsiTunnelSpec::EdgeReplicationSupported, - pmsi_tunnel->tunnel_flags); + pmsi_tunnel->tunnel_flags()); EXPECT_EQ(PmsiTunnelSpec::IngressReplication, - pmsi_tunnel->tunnel_type); + pmsi_tunnel->tunnel_type()); EXPECT_EQ(EvpnPrefix::kMaxVni, pmsi_tunnel->GetLabel(true)); - EXPECT_EQ("10.1.1.1", pmsi_tunnel->identifier.to_string()); + EXPECT_EQ("10.1.1.1", pmsi_tunnel->identifier().to_string()); } TEST_F(BgpAttrTest, PmsiTunnel5) { diff --git a/src/bgp/test/bgp_evpn_manager_test.cc b/src/bgp/test/bgp_evpn_manager_test.cc index 4e563d71a43..b90bd494c62 100644 --- a/src/bgp/test/bgp_evpn_manager_test.cc +++ b/src/bgp/test/bgp_evpn_manager_test.cc @@ -208,7 +208,7 @@ class BgpEvpnManagerTest : public ::testing::TestWithParam { if (olist == NULL) return false; bool found = false; - BOOST_FOREACH(const BgpOListElem *elem, olist->elements) { + BOOST_FOREACH(const BgpOListElem *elem, olist->elements()) { if (peer->address() == elem->address) { EXPECT_FALSE(found); found = true; @@ -237,7 +237,7 @@ class BgpEvpnManagerTest : public ::testing::TestWithParam { BgpOListPtr olist = leaf ? attr->leaf_olist() : attr->olist(); if (olist == NULL) return false; - BOOST_FOREACH(BgpOListElem *elem, olist->elements) { + BOOST_FOREACH(BgpOListElem *elem, olist->elements()) { if (peer->address() == elem->address) return false; } @@ -289,7 +289,7 @@ class BgpEvpnManagerTest : public ::testing::TestWithParam { } const BgpAttr *attr = uinfo->roattr.attr(); - if (attr->olist()->elements.size() != count) + if (attr->olist()->elements().size() != count) return false; if (include_leaf && peer->assisted_replication_supported()) { @@ -302,10 +302,10 @@ class BgpEvpnManagerTest : public ::testing::TestWithParam { leaf_count++; } - if (attr->leaf_olist()->elements.size() != leaf_count) + if (attr->leaf_olist()->elements().size() != leaf_count) return false; } else { - if (attr->leaf_olist()->elements.size() != 0) + if (attr->leaf_olist()->elements().size() != 0) return false; } @@ -477,11 +477,11 @@ class BgpEvpnManagerTest : public ::testing::TestWithParam { TASK_UTIL_EXPECT_TRUE(attr->pmsi_tunnel() != NULL); const PmsiTunnel *pmsi_tunnel = attr->pmsi_tunnel(); TASK_UTIL_EXPECT_EQ(PmsiTunnelSpec::EdgeReplicationSupported, - pmsi_tunnel->tunnel_flags); + pmsi_tunnel->tunnel_flags()); TASK_UTIL_EXPECT_EQ(PmsiTunnelSpec::IngressReplication, - pmsi_tunnel->tunnel_type); + pmsi_tunnel->tunnel_type()); TASK_UTIL_EXPECT_EQ(peer->label(), pmsi_tunnel->GetLabel()); - TASK_UTIL_EXPECT_EQ(peer->address(), pmsi_tunnel->identifier); + TASK_UTIL_EXPECT_EQ(peer->address(), pmsi_tunnel->identifier()); TASK_UTIL_EXPECT_EQ(peer->address(), attr->nexthop().to_v4()); TASK_UTIL_EXPECT_EQ(peer->address(), attr->originator_id()); TASK_UTIL_EXPECT_TRUE(attr->ext_community() != NULL); @@ -1094,12 +1094,12 @@ class BgpEvpnManagerTest : public ::testing::TestWithParam { const BgpAttr *attr = rt->BestPath()->GetAttr(); TASK_UTIL_EXPECT_TRUE(attr->pmsi_tunnel() != NULL); const PmsiTunnel *pmsi_tunnel = attr->pmsi_tunnel(); - TASK_UTIL_EXPECT_EQ(PmsiTunnelSpec::ARLeaf, pmsi_tunnel->tunnel_flags); + TASK_UTIL_EXPECT_EQ(PmsiTunnelSpec::ARLeaf, pmsi_tunnel->tunnel_flags()); TASK_UTIL_EXPECT_EQ(PmsiTunnelSpec::AssistedReplicationContrail, - pmsi_tunnel->tunnel_type); + pmsi_tunnel->tunnel_type()); TASK_UTIL_EXPECT_EQ(peer->label(), pmsi_tunnel->GetLabel()); TASK_UTIL_EXPECT_EQ(peer->replicator_address(), - pmsi_tunnel->identifier); + pmsi_tunnel->identifier()); TASK_UTIL_EXPECT_EQ(peer->address(), attr->nexthop().to_v4()); TASK_UTIL_EXPECT_TRUE(attr->ext_community() != NULL); vector encap = attr->ext_community()->GetTunnelEncap(); @@ -1263,11 +1263,11 @@ class BgpEvpnManagerTest : public ::testing::TestWithParam { const PmsiTunnel *pmsi_tunnel = attr->pmsi_tunnel(); uint8_t tunnel_flags = PmsiTunnelSpec::EdgeReplicationSupported | PmsiTunnelSpec::ARReplicator | PmsiTunnelSpec::LeafInfoRequired; - TASK_UTIL_EXPECT_EQ(tunnel_flags, pmsi_tunnel->tunnel_flags); + TASK_UTIL_EXPECT_EQ(tunnel_flags, pmsi_tunnel->tunnel_flags()); TASK_UTIL_EXPECT_EQ(PmsiTunnelSpec::IngressReplication, - pmsi_tunnel->tunnel_type); + pmsi_tunnel->tunnel_type()); TASK_UTIL_EXPECT_EQ(peer->label(), pmsi_tunnel->GetLabel()); - TASK_UTIL_EXPECT_EQ(peer->address(), pmsi_tunnel->identifier); + TASK_UTIL_EXPECT_EQ(peer->address(), pmsi_tunnel->identifier()); TASK_UTIL_EXPECT_EQ(peer->address(), attr->nexthop().to_v4()); TASK_UTIL_EXPECT_EQ(peer->address(), attr->originator_id()); TASK_UTIL_EXPECT_TRUE(attr->ext_community() != NULL); diff --git a/src/bgp/test/bgp_multicast_test.cc b/src/bgp/test/bgp_multicast_test.cc index a1dabea85a4..b03bb24d79e 100644 --- a/src/bgp/test/bgp_multicast_test.cc +++ b/src/bgp/test/bgp_multicast_test.cc @@ -261,8 +261,8 @@ class BgpMulticastTest : public ::testing::Test { TASK_UTIL_EXPECT_TRUE(uinfo.get() != NULL); BgpOList *olist = uinfo->roattr.attr()->olist().get(); TASK_UTIL_EXPECT_TRUE(olist != NULL); - EXPECT_GE(olist->elements.size(), 1); - EXPECT_LE(olist->elements.size(), McastTreeManager::kDegree + 1); + EXPECT_GE(olist->elements().size(), 1); + EXPECT_LE(olist->elements().size(), McastTreeManager::kDegree + 1); } void VerifyOnlyForwarderProperties(ErmVpnTable *table, diff --git a/src/bgp/test/bgp_server_test_util.cc b/src/bgp/test/bgp_server_test_util.cc index 6e4e9211ee4..c13b1094e31 100644 --- a/src/bgp/test/bgp_server_test_util.cc +++ b/src/bgp/test/bgp_server_test_util.cc @@ -26,6 +26,7 @@ int StateMachineTest::hold_time_msecs_ = 0; int StateMachineTest::keepalive_time_msecs_ = 0; int XmppStateMachineTest::hold_time_msecs_ = 0; TcpSession::Event XmppStateMachineTest::skip_tcp_event_ =TcpSession::EVENT_NONE; +TcpSession::Event StateMachineTest::skip_tcp_event_ = TcpSession::EVENT_NONE; // // This is a static data structure that maps client tcp end points to configured @@ -184,7 +185,7 @@ void BgpPeerTest::SetDataCollectionKey(BgpPeerInfo *peer_info) const { // BgpPeerTest::BgpPeerTest(BgpServer *server, RoutingInstance *rtinst, const BgpNeighborConfig *config) - : BgpPeer(server, rtinst, config) { + : BgpPeer(server, rtinst, config), id_(0) { SendUpdate_fnc_ = boost::bind(&BgpPeerTest::BgpPeerSendUpdate, this, _1, _2); MpNlriAllowed_fnc_ = boost::bind(&BgpPeerTest::BgpPeerMpNlriAllowed, this, diff --git a/src/bgp/test/bgp_server_test_util.h b/src/bgp/test/bgp_server_test_util.h index a9f956ac2bb..9db075951f5 100644 --- a/src/bgp/test/bgp_server_test_util.h +++ b/src/bgp/test/bgp_server_test_util.h @@ -6,6 +6,7 @@ #define __BGP_SERVER_TEST_UTIL_H__ #include +#include #include #include "base/util.h" @@ -178,9 +179,22 @@ class StateMachineTest : public StateMachine { keepalive_time_msecs_ = keepalive_time_msecs; } + static TcpSession::Event get_skip_tcp_event() { return skip_tcp_event_; } + static void set_skip_tcp_event(TcpSession::Event event) { + skip_tcp_event_ = event; + } + + virtual void OnSessionEvent(TcpSession *session, TcpSession::Event event) { + if (skip_tcp_event_ != event) + StateMachine::OnSessionEvent(session, event); + else + skip_tcp_event_ = TcpSession::EVENT_NONE; + } + private: static int hold_time_msecs_; static int keepalive_time_msecs_; + static TcpSession::Event skip_tcp_event_; }; class BgpServerTest : public BgpServer { @@ -259,6 +273,11 @@ class BgpPeerTest : public BgpPeer { bool BgpPeerIsReady(); void SetDataCollectionKey(BgpPeerInfo *peer_info) const; + void SendEorMarker() { + BOOST_FOREACH(std::string family, negotiated_families()) { + SendEndOfRIB(Address::FamilyFromString(family)); + } + } virtual bool IsReady() const { return IsReady_fnc_(); @@ -268,6 +287,9 @@ class BgpPeerTest : public BgpPeer { vpn_tables_registered_ = registered; } + const int id() const { return id_; } + void set_id(int id) { id_ = id; } + boost::function SendUpdate_fnc_; boost::function MpNlriAllowed_fnc_; boost::function IsReady_fnc_; @@ -276,6 +298,7 @@ class BgpPeerTest : public BgpPeer { private: static bool verbose_name_; + int id_; }; class PeerManagerTest : public PeerManager { diff --git a/src/bgp/test/graceful_restart_test.cc b/src/bgp/test/graceful_restart_test.cc index 6574c047e6e..9037aa51860 100644 --- a/src/bgp/test/graceful_restart_test.cc +++ b/src/bgp/test/graceful_restart_test.cc @@ -9,12 +9,14 @@ #include "base/test/addr_test_util.h" +#include "bgp/bgp_config_parser.h" #include "bgp/bgp_factory.h" #include "bgp/bgp_peer_membership.h" #include "bgp/bgp_session_manager.h" #include "bgp/bgp_xmpp_channel.h" #include "bgp/inet/inet_table.h" #include "bgp/l3vpn/inetvpn_table.h" +#include "bgp/bgp_session_manager.h" #include "bgp/test/bgp_server_test_util.h" #include "bgp/tunnel_encap/tunnel_encap.h" #include "bgp/xmpp_message_builder.h" @@ -39,12 +41,24 @@ using ::testing::Bool; using ::testing::ValuesIn; using ::testing::Combine; -static vector n_instances = boost::assign::list_of(8); -static vector n_routes = boost::assign::list_of(8); -static vector n_agents = boost::assign::list_of(8); -static vector n_targets = boost::assign::list_of(1); -static vector xmpp_close_from_control_node = - boost::assign::list_of(false); +static int d_instances = 4; +static int d_routes = 4; +static int d_agents = 4; +static int d_peers = 4; +static int d_targets = 1; + +static string d_log_category_ = ""; +static string d_log_level_ = "SYS_WARN"; +static bool d_log_local_enable_ = false; +static bool d_log_trace_enable_ = false; +static bool d_log_enable_ = false; + +static vector n_instances = boost::assign::list_of(d_instances); +static vector n_routes = boost::assign::list_of(d_routes); +static vector n_agents = boost::assign::list_of(d_agents); +static vector n_peers = boost::assign::list_of(d_peers); +static vector n_targets = boost::assign::list_of(d_targets); + static char **gargv; static int gargc; static int n_db_walker_wait_usecs = 0; @@ -55,21 +69,48 @@ static void process_command_line_args(int argc, char **argv) { if (cmd_line_processed) return; cmd_line_processed = true; - int instances = 1, routes = 1, agents = 1, targets = 1; - bool close_from_control_node = false; + int ninstances, nroutes, nagents, npeers, ntargets; bool cmd_line_arg_set = false; + const unsigned long log_file_size = 1*1024*1024*1024; // 1GB + const unsigned int log_file_index = 10; + const string log_file = ""; + bool log_file_uniquefy = false; // Declare the supported options. options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") - ("nroutes", value(), "set number of routes") - ("nagents", value(), "set number of xmpp agents") - ("ninstances", value(), "set number of routing instances") - ("ntargets", value(), "set number of route targets") + ("log-category", value()->default_value(d_log_category_), + "set log category") + ("log-disable", bool_switch(&d_log_enable_), + "Disable logging") + ("log-file", value()->default_value(log_file), + "Filename for the logs to be written to") + ("log-file-index", + value()->default_value(log_file_index), + "Maximum log file roll over index") + ("log-file-size", + value()->default_value(log_file_size), + "Maximum size of the log file") + ("log-file-uniquefy", bool_switch(&log_file_uniquefy), + "Use pid to make log-file name unique") + ("log-level", value()->default_value(d_log_level_), + "set log level ") + ("log-local-enable", bool_switch(&d_log_local_enable_), + "Enable local logging") + ("log-trace-enable", bool_switch(&d_log_trace_enable_), + "Enable logging traces") + ("nroutes", value()->default_value(d_routes), + "set number of routes") + ("nagents", value()->default_value(d_agents), + "set number of xmpp agents") + ("npeers", value()->default_value(d_peers), + "set number of bgp peers") + ("ninstances", value()->default_value(d_instances), + "set number of routing instances") + ("ntargets", value()->default_value(d_targets), + "set number of route targets") ("db-walker-wait-usecs", value(), "set usecs delay in walker cb") - ("close-from-control-node", bool_switch(&close_from_control_node), - "Initiate xmpp session close from control-node") ; variables_map vm; @@ -81,24 +122,24 @@ static void process_command_line_args(int argc, char **argv) { exit(1); } - if (close_from_control_node) { - cmd_line_arg_set = true; - } - if (vm.count("ninstances")) { - instances = vm["ninstances"].as(); + ninstances = vm["ninstances"].as(); cmd_line_arg_set = true; } if (vm.count("nroutes")) { - routes = vm["nroutes"].as(); + nroutes = vm["nroutes"].as(); cmd_line_arg_set = true; } if (vm.count("nagents")) { - agents = vm["nagents"].as(); + nagents = vm["nagents"].as(); + cmd_line_arg_set = true; + } + if (vm.count("npeers")) { + npeers = vm["npeers"].as(); cmd_line_arg_set = true; } if (vm.count("ntargets")) { - targets = vm["ntargets"].as(); + ntargets = vm["ntargets"].as(); cmd_line_arg_set = true; } if (vm.count("db-walker-wait-usecs")) { @@ -108,19 +149,48 @@ static void process_command_line_args(int argc, char **argv) { if (cmd_line_arg_set) { n_instances.clear(); - n_instances.push_back(instances); + n_instances.push_back(ninstances); n_routes.clear(); - n_routes.push_back(routes); + n_routes.push_back(nroutes); n_targets.clear(); - n_targets.push_back(targets); + n_targets.push_back(ntargets); n_agents.clear(); - n_agents.push_back(agents); + n_agents.push_back(nagents); + + n_peers.clear(); + n_peers.push_back(npeers); + } - xmpp_close_from_control_node.clear(); - xmpp_close_from_control_node.push_back(close_from_control_node); + if (!d_log_enable_) { + SetLoggingDisabled(true); + } + + // Set Sandesh log category and level + Sandesh::SetLoggingParams(d_log_local_enable_, d_log_category_, + d_log_level_, d_log_trace_enable_); + + if (!vm.count("log-file") || vm["log-file"].as() == "") { + bgp_log_test::init(); + } else { + ostringstream log_file; + log_file << vm["log-file"].as(); + if (log_file_uniquefy) { + boost::system::error_code error; + string hostname(boost::asio::ip::host_name(error)); + log_file << "." << hostname << "." << getpid(); + } + + Module::type module = Module::CONTROL_NODE; + string module_name = g_vns_constants.ModuleNames.find(module)->second; + bgp_log_test::init(log_file.str(), + vm.count("log-file-size") ? + vm["log-file-size"].as() : log_file_size, + vm.count("log-file-index") ? + vm["log-file-index"].as() : log_file_index, + d_log_enable_, d_log_level_, module_name, d_log_level_); } } @@ -134,6 +204,11 @@ static vector GetAgentParameters() { return n_agents; } +static vector GetPeerParameters() { + process_command_line_args(gargc, gargv); + return n_peers; +} + static vector GetRouteParameters() { process_command_line_args(gargc, gargv); return n_routes; @@ -164,7 +239,7 @@ class BgpXmppChannelManagerMock : public BgpXmppChannelManager { BgpXmppChannel *channel_; }; -typedef std::tr1::tuple TestParams; +typedef std::tr1::tuple TestParams; class GracefulRestartTest : public ::testing::TestWithParam { @@ -174,6 +249,9 @@ class GracefulRestartTest : public ::testing::TestWithParam { xmpp_server_->GetIsPeerCloseGraceful_fnc_ = boost::bind(&GracefulRestartTest::IsPeerCloseGraceful, this, graceful); + server_->GetIsPeerCloseGraceful_fnc_ = + boost::bind(&GracefulRestartTest::IsPeerCloseGraceful, this, + graceful); } protected: @@ -183,6 +261,8 @@ class GracefulRestartTest : public ::testing::TestWithParam { virtual void TearDown(); void AgentCleanup(); void Configure(); + void PeerUp(BgpPeerTest *peer); + void PeerDown(BgpPeerTest *peer); XmppChannelConfig *CreateXmppChannelCfg(const char *address, int port, const string &from, @@ -191,29 +271,32 @@ class GracefulRestartTest : public ::testing::TestWithParam { void GracefulRestartTestStart(); void GracefulRestartTestRun(); - string GetConfig(); + string GetConfig(bool delete_config); ExtCommunitySpec *CreateRouteTargets(); - void AddAgentsWithRoutes(const BgpInstanceConfig *instance_config); - void AddXmppPeersWithRoutes(); + void AddRoutes(); void CreateAgents(); void Subscribe(); void UnSubscribe(); test::NextHops GetNextHops(test::NetworkAgentMock *agent, int instance_id); void AddOrDeleteXmppRoutes(bool add, int nroutes = -1, int down_agents = -1); + void AddOrDeleteBgpRoutes(bool add, int nroutes = -1, int down_agents = -1); void VerifyReceivedXmppRoutes(int routes); void DeleteRoutingInstances(int count, vector &dont_unsubscribe); void DeleteRoutingInstances(vector instances, vector &dont_unsubscribe); void VerifyDeletedRoutingInstnaces(vector instances); - void VerifyRoutingInstances(); - void XmppPeerClose(int nagents = -1); + void VerifyRoutingInstances(BgpServer *server); + void XmppAgentClose(int nagents = -1); void CallStaleTimer(BgpXmppChannel *channel); + void CallStaleTimer(BgpPeerTest *peer); void InitParams(); void VerifyRoutes(int count); bool IsReady(bool ready); void WaitForAgentToBeEstablished(test::NetworkAgentMock *agent); + void WaitForPeerToBeEstablished( BgpPeerTest *peer); + void BgpPeersAdminUpOrDown(bool down); EventManager evm_; ServerThread thread_; @@ -223,35 +306,56 @@ class GracefulRestartTest : public ::testing::TestWithParam { scoped_ptr master_cfg_; RoutingInstance *master_instance_; std::vector xmpp_agents_; - std::vector xmpp_peers_; + std::vector bgp_peers_; + std::vector bgp_servers_; + std::vector bgp_xmpp_channels_; + std::vector bgp_server_peers_; int n_families_; std::vector familes_; int n_instances_; int n_routes_; int n_agents_; + int n_peers_; int n_targets_; - bool xmpp_close_from_control_node_; - struct AgentTestParams { - AgentTestParams(test::NetworkAgentMock *agent, vector instance_ids, + struct GRTestParams { + GRTestParams(test::NetworkAgentMock *agent, vector instance_ids, vector nroutes, TcpSession::Event skip_tcp_event) { - initialize(agent, instance_ids, nroutes, skip_tcp_event); + initialize(agent, NULL, instance_ids, nroutes, skip_tcp_event); } - AgentTestParams(test::NetworkAgentMock *agent, vector instance_ids, + GRTestParams(test::NetworkAgentMock *agent, vector instance_ids, vector nroutes) { - initialize(agent, instance_ids, nroutes, TcpSession::EVENT_NONE); + initialize(agent, NULL, instance_ids, nroutes, + TcpSession::EVENT_NONE); } - AgentTestParams(test::NetworkAgentMock *agent) { - initialize(agent, vector(), vector(), + GRTestParams(test::NetworkAgentMock *agent) { + initialize(agent, NULL, vector(), vector(), TcpSession::EVENT_NONE); } - void initialize(test::NetworkAgentMock *agent, + GRTestParams(BgpPeerTest *peer, vector instance_ids, + vector nroutes, TcpSession::Event skip_tcp_event) { + initialize(NULL, peer, instance_ids, nroutes, skip_tcp_event); + } + + GRTestParams(BgpPeerTest *peer, vector instance_ids, + vector nroutes) { + initialize(NULL, peer, instance_ids, nroutes, + TcpSession::EVENT_NONE); + } + + GRTestParams(BgpPeerTest *peer) { + initialize(NULL, peer, vector(), vector(), + TcpSession::EVENT_NONE); + } + + void initialize(test::NetworkAgentMock *agent, BgpPeerTest *peer, vector instance_ids, vector nroutes, TcpSession::Event skip_tcp_event) { this->agent = agent; + this->peer = peer; this->instance_ids = instance_ids; this->nroutes = nroutes; this->skip_tcp_event = skip_tcp_event; @@ -259,23 +363,39 @@ class GracefulRestartTest : public ::testing::TestWithParam { } test::NetworkAgentMock *agent; + BgpPeerTest *peer; vector instance_ids; vector nroutes; TcpSession::Event skip_tcp_event; bool send_eor; }; void ProcessFlippingAgents(int &total_routes, int remaining_instances, - std::vector &n_flipping_agents); - std::vector n_flipped_agents_; + std::vector &n_flipping_agents); + void ProcessVpnRoute(BgpPeerTest *peer, int instance, + int n_routes, bool add); + void ProcessFlippingPeers(int &total_routes, int remaining_instances, + vector &n_flipping_peers); + + std::vector n_flipped_agents_; + std::vector n_flipped_peers_; std::vector n_down_from_agents_; + std::vector n_down_from_peers_; std::vector instances_to_delete_before_gr_; std::vector instances_to_delete_during_gr_; }; void GracefulRestartTest::SetUp() { - server_.reset(new BgpServerTest(&evm_, "A")); - xmpp_server_ = new XmppServerTest(&evm_, XMPP_CONTROL_SERV); + InitParams(); + + server_.reset(new BgpServerTest(&evm_, "RTR0")); + bgp_servers_.push_back(server_.get()); + + for (int i = 1; i <= n_peers_; i++) { + bgp_servers_.push_back( + new BgpServerTest(&evm_, "RTR" + boost::lexical_cast(i))); + } + xmpp_server_ = new XmppServerTest(&evm_, XMPP_CONTROL_SERV); channel_manager_.reset(new BgpXmppChannelManagerMock( xmpp_server_, server_.get())); master_cfg_.reset(BgpTestUtil::CreateBgpInstanceConfig( @@ -287,7 +407,8 @@ void GracefulRestartTest::SetUp() { familes_.push_back(Address::INET); familes_.push_back(Address::INETVPN); - server_->session_manager()->Initialize(0); + for (int i = 0; i <= n_peers_; i++) + bgp_servers_[i]->session_manager()->Initialize(0); xmpp_server_->Initialize(0, false); thread_.Start(); } @@ -295,7 +416,7 @@ void GracefulRestartTest::SetUp() { void GracefulRestartTest::TearDown() { task_util::WaitForIdle(); SetPeerCloseGraceful(false); - XmppPeerClose(); + XmppAgentClose(); xmpp_server_->Shutdown(); task_util::WaitForIdle(); @@ -312,7 +433,16 @@ void GracefulRestartTest::TearDown() { TcpServerManager::DeleteServer(xmpp_server_); xmpp_server_ = NULL; - server_->Shutdown(); + + for (int i = 1; i <= n_instances_; i++) { + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + ProcessVpnRoute(peer, i, n_routes_, false); + } + } + + for (int i = 0; i <= n_peers_; i++) + bgp_servers_[i]->Shutdown(); + task_util::WaitForIdle(); evm_.Shutdown(); thread_.Join(); @@ -324,9 +454,38 @@ void GracefulRestartTest::TearDown() { } void GracefulRestartTest::Configure() { - server_->Configure(GetConfig().c_str()); + string config = GetConfig(false); + for (int i = 0; i <= n_peers_; i++) + bgp_servers_[i]->Configure(config.c_str()); task_util::WaitForIdle(); - VerifyRoutingInstances(); + for (int i = 0; i <= n_peers_; i++) + VerifyRoutingInstances(bgp_servers_[i]); + + // Get peers to DUT (RTR0) to bgp_peers_ vector. + for (int i = 1; i <= n_peers_; i++) { + string uuid = BgpConfigParser::session_uuid("RTR0", + "RTR" + boost::lexical_cast(i), 1); + TASK_UTIL_EXPECT_NE(static_cast(NULL), + bgp_servers_[i]->FindPeerByUuid( + BgpConfigManager::kMasterInstance, uuid)); + BgpPeerTest *peer = bgp_servers_[i]->FindPeerByUuid( + BgpConfigManager::kMasterInstance, uuid); + peer->set_id(i-1); + bgp_peers_.push_back(peer); + } + + // Get peers in DUT (RTR0) to other bgp_servers. + for (int i = 1; i <= n_peers_; i++) { + string uuid = BgpConfigParser::session_uuid("RTR0", + "RTR" + boost::lexical_cast(i), 1); + TASK_UTIL_EXPECT_NE(static_cast(NULL), + bgp_servers_[i]->FindPeerByUuid( + BgpConfigManager::kMasterInstance, uuid)); + BgpPeerTest *peer = bgp_servers_[0]->FindPeerByUuid( + BgpConfigManager::kMasterInstance, uuid); + peer->set_id(i-1); + bgp_server_peers_.push_back(peer); + } } XmppChannelConfig *GracefulRestartTest::CreateXmppChannelCfg( @@ -352,30 +511,50 @@ void GracefulRestartTest::VerifyRoutes(int count) { for (int i = 0; i < n_families_; i++) { BgpTable *tb = master_instance_->GetTable(familes_[i]); if (count && n_agents_ && familes_[i] == Address::INETVPN) { - BGP_VERIFY_ROUTE_COUNT(tb, n_agents_ * n_instances_ * count); + BGP_VERIFY_ROUTE_COUNT(tb, + (n_agents_ + n_peers_) * n_instances_ * count); } } } -string GracefulRestartTest::GetConfig() { +string GracefulRestartTest::GetConfig(bool delete_config) { ostringstream out; - out << - "\ - \ - 192.168.0.1\ -
127.0.0.1
\ - " << server_->session_manager()->GetPort() << "\ - \ - \ - inet-vpn\ - e-vpn\ - erm-vpn\ - route-target\ - \ - \ -
\ - "; + if (delete_config) + out << ""; + else + out << ""; + + for (int i = 0; i <= n_peers_; i++) { + out << "\ + 192.168.0." << i << "\ +
127.0.0.1
\ + " << bgp_servers_[i]->session_manager()->GetPort(); + out << ""; + + for (int j = 0; j <= n_peers_; j++) { + + // Do not peer with self + if (i == j) + continue; + + // Peer only with DUT + if (i > 0 && j > 0) + break; + + // Create a session between DUT and other BgpServers. + out << "\ + false\ + \ + inet-vpn\ + e-vpn\ + erm-vpn\ + route-target\ + \ + "; + } + out << "
"; + } for (int i = 1; i <= n_instances_; i++) { out << "\n"; @@ -386,20 +565,44 @@ string GracefulRestartTest::GetConfig() { } out << "
"; - BGP_DEBUG_UT("Applying config" << out.str()); return out.str(); } +void GracefulRestartTest::BgpPeersAdminUpOrDown(bool down) { + ostringstream out; + + out << ""; + for (int i = 1; i <= n_peers_; i++) { + out << ""; + + // Mark all sessions to DUT (RTR0) as down initially. + string admin_down = down ? "true" : "false"; + out << "\ + " << admin_down << "\ + "; + } + out << ""; + + BGP_DEBUG_UT("Applying config" << out.str()); + for (int i = 1; i <= n_peers_; i++) + bgp_servers_[i]->Configure(out.str().c_str()); + task_util::WaitForIdle(); +} + bool GracefulRestartTest::IsReady(bool ready) { return ready; } void GracefulRestartTest::WaitForAgentToBeEstablished( test::NetworkAgentMock *agent) { - TASK_UTIL_EXPECT_EQ(true, agent->IsChannelReady()); - TASK_UTIL_EXPECT_EQ(true, agent->IsEstablished()); + TASK_UTIL_EXPECT_TRUE(agent->IsChannelReady()); + TASK_UTIL_EXPECT_TRUE(agent->IsEstablished()); +} + +void GracefulRestartTest::WaitForPeerToBeEstablished(BgpPeerTest *peer) { + TASK_UTIL_EXPECT_TRUE(peer->IsReady()); } ExtCommunitySpec *GracefulRestartTest::CreateRouteTargets() { @@ -418,21 +621,25 @@ ExtCommunitySpec *GracefulRestartTest::CreateRouteTargets() { return commspec.release(); } -void GracefulRestartTest::AddXmppPeersWithRoutes() { - if (!n_agents_) return; +void GracefulRestartTest::AddRoutes() { + if (!n_agents_ && !n_peers_) + return; CreateAgents(); - BOOST_FOREACH(test::NetworkAgentMock *agent, xmpp_agents_) { WaitForAgentToBeEstablished(agent); } - task_util::WaitForIdle(); + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + BGP_WAIT_FOR_PEER_STATE(peer, StateMachine::ESTABLISHED); + } + Subscribe(); VerifyReceivedXmppRoutes(0); + AddOrDeleteBgpRoutes(true); AddOrDeleteXmppRoutes(true); task_util::WaitForIdle(); - VerifyReceivedXmppRoutes(n_instances_ * n_agents_ * n_routes_); + VerifyReceivedXmppRoutes(n_instances_ * (n_agents_ + n_peers_) * n_routes_); } void GracefulRestartTest::CreateAgents() { @@ -453,7 +660,7 @@ void GracefulRestartTest::CreateAgents() { TASK_UTIL_EXPECT_NE_MSG(static_cast(NULL), channel_manager_->channel_, "Waiting for channel_manager_->channel_ to be set"); - xmpp_peers_.push_back(channel_manager_->channel_); + bgp_xmpp_channels_.push_back(channel_manager_->channel_); channel_manager_->channel_ = NULL; prefix = task_util::Ip4PrefixIncrement(prefix); @@ -494,8 +701,72 @@ test::NextHops GracefulRestartTest::GetNextHops (test::NetworkAgentMock *agent, return nexthops; } +void GracefulRestartTest::ProcessVpnRoute(BgpPeerTest *peer, int instance, + int n_routes, bool add) { + + RoutingInstance *rtinstance = static_cast( + peer->server()->routing_instance_mgr()->GetRoutingInstance( + BgpConfigManager::kMasterInstance)); + BgpTable *table = rtinstance->GetTable(Address::INETVPN); + + + InetVpnPrefix vpn_prefix(InetVpnPrefix::FromString( + "123:" + boost::lexical_cast(instance) + ":" + + "20." + boost::lexical_cast(instance) + "." + + boost::lexical_cast(peer->id()) + ".1/32")); + + DBRequest req; + boost::scoped_ptr local_pref; + boost::scoped_ptr commspec; + + for (int rt = 0; rt < n_routes; rt++, + vpn_prefix = task_util::InetVpnPrefixIncrement(vpn_prefix)) { + + req.key.reset(new InetVpnTable::RequestKey(vpn_prefix, NULL)); + req.oper = add ? DBRequest::DB_ENTRY_ADD_CHANGE : + DBRequest::DB_ENTRY_DELETE; + + local_pref.reset(new BgpAttrLocalPref(100)); + + BgpAttrSpec attr_spec; + attr_spec.push_back(local_pref.get()); + + BgpAttrNextHop nexthop(0x7f010000 + peer->id()); + attr_spec.push_back(&nexthop); + + commspec.reset(CreateRouteTargets()); + + TunnelEncap tun_encap(std::string("gre")); + commspec->communities.push_back(get_value( + tun_encap.GetExtCommunity().begin(), 8)); + attr_spec.push_back(commspec.get()); + BgpAttrPtr attr = peer->server()->attr_db()->Locate(attr_spec); + + req.data.reset(new InetTable::RequestData(attr, 0, + 1000*instance + rt)); + table->Enqueue(&req); + } + task_util::WaitForIdle(); +} + +void GracefulRestartTest::AddOrDeleteBgpRoutes(bool add, int n_routes, + int down_peers) { + if (n_routes ==-1) + n_routes = n_routes_; + + if (down_peers == -1) + down_peers = n_peers_; + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + if (down_peers-- < 1) + continue; + for (int i = 1; i <= n_instances_; i++) + ProcessVpnRoute(peer, i, n_routes, add); + } +} + void GracefulRestartTest::AddOrDeleteXmppRoutes(bool add, int n_routes, - int down_agents) { + int down_agents) { if (n_routes ==-1) n_routes = n_routes_; @@ -524,7 +795,6 @@ void GracefulRestartTest::AddOrDeleteXmppRoutes(bool add, int n_routes, } } task_util::WaitForIdle(); - // if (!add) VerifyReceivedXmppRoutes(0); } void GracefulRestartTest::VerifyReceivedXmppRoutes(int routes) { @@ -585,6 +855,12 @@ void GracefulRestartTest::DeleteRoutingInstances(vector instances, agent) == dont_unsubscribe.end()) agent->Unsubscribe(instance_name); } + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + if (!peer->IsReady()) + continue; + ProcessVpnRoute(peer, i, n_routes_, false); + } } task_util::WaitForIdle(); } @@ -599,52 +875,41 @@ void GracefulRestartTest::VerifyDeletedRoutingInstnaces(vector instances) { task_util::WaitForIdle(); } -void GracefulRestartTest::VerifyRoutingInstances() { +void GracefulRestartTest::VerifyRoutingInstances(BgpServer *server) { for (int i = 1; i <= n_instances_; i++) { string instance_name = "instance" + boost::lexical_cast(i); TASK_UTIL_EXPECT_NE(static_cast(NULL), - server_->routing_instance_mgr()->\ + server->routing_instance_mgr()->\ GetRoutingInstance(instance_name)); } - // // Verify 'default' master routing-instance - // TASK_UTIL_EXPECT_NE(static_cast(NULL), - server_->routing_instance_mgr()->GetRoutingInstance( + server->routing_instance_mgr()->GetRoutingInstance( BgpConfigManager::kMasterInstance)); } -void GracefulRestartTest::AddAgentsWithRoutes( - const BgpInstanceConfig *instance_config) { - Configure(); - SetPeerCloseGraceful(false); - AddXmppPeersWithRoutes(); -} - // Invoke stale timer callbacks directly as evm is not running in this unit test void GracefulRestartTest::CallStaleTimer(BgpXmppChannel *channel) { channel->Peer()->peer_close()->close_manager()->RestartTimerCallback(); task_util::WaitForIdle(); } -void GracefulRestartTest::XmppPeerClose(int nagents) { +// Invoke stale timer callbacks directly as evm is not running in this unit test +void GracefulRestartTest::CallStaleTimer(BgpPeerTest *peer) { + peer->peer_close()->close_manager()->RestartTimerCallback(); + task_util::WaitForIdle(); +} + +void GracefulRestartTest::XmppAgentClose(int nagents) { if (nagents < 1) nagents = xmpp_agents_.size(); int down_count = nagents; - if (xmpp_close_from_control_node_) { - BOOST_FOREACH(BgpXmppChannel *peer, xmpp_peers_) { - peer->Peer()->Close(); - if (!--down_count) - break; - } - } else { - BOOST_FOREACH(test::NetworkAgentMock *agent, xmpp_agents_) { - agent->SessionDown(); - if (!--down_count) - break; - } + BOOST_FOREACH(test::NetworkAgentMock *agent, xmpp_agents_) { + agent->SessionDown(); + if (!--down_count) + break; } down_count = nagents; @@ -656,10 +921,10 @@ void GracefulRestartTest::XmppPeerClose(int nagents) { void GracefulRestartTest::InitParams() { n_instances_ = ::std::tr1::get<0>(GetParam()); - n_routes_ = ::std::tr1::get<1>(GetParam()); - n_agents_ = ::std::tr1::get<2>(GetParam()); - n_targets_ = ::std::tr1::get<3>(GetParam()); - xmpp_close_from_control_node_ = ::std::tr1::get<4>(GetParam()); + n_routes_ = ::std::tr1::get<1>(GetParam()); + n_agents_ = ::std::tr1::get<2>(GetParam()); + n_peers_ = ::std::tr1::get<3>(GetParam()); + n_targets_ = ::std::tr1::get<4>(GetParam()); } // Bring up n_agents_ in n_instances_ and advertise @@ -677,34 +942,52 @@ void GracefulRestartTest::InitParams() { // Subset of routes are [re]advertised after restart // Subset of routing-instances are deleted (during GR) void GracefulRestartTest::GracefulRestartTestStart () { - InitParams(); + SetPeerCloseGraceful(false); + Configure(); // Bring up n_agents_ in n_instances_ and advertise n_routes_ per session - AddAgentsWithRoutes(master_cfg_.get()); + AddRoutes(); VerifyRoutes(n_routes_); } +void GracefulRestartTest::PeerUp(BgpPeerTest *peer) { + TASK_UTIL_EXPECT_FALSE(peer->IsReady()); + peer->SetAdminState(false); + TASK_UTIL_EXPECT_TRUE(peer->IsReady()); +} + +void GracefulRestartTest::PeerDown(BgpPeerTest *peer) { + TASK_UTIL_EXPECT_TRUE(peer->IsReady()); + peer->SetAdminState(true); + TASK_UTIL_EXPECT_FALSE(peer->IsReady()); + + // Also delete the routes + for (int i = 1; i <= n_instances_; i++) + ProcessVpnRoute(peer, i, n_routes_, false); +} + void GracefulRestartTest::ProcessFlippingAgents(int &total_routes, int remaining_instances, - vector &n_flipping_agents) { + vector &n_flipping_agents) { int flipping_count = 3; for (int f = 0; f < flipping_count; f++) { - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipping_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; TASK_UTIL_EXPECT_FALSE(agent->IsEstablished()); agent->SessionUp(); WaitForAgentToBeEstablished(agent); } - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipping_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; WaitForAgentToBeEstablished(agent); // Subset of subscriptions after restart agent->Subscribe(BgpConfigManager::kMasterInstance, -1); - for (size_t i = 0; i < agent_test_param.instance_ids.size(); i++) { - int instance_id = agent_test_param.instance_ids[i]; + + for (size_t i = 0; i < gr_test_param.instance_ids.size(); i++) { + int instance_id = gr_test_param.instance_ids[i]; if (std::find(instances_to_delete_before_gr_.begin(), instances_to_delete_before_gr_.end(), instance_id) != instances_to_delete_before_gr_.end()) @@ -713,6 +996,7 @@ void GracefulRestartTest::ProcessFlippingAgents(int &total_routes, instances_to_delete_during_gr_.end(), instance_id) != instances_to_delete_during_gr_.end()) continue; + string instance_name = "instance" + boost::lexical_cast(instance_id); agent->Subscribe(instance_name, instance_id); @@ -721,7 +1005,7 @@ void GracefulRestartTest::ProcessFlippingAgents(int &total_routes, Ip4Prefix prefix(Ip4Prefix::FromString( "10." + boost::lexical_cast(instance_id) + "." + boost::lexical_cast(agent->id()) + ".1/32")); - int nroutes = agent_test_param.nroutes[i]; + int nroutes = gr_test_param.nroutes[i]; for (int rt = 0; rt < nroutes; rt++, prefix = task_util::Ip4PrefixIncrement(prefix)) { agent->AddRoute(instance_name, prefix.ToString(), @@ -737,19 +1021,22 @@ void GracefulRestartTest::ProcessFlippingAgents(int &total_routes, if (f == flipping_count - 1) count /= 2; int k = 0; - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipping_agents) { + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_agents) { if (k++ >= count) break; - test::NetworkAgentMock *agent = agent_test_param.agent; + test::NetworkAgentMock *agent = gr_test_param.agent; WaitForAgentToBeEstablished(agent); + XmppStateMachineTest::set_skip_tcp_event( - agent_test_param.skip_tcp_event); + gr_test_param.skip_tcp_event); + agent->SessionDown(); TASK_UTIL_EXPECT_FALSE(agent->IsEstablished()); TASK_UTIL_EXPECT_EQ(TcpSession::EVENT_NONE, XmppStateMachineTest::get_skip_tcp_event()); - for (size_t i = 0; i < agent_test_param.instance_ids.size(); i++) { - int instance_id = agent_test_param.instance_ids[i]; + + for (size_t i = 0; i < gr_test_param.instance_ids.size(); i++) { + int instance_id = gr_test_param.instance_ids[i]; if (std::find(instances_to_delete_before_gr_.begin(), instances_to_delete_before_gr_.end(), instance_id) != instances_to_delete_before_gr_.end()) @@ -758,7 +1045,7 @@ void GracefulRestartTest::ProcessFlippingAgents(int &total_routes, instances_to_delete_during_gr_.end(), instance_id) != instances_to_delete_during_gr_.end()) continue; - int nroutes = agent_test_param.nroutes[i]; + int nroutes = gr_test_param.nroutes[i]; total_routes -= nroutes; } } @@ -766,13 +1053,13 @@ void GracefulRestartTest::ProcessFlippingAgents(int &total_routes, // Send EoR marker or trigger GR timer for agents which came back up and // sent desired routes. - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipping_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; - if (agent_test_param.send_eor && agent->IsEstablished()) { + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; + if (gr_test_param.send_eor && agent->IsEstablished()) { agent->SendEorMarker(); } else { PeerCloseManager *pc = - xmpp_peers_[agent->id()]->Peer()->peer_close()->close_manager(); + bgp_xmpp_channels_[agent->id()]->Peer()->peer_close()->close_manager(); // If the session is down and TCP down event was meant to be skipped // then we do not expect control-node to be unaware of it. Hold @@ -780,25 +1067,121 @@ void GracefulRestartTest::ProcessFlippingAgents(int &total_routes, // first in order to bring the peer down in the controller and then // call the GR timer callback. if (!agent->IsEstablished()) { - if (agent_test_param.skip_tcp_event != TcpSession::EVENT_NONE) { + if (gr_test_param.skip_tcp_event != TcpSession::EVENT_NONE) { uint64_t stale = pc->stats().stale; - const XmppStateMachine *sm = xmpp_peers_[ + const XmppStateMachine *sm = bgp_xmpp_channels_[ agent->id()]->channel()->connection()->state_machine(); const_cast(sm)->HoldTimerExpired(); TASK_UTIL_EXPECT_EQ(stale + 1, pc->stats().stale); } TASK_UTIL_EXPECT_FALSE( - xmpp_peers_[agent->id()]->Peer()->IsReady()); + bgp_xmpp_channels_[agent->id()]->Peer()->IsReady()); + TASK_UTIL_EXPECT_EQ(PeerCloseManager::GR_TIMER, pc->state()); + } + CallStaleTimer(bgp_xmpp_channels_[agent->id()]); + } + } + task_util::WaitForIdle(); +} + +void GracefulRestartTest::ProcessFlippingPeers(int &total_routes, + int remaining_instances, vector &n_flipping_peers) { + int flipping_count = 3; + + for (int f = 0; f < flipping_count; f++) { + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_peers) { + PeerUp(gr_test_param.peer); + } + + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_peers) { + BgpPeerTest *peer = gr_test_param.peer; + WaitForPeerToBeEstablished(peer); + + for (size_t i = 0; i < gr_test_param.instance_ids.size(); i++) { + int instance_id = gr_test_param.instance_ids[i]; + if (std::find(instances_to_delete_before_gr_.begin(), + instances_to_delete_before_gr_.end(), instance_id) != + instances_to_delete_before_gr_.end()) + continue; + if (std::find(instances_to_delete_during_gr_.begin(), + instances_to_delete_during_gr_.end(), instance_id) != + instances_to_delete_during_gr_.end()) + continue; + + int nroutes = gr_test_param.nroutes[i]; + ProcessVpnRoute(peer, instance_id, nroutes, true); + total_routes += nroutes; + } + } + + // Bring back half of the flipping peers to established state and send + // routes. Rest do not come back up (nested closures and LLGR) + int count = n_flipping_peers.size(); + if (f == flipping_count - 1) + count /= 2; + int k = 0; + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_peers) { + if (k++ >= count) + break; + + BgpPeerTest *peer = gr_test_param.peer; + WaitForPeerToBeEstablished(peer); + StateMachineTest::set_skip_tcp_event(gr_test_param.skip_tcp_event); + + PeerDown(peer); + TASK_UTIL_EXPECT_EQ(TcpSession::EVENT_NONE, + StateMachineTest::get_skip_tcp_event()); + + for (size_t i = 0; i < gr_test_param.instance_ids.size(); i++) { + int instance_id = gr_test_param.instance_ids[i]; + if (std::find(instances_to_delete_before_gr_.begin(), + instances_to_delete_before_gr_.end(), instance_id) != + instances_to_delete_before_gr_.end()) + continue; + if (std::find(instances_to_delete_during_gr_.begin(), + instances_to_delete_during_gr_.end(), instance_id) != + instances_to_delete_during_gr_.end()) + continue; + total_routes -= gr_test_param.nroutes[i]; + } + } + } + + // Send EoR marker or trigger GR timer for peers which came back up and + // sent desired routes. + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_peers) { + BgpPeerTest *peer = gr_test_param.peer; + if (false && gr_test_param.send_eor && peer->IsReady()) { + peer->SendEorMarker(); + } else { + PeerCloseManager *pc = + bgp_server_peers_[peer->id()]->peer_close()->close_manager(); + + // If the session is down and TCP down event was meant to be skipped + // then we do not expect control-node to be unaware of it. Hold + // timer must have expired by then. Trigger the hold-timer expiry + // first in order to bring the peer down in the controller and then + // call the GR timer callback. + if (!peer->IsReady()) { + if (gr_test_param.skip_tcp_event != TcpSession::EVENT_NONE) { + uint64_t stale = pc->stats().stale; + const StateMachine *sm = bgp_server_peers_[ + peer->id()]->state_machine(); + const_cast(sm)->HoldTimerExpired(); + TASK_UTIL_EXPECT_EQ(stale + 1, pc->stats().stale); + } + TASK_UTIL_EXPECT_FALSE(bgp_server_peers_[ + peer->id()]->IsReady()); TASK_UTIL_EXPECT_EQ(PeerCloseManager::GR_TIMER, pc->state()); } - CallStaleTimer(xmpp_peers_[agent->id()]); + CallStaleTimer(bgp_server_peers_[peer->id()]); } } task_util::WaitForIdle(); } void GracefulRestartTest::GracefulRestartTestRun () { - int total_routes = n_instances_ * n_agents_ * n_routes_; + int total_routes = n_instances_ * (n_agents_ + n_peers_) * n_routes_; // Verify that n_agents_ * n_instances_ * n_routes_ routes are received in // agent in each instance @@ -815,7 +1198,7 @@ void GracefulRestartTest::GracefulRestartTestRun () { DeleteRoutingInstances(instances_to_delete_before_gr_, dont_unsubscribe); int remaining_instances = n_instances_; remaining_instances -= instances_to_delete_before_gr_.size(); - total_routes -= n_routes_ * n_agents_ * + total_routes -= n_routes_ * (n_agents_ + n_peers_) * instances_to_delete_before_gr_.size(); // Subset of agents go down permanently (Triggered from agents) @@ -826,12 +1209,19 @@ void GracefulRestartTest::GracefulRestartTestRun () { total_routes -= remaining_instances * n_routes_; } + // Subset of peers go down permanently (Triggered from peers) + BOOST_FOREACH(BgpPeerTest *peer, n_down_from_peers_) { + WaitForPeerToBeEstablished(peer); + PeerDown(peer); + total_routes -= remaining_instances * n_routes_; + } + // Divide flipped agents into two parts. Agents in the first part flip // once and come back up (normal GR). Those in the second part keep // flipping. Eventually half the second part come back to normal up state. // Rest (1/4th overall) remain down triggering LLGR during the whole time. - vector n_flipped_agents = vector(); - vector n_flipping_agents = vector(); + vector n_flipped_agents = vector(); + vector n_flipping_agents = vector(); for (size_t i = 0; i < n_flipped_agents_.size(); i++) { if (i < n_flipped_agents_.size()/2) n_flipped_agents.push_back(n_flipped_agents_[i]); @@ -839,31 +1229,58 @@ void GracefulRestartTest::GracefulRestartTestRun () { n_flipping_agents.push_back(n_flipped_agents_[i]); } + vector n_flipped_peers = vector(); + vector n_flipping_peers = vector(); + for (size_t i = 0; i < n_flipped_peers_.size(); i++) { + if (i < n_flipped_peers_.size()/2) + n_flipped_peers.push_back(n_flipped_peers_[i]); + else + n_flipping_peers.push_back(n_flipped_peers_[i]); + } + // Subset of agents flip (Triggered from agents) - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipped_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; WaitForAgentToBeEstablished(agent); XmppStateMachineTest::set_skip_tcp_event( - agent_test_param.skip_tcp_event); + gr_test_param.skip_tcp_event); agent->SessionDown(); dont_unsubscribe.push_back(agent); TASK_UTIL_EXPECT_FALSE(agent->IsEstablished()); TASK_UTIL_EXPECT_EQ(TcpSession::EVENT_NONE, XmppStateMachineTest::get_skip_tcp_event()); total_routes -= remaining_instances * n_routes_; + + } + + // Subset of peers flip (Triggered from peers) + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_peers) { + BgpPeerTest *peer = gr_test_param.peer; + WaitForPeerToBeEstablished(peer); + StateMachineTest::set_skip_tcp_event(gr_test_param.skip_tcp_event); + PeerDown(peer); + TASK_UTIL_EXPECT_EQ(TcpSession::EVENT_NONE, + StateMachineTest::get_skip_tcp_event()); + total_routes -= remaining_instances * n_routes_; } // Subset of agents flip (Triggered from agents) - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipping_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; WaitForAgentToBeEstablished(agent); - XmppStateMachineTest::set_skip_tcp_event( - agent_test_param.skip_tcp_event); + XmppStateMachineTest::set_skip_tcp_event(gr_test_param.skip_tcp_event); agent->SessionDown(); dont_unsubscribe.push_back(agent); TASK_UTIL_EXPECT_FALSE(agent->IsEstablished()); - TASK_UTIL_EXPECT_EQ(TcpSession::EVENT_NONE, - XmppStateMachineTest::get_skip_tcp_event()); + total_routes -= remaining_instances * n_routes_; + } + + // Subset of peers flip (Triggered from peers) + BOOST_FOREACH(GRTestParams gr_test_param, n_flipping_peers) { + BgpPeerTest *peer = gr_test_param.peer; + WaitForPeerToBeEstablished(peer); + StateMachineTest::set_skip_tcp_event(gr_test_param.skip_tcp_event); + PeerDown(peer); total_routes -= remaining_instances * n_routes_; } @@ -877,23 +1294,34 @@ void GracefulRestartTest::GracefulRestartTestRun () { (n_agents_ - n_flipped_agents.size() - n_flipping_agents.size() - n_down_from_agents_.size()) * instances_to_delete_during_gr_.size(); + total_routes -= n_routes_ * + (n_peers_ - n_flipped_peers.size() - n_flipping_peers.size() - + n_down_from_peers_.size()) * instances_to_delete_during_gr_.size(); + XmppStateMachineTest::set_skip_tcp_event(TcpSession::EVENT_NONE); + StateMachineTest::set_skip_tcp_event(TcpSession::EVENT_NONE); - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipped_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; TASK_UTIL_EXPECT_FALSE(agent->IsEstablished()); agent->SessionUp(); WaitForAgentToBeEstablished(agent); } - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipped_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_peers) { + BgpPeerTest *peer = gr_test_param.peer; + TASK_UTIL_EXPECT_FALSE(peer->IsReady()); + PeerUp(peer); + } + + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; WaitForAgentToBeEstablished(agent); // Subset of subscriptions after restart agent->Subscribe(BgpConfigManager::kMasterInstance, -1); - for (size_t i = 0; i < agent_test_param.instance_ids.size(); i++) { - int instance_id = agent_test_param.instance_ids[i]; + for (size_t i = 0; i < gr_test_param.instance_ids.size(); i++) { + int instance_id = gr_test_param.instance_ids[i]; if (std::find(instances_to_delete_before_gr_.begin(), instances_to_delete_before_gr_.end(), instance_id) != instances_to_delete_before_gr_.end()) @@ -910,7 +1338,7 @@ void GracefulRestartTest::GracefulRestartTestRun () { Ip4Prefix prefix(Ip4Prefix::FromString( "10." + boost::lexical_cast(instance_id) + "." + boost::lexical_cast(agent->id()) + ".1/32")); - int nroutes = agent_test_param.nroutes[i]; + int nroutes = gr_test_param.nroutes[i]; for (int rt = 0; rt < nroutes; rt++, prefix = task_util::Ip4PrefixIncrement(prefix)) { agent->AddRoute(instance_name, prefix.ToString(), @@ -920,24 +1348,64 @@ void GracefulRestartTest::GracefulRestartTestRun () { } } + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_peers) { + BgpPeerTest *peer = gr_test_param.peer; + WaitForPeerToBeEstablished(peer); + + for (size_t i = 0; i < gr_test_param.instance_ids.size(); i++) { + int instance_id = gr_test_param.instance_ids[i]; + if (std::find(instances_to_delete_before_gr_.begin(), + instances_to_delete_before_gr_.end(), instance_id) != + instances_to_delete_before_gr_.end()) + continue; + if (std::find(instances_to_delete_during_gr_.begin(), + instances_to_delete_during_gr_.end(), instance_id) != + instances_to_delete_during_gr_.end()) + continue; + + // Subset of routes are [re]advertised after restart + int nroutes = gr_test_param.nroutes[i]; + ProcessVpnRoute(peer, instance_id, nroutes, true); + total_routes += nroutes; + } + } + // Send EoR marker or trigger GR timer for agents which came back up and // sent desired routes. - BOOST_FOREACH(AgentTestParams agent_test_param, n_flipped_agents) { - test::NetworkAgentMock *agent = agent_test_param.agent; - if (agent_test_param.send_eor) + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_agents) { + test::NetworkAgentMock *agent = gr_test_param.agent; + if (gr_test_param.send_eor) agent->SendEorMarker(); else - CallStaleTimer(xmpp_peers_[agent->id()]); + CallStaleTimer(bgp_xmpp_channels_[agent->id()]); } + // Send EoR marker or trigger GR timer for peers which came back up and + // sent desired routes. + BOOST_FOREACH(GRTestParams gr_test_param, n_flipped_peers) { + BgpPeerTest *peer = gr_test_param.peer; + if (false && gr_test_param.send_eor) + peer->SendEorMarker(); + else + CallStaleTimer(bgp_server_peers_[peer->id()]); + } // Process agents which keep flipping and trigger LLGR.. ProcessFlippingAgents(total_routes, remaining_instances, n_flipping_agents); + // Process peers which keep flipping and trigger LLGR.. + ProcessFlippingPeers(total_routes, remaining_instances, n_flipping_peers); + // Trigger GR timer for agents which went down permanently. BOOST_FOREACH(test::NetworkAgentMock *agent, n_down_from_agents_) { - CallStaleTimer(xmpp_peers_[agent->id()]); + CallStaleTimer(bgp_xmpp_channels_[agent->id()]); + } + + // Trigger GR timer for peers which went down permanently. + BOOST_FOREACH(BgpPeerTest *peer, n_down_from_peers_) { + CallStaleTimer(bgp_server_peers_[peer->id()]); } + VerifyReceivedXmppRoutes(total_routes); VerifyDeletedRoutingInstnaces(instances_to_delete_before_gr_); VerifyDeletedRoutingInstnaces(instances_to_delete_during_gr_); @@ -956,6 +1424,7 @@ TEST_P(GracefulRestartTest, GracefulRestart_Down_2) { GracefulRestartTestStart(); n_down_from_agents_ = xmpp_agents_; + n_down_from_peers_ = bgp_peers_; GracefulRestartTestRun(); } @@ -966,6 +1435,8 @@ TEST_P(GracefulRestartTest, GracefulRestart_Down_3) { for (size_t i = 0; i < xmpp_agents_.size()/2; i++) n_down_from_agents_.push_back(xmpp_agents_[i]); + for (size_t i = 0; i < bgp_peers_.size()/2; i++) + n_down_from_peers_.push_back(bgp_peers_[i]); GracefulRestartTestRun(); } @@ -978,7 +1449,14 @@ TEST_P(GracefulRestartTest, GracefulRestart_Down_4) { if (i <= xmpp_agents_.size()/2) n_down_from_agents_.push_back(xmpp_agents_[i]); else - n_flipped_agents_.push_back(AgentTestParams(xmpp_agents_[i])); + n_flipped_agents_.push_back(GRTestParams(xmpp_agents_[i])); + } + + for (size_t i = 0; i < bgp_peers_.size(); i++) { + if (i <= bgp_peers_.size()/2) + n_down_from_peers_.push_back(bgp_peers_[i]); + else + n_flipped_peers_.push_back(GRTestParams(bgp_peers_[i])); } GracefulRestartTestRun(); } @@ -989,7 +1467,10 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_1) { GracefulRestartTestStart(); BOOST_FOREACH(test::NetworkAgentMock *agent, xmpp_agents_) { - n_flipped_agents_.push_back(AgentTestParams(agent)); + n_flipped_agents_.push_back(GRTestParams(agent)); + } + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + n_flipped_peers_.push_back(GRTestParams(peer)); } GracefulRestartTestRun(); } @@ -1010,9 +1491,22 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_2) { // Trigger the case of compute-node hard reset where in tcp fin event // never reaches control-node - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); } + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + vector instance_ids = vector(); + vector nroutes = vector(); + for (int i = 1; i <= n_instances_; i++) { + instance_ids.push_back(i); + nroutes.push_back(n_routes_); + } + + // Trigger the case of compute-node hard reset where in tcp fin event + // never reaches control-node + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + } GracefulRestartTestRun(); } @@ -1029,9 +1523,19 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_3) { instance_ids.push_back(i); nroutes.push_back(0); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); } + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + vector instance_ids = vector(); + vector nroutes = vector(); + for (int i = 1; i <= n_instances_; i++) { + instance_ids.push_back(i); + nroutes.push_back(0); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + } GracefulRestartTestRun(); } @@ -1048,9 +1552,19 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_4) { instance_ids.push_back(i); nroutes.push_back(n_routes_/2); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); } + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + vector instance_ids = vector(); + vector nroutes = vector(); + for (int i = 1; i <= n_instances_; i++) { + instance_ids.push_back(i); + nroutes.push_back(n_routes_/2); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + } GracefulRestartTestRun(); } @@ -1070,10 +1584,24 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_5) { // Trigger the case of compute-node hard reset where in tcp fin event // never reaches control-node - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes, TcpSession::CLOSE)); } + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + vector instance_ids = vector(); + vector nroutes = vector(); + for (int i = 1; i <= n_instances_; i++) { + instance_ids.push_back(i); + nroutes.push_back(n_routes_); + } + + // Trigger the case of compute-node hard reset where in tcp fin event + // never reaches control-node + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes, + TcpSession::CLOSE)); + } GracefulRestartTestRun(); } @@ -1090,10 +1618,21 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_6) { instance_ids.push_back(i); nroutes.push_back(0); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes, TcpSession::CLOSE)); } + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + vector instance_ids = vector(); + vector nroutes = vector(); + for (int i = 1; i <= n_instances_; i++) { + instance_ids.push_back(i); + nroutes.push_back(0); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes, + TcpSession::CLOSE)); + } GracefulRestartTestRun(); } @@ -1110,10 +1649,21 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_7) { instance_ids.push_back(i); nroutes.push_back(n_routes_/2); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes, TcpSession::CLOSE)); } + + BOOST_FOREACH(BgpPeerTest *peer, bgp_peers_) { + vector instance_ids = vector(); + vector nroutes = vector(); + for (int i = 1; i <= n_instances_; i++) { + instance_ids.push_back(i); + nroutes.push_back(n_routes_/2); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes, + TcpSession::CLOSE)); + } GracefulRestartTestRun(); } @@ -1125,7 +1675,12 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_1) { for (size_t i = 0; i < xmpp_agents_.size()/2; i++) { test::NetworkAgentMock *agent = xmpp_agents_[i]; - n_flipped_agents_.push_back(AgentTestParams(agent)); + n_flipped_agents_.push_back(GRTestParams(agent)); + } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + n_flipped_peers_.push_back(GRTestParams(peer)); } GracefulRestartTestRun(); } @@ -1143,11 +1698,25 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_2) { instance_ids.push_back(j); nroutes.push_back(n_routes_); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // All flipped agents send EoR. n_flipped_agents_[i].send_eor = true; } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // All flipped peers send EoR. + n_flipped_peers_[i].send_eor = true; + } GracefulRestartTestRun(); } @@ -1164,11 +1733,25 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_2_2) { instance_ids.push_back(j); nroutes.push_back(n_routes_); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // None of the flipped agents sends EoR. n_flipped_agents_[i].send_eor = false; } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // None of the flipped peers sends EoR. + n_flipped_peers_[i].send_eor = false; + } GracefulRestartTestRun(); } @@ -1185,11 +1768,25 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_2_3) { instance_ids.push_back(j); nroutes.push_back(n_routes_); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // Only even flipped agents send EoR. n_flipped_agents_[i].send_eor = ((i%2) == 0); } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // Only even flipped peers send EoR. + n_flipped_peers_[i].send_eor = ((i%2) == 0); + } GracefulRestartTestRun(); } @@ -1206,11 +1803,25 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_3) { instance_ids.push_back(j); nroutes.push_back(0); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // All flipped agents send EoR. n_flipped_agents_[i].send_eor = true; } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(0); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // All flipped peers send EoR. + n_flipped_peers_[i].send_eor = true; + } GracefulRestartTestRun(); } @@ -1227,11 +1838,25 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_3_2) { instance_ids.push_back(j); nroutes.push_back(0); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // None of the flipped agents sends EoR. n_flipped_agents_[i].send_eor = false; } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(0); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // None of the flipped peers sends EoR. + n_flipped_peers_[i].send_eor = false; + } GracefulRestartTestRun(); } @@ -1248,11 +1873,25 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_3_3) { instance_ids.push_back(j); nroutes.push_back(0); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // Only even flipped agents send EoR. n_flipped_agents_[i].send_eor = ((i%2) == 0); } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(0); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // Only even flipped peers send EoR. + n_flipped_peers_[i].send_eor = ((i%2) == 0); + } GracefulRestartTestRun(); } @@ -1269,12 +1908,25 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_4) { instance_ids.push_back(j); nroutes.push_back(n_routes_/2); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, - nroutes)); + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // All flipped agents send EoR. n_flipped_agents_[i].send_eor = true; } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_/2); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // All flipped peers send EoR. + n_flipped_peers_[i].send_eor = true; + } GracefulRestartTestRun(); } @@ -1291,12 +1943,26 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_4_2) { instance_ids.push_back(j); nroutes.push_back(n_routes_/2); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // None of the flipped agents sends EoR. n_flipped_agents_[i].send_eor = false; } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_/2); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // None of the flipped peers sends EoR. + n_flipped_peers_[i].send_eor = false; + } GracefulRestartTestRun(); } @@ -1313,12 +1979,26 @@ TEST_P(GracefulRestartTest, GracefulRestart_Flap_Some_4_3) { instance_ids.push_back(j); nroutes.push_back(n_routes_/2); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); // Only even flipped agents send EoR. n_flipped_agents_[i].send_eor = ((i%2) == 0); } + + for (size_t i = 0; i < bgp_peers_.size()/2; i++) { + BgpPeerTest *peer = bgp_peers_[i]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_/2); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + + // Only even flipped peers send EoR. + n_flipped_peers_[i].send_eor = ((i%2) == 0); + } GracefulRestartTestRun(); } @@ -1356,6 +2036,19 @@ TEST_P(GracefulRestartTest, GracefulRestart_Delete_RoutingInstances_2) { continue; } } + + for (size_t i = 1; i <= bgp_peers_.size(); i++) { + + // peers from 2nd half remain up through out this test + if (i > bgp_peers_.size()/2) + continue; + + // peers from 1st quarter go down permantently + if (i <= bgp_peers_.size()/4) { + n_down_from_peers_.push_back(bgp_peers_[i-1]); + continue; + } + } GracefulRestartTestRun(); } @@ -1381,6 +2074,19 @@ TEST_P(GracefulRestartTest, GracefulRestart_Delete_RoutingInstances_3) { continue; } } + + for (size_t i = 1; i <= bgp_peers_.size(); i++) { + + // peers from 2nd half remain up through out this test + if (i > bgp_peers_.size()/2) + continue; + + // peers from 1st quarter go down permantently + if (i <= bgp_peers_.size()/4) { + n_down_from_peers_.push_back(bgp_peers_[i-1]); + continue; + } + } for (int i = n_instances_/4 + 1; i <= n_instances_/2; i++) instances_to_delete_during_gr_.push_back(i); GracefulRestartTestRun(); @@ -1417,9 +2123,32 @@ TEST_P(GracefulRestartTest, GracefulRestart_Delete_RoutingInstances_4) { instance_ids.push_back(j); nroutes.push_back(n_routes_); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); } + + for (size_t i = 1; i <= bgp_peers_.size(); i++) { + + // peers from 2nd half remain up through out this test + if (i > bgp_peers_.size()/2) + continue; + + // peers from 1st quarter go down permantently + if (i <= bgp_peers_.size()/4) { + n_down_from_peers_.push_back(bgp_peers_[i-1]); + continue; + } + + // peers from 2nd quarter flip with gr + BgpPeerTest *peer = bgp_peers_[i-1]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + } GracefulRestartTestRun(); } @@ -1455,9 +2184,32 @@ TEST_P(GracefulRestartTest, GracefulRestart_Delete_RoutingInstances_5) { instance_ids.push_back(j); nroutes.push_back(n_routes_); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); } + + for (size_t i = 1; i <= bgp_peers_.size(); i++) { + + // peers from 2nd half remain up through out this test + if (i > bgp_peers_.size()/2) + continue; + + // peers from 1st quarter go down permantently + if (i <= bgp_peers_.size()/4) { + n_down_from_peers_.push_back(bgp_peers_[i-1]); + continue; + } + + // peers from 2nd quarter flip with gr + BgpPeerTest *peer = bgp_peers_[i-1]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + } for (int i = n_instances_/4 + 1; i <= n_instances_/2; i++) instances_to_delete_during_gr_.push_back(i); GracefulRestartTestRun(); @@ -1495,9 +2247,32 @@ TEST_P(GracefulRestartTest, GracefulRestart_Delete_RoutingInstances_6) { instance_ids.push_back(j); nroutes.push_back(n_routes_/2); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); } + + for (size_t i = 1; i <= bgp_peers_.size(); i++) { + + // peers from 2nd half remain up through out this test + if (i > bgp_peers_.size()/2) + continue; + + // peers from 1st quarter go down permantently + if (i <= bgp_peers_.size()/4) { + n_down_from_peers_.push_back(bgp_peers_[i-1]); + continue; + } + + // peers from 2nd quarter flip with gr + BgpPeerTest *peer = bgp_peers_[i-1]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_/2); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + } GracefulRestartTestRun(); } @@ -1533,9 +2308,32 @@ TEST_P(GracefulRestartTest, GracefulRestart_Delete_RoutingInstances_7) { instance_ids.push_back(j); nroutes.push_back(n_routes_/2); } - n_flipped_agents_.push_back(AgentTestParams(agent, instance_ids, + n_flipped_agents_.push_back(GRTestParams(agent, instance_ids, nroutes)); } + + for (size_t i = 1; i <= bgp_peers_.size(); i++) { + + // peers from 2nd half remain up through out this test + if (i > bgp_peers_.size()/2) + continue; + + // peers from 1st quarter go down permantently + if (i <= bgp_peers_.size()/4) { + n_down_from_peers_.push_back(bgp_peers_[i-1]); + continue; + } + + // peers from 2nd quarter flip with gr + BgpPeerTest *peer = bgp_peers_[i-1]; + vector instance_ids = vector(); + vector nroutes = vector(); + for (int j = 1; j <= n_instances_; j++) { + instance_ids.push_back(j); + nroutes.push_back(n_routes_/2); + } + n_flipped_peers_.push_back(GRTestParams(peer, instance_ids, nroutes)); + } for (int i = n_instances_/4 + 1; i <= n_instances_/2; i++) instances_to_delete_during_gr_.push_back(i); GracefulRestartTestRun(); @@ -1545,8 +2343,9 @@ TEST_P(GracefulRestartTest, GracefulRestart_Delete_RoutingInstances_7) { Combine(ValuesIn(GetInstanceParameters()), \ ValuesIn(GetRouteParameters()), \ ValuesIn(GetAgentParameters()), \ - ValuesIn(GetTargetParameters()), \ - ValuesIn(xmpp_close_from_control_node)) + ValuesIn(GetPeerParameters()), \ + ValuesIn(GetTargetParameters())) \ + INSTANTIATE_TEST_CASE_P(GracefulRestartTestWithParams, GracefulRestartTest, COMBINE_PARAMS); @@ -1564,6 +2363,8 @@ static void SetUp() { boost::factory()); XmppObjectFactory::Register( boost::factory()); + BgpObjectFactory::Register( + boost::factory()); } static void TearDown() { diff --git a/src/bgp/test/static_route_test.cc b/src/bgp/test/static_route_test.cc index ab5dfe0a291..a228ecfbb46 100644 --- a/src/bgp/test/static_route_test.cc +++ b/src/bgp/test/static_route_test.cc @@ -1978,7 +1978,7 @@ TYPED_TEST(StaticRouteTest, MultipleVpnRoutes) { TASK_UTIL_EXPECT_TRUE(this->IsQueueEmpty("nat-2")); for (int i = 0; i < DB::PartitionCount(); i++) { DBPartition *partition = this->bgp_server_->database()->GetPartition(i); - TASK_UTIL_EXPECT_FALSE(partition->IsDBQueueEmpty()); + TASK_UTIL_EXPECT_TRUE(partition->IsDBQueueEmpty()); } // Check for Static route @@ -2025,7 +2025,7 @@ TYPED_TEST(StaticRouteTest, MultipleVpnRoutes) { TASK_UTIL_EXPECT_TRUE(this->IsQueueEmpty("nat-2")); for (int i = 0; i < DB::PartitionCount(); i++) { DBPartition *partition = this->bgp_server_->database()->GetPartition(i); - TASK_UTIL_EXPECT_FALSE(partition->IsDBQueueEmpty()); + TASK_UTIL_EXPECT_TRUE(partition->IsDBQueueEmpty()); } this->VerifyRouteNoExists("blue", this->BuildPrefix("192.168.1.0", 24)); diff --git a/src/bgp/xmpp_message_builder.cc b/src/bgp/xmpp_message_builder.cc index 336971da51a..7e14f7c6fec 100644 --- a/src/bgp/xmpp_message_builder.cc +++ b/src/bgp/xmpp_message_builder.cc @@ -311,7 +311,7 @@ void BgpXmppMessage::AddEnetReach(const BgpRoute *route, if (olist) { assert(olist->olist().subcode == BgpAttribute::OList); - BOOST_FOREACH(const BgpOListElem *elem, olist->elements) { + BOOST_FOREACH(const BgpOListElem *elem, olist->elements()) { autogen::EnetNextHopType nh; nh.af = BgpAf::IPv4; nh.address = elem->address.to_string(); @@ -326,7 +326,7 @@ void BgpXmppMessage::AddEnetReach(const BgpRoute *route, if (leaf_olist) { assert(leaf_olist->olist().subcode == BgpAttribute::LeafOList); - BOOST_FOREACH(const BgpOListElem *elem, leaf_olist->elements) { + BOOST_FOREACH(const BgpOListElem *elem, leaf_olist->elements()) { autogen::EnetNextHopType nh; nh.af = BgpAf::IPv4; nh.address = elem->address.to_string(); @@ -376,7 +376,7 @@ void BgpXmppMessage::AddMcastReach(const BgpRoute *route, const BgpOList *olist = roattr->attr()->olist().get(); assert(olist->olist().subcode == BgpAttribute::OList); - BOOST_FOREACH(const BgpOListElem *elem, olist->elements) { + BOOST_FOREACH(const BgpOListElem *elem, olist->elements()) { autogen::McastNextHopType nh; nh.af = BgpAf::IPv4; nh.address = elem->address.to_string(); diff --git a/src/control-node/main.cc b/src/control-node/main.cc index 2f9e182a33a..10408a44072 100644 --- a/src/control-node/main.cc +++ b/src/control-node/main.cc @@ -355,10 +355,10 @@ bool ControlNodeInfoLogger(BgpServer *server, change = true; } - uint32_t num_closing_xmpp = xmpp_channel_mgr->closing_count(); - if (num_closing_xmpp != prev_state.get_num_closing_xmpp_peer() || first) { - state.set_num_closing_xmpp_peer(num_closing_xmpp); - prev_state.set_num_closing_xmpp_peer(num_closing_xmpp); + uint32_t num_deleting_xmpp = xmpp_channel_mgr->deleting_count(); + if (num_deleting_xmpp != prev_state.get_num_deleting_xmpp_peer() || first) { + state.set_num_deleting_xmpp_peer(num_deleting_xmpp); + prev_state.set_num_deleting_xmpp_peer(num_deleting_xmpp); change = true; } @@ -376,11 +376,11 @@ bool ControlNodeInfoLogger(BgpServer *server, change = true; } - uint32_t num_closing_bgp_peer = server->num_closing_bgp_peer(); - if (num_closing_bgp_peer != prev_state.get_num_closing_bgp_peer() || + uint32_t num_deleting_bgp_peer = server->num_deleting_bgp_peer(); + if (num_deleting_bgp_peer != prev_state.get_num_deleting_bgp_peer() || first) { - state.set_num_closing_bgp_peer(num_closing_bgp_peer); - prev_state.set_num_closing_bgp_peer(num_closing_bgp_peer); + state.set_num_deleting_bgp_peer(num_deleting_bgp_peer); + prev_state.set_num_deleting_bgp_peer(num_deleting_bgp_peer); change = true; } diff --git a/src/control-node/sandesh/control_node.sandesh b/src/control-node/sandesh/control_node.sandesh index 9cca605b3e6..80cf7cf0c9f 100644 --- a/src/control-node/sandesh/control_node.sandesh +++ b/src/control-node/sandesh/control_node.sandesh @@ -24,10 +24,10 @@ struct BgpRouterState { 7: optional u32 output_queue_depth; 8: optional u32 num_bgp_peer; 9: optional u32 num_up_bgp_peer; - 20: optional u32 num_closing_bgp_peer; + 20: optional u32 num_deleting_bgp_peer; 10: optional u32 num_xmpp_peer; 11: optional u32 num_up_xmpp_peer; - 21: optional u32 num_closing_xmpp_peer; + 21: optional u32 num_deleting_xmpp_peer; 12: optional u32 num_routing_instance; 22: optional u32 num_deleted_routing_instance; 23: optional u32 num_service_chains; diff --git a/src/xmpp/xmpp_connection.cc b/src/xmpp/xmpp_connection.cc index 04c071a8087..a818ddfa9c2 100644 --- a/src/xmpp/xmpp_connection.cc +++ b/src/xmpp/xmpp_connection.cc @@ -176,6 +176,10 @@ void XmppConnection::SetFrom(const string &from) { } } +static void XMPPPeerInfoSend(XmppPeerInfoData &peer_info) { + XMPPPeerInfo::Send(peer_info); +} + void XmppConnection::SetTo(const string &to) { if ((to_.size() == 0) && (to.size() != 0)) { to_ = to; @@ -183,7 +187,7 @@ void XmppConnection::SetTo(const string &to) { XmppPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_identifier(to_); - XMPPPeerInfo::Send(peer_info); + XMPPPeerInfoSend(peer_info); } } @@ -633,7 +637,7 @@ class XmppServerConnection::DeleteActor : public LifetimeActor { XmppPeerInfoData peer_info; peer_info.set_name(parent_->ToUVEKey()); peer_info.set_deleted(true); - XMPPPeerInfo::Send(peer_info); + XMPPPeerInfoSend(peer_info); } XmppSession *session = NULL; @@ -716,7 +720,7 @@ void XmppServerConnection::set_close_reason(const string &close_reason) { XmppPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_close_reason(close_reason); - XMPPPeerInfo::Send(peer_info); + XMPPPeerInfoSend(peer_info); } uint32_t XmppServerConnection::flap_count() const { @@ -740,7 +744,7 @@ void XmppServerConnection::increment_flap_count() { flap_info.set_flap_count(conn_endpoint->flap_count()); flap_info.set_flap_time(conn_endpoint->last_flap()); peer_info.set_flap_info(flap_info); - XMPPPeerInfo::Send(peer_info); + XMPPPeerInfoSend(peer_info); } const std::string XmppServerConnection::last_flap_at() const { @@ -854,7 +858,7 @@ void XmppClientConnection::set_close_reason(const string &close_reason) { XmppPeerInfoData peer_info; peer_info.set_name(ToUVEKey()); peer_info.set_close_reason(close_reason_); - XMPPPeerInfo::Send(peer_info); + XMPPPeerInfoSend(peer_info); } uint32_t XmppClientConnection::flap_count() const { @@ -874,7 +878,7 @@ void XmppClientConnection::increment_flap_count() { flap_info.set_flap_count(flap_count_); flap_info.set_flap_time(last_flap_); peer_info.set_flap_info(flap_info); - XMPPPeerInfo::Send(peer_info); + XMPPPeerInfoSend(peer_info); } const std::string XmppClientConnection::last_flap_at() const {