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 75 : AgentUtXmlValidationNode *CreateValidateNode(const string &type,
27 : const string &name, const uuid &id,
28 : const xml_node &node) {
29 75 : if (type == "global-vrouter-config")
30 0 : return new AgentUtXmlGlobalVrouterValidate(name, id, node);
31 75 : if (type == "virtual-network" || type == "vn")
32 6 : return new AgentUtXmlVnValidate(name, id, node);
33 69 : if (type == "virtual-machine" || type == "vm")
34 10 : return new AgentUtXmlVmValidate(name, id, node);
35 59 : if (type == "vxlan")
36 0 : return new AgentUtXmlVxlanValidate(name, id, node);
37 105 : if (type == "virtual-machine-interface" || type == "vm-interface"
38 105 : || type == "vmi")
39 13 : return new AgentUtXmlVmInterfaceValidate(name, id, node);
40 46 : if (type == "ethernet-interface" || type == "eth-port")
41 0 : return new AgentUtXmlEthInterfaceValidate(name, id, node);
42 46 : if (type == "flow")
43 42 : return new AgentUtXmlFlowValidate(name, node);
44 4 : if (type == "routing-instance" || type == "vrf")
45 1 : 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 131 : AgentUtXmlNode *CreateNode(const string &type, const string &name,
58 : const uuid &id, const xml_node &node,
59 : AgentUtXmlTestCase *test_case) {
60 131 : if (type == "global-vrouter-config")
61 0 : return new AgentUtXmlGlobalVrouter(name, id, node, test_case);
62 131 : if (type == "virtual-network" || type == "vn")
63 12 : return new AgentUtXmlVn(name, id, node, test_case);
64 119 : if (type == "virtual-machine" || type == "vm")
65 23 : return new AgentUtXmlVm(name, id, node, test_case);
66 164 : if (type == "virtual-machine-interface" || type == "vm-interface"
67 164 : || type == "vmi")
68 28 : return new AgentUtXmlVmInterface(name, id, node, test_case);
69 68 : if (type == "ethernet-interface" || type == "eth-port")
70 0 : return new AgentUtXmlEthInterface(name, id, node, test_case);
71 68 : if (type == "routing-instance" || type == "vrf")
72 12 : return new AgentUtXmlVrf(name, id, node, test_case);
73 56 : if (type == "access-control-list" || type == "acl")
74 8 : return new AgentUtXmlAcl(name, id, node, test_case);
75 96 : if (type == "virtual-machine-interface-routing-instance" ||
76 48 : type == "vmi-vrf")
77 22 : return new AgentUtXmlVmiVrf(name, id, node, test_case);
78 26 : if (type == "fdb" || type == "l2-route")
79 11 : 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 8 : void AgentUtXmlOperInit(AgentUtXmlTest *test) {
90 8 : test->AddConfigEntry("global-vrouter-config", CreateNode);
91 :
92 8 : test->AddConfigEntry("virtual-network", CreateNode);
93 8 : test->AddConfigEntry("vn", CreateNode);
94 :
95 8 : test->AddConfigEntry("virtual-machine", CreateNode);
96 8 : test->AddConfigEntry("vm", CreateNode);
97 :
98 8 : test->AddConfigEntry("vxlan", CreateNode);
99 :
100 8 : test->AddConfigEntry("virtual-machine-interface", CreateNode);
101 8 : test->AddConfigEntry("vm-interface", CreateNode);
102 8 : test->AddConfigEntry("vmi", CreateNode);
103 :
104 8 : test->AddConfigEntry("ethernet-interface", CreateNode);
105 8 : test->AddConfigEntry("eth-port", CreateNode);
106 :
107 8 : test->AddConfigEntry("routing-instance", CreateNode);
108 8 : test->AddConfigEntry("vrf", CreateNode);
109 :
110 8 : test->AddConfigEntry("access-control-list", CreateNode);
111 8 : test->AddConfigEntry("acl", CreateNode);
112 :
113 8 : test->AddConfigEntry("virtual-machine-interface-routing-instance",
114 : CreateNode);
115 8 : test->AddConfigEntry("vmi-vrf", CreateNode);
116 8 : test->AddConfigEntry("fdb", CreateNode);
117 8 : test->AddConfigEntry("l2-route", CreateNode);
118 8 : test->AddConfigEntry("l3-route", CreateNode);
119 8 : test->AddConfigEntry("sg", CreateNode);
120 8 : test->AddConfigEntry("security-group", CreateNode);
121 8 : test->AddConfigEntry("instance-ip", CreateNode);
122 :
123 8 : test->AddValidateEntry("global-vrouter-config", CreateValidateNode);
124 :
125 8 : test->AddValidateEntry("virtual-network", CreateValidateNode);
126 8 : test->AddValidateEntry("vn", CreateValidateNode);
127 8 : test->AddValidateEntry("vxlan", CreateValidateNode);
128 8 : test->AddValidateEntry("virtual-machine", CreateValidateNode);
129 8 : test->AddValidateEntry("vm", CreateValidateNode);
130 8 : test->AddValidateEntry("virtual-machine-interface", CreateValidateNode);
131 8 : test->AddValidateEntry("vm-interface", CreateValidateNode);
132 8 : test->AddValidateEntry("vmi", CreateValidateNode);
133 8 : test->AddValidateEntry("ethernet-interface", CreateValidateNode);
134 8 : test->AddValidateEntry("eth-port", CreateValidateNode);
135 8 : test->AddValidateEntry("flow", CreateValidateNode);
136 8 : test->AddValidateEntry("routing-instance", CreateValidateNode);
137 8 : test->AddValidateEntry("vrf", CreateValidateNode);
138 8 : test->AddValidateEntry("access-control-list", CreateValidateNode);
139 8 : test->AddValidateEntry("acl", CreateValidateNode);
140 8 : test->AddValidateEntry("pkt-parse", CreateValidateNode);
141 8 : test->AddValidateEntry("fdb", CreateValidateNode);
142 8 : test->AddValidateEntry("l2-route", CreateValidateNode);
143 8 : test->AddValidateEntry("l3-route", CreateValidateNode);
144 8 : }
145 :
146 : /////////////////////////////////////////////////////////////////////////////
147 : // AgentUtXmlGlobalVrouter routines
148 : /////////////////////////////////////////////////////////////////////////////
149 0 : AgentUtXmlGlobalVrouter::AgentUtXmlGlobalVrouter(const std::string &name,
150 : const uuid &id,
151 : const xml_node &node,
152 0 : AgentUtXmlTestCase *test_case) :
153 0 : AgentUtXmlConfig(name, id, node, test_case) {
154 0 : }
155 :
156 0 : AgentUtXmlGlobalVrouter::~AgentUtXmlGlobalVrouter() {
157 0 : }
158 :
159 0 : bool AgentUtXmlGlobalVrouter::ReadXml() {
160 0 : if (AgentUtXmlConfig::ReadXml() == false) {
161 0 : return false;
162 : }
163 0 : GetStringAttribute(node(), "vxlan-mode", &vxlan_mode_);
164 0 : bool got_attr = GetIntAttribute(node(), "flow-export-rate",
165 : &flow_export_rate_);
166 0 : if (!got_attr) {
167 0 : flow_export_rate_ = 0;
168 : }
169 0 : return true;
170 : }
171 :
172 0 : bool AgentUtXmlGlobalVrouter::ToXml(xml_node *parent) {
173 0 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
174 0 : AddXmlNodeWithValue(&n, "name", name());
175 0 : if (!vxlan_mode().empty()) {
176 0 : AddXmlNodeWithValue(&n, "vxlan-network-identifier-mode", vxlan_mode());
177 : }
178 0 : if (flow_export_rate() != 0) {
179 0 : AddXmlNodeWithIntValue(&n, "flow-export-rate", flow_export_rate());
180 : }
181 0 : AddIdPerms(&n);
182 0 : return true;
183 : }
184 :
185 0 : void AgentUtXmlGlobalVrouter::ToString(string *str) {
186 0 : AgentUtXmlConfig::ToString(str);
187 0 : *str += "\n";
188 0 : return;
189 : }
190 :
191 0 : string AgentUtXmlGlobalVrouter::NodeType() {
192 0 : return "global-vrouter-config";
193 : }
194 :
195 : /////////////////////////////////////////////////////////////////////////////
196 : // AgentUtXmlVn routines
197 : /////////////////////////////////////////////////////////////////////////////
198 12 : AgentUtXmlVn::AgentUtXmlVn(const string &name, const uuid &id,
199 : const xml_node &node,
200 12 : AgentUtXmlTestCase *test_case) :
201 12 : AgentUtXmlConfig(name, id, node, test_case) {
202 12 : }
203 :
204 24 : AgentUtXmlVn::~AgentUtXmlVn() {
205 24 : }
206 :
207 :
208 12 : bool AgentUtXmlVn::ReadXml() {
209 12 : if (AgentUtXmlConfig::ReadXml() == false) {
210 0 : return false;
211 : }
212 12 : GetStringAttribute(node(), "vxlan-id", &vxlan_id_);
213 12 : GetStringAttribute(node(), "network-id", &network_id_);
214 12 : GetStringAttribute(node(), "flood-unknown-unicast", &flood_unknown_unicast_);
215 12 : return true;
216 : }
217 :
218 12 : bool AgentUtXmlVn::ToXml(xml_node *parent) {
219 12 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
220 12 : AddXmlNodeWithValue(&n, "name", name());
221 12 : if (!network_id().empty()) {
222 3 : xml_node n1 = n.append_child("virtual-network-properties");
223 3 : AddXmlNodeWithValue(&n1, "network-id", network_id());
224 : }
225 12 : if (!vxlan_id().empty() && op_delete() == false) {
226 3 : xml_node n1 = n.append_child("virtual-network-properties");
227 3 : AddXmlNodeWithValue(&n1, "vxlan-network-identifier", vxlan_id());
228 : }
229 :
230 12 : if (!flood_unknown_unicast().empty() && op_delete() == false) {
231 0 : if (flood_unknown_unicast() == "true" ||
232 0 : flood_unknown_unicast() == "yes")
233 0 : AddXmlNodeWithValue(&n, "flood-unknown-unicast", "true");
234 : else
235 0 : AddXmlNodeWithValue(&n, "flood-unknown-unicast", "false");
236 : }
237 12 : AddIdPerms(&n);
238 12 : return true;
239 : }
240 :
241 12 : void AgentUtXmlVn::ToString(string *str) {
242 12 : AgentUtXmlConfig::ToString(str);
243 12 : *str += "\n";
244 12 : return;
245 : }
246 :
247 24 : string AgentUtXmlVn::NodeType() {
248 24 : return "virtual-network";
249 : }
250 :
251 : /////////////////////////////////////////////////////////////////////////////
252 : // AgentUtXmlVm routines
253 : /////////////////////////////////////////////////////////////////////////////
254 23 : AgentUtXmlVm::AgentUtXmlVm(const string &name, const uuid &id,
255 : const xml_node &node,
256 23 : AgentUtXmlTestCase *test_case) :
257 23 : AgentUtXmlConfig(name, id, node, test_case) {
258 23 : }
259 :
260 46 : AgentUtXmlVm::~AgentUtXmlVm() {
261 46 : }
262 :
263 :
264 23 : bool AgentUtXmlVm::ReadXml() {
265 23 : return AgentUtXmlConfig::ReadXml();
266 : }
267 :
268 23 : bool AgentUtXmlVm::ToXml(xml_node *parent) {
269 23 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
270 23 : AddXmlNodeWithValue(&n, "name", name());
271 23 : AddIdPerms(&n);
272 23 : return true;
273 : }
274 :
275 23 : void AgentUtXmlVm::ToString(string *str) {
276 23 : AgentUtXmlConfig::ToString(str);
277 23 : *str += "\n";
278 23 : return;
279 : }
280 :
281 46 : string AgentUtXmlVm::NodeType() {
282 46 : return "virtual-machine";
283 : }
284 :
285 : /////////////////////////////////////////////////////////////////////////////
286 : // AgentUtXmlVmInterface routines
287 : /////////////////////////////////////////////////////////////////////////////
288 28 : AgentUtXmlVmInterface::AgentUtXmlVmInterface(const string &name,
289 : const uuid &id,
290 : const xml_node &node,
291 28 : AgentUtXmlTestCase *test_case) :
292 28 : AgentUtXmlConfig(name, id, node, test_case), vlan_tag_(-1), parent_vmi_() {
293 28 : }
294 :
295 56 : AgentUtXmlVmInterface::~AgentUtXmlVmInterface() {
296 56 : }
297 :
298 28 : bool AgentUtXmlVmInterface::ReadXml() {
299 28 : if (AgentUtXmlConfig::ReadXml() == false)
300 0 : return false;
301 :
302 28 : GetStringAttribute(node(), "mac", &mac_);
303 :
304 28 : vm_name_ = "";
305 28 : vn_uuid_ = nil_uuid();
306 28 : vm_uuid_ = nil_uuid();
307 28 : vrf_ = "";
308 28 : add_nova_ = false;
309 28 : ip_ = "0.0.0.0";
310 :
311 28 : GetStringAttribute(node(), "vn-name", &vn_name_);
312 28 : uint16_t id = 0;
313 28 : GetUintAttribute(node(), "vn-uuid", &id);
314 28 : if (id) {
315 28 : vn_uuid_ = MakeUuid(id);
316 : }
317 :
318 28 : GetStringAttribute(node(), "vm-name", &vm_name_);
319 28 : id = 0;
320 28 : GetUintAttribute(node(), "vm-uuid", &id);
321 28 : if (id) {
322 28 : vm_uuid_ = MakeUuid(id);
323 : }
324 :
325 28 : GetStringAttribute(node(), "vrf", &vrf_);
326 28 : GetStringAttribute(node(), "ip", &ip_);
327 :
328 28 : string str;
329 58 : if (GetStringAttribute(node(), "nova", &str) ||
330 30 : GetUintAttribute(node(), "nova", &id)) {
331 26 : add_nova_ = true;
332 : }
333 :
334 58 : if (GetStringAttribute(node(), "nova", &str) ||
335 30 : GetUintAttribute(node(), "nova", &id)) {
336 26 : add_nova_ = true;
337 : }
338 :
339 28 : vlan_tag_ = 0;
340 28 : GetUintAttribute(node(), "vlan-tag", &vlan_tag_);
341 28 : GetStringAttribute(node(), "parent-vmi", &parent_vmi_);
342 :
343 28 : xml_attribute attr = node().attribute("fat-flow");
344 33 : 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 28 : return true;
353 28 : }
354 :
355 28 : bool AgentUtXmlVmInterface::ToXml(xml_node *parent) {
356 28 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
357 28 : AddXmlNodeWithValue(&n, "name", name());
358 :
359 28 : if (op_delete() == false) {
360 14 : xml_node n1 = n.append_child("virtual-machine-interface-mac-address");
361 14 : AddXmlNodeWithValue(&n1, "mac-address", mac_);
362 14 : AddIdPerms(&n);
363 :
364 14 : if (vlan_tag_ > 0) {
365 0 : n1 = n.append_child("virtual-machine-interface-properties");
366 : char buff[32];
367 0 : sprintf(buff, "%d", vlan_tag_);
368 0 : AddXmlNodeWithValue(&n1, "sub-interface-vlan-tag", buff);
369 : }
370 :
371 14 : n1 = n.append_child("virtual-machine-interface-fat-flow-protocols");
372 14 : std::vector<uint16_t>::const_iterator it = fat_flow_port_.begin();
373 17 : 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 28 : if (add_nova_) {
383 26 : boost::system::error_code ec;
384 26 : Ip4Address ip = Ip4Address::from_string(ip_, ec);
385 26 : NovaIntfAdd(op_delete(), id(), ip, vm_uuid_, vm_uuid_, name(), mac_,
386 26 : vm_name_);
387 : }
388 :
389 28 : if (vn_name_ != "") {
390 28 : LinkXmlNode(parent, NodeType(), name(), "virtual-network", vn_name_);
391 : }
392 :
393 28 : if (vm_name_ != "") {
394 28 : LinkXmlNode(parent, NodeType(), name(), "virtual-machine", vm_name_);
395 : }
396 :
397 28 : if (vrf_ != "") {
398 28 : string str = name() + "-" + vm_name_;
399 28 : LinkXmlNode(parent, "virtual-machine-interface-routing-instance",
400 28 : str, "routing-instance", vrf_);
401 :
402 28 : LinkXmlNode(parent, NodeType(), name(),
403 : "virtual-machine-interface-routing-instance", str);
404 28 : }
405 :
406 28 : if (parent_vmi_ != "") {
407 0 : LinkXmlNode(parent, NodeType(), name(), "virtual-machine-interface",
408 0 : parent_vmi_);
409 : }
410 28 : return true;
411 : }
412 :
413 28 : void AgentUtXmlVmInterface::ToString(string *str) {
414 28 : AgentUtXmlConfig::ToString(str);
415 28 : *str += "\n";
416 28 : return;
417 : }
418 :
419 140 : string AgentUtXmlVmInterface::NodeType() {
420 140 : 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 12 : AgentUtXmlVrf::AgentUtXmlVrf(const string &name, const uuid &id,
463 : const xml_node &node,
464 12 : AgentUtXmlTestCase *test_case) :
465 12 : AgentUtXmlConfig(name, id, node, test_case) {
466 12 : }
467 :
468 24 : AgentUtXmlVrf::~AgentUtXmlVrf() {
469 24 : }
470 :
471 :
472 12 : bool AgentUtXmlVrf::ReadXml() {
473 12 : if (AgentUtXmlConfig::ReadXml() == false)
474 0 : return false;
475 :
476 12 : GetStringAttribute(node(), "vn", &vn_name_);
477 12 : return true;
478 : }
479 :
480 12 : bool AgentUtXmlVrf::ToXml(xml_node *parent) {
481 12 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
482 12 : AddXmlNodeWithValue(&n, "name", name());
483 12 : AddIdPerms(&n);
484 12 : if (vn_name_ != "") {
485 1 : LinkXmlNode(parent, NodeType(), name(), "virtual-network", vn_name_);
486 : }
487 12 : return true;
488 : }
489 :
490 12 : void AgentUtXmlVrf::ToString(string *str) {
491 12 : AgentUtXmlConfig::ToString(str);
492 12 : *str += "\n";
493 12 : return;
494 : }
495 :
496 25 : string AgentUtXmlVrf::NodeType() {
497 25 : return "routing-instance";
498 : }
499 :
500 : /////////////////////////////////////////////////////////////////////////////
501 : // AgentUtXmlVmiVrf routines
502 : /////////////////////////////////////////////////////////////////////////////
503 22 : AgentUtXmlVmiVrf::AgentUtXmlVmiVrf(const string &name, const uuid &id,
504 : const xml_node &node,
505 22 : AgentUtXmlTestCase *test_case) :
506 22 : AgentUtXmlConfig(name, id, node, test_case) {
507 22 : }
508 :
509 44 : AgentUtXmlVmiVrf::~AgentUtXmlVmiVrf() {
510 44 : }
511 :
512 :
513 22 : bool AgentUtXmlVmiVrf::ReadXml() {
514 22 : return AgentUtXmlConfig::ReadXml();
515 : }
516 :
517 22 : bool AgentUtXmlVmiVrf::ToXml(xml_node *parent) {
518 22 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
519 22 : AddXmlNodeWithValue(&n, "name", name());
520 :
521 22 : xml_node n1 = n.append_child("value");
522 22 : AddXmlNodeWithValue(&n1, "direction", "both");
523 22 : AddXmlNodeWithValue(&n1, "vlan-tag", "0");
524 :
525 22 : AddIdPerms(&n);
526 22 : return true;
527 : }
528 :
529 22 : void AgentUtXmlVmiVrf::ToString(string *str) {
530 22 : AgentUtXmlConfig::ToString(str);
531 22 : *str += "\n";
532 22 : return;
533 : }
534 :
535 44 : string AgentUtXmlVmiVrf::NodeType() {
536 44 : return "virtual-machine-interface-routing-instance";
537 : }
538 :
539 : /////////////////////////////////////////////////////////////////////////////
540 : // AgentUtXmlAcl routines
541 : /////////////////////////////////////////////////////////////////////////////
542 8 : AgentUtXmlAcl::AgentUtXmlAcl(const string &name, const uuid &id,
543 : const xml_node &node,
544 8 : AgentUtXmlTestCase *test_case) :
545 8 : AgentUtXmlConfig(name, id, node, test_case) {
546 8 : }
547 :
548 16 : AgentUtXmlAcl::~AgentUtXmlAcl() {
549 16 : }
550 :
551 8 : bool AgentUtXmlAcl::ReadXml() {
552 8 : if (AgentUtXmlConfig::ReadXml() == false)
553 0 : return false;
554 :
555 20 : 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 8 : return true;
599 : }
600 :
601 8 : bool AgentUtXmlAcl::ToXml(xml_node *parent) {
602 8 : xml_node n = AddXmlNodeWithAttr(parent, NodeType().c_str());
603 8 : AddXmlNodeWithValue(&n, "name", name());
604 :
605 8 : xml_node n1 = n.append_child("access-control-list-entries");
606 8 : AddXmlNodeWithValue(&n1, "dynamic", "false");
607 :
608 20 : 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 8 : AddIdPerms(&n);
669 8 : return true;
670 : }
671 :
672 8 : void AgentUtXmlAcl::ToString(string *str) {
673 8 : AgentUtXmlConfig::ToString(str);
674 8 : *str += "\n";
675 8 : return;
676 : }
677 :
678 16 : string AgentUtXmlAcl::NodeType() {
679 16 : 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 0 : AgentUtXmlGlobalVrouterValidate::AgentUtXmlGlobalVrouterValidate(const string &name,
910 : const uuid &id,
911 0 : const xml_node &node) :
912 0 : AgentUtXmlValidationNode(name, node), id_(id), flow_export_rate_(-1) {
913 0 : }
914 :
915 0 : AgentUtXmlGlobalVrouterValidate::~AgentUtXmlGlobalVrouterValidate() {
916 0 : }
917 :
918 0 : bool AgentUtXmlGlobalVrouterValidate::ReadXml() {
919 0 : GetIntAttribute(node(), "flow-export-rate", &flow_export_rate_);
920 0 : return true;
921 : }
922 :
923 0 : bool AgentUtXmlGlobalVrouterValidate::Validate() {
924 0 : GlobalVrouter *vr = Agent::GetInstance()->oper_db()->global_vrouter();
925 :
926 0 : if (vr == NULL)
927 0 : return false;
928 :
929 0 : if (flow_export_rate_ != -1) {
930 0 : int32_t rate = flow_export_rate_;
931 0 : if (vr->flow_export_rate() != rate)
932 0 : return false;
933 : }
934 :
935 0 : return true;
936 : }
937 :
938 0 : const string AgentUtXmlGlobalVrouterValidate::ToString() {
939 0 : return "global-vrouter-config";
940 : }
941 :
942 : /////////////////////////////////////////////////////////////////////////////
943 : // AgentUtXmlVnValidate routines
944 : /////////////////////////////////////////////////////////////////////////////
945 6 : AgentUtXmlVnValidate::AgentUtXmlVnValidate(const string &name,
946 : const uuid &id,
947 6 : const xml_node &node) :
948 6 : AgentUtXmlValidationNode(name, node), id_(id), vxlan_id_(0),
949 6 : vxlan_id_ref_(false) {
950 6 : }
951 :
952 12 : AgentUtXmlVnValidate::~AgentUtXmlVnValidate() {
953 12 : }
954 :
955 6 : bool AgentUtXmlVnValidate::ReadXml() {
956 6 : GetUintAttribute(node(), "vxlan-id", &vxlan_id_);
957 6 : check_vxlan_id_ref_ = GetUintAttribute(node(), "vxlan-id-ref", &vxlan_id_ref_);
958 6 : return true;
959 : }
960 :
961 6 : bool AgentUtXmlVnValidate::Validate() {
962 6 : VnEntry *vn = VnGet(id());
963 6 : if (present() == false) {
964 1 : return (vn == NULL);
965 : }
966 :
967 5 : if (vn == NULL)
968 0 : return false;
969 :
970 5 : if (vxlan_id_ != 0) {
971 0 : if (vn->GetVxLanId() != vxlan_id_)
972 0 : return false;
973 : }
974 :
975 5 : if (check_vxlan_id_ref_) {
976 0 : if (vxlan_id_ref_ == 0) {
977 0 : if (vn->vxlan_id_ref() != NULL)
978 0 : return false;
979 : }
980 :
981 0 : if (vxlan_id_ref_) {
982 0 : const VxLanId *vxlan = vn->vxlan_id_ref();
983 0 : if (vxlan == NULL)
984 0 : return false;
985 :
986 0 : if (vxlan->vxlan_id() != vxlan_id_ref_)
987 0 : return false;
988 : }
989 : }
990 :
991 :
992 5 : return true;
993 : }
994 :
995 12 : const string AgentUtXmlVnValidate::ToString() {
996 12 : return "virtual-network";
997 : }
998 :
999 : /////////////////////////////////////////////////////////////////////////////
1000 : // AgentUtXmlVmValidate routines
1001 : /////////////////////////////////////////////////////////////////////////////
1002 10 : AgentUtXmlVmValidate::AgentUtXmlVmValidate(const string &name,
1003 : const uuid &id,
1004 10 : const xml_node &node) :
1005 10 : AgentUtXmlValidationNode(name, node), id_(id) {
1006 10 : }
1007 :
1008 20 : AgentUtXmlVmValidate::~AgentUtXmlVmValidate() {
1009 20 : }
1010 :
1011 10 : bool AgentUtXmlVmValidate::ReadXml() {
1012 10 : return true;
1013 : }
1014 :
1015 10 : bool AgentUtXmlVmValidate::Validate() {
1016 10 : return true;
1017 : }
1018 :
1019 20 : const string AgentUtXmlVmValidate::ToString() {
1020 20 : return "virtual-machine";
1021 : }
1022 :
1023 : /////////////////////////////////////////////////////////////////////////////
1024 : // AgentUtXmlVxlanValidate routines
1025 : /////////////////////////////////////////////////////////////////////////////
1026 0 : AgentUtXmlVxlanValidate::AgentUtXmlVxlanValidate(const string &name,
1027 : const uuid &id,
1028 0 : const xml_node &node) :
1029 0 : AgentUtXmlValidationNode(name, node), id_(id), vxlan_id_(0), vrf_(),
1030 0 : flood_unknown_unicast_() {
1031 0 : }
1032 :
1033 0 : AgentUtXmlVxlanValidate::~AgentUtXmlVxlanValidate() {
1034 0 : }
1035 :
1036 0 : bool AgentUtXmlVxlanValidate::ReadXml() {
1037 0 : GetUintAttribute(node(), "vxlan-id", &vxlan_id_);
1038 0 : GetStringAttribute(node(), "vrf", &vrf_);
1039 0 : GetStringAttribute(node(), "flood-unknown-unicast", &flood_unknown_unicast_);
1040 0 : return true;
1041 : }
1042 :
1043 0 : bool AgentUtXmlVxlanValidate::Validate() {
1044 0 : VxLanId *vxlan = VxlanGet(vxlan_id_);
1045 :
1046 0 : if (!present()) {
1047 0 : return (vxlan == NULL);
1048 : }
1049 :
1050 0 : if (vxlan == NULL)
1051 0 : return false;
1052 :
1053 0 : if (vxlan->vxlan_id() != vxlan_id_)
1054 0 : return false;
1055 :
1056 0 : if (flood_unknown_unicast_.empty() == false) {
1057 0 : const VrfNH *nh = dynamic_cast<const VrfNH *>(vxlan->nexthop());
1058 0 : if (nh == NULL)
1059 0 : return false;
1060 :
1061 0 : if (flood_unknown_unicast_ == "true" ||
1062 0 : flood_unknown_unicast_ == "yes") {
1063 0 : return (nh->flood_unknown_unicast() == true);
1064 : } else {
1065 0 : return (nh->flood_unknown_unicast() == false);
1066 : }
1067 : }
1068 :
1069 0 : if (vrf_.empty() == false) {
1070 0 : const VrfNH *nh = dynamic_cast<const VrfNH *>(vxlan->nexthop());
1071 0 : if (nh == NULL)
1072 0 : return false;
1073 :
1074 0 : if (nh->GetType() != NextHop::VRF)
1075 0 : return false;
1076 :
1077 0 : const VrfEntry *vrf = nh->GetVrf();
1078 0 : if (vrf == NULL)
1079 0 : return false;
1080 :
1081 0 : if (vrf->GetName() != vrf_)
1082 0 : return false;
1083 : }
1084 :
1085 0 : return true;
1086 : }
1087 :
1088 0 : const string AgentUtXmlVxlanValidate::ToString() {
1089 0 : return "vxlan";
1090 : }
1091 :
1092 : /////////////////////////////////////////////////////////////////////////////
1093 : // AgentUtXmlVmInterfaceValidate routines
1094 : /////////////////////////////////////////////////////////////////////////////
1095 13 : AgentUtXmlVmInterfaceValidate::AgentUtXmlVmInterfaceValidate(const string &name,
1096 : const uuid &id,
1097 13 : const xml_node &node) :
1098 13 : AgentUtXmlValidationNode(name, node), id_(id), vlan_tag_(0), vn_uuid_() {
1099 13 : }
1100 :
1101 26 : AgentUtXmlVmInterfaceValidate::~AgentUtXmlVmInterfaceValidate() {
1102 26 : }
1103 :
1104 13 : bool AgentUtXmlVmInterfaceValidate::ReadXml() {
1105 13 : GetUintAttribute(node(), "vlan", &vlan_tag_);
1106 13 : GetStringAttribute(node(), "active", &active_);
1107 13 : GetStringAttribute(node(), "device-type", &device_type_);
1108 13 : GetStringAttribute(node(), "vmi-type", &vmi_type_);
1109 13 : uint16_t id = 0;
1110 13 : GetUintAttribute(node(), "vn-uuid", &id);
1111 13 : if (id) {
1112 0 : vn_uuid_ = MakeUuid(id);
1113 : }
1114 :
1115 13 : return true;
1116 : }
1117 :
1118 0 : static string DeviceTypeToString(VmInterface::DeviceType type) {
1119 0 : if (type == VmInterface::VM_ON_TAP)
1120 0 : return "VM-Tap";
1121 0 : if (type == VmInterface::VM_VLAN_ON_VMI)
1122 0 : 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 0 : static string VmiTypeToString(VmInterface::VmiType type) {
1132 0 : if (type == VmInterface::INSTANCE)
1133 0 : 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 13 : bool AgentUtXmlVmInterfaceValidate::Validate() {
1143 13 : VmInterface *vmi = VmInterfaceGet(id());
1144 :
1145 13 : if (present()) {
1146 12 : if (vmi == NULL)
1147 0 : return false;
1148 : } else {
1149 1 : return vmi == NULL;
1150 : }
1151 :
1152 12 : if (active_.empty() == false) {
1153 30 : if (boost::iequals(active_, "true") ||
1154 20 : (boost::iequals(active_, "0") == false)){
1155 10 : if (VmPortActive(id()) == false)
1156 0 : return false;
1157 : } else {
1158 0 : if (VmPortActive(id()) == true)
1159 0 : return false;
1160 : }
1161 : }
1162 :
1163 12 : if (device_type_.empty() == false) {
1164 0 : if (boost::iequals(device_type_, DeviceTypeToString(vmi->device_type()))
1165 0 : == false)
1166 0 : return false;
1167 : }
1168 :
1169 12 : if (vmi_type_.empty() == false) {
1170 0 : if (boost::iequals(vmi_type_, VmiTypeToString(vmi->vmi_type()))
1171 0 : == false)
1172 0 : return false;
1173 : }
1174 :
1175 12 : if (vlan_tag_ > 0) {
1176 0 : if (vmi->rx_vlan_id() != vlan_tag_)
1177 0 : return false;
1178 : }
1179 :
1180 12 : if (vn_uuid_.is_nil() == false) {
1181 0 : const VnEntry *vn = vmi->vn();
1182 0 : if (vn == NULL)
1183 0 : return false;
1184 :
1185 0 : if (vn->GetUuid() != vn_uuid_)
1186 0 : return false;
1187 : }
1188 :
1189 12 : return true;
1190 : }
1191 :
1192 26 : const string AgentUtXmlVmInterfaceValidate::ToString() {
1193 26 : 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 1 : AgentUtXmlVrfValidate::AgentUtXmlVrfValidate(const string &name,
1224 1 : const xml_node &node) :
1225 1 : AgentUtXmlValidationNode(name, node) {
1226 1 : }
1227 :
1228 2 : AgentUtXmlVrfValidate::~AgentUtXmlVrfValidate() {
1229 2 : }
1230 :
1231 1 : bool AgentUtXmlVrfValidate::ReadXml() {
1232 1 : GetStringAttribute(node(), "vn", &vn_name_);
1233 1 : return true;
1234 : }
1235 :
1236 1 : bool AgentUtXmlVrfValidate::Validate() {
1237 :
1238 1 : VrfEntry *vrf = VrfGet(name().c_str(), true);
1239 :
1240 1 : if (present() && (vrf == NULL)) {
1241 0 : return false;
1242 1 : } else if (!present() && (vrf != NULL)) {
1243 0 : return false;
1244 : }
1245 :
1246 1 : if (vrf == NULL)
1247 1 : return true;
1248 :
1249 0 : if (delete_marked()) {
1250 0 : if (vrf->IsDeleted() == false)
1251 0 : return false;
1252 : }
1253 :
1254 0 : if (vn_name_ == "") {
1255 0 : return true;
1256 : }
1257 :
1258 0 : if (vn_name_ == "nil" || vn_name_ == "NIL") {
1259 0 : return (vrf->vn() == NULL);
1260 : }
1261 :
1262 0 : if (vrf->vn() == NULL)
1263 0 : return false;
1264 :
1265 0 : return (vrf->vn()->GetName() == vn_name_);
1266 : }
1267 :
1268 2 : const string AgentUtXmlVrfValidate::ToString() {
1269 2 : 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 42 : AgentUtXmlFlowValidate::AgentUtXmlFlowValidate(const string &name,
1303 42 : const xml_node &node) :
1304 42 : AgentUtXmlValidationNode(name, node) {
1305 42 : }
1306 :
1307 84 : AgentUtXmlFlowValidate::~AgentUtXmlFlowValidate() {
1308 84 : }
1309 :
1310 42 : bool AgentUtXmlFlowValidate::ReadXml() {
1311 42 : if (GetUintAttribute(node(), "nh", &nh_id_) == false) {
1312 0 : cout << "Attribute \"nh\" not specified for Flow. Skipping" << endl;
1313 0 : return false;
1314 : }
1315 :
1316 42 : if (GetStringAttribute(node(), "sip", &sip_) == false) {
1317 0 : cout << "Attribute \"sip\" not specified for Flow. Skipping" << endl;
1318 0 : return false;
1319 : }
1320 :
1321 42 : if (GetStringAttribute(node(), "dip", &dip_) == false) {
1322 0 : cout << "Attribute \"dip\" not specified for Flow. Skipping" << endl;
1323 0 : return false;
1324 : }
1325 :
1326 84 : if (GetStringAttribute(node(), "proto", &proto_) == false &&
1327 42 : GetUintAttribute(node(), "proto", &proto_id_) == false) {
1328 0 : cout << "Attribute \"proto\" not specified for Flow. Skipping"
1329 0 : << endl;
1330 0 : return false;
1331 : }
1332 :
1333 42 : if (proto_ == "tcp" || proto_ == "udp") {
1334 42 : if (proto_ == "tcp")
1335 0 : proto_id_ = 6;
1336 : else
1337 42 : proto_id_ = 17;
1338 42 : if (GetUintAttribute(node(), "sport", &sport_) == false) {
1339 0 : cout << "Attribute \"sport\" not specified for Flow. Skipping"
1340 0 : << endl;
1341 0 : return false;
1342 : }
1343 :
1344 42 : if (GetUintAttribute(node(), "dport", &dport_) == false) {
1345 0 : cout << "Attribute \"dport\" not specified for Flow. Skipping"
1346 0 : << endl; return false;
1347 : }
1348 : }
1349 :
1350 42 : GetStringAttribute(node(), "svn", &svn_);
1351 42 : GetStringAttribute(node(), "dvn", &dvn_);
1352 42 : GetStringAttribute(node(), "action", &action_);
1353 42 : if (GetUintAttribute(node(), "rpf_nh", &rpf_nh_) == false) {
1354 25 : rpf_nh_ = 0;
1355 : }
1356 42 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1357 0 : vrf_ ="";
1358 : }
1359 42 : if (GetStringAttribute(node(), "deleted", &deleted_) == false) {
1360 42 : deleted_ = "false";
1361 : }
1362 42 : return true;
1363 : }
1364 :
1365 42 : static bool MatchFlowAction(FlowEntry *flow, const string &str) {
1366 42 : uint64_t action = flow->data().match_p.action_info.action;
1367 42 : if (str == "pass") {
1368 22 : return (action & (1 << TrafficAction::PASS));
1369 : }
1370 :
1371 20 : if (str == "deny") {
1372 40 : return (((action & TrafficAction::DROP_FLAGS) != 0) |
1373 20 : (flow->IsShortFlow()));
1374 : }
1375 :
1376 0 : return false;
1377 : }
1378 :
1379 42 : bool AgentUtXmlFlowValidate::Validate() {
1380 42 : FlowEntry *flow = FlowGet(0, sip_, dip_, proto_id_, sport_, dport_,
1381 42 : nh_id_);
1382 42 : if (deleted_ == "true" && flow == NULL) {
1383 0 : return true;
1384 : }
1385 :
1386 42 : if (present() == false)
1387 0 : return (flow == NULL);
1388 :
1389 42 : if (flow == NULL) {
1390 0 : return false;
1391 : }
1392 :
1393 42 : if (svn_ != "" && !VnMatch(flow->data().source_vn_list, svn_))
1394 0 : return false;
1395 :
1396 42 : if (dvn_ != "" && !VnMatch(flow->data().dest_vn_list, dvn_))
1397 0 : return false;
1398 :
1399 42 : if (MatchFlowAction(flow, action_) == false) {
1400 0 : return false;
1401 : }
1402 :
1403 42 : if (rpf_nh_) {
1404 17 : int nh_id = 0;
1405 17 : if (vrf_ != "") {
1406 17 : Agent *agent = Agent::GetInstance();
1407 : InetUnicastAgentRouteTable *inet_table =
1408 : static_cast<InetUnicastAgentRouteTable *>
1409 17 : (agent->vrf_table()->GetInet4UnicastRouteTable(vrf_));
1410 : InetUnicastRouteEntry *rt =
1411 17 : inet_table->FindRoute(Ip4Address::from_string(sip_));
1412 17 : if ( rt != NULL) {
1413 15 : const NextHop *nh = rt->GetActiveNextHop();
1414 15 : if ( nh && (nh->id() != rpf_nh_)) {
1415 3 : nh_id = nh->id();
1416 : }
1417 : }
1418 : }
1419 17 : if (rpf_nh_ == NextHopTable::kRpfDiscardIndex) {
1420 0 : if (flow->data().rpf_nh.get() != NULL) {
1421 0 : return false;
1422 : }
1423 34 : } else if (!flow->data().rpf_nh.get() ||
1424 17 : ((flow->data().rpf_nh.get()->id() != rpf_nh_) &&
1425 0 : (flow->data().rpf_nh.get()->id() != nh_id))) {
1426 0 : return false;
1427 : }
1428 : }
1429 42 : return true;
1430 : }
1431 :
1432 84 : const string AgentUtXmlFlowValidate::ToString() {
1433 168 : return ("flow <" + name() + ">");
1434 : }
1435 :
1436 42 : uint32_t AgentUtXmlFlowValidate::wait_count() const {
1437 42 : if (present()) {
1438 42 : return 10;
1439 : } else {
1440 0 : return AgentUtXmlValidationNode::wait_count();
1441 : }
1442 : }
1443 :
1444 : /////////////////////////////////////////////////////////////////////////////
1445 : // AgentUtXmlL2Route routines
1446 : /////////////////////////////////////////////////////////////////////////////
1447 11 : AgentUtXmlL2Route::AgentUtXmlL2Route(const string &name, const uuid &id,
1448 : const xml_node &node,
1449 11 : AgentUtXmlTestCase *test_case) :
1450 11 : AgentUtXmlNode(name, node, false, test_case) {
1451 11 : }
1452 :
1453 22 : AgentUtXmlL2Route::~AgentUtXmlL2Route() {
1454 22 : }
1455 :
1456 :
1457 11 : bool AgentUtXmlL2Route::ReadXml() {
1458 11 : if (GetStringAttribute(node(), "mac", &mac_) == false) {
1459 0 : cout << "Attribute \"mac\" not specified. Skipping" << endl;
1460 0 : return false;
1461 : }
1462 :
1463 11 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1464 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1465 0 : return false;
1466 : }
1467 :
1468 11 : GetStringAttribute(node(), "ip", &ip_);
1469 11 : GetStringAttribute(node(), "vn", &vn_);
1470 11 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1471 11 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1472 11 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1473 11 : GetUintAttribute(node(), "sg", &sg_id_);
1474 11 : GetUintAttribute(node(), "tag", &tag_id_);
1475 11 : GetUintAttribute(node(), "label", &label_);
1476 11 : if (ip_.empty()) {
1477 11 : ip_ = "0.0.0.0";
1478 : }
1479 11 : return true;
1480 : }
1481 :
1482 0 : bool AgentUtXmlL2Route::ToXml(xml_node *parent) {
1483 0 : assert(0);
1484 : return true;
1485 : }
1486 :
1487 11 : void AgentUtXmlL2Route::ToString(string *str) {
1488 11 : *str = "L2-Route";
1489 11 : return;
1490 : }
1491 :
1492 0 : string AgentUtXmlL2Route::NodeType() {
1493 0 : return "FDB";
1494 : }
1495 :
1496 11 : bool AgentUtXmlL2Route::Run() {
1497 11 : Agent *agent = Agent::GetInstance();
1498 : EvpnAgentRouteTable *rt_table =
1499 : static_cast<EvpnAgentRouteTable *>
1500 11 : (Agent::GetInstance()->vrf_table()->GetEvpnRouteTable(vrf_));
1501 :
1502 11 : SecurityGroupList sg_list;
1503 11 : TagList tag_list;
1504 11 : if (sg_id_)
1505 9 : sg_list.push_back(sg_id_);
1506 11 : if (tag_id_)
1507 0 : tag_list.push_back(tag_id_);
1508 :
1509 11 : TunnelType::TypeBmap bmap = 0;
1510 : TunnelEncapType::Encap encap =
1511 11 : TunnelEncapType::TunnelEncapFromString(tunnel_type_);
1512 11 : if (encap == TunnelEncapType::MPLS_O_GRE)
1513 0 : bmap |= (1 << TunnelType::MPLS_GRE);
1514 11 : if (encap == TunnelEncapType::MPLS_O_UDP)
1515 0 : bmap |= (1 << TunnelType::MPLS_UDP);
1516 11 : if (encap == TunnelEncapType::VXLAN)
1517 9 : bmap |= (1 << TunnelType::VXLAN);
1518 11 : if (op_delete()) {
1519 10 : rt_table->DeleteReq(bgp_peer_, vrf_,
1520 5 : MacAddress::FromString(mac_),
1521 10 : Ip4Address::from_string(ip_), 32, vxlan_id_,
1522 5 : (new ControllerVmRoute(bgp_peer_)));
1523 : } else {
1524 6 : VnListType vn_list;
1525 6 : vn_list.insert(vn_);
1526 : ControllerVmRoute *data =
1527 6 : ControllerVmRoute::MakeControllerVmRoute(bgp_peer_,
1528 : agent->fabric_vrf_name(),
1529 6 : agent->router_id(), vrf_,
1530 0 : Ip4Address::from_string(tunnel_dest_),
1531 6 : bmap, label_, MacAddress(),
1532 : vn_list, sg_list, tag_list,
1533 12 : PathPreference(), false,
1534 12 : EcmpLoadBalance(), false);
1535 12 : rt_table->AddRemoteVmRouteReq(bgp_peer_, vrf_,
1536 6 : MacAddress::FromString(mac_),
1537 0 : Ip4Address::from_string(ip_),
1538 6 : 32, vxlan_id_, data);
1539 6 : }
1540 11 : return true;
1541 11 : }
1542 :
1543 : /////////////////////////////////////////////////////////////////////////////
1544 : // AgentUtXmlL2RouteValidate routines
1545 : /////////////////////////////////////////////////////////////////////////////
1546 0 : AgentUtXmlL2RouteValidate::AgentUtXmlL2RouteValidate(const string &name,
1547 0 : const xml_node &node) :
1548 0 : AgentUtXmlValidationNode(name, node) {
1549 0 : }
1550 :
1551 0 : AgentUtXmlL2RouteValidate::~AgentUtXmlL2RouteValidate() {
1552 0 : }
1553 :
1554 0 : bool AgentUtXmlL2RouteValidate::ReadXml() {
1555 0 : if (GetStringAttribute(node(), "mac", &mac_) == false) {
1556 0 : cout << "Attribute \"mac\" not specified. Skipping" << endl;
1557 0 : return false;
1558 : }
1559 :
1560 0 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1561 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1562 0 : return false;
1563 : }
1564 :
1565 0 : if (GetStringAttribute(node(), "vn", &vn_) == false) {
1566 0 : cout << "Attribute \"vn\" not specified. Skipping" << endl;
1567 0 : return false;
1568 : }
1569 :
1570 0 : string addr = "";
1571 0 : GetStringAttribute(node(), "ip", &addr);
1572 0 : boost::system::error_code ec;
1573 0 : ip_ = IpAddress::from_string(addr, ec);
1574 :
1575 0 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1576 0 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1577 0 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1578 0 : GetUintAttribute(node(), "intf", &intf_uuid_);
1579 :
1580 0 : return true;
1581 0 : }
1582 :
1583 0 : bool AgentUtXmlL2RouteValidate::Validate() {
1584 0 : Agent *agent = Agent::GetInstance();
1585 : BridgeAgentRouteTable *bridge_table =
1586 : static_cast<BridgeAgentRouteTable *>
1587 0 : (agent->vrf_table()->GetBridgeRouteTable(vrf_));
1588 : BridgeRouteEntry *rt =
1589 0 : bridge_table->FindRoute(MacAddress::FromString(mac_));
1590 0 : if (present() == false)
1591 0 : return (rt == NULL);
1592 :
1593 0 : if (rt == NULL)
1594 0 : return false;
1595 :
1596 0 : if (vn_ != "" && vn_ != rt->dest_vn_name())
1597 0 : return false;
1598 :
1599 0 : return true;
1600 : }
1601 :
1602 0 : const string AgentUtXmlL2RouteValidate::ToString() {
1603 0 : return ("FDB <" + name() + ">");
1604 : }
1605 :
1606 6 : AgentUtXmlL3Route::AgentUtXmlL3Route(const string &name, const uuid &id,
1607 : const xml_node &node,
1608 6 : AgentUtXmlTestCase *test_case) :
1609 6 : AgentUtXmlNode(name, node, false, test_case) {
1610 6 : }
1611 :
1612 12 : AgentUtXmlL3Route::~AgentUtXmlL3Route() {
1613 12 : }
1614 :
1615 :
1616 6 : bool AgentUtXmlL3Route::ReadXml() {
1617 6 : if (GetStringAttribute(node(), "src-ip", &src_ip_) == false) {
1618 0 : cout << "Attribute \"ip\" not specified. Skipping" << endl;
1619 0 : return false;
1620 : }
1621 :
1622 6 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1623 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1624 0 : return false;
1625 : }
1626 :
1627 6 : GetStringAttribute(node(), "ip", &ip_);
1628 6 : GetStringAttribute(node(), "vn", &vn_);
1629 6 : GetUintAttribute(node(), "plen", &plen_);
1630 6 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1631 6 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1632 6 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1633 6 : GetUintAttribute(node(), "sg", &sg_id_);
1634 6 : GetUintAttribute(node(), "tag", &tag_id_);
1635 6 : GetUintAttribute(node(), "label", &label_);
1636 6 : if (ip_.empty()) {
1637 6 : ip_ = "0.0.0.0";
1638 : }
1639 6 : return true;
1640 : }
1641 :
1642 0 : bool AgentUtXmlL3Route::ToXml(xml_node *parent) {
1643 0 : assert(0);
1644 : return true;
1645 : }
1646 :
1647 6 : void AgentUtXmlL3Route::ToString(string *str) {
1648 6 : *str = "L3-Route";
1649 6 : return;
1650 : }
1651 :
1652 0 : string AgentUtXmlL3Route::NodeType() {
1653 0 : return "L3-Route";
1654 : }
1655 :
1656 6 : bool AgentUtXmlL3Route::Run() {
1657 6 : Agent *agent = Agent::GetInstance();
1658 : InetUnicastAgentRouteTable *rt_table =
1659 : static_cast<InetUnicastAgentRouteTable *>
1660 6 : (Agent::GetInstance()->vrf_table()->GetInet4UnicastRouteTable(vrf_));
1661 :
1662 6 : SecurityGroupList sg_list;
1663 6 : TagList tag_list;
1664 6 : if (sg_id_)
1665 6 : sg_list.push_back(sg_id_);
1666 6 : if (tag_id_)
1667 0 : tag_list.push_back(tag_id_);
1668 :
1669 6 : TunnelType::TypeBmap bmap = 0;
1670 : TunnelEncapType::Encap encap =
1671 6 : TunnelEncapType::TunnelEncapFromString(tunnel_type_);
1672 6 : if (encap == TunnelEncapType::MPLS_O_GRE)
1673 0 : bmap |= (1 << TunnelType::MPLS_GRE);
1674 6 : if (encap == TunnelEncapType::MPLS_O_UDP)
1675 0 : bmap |= (1 << TunnelType::MPLS_UDP);
1676 6 : if (encap == TunnelEncapType::VXLAN)
1677 0 : bmap |= (1 << TunnelType::VXLAN);
1678 6 : if (op_delete()) {
1679 3 : rt_table->DeleteReq(bgp_peer_, vrf_,
1680 6 : Ip4Address::from_string(src_ip_), plen_,
1681 3 : (new ControllerVmRoute(bgp_peer_)));
1682 : } else {
1683 3 : VnListType vn_list;
1684 3 : vn_list.insert(vn_);
1685 : ControllerVmRoute *data =
1686 3 : ControllerVmRoute::MakeControllerVmRoute(bgp_peer_,
1687 : agent->fabric_vrf_name(),
1688 3 : agent->router_id(), vrf_,
1689 0 : Ip4Address::from_string(tunnel_dest_),
1690 3 : bmap, label_, MacAddress(),
1691 : vn_list, sg_list, tag_list,
1692 6 : PathPreference(), false,
1693 6 : EcmpLoadBalance(),
1694 : false);
1695 3 : rt_table->AddRemoteVmRouteReq(bgp_peer_, vrf_,
1696 3 : Ip4Address::from_string(src_ip_), plen_,
1697 : data);
1698 3 : }
1699 6 : return true;
1700 6 : }
1701 :
1702 0 : AgentUtXmlL3RouteValidate::AgentUtXmlL3RouteValidate(const string &name,
1703 0 : const xml_node &node) :
1704 0 : AgentUtXmlValidationNode(name, node) {
1705 0 : }
1706 :
1707 0 : AgentUtXmlL3RouteValidate::~AgentUtXmlL3RouteValidate() {
1708 0 : }
1709 :
1710 0 : bool AgentUtXmlL3RouteValidate::ReadXml() {
1711 0 : if (GetStringAttribute(node(), "src-ip", &src_ip_) == false) {
1712 0 : cout << "Attribute \"mac\" not specified. Skipping" << endl;
1713 0 : return false;
1714 : }
1715 :
1716 0 : if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1717 0 : cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1718 0 : return false;
1719 : }
1720 :
1721 0 : if (GetStringAttribute(node(), "vn", &vn_) == false) {
1722 0 : cout << "Attribute \"vn\" not specified. Skipping" << endl;
1723 0 : return false;
1724 : }
1725 :
1726 0 : string addr = "";
1727 0 : GetStringAttribute(node(), "ip", &addr);
1728 0 : boost::system::error_code ec;
1729 0 : ip_ = IpAddress::from_string(addr, ec);
1730 :
1731 0 : GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1732 0 : GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1733 0 : GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1734 0 : GetUintAttribute(node(), "intf", &intf_uuid_);
1735 :
1736 0 : return true;
1737 0 : }
1738 :
1739 0 : bool AgentUtXmlL3RouteValidate::Validate() {
1740 0 : Agent *agent = Agent::GetInstance();
1741 : InetUnicastAgentRouteTable *inet_table =
1742 : static_cast<InetUnicastAgentRouteTable *>
1743 0 : (agent->vrf_table()->GetInet4UnicastRouteTable(vrf_));
1744 : InetUnicastRouteEntry *rt =
1745 0 : inet_table->FindRoute(Ip4Address::from_string(src_ip_));
1746 0 : if (present() == false)
1747 0 : return (rt == NULL);
1748 :
1749 0 : if (rt == NULL)
1750 0 : return false;
1751 :
1752 0 : if (vn_ != "" && vn_ != rt->dest_vn_name())
1753 0 : return false;
1754 :
1755 0 : return true;
1756 : }
1757 :
1758 0 : const string AgentUtXmlL3RouteValidate::ToString() {
1759 0 : return ("IP route <" + name() + ">");
1760 : }
|