7 #include <sys/resource.h>
9 #include <boost/foreach.hpp>
10 #include <boost/tuple/tuple.hpp>
34 #include "config-client-mgr/config_client_show_types.h"
35 #include "control-node/sandesh/control_node_types.h"
37 using boost::system::error_code;
43 using std::noboolalpha;
79 bool clear_peers =
false;
155 bool clear_bgpaas_peers =
false;
162 clear_bgpaas_peers =
true;
170 clear_bgpaas_peers =
true;
181 if (clear_peers || clear_bgpaas_peers)
187 const string &instance_name = protocol_config->
instance_name();
206 boost::system::error_code ec;
207 uint32_t config_identifier = 0;
208 uint32_t config_autonomous_system = 0;
209 uint32_t config_local_autonomous_system = 0;
210 uint32_t config_hold_time = 0;
211 uint32_t config_cluster_id = 0;
212 bool config_admin_down =
false;
228 boolalpha << config_admin_down << noboolalpha);
231 "Updated Admin Down from " <<
234 boolalpha << config_admin_down << noboolalpha);
246 rlimit new_core_limit;
247 new_core_limit.rlim_cur = 0;
248 new_core_limit.rlim_max = 0;
249 setrlimit(RLIMIT_CORE, &new_core_limit);
251 "Process exit! due to tcp server port " << config->
port() <<
254 kill(getpid(), SIGTERM);
257 Ip4Address identifier(ntohl(config_identifier));
261 "Updated Router ID from " <<
263 identifier.to_string());
268 identifier.to_string());
273 bool notify_asn_update =
false;
277 if (config_local_autonomous_system) {
286 "Updated Autonomous System from " << old_asn <<
291 "Updated Autonomous System from " << old_asn <<
294 notify_asn_update =
true;
298 if (old_local_asn != 0) {
300 "Updated Local Autonomous System from " <<
301 old_local_asn <<
" to " <<
306 "Updated Local Autonomous System from " <<
307 old_local_asn <<
" to " <<
310 notify_asn_update =
true;
313 if (notify_asn_update) {
319 "Updated Hold Time from " <<
326 "Updated Cluster Id from " <<
336 ConnectionState::GetInstance()->Update();
436 static int db_table_task_id = scheduler->
GetTaskId(
"db::DBTable");
437 static int resolver_path_task_id =
438 scheduler->
GetTaskId(
"bgp::ResolverPath");
439 static int resolver_nexthop_task_id =
440 scheduler->
GetTaskId(
"bgp::ResolverNexthop");
486 : admin_down_(false),
488 autonomous_system_(0),
489 local_autonomous_system_(0),
491 bgp_identifier_u32_(0),
493 gr_helper_disable_(false),
498 logging_disabled_(false),
499 mvpn_ipv4_enable_(false),
500 ignore_aspath_(false),
528 inet_service_chain_mgr_(
530 inet6_service_chain_mgr_(
532 evpn_service_chain_mgr_(
534 evpn6_service_chain_mgr_(
594 BgpPeerList::iterator loc;
598 assert(loc->second == peer);
625 for (
size_t i =
peer_bmap_.size(); i != 0; i--) {
637 BgpPeerList::iterator loc =
peer_list_.find(name);
638 return (loc !=
peer_list_.end() ? loc->second : NULL);
642 BgpPeerList::iterator loc =
peer_list_.upper_bound(name);
643 return (loc !=
peer_list_.end() ? loc->second : NULL);
647 if (!remote.port() && remote.address().is_unspecified())
655 if (loc->second == peer) {
675 EndpointPeerList::const_iterator loc =
678 if (loc->second == peer)
766 uint32_t out_q_depth = 0;
770 rit->second->GetTables();
771 for (RoutingInstance::RouteTableList::const_iterator it =
772 rt_list.begin(); it != rt_list.end(); ++it) {
812 for (BgpPeerList::const_iterator loc =
peer_list_.begin();
819 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
835 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
854 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
865 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
881 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
891 if ((
size_t) listener >=
asn_bmap_.size()) {
899 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
900 for (ASNUpdateListenersList::iterator iter =
asn_listeners_.begin();
904 (cb)(old_asn, old_local_asn);
910 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
926 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
944 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
949 (cb)(new_dscp_value);
955 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
971 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
981 if ((
size_t) listener >=
id_bmap_.size()) {
989 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
990 for (IdentifierUpdateListenersList::iterator iter =
id_listeners_.begin();
994 (cb)(old_identifier);
1001 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
1007 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
1013 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
1044 PeerStatsInfo stats;
1047 BgpPeerInfoData peer_info;
1048 peer_info.set_name(peer->
ToUVEKey());
1049 peer_info.set_peer_stats_info(stats);
1050 assert(!peer_info.get_name().empty());
1053 PeerStatsData peer_stats_data;
1054 peer_stats_data.set_name(peer->
ToUVEKey());
1055 peer_stats_data.set_encoding(
"BGP");
1057 assert(!peer_stats_data.get_name().empty());
1058 BGP_UVE_SEND2(PeerStatsUve, peer_stats_data,
"ObjectBgpPeer");
1060 PeerFlapInfo flap_info;
1061 flap_info.set_flap_count(peer->
flap_count());
1062 flap_info.set_flap_time(peer->
last_flap());
1064 PeerFlapData peer_flap_data;
1065 peer_flap_data.set_name(peer->
ToUVEKey());
1066 peer_flap_data.set_encoding(
"BGP");
1067 peer_flap_data.set_flap_info(flap_info);
1068 assert(!peer_flap_data.get_name().empty());
1076 bool change =
false;
1078 if (first || is_admin_down != state->get_admin_down()) {
1079 state->set_admin_down(is_admin_down);
1084 if (first || router_id != state->get_router_id()) {
1085 state->set_router_id(router_id);
1090 if (first || local_asn != state->get_local_asn()) {
1091 state->set_local_asn(local_asn);
1096 if (first || global_asn != state->get_global_asn()) {
1097 state->set_global_asn(global_asn);
1102 if (first || num_bgp != state->get_num_bgp_peer()) {
1103 state->set_num_bgp_peer(num_bgp);
1108 if (first || num_up_bgp_peer != state->get_num_up_bgp_peer()) {
1109 state->set_num_up_bgp_peer(num_up_bgp_peer);
1114 if (first || deleting_bgp_peer != state->get_num_deleting_bgp_peer()) {
1115 state->set_num_deleting_bgp_peer(deleting_bgp_peer);
1120 if (first || num_bgpaas != state->get_num_bgpaas_peer()) {
1121 state->set_num_bgpaas_peer(num_bgpaas);
1126 if (first || num_up_bgpaas_peer != state->get_num_up_bgpaas_peer()) {
1127 state->set_num_up_bgpaas_peer(num_up_bgpaas_peer);
1132 if (first || deleting_bgpaas_peer !=
1133 state->get_num_deleting_bgpaas_peer()) {
1134 state->set_num_deleting_bgpaas_peer(deleting_bgpaas_peer);
1139 if (first || num_ri != state->get_num_routing_instance()) {
1140 state->set_num_routing_instance(num_ri);
1145 if (first || num_deleted_ri != state->get_num_deleted_routing_instance()) {
1146 state->set_num_deleted_routing_instance(num_deleted_ri);
1151 if (first || service_chains != state->get_num_service_chains()) {
1152 state->set_num_service_chains(service_chains);
1157 if (first || down_service_chains != state->get_num_down_service_chains()) {
1158 state->set_num_down_service_chains(down_service_chains);
1163 if (first || static_routes != state->get_num_static_routes()) {
1164 state->set_num_static_routes(static_routes);
1169 if (first || down_static_routes != state->get_num_down_static_routes()) {
1170 state->set_num_down_static_routes(down_static_routes);
1174 uint32_t out_load =
inst_mgr_->SendTableStatsUve();
1175 if (first || out_load != state->get_output_queue_depth()) {
1176 state->set_output_queue_depth(out_load);
1180 vector<string> bgp_config_peer_list;
1181 BOOST_FOREACH(BgpConfigManager::NeighborMap::value_type value,
1188 name += neighbor->
name();
1189 bgp_config_peer_list.push_back(name);
1191 sort(bgp_config_peer_list.begin(), bgp_config_peer_list.end());
1192 if (first || bgp_config_peer_list != state->get_bgp_config_peer_list()) {
1193 state->set_bgp_config_peer_list(bgp_config_peer_list);
1197 vector<string> bgp_oper_peer_list;
1201 peer != NULL; peer = peer_manager->
NextPeer(peer->peer_key())) {
1202 bgp_oper_peer_list.push_back(peer->ToUVEKey());
1204 sort(bgp_oper_peer_list.begin(), bgp_oper_peer_list.end());
1205 if (first || bgp_oper_peer_list != state->get_bgp_oper_peer_list()) {
1206 state->set_bgp_oper_peer_list(bgp_oper_peer_list);
void ProcessInstanceConfig(const BgpInstanceConfig *instance_config, BgpConfigManager::EventType event)
bool IsNextHopCheckEnabled() const
ConfigUpdater(BgpServer *server)
BgpGlobalSystemConfigObserver system
time_t last_updated() const
LifetimeActor * deleter()
boost::dynamic_bitset dscp_bmap_
boost::asio::ip::tcp::endpoint Endpoint
void ClearAllInternalPeers()
bool nh_check_enabled() const
uint64_t flap_count() const
boost::scoped_ptr< RTargetGroupMgr > rtarget_group_mgr_
BgpTable * GetTable(Address::Family fmly)
void UnregisterAdminDownCallback(int listener)
boost::dynamic_bitset id_bmap_
boost::scoped_ptr< BgpConfigManager > config_mgr_
uint32_t hold_time() const
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
PeerManager * peer_manager()
boost::dynamic_bitset peer_bmap_
RoutingInstance * GetRoutingInstance(const std::string &name)
uint32_t NumUpPeer() const
tbb::spin_rw_mutex rw_mutex_
uint8_t control_dscp() const
BgpServer(EventManager *evm)
AdminDownListenersList admin_down_listeners_
bool IsServerStartingUp() const
const std::string & name() const
as_t local_autonomous_system_
void set_gr_time(uint16_t gr_time)
BgpInstanceObserver instance
uint32_t bgp_identifier_u32() const
void UnregisterASNUpdateCallback(int listener)
uint32_t num_static_routes() const
const std::string & instance_name() const
uint32_t autonomous_system() const
boost::function< void(as_t, as_t)> ASNUpdateCb
BgpPeer * TriggerPeerDeletion(const BgpNeighborConfig *config)
bool gr_bgp_helper() const
void ProcessGlobalSystemConfig(const BgpGlobalSystemConfig *new_config, BgpConfigManager::EventType event)
tbb::atomic< uint32_t > deleting_bgpaas_count_
bool IsDBQueueEmpty() const
uint32_t num_deleting_bgp_peer() const
boost::scoped_ptr< IServiceChainMgr > evpn6_service_chain_mgr_
void set_always_compare_med(bool always_compare_med)
uint32_t NumUpBgpaasPeer() const
static const char * kMasterInstance
void InsertStaticRouteMgr(IStaticRouteMgr *srt_manager)
void VisitBgpPeers(BgpServer::VisitorFn) const
ASNUpdateListenersList asn_listeners_
bool IsReadyForDeletion()
void ProcessNeighborConfig(const BgpNeighborConfig *neighbor_config, BgpConfigManager::EventType event)
BgpGlobalSystemConfig * global_config()
void RegisterObservers(const Observers &obs)
uint16_t rd_cluster_seed() const
virtual void DeleteRoutingInstance(const std::string &name)
uint32_t GetLongLivedGracefulRestartTime() const
void NotifyASNUpdate(as_t old_asn, as_t old_local_asn)
BgpGlobalQosConfig * global_qos()
virtual void DeleteRoutingPolicy(const std::string &name)
boost::asio::io_context * io_service()
tbb::atomic< uint32_t > num_up_bgpaas_peer_
RoutingInstanceMgr * routing_instance_mgr()
virtual uint32_t GetRouteCount() const =0
Ip4Address bgp_identifier_
#define BGP_UVE_SEND(type, object)
time_t GetRTargetTableLastUpdatedTimeStamp() const
uint32_t get_output_queue_depth() const
bool IsRouterTypeBGPaaS() const
BgpPeer * FindExactPeer(const BgpPeer *peer) const
RoutingInstance * GetDefaultRoutingInstance()
EventManager * event_manager()
bool IsFastConvergenceEnabled() const
BgpPeer * FindPeer(const std::string &name)
static time_t GetUpTimeSeconds()
BgpProtocolObserver protocol
uint32_t local_autonomous_system() const
void ProcessRoutingPolicyConfig(const BgpRoutingPolicyConfig *policy_config, BgpConfigManager::EventType event)
boost::scoped_ptr< BgpGlobalSystemConfig > global_config_
int RegisterDSCPUpdateCallback(DSCPUpdateCb cb)
bool IsGRHelperModeEnabled() const
tbb::atomic< uint64_t > message_build_error_
void NotifyAllStaticRoutes()
DeleteActor(BgpServer *server)
int GetTaskId(const std::string &name)
#define BGP_LOG_STR(obj, level, flags, arg)
void FillPeerStats(const BgpPeer *peer) const
void ConfigUpdate(const BgpNeighborConfig *config)
uint32_t num_routing_instance() const
as_t local_autonomous_system() const
tbb::atomic< uint32_t > deleting_count_
static void FillPeerUpdateStats(const IPeerDebugStats *peer_stats, PeerStatsData *peer_stats_data)
const BgpPeer * NextPeer(const BgpPeerKey &key) const
uint32_t GetDownStaticRouteCount() const
RoutingPolicyMgr * routing_policy_mgr()
boost::function< void(uint8_t)> DSCPUpdateCb
const std::string & name() const
bool always_compare_med() const
std::string bgp_identifier_string() const
uint32_t GetEndOfRibReceiveTime() const
#define XMPP_HOLD_TIME_DEFAULT
int RegisterIdentifierUpdateCallback(IdentifierUpdateCb callback)
boost::scoped_ptr< IServiceChainMgr > evpn_service_chain_mgr_
IdentifierUpdateListenersList id_listeners_
#define BGP_LOG_FLAG_SYSLOG
tbb::atomic< uint32_t > num_up_peer_
uint32_t identifier() const
void BgpServerConfigUpdate(string instance_name, const BgpProtocolConfig *config)
const std::string & peer_name() const
static TaskScheduler * GetInstance()
boost::function< void(Ip4Address)> IdentifierUpdateCb
BgpConfigManager * config_manager()
boost::dynamic_bitset admin_down_bmap_
virtual IPeerDebugStats * peer_stats()
BgpSessionManager * session_mgr_
void ProcessProtocolConfig(const BgpProtocolConfig *protocol_config, BgpConfigManager::EventType event)
uint32_t bgp_identifier_u32_
void NotifyDSCPUpdate(int new_dscp_value)
bool all_tags_are_global() const
BgpGlobalQosConfigObserver qos
virtual bool Initialize(unsigned short port)
StaticRouteMgrList srt_manager_list_
int RegisterASNUpdateCallback(ASNUpdateCb callback)
boost::scoped_ptr< DeleteActor > deleter_
#define CHECK_CONCURRENCY(...)
virtual void NotifyAllRoutes()=0
void set_analytics_dscp(uint8_t value)
void RemovePeer(TcpSession::Endpoint remote, BgpPeer *peer)
int RegisterPeer(BgpPeer *peer)
bool CollectStats(BgpRouterState *state, bool first) const
BgpNeighborObserver neighbor
uint16_t GetXmppHoldTime() const
uint32_t num_deleting_bgpaas_peer() const
BgpSessionManager * session_manager()
boost::scoped_ptr< IServiceChainMgr > inet6_service_chain_mgr_
uint16_t end_of_rib_timeout() const
static void DeleteServer(TcpServer *server)
void set_enable_4byte_as(bool as_4byte)
boost::scoped_ptr< BgpMembershipManager > membership_mgr_
tbb::atomic< uint32_t > bgp_count_
#define BGP_LOG_WARNING_STR(obj, flags, arg)
void UpdateBgpIdentifier(const Ip4Address &identifier)
uint32_t num_service_chains() const
uint32_t num_deleted_routing_instance() const
void UpdateRoutingPolicy(const BgpRoutingPolicyConfig *config)
LifetimeManager * lifetime_manager()
uint32_t num_down_service_chains() const
tbb::atomic< uint32_t > bgpaas_count_
void LocateRoutingInstance(const BgpInstanceConfig *config)
virtual const std::string & ToUVEKey() const
boost::function< void()> AdminDownCb
boost::asio::ip::address_v4 Ip4Address
void InsertPeer(TcpSession::Endpoint remote, BgpPeer *peer)
uint16_t bgpaas_port_start() const
std::map< std::string, BgpTable * > RouteTableList
size_t GetPendingRiboutsCount(size_t *markers) const
bool HasSelfConfiguration() const
void UnregisterDSCPUpdateCallback(int listener)
void NotifyIdentifierUpdate(Ip4Address old_identifier)
void set_llgr_time(uint64_t llgr_time)
uint8_t analytics_dscp() const
static void FillPeerDebugStats(const IPeerDebugStats *peer_stats, PeerStatsInfo *stats)
boost::asio::io_context * ioservice()
#define BGP_UVE_SEND2(type, object, arg)
virtual RoutingPolicy * CreateRoutingPolicy(const BgpRoutingPolicyConfig *config)
uint32_t GetEndOfRibSendTime() const
int RegisterAdminDownCallback(AdminDownCb callback)
uint32_t num_down_static_routes() const
uint8_t xmpp_hold_time() const
void set_fc_enabled(bool enable)
uint16_t bgpaas_port_end() const
void set_rd_cluster_seed(uint16_t seed)
void set_gr_bgp_helper(bool helper)
void UnregisterPeer(BgpPeer *peer)
void ProcessGlobalQosConfig(const BgpGlobalQosConfig *qos, BgpConfigManager::EventType event)
BgpRoutingPolicyObserver policy
boost::scoped_ptr< IServiceChainMgr > inet_service_chain_mgr_
void set_bgpaas_port_start(uint16_t bgpaas_port_start)
virtual uint32_t GetDownRouteCount() const =0
uint32_t GetStaticRouteCount() const
void set_enable_4byte_as(bool flag)
void set_gr_enable(bool enable)
bool enable_4byte_as() const
EndpointPeerList endpoint_peer_list_
void set_all_tags_are_global(bool all_tags_are_global)
BgpPeer * FindNextPeer(const std::string &name=std::string())
bool enable_4byte_as() const
uint32_t num_bgp_peer() const
virtual std::string ToString() const
virtual bool MayDelete() const
void set_xmpp_hold_time(uint8_t hold_time)
uint32_t num_bgpaas_peer() const
uint32_t cluster_id() const
uint16_t GetGracefulRestartTime() const
virtual BgpPeer * PeerLocate(BgpServer *server, const BgpNeighborConfig *config)
uint64_t last_flap() const
bool IsTaskGroupEmpty(int task_id) const
Check if there are any Tasks in the given TaskGroup. Assumes that all task ids are mutually exclusive...
const std::string & instance_name() const
const std::string & name() const
#define BGP_LOG_NOTICE_STR(obj, flags, arg)
uint32_t llgr_time() const
as_t autonomous_system() const
PeerManager * LocatePeerManager()
TcpSession::Endpoint endpoint() const
DSCPUpdateListenersList dscp_listeners_
void set_end_of_rib_timeout(uint16_t time)
void UnregisterIdentifierUpdateCallback(int listener)
boost::dynamic_bitset asn_bmap_
void set_cluster_id(uint32_t id)
RoutingInstanceList::iterator RoutingInstanceIterator
boost::function< void(BgpPeer *)> VisitorFn
boost::scoped_ptr< RoutingInstanceMgr > inst_mgr_
void set_bgpaas_port_end(uint16_t bgpaas_port_end)
uint32_t cluster_id() const
void RemoveStaticRouteMgr(IStaticRouteMgr *srt_manager)
virtual void Terminate()=0
void set_nh_check_enabled(bool enable)
const std::string & localname() const
void set_control_dscp(uint8_t value)