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

Generated by: LCOV version 1.14