LCOV - code coverage report
Current view: top level - bgp - bgp_config_ifmap.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 47 47 100.0 %
Date: 2026-06-11 01:56:02 Functions: 41 41 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef SRC_BGP_BGP_CONFIG_IFMAP_H__
       6             : #define SRC_BGP_BGP_CONFIG_IFMAP_H__
       7             : 
       8             : #include <boost/function.hpp>
       9             : #include <boost/scoped_ptr.hpp>
      10             : 
      11             : #include <map>
      12             : #include <set>
      13             : #include <string>
      14             : #include <utility>
      15             : #include <vector>
      16             : 
      17             : #include "base/task_trigger.h"
      18             : #include "base/util.h"
      19             : #include "base/index_map.h"
      20             : #include "bgp/bgp_config.h"
      21             : #include "ifmap/ifmap_config_listener.h"
      22             : #include "ifmap/ifmap_node_proxy.h"
      23             : 
      24             : #define EVPN_ES_IMPORT_ROUTE_TARGET_AS2 (BGP_RTGT_MIN_ID_AS2 - 1) // 7999999
      25             : #define EVPN_ES_IMPORT_ROUTE_TARGET_AS4 (BGP_RTGT_MIN_ID_AS4 - 1) // 7999
      26             : 
      27             : class BgpConfigListener;
      28             : typedef struct IFMapConfigListener::ConfigDelta BgpConfigDelta;
      29             : class BgpIfmapConfigManager;
      30             : class BgpIfmapInstanceConfig;
      31             : class BgpIfmapRoutingPolicyConfig;
      32             : class BgpServer;
      33             : class DB;
      34             : class DBGraph;
      35             : 
      36             : namespace autogen {
      37             : class BgpPeering;
      38             : class BgpRouter;
      39             : class RoutingInstance;
      40             : class RoutingPolicy;
      41             : class RoutingPolicyRoutingInstance;
      42             : struct BgpRouterParams;
      43             : }
      44             : 
      45             : //
      46             : // A BgpIfmapPeeringConfig corresponds to a bgp-peering link in the
      47             : // schema. Since a bgp-peering is a link with attributes, it's
      48             : // represented as a node in the configuration database. There's a
      49             : // single BgpIfmapPeeringConfig between a given pair of bgp-routers in
      50             : // a particular routing-instance.
      51             : //
      52             : // A bgp-peering link is represented in IFMap DB using a autogen::BgpPeering
      53             : // object. This object has a vector of autogen::BgpSessions, with each entry
      54             : // corresponding to a single session. A BgpNeighborConfig is created for each
      55             : // session.
      56             : //
      57             : // The NeighborMap keeps pointers to all the BgpNeighborConfig objects
      58             : // for a BgpIfmapPeeringConfig. There's typically just a single entry
      59             : // in this map, but we allow for multiple entries if there's more than
      60             : // 1 autogen::BgpSesssion in the autogen::BgpPeering.
      61             : //
      62             : // A BgpIfmapPeeringConfig gets created/updated/deleted when the
      63             : // IFMapNode for the bgp-peering is created/updated/deleted.
      64             : //
      65             : // There's no direct operational object corresponding to
      66             : // BgpIfmapPeeringConfig. A BgpIfmapPeeringConfig results in the
      67             : // creation of one or more BgpNeighborConfigs each of which is
      68             : // associated with a BgpPeer.
      69             : //
      70             : // The instance_ field is a back pointer to the BgpInstanceConfig object for
      71             : // the routing-instance to which this bgp-peering belongs.
      72             : // The IFMapNodeProxy maintains a reference to the IFMapNode object for the
      73             : // bgp-peering in the ifmap metadata table.
      74             : //
      75             : class BgpIfmapPeeringConfig {
      76             : public:
      77             :     typedef std::map<std::string, BgpNeighborConfig *> NeighborMap;
      78             : 
      79             :     explicit BgpIfmapPeeringConfig(BgpIfmapInstanceConfig *instance);
      80             :     ~BgpIfmapPeeringConfig();
      81             : 
      82             :     void SetNodeProxy(IFMapNodeProxy *proxy);
      83             :     void Update(BgpIfmapConfigManager *manager,
      84             :                 const autogen::BgpPeering *peering);
      85             :     void Delete(BgpIfmapConfigManager *manager);
      86             : 
      87             :     static bool GetRouterPair(DBGraph *db_graph, const std::string  &localname,
      88             :                               IFMapNode *node,
      89             :                               std::pair<IFMapNode *, IFMapNode *> *pair);
      90             : 
      91       18600 :     const IFMapNode *node() const { return node_proxy_.node(); }
      92        8560 :     BgpIfmapInstanceConfig *instance() { return instance_; }
      93           6 :     const BgpIfmapInstanceConfig *instance() const { return instance_; }
      94       19999 :     std::string name() const { return name_; }
      95        1548 :     size_t size() const { return neighbors_.size(); }
      96       18095 :     const autogen::BgpPeering *bgp_peering() const {
      97       18095 :         return bgp_peering_.get();
      98             :     }
      99             : 
     100             : private:
     101             :     void BuildNeighbors(BgpIfmapConfigManager *manager,
     102             :                         const autogen::BgpRouter *local_rt_config,
     103             :                         const std::string &peername,
     104             :                         const autogen::BgpRouter *remote_rt_config,
     105             :                         const autogen::BgpPeering *peering, NeighborMap *map);
     106             : 
     107             :     BgpIfmapInstanceConfig *instance_;
     108             :     std::string name_;
     109             :     IFMapNodeProxy node_proxy_;
     110             :     NeighborMap neighbors_;
     111             :     boost::intrusive_ptr<const autogen::BgpPeering> bgp_peering_;
     112             : 
     113             :     DISALLOW_COPY_AND_ASSIGN(BgpIfmapPeeringConfig);
     114             : };
     115             : 
     116             : //
     117             : // Represents a local IFMap bgp-router node in a specific routing-instance.
     118             : //
     119             : // A BgpProtocolConfig is created/updated/deleted when the IFMapNode for the
     120             : // bgp-router is created/updated/deleted.
     121             : //
     122             : // The instance_ field is a back pointer to the BgpInstanceConfig object for
     123             : // the routing-instance to which this bgp-router belongs.
     124             : // The IFMapNodeProxy maintains a reference to the IFMapNode object for the
     125             : // bgp-router in the ifmap bgp-router table.
     126             : //
     127             : class BgpIfmapProtocolConfig {
     128             : public:
     129             :     explicit BgpIfmapProtocolConfig(BgpIfmapInstanceConfig *instance);
     130             :     ~BgpIfmapProtocolConfig();
     131             : 
     132             :     void SetNodeProxy(IFMapNodeProxy *proxy);
     133             : 
     134             :     void Update(BgpIfmapConfigManager *manager,
     135             :                 const autogen::BgpRouter *router);
     136             :     void Delete(BgpIfmapConfigManager *manager);
     137             : 
     138             :     const std::string &InstanceName() const;
     139             : 
     140             :     const autogen::BgpRouterParams &router_params() const;
     141       61662 :     const autogen::BgpRouter *bgp_router() const { return bgp_router_.get(); }
     142             : 
     143        9233 :     IFMapNode *node() { return node_proxy_.node(); }
     144       18028 :     const BgpIfmapInstanceConfig *instance() { return instance_; }
     145             : 
     146      471540 :     const BgpProtocolConfig *protocol_config() const { return &data_; }
     147             : 
     148             : private:
     149             :     BgpIfmapInstanceConfig *instance_;
     150             :     IFMapNodeProxy node_proxy_;
     151             :     BgpProtocolConfig data_;
     152             :     boost::intrusive_ptr<const autogen::BgpRouter> bgp_router_;
     153             : 
     154             :     DISALLOW_COPY_AND_ASSIGN(BgpIfmapProtocolConfig);
     155             : };
     156             : 
     157             : //
     158             : // Internal representation of routing-instance.
     159             : //
     160             : // A BgpInstanceConfig causes creation of a RoutingInstance. RoutingInstance
     161             : // has a pointer to the BgpInstanceConfig. This pointer gets invalidated and
     162             : // cleared when the RoutingInstance is undergoing deletion.
     163             : //
     164             : // The IFMapNodeProxy maintains a reference to the IFMapNode object for the
     165             : // routing-instance in the ifmap routing-instance table.
     166             : //
     167             : // The BgpInstanceConfig for the master instance is manually created when the
     168             : // BgpConfigManager is initialized. It gets deleted when the BgpConfigManager
     169             : // is terminated.
     170             : //
     171             : // For other routing-instances, a BgpInstanceConfig is created when we first
     172             : // see the IFMapNode for the routing-instance or when we see the IFMapNode for
     173             : // the local bgp-router in the routing-instance.
     174             : //
     175             : // BgpInstanceConfig is deleted only when all references to it are
     176             : // gone. The IFMapNode for the routing-instance must be deleted, any
     177             : // BgpProtcolConfig for the local bgp-router in the routing-instance
     178             : // must be deleted and all the BgpNeighborConfigs and
     179             : // BgpIfmapPeeringConfigs in the routing-instance must be deleted.
     180             : //
     181             : // The protocol_ field is a pointer to the BgpProtocolConfig object
     182             : // for the local bgp-router object, if any, in the routing-instance.
     183             : // The NeighborMap keeps pointers to all the BgpNeighborConfig objects
     184             : // in a BgpInstanceConfig.  The PeeringMap keeps pointers to all the
     185             : // BgpIfmapPeeringConfig objects in the BgpInstanceConfig.
     186             : //
     187             : class BgpIfmapInstanceConfig {
     188             : public:
     189             :     typedef BgpInstanceConfig::RouteTargetList RouteTargetList;
     190             :     typedef std::map<std::string,
     191             :         BgpNeighborConfig *> NeighborMap;
     192             :     typedef std::map<std::string,
     193             :         BgpIfmapPeeringConfig *> PeeringMap;
     194             :     typedef std::map<std::string,
     195             :         BgpIfmapRoutingPolicyConfig *> RouitngPolicyMap;
     196             : 
     197             :     explicit BgpIfmapInstanceConfig(const std::string &name);
     198             :     ~BgpIfmapInstanceConfig();
     199             : 
     200             :     void SetNodeProxy(IFMapNodeProxy *proxy);
     201             : 
     202             :     void Update(BgpIfmapConfigManager *manager,
     203             :                 const autogen::RoutingInstance *config);
     204             : 
     205             :     // The corresponding if-map node has been deleted.
     206             :     void ResetConfig();
     207             :     bool DeleteIfEmpty(BgpConfigManager *manager);
     208             : 
     209      248115 :     const BgpIfmapProtocolConfig *protocol_config() const {
     210      248115 :         return protocol_.get();
     211             :     }
     212        9798 :     BgpIfmapProtocolConfig *protocol_config_mutable() {
     213        9798 :         return protocol_.get();
     214             :     }
     215             :     BgpIfmapProtocolConfig *LocateProtocol();
     216             :     void ResetProtocol();
     217             : 
     218             :     void AddNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor);
     219             :     void ChangeNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor);
     220             :     void DeleteNeighbor(BgpConfigManager *manager, BgpNeighborConfig *neighbor);
     221             :     const BgpNeighborConfig *FindNeighbor(const std::string &name) const;
     222             : 
     223             :     BgpConfigManager::NeighborMapRange NeighborMapItems() const;
     224             : 
     225          12 :     const NeighborMap &neighbors() const { return neighbors_; }
     226           7 :     const PeeringMap &peerings() const { return peerings_; }
     227             : 
     228             :     void AddPeering(BgpIfmapPeeringConfig *peering);
     229             :     void DeletePeering(BgpIfmapPeeringConfig *peering);
     230             : 
     231      104001 :     IFMapNode *node() { return node_proxy_.node(); }
     232      249641 :     const std::string &name() const { return name_; }
     233             : 
     234      393914 :     BgpInstanceConfig *instance_config() { return &data_; }
     235             :     const BgpInstanceConfig *instance_config() const { return &data_; }
     236             : 
     237      283300 :     const RouteTargetList &import_list() const {
     238      283300 :         return data_.import_list();
     239             :     }
     240      283300 :     const RouteTargetList &export_list() const {
     241      283300 :         return data_.export_list();
     242             :     }
     243      150482 :     const std::string &virtual_network() const {
     244      150482 :         return data_.virtual_network();
     245             :     }
     246      150482 :     int virtual_network_index() const { return data_.virtual_network_index(); }
     247             :     void AddRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp);
     248             :     void DeleteRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp);
     249       50599 :     void set_index(int index) { index_ = index; };
     250      356449 :     int index() const { return index_; }
     251             :     std::string GetVitFromId(uint32_t identifier) const;
     252             :     std::string GetESRouteTarget(uint32_t as) const;
     253             :     void InsertVitAndESRTargetInImportList(BgpIfmapConfigManager *manager,
     254             :             BgpInstanceConfig::RouteTargetList& import_list);
     255             :     void ProcessIdentifierUpdate(uint32_t new_id, uint32_t old_id);
     256             :     void ProcessASUpdate(uint32_t new_as, uint32_t old_as);
     257             : 
     258             : private:
     259             :     friend class BgpConfigManagerTest;
     260             : 
     261             :     std::string name_;
     262             :     IFMapNodeProxy node_proxy_;
     263             :     BgpInstanceConfig data_;
     264             :     int index_;
     265             :     boost::scoped_ptr<BgpIfmapProtocolConfig> protocol_;
     266             :     NeighborMap neighbors_;
     267             :     PeeringMap peerings_;
     268             :     RouitngPolicyMap routing_policies_;
     269             : 
     270             :     DISALLOW_COPY_AND_ASSIGN(BgpIfmapInstanceConfig);
     271             : };
     272             : 
     273             : class BgpIfmapRoutingPolicyLinkConfig {
     274             : public:
     275             :     explicit BgpIfmapRoutingPolicyLinkConfig(BgpIfmapInstanceConfig *rti,
     276             :         BgpIfmapRoutingPolicyConfig *rtp);
     277             :     ~BgpIfmapRoutingPolicyLinkConfig();
     278             : 
     279             :     void SetNodeProxy(IFMapNodeProxy *proxy);
     280             : 
     281         282 :     const IFMapNode *node() const { return node_proxy_.node(); }
     282             :     std::string name() const { return name_; }
     283             :     const autogen::RoutingPolicyRoutingInstance *routing_policy_link() const {
     284             :         return ri_rp_link_.get();
     285             :     }
     286             :     static bool GetInstancePolicyPair(DBGraph *graph, IFMapNode *node,
     287             :         std::pair<IFMapNode *, IFMapNode *> *pair);
     288         303 :     BgpIfmapInstanceConfig *instance() { return instance_; }
     289         303 :     BgpIfmapRoutingPolicyConfig *policy() { return policy_; }
     290             : 
     291             :     void Update(BgpIfmapConfigManager *manager,
     292             :                 const autogen::RoutingPolicyRoutingInstance *ri_rp);
     293             :     void Delete(BgpIfmapConfigManager *manager);
     294             : 
     295             : private:
     296             :     BgpIfmapInstanceConfig *instance_;
     297             :     BgpIfmapRoutingPolicyConfig *policy_;
     298             :     std::string name_;
     299             :     IFMapNodeProxy node_proxy_;
     300             :     boost::intrusive_ptr<
     301             :         const autogen::RoutingPolicyRoutingInstance> ri_rp_link_;
     302             : 
     303             :     DISALLOW_COPY_AND_ASSIGN(BgpIfmapRoutingPolicyLinkConfig);
     304             : };
     305             : 
     306             : class BgpIfmapRoutingPolicyConfig {
     307             : public:
     308             :     typedef std::map<std::string, BgpIfmapInstanceConfig *> InstanceMap;
     309             :     explicit BgpIfmapRoutingPolicyConfig(const std::string &name);
     310             :     ~BgpIfmapRoutingPolicyConfig();
     311             : 
     312             :     void SetNodeProxy(IFMapNodeProxy *proxy);
     313             : 
     314             :     // The corresponding if-map node has been deleted.
     315             :     void ResetConfig();
     316             :     void Delete(BgpConfigManager *manager);
     317             :     bool DeleteIfEmpty(BgpConfigManager *manager);
     318             : 
     319             :     void Update(BgpIfmapConfigManager *manager,
     320             :                 const autogen::RoutingPolicy *policy);
     321             : 
     322         368 :     IFMapNode *node() { return node_proxy_.node(); }
     323         297 :     const std::string &name() const { return name_; }
     324             : 
     325         572 :     BgpRoutingPolicyConfig *routing_policy_config() { return &data_; }
     326             :     const BgpRoutingPolicyConfig *routing_policy_config() const {
     327             :         return &data_;
     328             :     }
     329             : 
     330             :     void AddInstance(BgpIfmapInstanceConfig *rti);
     331             :     void RemoveInstance(BgpIfmapInstanceConfig *rti);
     332             : 
     333             : private:
     334             :     friend class BgpConfigManagerTest;
     335             : 
     336             :     std::string name_;
     337             :     IFMapNodeProxy node_proxy_;
     338             :     BgpRoutingPolicyConfig data_;
     339             :     boost::intrusive_ptr<const autogen::RoutingPolicy> routing_policy_;
     340             :     InstanceMap instances_;
     341             : 
     342             :     DISALLOW_COPY_AND_ASSIGN(BgpIfmapRoutingPolicyConfig);
     343             : };
     344             : 
     345             : class BgpIfmapGlobalSystemConfig {
     346             : public:
     347         867 :     const BgpGlobalSystemConfig *config() const { return &data_; }
     348             :     bool Update(BgpIfmapConfigManager *manager,
     349             :                 const autogen::GlobalSystemConfig *system);
     350             : 
     351             : private:
     352             :     BgpGlobalSystemConfig data_;
     353             : };
     354             : 
     355             : class BgpIfmapGlobalQosConfig {
     356             : public:
     357           9 :     const BgpGlobalQosConfig *config() const { return &data_; }
     358             :     bool Update(BgpIfmapConfigManager *manager,
     359             :                 const autogen::GlobalQosConfig *qos);
     360             : 
     361             : private:
     362             :     BgpGlobalQosConfig data_;
     363             : };
     364             : 
     365             : //
     366             : // BgpConfigData contains all the configuration data that's relevant to a
     367             : // node. The BgpConfigManager has a pointer to BgpConfigData.
     368             : //
     369             : // The IfmapInstanceMap stores pointers to the BgpIfmapInstanceConfigs
     370             : // that have been created for all the routing-instances.
     371             : // The IfmapPeeringMap stores pointers to the BgpIfmapPeeringConfigs
     372             : // that have been created for all the bgp-peerings.
     373             : // The IfmapRoutingPolicyMap stores pointers to the BgpIfmapRoutingPolicyConfig
     374             : // that have been created for all the routing-policy.
     375             : //
     376             : class BgpIfmapConfigData {
     377             : public:
     378             :     typedef BgpConfigManager::InstanceMap BgpInstanceMap;
     379             :     typedef BgpConfigManager::RoutingPolicyMap BgpRoutingPolicyMap;
     380             :     typedef IndexMap<std::string,
     381             :         BgpIfmapInstanceConfig, BitSet> IfmapInstanceMap;
     382             :     typedef std::map<std::string,
     383             :         BgpIfmapRoutingPolicyConfig *> IfmapRoutingPolicyMap;
     384             :     typedef std::map<std::string,
     385             :         BgpIfmapPeeringConfig *> IfmapPeeringMap;
     386             :     typedef std::map<std::string,
     387             :         BgpIfmapRoutingPolicyLinkConfig *> IfmapRoutingPolicyLinkMap;
     388             : 
     389             :     BgpIfmapConfigData();
     390             :     ~BgpIfmapConfigData();
     391             : 
     392             :     BgpIfmapInstanceConfig *LocateInstance(const std::string &name);
     393             :     void DeleteInstance(BgpIfmapInstanceConfig *rti);
     394             :     BgpIfmapInstanceConfig *FindInstance(const std::string &name);
     395             :     const BgpIfmapInstanceConfig *FindInstance(const std::string &name) const;
     396             : 
     397             :     // Routing Policy
     398             :     BgpIfmapRoutingPolicyConfig *LocateRoutingPolicy(const std::string &name);
     399             :     void DeleteRoutingPolicy(BgpIfmapRoutingPolicyConfig *rtp);
     400             :     BgpIfmapRoutingPolicyConfig *FindRoutingPolicy(const std::string &name);
     401             :     const BgpIfmapRoutingPolicyConfig *FindRoutingPolicy(
     402             :         const std::string &name) const;
     403             : 
     404             :     BgpIfmapPeeringConfig *CreatePeering(BgpIfmapInstanceConfig *rti,
     405             :         IFMapNodeProxy *proxy);
     406             :     void DeletePeering(BgpIfmapPeeringConfig *peer);
     407             :     BgpIfmapPeeringConfig *FindPeering(const std::string &name);
     408             :     const BgpIfmapPeeringConfig *FindPeering(const std::string &name) const;
     409           7 :     int PeeringCount() const { return peerings_.size(); }
     410             : 
     411             :     BgpIfmapRoutingPolicyLinkConfig *CreateRoutingPolicyLink(
     412             :         BgpIfmapInstanceConfig *rti, BgpIfmapRoutingPolicyConfig *rtp,
     413             :         IFMapNodeProxy *proxy);
     414             :     void DeleteRoutingPolicyLink(BgpIfmapRoutingPolicyLinkConfig *ri_rp_link);
     415             :     BgpIfmapRoutingPolicyLinkConfig *FindRoutingPolicyLink(
     416             :         const std::string &name);
     417             :     const BgpIfmapRoutingPolicyLinkConfig *FindRoutingPolicyLink(
     418             :         const std::string &name) const;
     419             : 
     420             :     BgpConfigManager::InstanceMapRange InstanceMapItems(
     421             :         const std::string &start_name = std::string()) const;
     422             :     BgpConfigManager::RoutingPolicyMapRange RoutingPolicyMapItems(
     423             :         const std::string &start_name = std::string()) const;
     424             : 
     425       51026 :     IfmapInstanceMap &instances() { return instances_; }
     426        9798 :     const IfmapPeeringMap &peerings() const { return peerings_; }
     427        2030 :     BgpIfmapGlobalSystemConfig *global_config() { return &global_config_; }
     428             :     const BgpIfmapGlobalSystemConfig *global_config() const {
     429             :         return &global_config_;
     430             :     }
     431          20 :     BgpIfmapGlobalQosConfig *global_qos() { return &global_qos_; }
     432             :     const BgpIfmapGlobalQosConfig *global_qos() const {
     433             :         return &global_qos_;
     434             :     }
     435             :     void ProcessIdentifierAndASUpdate(BgpIfmapConfigManager* manager,
     436             :         uint32_t new_id, uint32_t old_id, uint32_t new_as, uint32_t old_as);
     437             : 
     438             : private:
     439             :     IfmapInstanceMap instances_;
     440             :     BgpInstanceMap instance_config_map_;
     441             :     IfmapRoutingPolicyMap routing_policies_;
     442             :     BgpRoutingPolicyMap routing_policy_config_map_;
     443             :     IfmapPeeringMap peerings_;
     444             :     IfmapRoutingPolicyLinkMap ri_rp_links_;
     445             :     BgpIfmapGlobalSystemConfig global_config_;
     446             :     BgpIfmapGlobalQosConfig global_qos_;
     447             : 
     448             :     DISALLOW_COPY_AND_ASSIGN(BgpIfmapConfigData);
     449             : };
     450             : 
     451             : //
     452             : // This class is responsible for managing all bgp related configuration for
     453             : // a BgpServer. A BgpServer allocates an instance of a BgpConfigManager.
     454             : //
     455             : // BgpConfigManager listens to updates for IFMap objects which are relevant
     456             : // to BGP.  This is accomplished using an instance of the BgpConfigListener.
     457             : // The BgpConfigListener is used to build a ChangeList of BgpConfigDeltas
     458             : // that are then processed by the BgpConfigManager.
     459             : //
     460             : // Internal representations of interesting IFMap objects are generated and
     461             : // updated as BgpConfigDeltas are processed.  An instance of BgpConfigData
     462             : // is used to store the internal representations (the BgpXyzConfig classes).
     463             : //
     464             : // Notifications of changes to the internal representations are sent to the
     465             : // registered Observers. The BgpServer::ConfigUpdater is the only client that
     466             : // registers observers.
     467             : //
     468             : class BgpIfmapConfigManager : public BgpConfigManager,
     469             :     public IFMapConfigListener::ConfigManager {
     470             : public:
     471             :     explicit BgpIfmapConfigManager(BgpServer *server);
     472             :     virtual ~BgpIfmapConfigManager();
     473             : 
     474             :     void Initialize(DB *db, DBGraph *db_graph, const std::string &localname);
     475             : 
     476             :     /*
     477             :      * begin: BgpConfigManager Interface
     478             :      */
     479             :     virtual void Terminate();
     480      698959 :     virtual const std::string &localname() const { return localname_; }
     481             : 
     482             :     virtual InstanceMapRange InstanceMapItems(
     483             :         const std::string &start_name = std::string()) const;
     484             :     virtual RoutingPolicyMapRange RoutingPolicyMapItems(
     485             :         const std::string &start_name = std::string()) const;
     486             :     virtual NeighborMapRange NeighborMapItems(
     487             :         const std::string &instance_name) const;
     488             : 
     489             :     virtual int NeighborCount(const std::string &instance_name) const;
     490             :     virtual void ResetRoutingInstanceIndexBit(int index);
     491             : 
     492             :     virtual const BgpInstanceConfig *FindInstance(
     493             :         const std::string &name) const;
     494             :     virtual const BgpRoutingPolicyConfig *FindRoutingPolicy(
     495             :         const std::string &name) const;
     496             :     virtual const BgpProtocolConfig *GetProtocolConfig(
     497             :         const std::string &instance_name) const;
     498             :     virtual const BgpNeighborConfig *FindNeighbor(
     499             :         const std::string &instance_name, const std::string &name) const;
     500             :     // end: BgpConfigManager
     501             : 
     502             :     void DefaultBgpRouterParams(autogen::BgpRouterParams *param);
     503             :     void OnChange();
     504             : 
     505      396282 :     DB *database() { return db_; }
     506      153939 :     DBGraph *graph() { return db_graph_; }
     507           7 :     const BgpIfmapConfigData *config() const { return config_.get(); }
     508      192337 :     BgpIfmapConfigData *config() { return config_.get(); }
     509             :     void UpdateInstanceConfig(BgpIfmapInstanceConfig *rti,
     510             :             BgpConfigManager::EventType event);
     511             : 
     512             : private:
     513             :     friend class BgpConfigListenerTest;
     514             : 
     515             :     typedef std::vector<BgpConfigDelta> ChangeList;
     516             :     typedef std::map<std::string,
     517             :         boost::function<void(const BgpConfigDelta &)> >IdentifierMap;
     518             : 
     519             :     void IdentifierMapInit();
     520             :     void DefaultConfig();
     521             : 
     522             :     void ProcessChanges(const ChangeList &change_list);
     523             :     void ProcessRoutingInstance(const BgpConfigDelta &change);
     524             :     void ProcessRoutingPolicyLink(const BgpConfigDelta &change);
     525             :     void ProcessRoutingPolicy(const BgpConfigDelta &change);
     526             :     void ProcessBgpRouter(const BgpConfigDelta &change);
     527             :     void ProcessBgpProtocol(const BgpConfigDelta &change);
     528             :     void ProcessBgpPeering(const BgpConfigDelta &change);
     529             :     void ProcessGlobalSystemConfig(const BgpConfigDelta &delta);
     530             :     void ProcessGlobalQosConfig(const BgpConfigDelta &delta);
     531             : 
     532             :     bool ConfigHandler();
     533             : 
     534             :     static const int kConfigTaskInstanceId;
     535             : 
     536             :     DB *db_;
     537             :     DBGraph *db_graph_;
     538             :     std::string localname_;
     539             :     IdentifierMap id_map_;
     540             : 
     541             :     TaskTrigger trigger_;
     542             :     boost::scoped_ptr<BgpConfigListener> listener_;
     543             :     boost::scoped_ptr<BgpIfmapConfigData> config_;
     544             : 
     545             :     DISALLOW_COPY_AND_ASSIGN(BgpIfmapConfigManager);
     546             : };
     547             : 
     548             : #endif  // SRC_BGP_BGP_CONFIG_IFMAP_H_

Generated by: LCOV version 1.14