# Add here your files containing confidential testbed details such as IP addresses, ports, usernames, passwords, etc.
Credentials.py
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy, json, sys
from .Objects import CONTEXTS, DEVICES, LINKS, TOPOLOGIES
def main():
with open('tests/ofc22/descriptors_emulated.json', 'w', encoding='UTF-8') as f:
devices = []
for device,connect_rules in DEVICES:
device = copy.deepcopy(device)
device['device_config']['config_rules'].extend(connect_rules)
devices.append(device)
f.write(json.dumps({
'contexts': CONTEXTS,
'topologies': TOPOLOGIES,
'devices': devices,
'links': LINKS
}))
return 0
if __name__ == '__main__':
sys.exit(main())
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json, logging, sys
from common.Settings import get_setting
from context.client.ContextClient import ContextClient
from common.proto.context_pb2 import Context, Device, Link, Topology
from device.client.DeviceClient import DeviceClient
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
def main():
context_client = ContextClient(
get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
device_client = DeviceClient(
get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC'))
with open('tests/ofc22/descriptors.json', 'r', encoding='UTF-8') as f:
descriptors = json.loads(f.read())
for context in descriptors['contexts' ]: context_client.SetContext (Context (**context ))
for topology in descriptors['topologies']: context_client.SetTopology(Topology(**topology))
for device in descriptors['devices' ]: device_client .AddDevice (Device (**device ))
for link in descriptors['links' ]: context_client.SetLink (Link (**link ))
return 0
if __name__ == '__main__':
sys.exit(main())
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from typing import Dict, List, Tuple
from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID
from common.tools.object_factory.Context import json_context, json_context_id
from common.tools.object_factory.Device import (
json_device_connect_rules, json_device_emulated_connect_rules, json_device_emulated_packet_router_disabled,
json_device_connect_rules, json_device_id, json_device_p4_disabled,
json_device_emulated_tapi_disabled, json_device_id, json_device_packetrouter_disabled, json_device_tapi_disabled)
from common.tools.object_factory.Service import (
get_service_uuid, json_service_l3nm_planned,json_service_p4_planned)
from common.tools.object_factory.ConfigRule import (
json_config_rule_set, json_config_rule_delete)
from common.tools.object_factory.EndPoint import json_endpoint, json_endpoint_ids, json_endpoints, json_endpoint_id
from common.tools.object_factory.Link import get_link_uuid, json_link, json_link_id
from common.tools.object_factory.Topology import json_topology, json_topology_id
from common.proto.kpi_sample_types_pb2 import KpiSampleType
# ----- Context --------------------------------------------------------------------------------------------------------
CONTEXT_ID = json_context_id(DEFAULT_CONTEXT_UUID)
CONTEXT = json_context(DEFAULT_CONTEXT_UUID)
# ----- Topology -------------------------------------------------------------------------------------------------------
TOPOLOGY_ID = json_topology_id(DEFAULT_TOPOLOGY_UUID, context_id=CONTEXT_ID)
TOPOLOGY = json_topology(DEFAULT_TOPOLOGY_UUID, context_id=CONTEXT_ID)
# ----- Monitoring Samples ---------------------------------------------------------------------------------------------
PACKET_PORT_SAMPLE_TYPES = [
KpiSampleType.KPISAMPLETYPE_PACKETS_TRANSMITTED,
KpiSampleType.KPISAMPLETYPE_PACKETS_RECEIVED,
KpiSampleType.KPISAMPLETYPE_BYTES_TRANSMITTED,
KpiSampleType.KPISAMPLETYPE_BYTES_RECEIVED,
]
# ----- Device Credentials and Settings --------------------------------------------------------------------------------
# ----- Devices --------------------------------------------------------------------------------------------------------
CUR_PATH = os.path.dirname(os.path.abspath(__file__))
DEVICE_SW1_UUID = 'SW1'
DEVICE_SW1_TIMEOUT = 60
DEVICE_SW1_ID = json_device_id(DEVICE_SW1_UUID)
DEVICE_SW1 = json_device_p4_disabled(DEVICE_SW1_UUID)
DEVICE_SW1_DPID = 1
DEVICE_SW1_NAME = DEVICE_SW1_UUID
DEVICE_SW1_IP_ADDR = '10.0.2.10'
DEVICE_SW1_PORT = '50001'
DEVICE_SW1_VENDOR = 'Open Networking Foundation'
DEVICE_SW1_HW_VER = 'BMv2 simple_switch'
DEVICE_SW1_SW_VER = 'Stratum'
DEVICE_SW1_BIN_PATH = '/root/p4/bmv2.json'
DEVICE_SW1_INFO_PATH = '/root/p4/p4info.txt'
DEVICE_SW1_ENDPOINT_DEFS = [('1', 'port', []), ('2', 'port', []), ('3', 'port', [])]
DEVICE_SW1_ENDPOINTS = json_endpoints(DEVICE_SW1_ID, DEVICE_SW1_ENDPOINT_DEFS)
DEVICE_SW1_ENDPOINT_IDS = json_endpoint_ids(DEVICE_SW1_ID, DEVICE_SW1_ENDPOINT_DEFS)
ENDPOINT_ID_SW1_1 = DEVICE_SW1_ENDPOINTS[0]['endpoint_id']
ENDPOINT_ID_SW1_2 = DEVICE_SW1_ENDPOINTS[1]['endpoint_id']
ENDPOINT_ID_SW1_3 = DEVICE_SW1_ENDPOINTS[2]['endpoint_id']
DEVICE_SW1_CONNECT_RULES = json_device_connect_rules(
DEVICE_SW1_IP_ADDR,
DEVICE_SW1_PORT,
{
'id': DEVICE_SW1_DPID,
'name': DEVICE_SW1_NAME,
'vendor': DEVICE_SW1_VENDOR,
'hw_ver': DEVICE_SW1_HW_VER,
'sw_ver': DEVICE_SW1_SW_VER,
'timeout': DEVICE_SW1_TIMEOUT,
'p4bin': DEVICE_SW1_BIN_PATH,
'p4info': DEVICE_SW1_INFO_PATH
}
)
DEVICE_SW2_UUID = 'SW2'
DEVICE_SW2_TIMEOUT = 60
DEVICE_SW2_ID = json_device_id(DEVICE_SW2_UUID)
DEVICE_SW2 = json_device_p4_disabled(DEVICE_SW2_UUID)
DEVICE_SW2_DPID = 1
DEVICE_SW2_NAME = DEVICE_SW2_UUID
DEVICE_SW2_IP_ADDR = '10.0.2.10'
DEVICE_SW2_PORT = '50002'
DEVICE_SW2_VENDOR = 'Open Networking Foundation'
DEVICE_SW2_HW_VER = 'BMv2 simple_switch'
DEVICE_SW2_SW_VER = 'Stratum'
DEVICE_SW2_BIN_PATH = '/root/p4/bmv2.json'
DEVICE_SW2_INFO_PATH = '/root/p4/p4info.txt'
DEVICE_SW2_ENDPOINT_DEFS = [('1', 'port', []), ('2', 'port', [])]
DEVICE_SW2_ENDPOINTS = json_endpoints(DEVICE_SW2_ID, DEVICE_SW2_ENDPOINT_DEFS)
DEVICE_SW2_ENDPOINT_IDS = json_endpoint_ids(DEVICE_SW2_ID, DEVICE_SW2_ENDPOINT_DEFS)
ENDPOINT_ID_SW2_1 = DEVICE_SW2_ENDPOINTS[0]['endpoint_id']
ENDPOINT_ID_SW2_2 = DEVICE_SW2_ENDPOINTS[1]['endpoint_id']
DEVICE_SW2_CONNECT_RULES = json_device_connect_rules(
DEVICE_SW2_IP_ADDR,
DEVICE_SW2_PORT,
{
'id': DEVICE_SW2_DPID,
'name': DEVICE_SW2_NAME,
'vendor': DEVICE_SW2_VENDOR,
'hw_ver': DEVICE_SW2_HW_VER,
'sw_ver': DEVICE_SW2_SW_VER,
'timeout': DEVICE_SW2_TIMEOUT,
'p4bin': DEVICE_SW2_BIN_PATH,
'p4info': DEVICE_SW2_INFO_PATH
}
)
DEVICE_SW3_UUID = 'SW3'
DEVICE_SW3_TIMEOUT = 60
DEVICE_SW3_ID = json_device_id(DEVICE_SW3_UUID)
DEVICE_SW3 = json_device_p4_disabled(DEVICE_SW3_UUID)
DEVICE_SW3_DPID = 1
DEVICE_SW3_NAME = DEVICE_SW3_UUID
DEVICE_SW3_IP_ADDR = '10.0.2.10'
DEVICE_SW3_PORT = '50003'
DEVICE_SW3_VENDOR = 'Open Networking Foundation'
DEVICE_SW3_HW_VER = 'BMv2 simple_switch'
DEVICE_SW3_SW_VER = 'Stratum'
DEVICE_SW3_BIN_PATH = '/root/p4/bmv2.json'
DEVICE_SW3_INFO_PATH = '/root/p4/p4info.txt'
DEVICE_SW3_ENDPOINT_DEFS = [('1', 'port', []), ('2', 'port', [])]
DEVICE_SW3_ENDPOINTS = json_endpoints(DEVICE_SW3_ID, DEVICE_SW3_ENDPOINT_DEFS)
DEVICE_SW3_ENDPOINT_IDS = json_endpoint_ids(DEVICE_SW3_ID, DEVICE_SW3_ENDPOINT_DEFS)
ENDPOINT_ID_SW3_1 = DEVICE_SW3_ENDPOINTS[0]['endpoint_id']
ENDPOINT_ID_SW3_2 = DEVICE_SW3_ENDPOINTS[1]['endpoint_id']
DEVICE_SW3_CONNECT_RULES = json_device_connect_rules(
DEVICE_SW3_IP_ADDR,
DEVICE_SW3_PORT,
{
'id': DEVICE_SW3_DPID,
'name': DEVICE_SW3_NAME,
'vendor': DEVICE_SW3_VENDOR,
'hw_ver': DEVICE_SW3_HW_VER,
'sw_ver': DEVICE_SW3_SW_VER,
'timeout': DEVICE_SW3_TIMEOUT,
'p4bin': DEVICE_SW3_BIN_PATH,
'p4info': DEVICE_SW3_INFO_PATH
}
)
DEVICE_SW4_UUID = 'SW4'
DEVICE_SW4_TIMEOUT = 60
DEVICE_SW4_ID = json_device_id(DEVICE_SW4_UUID)
DEVICE_SW4 = json_device_p4_disabled(DEVICE_SW4_UUID)
DEVICE_SW4_DPID = 1
DEVICE_SW4_NAME = DEVICE_SW4_UUID
DEVICE_SW4_IP_ADDR = '10.0.2.10'
DEVICE_SW4_PORT = '50004'
DEVICE_SW4_VENDOR = 'Open Networking Foundation'
DEVICE_SW4_HW_VER = 'BMv2 simple_switch'
DEVICE_SW4_SW_VER = 'Stratum'
DEVICE_SW4_BIN_PATH = '/root/p4/bmv2.json'
DEVICE_SW4_INFO_PATH = '/root/p4/p4info.txt'
DEVICE_SW4_ENDPOINT_DEFS = [('1', 'port', []), ('2', 'port', [])]
DEVICE_SW4_ENDPOINTS = json_endpoints(DEVICE_SW4_ID, DEVICE_SW4_ENDPOINT_DEFS)
DEVICE_SW4_ENDPOINT_IDS = json_endpoint_ids(DEVICE_SW4_ID, DEVICE_SW4_ENDPOINT_DEFS)
ENDPOINT_ID_SW4_1 = DEVICE_SW4_ENDPOINTS[0]['endpoint_id']
ENDPOINT_ID_SW4_2 = DEVICE_SW4_ENDPOINTS[1]['endpoint_id']
DEVICE_SW4_CONNECT_RULES = json_device_connect_rules(
DEVICE_SW4_IP_ADDR,
DEVICE_SW4_PORT,
{
'id': DEVICE_SW4_DPID,
'name': DEVICE_SW4_NAME,
'vendor': DEVICE_SW4_VENDOR,
'hw_ver': DEVICE_SW4_HW_VER,
'sw_ver': DEVICE_SW4_SW_VER,
'timeout': DEVICE_SW4_TIMEOUT,
'p4bin': DEVICE_SW4_BIN_PATH,
'p4info': DEVICE_SW4_INFO_PATH
}
)
DEVICE_SW5_UUID = 'SW5'
DEVICE_SW5_TIMEOUT = 60
DEVICE_SW5_ID = json_device_id(DEVICE_SW5_UUID)
DEVICE_SW5 = json_device_p4_disabled(DEVICE_SW5_UUID)
DEVICE_SW5_DPID = 1
DEVICE_SW5_NAME = DEVICE_SW5_UUID
DEVICE_SW5_IP_ADDR = '10.0.2.10'
DEVICE_SW5_PORT = '50005'
DEVICE_SW5_VENDOR = 'Open Networking Foundation'
DEVICE_SW5_HW_VER = 'BMv2 simple_switch'
DEVICE_SW5_SW_VER = 'Stratum'
DEVICE_SW5_BIN_PATH = '/root/p4/bmv2.json'
DEVICE_SW5_INFO_PATH = '/root/p4/p4info.txt'
DEVICE_SW5_ENDPOINT_DEFS = [('1', 'port', []), ('2', 'port', [])]
DEVICE_SW5_ENDPOINTS = json_endpoints(DEVICE_SW5_ID, DEVICE_SW5_ENDPOINT_DEFS)
DEVICE_SW5_ENDPOINT_IDS = json_endpoint_ids(DEVICE_SW5_ID, DEVICE_SW5_ENDPOINT_DEFS)
ENDPOINT_ID_SW5_1 = DEVICE_SW5_ENDPOINTS[0]['endpoint_id']
ENDPOINT_ID_SW5_2 = DEVICE_SW5_ENDPOINTS[1]['endpoint_id']
DEVICE_SW5_CONNECT_RULES = json_device_connect_rules(
DEVICE_SW5_IP_ADDR,
DEVICE_SW5_PORT,
{
'id': DEVICE_SW5_DPID,
'name': DEVICE_SW5_NAME,
'vendor': DEVICE_SW5_VENDOR,
'hw_ver': DEVICE_SW5_HW_VER,
'sw_ver': DEVICE_SW5_SW_VER,
'timeout': DEVICE_SW5_TIMEOUT,
'p4bin': DEVICE_SW5_BIN_PATH,
'p4info': DEVICE_SW5_INFO_PATH
}
)
DEVICE_SW6_UUID = 'SW6'
DEVICE_SW6_TIMEOUT = 60
DEVICE_SW6_ID = json_device_id(DEVICE_SW6_UUID)
DEVICE_SW6 = json_device_p4_disabled(DEVICE_SW6_UUID)
DEVICE_SW6_DPID = 1
DEVICE_SW6_NAME = DEVICE_SW6_UUID
DEVICE_SW6_IP_ADDR = '10.0.2.10'
DEVICE_SW6_PORT = '50006'
DEVICE_SW6_VENDOR = 'Open Networking Foundation'
DEVICE_SW6_HW_VER = 'BMv2 simple_switch'
DEVICE_SW6_SW_VER = 'Stratum'
DEVICE_SW6_BIN_PATH = '/root/p4/bmv2.json'
DEVICE_SW6_INFO_PATH = '/root/p4/p4info.txt'
DEVICE_SW6_ENDPOINT_DEFS = [('1', 'port', []), ('2', 'port', []), ('3', 'port', [])]
DEVICE_SW6_ENDPOINTS = json_endpoints(DEVICE_SW6_ID, DEVICE_SW6_ENDPOINT_DEFS)
DEVICE_SW6_ENDPOINT_IDS = json_endpoint_ids(DEVICE_SW6_ID, DEVICE_SW6_ENDPOINT_DEFS)
ENDPOINT_ID_SW6_1 = DEVICE_SW6_ENDPOINTS[0]['endpoint_id']
ENDPOINT_ID_SW6_2 = DEVICE_SW6_ENDPOINTS[1]['endpoint_id']
ENDPOINT_ID_SW6_3 = DEVICE_SW6_ENDPOINTS[2]['endpoint_id']
DEVICE_SW6_CONNECT_RULES = json_device_connect_rules(
DEVICE_SW6_IP_ADDR,
DEVICE_SW6_PORT,
{
'id': DEVICE_SW6_DPID,
'name': DEVICE_SW6_NAME,
'vendor': DEVICE_SW6_VENDOR,
'hw_ver': DEVICE_SW6_HW_VER,
'sw_ver': DEVICE_SW6_SW_VER,
'timeout': DEVICE_SW6_TIMEOUT,
'p4bin': DEVICE_SW6_BIN_PATH,
'p4info': DEVICE_SW6_INFO_PATH
}
)
# ----- Links ----------------------------------------------------------------------------------------------------------
LINK_SW1_SW2_UUID = get_link_uuid(ENDPOINT_ID_SW1_1, ENDPOINT_ID_SW2_1)
LINK_SW1_SW2_ID = json_link_id(LINK_SW1_SW2_UUID)
LINK_SW1_SW2 = json_link(LINK_SW1_SW2_UUID, [ENDPOINT_ID_SW1_1, ENDPOINT_ID_SW2_1])
LINK_SW1_SW3_UUID = get_link_uuid(ENDPOINT_ID_SW1_2, ENDPOINT_ID_SW3_1)
LINK_SW1_SW3_ID = json_link_id(LINK_SW1_SW3_UUID)
LINK_SW1_SW3 = json_link(LINK_SW1_SW3_UUID, [ENDPOINT_ID_SW1_2, ENDPOINT_ID_SW3_1])
LINK_SW2_SW4_UUID = get_link_uuid(ENDPOINT_ID_SW2_2, ENDPOINT_ID_SW4_1)
LINK_SW2_SW4_ID = json_link_id(LINK_SW2_SW4_UUID)
LINK_SW2_SW4 = json_link(LINK_SW2_SW4_UUID, [ENDPOINT_ID_SW2_2, ENDPOINT_ID_SW4_1])
LINK_SW3_SW5_UUID = get_link_uuid(ENDPOINT_ID_SW3_2, ENDPOINT_ID_SW5_1)
LINK_SW3_SW5_ID = json_link_id(LINK_SW3_SW5_UUID)
LINK_SW3_SW5 = json_link(LINK_SW3_SW5_UUID, [ENDPOINT_ID_SW3_2, ENDPOINT_ID_SW5_1])
LINK_SW4_SW6_UUID = get_link_uuid(ENDPOINT_ID_SW4_2, ENDPOINT_ID_SW6_1)
LINK_SW4_SW6_ID = json_link_id(LINK_SW4_SW6_UUID)
LINK_SW4_SW6 = json_link(LINK_SW4_SW6_UUID, [ENDPOINT_ID_SW4_2, ENDPOINT_ID_SW6_1])
LINK_SW5_SW6_UUID = get_link_uuid(ENDPOINT_ID_SW5_2, ENDPOINT_ID_SW6_2)
LINK_SW5_SW6_ID = json_link_id(LINK_SW5_SW6_UUID)
LINK_SW5_SW6 = json_link(LINK_SW5_SW6_UUID, [ENDPOINT_ID_SW5_2, ENDPOINT_ID_SW6_2])
# ----- Service ----------------------------------------------------------------------------------------------------------
#SERVICE_SW1_UUID = get_service_uuid(ENDPOINT_ID_SW1_1, ENDPOINT_ID_SW1_2)
#SERVICE_SW1 = json_service_p4_planned(SERVICE_SW1_UUID)
#SERVICE_SW2_UUID = get_service_uuid(ENDPOINT_ID_SW2_1, ENDPOINT_ID_SW2_2)
#SERVICE_SW2 = json_service_p4_planned(SERVICE_SW2_UUID)
SERVICE_SW1_SW6_UUID = get_service_uuid(ENDPOINT_ID_SW1_3, ENDPOINT_ID_SW6_3)
SERVICE_SW1_SW6 = json_service_p4_planned(SERVICE_SW1_SW6_UUID)
SERVICE_SW1_SW6_ENDPOINT_IDS = [DEVICE_SW1_ENDPOINT_IDS[2], DEVICE_SW6_ENDPOINT_IDS[2]]
# ----- Object Collections ---------------------------------------------------------------------------------------------
CONTEXTS = [CONTEXT]
TOPOLOGIES = [TOPOLOGY]
DEVICES = [
(DEVICE_SW1, DEVICE_SW1_CONNECT_RULES, DEVICE_SW1_ENDPOINTS),
(DEVICE_SW2, DEVICE_SW2_CONNECT_RULES, DEVICE_SW2_ENDPOINTS),
(DEVICE_SW3, DEVICE_SW3_CONNECT_RULES, DEVICE_SW3_ENDPOINTS),
(DEVICE_SW4, DEVICE_SW4_CONNECT_RULES, DEVICE_SW4_ENDPOINTS),
(DEVICE_SW5, DEVICE_SW5_CONNECT_RULES, DEVICE_SW5_ENDPOINTS),
(DEVICE_SW6, DEVICE_SW6_CONNECT_RULES, DEVICE_SW6_ENDPOINTS),
]
LINKS = [
LINK_SW1_SW2,
LINK_SW1_SW3,
LINK_SW2_SW4,
LINK_SW3_SW5,
LINK_SW4_SW6,
LINK_SW5_SW6
]
#SERVICES = [(SERVICE_SW1, DEVICE_SW1_ENDPOINT_IDS), (SERVICE_SW2, DEVICE_SW2_ENDPOINT_IDS)]
#SERVICE_SW1_SW2_ENDPOINT_IDS = DEVICE_SW1_ENDPOINT_IDS + DEVICE_SW2_ENDPOINT_IDS
SERVICES = [(SERVICE_SW1_SW6, SERVICE_SW1_SW6_ENDPOINT_IDS)]
\ No newline at end of file
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy, logging, pytest
from common.Settings import get_setting
from common.tests.EventTools import EVENT_CREATE, EVENT_UPDATE, check_events
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.Link import json_link_id
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
from context.client.EventsCollector import EventsCollector
from common.proto.context_pb2 import ConfigActionEnum, Context, ContextId, Device, Empty, Link, Topology, DeviceOperationalStatusEnum
from device.client.DeviceClient import DeviceClient
from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
@pytest.fixture(scope='session')
def context_client():
_client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
@pytest.fixture(scope='session')
def device_client():
_client = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
def test_prepare_scenario(context_client : ContextClient): # pylint: disable=redefined-outer-name
# ----- Create Contexts and Topologies -----------------------------------------------------------------------------
for context in CONTEXTS:
context_uuid = context['context_id']['context_uuid']['uuid']
LOGGER.info('Adding Context {:s}'.format(context_uuid))
response = context_client.SetContext(Context(**context))
assert response.context_uuid.uuid == context_uuid
for topology in TOPOLOGIES:
context_uuid = topology['topology_id']['context_id']['context_uuid']['uuid']
topology_uuid = topology['topology_id']['topology_uuid']['uuid']
LOGGER.info('Adding Topology {:s}/{:s}'.format(context_uuid, topology_uuid))
response = context_client.SetTopology(Topology(**topology))
assert response.context_id.context_uuid.uuid == context_uuid
assert response.topology_uuid.uuid == topology_uuid
context_id = json_context_id(context_uuid)
def test_scenario_ready(context_client : ContextClient): # pylint: disable=redefined-outer-name
# ----- List entities - Ensure scenario is ready -------------------------------------------------------------------
response = context_client.ListContexts(Empty())
assert len(response.contexts) == len(CONTEXTS)
response = context_client.ListTopologies(ContextId(**CONTEXT_ID))
assert len(response.topologies) == len(TOPOLOGIES)
response = context_client.ListDevices(Empty())
assert len(response.devices) == 0
def test_devices_bootstraping(
context_client : ContextClient, device_client : DeviceClient): # pylint: disable=redefined-outer-name
# ----- Create Devices ---------------------------------------------------------------
for device, connect_rules, endpoints, in DEVICES:
device_uuid = device['device_id']['device_uuid']['uuid']
LOGGER.info('Adding Device {:s}'.format(device_uuid))
device_p4_with_connect_rules = copy.deepcopy(device)
device_p4_with_connect_rules['device_config']['config_rules'].extend(connect_rules)
response = device_client.AddDevice(Device(**device_p4_with_connect_rules))
assert response.device_uuid.uuid == device_uuid
device_p4_with_endpoints = copy.deepcopy(device)
device_p4_with_endpoints['device_endpoints'].extend(endpoints)
device_client.ConfigureDevice(Device(**device_p4_with_endpoints))
for link in LINKS:
link_uuid = link['link_id']['link_uuid']['uuid']
LOGGER.info('Adding Link {:s}'.format(link_uuid))
response = context_client.SetLink(Link(**link))
assert response.link_uuid.uuid == link_uuid
context_client.SetLink(Link(**link))
def test_devices_bootstrapped(context_client : ContextClient): # pylint: disable=redefined-outer-name
# ----- List entities - Ensure bevices are created -----------------------------------------------------------------
response = context_client.ListContexts(Empty())
assert len(response.contexts) == len(CONTEXTS)
response = context_client.ListTopologies(ContextId(**CONTEXT_ID))
assert len(response.topologies) == len(TOPOLOGIES)
response = context_client.ListDevices(Empty())
assert len(response.devices) == len(DEVICES)
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy, logging, pytest
from common.Settings import get_setting
from common.tests.EventTools import EVENT_REMOVE, check_events
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.Link import json_link_id
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
from context.client.EventsCollector import EventsCollector
from common.proto.context_pb2 import ConfigActionEnum, ContextId, Device, DeviceId, Empty, Link, LinkId, TopologyId, DeviceOperationalStatusEnum
from device.client.DeviceClient import DeviceClient
from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
@pytest.fixture(scope='session')
def context_client():
_client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
@pytest.fixture(scope='session')
def device_client():
_client = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
def test_scenario_cleanup(
context_client : ContextClient, device_client : DeviceClient): # pylint: disable=redefined-outer-name
for link in LINKS:
link_uuid = link['link_id']['link_uuid']['uuid']
LOGGER.info('Removing Link {:s}'.format(link_uuid))
link_id = link['link_id']
context_client.RemoveLink(LinkId(**link_id))
# ----- Delete Devices and Validate Collected Events ---------------------------------------------------------------
for device, _, _ in DEVICES:
device_id = device['device_id']
device_uuid = device_id['device_uuid']['uuid']
LOGGER.info('Deleting Device {:s}'.format(device_uuid))
device_client.DeleteDevice(DeviceId(**device_id))
#expected_events.append(('DeviceEvent', EVENT_REMOVE, json_device_id(device_uuid)))
response = context_client.ListDevices(Empty())
assert len(response.devices) == 0
# ----- Delete Topologies and Validate Collected Events ------------------------------------------------------------
for topology in TOPOLOGIES:
topology_id = topology['topology_id']
context_uuid = topology_id['context_id']['context_uuid']['uuid']
topology_uuid = topology_id['topology_uuid']['uuid']
LOGGER.info('Deleting Topology {:s}/{:s}'.format(context_uuid, topology_uuid))
context_client.RemoveTopology(TopologyId(**topology_id))
context_id = json_context_id(context_uuid)
#expected_events.append(('TopologyEvent', EVENT_REMOVE, json_topology_id(topology_uuid, context_id=context_id)))
# ----- Delete Contexts and Validate Collected Events --------------------------------------------------------------
for context in CONTEXTS:
context_id = context['context_id']
context_uuid = context_id['context_uuid']['uuid']
LOGGER.info('Deleting Context {:s}'.format(context_uuid))
context_client.RemoveContext(ContextId(**context_id))
#expected_events.append(('ContextEvent', EVENT_REMOVE, json_context_id(context_uuid)))
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy, logging, pytest
from common.Settings import get_setting
from common.tests.EventTools import EVENT_CREATE, EVENT_UPDATE, check_events
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.Service import json_service_id
from common.tools.object_factory.Link import json_link_id
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
from context.client.EventsCollector import EventsCollector
from common.proto.context_pb2 import Context, ContextId, Device, Empty, Link, Topology, Service, ServiceId
from device.client.DeviceClient import DeviceClient
from service.client.ServiceClient import ServiceClient
from tests.p4.tests.Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES, SERVICES
from common.proto.context_pb2 import ConfigActionEnum, Device, DeviceId,\
DeviceOperationalStatusEnum
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
@pytest.fixture(scope='session')
def context_client():
_client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
@pytest.fixture(scope='session')
def device_client():
_client = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
@pytest.fixture(scope='session')
def service_client():
_client = ServiceClient(get_setting('SERVICESERVICE_SERVICE_HOST'), get_setting('SERVICESERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
def test_rules_entry(
context_client : ContextClient, device_client : DeviceClient, service_client : ServiceClient): # pylint: disable=redefined-outer-name
for device, _, __ in DEVICES:
# Enable device
device_p4_with_operational_status = copy.deepcopy(device)
device_p4_with_operational_status['device_operational_status'] = \
DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
device_client.ConfigureDevice(Device(**device_p4_with_operational_status))
# ----- Create Services ---------------------------------------------------------------
for service, endpoints in SERVICES:
# Insert Service (table entries)
service_uuid = service['service_id']['service_uuid']['uuid']
print('Creating Service {:s}'.format(service_uuid))
service_p4 = copy.deepcopy(service)
service_client.CreateService(Service(**service_p4))
service_p4['service_endpoint_ids'].extend(endpoints)
service_client.UpdateService(Service(**service_p4))
"""
con_cl = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
dev_cl = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC'))
srv_cl = ServiceClient(get_setting('SERVICESERVICE_SERVICE_HOST'), get_setting('SERVICESERVICE_SERVICE_PORT_GRPC'))
for service, endpoints in SERVICES:
service_uuid = service['service_id']['service_uuid']['uuid']
print('Creating Service {:s}'.format(service_uuid))
service_p4 = copy.deepcopy(service)
srv_cl.CreateService(Service(**service_p4))
#service_data = con_cl.GetService(ServiceId(**json_service_id('svc1')))
#print('service_data = {:s}'.format(grpc_message_to_json_string(service_data)))
service_p4 = copy.deepcopy(service)
service_p4['service_endpoint_ids'].extend(endpoints)
srv_cl.UpdateService(Service(**service_p4))
"""
\ No newline at end of file
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy, logging, pytest
from common.Settings import get_setting
from common.tests.EventTools import EVENT_REMOVE, check_events
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.Service import json_service_id
from common.tools.object_factory.Link import json_link_id
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
from context.client.EventsCollector import EventsCollector
from common.proto.context_pb2 import ConfigActionEnum, ContextId, Device, DeviceId, Empty, LinkId, TopologyId, Service, ServiceId, DeviceOperationalStatusEnum
from device.client.DeviceClient import DeviceClient
from service.client.ServiceClient import ServiceClient
from .Objects import CONTEXT_ID, CONTEXTS, DEVICES, LINKS, TOPOLOGIES, SERVICES
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
@pytest.fixture(scope='session')
def context_client():
_client = ContextClient(get_setting('CONTEXTSERVICE_SERVICE_HOST'), get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
@pytest.fixture(scope='session')
def device_client():
_client = DeviceClient(get_setting('DEVICESERVICE_SERVICE_HOST'), get_setting('DEVICESERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
@pytest.fixture(scope='session')
def service_client():
_client = ServiceClient(get_setting('SERVICESERVICE_SERVICE_HOST'), get_setting('SERVICESERVICE_SERVICE_PORT_GRPC'))
yield _client
_client.close()
def test_rules_delete(
context_client : ContextClient, device_client : DeviceClient, service_client : ServiceClient): # pylint: disable=redefined-outer-name
# ----- Create Services ---------------------------------------------------------------
for service, endpoints in SERVICES:
# Delete Service (table entries)
service_uuid = service['service_id']['service_uuid']['uuid']
print('Deleting Service {:s}'.format(service_uuid))
service_p4 = copy.deepcopy(service)
response = service_client.DeleteService(ServiceId(**json_service_id(service_uuid, CONTEXT_ID)))
# ----- Disable Devices ---------------------------------------------------------------
for device, _, _ in DEVICES:
device_p4_with_operational_status = copy.deepcopy(device)
device_p4_with_operational_status['device_operational_status'] = \
DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED
device_client.ConfigureDevice(Device(**device_p4_with_operational_status))