diff --git a/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py b/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py index 9c2c0abb33d1789c2a3fb78f91790c2742b1fc31..f0ef6520d33f48dc10fd8619d8daaa7a5485357f 100644 --- a/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py +++ b/src/device/service/drivers/gnmi_openconfig/GnmiSessionHandler.py @@ -25,7 +25,7 @@ from .tools.Channel import get_grpc_channel from .tools.Path import path_from_string, path_to_string #, compose_path from .tools.Subscriptions import Subscriptions from .tools.Value import decode_value #, value_exists -#from .MonitoringThread import MonitoringThread +from .MonitoringThread import MonitoringThread class GnmiSessionHandler: def __init__(self, address : str, port : int, settings : Dict, logger : logging.Logger) -> None: @@ -41,7 +41,7 @@ class GnmiSessionHandler: self._channel : Optional[grpc.Channel] = None self._stub : Optional[gNMIStub] = None self._yang_handler = YangHandler() - #self._monit_thread = None + self._monit_thread = None self._subscriptions = Subscriptions() self._in_subscriptions = queue.Queue() self._out_samples = queue.Queue() @@ -68,16 +68,16 @@ class GnmiSessionHandler: self._channel = get_grpc_channel(self._address, self._port, self._use_tls, self._logger) self._stub = gNMIStub(self._channel) check_capabilities(self._stub, self._username, self._password, timeout=120) - #self._monit_thread = MonitoringThread( - # self._stub, self._logger, self._settings, self._in_subscriptions, self._out_samples) - #self._monit_thread.start() + self._monit_thread = MonitoringThread( + self._stub, self._logger, self._settings, self._in_subscriptions, self._out_samples) + self._monit_thread.start() self._connected.set() def disconnect(self): if not self._connected.is_set(): return with self._lock: - #self._monit_thread.stop() - #self._monit_thread.join() + self._monit_thread.stop() + self._monit_thread.join() self._channel.close() self._connected.clear() diff --git a/src/device/service/drivers/gnmi_openconfig/MonitoringThread.py b/src/device/service/drivers/gnmi_openconfig/MonitoringThread.py index 8bf6704a854542b3a085af05d55391e23c8d224f..c3668a86e17a1044c18a2cd092dfb590edb0eca8 100644 --- a/src/device/service/drivers/gnmi_openconfig/MonitoringThread.py +++ b/src/device/service/drivers/gnmi_openconfig/MonitoringThread.py @@ -147,16 +147,22 @@ class MonitoringThread(threading.Thread): timestamp = timestamp_local for update_entry in update.update: str_path = path_to_string(update_entry.path) + if str_path.startswith('/interfaces/'): + # Add namespace, if missing + str_path_parts = str_path.split('/') + str_path_parts[1] = 'openconfig-interfaces:interfaces' + str_path = '/'.join(str_path_parts) #if str_path != '/system/name/host-name': continue #counter_name = update_entry.path[-1].name value_type = update_entry.val.WhichOneof('value') value = getattr(update_entry.val, value_type) - if re.match(r'^[0-9]+$', value) is not None: - value = int(value) - elif re.match(r'^[0-9]*\.[0-9]*$', value) is not None: - value = float(value) - else: - value = str(value) + if isinstance(value, str): + if re.match(r'^[0-9]+$', value) is not None: + value = int(value) + elif re.match(r'^[0-9]*\.[0-9]*$', value) is not None: + value = float(value) + else: + value = str(value) delta_sample = self._delta_sample_cache.get_delta(str_path, timestamp, value) if delta_sample is None: sample = (timestamp, str_path, value) diff --git a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py index a769692baf5d5d4831cfae3754298f36335e992e..aba6f4aac1702ecf8609b1633f591b4b52dfc10e 100644 --- a/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py +++ b/src/device/service/drivers/gnmi_openconfig/handlers/Interface.py @@ -149,8 +149,6 @@ class InterfaceHandler(_Handler): _subinterface['name'] = subinterface_state['name'] if 'enabled' in subinterface_state: _subinterface['enabled'] = subinterface_state['enabled'] - entry_subinterface_key = '{:s}/subinterface[{:d}]'.format(entry_interface_key, subinterface_index) - entries.append((entry_subinterface_key, _subinterface)) if 'vlan' in subinterface: vlan = subinterface['vlan'] @@ -160,44 +158,36 @@ class InterfaceHandler(_Handler): if single_tagged is not None: single_tagged_config = single_tagged['config'] vlan_id = single_tagged_config['vlan-id'] - - _vlan = {'vlan_id': vlan_id} - entry_vlan_key = '{:s}/vlan[single:{:s}]'.format(entry_subinterface_key, vlan_id) - entries.append((entry_vlan_key, _vlan)) + _subinterface['vlan_id'] = vlan_id if len(vlan_match) > 0: raise Exception('Unsupported VLAN schema: {:s}'.format(str(vlan))) ipv4_addresses = subinterface.get('ipv4', {}).get('addresses', {}).get('address', []) + if len(ipv4_addresses) > 1: + raise Exception('Multiple IPv4 Addresses not supported: {:s}'.format(str(ipv4_addresses))) for ipv4_address in ipv4_addresses: LOGGER.debug('ipv4_address={:s}'.format(str(ipv4_address))) - - ipv4_address_ip = ipv4_address['ip'] + _subinterface['address_ip'] = ipv4_address['ip'] ipv4_address_state = ipv4_address.get('state', {}) - - _ipv4_address = {'ip': ipv4_address_ip} - if 'origin' in ipv4_address_state: - _ipv4_address['origin'] = ipv4_address_state['origin'] + #if 'origin' in ipv4_address_state: + # _subinterface['origin'] = ipv4_address_state['origin'] if 'prefix-length' in ipv4_address_state: - _ipv4_address['prefix'] = ipv4_address_state['prefix-length'] - - entry_ipv4_address_key = '{:s}/ipv4[{:s}]'.format(entry_subinterface_key, ipv4_address_ip) - entries.append((entry_ipv4_address_key, _ipv4_address)) + _subinterface['address_prefix'] = ipv4_address_state['prefix-length'] ipv6_addresses = subinterface.get('ipv6', {}).get('addresses', {}).get('address', []) + if len(ipv6_addresses) > 1: + raise Exception('Multiple IPv6 Addresses not supported: {:s}'.format(str(ipv6_addresses))) for ipv6_address in ipv6_addresses: LOGGER.debug('ipv6_address={:s}'.format(str(ipv6_address))) - - ipv6_address_ip = ipv6_address['ip'] + _subinterface['address_ipv6'] = ipv6_address['ip'] ipv6_address_state = ipv6_address.get('state', {}) - - _ipv6_address = {'ip': ipv6_address_ip} - if 'origin' in ipv6_address_state: - _ipv6_address['origin'] = ipv6_address_state['origin'] + #if 'origin' in ipv6_address_state: + # _subinterface['origin_ipv6'] = ipv6_address_state['origin'] if 'prefix-length' in ipv6_address_state: - _ipv6_address['prefix'] = ipv6_address_state['prefix-length'] + _subinterface['address_prefix_ipv6'] = ipv6_address_state['prefix-length'] - entry_ipv6_address_key = '{:s}/ipv6[{:s}]'.format(entry_subinterface_key, ipv6_address_ip) - entries.append((entry_ipv6_address_key, _ipv6_address)) + entry_subinterface_key = '{:s}/subinterface[{:d}]'.format(entry_interface_key, subinterface_index) + entries.append((entry_subinterface_key, _subinterface)) return entries