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