2020-05-25 07:37:38 +01:00
|
|
|
from typing import Tuple
|
|
|
|
|
|
|
|
from core.emulator.emudata import IpPrefixes, LinkOptions
|
|
|
|
from core.emulator.session import Session
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.nodes.base import CoreNode
|
|
|
|
from core.nodes.network import SwitchNode
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def create_ptp_network(
|
|
|
|
session: Session, ip_prefixes: IpPrefixes
|
|
|
|
) -> Tuple[CoreNode, CoreNode]:
|
2018-04-26 00:33:58 +01:00
|
|
|
# create nodes
|
2020-05-21 06:14:03 +01:00
|
|
|
node_one = session.add_node(CoreNode)
|
|
|
|
node_two = session.add_node(CoreNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# 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:
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_ptp(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
node_one = session.add_node(CoreNode)
|
|
|
|
node_two = session.add_node(CoreNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
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
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
node_one = session.add_node(CoreNode)
|
|
|
|
node_two = session.add_node(SwitchNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
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
|
2020-03-13 06:12:17 +00:00
|
|
|
assert node_two.all_link_data()
|
2018-04-26 00:33:58 +01:00
|
|
|
assert node_one.netif(interface_one.id)
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
node_one = session.add_node(SwitchNode)
|
|
|
|
node_two = session.add_node(CoreNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
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
|
2020-03-13 06:12:17 +00:00
|
|
|
assert node_one.all_link_data()
|
2018-04-26 00:33:58 +01:00
|
|
|
assert node_two.netif(interface_two.id)
|
|
|
|
|
|
|
|
def test_net_to_net(self, session):
|
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
node_one = session.add_node(SwitchNode)
|
|
|
|
node_two = session.add_node(SwitchNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# 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
|
2020-03-13 06:12:17 +00:00
|
|
|
assert node_one.all_link_data()
|
2018-04-26 00:33:58 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_update(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2019-09-11 05:33:35 +01:00
|
|
|
delay = 50
|
|
|
|
bandwidth = 5000000
|
|
|
|
per = 25
|
|
|
|
dup = 25
|
|
|
|
jitter = 10
|
2020-05-21 06:14:03 +01:00
|
|
|
node_one = session.add_node(CoreNode)
|
|
|
|
node_two = session.add_node(SwitchNode)
|
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,
|
2020-06-09 21:46:26 +01:00
|
|
|
options=link_options,
|
2019-09-10 23:10:24 +01:00
|
|
|
)
|
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
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_delete(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-05-21 06:14:03 +01:00
|
|
|
node_one = session.add_node(CoreNode)
|
|
|
|
node_two = session.add_node(CoreNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
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)
|