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