Esempio n. 1
0
    def proxy_address(self):
        if self._proxy_address is None:
            from voltha.protos.device_pb2 import Device

            device_id = self.olt.device_id

            if self.olt.autoactivate:
                self._proxy_address = Device.ProxyAddress(
                    device_id=device_id,
                    channel_id=self.onu_vid,
                    channel_group_id=self.pon.pon_id,
                    onu_id=self.onu_id)
            else:
                try:
                    v_ont_ani = self._vont_ani
                    voltha_core = self.olt.adapter_agent.core
                    xpon_agent = voltha_core.xpon_agent
                    channel_group_id = xpon_agent.get_channel_group_for_vont_ani(
                        v_ont_ani)
                    parent_chnl_pair_id = xpon_agent.get_port_num(
                        device_id, v_ont_ani.data.preferred_chanpair)
                    self._proxy_address = Device.ProxyAddress(
                        device_id=device_id,
                        channel_group_id=channel_group_id,
                        channel_id=parent_chnl_pair_id,
                        channel_termination=v_ont_ani.data.preferred_chanpair,
                        onu_id=self.onu_id,
                        onu_session_id=self.onu_id)
                except Exception:
                    pass

        return self._proxy_address
Esempio n. 2
0
    def _detect_onus(self, device):
        # send out get 'links' to the OLT device
        olt_mac = device.mac_address
        links_frame = self._make_links_frame(mac_address=olt_mac)
        self.io_port.send(links_frame)
        while True:
            response = yield self.incoming_queues[olt_mac].get()
            # verify response and if not the expected response
            if 1: # TODO check if it is really what we expect, and wait if not
                break

        jdev = json.loads(response.payload.payload.body.load)
        onu_mac = ''
        for macid in jdev['results']:
            if macid['macid'] is None:
                log.info('MAC ID is NONE %s' % str(macid['macid']))
            elif macid['macid'][:6].upper() == SUMITOMO_ELECTRIC_INDUSTRIES_OUI:
                onu_mac = macid['macid']
                log.info('SUMITOMO mac address %s' % str(macid['macid']))
                log.info('activate-olt-for-onu-%s' % onu_mac)
                # Convert from string to colon separated form
                onu_mac = ':'.join(s.encode('hex') for s in onu_mac.decode('hex'))
                vlan_id = self._olt_side_onu_activation(int(macid['macid'][-4:-2], 16))
                self.adapter_agent.child_device_detected(
                    parent_device_id=device.id,
                    parent_port_no=1,
                    child_device_type='dpoe_onu',
                    mac_address = onu_mac,
                    proxy_address=Device.ProxyAddress(
                        device_id=device.id,
                        channel_id=vlan_id
                        ),
                        vlan=vlan_id
                    )

            else:
                onu_mac = '000c' + macid.get('macid', 'e2000000')[4:]
                log.info('activate-olt-for-onu-%s' % onu_mac)
                # Convert from string to colon separated form
                onu_mac = ':'.join(s.encode('hex') for s in onu_mac.decode('hex'))
                vlan_id = self._olt_side_onu_activation(int(macid['macid'][-4:-2], 16))
                self.adapter_agent.child_device_detected(
                    parent_device_id=device.id,
                    parent_port_no=1,
                    child_device_type='tibit_onu',
                    mac_address = onu_mac,
                    proxy_address=Device.ProxyAddress(
                        device_id=device.id,
                        channel_id=vlan_id
                        ),
                        vlan=vlan_id
                    )

            # also record the vlan_id -> (device_id, logical_device_id, linkid) for
            # later use.  The linkid is the macid returned.
            self.vlan_to_device_ids[vlan_id] = (device.id, device.parent_id, macid.get('macid', 0))

        # Give the ONUs a chance to arrive before starting metric collection
        reactor.callLater(5.0, self.start_kpi_collection, device.id)
Esempio n. 3
0
    def add_onu_device(self, intf_id, port_no, onu_id, serial_number):
        self.log.info("Adding ONU",
                      port_no=port_no,
                      onu_id=onu_id,
                      serial_number=serial_number)

        # NOTE - channel_id of onu is set to intf_id
        proxy_address = Device.ProxyAddress(device_id=self.device_id,
                                            channel_id=intf_id,
                                            onu_id=onu_id,
                                            onu_session_id=onu_id)

        self.log.debug("Adding ONU", proxy_address=proxy_address)

        serial_number_str = self.stringify_serial_number(serial_number)

        self.adapter_agent.add_onu_device(
            parent_device_id=self.device_id,
            parent_port_no=port_no,
            vendor_id=serial_number.vendor_id,
            proxy_address=proxy_address,
            root=True,
            serial_number=serial_number_str,
            admin_state=AdminState.
            ENABLED  #, **{'vlan':4091} # magic still maps to brcm_openomci_onu.pon_port.BRDCM_DEFAULT_VLAN
        )
Esempio n. 4
0
    def add_onu_device(self, intf_id, port_no, onu_id, serial_number):

        self.log.info("Adding ONU",
                      port_no=port_no,
                      onu_id=onu_id,
                      serial_number=serial_number)

        # NOTE - channel_id of onu is set to intf_id
        proxy_address = Device.ProxyAddress(device_id=self.device_id,
                                            channel_id=intf_id,
                                            onu_id=onu_id,
                                            onu_session_id=onu_id)

        self.log.info("Adding ONU", proxy_address=proxy_address)

        serial_number_str = ''.join([
            serial_number.vendor_id,
            self.stringify_vendor_specific(serial_number.vendor_specific)
        ])

        self.adapter_agent.add_onu_device(
            parent_device_id=self.device_id,
            parent_port_no=port_no,
            vendor_id=serial_number.vendor_id,
            proxy_address=proxy_address,
            root=True,
            serial_number=serial_number_str,
            admin_state=AdminState.ENABLED)  # FIXME
Esempio n. 5
0
    def onu_create(self, intf_id, onu_id, serial_number):
        onu_device = self.adapter_agent.get_child_device(
            self.device.id, serial_number=serial_number)

        if onu_device:
            self.log.debug("data_model onu update",
                           intf_id=intf_id,
                           onu_id=onu_id,
                           serial_number=serial_number,
                           oper_state=onu_device.oper_status)
            if onu_device.oper_status == OperStatus.UNKNOWN:
                # olt reboot
                self.log.debug("onu active or activating",
                               intf_id=intf_id,
                               onu_id=onu_id,
                               serial_number=serial_number,
                               oper_state=onu_device.oper_status)
                onu_device.oper_status = OperStatus.DISCOVERED
                onu_device.connect_status = ConnectStatus.REACHABLE
                self.adapter_agent.update_device(onu_device)
            else:
                # onu activating
                self.log.debug("onu active or activating",
                               intf_id=intf_id,
                               onu_id=onu_id,
                               serial_number=serial_number,
                               oper_state=onu_device.oper_status)
                raise ValueError
            return

        self.log.debug("data_model onu create",
                       intf_id=intf_id,
                       onu_id=onu_id,
                       serial_number=serial_number)

        # NOTE - channel_id of onu is set to intf_id
        proxy_address = Device.ProxyAddress(device_id=self.device.id,
                                            channel_id=intf_id,
                                            onu_id=onu_id,
                                            onu_session_id=onu_id)
        port_no = self.platform.intf_id_to_port_no(intf_id, Port.PON_OLT)
        vendor_id = serial_number[:4]
        self.adapter_agent.add_onu_device(
            parent_device_id=self.device.id,
            parent_port_no=port_no,
            vendor_id=vendor_id,
            proxy_address=proxy_address,
            root=False,
            serial_number=serial_number,
            admin_state=AdminState.ENABLED,
            connect_status=ConnectStatus.REACHABLE)

        # Add onu info to cache
        onu_info = OnuInfo(intf_id=intf_id,
                           onu_id=onu_id,
                           serial_number=serial_number)
        self._onu_ids[OnuId(intf_id=intf_id, onu_id=onu_id)] = onu_info
        self._onu_serial_numbers[serial_number] = onu_info
Esempio n. 6
0
    def proxy_address(self):
        if self._proxy_address is None:
            from voltha.protos.device_pb2 import Device

            device_id = self.olt.device_id
            self._proxy_address = Device.ProxyAddress(
                device_id=device_id,
                channel_id=self.pon.port_no,
                onu_id=self.onu_id,
                onu_session_id=self.onu_id)
        return self._proxy_address
Esempio n. 7
0
 def onu_detected(self,
                  parent_port_no=None,
                  child_device_type=None,
                  onu_id=None):
     self.adapter_agent.child_device_detected(
         parent_device_id=self.device.id,
         parent_port_no=parent_port_no,
         child_device_type=child_device_type,
         proxy_address=Device.ProxyAddress(device_id=self.device.id,
                                           channel_id=onu_id),
         vlan=0)
Esempio n. 8
0
 def _simulate_detection_of_onus(self, device_id):
     for i in xrange(1, 5):
         log.info('activate-olt-for-onu-{}'.format(i))
         vlan_id = self._olt_side_onu_activation(i)
         yield asleep(0.05)
         self.adapter_agent.child_device_detected(
             parent_device_id=device_id,
             parent_port_no=1,
             child_device_type='simulated_onu',
             proxy_address=Device.ProxyAddress(device_id=device_id,
                                               channel_id=vlan_id),
             vlan=vlan_id)
Esempio n. 9
0
 def deactivate_onu(self, onu_id=None, channel_id=None, onu_session_id=None):
     try:
         child_device = self.adapter_agent.get_child_device_with_proxy_address(Device.ProxyAddress(
             device_id=self.device.id,
             channel_id=channel_id,
             onu_id=onu_id,
             onu_session_id=onu_session_id
         ))
         if child_device:
             # self.adapter_agent.update_child_device_state(child_device, admin_state=AdminState.DISABLED)
             child_device.admin_state=AdminState.DISABLED
             self.adapter_agent.update_device(child_device)
     except KeyError:
         log.debug("ONU {} cannot be deactivated".format(onu_id))
Esempio n. 10
0
 def _simulate_detection_of_onus(self, device_id):
     try:
         for i in xrange(1, 5):
             log.info('activate-olt-for-onu-{}'.format(i))
             vlan_id = self._olt_side_onu_activation(i)
             yield asleep(0.05)
             self.adapter_agent.child_device_detected(
                 parent_device_id=device_id,
                 parent_port_no=1,
                 child_device_type='simulated_onu',
                 proxy_address=Device.ProxyAddress(device_id=device_id,
                                                   channel_id=vlan_id),
                 admin_state=AdminState.ENABLED,
                 vlan=vlan_id)
     except Exception as e:
         log.exception('error', e=e)
Esempio n. 11
0
    def __init__(self, onu_info):
        self._onu_id = onu_info['onu-id']
        if self._onu_id is None:
            raise ValueError('No ONU ID available')

        pon = onu_info['pon']
        self._olt = pon.olt
        self._pon_id = pon.pon_id
        self._name = '{}@{}'.format(pon.physical_port_name, self._onu_id)
        self.log = structlog.get_logger(pon_id=self._pon_id,
                                        onu_id=self._onu_id)

        self._valid = True  # Set false during delete/cleanup
        self._serial_number_base64 = Onu.string_to_serial_number(
            onu_info['serial-number'])
        self._serial_number_string = onu_info['serial-number']
        self._device_id = onu_info['device-id']
        self._password = onu_info['password']

        self._created = False
        self._proxy_address = Device.ProxyAddress(
            device_id=self.olt.device_id,
            channel_id=self.olt.pon_id_to_port_number(self._pon_id),
            onu_id=self._onu_id,
            onu_session_id=self._onu_id)
        self._sync_tick = _HW_SYNC_SECS
        self._expedite_sync = False
        self._expedite_count = 0
        self._resync_flows = False
        self._sync_deferred = None  # For sync of ONT config to hardware

        # Resources
        self._gem_ports = {}  # gem-id -> GemPort
        self._tconts = {}  # alloc-id -> TCont
        self._uni_ports = onu_info['uni-ports']

        # Provisionable items
        self._enabled = onu_info['enabled']
        self._upstream_fec_enable = onu_info.get('upstream-fec')
        self._upstream_channel_speed = onu_info['upstream-channel-speed']
        # TODO: how do we want to enforce upstream channel speed (if at all)?

        # KPI related items
        self._rssi = -9999
        self._equalization_delay = 0
        self._fiber_length = 0
        self._timestamp = None  # Last time the KPI items were updated
Esempio n. 12
0
    def on_new_onu_discovered(self, onu):
        """
        Called when a new ONU is discovered and VOLTHA device adapter needs to be informed
        :param onu: 
        :return: 
        """
        olt = self.parent
        adapter = olt.adapter_agent

        proxy = Device.ProxyAddress(device_id=olt.device_id,
                                    channel_id=self.port_number,
                                    onu_id=onu.onu_id)

        adapter.child_device_detected(parent_device_id=olt.device_id,
                                      parent_port_no=self.port_number,
                                      child_device_type=onu.vendor_device,
                                      proxy_address=proxy)
Esempio n. 13
0
 def onu_detected(self,
                  parent_port_no=None,
                  child_device_type=None,
                  onu_id=None,
                  serial_number=None,
                  onu_session_id=None):
     self.adapter_agent.child_device_detected(
         parent_device_id=self.device.id,
         parent_port_no=parent_port_no,
         child_device_type=child_device_type,
         serial_number=serial_number,
         proxy_address=Device.ProxyAddress(
             device_id=self.device.id,
             channel_id=
             parent_port_no,  # happens to be the channel id as well
             onu_id=onu_id,
             onu_session_id=onu_session_id),
         vlan=0)
Esempio n. 14
0
    def activate_onu(self, onu):
        """
        Called when a new ONU is discovered and VOLTHA device adapter needs to be informed
        :param onu: 
        :return: 
        """
        olt = self.olt
        adapter = self.adapter_agent
        channel_id = onu.onu_vid

        proxy = Device.ProxyAddress(device_id=olt.device_id, channel_id=channel_id)

        adapter.child_device_detected(parent_device_id=olt.device_id,
                                      parent_port_no=self._port_no,
                                      child_device_type=onu.vendor_id,
                                      proxy_address=proxy,
                                      admin_state=AdminState.ENABLED,
                                      vlan=channel_id)
Esempio n. 15
0
 def deactivate_onu(self, onu_id=None, channel_id=None, onu_session_id=None):
     try:
         child_device = self.adapter_agent.get_child_device_with_proxy_address(Device.ProxyAddress(
             device_id=self.device.id,
             channel_id=channel_id,
             onu_id=onu_id,
             onu_session_id=onu_session_id
         ))
         # self.adapter_agent.delete_child_device(self.device.id, child_device)
         if child_device:
             child_device.admin_state = AdminState.DISABLED
             # self.adapter_agent._make_up_to_date('/devices', child_device.id, child_device)
             reactor.callLater(0, self.adapter_agent._make_up_to_date,
                 '/devices', child_device.id, child_device)
             #child_device.admin_state=AdminState.DISABLED
             #self.adapter_agent.update_device(child_device)
     except Exception:
         log.debug("ONU {} cannot be deactivated".format(onu_id))
Esempio n. 16
0
    def delete_onu(self, onu_id):
        uri = AdtranOltHandler.GPON_ONU_CONFIG_URI.format(self._pon_id, onu_id)
        name = 'pon-delete-onu-{}-{}'.format(self._pon_id, onu_id)

        onu = self._onu_by_id.get(onu_id)

        # Remove from any local dictionary
        if onu_id in self._onu_by_id:
            del self._onu_by_id[onu_id]
        for sn in [
                onu.serial_numbers for onu in self._onus.itervalues()
                if onu.onu_id == onu_id
        ]:
            del self._onus[sn]
        try:
            yield self._parent.rest_client.request('DELETE', uri, name=name)

        except Exception as e:
            self.log.exception('onu', serial_number=onu.serial_number, e=e)

        if onu is not None:
            # Clean up adapter agent of this ONU

            proxy = Device.ProxyAddress(device_id=self.olt.device_id,
                                        channel_id=onu.channel_id)
            onu_device = self.olt.adapter_agent.get_child_device_with_proxy_address(
                proxy)

            if onu_device is not None:
                self.olt.adapter_agent.delete_child_device(
                    self.olt.device_id, onu_device.device_id)

        self.olt.adapter_agent.update_child_devices_state(
            self.olt.device_id, admin_state=AdminState.DISABLED)

        def delete_child_device(self, parent_device_id, child_device_id):
            onu_device = self.root_proxy.get(
                '/devices/{}'.format(child_device_id))
            if onu_device is not None:
                if onu_device.parent_id == parent_device_id:
                    self.log.debug('deleting-child-device',
                                   parent_device_id=parent_device_id,
                                   child_device_id=child_device_id)
                    self._remove_node('/devices', child_device_id)
Esempio n. 17
0
    def rx_packet(self, message):
        try:
            self.log.debug('rx_packet')

            pon_id, onu_id, msg, is_omci = AdtranZmqClient.decode_packet(message)

            if is_omci:
                proxy_address = Device.ProxyAddress(device_id=self.device_id,
                                                    channel_id=self.get_channel_id(pon_id, onu_id),
                                                    onu_id=onu_id)

                self.adapter_agent.receive_proxied_message(proxy_address, msg)
            else:
                pass  # TODO: Packet in support not yet supported
                # self.adapter_agent.send_packet_in(logical_device_id=logical_device_id,
                #                                   logical_port_no=cvid,  # C-VID encodes port no
                #                                   packet=str(msg))
        except Exception as e:
            self.log.exception('rx_packet', e=e)
Esempio n. 18
0
    def onu_detected(self, parent_port_no=None,
                     child_device_type=None,
                     onu_id=None,
                     serial_number=None,
                     onu_session_id=None,
                     channel_id=None):
        log.debug('onu-detected')
        try:
            # self.adapter_agent.child_device_detected(
            #     parent_device_id=self.device.id,
            #     parent_port_no=parent_port_no,
            #     child_device_type=child_device_type,
            #     serial_number=serial_number,
            #     proxy_address=Device.ProxyAddress(
            #         device_id=self.device.id,
            #         channel_id=channel_id,  # happens to be the channel id as well
            #         onu_id=onu_id,
            #         onu_session_id=onu_session_id
            #     ),
            #     admin_state=AdminState.ENABLED,
            #     vlan=0)
            reactor.callLater(0, self.adapter_agent.child_device_detected,
                parent_device_id=self.device.id,
                parent_port_no=parent_port_no,
                child_device_type=child_device_type,
                serial_number=serial_number,
                proxy_address=Device.ProxyAddress(
                    device_id=self.device.id,
                    channel_id=channel_id,  # happens to be the channel id as well
                    onu_id=onu_id,
                    onu_session_id=onu_session_id
                ),
                admin_state=AdminState.ENABLED,
                vlan=0)

        except Exception as e:
            log.exception('onu-detected-failed', e=e)
            raise e
Esempio n. 19
0
 def create_onu_device(self, device, v_ont_ani):
     log.info('create-onu-device', device_id=device.id, v_ont_ani=v_ont_ani)
     adapter_agent = self.get_device_adapter_agent(device)
     parent_chnl_pair_id = self.get_port_num(
         device.id, v_ont_ani.data.preferred_chanpair)
     log.info('create-onu-device:', parent_chnl_pair_id=parent_chnl_pair_id)
     vendor_id = v_ont_ani.data.expected_serial_number[:4]
     proxy_address = Device.ProxyAddress(
         device_id=device.id,
         channel_group_id=self.get_channel_group_for_vont_ani(v_ont_ani),
         channel_id=parent_chnl_pair_id,
         channel_termination=v_ont_ani.data.preferred_chanpair,
         onu_id=v_ont_ani.data.onu_id,
         onu_session_id=v_ont_ani.data.onu_id)
     adapter_agent.add_onu_device(
         parent_device_id=device.id,
         parent_port_no=parent_chnl_pair_id,
         vendor_id=vendor_id,
         proxy_address=proxy_address,
         root=True,
         serial_number=v_ont_ani.data.expected_serial_number,
         admin_state=AdminState.ENABLED
         if v_ont_ani.interface.enabled else AdminState.PREPROVISIONED)
     return
    def test_subsribe_to_proxy_child_messages(self, mock_set_adapter_agent,
                                              mock_delete_device):

        # Add OLT
        olt_device = Device(id='olt',
                            root=True,
                            parent_id='id',
                            type='asfvolt16_olt')
        self.adapter_agent_olt.add_device(olt_device)

        # Initially when no ONUs are attached to the OLT, the tx_event_subscriptions
        # should be 0
        self.assertEqual(len(self.adapter_agent_olt._tx_event_subscriptions),
                         0)

        # Add 1st ONU to the OLT
        onu1_proxy_address = Device.ProxyAddress(device_id='olt',
                                                 channel_id=1,
                                                 onu_id=1,
                                                 onu_session_id=1)
        self.adapter_agent_olt.add_onu_device('olt', 1, "BRCM",
                                              onu1_proxy_address,
                                              AdminState.UNKNOWN)

        # The tx_event_subscriptions should increment to 1 after adding 1st ONU
        self.assertEqual(len(self.adapter_agent_olt._tx_event_subscriptions),
                         1)

        # Add 2nd ONU to the OLT
        onu2_proxy_address = Device.ProxyAddress(device_id='olt',
                                                 channel_id=2,
                                                 onu_id=2,
                                                 onu_session_id=2)
        self.adapter_agent_olt.add_onu_device('olt', 1, "BRCM",
                                              onu2_proxy_address,
                                              AdminState.UNKNOWN)

        # The tx_event_subscriptions should increment to 2 after adding 2nd ONU
        self.assertEqual(len(self.adapter_agent_olt._tx_event_subscriptions),
                         2)

        # Remove one ONU
        children = self.adapter_agent_olt.get_child_devices('olt')
        self.assertEqual(len(children), 2)
        for child in children:
            self.adapter_agent_olt.delete_child_device('olt', child.id)
            break

        # The tx_event_subscriptions should decrement to 1 after removing one ONU
        self.assertEqual(len(self.adapter_agent_olt._tx_event_subscriptions),
                         1)

        # Add new ONU to the OLT. The total ONUs on the OLT are now 2
        onu3_proxy_address = Device.ProxyAddress(device_id='olt',
                                                 channel_id=3,
                                                 onu_id=3,
                                                 onu_session_id=3)
        self.adapter_agent_olt.add_onu_device('olt', 1, "BRCM",
                                              onu3_proxy_address,
                                              AdminState.UNKNOWN)

        # The tx_event_subscriptions should increment to 2 after adding another ONU
        self.assertEqual(len(self.adapter_agent_olt._tx_event_subscriptions),
                         2)

        # delete all child devices (ONUs)
        self.adapter_agent_olt.delete_all_child_devices('olt')

        # There should be no tx_event_subscriptions after deleting all child devices (ONUs)
        self.assertEqual(len(self.adapter_agent_olt._tx_event_subscriptions),
                         0)
Esempio n. 21
0
    def activate(self, device):
        self.log.info('activating')

        if not device.host_and_port:
            device.oper_status = OperStatus.FAILED
            device.reason = 'No host_and_port field provided'
            self.adapter_agent.update_device(device)
            return

        stub = ponsim_pb2.PonSimStub(self.get_channel())
        info = stub.GetDeviceInfo(Empty())
        log.info('got-info', info=info)

        device.root = True
        device.vendor = 'ponsim'
        device.model = 'n/a'
        device.serial_number = device.host_and_port
        device.connect_status = ConnectStatus.REACHABLE
        self.adapter_agent.update_device(device)

        # Now set the initial PM configuration for this device
        self.pm_metrics = AdapterPmMetrics(device)
        pm_config = self.pm_metrics.make_proto()
        log.info("initial-pm-config", pm_config=pm_config)
        self.adapter_agent.update_device_pm_config(pm_config, init=True)

        # Setup alarm handler
        self.alarms = AdapterAlarms(self.adapter, device)

        nni_port = Port(
            port_no=2,
            label='NNI facing Ethernet port',
            type=Port.ETHERNET_NNI,
            admin_state=AdminState.ENABLED,
            oper_status=OperStatus.ACTIVE
        )
        self.nni_port = nni_port
        self.adapter_agent.add_port(device.id, nni_port)
        self.adapter_agent.add_port(device.id, Port(
            port_no=1,
            label='PON port',
            type=Port.PON_OLT,
            admin_state=AdminState.ENABLED,
            oper_status=OperStatus.ACTIVE
        ))

        ld = LogicalDevice(
            # not setting id and datapth_id will let the adapter agent pick id
            desc=ofp_desc(
                mfr_desc='cord porject',
                hw_desc='simualted pon',
                sw_desc='simualted pon',
                serial_num=uuid4().hex,
                dp_desc='n/a'
            ),
            switch_features=ofp_switch_features(
                n_buffers=256,  # TODO fake for now
                n_tables=2,  # TODO ditto
                capabilities=(  # TODO and ditto
                    OFPC_FLOW_STATS
                    | OFPC_TABLE_STATS
                    | OFPC_PORT_STATS
                    | OFPC_GROUP_STATS
                )
            ),
            root_device_id=device.id
        )
        ld_initialized = self.adapter_agent.create_logical_device(ld)
        cap = OFPPF_1GB_FD | OFPPF_FIBER
        self.ofp_port_no = info.nni_port
        self.adapter_agent.add_logical_port(ld_initialized.id, LogicalPort(
            id='nni',
            ofp_port=ofp_port(
                port_no=info.nni_port,
                hw_addr=mac_str_to_tuple(
                    '00:00:00:00:00:%02x' % info.nni_port),
                name='nni',
                config=0,
                state=OFPPS_LIVE,
                curr=cap,
                advertised=cap,
                peer=cap,
                curr_speed=OFPPF_1GB_FD,
                max_speed=OFPPF_1GB_FD
            ),
            device_id=device.id,
            device_port_no=nni_port.port_no,
            root_port=True
        ))

        device = self.adapter_agent.get_device(device.id)
        device.parent_id = ld_initialized.id
        device.oper_status = OperStatus.ACTIVE
        self.adapter_agent.update_device(device)
        self.logical_device_id = ld_initialized.id

        # register ONUS per uni port
        for port_no in info.uni_ports:
            vlan_id = port_no
            self.adapter_agent.child_device_detected(
                parent_device_id=device.id,
                parent_port_no=1,
                child_device_type='ponsim_onu',
                proxy_address=Device.ProxyAddress(
                    device_id=device.id,
                    channel_id=vlan_id
                ),
                vlan=vlan_id
            )

        # finally, open the frameio port to receive in-band packet_in messages
        self.log.info('registering-frameio')
        self.io_port = registry('frameio').open_port(
            self.interface, self.rcv_io, is_inband_frame)
        self.log.info('registered-frameio')

        # Start collecting stats from the device after a brief pause
        self.start_kpi_collection(device.id)
Esempio n. 22
0
    def _rcv_io(self, port, frame):

        log.info('frame-received', frame=hexify(frame))

        # make into frame to extract source mac
        response = Ether(frame)

        if response.haslayer(Dot1Q):

            # All OAM responses from the OLT should have a TIBIT_MGMT_VLAN.
            # Responses from the ONUs should have a TIBIT_MGMT_VLAN followed by a ONU CTAG
            # All packet-in frames will have the TIBIT_PACKET_IN_VLAN.
            if response.getlayer(Dot1Q).type == 0x8100:

                if response.getlayer(Dot1Q).vlan == TIBIT_PACKET_IN_VLAN:

                    inner_tag_and_rest = response.payload.payload

                    if isinstance(inner_tag_and_rest, Dot1Q):

                        cvid = inner_tag_and_rest.vlan

                        frame = Ether(src=response.src,
                                      dst=response.dst,
                                      type=inner_tag_and_rest.type) /\
                                      inner_tag_and_rest.payload

                        _, logical_device_id = self.vlan_to_device_ids.get(cvid)
                        if logical_device_id is None:
                            log.error('invalid-cvid', cvid=cvid)
                        else:
                            self.adapter_agent.send_packet_in(
                                logical_device_id=logical_device_id,
                                logical_port_no=cvid,  # C-VID encodes port no
                                packet=str(frame))

                    else:
                        log.error('packet-in-single-tagged',
                                  frame=hexify(response))

                else:
                    ## Mgmt responses received from the ONU
                    ## Since the type of the first layer is 0x8100,
                    ## then the frame must have an inner tag layer
                    olt_mac = response.src
                    device_id = self.device_ids[olt_mac]
                    channel_id = response[Dot1Q:2].vlan
                    log.info('received_channel_id', channel_id=channel_id,
                             device_id=device_id)

                    proxy_address=Device.ProxyAddress(
                        device_id=device_id,
                        channel_id=channel_id
                        )
                    # pop dot1q header(s)
                    msg = response.payload.payload
                    self.adapter_agent.receive_proxied_message(proxy_address, msg)

            else:
                ## Mgmt responses received from the OLT
                ## enqueue incoming parsed frame to right device
                log.info('received-dot1q-not-8100')
                self.incoming_queues[response.src].put(response)
Esempio n. 23
0
    def _detect_onus(self, device):
        # send out get 'links' to the OLT device
        olt_mac = device.mac_address
        links_frame = self._make_links_frame(mac_address=olt_mac)
        self.io_port.send(links_frame)
        while True:
            response = yield self.incoming_queues[olt_mac].get()
            # verify response and if not the expected response
            if 1:  # TODO check if it is really what we expect, and wait if not
                break

        jdev = json.loads(response.payload.payload.body.load)
        onu_mac = ''
        for macid in jdev['results']:
            if macid['macid'] is None:
                log.info('MAC ID is NONE %s' % str(macid['macid']))
            elif macid['macid'][:6].upper(
            ) == SUMITOMO_ELECTRIC_INDUSTRIES_OUI:
                onu_mac = macid['macid']
                log.info('SUMITOMO mac address %s' % str(macid['macid']))
                log.info('activate-olt-for-onu-%s' % onu_mac)
                # Convert from string to colon separated form
                onu_mac = ':'.join(
                    s.encode('hex') for s in onu_mac.decode('hex'))
                vlan_id = self._olt_side_onu_activation(
                    int(macid['macid'][-4:-2], 16))
                self.adapter_agent.child_device_detected(
                    parent_device_id=device.id,
                    parent_port_no=1,
                    child_device_type='dpoe_onu',
                    mac_address=onu_mac,
                    proxy_address=Device.ProxyAddress(device_id=device.id,
                                                      channel_id=vlan_id),
                    vlan=vlan_id)

            else:
                onu_mac_string = '000c' + macid.get('macid', 'e2000000')[4:]
                log.info('activate-olt-for-onu-%s' % onu_mac)
                # Convert from string to colon separated form
                onu_mac = ':'.join(
                    s.encode('hex') for s in onu_mac_string.decode('hex'))
                serial_num = int(macid['macid'][-4:-2], 16)
                vlan_id = self._olt_side_onu_activation(serial_num)
                self.adapter_agent.child_device_detected(
                    parent_device_id=device.id,
                    parent_port_no=1,
                    child_device_type='tibit_onu',
                    mac_address=onu_mac,
                    proxy_address=Device.ProxyAddress(device_id=device.id,
                                                      channel_id=vlan_id),
                    vlan=vlan_id)

                ## Automatically setup default downstream control frames flow (in this case VLAN 4000)
                Clause = {v: k for k, v in ClauseSubtypeEnum.iteritems()}
                Operator = {v: k for k, v in RuleOperatorEnum.iteritems()}
                packet_out_rule = (
                    Ether(dst=device.mac_address) /
                    Dot1Q(vlan=TIBIT_MGMT_VLAN, prio=TIBIT_MGMT_PRIORITY) /
                    EOAMPayload(
                        body=CablelabsOUI() / DPoEOpcode_SetRequest() /
                        NetworkToNetworkPortObject() /
                        PortIngressRuleHeader(precedence=13) /
                        PortIngressRuleClauseMatchLength02(
                            fieldcode=Clause['C-VLAN Tag'],
                            fieldinstance=0,
                            operator=Operator['=='],
                            match=TIBIT_PACKET_OUT_VLAN) /
                        PortIngressRuleClauseMatchLength02(
                            fieldcode=Clause['C-VLAN Tag'],
                            fieldinstance=1,
                            operator=Operator['=='],
                            match=vlan_id) / PortIngressRuleResultOLTQueue(
                                unicastvssn="TBIT",
                                unicastlink=int(onu_mac_string[4:], 16)) /
                        PortIngressRuleResultForward() /
                        PortIngressRuleResultDelete(
                            fieldcode=Clause['C-VLAN Tag']) /
                        PortIngressRuleTerminator() / AddPortIngressRule()))

                self.io_port.send(str(packet_out_rule))
                while True:
                    response = yield self.incoming_queues[olt_mac].get()
                    # verify response and if not the expected response
                    if 1:  # TODO check if it is really what we expect, and wait if not
                        break

            # also record the vlan_id -> (device_id, logical_device_id, linkid) for
            # later use.  The linkid is the macid returned.
            self.vlan_to_device_ids[vlan_id] = (device.id, device.parent_id,
                                                macid.get('macid', 0))
Esempio n. 24
0
    def activate(self, device):
        self.log.info('activating')

        if not device.ipv4_address:
            device.oper_status = OperStatus.FAILED
            device.reason = 'No ipv4_address field provided'
            self.adapter_agent.update_device(device)
            return

        self.log.info('initiating-connection-to-olt',
                      device_id=device.id,
                      ipv4=device.ipv4_address,
                      port=self.pbc_port)
        reactor.connectTCP(device.ipv4_address, self.pbc_port,
                           self.pbc_factory)
        try:
            self.channel = yield self.pbc_factory.getRootObject()
            self.log.info('connected-to-olt',
                          device_id=device.id,
                          ipv4=device.ipv4_address,
                          port=self.pbc_port)
        except Exception as e:
            self.log.info('get-channel-exception', exc=str(e))

        yield self.send_set_remote()
        yield self.send_connect_olt(0)
        yield self.send_activate_olt(0)

        device.root = True
        device.vendor = 'Broadcom'
        device.model = 'bcm68620'
        device.serial_number = device.ipv4_address
        device.connect_status = ConnectStatus.REACHABLE
        self.adapter_agent.update_device(device)

        nni_port = Port(port_no=2,
                        label='NNI facing Ethernet port',
                        type=Port.ETHERNET_NNI,
                        admin_state=AdminState.ENABLED,
                        oper_status=OperStatus.ACTIVE)
        self.adapter_agent.add_port(device.id, nni_port)
        self.adapter_agent.add_port(
            device.id,
            Port(port_no=1,
                 label='PON port',
                 type=Port.PON_OLT,
                 admin_state=AdminState.ENABLED,
                 oper_status=OperStatus.ACTIVE))

        ld = LogicalDevice(
            # not setting id and datapth_id will let the adapter agent pick id
            desc=ofp_desc(mfr_desc='cord project',
                          hw_desc='n/a',
                          sw_desc='logical device for Maple-based PON',
                          serial_num=uuid4().hex,
                          dp_desc='n/a'),
            switch_features=ofp_switch_features(
                n_buffers=256,  # TODO fake for now
                n_tables=2,  # TODO ditto
                capabilities=(  # TODO and ditto
                    OFPC_FLOW_STATS
                    | OFPC_TABLE_STATS
                    | OFPC_PORT_STATS
                    | OFPC_GROUP_STATS)),
            root_device_id=device.id)
        ld_initialized = self.adapter_agent.create_logical_device(ld)
        cap = OFPPF_1GB_FD | OFPPF_FIBER
        self.adapter_agent.add_logical_port(
            ld_initialized.id,
            LogicalPort(
                id='nni',
                ofp_port=ofp_port(
                    port_no=0,  # is 0 OK?
                    hw_addr=mac_str_to_tuple('00:00:00:00:00:%02x' % 129),
                    name='nni',
                    config=0,
                    state=OFPPS_LIVE,
                    curr=cap,
                    advertised=cap,
                    peer=cap,
                    curr_speed=OFPPF_1GB_FD,
                    max_speed=OFPPF_1GB_FD),
                device_id=device.id,
                device_port_no=nni_port.port_no,
                root_port=True))

        device = self.adapter_agent.get_device(device.id)
        device.parent_id = ld_initialized.id
        device.oper_status = OperStatus.ACTIVE
        self.adapter_agent.update_device(device)
        self.logical_device_id = ld_initialized.id

        # register ONUS per uni port until done asynchronously
        for onu_no in [1]:
            vlan_id = self.get_vlan_from_onu(onu_no)
            yield self.send_create_onu(0, onu_no, '4252434d', '12345678')
            yield self.send_configure_alloc_id(0, onu_no, vlan_id)
            yield self.send_configure_unicast_gem(0, onu_no, vlan_id)
            yield self.send_configure_multicast_gem(0, onu_no, 4000)
            yield self.send_activate_onu(0, onu_no)

            self.adapter_agent.child_device_detected(
                parent_device_id=device.id,
                parent_port_no=1,
                child_device_type='broadcom_onu',
                proxy_address=Device.ProxyAddress(device_id=device.id,
                                                  channel_id=vlan_id),
                vlan=vlan_id)

        # finally, open the frameio port to receive in-band packet_in messages
        self.log.info('registering-frameio')
        self.io_port = registry('frameio').open_port(self.interface,
                                                     self.rcv_io,
                                                     is_inband_frame)