2018-05-01 18:40:25 +01:00
|
|
|
from core.emulator.emudata import LinkOptions
|
2019-04-30 07:31:47 +01:00
|
|
|
from core.emulator.enumerations import NodeTypes
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def create_ptp_network(session, ip_prefixes):
|
|
|
|
# create nodes
|
|
|
|
node_one = session.add_node()
|
|
|
|
node_two = session.add_node()
|
|
|
|
|
|
|
|
# link nodes to net node
|
|
|
|
interface_one = ip_prefixes.create_interface(node_one)
|
|
|
|
interface_two = ip_prefixes.create_interface(node_two)
|
2019-04-27 06:07:51 +01:00
|
|
|
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
|
|
|
return node_one, node_two
|
|
|
|
|
|
|
|
|
|
|
|
class TestLinks:
|
|
|
|
def test_ptp(self, session, ip_prefixes):
|
|
|
|
# given
|
|
|
|
node_one = session.add_node()
|
|
|
|
node_two = session.add_node()
|
|
|
|
interface_one = ip_prefixes.create_interface(node_one)
|
2019-09-11 05:35:47 +01:00
|
|
|
interface_two = ip_prefixes.create_interface(node_two)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2019-09-11 05:35:47 +01:00
|
|
|
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert node_one.netif(interface_one.id)
|
2019-09-11 05:35:47 +01:00
|
|
|
assert node_two.netif(interface_two.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
def test_node_to_net(self, session, ip_prefixes):
|
|
|
|
# given
|
|
|
|
node_one = session.add_node()
|
|
|
|
node_two = session.add_node(_type=NodeTypes.SWITCH)
|
|
|
|
interface_one = ip_prefixes.create_interface(node_one)
|
|
|
|
|
|
|
|
# when
|
2019-04-27 06:07:51 +01:00
|
|
|
session.add_link(node_one.id, node_two.id, interface_one)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert node_two.all_link_data(0)
|
|
|
|
assert node_one.netif(interface_one.id)
|
|
|
|
|
|
|
|
def test_net_to_node(self, session, ip_prefixes):
|
|
|
|
# given
|
|
|
|
node_one = session.add_node(_type=NodeTypes.SWITCH)
|
|
|
|
node_two = session.add_node()
|
|
|
|
interface_two = ip_prefixes.create_interface(node_two)
|
|
|
|
|
|
|
|
# when
|
2019-04-27 06:07:51 +01:00
|
|
|
session.add_link(node_one.id, node_two.id, interface_two=interface_two)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert node_one.all_link_data(0)
|
|
|
|
assert node_two.netif(interface_two.id)
|
|
|
|
|
|
|
|
def test_net_to_net(self, session):
|
|
|
|
# given
|
|
|
|
node_one = session.add_node(_type=NodeTypes.SWITCH)
|
|
|
|
node_two = session.add_node(_type=NodeTypes.SWITCH)
|
|
|
|
|
|
|
|
# when
|
2019-04-27 06:07:51 +01:00
|
|
|
session.add_link(node_one.id, node_two.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert node_one.all_link_data(0)
|
|
|
|
|
|
|
|
def test_link_update(self, session, ip_prefixes):
|
|
|
|
# given
|
2019-09-11 05:33:35 +01:00
|
|
|
delay = 50
|
|
|
|
bandwidth = 5000000
|
|
|
|
per = 25
|
|
|
|
dup = 25
|
|
|
|
jitter = 10
|
2018-04-26 00:33:58 +01:00
|
|
|
node_one = session.add_node()
|
|
|
|
node_two = session.add_node(_type=NodeTypes.SWITCH)
|
2019-09-11 05:33:35 +01:00
|
|
|
interface_one_data = ip_prefixes.create_interface(node_one)
|
|
|
|
session.add_link(node_one.id, node_two.id, interface_one_data)
|
|
|
|
interface_one = node_one.netif(interface_one_data.id)
|
|
|
|
assert interface_one.getparam("delay") != delay
|
|
|
|
assert interface_one.getparam("bw") != bandwidth
|
|
|
|
assert interface_one.getparam("loss") != per
|
|
|
|
assert interface_one.getparam("duplicate") != dup
|
|
|
|
assert interface_one.getparam("jitter") != jitter
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
|
|
|
link_options = LinkOptions()
|
2019-09-11 05:33:35 +01:00
|
|
|
link_options.delay = delay
|
|
|
|
link_options.bandwidth = bandwidth
|
|
|
|
link_options.per = per
|
|
|
|
link_options.dup = dup
|
|
|
|
link_options.jitter = jitter
|
2019-09-10 23:10:24 +01:00
|
|
|
session.update_link(
|
|
|
|
node_one.id,
|
|
|
|
node_two.id,
|
2019-09-11 05:33:35 +01:00
|
|
|
interface_one_id=interface_one_data.id,
|
2019-09-10 23:10:24 +01:00
|
|
|
link_options=link_options,
|
|
|
|
)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2019-09-11 05:33:35 +01:00
|
|
|
assert interface_one.getparam("delay") == delay
|
|
|
|
assert interface_one.getparam("bw") == bandwidth
|
|
|
|
assert interface_one.getparam("loss") == per
|
|
|
|
assert interface_one.getparam("duplicate") == dup
|
|
|
|
assert interface_one.getparam("jitter") == jitter
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
def test_link_delete(self, session, ip_prefixes):
|
|
|
|
# given
|
|
|
|
node_one = session.add_node()
|
|
|
|
node_two = session.add_node()
|
|
|
|
interface_one = ip_prefixes.create_interface(node_one)
|
|
|
|
interface_two = ip_prefixes.create_interface(node_two)
|
2019-04-27 06:07:51 +01:00
|
|
|
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
|
2018-04-26 00:33:58 +01:00
|
|
|
assert node_one.netif(interface_one.id)
|
|
|
|
assert node_two.netif(interface_two.id)
|
|
|
|
|
|
|
|
# when
|
2019-09-10 23:10:24 +01:00
|
|
|
session.delete_link(
|
|
|
|
node_one.id, node_two.id, interface_one.id, interface_two.id
|
|
|
|
)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert not node_one.netif(interface_one.id)
|
|
|
|
assert not node_two.netif(interface_two.id)
|