LCOV - code coverage report
Current view: top level - vnsw/agent/test-xml - test_xml_oper.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 693 1151 60.2 %
Date: 2026-11-09 02:10:49 Functions: 104 177 58.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14