7 #include <pugixml/pugixml.hpp>
8 #include <boost/filesystem.hpp>
9 #include <boost/uuid/uuid.hpp>
11 #include <test/test_cmn_util.h>
12 #include <pkt/test/test_pkt_util.h>
21 using namespace boost::uuids;
22 using namespace AgentUtXmlUtils;
24 namespace AgentUtXmlUtils {
27 xml_attribute attr = node.attribute(name.c_str());
32 *value = attr.as_string();
39 xml_attribute attr = node.attribute(name.c_str());
44 *value = attr.as_uint();
50 xml_attribute attr = node.attribute(name.c_str());
55 *value = attr.as_int();
62 xml_attribute attr = node.attribute(name.c_str());
67 string str = attr.as_string();
68 if (str ==
"true" || str ==
"yes")
76 const uuid &vm_uuid,
const uuid vn_uuid,
const string &name,
77 const string &mac,
const string vm_name) {
80 cout <<
"Nova Del Interface Message " << endl;
84 PortSubscribe(name,
id, vm_uuid, vm_name, vn_uuid, MakeUuid(1), ip,
85 Ip6Address::v4_compatible(ip), mac);
86 cout <<
"Nova Add Interface Message " << endl;
90 void LinkXmlNode(xml_node *parent,
const string <ype,
const string lname,
91 const string &rtype,
const string rname) {
92 xml_node n = parent->append_child(
"link");
94 xml_node n1 = n.append_child(
"node");
95 n1.append_attribute(
"type") = ltype.c_str();
97 xml_node n2 = n1.append_child(
"name");
98 n2.append_child(pugi::node_pcdata).set_value(lname.c_str());
100 n1 = n.append_child(
"node");
101 n1.append_attribute(
"type") = rtype.c_str();
103 n2 = n1.append_child(
"name");
104 n2.append_child(pugi::node_pcdata).set_value(rname.c_str());
106 string mdata = GetMetadata(ltype.c_str(), rtype.c_str());
107 xml_node n3 = n.append_child(
"metadata");
108 n3.append_attribute(
"type") = mdata.c_str();
113 xml_node n = parent->append_child(
"node");
114 n.append_attribute(
"type") = attr;
119 const string &value) {
120 xml_node n = parent->append_child(name);
121 n.append_child(pugi::node_pcdata).set_value(value.c_str());
129 xml_node n = parent->append_child(name);
130 n.append_child(pugi::node_pcdata).set_value(s.str().c_str());
143 for (AgentUtXmlTestList::iterator i =
test_list_.begin();
161 AgentUtXmlTestConfigFactory::iterator iter =
config_factory_.find(name);
179 xml_node list =
doc_.child(
"test_suite");
182 for (xml_node node = list.first_child(); node; node = node.next_sibling()) {
183 if (strcmp(node.name(),
"test") == 0) {
184 xml_attribute attr = node.attribute(
"name");
186 cout <<
"Missing attribute \"name\". Skipping" << endl;
191 attr = node.attribute(
"verbose");
192 bool verbose =
false;
196 if (atoi(attr.value()))
209 boost::system::error_code ec;
210 boost::filesystem::path file_path(
file_name_);
211 uintmax_t file_size = boost::filesystem::file_size(file_path, ec);
213 cout <<
"Error <" << ec <<
"> opening file" <<
file_name_ << endl;
217 std::fstream file(
file_name_.c_str(), std::ios::binary | std::ios_base::in);
219 cout <<
"Error <fstream error> opening file" <<
file_name_ << endl;
223 std::vector<char> data(file_size + 1, 0);
224 file.read(data.data(), file_size);
225 if (!file || file.gcount() <
static_cast<std::streamsize
>(file_size)) {
226 cout <<
"Error <fstream::read> reading file" <<
file_name_ << endl;
230 xml_parse_result result =
doc_.load(data.data());
232 cout <<
"Loaded data file successfully" << endl;
234 cout <<
"Error in XML string at offset <: " << result.offset
235 <<
"> (error at [..." << (data.data() + result.offset) <<
"])" << endl;
245 s <<
"Test Suite : " <<
name_ << endl;
247 for (AgentUtXmlTestList::iterator it =
test_list_.begin();
249 (*it)->ToString(str);
255 for (AgentUtXmlTestList::iterator it =
test_list_.begin();
264 for (AgentUtXmlTestList::iterator it =
test_list_.begin();
266 if ((*it)->name().compare(test_case) == 0) {
279 uuid *
id,
string *name) {
280 if (strcmp(node.name(), node_name.c_str()) != 0) {
284 xml_attribute attr = node.attribute(
"name");
286 cout <<
"Attribute \"name\" not found for " << node_name
287 <<
". Skipping..." << endl;
291 *name = attr.as_string();
293 cout <<
"Invalid \"name\" for " << node_name <<
" Skipping" << endl;
297 if (node_name ==
"validate")
300 attr = node.attribute(
"uuid");
302 cout <<
"Attribute \"uuid\" not found for " << node_name
303 <<
". Skipping..." << endl;
307 int x = attr.as_uint();
309 cout <<
"Invalid \"uuid\" (0) for " << node_name <<
" Skipping" << endl;
319 const xml_node &node,
321 : name_(name), xml_node_(node), test_(test), verbose_(false) {
322 cout <<
"Creating test-case <" <<
name_ <<
">" << endl;
326 for (AgentUtXmlNodeList::iterator i =
node_list_.begin();
333 for (xml_node node =
xml_node_.first_child(); node;
334 node = node.next_sibling()) {
337 bool op_delete =
false;
340 if (str !=
"false" && str !=
"0")
351 if (fn.empty() ==
false)
352 cfg = fn(node.name(),
name, id, node,
this);
355 if (strcmp(node.name(),
"link") == 0) {
359 if (strcmp(node.name(),
"packet") == 0) {
361 cout <<
"Attribute \"name\" not specified for Packet. Skipping"
368 if (strcmp(node.name(),
"task") == 0) {
372 if (strcmp(node.name(),
"validate") == 0) {
374 cout <<
"Attribute \"name\" not specified for validate."
384 cout <<
"Unknown node name <" << node.name() <<
">. Ignoring"
389 if (op_delete ==
false && ret ==
false) {
404 for (AgentUtXmlNodeList::iterator it =
node_list_.begin();
406 if ((*it)->gen_xml() ==
false) {
414 xml_node decl = doc.prepend_child(pugi::node_declaration);
415 decl.append_attribute(
"version") =
"1.0";
417 xml_node n = doc.append_child(
"config");
419 if ((*it)->op_delete()) {
420 n1 = n.append_child(
"delete");
422 n1 = n.append_child(
"update");
426 doc.print(std::cout);
439 s <<
"Test Case : " <<
name_ << endl;
441 for (AgentUtXmlNodeList::iterator it =
node_list_.begin();
443 (*it)->ToString(str);
453 node_(node), name_(name), op_delete_(false), gen_xml_(true),
454 test_case_(test_case) {
459 node_(node), name_(name), op_delete_(false), gen_xml_(gen_xml),
460 test_case_(test_case) {
471 if (str !=
"false" && str !=
"0")
516 s <<
"Stop : " <<
stop_ << endl;
526 if (boost::iequals(
stop_,
"1") || boost::iequals(
stop_,
"yes")) {
549 cout <<
"Left node-type not specified for link. Skipping" << endl;
554 cout <<
"Right node-name not specified for link. Skipping" << endl;
559 cout <<
"Right node-type not specified for link. Skipping" << endl;
564 cout <<
"Right node-name not specified for link. Skipping" << endl;
580 s <<
"<" <<
l_node_ <<
" : " <<
l_name_ <<
"> <" <<
" right-node "
595 const xml_node &node,
601 const xml_node &node,
bool gen_xml,
616 s <<
" UUID : " <<
id_;
621 xml_node n = parent->append_child(
"permissions");
631 xml_node n = parent->append_child(
"uuid");
633 std::vector<uint8_t> v1(
id.size());
634 std::vector<uint64_t> v(
id.size());
635 std::copy(
id.begin(),
id.end(), v.begin());
637 uint64_t ms_val = v[7] + (v[6] << 8) + (v[5] << 16) + (v[4] << 24) +
638 (v[3] << 32) + (v[2] << 40) + (v[1] << 48) + (v[0] << 56);
639 uint64_t ls_val = v[15] + (v[14] << 8) + (v[13] << 16) + (v[12] << 24) +
640 (v[11] << 32) + (v[10] << 40) + (v[9] << 48) + (v[8] << 56);
655 xml_node n = parent->append_child(
"id-perms");
boost::function< AgentUtXmlValidationNode *(const std::string &type, const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)> AgentUtXmlTestValidateCreateFn
virtual void ToString(std::string *str)
IFMapAgentParser * ifmap_parser() const
virtual ~AgentUtXmlTest()
virtual std::string NodeType()
virtual void ToString(std::string *str)
virtual void ToString(std::string *str)
xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name, int val)
void set_verbose(bool val)
AgentUtXmlNode(const std::string &name, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
static Agent * GetInstance()
bool GetIntAttribute(const xml_node &node, const string &name, int *value)
virtual void ToString(std::string *str)
AgentUtXmlTestValidateFactory validate_factory_
static bool CheckConfigNode(const string &node_name, const xml_node &node, uuid *id, string *name)
AgentUtXmlTestValidateCreateFn GetValidateCreateFn(const std::string &name)
const std::string & name() const
AgentUtXmlTask(const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
void ToString(std::string *str)
static void AddPermissions(xml_node *parent)
virtual ~AgentUtXmlConfig()
AgentUtXmlTestList test_list_
void Start()
Starts scheduling of all tasks.
static void WaitForIdle()
void NovaIntfAdd(bool op_delete, const uuid &id, const Ip4Address &ip, const uuid &vm_uuid, const uuid vn_uuid, const string &name, const string &mac, const string vm_name)
bool GetBoolAttribute(const xml_node &node, const string &name, bool *value)
xml_node AddXmlNodeWithValue(xml_node *parent, const char *name, const string &value)
virtual ~AgentUtXmlNode()
AgentUtXmlTestCase(const std::string &name, const pugi::xml_node &node, AgentUtXmlTest *test)
virtual std::string NodeType()=0
xml_node AddXmlNodeWithAttr(xml_node *parent, const char *attr)
void AddIdPerms(pugi::xml_node *parent)
boost::function< AgentUtXmlNode *(const std::string type, const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)> AgentUtXmlTestConfigCreateFn
virtual std::string NodeType()
virtual ~AgentUtXmlTask()
AgentUtXmlTest(const std::string &file_name)
static TaskScheduler * GetInstance()
void AddConfigEntry(const std::string &name, AgentUtXmlTestConfigCreateFn fn)
bool GetStringAttribute(const xml_node &node, const string &name, string *value)
virtual ~AgentUtXmlTestCase()
boost::asio::ip::address_v4 Ip4Address
void ConfigParse(const pugi::xml_node config, uint64_t seq)
AgentUtXmlLink(const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual bool ToXml(pugi::xml_node *parent)
virtual bool ToXml(pugi::xml_node *parent)
bool GetUintAttribute(const xml_node &node, const string &name, uint16_t *value)
virtual ~AgentUtXmlLink()
static void AddUuid(xml_node *parent, const uuid &id)
void AddValidateEntry(const std::string &name, AgentUtXmlTestValidateCreateFn fn)
void set_op_delete(bool val)
void Stop()
Stops scheduling of all tasks.
AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
AgentUtXmlTestConfigFactory config_factory_
const pugi::xml_node & node() const
virtual void ToString(std::string *str)
AgentUtXmlTestConfigCreateFn GetConfigCreateFn(const std::string &name)
void LinkXmlNode(xml_node *parent, const string <ype, const string lname, const string &rtype, const string rname)
AgentUtXmlNodeList node_list_