def if_handle_set_media_type(op, obj):
    if_name = None
    try:
        npu = obj.get_attr_data(npu_attr_name)
        port = obj.get_attr_data(port_attr_name)
        media_type = obj.get_attr_data(media_type_attr_name)
    except:
        nas_if.log_err(
            'missing npu,port or media type in set media type request')
        return
    # find npu, port in the _if_config
    if_name = find_if_config_by_npu_port(npu, port)
    if if_name == None:
        nas_if.log_err("No interface present for the npu " + str(npu) +
                       "and port " + str(port))
        return
    nas_if.log_info("if name is " + str(if_name))
    config = _if_config[if_name]
    config.set_media_type(media_type)
    obj.add_attr(ifname_attr_name, if_name)
    # set the default speed if the speed is configured to auto it is in non-breakout mode
    if config.get_breakout_mode() == _yang_breakout_1x1 and config.get_speed(
    ) == _yang_auto_speed:
        _add_default_speed(media_type, obj)
    if config.get_negotiation() == _yang_auto_neg:
        _add_default_autoneg(media_type, obj)
    if config.get_duplex() == _yang_auto_dup:
        _add_default_duplex(media_type, obj)

    nas_if.log_info("media type setting is successful for " + str(if_name))
    config.show()
def set_bridge_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'])
    return _handle_bridge_intf(cps_obj, params)
예제 #3
0
def set_media_transceiver(interface_obj):
    # get front panel port from ifindex
    if_obj = cps_object.CPSObject(obj=interface_obj)
    npu = if_obj.get_attr_data('base-if-phy/if/interfaces/interface/npu-id')
    port = if_obj.get_attr_data('base-if-phy/if/interfaces/interface/port-id')
    nas_if.log_info("set_media_transceiver for "+str(npu)+" , " +str(port))
    enable = if_obj.get_attr_data('if/interfaces/interface/enabled')
    port_list = nas_if.nas_os_phy_list(
        d={'npu-id': npu, 'port-id': port})
    phy_obj = cps_object.CPSObject(obj=port_list[0])
    fanout = phy_obj.get_attr_data('fanout-mode')
    try:
        hwport = phy_obj.get_attr_data('hardware-port-id')
        fp_details = fp.find_port_by_hwport(npu, hwport)
    except:
        nas_if.log_err(" Error in setting media Transceiver for ", if_obj.get_attr_data('name'))
        return
    # set media transceiver using media Id and channel ID
    # in case of 40G mode all channels should be enabled/disabled
    #  else only one channel.
    #
    nas_if.log_info("fanout " + str(fanout))
    if fanout == 2:  # then it is in 4x10G fanout mode BASE_PORT_BREAKOUT_MODE_BREAKOUT_4X1
        _lane = fp_details.lane
    else:    # non-fanout mode 1x40g mode
        _lane = None # enable/disable all channels. Do not pass Lane #
    media.media_transceiver_set(1, fp_details.media_id, _lane, enable)
예제 #4
0
def update(cps_obj, params, cfg_obj):
    """Method to set attributes for the VTEP in Linux"""
    _remote_endpoints = remote_endpoints = []
    member_op = if_vtep_config.get_member_op(cps_obj)
    ret, remote_endpoints = if_vtep_config.get_remote_endpoint_list(cps_obj)

    while True:
        if member_op == 'add':
            ret, _remote_endpoints = __add_remote_endpoints(
                cfg_obj.name, remote_endpoints)
            if ret is False:
                break
        else:
            ret, _remote_endpoints = __remove_remote_endpoints(
                cfg_obj.name, remote_endpoints)
            if ret is False:
                break
        return True

    nas_if.log_err("Update VTEP Failed, Rolling back")
    if member_op == 'add':
        __remove_remote_endpoints(cfg_obj.name, _remote_endpoints)
    else:
        __add_remote_endpoints(cfg_obj.name, _remote_endpoints)
    return False
예제 #5
0
def create_loopback_interface(obj, params):
    name = None
    mac_str = None
    mac = None
    try:
        name = obj.get_attr_data('if/interfaces/interface/name')
        mac_str = obj.get_attr_data(
            'dell-if/if/interfaces/interface/phys-address')
    except:
        pass
    if name is None:
        nas_if.log_err("Failed to create interface without name")
        return False
    nas_if.log_info("interface name is" + str(name))
    lst = dn_base_ip_tool.get_if_details(name)
    if (len(lst)) > 0:
        nas_if.log_err("Interface already exists" + str(name))
        return False
    if mac_str is None:
        mac_str = ma.get_offset_mac_addr(ma.get_base_mac_addr(), 0)
    rc = dn_base_ip_tool.create_loopback_if(name, mac=mac_str)
    if rc:
        nas_if.log_info("loopback interface is created" + str(name))
        rc = set_loopback_interface(obj)
        if_index = ifindex_utils.if_nametoindex(name)
        obj.add_attr(nas_comm.yang.get_value('if_index', 'attr_name'),
                     if_index)
        params['change'] = obj.get()
    return rc
예제 #6
0
def process_media_event(npu, port, pas_media_obj):

    try:
        media_id = pas_media_obj.get_attr_data('base-pas/media/port')
        display_str = pas_media_obj.get_attr_data(
            'base-pas/media/display-string')
    except:
        nas_if.log_info(
            "Media event without enough attributes to determine default media settings"
        )
        return

    if_name = if_config.if_config_get_by_npu_port(npu, port)
    if if_name is None:
        nas_if.log_err("Interface Name: None")
        return False

    config = if_config.if_config_get(if_name)

    port = fp.find_front_panel_port(config.fp_port)
    pas_media_obj.add_attr('dell-if/if/interfaces/interface/speed',
                           config.get_speed())
    pas_media_obj.add_attr('base-if-phy/physical/speed',
                           fp.get_max_port_speed(port))
    config.set_media_obj(pas_media_obj)
    return True
def create_nas_ports(npu, hwports, br_mode, speed, phy_mode, fr_port,
                     created_phy_ports):
    if br_mode not in breakout_to_hwp_count:
        nas_if.log_err('unsupported breakout mode %d' % br_mode)
        return False

    hwp_count = breakout_to_hwp_count[br_mode]
    hwports.reverse()

    while len(hwports) != 0 and hwp_count != 0:
        i = 0
        hw_list = []
        if len(hwports) < hwp_count:
            nas_if.log_err('some problem in creating hwport len %s ' %
                           str(hwports))
            return False
        # Get hw_ports_list for creating new phy port
        while i < hwp_count:
            hw_list.append(hwports.pop())
            i = i + 1
        # Send request to create phy port with hwlist and port speed
        obj = cps_create_nas_port(npu, hw_list, speed, phy_mode, fr_port)
        if obj == None:
            return False
        created_phy_ports[hw_list[0]] = obj
    return True
예제 #8
0
def set_media_transceiver(interface_obj):
    # get front panel port from ifindex
    if_obj = cps_object.CPSObject(obj=interface_obj)
    npu = if_obj.get_attr_data('base-if-phy/if/interfaces/interface/npu-id')
    port = if_obj.get_attr_data('base-if-phy/if/interfaces/interface/port-id')
    enable = if_obj.get_attr_data('if/interfaces/interface/enabled')
    nas_if.log_info("set_media_transceiver as " + str(enable) + " for " +
                    str(npu) + " , " + str(port))
    port_list = nas_if.nas_os_phy_list(d={'npu-id': npu, 'port-id': port})
    phy_obj = cps_object.CPSObject(obj=port_list[0])
    try:
        hwport_list = phy_obj.get_attr_data('hardware-port-list')
    except:
        nas_if.log_err(" Error in setting media Transceiver for %s" %
                       if_obj.get_attr_data('name'))
        return
    # set media transceiver using media Id and channel ID
    #
    for hwport in hwport_list:
        fp_details = fp.find_port_by_hwport(npu, hwport)
        if fp_details.port_group_id is None:
            _lane = fp_details.lane
        else:
            pg_list = fp.get_port_group_list()
            pg_obj = pg_list[fp_details.port_group_id]
            if ((pg_obj.get_profile_type()) == "ethernet_ddqsfp28"):
                _lane = pg_obj.get_lane(hwport)
            else:
                _lane = fp_details.lane
        media.media_transceiver_set(1, fp_details.media_id, _lane, enable)
예제 #9
0
def _set_fec_mode(fec_mode, config, obj, op):
    if_cfg_speed = config.get_cfg_speed()
    if fec_mode != None:
        if not nas_comm.is_fec_supported(fec_mode, if_cfg_speed):
            _str_err = ('FEC mode %s is not supported with speed %s'
                        %(nas_comm.get_value(nas_comm.fec_mode_to_yang,fec_mode),
                        nas_comm.get_value(nas_comm.yang_to_mbps_speed,if_cfg_speed)))
            nas_if.log_err(_str_err)
            obj.set_error_string(1,_str_err)
            return False
    else:
        if (op == 'create' and
            nas_comm.is_fec_supported(nas_comm.get_value(nas_comm.yang_fec_mode, 'AUTO'), if_cfg_speed)):
            # set default FEC mode as auto to newly created interface
            fec_mode = nas_comm.get_value(nas_comm.yang_fec_mode, 'AUTO')
        else:
            return True

    nas_if.log_info('set FEC mode %d' % fec_mode)
    config.set_fec_mode(fec_mode)
    if fec_mode == nas_comm.get_value(nas_comm.yang_fec_mode, 'AUTO'):
        media_type = config.get_media_type()
        fec_mode = _get_default_fec_mode(media_type,if_cfg_speed)
    obj.add_attr(fec_mode_attr_name, fec_mode)
    return True
def get_intf_mac_addr(if_type, cps_obj, fp_cache=None):
    param_list = 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 None
    return if_get_mac_addr(**param_list)
def get_mac_addr_base_range(appl_name, type_name):
    def add_node_to_cache(appl, xml_node):
        n_type = xml_node.get('type')
        n_base = int(xml_node.get('base-offset'))
        n_range = int(xml_node.get('offset-range'))
        nas_if.log_info('%-15s: base %d range %d' % (n_type, n_base, n_range))
        appl_mac_info_cache[(appl, n_type)] = (n_base, n_range)

    if len(appl_mac_info_cache) == 0:
        try:
            cfg = ET.parse('/etc/opx/mac_address_alloc.xml')
        except IOError:
            nas_if.log_err('No mac address config file')
            return None
        root = cfg.getroot()
        for node in root.findall('interface'):
            add_node_to_cache('interface', node)
        for node in root.findall('application'):
            appl = node.get('name')
            for sub_node in node.findall('mac-range'):
                add_node_to_cache(appl, sub_node)

    if not (appl_name, type_name) in appl_mac_info_cache:
        nas_if.log_err(
            'No mac address setting for application %s and type %s' %
            (appl_name, type_name))
        return None
    return appl_mac_info_cache[(appl_name, type_name)]
예제 #12
0
def get_remote_endpoint_list(cps_obj):
    """Method to retrive a list of remote endpoints from the CPS object"""
    rlist = {}
    remote_endpoints = __read_attr(cps_obj, REMOTE_ENDPOINT_LIST)

    if remote_endpoints is not None:
        for name in remote_endpoints:
            ip = None
            addr_family = None
            flooding_enabled = None
            try:
                endpoint = remote_endpoints[name]

                addr_family = endpoint[REMOTE_ENDPOINT_ADDR_FAMILY]
                if addr_family is None:
                    return False, rlist
                cps_utils.cps_attr_types_map.add_type(
                    cps_obj.generate_path(
                        [REMOTE_ENDPOINT_LIST, name, REMOTE_ENDPOINT_IP_ADDR]),
                    INET_TO_STR_MAP[addr_family])

                ip = endpoint[REMOTE_ENDPOINT_IP_ADDR]
                flooding_enabled = endpoint[REMOTE_ENDPOINT_FLOODING_ENABLED]
            except ValueError:
                nas_if.log_err("Failed to read attr of remote endpoint")
                pass

            if ip is None or addr_family is None or flooding_enabled is None:
                return False, rlist
            rlist[ip] = RemoteEndpoint(ip, addr_family, flooding_enabled)

    return True, rlist
def get_remote_endpoint_list(cps_obj):
    """Method to retrive a list of remote endpoints from the CPS object"""
    rlist = {}
    remote_endpoints = __read_attr(cps_obj, REMOTE_ENDPOINT_LIST)

    if remote_endpoints is not None:
        for name in remote_endpoints:
            ip = None
            addr_family = None
            flooding_enabled = 1
            try:
                endpoint = remote_endpoints[name]
                nas_if.log_info(" remote endpoint %s" % (str(remote_endpoints)))
                addr_family = endpoint[REMOTE_ENDPOINT_ADDR_FAMILY]
                if addr_family is None:
                    return False, rlist
                ip = None
                if addr_family is socket.AF_INET:
                    ip_ba = ba.hex_to_ba('ipv4', endpoint[REMOTE_ENDPOINT_IP_ADDR])
                    ip = ba.ba_to_ipv4str('ipv4', ip_ba)
                else:
                    ip_ba = ba.hex_to_ba('ipv6', endpoint[REMOTE_ENDPOINT_IP_ADDR])
                    ip = ba.ba_to_ipv6str('ipv6', ip_ba)
                if REMOTE_ENDPOINT_FLOODING_ENABLED in endpoint:
                    flooding_enabled = endpoint[REMOTE_ENDPOINT_FLOODING_ENABLED]
            except ValueError:
                logging.exception('error:')
                nas_if.log_err("Failed to read attr of remote endpoint")
                pass

            if ip is None or addr_family is None or flooding_enabled is None:
                return False, rlist
            rlist[ip] = RemoteEndpoint(ip, addr_family, flooding_enabled)

    return True, rlist
def init_profile():

    while cps.enabled(nas_comm.yang.get_tbl('keys_id')['switch_key']) is False:
        nas_if.log_err('Switch profile service not yet ready')
        time.sleep(1)

    l = []
    obj = cps_object.CPSObject(
        module='base-switch/switching-entities/switching-entity',
        qual='observed',
        data={'switch-id': 0})
    if not cps.get([obj.get()], l):
        nas_if.log_info('Get profile : CPS GET FAILED')
        return False
    switch_obj = cps_object.CPSObject(obj=l[0])
    try:
        profile = switch_obj.get_attr_data(current_profile)
    except:
        nas_if.log_info("Current profile missing in CPS get")
        return False
    nas_if.log_info('Get profile returned ' + str(profile))
    profile = '/etc/opx/' + profile + '-base_port_physical_mapping_table.xml'
    if os.path.isfile(profile):
        fp.init(profile)
        return True
    else:
        nas_if.log_err('Profile file missing' + str(profile))
        return False
def set_if_speed(speed, config, obj):
    ''' Method to set Speed in CPS Object '''

    # 1. Interface Speed is pushed down to hardware based on media connected and if it is configured AUTO(default).
    # 2. Based on the port capability (QSFP+ or QSFP28) and mode configured(ethernet or FC), connected physical media
    #    may not be supported and media based default speed will not be pushed down to the NPU/Hardware.
    # 3. If user set something other than AUTO( default ) then it will be passed down without checking connected media.
    # 4. In case of ethernet fanout mode, default speed is skipped.
    if config.get_media_obj() is None:
        return True

    nas_if.log_info("Application Configured Breakout Mode: " +
                    str(config.get_breakout_mode()))
    nas_if.log_info("Application Configured Speed: " + str(speed))
    if speed != nas_comm.yang.get_value(
            'auto', 'yang-speed') and verify_intf_supported_speed(
                config, speed) is False:
        return False

    # Set in config object
    config.set_speed(speed)

    # Retrieve default setting
    if speed == nas_comm.yang.get_value('auto', 'yang-speed'):
        try:
            obj.del_attr(nas_comm.yang.get_value('speed', 'attr_name'))
        except:
            pass
        speed = _get_default_speed(config)
        nas_if.log_info('Default Speed: ' + str(speed))

    try:
        (npu_id, port_id) = config.get_npu_port()
        nas_if.log_info(
            'set_if_speed: Obtained npu %s and port %s from config for intf %s'
            % (str(npu_id), str(port_id), str(config.name)))
    except ValueError:
        nas_if.log_err(
            'Missing npu or port or non physical port cps obj request')
        nas_if.log_obj(obj.get())
        return False

    supported_speed_list = []
    supported_speed_list = port_utils.phy_port_supported_speed_get(
        npu_id, port_id)

    nas_if.log_info('supported-speed list: ' + str(supported_speed_list))
    # Add attribute to CPS object
    if speed is not None and verify_intf_supported_speed(config,
                                                         speed) == True:
        if speed in supported_speed_list:
            obj.add_attr(nas_comm.yang.get_value('speed', 'attr_name'), speed)
            nas_if.log_info('Added speed %s into obj' % str(speed))
        else:
            nas_if.log_err('speed %s not added into the obj' % str(speed))

    config.get_media_obj().add_attr(
        nas_comm.yang.get_value('speed', 'attr_name'), speed)
    return True
예제 #16
0
def get_member_op(cps_obj):
    """Method to read CPS attr of the member operation from CPS Object"""
    member_op = __read_attr(cps_obj, MEMBER_OP_ATTR_NAME)
    if member_op in OP_ID_TO_NAME_MAP:
        return OP_ID_TO_NAME_MAP[member_op]

    nas_if.log_err('Invalid operation type ' + str(member_op))
    return member_op
예제 #17
0
def __delete_vlan_sub_if(parent_intf, vlan_id):
    """Method to delete VLAN SubInterface in Linux"""
    vlan_subintf_name = str(parent_intf) + '.' + str(vlan_id)
    if dn_base_ip_tool.delete_if(vlan_subintf_name) is False:
        nas_if.log_err("Failed to delete VLAN SubInterface for " + str(vlan_subintf_name))
        return False
    nas_if.log_info("Successfully deleted VLAN SubInterface " + str(vlan_subintf_name))
    return True
예제 #18
0
def __create_vlan_sub_if(parent_intf, vlan_id):
    """Method to create VLAN SubInterface in Linux"""
    vlan_subintf_name = str(parent_intf) + '.' + str(vlan_id)
    if dn_base_ip_tool.configure_vlan_tag(parent_intf, vlan_id) is False:
        nas_if.log_err("Failed to configure VLAN tag for " + str(vlan_subintf_name))
        return False
    nas_if.log_info("Successfully created VLAN SubInterface " + str(vlan_subintf_name))
    return True
예제 #19
0
def _verify_intf_supported_speed(config, speed):
    # if it is ethernet type then check if the speed is supported globally
    intf_phy_mode = nas_comm.get_value(nas_comm.ietf_type_2_phy_mode, config.get_ietf_intf_type())
    if intf_phy_mode == nas_comm.get_value(nas_comm.yang_phy_mode, 'ether'):
        if  fp.verify_npu_supported_speed(speed) == False:
            nas_if.log_err('Configured speed not supported %s' % str(speed))
            return False
    return True
def __delete_br_if(br_name):
    """Method to delete bridge interface in Linux"""
    if __if_present(br_name) is True and \
       dn_base_br_tool.del_br(br_name) is False:
        nas_if.log_err("Failed to delete Bridge Interface " + str(br_name))
        return False
    nas_if.log_info("Successfully deleted Bridge Interface " + str(br_name))
    return True
예제 #21
0
def check_if_media_support_phy_mode(media_type, config):
    intf_phy_mode = nas_comm.get_value(nas_comm.ietf_type_2_phy_mode, config.get_ietf_intf_type())

    # Make sure that connected media supports  the configured intf phy mode.
    supported_phy_modes = media.get_default_media_setting(media_type, 'supported-phy-mode')
    if intf_phy_mode not in supported_phy_modes:
        nas_if.log_err('Connected media does not support configured phy mode')
        return(False)
    return(True)
예제 #22
0
def __delete_vtep_if(vtep_name):
    """Method to delete vtep interface in Linux"""
    if __if_present(vtep_name) is True and \
       dn_base_ip_tool.delete_if(vtep_name):
        nas_if.log_info("Successfully deleted VTEP Interface " +
                        str(vtep_name))
        return True
    nas_if.log_err("Failed to delete VTEP Interface " + str(vtep_name))
    return False
def get_intf_type(cps_obj):
    try:
        obj_if_type = cps_obj.get_attr_data('if/interfaces/interface/type')
    except:
        return None
    if not obj_if_type in nas_comm.yang.get_tbl('if_type_map'):
        nas_if.log_err('Unknown if type: ' + str(obj_if_type))
        return None
    return nas_comm.yang.get_value(obj_if_type, 'if_type_map')
예제 #24
0
def subscribe_events():
    while cps.enabled(nas_comm.yang.get_value('fp_key', 'keys_id')) == False:
        #wait for front panel port objects to be ready
        nas_if.log_err('Media or front panel port object is not yet ready')
        time.sleep(1)

    if_thread = interfaceMonitorThread(1, "Interface event Monitoring Thread")
    if_thread.daemon = True
    if_thread.start()
예제 #25
0
def check_if_media_supported(media_type, config):
    supported = True   # by default media is supported

    # Check if Ethernet QSFP28 plugged-in the QSFP+ slot
    if media.is_qsfp28_media_type(media_type):
        #check if front port supports QSFP28 media
        if fp.is_qsfp28_cap_supported(config.get_fp_port()) == False:
            nas_if.log_err('Connected media QSFP28 is not support in this port')
            supported = False
    return(supported)
예제 #26
0
def __read_attr(cps_obj, attr_id):
    """Method to read a CPS attribute value from the CPS object"""
    val = None
    try:
        val = cps_obj.get_attr_data(attr_id)
        nas_if.log_info("Value of CPS attr %s is %s: " % \
                        (str(attr_id), str(val)))
    except ValueError:
        nas_if.log_err("Failed to read value of the CPS attr %s" % str(attr_id))
    return val
def verify_intf_supported_speed(config, speed):
    ''' Method to verify if speed is supported by the interface '''

    # if it is ethernet type then check if the speed is supported globally
    intf_phy_mode = nas_comm.yang.get_value(config.get_ietf_intf_type(),
                                            'ietf-type-2-phy-mode')
    if intf_phy_mode == nas_comm.yang.get_value('ether', 'yang-phy-mode'):
        if fp.verify_npu_supported_speed(speed) == False:
            nas_if.log_err('Configured speed not supported %s' % str(speed))
            return False
    return True
예제 #28
0
def subscribe_events():

    while cps.enabled(nas_comm.yang.get_value('media_key',
                                              'keys_id')) == False:
        #wait for media and front panel port objects to be ready
        nas_if.log_err('Media or front panel port object is not yet ready')
        time.sleep(1)

    media_thread = mediaMonitorThread(2, "Media event Monitoring Thread")
    media_thread.daemon = True
    media_thread.start()
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
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