Ejemplo n.º 1
0
    def run_to_completion(self) -> OMHStatus:
        # Check if ONU is already in sync
        logger.info('Starting activation of ONU {}'.format(self.onu.onu_id))
        onu_data = self.onu.get(omci_me_class['ONU_DATA'], 0, False)
        if not self._force_reset and onu_data is not None:
            action = GetAction(self, onu_data_me(0), ('mib_data_sync', ))
            status = self.transaction(action)
            if status != OMHStatus.OK:
                return status
            # Mib Sync would have happened already during the set_onu_comminication
            # Just have to trigger MIB Reset,Upload and Intial Config for the ONU
            if action.me.mib_data_sync == onu_data.mib_data_sync and onu_data.mib_data_sync != 0:
                logger.info('ONU {} is already in sync'.format(
                    self.onu.onu_id))
                return OMHStatus.OK
            logger.info(
                'ONU {} is not in sync. local mib_sync={}  received mib_sync={}'
                .format(self.onu.onu_id, onu_data.mib_data_sync,
                        action.me.mib_data_sync))

        # Execute activation sequence
        if self.run_subsidiary(OnuMibResetHandler(self._onu)) != OMHStatus.OK:
            return self.status

        if self.run_subsidiary(OnuMibUploadHandler(self._onu)) != OMHStatus.OK:
            return self.status

        #
        # At this point ONU MIB is freshly populated. Start the initial provisioning
        #
        # 1. Create GAL Ethernet Profile if doesn't exist
        gal_eth_prof = self._onu.get_first(omci_me_class['GAL_ETH_PROF'])
        if gal_eth_prof is None:
            logger.info('{} ONU {}: Create GAL EThernet Profile'.format(
                self._name, self.onu.onu_id))
            gal_eth_prof = gal_eth_prof_me(1)
            gal_eth_prof.max_gem_payload_size = 4095  # Default value
            action = CreateAction(self, gal_eth_prof)
            status = self.transaction(action)
            if status != OMHStatus.OK:
                return status
        gal_eth_prof.user_name = 'gal_eth_prof'
        self._onu.set(gal_eth_prof)

        # 2. Create MAC bridge service profile if doesn't exist
        mac_bridge_svc_prof = self._onu.get_first(
            omci_me_class['MAC_BRIDGE_SVC_PROF'])
        if mac_bridge_svc_prof is None:
            logger.info('{} - Create MAC Bridge Service Profile'.format(
                self.info()))
            mac_bridge_svc_prof = mac_bridge_svc_prof_me(1)
            mac_bridge_svc_prof.dynamic_filtering_ageing_time = 300  # Default value
            action = CreateAction(self, mac_bridge_svc_prof)
            status = self.transaction(action)
            if status != OMHStatus.OK:
                return status

        return OMHStatus.OK
def create_8021p_svc_mapper(handler: OmhHandler, name: str) -> OMHStatus:
    """ Create 802.1p Service Mapper

        handler: OMH handler that requested this service
        name: QoS profile name
    Returns:
        completion status
    """
    all_instance_ids = handler._onu.get_all_instance_ids(
        omci_me_class['IEEE_8021_P_MAPPER_SVC_PROF'])
    inst_id = len(all_instance_ids) > 0 and all_instance_ids[-1] + 1 or 1
    profile_me = ieee_8021_p_mapper_svc_prof_me(
        inst_id,
        tp_ptr=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_0=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_1=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_2=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_3=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_4=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_5=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_6=OMCI_NULL_PTR,
        interwork_tp_ptr_pri_7=OMCI_NULL_PTR,
        unmarked_frame_opt='DERIVE_IMPLIED_PCP',
        mapper_tp_type='BRIDGING_MAPPING')
    profile_me.user_name = name
    if handler.transaction(CreateAction(handler, profile_me)) != OMHStatus.OK:
        return handler.logerr_and_return(
            handler._transaction_status,
            'Create IEEE 802.1p Mapper SVC Profile ME {}'.format(name))
    return OMHStatus.OK
def create_ext_vlan_tag_oper_config_data(handler: OmhHandler,
                                         iface: ME,
                                         input_tpid: int = 0,
                                         output_tpid: int = 0) -> OMHStatus:
    """Create MAC Bridge Port Config Data for an interface
    Requires user attribute iface.bridge_port_num to be set
    """
    all_instances = handler._onu.get_all_instance_ids(
        omci_me_class['EXT_VLAN_TAG_OPER_CONFIG_DATA'])
    inst = len(all_instances) > 0 and all_instances[-1] + 1 or 1
    ext_vlan_tag = ext_vlan_tag_oper_config_data_me(inst)
    if type(iface) is pptp_eth_uni_me:
        ext_vlan_tag.assoc_type = 'PPTP_ETH_UNI'
    elif type(iface) is virtual_eth_intf_point_me:
        ext_vlan_tag.assoc_type = 'VEIP'
    elif type(iface) is mac_bridge_port_config_data_me:
        ext_vlan_tag.assoc_type = 'MAC_BRIDGE_PORT_CFG_DATA'
    else:
        return OMHStatus.NOT_SUPPORTED
    ext_vlan_tag.assoc_me_ptr = iface.inst
    status = handler.transaction(CreateAction(handler, ext_vlan_tag))
    if status != OMHStatus.OK:
        return status
    # Now set attributes that can't be set by 'create' action
    ext_vlan_tag.input_tpid = input_tpid != 0 and input_tpid or 0x8100
    ext_vlan_tag.output_tpid = output_tpid != 0 and output_tpid or 0x8100
    # XXX TODO: need to support additional downstream_mode values?
    ext_vlan_tag.ds_mode = 'US_INVERSE'
    status = handler.transaction(
        SetAction(handler, ext_vlan_tag,
                  ('input_tpid', 'output_tpid', 'ds_mode')))
    if status != OMHStatus.OK:
        return status
    iface.set_user_attr('ext_vlan_tag_op', inst)
    return OMHStatus.OK
def create_vlan_tagging_filter_data(handler: OmhHandler, inst: int, name: str,
                                    classifier: PacketClassifier,
                                    vlan_action: VlanAction) -> OMHStatus:
    """ Create and configure VLAN Tagging Filter Data ME

    Please note that vlan tagging filter is applied BEFORE vlan_action in the ingress
    and AFTER vlan_action in the egress. Therefore, need to take 'action' into account.

    Args:
        handler: OMH handler that requested this service
        inst: instance id. Must be equal to the instance of the associated MAC Bridge Port Data ME
        classifier: Packet classifier
        vlan_action: Packet VLAN action
    Returns:
        completion status
    """

    # XXX: TODO: add support for multiple VLAN classifier in a sub-interface
    if vlan_action is not None:
        if vlan_action.action == VlanAction.Action.PUSH or vlan_action.action == VlanAction.Action.TRANSLATE:
            o_vid = vlan_action.o_vid
        elif vlan_action.action == VlanAction.Action.POP:
            o_vid = classifier is None and None or classifier.field('i_vid')
        else:
            return handler.logerr_and_return(
                OMHStatus.NOT_SUPPORTED,
                "VLAN action {} is not supported".format(vlan_action.action))
    else:
        o_vid = classifier is None and None or classifier.field('o_vid')

    tcid = 0
    if o_vid is None:
        action = 'TAGGED_BRIDGING_A_NO_INVESTIGATION_UNTAGGED_BRIDGING_A'
    elif o_vid.pbit != PBIT_VALUE_ANY:
        tcid |= (o_vid.pbit << 13)
        if o_vid.vid != VID_VALUE_ANY:
            action = 'TAGGED_ACTION_H_TCI_INVESTIGATION_UNTAGGED_DISCARDING_C_DUP'
            tcid |= o_vid.vid
        else:
            action = 'TAGGED_ACTION_H_PRI_INVESTIGATION_UNTAGGED_DISCARDING_C_DUP'
    elif o_vid.vid != VID_VALUE_ANY:
        # Classify by VID only
        action = 'TAGGED_ACTION_H_VID_INVESTIGATION_UNTAGGED_DISCARDING_C_DUP'
        tcid |= o_vid.vid

    vlan_filter = bytearray(2)
    vlan_filter[0] = tcid >> 8
    vlan_filter[1] = tcid & 0xff
    tag_filter_me = vlan_tag_filter_data_me(inst,
                                            vlan_filter_list=vlan_filter,
                                            forward_oper=action,
                                            num_of_entries=1)
    tag_filter_me.user_name = name
    return handler.transaction(CreateAction(handler, tag_filter_me))
Ejemplo n.º 5
0
    def run_to_completion(self) -> OMHStatus:
        logger.info(self.info())

        # Validate parameters and fetch the relevant MEs
        tcont_me = None
        if self._is_upstream:
            tcont_me = self._onu.get_by_name(self._tcont_name)
            if tcont_me is None:
                return self.logerr_and_return(
                    OMHStatus.ERROR_IN_PARAMETERS,
                    'TCONT {} is not found'.format(self._tcont_name))

        uni_me = get_uni(self._onu, self._uni_name)
        if uni_me is None:
            return self.logerr_and_return(
                OMHStatus.ERROR_IN_PARAMETERS,
                'UNI {} is not found'.format(self._uni_name))

        ds_queue_me = None
        if self._is_downstream:
            ds_queue_me = get_queue_by_owner_tc(self._onu, False, uni_me,
                                                self._tc)

        us_queue_me = None
        if self._is_upstream:
            us_queue_me = get_queue_by_owner_tc(self._onu, True, tcont_me,
                                                self._tc)

        me = gem_port_net_ctp_me(
            self._gem_port_id,
            port_id=self._gem_port_id,
            direction=self._direction,
            tcont_ptr=tcont_me is not None and tcont_me.inst or OMCI_NULL_PTR,
            traffic_desc_prof_ptr_us=OMCI_NULL_PTR,  # XXX for now
            traffic_mgmt_ptr_us=us_queue_me is not None and us_queue_me.inst
            or OMCI_NULL_PTR,
            traffic_desc_prof_ptr_ds=OMCI_NULL_PTR,  # XXX for now
            pri_queue_ptr_ds=ds_queue_me is not None and ds_queue_me.inst
            or OMCI_NULL_PTR,
            encryption_key_ring=self._encryption)
        me.user_name = self._gem_port_id
        me.set_user_attr('tc', self._tc)
        me.set_user_attr('uni', self._uni_name)

        return self.transaction(CreateAction(self, me))
def _set_8021p_mapper(handler: OmhHandler,
                      mapper_me: ieee_8021_p_mapper_svc_prof_me,
                      pbit_to_tc: 'PbitToTCMapper', uni_name: str,
                      pbit: int) -> (OMHStatus, bool):
    """ Set up 802_1p mapper ME for a specified priority and all other priorities that
        map to the same traffic class
    """
    tc = pbit_to_tc.tc(pbit)
    if tc is None:
        return OMHStatus.OK, False

    # Find a GEM port by UNI and TC
    gem = get_gem_port_by_uni_tc(handler.onu, uni_name, tc)
    if gem is None:
        return OMHStatus.OK, False

    # Find GAL ethernet profile
    gal_eth_prof = handler.onu.get_by_name('gal_eth_prof')
    if gal_eth_prof is None:
        logger.error("set_8021p_mapper: GAL Ethernet Profile is not found")
        return OMHStatus.INTERNAL_ERROR, False

    # Create GEM_IW_TP
    all_gem_iw_tp_inst = handler.onu.get_all_instance_ids(
        omci_me_class['GEM_IW_TP'])
    gem_iw_tp_inst = len(
        all_gem_iw_tp_inst) > 0 and all_gem_iw_tp_inst[-1] + 1 or 1
    gem_iw_tp = gem_iw_tp_me(gem_iw_tp_inst,
                             gem_port_net_ctp_conn_ptr=gem.inst,
                             iw_opt='IEEE_8021_P_MAPPER',
                             svc_prof_ptr=mapper_me.inst,
                             iw_tp_ptr=OMCI_NULL_PTR,
                             gal_prof_ptr=gal_eth_prof.inst)
    status = handler.transaction(CreateAction(handler, gem_iw_tp))
    if status != OMHStatus.OK:
        return status, False

    # Plug GEM IW_TP into all priorities that map to the same tc
    pbits_by_tc = pbit_to_tc.pbits_by_tc(tc)
    for pbit in pbits_by_tc:
        _set_8021p_priority(mapper_me, pbit, gem_iw_tp.inst)

    return OMHStatus.OK, True
def create_mac_bridge_port(handler: OmhHandler, tp: ME) -> OMHStatus:
    """Create MAC Bridge Port Config Data for an interface

    Args:
        handler: OMH handler that requested this service
        tp: Bridge port Termination Point
    Returns:
        completion status
    """

    # Get mac_bridge_svc_prof ME
    mac_bridge_svc_prof = handler._onu.get_first(
        omci_me_class['MAC_BRIDGE_SVC_PROF'])
    if mac_bridge_svc_prof is None:
        return handler.logerr_and_return(
            OMHStatus.INTERNAL_ERROR,
            "MAC Bridge Service Profile ME doesn't exist")

    all_bridge_ports = handler._onu.get_all_instance_ids(
        omci_me_class['MAC_BRIDGE_PORT_CONFIG_DATA'])
    port_num = len(all_bridge_ports) > 0 and all_bridge_ports[-1] + 1 or 1
    mac_bridge_port = mac_bridge_port_config_data_me(
        inst=port_num,
        bridge_id_ptr=mac_bridge_svc_prof.inst,
        port_num=port_num,
        tp_ptr=tp.inst)
    if type(tp) is pptp_eth_uni_me:
        mac_bridge_port.tp_type = 'PHY_PATH_TP_ETH_UNI'
    elif type(tp) is virtual_eth_intf_point_me:
        mac_bridge_port.tp_type = 'VIRTUAL_ETH_INTERFACE_POINT'
    elif type(tp) is ieee_8021_p_mapper_svc_prof_me:
        mac_bridge_port.tp_type = 'IEEE_8021_P_MAPPER_SVC_PROF'
    else:
        return OMHStatus.NOT_SUPPORTED
    status = handler.transaction(CreateAction(handler, mac_bridge_port))
    if status == OMHStatus.OK:
        tp.set_user_attr('bridge_port', mac_bridge_port.inst)
    return OMHStatus.OK