Line data Source code
1 : /*
2 : * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3 : */
4 : #include <base/os.h>
5 : #include <iostream>
6 : #include <string>
7 : #include <fstream>
8 : #include <pugixml/pugixml.hpp>
9 : #include <boost/uuid/uuid.hpp>
10 :
11 : #include <test/test_cmn_util.h>
12 : #include <pkt/test/test_pkt_util.h>
13 : #include <net/tunnel_encap_type.h>
14 : #include <pkt/flow_mgmt.h>
15 : #include <oper/global_vrouter.h>
16 : #include "test_xml.h"
17 : #include "test_xml_oper.h"
18 : #include "test_xml_validate.h"
19 : #include "test_xml_packet.h"
20 :
21 : using namespace std;
22 : using namespace pugi;
23 : using namespace boost::uuids;
24 : using namespace AgentUtXmlUtils;
25 :
26 206 : AgentUtXmlValidationNode *CreateValidateNode(const string &type,
27 : const string &name, const uuid &id,
28 : const xml_node &node) {
29 206 : if (type == "global-vrouter-config")
30 3 : return new AgentUtXmlGlobalVrouterValidate(name, id, node);
31 203 : if (type == "virtual-network" || type == "vn")
32 39 : return new AgentUtXmlVnValidate(name, id, node);
33 164 : if (type == "virtual-machine" || type == "vm")
34 14 : return new AgentUtXmlVmValidate(name, id, node);
35 150 : if (type == "vxlan")
36 30 : return new AgentUtXmlVxlanValidate(name, id, node);
37 220 : if (type == "virtual-machine-interface" || type == "vm-interface"
38 220 : || type == "vmi")
39 53 : return new AgentUtXmlVmInterfaceValidate(name, id, node);
40 67 : if (type == "ethernet-interface" || type == "eth-port")
41 0 : return new AgentUtXmlEthInterfaceValidate(name, id, node);
42 67 : if (type == "flow")
43 45 : return new AgentUtXmlFlowValidate(name, node);
44 22 : if (type == "routing-instance" || type == "vrf")
45 19 : return new AgentUtXmlVrfValidate(name, node);
46 3 : if (type == "access-control-list" || type == "acl")
47 0 : return new AgentUtXmlAclValidate(name, node);
48 3 : if (type == "pkt-parse")
49 3 : return new AgentUtXmlPktParseValidate(name, node);
50 0 : if (type == "fdb")
51 0 : return new AgentUtXmlL2RouteValidate(name, node);
52 0 : if (type == "l3-route")
53 0 : return new AgentUtXmlL3RouteValidate(name, node);
54 0 : return NULL;
55 : }
56 :
57 318 : AgentUtXmlNode *CreateNode(const string &type, const string &name,
58 : const uuid &id, const xml_node &node,
59 : AgentUtXmlTestCase *test_case) {
60 318 : if (type == "global-vrouter-config")
61 12 : return new AgentUtXmlGlobalVrouter(name, id, node, test_case);
62 306 : if (type == "virtual-network" || type == "vn")
63 73 : return new AgentUtXmlVn(name, id, node, test_case);
64 233 : if (type == "virtual-machine" || type == "vm")
65 43 : return new AgentUtXmlVm(name, id, node, test_case);
66 338 : if (type == "virtual-machine-interface" || type == "vm-interface"
67 338 : || type == "vmi")
68 67 : return new AgentUtXmlVmInterface(name, id, node, test_case);
69 123 : if (type == "ethernet-interface" || type == "eth-port")
70 0 : return new AgentUtXmlEthInterface(name, id, node, test_case);
71 123 : if (type == "routing-instance" || type == "vrf")
72 49 : return new AgentUtXmlVrf(name, id, node, test_case);
73 74 : if (type == "access-control-list" || type == "acl")
74 11 : return new AgentUtXmlAcl(name, id, node, test_case);
75 126 : if (type == "virtual-machine-interface-routing-instance" ||
76 63 : type == "vmi-vrf")
77 35 : return new AgentUtXmlVmiVrf(name, id, node, test_case);
78 28 : if (type == "fdb" || type == "l2-route")
79 13 : return new AgentUtXmlL2Route(name, id, node, test_case);
80 15 : if (type == "l3-route")
81 6 : return new AgentUtXmlL3Route(name, id, node, test_case);
82 9 : if (type == "sg" || type == "securiy-group")
83 3 : return new AgentUtXmlSg(name, id, node, test_case);
84 6 : if (type == "iip" || type == "instance-ip")
85 6 : return new AgentUtXmlInstanceIp(name, id, node, test_case);
86 0 : return NULL;
87 : }
88 :
89 21 : void AgentUtXmlOperInit(AgentUtXmlTest *test) {
90 21 : test->AddConfigEntry("global-vrouter-config", CreateNode);
91 :
92 21 : test->AddConfigEntry("virtual-network", CreateNode);
93 21 : test->AddConfigEntry("vn", CreateNode);
94 :
95 21 : test->AddConfigEntry("virtual-machine", CreateNode);
96 21 : test->AddConfigEntry("vm", CreateNode);
97 :
98 21 : test->AddConfigEntry("vxlan", CreateNode);
99 :
100 21 : test->AddConfigEntry("virtual-machine-interface", CreateNode);
101 21 : test->AddConfigEntry("vm-interface", CreateNode);
102 21 : test->AddConfigEntry("vmi", CreateNode);
103 :
104 21 : test->AddConfigEntry("ethernet-interface", CreateNode);
105 21 : test->AddConfigEntry("eth-port", CreateNode);
106 :
107 21 : test->AddConfigEntry("routing-instance", CreateNode);
108 21 : test->AddConfigEntry("vrf", CreateNode);
109 :
110 21 : test->AddConfigEntry("access-control-list", CreateNode);
111 21 : test->AddConfigEntry("acl", CreateNode);
112 :
113 21 : test->AddConfigEntry("virtual-machine-interface-routing-instance",
114 : CreateNode);
115 21 : test->AddConfigEntry("vmi-vrf", CreateNode);
116 21 : test->AddConfigEntry("fdb", CreateNode);
117 21 : test->AddConfigEntry("l2-route", CreateNode);
118 21 : test->AddConfigEntry("l3-route", CreateNode);
119 21 : test->AddConfigEntry("sg", CreateNode);
120 21 : test->AddConfigEntry("security-group", CreateNode);
121 21 : test->AddConfigEntry("instance-ip", CreateNode);
122 :
123 21 : test->AddValidateEntry("global-vrouter-config", CreateValidateNode);
124 :
125 21 : test->AddValidateEntry("virtual-network", CreateValidateNode);
126 21 : test->AddValidateEntry("vn", CreateValidateNode);
127 21 : test->AddValidateEntry("vxlan", CreateValidateNode);
128 21 : test->AddValidateEntry("virtual-machine", CreateValidateNode);
129 21 : test->AddValidateEntry("vm", CreateValidateNode);
130 21 : test->AddValidateEntry("virtual-machine-interface", CreateValidateNode);
131 21 : test->AddValidateEntry("vm-interface", CreateValidateNode);
132 21 : test->AddValidateEntry("vmi", CreateValidateNode);
133 21 : test->AddValidateEntry("ethernet-interface", CreateValidateNode);
134 21 : test->AddValidateEntry("eth-port", CreateValidateNode);
135 21 : test->AddValidateEntry("flow", CreateValidateNode);
136 21 : test->AddValidateEntry("routing-instance", CreateValidateNode);
137 21 : test->AddValidateEntry("vrf", CreateValidateNode);
138 21 : test->AddValidateEntry("access-control-list", CreateValidateNode);
139 21 : test->AddValidateEntry("acl", CreateValidateNode);
140 21 : test->AddValidateEntry("pkt-parse", CreateValidateNode);
141 21 : test->AddValidateEntry("fdb", CreateValidateNode);
142 21 : test->AddValidateEntry("l2-route", CreateValidateNode);
143 21 : test->AddValidateEntry("l3-route", CreateValidateNode);
144 21 : }
145 :
146 : /////////////////////////////////////////////////////////////////////////////
147 : // AgentUtXmlGlobalVrouter routines
148 : /////////////////////////////////////////////////////////////////////////////
149 12 : AgentUtXmlGlobalVrouter::AgentUtXmlGlobalVrouter(const std::string &name,
150 : const uuid &id,
151 : const xml_node &node,
152 12 : AgentUtXmlTestCase *test_case) :
153 12 : AgentUtXmlConfig(name, id, node, test_case) {
154 12 : }
155 :
156 24 : AgentUtXmlGlobalVrouter::~AgentUtXmlGlobalVrouter() {
157 24 : }
158 :
159 12 : bool AgentUtXmlGlobalVrouter::ReadXml() {
160 12 : if (AgentUtXmlConfig::ReadXml() == false) {
161 0 : return false;
162 : }
163 12 : GetStringAttribute(node(), "vxlan-mode", &vxlan_mode_);
164 12 : bool got_attr = GetIntAttribute(node(), "flow-export-rate",
165 : &flow_export_rate_);
166 12 : if (!got_attr) {
167 10 : flow_export_rate_ = 0;
168 : }
169 12 : return true;
170 : }
171 :
172 12 : bool AgentUtXmlGlobalVrouter::ToXml(xml_node *parent) {
173 12 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
174 12 : AddXmlNodeWithValue(&n, "name", name());
175 12 : if (!vxlan_mode().empty()) {
176 12 : AddXmlNodeWithValue(&n, "vxlan-network-identifier-mode", vxlan_mode());
177 : }
178 12 : if (flow_export_rate() != 0) {
179 2 : AddXmlNodeWithIntValue(&n, "flow-export-rate", flow_export_rate());
180 : }
181 12 : AddIdPerms(&n);
182 12 : return true;
183 : }
184 :
185 12 : void AgentUtXmlGlobalVrouter::ToString(string *str) {
186 12 : AgentUtXmlConfig::ToString(str);
187 12 : *str += "\n";
188 12 : return;
189 : }
190 :
191 24 : string AgentUtXmlGlobalVrouter::NodeType() {
192 24 : return "global-vrouter-config";
193 : }
194 :
195 : /////////////////////////////////////////////////////////////////////////////
196 : // AgentUtXmlVn routines
197 : /////////////////////////////////////////////////////////////////////////////
198 73 : AgentUtXmlVn::AgentUtXmlVn(const string &name, const uuid &id,
199 : const xml_node &node,
200 73 : AgentUtXmlTestCase *test_case) :
201 73 : AgentUtXmlConfig(name, id, node, test_case) {
202 73 : }
203 :
204 146 : AgentUtXmlVn::~AgentUtXmlVn() {
205 146 : }
206 :
207 :
208 73 : bool AgentUtXmlVn::ReadXml() {
209 73 : if (AgentUtXmlConfig::ReadXml() == false) {
210 0 : return false;
211 : }
212 73 : GetStringAttribute(node(), "vxlan-id", &vxlan_id_);
213 73 : GetStringAttribute(node(), "network-id", &network_id_);
214 73 : GetStringAttribute(node(), "flood-unknown-unicast", &flood_unknown_unicast_);
215 73 : return true;
216 : }
217 :
218 73 : bool AgentUtXmlVn::ToXml(xml_node *parent) {
219 73 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
220 73 : AddXmlNodeWithValue(&n, "name", name());
221 73 : if (!network_id().empty()) {
222 33 : xml_node n1 = n.append_child("virtual-network-properties");
223 33 : AddXmlNodeWithValue(&n1, "network-id", network_id());
224 : }
225 73 : if (!vxlan_id().empty() && op_delete() == false) {
226 27 : xml_node n1 = n.append_child("virtual-network-properties");
227 27 : AddXmlNodeWithValue(&n1, "vxlan-network-identifier", vxlan_id());
228 : }
229 :
230 73 : if (!flood_unknown_unicast().empty() && op_delete() == false) {
231 10 : if (flood_unknown_unicast() == "true" ||
232 2 : flood_unknown_unicast() == "yes")
233 6 : AddXmlNodeWithValue(&n, "flood-unknown-unicast", "true");
234 : else
235 2 : AddXmlNodeWithValue(&n, "flood-unknown-unicast", "false");
236 : }
237 73 : AddIdPerms(&n);
238 73 : return true;
239 : }
240 :
241 73 : void AgentUtXmlVn::ToString(string *str) {
242 73 : AgentUtXmlConfig::ToString(str);
243 73 : *str += "\n";
244 73 : return;
245 : }
246 :
247 146 : string AgentUtXmlVn::NodeType() {
248 146 : return "virtual-network";
249 : }
250 :
251 : /////////////////////////////////////////////////////////////////////////////
252 : // AgentUtXmlVm routines
253 : /////////////////////////////////////////////////////////////////////////////
254 43 : AgentUtXmlVm::AgentUtXmlVm(const string &name, const uuid &id,
255 : const xml_node &node,
256 43 : AgentUtXmlTestCase *test_case) :
257 43 : AgentUtXmlConfig(name, id, node, test_case) {
258 43 : }
259 :
260 86 : AgentUtXmlVm::~AgentUtXmlVm() {
261 86 : }
262 :
263 :
264 43 : bool AgentUtXmlVm::ReadXml() {
265 43 : return AgentUtXmlConfig::ReadXml();
266 : }
267 :
268 43 : bool AgentUtXmlVm::ToXml(xml_node *parent) {
269 43 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
270 43 : AddXmlNodeWithValue(&n, "name", name());
271 43 : AddIdPerms(&n);
272 43 : return true;
273 : }
274 :
275 43 : void AgentUtXmlVm::ToString(string *str) {
276 43 : AgentUtXmlConfig::ToString(str);
277 43 : *str += "\n";
278 43 : return;
279 : }
280 :
281 86 : string AgentUtXmlVm::NodeType() {
282 86 : return "virtual-machine";
283 : }
284 :
285 : /////////////////////////////////////////////////////////////////////////////
286 : // AgentUtXmlVmInterface routines
287 : /////////////////////////////////////////////////////////////////////////////
288 67 : AgentUtXmlVmInterface::AgentUtXmlVmInterface(const string &name,
289 : const uuid &id,
290 : const xml_node &node,
291 67 : AgentUtXmlTestCase *test_case) :
292 67 : AgentUtXmlConfig(name, id, node, test_case), vlan_tag_(-1), parent_vmi_() {
293 67 : }
294 :
295 134 : AgentUtXmlVmInterface::~AgentUtXmlVmInterface() {
296 134 : }
297 :
298 67 : bool AgentUtXmlVmInterface::ReadXml() {
299 67 : if (AgentUtXmlConfig::ReadXml() == false)
300 0 : return false;
301 :
302 67 : GetStringAttribute(node(), "mac", &mac_);
303 :
304 67 : vm_name_ = "";
305 67 : vn_uuid_ = nil_uuid();
306 67 : vm_uuid_ = nil_uuid();
307 67 : vrf_ = "";
308 67 : add_nova_ = false;
309 67 : ip_ = "0.0.0.0";
310 :
311 67 : GetStringAttribute(node(), "vn-name", &vn_name_);
312 67 : uint16_t id = 0;
313 67 : GetUintAttribute(node(), "vn-uuid", &id);
314 67 : if (id) {
315 67 : vn_uuid_ = MakeUuid(id);
316 : }
317 :
318 67 : GetStringAttribute(node(), "vm-name", &vm_name_);
319 67 : id = 0;
320 67 : GetUintAttribute(node(), "vm-uuid", &id);
321 67 : if (id) {
322 61 : vm_uuid_ = MakeUuid(id);
323 : }
324 :
325 67 : GetStringAttribute(node(), "vrf", &vrf_);
326 67 : GetStringAttribute(node(), "ip", &ip_);
327 :
328 67 : string str;
329 155 : if (GetStringAttribute(node(), "nova", &str) ||
330 88 : GetUintAttribute(node(), "nova", &id)) {
331 46 : add_nova_ = true;
332 : }
333 :
334 155 : if (GetStringAttribute(node(), "nova", &str) ||
335 88 : GetUintAttribute(node(), "nova", &id)) {
336 46 : add_nova_ = true;
337 : }
338 :
339 67 : vlan_tag_ = 0;
340 67 : GetUintAttribute(node(), "vlan-tag", &vlan_tag_);
341 67 : GetStringAttribute(node(), "parent-vmi", &parent_vmi_);
342 :
343 67 : xml_attribute attr = node().attribute("fat-flow");
344 72 : for (;attr != xml_attribute(); attr = attr.next_attribute()) {
345 5 : if (std::string(attr.name()) == "fat-flow") {
346 5 : uint32_t value = attr.as_uint();
347 5 : fat_flow_port_.push_back(value);
348 : } else {
349 0 : break;
350 : }
351 : }
352 67 : return true;
353 67 : }
354 :
355 67 : bool AgentUtXmlVmInterface::ToXml(xml_node *parent) {
356 67 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
357 67 : AddXmlNodeWithValue(&n, "name", name());
358 :
359 67 : if (op_delete() == false) {
360 33 : xml_node n1 = n.append_child("virtual-machine-interface-mac-address");
361 33 : AddXmlNodeWithValue(&n1, "mac-address", mac_);
362 33 : AddIdPerms(&n);
363 :
364 33 : if (vlan_tag_ > 0) {
365 3 : n1 = n.append_child("virtual-machine-interface-properties");
366 : char buff[32];
367 3 : sprintf(buff, "%d", vlan_tag_);
368 3 : AddXmlNodeWithValue(&n1, "sub-interface-vlan-tag", buff);
369 : }
370 :
371 33 : n1 = n.append_child("virtual-machine-interface-fat-flow-protocols");
372 33 : std::vector<uint16_t>::const_iterator it = fat_flow_port_.begin();
373 36 : for(;it != fat_flow_port_.end(); it++) {
374 3 : xml_node n2 = n1.append_child("fat-flow-protocol");
375 3 : AddXmlNodeWithValue(&n2, "protocol", "UDP");
376 3 : stringstream s;
377 3 : s << *it;
378 3 : AddXmlNodeWithValue(&n2, "port", s.str());
379 3 : }
380 : }
381 :
382 67 : if (add_nova_) {
383 46 : boost::system::error_code ec;
384 46 : Ip4Address ip = Ip4Address::from_string(ip_, ec);
385 46 : NovaIntfAdd(op_delete(), id(), ip, vm_uuid_, vm_uuid_, name(), mac_,
386 46 : vm_name_);
387 : }
388 :
389 67 : if (vn_name_ != "") {
390 67 : LinkXmlNode(parent, NodeType(), name(), "virtual-network", vn_name_);
391 : }
392 :
393 67 : if (vm_name_ != "") {
394 61 : LinkXmlNode(parent, NodeType(), name(), "virtual-machine", vm_name_);
395 : }
396 :
397 67 : if (vrf_ != "") {
398 67 : string str = name() + "-" + vm_name_;
399 67 : LinkXmlNode(parent, "virtual-machine-interface-routing-instance",
400 67 : str, "routing-instance", vrf_);
401 :
402 67 : LinkXmlNode(parent, NodeType(), name(),
403 : "virtual-machine-interface-routing-instance", str);
404 67 : }
405 :
406 67 : if (parent_vmi_ != "") {
407 3 : LinkXmlNode(parent, NodeType(), name(), "virtual-machine-interface",
408 3 : parent_vmi_);
409 : }
410 67 : return true;
411 : }
412 :
413 67 : void AgentUtXmlVmInterface::ToString(string *str) {
414 67 : AgentUtXmlConfig::ToString(str);
415 67 : *str += "\n";
416 67 : return;
417 : }
418 :
419 332 : string AgentUtXmlVmInterface::NodeType() {
420 332 : return "virtual-machine-interface";
421 : }
422 :
423 : /////////////////////////////////////////////////////////////////////////////
424 : // AgentUtXmlEthInterface routines
425 : /////////////////////////////////////////////////////////////////////////////
426 0 : AgentUtXmlEthInterface::AgentUtXmlEthInterface(const string &name,
427 : const uuid &id,
428 : const xml_node &node,
429 0 : AgentUtXmlTestCase *test_case) :
430 0 : AgentUtXmlConfig(name, id, node, false, test_case) {
431 0 : }
432 :
433 0 : AgentUtXmlEthInterface::~AgentUtXmlEthInterface() {
434 0 : }
435 :
436 0 : bool AgentUtXmlEthInterface::ReadXml() {
437 0 : return AgentUtXmlConfig::ReadXml();
438 : }
439 :
440 0 : bool AgentUtXmlEthInterface::ToXml(xml_node *parent) {
441 0 : assert(0);
442 : return true;
443 : }
444 :
445 0 : void AgentUtXmlEthInterface::ToString(string *str) {
446 0 : AgentUtXmlConfig::ToString(str);
447 0 : *str += "\n";
448 0 : return;
449 : }
450 :
451 0 : string AgentUtXmlEthInterface::NodeType() {
452 0 : return "physical-interface";
453 : }
454 :
455 0 : bool AgentUtXmlEthInterface::Run() {
456 0 : cout << "Create Ethernet Interface" << endl;
457 0 : return true;
458 : }
459 : /////////////////////////////////////////////////////////////////////////////
460 : // AgentUtXmlVrf routines
461 : /////////////////////////////////////////////////////////////////////////////
462 49 : AgentUtXmlVrf::AgentUtXmlVrf(const string &name, const uuid &id,
463 : const xml_node &node,
464 49 : AgentUtXmlTestCase *test_case) :
465 49 : AgentUtXmlConfig(name, id, node, test_case) {
466 49 : }
467 :
468 98 : AgentUtXmlVrf::~AgentUtXmlVrf() {
469 98 : }
470 :
471 :
472 49 : bool AgentUtXmlVrf::ReadXml() {
473 49 : if (AgentUtXmlConfig::ReadXml() == false)
474 0 : return false;
475 :
476 49 : GetStringAttribute(node(), "vn", &vn_name_);
477 49 : return true;
478 : }
479 :
480 49 : bool AgentUtXmlVrf::ToXml(xml_node *parent) {
481 49 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
482 49 : AddXmlNodeWithValue(&n, "name", name());
483 49 : AddIdPerms(&n);
484 49 : if (vn_name_ != "") {
485 20 : LinkXmlNode(parent, NodeType(), name(), "virtual-network", vn_name_);
486 : }
487 49 : return true;
488 : }
489 :
490 49 : void AgentUtXmlVrf::ToString(string *str) {
491 49 : AgentUtXmlConfig::ToString(str);
492 49 : *str += "\n";
493 49 : return;
494 : }
495 :
496 118 : string AgentUtXmlVrf::NodeType() {
497 118 : return "routing-instance";
498 : }
499 :
500 : /////////////////////////////////////////////////////////////////////////////
501 : // AgentUtXmlVmiVrf routines
502 : /////////////////////////////////////////////////////////////////////////////
503 35 : AgentUtXmlVmiVrf::AgentUtXmlVmiVrf(const string &name, const uuid &id,
504 : const xml_node &node,
505 35 : AgentUtXmlTestCase *test_case) :
506 35 : AgentUtXmlConfig(name, id, node, test_case) {
507 35 : }
508 :
509 70 : AgentUtXmlVmiVrf::~AgentUtXmlVmiVrf() {
510 70 : }
511 :
512 :
513 35 : bool AgentUtXmlVmiVrf::ReadXml() {
514 35 : return AgentUtXmlConfig::ReadXml();
515 : }
516 :
517 35 : bool AgentUtXmlVmiVrf::ToXml(xml_node *parent) {
518 35 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
519 35 : AddXmlNodeWithValue(&n, "name", name());
520 :
521 35 : xml_node n1 = n.append_child("value");
522 35 : AddXmlNodeWithValue(&n1, "direction", "both");
523 35 : AddXmlNodeWithValue(&n1, "vlan-tag", "0");
524 :
525 35 : AddIdPerms(&n);
526 35 : return true;
527 : }
528 :
529 35 : void AgentUtXmlVmiVrf::ToString(string *str) {
530 35 : AgentUtXmlConfig::ToString(str);
531 35 : *str += "\n";
532 35 : return;
533 : }
534 :
535 70 : string AgentUtXmlVmiVrf::NodeType() {
536 70 : return "virtual-machine-interface-routing-instance";
537 : }
538 :
539 : /////////////////////////////////////////////////////////////////////////////
540 : // AgentUtXmlAcl routines
541 : /////////////////////////////////////////////////////////////////////////////
542 11 : AgentUtXmlAcl::AgentUtXmlAcl(const string &name, const uuid &id,
543 : const xml_node &node,
544 11 : AgentUtXmlTestCase *test_case) :
545 11 : AgentUtXmlConfig(name, id, node, test_case) {
546 11 : }
547 :
548 22 : AgentUtXmlAcl::~AgentUtXmlAcl() {
549 22 : }
550 :
551 11 : bool AgentUtXmlAcl::ReadXml() {
552 11 : if (AgentUtXmlConfig::ReadXml() == false)
553 0 : return false;
554 :
555 23 : for (xml_node n = node().first_child(); n; n = n.next_sibling()) {
556 12 : if (strcmp(n.name(), "ace") != 0) {
557 0 : continue;
558 : }
559 :
560 12 : Ace ace;
561 :
562 12 : GetUintAttribute(n, "src-sg", (uint16_t *)&ace.src_sg_);
563 12 : GetUintAttribute(n, "dst-sg", (uint16_t *)&ace.dst_sg_);
564 :
565 12 : GetStringAttribute(n, "src-vn", &ace.src_vn_);
566 12 : GetStringAttribute(n, "dst-vn", &ace.dst_vn_);
567 :
568 12 : GetStringAttribute(n, "src-ip", &ace.src_ip_);
569 12 : GetUintAttribute(n, "src-plen", (uint16_t *)&ace.src_ip_plen_);
570 12 : GetStringAttribute(n, "dst-ip", &ace.dst_ip_);
571 12 : GetUintAttribute(n, "dst-plen", (uint16_t *)&ace.dst_ip_plen_);
572 :
573 12 : std::string str;
574 12 : GetStringAttribute(n, "sport", &str);
575 12 : if (str.empty()) {
576 0 : ace.sport_begin_ = 0;
577 0 : ace.sport_end_ = 65535;
578 : } else {
579 12 : sscanf(str.c_str(), "%d:%d", &ace.sport_begin_, &ace.sport_end_);
580 : }
581 :
582 12 : GetStringAttribute(n, "dport", &str);
583 12 : if (str.empty()) {
584 0 : ace.dport_begin_ = 0;
585 0 : ace.dport_end_ = 65535;
586 : } else {
587 12 : sscanf(str.c_str(), "%d:%d", &ace.dport_begin_, &ace.dport_end_);
588 : }
589 :
590 12 : GetStringAttribute(n, "action", &ace.action_);
591 12 : GetStringAttribute(n, "direction", &ace.direction_);
592 12 : if (ace.direction_ != ">")
593 12 : ace.direction_ = "<";
594 :
595 12 : ace_list_.push_back(ace);
596 12 : }
597 :
598 11 : return true;
599 : }
600 :
601 11 : bool AgentUtXmlAcl::ToXml(xml_node *parent) {
602 11 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
603 11 : AddXmlNodeWithValue(&n, "name", name());
604 :
605 11 : xml_node n1 = n.append_child("access-control-list-entries");
606 11 : AddXmlNodeWithValue(&n1, "dynamic", "false");
607 :
608 23 : for (AceList::iterator it = ace_list_.begin(); it != ace_list_.end();
609 12 : it++) {
610 12 : xml_node n2 = n1.append_child("acl-rule");
611 :
612 12 : xml_node n3 = n2.append_child("match-condition");
613 12 : AddXmlNodeWithValue(&n3, "protocol", "any");
614 :
615 12 : xml_node n4 = n3.append_child("src-address");
616 :
617 12 : Ace ace = (*it);
618 12 : if (ace.src_sg_) {
619 8 : AddXmlNodeWithIntValue(&n4, "security-group", ace.src_sg_);
620 : }
621 :
622 12 : if (ace.src_vn_ != "") {
623 0 : AddXmlNodeWithValue(&n4, "virtual-network", ace.src_vn_);
624 : }
625 :
626 12 : if (ace.src_ip_ != "") {
627 4 : xml_node n5 = n4.append_child("subnet");
628 4 : AddXmlNodeWithValue(&n5, "ip-prefix", ace.src_ip_);
629 4 : AddXmlNodeWithIntValue(&n5, "ip-prefix-len", ace.src_ip_plen_);
630 : }
631 :
632 12 : n4 = n3.append_child("dst-address");
633 12 : if (ace.dst_sg_) {
634 8 : AddXmlNodeWithIntValue(&n4, "security-group", ace.dst_sg_);
635 : }
636 :
637 12 : if (ace.dst_vn_ != "") {
638 0 : AddXmlNodeWithValue(&n4, "virtual-network", ace.dst_vn_);
639 : }
640 :
641 12 : if (ace.dst_ip_ != "") {
642 4 : xml_node n5 = n4.append_child("subnet");
643 4 : AddXmlNodeWithValue(&n5, "ip-prefix", ace.dst_ip_);
644 4 : AddXmlNodeWithIntValue(&n5, "ip-prefix-len", ace.dst_ip_plen_);
645 : }
646 :
647 12 : stringstream str;
648 12 : n4 = n3.append_child("src-port");
649 12 : str.str("");
650 12 : str << ace.sport_begin_;
651 12 : AddXmlNodeWithValue(&n4, "start-port", str.str());
652 12 : str.str("");
653 12 : str << ace.sport_end_;
654 12 : AddXmlNodeWithValue(&n4, "end-port", str.str());
655 :
656 12 : n4 = n3.append_child("dst-port");
657 12 : str.str("");
658 12 : str << ace.dport_begin_;
659 12 : AddXmlNodeWithValue(&n4, "start-port", str.str());
660 12 : str.str("");
661 12 : str << ace.dport_end_;
662 12 : AddXmlNodeWithValue(&n4, "end-port", str.str());
663 :
664 12 : n3 = n2.append_child("action-list");
665 12 : AddXmlNodeWithValue(&n3, "simple-action", ace.action_);
666 12 : }
667 :
668 11 : AddIdPerms(&n);
669 11 : return true;
670 : }
671 :
672 11 : void AgentUtXmlAcl::ToString(string *str) {
673 11 : AgentUtXmlConfig::ToString(str);
674 11 : *str += "\n";
675 11 : return;
676 : }
677 :
678 22 : string AgentUtXmlAcl::NodeType() {
679 22 : return "access-control-list";
680 : }
681 :
682 : /////////////////////////////////////////////////////////////////////////////
683 : // AgentUtXmlSg routines
684 : /////////////////////////////////////////////////////////////////////////////
685 3 : AgentUtXmlSg::AgentUtXmlSg(const string &name, const uuid &id,
686 : const xml_node &node,
687 3 : AgentUtXmlTestCase *test_case) :
688 3 : AgentUtXmlConfig(name, id, node, test_case) {
689 3 : }
690 :
691 6 : AgentUtXmlSg::~AgentUtXmlSg() {
692 6 : }
693 :
694 3 : bool AgentUtXmlSg::ReadXml() {
695 3 : if (AgentUtXmlConfig::ReadXml() == false)
696 0 : return false;
697 :
698 3 : GetStringAttribute(node(), "sg_id", &sg_id_);
699 3 : GetStringAttribute(node(), "ingress", &ingress_);
700 3 : GetStringAttribute(node(), "egress", &egress_);
701 3 : return true;
702 : }
703 :
704 3 : bool AgentUtXmlSg::ToXml(xml_node *parent) {
705 3 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
706 3 : AddXmlNodeWithValue(&n, "name", name());
707 3 : AddXmlNodeWithValue(&n, "security-group-id", sg_id_);
708 3 : AddIdPerms(&n);
709 :
710 3 : string str;
711 3 : if (ingress_ != "") {
712 3 : str = "ingress-access-control-list-" + ingress_;
713 3 : LinkXmlNode(parent, NodeType(), name(), "access-control-list", str);
714 : }
715 :
716 3 : if (egress_ != "") {
717 3 : str = "egress-access-control-list-" + egress_;
718 3 : LinkXmlNode(parent, NodeType(), name(), "access-control-list", str);
719 : }
720 :
721 3 : return true;
722 3 : }
723 :
724 3 : void AgentUtXmlSg::ToString(string *str) {
725 3 : AgentUtXmlConfig::ToString(str);
726 3 : *str += "\n";
727 3 : return;
728 : }
729 :
730 12 : string AgentUtXmlSg::NodeType() {
731 12 : return "security-group";
732 : }
733 :
734 : /////////////////////////////////////////////////////////////////////////////
735 : // AgentUtXmlTag routines
736 : /////////////////////////////////////////////////////////////////////////////
737 0 : AgentUtXmlTag::AgentUtXmlTag(const string &name, const uuid &id,
738 : const xml_node &node,
739 0 : AgentUtXmlTestCase *test_case) :
740 0 : AgentUtXmlConfig(name, id, node, test_case) {
741 0 : }
742 :
743 0 : AgentUtXmlTag::~AgentUtXmlTag() {
744 0 : }
745 :
746 0 : bool AgentUtXmlTag::ReadXml() {
747 0 : if (AgentUtXmlConfig::ReadXml() == false)
748 0 : return false;
749 :
750 0 : GetStringAttribute(node(), "tag_id", &tag_id_);
751 0 : return true;
752 : }
753 :
754 0 : bool AgentUtXmlTag::ToXml(xml_node *parent) {
755 0 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
756 0 : AddXmlNodeWithValue(&n, "name", name());
757 0 : AddXmlNodeWithValue(&n, "tag-id", tag_id_);
758 0 : AddIdPerms(&n);
759 :
760 0 : return true;
761 : }
762 :
763 0 : void AgentUtXmlTag::ToString(string *str) {
764 0 : AgentUtXmlConfig::ToString(str);
765 0 : *str += "\n";
766 0 : return;
767 : }
768 :
769 0 : string AgentUtXmlTag::NodeType() {
770 0 : return "tag";
771 : }
772 :
773 : /////////////////////////////////////////////////////////////////////////////
774 : // AgentUtXmlInstanceIp routines
775 : /////////////////////////////////////////////////////////////////////////////
776 6 : AgentUtXmlInstanceIp::AgentUtXmlInstanceIp(const string &name, const uuid &id,
777 : const xml_node &node,
778 6 : AgentUtXmlTestCase *test_case) :
779 6 : AgentUtXmlConfig(name, id, node, test_case) {
780 6 : }
781 :
782 12 : AgentUtXmlInstanceIp::~AgentUtXmlInstanceIp() {
783 12 : }
784 :
785 :
786 6 : bool AgentUtXmlInstanceIp::ReadXml() {
787 6 : if (AgentUtXmlConfig::ReadXml() == false)
788 0 : return false;
789 :
790 6 : GetStringAttribute(node(), "ip", &ip_);
791 6 : GetStringAttribute(node(), "vmi", &vmi_);
792 6 : std::string str;
793 6 : if (GetStringAttribute(node(), "ecmp", &str) == true) {
794 2 : ecmp_ = true;
795 : } else {
796 4 : ecmp_ = false;
797 : }
798 :
799 6 : return true;
800 6 : }
801 :
802 6 : bool AgentUtXmlInstanceIp::ToXml(xml_node *parent) {
803 6 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
804 6 : AddXmlNodeWithValue(&n, "name", name());
805 6 : if (op_delete() == false) {
806 4 : AddXmlNodeWithValue(&n, "instance-ip-address", ip_);
807 4 : if (ecmp_ == true) {
808 2 : AddXmlNodeWithValue(&n, "instance-ip-mode", "active-active");
809 : }
810 4 : AddIdPerms(&n);
811 : }
812 :
813 6 : if (vmi_ != "") {
814 6 : LinkXmlNode(parent, NodeType(), name(),
815 6 : "virtual-machine-interface", vmi_);
816 : }
817 :
818 6 : return true;
819 : }
820 :
821 6 : void AgentUtXmlInstanceIp::ToString(string *str) {
822 6 : AgentUtXmlConfig::ToString(str);
823 6 : *str += "\n";
824 6 : return;
825 : }
826 :
827 18 : string AgentUtXmlInstanceIp::NodeType() {
828 18 : return "instance-ip";
829 : }
830 :
831 : /////////////////////////////////////////////////////////////////////////////
832 : // AgentUtXmlNova routines
833 : /////////////////////////////////////////////////////////////////////////////
834 0 : AgentUtXmlNova::AgentUtXmlNova(const string &name, const uuid &id,
835 : const xml_node &node,
836 0 : AgentUtXmlTestCase *test_case) :
837 0 : AgentUtXmlConfig(name, id, node, false, test_case) {
838 0 : }
839 :
840 0 : AgentUtXmlNova::~AgentUtXmlNova() {
841 0 : }
842 :
843 0 : bool AgentUtXmlNova::ReadXml() {
844 0 : if (AgentUtXmlNode::ReadXml() == false)
845 0 : return false;
846 :
847 0 : if (GetStringAttribute(node(), "mac", &mac_) == false) {
848 0 : cout << "Attribute \"mac\" not specified for nova. Skipping"
849 0 : << endl;
850 0 : return false;
851 : }
852 :
853 : uint16_t num;
854 0 : if (GetUintAttribute(node(), "vm-uuid", &num) == false) {
855 0 : cout << "Attribute \"vm-uuid\" not specified for nova. Skipping"
856 0 : << endl;
857 0 : return false;
858 : }
859 0 : vm_uuid_ = MakeUuid(num);
860 :
861 0 : if (GetUintAttribute(node(), "vn-uuid", &num) == false) {
862 0 : cout << "Attribute \"vn-uuid\" not specified for nova. Skipping"
863 0 : << endl;
864 0 : return false;
865 : }
866 0 : vn_uuid_ = MakeUuid(num);
867 :
868 0 : if (GetStringAttribute(node(), "vm-name", &vm_name_) == false) {
869 0 : cout << "Attribute \"vm_name\" not specified for nova. Skipping"
870 0 : << endl;
871 0 : return false;
872 : }
873 :
874 0 : if (GetStringAttribute(node(), "ip", &ip_) == false) {
875 0 : cout << "Attribute \"ip\" not specified for nova. Skipping"
876 0 : << endl;
877 0 : return false;
878 : }
879 :
880 0 : return true;
881 : }
882 :
883 0 : bool AgentUtXmlNova::ToXml(xml_node *parent) {
884 0 : assert(0);
885 : return false;
886 : }
887 :
888 0 : void AgentUtXmlNova::ToString(string *str) {
889 0 : AgentUtXmlConfig::ToString(str);
890 0 : *str += "\n";
891 0 : return;
892 : }
893 :
894 0 : string AgentUtXmlNova::NodeType() {
895 0 : return "Nova";
896 : }
897 :
898 0 : bool AgentUtXmlNova::Run() {
899 0 : boost::system::error_code ec;
900 0 : Ip4Address ip = Ip4Address::from_string(ip_, ec);
901 0 : NovaIntfAdd(op_delete(), id(), ip, vm_uuid_, vn_uuid_, name(), mac_,
902 0 : vm_name_);
903 0 : return true;
904 : }
905 :
906 : /////////////////////////////////////////////////////////////////////////////
907 : // AgentUtXmlGlobalVrouterValidate routines
908 : /////////////////////////////////////////////////////////////////////////////
909 3 : AgentUtXmlGlobalVrouterValidate::AgentUtXmlGlobalVrouterValidate(const string &name,
910 : const uuid &id,
911 3 : const xml_node &node) :
912 3 : AgentUtXmlValidationNode(name, node), id_(id), flow_export_rate_(-1) {
913 3 : }
914 :
915 6 : AgentUtXmlGlobalVrouterValidate::~AgentUtXmlGlobalVrouterValidate() {
916 6 : }
917 :
918 3 : bool AgentUtXmlGlobalVrouterValidate::ReadXml() {
919 3 : GetIntAttribute(node(), "flow-export-rate", &flow_export_rate_);
920 3 : return true;
921 : }
922 :
923 3 : bool AgentUtXmlGlobalVrouterValidate::Validate() {
924 3 : GlobalVrouter *vr = Agent::GetInstance()->oper_db()->global_vrouter();
925 :
926 3 : if (vr == NULL)
927 0 : return false;
928 :
929 3 : if (flow_export_rate_ != -1) {
930 3 : int32_t rate = flow_export_rate_;
931 3 : if (vr->flow_export_rate() != rate)
932 0 : return false;
933 : }
934 :
935 3 : return true;
936 : }
937 :
938 6 : const string AgentUtXmlGlobalVrouterValidate::ToString() {
939 6 : return "global-vrouter-config";
940 : }
941 :
942 : /////////////////////////////////////////////////////////////////////////////
943 : // AgentUtXmlVnValidate routines
944 : /////////////////////////////////////////////////////////////////////////////
945 39 : AgentUtXmlVnValidate::AgentUtXmlVnValidate(const string &name,
946 : const uuid &id,
947 39 : const xml_node &node) :
948 39 : AgentUtXmlValidationNode(name, node), id_(id), vxlan_id_(0),
949 39 : vxlan_id_ref_(false) {
950 39 : }
951 :
952 78 : AgentUtXmlVnValidate::~AgentUtXmlVnValidate() {
953 78 : }
954 :
955 39 : bool AgentUtXmlVnValidate::ReadXml() {
956 39 : GetUintAttribute(node(), "vxlan-id", &vxlan_id_);
957 39 : check_vxlan_id_ref_ = GetUintAttribute(node(), "vxlan-id-ref", &vxlan_id_ref_);
958 39 : return true;
959 : }
960 :
961 39 : bool AgentUtXmlVnValidate::Validate() {
962 39 : VnEntry *vn = VnGet(id());
963 39 : if (present() == false) {
964 2 : return (vn == NULL);
965 : }
966 :
967 37 : if (vn == NULL)
968 0 : return false;
969 :
970 37 : if (vxlan_id_ != 0) {
971 0 : if (vn->GetVxLanId() != vxlan_id_)
972 0 : return false;
973 : }
974 :
975 37 : if (check_vxlan_id_ref_) {
976 22 : if (vxlan_id_ref_ == 0) {
977 8 : if (vn->vxlan_id_ref() != NULL)
978 0 : return false;
979 : }
980 :
981 22 : if (vxlan_id_ref_) {
982 14 : const VxLanId *vxlan = vn->vxlan_id_ref();
983 14 : if (vxlan == NULL)
984 0 : return false;
985 :
986 14 : if (vxlan->vxlan_id() != vxlan_id_ref_)
987 0 : return false;
988 : }
989 : }
990 :
991 :
992 37 : return true;
993 : }
994 :
995 78 : const string AgentUtXmlVnValidate::ToString() {
996 78 : return "virtual-network";
997 : }
998 :
999 : /////////////////////////////////////////////////////////////////////////////
1000 : // AgentUtXmlVmValidate routines
1001 : /////////////////////////////////////////////////////////////////////////////
1002 14 : AgentUtXmlVmValidate::AgentUtXmlVmValidate(const string &name,
1003 : const uuid &id,
1004 14 : const xml_node &node) :
1005 14 : AgentUtXmlValidationNode(name, node), id_(id) {
1006 14 : }
1007 :
1008 28 : AgentUtXmlVmValidate::~AgentUtXmlVmValidate() {
1009 28 : }
1010 :
1011 14 : bool AgentUtXmlVmValidate::ReadXml() {
1012 14 : return true;
1013 : }
1014 :
1015 14 : bool AgentUtXmlVmValidate::Validate() {
1016 14 : return true;
1017 : }
1018 :
1019 28 : const string AgentUtXmlVmValidate::ToString() {
1020 28 : return "virtual-machine";
1021 : }
1022 :
1023 : /////////////////////////////////////////////////////////////////////////////
1024 : // AgentUtXmlVxlanValidate routines
1025 : /////////////////////////////////////////////////////////////////////////////
1026 30 : AgentUtXmlVxlanValidate::AgentUtXmlVxlanValidate(const string &name,
1027 : const uuid &id,
1028 30 : const xml_node &node) :
1029 30 : AgentUtXmlValidationNode(name, node), id_(id), vxlan_id_(0), vrf_(),
1030 30 : flood_unknown_unicast_() {
1031 30 : }
1032 :
1033 60 : AgentUtXmlVxlanValidate::~AgentUtXmlVxlanValidate() {
1034 60 : }
1035 :
1036 30 : bool AgentUtXmlVxlanValidate::ReadXml() {
1037 30 : GetUintAttribute(node(), "vxlan-id", &vxlan_id_);
1038 30 : GetStringAttribute(node(), "vrf", &vrf_);
1039 30 : GetStringAttribute(node(), "flood-unknown-unicast", &flood_unknown_unicast_);
1040 30 : return true;
1041 : }
1042 :
1043 30 : bool AgentUtXmlVxlanValidate::Validate() {
1044 30 : VxLanId *vxlan = VxlanGet(vxlan_id_);
1045 :
1046 30 : if (!present()) {
1047 12 : return (vxlan == NULL);
1048 : }
1049 :
1050 18 : if (vxlan == NULL)
1051 0 : return false;
1052 :
1053 18 : if (vxlan->vxlan_id() != vxlan_id_)
1054 0 : return false;
1055 :
1056 18 : if (flood_unknown_unicast_.empty() == false) {
1057 9 : const VrfNH *nh = dynamic_cast<const VrfNH *>(vxlan->nexthop());
1058 9 : if (nh == NULL)
1059 0 : return false;
1060 :
1061 13 : if (flood_unknown_unicast_ == "true" ||
1062 4 : flood_unknown_unicast_ == "yes") {
1063 5 : return (nh->flood_unknown_unicast() == true);
1064 : } else {
1065 4 : return (nh->flood_unknown_unicast() == false);
1066 : }
1067 : }
1068 :
1069 9 : if (vrf_.empty() == false) {
1070 9 : const VrfNH *nh = dynamic_cast<const VrfNH *>(vxlan->nexthop());
1071 9 : if (nh == NULL)
1072 0 : return false;
1073 :
1074 9 : if (nh->GetType() != NextHop::VRF)
1075 0 : return false;
1076 :
1077 9 : const VrfEntry *vrf = nh->GetVrf();
1078 9 : if (vrf == NULL)
1079 0 : return false;
1080 :
1081 9 : if (vrf->GetName() != vrf_)
1082 0 : return false;
1083 : }
1084 :
1085 9 : return true;
1086 : }
1087 :
1088 60 : const string AgentUtXmlVxlanValidate::ToString() {
1089 60 : return "vxlan";
1090 : }
1091 :
1092 : /////////////////////////////////////////////////////////////////////////////
1093 : // AgentUtXmlVmInterfaceValidate routines
1094 : /////////////////////////////////////////////////////////////////////////////
1095 53 : AgentUtXmlVmInterfaceValidate::AgentUtXmlVmInterfaceValidate(const string &name,
1096 : const uuid &id,
1097 53 : const xml_node &node) :
1098 53 : AgentUtXmlValidationNode(name, node), id_(id), vlan_tag_(0), vn_uuid_() {
1099 53 : }
1100 :
1101 106 : AgentUtXmlVmInterfaceValidate::~AgentUtXmlVmInterfaceValidate() {
1102 106 : }
1103 :
1104 53 : bool AgentUtXmlVmInterfaceValidate::ReadXml() {
1105 53 : GetUintAttribute(node(), "vlan", &vlan_tag_);
1106 53 : GetStringAttribute(node(), "active", &active_);
1107 53 : GetStringAttribute(node(), "device-type", &device_type_);
1108 53 : GetStringAttribute(node(), "vmi-type", &vmi_type_);
1109 53 : uint16_t id = 0;
1110 53 : GetUintAttribute(node(), "vn-uuid", &id);
1111 53 : if (id) {
1112 3 : vn_uuid_ = MakeUuid(id);
1113 : }
1114 :
1115 53 : return true;
1116 : }
1117 :
1118 6 : static string DeviceTypeToString(VmInterface::DeviceType type) {
1119 6 : if (type == VmInterface::VM_ON_TAP)
1120 3 : return "VM-Tap";
1121 3 : if (type == VmInterface::VM_VLAN_ON_VMI)
1122 3 : return "VM-Sub-Intf";
1123 0 : if (type == VmInterface::TOR)
1124 0 : return "Tor";
1125 0 : if (type == VmInterface::LOCAL_DEVICE)
1126 0 : return "Baremetal";
1127 0 : return "Invalid";
1128 :
1129 : }
1130 :
1131 6 : static string VmiTypeToString(VmInterface::VmiType type) {
1132 6 : if (type == VmInterface::INSTANCE)
1133 6 : return "vm";
1134 0 : if (type == VmInterface::BAREMETAL)
1135 0 : return "Baremetal";
1136 0 : if (type == VmInterface::GATEWAY)
1137 0 : return "Gateway";
1138 :
1139 0 : return "Invalid";
1140 : }
1141 :
1142 53 : bool AgentUtXmlVmInterfaceValidate::Validate() {
1143 53 : VmInterface *vmi = VmInterfaceGet(id());
1144 :
1145 53 : if (present()) {
1146 26 : if (vmi == NULL)
1147 0 : return false;
1148 : } else {
1149 27 : return vmi == NULL;
1150 : }
1151 :
1152 26 : if (active_.empty() == false) {
1153 45 : if (boost::iequals(active_, "true") ||
1154 30 : (boost::iequals(active_, "0") == false)){
1155 15 : if (VmPortActive(id()) == false)
1156 0 : return false;
1157 : } else {
1158 0 : if (VmPortActive(id()) == true)
1159 0 : return false;
1160 : }
1161 : }
1162 :
1163 26 : if (device_type_.empty() == false) {
1164 12 : if (boost::iequals(device_type_, DeviceTypeToString(vmi->device_type()))
1165 6 : == false)
1166 0 : return false;
1167 : }
1168 :
1169 26 : if (vmi_type_.empty() == false) {
1170 12 : if (boost::iequals(vmi_type_, VmiTypeToString(vmi->vmi_type()))
1171 6 : == false)
1172 0 : return false;
1173 : }
1174 :
1175 26 : if (vlan_tag_ > 0) {
1176 0 : if (vmi->rx_vlan_id() != vlan_tag_)
1177 0 : return false;
1178 : }
1179 :
1180 26 : if (vn_uuid_.is_nil() == false) {
1181 3 : const VnEntry *vn = vmi->vn();
1182 3 : if (vn == NULL)
1183 0 : return false;
1184 :
1185 3 : if (vn->GetUuid() != vn_uuid_)
1186 0 : return false;
1187 : }
1188 :
1189 26 : return true;
1190 : }
1191 :
1192 106 : const string AgentUtXmlVmInterfaceValidate::ToString() {
1193 106 : return "virtual-machine-interface";
1194 : }
1195 :
1196 : /////////////////////////////////////////////////////////////////////////////
1197 : // AgentUtXmlEthInterfaceValidate routines
1198 : /////////////////////////////////////////////////////////////////////////////
1199 0 : AgentUtXmlEthInterfaceValidate::AgentUtXmlEthInterfaceValidate(const string &name,
1200 : const uuid &id,
1201 0 : const xml_node &node) :
1202 0 : AgentUtXmlValidationNode(name, node), id_(id) {
1203 0 : }
1204 :
1205 0 : AgentUtXmlEthInterfaceValidate::~AgentUtXmlEthInterfaceValidate() {
1206 0 : }
1207 :
1208 0 : bool AgentUtXmlEthInterfaceValidate::ReadXml() {
1209 0 : return true;
1210 : }
1211 :
1212 0 : bool AgentUtXmlEthInterfaceValidate::Validate() {
1213 0 : return true;
1214 : }
1215 :
1216 0 : const string AgentUtXmlEthInterfaceValidate::ToString() {
1217 0 : return "eth-interface";
1218 : }
1219 :
1220 : /////////////////////////////////////////////////////////////////////////////
1221 : // AgentUtXmlVrfValidate routines
1222 : /////////////////////////////////////////////////////////////////////////////
1223 19 : AgentUtXmlVrfValidate::AgentUtXmlVrfValidate(const string &name,
1224 19 : const xml_node &node) :
1225 19 : AgentUtXmlValidationNode(name, node) {
1226 19 : }
1227 :
1228 38 : AgentUtXmlVrfValidate::~AgentUtXmlVrfValidate() {
1229 38 : }
1230 :
1231 19 : bool AgentUtXmlVrfValidate::ReadXml() {
1232 19 : GetStringAttribute(node(), "vn", &vn_name_);
1233 19 : return true;
1234 : }
1235 :
1236 19 : bool AgentUtXmlVrfValidate::Validate() {
1237 :
1238 19 : VrfEntry *vrf = VrfGet(name().c_str(), true);
1239 :
1240 19 : if (present() && (vrf == NULL)) {
1241 0 : return false;
1242 19 : } else if (!present() && (vrf != NULL)) {
1243 0 : return false;
1244 : }
1245 :
1246 19 : if (vrf == NULL)
1247 12 : return true;
1248 :
1249 7 : if (delete_marked()) {
1250 0 : if (vrf->IsDeleted() == false)
1251 0 : return false;
1252 : }
1253 :
1254 7 : if (vn_name_ == "") {
1255 0 : return true;
1256 : }
1257 :
1258 7 : if (vn_name_ == "nil" || vn_name_ == "NIL") {
1259 3 : return (vrf->vn() == NULL);
1260 : }
1261 :
1262 4 : if (vrf->vn() == NULL)
1263 0 : return false;
1264 :
1265 4 : return (vrf->vn()->GetName() == vn_name_);
1266 : }
1267 :
1268 38 : const string AgentUtXmlVrfValidate::ToString() {
1269 38 : return "vrf";
1270 : }
1271 :
1272 : /////////////////////////////////////////////////////////////////////////////
1273 : // AgentUtXmlAclValidate routines
1274 : /////////////////////////////////////////////////////////////////////////////
1275 0 : AgentUtXmlAclValidate::AgentUtXmlAclValidate(const string &name,
1276 0 : const xml_node &node) :
1277 0 : AgentUtXmlValidationNode(name, node) {
1278 0 : }
1279 :
1280 0 : AgentUtXmlAclValidate::~AgentUtXmlAclValidate() {
1281 0 : }
1282 :
1283 0 : bool AgentUtXmlAclValidate::ReadXml() {
1284 0 : return true;
1285 : }
1286 :
1287 0 : bool AgentUtXmlAclValidate::Validate() {
1288 0 : if (present()) {
1289 0 : return AclFind(id());
1290 : } else {
1291 0 : return !AclFind(id());
1292 : }
1293 : }
1294 :
1295 0 : const string AgentUtXmlAclValidate::ToString() {
1296 0 : return "access-control-list";
1297 : }
1298 :
1299 : /////////////////////////////////////////////////////////////////////////////
1300 : // AgentUtXmlFlowValidate routines
1301 : /////////////////////////////////////////////////////////////////////////////
1302 45 : AgentUtXmlFlowValidate::AgentUtXmlFlowValidate(const string &name,
1303 45 : const xml_node &node) :
1304 45 : AgentUtXmlValidationNode(name, node), attempt_(0), nh_auto_(false) {
1305 45 : }
1306 :
1307 90 : AgentUtXmlFlowValidate::~AgentUtXmlFlowValidate() {
1308 90 : }
1309 :
1310 45 : bool AgentUtXmlFlowValidate::ReadXml() {
1311 45 : if (GetUintAttribute(node(), "nh", &nh_id_) == false) {
1312 45 : nh_id_ = 0;
1313 45 : nh_auto_ = true;
1314 : } else {
1315 0 : nh_auto_ = false;
1316 : }
1317 :
1318 45 : if (GetStringAttribute(node(), "sip", &sip_) == false) {
1319 0 : cout << "Attribute \"sip\" not specified for Flow. Skipping" << endl;
1320 0 : return false;
1321 : }
1322 :
1323 45 : if (GetStringAttribute(node(), "dip", &dip_) == false) {
1324 0 : cout << "Attribute \"dip\" not specified for Flow. Skipping" << endl;
1325 0 : return false;
1326 : }
1327 :
1328 90 : if (GetStringAttribute(node(), "proto", &proto_) == false &&
1329 45 : GetUintAttribute(node(), "proto", &proto_id_) == false) {
1330 0 : cout << "Attribute \"proto\" not specified for Flow. Skipping"
1331 0 : << endl;
1332 0 : return false;
1333 : }
1334 :
1335 45 : if (proto_ == "tcp" || proto_ == "udp") {
1336 45 : if (proto_ == "tcp")
1337 3 : proto_id_ = 6;
1338 : else
1339 42 : proto_id_ = 17;
1340 45 : if (GetUintAttribute(node(), "sport", &sport_) == false) {
1341 0 : cout << "Attribute \"sport\" not specified for Flow. Skipping"
1342 0 : << endl;
1343 0 : return false;
1344 : }
1345 :
1346 45 : if (GetUintAttribute(node(), "dport", &dport_) == false) {
1347 0 : cout << "Attribute \"dport\" not specified for Flow. Skipping"
1348 0 : << endl; return false;
1349 : }
1350 : }
1351 :
1352 45 : GetStringAttribute(node(), "svn", &svn_);
1353 45 : GetStringAttribute(node(), "dvn", &dvn_);
1354 45 : GetStringAttribute(node(), "action", &action_);
1355 45 : if (GetUintAttribute(node(), "rpf_nh", &rpf_nh_) == false) {
1356 28 : rpf_nh_ = 0;
1357 : }
1358 45 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1359 0 : vrf_ ="";
1360 : }
1361 45 : if (GetStringAttribute(node(), "deleted", &deleted_) == false) {
1362 44 : deleted_ = "false";
1363 : }
1364 45 : return true;
1365 : }
1366 :
1367 44 : static bool MatchFlowAction(FlowEntry *flow, const string &str) {
1368 44 : uint64_t action = flow->data().match_p.action_info.action;
1369 44 : if (str == "pass") {
1370 24 : return (action & (1 << TrafficAction::PASS));
1371 : }
1372 :
1373 20 : if (str == "deny") {
1374 40 : return (((action & TrafficAction::DROP_FLAGS) != 0) |
1375 20 : (flow->IsShortFlow()));
1376 : }
1377 :
1378 0 : return false;
1379 : }
1380 :
1381 0 : void AgentUtXmlFlowValidate::SuggestNhId() {
1382 0 : Agent *agent = Agent::GetInstance();
1383 0 : if (agent == NULL || agent->nexthop_table() == NULL) {
1384 0 : return;
1385 : }
1386 :
1387 0 : cout << " flow <" << name() << "> not found with nh=" << nh_id_
1388 0 : << " (key: vrf=" << vrf_ << " " << sip_ << " -> " << dip_
1389 0 : << " proto=" << proto_id_ << " " << sport_ << "/" << dport_ << ")"
1390 0 : << endl;
1391 :
1392 0 : bool found = false;
1393 : DBTablePartition *part = static_cast<DBTablePartition *>
1394 0 : (agent->nexthop_table()->GetTablePartition(0));
1395 0 : for (DBEntry *e = part->GetFirst(); e != NULL; e = part->GetNext(e)) {
1396 0 : NextHop *nh = static_cast<NextHop *>(e);
1397 0 : FlowEntry *f = FlowGet(0, sip_, dip_, proto_id_, sport_, dport_,
1398 0 : nh->id());
1399 0 : if (f != NULL) {
1400 0 : found = true;
1401 0 : cout << " ==> MATCHES with nh=\"" << nh->id() << "\""
1402 0 : << " (nh type=" << nh->GetType()
1403 0 : << ", " << nh->ToString() << ")" << endl;
1404 : }
1405 : }
1406 0 : if (found == false) {
1407 : cout << " ==> no nexthop index yields this flow; the flow itself was"
1408 0 : " not created (check the packet, not the nh)" << endl;
1409 : }
1410 : }
1411 :
1412 45 : FlowEntry *AgentUtXmlFlowValidate::FindFlowAnyNh(uint16_t *found_nh) {
1413 45 : Agent *agent = Agent::GetInstance();
1414 45 : if (agent == NULL || agent->nexthop_table() == NULL) {
1415 0 : return NULL;
1416 : }
1417 :
1418 45 : FlowEntry *result = NULL;
1419 45 : uint32_t matches = 0;
1420 : DBTablePartition *part = static_cast<DBTablePartition *>
1421 45 : (agent->nexthop_table()->GetTablePartition(0));
1422 1419 : for (DBEntry *e = part->GetFirst(); e != NULL; e = part->GetNext(e)) {
1423 1374 : NextHop *nh = static_cast<NextHop *>(e);
1424 1374 : FlowEntry *f = FlowGet(0, sip_, dip_, proto_id_, sport_, dport_,
1425 1374 : nh->id());
1426 1374 : if (f != NULL) {
1427 44 : matches++;
1428 44 : if (result == NULL) {
1429 44 : result = f;
1430 44 : *found_nh = nh->id();
1431 : }
1432 : }
1433 : }
1434 :
1435 45 : if (matches > 1) {
1436 0 : cout << " flow <" << name() << "> matches " << matches
1437 0 : << " nexthops; the key is ambiguous -- specify nh= explicitly"
1438 0 : << endl;
1439 0 : return NULL;
1440 : }
1441 45 : return result;
1442 : }
1443 :
1444 45 : bool AgentUtXmlFlowValidate::Validate() {
1445 45 : FlowEntry *flow = NULL;
1446 45 : uint16_t used_nh = nh_id_;
1447 45 : if (nh_auto_) {
1448 45 : flow = FindFlowAnyNh(&used_nh);
1449 : } else {
1450 0 : flow = FlowGet(0, sip_, dip_, proto_id_, sport_, dport_, nh_id_);
1451 : }
1452 :
1453 45 : if (deleted_ == "true" && flow == NULL) {
1454 1 : return true;
1455 : }
1456 :
1457 44 : if (present() == false)
1458 0 : return (flow == NULL);
1459 :
1460 44 : if (flow == NULL) {
1461 0 : if (nh_auto_ == false && ++attempt_ >= wait_count()) {
1462 0 : SuggestNhId();
1463 : }
1464 0 : return false;
1465 : }
1466 :
1467 44 : if (nh_auto_) {
1468 44 : cout << " flow <" << name() << "> resolved to nh=" << used_nh << endl;
1469 : }
1470 :
1471 44 : if (svn_ != "" && !VnMatch(flow->data().source_vn_list, svn_))
1472 0 : return false;
1473 :
1474 44 : if (dvn_ != "" && !VnMatch(flow->data().dest_vn_list, dvn_))
1475 0 : return false;
1476 :
1477 44 : if (MatchFlowAction(flow, action_) == false) {
1478 0 : return false;
1479 : }
1480 :
1481 44 : if (rpf_nh_) {
1482 17 : int nh_id = 0;
1483 17 : if (vrf_ != "") {
1484 17 : Agent *agent = Agent::GetInstance();
1485 : InetUnicastAgentRouteTable *inet_table =
1486 : static_cast<InetUnicastAgentRouteTable *>
1487 17 : (agent->vrf_table()->GetInet4UnicastRouteTable(vrf_));
1488 : InetUnicastRouteEntry *rt =
1489 17 : inet_table->FindRoute(Ip4Address::from_string(sip_));
1490 17 : if ( rt != NULL) {
1491 15 : const NextHop *nh = rt->GetActiveNextHop();
1492 15 : if ( nh && (nh->id() != rpf_nh_)) {
1493 3 : nh_id = nh->id();
1494 : }
1495 : }
1496 : }
1497 17 : if (rpf_nh_ == NextHopTable::kRpfDiscardIndex) {
1498 0 : if (flow->data().rpf_nh.get() != NULL) {
1499 0 : return false;
1500 : }
1501 34 : } else if (!flow->data().rpf_nh.get() ||
1502 17 : ((flow->data().rpf_nh.get()->id() != rpf_nh_) &&
1503 0 : (flow->data().rpf_nh.get()->id() != nh_id))) {
1504 0 : return false;
1505 : }
1506 : }
1507 44 : return true;
1508 : }
1509 :
1510 90 : const string AgentUtXmlFlowValidate::ToString() {
1511 180 : return ("flow <" + name() + ">");
1512 : }
1513 :
1514 45 : uint32_t AgentUtXmlFlowValidate::wait_count() const {
1515 45 : if (present()) {
1516 45 : return 10;
1517 : } else {
1518 0 : return AgentUtXmlValidationNode::wait_count();
1519 : }
1520 : }
1521 :
1522 : /////////////////////////////////////////////////////////////////////////////
1523 : // AgentUtXmlL2Route routines
1524 : /////////////////////////////////////////////////////////////////////////////
1525 13 : AgentUtXmlL2Route::AgentUtXmlL2Route(const string &name, const uuid &id,
1526 : const xml_node &node,
1527 13 : AgentUtXmlTestCase *test_case) :
1528 13 : AgentUtXmlNode(name, node, false, test_case) {
1529 13 : }
1530 :
1531 26 : AgentUtXmlL2Route::~AgentUtXmlL2Route() {
1532 26 : }
1533 :
1534 :
1535 13 : bool AgentUtXmlL2Route::ReadXml() {
1536 13 : if (GetStringAttribute(node(), "mac", &mac_) == false) {
1537 0 : cout << "Attribute \"mac\" not specified. Skipping" << endl;
1538 0 : return false;
1539 : }
1540 :
1541 13 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1542 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1543 0 : return false;
1544 : }
1545 :
1546 13 : GetStringAttribute(node(), "ip", &ip_);
1547 13 : GetStringAttribute(node(), "vn", &vn_);
1548 13 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1549 13 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1550 13 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1551 13 : GetUintAttribute(node(), "sg", &sg_id_);
1552 13 : GetUintAttribute(node(), "tag", &tag_id_);
1553 13 : GetUintAttribute(node(), "label", &label_);
1554 13 : if (ip_.empty()) {
1555 13 : ip_ = "0.0.0.0";
1556 : }
1557 13 : return true;
1558 : }
1559 :
1560 0 : bool AgentUtXmlL2Route::ToXml(xml_node *parent) {
1561 0 : assert(0);
1562 : return true;
1563 : }
1564 :
1565 13 : void AgentUtXmlL2Route::ToString(string *str) {
1566 13 : *str = "L2-Route";
1567 13 : return;
1568 : }
1569 :
1570 0 : string AgentUtXmlL2Route::NodeType() {
1571 0 : return "FDB";
1572 : }
1573 :
1574 13 : bool AgentUtXmlL2Route::Run() {
1575 13 : Agent *agent = Agent::GetInstance();
1576 : EvpnAgentRouteTable *rt_table =
1577 : static_cast<EvpnAgentRouteTable *>
1578 13 : (Agent::GetInstance()->vrf_table()->GetEvpnRouteTable(vrf_));
1579 :
1580 13 : SecurityGroupList sg_list;
1581 13 : TagList tag_list;
1582 13 : if (sg_id_)
1583 11 : sg_list.push_back(sg_id_);
1584 13 : if (tag_id_)
1585 0 : tag_list.push_back(tag_id_);
1586 :
1587 13 : TunnelType::TypeBmap bmap = 0;
1588 : TunnelEncapType::Encap encap =
1589 13 : TunnelEncapType::TunnelEncapFromString(tunnel_type_);
1590 13 : if (encap == TunnelEncapType::MPLS_O_GRE)
1591 0 : bmap |= (1 << TunnelType::MPLS_GRE);
1592 13 : if (encap == TunnelEncapType::MPLS_O_UDP)
1593 0 : bmap |= (1 << TunnelType::MPLS_UDP);
1594 13 : if (encap == TunnelEncapType::VXLAN)
1595 11 : bmap |= (1 << TunnelType::VXLAN);
1596 13 : if (op_delete()) {
1597 12 : rt_table->DeleteReq(bgp_peer_, vrf_,
1598 6 : MacAddress::FromString(mac_),
1599 12 : Ip4Address::from_string(ip_), 32, vxlan_id_,
1600 6 : (new ControllerVmRoute(bgp_peer_)));
1601 : } else {
1602 7 : VnListType vn_list;
1603 7 : vn_list.insert(vn_);
1604 : ControllerVmRoute *data =
1605 7 : ControllerVmRoute::MakeControllerVmRoute(bgp_peer_,
1606 : agent->fabric_vrf_name(),
1607 7 : agent->router_id(), vrf_,
1608 0 : Ip4Address::from_string(tunnel_dest_),
1609 7 : bmap, label_, MacAddress(),
1610 : vn_list, sg_list, tag_list,
1611 14 : PathPreference(), false,
1612 14 : EcmpLoadBalance(), false);
1613 14 : rt_table->AddRemoteVmRouteReq(bgp_peer_, vrf_,
1614 7 : MacAddress::FromString(mac_),
1615 0 : Ip4Address::from_string(ip_),
1616 7 : 32, vxlan_id_, data);
1617 7 : }
1618 13 : return true;
1619 13 : }
1620 :
1621 : /////////////////////////////////////////////////////////////////////////////
1622 : // AgentUtXmlL2RouteValidate routines
1623 : /////////////////////////////////////////////////////////////////////////////
1624 0 : AgentUtXmlL2RouteValidate::AgentUtXmlL2RouteValidate(const string &name,
1625 0 : const xml_node &node) :
1626 0 : AgentUtXmlValidationNode(name, node) {
1627 0 : }
1628 :
1629 0 : AgentUtXmlL2RouteValidate::~AgentUtXmlL2RouteValidate() {
1630 0 : }
1631 :
1632 0 : bool AgentUtXmlL2RouteValidate::ReadXml() {
1633 0 : if (GetStringAttribute(node(), "mac", &mac_) == false) {
1634 0 : cout << "Attribute \"mac\" not specified. Skipping" << endl;
1635 0 : return false;
1636 : }
1637 :
1638 0 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1639 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1640 0 : return false;
1641 : }
1642 :
1643 0 : if (GetStringAttribute(node(), "vn", &vn_) == false) {
1644 0 : cout << "Attribute \"vn\" not specified. Skipping" << endl;
1645 0 : return false;
1646 : }
1647 :
1648 0 : string addr = "";
1649 0 : GetStringAttribute(node(), "ip", &addr);
1650 0 : boost::system::error_code ec;
1651 0 : ip_ = IpAddress::from_string(addr, ec);
1652 :
1653 0 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1654 0 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1655 0 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1656 0 : GetUintAttribute(node(), "intf", &intf_uuid_);
1657 :
1658 0 : return true;
1659 0 : }
1660 :
1661 0 : bool AgentUtXmlL2RouteValidate::Validate() {
1662 0 : Agent *agent = Agent::GetInstance();
1663 : BridgeAgentRouteTable *bridge_table =
1664 : static_cast<BridgeAgentRouteTable *>
1665 0 : (agent->vrf_table()->GetBridgeRouteTable(vrf_));
1666 : BridgeRouteEntry *rt =
1667 0 : bridge_table->FindRoute(MacAddress::FromString(mac_));
1668 0 : if (present() == false)
1669 0 : return (rt == NULL);
1670 :
1671 0 : if (rt == NULL)
1672 0 : return false;
1673 :
1674 0 : if (vn_ != "" && vn_ != rt->dest_vn_name())
1675 0 : return false;
1676 :
1677 0 : return true;
1678 : }
1679 :
1680 0 : const string AgentUtXmlL2RouteValidate::ToString() {
1681 0 : return ("FDB <" + name() + ">");
1682 : }
1683 :
1684 6 : AgentUtXmlL3Route::AgentUtXmlL3Route(const string &name, const uuid &id,
1685 : const xml_node &node,
1686 6 : AgentUtXmlTestCase *test_case) :
1687 6 : AgentUtXmlNode(name, node, false, test_case) {
1688 6 : }
1689 :
1690 12 : AgentUtXmlL3Route::~AgentUtXmlL3Route() {
1691 12 : }
1692 :
1693 :
1694 6 : bool AgentUtXmlL3Route::ReadXml() {
1695 6 : if (GetStringAttribute(node(), "src-ip", &src_ip_) == false) {
1696 0 : cout << "Attribute \"ip\" not specified. Skipping" << endl;
1697 0 : return false;
1698 : }
1699 :
1700 6 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1701 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1702 0 : return false;
1703 : }
1704 :
1705 6 : GetStringAttribute(node(), "ip", &ip_);
1706 6 : GetStringAttribute(node(), "vn", &vn_);
1707 6 : GetUintAttribute(node(), "plen", &plen_);
1708 6 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1709 6 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1710 6 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1711 6 : GetUintAttribute(node(), "sg", &sg_id_);
1712 6 : GetUintAttribute(node(), "tag", &tag_id_);
1713 6 : GetUintAttribute(node(), "label", &label_);
1714 6 : if (ip_.empty()) {
1715 6 : ip_ = "0.0.0.0";
1716 : }
1717 6 : return true;
1718 : }
1719 :
1720 0 : bool AgentUtXmlL3Route::ToXml(xml_node *parent) {
1721 0 : assert(0);
1722 : return true;
1723 : }
1724 :
1725 6 : void AgentUtXmlL3Route::ToString(string *str) {
1726 6 : *str = "L3-Route";
1727 6 : return;
1728 : }
1729 :
1730 0 : string AgentUtXmlL3Route::NodeType() {
1731 0 : return "L3-Route";
1732 : }
1733 :
1734 6 : bool AgentUtXmlL3Route::Run() {
1735 6 : Agent *agent = Agent::GetInstance();
1736 : InetUnicastAgentRouteTable *rt_table =
1737 : static_cast<InetUnicastAgentRouteTable *>
1738 6 : (Agent::GetInstance()->vrf_table()->GetInet4UnicastRouteTable(vrf_));
1739 :
1740 6 : SecurityGroupList sg_list;
1741 6 : TagList tag_list;
1742 6 : if (sg_id_)
1743 6 : sg_list.push_back(sg_id_);
1744 6 : if (tag_id_)
1745 0 : tag_list.push_back(tag_id_);
1746 :
1747 6 : TunnelType::TypeBmap bmap = 0;
1748 : TunnelEncapType::Encap encap =
1749 6 : TunnelEncapType::TunnelEncapFromString(tunnel_type_);
1750 6 : if (encap == TunnelEncapType::MPLS_O_GRE)
1751 0 : bmap |= (1 << TunnelType::MPLS_GRE);
1752 6 : if (encap == TunnelEncapType::MPLS_O_UDP)
1753 0 : bmap |= (1 << TunnelType::MPLS_UDP);
1754 6 : if (encap == TunnelEncapType::VXLAN)
1755 0 : bmap |= (1 << TunnelType::VXLAN);
1756 6 : if (op_delete()) {
1757 3 : rt_table->DeleteReq(bgp_peer_, vrf_,
1758 6 : Ip4Address::from_string(src_ip_), plen_,
1759 3 : (new ControllerVmRoute(bgp_peer_)));
1760 : } else {
1761 3 : VnListType vn_list;
1762 3 : vn_list.insert(vn_);
1763 : ControllerVmRoute *data =
1764 3 : ControllerVmRoute::MakeControllerVmRoute(bgp_peer_,
1765 : agent->fabric_vrf_name(),
1766 3 : agent->router_id(), vrf_,
1767 0 : Ip4Address::from_string(tunnel_dest_),
1768 3 : bmap, label_, MacAddress(),
1769 : vn_list, sg_list, tag_list,
1770 6 : PathPreference(), false,
1771 6 : EcmpLoadBalance(),
1772 : false);
1773 3 : rt_table->AddRemoteVmRouteReq(bgp_peer_, vrf_,
1774 3 : Ip4Address::from_string(src_ip_), plen_,
1775 : data);
1776 3 : }
1777 6 : return true;
1778 6 : }
1779 :
1780 0 : AgentUtXmlL3RouteValidate::AgentUtXmlL3RouteValidate(const string &name,
1781 0 : const xml_node &node) :
1782 0 : AgentUtXmlValidationNode(name, node) {
1783 0 : }
1784 :
1785 0 : AgentUtXmlL3RouteValidate::~AgentUtXmlL3RouteValidate() {
1786 0 : }
1787 :
1788 0 : bool AgentUtXmlL3RouteValidate::ReadXml() {
1789 0 : if (GetStringAttribute(node(), "src-ip", &src_ip_) == false) {
1790 0 : cout << "Attribute \"mac\" not specified. Skipping" << endl;
1791 0 : return false;
1792 : }
1793 :
1794 0 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1795 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1796 0 : return false;
1797 : }
1798 :
1799 0 : if (GetStringAttribute(node(), "vn", &vn_) == false) {
1800 0 : cout << "Attribute \"vn\" not specified. Skipping" << endl;
1801 0 : return false;
1802 : }
1803 :
1804 0 : string addr = "";
1805 0 : GetStringAttribute(node(), "ip", &addr);
1806 0 : boost::system::error_code ec;
1807 0 : ip_ = IpAddress::from_string(addr, ec);
1808 :
1809 0 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1810 0 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1811 0 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1812 0 : GetUintAttribute(node(), "intf", &intf_uuid_);
1813 :
1814 0 : return true;
1815 0 : }
1816 :
1817 0 : bool AgentUtXmlL3RouteValidate::Validate() {
1818 0 : Agent *agent = Agent::GetInstance();
1819 : InetUnicastAgentRouteTable *inet_table =
1820 : static_cast<InetUnicastAgentRouteTable *>
1821 0 : (agent->vrf_table()->GetInet4UnicastRouteTable(vrf_));
1822 : InetUnicastRouteEntry *rt =
1823 0 : inet_table->FindRoute(Ip4Address::from_string(src_ip_));
1824 0 : if (present() == false)
1825 0 : return (rt == NULL);
1826 :
1827 0 : if (rt == NULL)
1828 0 : return false;
1829 :
1830 0 : if (vn_ != "" && vn_ != rt->dest_vn_name())
1831 0 : return false;
1832 :
1833 0 : return true;
1834 : }
1835 :
1836 0 : const string AgentUtXmlL3RouteValidate::ToString() {
1837 0 : return ("IP route <" + name() + ">");
1838 : }
|