Example #1
0
def get_mac_rpc_cb(methods, params):
    if params['operation'] != 'rpc':
        nas_if.log_err('Operation %s not supported' % params['operation'])
        return False
    cps_obj = cps_object.CPSObject(obj=params['change'])

    if_type = if_config.get_intf_type(cps_obj)
    if if_type == 'loopback' or if_type == 'management':
        nas_if.log_err('Interface type %s not supported' % if_type)
        return False
    with fp_lock:
        param_list = ma.get_alloc_mac_addr_params(if_type, cps_obj, fp_cache)
        if param_list is None:
            nas_if.log_err(
                'No enough attributes in input object to get mac address')
            return False

    mac_addr = ma.if_get_mac_addr(**param_list)
    if mac_addr is None or len(mac_addr) == 0:
        nas_if.log_err('Failed to get mac address')
        return False
    cps_obj.add_attr(mac_attr_name, mac_addr)

    params['change'] = cps_obj.get()
    return True
Example #2
0
def get_mac_rpc_cb(methods, params):
    if params['operation'] != 'rpc':
        nas_if.log_err('Operation %s not supported' % params['operation'])
        return False
    cps_obj = cps_object.CPSObject(obj = params['change'])

    try:
        appl_name = cps_obj.get_attr_data('dell-base-if-cmn/get-mac-address/input/application')
        type_name = cps_obj.get_attr_data('dell-base-if-cmn/get-mac-address/input/type')
        nas_if.log_info('Get MAC address for application %s and type %s' % (appl_name, type_name))
    except ValueError:
        appl_name = 'interface'
        type_name = ''
        nas_if.log_info('Use interface as default application')
    try:
        offset = cps_obj.get_attr_data('dell-base-if-cmn/get-mac-address/input/offset')
        nas_if.log_info('MAC address offset %d' % offset)
    except ValueError:
        offset = 0
        nas_if.log_info('Use 0 as default offset')

    if appl_name == 'interface':
        if_type = if_config.get_intf_type(cps_obj)
        if if_type == 'loopback' or if_type == 'management':
            nas_if.log_err('Interface type %s not supported' % if_type)
            return False
        with fp_lock:
            mac_addr_info = ma.get_intf_mac_addr(if_type, cps_obj, fp_cache)
    else:
        mac_addr_info = ma.get_appl_mac_addr(appl_name, type_name, offset)

    if mac_addr_info is None:
        nas_if.log_err('Failed to get mac address')
        return False
    mac_addr, addr_num = mac_addr_info
    if mac_addr is None or len(mac_addr) == 0:
        nas_if.log_err('Invaid mac address got')
        return False
    cps_obj.add_attr(mac_attr_name, mac_addr)
    cps_obj.add_attr('dell-base-if-cmn/get-mac-address/output/number-of-mac-addresses', addr_num)

    params['change'] = cps_obj.get()
    return True
Example #3
0
def set_intf_rpc_cb(methods, params):
    if params['operation'] != 'rpc':
        nas_if.log_err('Operation '+str(params['operation'])+' not supported')
        return False
    cps_obj = cps_object.CPSObject(obj = params['change'])

    try:
        if def_vlan_mode_attr_name in params['change']['data']:
            return _handle_global_vlan_config(cps_obj)
    except:
        pass

    if_type = if_config.get_intf_type(cps_obj)
    if if_type == 'loopback':
        return _handle_loopback_intf(cps_obj, params)
    elif if_type == 'management':
        return False
    elif if_type == 'macvlan':
        return _handle_macvlan_intf(cps_obj, params)

    op = _get_op_id(cps_obj)
    if op is None:
        return False

    member_port = None
    try:
        member_port = cps_obj.get_attr_data('dell-if/if/interfaces/interface/member-ports/name')
    except ValueError:
        member_port = None

    have_fp_attr = True
    front_panel_port = None
    try:
        front_panel_port = cps_obj.get_attr_data(fp_port_attr_name)
    except ValueError:
        have_fp_attr = False

    if_name = nas_if.get_cps_attr(cps_obj, ifname_attr_name)
    nas_if.log_info('Logical interface configuration: op %s if_name %s if_type %s' % (
                     op, if_name if if_name != None else '-', if_type))
    if ((op == 'create' or (op == 'set' and have_fp_attr == True and front_panel_port is not None))
        and member_port is None):
        if op == 'set' and if_type is None:
            # For set operation, if front_panel_port is given, if_type should be front-panel
            if_type = 'front-panel'
        nas_if.log_info('Interface MAC address setup for type %s' % if_type)
        try:
            mac_addr = cps_obj.get_attr_data(mac_attr_name)
        except ValueError:
            mac_addr = None
        if mac_addr is None:
            nas_if.log_info('No mac address given in input object, get assigned mac address')
            try:
                param_list = get_alloc_mac_addr_params(if_type, cps_obj)
            except Exception:
                logging.exception('Failed to get params')
                return False
            if param_list != None:
                try:
                    mac_addr = ma.if_get_mac_addr(**param_list)
                except:
                    logging.exception('Failed to get mac address')
                    return False
                if mac_addr is None:
                    nas_if.log_err('Failed to get mac address')
                    return False
                if len(mac_addr) > 0:
                    nas_if.log_info('Assigned mac address: %s' % mac_addr)
                    cps_obj.add_attr(mac_attr_name, mac_addr)

    if op == 'set' or op == 'create':
        if have_fp_attr == True:
            subport_id = 0
            try:
                subport_id = cps_obj.get_attr_data(subport_attr_name)
            except ValueError:
                # use default value if no attribute found in object
                pass
            if front_panel_port is None:
                npu_id = None
                port_id = None
            else:
                try:
                    (npu_id, port_id, hw_port) = fp_utils.get_npu_port_from_fp(
                                                            front_panel_port, subport_id)
                except ValueError as inst:
                    nas_if.log_info(inst.args[0])
                    return False
                nas_if.log_info('Front panel port %d, NPU port %d' % (front_panel_port, port_id))
                in_phy_mode = if_config.get_intf_phy_mode(cps_obj)
                if in_phy_mode != None:
                    phy_mode = port_utils.hw_port_to_phy_mode(port_list, npu_id, hw_port)
                    if in_phy_mode != phy_mode:
                        nas_if.log_err('Input PHY mode %d mis-match with physical port mode %d' % (
                                       in_phy_mode, phy_mode))
                        return False
            cps_obj.add_attr(npu_attr_name, npu_id)
            cps_obj.add_attr(port_attr_name, port_id)

        try:
            if _if_update_config(op, cps_obj) == False:
                params['change'] = cps_obj.get()
                nas_if.log_err( "Interface update config failed during set or create ")
                return False
        except Exception:
            nas_if.log_err( "Interface update config failed during set or create ")
            logging.exception('Error:')

    module_name = nas_if.get_if_key()
    in_obj = copy.deepcopy(cps_obj)
    in_obj.set_key(cps.key_from_name('target', module_name))
    in_obj.root_path = module_name + '/'
    obj = in_obj.get()
    if op_attr_name in obj['data']:
        del obj['data'][op_attr_name]
    upd = (op, obj)
    trans = cps_utils.CPSTransaction([upd])
    ret_data = trans.commit()
    if ret_data == False:
        nas_if.log_err('Failed to commit request')
        ret_data = trans.get_objects()
        if len(ret_data) > 0 and 'change' in ret_data[0]:
            ret_obj = cps_object.CPSObject(obj = ret_data[0]['change'])
            try:
                ret_code = ret_obj.get_attr_data(retcode_attr_name)
                ret_str = ret_obj.get_attr_data(retstr_attr_name)
            except ValueError:
                nas_if.log_info('Return code and string not found from returned object')
                return False
            cps_obj.add_attr(retcode_attr_name, ret_code)
            cps_obj.add_attr(retstr_attr_name, ret_str)
            params['change'] = cps_obj.get()
        return False
    if op == 'delete':
        try:
            _if_update_config(op, in_obj)
        except:
            nas_if.log_err('update config failed for delete operation')
            logging.exception('Error:')
        return True
    if len(ret_data) == 0 or not 'change' in ret_data[0]:
        nas_if.log_err('Invalid return object from cps request')
        return False
    if (op == 'create' and member_port is None):
        ret_obj = cps_object.CPSObject(obj = ret_data[0]['change'])
        try:
            ifindex = ret_obj.get_attr_data(ifindex_attr_name)
        except ValueError:
            nas_if.log_err('Ifindex not found from returned object')
            return False
        cps_obj.add_attr(ifindex_attr_name, ifindex)

    params['change'] = cps_obj.get()
    return True
Example #4
0
def _if_update_config(op, obj):

    if_name = None
    npu_id = None
    port_id = None
    negotiation = None
    speed = None
    duplex = None
    media_type = None
    breakout_mode = None

    try:
        if_name = obj.get_attr_data(ifname_attr_name)
    except:
        # check for media_type change event obj
        nas_if.log_info('process media event, op %s' % op)
        return(if_handle_set_media_type(op, obj))

    nas_if.log_info('update config for %s: op %s' % (if_name, op))

    npu_port_found = True
    try:
        npu_id = obj.get_attr_data(npu_attr_name)
        port_id = obj.get_attr_data(port_attr_name)
    except:
        npu_port_found = False

    if op == 'create':
        # if config is cached only for physical interface
        if_type = if_config.get_intf_type(obj)
        if if_type != 'front-panel':
            return True

        ietf_intf_type = nas_if.get_cps_attr(obj,nas_comm.get_value(nas_comm.attr_name,'intf_type'))
        config = if_config.IF_CONFIG(if_name, ietf_intf_type)

        if if_config.if_config_add(if_name, config) == False:
            nas_if.log_err(' interface config already present for ' + str(if_name))
        nas_if.log_info(' interface config added successfully for ' + str(if_name))

        if (nas_if.get_cps_attr(obj, negotiation_attr_name) is None):
            obj.add_attr(negotiation_attr_name, _yang_auto_neg)

    config = if_config.if_config_get(if_name)
    if config is None:
        nas_if.log_info(' interface not present in if config list' + str(if_name))
        return True
    if npu_port_found:
        #NPU port attribute only found in create or associate/disassociate request
        nas_if.log_info(' set npu %s and port %s to if config' % (str(npu_id), str(port_id)))
        config.set_npu_port(npu_id, port_id)

    if op == 'set' or op == 'create':
        force_update = False
        if npu_port_found:
            if npu_id != None or port_id != None:
                #for create or assiociate request
                fp_port = nas_if.get_cps_attr(obj, fp_port_attr_name)
                subport_id = nas_if.get_cps_attr(obj, subport_attr_name)
                config.set_fp_port(fp_port)
                config.set_subport_id(subport_id)

                fp_obj = fp.find_front_panel_port(fp_port)
                if fp_obj != None:
                    config.set_cfg_speed(fp_obj.get_port_speed())
                    config.set_breakout_mode(fp_obj.get_breakout_mode())
                    obj.add_attr(supported_autoneg, fp_obj.get_supported_autoneg())
                else:
                    nas_if.log_err('Unable to find front panel object for port %d' % fp_port)

                #read media type from PAS
                media_type = _get_if_media_type(fp_port)
                nas_if.log_info(' set media_type %s to if config for fp %d' % (
                                str(media_type), fp_port));
                config.set_media_type(media_type)

                if check_if_media_supported(media_type, config) != True:
                    config.set_is_media_supported(False)
                    nas_if.log_err(' Plugged-in media is not supported for ' + str(if_name))
                    return True

                if check_if_media_support_phy_mode(media_type, config) != True:
                    config.set_is_media_supported(False)
                    nas_if.log_err(' Plugged-in media does not support configured phy mode for %s' %
                                   if_name)
                    return True

                config.set_is_media_supported(True)
                obj.add_attr(media_type_attr_name, media_type)
                _if_init_config(obj, config)
                if op != 'create':
                    # for the case of interface associate, force attribute update
                    force_update = True
            else:
                #for disassociate request
                nas_if.log_info(' reset breakout_mode and media type in if config')
                config.set_breakout_mode(None)
                config.set_media_type(None)

        if not(_fp_identification_led_handle(obj)):
            nas_if.log_err('Setting identification led failed')
            return False

        if config.get_is_media_supported() == False:
            nas_if.log_info('media type not supported')
            # Do not do any further processing based on the media connected
            return True

        negotiation = nas_if.get_cps_attr(obj, negotiation_attr_name)
        speed = nas_if.get_cps_attr(obj, speed_attr_name)
        duplex = nas_if.get_cps_attr(obj, duplex_attr_name)
        # update the new speed, duplex and autoneg in the config. If
        # autoneg, speed or duplex is auto then fetch default value and replace in the cps object
        # do not set auto speed in case of breakout mode.
        # In case of ethernet mode, set default speed only in case of breakout mode 1x1
        # in case of FC mode, set the default speed of the media.
        if speed != None and (force_update or speed != config.get_speed()):
            if _set_speed(speed, config, obj) == False:
                nas_if.log_err('failed to set speed')
                return False

        # in case of negotiation, add autoneg attribute to on or off or default autoneg
        # if negotiation== auto
        if negotiation != None and (force_update or negotiation != config.get_negotiation()):
            _set_autoneg(negotiation, config, obj)

        if duplex != None and (force_update or duplex != config.get_duplex()):
            _set_duplex(duplex, config, obj)

        fec_mode = nas_if.get_cps_attr(obj, fec_mode_attr_name)
        if op == 'create' or (fec_mode != None and
                              (force_update or fec_mode != config.get_fec_mode())):
            if _set_fec_mode(fec_mode, config, obj, op) != True:
                nas_if.log_err('Failed to set FEC mode %d to interface %s' % (fec_mode, if_name))
                return False

        if op == 'create':
            _set_hw_profile(config, obj)

        config.show()

    if op == 'delete':
        # remove the interface entry from the config
        if_config.if_config_del(if_name)
    return True
def _if_update_config(op, obj):

    if_name = None
    npu_id = None
    port_id = None
    negotiation = None
    speed = None
    duplex = None

    try:
        if_name = obj.get_attr_data(
            nas_comm.yang.get_value('if_name', 'attr_name'))
    except:
        nas_if.log_info("Interface name not present in the object")
        return True

    nas_if.log_info('update config for %s: op %s' % (if_name, op))

    npu_port_found = True
    try:
        npu_id = obj.get_attr_data(
            nas_comm.yang.get_value('npu_id', 'attr_name'))
        port_id = obj.get_attr_data(
            nas_comm.yang.get_value('port_id', 'attr_name'))
    except:
        npu_port_found = False

    if op == 'create':
        # if config is cached only for physical interface
        if_type = if_config.get_intf_type(obj)
        if if_type != 'front-panel':
            return True

        ietf_intf_type = nas_if.get_cps_attr(
            obj, nas_comm.yang.get_value('intf_type', 'attr_name'))
        config = if_config.IF_CONFIG(if_name, ietf_intf_type)

        if if_config.if_config_add(if_name, config) == False:
            nas_if.log_err(' interface config already present for ' +
                           str(if_name))
        nas_if.log_info(' interface config added successfully for ' +
                        str(if_name))

        if (nas_if.get_cps_attr(
                obj, nas_comm.yang.get_value('negotiation', 'attr_name')) is
                None):
            obj.add_attr(nas_comm.yang.get_value('negotiation', 'attr_name'),
                         nas_comm.yang.get_value('auto', 'yang-autoneg'))

    config = if_config.if_config_get(if_name)
    if config is None:
        nas_if.log_info(' interface not present in if config list' +
                        str(if_name))
        return True
    if npu_port_found:
        #NPU port attribute only found in create or associate/disassociate request
        nas_if.log_info(' set npu %s and port %s to if config' %
                        (str(npu_id), str(port_id)))
        config.set_npu_port(npu_id, port_id)

    if op == 'set' or op == 'create':
        force_update = False
        negotiation = nas_if.get_cps_attr(
            obj, nas_comm.yang.get_value('negotiation', 'attr_name'))
        speed = nas_if.get_cps_attr(
            obj, nas_comm.yang.get_value('speed', 'attr_name'))
        duplex = nas_if.get_cps_attr(
            obj, nas_comm.yang.get_value('duplex', 'attr_name'))
        fec = nas_if.get_cps_attr(
            obj, nas_comm.yang.get_value('fec_mode', 'attr_name'))
        if npu_port_found:
            if npu_id != None or port_id != None:
                #for create or assiociate request
                fp_port = nas_if.get_cps_attr(
                    obj, nas_comm.yang.get_value('fp_port', 'attr_name'))
                subport_id = nas_if.get_cps_attr(
                    obj, nas_comm.yang.get_value('subport_id', 'attr_name'))
                config.set_fp_port(fp_port)
                config.set_subport_id(subport_id)

                fp_obj = fp.find_front_panel_port(fp_port)
                if fp_obj != None:
                    config.set_cfg_speed(fp_obj.get_port_speed())
                    config.set_breakout_mode(fp_obj.get_breakout_mode())
                    obj.add_attr(
                        nas_comm.yang.get_value('supported_autoneg',
                                                'attr_name'),
                        fp_obj.get_supported_autoneg())
                else:
                    nas_if.log_err(
                        'Unable to find front panel object for port %d' %
                        fp_port)

                #read media type from PAS
                try:
                    media_obj = _get_if_media_obj(fp_port)
                except:
                    media_obj = None

                media_monitor.process_media_event(npu_id, port_id, media_obj)

                if if_lib.check_if_media_supported(
                        config
                ) != True or if_lib.check_if_media_support_phy_mode(
                        config) != True:
                    config.set_is_media_supported(False)
                    if negotiation is not None:
                        config.set_negotiation(negotiation)
                    if fec is not None and nas_comm.is_fec_supported(
                            fec, config.get_cfg_speed()) is True:
                        config.set_fec_mode(fec)
                    if duplex is not None:
                        config.set_duplex(duplex)
                    if speed is not None:
                        if speed != nas_comm.yang.get_value(
                                'auto', 'yang-speed'
                        ) and if_lib.verify_intf_supported_speed(
                                config, speed) is True:
                            config.set_speed(speed)
                    return True

                obj.add_attr(
                    nas_comm.yang.get_value('media_type', 'attr_name'),
                    config.get_media_cable_type())
                config.set_is_media_supported(True)
                _if_init_config(obj, config)
                if op != 'create':
                    # for the case of interface associate, force attribute update
                    force_update = True
            else:
                #for disassociate request
                nas_if.log_info(
                    ' reset breakout_mode and media type in if config')
                config.set_breakout_mode(None)
                config.set_media_obj(None)

        if not (_fp_identification_led_handle(obj)):
            nas_if.log_err('Setting identification led failed')
            return False

        if config.get_is_media_supported() == False:
            nas_if.log_info('media type not supported')
            # Do not do any further processing based on the media connected
            if negotiation is not None:
                config.set_negotiation(negotiation)
            if fec is not None and nas_comm.is_fec_supported(
                    fec, config.get_cfg_speed()) is True:
                config.set_fec_mode(fec)
            if duplex is not None:
                config.set_duplex(duplex)
            if speed is not None:
                if speed != nas_comm.yang.get_value(
                        'auto',
                        'yang-speed') and if_lib.verify_intf_supported_speed(
                            config, speed) is True:
                    config.set_speed(speed)
            return True

        # update the new speed, duplex and autoneg in the config. If
        # autoneg, speed or duplex is auto then fetch default value and replace in the cps object
        # do not set auto speed in case of breakout mode.
        # In case of ethernet mode, set default speed only in case of breakout mode 1x1
        # in case of FC mode, set the default speed of the media.
        if speed != None and (force_update or speed != config.get_speed()):
            if if_lib.set_if_speed(speed, config, obj) == False:
                nas_if.log_err('failed to set speed')
                return False

        if duplex != None and (force_update or duplex != config.get_duplex()):
            if_lib.set_if_duplex(duplex, config, obj)
        # in case of negotiation, add autoneg attribute to on or off or default autoneg for eth mode interfaces
        intf_phy_mode = nas_comm.yang.get_value(config.get_ietf_intf_type(),
                                                'ietf-type-2-phy-mode')

        if intf_phy_mode is not nas_comm.yang.get_value('fc', 'yang-phy-mode'):
            if negotiation != None and (
                    force_update or negotiation != config.get_negotiation()):
                if_lib.set_if_autoneg(negotiation, config, obj)
        else:
            if (nas_if.get_cps_attr(
                    obj, nas_comm.yang.get_value('negotiation', 'attr_name'))
                    is not None):
                obj.del_attr(nas_comm.yang.get_value('auto_neg', 'attr_name'))

        if ((intf_phy_mode == nas_comm.yang.get_value('ether',
                                                      'yang-phy-mode'))
                and (op == 'create' or
                     (fec != None and
                      (force_update or fec != config.get_fec_mode())))):
            if if_lib.set_if_fec(fec, config, obj, op) == False:
                if op == 'create':
                    obj.del_attr(
                        nas_comm.yang.get_value('fec_mode', 'attr_name'))
                    nas_if.log_info("Failed to set FEC")
                else:
                    nas_if.log_err("Failed to set FEC")
                    return False

        if op == 'create':
            if_lib.set_if_hw_profile(config, obj)

        config.show()

    if op == 'delete':
        # remove the interface entry from the config
        if_config.if_config_del(if_name)
    return True