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),
 
  529       inet_service_chain_mgr_(
 
  531       inet6_service_chain_mgr_(
 
  533       evpn_service_chain_mgr_(
 
  535       evpn6_service_chain_mgr_(
 
  595     BgpPeerList::iterator loc;
 
  599     assert(loc->second == peer);
 
  626     for (
size_t i = 
peer_bmap_.size(); i != 0; i--) {
 
  638     BgpPeerList::iterator loc = 
peer_list_.find(name);
 
  639     return (loc != 
peer_list_.end() ? loc->second : NULL);
 
  643     BgpPeerList::iterator loc = 
peer_list_.upper_bound(name);
 
  644     return (loc != 
peer_list_.end() ? loc->second : NULL);
 
  648     if (!remote.port() && remote.address().is_unspecified())
 
  656         if (loc->second == peer) {
 
  676     EndpointPeerList::const_iterator loc =
 
  679         if (loc->second == peer)
 
  767     uint32_t out_q_depth = 0;
 
  771                      rit->second->GetTables();
 
  772         for (RoutingInstance::RouteTableList::const_iterator it =
 
  773              rt_list.begin(); it != rt_list.end(); ++it) {
 
  813     for (BgpPeerList::const_iterator loc = 
peer_list_.begin();
 
  820     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  836     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  855     tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_, 
false);
 
  866     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  882     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  892         if ((
size_t) listener >= 
asn_bmap_.size()) {
 
  900     tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_, 
false);
 
  901     for (ASNUpdateListenersList::iterator iter = 
asn_listeners_.begin();
 
  905             (cb)(old_asn, old_local_asn);
 
  911     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  927     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  945     tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_, 
false);
 
  950             (cb)(new_dscp_value);
 
  956     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  972     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
  982         if ((
size_t) listener >= 
id_bmap_.size()) {
 
  990     tbb::spin_rw_mutex::scoped_lock read_lock(
rw_mutex_, 
false);
 
  991     for (IdentifierUpdateListenersList::iterator iter = 
id_listeners_.begin();
 
  995             (cb)(old_identifier);
 
 1002     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
 1008     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
 1014     tbb::spin_rw_mutex::scoped_lock write_lock(
rw_mutex_, 
true);
 
 1045     PeerStatsInfo stats;
 
 1048     BgpPeerInfoData peer_info;
 
 1049     peer_info.set_name(peer->
ToUVEKey());
 
 1050     peer_info.set_peer_stats_info(stats);
 
 1051     assert(!peer_info.get_name().empty());
 
 1054     PeerStatsData peer_stats_data;
 
 1055     peer_stats_data.set_name(peer->
ToUVEKey());
 
 1056     peer_stats_data.set_encoding(
"BGP");
 
 1058     assert(!peer_stats_data.get_name().empty());
 
 1059     BGP_UVE_SEND2(PeerStatsUve, peer_stats_data, 
"ObjectBgpPeer");
 
 1061     PeerFlapInfo flap_info;
 
 1062     flap_info.set_flap_count(peer->
flap_count());
 
 1063     flap_info.set_flap_time(peer->
last_flap());
 
 1065     PeerFlapData peer_flap_data;
 
 1066     peer_flap_data.set_name(peer->
ToUVEKey());
 
 1067     peer_flap_data.set_encoding(
"BGP");
 
 1068     peer_flap_data.set_flap_info(flap_info);
 
 1069     assert(!peer_flap_data.get_name().empty());
 
 1077     bool change = 
false;
 
 1079     if (first || is_admin_down != state->get_admin_down()) {
 
 1080         state->set_admin_down(is_admin_down);
 
 1085     if (first || router_id != state->get_router_id()) {
 
 1086         state->set_router_id(router_id);
 
 1091     if (first || local_asn != state->get_local_asn()) {
 
 1092         state->set_local_asn(local_asn);
 
 1097     if (first || global_asn != state->get_global_asn()) {
 
 1098         state->set_global_asn(global_asn);
 
 1103     if (first || num_bgp != state->get_num_bgp_peer()) {
 
 1104         state->set_num_bgp_peer(num_bgp);
 
 1109     if (first || num_up_bgp_peer != state->get_num_up_bgp_peer()) {
 
 1110         state->set_num_up_bgp_peer(num_up_bgp_peer);
 
 1115     if (first || deleting_bgp_peer != state->get_num_deleting_bgp_peer()) {
 
 1116         state->set_num_deleting_bgp_peer(deleting_bgp_peer);
 
 1121     if (first || num_bgpaas != state->get_num_bgpaas_peer()) {
 
 1122         state->set_num_bgpaas_peer(num_bgpaas);
 
 1127     if (first || num_up_bgpaas_peer != state->get_num_up_bgpaas_peer()) {
 
 1128         state->set_num_up_bgpaas_peer(num_up_bgpaas_peer);
 
 1133     if (first || deleting_bgpaas_peer !=
 
 1134             state->get_num_deleting_bgpaas_peer()) {
 
 1135         state->set_num_deleting_bgpaas_peer(deleting_bgpaas_peer);
 
 1140     if (first || num_ri != state->get_num_routing_instance()) {
 
 1141         state->set_num_routing_instance(num_ri);
 
 1146     if (first || num_deleted_ri != state->get_num_deleted_routing_instance()) {
 
 1147         state->set_num_deleted_routing_instance(num_deleted_ri);
 
 1152     if (first || service_chains != state->get_num_service_chains()) {
 
 1153         state->set_num_service_chains(service_chains);
 
 1158     if (first || down_service_chains != state->get_num_down_service_chains()) {
 
 1159         state->set_num_down_service_chains(down_service_chains);
 
 1164     if (first || static_routes != state->get_num_static_routes()) {
 
 1165         state->set_num_static_routes(static_routes);
 
 1170     if (first || down_static_routes != state->get_num_down_static_routes()) {
 
 1171         state->set_num_down_static_routes(down_static_routes);
 
 1175     uint32_t out_load = 
inst_mgr_->SendTableStatsUve();
 
 1176     if (first || out_load != state->get_output_queue_depth()) {
 
 1177         state->set_output_queue_depth(out_load);
 
 1181     vector<string> bgp_config_peer_list;
 
 1182     BOOST_FOREACH(BgpConfigManager::NeighborMap::value_type value,
 
 1189         name += neighbor->
name();
 
 1190         bgp_config_peer_list.push_back(name);
 
 1192     sort(bgp_config_peer_list.begin(), bgp_config_peer_list.end());
 
 1193     if (first || bgp_config_peer_list != state->get_bgp_config_peer_list()) {
 
 1194         state->set_bgp_config_peer_list(bgp_config_peer_list);
 
 1198     vector<string> bgp_oper_peer_list;
 
 1202         peer != NULL; peer = peer_manager->
NextPeer(peer->peer_key())) {
 
 1203         bgp_oper_peer_list.push_back(peer->ToUVEKey());
 
 1205     sort(bgp_oper_peer_list.begin(), bgp_oper_peer_list.end());
 
 1206     if (first || bgp_oper_peer_list != state->get_bgp_oper_peer_list()) {
 
 1207         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(...)