diff --git a/daemon/tests/test_xml.py b/daemon/tests/test_xml.py index f093b225..e5e8cf99 100644 --- a/daemon/tests/test_xml.py +++ b/daemon/tests/test_xml.py @@ -3,7 +3,7 @@ from xml.etree import ElementTree import pytest from core.emane.ieee80211abg import EmaneIeee80211abgModel -from core.emulator.emudata import NodeOptions +from core.emulator.emudata import NodeOptions, LinkOptions from core.emulator.enumerations import NodeTypes from core.location.mobility import BasicRangeModel from core.services.utility import SshService @@ -16,7 +16,6 @@ class TestXml: :param session: session for test :param tmpdir: tmpdir to create data in - :param str version: xml version to write and parse """ # create hook file_name = "runtime_hook.sh" @@ -51,7 +50,6 @@ class TestXml: :param session: session for test :param tmpdir: tmpdir to create data in - :param str version: xml version to write and parse :param ip_prefixes: generates ip addresses for nodes """ # create ptp @@ -104,7 +102,6 @@ class TestXml: :param session: session for test :param tmpdir: tmpdir to create data in - :param str version: xml version to write and parse :param ip_prefixes: generates ip addresses for nodes """ # create ptp @@ -168,7 +165,6 @@ class TestXml: :param session: session for test :param tmpdir: tmpdir to create data in - :param str version: xml version to write and parse :param ip_prefixes: generates ip addresses for nodes """ # create wlan @@ -230,7 +226,6 @@ class TestXml: :param session: session for test :param tmpdir: tmpdir to create data in - :param str version: xml version to write and parse :param ip_prefixes: generates ip addresses for nodes """ # create emane node for networking the core nodes @@ -290,3 +285,181 @@ class TestXml: assert session.get_node(n2_id) assert session.get_node(emane_id) assert value == "1" + + def test_network_to_network(self, session, tmpdir): + """ + Test xml generation when dealing with network to network nodes. + + :param session: session for test + :param tmpdir: tmpdir to create data in + """ + # create nodes + switch_one = session.add_node(_type=NodeTypes.SWITCH) + switch_two = session.add_node(_type=NodeTypes.SWITCH) + + # link nodes + session.add_link(switch_one.id, switch_two.id) + + # instantiate session + session.instantiate() + + # get ids for nodes + n1_id = switch_one.id + n2_id = switch_two.id + + # save xml + xml_file = tmpdir.join("session.xml") + file_path = xml_file.strpath + session.save_xml(file_path) + + # verify xml file was created and can be parsed + assert xml_file.isfile() + assert ElementTree.parse(file_path) + + # stop current session, clearing data + session.shutdown() + + # verify nodes have been removed from session + with pytest.raises(KeyError): + assert not session.get_node(n1_id) + with pytest.raises(KeyError): + assert not session.get_node(n2_id) + + # load saved xml + session.open_xml(file_path, start=True) + + # verify nodes have been recreated + switch_one = session.get_node(n1_id) + switch_two = session.get_node(n2_id) + assert switch_one + assert switch_two + assert len(switch_one.all_link_data(0) + switch_two.all_link_data(0)) == 1 + + def test_link_options(self, session, tmpdir, ip_prefixes): + """ + Test xml client methods for a ptp network. + + :param session: session for test + :param tmpdir: tmpdir to create data in + :param ip_prefixes: generates ip addresses for nodes + """ + # create nodes + node_one = session.add_node() + interface_one = ip_prefixes.create_interface(node_one) + switch = session.add_node(_type=NodeTypes.SWITCH) + + # create link + link_options = LinkOptions() + link_options.per = 20 + link_options.bandwidth = 50000 + link_options.jitter = 10 + link_options.delay = 30 + link_options.dup = 5 + session.add_link(node_one.id, switch.id, interface_one, link_options=link_options) + + # instantiate session + session.instantiate() + + # get ids for nodes + n1_id = node_one.id + n2_id = switch.id + + # save xml + xml_file = tmpdir.join("session.xml") + file_path = xml_file.strpath + session.save_xml(file_path) + + # verify xml file was created and can be parsed + assert xml_file.isfile() + assert ElementTree.parse(file_path) + + # stop current session, clearing data + session.shutdown() + + # verify nodes have been removed from session + with pytest.raises(KeyError): + assert not session.get_node(n1_id) + with pytest.raises(KeyError): + assert not session.get_node(n2_id) + + # load saved xml + session.open_xml(file_path, start=True) + + # verify nodes have been recreated + assert session.get_node(n1_id) + assert session.get_node(n2_id) + links = [] + for node_id in session.nodes: + node = session.nodes[node_id] + links += node.all_link_data(0) + link = links[0] + assert link_options.per == link.per + assert link_options.bandwidth == link.bandwidth + assert link_options.jitter == link.jitter + assert link_options.delay == link.delay + assert link_options.dup == link.dup + + def test_link_options_ptp(self, session, tmpdir, ip_prefixes): + """ + Test xml client methods for a ptp network. + + :param session: session for test + :param tmpdir: tmpdir to create data in + :param ip_prefixes: generates ip addresses for nodes + """ + # create nodes + node_one = session.add_node() + interface_one = ip_prefixes.create_interface(node_one) + node_two = session.add_node() + interface_two = ip_prefixes.create_interface(node_two) + + # create link + link_options = LinkOptions() + link_options.per = 20 + link_options.bandwidth = 50000 + link_options.jitter = 10 + link_options.delay = 30 + link_options.dup = 5 + session.add_link(node_one.id, node_two.id, interface_one, interface_two, link_options) + + # instantiate session + session.instantiate() + + # get ids for nodes + n1_id = node_one.id + n2_id = node_two.id + + # save xml + xml_file = tmpdir.join("session.xml") + file_path = xml_file.strpath + session.save_xml(file_path) + + # verify xml file was created and can be parsed + assert xml_file.isfile() + assert ElementTree.parse(file_path) + + # stop current session, clearing data + session.shutdown() + + # verify nodes have been removed from session + with pytest.raises(KeyError): + assert not session.get_node(n1_id) + with pytest.raises(KeyError): + assert not session.get_node(n2_id) + + # load saved xml + session.open_xml(file_path, start=True) + + # verify nodes have been recreated + assert session.get_node(n1_id) + assert session.get_node(n2_id) + links = [] + for node_id in session.nodes: + node = session.nodes[node_id] + links += node.all_link_data(0) + link = links[0] + assert link_options.per == link.per + assert link_options.bandwidth == link.bandwidth + assert link_options.jitter == link.jitter + assert link_options.delay == link.delay + assert link_options.dup == link.dup