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