daemon: updated session.delete_link to have the interface ids default to none, since only one may need to be provided, updated link tests to account for more cases
This commit is contained in:
parent
f626564200
commit
c64094ac1c
3 changed files with 126 additions and 15 deletions
|
@ -788,7 +788,6 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
link_options.network_id = message.get_tlv(LinkTlvs.NETWORK_ID.value)
|
||||
link_options.key = message.get_tlv(LinkTlvs.KEY.value)
|
||||
link_options.opaque = message.get_tlv(LinkTlvs.OPAQUE.value)
|
||||
|
||||
if message.flags & MessageFlags.ADD.value:
|
||||
self.session.add_link(
|
||||
node_one_id, node_two_id, interface_one, interface_two, link_options
|
||||
|
|
|
@ -319,8 +319,8 @@ class Session:
|
|||
self,
|
||||
node_one_id: int,
|
||||
node_two_id: int,
|
||||
interface_one_id: int,
|
||||
interface_two_id: int,
|
||||
interface_one_id: int = None,
|
||||
interface_two_id: int = None,
|
||||
link_type: LinkTypes = LinkTypes.WIRED,
|
||||
) -> None:
|
||||
"""
|
||||
|
|
|
@ -25,7 +25,7 @@ def create_ptp_network(
|
|||
|
||||
|
||||
class TestLinks:
|
||||
def test_ptp(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
def test_add_ptp(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
@ -39,20 +39,20 @@ class TestLinks:
|
|||
assert node_one.netif(interface_one.id)
|
||||
assert node_two.netif(interface_two.id)
|
||||
|
||||
def test_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
def test_add_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(SwitchNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
|
||||
# when
|
||||
session.add_link(node_one.id, node_two.id, interface_one)
|
||||
session.add_link(node_one.id, node_two.id, interface_one=interface_one)
|
||||
|
||||
# then
|
||||
assert node_two.all_link_data()
|
||||
assert node_one.netif(interface_one.id)
|
||||
|
||||
def test_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
def test_add_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node_one = session.add_node(SwitchNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
@ -76,7 +76,7 @@ class TestLinks:
|
|||
# then
|
||||
assert node_one.all_link_data()
|
||||
|
||||
def test_link_update(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
def test_update_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
delay = 50
|
||||
bandwidth = 5000000
|
||||
|
@ -95,12 +95,9 @@ class TestLinks:
|
|||
assert interface_one.getparam("jitter") != jitter
|
||||
|
||||
# when
|
||||
link_options = LinkOptions()
|
||||
link_options.delay = delay
|
||||
link_options.bandwidth = bandwidth
|
||||
link_options.per = per
|
||||
link_options.dup = dup
|
||||
link_options.jitter = jitter
|
||||
link_options = LinkOptions(
|
||||
delay=delay, bandwidth=bandwidth, per=per, dup=dup, jitter=jitter
|
||||
)
|
||||
session.update_link(
|
||||
node_one.id,
|
||||
node_two.id,
|
||||
|
@ -115,7 +112,94 @@ class TestLinks:
|
|||
assert interface_one.getparam("duplicate") == dup
|
||||
assert interface_one.getparam("jitter") == jitter
|
||||
|
||||
def test_link_delete(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
def test_update_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
delay = 50
|
||||
bandwidth = 5000000
|
||||
per = 25
|
||||
dup = 25
|
||||
jitter = 10
|
||||
node_one = session.add_node(SwitchNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two_data = ip_prefixes.create_interface(node_two)
|
||||
session.add_link(node_one.id, node_two.id, interface_two=interface_two_data)
|
||||
interface_two = node_two.netif(interface_two_data.id)
|
||||
assert interface_two.getparam("delay") != delay
|
||||
assert interface_two.getparam("bw") != bandwidth
|
||||
assert interface_two.getparam("loss") != per
|
||||
assert interface_two.getparam("duplicate") != dup
|
||||
assert interface_two.getparam("jitter") != jitter
|
||||
|
||||
# when
|
||||
link_options = LinkOptions(
|
||||
delay=delay, bandwidth=bandwidth, per=per, dup=dup, jitter=jitter
|
||||
)
|
||||
session.update_link(
|
||||
node_one.id,
|
||||
node_two.id,
|
||||
interface_two_id=interface_two_data.id,
|
||||
options=link_options,
|
||||
)
|
||||
|
||||
# then
|
||||
assert interface_two.getparam("delay") == delay
|
||||
assert interface_two.getparam("bw") == bandwidth
|
||||
assert interface_two.getparam("loss") == per
|
||||
assert interface_two.getparam("duplicate") == dup
|
||||
assert interface_two.getparam("jitter") == jitter
|
||||
|
||||
def test_update_ptp(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
delay = 50
|
||||
bandwidth = 5000000
|
||||
per = 25
|
||||
dup = 25
|
||||
jitter = 10
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_one_data = ip_prefixes.create_interface(node_one)
|
||||
interface_two_data = ip_prefixes.create_interface(node_two)
|
||||
session.add_link(
|
||||
node_one.id, node_two.id, interface_one_data, interface_two_data
|
||||
)
|
||||
interface_one = node_one.netif(interface_one_data.id)
|
||||
interface_two = node_two.netif(interface_two_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
|
||||
assert interface_two.getparam("delay") != delay
|
||||
assert interface_two.getparam("bw") != bandwidth
|
||||
assert interface_two.getparam("loss") != per
|
||||
assert interface_two.getparam("duplicate") != dup
|
||||
assert interface_two.getparam("jitter") != jitter
|
||||
|
||||
# when
|
||||
link_options = LinkOptions(
|
||||
delay=delay, bandwidth=bandwidth, per=per, dup=dup, jitter=jitter
|
||||
)
|
||||
session.update_link(
|
||||
node_one.id,
|
||||
node_two.id,
|
||||
interface_one_data.id,
|
||||
interface_two_data.id,
|
||||
link_options,
|
||||
)
|
||||
|
||||
# then
|
||||
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
|
||||
assert interface_two.getparam("delay") == delay
|
||||
assert interface_two.getparam("bw") == bandwidth
|
||||
assert interface_two.getparam("loss") == per
|
||||
assert interface_two.getparam("duplicate") == dup
|
||||
assert interface_two.getparam("jitter") == jitter
|
||||
|
||||
def test_delete_ptp(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
|
@ -133,3 +217,31 @@ class TestLinks:
|
|||
# then
|
||||
assert not node_one.netif(interface_one.id)
|
||||
assert not node_two.netif(interface_two.id)
|
||||
|
||||
def test_delete_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node_one = session.add_node(CoreNode)
|
||||
node_two = session.add_node(SwitchNode)
|
||||
interface_one = ip_prefixes.create_interface(node_one)
|
||||
session.add_link(node_one.id, node_two.id, interface_one)
|
||||
assert node_one.netif(interface_one.id)
|
||||
|
||||
# when
|
||||
session.delete_link(node_one.id, node_two.id, interface_one_id=interface_one.id)
|
||||
|
||||
# then
|
||||
assert not node_one.netif(interface_one.id)
|
||||
|
||||
def test_delete_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
|
||||
# given
|
||||
node_one = session.add_node(SwitchNode)
|
||||
node_two = session.add_node(CoreNode)
|
||||
interface_two = ip_prefixes.create_interface(node_two)
|
||||
session.add_link(node_one.id, node_two.id, interface_two=interface_two)
|
||||
assert node_two.netif(interface_two.id)
|
||||
|
||||
# when
|
||||
session.delete_link(node_one.id, node_two.id, interface_two_id=interface_two.id)
|
||||
|
||||
# then
|
||||
assert not node_two.netif(interface_two.id)
|
||||
|
|
Loading…
Reference in a new issue