Loading src/device/service/drivers/p4/p4_driver.py +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ class P4Driver(_Driver): transport port number of the P4Runtime server running on the P4 device **settings : map id : int P4 device ID (Mandatory) P4 device datapath ID (Mandatory) name : str P4 device name (Optional) vendor : str Loading src/device/tests/device_p4.py +16 −14 Original line number Diff line number Diff line Loading @@ -17,9 +17,10 @@ P4 device example configuration. """ from common.tools.object_factory.ConfigRule import json_config_rule_set from common.tools.object_factory.Device import json_device_p4_disabled from common.tools.object_factory.Device import ( json_device_connect_rules, json_device_id, json_device_p4_disabled) DEVICE_P4_ID = 0 DEVICE_P4_DPID = 0 DEVICE_P4_NAME = 'device:leaf1' DEVICE_P4_ADDRESS = '127.0.0.1' DEVICE_P4_PORT = '50101' Loading @@ -29,21 +30,22 @@ DEVICE_P4_SW_VER = 'Stratum' DEVICE_P4_PIPECONF = 'org.onosproject.pipelines.fabric' DEVICE_P4_WORKERS = 2 DEVICE_P4_GRACE_PERIOD = 60 DEVICE_P4_TIMEOUT = 60 DEVICE_P4_UUID = {'device_uuid': {'uuid': DEVICE_P4_NAME}} DEVICE_P4_UUID = DEVICE_P4_NAME DEVICE_P4_ID = json_device_id(DEVICE_P4_UUID) DEVICE_P4 = json_device_p4_disabled(DEVICE_P4_UUID) DEVICE_P4_CONNECT_RULES = [ json_config_rule_set('_connect/address', DEVICE_P4_ADDRESS), json_config_rule_set('_connect/port', DEVICE_P4_PORT), json_config_rule_set('_connect/settings', { 'id' : int(DEVICE_P4_ID), DEVICE_P4_CONNECT_RULES = json_device_connect_rules( DEVICE_P4_ADDRESS, DEVICE_P4_PORT, { 'id': DEVICE_P4_DPID, 'name': DEVICE_P4_NAME, 'hw-ver': DEVICE_P4_HW_VER, 'sw-ver': DEVICE_P4_SW_VER, 'pipeconf': DEVICE_P4_PIPECONF }), ] 'pipeconf': DEVICE_P4_PIPECONF, 'timeout': DEVICE_P4_TIMEOUT } ) DEVICE_P4_CONFIG_RULES = [ json_config_rule_set('key1', 'value1'), Loading src/device/tests/test_unit_p4.py +2 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ import pytest from device.service.drivers.p4.p4_driver import P4Driver from .device_p4 import( DEVICE_P4_ADDRESS, DEVICE_P4_PORT, DEVICE_P4_ID, DEVICE_P4_NAME, DEVICE_P4_ADDRESS, DEVICE_P4_PORT, DEVICE_P4_DPID, DEVICE_P4_NAME, DEVICE_P4_VENDOR, DEVICE_P4_HW_VER, DEVICE_P4_SW_VER, DEVICE_P4_PIPECONF, DEVICE_P4_WORKERS, DEVICE_P4_GRACE_PERIOD) from .mock_p4runtime_service import MockP4RuntimeService Loading @@ -37,7 +37,7 @@ def device_driverapi_p4(): _driver = P4Driver( address=DEVICE_P4_ADDRESS, port=DEVICE_P4_PORT, id=DEVICE_P4_ID, id=DEVICE_P4_DPID, name=DEVICE_P4_NAME, vendor=DEVICE_P4_VENDOR, hw_ver=DEVICE_P4_HW_VER, Loading src/device/tests/test_unitary.py +20 −9 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ except ImportError: #ENABLE_EMULATED = False # set to False to disable tests of Emulated devices #ENABLE_OPENCONFIG = False # set to False to disable tests of OpenConfig devices #ENABLE_TAPI = False # set to False to disable tests of TAPI devices ENABLE_P4 = False # set to False to disable tests of P4 devices (P4 device not available in GitLab) #ENABLE_P4 = False # set to False to disable tests of P4 devices ENABLE_OPENCONFIG_CONFIGURE = True ENABLE_OPENCONFIG_MONITOR = True Loading Loading @@ -917,7 +917,8 @@ def test_device_p4_add_error_cases( device_client: DeviceClient, # pylint: disable=redefined-outer-name device_service: DeviceService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') with pytest.raises(grpc.RpcError) as e: device_p4_with_extra_rules = copy.deepcopy(DEVICE_P4) Loading @@ -940,13 +941,14 @@ def test_device_p4_add_correct( device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') device_p4_with_connect_rules = copy.deepcopy(DEVICE_P4) device_p4_with_connect_rules['device_config']['config_rules'].extend( DEVICE_P4_CONNECT_RULES) device_client.AddDevice(Device(**device_p4_with_connect_rules)) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_NAME) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_UUID) assert driver is not None Loading @@ -956,13 +958,14 @@ def test_device_p4_get( device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') initial_config = device_client.GetInitialConfig(DeviceId(**DEVICE_P4_UUID)) initial_config = device_client.GetInitialConfig(DeviceId(**DEVICE_P4_ID)) LOGGER.info('initial_config = {:s}'.format( grpc_message_to_json_string(initial_config))) device_data = context_client.GetDevice(DeviceId(**DEVICE_P4_UUID)) device_data = context_client.GetDevice(DeviceId(**DEVICE_P4_ID)) LOGGER.info('device_data = {:s}'.format( grpc_message_to_json_string(device_data))) Loading @@ -972,6 +975,10 @@ def test_device_p4_configure( device_client: DeviceClient, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') pytest.skip('Skipping test for unimplemented method') Loading @@ -980,6 +987,10 @@ def test_device_p4_deconfigure( device_client: DeviceClient, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') pytest.skip('Skipping test for unimplemented method') Loading @@ -991,6 +1002,6 @@ def test_device_p4_delete( if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') device_client.DeleteDevice(DeviceId(**DEVICE_P4_UUID)) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_NAME) device_client.DeleteDevice(DeviceId(**DEVICE_P4_ID)) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_UUID) assert driver is None Loading
src/device/service/drivers/p4/p4_driver.py +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ class P4Driver(_Driver): transport port number of the P4Runtime server running on the P4 device **settings : map id : int P4 device ID (Mandatory) P4 device datapath ID (Mandatory) name : str P4 device name (Optional) vendor : str Loading
src/device/tests/device_p4.py +16 −14 Original line number Diff line number Diff line Loading @@ -17,9 +17,10 @@ P4 device example configuration. """ from common.tools.object_factory.ConfigRule import json_config_rule_set from common.tools.object_factory.Device import json_device_p4_disabled from common.tools.object_factory.Device import ( json_device_connect_rules, json_device_id, json_device_p4_disabled) DEVICE_P4_ID = 0 DEVICE_P4_DPID = 0 DEVICE_P4_NAME = 'device:leaf1' DEVICE_P4_ADDRESS = '127.0.0.1' DEVICE_P4_PORT = '50101' Loading @@ -29,21 +30,22 @@ DEVICE_P4_SW_VER = 'Stratum' DEVICE_P4_PIPECONF = 'org.onosproject.pipelines.fabric' DEVICE_P4_WORKERS = 2 DEVICE_P4_GRACE_PERIOD = 60 DEVICE_P4_TIMEOUT = 60 DEVICE_P4_UUID = {'device_uuid': {'uuid': DEVICE_P4_NAME}} DEVICE_P4_UUID = DEVICE_P4_NAME DEVICE_P4_ID = json_device_id(DEVICE_P4_UUID) DEVICE_P4 = json_device_p4_disabled(DEVICE_P4_UUID) DEVICE_P4_CONNECT_RULES = [ json_config_rule_set('_connect/address', DEVICE_P4_ADDRESS), json_config_rule_set('_connect/port', DEVICE_P4_PORT), json_config_rule_set('_connect/settings', { 'id' : int(DEVICE_P4_ID), DEVICE_P4_CONNECT_RULES = json_device_connect_rules( DEVICE_P4_ADDRESS, DEVICE_P4_PORT, { 'id': DEVICE_P4_DPID, 'name': DEVICE_P4_NAME, 'hw-ver': DEVICE_P4_HW_VER, 'sw-ver': DEVICE_P4_SW_VER, 'pipeconf': DEVICE_P4_PIPECONF }), ] 'pipeconf': DEVICE_P4_PIPECONF, 'timeout': DEVICE_P4_TIMEOUT } ) DEVICE_P4_CONFIG_RULES = [ json_config_rule_set('key1', 'value1'), Loading
src/device/tests/test_unit_p4.py +2 −2 Original line number Diff line number Diff line Loading @@ -15,7 +15,7 @@ import pytest from device.service.drivers.p4.p4_driver import P4Driver from .device_p4 import( DEVICE_P4_ADDRESS, DEVICE_P4_PORT, DEVICE_P4_ID, DEVICE_P4_NAME, DEVICE_P4_ADDRESS, DEVICE_P4_PORT, DEVICE_P4_DPID, DEVICE_P4_NAME, DEVICE_P4_VENDOR, DEVICE_P4_HW_VER, DEVICE_P4_SW_VER, DEVICE_P4_PIPECONF, DEVICE_P4_WORKERS, DEVICE_P4_GRACE_PERIOD) from .mock_p4runtime_service import MockP4RuntimeService Loading @@ -37,7 +37,7 @@ def device_driverapi_p4(): _driver = P4Driver( address=DEVICE_P4_ADDRESS, port=DEVICE_P4_PORT, id=DEVICE_P4_ID, id=DEVICE_P4_DPID, name=DEVICE_P4_NAME, vendor=DEVICE_P4_VENDOR, hw_ver=DEVICE_P4_HW_VER, Loading
src/device/tests/test_unitary.py +20 −9 Original line number Diff line number Diff line Loading @@ -81,7 +81,7 @@ except ImportError: #ENABLE_EMULATED = False # set to False to disable tests of Emulated devices #ENABLE_OPENCONFIG = False # set to False to disable tests of OpenConfig devices #ENABLE_TAPI = False # set to False to disable tests of TAPI devices ENABLE_P4 = False # set to False to disable tests of P4 devices (P4 device not available in GitLab) #ENABLE_P4 = False # set to False to disable tests of P4 devices ENABLE_OPENCONFIG_CONFIGURE = True ENABLE_OPENCONFIG_MONITOR = True Loading Loading @@ -917,7 +917,8 @@ def test_device_p4_add_error_cases( device_client: DeviceClient, # pylint: disable=redefined-outer-name device_service: DeviceService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') with pytest.raises(grpc.RpcError) as e: device_p4_with_extra_rules = copy.deepcopy(DEVICE_P4) Loading @@ -940,13 +941,14 @@ def test_device_p4_add_correct( device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') device_p4_with_connect_rules = copy.deepcopy(DEVICE_P4) device_p4_with_connect_rules['device_config']['config_rules'].extend( DEVICE_P4_CONNECT_RULES) device_client.AddDevice(Device(**device_p4_with_connect_rules)) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_NAME) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_UUID) assert driver is not None Loading @@ -956,13 +958,14 @@ def test_device_p4_get( device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') initial_config = device_client.GetInitialConfig(DeviceId(**DEVICE_P4_UUID)) initial_config = device_client.GetInitialConfig(DeviceId(**DEVICE_P4_ID)) LOGGER.info('initial_config = {:s}'.format( grpc_message_to_json_string(initial_config))) device_data = context_client.GetDevice(DeviceId(**DEVICE_P4_UUID)) device_data = context_client.GetDevice(DeviceId(**DEVICE_P4_ID)) LOGGER.info('device_data = {:s}'.format( grpc_message_to_json_string(device_data))) Loading @@ -972,6 +975,10 @@ def test_device_p4_configure( device_client: DeviceClient, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') pytest.skip('Skipping test for unimplemented method') Loading @@ -980,6 +987,10 @@ def test_device_p4_deconfigure( device_client: DeviceClient, # pylint: disable=redefined-outer-name device_service: DeviceService, # pylint: disable=redefined-outer-name p4runtime_service: MockP4RuntimeService): # pylint: disable=redefined-outer-name if not ENABLE_P4: pytest.skip( 'Skipping test: No P4 device has been configured') pytest.skip('Skipping test for unimplemented method') Loading @@ -991,6 +1002,6 @@ def test_device_p4_delete( if not ENABLE_P4: pytest.skip('Skipping test: No P4 device has been configured') device_client.DeleteDevice(DeviceId(**DEVICE_P4_UUID)) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_NAME) device_client.DeleteDevice(DeviceId(**DEVICE_P4_ID)) driver : _Driver = device_service.driver_instance_cache.get(DEVICE_P4_UUID) assert driver is None