コード例 #1
0
def get_mac_offset_from_fp(fp_port, sub_port, fp_cache=None):
    nas_if.log_info(
        'Trying to get npu port based on front-panel %d subport %d' %
        (fp_port, sub_port))
    if fp_cache is None:
        # Use local front-panel-port db
        port_obj = fp.find_front_panel_port(fp_port)
        if port_obj is None:
            raise ValueError('Front-panel-port %d not found in cache' %
                             fp_port)
        br_mode = port_obj.get_breakout_mode()
        mac_offset = port_obj.mac_offset
    else:
        cps_port_obj = fp_cache.get(fp_port)
        if cps_port_obj is None:
            raise ValueError('Front-panel-port %d not found in cps cache' %
                             fp_port)
        br_mode = nas_if.get_cps_attr(cps_port_obj, _fp_attr('breakout-mode'))
        mac_offset = nas_if.get_cps_attr(cps_port_obj, _fp_attr('mac-offset'))
        if br_mode is None or mac_offset is None:
            raise ValueError('Mandatory attributes not found in cps object')

    nas_if.log_info('Cached breakout mode of front panel port %d is %d' %
                    (fp_port, br_mode))
    lane_id = nas_comm.subport_to_lane(br_mode, sub_port)
    if lane_id is None:
        raise ValueError('Failed to get lane id from br_mode %d subport %d' %
                         (br_mode, sub_port))
    if isinstance(lane_id, tuple):
        lane_id, flag = lane_id
        nas_if.log_info('Get lane id %d with extended condition %s' %
                        (lane_id, flag))

    return mac_offset + lane_id
コード例 #2
0
def _if_init_config(obj, config):
    # Below rule is applied to process speed, duplex, auto-neg and FEC attritube in cps object
    # 1. if attribute is in input cps object, use it and do not change anything
    # 2. else, if attribute is in config, add it to cps object
    # 3. else, add "auto" to cps object
    speed = nas_if.get_cps_attr(obj, speed_attr_name)
    if speed is None:
        cfg_speed = config.get_speed()
        if cfg_speed is None:
            cfg_speed = _yang_auto_speed
        obj.add_attr(speed_attr_name, cfg_speed)
    duplex = nas_if.get_cps_attr(obj, duplex_attr_name)
    if duplex is None:
        cfg_duplex = config.get_duplex()
        if cfg_duplex is None:
            cfg_duplex = _yang_auto_dup
        obj.add_attr(duplex_attr_name, cfg_duplex)
    ng = nas_if.get_cps_attr(obj, negotiation_attr_name)
    if ng is None:
        cfg_ng = config.get_negotiation()
        if cfg_ng is None:
            cfg_ng = _yang_auto_neg
        obj.add_attr(negotiation_attr_name, cfg_ng)

    fec = nas_if.get_cps_attr(obj, fec_mode_attr_name)
    if fec is None:
        cfg_fec = config.get_fec_mode()
        if cfg_fec is None:
            auto_fec = nas_comm.get_value(nas_comm.yang_fec_mode, 'AUTO')
            if_cfg_speed = config.get_cfg_speed()
            if if_cfg_speed != None and nas_comm.is_fec_supported(auto_fec, if_cfg_speed):
                cfg_fec = auto_fec
        if cfg_fec != None:
            obj.add_attr(fec_mode_attr_name, cfg_fec)
コード例 #3
0
def bridge_create_test():
    global g_intf_list
    exec_shell("brctl delbr br600")

    # test
    exec_shell("brctl addbr br600")
    while 'br600' not in g_intf_list:
        time.sleep(1)

    dbg_print("********Bridge br600 creation is successful*****")
    # create a sub interface
    exec_shell("ip link add link e101-001-0 name e101-001-0.600 type vlan id 600")
    while 'e101-001-0.600' not in g_intf_list:
        time.sleep(1)
    # Add the sub interface to the bridge
    exec_shell("brctl addif br600 e101-001-0.600")
    t_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/tagged-ports')
    while t_mem is None:
        t_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/tagged-ports')
    if 'e101-001-0.600' in t_mem:
        dbg_print("********Member e101-001-0.600 addition is successful*****")

    # delete member from the bridge
    exec_shell("brctl delif br600 e101-001-0.600")
    t_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/tagged-ports')
    if t_mem is None:
        dbg_print("********Member e101-001-0.600 from bridge deletion is successful*****")
コード例 #4
0
def _check_hg_port_breakout(hybrid_group_name, port_id, br_mode):
    #Get Hybrid Group Object
    resp = hg_utils.get_hg(str(hybrid_group_name))
    assert len(resp) == 1
    for o in resp:
        assert o is not None
    obj = cps_object.CPSObject(obj=o)

    #Check if name is correct
    hg_name = nas_if.get_cps_attr(obj, hg_utils.hg_attr('id'))
    assert hg_name == str(hybrid_group_name)

    port_list = nas_if.get_cps_attr(obj, hg_utils.hg_attr('port'))
    for port_idx in port_list:
        port = port_list[port_idx]
        pr_id = port['port-id']
        if str(pr_id) == str(port_id):
            phy_mode = port['phy-mode']
            breakout_mode = port['breakout-mode']
            port_speed = port['port-speed']
            breakout_option = (breakout_mode, port_speed)
            breakout = nas_comm.yang.get_key(breakout_option,
                                             'yang-breakout-port-speed')
            assert str(breakout) == str(br_mode)
            break
コード例 #5
0
def get_default_media_setting(_media_type, def_param):
    base_media_info_list = get_base_media_info(_media_type)
    for j in base_media_info_list:
        obj = cps_object.CPSObject(obj=j)
        if def_param == 'speed':
            _def_attr = nas_if.get_cps_attr(obj, 'speed')
        elif def_param == 'duplex':
            _def_attr = nas_if.get_cps_attr(obj, 'duplex')
        elif def_param == 'autoneg':
            _def_attr = nas_if.get_cps_attr(obj, 'autoneg')
    return _def_attr
コード例 #6
0
def _if_init_config(obj, config):
    ''' Method to initialize interface config
    Below rule is applied to process speed, duplex, auto-neg and FEC attritube in cps object
    1. if attribute is in input cps object, use it and do not change anything
    2. else, if attribute is in config, add it to cps object
    3. else, add "auto" to cps object '''

    speed = nas_if.get_cps_attr(obj,
                                nas_comm.yang.get_value('speed', 'attr_name'))
    _auto_speed = nas_comm.yang.get_value('auto', 'yang-speed')
    if speed is None:
        cfg_speed = config.get_speed()
        if cfg_speed is None:
            cfg_speed = _auto_speed
        obj.add_attr(nas_comm.yang.get_value('speed', 'attr_name'), cfg_speed)

    duplex = nas_if.get_cps_attr(
        obj, nas_comm.yang.get_value('duplex', 'attr_name'))
    _auto_duplex = nas_comm.yang.get_value('auto', 'yang-duplex')
    if duplex is None:
        cfg_duplex = config.get_duplex()
        if cfg_duplex is None:
            cfg_duplex = _auto_duplex
        obj.add_attr(nas_comm.yang.get_value('duplex', 'attr_name'),
                     cfg_duplex)

    ng = nas_if.get_cps_attr(
        obj, nas_comm.yang.get_value('negotiation', 'attr_name'))
    _auto_negotiation = nas_comm.yang.get_value('auto', 'yang-autoneg')
    if ng is None:
        cfg_ng = config.get_negotiation()
        if cfg_ng is None:
            cfg_ng = _auto_negotiation
        obj.add_attr(nas_comm.yang.get_value('negotiation', 'attr_name'),
                     cfg_ng)

    fec = nas_if.get_cps_attr(obj,
                              nas_comm.yang.get_value('fec_mode', 'attr_name'))
    _auto_fec = nas_comm.yang.get_value('auto', 'yang-fec')
    if fec is None:
        cfg_fec = config.get_fec_mode()
        if cfg_fec is None:
            if_cfg_speed = config.get_cfg_speed()
            if if_cfg_speed != None and nas_comm.is_fec_supported(
                    _auto_fec, if_cfg_speed):
                cfg_fec = _auto_fec
        if cfg_fec != None:
            obj.add_attr(nas_comm.yang.get_value('fec_mode', 'attr_name'),
                         cfg_fec)
コード例 #7
0
def _check_hg_profile(hybrid_group_name, profile_name):
    #Get Hybrid Group Object
    resp = hg_utils.get_hg(str(hybrid_group_name))
    assert len(resp) == 1
    for o in resp:
        assert o is not None
    obj = cps_object.CPSObject(obj=o)

    #Check if name is correct
    hg_name = nas_if.get_cps_attr(obj, hg_utils.hg_attr('id'))
    assert hg_name == str(hybrid_group_name)

    #Check profile Type
    hg_profile = nas_if.get_cps_attr(obj, hg_utils.hg_attr('profile'))
    assert hg_profile == str(profile_name)
コード例 #8
0
def set_fp_rpc_cb_int(params):
    nas_if.log_info('received set breakout config command')

    obj = cps_object.CPSObject(obj=params['change'])

    fr_port = obj.get_attr_data(_breakout_i_attr('front-panel-port'))
    br_mode = nas_if.get_cps_attr(obj, _breakout_i_attr('breakout-mode'))
    phy_port_speed = nas_if.get_cps_attr(obj, _breakout_i_attr('port-speed'))
    if br_mode == None:
        nas_if.log_err('No breakout mode given in input')
        return False
    if phy_port_speed == None:
        nas_if.log_err('phy port speed not received in cps')
        return False
    # set the breakout mode
    return set_fp_port_config(fr_port, br_mode, phy_port_speed, None)
コード例 #9
0
def get_default_media_setting(_media_type, def_param):
    base_media_info_list = get_base_media_info(_media_type)
    if len(base_media_info_list) == 0:
        return None
    for j in base_media_info_list:
        obj = cps_object.CPSObject(obj=j)
        if def_param == 'speed':
            _def_attr = nas_if.get_cps_attr(obj, 'speed')
        elif def_param == 'duplex':
            _def_attr = nas_if.get_cps_attr(obj, 'duplex')
        elif def_param == 'autoneg':
            _def_attr = nas_if.get_cps_attr(obj, 'autoneg')
        elif def_param == 'supported-phy-mode':
            _def_attr = nas_if.get_cps_attr(obj, 'supported-phy-mode')
        elif def_param == 'hw-profile':
            _def_attr = nas_if.get_cps_attr(obj, 'hw-profile')
    return _def_attr
コード例 #10
0
def _update_fp(fp_obj):
    fr_port = nas_if.get_cps_attr(fp_obj, 'front-panel-port')
    if fr_port is None:
        nas_if.log_info('No front-panel-port found in event obj')
        nas_if.log_info('Event obj: %s' % str(fp_obj.get()))
        return
    if fr_port not in fp_cache:
        nas_if.log_err('Front panel port %d not in cache' % fr_port)
        return
    br_mode = nas_if.get_cps_attr(fp_obj, 'breakout-mode')
    if br_mode is None:
        nas_if.log_err('No breakout mode found in event obj')
        return
    cached_br_mode = nas_if.get_cps_attr(fp_cache[fr_port], 'breakout-mode')
    if br_mode != cached_br_mode:
        nas_if.log_info('Change breakout mode of fp port %d to %d' % (fr_port, br_mode))
        with fp_lock:
            fp_cache[fr_port].add_attr('breakout-mode', br_mode)
コード例 #11
0
def _get_hg_state_hdlr(methods, params):
    '''Helper Method to get Hybrid Group State'''
    obj = cps_object.CPSObject(obj=params['filter'])
    resp = params['list']

    if obj.get_key() == hg_utils.hg_state_key:
        hg_name = nas_if.get_cps_attr(obj, hg_utils.hg_state_attr('id'))
        return _service_get_hg_state(hg_name, resp)

    nas_if.log_err("Key Error: Hybrid Group State Key issue")
    return False
コード例 #12
0
def gen_port_group_state_list(obj, resp):
    pg_name = nas_if.get_cps_attr(obj, pg_state_attr('id'))
    pg_list = fp.get_port_group_list()
    if pg_name != None:
        pg = pg_list[pg_name]
        return create_and_add_pg_state_obj(pg, resp)
    else:
        # return all port groups
        for name in pg_list:
            ret = create_and_add_pg_state_obj(pg_list[name], resp)
        return True
コード例 #13
0
def _set_hg_hdlr(methods, params):
    '''CPS Set Helper for Hybrid Group'''
    obj = cps_object.CPSObject(obj=params['change'])
    resp = params['change']

    if obj.get_key() == hg_utils.hg_key:
        hg_name = nas_if.get_cps_attr(obj, hg_utils.hg_attr('id'))
        return _service_set_hg(hg_name, obj, resp)

    nas_if.log_err("Key Error: Hybrid Group Key issue")
    return False
コード例 #14
0
def set_int_pg_cb(methods, params):
    nas_if.log_info("set port group config")
    obj = cps_object.CPSObject(obj=params['change'])
    if obj.get_key() == _port_group_key:
        pg_name = nas_if.get_cps_attr(obj, pg_attr('id'))
        if pg_name == None:
            nas_if.log_err('port group name not present')
            return False
        phy_mode = nas_if.get_cps_attr(obj, pg_attr('phy-mode'))
        br_mode = nas_if.get_cps_attr(obj, pg_attr('breakout-mode'))
        port_speed = nas_if.get_cps_attr(obj, pg_attr('port-speed'))
        pg_list = fp.get_port_group_list()
        ret = set_port_group_config(pg_list[pg_name], phy_mode, br_mode,
                                    port_speed)
        if ret == True:
            obj = create_pg_cps_obj(pg_list[pg_name])
            params['change'] = obj.get()
    else:
        return False

    return True
コード例 #15
0
def _fp_identification_led_handle(cps_obj):
    ret = True
    if fp_identification_led_control:
        try:
            led_val = nas_if.get_cps_attr(cps_obj, 'base-if-phy/if/interfaces/interface/identification-led')
            if led_val != None:
                cps_obj.del_attr('base-if-phy/if/interfaces/interface/identification-led')
                name = cps_obj.get_attr_data('if/interfaces/interface/name')
                ret = fp_led.identification_led_set(name, led_val)
        except:
            pass
    return ret
コード例 #16
0
def print_hg_cps_obj(o):
    if o is None:
        return None

    obj = cps_object.CPSObject(obj=o)
    hg_name = nas_if.get_cps_attr(obj, hg_attr('id'))
    hg_profile = nas_if.get_cps_attr(obj, hg_attr('profile'))
    port_list = nas_if.get_cps_attr(obj, hg_attr('port'))
    print("Hybrid Group Name: %s Profile: %s " % (hg_name, hg_profile))

    for port_idx in port_list:
        port = port_list[port_idx]
        port_id = port['port-id']
        phy_mode = port['phy-mode']
        breakout_mode = port['breakout-mode']
        port_speed = port['port-speed']
        breakout_option = (breakout_mode,port_speed)
        breakout = nas_comm.yang.get_key(breakout_option, 'yang-breakout-port-speed')
        print("Port ID: %s Phy-mode: %s Breakout-mode: %s " % (str(port_id),
                                                               str(nas_comm.yang.get_key(phy_mode, 'yang-phy-mode')),
                                                               str(breakout)))
コード例 #17
0
def nas_os_event_handler(ev_obj):

    global g_intf_list
    operation, if_name, untagged_if_name, tagged_if_name = None, None, None, None

    if 'operation' in ev_obj:
        operation = ev_obj['operation']
    else:
        return
    intf_obj = cps_object.CPSObject(obj=ev_obj)
    dbg_print(" Operation:  %s " % (operation))

    if_name = nas_if.get_cps_attr(intf_obj, 'if/interfaces/interface/name')
    if if_name is None:
        dbg_print("Exception in reading name")
    if_type = nas_if.get_cps_attr(intf_obj, 'base-if-linux/if/interfaces/interface/dell-type')
    if operation == 'create':

        if if_name in g_intf_list:
            dbg_print(" Interface %s already present" %(if_name))
        if BASE_CMN_INTERFACE_TYPE_L2_PORT == 2 and if_name in g_intf_list:
            # Member Addition in a bridge
            # Check for untagged member
            ut_mem = nas_if.get_cps_attr(intf_obj, 'dell-if/if/interfaces/interface/untagged-ports')
            t_mem = nas_if.get_cps_attr(intf_obj, 'dell-if/if/interfaces/interface/tagged-ports')
            if ut_mem is not None:
                g_intf_list[if_name].add_attr('dell-if/if/interfaces/interface/untagged-ports', ut_mem)
                dbg_print(" New untagged Member %s addition to the bridge %s" %(ut_mem, if_name))
            # Check for tagged member
            if t_mem is not None:
                g_intf_list[if_name].add_attr('dell-if/if/interfaces/interface/tagged-ports', t_mem)
                dbg_print(" New tagged Member %s addition to the bridge %s" %(t_mem, if_name))
        else:
            g_intf_list[if_name] = intf_obj
            dbg_print(" Create Interface %s  type %s create event" % (if_name, dell_type_to_str[if_type]))
    elif operation == 'delete':
        if if_name not in g_intf_list:
            dbg_print(" delete interface or member event received but intf %s not present" % (if_name))
        else:
            if if_type == 2:
                # member delete event
                ut_mem = nas_if.get_cps_attr(intf_obj, 'dell-if/if/interfaces/interface/untagged-ports')
                t_mem = nas_if.get_cps_attr(intf_obj, 'dell-if/if/interfaces/interface/tagged-ports')
                if ut_mem is not None:
                    g_intf_list[if_name].del_attr('dell-if/if/interfaces/interface/untagged-ports')
                    dbg_print(" Untagged Member %s deletion to the bridge %s" %(ut_mem, if_name))
                if t_mem is not None:
                    g_intf_list[if_name].del_attr('dell-if/if/interfaces/interface/tagged-ports')
                    dbg_print(" tagged Member %s deletion to the bridge %s" %(t_mem, if_name))
            else:
                # Delete Interface event
                dbg_print(" Delete Interface %s event received" % (if_name))
                del g_intf_list[if_name]

    elif operation == 'set':
        dbg_print(" set Interface event received ")
        if if_name not in g_intf_list:
            dbg_print(" set event received but intf not present")
    cps_utils.print_obj(ev_obj)
コード例 #18
0
def gen_port_group_list(obj, resp):
    pg_name = nas_if.get_cps_attr(obj, pg_attr('id'))
    pg_list = fp.get_port_group_list()
    if pg_name != None:
        pg = pg_list[pg_name]
        obj = create_pg_cps_obj(pg)
        if obj == None:
            return False
        resp.append(obj.get())

    else:
        # return all port groups
        for name in pg_list:
            obj = create_pg_cps_obj(pg_list[name])
            if obj != None:
                resp.append(obj.get())
        return True
コード例 #19
0
def bridge_1d_configure_test():
    bridge_create_test()
    vxlan_create_test()
    vlan_sub_interface_create_test()
    lag_create_test()

    # Add Lag, VXLAN and VLans sub interfaces to the bridge

    # Add VXLAN to the bridge
    exec_shell("brctl addif br600 vtep500")
    t_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/tagged-ports')
    while t_mem is None or 'vtep500' not in t_mem:
        t_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/tagged-ports')

    dbg_print("********Interface Vtep500 added in the bridge br600**************************")

    # Add Vlan sub interface  to the bridge
    exec_shell("brctl addif br600 e101-001-0.600")
    t_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/tagged-ports')
    while 'e101-001-0.600' not in t_mem:
        t_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/tagged-ports')
    dbg_print("********Interface e101-001-0.600 added in the bridge br600**************************")

    # Add Bond interface  to the bridge
    exec_shell("brctl addif br600 bond100")
    ut_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/untagged-ports')
    while ut_mem is None or 'bond100' not in ut_mem:
        ut_mem = nas_if.get_cps_attr(g_intf_list['br600'], 'dell-if/if/interfaces/interface/untagged-ports')
    dbg_print("********Interface bond100 added in the bridge br600**************************")


    exec_shell("brctl delif br600 vtep500")
    exec_shell("brctl delif br600 bond100")
    exec_shell("brctl delif br600 e101-001-0.600")
    exec_shell("brctl delbr br600")
    exec_shell("ip link del vtep500")
    exec_shell("ip link del bond100")
    exec_shell("ip link del e101-001-0.600")
コード例 #20
0
        return 1  #ERROR SCENARIO

    #print "CPS GET DUMP" + str(if_details)
    d = if_details[0]['data']
    if attr not in d:
        return 1  #ERROR SCENARIO
    if_index = cps_utils.cps_attr_types_map.from_data(attr, d[attr])
    print("Interface %s IF Index is %s " % (intf_name, str(if_index)))
    return 0


nas_fp_cache = nas_if.FpPortCache()
front_port = nas_if.get_front_port_from_name(ifname)
fp_port_id = front_port[0]
fp_obj = nas_fp_cache.get(fp_port_id)
pg_name = nas_if.get_cps_attr(
    fp_obj, 'port-group')  # None if interface not part of port-group

# Run fanout on the port-group
if pg_name:

    def test_fanout_100g_to_10g():
        print '=========== Configuring fanout for %s with Mode 4x1 and 10G Speed ===========' % pg_name
        cmd_str = '/usr/bin/opx-config-fanout --pg_name ' + pg_name + ' --mode 4x1  --speed 10g'
        os.system(cmd_str)
        #Get interfaces in the port group
        temp = ifname[:-1] + str(1)
        #Check if the fanout interface present
        assert check_intf_presence(temp) == 0

    def revert_fanout_100g():
        #Deleting the fanout config in the given port-group name
コード例 #21
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
    breakout_cap = None

    nas_if.log_info("update config for " + str(op))
    try:
        if_name = obj.get_attr_data(ifname_attr_name)
    except:
        # check for media_type change event obj
        nas_if.log_err('process media event')
        if_handle_set_media_type(op, obj)
        return
    if op == 'create':
        if_type = _get_intf_type(obj)
        if if_type != 'front-panel':
            return
        try:
            npu_id = obj.get_attr_data(npu_attr_name)
            port_id = obj.get_attr_data(port_attr_name)
        except:
            nas_if.log_err(
                ' update config: Unable to get npu or port from the obj ' +
                str(if_name))
            return
        #read media type from PAS
        try:
            (breakout_cap,
             breakout_mode) = nas_if.get_port_breakoutCap_currentMode_mode(
                 npu_id, port_id)
        except:
            nas_if.log_err(' unable to get breakout mode ' + str(if_name))
            return

        fp_port = nas_if.get_cps_attr(obj, fp_port_attr_name)
        media_type = _get_if_media_type(fp_port)

        config = IF_CONFIG(if_name, npu_id, port_id, media_type, breakout_mode)
        _if_config_add_interface(if_name, config)
        nas_if.log_info(' interface config updated successfully for ' +
                        str(if_name))
    if op == 'set' or op == 'create':
        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.
        config = _if_config_get(if_name)
        if config == None:
            nas_if.log_err(' interface not present in config')
            return
        breakout_mode = config.get_breakout_mode()
        nas_if.log_info("breakout mode " + str(breakout_mode))
        if speed != None and speed != config.get_speed():
            nas_if.log_info("speed " + str(speed))
            if speed == _yang_auto_speed and breakout_mode == _yang_breakout_1x1:
                nas_if.log_info("set default speed media type " +
                                str(config.get_media_type()))
                # TODO default speed in breakout mode is not supported  yet
                _add_default_speed(config.get_media_type(), obj)
            config.set_speed(speed)

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

        if duplex != None and duplex != config.get_duplex():
            _set_duplex(duplex, config, obj)
            nas_if.log_info("duplex is " + str(duplex))
        config.show()

    if op == 'delete':
        # remove the interface entry from the config
        del _if_config[if_name]
コード例 #22
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
コード例 #23
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
コード例 #24
0
def apply_cps_config_to_hg(obj, hg_obj):
    '''Method to configure a Hybrid Group'''

    #Configure Profile Mode
    rollback_list = []
    prev_profile_mode = hg_obj.get_hybrid_group_profile_mode()
    cur_profile_mode = nas_if.get_cps_attr(obj, hg_utils.hg_attr('profile'))
    if cur_profile_mode is not None and prev_profile_mode != cur_profile_mode:
        hg_obj.set_hybrid_group_profile_mode(cur_profile_mode)

        # Configure Default Breakout for profile mode
        port_list = hg_obj.get_fp_ports()
        if port_list is not None:
            for fpp_num in port_list:

                port = fp.find_front_panel_port(fpp_num)

                # Previous configuration
                prev_br_mode = port.get_breakout_mode()
                prev_port_speed = port.get_port_speed()
                prev_phy_mode = port.get_phy_mode()
                prev_port_profile_name = port.get_profile_type()

                # Current configuration
                hybrid_profile = port.get_hybrid_profile()
                cur_port_profile_name = str(
                    hybrid_profile.get_port_profile(cur_profile_mode))
                port.apply_port_profile(
                    fp.get_port_profile(cur_port_profile_name))
                cur_phy_mode = port.get_def_phy_mode()
                cur_br_mode = port.get_def_breakout()
                cur_port_speed = port.get_default_phy_port_speed()

                rollback_list.append((fpp_num, prev_br_mode, prev_port_speed,
                                      prev_phy_mode, prev_port_profile_name))

                # Apply configuration
                rc = fp_utils.set_fp_port_config(fpp_num, cur_br_mode,
                                                 cur_port_speed, cur_phy_mode)

                if rc is False or fpp_num not in hg_obj.get_fp_ports():
                    nas_if.log_err(
                        'failed to config fp_port %d, start rollback' %
                        fpp_num)

                    # Rollback
                    for (fpp, br_mode, port_speed, phy_mode,
                         port_profile_name) in rollback_list:
                        nas_if.log_info('rollback port %d config' % fpp)
                        port = fp.find_front_panel_port(fpp)
                        fp_utils.set_fp_port_config(fpp, br_mode, port_speed,
                                                    phy_mode)
                        port.apply_port_profile(
                            fp.get_port_profile(port_profile_name))
                    hg_obj.set_hybrid_group_profile_mode(prev_profile_mode)
                    return False

                hwp_speed = pg_utils.get_hwp_speed(cur_br_mode, cur_port_speed,
                                                   cur_phy_mode)
                port.set_hwp_speed(hwp_speed)

    # Configure User Specified Breakout for profile mode
    port_list = nas_if.get_cps_attr(obj, hg_utils.hg_attr('port'))
    if port_list is not None:
        for fpp_idx in port_list:

            fpp_num = int(port_list[fpp_idx]['port-id'])
            port = fp.find_front_panel_port(fpp_num)

            # Current configuration
            cur_phy_mode = port_list[fpp_idx]['phy-mode']
            cur_br_mode = port_list[fpp_idx]['breakout-mode']
            cur_port_speed = port_list[fpp_idx]['port-speed']

            # Apply configuration
            rc = fp_utils.set_fp_port_config(fpp_num, cur_br_mode,
                                             cur_port_speed, cur_phy_mode)

            if rc is False or fpp_num not in hg_obj.get_fp_ports():
                nas_if.log_err('failed to config fp_port %d, start rollback' %
                               fpp_num)

                # Rollback
                for (fpp, br_mode, port_speed, phy_mode,
                     port_profile_name) in rollback_list:
                    nas_if.log_info('rollback port %d config' % fpp)
                    port = fp.find_front_panel_port(fpp)
                    fp_utils.set_fp_port_config(fpp, br_mode, port_speed,
                                                phy_mode)
                    port.apply_port_profile(
                        fp.get_port_profile(port_profile_name))
                hg_obj.set_hybrid_group_profile_mode(prev_profile_mode)
                return False

            hwp_speed = pg_utils.get_hwp_speed(cur_br_mode, cur_port_speed,
                                               cur_phy_mode)
            port.set_hwp_speed(hwp_speed)
    return True
コード例 #25
0
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
コード例 #26
0
def _update_fp(fp_obj):
    fr_port = nas_if.get_cps_attr(fp_obj, 'front-panel-port')
    fp_db = fp.find_front_panel_port(fr_port)
    fp_db.set_breakout_mode(nas_if.get_cps_attr(fp_obj, 'breakout-mode'))
    fp_db.set_speed(nas_if.get_cps_attr(fp_obj, 'port-speed'))