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);
boost::asio::ip::address_v4 Ip4Address
#define XMPP_HOLD_TIME_DEFAULT
#define BGP_LOG_FLAG_SYSLOG
#define BGP_LOG_WARNING_STR(obj, flags, arg)
#define BGP_LOG_NOTICE_STR(obj, flags, arg)
#define BGP_UVE_SEND2(type, object, arg)
#define BGP_UVE_SEND(type, object)
#define BGP_LOG_STR(obj, level, flags, arg)
void RegisterObservers(const Observers &obs)
static const char * kMasterInstance
virtual void Terminate()=0
uint8_t analytics_dscp() const
void set_control_dscp(uint8_t value)
uint8_t control_dscp() const
void set_analytics_dscp(uint8_t value)
bool all_tags_are_global() const
void set_xmpp_hold_time(uint8_t hold_time)
void set_all_tags_are_global(bool all_tags_are_global)
void set_end_of_rib_timeout(uint16_t time)
uint16_t bgpaas_port_start() const
uint16_t end_of_rib_timeout() const
uint16_t bgpaas_port_end() const
void set_rd_cluster_seed(uint16_t seed)
bool gr_bgp_helper() const
void set_always_compare_med(bool always_compare_med)
uint16_t rd_cluster_seed() const
uint32_t llgr_time() const
bool enable_4byte_as() const
void set_gr_time(uint16_t gr_time)
void set_fc_enabled(bool enable)
void set_llgr_time(uint64_t llgr_time)
bool always_compare_med() const
void set_gr_bgp_helper(bool helper)
void set_nh_check_enabled(bool enable)
void set_bgpaas_port_end(uint16_t bgpaas_port_end)
void set_bgpaas_port_start(uint16_t bgpaas_port_start)
uint8_t xmpp_hold_time() const
bool nh_check_enabled() const
void set_gr_enable(bool enable)
void set_enable_4byte_as(bool as_4byte)
const std::string & name() const
const std::string & instance_name() const
const std::string & name() const
virtual const std::string & ToUVEKey() const
bool IsRouterTypeBGPaaS() const
TcpSession::Endpoint endpoint() const
const std::string & peer_name() const
uint64_t flap_count() const
virtual IPeerDebugStats * peer_stats()
uint64_t last_flap() const
void ConfigUpdate(const BgpNeighborConfig *config)
uint32_t local_autonomous_system() const
uint32_t hold_time() const
uint32_t cluster_id() const
uint32_t autonomous_system() const
const std::string & instance_name() const
uint32_t identifier() const
const std::string & name() const
void ProcessProtocolConfig(const BgpProtocolConfig *protocol_config, BgpConfigManager::EventType event)
void ProcessRoutingPolicyConfig(const BgpRoutingPolicyConfig *policy_config, BgpConfigManager::EventType event)
void BgpServerConfigUpdate(string instance_name, const BgpProtocolConfig *config)
void ProcessInstanceConfig(const BgpInstanceConfig *instance_config, BgpConfigManager::EventType event)
void ProcessGlobalQosConfig(const BgpGlobalQosConfig *qos, BgpConfigManager::EventType event)
ConfigUpdater(BgpServer *server)
void ProcessNeighborConfig(const BgpNeighborConfig *neighbor_config, BgpConfigManager::EventType event)
void ProcessGlobalSystemConfig(const BgpGlobalSystemConfig *new_config, BgpConfigManager::EventType event)
DeleteActor(BgpServer *server)
virtual bool MayDelete() const
uint32_t num_deleting_bgp_peer() const
std::string bgp_identifier_string() const
tbb::atomic< uint32_t > num_up_bgpaas_peer_
DSCPUpdateListenersList dscp_listeners_
uint32_t cluster_id() const
uint32_t GetStaticRouteCount() const
as_t local_autonomous_system_
bool CollectStats(BgpRouterState *state, bool first) const
void RemovePeer(TcpSession::Endpoint remote, BgpPeer *peer)
boost::asio::io_context * ioservice()
uint32_t bgp_identifier_u32_
uint32_t num_service_chains() const
BgpServer(EventManager *evm)
BgpSessionManager * session_mgr_
uint32_t num_bgp_peer() const
uint32_t num_static_routes() const
boost::scoped_ptr< IServiceChainMgr > evpn_service_chain_mgr_
uint32_t GetDownStaticRouteCount() const
bool enable_4byte_as() const
uint32_t GetEndOfRibSendTime() const
LifetimeActor * deleter()
BgpPeer * FindExactPeer(const BgpPeer *peer) const
BgpPeer * FindNextPeer(const std::string &name=std::string())
tbb::spin_rw_mutex rw_mutex_
void VisitBgpPeers(BgpServer::VisitorFn) const
void UnregisterAdminDownCallback(int listener)
boost::dynamic_bitset admin_down_bmap_
void UnregisterPeer(BgpPeer *peer)
RoutingInstanceMgr * routing_instance_mgr()
Ip4Address bgp_identifier_
uint32_t num_down_static_routes() const
boost::function< void(BgpPeer *)> VisitorFn
bool HasSelfConfiguration() const
tbb::atomic< uint32_t > deleting_bgpaas_count_
int RegisterIdentifierUpdateCallback(IdentifierUpdateCb callback)
tbb::atomic< uint32_t > bgp_count_
uint32_t GetEndOfRibReceiveTime() const
boost::scoped_ptr< IServiceChainMgr > evpn6_service_chain_mgr_
tbb::atomic< uint64_t > message_build_error_
uint32_t num_down_service_chains() const
boost::scoped_ptr< BgpConfigManager > config_mgr_
IdentifierUpdateListenersList id_listeners_
uint32_t num_deleting_bgpaas_peer() const
void NotifyASNUpdate(as_t old_asn, as_t old_local_asn)
int RegisterPeer(BgpPeer *peer)
bool IsFastConvergenceEnabled() const
boost::dynamic_bitset dscp_bmap_
BgpConfigManager * config_manager()
BgpGlobalQosConfig * global_qos()
StaticRouteMgrList srt_manager_list_
boost::function< void(Ip4Address)> IdentifierUpdateCb
uint16_t GetGracefulRestartTime() const
void UnregisterASNUpdateCallback(int listener)
int RegisterAdminDownCallback(AdminDownCb callback)
ASNUpdateListenersList asn_listeners_
uint32_t NumUpPeer() const
void UnregisterDSCPUpdateCallback(int listener)
as_t autonomous_system() const
void UpdateBgpIdentifier(const Ip4Address &identifier)
boost::scoped_ptr< BgpMembershipManager > membership_mgr_
virtual std::string ToString() const
boost::dynamic_bitset asn_bmap_
void set_cluster_id(uint32_t id)
void InsertStaticRouteMgr(IStaticRouteMgr *srt_manager)
BgpPeer * FindPeer(const std::string &name)
tbb::atomic< uint32_t > bgpaas_count_
boost::scoped_ptr< RTargetGroupMgr > rtarget_group_mgr_
uint32_t num_deleted_routing_instance() const
tbb::atomic< uint32_t > num_up_peer_
boost::scoped_ptr< BgpGlobalSystemConfig > global_config_
boost::function< void(uint8_t)> DSCPUpdateCb
void NotifyDSCPUpdate(int new_dscp_value)
bool IsNextHopCheckEnabled() const
uint32_t bgp_identifier_u32() const
int RegisterDSCPUpdateCallback(DSCPUpdateCb cb)
uint16_t GetXmppHoldTime() const
uint32_t num_routing_instance() const
tbb::atomic< uint32_t > deleting_count_
bool IsServerStartingUp() const
boost::function< void()> AdminDownCb
uint32_t get_output_queue_depth() const
void InsertPeer(TcpSession::Endpoint remote, BgpPeer *peer)
as_t local_autonomous_system() const
boost::scoped_ptr< IServiceChainMgr > inet_service_chain_mgr_
void NotifyIdentifierUpdate(Ip4Address old_identifier)
boost::scoped_ptr< DeleteActor > deleter_
void set_enable_4byte_as(bool flag)
void UnregisterIdentifierUpdateCallback(int listener)
void NotifyAllStaticRoutes()
boost::scoped_ptr< RoutingInstanceMgr > inst_mgr_
const std::string & localname() const
boost::function< void(as_t, as_t)> ASNUpdateCb
time_t GetRTargetTableLastUpdatedTimeStamp() const
BgpSessionManager * session_manager()
int RegisterASNUpdateCallback(ASNUpdateCb callback)
BgpGlobalSystemConfig * global_config()
RoutingPolicyMgr * routing_policy_mgr()
EndpointPeerList endpoint_peer_list_
uint32_t NumUpBgpaasPeer() const
boost::dynamic_bitset peer_bmap_
bool IsReadyForDeletion()
LifetimeManager * lifetime_manager()
bool IsGRHelperModeEnabled() const
AdminDownListenersList admin_down_listeners_
boost::dynamic_bitset id_bmap_
uint32_t num_bgpaas_peer() const
uint32_t GetLongLivedGracefulRestartTime() const
void RemoveStaticRouteMgr(IStaticRouteMgr *srt_manager)
boost::scoped_ptr< IServiceChainMgr > inet6_service_chain_mgr_
void FillPeerStats(const BgpPeer *peer) const
virtual bool Initialize(unsigned short port)
size_t GetPendingRiboutsCount(size_t *markers) const
bool IsDBQueueEmpty() const
boost::asio::io_context * io_service()
virtual uint32_t GetRouteCount() const =0
virtual uint32_t GetDownRouteCount() const =0
virtual void NotifyAllRoutes()=0
static time_t GetUpTimeSeconds()
void ClearAllInternalPeers()
virtual BgpPeer * PeerLocate(BgpServer *server, const BgpNeighborConfig *config)
const BgpPeer * NextPeer(const BgpPeerKey &key) const
BgpPeer * TriggerPeerDeletion(const BgpNeighborConfig *config)
static void FillPeerUpdateStats(const IPeerDebugStats *peer_stats, PeerStatsData *peer_stats_data)
static void FillPeerDebugStats(const IPeerDebugStats *peer_stats, PeerStatsInfo *stats)
time_t last_updated() const
RoutingInstanceList::iterator RoutingInstanceIterator
RoutingInstance * GetRoutingInstance(const std::string &name)
RoutingInstance * GetDefaultRoutingInstance()
virtual void DeleteRoutingInstance(const std::string &name)
void LocateRoutingInstance(const BgpInstanceConfig *config)
std::map< std::string, BgpTable * > RouteTableList
PeerManager * peer_manager()
PeerManager * LocatePeerManager()
BgpTable * GetTable(Address::Family fmly)
void UpdateRoutingPolicy(const BgpRoutingPolicyConfig *config)
virtual RoutingPolicy * CreateRoutingPolicy(const BgpRoutingPolicyConfig *config)
virtual void DeleteRoutingPolicy(const std::string &name)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
bool IsTaskGroupEmpty(int task_id) const
Check if there are any Tasks in the given TaskGroup. Assumes that all task ids are mutually exclusive...
int GetTaskId(const std::string &name)
static TaskScheduler * GetInstance()
static void DeleteServer(TcpServer *server)
EventManager * event_manager()
boost::asio::ip::tcp::endpoint Endpoint
BgpRoutingPolicyObserver policy
BgpNeighborObserver neighbor
BgpGlobalSystemConfigObserver system
BgpGlobalQosConfigObserver qos
BgpProtocolObserver protocol
BgpInstanceObserver instance
#define CHECK_CONCURRENCY(...)