2017-05-03 23:29:15 +01:00
|
|
|
"""
|
2019-06-24 23:49:12 +01:00
|
|
|
Tests for testing tlv message handling.
|
2017-05-03 23:29:15 +01:00
|
|
|
"""
|
2019-06-24 23:49:12 +01:00
|
|
|
import time
|
2021-03-19 23:54:24 +00:00
|
|
|
from pathlib import Path
|
2020-05-25 07:37:38 +01:00
|
|
|
from typing import Optional
|
2017-08-03 17:48:26 +01:00
|
|
|
|
2019-06-24 23:49:12 +01:00
|
|
|
import mock
|
2020-01-08 21:25:00 +00:00
|
|
|
import netaddr
|
2019-06-22 07:12:18 +01:00
|
|
|
import pytest
|
2019-10-24 07:15:19 +01:00
|
|
|
from mock import MagicMock
|
2019-09-11 05:33:35 +01:00
|
|
|
|
2019-06-22 07:12:18 +01:00
|
|
|
from core.api.tlv import coreapi
|
2020-05-25 07:37:38 +01:00
|
|
|
from core.api.tlv.corehandlers import CoreHandler
|
2020-03-22 21:09:38 +00:00
|
|
|
from core.api.tlv.enumerations import (
|
2019-09-10 22:20:51 +01:00
|
|
|
ConfigFlags,
|
|
|
|
ConfigTlvs,
|
|
|
|
EventTlvs,
|
|
|
|
ExecuteTlvs,
|
|
|
|
FileTlvs,
|
|
|
|
LinkTlvs,
|
|
|
|
NodeTlvs,
|
|
|
|
SessionTlvs,
|
|
|
|
)
|
2021-05-07 18:40:18 +01:00
|
|
|
from core.emane.models.ieee80211abg import EmaneIeee80211abgModel
|
2020-03-22 21:09:38 +00:00
|
|
|
from core.emulator.enumerations import EventTypes, MessageFlags, NodeTypes, RegisterTlvs
|
2019-09-28 07:29:15 +01:00
|
|
|
from core.errors import CoreError
|
2019-06-25 20:29:46 +01:00
|
|
|
from core.location.mobility import BasicRangeModel
|
2020-05-20 22:44:34 +01:00
|
|
|
from core.nodes.base import CoreNode, NodeBase
|
2020-05-21 06:14:03 +01:00
|
|
|
from core.nodes.network import SwitchNode, WlanNode
|
2017-05-03 23:29:15 +01:00
|
|
|
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def dict_to_str(values) -> str:
|
2019-10-18 03:25:52 +01:00
|
|
|
return "|".join(f"{x}={values[x]}" for x in values)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
|
|
|
|
2017-05-03 23:29:15 +01:00
|
|
|
class TestGui:
|
2019-09-10 23:10:24 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"node_type, model",
|
|
|
|
[
|
|
|
|
(NodeTypes.DEFAULT, "PC"),
|
|
|
|
(NodeTypes.EMANE, None),
|
|
|
|
(NodeTypes.HUB, None),
|
|
|
|
(NodeTypes.SWITCH, None),
|
|
|
|
(NodeTypes.WIRELESS_LAN, None),
|
|
|
|
(NodeTypes.TUNNEL, None),
|
|
|
|
],
|
|
|
|
)
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_node_add(
|
|
|
|
self, coretlv: CoreHandler, node_type: NodeTypes, model: Optional[str]
|
|
|
|
):
|
2019-06-22 07:12:18 +01:00
|
|
|
node_id = 1
|
2020-06-13 00:52:41 +01:00
|
|
|
name = "node1"
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreNodeMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
|
|
|
(NodeTlvs.NUMBER, node_id),
|
|
|
|
(NodeTlvs.TYPE, node_type.value),
|
2020-06-13 00:52:41 +01:00
|
|
|
(NodeTlvs.NAME, name),
|
2019-09-10 23:10:24 +01:00
|
|
|
(NodeTlvs.X_POSITION, 0),
|
|
|
|
(NodeTlvs.Y_POSITION, 0),
|
|
|
|
(NodeTlvs.MODEL, model),
|
|
|
|
],
|
|
|
|
)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2020-06-13 00:52:41 +01:00
|
|
|
node = coretlv.session.get_node(node_id, NodeBase)
|
|
|
|
assert node
|
|
|
|
assert node.name == name
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_node_update(self, coretlv: CoreHandler):
|
2019-06-22 07:12:18 +01:00
|
|
|
node_id = 1
|
2020-05-21 06:14:03 +01:00
|
|
|
coretlv.session.add_node(CoreNode, _id=node_id)
|
2019-06-22 07:12:18 +01:00
|
|
|
x = 50
|
|
|
|
y = 100
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreNodeMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(NodeTlvs.NUMBER, node_id),
|
|
|
|
(NodeTlvs.X_POSITION, x),
|
|
|
|
(NodeTlvs.Y_POSITION, y),
|
|
|
|
],
|
|
|
|
)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-05-20 22:44:34 +01:00
|
|
|
node = coretlv.session.get_node(node_id, NodeBase)
|
2019-06-22 07:12:18 +01:00
|
|
|
assert node is not None
|
|
|
|
assert node.position.x == x
|
|
|
|
assert node.position.y == y
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_node_delete(self, coretlv: CoreHandler):
|
2019-06-22 07:12:18 +01:00
|
|
|
node_id = 1
|
2020-05-21 06:14:03 +01:00
|
|
|
coretlv.session.add_node(CoreNode, _id=node_id)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreNodeMessage.create(
|
|
|
|
MessageFlags.DELETE.value, [(NodeTlvs.NUMBER, node_id)]
|
|
|
|
)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2019-09-11 21:12:42 +01:00
|
|
|
with pytest.raises(CoreError):
|
2020-05-20 22:44:34 +01:00
|
|
|
coretlv.session.get_node(node_id, NodeBase)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_add_node_to_net(self, coretlv: CoreHandler):
|
2020-06-13 00:52:41 +01:00
|
|
|
node1_id = 1
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node1_id)
|
|
|
|
switch_id = 2
|
|
|
|
coretlv.session.add_node(SwitchNode, _id=switch_id)
|
2020-01-08 21:25:00 +00:00
|
|
|
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_ip4 = str(ip_prefix[node1_id])
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, switch_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE1_IP4, iface1_ip4),
|
|
|
|
(LinkTlvs.IFACE1_IP4_MASK, 24),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_add_net_to_node(self, coretlv: CoreHandler):
|
2020-06-13 00:52:41 +01:00
|
|
|
node1_id = 1
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node1_id)
|
|
|
|
switch_id = 2
|
|
|
|
coretlv.session.add_node(SwitchNode, _id=switch_id)
|
2020-01-08 21:25:00 +00:00
|
|
|
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
2020-06-16 17:30:16 +01:00
|
|
|
iface2_ip4 = str(ip_prefix[node1_id])
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, switch_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, node1_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE2_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE2_IP4, iface2_ip4),
|
|
|
|
(LinkTlvs.IFACE2_IP4_MASK, 24),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-24 23:49:12 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_add_node_to_node(self, coretlv: CoreHandler):
|
2020-06-13 00:52:41 +01:00
|
|
|
node1_id = 1
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node1_id)
|
|
|
|
node2_id = 2
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node2_id)
|
2020-01-08 21:25:00 +00:00
|
|
|
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_ip4 = str(ip_prefix[node1_id])
|
|
|
|
iface2_ip4 = str(ip_prefix[node2_id])
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, node2_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE1_IP4, iface1_ip4),
|
|
|
|
(LinkTlvs.IFACE1_IP4_MASK, 24),
|
|
|
|
(LinkTlvs.IFACE2_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE2_IP4, iface2_ip4),
|
|
|
|
(LinkTlvs.IFACE2_IP4_MASK, 24),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
|
|
|
all_links = []
|
2019-10-24 18:58:26 +01:00
|
|
|
for node_id in coretlv.session.nodes:
|
|
|
|
node = coretlv.session.nodes[node_id]
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links += node.links()
|
2019-06-24 23:49:12 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_update(self, coretlv: CoreHandler):
|
2020-06-13 00:52:41 +01:00
|
|
|
node1_id = 1
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node1_id)
|
|
|
|
switch_id = 2
|
|
|
|
coretlv.session.add_node(SwitchNode, _id=switch_id)
|
2020-01-08 21:25:00 +00:00
|
|
|
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_ip4 = str(ip_prefix[node1_id])
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, switch_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE1_IP4, iface1_ip4),
|
|
|
|
(LinkTlvs.IFACE1_IP4_MASK, 24),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
link = all_links[0]
|
2020-06-16 22:18:19 +01:00
|
|
|
assert link.options.bandwidth is None
|
2019-06-22 07:12:18 +01:00
|
|
|
|
|
|
|
bandwidth = 50000
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, switch_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
2019-09-10 23:10:24 +01:00
|
|
|
(LinkTlvs.BANDWIDTH, bandwidth),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
link = all_links[0]
|
2020-06-16 22:18:19 +01:00
|
|
|
assert link.options.bandwidth == bandwidth
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_delete_node_to_node(self, coretlv: CoreHandler):
|
2020-06-13 00:52:41 +01:00
|
|
|
node1_id = 1
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node1_id)
|
|
|
|
node2_id = 2
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node2_id)
|
2020-01-08 21:25:00 +00:00
|
|
|
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_ip4 = str(ip_prefix[node1_id])
|
|
|
|
iface2_ip4 = str(ip_prefix[node2_id])
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, node2_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE1_IP4, iface1_ip4),
|
|
|
|
(LinkTlvs.IFACE1_IP4_MASK, 24),
|
|
|
|
(LinkTlvs.IFACE2_IP4, iface2_ip4),
|
|
|
|
(LinkTlvs.IFACE2_IP4_MASK, 24),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
all_links = []
|
2019-10-24 18:58:26 +01:00
|
|
|
for node_id in coretlv.session.nodes:
|
|
|
|
node = coretlv.session.nodes[node_id]
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links += node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.DELETE.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, node2_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE2_NUMBER, 0),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
|
|
|
all_links = []
|
2019-10-24 18:58:26 +01:00
|
|
|
for node_id in coretlv.session.nodes:
|
|
|
|
node = coretlv.session.nodes[node_id]
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links += node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 0
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_delete_node_to_net(self, coretlv: CoreHandler):
|
2020-06-13 00:52:41 +01:00
|
|
|
node1_id = 1
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node1_id)
|
|
|
|
switch_id = 2
|
|
|
|
coretlv.session.add_node(SwitchNode, _id=switch_id)
|
2020-01-08 21:25:00 +00:00
|
|
|
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_ip4 = str(ip_prefix[node1_id])
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, switch_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE1_IP4, iface1_ip4),
|
|
|
|
(LinkTlvs.IFACE1_IP4_MASK, 24),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.DELETE.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, switch_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 0
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_link_delete_net_to_node(self, coretlv: CoreHandler):
|
2020-06-13 00:52:41 +01:00
|
|
|
node1_id = 1
|
|
|
|
coretlv.session.add_node(CoreNode, _id=node1_id)
|
|
|
|
switch_id = 2
|
|
|
|
coretlv.session.add_node(SwitchNode, _id=switch_id)
|
2020-01-08 21:25:00 +00:00
|
|
|
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
|
2020-06-16 17:30:16 +01:00
|
|
|
iface1_ip4 = str(ip_prefix[node1_id])
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, node1_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, switch_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE1_NUMBER, 0),
|
|
|
|
(LinkTlvs.IFACE1_IP4, iface1_ip4),
|
|
|
|
(LinkTlvs.IFACE1_IP4_MASK, 24),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 1
|
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreLinkMessage.create(
|
|
|
|
MessageFlags.DELETE.value,
|
|
|
|
[
|
2020-06-13 00:52:41 +01:00
|
|
|
(LinkTlvs.N1_NUMBER, switch_id),
|
|
|
|
(LinkTlvs.N2_NUMBER, node1_id),
|
2020-06-16 17:30:16 +01:00
|
|
|
(LinkTlvs.IFACE2_NUMBER, 0),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-22 07:12:18 +01:00
|
|
|
|
2020-06-13 00:52:41 +01:00
|
|
|
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
|
2020-06-19 05:33:28 +01:00
|
|
|
all_links = switch_node.links()
|
2019-06-22 07:12:18 +01:00
|
|
|
assert len(all_links) == 0
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_session_update(self, coretlv: CoreHandler):
|
2019-10-24 18:58:26 +01:00
|
|
|
session_id = coretlv.session.id
|
2019-06-24 23:49:12 +01:00
|
|
|
name = "test"
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreSessionMessage.create(
|
|
|
|
0, [(SessionTlvs.NUMBER, str(session_id)), (SessionTlvs.NAME, name)]
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.name == name
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_session_query(self, coretlv: CoreHandler):
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.dispatch_replies = mock.MagicMock()
|
2019-06-24 23:49:12 +01:00
|
|
|
message = coreapi.CoreSessionMessage.create(MessageFlags.STRING.value, [])
|
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
args, _ = coretlv.dispatch_replies.call_args
|
2019-06-24 23:49:12 +01:00
|
|
|
replies = args[0]
|
|
|
|
assert len(replies) == 1
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_session_join(self, coretlv: CoreHandler):
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.dispatch_replies = mock.MagicMock()
|
|
|
|
session_id = coretlv.session.id
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreSessionMessage.create(
|
|
|
|
MessageFlags.ADD.value, [(SessionTlvs.NUMBER, str(session_id))]
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.id == session_id
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_session_delete(self, coretlv: CoreHandler):
|
2019-10-24 18:58:26 +01:00
|
|
|
assert len(coretlv.coreemu.sessions) == 1
|
|
|
|
session_id = coretlv.session.id
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreSessionMessage.create(
|
|
|
|
MessageFlags.DELETE.value, [(SessionTlvs.NUMBER, str(session_id))]
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert len(coretlv.coreemu.sessions) == 0
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_file_hook_add(self, coretlv: CoreHandler):
|
2020-03-07 06:35:23 +00:00
|
|
|
state = EventTypes.DATACOLLECT_STATE
|
2020-06-13 04:22:51 +01:00
|
|
|
assert coretlv.session.hooks.get(state) is None
|
2019-06-24 23:49:12 +01:00
|
|
|
file_name = "test.sh"
|
|
|
|
file_data = "echo hello"
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreFileMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
2020-03-07 06:35:23 +00:00
|
|
|
(FileTlvs.TYPE, f"hook:{state.value}"),
|
2019-09-10 23:10:24 +01:00
|
|
|
(FileTlvs.NAME, file_name),
|
|
|
|
(FileTlvs.DATA, file_data),
|
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-06-13 04:22:51 +01:00
|
|
|
hooks = coretlv.session.hooks.get(state)
|
2019-06-24 23:49:12 +01:00
|
|
|
assert len(hooks) == 1
|
|
|
|
name, data = hooks[0]
|
|
|
|
assert file_name == name
|
|
|
|
assert file_data == data
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_file_service_file_set(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-06-24 23:49:12 +01:00
|
|
|
service = "DefaultRoute"
|
|
|
|
file_name = "defaultroute.sh"
|
|
|
|
file_data = "echo hello"
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreFileMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
|
|
|
(FileTlvs.NODE, node.id),
|
2019-10-18 03:25:52 +01:00
|
|
|
(FileTlvs.TYPE, f"service:{service}"),
|
2019-09-10 23:10:24 +01:00
|
|
|
(FileTlvs.NAME, file_name),
|
|
|
|
(FileTlvs.DATA, file_data),
|
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
service_file = coretlv.session.services.get_service_file(
|
|
|
|
node, service, file_name
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
assert file_data == service_file.data
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_file_node_file_copy(self, request, coretlv: CoreHandler):
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path("/var/log/test/node.log")
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-06-24 23:49:12 +01:00
|
|
|
node.makenodedir()
|
|
|
|
file_data = "echo hello"
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreFileMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
|
|
|
(FileTlvs.NODE, node.id),
|
2021-03-19 23:54:24 +00:00
|
|
|
(FileTlvs.NAME, str(file_path)),
|
2019-09-10 23:10:24 +01:00
|
|
|
(FileTlvs.DATA, file_data),
|
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 07:15:19 +01:00
|
|
|
if not request.config.getoption("mock"):
|
2021-09-17 22:34:37 +01:00
|
|
|
expected_path = node.directory / "var.log/test" / file_path.name
|
|
|
|
assert expected_path.exists()
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_exec_node_tty(self, coretlv: CoreHandler):
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.dispatch_replies = mock.MagicMock()
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreExecMessage.create(
|
|
|
|
MessageFlags.TTY.value,
|
|
|
|
[
|
|
|
|
(ExecuteTlvs.NODE, node.id),
|
|
|
|
(ExecuteTlvs.NUMBER, 1),
|
|
|
|
(ExecuteTlvs.COMMAND, "bash"),
|
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
args, _ = coretlv.dispatch_replies.call_args
|
2019-06-24 23:49:12 +01:00
|
|
|
replies = args[0]
|
|
|
|
assert len(replies) == 1
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_exec_local_command(self, request, coretlv: CoreHandler):
|
2019-10-24 07:15:19 +01:00
|
|
|
if request.config.getoption("mock"):
|
|
|
|
pytest.skip("mocking calls")
|
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.dispatch_replies = mock.MagicMock()
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-10-24 07:15:19 +01:00
|
|
|
cmd = "echo hello"
|
2019-06-24 23:49:12 +01:00
|
|
|
message = coreapi.CoreExecMessage.create(
|
2019-09-10 23:10:24 +01:00
|
|
|
MessageFlags.TEXT.value | MessageFlags.LOCAL.value,
|
|
|
|
[
|
2019-06-24 23:49:12 +01:00
|
|
|
(ExecuteTlvs.NODE, node.id),
|
|
|
|
(ExecuteTlvs.NUMBER, 1),
|
2019-10-24 07:15:19 +01:00
|
|
|
(ExecuteTlvs.COMMAND, cmd),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
args, _ = coretlv.dispatch_replies.call_args
|
2019-06-24 23:49:12 +01:00
|
|
|
replies = args[0]
|
|
|
|
assert len(replies) == 1
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_exec_node_command(self, coretlv: CoreHandler):
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.dispatch_replies = mock.MagicMock()
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-10-24 07:15:19 +01:00
|
|
|
cmd = "echo hello"
|
2019-06-24 23:49:12 +01:00
|
|
|
message = coreapi.CoreExecMessage.create(
|
2019-09-10 23:10:24 +01:00
|
|
|
MessageFlags.TEXT.value,
|
|
|
|
[
|
2019-06-24 23:49:12 +01:00
|
|
|
(ExecuteTlvs.NODE, node.id),
|
|
|
|
(ExecuteTlvs.NUMBER, 1),
|
2019-10-24 07:15:19 +01:00
|
|
|
(ExecuteTlvs.COMMAND, cmd),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 07:15:19 +01:00
|
|
|
node.cmd = MagicMock(return_value="hello")
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 07:15:19 +01:00
|
|
|
node.cmd.assert_called_with(cmd)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"state",
|
|
|
|
[
|
|
|
|
EventTypes.SHUTDOWN_STATE,
|
|
|
|
EventTypes.RUNTIME_STATE,
|
|
|
|
EventTypes.DATACOLLECT_STATE,
|
|
|
|
EventTypes.CONFIGURATION_STATE,
|
|
|
|
EventTypes.DEFINITION_STATE,
|
|
|
|
],
|
|
|
|
)
|
2020-06-09 17:12:31 +01:00
|
|
|
def test_event_state(self, coretlv: CoreHandler, state: EventTypes):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreEventMessage.create(0, [(EventTlvs.TYPE, state.value)])
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-03-07 06:35:23 +00:00
|
|
|
assert coretlv.session.state == state
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_event_schedule(self, coretlv: CoreHandler):
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.add_event = mock.MagicMock()
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreEventMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
|
|
|
[
|
|
|
|
(EventTlvs.TYPE, EventTypes.SCHEDULED.value),
|
2019-12-06 17:42:41 +00:00
|
|
|
(EventTlvs.TIME, str(time.monotonic() + 100)),
|
2019-09-10 23:10:24 +01:00
|
|
|
(EventTlvs.NODE, node.id),
|
|
|
|
(EventTlvs.NAME, "event"),
|
|
|
|
(EventTlvs.DATA, "data"),
|
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.add_event.assert_called_once()
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-06-09 17:12:31 +01:00
|
|
|
def test_event_save_xml(self, coretlv: CoreHandler, tmpdir):
|
2019-10-24 18:58:26 +01:00
|
|
|
xml_file = tmpdir.join("coretlv.session.xml")
|
2019-06-24 23:49:12 +01:00
|
|
|
file_path = xml_file.strpath
|
2020-05-21 06:14:03 +01:00
|
|
|
coretlv.session.add_node(CoreNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreEventMessage.create(
|
|
|
|
0,
|
|
|
|
[(EventTlvs.TYPE, EventTypes.FILE_SAVE.value), (EventTlvs.NAME, file_path)],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2021-03-19 23:54:24 +00:00
|
|
|
assert Path(file_path).exists()
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-06-09 17:12:31 +01:00
|
|
|
def test_event_open_xml(self, coretlv: CoreHandler, tmpdir):
|
2019-10-24 18:58:26 +01:00
|
|
|
xml_file = tmpdir.join("coretlv.session.xml")
|
2021-03-19 23:54:24 +00:00
|
|
|
file_path = Path(xml_file.strpath)
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.save_xml(file_path)
|
|
|
|
coretlv.session.delete_node(node.id)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreEventMessage.create(
|
|
|
|
0,
|
2021-03-19 23:54:24 +00:00
|
|
|
[
|
|
|
|
(EventTlvs.TYPE, EventTypes.FILE_OPEN.value),
|
|
|
|
(EventTlvs.NAME, str(file_path)),
|
|
|
|
],
|
2019-09-10 23:10:24 +01:00
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2020-05-20 22:44:34 +01:00
|
|
|
assert coretlv.session.get_node(node.id, NodeBase)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"state",
|
|
|
|
[
|
|
|
|
EventTypes.START,
|
|
|
|
EventTypes.STOP,
|
|
|
|
EventTypes.RESTART,
|
|
|
|
EventTypes.PAUSE,
|
|
|
|
EventTypes.RECONFIGURE,
|
|
|
|
],
|
|
|
|
)
|
2020-06-09 17:12:31 +01:00
|
|
|
def test_event_service(self, coretlv: CoreHandler, state: EventTypes):
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.broadcast_event = mock.MagicMock()
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreEventMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(EventTlvs.TYPE, state.value),
|
|
|
|
(EventTlvs.NODE, node.id),
|
|
|
|
(EventTlvs.NAME, "service:DefaultRoute"),
|
|
|
|
],
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.broadcast_event.assert_called_once()
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-09-10 23:10:24 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"state",
|
|
|
|
[
|
|
|
|
EventTypes.START,
|
|
|
|
EventTypes.STOP,
|
|
|
|
EventTypes.RESTART,
|
|
|
|
EventTypes.PAUSE,
|
|
|
|
EventTypes.RECONFIGURE,
|
|
|
|
],
|
|
|
|
)
|
2020-06-09 17:12:31 +01:00
|
|
|
def test_event_mobility(self, coretlv: CoreHandler, state: EventTypes):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreEventMessage.create(
|
|
|
|
0, [(EventTlvs.TYPE, state.value), (EventTlvs.NAME, "mobility:ns2script")]
|
|
|
|
)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_register_gui(self, coretlv: CoreHandler):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreRegMessage.create(0, [(RegisterTlvs.GUI, "gui")])
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-06-09 17:12:31 +01:00
|
|
|
def test_register_xml(self, coretlv: CoreHandler, tmpdir):
|
2019-10-24 18:58:26 +01:00
|
|
|
xml_file = tmpdir.join("coretlv.session.xml")
|
2019-06-24 23:49:12 +01:00
|
|
|
file_path = xml_file.strpath
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.save_xml(file_path)
|
|
|
|
coretlv.session.delete_node(node.id)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreRegMessage.create(
|
|
|
|
0, [(RegisterTlvs.EXECUTE_SERVER, file_path)]
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.instantiate()
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-05-20 22:44:34 +01:00
|
|
|
assert coretlv.coreemu.sessions[1].get_node(node.id, CoreNode)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2020-06-09 17:12:31 +01:00
|
|
|
def test_register_python(self, coretlv: CoreHandler, tmpdir):
|
2019-06-24 23:49:12 +01:00
|
|
|
xml_file = tmpdir.join("test.py")
|
|
|
|
file_path = xml_file.strpath
|
|
|
|
with open(file_path, "w") as f:
|
2020-05-21 06:14:03 +01:00
|
|
|
f.write("from core.nodes.base import CoreNode\n")
|
2019-06-24 23:49:12 +01:00
|
|
|
f.write("coreemu = globals()['coreemu']\n")
|
2019-10-24 18:58:26 +01:00
|
|
|
f.write(f"session = coreemu.sessions[{coretlv.session.id}]\n")
|
2020-05-21 06:14:03 +01:00
|
|
|
f.write("session.add_node(CoreNode)\n")
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreRegMessage.create(
|
|
|
|
0, [(RegisterTlvs.EXECUTE_SERVER, file_path)]
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.instantiate()
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-24 23:49:12 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert len(coretlv.session.nodes) == 1
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_all(self, coretlv: CoreHandler):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
MessageFlags.ADD.value,
|
2019-10-24 21:05:02 +01:00
|
|
|
[(ConfigTlvs.OBJECT, "all"), (ConfigTlvs.TYPE, ConfigFlags.RESET.value)],
|
2019-09-10 23:10:24 +01:00
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.location.refxyz = (10, 10, 10)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.location.refxyz == (0, 0, 0)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_options_request(self, coretlv: CoreHandler):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "session"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.REQUEST.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config.assert_called_once()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_options_update(self, coretlv: CoreHandler):
|
2019-06-25 20:29:46 +01:00
|
|
|
test_key = "test"
|
|
|
|
test_value = "test"
|
2019-09-10 23:10:24 +01:00
|
|
|
values = {test_key: test_value}
|
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "session"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.UPDATE.value),
|
|
|
|
(ConfigTlvs.VALUES, dict_to_str(values)),
|
|
|
|
],
|
|
|
|
)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.options.get_config(test_key) == test_value
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_location_reset(self, coretlv: CoreHandler):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "location"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.RESET.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.location.refxyz = (10, 10, 10)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.location.refxyz == (0, 0, 0)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_location_update(self, coretlv: CoreHandler):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "location"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.UPDATE.value),
|
|
|
|
(ConfigTlvs.VALUES, "10|10|70|50|0|0.5"),
|
|
|
|
],
|
|
|
|
)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.location.refxyz == (10, 10, 0.0)
|
|
|
|
assert coretlv.session.location.refgeo == (70, 50, 0)
|
|
|
|
assert coretlv.session.location.refscale == 0.5
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_metadata_request(self, coretlv: CoreHandler):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "metadata"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.REQUEST.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config.assert_called_once()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_metadata_update(self, coretlv: CoreHandler):
|
2019-06-25 20:29:46 +01:00
|
|
|
test_key = "test"
|
|
|
|
test_value = "test"
|
2019-09-10 23:10:24 +01:00
|
|
|
values = {test_key: test_value}
|
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "metadata"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.UPDATE.value),
|
|
|
|
(ConfigTlvs.VALUES, dict_to_str(values)),
|
|
|
|
],
|
|
|
|
)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-30 20:27:12 +00:00
|
|
|
assert coretlv.session.metadata[test_key] == test_value
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_broker_request(self, coretlv: CoreHandler):
|
2019-06-25 20:29:46 +01:00
|
|
|
server = "test"
|
|
|
|
host = "10.0.0.1"
|
|
|
|
port = 50000
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "broker"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.UPDATE.value),
|
2019-10-18 03:25:52 +01:00
|
|
|
(ConfigTlvs.VALUES, f"{server}:{host}:{port}"),
|
2019-09-10 23:10:24 +01:00
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.distributed.add_server = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.distributed.add_server.assert_called_once_with(server, host)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_services_request_all(self, coretlv: CoreHandler):
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "services"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.REQUEST.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config.assert_called_once()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_services_request_specific(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.NODE, node.id),
|
|
|
|
(ConfigTlvs.OBJECT, "services"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.REQUEST.value),
|
|
|
|
(ConfigTlvs.OPAQUE, "service:DefaultRoute"),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config.assert_called_once()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_services_request_specific_file(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.NODE, node.id),
|
|
|
|
(ConfigTlvs.OBJECT, "services"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.REQUEST.value),
|
|
|
|
(ConfigTlvs.OPAQUE, "service:DefaultRoute:defaultroute.sh"),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.broadcast_file = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.broadcast_file.assert_called_once()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_services_reset(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-06-25 20:29:46 +01:00
|
|
|
service = "DefaultRoute"
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.services.set_service(node.id, service)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "services"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.RESET.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.services.get_service(node.id, service) is not None
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.services.get_service(node.id, service) is None
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_services_set(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
node = coretlv.session.add_node(CoreNode)
|
2019-06-25 20:29:46 +01:00
|
|
|
service = "DefaultRoute"
|
2019-09-10 23:10:24 +01:00
|
|
|
values = {"meta": "metadata"}
|
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.NODE, node.id),
|
|
|
|
(ConfigTlvs.OBJECT, "services"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.UPDATE.value),
|
2019-10-18 03:25:52 +01:00
|
|
|
(ConfigTlvs.OPAQUE, f"service:{service}"),
|
2019-09-10 23:10:24 +01:00
|
|
|
(ConfigTlvs.VALUES, dict_to_str(values)),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.services.get_service(node.id, service) is None
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert coretlv.session.services.get_service(node.id, service) is not None
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_mobility_reset(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan = coretlv.session.add_node(WlanNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.OBJECT, "MobilityManager"),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.RESET.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.session.mobility.set_model_config(wlan.id, BasicRangeModel.name, {})
|
|
|
|
assert len(coretlv.session.mobility.node_configurations) == 1
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
assert len(coretlv.session.mobility.node_configurations) == 0
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_mobility_model_request(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan = coretlv.session.add_node(WlanNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.NODE, wlan.id),
|
|
|
|
(ConfigTlvs.OBJECT, BasicRangeModel.name),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.REQUEST.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config.assert_called_once()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_mobility_model_update(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan = coretlv.session.add_node(WlanNode)
|
2019-06-25 20:29:46 +01:00
|
|
|
config_key = "range"
|
|
|
|
config_value = "1000"
|
2019-09-10 23:10:24 +01:00
|
|
|
values = {config_key: config_value}
|
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.NODE, wlan.id),
|
|
|
|
(ConfigTlvs.OBJECT, BasicRangeModel.name),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.UPDATE.value),
|
|
|
|
(ConfigTlvs.VALUES, dict_to_str(values)),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-09-10 23:10:24 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
config = coretlv.session.mobility.get_model_config(
|
|
|
|
wlan.id, BasicRangeModel.name
|
|
|
|
)
|
2019-06-25 20:29:46 +01:00
|
|
|
assert config[config_key] == config_value
|
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_emane_model_request(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan = coretlv.session.add_node(WlanNode)
|
2019-09-10 23:10:24 +01:00
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.NODE, wlan.id),
|
|
|
|
(ConfigTlvs.OBJECT, EmaneIeee80211abgModel.name),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.REQUEST.value),
|
|
|
|
],
|
|
|
|
)
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config = mock.MagicMock()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_broadcast_config.assert_called_once()
|
2019-06-25 20:29:46 +01:00
|
|
|
|
2020-05-25 07:37:38 +01:00
|
|
|
def test_config_emane_model_update(self, coretlv: CoreHandler):
|
2020-05-21 06:14:03 +01:00
|
|
|
wlan = coretlv.session.add_node(WlanNode)
|
2019-06-25 20:29:46 +01:00
|
|
|
config_key = "distance"
|
|
|
|
config_value = "50051"
|
2019-09-10 23:10:24 +01:00
|
|
|
values = {config_key: config_value}
|
|
|
|
message = coreapi.CoreConfMessage.create(
|
|
|
|
0,
|
|
|
|
[
|
|
|
|
(ConfigTlvs.NODE, wlan.id),
|
|
|
|
(ConfigTlvs.OBJECT, EmaneIeee80211abgModel.name),
|
|
|
|
(ConfigTlvs.TYPE, ConfigFlags.UPDATE.value),
|
|
|
|
(ConfigTlvs.VALUES, dict_to_str(values)),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2019-10-24 18:58:26 +01:00
|
|
|
coretlv.handle_message(message)
|
2019-09-10 23:10:24 +01:00
|
|
|
|
2021-05-07 18:40:18 +01:00
|
|
|
config = coretlv.session.emane.get_config(wlan.id, EmaneIeee80211abgModel.name)
|
2019-06-25 20:29:46 +01:00
|
|
|
assert config[config_key] == config_value
|