OpenSDN source code
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 
1120  return "VM-Tap";
1122  return "VM-Sub-Intf";
1123  if (type == VmInterface::TOR)
1124  return "Tor";
1126  return "Baremetal";
1127  return "Invalid";
1128 
1129 }
1130 
1132  if (type == VmInterface::INSTANCE)
1133  return "vm";
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), attempt_(0), nh_auto_(false) {
1305 }
1306 
1308 }
1309 
1311  if (GetUintAttribute(node(), "nh", &nh_id_) == false) {
1312  nh_id_ = 0;
1313  nh_auto_ = true;
1314  } else {
1315  nh_auto_ = false;
1316  }
1317 
1318  if (GetStringAttribute(node(), "sip", &sip_) == false) {
1319  cout << "Attribute \"sip\" not specified for Flow. Skipping" << endl;
1320  return false;
1321  }
1322 
1323  if (GetStringAttribute(node(), "dip", &dip_) == false) {
1324  cout << "Attribute \"dip\" not specified for Flow. Skipping" << endl;
1325  return false;
1326  }
1327 
1328  if (GetStringAttribute(node(), "proto", &proto_) == false &&
1329  GetUintAttribute(node(), "proto", &proto_id_) == false) {
1330  cout << "Attribute \"proto\" not specified for Flow. Skipping"
1331  << endl;
1332  return false;
1333  }
1334 
1335  if (proto_ == "tcp" || proto_ == "udp") {
1336  if (proto_ == "tcp")
1337  proto_id_ = 6;
1338  else
1339  proto_id_ = 17;
1340  if (GetUintAttribute(node(), "sport", &sport_) == false) {
1341  cout << "Attribute \"sport\" not specified for Flow. Skipping"
1342  << endl;
1343  return false;
1344  }
1345 
1346  if (GetUintAttribute(node(), "dport", &dport_) == false) {
1347  cout << "Attribute \"dport\" not specified for Flow. Skipping"
1348  << endl; return false;
1349  }
1350  }
1351 
1352  GetStringAttribute(node(), "svn", &svn_);
1353  GetStringAttribute(node(), "dvn", &dvn_);
1354  GetStringAttribute(node(), "action", &action_);
1355  if (GetUintAttribute(node(), "rpf_nh", &rpf_nh_) == false) {
1356  rpf_nh_ = 0;
1357  }
1358  if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1359  vrf_ ="";
1360  }
1361  if (GetStringAttribute(node(), "deleted", &deleted_) == false) {
1362  deleted_ = "false";
1363  }
1364  return true;
1365 }
1366 
1367 static bool MatchFlowAction(FlowEntry *flow, const string &str) {
1368  uint64_t action = flow->data().match_p.action_info.action;
1369  if (str == "pass") {
1370  return (action & (1 << TrafficAction::PASS));
1371  }
1372 
1373  if (str == "deny") {
1374  return (((action & TrafficAction::DROP_FLAGS) != 0) |
1375  (flow->IsShortFlow()));
1376  }
1377 
1378  return false;
1379 }
1380 
1382  Agent *agent = Agent::GetInstance();
1383  if (agent == NULL || agent->nexthop_table() == NULL) {
1384  return;
1385  }
1386 
1387  cout << " flow <" << name() << "> not found with nh=" << nh_id_
1388  << " (key: vrf=" << vrf_ << " " << sip_ << " -> " << dip_
1389  << " proto=" << proto_id_ << " " << sport_ << "/" << dport_ << ")"
1390  << endl;
1391 
1392  bool found = false;
1393  DBTablePartition *part = static_cast<DBTablePartition *>
1394  (agent->nexthop_table()->GetTablePartition(0));
1395  for (DBEntry *e = part->GetFirst(); e != NULL; e = part->GetNext(e)) {
1396  NextHop *nh = static_cast<NextHop *>(e);
1397  FlowEntry *f = FlowGet(0, sip_, dip_, proto_id_, sport_, dport_,
1398  nh->id());
1399  if (f != NULL) {
1400  found = true;
1401  cout << " ==> MATCHES with nh=\"" << nh->id() << "\""
1402  << " (nh type=" << nh->GetType()
1403  << ", " << nh->ToString() << ")" << endl;
1404  }
1405  }
1406  if (found == false) {
1407  cout << " ==> no nexthop index yields this flow; the flow itself was"
1408  " not created (check the packet, not the nh)" << endl;
1409  }
1410 }
1411 
1413  Agent *agent = Agent::GetInstance();
1414  if (agent == NULL || agent->nexthop_table() == NULL) {
1415  return NULL;
1416  }
1417 
1418  FlowEntry *result = NULL;
1419  uint32_t matches = 0;
1420  DBTablePartition *part = static_cast<DBTablePartition *>
1421  (agent->nexthop_table()->GetTablePartition(0));
1422  for (DBEntry *e = part->GetFirst(); e != NULL; e = part->GetNext(e)) {
1423  NextHop *nh = static_cast<NextHop *>(e);
1424  FlowEntry *f = FlowGet(0, sip_, dip_, proto_id_, sport_, dport_,
1425  nh->id());
1426  if (f != NULL) {
1427  matches++;
1428  if (result == NULL) {
1429  result = f;
1430  *found_nh = nh->id();
1431  }
1432  }
1433  }
1434 
1435  if (matches > 1) {
1436  cout << " flow <" << name() << "> matches " << matches
1437  << " nexthops; the key is ambiguous -- specify nh= explicitly"
1438  << endl;
1439  return NULL;
1440  }
1441  return result;
1442 }
1443 
1445  FlowEntry *flow = NULL;
1446  uint16_t used_nh = nh_id_;
1447  if (nh_auto_) {
1448  flow = FindFlowAnyNh(&used_nh);
1449  } else {
1450  flow = FlowGet(0, sip_, dip_, proto_id_, sport_, dport_, nh_id_);
1451  }
1452 
1453  if (deleted_ == "true" && flow == NULL) {
1454  return true;
1455  }
1456 
1457  if (present() == false)
1458  return (flow == NULL);
1459 
1460  if (flow == NULL) {
1461  if (nh_auto_ == false && ++attempt_ >= wait_count()) {
1462  SuggestNhId();
1463  }
1464  return false;
1465  }
1466 
1467  if (nh_auto_) {
1468  cout << " flow <" << name() << "> resolved to nh=" << used_nh << endl;
1469  }
1470 
1471  if (svn_ != "" && !VnMatch(flow->data().source_vn_list, svn_))
1472  return false;
1473 
1474  if (dvn_ != "" && !VnMatch(flow->data().dest_vn_list, dvn_))
1475  return false;
1476 
1477  if (MatchFlowAction(flow, action_) == false) {
1478  return false;
1479  }
1480 
1481  if (rpf_nh_) {
1482  int nh_id = 0;
1483  if (vrf_ != "") {
1484  Agent *agent = Agent::GetInstance();
1485  InetUnicastAgentRouteTable *inet_table =
1486  static_cast<InetUnicastAgentRouteTable *>
1488  InetUnicastRouteEntry *rt =
1489  inet_table->FindRoute(Ip4Address::from_string(sip_));
1490  if ( rt != NULL) {
1491  const NextHop *nh = rt->GetActiveNextHop();
1492  if ( nh && (nh->id() != rpf_nh_)) {
1493  nh_id = nh->id();
1494  }
1495  }
1496  }
1498  if (flow->data().rpf_nh.get() != NULL) {
1499  return false;
1500  }
1501  } else if (!flow->data().rpf_nh.get() ||
1502  ((flow->data().rpf_nh.get()->id() != rpf_nh_) &&
1503  (flow->data().rpf_nh.get()->id() != nh_id))) {
1504  return false;
1505  }
1506  }
1507  return true;
1508 }
1509 
1511  return ("flow <" + name() + ">");
1512 }
1513 
1515  if (present()) {
1516  return 10;
1517  } else {
1519  }
1520 }
1521 
1523 // AgentUtXmlL2Route routines
1525 AgentUtXmlL2Route::AgentUtXmlL2Route(const string &name, const uuid &id,
1526  const xml_node &node,
1527  AgentUtXmlTestCase *test_case) :
1528  AgentUtXmlNode(name, node, false, test_case) {
1529 }
1530 
1532 }
1533 
1534 
1536  if (GetStringAttribute(node(), "mac", &mac_) == false) {
1537  cout << "Attribute \"mac\" not specified. Skipping" << endl;
1538  return false;
1539  }
1540 
1541  if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1542  cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1543  return false;
1544  }
1545 
1546  GetStringAttribute(node(), "ip", &ip_);
1547  GetStringAttribute(node(), "vn", &vn_);
1548  GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1549  GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1550  GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1551  GetUintAttribute(node(), "sg", &sg_id_);
1552  GetUintAttribute(node(), "tag", &tag_id_);
1553  GetUintAttribute(node(), "label", &label_);
1554  if (ip_.empty()) {
1555  ip_ = "0.0.0.0";
1556  }
1557  return true;
1558 }
1559 
1560 bool AgentUtXmlL2Route::ToXml(xml_node *parent) {
1561  assert(0);
1562  return true;
1563 }
1564 
1565 void AgentUtXmlL2Route::ToString(string *str) {
1566  *str = "L2-Route";
1567  return;
1568 }
1569 
1571  return "FDB";
1572 }
1573 
1575  Agent *agent = Agent::GetInstance();
1576  EvpnAgentRouteTable *rt_table =
1577  static_cast<EvpnAgentRouteTable *>
1579 
1580  SecurityGroupList sg_list;
1581  TagList tag_list;
1582  if (sg_id_)
1583  sg_list.push_back(sg_id_);
1584  if (tag_id_)
1585  tag_list.push_back(tag_id_);
1586 
1587  TunnelType::TypeBmap bmap = 0;
1588  TunnelEncapType::Encap encap =
1590  if (encap == TunnelEncapType::MPLS_O_GRE)
1591  bmap |= (1 << TunnelType::MPLS_GRE);
1592  if (encap == TunnelEncapType::MPLS_O_UDP)
1593  bmap |= (1 << TunnelType::MPLS_UDP);
1594  if (encap == TunnelEncapType::VXLAN)
1595  bmap |= (1 << TunnelType::VXLAN);
1596  if (op_delete()) {
1597  rt_table->DeleteReq(bgp_peer_, vrf_,
1599  Ip4Address::from_string(ip_), 32, vxlan_id_,
1600  (new ControllerVmRoute(bgp_peer_)));
1601  } else {
1602  VnListType vn_list;
1603  vn_list.insert(vn_);
1604  ControllerVmRoute *data =
1606  agent->fabric_vrf_name(),
1607  agent->router_id(), vrf_,
1608  Ip4Address::from_string(tunnel_dest_),
1609  bmap, label_, MacAddress(),
1610  vn_list, sg_list, tag_list,
1611  PathPreference(), false,
1612  EcmpLoadBalance(), false);
1613  rt_table->AddRemoteVmRouteReq(bgp_peer_, vrf_,
1615  Ip4Address::from_string(ip_),
1616  32, vxlan_id_, data);
1617  }
1618  return true;
1619 }
1620 
1622 // AgentUtXmlL2RouteValidate routines
1625  const xml_node &node) :
1626  AgentUtXmlValidationNode(name, node) {
1627 }
1628 
1630 }
1631 
1633  if (GetStringAttribute(node(), "mac", &mac_) == false) {
1634  cout << "Attribute \"mac\" not specified. Skipping" << endl;
1635  return false;
1636  }
1637 
1638  if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1639  cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1640  return false;
1641  }
1642 
1643  if (GetStringAttribute(node(), "vn", &vn_) == false) {
1644  cout << "Attribute \"vn\" not specified. Skipping" << endl;
1645  return false;
1646  }
1647 
1648  string addr = "";
1649  GetStringAttribute(node(), "ip", &addr);
1650  boost::system::error_code ec;
1651  ip_ = IpAddress::from_string(addr, ec);
1652 
1653  GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1654  GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1655  GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1656  GetUintAttribute(node(), "intf", &intf_uuid_);
1657 
1658  return true;
1659 }
1660 
1662  Agent *agent = Agent::GetInstance();
1663  BridgeAgentRouteTable *bridge_table =
1664  static_cast<BridgeAgentRouteTable *>
1665  (agent->vrf_table()->GetBridgeRouteTable(vrf_));
1666  BridgeRouteEntry *rt =
1667  bridge_table->FindRoute(MacAddress::FromString(mac_));
1668  if (present() == false)
1669  return (rt == NULL);
1670 
1671  if (rt == NULL)
1672  return false;
1673 
1674  if (vn_ != "" && vn_ != rt->dest_vn_name())
1675  return false;
1676 
1677  return true;
1678 }
1679 
1681  return ("FDB <" + name() + ">");
1682 }
1683 
1684 AgentUtXmlL3Route::AgentUtXmlL3Route(const string &name, const uuid &id,
1685  const xml_node &node,
1686  AgentUtXmlTestCase *test_case) :
1687  AgentUtXmlNode(name, node, false, test_case) {
1688 }
1689 
1691 }
1692 
1693 
1695  if (GetStringAttribute(node(), "src-ip", &src_ip_) == false) {
1696  cout << "Attribute \"ip\" not specified. Skipping" << endl;
1697  return false;
1698  }
1699 
1700  if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1701  cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1702  return false;
1703  }
1704 
1705  GetStringAttribute(node(), "ip", &ip_);
1706  GetStringAttribute(node(), "vn", &vn_);
1707  GetUintAttribute(node(), "plen", &plen_);
1708  GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1709  GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1710  GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1711  GetUintAttribute(node(), "sg", &sg_id_);
1712  GetUintAttribute(node(), "tag", &tag_id_);
1713  GetUintAttribute(node(), "label", &label_);
1714  if (ip_.empty()) {
1715  ip_ = "0.0.0.0";
1716  }
1717  return true;
1718 }
1719 
1720 bool AgentUtXmlL3Route::ToXml(xml_node *parent) {
1721  assert(0);
1722  return true;
1723 }
1724 
1725 void AgentUtXmlL3Route::ToString(string *str) {
1726  *str = "L3-Route";
1727  return;
1728 }
1729 
1731  return "L3-Route";
1732 }
1733 
1735  Agent *agent = Agent::GetInstance();
1736  InetUnicastAgentRouteTable *rt_table =
1737  static_cast<InetUnicastAgentRouteTable *>
1739 
1740  SecurityGroupList sg_list;
1741  TagList tag_list;
1742  if (sg_id_)
1743  sg_list.push_back(sg_id_);
1744  if (tag_id_)
1745  tag_list.push_back(tag_id_);
1746 
1747  TunnelType::TypeBmap bmap = 0;
1748  TunnelEncapType::Encap encap =
1750  if (encap == TunnelEncapType::MPLS_O_GRE)
1751  bmap |= (1 << TunnelType::MPLS_GRE);
1752  if (encap == TunnelEncapType::MPLS_O_UDP)
1753  bmap |= (1 << TunnelType::MPLS_UDP);
1754  if (encap == TunnelEncapType::VXLAN)
1755  bmap |= (1 << TunnelType::VXLAN);
1756  if (op_delete()) {
1757  rt_table->DeleteReq(bgp_peer_, vrf_,
1758  Ip4Address::from_string(src_ip_), plen_,
1759  (new ControllerVmRoute(bgp_peer_)));
1760  } else {
1761  VnListType vn_list;
1762  vn_list.insert(vn_);
1763  ControllerVmRoute *data =
1765  agent->fabric_vrf_name(),
1766  agent->router_id(), vrf_,
1767  Ip4Address::from_string(tunnel_dest_),
1768  bmap, label_, MacAddress(),
1769  vn_list, sg_list, tag_list,
1770  PathPreference(), false,
1771  EcmpLoadBalance(),
1772  false);
1773  rt_table->AddRemoteVmRouteReq(bgp_peer_, vrf_,
1774  Ip4Address::from_string(src_ip_), plen_,
1775  data);
1776  }
1777  return true;
1778 }
1779 
1781  const xml_node &node) :
1782  AgentUtXmlValidationNode(name, node) {
1783 }
1784 
1786 }
1787 
1789  if (GetStringAttribute(node(), "src-ip", &src_ip_) == false) {
1790  cout << "Attribute \"mac\" not specified. Skipping" << endl;
1791  return false;
1792  }
1793 
1794  if (GetStringAttribute(node(), "vrf", &vrf_) == false) {
1795  cout << "Attribute \"vrf_\" not specified. Skipping" << endl;
1796  return false;
1797  }
1798 
1799  if (GetStringAttribute(node(), "vn", &vn_) == false) {
1800  cout << "Attribute \"vn\" not specified. Skipping" << endl;
1801  return false;
1802  }
1803 
1804  string addr = "";
1805  GetStringAttribute(node(), "ip", &addr);
1806  boost::system::error_code ec;
1807  ip_ = IpAddress::from_string(addr, ec);
1808 
1809  GetUintAttribute(node(), "vxlan_id", &vxlan_id_);
1810  GetStringAttribute(node(), "tunnel-dest", &tunnel_dest_);
1811  GetStringAttribute(node(), "tunnel-type", &tunnel_type_);
1812  GetUintAttribute(node(), "intf", &intf_uuid_);
1813 
1814  return true;
1815 }
1816 
1818  Agent *agent = Agent::GetInstance();
1819  InetUnicastAgentRouteTable *inet_table =
1820  static_cast<InetUnicastAgentRouteTable *>
1822  InetUnicastRouteEntry *rt =
1823  inet_table->FindRoute(Ip4Address::from_string(src_ip_));
1824  if (present() == false)
1825  return (rt == NULL);
1826 
1827  if (rt == NULL)
1828  return false;
1829 
1830  if (vn_ != "" && vn_ != rt->dest_vn_name())
1831  return false;
1832 
1833  return true;
1834 }
1835 
1837  return ("IP route <" + name() + ">");
1838 }
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
std::vector< uint64_t > TagList
Definition: agent.h:202
std::vector< int > SecurityGroupList
Definition: agent.h:201
std::set< std::string > VnListType
Definition: agent.h:212
const NextHop * GetActiveNextHop() const
Definition: agent_route.cc:882
const std::string & dest_vn_name() const
virtual bool ReadXml()
virtual ~AgentUtXmlAclValidate()
virtual const std::string ToString()
AgentUtXmlAclValidate(const std::string &name, const pugi::xml_node &node)
virtual bool Validate()
virtual std::string NodeType()
AgentUtXmlAcl(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
AceList ace_list_
virtual bool ToXml(pugi::xml_node *parent)
virtual bool ReadXml()
virtual void ToString(std::string *str)
virtual bool ReadXml()
Definition: test_xml.cc:609
virtual void ToString(std::string *str)
Definition: test_xml.cc:613
void AddIdPerms(pugi::xml_node *parent)
Definition: test_xml.cc:650
virtual const std::string ToString()
AgentUtXmlEthInterfaceValidate(const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)
virtual void ToString(std::string *str)
virtual std::string NodeType()
virtual bool ToXml(pugi::xml_node *parent)
virtual bool ReadXml()
AgentUtXmlEthInterface(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual uint32_t wait_count() const
FlowEntry * FindFlowAnyNh(uint16_t *found_nh)
AgentUtXmlFlowValidate(const std::string &name, const pugi::xml_node &node)
virtual const std::string ToString()
virtual const std::string ToString()
AgentUtXmlGlobalVrouterValidate(const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)
int flow_export_rate() const
Definition: test_xml_oper.h:27
AgentUtXmlGlobalVrouter(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ToXml(pugi::xml_node *parent)
virtual void ToString(std::string *str)
virtual std::string NodeType()
std::string & vxlan_mode()
Definition: test_xml_oper.h:26
AgentUtXmlInstanceIp(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ReadXml()
virtual void ToString(std::string *str)
virtual std::string NodeType()
virtual bool ToXml(pugi::xml_node *parent)
virtual const std::string ToString()
AgentUtXmlL2RouteValidate(const std::string &name, const pugi::xml_node &node)
std::string tunnel_type_
virtual void ToString(std::string *str)
virtual std::string NodeType()
virtual bool Run()
std::string tunnel_dest_
virtual bool ToXml(pugi::xml_node *parent)
std::string mac_
std::string vrf_
virtual bool ReadXml()
AgentUtXmlL2Route(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual const std::string ToString()
AgentUtXmlL3RouteValidate(const std::string &name, const pugi::xml_node &node)
virtual std::string NodeType()
std::string tunnel_type_
std::string tunnel_dest_
virtual bool Run()
AgentUtXmlL3Route(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ReadXml()
virtual bool ToXml(pugi::xml_node *parent)
std::string src_ip_
virtual void ToString(std::string *str)
std::string vrf_
const pugi::xml_node & node() const
Definition: test_xml.h:131
bool op_delete() const
Definition: test_xml.h:128
virtual bool ReadXml()=0
Definition: test_xml.cc:466
const std::string & name() const
Definition: test_xml.h:130
virtual bool Run()
boost::uuids::uuid vn_uuid_
AgentUtXmlNova(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ReadXml()
std::string mac_
virtual std::string NodeType()
virtual bool ToXml(pugi::xml_node *parent)
virtual void ToString(std::string *str)
std::string ip_
std::string vm_name_
boost::uuids::uuid vm_uuid_
virtual void ToString(std::string *str)
std::string ingress_
virtual bool ReadXml()
virtual std::string NodeType()
std::string sg_id_
virtual bool ToXml(pugi::xml_node *parent)
std::string egress_
AgentUtXmlSg(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ReadXml()
std::string tag_id_
AgentUtXmlTag(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual std::string NodeType()
virtual bool ToXml(pugi::xml_node *parent)
virtual void ToString(std::string *str)
void AddValidateEntry(const std::string &name, AgentUtXmlTestValidateCreateFn fn)
Definition: test_xml.cc:154
void AddConfigEntry(const std::string &name, AgentUtXmlTestConfigCreateFn fn)
Definition: test_xml.cc:149
const pugi::xml_node & node() const
virtual uint32_t wait_count() const
const std::string & name() const
boost::uuids::uuid vn_uuid_
AgentUtXmlVmInterfaceValidate(const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)
virtual const std::string ToString()
std::string parent_vmi_
Definition: test_xml_oper.h:95
boost::uuids::uuid vm_uuid_
Definition: test_xml_oper.h:88
std::vector< uint16_t > fat_flow_port_
Definition: test_xml_oper.h:94
virtual bool ReadXml()
AgentUtXmlVmInterface(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
boost::uuids::uuid vn_uuid_
Definition: test_xml_oper.h:86
virtual bool ToXml(pugi::xml_node *parent)
virtual std::string NodeType()
virtual void ToString(std::string *str)
virtual const std::string ToString()
AgentUtXmlVmValidate(const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)
virtual bool Validate()
virtual bool ReadXml()
virtual ~AgentUtXmlVmValidate()
virtual std::string NodeType()
virtual bool ReadXml()
virtual void ToString(std::string *str)
AgentUtXmlVm(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ToXml(pugi::xml_node *parent)
virtual bool ReadXml()
virtual bool ToXml(pugi::xml_node *parent)
virtual std::string NodeType()
AgentUtXmlVmiVrf(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual void ToString(std::string *str)
virtual bool ReadXml()
virtual const std::string ToString()
virtual ~AgentUtXmlVnValidate()
virtual bool Validate()
AgentUtXmlVnValidate(const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)
AgentUtXmlVn(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
std::string & network_id()
Definition: test_xml_oper.h:46
std::string & flood_unknown_unicast()
Definition: test_xml_oper.h:47
std::string flood_unknown_unicast_
Definition: test_xml_oper.h:54
virtual void ToString(std::string *str)
std::string vxlan_id_
Definition: test_xml_oper.h:52
std::string network_id_
Definition: test_xml_oper.h:53
std::string & vxlan_id()
Definition: test_xml_oper.h:45
virtual std::string NodeType()
virtual bool ReadXml()
virtual bool ToXml(pugi::xml_node *parent)
virtual bool ReadXml()
AgentUtXmlVrfValidate(const std::string &name, const pugi::xml_node &node)
virtual bool Validate()
virtual ~AgentUtXmlVrfValidate()
virtual const std::string ToString()
virtual bool ToXml(pugi::xml_node *parent)
virtual std::string NodeType()
AgentUtXmlVrf(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ReadXml()
std::string vn_name_
virtual void ToString(std::string *str)
AgentUtXmlVxlanValidate(const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)
virtual const std::string ToString()
std::string flood_unknown_unicast_
Definition: agent.h:360
OperDB * oper_db() const
Definition: agent.cc:1016
VrfTable * vrf_table() const
Definition: agent.h:487
NextHopTable * nexthop_table() const
Definition: agent.h:477
static Agent * GetInstance()
Definition: agent.h:438
const std::string & fabric_vrf_name() const
Definition: agent.h:905
Ip4Address router_id() const
Definition: agent.h:668
BridgeRouteEntry * FindRoute(const MacAddress &mac)
Definition: bridge_route.cc:72
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)
bool IsDeleted() const
Definition: db_entry.h:48
virtual DBEntry * GetNext(const DBEntryBase *entry)
virtual DBEntry * GetFirst()
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
Definition: db_table.cc:462
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)
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)
bool IsShortFlow() const
Definition: flow_entry.h:682
FlowData & data()
Definition: flow_entry.h:595
int32_t flow_export_rate() const
InetUnicastRouteEntry * FindRoute(const IpAddress &ip)
static void AddRemoteVmRouteReq(const Peer *peer, const string &vm_vrf, const IpAddress &vm_addr, uint8_t plen, AgentRouteData *data)
static void DeleteReq(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen, AgentRouteData *data)
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: mac_address.cc:71
static const uint32_t kRpfDiscardIndex
Definition: nexthop.h:1947
uint32_t id() const
Definition: nexthop.h:408
@ VRF
Definition: nexthop.h:350
virtual std::string ToString() const
Definition: nexthop.h:368
Type GetType() const
Definition: nexthop.h:405
GlobalVrouter * global_vrouter() const
Definition: operdb_init.h:54
static const uint32_t DROP_FLAGS
static TunnelEncapType::Encap TunnelEncapFromString(const std::string &encap)
@ MPLS_UDP
Definition: nexthop.h:242
@ MPLS_GRE
Definition: nexthop.h:241
uint32_t TypeBmap
Definition: nexthop.h:248
VmInterface::VmiType vmi_type() const
VmInterface::DeviceType device_type() const
uint16_t rx_vlan_id() const
const VnEntry * vn() const
Definition: vn.h:151
const boost::uuids::uuid & GetUuid() const
Definition: vn.h:161
int GetVxLanId() const
Definition: vn.cc:728
const string & GetName() const
Definition: vn.h:162
const VxLanId * vxlan_id_ref() const
Definition: vn.h:192
Definition: vrf.h:89
const string & GetName() const
Definition: vrf.h:103
VnEntry * vn() const
Definition: vrf.h:104
bool flood_unknown_unicast() const
Definition: nexthop.h:1449
const VrfEntry * GetVrf() const
Definition: nexthop.h:1444
AgentRouteTable * GetEvpnRouteTable(const std::string &vrf_name)
Definition: vrf.cc:913
AgentRouteTable * GetBridgeRouteTable(const std::string &vrf_name)
Definition: vrf.cc:917
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:898
Definition: vxlan.h:14
const NextHop * nexthop() const
Definition: vxlan.h:28
uint32_t vxlan_id() const
Definition: vxlan.h:27
uint8_t type
Definition: load_balance.h:2
bool GetIntAttribute(const xml_node &node, const string &name, int *value)
Definition: test_xml.cc:49
bool GetUintAttribute(const xml_node &node, const string &name, uint16_t *value)
Definition: test_xml.cc:37
xml_node AddXmlNodeWithValue(xml_node *parent, const char *name, const string &value)
Definition: test_xml.cc:118
xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name, int val)
Definition: test_xml.cc:125
void LinkXmlNode(xml_node *parent, const string &ltype, const string lname, const string &rtype, const string rname)
Definition: test_xml.cc:90
xml_node AddXmlNodeWithAttr(xml_node *parent, const char *attr)
Definition: test_xml.cc:112
bool GetStringAttribute(const xml_node &node, const string &name, string *value)
Definition: test_xml.cc:25
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
std::string src_ip_
std::string dst_vn_
std::string action_
std::string src_vn_
std::string direction_
std::string dst_ip_
uint32_t action
Definition: acl.h:43
MatchPolicy match_p
Definition: flow_entry.h:309
VnListType dest_vn_list
Definition: flow_entry.h:299
VnListType source_vn_list
Definition: flow_entry.h:298
NextHopConstRef rpf_nh
Definition: flow_entry.h:348
FlowAction action_info
Definition: flow_entry.h:277
static string DeviceTypeToString(VmInterface::DeviceType type)
AgentUtXmlNode * CreateNode(const string &type, const string &name, const uuid &id, const xml_node &node, AgentUtXmlTestCase *test_case)
static string VmiTypeToString(VmInterface::VmiType type)
static bool MatchFlowAction(FlowEntry *flow, const string &str)
void AgentUtXmlOperInit(AgentUtXmlTest *test)
AgentUtXmlValidationNode * CreateValidateNode(const string &type, const string &name, const uuid &id, const xml_node &node)
boost::uuids::uuid uuid