LCOV - code coverage report
Current view: top level - vnsw/agent/test-xml - test_xml.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 319 402 79.4 %
Date: 2026-11-23 02:04:52 Functions: 44 58 75.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : #include "base/os.h"
       6             : #include <iostream>
       7             : #include <fstream>
       8             : #include <pugixml/pugixml.hpp>
       9             : #include <boost/filesystem.hpp>
      10             : #include <boost/uuid/uuid.hpp>
      11             : 
      12             : #include <test/test_cmn_util.h>
      13             : #include <pkt/test/test_pkt_util.h>
      14             : #include <pkt/flow_mgmt.h>
      15             : #include <oper/global_vrouter.h>
      16             : #include "test_xml.h"
      17             : #include "test_xml_validate.h"
      18             : #include "test_xml_packet.h"
      19             : 
      20             : using namespace std;
      21             : using namespace pugi;
      22             : using namespace boost::uuids;
      23             : using namespace AgentUtXmlUtils;
      24             : 
      25             : namespace AgentUtXmlUtils {
      26        5756 : bool GetStringAttribute(const xml_node &node, const string &name,
      27             :                         string *value) {
      28        5756 :     xml_attribute attr = node.attribute(name.c_str());
      29        5756 :     if (!attr) {
      30        3242 :         return false;;
      31             :     }
      32             : 
      33        2514 :     *value = attr.as_string();
      34             : 
      35        2514 :     return true;
      36             : }
      37             : 
      38        1532 : bool GetUintAttribute(const xml_node &node, const string &name,
      39             :                       uint16_t *value) {
      40        1532 :     xml_attribute attr = node.attribute(name.c_str());
      41        1532 :     if (!attr) {
      42         772 :         return false;;
      43             :     }
      44             : 
      45         760 :     *value = attr.as_uint();
      46             : 
      47         760 :     return true;
      48             : }
      49             : 
      50          15 : bool GetIntAttribute(const xml_node &node, const string &name, int *value) {
      51          15 :     xml_attribute attr = node.attribute(name.c_str());
      52          15 :     if (!attr) {
      53          10 :         return false;;
      54             :     }
      55             : 
      56           5 :     *value = attr.as_int();
      57             : 
      58           5 :     return true;
      59             : }
      60             : 
      61           0 : bool GetBoolAttribute(const xml_node &node, const string &name,
      62             :                       bool *value) {
      63           0 :     xml_attribute attr = node.attribute(name.c_str());
      64           0 :     if (!attr) {
      65           0 :         return false;;
      66             :     }
      67             : 
      68           0 :     string str = attr.as_string();
      69           0 :     if (str == "true" || str == "yes")
      70           0 :         *value = true;
      71             :     else
      72           0 :         *value = false;
      73           0 :     return true;
      74           0 : }
      75             : 
      76          46 : void NovaIntfAdd(bool op_delete, const uuid &id, const Ip4Address &ip,
      77             :                  const uuid &vm_uuid, const uuid vn_uuid, const string &name,
      78             :                  const string &mac, const string vm_name) {
      79          46 :     if (op_delete) {
      80          24 :         PortUnSubscribe(id);
      81          24 :         cout << "Nova Del Interface Message " << endl;
      82          24 :         return;
      83             :     }
      84             : 
      85          22 :     PortSubscribe(name, id, vm_uuid, vm_name, vn_uuid, MakeUuid(1), ip,
      86          22 :                   Ip6Address::v4_compatible(ip), mac);
      87          22 :     cout << "Nova Add Interface Message " << endl;
      88          22 :     return;
      89             : }
      90             : 
      91         441 : void LinkXmlNode(xml_node *parent, const string &ltype, const string lname,
      92             :                  const string &rtype, const string rname) {
      93         441 :     xml_node n = parent->append_child("link");
      94             : 
      95         441 :     xml_node n1 = n.append_child("node");
      96         441 :     n1.append_attribute("type") = ltype.c_str();
      97             : 
      98         441 :     xml_node n2 = n1.append_child("name");
      99         441 :     n2.append_child(pugi::node_pcdata).set_value(lname.c_str());
     100             : 
     101         441 :     n1 = n.append_child("node");
     102         441 :     n1.append_attribute("type") = rtype.c_str();
     103             : 
     104         441 :     n2 = n1.append_child("name");
     105         441 :     n2.append_child(pugi::node_pcdata).set_value(rname.c_str());
     106             : 
     107         441 :     string mdata = GetMetadata(ltype.c_str(), rtype.c_str());
     108         441 :     xml_node n3 = n.append_child("metadata");
     109         441 :     n3.append_attribute("type") = mdata.c_str();
     110         882 :     return;
     111         441 : }
     112             : 
     113         375 : xml_node AddXmlNodeWithAttr(xml_node *parent, const char *attr) {
     114         375 :     xml_node n = parent->append_child("node");
     115         375 :     n.append_attribute("type") = attr;
     116         375 :     return n;
     117             : }
     118             : 
     119        2397 : xml_node AddXmlNodeWithValue(xml_node *parent, const char *name,
     120             :                              const string &value) {
     121        2397 :     xml_node n = parent->append_child(name);
     122        2397 :     n.append_child(pugi::node_pcdata).set_value(value.c_str());
     123        2397 :     return n;
     124             : }
     125             : 
     126          35 : xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name,
     127             :                                 int val) {
     128          35 :     stringstream s;
     129          35 :     s << val;
     130          35 :     xml_node n = parent->append_child(name);
     131          35 :     n.append_child(pugi::node_pcdata).set_value(s.str().c_str());
     132          35 :     return n;
     133          35 : }
     134             : }
     135             : 
     136             : /////////////////////////////////////////////////////////////////////////////
     137             : //  AgentUtXmlTest routines
     138             : /////////////////////////////////////////////////////////////////////////////
     139          21 : AgentUtXmlTest::AgentUtXmlTest(const std::string &name) : file_name_(name) {
     140          21 : }
     141             : 
     142          21 : AgentUtXmlTest::~AgentUtXmlTest() {
     143             : 
     144          21 :     for (AgentUtXmlTestList::iterator i = test_list_.begin();
     145          55 :          i != test_list_.end(); i++) {
     146          34 :         delete *i;
     147             :     }
     148          21 : }
     149             : 
     150         532 : void AgentUtXmlTest::AddConfigEntry(const std::string &name,
     151             :                                     AgentUtXmlTestConfigCreateFn fn) {
     152         532 :     config_factory_[name] = fn;
     153         532 : }
     154             : 
     155         490 : void AgentUtXmlTest::AddValidateEntry(const std::string &name,
     156             :                                       AgentUtXmlTestValidateCreateFn fn) {
     157         490 :     validate_factory_[name] = fn;
     158         490 : }
     159             : 
     160             : AgentUtXmlTest::AgentUtXmlTestConfigCreateFn
     161         675 : AgentUtXmlTest::GetConfigCreateFn(const std::string &name) {
     162         675 :     AgentUtXmlTestConfigFactory::iterator iter = config_factory_.find(name);
     163         675 :     if (iter == config_factory_.end()) {
     164         280 :         return AgentUtXmlTest::AgentUtXmlTestConfigCreateFn();
     165             :     }
     166             : 
     167         395 :     return iter->second;
     168             : }
     169             : 
     170             : AgentUtXmlTest::AgentUtXmlTestValidateCreateFn
     171         265 : AgentUtXmlTest::GetValidateCreateFn(const std::string &name) {
     172         265 :     AgentUtXmlTestValidateFactory::iterator iter = validate_factory_.find(name);
     173         265 :     if (iter == validate_factory_.end()) {
     174           0 :         assert(0);
     175             :     }
     176         530 :     return iter->second;
     177             : }
     178             : 
     179          21 : bool AgentUtXmlTest::ReadXml() {
     180          21 :     xml_node list = doc_.child("test_suite");
     181          21 :     GetStringAttribute(list, "name", &name_);
     182             : 
     183          55 :     for (xml_node node = list.first_child(); node; node = node.next_sibling()) {
     184          34 :         if (strcmp(node.name(), "test") == 0) {
     185          34 :             xml_attribute attr = node.attribute("name");
     186          34 :             if (!attr) {
     187           0 :                 cout << "Missing attribute \"name\". Skipping" << endl;
     188           0 :                 continue;
     189             :             }
     190             :             AgentUtXmlTestCase *test = new AgentUtXmlTestCase(attr.value(),
     191          34 :                                                               node, this);
     192          34 :             attr = node.attribute("verbose");
     193          34 :             bool verbose = false;
     194          34 :             if (!attr) {
     195          18 :                 verbose = false;
     196             :             } else {
     197          16 :                 if (atoi(attr.value()))
     198           0 :                     verbose = true;
     199             :             }
     200          34 :             test->set_verbose(verbose);
     201          34 :             test_list_.push_back(test);
     202          34 :             test->ReadXml();
     203             :         }
     204             :     }
     205             : 
     206          21 :     return true;
     207             : }
     208             : 
     209          21 : bool AgentUtXmlTest::Load() {
     210          21 :     boost::system::error_code ec;
     211          21 :     boost::filesystem::path file_path(file_name_);
     212          21 :     uintmax_t file_size = boost::filesystem::file_size(file_path, ec);
     213          21 :     if (ec) {
     214           0 :         cout << "Error <" << ec << "> opening file" << file_name_ << endl;
     215           0 :         return false;
     216             :     }
     217             : 
     218          21 :     std::fstream file(file_name_.c_str(), std::ios::binary | std::ios_base::in);
     219          21 :     if (!file) {
     220           0 :         cout << "Error <fstream error> opening file" << file_name_ << endl;
     221           0 :         return false;
     222             :     }
     223             : 
     224          21 :     std::vector<char> data(file_size + 1, 0);
     225          21 :     file.read(data.data(), file_size);
     226          21 :     if (!file || file.gcount() < static_cast<std::streamsize>(file_size)) {
     227           0 :         cout << "Error <fstream::read> reading file" << file_name_ << endl;
     228           0 :         return false;
     229             :     }
     230             : 
     231          21 :     xml_parse_result result = doc_.load_string(data.data());
     232          21 :     if (result) {
     233          21 :         cout << "Loaded data file successfully" << endl;
     234             :     } else {
     235           0 :         cout << "Error in XML string at offset <: " << result.offset
     236           0 :             << "> (error at [..." << (data.data() + result.offset) << "])" << endl;
     237           0 :         return false;
     238             :     }
     239             : 
     240          21 :     return true;
     241          21 : }
     242             : 
     243          21 : void AgentUtXmlTest::ToString(string *str) {
     244          21 :     stringstream s;
     245             : 
     246          21 :     s << "Test Suite : " << name_ << endl;
     247          21 :     *str += s.str();
     248          21 :     for (AgentUtXmlTestList::iterator it = test_list_.begin();
     249          55 :          it != test_list_.end(); it++) {
     250          34 :         (*it)->ToString(str);
     251             :     }
     252          42 :     return;
     253          21 : }
     254             : 
     255          21 : bool AgentUtXmlTest::Run() {
     256          21 :     for (AgentUtXmlTestList::iterator it = test_list_.begin();
     257          55 :          it != test_list_.end(); it++) {
     258          34 :         (*it)->Run();
     259             :     }
     260             : 
     261          21 :     return true;
     262             : }
     263             : 
     264           0 : bool AgentUtXmlTest::Run(std::string test_case) {
     265           0 :     for (AgentUtXmlTestList::iterator it = test_list_.begin();
     266           0 :          it != test_list_.end(); it++) {
     267           0 :         if ((*it)->name().compare(test_case) == 0) {
     268           0 :             (*it)->Run();
     269           0 :             return true;
     270             :         }
     271             :     }
     272             : 
     273           0 :     return false;
     274             : }
     275             : 
     276             : /////////////////////////////////////////////////////////////////////////////
     277             : //  AgentUtXmlTestCase routines
     278             : /////////////////////////////////////////////////////////////////////////////
     279         675 : static bool CheckConfigNode(const string &node_name, const xml_node &node,
     280             :                             uuid *id, string *name) {
     281         675 :     if (strcmp(node.name(), node_name.c_str()) != 0) {
     282           0 :         return false;
     283             :     }
     284             : 
     285         675 :     xml_attribute attr = node.attribute("name");
     286         675 :     if (!attr) {
     287             :         cout << "Attribute \"name\" not found for " << node_name
     288          63 :             << ". Skipping..." << endl;
     289          63 :         return false;
     290             :     }
     291             : 
     292         612 :     *name = attr.as_string();
     293         612 :     if (*name == "") {
     294           0 :         cout << "Invalid \"name\" for " << node_name << " Skipping" << endl;
     295           0 :         return false;
     296             :     }
     297             : 
     298         612 :     if (node_name == "validate")
     299         148 :         return false;
     300             : 
     301         464 :     attr = node.attribute("uuid");
     302         464 :     if (!attr) {
     303             :         cout << "Attribute \"uuid\" not found for " << node_name
     304           0 :             << ". Skipping..." << endl;
     305           0 :         return false;;
     306             :     }
     307             : 
     308         464 :     int x = attr.as_uint();
     309         464 :     if (x == 0) {
     310           1 :         cout << "Invalid \"uuid\" (0) for " << node_name << " Skipping" << endl;
     311           1 :         return false;
     312             :     }
     313             : 
     314         463 :     *id = MakeUuid(x);
     315             : 
     316         463 :     return true;
     317             : }
     318             : 
     319          34 : AgentUtXmlTestCase::AgentUtXmlTestCase(const std::string &name,
     320             :                                        const xml_node &node,
     321          34 :                                        AgentUtXmlTest *test)
     322          34 :     : name_(name), xml_node_(node), test_(test), verbose_(false) {
     323          34 :     cout << "Creating test-case <" << name_ << ">" << endl;
     324          34 : }
     325             : 
     326          68 : AgentUtXmlTestCase::~AgentUtXmlTestCase() {
     327          34 :     for (AgentUtXmlNodeList::iterator i =  node_list_.begin();
     328         708 :          i != node_list_.end(); i++) {
     329         674 :         delete *i;
     330             :     }
     331          68 : }
     332             : 
     333          34 : bool AgentUtXmlTestCase::ReadXml() {
     334         709 :     for (xml_node node = xml_node_.first_child(); node;
     335         675 :          node = node.next_sibling()) {
     336             : 
     337         675 :         string str;
     338         675 :         bool op_delete = false;
     339        1916 :         if (GetStringAttribute(node, "delete", &str) == true ||
     340        1241 :             GetStringAttribute(node, "del", &str) == true) {
     341         243 :             if (str != "false" && str != "0")
     342         243 :                 op_delete = true;
     343             :         }
     344             : 
     345             :         uuid id;
     346         675 :         string name;
     347         675 :         AgentUtXmlNode *cfg = NULL;
     348             : 
     349             :         AgentUtXmlTest::AgentUtXmlTestConfigCreateFn fn =
     350        1350 :             test_->GetConfigCreateFn(node.name());
     351         675 :         if (CheckConfigNode(node.name(), node, &id, &name) == true) {
     352         463 :             if (fn.empty() == false)
     353         394 :                 cfg = fn(node.name(), name, id, node, this);
     354             :         }
     355             : 
     356         675 :         if (strcmp(node.name(), "link") == 0) {
     357         108 :             cfg = new AgentUtXmlLink(node, this);
     358             :         }
     359             : 
     360         675 :         if (strcmp(node.name(), "packet") == 0) {
     361          24 :             if (GetStringAttribute(node, "name", &name) == false) {
     362           0 :                 cout << "Attribute \"name\" not specified for Packet. Skipping"
     363           0 :                     << endl;
     364           0 :                 continue;
     365             :             }
     366          24 :             cfg = new AgentUtXmlPacket(name, node, this);
     367             :         }
     368             : 
     369         675 :         if (strcmp(node.name(), "task") == 0) {
     370           0 :             cfg = new AgentUtXmlTask(node, this);
     371             :         }
     372             : 
     373         675 :         if (strcmp(node.name(), "validate") == 0) {
     374         148 :             if (GetStringAttribute(node, "name", &name) == false) {
     375             :                 cout << "Attribute \"name\" not specified for validate."
     376           0 :                    " Skipping" << endl;
     377           0 :                 continue;
     378             :             }
     379         148 :             cfg = new AgentUtXmlValidate(name, node, this);
     380             :         }
     381             : 
     382         675 :         if (cfg) {
     383         674 :             cfg->set_op_delete(op_delete);
     384             :         } else {
     385           1 :             cout << "Unknown node name <" << node.name() << ">. Ignoring"
     386           1 :                 << endl;
     387             :         }
     388         675 :         if (cfg) {
     389         674 :             bool ret = cfg->ReadXml();
     390         674 :             if (op_delete == false && ret == false) {
     391           0 :                 delete cfg;
     392           0 :                 cfg = NULL;
     393             :             }
     394             :         }
     395             : 
     396         675 :         if (cfg) {
     397         674 :             node_list_.push_back(cfg);
     398             :         }
     399         675 :     }
     400             : 
     401          34 :     return true;
     402             : }
     403             : 
     404          34 : bool AgentUtXmlTestCase::Run() {
     405          34 :     for (AgentUtXmlNodeList::iterator it = node_list_.begin();
     406         708 :          it != node_list_.end(); it++) {
     407         674 :         if ((*it)->gen_xml() == false) {
     408         191 :             (*it)->Run();
     409         191 :             TestClient::WaitForIdle();
     410         191 :             continue;
     411             :         }
     412             : 
     413         483 :         xml_document doc;
     414             : 
     415         483 :         xml_node decl = doc.prepend_child(pugi::node_declaration);
     416         483 :         decl.append_attribute("version") = "1.0";
     417             : 
     418         483 :         xml_node n = doc.append_child("config");
     419         483 :         xml_node n1;
     420         483 :         if ((*it)->op_delete()) {
     421         234 :             n1 = n.append_child("delete");
     422             :         } else {
     423         249 :             n1 = n.append_child("update");
     424             :         }
     425         483 :         (*it)->ToXml(&n1);
     426         483 :         if (verbose_) {
     427           0 :             doc.print(std::cout);
     428             :         }
     429         483 :         Agent *agent = Agent::GetInstance();
     430         483 :         agent->ifmap_parser()->ConfigParse(n, 0);
     431         483 :         TestClient::WaitForIdle();
     432         483 :     }
     433             : 
     434          34 :     return true;
     435             : }
     436             : 
     437          34 : void AgentUtXmlTestCase::ToString(string *str) {
     438          34 :     stringstream s;
     439             : 
     440          34 :     s << "Test Case : " << name_ << endl;
     441          34 :     *str += s.str();
     442          34 :     for (AgentUtXmlNodeList::iterator it = node_list_.begin();
     443         708 :          it != node_list_.end(); it++) {
     444         674 :         (*it)->ToString(str);
     445             :     }
     446          68 :     return;
     447          34 : }
     448             : 
     449             : /////////////////////////////////////////////////////////////////////////////
     450             : //  AgentUtXmlNode routines
     451             : /////////////////////////////////////////////////////////////////////////////
     452         483 : AgentUtXmlNode::AgentUtXmlNode(const string &name, const xml_node &node,
     453         483 :                                AgentUtXmlTestCase *test_case) :
     454         483 :     node_(node), name_(name), op_delete_(false), gen_xml_(true),
     455         483 :     test_case_(test_case) {
     456         483 : }
     457             : 
     458         191 : AgentUtXmlNode::AgentUtXmlNode(const string &name, const xml_node &node,
     459         191 :                                bool gen_xml, AgentUtXmlTestCase *test_case) :
     460         191 :     node_(node), name_(name), op_delete_(false), gen_xml_(gen_xml),
     461         191 :     test_case_(test_case) {
     462         191 : }
     463             : 
     464         674 : AgentUtXmlNode::~AgentUtXmlNode() {
     465         674 : }
     466             : 
     467         547 : bool AgentUtXmlNode::ReadXml() {
     468         547 :     string str;
     469         547 :     op_delete_ = false;
     470        1549 :     if (GetStringAttribute(node_, "delete", &str) == true ||
     471        1002 :         GetStringAttribute(node_, "del", &str) == true) {
     472         172 :         if (str != "false" && str != "0")
     473         172 :             op_delete_ = true;
     474             :     }
     475             : 
     476         547 :     return true;
     477         547 : }
     478             : 
     479         631 : void AgentUtXmlNode::ToString(string *str) {
     480         631 :     stringstream s;
     481             : 
     482         631 :     if (op_delete_)
     483         234 :         s << "Delete ";
     484             :     else
     485         397 :         s << "Add ";
     486             : 
     487         631 :     s << NodeType() << " : " << name_ << " ";
     488             : 
     489         631 :     *str += s.str();
     490        1262 :     return;
     491         631 : }
     492             : 
     493             : /////////////////////////////////////////////////////////////////////////////
     494             : //  AgentUtXmlTask routines
     495             : /////////////////////////////////////////////////////////////////////////////
     496           0 : AgentUtXmlTask::AgentUtXmlTask(const xml_node &node,
     497           0 :                                AgentUtXmlTestCase *test_case) :
     498           0 :     AgentUtXmlNode("task", node, false, test_case) {
     499           0 : }
     500             : 
     501           0 : AgentUtXmlTask::~AgentUtXmlTask() {
     502           0 : }
     503             : 
     504           0 : bool AgentUtXmlTask::ReadXml() {
     505           0 :     GetStringAttribute(node(), "stop", &stop_);
     506           0 :     return true;
     507             : }
     508             : 
     509           0 : bool AgentUtXmlTask::ToXml(xml_node *parent) {
     510           0 :     return true;
     511             : }
     512             : 
     513           0 : void AgentUtXmlTask::ToString(string *str) {
     514           0 :     AgentUtXmlNode::ToString(str);
     515           0 :     stringstream s;
     516             : 
     517           0 :     s << "Stop : " << stop_ << endl;
     518           0 :     *str += s.str();
     519           0 :     return;
     520           0 : }
     521             : 
     522           0 : string AgentUtXmlTask::NodeType() {
     523           0 :     return "Task";
     524             : }
     525             : 
     526           0 : bool AgentUtXmlTask::Run() {
     527           0 :     if (boost::iequals(stop_, "1") || boost::iequals(stop_, "yes")) {
     528           0 :         TestClient::WaitForIdle();
     529           0 :         TaskScheduler::GetInstance()->Stop();
     530             :     } else {
     531           0 :         TaskScheduler::GetInstance()->Start();
     532           0 :         TestClient::WaitForIdle();
     533             :     }
     534           0 :     return true;
     535             : }
     536             : 
     537             : /////////////////////////////////////////////////////////////////////////////
     538             : //  AgentUtXmlLink routines
     539             : /////////////////////////////////////////////////////////////////////////////
     540         108 : AgentUtXmlLink::AgentUtXmlLink(const xml_node &node,
     541         108 :                                AgentUtXmlTestCase *test_case) :
     542         108 :     AgentUtXmlNode("link", node, test_case) {
     543         108 : }
     544             : 
     545         216 : AgentUtXmlLink::~AgentUtXmlLink() {
     546         216 : }
     547             : 
     548         108 : bool AgentUtXmlLink::ReadXml() {
     549         108 :     if (GetStringAttribute(node(), "left", &l_node_) == false) {
     550           0 :         cout << "Left node-type not specified for link. Skipping" << endl;
     551           0 :         return false;
     552             :     }
     553             : 
     554         108 :     if (GetStringAttribute(node(), "left-name", &l_name_) == false) {
     555           0 :         cout << "Right node-name not specified for link. Skipping" << endl;
     556           0 :         return false;
     557             :     }
     558             : 
     559         108 :     if (GetStringAttribute(node(), "right", &r_node_) == false) {
     560           0 :         cout << "Right node-type not specified for link. Skipping" << endl;
     561           0 :         return false;
     562             :     }
     563             : 
     564         108 :     if (GetStringAttribute(node(), "right-name", &r_name_) == false) {
     565           0 :         cout << "Right node-name not specified for link. Skipping" << endl;
     566           0 :         return false;
     567             :     }
     568             : 
     569         108 :     return true;
     570             : }
     571             : 
     572         108 : bool AgentUtXmlLink::ToXml(xml_node *parent) {
     573         108 :     LinkXmlNode(parent, l_node_, l_name_, r_node_, r_name_);
     574         108 :     return true;
     575             : }
     576             : 
     577         108 : void AgentUtXmlLink::ToString(string *str) {
     578         108 :     AgentUtXmlNode::ToString(str);
     579         108 :     stringstream s;
     580             : 
     581         216 :     s << "<" << l_node_ << " : " << l_name_ << "> <" << " right-node "
     582         108 :         << r_node_ << " : " << r_name_ << ">" << endl;
     583             : 
     584         108 :     *str += s.str();
     585         216 :     return;
     586         108 : }
     587             : 
     588         108 : string AgentUtXmlLink::NodeType() {
     589         108 :     return "Link";
     590             : }
     591             : 
     592             : /////////////////////////////////////////////////////////////////////////////
     593             : //  AgentUtXmlConfig routines
     594             : /////////////////////////////////////////////////////////////////////////////
     595         375 : AgentUtXmlConfig::AgentUtXmlConfig(const string &name, const uuid &id,
     596             :                                    const xml_node &node,
     597         375 :                                    AgentUtXmlTestCase *test_case) :
     598         375 :     AgentUtXmlNode(name, node, test_case), id_(id) {
     599         375 : }
     600             : 
     601           0 : AgentUtXmlConfig::AgentUtXmlConfig(const string &name, const uuid &id,
     602             :                                    const xml_node &node, bool gen_xml,
     603           0 :                                    AgentUtXmlTestCase *test_case) :
     604           0 :     AgentUtXmlNode(name, node, gen_xml, test_case), id_(id) {
     605           0 : }
     606             : 
     607         375 : AgentUtXmlConfig::~AgentUtXmlConfig() {
     608         375 : }
     609             : 
     610         375 : bool AgentUtXmlConfig::ReadXml() {
     611         375 :     return AgentUtXmlNode::ReadXml();
     612             : }
     613             : 
     614         375 : void AgentUtXmlConfig::ToString(std::string *str) {
     615         375 :     AgentUtXmlNode::ToString(str);
     616         375 :     stringstream s;
     617         375 :     s << " UUID : " << id_;
     618         375 :     *str += s.str();
     619         375 : }
     620             : 
     621         203 : static void AddPermissions(xml_node *parent) {
     622         203 :     xml_node n = parent->append_child("permissions");
     623             : 
     624         203 :     AddXmlNodeWithValue(&n, "owner", "cloud-admin");
     625         203 :     AddXmlNodeWithValue(&n, "owner-access", "7");
     626         203 :     AddXmlNodeWithValue(&n, "group", "cloud-admin-group");
     627         203 :     AddXmlNodeWithValue(&n, "group-access", "7");
     628         203 :     AddXmlNodeWithValue(&n, "other-access", "7");
     629         203 : }
     630             : 
     631         203 : static void AddUuid(xml_node *parent, const uuid &id) {
     632         203 :     xml_node n = parent->append_child("uuid");
     633             : 
     634         203 :     std::vector<uint8_t> v1(id.size());
     635         203 :     std::vector<uint64_t> v(id.size());
     636         203 :     std::copy(id.begin(), id.end(), v.begin());
     637             : 
     638         203 :     uint64_t ms_val = v[7] + (v[6] << 8) + (v[5] << 16) + (v[4] << 24) +
     639         203 :                    (v[3] << 32) + (v[2] << 40) + (v[1] << 48) + (v[0] << 56);
     640         203 :     uint64_t ls_val = v[15] + (v[14] << 8) + (v[13] << 16) + (v[12] << 24) +
     641         203 :                    (v[11] << 32) + (v[10] << 40) + (v[9] << 48) + (v[8] << 56);
     642         203 :     stringstream s;
     643         203 :     s << ms_val;
     644         203 :     AddXmlNodeWithValue(&n, "uuid-mslong", s.str());
     645             : 
     646         203 :     stringstream s1;
     647         203 :     s1 << ls_val;
     648         203 :     AddXmlNodeWithValue(&n, "uuid-lslong", s1.str());
     649         203 : }
     650             : 
     651         339 : void AgentUtXmlConfig::AddIdPerms(xml_node *parent) {
     652             : 
     653         339 :     if (op_delete())
     654         136 :         return;
     655             : 
     656         203 :     xml_node n = parent->append_child("id-perms");
     657         203 :     AddPermissions(&n);
     658         203 :     AddUuid(&n, id());
     659         203 :     AddXmlNodeWithValue(&n, "enable", "true");
     660             : }

Generated by: LCOV version 1.14