Line data Source code
1 : /* 2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : #ifndef SRC_VNSW_AGENT_OPER_CONFIG_MANAGER_H_ 6 : #define SRC_VNSW_AGENT_OPER_CONFIG_MANAGER_H_ 7 : 8 : /***************************************************************************** 9 : * Implements change list for the oper table. Normally, the oper objects 10 : * process configuration thru IFNodeToReq or IFLinkToReq callback methods. 11 : * 12 : * In scaled environments there can be large number of invocations to 13 : * IFNodeToReq and IFLinkToReq APIs. The config processing routines are 14 : * written to act on the latest version of configuration. So, an invocation 15 : * of config routine will override all previous invocations. Ideally, we wnat 16 : * to invoke the config callbacks only once after all configuraiton is 17 : * received. However, we dont have any marker to identify end of configuration. 18 : * 19 : * The next best design we follow is to add the objects changed into a 20 : * change list. The change-list is run from a task-trigger. The list can 21 : * potentially compress multiple changes to a node 22 : * 23 : * The changelist should also take care of dependency between objects. For 24 : * example, VMInterface has reference to VirtualNetwork. So, the change list 25 : * for virtual-network should be invoked before VMInterface. The changelist 26 : * should take of all dependencies. 27 : * 28 : * The changelist is implemented to objects 29 : * security-group 30 : * virtual-machine-interface 31 : * logical-interfaces 32 : * physical-device-vn 33 : * physical-router 34 : *****************************************************************************/ 35 : 36 : #include <cmn/agent_cmn.h> 37 : #include <cmn/agent_db.h> 38 : #include <operdb_init.h> 39 : #include <ifmap_dependency_manager.h> 40 : 41 : class ConfigManagerNodeList; 42 : class ConfigManagerDeviceVnList; 43 : class IFMapAgentLinkTable; 44 : 45 : class ConfigHelper { 46 : public: 47 : ConfigHelper(const ConfigManager *mgr, const Agent *agent); 48 4 : virtual ~ConfigHelper() { } 49 : 50 : IFMapNode *GetOtherAdjacentNode(IFMapLink *link, 51 : IFMapNode *node); 52 : IFMapNode *FindLink(const char *type, IFMapNode *node); 53 : 54 : private: 55 : const ConfigManager *mgr_; 56 : IFMapAgentLinkTable *link_table_; 57 : const Agent *agent_; 58 : DISALLOW_COPY_AND_ASSIGN(ConfigHelper); 59 : }; 60 : 61 : class ConfigManager { 62 : public: 63 : // Number of changelist entries to pick in one run 64 : const static uint32_t kIterationCount = 64; 65 : const static uint32_t kMinTimeout = 1; 66 : const static uint32_t kMaxTimeout = 10; 67 : 68 : ConfigManager(Agent *agent); 69 : virtual ~ConfigManager(); 70 : 71 : void Init(); 72 : int Run(); 73 : bool TriggerRun(); 74 : bool TimerRun(); 75 : void Start(); 76 : 77 : uint32_t Size() const; 78 : uint32_t ProcessCount() const; 79 0 : uint32_t timeout() const { return timeout_; } 80 : std::string ProfileInfo() const; 81 : 82 : void AddVmiNode(IFMapNode *node); 83 : uint32_t VmiNodeCount() const; 84 : 85 : void AddLogicalInterfaceNode(IFMapNode *node); 86 : void AddPhysicalInterfaceNode(IFMapNode *node); 87 : void AddSgNode(IFMapNode *node); 88 : void AddTagNode(IFMapNode *node); 89 : void AddVnNode(IFMapNode *node); 90 : void AddVrfNode(IFMapNode *node); 91 : void AddVmNode(IFMapNode *node); 92 : void AddQosConfigNode(IFMapNode *node); 93 : void AddQosQueueNode(IFMapNode *node); 94 : void AddForwardingClassNode(IFMapNode *node); 95 : void AddGlobalQosConfigNode(IFMapNode *node); 96 : void AddGlobalSystemConfigNode(IFMapNode *node); 97 : void AddNetworkIpamNode(IFMapNode *node); 98 : void AddVirtualDnsNode(IFMapNode *node); 99 : void AddGlobalVrouterNode(IFMapNode *node); 100 : void AddBgpRouterConfigNode(IFMapNode *node); 101 : void AddVirtualRouterNode(IFMapNode *node); 102 : uint32_t LogicalInterfaceNodeCount() const; 103 : void AddSecurityLoggingObjectNode(IFMapNode *node); 104 : void AddMulticastPolicyNode(IFMapNode *node); 105 : 106 : void AddPhysicalDeviceNode(IFMapNode *node); 107 : void AddPhysicalDeviceVn(const boost::uuids::uuid &dev, 108 : const boost::uuids::uuid &vn); 109 : void DelPhysicalDeviceVn(const boost::uuids::uuid &dev, 110 : const boost::uuids::uuid &vn); 111 : void AddHealthCheckServiceNode(IFMapNode *node); 112 : void AddBridgeDomainNode(IFMapNode *node); 113 : void AddPolicySetNode(IFMapNode *node); 114 : void AddProjectNode(IFMapNode *node); 115 : uint32_t PhysicalDeviceVnCount() const; 116 : bool CanUseNode(IFMapNode *node); 117 : bool CanUseNode(IFMapNode *node, IFMapAgentTable *table); 118 : bool SkipNode(IFMapNode *node); 119 : bool SkipNode(IFMapNode *node, IFMapAgentTable *table); 120 : IFMapNode * FindAdjacentIFMapNode(IFMapNode *node, 121 : const char *type); 122 : void NodeResync(IFMapNode *node); 123 : ConfigHelper *helper() const {return helper_.get();} 124 : 125 12286 : Agent *agent() { return agent_; } 126 : 127 : private: 128 : Agent *agent_; 129 : std::unique_ptr<TaskTrigger> trigger_; 130 : Timer *timer_; 131 : uint32_t timeout_; 132 : 133 : std::unique_ptr<ConfigManagerNodeList> vmi_list_; 134 : std::unique_ptr<ConfigManagerNodeList> physical_interface_list_; 135 : std::unique_ptr<ConfigManagerNodeList> logical_interface_list_; 136 : std::unique_ptr<ConfigManagerNodeList> device_list_; 137 : std::unique_ptr<ConfigManagerNodeList> sg_list_; 138 : std::unique_ptr<ConfigManagerNodeList> tag_list_; 139 : std::unique_ptr<ConfigManagerNodeList> vn_list_; 140 : std::unique_ptr<ConfigManagerNodeList> vrf_list_; 141 : std::unique_ptr<ConfigManagerNodeList> vm_list_; 142 : std::unique_ptr<ConfigManagerNodeList> hc_list_; 143 : std::unique_ptr<ConfigManagerNodeList> qos_config_list_; 144 : std::unique_ptr<ConfigManagerNodeList> qos_queue_list_; 145 : std::unique_ptr<ConfigManagerNodeList> forwarding_class_list_; 146 : std::unique_ptr<ConfigManagerDeviceVnList> device_vn_list_; 147 : std::unique_ptr<ConfigManagerNodeList> bridge_domain_list_; 148 : std::unique_ptr<ConfigManagerNodeList> slo_list_; 149 : std::unique_ptr<ConfigManagerNodeList> policy_set_list_; 150 : std::unique_ptr<ConfigManagerNodeList> mp_list_; 151 : 152 : // Lists of IFMapNodes without corresponding oper db-tables 153 : std::unique_ptr<ConfigManagerNodeList> global_vrouter_list_; 154 : std::unique_ptr<ConfigManagerNodeList> bgp_router_config_list_; 155 : std::unique_ptr<ConfigManagerNodeList> virtual_router_list_; 156 : std::unique_ptr<ConfigManagerNodeList> global_qos_config_list_; 157 : std::unique_ptr<ConfigManagerNodeList> network_ipam_list_; 158 : std::unique_ptr<ConfigManagerNodeList> virtual_dns_list_; 159 : std::unique_ptr<ConfigManagerNodeList> global_system_config_list_; 160 : std::unique_ptr<ConfigManagerNodeList> project_list_; 161 : 162 : uint64_t process_config_count_[kMaxTimeout + 1]; 163 : boost::scoped_ptr<ConfigHelper> helper_; 164 : DISALLOW_COPY_AND_ASSIGN(ConfigManager); 165 : }; 166 : 167 : #endif // SRC_VNSW_AGENT_OPER_CONFIG_MANAGER_H_