From 8ce882ca44dc28e73e847f902e41cbf2259d9fdf Mon Sep 17 00:00:00 2001 From: PedroDuarte536 Date: Wed, 7 May 2025 19:25:07 +0100 Subject: [PATCH 1/3] add ipi namespaces for netconf --- .../service/drivers/openconfig/templates/Namespace.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/device/service/drivers/openconfig/templates/Namespace.py b/src/device/service/drivers/openconfig/templates/Namespace.py index 82333c788..4059beec5 100644 --- a/src/device/service/drivers/openconfig/templates/Namespace.py +++ b/src/device/service/drivers/openconfig/templates/Namespace.py @@ -30,6 +30,10 @@ NAMESPACE_ROUTING_POLICY = 'http://openconfig.net/yang/routing-policy' NAMESPACE_VLAN = 'http://openconfig.net/yang/vlan' NAMESPACE_PLATFORM_TRANSCEIVER = 'http://openconfig.net/yang/platform/transceiver' +NAMESPACE_IPI_INTERFACE = 'http://www.ipinfusion.com/yang/ocnos/ipi-interface' +NAMESPACE_IPI_INTERFACE_EXTENDED = 'http://www.ipinfusion.com/yang/ocnos/ipi-if-extended' +NAMESPACE_IPI_INTERFACE_IP = 'http://www.ipinfusion.com/yang/ocnos/ipi-if-ip' + NAMESPACES = { 'nc' : NAMESPACE_NETCONF, 'ocacl': NAMESPACE_ACL, @@ -46,4 +50,8 @@ NAMESPACES = { 'ocrp' : NAMESPACE_ROUTING_POLICY, 'ocv' : NAMESPACE_VLAN, 'ocptr': NAMESPACE_PLATFORM_TRANSCEIVER, + + 'ipii': NAMESPACE_IPI_INTERFACE, + 'ipiie': NAMESPACE_IPI_INTERFACE_EXTENDED, + 'ipiiip': NAMESPACE_IPI_INTERFACE_IP, } -- GitLab From 41c4f5b8763fba0649c5c526ffd9c145c906a6a3 Mon Sep 17 00:00:00 2001 From: PedroDuarte536 Date: Thu, 24 Jul 2025 20:08:38 +0100 Subject: [PATCH 2/3] init device translation module --- src/inter_device_translation/__init__.py | 55 +++++++++++++++++++ .../config/config.yml | 2 + .../config/dict.ipi.yml | 13 +++++ .../config/dict.oc.yml | 13 +++++ 4 files changed, 83 insertions(+) create mode 100644 src/inter_device_translation/__init__.py create mode 100644 src/inter_device_translation/config/config.yml create mode 100644 src/inter_device_translation/config/dict.ipi.yml create mode 100644 src/inter_device_translation/config/dict.oc.yml diff --git a/src/inter_device_translation/__init__.py b/src/inter_device_translation/__init__.py new file mode 100644 index 000000000..98d44dd8b --- /dev/null +++ b/src/inter_device_translation/__init__.py @@ -0,0 +1,55 @@ +import yaml + + +with open('config/config.yml') as cfg: + config : dict = yaml.safe_load(cfg) + +dict_name = config.get('name') +dict_default = config.get('default') + + +class DictHelper: + def __init__(self, file): + self.file = file + + def _read(self) -> dict: + with open(self.file) as cfg: + return yaml.safe_load(cfg) + + def get_object(self, name, plural=False) -> str: + return self._read().get(name).get('plural' if plural else 'singular') + + def get_namespaces(self, name) -> str: + return self._read().get(name) + + def get_path(self, name) -> str: + path_details = self._read().get(name) + + path : str = path_details.get('path') + namespace = path_details.get('namespace') + + if namespace is None: + return path + + path_segments = path.split('/') + required_namespaces = len([s for s in path_segments if len(s > 1)]) + + if type(namespace) == list and len(namespace) != required_namespaces: + raise Exception(f'Number of namespaces do not match the specified path : {path}') + + elif type(namespace) == str: + namespace = [namespace for _ in range(required_namespaces)] + + ns_i = 0 + processed_segments = [] + for s in path_segments: + if len(s) > 1: + processed_segments.append(f'{namespace[ns_i]}:{s}') + ns_i += 1 + else: + processed_segments.append(s) + + +def get_dict_helper(dict_type = None) -> DictHelper: + if dict_type is None: dict_type = dict_default + return DictHelper(f'config/{dict_name}.{dict_type}.yml') diff --git a/src/inter_device_translation/config/config.yml b/src/inter_device_translation/config/config.yml new file mode 100644 index 000000000..37f7fb1fe --- /dev/null +++ b/src/inter_device_translation/config/config.yml @@ -0,0 +1,2 @@ +name: dict +default: oc \ No newline at end of file diff --git a/src/inter_device_translation/config/dict.ipi.yml b/src/inter_device_translation/config/dict.ipi.yml new file mode 100644 index 000000000..5db6eaa8d --- /dev/null +++ b/src/inter_device_translation/config/dict.ipi.yml @@ -0,0 +1,13 @@ +namespaces: + interfaces: ipii + interfaces_ip: ipiiip + +objects: + components: + singular: interface + plural: interfaces + +paths: + component_type: + namespace: ipiie + path: extended/state/hardware-type \ No newline at end of file diff --git a/src/inter_device_translation/config/dict.oc.yml b/src/inter_device_translation/config/dict.oc.yml new file mode 100644 index 000000000..437783f9c --- /dev/null +++ b/src/inter_device_translation/config/dict.oc.yml @@ -0,0 +1,13 @@ +namespaces: + interfaces: oci + interfaces_ip: ociip + +objects: + components: + singular: component + plural: components + +paths: + component_type: + namespace: ocpp + path: port/breakout-mode/state/channel-speed \ No newline at end of file -- GitLab From 0316ea213a55ea0471846f188ed3659c6d378128 Mon Sep 17 00:00:00 2001 From: PedroDuarte536 Date: Mon, 11 Aug 2025 17:51:49 +0100 Subject: [PATCH 3/3] temporary stash --- .../service/drivers/gnmi_openconfig/handlers/Component.py | 8 ++++++-- .../service/drivers/openconfig/templates/EndPoints.py | 1 + .../service/drivers/openconfig/templates/Interfaces.py | 1 + .../drivers/openconfig/templates/component/get.xml | 6 +++--- .../drivers/openconfig/templates/interface/get.xml | 6 +++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/device/service/drivers/gnmi_openconfig/handlers/Component.py b/src/device/service/drivers/gnmi_openconfig/handlers/Component.py index fab472233..6f26bee86 100644 --- a/src/device/service/drivers/gnmi_openconfig/handlers/Component.py +++ b/src/device/service/drivers/gnmi_openconfig/handlers/Component.py @@ -17,6 +17,7 @@ from typing import Any, Dict, List, Tuple from common.proto.kpi_sample_types_pb2 import KpiSampleType from ._Handler import _Handler from .YangHandler import YangHandler +from inter_device_translation import get_dict_helper LOGGER = logging.getLogger(__name__) @@ -24,8 +25,11 @@ PATH_IF_CTR = '/openconfig-interfaces:interfaces/interface[name={:s}]/state/coun #pylint: disable=abstract-method class ComponentHandler(_Handler): + def __init__(self, device_type=None): + self._dict_helper = get_dict_helper(device_type) + def get_resource_key(self) -> str: return '/endpoints/endpoint' - def get_path(self) -> str: return '/openconfig-platform:components' + def get_path(self) -> str: return self._dict_helper.get_path('components') def parse( self, json_data : Dict, yang_handler : YangHandler @@ -36,7 +40,7 @@ class ComponentHandler(_Handler): json_data_valid = yang_handler.parse_to_dict(yang_components_path, json_data, fmt='json') entries = [] - for component in json_data_valid['components']['component']: + for component in json_data_valid[self._dict_helper.get_object('components')][self._dict_helper.get_object('component')]: LOGGER.debug('component={:s}'.format(str(component))) component_name = component['name'] diff --git a/src/device/service/drivers/openconfig/templates/EndPoints.py b/src/device/service/drivers/openconfig/templates/EndPoints.py index dc607cb67..ab745e282 100644 --- a/src/device/service/drivers/openconfig/templates/EndPoints.py +++ b/src/device/service/drivers/openconfig/templates/EndPoints.py @@ -17,6 +17,7 @@ from typing import Any, Dict, List, Tuple from common.proto.kpi_sample_types_pb2 import KpiSampleType from .Namespace import NAMESPACES from .Tools import add_value_from_collection, add_value_from_tag +from inter_device_translation import get_dict_helper, DictHelper LOGGER = logging.getLogger(__name__) diff --git a/src/device/service/drivers/openconfig/templates/Interfaces.py b/src/device/service/drivers/openconfig/templates/Interfaces.py index aea737100..4efcd324b 100644 --- a/src/device/service/drivers/openconfig/templates/Interfaces.py +++ b/src/device/service/drivers/openconfig/templates/Interfaces.py @@ -16,6 +16,7 @@ import logging, lxml.etree as ET from typing import Any, Dict, List, Tuple from .Namespace import NAMESPACES from .Tools import add_value_from_tag +from inter_device_translation import get_dict_helper, DictHelper LOGGER = logging.getLogger(__name__) diff --git a/src/device/service/drivers/openconfig/templates/component/get.xml b/src/device/service/drivers/openconfig/templates/component/get.xml index aa25ed1e3..1f98ca78f 100644 --- a/src/device/service/drivers/openconfig/templates/component/get.xml +++ b/src/device/service/drivers/openconfig/templates/component/get.xml @@ -1,3 +1,3 @@ - - - +<{{components}}> + <{{component}}/> + diff --git a/src/device/service/drivers/openconfig/templates/interface/get.xml b/src/device/service/drivers/openconfig/templates/interface/get.xml index c0867655b..26cc3e966 100644 --- a/src/device/service/drivers/openconfig/templates/interface/get.xml +++ b/src/device/service/drivers/openconfig/templates/interface/get.xml @@ -1,3 +1,3 @@ - - - +<{{interfaces}}> + <{{interface}}/> + -- GitLab