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

Generated by: LCOV version 1.14