Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : * Copyright Contributors to the OpenSDN project
4 : */
5 : #include <cmn/agent_cmn.h>
6 :
7 : #include <boost/property_tree/xml_parser.hpp>
8 : #include <db/db_graph.h>
9 :
10 : #include <cmn/agent.h>
11 : #include <cmn/agent_db.h>
12 :
13 : #include <bgp_schema_types.h>
14 :
15 : #include <cfg/cfg_init.h>
16 : #include <cfg/cfg_filter.h>
17 : #include <cfg/cfg_mirror.h>
18 :
19 : #include <oper/vn.h>
20 : #include <oper/sg.h>
21 : #include <oper/vm.h>
22 : #include <oper/vrf.h>
23 : #include <oper/nexthop.h>
24 : #include <oper/interface_common.h>
25 : #include <oper/mirror_table.h>
26 : #include <oper/route_common.h>
27 : #include <oper/operdb_init.h>
28 : #include <oper/global_vrouter.h>
29 : #include <oper/service_instance.h>
30 : #include <oper/physical_device.h>
31 :
32 : #include <vgw/cfg_vgw.h>
33 : #include <vgw/vgw.h>
34 : #include <filter/acl.h>
35 :
36 : using namespace std;
37 : using namespace autogen;
38 : using namespace boost::property_tree;
39 : using namespace boost::uuids;
40 : using boost::optional;
41 :
42 : void IFMapAgentSandeshInit(DB *, IFMapAgentParser *);
43 :
44 : SandeshTraceBufferPtr CfgTraceBuf(SandeshTraceBufferCreate("Config", 2000));
45 :
46 1 : AgentConfig::AgentConfig(Agent *agent)
47 1 : : agent_(agent) {
48 1 : cfg_filter_ = std::unique_ptr<CfgFilter>(new CfgFilter(this));
49 :
50 1 : cfg_graph_ = std::unique_ptr<DBGraph>(new DBGraph());
51 1 : cfg_mirror_table_ = std::unique_ptr<MirrorCfgTable>(new MirrorCfgTable(this));
52 1 : agent_->set_mirror_cfg_table(cfg_mirror_table_.get());
53 :
54 2 : cfg_intf_mirror_table_ = std::unique_ptr<IntfMirrorCfgTable>
55 2 : (new IntfMirrorCfgTable(this));
56 1 : agent_->set_interface_mirror_cfg_table(cfg_intf_mirror_table_.get());
57 1 : }
58 :
59 2 : AgentConfig::~AgentConfig() {
60 1 : cfg_filter_.reset();
61 1 : cfg_parser_.reset();
62 1 : cfg_graph_.reset();
63 1 : cfg_mirror_table_.reset();
64 1 : cfg_intf_mirror_table_.reset();
65 2 : }
66 :
67 1 : void AgentConfig::CreateDBTables(DB *db) {
68 : // Create parser once we know the db
69 1 : cfg_parser_ = std::unique_ptr<IFMapAgentParser>(new IFMapAgentParser(db));
70 1 : vnc_cfg_Agent_ModuleInit(db, cfg_graph_.get());
71 1 : vnc_cfg_Agent_ParserInit(db, cfg_parser_.get());
72 1 : bgp_schema_Agent_ModuleInit(db, cfg_graph_.get());
73 1 : bgp_schema_Agent_ParserInit(db, cfg_parser_.get());
74 1 : IFMapAgentLinkTable_Init(db, cfg_graph_.get());
75 1 : agent_->set_ifmap_parser(cfg_parser_.get());
76 : IFMapAgentStaleCleaner *cl =
77 1 : new IFMapAgentStaleCleaner(db, cfg_graph_.get());
78 1 : agent_->set_ifmap_stale_cleaner(cl);
79 :
80 1 : IFMapAgentSandeshInit(db, cfg_parser_.get());
81 1 : }
82 :
83 0 : void AgentConfig::Register(const char *node_name, AgentDBTable *table,
84 : int need_property_id) {
85 0 : }
86 :
87 1 : void AgentConfig::RegisterDBClients(DB *db) {
88 :
89 1 : cfg_vm_interface_table_ = (static_cast<IFMapAgentTable *>
90 1 : (IFMapTable::FindTable(agent_->db(), "virtual-machine-interface")));
91 1 : assert(cfg_vm_interface_table_);
92 :
93 1 : cfg_acl_table_ = (static_cast<IFMapAgentTable *>
94 1 : (IFMapTable::FindTable(agent_->db(), "access-control-list")));
95 1 : assert(cfg_acl_table_);
96 :
97 1 : cfg_vm_table_ = (static_cast<IFMapAgentTable *>
98 1 : (IFMapTable::FindTable(agent_->db(), "virtual-machine")));
99 1 : assert(cfg_vm_table_);
100 :
101 1 : cfg_vn_table_ = (static_cast<IFMapAgentTable *>
102 1 : (IFMapTable::FindTable(agent_->db(), "virtual-network")));
103 1 : assert(cfg_vn_table_);
104 :
105 1 : cfg_sg_table_ = (static_cast<IFMapAgentTable *>
106 1 : (IFMapTable::FindTable(agent_->db(), "security-group")));
107 1 : assert(cfg_sg_table_);
108 :
109 1 : cfg_vrf_table_ = (static_cast<IFMapAgentTable *>
110 1 : (IFMapTable::FindTable(agent_->db(), "routing-instance")));
111 1 : assert(cfg_vrf_table_);
112 :
113 1 : cfg_instanceip_table_ = (static_cast<IFMapAgentTable *>
114 1 : (IFMapTable::FindTable(agent_->db(), "instance-ip")));
115 1 : assert(cfg_instanceip_table_);
116 :
117 1 : cfg_floatingip_table_ = (static_cast<IFMapAgentTable *>
118 1 : (IFMapTable::FindTable(agent_->db(), "floating-ip")));
119 1 : assert(cfg_floatingip_table_);
120 :
121 1 : cfg_aliasip_table_ = (static_cast<IFMapAgentTable *>
122 1 : (IFMapTable::FindTable(agent_->db(), "alias-ip")));
123 1 : assert(cfg_aliasip_table_);
124 :
125 1 : cfg_floatingip_pool_table_ = (static_cast<IFMapAgentTable *>
126 1 : (IFMapTable::FindTable(agent_->db(), "floating-ip-pool")));
127 1 : assert(cfg_floatingip_pool_table_);
128 :
129 1 : cfg_aliasip_pool_table_ = (static_cast<IFMapAgentTable *>
130 1 : (IFMapTable::FindTable(agent_->db(), "alias-ip-pool")));
131 1 : assert(cfg_aliasip_pool_table_);
132 :
133 1 : cfg_network_ipam_table_ = (static_cast<IFMapAgentTable *>
134 1 : (IFMapTable::FindTable(agent_->db(), "network-ipam")));
135 1 : assert(cfg_network_ipam_table_);
136 :
137 1 : cfg_vn_network_ipam_table_ = (static_cast<IFMapAgentTable *>
138 1 : (IFMapTable::FindTable(agent_->db(),
139 : "virtual-network-network-ipam")));
140 1 : assert(cfg_vn_network_ipam_table_);
141 :
142 1 : cfg_vm_port_vrf_table_ = (static_cast<IFMapAgentTable *>
143 1 : (IFMapTable::FindTable(agent_->db(),
144 : "virtual-machine-interface-routing-instance")));
145 1 : assert(cfg_vm_port_vrf_table_);
146 :
147 1 : cfg_route_table_ = (static_cast<IFMapAgentTable *>
148 1 : (IFMapTable::FindTable(agent_->db(),
149 : "interface-route-table")));
150 1 : assert(cfg_route_table_);
151 :
152 1 : cfg_service_instance_table_ = (static_cast<IFMapAgentTable *>
153 1 : (IFMapTable::FindTable(agent_->db(),
154 : "service_instance")));
155 1 : assert(cfg_service_instance_table_);
156 :
157 1 : cfg_service_template_table_ = (static_cast<IFMapAgentTable *>
158 1 : (IFMapTable::FindTable(agent_->db(),
159 : "service-template")));
160 1 : assert(cfg_service_template_table_);
161 :
162 1 : cfg_security_group_table_ = (static_cast<IFMapAgentTable *>
163 1 : (IFMapTable::FindTable(agent_->db(),
164 : "security_group")));
165 1 : assert(cfg_security_group_table_);
166 :
167 1 : cfg_subnet_table_ = (static_cast<IFMapAgentTable *>
168 1 : (IFMapTable::FindTable(agent_->db(),
169 : "subnet")));
170 1 : assert(cfg_route_table_);
171 :
172 1 : cfg_logical_port_table_ = (static_cast<IFMapAgentTable *>
173 1 : (IFMapTable::FindTable(agent_->db(),
174 : "logical-interface")));
175 1 : assert(cfg_logical_port_table_);
176 :
177 1 : cfg_physical_device_table_ = (static_cast<IFMapAgentTable *>
178 1 : (IFMapTable::FindTable(agent_->db(),
179 : "physical-router")));
180 1 : assert(cfg_physical_device_table_);
181 :
182 1 : cfg_health_check_table_ = (static_cast<IFMapAgentTable *>
183 1 : (IFMapTable::FindTable(agent_->db(),
184 : "service-health-check")));
185 1 : assert(cfg_health_check_table_);
186 :
187 1 : cfg_qos_table_ = (static_cast<IFMapAgentTable *>
188 1 : (IFMapTable::FindTable(agent_->db(),
189 : "qos-config")));
190 1 : assert(cfg_qos_table_);
191 :
192 1 : cfg_global_qos_table_ = (static_cast<IFMapAgentTable *>
193 1 : (IFMapTable::FindTable(agent_->db(),
194 : "global-qos-config")));
195 1 : assert(cfg_global_qos_table_);
196 :
197 1 : cfg_qos_queue_table_ = (static_cast<IFMapAgentTable *>
198 1 : (IFMapTable::FindTable(agent_->db(),
199 : "qos-queue")));
200 1 : assert(cfg_qos_queue_table_);
201 :
202 1 : cfg_forwarding_class_table_ = (static_cast<IFMapAgentTable *>
203 1 : (IFMapTable::FindTable(agent_->db(),
204 : "forwarding-class")));
205 1 : assert(cfg_forwarding_class_table_);
206 :
207 1 : cfg_bridge_domain_table_ = (static_cast<IFMapAgentTable *>
208 1 : (IFMapTable::FindTable(agent_->db(),
209 : "bridge-domain")));
210 1 : assert(cfg_bridge_domain_table_);
211 :
212 1 : cfg_vm_port_bridge_domain_table_ = (static_cast<IFMapAgentTable *>
213 1 : (IFMapTable::FindTable(agent_->db(),
214 : "virtual-machine-interface-bridge-domain")));
215 1 : assert(cfg_vm_port_bridge_domain_table_);
216 :
217 1 : cfg_policy_set_table_ = (static_cast<IFMapAgentTable *>
218 1 : (IFMapTable::FindTable(agent_->db(),
219 : "application-policy-set")));
220 1 : assert(cfg_policy_set_table_);
221 :
222 1 : cfg_firewall_policy_table_ = (static_cast<IFMapAgentTable *>
223 1 : (IFMapTable::FindTable(agent_->db(),
224 : "firewall-policy")));
225 1 : assert(cfg_firewall_policy_table_);
226 :
227 1 : cfg_firewall_rule_table_ = (static_cast<IFMapAgentTable *>
228 1 : (IFMapTable::FindTable(agent_->db(),
229 : "firewall-rule")));
230 1 : assert(cfg_firewall_rule_table_);
231 :
232 1 : cfg_service_group_table_ = (static_cast<IFMapAgentTable *>
233 1 : (IFMapTable::FindTable(agent_->db(),
234 : "service-group")));
235 1 : assert(cfg_service_group_table_);
236 :
237 1 : cfg_address_group_table_ = (static_cast<IFMapAgentTable *>
238 1 : (IFMapTable::FindTable(agent_->db(),
239 : "address-group")));
240 1 : assert(cfg_address_group_table_);
241 :
242 1 : cfg_firewall_policy_firewall_rule_table_ =
243 1 : (static_cast<IFMapAgentTable *>(IFMapTable::FindTable(agent_->db(),
244 : "firewall-policy-firewall-rule")));
245 1 : assert(cfg_firewall_policy_firewall_rule_table_);
246 :
247 1 : cfg_tag_table_ =
248 1 : (static_cast<IFMapAgentTable *>(IFMapTable::FindTable(agent_->db(),
249 : "tag")));
250 1 : assert(cfg_tag_table_);
251 :
252 1 : cfg_policy_set_firewall_policy_table_ =
253 1 : (static_cast<IFMapAgentTable *>(IFMapTable::FindTable(agent_->db(),
254 : "application-policy-set-firewall-policy")));
255 1 : assert(cfg_policy_set_firewall_policy_table_);
256 :
257 1 : cfg_policy_management_table_ = (static_cast<IFMapAgentTable *>(
258 1 : IFMapTable::FindTable(agent_->db(), "policy-management")));
259 1 : assert(cfg_policy_management_table_);
260 :
261 1 : cfg_project_table_ =
262 1 : (static_cast<IFMapAgentTable *>(IFMapTable::FindTable(agent_->db(),
263 : "project")));
264 1 : assert(cfg_project_table_);
265 :
266 1 : cfg_slo_table_ = (static_cast<IFMapAgentTable *>
267 1 : (IFMapTable::FindTable(agent_->db(),
268 : "security-logging-object")));
269 1 : assert(cfg_slo_table_);
270 :
271 1 : cfg_port_tuple_table_ = (static_cast<IFMapAgentTable *>
272 1 : (IFMapTable::FindTable(agent_->db(),
273 : "port-tuple")));
274 1 : assert(cfg_port_tuple_table_);
275 :
276 1 : cfg_multicast_policy_table_ = (static_cast<IFMapAgentTable *>
277 1 : (IFMapTable::FindTable(agent_->db(),
278 : "multicast-policy")));
279 1 : assert(cfg_multicast_policy_table_);
280 1 : }
281 :
282 1 : void AgentConfig::Init() {
283 1 : cfg_filter_->Init();
284 1 : cfg_mirror_table_->Init();
285 1 : cfg_intf_mirror_table_->Init();
286 1 : }
287 :
288 1 : void AgentConfig::InitDone() {
289 1 : }
290 :
291 1 : void AgentConfig::Shutdown() {
292 1 : cfg_filter_->Shutdown();
293 :
294 1 : cfg_mirror_table_->Shutdown();
295 1 : cfg_intf_mirror_table_->Shutdown();
296 :
297 1 : agent_->set_ifmap_parser(NULL);
298 :
299 1 : agent_->ifmap_stale_cleaner()->Clear();
300 1 : delete agent_->ifmap_stale_cleaner();
301 1 : agent_->set_ifmap_stale_cleaner(NULL);
302 1 : }
|