def create_tcont(self, tcont_data, traffic_descriptor_data):
        self.log.debug('create-tcont',
                       tcont_data=tcont_data,
                       traffic_descriptor_data=traffic_descriptor_data)
        tcontdata = TcontsConfigData()
        tcontdata.CopyFrom(tcont_data)

        # TODO: fill in what i have.  This needs to be provided from the OLT
        # currently its hardcoded/static
        tcontdict = dict()
        tcontdict['alloc-id'] = tcontdata.alloc_id
        tcontdict['name'] = tcontdata.name
        tcontdict['vont-ani'] = tcontdata.interface_reference

        # TODO: Not sure what to do with any of this...
        tddata = dict()
        tddata['name'] = 'not-sure-td-profile'
        tddata['fixed-bandwidth'] = "not-sure-fixed"
        tddata['assured-bandwidth'] = "not-sure-assured"
        tddata['maximum-bandwidth'] = "not-sure-max"
        tddata['additional-bw-eligibility-indicator'] = "not-sure-additional"

        td = OnuTrafficDescriptor.create(tddata)
        tcont = OnuTCont.create(self, tcont=tcontdict, td=td)

        self._pon.add_tcont(tcont)

        self.log.debug('pon-add-tcont', tcont=tcont)

        if tcontdata.interface_reference is not None:
            self.log.debug('tcont', tcont=tcont.alloc_id)
        else:
            self.log.info('received-null-tcont-data', tcont=tcont.alloc_id)
Esempio n. 2
0
    def create_xpon_tcont(self, onu_id):
        """ Create the xPON TCONT Config data """
        tcont = TcontsConfigData()
        tcont.name = 'tcont-{}-{}-data'.format(self.pon_id, onu_id)
        pon_intf_onu_id = (self.pon_id, onu_id)
        try:
            tcont.alloc_id = self._parent.resource_mgr.get_alloc_id(
                pon_intf_onu_id)

        except Exception as _e:
            raise

        traffic_desc = TrafficDescriptorProfileData(
            name=tcont.name,
            fixed_bandwidth=0,
            assured_bandwidth=0,
            maximum_bandwidth=10000000,
            priority=0,
            weight=0,
            additional_bw_eligibility_indicator=0)
        tc = {
            'name': tcont.name,
            'alloc-id': tcont.alloc_id,
            'pon-id': self.pon_id,
            'onu-id': onu_id,
            'td-ref':
            {  # TODO: This should be the TD Name and the TD installed in xpon cache
                'name': traffic_desc.name,
                'fixed-bandwidth': traffic_desc.fixed_bandwidth,
                'assured-bandwidth': traffic_desc.assured_bandwidth,
                'maximum-bandwidth': traffic_desc.maximum_bandwidth,
                'priority': traffic_desc.priority,
                'weight': traffic_desc.weight,
                'additional-bw-eligibility-indicator': 0,
                'data': traffic_desc
            },
            'data': tcont
        }
        return tcont, tc, traffic_desc
Esempio n. 3
0
def createTcont(name, username, trafficDescriptor, id):
    tcont_request = TcontsConfigData()
    log.debug("FOUNDRY-creating-tcont-config",
              config=tcont_request,
              name=name,
              username=username,
              alloc_id=id)

    try:
        tcont_request.name = name
        tcont_request.interface_reference = username
        tcont_request.traffic_descriptor_profile_ref = trafficDescriptor
        tcont_request.alloc_id = id

        log.debug("FOUNDRY-tcont-config-prepared",
                  config=tcont_request,
                  name=name,
                  username=username,
                  alloc_id=id)
    except Exception as e:
        log.error("FOUNDRY-tcont-config-error",
                  exception=e,
                  config=tcont_request,
                  name=name,
                  username=username,
                  alloc_id=id)

    try:
        log.debug("FOUNDRY-tcont-grpc-call",
                  config=tcont_request,
                  name=name,
                  username=username,
                  alloc_id=id)
        stub.CreateTcontsConfigData(tcont_request)
        log.info("FOUNDRY-autodetection-tcont-created",
                 config=tcont_request,
                 name=name,
                 username=username,
                 alloc_id=id)
    except Exception as e:
        log.error("FOUNDRY-tcont-config-grpc-call-error",
                  exception=e,
                  config=tcont_request,
                  name=name,
                  username=username,
                  alloc_id=id)
Esempio n. 4
0
    def onu_indication(self, onu_indication):
        self.log.debug("onu indication",
                       intf_id=onu_indication.intf_id,
                       onu_id=onu_indication.onu_id,
                       serial_number=onu_indication.serial_number,
                       oper_state=onu_indication.oper_state,
                       admin_state=onu_indication.admin_state)
        try:
            serial_number_str = self.stringify_serial_number(
                onu_indication.serial_number)
        except Exception as e:
            serial_number_str = None

        if serial_number_str is not None:
            onu_device = self.adapter_agent.get_child_device(
                self.device_id, serial_number=serial_number_str)
        else:
            onu_device = self.adapter_agent.get_child_device(
                self.device_id,
                parent_port_no=self.platform.intf_id_to_port_no(
                    onu_indication.intf_id, Port.PON_OLT),
                onu_id=onu_indication.onu_id)

        if onu_device is None:
            self.log.error('onu not found',
                           intf_id=onu_indication.intf_id,
                           onu_id=onu_indication.onu_id)
            return

        if self.platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
                != onu_indication.intf_id:
            self.log.warn(
                'ONU-is-on-a-different-intf-id-now',
                previous_intf_id=self.platform.intf_id_from_pon_port_no(
                    onu_device.parent_port_no),
                current_intf_id=onu_indication.intf_id)
            # FIXME - handle intf_id mismatch (ONU move?)

        if onu_device.proxy_address.onu_id != onu_indication.onu_id:
            # FIXME - handle onu id mismatch
            self.log.warn(
                'ONU-id-mismatch, can happen if both voltha and '
                'the olt rebooted',
                expected_onu_id=onu_device.proxy_address.onu_id,
                received_onu_id=onu_indication.onu_id)

        uni_no = self.platform.mk_uni_port_num(onu_indication.intf_id,
                                               onu_indication.onu_id)
        uni_name = self.port_name(uni_no,
                                  Port.ETHERNET_UNI,
                                  serial_number=onu_device.serial_number)

        self.log.debug('port-number-ready', uni_no=uni_no, uni_name=uni_name)

        # Admin state
        if onu_indication.admin_state == 'down':
            if onu_indication.oper_state != 'down':
                self.log.error('ONU-admin-state-down-and-oper-status-not-down',
                               oper_state=onu_indication.oper_state)
                # Forcing the oper state change code to execute
                onu_indication.oper_state = 'down'

            # Port and logical port update is taken care of by oper state block

        elif onu_indication.admin_state == 'up':
            pass

        else:
            self.log.warn('Invalid-or-not-implemented-admin-state',
                          received_admin_state=onu_indication.admin_state)

        self.log.debug('admin-state-dealt-with')

        onu_adapter_agent = \
            registry('adapter_loader').get_agent(onu_device.adapter)
        if onu_adapter_agent is None:
            self.log.error('onu_adapter_agent-could-not-be-retrieved',
                           onu_device=onu_device)
            return

        # Operating state
        if onu_indication.oper_state == 'down':

            if onu_device.connect_status != ConnectStatus.UNREACHABLE:
                onu_device.connect_status = ConnectStatus.UNREACHABLE
                self.adapter_agent.update_device(onu_device)

            # Move to discovered state
            self.log.debug('onu-oper-state-is-down')

            if onu_device.oper_status != OperStatus.DISCOVERED:
                onu_device.oper_status = OperStatus.DISCOVERED
                self.adapter_agent.update_device(onu_device)
            # Set port oper state to Discovered
            self.onu_ports_down(onu_device, uni_no, uni_name,
                                OperStatus.DISCOVERED)

            if onu_device.adapter == 'brcm_openomci_onu':
                self.log.debug('using-brcm_openomci_onu')
                onu_adapter_agent.update_interface(onu_device,
                                                   {'oper_state': 'down'})

        elif onu_indication.oper_state == 'up':

            if onu_device.connect_status != ConnectStatus.REACHABLE:
                onu_device.connect_status = ConnectStatus.REACHABLE
                self.adapter_agent.update_device(onu_device)

            if onu_device.oper_status != OperStatus.DISCOVERED:
                self.log.debug("ignore onu indication",
                               intf_id=onu_indication.intf_id,
                               onu_id=onu_indication.onu_id,
                               state=onu_device.oper_status,
                               msg_oper_state=onu_indication.oper_state)
                return

            # Device was in Discovered state, setting it to active

            # Prepare onu configuration
            # If we are using the old/current broadcom adapter otherwise
            # use the openomci adapter
            if onu_device.adapter == 'broadcom_onu':
                self.log.debug('using-broadcom_onu')

                # onu initialization, base configuration (bridge setup ...)
                def onu_initialization():

                    onu_adapter_agent.adapter.devices_handlers[onu_device.id] \
                                     .message_exchange()
                    self.log.debug('broadcom-message-exchange-started')

                # tcont creation (onu)
                tcont = TcontsConfigData()
                tcont.alloc_id = self.platform.mk_alloc_id(
                    onu_indication.intf_id, onu_indication.onu_id)

                # gem port creation
                gem_port = GemportsConfigData()
                gem_port.gemport_id = self.platform.mk_gemport_id(
                    onu_indication.intf_id, onu_indication.onu_id)

                # ports creation/update
                def port_config():

                    # "v_enet" creation (olt)

                    # add_port update port when it exists
                    self.adapter_agent.add_port(
                        self.device_id,
                        Port(port_no=uni_no,
                             label=uni_name,
                             type=Port.ETHERNET_UNI,
                             admin_state=AdminState.ENABLED,
                             oper_status=OperStatus.ACTIVE))

                    # v_enet creation (onu)

                    venet = VEnetConfig(name=uni_name)
                    venet.interface.name = uni_name
                    onu_adapter_agent.create_interface(onu_device, venet)

                # ONU device status update in the datastore
                def onu_update_oper_status():
                    onu_device.oper_status = OperStatus.ACTIVE
                    onu_device.connect_status = ConnectStatus.REACHABLE
                    self.adapter_agent.update_device(onu_device)

                # FIXME : the asynchronicity has to be taken care of properly
                onu_initialization()
                reactor.callLater(10,
                                  onu_adapter_agent.create_tcont,
                                  device=onu_device,
                                  tcont_data=tcont,
                                  traffic_descriptor_data=None)
                reactor.callLater(11, onu_adapter_agent.create_gemport,
                                  onu_device, gem_port)
                reactor.callLater(12, port_config)
                reactor.callLater(12, onu_update_oper_status)

            elif onu_device.adapter == 'brcm_openomci_onu':
                self.log.debug('using-brcm_openomci_onu')

                # tcont creation (onu)
                tcont = TcontsConfigData()
                tcont.alloc_id = self.platform.mk_alloc_id(
                    onu_indication.intf_id, onu_indication.onu_id)

                # gem port creation
                gem_port = GemportsConfigData()
                gem_port.gemport_id = self.platform.mk_gemport_id(
                    onu_indication.intf_id, onu_indication.onu_id)
                gem_port.tcont_ref = str(tcont.alloc_id)

                self.log.info('inject-tcont-gem-data-onu-handler',
                              onu_indication=onu_indication,
                              tcont=tcont,
                              gem_port=gem_port)

                onu_adapter_agent.create_tcont(onu_device,
                                               tcont,
                                               traffic_descriptor_data=None)
                onu_adapter_agent.create_gemport(onu_device, gem_port)
                onu_adapter_agent.create_interface(onu_device, onu_indication)

            else:
                self.log.error('unsupported-openolt-onu-adapter')

        else:
            self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
                          oper_state=onu_indication.oper_state)
Esempio n. 5
0
    def onu_indication(self, onu_indication):
        self.log.debug("onu indication",
                       intf_id=onu_indication.intf_id,
                       onu_id=onu_indication.onu_id,
                       serial_number=onu_indication.serial_number,
                       oper_state=onu_indication.oper_state,
                       admin_state=onu_indication.admin_state)
        try:
            serial_number_str = self.stringify_serial_number(
                onu_indication.serial_number)
        except Exception as e:
            serial_number_str = None

        if serial_number_str is not None:
            onu_device = self.adapter_agent.get_child_device(
                self.device_id, serial_number=serial_number_str)
        else:
            onu_device = self.adapter_agent.get_child_device(
                self.device_id,
                parent_port_no=platform.intf_id_to_port_no(
                    onu_indication.intf_id, Port.PON_OLT),
                onu_id=onu_indication.onu_id)

        if onu_device is None:
            self.log.error('onu not found',
                           intf_id=onu_indication.intf_id,
                           onu_id=onu_indication.onu_id)
            return

        # We will use this alloc_id and gemport_id to pass on to the onu adapter
        pon_intf_onu_id = (onu_indication.intf_id, onu_indication.onu_id)
        alloc_id = yield self.resource_manager.get_alloc_id(pon_intf_onu_id)
        gemport_id = yield self.resource_manager.get_gemport_id(
            pon_intf_onu_id)

        if platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
                != onu_indication.intf_id:
            self.log.warn('ONU-is-on-a-different-intf-id-now',
                          previous_intf_id=platform.intf_id_from_pon_port_no(
                              onu_device.parent_port_no),
                          current_intf_id=onu_indication.intf_id)
            # FIXME - handle intf_id mismatch (ONU move?)

        if onu_device.proxy_address.onu_id != onu_indication.onu_id:
            # FIXME - handle onu id mismatch
            self.log.warn(
                'ONU-id-mismatch, can happen if both voltha and '
                'the olt rebooted',
                expected_onu_id=onu_device.proxy_address.onu_id,
                received_onu_id=onu_indication.onu_id)

        uni_no = platform.mk_uni_port_num(onu_indication.intf_id,
                                          onu_indication.onu_id)
        uni_name = self.port_name(uni_no,
                                  Port.ETHERNET_UNI,
                                  serial_number=onu_device.serial_number)

        self.log.debug('port-number-ready', uni_no=uni_no, uni_name=uni_name)

        # Admin state
        if onu_indication.admin_state == 'down':
            if onu_indication.oper_state != 'down':
                self.log.error('ONU-admin-state-down-and-oper-status-not-down',
                               oper_state=onu_indication.oper_state)
                # Forcing the oper state change code to execute
                onu_indication.oper_state = 'down'

            # Port and logical port update is taken care of by oper state block

        elif onu_indication.admin_state == 'up':
            pass

        else:
            self.log.warn('Invalid-or-not-implemented-admin-state',
                          received_admin_state=onu_indication.admin_state)

        self.log.debug('admin-state-dealt-with')

        onu_adapter_agent = \
            registry('adapter_loader').get_agent(onu_device.adapter)
        if onu_adapter_agent is None:
            self.log.error('onu_adapter_agent-could-not-be-retrieved',
                           onu_device=onu_device)
            return

        # Operating state
        if onu_indication.oper_state == 'down':

            if onu_device.connect_status != ConnectStatus.UNREACHABLE:
                onu_device.connect_status = ConnectStatus.UNREACHABLE
                self.adapter_agent.update_device(onu_device)

            # Move to discovered state
            self.log.debug('onu-oper-state-is-down')

            if onu_device.oper_status != OperStatus.DISCOVERED:
                onu_device.oper_status = OperStatus.DISCOVERED
                self.adapter_agent.update_device(onu_device)
            # Set port oper state to Discovered
            self.onu_ports_down(onu_device, uni_no, uni_name,
                                OperStatus.DISCOVERED)

            if onu_device.adapter == 'brcm_openomci_onu':
                self.log.debug('using-brcm_openomci_onu')
                onu_adapter_agent.update_interface(onu_device,
                                                   {'oper_state': 'down'})

        elif onu_indication.oper_state == 'up':

            if onu_device.connect_status != ConnectStatus.REACHABLE:
                onu_device.connect_status = ConnectStatus.REACHABLE
                self.adapter_agent.update_device(onu_device)

            if onu_device.oper_status != OperStatus.DISCOVERED:
                self.log.debug("ignore onu indication",
                               intf_id=onu_indication.intf_id,
                               onu_id=onu_indication.onu_id,
                               state=onu_device.oper_status,
                               msg_oper_state=onu_indication.oper_state)
                return

            # Device was in Discovered state, setting it to active

            # Prepare onu configuration
            # If we are  brcm_openomci adapter proceed

            if onu_device.adapter == 'brcm_openomci_onu':
                self.log.debug('using-brcm_openomci_onu')

                # tcont creation (onu)
                tcont = TcontsConfigData()
                tcont.alloc_id = alloc_id

                # gem port creation
                gem_port = GemportsConfigData()
                gem_port.gemport_id = gemport_id

                gem_port.tcont_ref = str(tcont.alloc_id)

                self.log.info('inject-tcont-gem-data-onu-handler',
                              onu_indication=onu_indication,
                              tcont=tcont,
                              gem_port=gem_port)

                onu_adapter_agent.create_tcont(onu_device,
                                               tcont,
                                               traffic_descriptor_data=None)
                onu_adapter_agent.create_gemport(onu_device, gem_port)
                onu_adapter_agent.create_interface(onu_device, onu_indication)

            else:
                self.log.error('unsupported-openolt-onu-adapter',
                               onu_adapter=onu_device.adapter)

        else:
            self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
                          oper_state=onu_indication.oper_state)
Esempio n. 6
0
    def onu_indication(self, onu_indication):
        self.log.debug("onu-indication",
                       intf_id=onu_indication.intf_id,
                       onu_id=onu_indication.onu_id,
                       serial_number=onu_indication.serial_number,
                       oper_state=onu_indication.oper_state,
                       admin_state=onu_indication.admin_state)

        serial_number_str = self.stringify_serial_number(
            onu_indication.serial_number)

        if serial_number_str == '000000000000':
            self.log.debug(
                'serial-number-was-not-provided-or-default-serial-number-provided-identifying-onu-by-onu_id'
            )
            #FIXME: if multiple PON ports onu_id is not a sufficient key
            onu_device = self.adapter_agent.get_child_device(
                self.device_id, onu_id=onu_indication.onu_id)
        else:
            onu_device = self.adapter_agent.get_child_device(
                self.device_id, serial_number=serial_number_str)

        self.log.debug('onu-device',
                       olt_device_id=self.device_id,
                       device=onu_device)

        # FIXME - handle serial_number mismatch
        # assert key is not None
        # assert onu_device is not None
        if onu_device is None:
            self.log.warn('onu-device-is-none-invalid-message')
            return

        if onu_device.connect_status != ConnectStatus.REACHABLE:
            onu_device.connect_status = ConnectStatus.REACHABLE
            self.adapter_agent.update_device(onu_device)

        if platform.intf_id_from_pon_port_no(
                onu_device.parent_port_no) != onu_indication.intf_id:
            self.log.warn('ONU-is-on-a-different-intf-id-now',
                          previous_intf_id=platform.intf_id_from_pon_port_no(
                              onu_device.parent_port_no),
                          current_intf_id=onu_indication.intf_id)
            # FIXME - handle intf_id mismatch (ONU move?)

        if onu_device.proxy_address.onu_id != onu_indication.onu_id:
            # FIXME - handle onu id mismatch
            self.log.warn('ONU-id-mismatch',
                          expected_onu_id=onu_device.proxy_address.onu_id,
                          received_onu_id=onu_indication.onu_id)

        uni_no = platform.mk_uni_port_num(onu_indication.intf_id,
                                          onu_indication.onu_id)
        uni_name = self.port_name(uni_no,
                                  Port.ETHERNET_UNI,
                                  serial_number=serial_number_str)

        self.log.debug('port-number-ready', uni_no=uni_no, uni_name=uni_name)

        #Admin state
        if onu_indication.admin_state == 'down':
            if onu_indication.oper_state != 'down':
                self.log.error('ONU-admin-state-down-and-oper-status-not-down',
                               oper_state=onu_indication.oper_state)
                onu_indication.oper_state = 'down'  # Forcing the oper state change code to execute

            if onu_device.admin_state != AdminState.DISABLED:
                onu_device.admin_state = AdminState.DISABLED
                self.adapter_agent.update(onu_device)
                self.log.debug('putting-onu-in-disabled-state',
                               onu_serial_number=onu_device.serial_number)

            #Port and logical port update is taken care of by oper state block

        elif onu_indication.admin_state == 'up':
            if onu_device.admin_state != AdminState.ENABLED:
                onu_device.admin_state = AdminState.ENABLED
                self.adapter_agent.update(onu_device)
                self.log.debug('putting-onu-in-enabled-state',
                               onu_serial_number=onu_device.serial_number)

        else:
            self.log.warn('Invalid-or-not-implemented-admin-state',
                          received_admin_state=onu_indication.admin_state)

        self.log.debug('admin-state-dealt-with')

        #Operating state
        if onu_indication.oper_state == 'down':
            #Move to discovered state
            self.log.debug('onu-oper-state-is-down')

            if onu_device.oper_status != OperStatus.DISCOVERED:
                onu_device.oper_status = OperStatus.DISCOVERED
                self.adapter_agent.update_device(onu_device)
            #Set port oper state to Discovered

            self.onu_ports_down(onu_device, uni_no, uni_name,
                                OperStatus.DISCOVERED)

        elif onu_indication.oper_state == 'up':

            if onu_device.oper_status != OperStatus.DISCOVERED:
                self.log.debug("ignore onu indication",
                               intf_id=onu_indication.intf_id,
                               onu_id=onu_indication.onu_id,
                               state=onu_device.oper_status,
                               msg_oper_state=onu_indication.oper_state)
                return

            #Device was in Discovered state, setting it to active

            onu_adapter_agent = registry('adapter_loader').get_agent(
                onu_device.adapter)
            if onu_adapter_agent is None:
                self.log.error('onu_adapter_agent-could-not-be-retrieved',
                               onu_device=onu_device)
                return

            #Prepare onu configuration

            # onu initialization, base configuration (bridge setup ...)
            def onu_initialization():

                #FIXME: that's definitely cheating
                if onu_device.adapter == 'broadcom_onu':
                    onu_adapter_agent.adapter.devices_handlers[
                        onu_device.id].message_exchange()
                    self.log.debug('broadcom-message-exchange-started')

            # tcont creation (onu)
            tcont = TcontsConfigData()
            tcont.alloc_id = platform.mk_alloc_id(onu_indication.onu_id)

            # gem port creation
            gem_port = GemportsConfigData()
            gem_port.gemport_id = platform.mk_gemport_id(onu_indication.onu_id)

            #ports creation/update
            def port_config():

                # "v_enet" creation (olt)

                #add_port update port when it exists
                self.adapter_agent.add_port(
                    self.device_id,
                    Port(port_no=uni_no,
                         label=uni_name,
                         type=Port.ETHERNET_UNI,
                         admin_state=AdminState.ENABLED,
                         oper_status=OperStatus.ACTIVE))

                # v_enet creation (onu)

                venet = VEnetConfig(name=uni_name)
                venet.interface.name = uni_name
                onu_adapter_agent.create_interface(onu_device, venet)

            # ONU device status update in the datastore
            def onu_update_oper_status():
                onu_device.oper_status = OperStatus.ACTIVE
                onu_device.connect_status = ConnectStatus.REACHABLE
                self.adapter_agent.update_device(onu_device)

            # FIXME : the asynchronicity has to be taken care of properly
            onu_initialization()
            reactor.callLater(10,
                              onu_adapter_agent.create_tcont,
                              device=onu_device,
                              tcont_data=tcont,
                              traffic_descriptor_data=None)
            reactor.callLater(11, onu_adapter_agent.create_gemport, onu_device,
                              gem_port)
            reactor.callLater(12, port_config)
            reactor.callLater(12, onu_update_oper_status)

        else:
            self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
                          oper_state=onu_indication.oper_state)