2021-03-19 23:54:24 +00:00
|
|
|
from pathlib import Path
|
2020-05-25 07:37:38 +01:00
|
|
|
from tempfile import TemporaryFile
|
2018-06-13 19:59:50 +01:00
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
|
|
import pytest
|
2019-09-11 05:33:35 +01:00
|
|
|
|
2022-05-25 18:51:42 +01:00
|
|
|
from core.emulator.data import IpPrefixes, LinkOptions
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.emulator.enumerations import EventTypes
|
2020-05-25 07:37:38 +01:00
|
|
|
from core.emulator.session import Session
|
2019-09-28 07:29:15 +01:00
|
|
|
from core.errors import CoreError
|
2019-04-30 07:31:47 +01:00
|
|
|
from core.location.mobility import BasicRangeModel
|
2020-05-20 22:44:34 +01:00
|
|
|
from core.nodes.base import CoreNode
|
2022-03-17 22:28:38 +00:00
|
|
|
from core.nodes.network import SwitchNode, WlanNode
|
2018-06-15 22:03:27 +01:00
|
|
|
from core.services.utility import SshService
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestXml:
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_xml_hooks(self, session: Session, tmpdir: TemporaryFile):
|
2018-07-28 00:31:33 +01:00
|
|
|
"""
|
|
|
|
Test save/load hooks in xml.
|
|
|
|
|
|
|
|
:param session: session for test
|
|
|
|
:param tmpdir: tmpdir to create data in
|
|
|
|
"""
|
2020-05-11 20:41:57 +01:00
|
|
|
# create hooks
|
2018-07-28 00:31:33 +01:00
|
|
|
file_name = "runtime_hook.sh"
|
|
|
|
data = "#!/bin/sh\necho hello"
|
2020-03-07 06:35:23 +00:00
|
|
|
state = EventTypes.RUNTIME_STATE
|
2020-05-21 08:20:05 +01:00
|
|
|
session.add_hook(state, file_name, data)
|
2018-07-28 00:31:33 +01:00
|
|
|
|
2020-05-11 20:41:57 +01:00
|
|
|
file_name = "instantiation_hook.sh"
|
|
|
|
data = "#!/bin/sh\necho hello"
|
|
|
|
state = EventTypes.INSTANTIATION_STATE
|
2020-05-21 08:20:05 +01:00
|
|
|
session.add_hook(state, file_name, data)
|
2020-05-11 20:41:57 +01:00
|
|
|
|
2018-07-28 00:31:33 +01:00
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2018-10-12 05:22:57 +01:00
|
|
|
session.save_xml(file_path)
|
2018-07-28 00:31:33 +01:00
|
|
|
|
|
|
|
# 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()
|
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# verify nodes have been recreated
|
2020-06-13 04:22:51 +01:00
|
|
|
runtime_hooks = session.hooks.get(state)
|
2018-07-28 00:31:33 +01:00
|
|
|
assert runtime_hooks
|
|
|
|
runtime_hook = runtime_hooks[0]
|
|
|
|
assert file_name == runtime_hook[0]
|
|
|
|
assert data == runtime_hook[1]
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_xml_ptp(
|
|
|
|
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
|
|
|
|
):
|
2018-06-13 19:59:50 +01:00
|
|
|
"""
|
2018-07-28 00:31:33 +01:00
|
|
|
Test xml client methods for a ptp network.
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
:param session: session for test
|
|
|
|
:param tmpdir: tmpdir to create data in
|
|
|
|
:param ip_prefixes: generates ip addresses for nodes
|
|
|
|
"""
|
|
|
|
# create nodes
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2018-06-13 19:59:50 +01:00
|
|
|
|
2022-03-17 22:28:38 +00:00
|
|
|
# link nodes
|
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
|
|
|
session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2018-10-12 05:22:57 +01:00
|
|
|
session.save_xml(file_path)
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# 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
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node1.id, CoreNode)
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node2.id, CoreNode)
|
|
|
|
# verify no links are known
|
|
|
|
assert len(session.link_manager.links()) == 0
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# verify nodes have been recreated
|
2022-03-17 22:28:38 +00:00
|
|
|
assert session.get_node(node1.id, CoreNode)
|
|
|
|
assert session.get_node(node2.id, CoreNode)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
2018-06-13 19:59:50 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_xml_ptp_services(
|
|
|
|
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
|
|
|
|
):
|
2018-06-15 22:03:27 +01:00
|
|
|
"""
|
|
|
|
Test xml client methods for a ptp neetwork.
|
|
|
|
|
|
|
|
:param session: session for test
|
|
|
|
:param tmpdir: tmpdir to create data in
|
|
|
|
:param ip_prefixes: generates ip addresses for nodes
|
|
|
|
"""
|
|
|
|
# create nodes
|
2022-05-25 18:51:42 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
2020-06-13 00:52:41 +01:00
|
|
|
node2 = session.add_node(CoreNode)
|
2018-06-15 22:03:27 +01:00
|
|
|
|
|
|
|
# link nodes to ptp net
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
|
|
|
session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
2018-06-15 22:03:27 +01:00
|
|
|
|
2018-06-22 16:16:59 +01:00
|
|
|
# set custom values for node service
|
2020-06-13 00:52:41 +01:00
|
|
|
session.services.set_service(node1.id, SshService.name)
|
2018-06-15 22:03:27 +01:00
|
|
|
service_file = SshService.configs[0]
|
|
|
|
file_data = "# test"
|
2019-09-10 23:10:24 +01:00
|
|
|
session.services.set_service_file(
|
2020-06-13 00:52:41 +01:00
|
|
|
node1.id, SshService.name, service_file, file_data
|
2019-09-10 23:10:24 +01:00
|
|
|
)
|
2018-06-15 22:03:27 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2018-10-12 05:22:57 +01:00
|
|
|
session.save_xml(file_path)
|
2018-06-15 22:03:27 +01:00
|
|
|
|
|
|
|
# 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
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node1.id, CoreNode)
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node2.id, CoreNode)
|
2018-06-15 22:03:27 +01:00
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# retrieve custom service
|
2020-06-13 00:52:41 +01:00
|
|
|
service = session.services.get_service(node1.id, SshService.name)
|
2018-06-15 22:03:27 +01:00
|
|
|
|
|
|
|
# verify nodes have been recreated
|
2022-03-17 22:28:38 +00:00
|
|
|
assert session.get_node(node1.id, CoreNode)
|
|
|
|
assert session.get_node(node2.id, CoreNode)
|
2018-06-22 22:41:06 +01:00
|
|
|
assert service.config_data.get(service_file) == file_data
|
2018-06-15 22:03:27 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_xml_mobility(
|
|
|
|
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
|
|
|
|
):
|
2018-06-13 19:59:50 +01:00
|
|
|
"""
|
|
|
|
Test xml client methods for mobility.
|
|
|
|
|
|
|
|
:param session: session for test
|
|
|
|
:param tmpdir: tmpdir to create data in
|
|
|
|
:param ip_prefixes: generates ip addresses for nodes
|
|
|
|
"""
|
|
|
|
# create wlan
|
2022-03-17 22:28:38 +00:00
|
|
|
wlan = session.add_node(WlanNode)
|
|
|
|
session.mobility.set_model(wlan, BasicRangeModel, {"test": "1"})
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# create nodes
|
2022-05-25 18:51:42 +01:00
|
|
|
options = CoreNode.create_options()
|
|
|
|
options.model = "mdr"
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode, options=options)
|
|
|
|
node2 = session.add_node(CoreNode, options=options)
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# link nodes
|
2020-06-13 00:52:41 +01:00
|
|
|
for node in [node1, node2]:
|
2020-06-16 17:30:16 +01:00
|
|
|
iface_data = ip_prefixes.create_iface(node)
|
2022-03-17 22:28:38 +00:00
|
|
|
session.add_link(node.id, wlan.id, iface1_data=iface_data)
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2018-10-12 05:22:57 +01:00
|
|
|
session.save_xml(file_path)
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# 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
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node1.id, CoreNode)
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node2.id, CoreNode)
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# retrieve configuration we set originally
|
2022-03-17 22:28:38 +00:00
|
|
|
value = str(session.mobility.get_config("test", wlan.id, BasicRangeModel.name))
|
2018-06-13 19:59:50 +01:00
|
|
|
|
|
|
|
# verify nodes and configuration were restored
|
2022-03-17 22:28:38 +00:00
|
|
|
assert session.get_node(node1.id, CoreNode)
|
|
|
|
assert session.get_node(node2.id, CoreNode)
|
|
|
|
assert session.get_node(wlan.id, WlanNode)
|
2018-06-13 19:59:50 +01:00
|
|
|
assert value == "1"
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_network_to_network(self, session: Session, tmpdir: TemporaryFile):
|
2019-06-08 22:01:26 +01:00
|
|
|
"""
|
|
|
|
Test xml generation when dealing with network to network nodes.
|
|
|
|
|
|
|
|
:param session: session for test
|
|
|
|
:param tmpdir: tmpdir to create data in
|
|
|
|
"""
|
|
|
|
# create nodes
|
2020-06-13 00:52:41 +01:00
|
|
|
switch1 = session.add_node(SwitchNode)
|
|
|
|
switch2 = session.add_node(SwitchNode)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# link nodes
|
2020-06-13 00:52:41 +01:00
|
|
|
session.add_link(switch1.id, switch2.id)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2019-06-08 22:01:26 +01:00
|
|
|
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
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(switch1.id, SwitchNode)
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(switch2.id, SwitchNode)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# verify nodes have been recreated
|
2022-03-17 22:28:38 +00:00
|
|
|
switch1 = session.get_node(switch1.id, SwitchNode)
|
|
|
|
switch2 = session.get_node(switch2.id, SwitchNode)
|
2020-06-13 00:52:41 +01:00
|
|
|
assert switch1
|
|
|
|
assert switch2
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 1
|
2019-06-08 22:01:26 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_options(
|
|
|
|
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
|
|
|
|
):
|
2019-06-08 22:01:26 +01:00
|
|
|
"""
|
|
|
|
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
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
2020-05-21 06:14:03 +01:00
|
|
|
switch = session.add_node(SwitchNode)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# create link
|
2020-06-13 00:52:41 +01:00
|
|
|
options = LinkOptions()
|
2020-06-14 02:07:21 +01:00
|
|
|
options.loss = 10.5
|
2020-06-13 00:52:41 +01:00
|
|
|
options.bandwidth = 50000
|
|
|
|
options.jitter = 10
|
|
|
|
options.delay = 30
|
|
|
|
options.dup = 5
|
2020-12-08 06:31:53 +00:00
|
|
|
options.buffer = 100
|
2020-06-16 17:30:16 +01:00
|
|
|
session.add_link(node1.id, switch.id, iface1_data, options=options)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2019-06-08 22:01:26 +01:00
|
|
|
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
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node1.id, CoreNode)
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(switch.id, SwitchNode)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# verify nodes have been recreated
|
2022-03-17 22:28:38 +00:00
|
|
|
assert session.get_node(node1.id, CoreNode)
|
|
|
|
assert session.get_node(switch.id, SwitchNode)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
link = list(session.link_manager.links())[0]
|
|
|
|
link_options = link.options()
|
|
|
|
assert options.loss == link_options.loss
|
|
|
|
assert options.bandwidth == link_options.bandwidth
|
|
|
|
assert options.jitter == link_options.jitter
|
|
|
|
assert options.delay == link_options.delay
|
|
|
|
assert options.dup == link_options.dup
|
|
|
|
assert options.buffer == link_options.buffer
|
2019-06-08 22:01:26 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_options_ptp(
|
|
|
|
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
|
|
|
|
):
|
2019-06-08 22:01:26 +01:00
|
|
|
"""
|
|
|
|
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
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
2020-06-13 00:52:41 +01:00
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# create link
|
2020-06-13 00:52:41 +01:00
|
|
|
options = LinkOptions()
|
2020-06-14 02:07:21 +01:00
|
|
|
options.loss = 10.5
|
2020-06-13 00:52:41 +01:00
|
|
|
options.bandwidth = 50000
|
|
|
|
options.jitter = 10
|
|
|
|
options.delay = 30
|
|
|
|
options.dup = 5
|
2020-12-08 06:31:53 +00:00
|
|
|
options.buffer = 100
|
2020-06-16 17:30:16 +01:00
|
|
|
session.add_link(node1.id, node2.id, iface1_data, iface2_data, options)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2019-06-08 22:01:26 +01:00
|
|
|
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
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node1.id, CoreNode)
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node2.id, CoreNode)
|
2019-06-08 22:01:26 +01:00
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# verify nodes have been recreated
|
2022-03-17 22:28:38 +00:00
|
|
|
assert session.get_node(node1.id, CoreNode)
|
|
|
|
assert session.get_node(node2.id, CoreNode)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
link = list(session.link_manager.links())[0]
|
|
|
|
link_options = link.options()
|
|
|
|
assert options.loss == link_options.loss
|
|
|
|
assert options.bandwidth == link_options.bandwidth
|
|
|
|
assert options.jitter == link_options.jitter
|
|
|
|
assert options.delay == link_options.delay
|
|
|
|
assert options.dup == link_options.dup
|
|
|
|
assert options.buffer == link_options.buffer
|
2019-06-09 00:56:39 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_options_bidirectional(
|
|
|
|
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
|
|
|
|
):
|
2019-06-09 00:56:39 +01:00
|
|
|
"""
|
|
|
|
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
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
2020-06-13 00:52:41 +01:00
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2019-06-09 00:56:39 +01:00
|
|
|
|
|
|
|
# create link
|
2020-06-13 00:52:41 +01:00
|
|
|
options1 = LinkOptions()
|
|
|
|
options1.unidirectional = 1
|
|
|
|
options1.bandwidth = 5000
|
|
|
|
options1.delay = 10
|
2020-06-14 02:07:21 +01:00
|
|
|
options1.loss = 10.5
|
2020-06-13 00:52:41 +01:00
|
|
|
options1.dup = 5
|
|
|
|
options1.jitter = 5
|
2020-12-08 06:31:53 +00:00
|
|
|
options1.buffer = 50
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(
|
|
|
|
node1.id, node2.id, iface1_data, iface2_data, options1
|
|
|
|
)
|
2020-06-13 00:52:41 +01:00
|
|
|
options2 = LinkOptions()
|
|
|
|
options2.unidirectional = 1
|
|
|
|
options2.bandwidth = 10000
|
|
|
|
options2.delay = 20
|
2020-06-14 02:07:21 +01:00
|
|
|
options2.loss = 10
|
2020-06-13 00:52:41 +01:00
|
|
|
options2.dup = 10
|
|
|
|
options2.jitter = 10
|
2020-12-08 06:31:53 +00:00
|
|
|
options2.buffer = 100
|
2022-03-17 22:28:38 +00:00
|
|
|
session.update_link(node2.id, node1.id, iface2.id, iface1.id, options2)
|
2019-06-09 00:56:39 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
# save xml
|
|
|
|
xml_file = tmpdir.join("session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2019-06-09 00:56:39 +01:00
|
|
|
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
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node1.id, CoreNode)
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
assert not session.get_node(node2.id, CoreNode)
|
2019-06-09 00:56:39 +01:00
|
|
|
|
|
|
|
# load saved xml
|
|
|
|
session.open_xml(file_path, start=True)
|
|
|
|
|
|
|
|
# verify nodes have been recreated
|
2022-03-17 22:28:38 +00:00
|
|
|
assert session.get_node(node1.id, CoreNode)
|
|
|
|
assert session.get_node(node2.id, CoreNode)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert options1.bandwidth == iface1.options.bandwidth
|
|
|
|
assert options1.delay == iface1.options.delay
|
|
|
|
assert options1.loss == iface1.options.loss
|
|
|
|
assert options1.dup == iface1.options.dup
|
|
|
|
assert options1.jitter == iface1.options.jitter
|
|
|
|
assert options1.buffer == iface1.options.buffer
|
|
|
|
assert options2.bandwidth == iface2.options.bandwidth
|
|
|
|
assert options2.delay == iface2.options.delay
|
|
|
|
assert options2.loss == iface2.options.loss
|
|
|
|
assert options2.dup == iface2.options.dup
|
|
|
|
assert options2.jitter == iface2.options.jitter
|
|
|
|
assert options2.buffer == iface2.options.buffer
|