8 #include <pugixml/pugixml.hpp>
9 #include <boost/filesystem.hpp>
10 #include <boost/uuid/uuid.hpp>
12 #include <test/test_cmn_util.h>
13 #include <pkt/test/test_pkt_util.h>
22 using namespace boost::uuids;
28 xml_attribute attr = node.attribute(name.c_str());
33 *value = attr.as_string();
40 xml_attribute attr = node.attribute(name.c_str());
45 *value = attr.as_uint();
51 xml_attribute attr = node.attribute(name.c_str());
56 *value = attr.as_int();
63 xml_attribute attr = node.attribute(name.c_str());
68 string str = attr.as_string();
69 if (str ==
"true" || str ==
"yes")
77 const uuid &vm_uuid,
const uuid vn_uuid,
const string &name,
78 const string &mac,
const string vm_name) {
81 cout <<
"Nova Del Interface Message " << endl;
85 PortSubscribe(name,
id, vm_uuid, vm_name, vn_uuid, MakeUuid(1), ip,
86 Ip6Address::v4_compatible(ip), mac);
87 cout <<
"Nova Add Interface Message " << endl;
91 void LinkXmlNode(xml_node *parent,
const string <ype,
const string lname,
92 const string &rtype,
const string rname) {
93 xml_node n = parent->append_child(
"link");
95 xml_node n1 = n.append_child(
"node");
96 n1.append_attribute(
"type") = ltype.c_str();
98 xml_node n2 = n1.append_child(
"name");
99 n2.append_child(pugi::node_pcdata).set_value(lname.c_str());
101 n1 = n.append_child(
"node");
102 n1.append_attribute(
"type") = rtype.c_str();
104 n2 = n1.append_child(
"name");
105 n2.append_child(pugi::node_pcdata).set_value(rname.c_str());
107 string mdata = GetMetadata(ltype.c_str(), rtype.c_str());
108 xml_node n3 = n.append_child(
"metadata");
109 n3.append_attribute(
"type") = mdata.c_str();
114 xml_node n = parent->append_child(
"node");
115 n.append_attribute(
"type") = attr;
120 const string &value) {
121 xml_node n = parent->append_child(name);
122 n.append_child(pugi::node_pcdata).set_value(value.c_str());
130 xml_node n = parent->append_child(name);
131 n.append_child(pugi::node_pcdata).set_value(s.str().c_str());
144 for (AgentUtXmlTestList::iterator i =
test_list_.begin();
162 AgentUtXmlTestConfigFactory::iterator iter =
config_factory_.find(name);
180 xml_node list =
doc_.child(
"test_suite");
183 for (xml_node node = list.first_child(); node; node = node.next_sibling()) {
184 if (strcmp(node.name(),
"test") == 0) {
185 xml_attribute attr = node.attribute(
"name");
187 cout <<
"Missing attribute \"name\". Skipping" << endl;
192 attr = node.attribute(
"verbose");
193 bool verbose =
false;
197 if (atoi(attr.value()))
210 boost::system::error_code ec;
211 boost::filesystem::path file_path(
file_name_);
212 uintmax_t file_size = boost::filesystem::file_size(file_path, ec);
214 cout <<
"Error <" << ec <<
"> opening file" <<
file_name_ << endl;
218 std::fstream file(
file_name_.c_str(), std::ios::binary | std::ios_base::in);
220 cout <<
"Error <fstream error> opening file" <<
file_name_ << endl;
224 std::vector<char> data(file_size + 1, 0);
225 file.read(data.data(), file_size);
226 if (!file || file.gcount() <
static_cast<std::streamsize
>(file_size)) {
227 cout <<
"Error <fstream::read> reading file" <<
file_name_ << endl;
231 xml_parse_result result =
doc_.load_string(data.data());
233 cout <<
"Loaded data file successfully" << endl;
235 cout <<
"Error in XML string at offset <: " << result.offset
236 <<
"> (error at [..." << (data.data() + result.offset) <<
"])" << endl;
246 s <<
"Test Suite : " <<
name_ << endl;
248 for (AgentUtXmlTestList::iterator it =
test_list_.begin();
250 (*it)->ToString(str);
256 for (AgentUtXmlTestList::iterator it =
test_list_.begin();
265 for (AgentUtXmlTestList::iterator it =
test_list_.begin();
267 if ((*it)->name().compare(test_case) == 0) {
280 uuid *
id,
string *name) {
281 if (strcmp(node.name(), node_name.c_str()) != 0) {
285 xml_attribute attr = node.attribute(
"name");
287 cout <<
"Attribute \"name\" not found for " << node_name
288 <<
". Skipping..." << endl;
292 *name = attr.as_string();
294 cout <<
"Invalid \"name\" for " << node_name <<
" Skipping" << endl;
298 if (node_name ==
"validate")
301 attr = node.attribute(
"uuid");
303 cout <<
"Attribute \"uuid\" not found for " << node_name
304 <<
". Skipping..." << endl;
308 int x = attr.as_uint();
310 cout <<
"Invalid \"uuid\" (0) for " << node_name <<
" Skipping" << endl;
320 const xml_node &node,
322 : name_(name), xml_node_(node), test_(test), verbose_(false) {
323 cout <<
"Creating test-case <" <<
name_ <<
">" << endl;
327 for (AgentUtXmlNodeList::iterator i =
node_list_.begin();
334 for (xml_node node =
xml_node_.first_child(); node;
335 node = node.next_sibling()) {
338 bool op_delete =
false;
341 if (str !=
"false" && str !=
"0")
352 if (fn.empty() ==
false)
353 cfg = fn(node.name(),
name,
id, node,
this);
356 if (strcmp(node.name(),
"link") == 0) {
360 if (strcmp(node.name(),
"packet") == 0) {
362 cout <<
"Attribute \"name\" not specified for Packet. Skipping"
369 if (strcmp(node.name(),
"task") == 0) {
373 if (strcmp(node.name(),
"validate") == 0) {
375 cout <<
"Attribute \"name\" not specified for validate."
385 cout <<
"Unknown node name <" << node.name() <<
">. Ignoring"
390 if (op_delete ==
false && ret ==
false) {
405 for (AgentUtXmlNodeList::iterator it =
node_list_.begin();
407 if ((*it)->gen_xml() ==
false) {
415 xml_node decl = doc.prepend_child(pugi::node_declaration);
416 decl.append_attribute(
"version") =
"1.0";
418 xml_node n = doc.append_child(
"config");
420 if ((*it)->op_delete()) {
421 n1 = n.append_child(
"delete");
423 n1 = n.append_child(
"update");
427 doc.print(std::cout);
440 s <<
"Test Case : " <<
name_ << endl;
442 for (AgentUtXmlNodeList::iterator it =
node_list_.begin();
444 (*it)->ToString(str);
454 node_(node), name_(name), op_delete_(false), gen_xml_(true),
455 test_case_(test_case) {
460 node_(node), name_(name), op_delete_(false), gen_xml_(gen_xml),
461 test_case_(test_case) {
472 if (str !=
"false" && str !=
"0")
517 s <<
"Stop : " <<
stop_ << endl;
527 if (boost::iequals(
stop_,
"1") || boost::iequals(
stop_,
"yes")) {
550 cout <<
"Left node-type not specified for link. Skipping" << endl;
555 cout <<
"Right node-name not specified for link. Skipping" << endl;
560 cout <<
"Right node-type not specified for link. Skipping" << endl;
565 cout <<
"Right node-name not specified for link. Skipping" << endl;
581 s <<
"<" <<
l_node_ <<
" : " <<
l_name_ <<
"> <" <<
" right-node "
596 const xml_node &node,
602 const xml_node &node,
bool gen_xml,
617 s <<
" UUID : " <<
id_;
622 xml_node n = parent->append_child(
"permissions");
632 xml_node n = parent->append_child(
"uuid");
634 std::vector<uint8_t> v1(
id.size());
635 std::vector<uint64_t> v(
id.size());
636 std::copy(
id.begin(),
id.end(), v.begin());
638 uint64_t ms_val = v[7] + (v[6] << 8) + (v[5] << 16) + (v[4] << 24) +
639 (v[3] << 32) + (v[2] << 40) + (v[1] << 48) + (v[0] << 56);
640 uint64_t ls_val = v[15] + (v[14] << 8) + (v[13] << 16) + (v[12] << 24) +
641 (v[11] << 32) + (v[10] << 40) + (v[9] << 48) + (v[8] << 56);
656 xml_node n = parent->append_child(
"id-perms");
boost::asio::ip::address_v4 Ip4Address
virtual ~AgentUtXmlConfig()
AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual void ToString(std::string *str)
void AddIdPerms(pugi::xml_node *parent)
virtual void ToString(std::string *str)
virtual bool ToXml(pugi::xml_node *parent)
virtual ~AgentUtXmlLink()
AgentUtXmlLink(const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual std::string NodeType()
void set_op_delete(bool val)
const pugi::xml_node & node() const
virtual void ToString(std::string *str)
AgentUtXmlNode(const std::string &name, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual ~AgentUtXmlNode()
virtual std::string NodeType()=0
virtual bool ToXml(pugi::xml_node *parent)
AgentUtXmlTask(const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual std::string NodeType()
virtual ~AgentUtXmlTask()
virtual void ToString(std::string *str)
virtual void ToString(std::string *str)
void set_verbose(bool val)
AgentUtXmlTestCase(const std::string &name, const pugi::xml_node &node, AgentUtXmlTest *test)
AgentUtXmlNodeList node_list_
const std::string & name() const
virtual ~AgentUtXmlTestCase()
AgentUtXmlTestList test_list_
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
AgentUtXmlTestConfigFactory config_factory_
boost::function< AgentUtXmlValidationNode *(const std::string &type, const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)> AgentUtXmlTestValidateCreateFn
AgentUtXmlTest(const std::string &file_name)
void AddValidateEntry(const std::string &name, AgentUtXmlTestValidateCreateFn fn)
virtual ~AgentUtXmlTest()
AgentUtXmlTestConfigCreateFn GetConfigCreateFn(const std::string &name)
AgentUtXmlTestValidateFactory validate_factory_
void ToString(std::string *str)
AgentUtXmlTestValidateCreateFn GetValidateCreateFn(const std::string &name)
void AddConfigEntry(const std::string &name, AgentUtXmlTestConfigCreateFn fn)
IFMapAgentParser * ifmap_parser() const
static Agent * GetInstance()
void ConfigParse(const pugi::xml_node config, uint64_t seq)
void Stop()
Stops scheduling of all tasks.
static TaskScheduler * GetInstance()
void Start()
Starts scheduling of all tasks.
static void WaitForIdle()
bool GetIntAttribute(const xml_node &node, const string &name, int *value)
bool GetUintAttribute(const xml_node &node, const string &name, uint16_t *value)
xml_node AddXmlNodeWithValue(xml_node *parent, const char *name, const string &value)
xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name, int val)
void LinkXmlNode(xml_node *parent, const string <ype, const string lname, const string &rtype, const string rname)
xml_node AddXmlNodeWithAttr(xml_node *parent, const char *attr)
bool GetStringAttribute(const xml_node &node, const string &name, string *value)
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)
static void AddPermissions(xml_node *parent)
static void AddUuid(xml_node *parent, const uuid &id)
static bool CheckConfigNode(const string &node_name, const xml_node &node, uuid *id, string *name)