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;
148 bool clear_bgpaas_peers =
false;
155 clear_bgpaas_peers =
true;
163 clear_bgpaas_peers =
true;
174 if (clear_peers || clear_bgpaas_peers)
180 const string &instance_name = protocol_config->
instance_name();
199 boost::system::error_code ec;
200 uint32_t config_identifier = 0;
201 uint32_t config_autonomous_system = 0;
202 uint32_t config_local_autonomous_system = 0;
203 uint32_t config_hold_time = 0;
204 uint32_t config_cluster_id = 0;
205 bool config_admin_down =
false;
221 boolalpha << config_admin_down << noboolalpha);
224 "Updated Admin Down from " <<
227 boolalpha << config_admin_down << noboolalpha);
239 rlimit new_core_limit;
240 new_core_limit.rlim_cur = 0;
241 new_core_limit.rlim_max = 0;
242 setrlimit(RLIMIT_CORE, &new_core_limit);
244 "Process exit! due to tcp server port " << config->
port() <<
247 kill(getpid(), SIGTERM);
250 Ip4Address identifier(ntohl(config_identifier));
254 "Updated Router ID from " <<
256 identifier.to_string());
261 identifier.to_string());
266 bool notify_asn_update =
false;
270 if (config_local_autonomous_system) {
279 "Updated Autonomous System from " << old_asn <<
284 "Updated Autonomous System from " << old_asn <<
287 notify_asn_update =
true;
291 if (old_local_asn != 0) {
293 "Updated Local Autonomous System from " <<
294 old_local_asn <<
" to " <<
299 "Updated Local Autonomous System from " <<
300 old_local_asn <<
" to " <<
303 notify_asn_update =
true;
306 if (notify_asn_update) {
312 "Updated Hold Time from " <<
319 "Updated Cluster Id from " <<
329 ConnectionState::GetInstance()->Update();
429 static int db_table_task_id = scheduler->
GetTaskId(
"db::DBTable");
430 static int resolver_path_task_id =
431 scheduler->
GetTaskId(
"bgp::ResolverPath");
432 static int resolver_nexthop_task_id =
433 scheduler->
GetTaskId(
"bgp::ResolverNexthop");
479 : admin_down_(false),
481 autonomous_system_(0),
482 local_autonomous_system_(0),
484 bgp_identifier_u32_(0),
486 gr_helper_disable_(false),
491 logging_disabled_(false),
492 mvpn_ipv4_enable_(false),
493 ignore_aspath_(false),
521 inet_service_chain_mgr_(
523 inet6_service_chain_mgr_(
525 evpn_service_chain_mgr_(
527 evpn6_service_chain_mgr_(
587 BgpPeerList::iterator loc;
591 assert(loc->second == peer);
618 for (
size_t i =
peer_bmap_.size(); i != 0; i--) {
630 BgpPeerList::iterator loc =
peer_list_.find(name);
631 return (loc !=
peer_list_.end() ? loc->second : NULL);
635 BgpPeerList::iterator loc =
peer_list_.upper_bound(name);
636 return (loc !=
peer_list_.end() ? loc->second : NULL);
640 if (!remote.port() && remote.address().is_unspecified())
648 if (loc->second == peer) {
668 EndpointPeerList::const_iterator loc =
671 if (loc->second == peer)
759 uint32_t out_q_depth = 0;
763 rit->second->GetTables();
764 for (RoutingInstance::RouteTableList::const_iterator it =
765 rt_list.begin(); it != rt_list.end(); ++it) {
805 for (BgpPeerList::const_iterator loc =
peer_list_.begin();
812 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
828 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
847 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
858 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
874 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
884 if ((
size_t) listener >=
asn_bmap_.size()) {
892 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
893 for (ASNUpdateListenersList::iterator iter =
asn_listeners_.begin();
897 (cb)(old_asn, old_local_asn);
903 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
919 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
937 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
942 (cb)(new_dscp_value);
948 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
964 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
974 if ((
size_t) listener >=
id_bmap_.size()) {
982 tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_,
false);
983 for (IdentifierUpdateListenersList::iterator iter =
id_listeners_.begin();
987 (cb)(old_identifier);
994 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
1000 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
1006 tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_,
true);
1037 PeerStatsInfo stats;
1040 BgpPeerInfoData peer_info;
1041 peer_info.set_name(peer->
ToUVEKey());
1042 peer_info.set_peer_stats_info(stats);
1043 assert(!peer_info.get_name().empty());
1046 PeerStatsData peer_stats_data;
1047 peer_stats_data.set_name(peer->
ToUVEKey());
1048 peer_stats_data.set_encoding(
"BGP");
1050 assert(!peer_stats_data.get_name().empty());
1051 BGP_UVE_SEND2(PeerStatsUve, peer_stats_data,
"ObjectBgpPeer");
1053 PeerFlapInfo flap_info;
1054 flap_info.set_flap_count(peer->
flap_count());
1055 flap_info.set_flap_time(peer->
last_flap());
1057 PeerFlapData peer_flap_data;
1058 peer_flap_data.set_name(peer->
ToUVEKey());
1059 peer_flap_data.set_encoding(
"BGP");
1060 peer_flap_data.set_flap_info(flap_info);
1061 assert(!peer_flap_data.get_name().empty());
1069 bool change =
false;
1071 if (first || is_admin_down != state->get_admin_down()) {
1072 state->set_admin_down(is_admin_down);
1077 if (first || router_id != state->get_router_id()) {
1078 state->set_router_id(router_id);
1083 if (first || local_asn != state->get_local_asn()) {
1084 state->set_local_asn(local_asn);
1089 if (first || global_asn != state->get_global_asn()) {
1090 state->set_global_asn(global_asn);
1095 if (first || num_bgp != state->get_num_bgp_peer()) {
1096 state->set_num_bgp_peer(num_bgp);
1101 if (first || num_up_bgp_peer != state->get_num_up_bgp_peer()) {
1102 state->set_num_up_bgp_peer(num_up_bgp_peer);
1107 if (first || deleting_bgp_peer != state->get_num_deleting_bgp_peer()) {
1108 state->set_num_deleting_bgp_peer(deleting_bgp_peer);
1113 if (first || num_bgpaas != state->get_num_bgpaas_peer()) {
1114 state->set_num_bgpaas_peer(num_bgpaas);
1119 if (first || num_up_bgpaas_peer != state->get_num_up_bgpaas_peer()) {
1120 state->set_num_up_bgpaas_peer(num_up_bgpaas_peer);
1125 if (first || deleting_bgpaas_peer !=
1126 state->get_num_deleting_bgpaas_peer()) {
1127 state->set_num_deleting_bgpaas_peer(deleting_bgpaas_peer);
1132 if (first || num_ri != state->get_num_routing_instance()) {
1133 state->set_num_routing_instance(num_ri);
1138 if (first || num_deleted_ri != state->get_num_deleted_routing_instance()) {
1139 state->set_num_deleted_routing_instance(num_deleted_ri);
1144 if (first || service_chains != state->get_num_service_chains()) {
1145 state->set_num_service_chains(service_chains);
1150 if (first || down_service_chains != state->get_num_down_service_chains()) {
1151 state->set_num_down_service_chains(down_service_chains);
1156 if (first || static_routes != state->get_num_static_routes()) {
1157 state->set_num_static_routes(static_routes);
1162 if (first || down_static_routes != state->get_num_down_static_routes()) {
1163 state->set_num_down_static_routes(down_static_routes);
1167 uint32_t out_load =
inst_mgr_->SendTableStatsUve();
1168 if (first || out_load != state->get_output_queue_depth()) {
1169 state->set_output_queue_depth(out_load);
1173 vector<string> bgp_config_peer_list;
1174 BOOST_FOREACH(BgpConfigManager::NeighborMap::value_type value,
1181 name += neighbor->
name();
1182 bgp_config_peer_list.push_back(name);
1184 sort(bgp_config_peer_list.begin(), bgp_config_peer_list.end());
1185 if (first || bgp_config_peer_list != state->get_bgp_config_peer_list()) {
1186 state->set_bgp_config_peer_list(bgp_config_peer_list);
1190 vector<string> bgp_oper_peer_list;
1194 peer != NULL; peer = peer_manager->
NextPeer(peer->peer_key())) {
1195 bgp_oper_peer_list.push_back(peer->ToUVEKey());
1197 sort(bgp_oper_peer_list.begin(), bgp_oper_peer_list.end());
1198 if (first || bgp_oper_peer_list != state->get_bgp_oper_peer_list()) {
1199 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)
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_
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)