def perform_lock(self):
        """
        Perform the lock/unlock
        """
        self.log.info('setting-uni-lock-state', lock=self._lock)

        try:
            state = 1 if self._lock else 0

            # lock the whole ont and all the pptp.  some onu dont causing odd behavior.
            pptp_list = sorted(self._config.pptp_entities
                               ) if self._config.pptp_entities else []
            veip_list = sorted(self._config.veip_entities
                               ) if self._config.veip_entities else []

            if self._lock is True:
                # lock unis first, ontg must be last
                for entity_id in pptp_list:
                    msg = PptpEthernetUniFrame(
                        entity_id, attributes=dict(administrative_state=state))
                    yield self._send_omci_msg(msg)

                for entity_id in veip_list:
                    msg = VeipUniFrame(
                        entity_id, attributes=dict(administrative_state=state))
                    yield self._send_omci_msg(msg)

                msg = OntGFrame(attributes={'administrative_state': state})
                yield self._send_omci_msg(msg)
            else:
                # ontg must be unlocked first, then unis
                msg = OntGFrame(attributes={'administrative_state': state})
                yield self._send_omci_msg(msg)

                for entity_id in pptp_list:
                    msg = PptpEthernetUniFrame(
                        entity_id, attributes=dict(administrative_state=state))
                    yield self._send_omci_msg(msg)

                for entity_id in veip_list:
                    msg = VeipUniFrame(
                        entity_id, attributes=dict(administrative_state=state))
                    yield self._send_omci_msg(msg)

            self.deferred.callback('setting-uni-lock-state-finished')

        except Exception as e:
            self.log.exception('setting-uni-lock-state', e=e)
            self.deferred.errback(failure.Failure(e))
Ejemplo n.º 2
0
    def first_in_sync_event(self):
        """
        This event is called on the first MIB synchronization event after
        OpenOMCI has been started. It is responsible for starting any
        other state machine and to initiate an ONU Capabilities report
        """
        if self._first_in_sync:
            self._first_in_sync = False

            # Start up the ONU Capabilities task
            self._configuration.reset()

            # Insure that the ONU-G Administrative lock is disabled
            def failure(reason):
                self.log.error('disable-admin-state-lock', reason=reason)

            frame = OntGFrame(attributes={'administrative_state': 0}).set()
            task = OmciModifyRequest(self._omci_agent, self.device_id, frame)
            self.task_runner.queue_task(task).addErrback(failure)

            # Start up any other remaining OpenOMCI state machines
            def start_state_machines(machines):
                for sm in machines:
                    self._state_machines.append(sm)
                    reactor.callLater(0, sm.start)

            self._deferred = reactor.callLater(0, start_state_machines,
                                               self._on_sync_state_machines)

            # if an ongoing upgrading is not accomplished, restart it
            if self._img_deferred is not None:
                self._image_agent.onu_bootup()
    def perform_lock(self):
        """
        Perform the lock/unlock
        """
        self.log.info('setting-uni-lock-state', lock=self._lock)

        try:
            state = 1 if self._lock else 0

            # lock the whole ont and all the pptp.  some onu dont causing odd behavior.
            msg = OntGFrame(attributes={'administrative_state': state})
            frame = msg.set()
            self.log.debug('openomci-msg', omci_msg=msg)
            results = yield self._device.omci_cc.send(frame)
            self.strobe_watchdog()

            status = results.fields['omci_message'].fields['success_code']
            self.log.info('response-status', status=status)

            # Success?
            if status in (RC.Success.value, RC.InstanceExists):
                self.log.debug('set-lock-ontg', lock=self._lock)
            else:
                self.log.warn('cannot-set-lock-ontg', lock=self._lock)

            pptp_list = sorted(self._config.pptp_entities
                               ) if self._config.pptp_entities else []
            veip_list = sorted(self._config.veip_entities
                               ) if self._config.veip_entities else []

            for entity_id in pptp_list:
                pptp_value = self._config.pptp_entities[entity_id]
                msg = PptpEthernetUniFrame(
                    entity_id, attributes=dict(administrative_state=state))
                self._send_uni_lock_msg(entity_id, pptp_value, msg)

            for entity_id in veip_list:
                veip_value = self._config.veip_entities[entity_id]
                msg = VeipUniFrame(entity_id,
                                   attributes=dict(administrative_state=state))
                self._send_uni_lock_msg(entity_id, veip_value, msg)

            self.deferred.callback(self)

        except Exception as e:
            self.log.exception('setting-uni-lock-state', e=e)
            self.deferred.errback(failure.Failure(e))
Ejemplo n.º 4
0
    def send_reboot(self, timeout=DEFAULT_OMCI_TIMEOUT, high_priority=False):
        """
        Send an ONU Device reboot request (ONU-G ME).

        NOTICE: This method is being deprecated and replaced with a tasks to preform this function
        """
        self.log.debug('send-mib-reboot')

        frame = OntGFrame().reboot()
        return self.send(frame, timeout=timeout, high_priority=high_priority)
    def check_pulse(self):
        if self.enabled:
            try:
                self._defer = self._handler.openomci.omci_cc.send(
                    OntGFrame(self.check_item).get())
                self._defer.addCallbacks(self._heartbeat_success,
                                         self._heartbeat_fail)

            except Exception as e:
                self._defer = reactor.callLater(5, self._heartbeat_fail, e)
Ejemplo n.º 6
0
    def perform_reboot(self):
        """
        Perform the reboot requests

        Depending on the ONU implementation, a response may not be returned. For this
        reason, a timeout is considered successful.
        """
        self.log.info('perform-reboot')

        try:
            frame = OntGFrame().reboot(reboot_code=self._flags)
            self.strobe_watchdog()
            results = yield self._device.omci_cc.send(frame,
                                                      timeout=self._timeout,
                                                      high_priority=True)

            status = results.fields['omci_message'].fields['success_code']
            self.log.debug('reboot-status', status=status)

            # Did it fail
            if status != RC.Success.value:
                if self._flags != RebootFlags.Reboot_Unconditionally and\
                        status == RC.DeviceBusy.value:
                    raise DeviceBusy('ONU is busy, try again later')
                else:
                    msg = 'Reboot request failed with status {}'.format(status)
                    raise RebootException(msg)

            self.log.info('reboot-success')
            self.deferred.callback(self)

        except TimeoutError:
            self.log.info('timeout',
                          msg='Request timeout is not considered an error')
            self.deferred.callback(None)

        except DeviceBusy as e:
            self.log.warn('perform-reboot', msg=e)
            self.deferred.errback(failure.Failure(e))

        except Exception as e:
            self.log.exception('perform-reboot', e=e)
            self.deferred.errback(failure.Failure(e))
Ejemplo n.º 7
0
    def perform_sync_time(self):
        """
        Sync the time
        """
        self.log.debug('perform-sync-time')

        try:
            device = self.omci_agent.get_device(self.device_id)

            #########################################
            # ONT-G (ME #256)
            dt = datetime.utcnow() if self._use_utc else datetime.now()

            results = yield device.omci_cc.send(
                OntGFrame().synchronize_time(dt))

            omci_msg = results.fields['omci_message'].fields
            status = omci_msg['success_code']
            self.log.debug('sync-time', status=status)

            if status == RC.Success:
                self.log.info('sync-time',
                              success_info=omci_msg['success_info'] & 0x0f)

            assert status == RC.Success, 'Unexpected Response Status: {}'.format(
                status)

            # Successful if here
            self.deferred.callback(results)

        except TimeoutError as e:
            self.log.warn('sync-time-timeout', e=e)
            self.deferred.errback(failure.Failure(e))

        except Exception as e:
            self.log.exception('sync-time', e=e)
            self.deferred.errback(failure.Failure(e))
Ejemplo n.º 8
0
    def create_template_instance(self):
        """
        Gather unique identifying elements from the ONU.  Lookup template in persistent storage and return
        If no template is found return None so normal MIB Upload sequence can happen
        """
        self.log.debug('create-mib-template-instance')

        try:
            # MIB Reset start fresh
            self.strobe_watchdog()
            results = yield self._device.omci_cc.send_mib_reset()

            status = results.fields['omci_message'].fields['success_code']
            if status != ReasonCodes.Success.value:
                raise Exception(
                    'MIB Reset request failed with status code: {}'.format(
                        status))

            self.log.debug('gather-onu-info')

            # Query for Vendor ID, Equipment ID and Software Version
            results = yield self._get_omci(
                OntGFrame(attributes=['vendor_id', 'serial_number']))
            self.log.debug('got-ontg', results=results)

            vendor_id = results.get('vendor_id',
                                    b'').decode('ascii').rstrip('\x00')
            serial_number = results.get('serial_number', '')

            results = yield self._get_omci(
                Ont2GFrame(attributes='equipment_id'))
            self.log.debug('got-ont2g', results=results)

            equipment_id = results.get('equipment_id',
                                       b'').decode('ascii').rstrip('\x00')

            # check only two software slots for active version.
            results1 = yield self._get_omci(
                SoftwareImageFrame(0, attributes=['is_active', 'version']))
            results2 = yield self._get_omci(
                SoftwareImageFrame(1, attributes=['is_active', 'version']))
            self.log.debug('got-software',
                           results1=results1,
                           results2=results2)

            software_version = ''
            if results1.get('is_active') == 1:
                software_version = results1.get(
                    'version', b'').decode('ascii').rstrip('\x00')
            elif results2.get('is_active') == 1:
                software_version = results2.get(
                    'version', b'').decode('ascii').rstrip('\x00')

            results = yield self._get_omci(
                IpHostConfigDataFrame(1, attributes='mac_address'))
            self.log.debug('got-ip-host-config', results=results)

            mac_address = results.get('mac_address', '')

            # Lookup template base on unique onu type info
            template = None
            if vendor_id and equipment_id and software_version:
                self.log.debug('looking-up-template',
                               vendor_id=vendor_id,
                               equipment_id=equipment_id,
                               software_version=software_version)
                template = MibTemplateDb(vendor_id, equipment_id,
                                         software_version, serial_number,
                                         mac_address)
            else:
                self.log.info('no-usable-template-lookup-data',
                              vendor_id=vendor_id,
                              equipment_id=equipment_id,
                              software_version=software_version)

            if template and template.loaded:
                # generate db instance
                loaded_template_instance = template.get_template_instance()
                self.deferred.callback(loaded_template_instance)
            else:
                self.deferred.callback(None)

        except TimeoutError as e:
            self.log.warn('mib-template-timeout', e=e)
            self.deferred.errback(failure.Failure(e))

        except AlreadyCalledError:
            # Can occur if task canceled due to MIB Sync state change
            self.log.debug('already-called-exception')
            assert self.deferred.called, 'Unexpected AlreadyCalledError exception'
        except Exception as e:
            self.log.exception('mib-template', e=e)
            self.deferred.errback(failure.Failure(e))
Ejemplo n.º 9
0
 def send_reboot(self, timeout=DEFAULT_OMCI_TIMEOUT, high_priority=False):
     frame = OntGFrame().reboot()
     return self.send(frame, timeout=timeout, high_priority=high_priority)