Line data Source code
1 : /* 2 : * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __AGENT_OPER_BGP_ROUTER_H 6 : #define __AGENT_OPER_BGP_ROUTER_H 7 : 8 : #include <mutex> 9 : 10 : #include <cmn/agent_cmn.h> 11 : #include <oper/oper_db.h> 12 : #include <bgp_schema_types.h> 13 : 14 : #define BGP_ROUTER_TYPE "control-node" 15 : #define BGP_ROUTER_EXT_TYPE "external-control-node" 16 : #define CONTROL_NODE_ZONE_CONFIG_NAME "control-node-zone" 17 : 18 : class IFMapNode; 19 : class BgpRouter; 20 : class ControlNodeZone; 21 : class BgpRouterConfig; 22 : 23 : typedef boost::shared_ptr<BgpRouter> BgpRouterPtr; 24 : typedef boost::shared_ptr<ControlNodeZone> ControlNodeZonePtr; 25 : typedef std::map<std::string, BgpRouterPtr> BgpRouterTree; 26 : typedef std::map<std::string, ControlNodeZonePtr> ControlNodeZoneTree; 27 : 28 : class BgpRouter { 29 : public: 30 : BgpRouter(const std::string &name, 31 : const std::string &ipv4_address, 32 : const uint32_t &port, autogen::BgpRouterParams ¶ms); 33 : ~BgpRouter(); 34 : 35 : void set_ip_address_port(const std::string &ip_address, const uint32_t &port); 36 : void set_control_node_zone_name(const std::string &contol_node_zone_name); 37 : 38 0 : const std::string &name() const { return name_; } 39 0 : const Ip4Address &ipv4_address() const { return ipv4_address_; } 40 0 : const uint32_t &port() const { return port_; } 41 0 : const std::string &control_node_zone_name() const { 42 0 : return control_node_zone_name_; 43 : } 44 : void set_inet_labeled_af(const autogen::BgpRouterParams params); 45 0 : bool get_inet_labeled_af() { 46 0 : return inet_labeled_af_enable_;} 47 : private: 48 : std::string name_; 49 : Ip4Address ipv4_address_; 50 : uint32_t port_; 51 : bool inet_labeled_af_enable_; 52 : std::string control_node_zone_name_; 53 : autogen::BgpRouterParams params_; 54 : DISALLOW_COPY_AND_ASSIGN(BgpRouter); 55 : }; 56 : 57 : class ControlNodeZone { 58 : public: 59 : ControlNodeZone(const std::string &name, const std::string &display_name, 60 : const boost::uuids::uuid &uuid); 61 : ~ControlNodeZone(); 62 : 63 0 : const std::string &name() const { return name_; } 64 0 : const BgpRouterTree &bgp_router_tree() const { 65 0 : return bgp_router_tree_; 66 : } 67 : private: 68 : friend class BgpRouterConfig; 69 : std::string name_; 70 : std::string display_name_; 71 : boost::uuids::uuid uuid_; 72 : BgpRouterTree bgp_router_tree_; 73 : DISALLOW_COPY_AND_ASSIGN(ControlNodeZone); 74 : }; 75 : 76 : class BgpRouterConfig : public OperIFMapTable { 77 : public: 78 : BgpRouterConfig(Agent *agent); 79 : virtual ~BgpRouterConfig(); 80 : 81 : std::mutex &mutex() { return mutex_; } 82 17 : uint32_t GetBgpRouterCount() { return bgp_router_tree_.size(); } 83 : uint32_t GetBgpRouterCount(const std::string &cnz_name); 84 16 : uint32_t GetControlNodeZoneCount() { 85 16 : return control_node_zone_tree_.size(); 86 : } 87 : 88 0 : const BgpRouterTree &bgp_router_tree() const { 89 0 : return bgp_router_tree_; 90 : } 91 : 92 0 : const ControlNodeZoneTree &control_node_zone_tree() const { 93 0 : return control_node_zone_tree_; 94 : } 95 : 96 : BgpRouterPtr GetBgpRouterFromXmppServer(const std::string &xmpp_server); 97 : BgpRouterPtr GetBgpRouterFromControlNodeZone(const std::string &cnz_name); 98 : 99 : void UpdateControlNodeZoneConfig(IFMapNode *bgp_router_node, 100 : BgpRouterPtr bgp_router); 101 : void DeleteControlNodeZoneConfig(IFMapNode *bgp_router_node, 102 : BgpRouterPtr bgp_router); 103 : 104 : void ConfigDelete(IFMapNode *node); 105 : void ConfigAddChange(IFMapNode *node); 106 : void ConfigManagerEnqueue(IFMapNode *node); 107 : bool GetInetLabeledAfEnableStatus() { 108 : return inet_labeled_af_enabled_; } 109 : private: 110 : void UpdateBgpRouterConfigAf(); 111 : std::mutex mutex_; 112 : BgpRouterTree bgp_router_tree_; 113 : ControlNodeZoneTree control_node_zone_tree_; 114 : bool inet_labeled_af_enabled_; 115 : DISALLOW_COPY_AND_ASSIGN(BgpRouterConfig); 116 : }; 117 : 118 : #endif