diff --git a/scripts/run_tests_locally-device-openconfig-ocnos.sh b/scripts/run_tests_locally-device-openconfig-ocnos.sh index 413691b8577dc22ca794f7f6c793471342fcfb4e..60af6768d37199c957d17c6804c8af1072d0b0e1 100755 --- a/scripts/run_tests_locally-device-openconfig-ocnos.sh +++ b/scripts/run_tests_locally-device-openconfig-ocnos.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/device/tests/test_unitary_openconfig_ocnos.py b/src/device/tests/test_unitary_openconfig_ocnos.py index 5e02accdd1ea3985d12a598fb9538255485af2a5..87d951581ad98147f8dd565af616fe034a346693 100644 --- a/src/device/tests/test_unitary_openconfig_ocnos.py +++ b/src/device/tests/test_unitary_openconfig_ocnos.py @@ -143,49 +143,49 @@ def test_configure(drivers : Dict[str, OpenConfigDriver]): #results_getconfig = driver.GetConfig(resources_to_get) #LOGGER.info('results_getconfig = {:s}'.format(str(results_getconfig))) - #csgw1_resources_to_set = [ - # network_instance('ecoc24', 'L3VRF', '192.168.150.1', '65001:1'), - # network_instance_add_protocol_direct('ecoc24', 'L3VRF'), - # network_instance_add_protocol_static('ecoc24', 'L3VRF'), - # network_instance_add_protocol_bgp('ecoc24', 'L3VRF', '192.168.150.1', '65001', neighbors=[ - # ('192.168.150.2', '65001') - # ]), - # network_instance_add_table_connection('ecoc24', 'DIRECTLY_CONNECTED', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), - # network_instance_add_table_connection('ecoc24', 'STATIC', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), - # - # interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500), - # network_instance_interface('ecoc24', 'L3VRF', 'ce1', 0), - # interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.10.1', 24), enabled=True), - # - # interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500), - # network_instance_interface('ecoc24', 'L3VRF', 'xe5', 0), - # interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.150.1', 24), enabled=True), - #] - #LOGGER.info('CSGW1 resources_to_set = {:s}'.format(str(csgw1_resources_to_set))) - #results_setconfig = drivers['CSGW1'].SetConfig(csgw1_resources_to_set) - #LOGGER.info('CSGW1 results_setconfig = {:s}'.format(str(results_setconfig))) - - #csgw2_resources_to_set = [ - # network_instance('ecoc24', 'L3VRF', '192.168.150.2', '65001:1'), - # network_instance_add_protocol_direct('ecoc24', 'L3VRF'), - # network_instance_add_protocol_static('ecoc24', 'L3VRF'), - # network_instance_add_protocol_bgp('ecoc24', 'L3VRF', '192.168.150.2', '65001', neighbors=[ - # ('192.168.150.1', '65001') - # ]), - # network_instance_add_table_connection('ecoc24', 'DIRECTLY_CONNECTED', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), - # network_instance_add_table_connection('ecoc24', 'STATIC', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), - # - # interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500), - # network_instance_interface('ecoc24', 'L3VRF', 'ce1', 0), - # interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.20.1', 24), enabled=True), - # - # interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500), - # network_instance_interface('ecoc24', 'L3VRF', 'xe5', 0), - # interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.150.2', 24), enabled=True), - #] - #LOGGER.info('CSGW2 resources_to_set = {:s}'.format(str(csgw2_resources_to_set))) - #results_setconfig = drivers['CSGW2'].SetConfig(csgw2_resources_to_set) - #LOGGER.info('CSGW2 results_setconfig = {:s}'.format(str(results_setconfig))) + csgw1_resources_to_set = [ + network_instance('ecoc24', 'L3VRF', '192.168.150.1', '65001:1'), + network_instance_add_protocol_direct('ecoc24', 'L3VRF'), + network_instance_add_protocol_static('ecoc24', 'L3VRF'), + network_instance_add_protocol_bgp('ecoc24', 'L3VRF', '192.168.150.1', '65001', neighbors=[ + ('192.168.150.2', '65001') + ]), + network_instance_add_table_connection('ecoc24', 'DIRECTLY_CONNECTED', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), + network_instance_add_table_connection('ecoc24', 'STATIC', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), + + interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500), + network_instance_interface('ecoc24', 'L3VRF', 'ce1', 0), + interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.10.1', 24), enabled=True), + + interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500), + network_instance_interface('ecoc24', 'L3VRF', 'xe5', 0), + interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.150.1', 24), enabled=True), + ] + LOGGER.info('CSGW1 resources_to_set = {:s}'.format(str(csgw1_resources_to_set))) + results_setconfig = drivers['CSGW1'].SetConfig(csgw1_resources_to_set) + LOGGER.info('CSGW1 results_setconfig = {:s}'.format(str(results_setconfig))) + + csgw2_resources_to_set = [ + network_instance('ecoc24', 'L3VRF', '192.168.150.2', '65001:1'), + network_instance_add_protocol_direct('ecoc24', 'L3VRF'), + network_instance_add_protocol_static('ecoc24', 'L3VRF'), + network_instance_add_protocol_bgp('ecoc24', 'L3VRF', '192.168.150.2', '65001', neighbors=[ + ('192.168.150.1', '65001') + ]), + network_instance_add_table_connection('ecoc24', 'DIRECTLY_CONNECTED', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), + network_instance_add_table_connection('ecoc24', 'STATIC', 'BGP', 'IPV4', 'ACCEPT_ROUTE', bgp_as='65001'), + + interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500), + network_instance_interface('ecoc24', 'L3VRF', 'ce1', 0), + interface('ce1', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.20.1', 24), enabled=True), + + interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500), + network_instance_interface('ecoc24', 'L3VRF', 'xe5', 0), + interface('xe5', 0, if_type='ethernetCsmacd', mtu=1500, ipv4_address_prefix=('192.168.150.2', 24), enabled=True), + ] + LOGGER.info('CSGW2 resources_to_set = {:s}'.format(str(csgw2_resources_to_set))) + results_setconfig = drivers['CSGW2'].SetConfig(csgw2_resources_to_set) + LOGGER.info('CSGW2 results_setconfig = {:s}'.format(str(results_setconfig))) csgw1_resources_to_delete = [ network_instance_interface('ecoc24', 'L3VRF', 'ce1', 0), @@ -198,13 +198,13 @@ def test_configure(drivers : Dict[str, OpenConfigDriver]): results_deleteconfig = drivers['CSGW1'].DeleteConfig(csgw1_resources_to_delete) LOGGER.info('CSGW1 results_deleteconfig = {:s}'.format(str(results_deleteconfig))) - #csgw2_resources_to_delete = [ - # network_instance_interface('ecoc24', 'L3VRF', 'ce1', 0), - # network_instance_interface('ecoc24', 'L3VRF', 'xe5', 0), - # #interface('ce1', 0), - # #interface('xe5', 0), - # network_instance('ecoc24', 'L3VRF'), - #] - #LOGGER.info('CSGW2 resources_to_delete = {:s}'.format(str(csgw2_resources_to_delete))) - #results_deleteconfig = drivers['CSGW2'].DeleteConfig(csgw2_resources_to_delete) - #LOGGER.info('CSGW2 results_deleteconfig = {:s}'.format(str(results_deleteconfig))) + csgw2_resources_to_delete = [ + network_instance_interface('ecoc24', 'L3VRF', 'ce1', 0), + network_instance_interface('ecoc24', 'L3VRF', 'xe5', 0), + #interface('ce1', 0), + #interface('xe5', 0), + network_instance('ecoc24', 'L3VRF'), + ] + LOGGER.info('CSGW2 resources_to_delete = {:s}'.format(str(csgw2_resources_to_delete))) + results_deleteconfig = drivers['CSGW2'].DeleteConfig(csgw2_resources_to_delete) + LOGGER.info('CSGW2 results_deleteconfig = {:s}'.format(str(results_deleteconfig))) diff --git a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py index 716d0413abc0ed4897c5825f7471946ea7d28aa3..7527932877f47a092a35f286defb3744e05db109 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py +++ b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py @@ -12,10 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict, List, Tuple +from typing import Any, Dict, List, Optional, Tuple from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set from service.service.service_handler_api.AnyTreeTools import TreeNode +def get_value(field_name : str, *containers, default=None) -> Optional[Any]: + if len(containers) == 0: raise Exception('No containers specified') + for container in containers: + if field_name not in container: continue + return container[field_name] + return default + def setup_config_rules( service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str, service_settings : TreeNode, device_settings : TreeNode, endpoint_settings : TreeNode, endpoint_acls : List [Tuple] @@ -29,9 +36,11 @@ def setup_config_rules( json_device_settings : Dict = device_settings.value json_endpoint_settings : Dict = endpoint_settings.value - mtu = json_settings.get('mtu', 1450 ) # 1512 + settings = (json_settings, json_endpoint_settings, json_device_settings) + + mtu = get_value('mtu', *settings, default=1450) # 1512 #address_families = json_settings.get('address_families', [] ) # ['IPV4'] - bgp_as = json_settings.get('bgp_as', 65000 ) # 65000 + bgp_as = get_value('bgp_as', *settings, default=65000) # 65000 router_id = json_endpoint_settings.get('router_id', '0.0.0.0') # '10.95.0.10' route_distinguisher = json_settings.get('route_distinguisher', '65000:101' ) # '60001:801' @@ -199,21 +208,23 @@ def teardown_config_rules( ) -> List[Dict]: if service_settings is None: return [] - if device_settings is None: return [] + if device_settings is None: return [] if endpoint_settings is None: return [] json_settings : Dict = service_settings.value json_device_settings : Dict = device_settings.value json_endpoint_settings : Dict = endpoint_settings.value + settings = (json_settings, json_endpoint_settings, json_device_settings) + service_short_uuid = service_uuid.split('-')[-1] network_instance_name = '{:s}-NetInst'.format(service_short_uuid) #network_interface_desc = '{:s}-NetIf'.format(service_uuid) #network_subinterface_desc = '{:s}-NetSubIf'.format(service_uuid) - #mtu = json_settings.get('mtu', 1450 ) # 1512 + #mtu = get_value('mtu', *settings, default=1450) # 1512 #address_families = json_settings.get('address_families', [] ) # ['IPV4'] - #bgp_as = json_settings.get('bgp_as', 65000 ) # 65000 + #bgp_as = get_value('bgp_as', *settings, default=65000) # 65000 route_distinguisher = json_settings.get('route_distinguisher', '0:0' ) # '60001:801' #sub_interface_index = json_endpoint_settings.get('sub_interface_index', 0 ) # 1 #router_id = json_endpoint_settings.get('router_id', '0.0.0.0') # '10.95.0.10' diff --git a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py index 1f2593b0d494ab42c9af250c18642a380b68bbcd..5fa1d0b5b6931902b4ac50847c90bf67738032ba 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py +++ b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py @@ -22,12 +22,12 @@ def setup_config_rules( ) -> List[Dict]: if service_settings is None: return [] + if device_settings is None: return [] if endpoint_settings is None: return [] - if device_settings is None: return [] json_settings : Dict = service_settings.value - json_endpoint_settings : Dict = endpoint_settings.value json_device_settings : Dict = device_settings.value + json_endpoint_settings : Dict = endpoint_settings.value mtu = json_settings.get('mtu', 1450 ) # 1512 #address_families = json_settings.get('address_families', [] ) # ['IPV4'] @@ -233,12 +233,12 @@ def teardown_config_rules( ) -> List[Dict]: if service_settings is None: return [] + if device_settings is None: return [] if endpoint_settings is None: return [] - if device_settings is None: return [] json_settings : Dict = service_settings.value - json_endpoint_settings : Dict = endpoint_settings.value json_device_settings : Dict = device_settings.value + json_endpoint_settings : Dict = endpoint_settings.value service_short_uuid = service_uuid.split('-')[-1] # network_instance_name = '{:s}-NetInst'.format(service_short_uuid)