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