2020-05-25 07:37:38 +01:00
|
|
|
from typing import Tuple
|
|
|
|
|
2022-01-25 17:13:39 +00:00
|
|
|
import pytest
|
|
|
|
|
2020-06-16 20:50:24 +01:00
|
|
|
from core.emulator.data import IpPrefixes, LinkOptions
|
2020-05-25 07:37:38 +01:00
|
|
|
from core.emulator.session import Session
|
2022-01-25 17:13:39 +00:00
|
|
|
from core.errors import CoreError
|
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
|
|
|
|
2022-01-25 17:13:39 +00:00
|
|
|
INVALID_ID: int = 100
|
|
|
|
LINK_OPTIONS: LinkOptions = LinkOptions(
|
|
|
|
delay=50, bandwidth=5000000, loss=25, dup=25, jitter=10, buffer=100
|
|
|
|
)
|
|
|
|
|
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-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# link nodes to net node
|
2020-06-16 17:30:16 +01: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-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# instantiate session
|
|
|
|
session.instantiate()
|
|
|
|
|
2020-06-13 00:52:41 +01:00
|
|
|
return node1, node2
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestLinks:
|
2022-01-25 17:13:39 +00:00
|
|
|
def test_add_node_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2022-01-25 17:13:39 +00:00
|
|
|
iface1, iface2 = session.add_link(
|
|
|
|
node1.id, node2.id, iface1_data, iface2_data, options=LINK_OPTIONS
|
|
|
|
)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 1
|
2020-06-16 17:30:16 +01:00
|
|
|
assert node1.get_iface(iface1_data.id)
|
|
|
|
assert node2.get_iface(iface2_data.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
assert iface1 is not None
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
|
|
|
assert node1.get_iface(iface1_data.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
assert iface2 is not None
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
|
|
|
assert node1.get_iface(iface1_data.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
2020-06-12 03:01:38 +01:00
|
|
|
def test_add_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(
|
2022-01-25 17:13:39 +00:00
|
|
|
node1.id, node2.id, iface1_data=iface1_data, options=LINK_OPTIONS
|
|
|
|
)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert iface1 is not None
|
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
2020-06-16 17:30:16 +01:00
|
|
|
assert node1.get_iface(iface1_data.id)
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface2 is not None
|
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
|
|
|
assert node2.get_iface(iface1_data.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
2020-06-12 03:01:38 +01:00
|
|
|
def test_add_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(
|
2022-01-25 17:13:39 +00:00
|
|
|
node1.id, node2.id, iface2_data=iface2_data, options=LINK_OPTIONS
|
|
|
|
)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert iface1 is not None
|
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert iface2 is not None
|
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
|
|
|
assert node2.get_iface(iface2.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
2022-03-17 22:28:38 +00:00
|
|
|
def test_add_net_to_net(self, session: Session):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, options=LINK_OPTIONS)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert iface1 is not None
|
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
|
|
|
assert iface2 is not None
|
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_add_node_to_node_uni(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
|
|
|
link_options1 = LinkOptions(
|
|
|
|
delay=50,
|
|
|
|
bandwidth=5000000,
|
|
|
|
loss=25,
|
|
|
|
dup=25,
|
|
|
|
jitter=10,
|
|
|
|
buffer=100,
|
|
|
|
unidirectional=True,
|
|
|
|
)
|
|
|
|
link_options2 = LinkOptions(
|
|
|
|
delay=51,
|
|
|
|
bandwidth=5000001,
|
|
|
|
loss=26,
|
|
|
|
dup=26,
|
|
|
|
jitter=11,
|
|
|
|
buffer=101,
|
|
|
|
unidirectional=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
# when
|
|
|
|
iface1, iface2 = session.add_link(
|
|
|
|
node1.id, node2.id, iface1_data, iface2_data, link_options1
|
|
|
|
)
|
|
|
|
session.update_link(
|
|
|
|
node2.id, node1.id, iface2_data.id, iface1_data.id, link_options2
|
|
|
|
)
|
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 1
|
2022-01-25 17:13:39 +00:00
|
|
|
assert node1.get_iface(iface1_data.id)
|
|
|
|
assert node2.get_iface(iface2_data.id)
|
|
|
|
assert iface1 is not None
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface1.options == link_options1
|
|
|
|
assert iface1.has_netem
|
2022-01-25 17:13:39 +00:00
|
|
|
assert iface2 is not None
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface2.options == link_options2
|
|
|
|
assert iface2.has_netem
|
2018-04-26 00:33:58 +01:00
|
|
|
|
2020-06-12 03:01:38 +01:00
|
|
|
def test_update_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert iface1.options != LINK_OPTIONS
|
|
|
|
assert iface2.options != LINK_OPTIONS
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
2018-04-26 00:33:58 +01:00
|
|
|
|
2020-06-12 03:01:38 +01:00
|
|
|
def test_update_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
|
|
|
assert iface1.options != LINK_OPTIONS
|
|
|
|
assert iface2.options != LINK_OPTIONS
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
def test_update_ptp(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2022-01-25 17:13:39 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface1.options != LINK_OPTIONS
|
|
|
|
assert iface2.options != LINK_OPTIONS
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_update_net_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id)
|
|
|
|
assert iface1.options != LINK_OPTIONS
|
|
|
|
assert iface2.options != LINK_OPTIONS
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.update_link(node1.id, node2.id, iface1.id, iface2.id, LINK_OPTIONS)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# then
|
2022-01-26 05:39:52 +00:00
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
|
|
|
|
|
|
|
def test_update_error(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
|
|
|
assert iface1.options != LINK_OPTIONS
|
|
|
|
assert iface2.options != LINK_OPTIONS
|
|
|
|
|
|
|
|
# when
|
|
|
|
with pytest.raises(CoreError):
|
|
|
|
session.delete_link(node1.id, INVALID_ID, iface1.id, iface2.id)
|
2022-01-26 05:39:52 +00:00
|
|
|
|
|
|
|
def test_clear_net_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, options=LINK_OPTIONS)
|
2022-01-26 05:39:52 +00:00
|
|
|
assert iface1.options == LINK_OPTIONS
|
|
|
|
assert iface1.has_netem
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface2.options == LINK_OPTIONS
|
|
|
|
assert iface2.has_netem
|
2022-01-26 05:39:52 +00:00
|
|
|
|
|
|
|
# when
|
|
|
|
options = LinkOptions(delay=0, bandwidth=0, loss=0.0, dup=0, jitter=0, buffer=0)
|
2022-03-17 22:28:38 +00:00
|
|
|
session.update_link(node1.id, node2.id, iface1.id, iface2.id, options)
|
2022-01-26 05:39:52 +00:00
|
|
|
|
|
|
|
# then
|
|
|
|
assert iface1.options.is_clear()
|
|
|
|
assert not iface1.has_netem
|
2022-03-17 22:28:38 +00:00
|
|
|
assert iface2.options.is_clear()
|
|
|
|
assert not iface2.has_netem
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_delete_node_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
2018-04-26 00:33:58 +01:00
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
2018-04-26 00:33:58 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 0
|
|
|
|
assert iface1.id not in node1.ifaces
|
|
|
|
assert iface2.id not in node2.ifaces
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
def test_delete_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 0
|
|
|
|
assert iface1.id not in node1.ifaces
|
|
|
|
assert iface2.id not in node2.ifaces
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
def test_delete_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
2020-06-13 00:52:41 +01:00
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
2020-06-16 17:30:16 +01:00
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
2020-06-12 03:01:38 +01:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 0
|
|
|
|
assert iface1.id not in node1.ifaces
|
|
|
|
assert iface2.id not in node2.ifaces
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_delete_net_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# when
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node2.id, iface1.id, iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# then
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 0
|
|
|
|
assert iface1.id not in node1.ifaces
|
|
|
|
assert iface2.id not in node2.ifaces
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_delete_node_error(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# when
|
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, INVALID_ID, iface1.id, iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(INVALID_ID, node2.id, iface1.id, iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_delete_net_to_net_error(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
|
|
|
node3 = session.add_node(SwitchNode)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# when
|
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_delete_node_to_net_error(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(SwitchNode)
|
|
|
|
node3 = session.add_node(SwitchNode)
|
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# when
|
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_delete_net_to_node_error(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(SwitchNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
|
|
|
node3 = session.add_node(SwitchNode)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
2022-03-17 22:28:38 +00:00
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface2_data=iface2_data)
|
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# when
|
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
def test_delete_node_to_node_error(self, session: Session, ip_prefixes: IpPrefixes):
|
|
|
|
# given
|
|
|
|
node1 = session.add_node(CoreNode)
|
|
|
|
node2 = session.add_node(CoreNode)
|
|
|
|
node3 = session.add_node(SwitchNode)
|
|
|
|
iface1_data = ip_prefixes.create_iface(node1)
|
|
|
|
iface2_data = ip_prefixes.create_iface(node2)
|
|
|
|
iface1, iface2 = session.add_link(node1.id, node2.id, iface1_data, iface2_data)
|
2022-03-17 22:28:38 +00:00
|
|
|
assert len(session.link_manager.links()) == 1
|
|
|
|
assert node1.get_iface(iface1.id)
|
|
|
|
assert node2.get_iface(iface2.id)
|
2022-01-25 17:13:39 +00:00
|
|
|
|
|
|
|
# when
|
|
|
|
with pytest.raises(CoreError):
|
2022-03-17 22:28:38 +00:00
|
|
|
session.delete_link(node1.id, node3.id, iface1.id, iface2.id)
|