def _subscribe_to_events(self): from voltha.extensions.omci.onu_device_entry import OnuDeviceEvents, \ OnuDeviceEntry from voltha.extensions.omci.omci_cc import OMCI_CC, OmciCCRxEvents # OMCI MIB Database sync status bus = self._onu_omci_device.event_bus topic = OnuDeviceEntry.event_bus_topic(self._handler.device_id, OnuDeviceEvents.MibDatabaseSyncEvent) self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler) # OMCI Capabilities (MEs and Message Types bus = self._onu_omci_device.event_bus topic = OnuDeviceEntry.event_bus_topic(self._handler.device_id, OnuDeviceEvents.OmciCapabilitiesEvent) self._capabilities_subscription = bus.subscribe(topic, self.capabilities_handler) # OMCI-CC Connectivity Events (for reachability/heartbeat) bus = self._onu_omci_device.omci_cc.event_bus topic = OMCI_CC.event_bus_topic(self._handler.device_id, OmciCCRxEvents.Connectivity) self._connectivity_subscription = bus.subscribe(topic, self.onu_is_reachable)
def _subscribe_to_events(self): self.log.debug('function-entry') # OMCI MIB Database sync status bus = self._onu_omci_device.event_bus topic = OnuDeviceEntry.event_bus_topic(self.device_id, OnuDeviceEvents.MibDatabaseSyncEvent) self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler) # OMCI Capabilities bus = self._onu_omci_device.event_bus topic = OnuDeviceEntry.event_bus_topic(self.device_id, OnuDeviceEvents.OmciCapabilitiesEvent) self._capabilities_subscription = bus.subscribe(topic, self.capabilties_handler)
def add_device(self, device_id, adapter_agent, custom_me_map=None, support_classes=OpenOmciAgentDefaults): """ Add a new ONU to be managed. To provide vendor-specific or custom Managed Entities, create your own Entity ID to class mapping dictionary. Since ONU devices can be added at any time (even during Device Handler startup), the ONU device handler is responsible for calling start()/stop() for this object. :param device_id: (str) Device ID of ONU to add :param adapter_agent: (AdapterAgent) Adapter agent for ONU :param custom_me_map: (dict) Additional/updated ME to add to class map :param support_classes: (dict) State machines and tasks for this ONU :return: (OnuDeviceEntry) The ONU device """ self.log.debug('add-device', device_id=device_id) device = self._devices.get(device_id) if device is None: device = OnuDeviceEntry(self, device_id, adapter_agent, custom_me_map, self._mib_db, support_classes) self._devices[device_id] = device return device
def on_enter_out_of_sync(self): """ State machine has just started or the MIB database has transitioned to an out-of-synchronization state """ self.log.debug('state-transition') self._cancel_deferred() self._device = self._agent.get_device(self._device_id) # Subscribe to events of interest try: for event, sub in self._sub_mapping.iteritems(): if self._subscriptions[event] is None: self._subscriptions[event] = \ self._device.event_bus.subscribe( topic=OnuDeviceEntry.event_bus_topic(self._device_id, event), callback=sub) except Exception as e: self.log.exception('subscription-setup', e=e) # Periodically check/poll for in-sync in case subscription was missed or # already in sync self._deferred = reactor.callLater(0, self.check_in_sync)
def _subscribe_to_events(self): from voltha.extensions.omci.onu_device_entry import OnuDeviceEvents, \ OnuDeviceEntry # OMCI MIB Database sync status bus = self.openomci.onu_omci_device.event_bus topic = OnuDeviceEntry.event_bus_topic(self.device_id, OnuDeviceEvents.MibDatabaseSyncEvent) self._in_sync_subscription = bus.subscribe(topic, self.in_sync_handler)
def on_enter_starting(self): """ Determine ONU status and start/re-start MIB Synchronization tasks """ self._device = self._agent.get_device(self._device_id) self.advertise(OpenOmciEventType.state_change, self.state) # Make sure root of external MIB Database exists self._seed_database() # Set up Response and Autonomous notification subscriptions try: for event, sub in self._omci_cc_sub_mapping.iteritems(): if self._omci_cc_subscriptions[event] is None: self._omci_cc_subscriptions[event] = \ self._device.omci_cc.event_bus.subscribe( topic=OMCI_CC.event_bus_topic(self._device_id, event), callback=sub) except Exception as e: self.log.exception('omci-cc-subscription-setup', e=e) # Set up ONU device subscriptions try: for event, sub in self._onu_dev_sub_mapping.iteritems(): if self._onu_dev_subscriptions[event] is None: self._onu_dev_subscriptions[event] = \ self._device.event_bus.subscribe( topic=OnuDeviceEntry.event_bus_topic(self._device_id, event), callback=sub) except Exception as e: self.log.exception('dev-subscription-setup', e=e) # Clear any previous audit results self._on_olt_only_diffs = None self._on_onu_only_diffs = None self._attr_diffs = None self._audited_olt_db = None self._audited_onu_db = None # Determine if this ONU has ever synchronized if self.is_new_onu: # Start full MIB upload self._deferred = reactor.callLater(0, self.upload_mib) else: # Examine the MIB Data Sync self._deferred = reactor.callLater(0, self.examine_mds)
def _subscribe_to_events(self): from voltha.extensions.omci.onu_device_entry import OnuDeviceEvents, \ OnuDeviceEntry, IN_SYNC_KEY from voltha.extensions.omci.omci_cc import OMCI_CC, OmciCCRxEvents, \ CONNECTED_KEY def in_sync_handler(_topic, msg): if self._in_sync_subscription is not None: try: in_sync = msg[IN_SYNC_KEY] if in_sync: # Only call this once as well (after PON enable) bus = self._onu_omci_device.event_bus bus.unsubscribe(self._in_sync_subscription) self._in_sync_subscription = None # Start up device_info load reactor.callLater(0, self._mib_in_sync) except Exception as e: self.log.exception('in-sync', e=e) def onu_is_reachable(_topic, msg): """ Reach-ability change event :param _topic: (str) subscription topic, not used :param msg: (dict) 'connected' key holds True if reachable """ if self._connectivity_subscription is not None: try: connected = msg[CONNECTED_KEY] # TODO: For now, only care about the first. # Later we could use this for a heartbeat, but may want some hysteresis # Cancel any 'reachable' subscriptions if connected: evt_bus = self._onu_omci_device.omci_cc.event_bus evt_bus.unsubscribe(self._connectivity_subscription) self._connectivity_subscription = None self._connected = True device = self._handler.adapter_agent.get_device(self._handler.device_id) device.oper_status = OperStatus.ACTIVE device.connect_status = ConnectStatus.REACHABLE self._handler.adapter_agent.update_device(device) except Exception as e: self.log.exception('onu-reachable', e=e) # OMCI MIB Database sync status bus = self._onu_omci_device.event_bus topic = OnuDeviceEntry.event_bus_topic(self._handler.device_id, OnuDeviceEvents.MibDatabaseSyncEvent) self._in_sync_subscription = bus.subscribe(topic, in_sync_handler) # OMCI-CC Connectivity Events (for reachbility/heartbeat) bus = self._onu_omci_device.omci_cc.event_bus topic = OMCI_CC.event_bus_topic(self._handler.device_id, OmciCCRxEvents.Connectivity) self._connectivity_subscription = bus.subscribe(topic, onu_is_reachable)