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 _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 is_40g_mode_on_100g_port(fp_obj): try: port_speed = fp_obj.get_attr_data('port-speed') def_port_speed = fp_obj.get_attr_data('default-port-speed') except ValueError: log_err('Unable to find supported-speed from cps object') return False # Checking if default port speed is 100g and port speed is 40g if (def_port_speed == nas_comm.get_value(nas_comm.yang_speed,'100G') and port_speed == nas_comm.get_value(nas_comm.yang_speed,'40G')): log_info('100G physical port was configured as 40G breakout mode') return True return False
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)
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)
def _get_default_fec_mode(media_type,if_speed): """ Auto option will configure default FEC. Default FEC for 100G is CL91 for all types of media. Default option for 25G/50G for 25/50G CR is CL108 and other 25/50g is OFF for all types of media. """ fec_mode = None media_str = media.get_media_str(media_type) if if_speed == nas_comm.get_value(nas_comm.yang_speed, '100G'): fec_mode = nas_comm.get_value(nas_comm.yang_fec_mode, 'CL91-RS') elif (if_speed == nas_comm.get_value(nas_comm.yang_speed, '25G') or if_speed == nas_comm.get_value(nas_comm.yang_speed, '50G')): if(media_str in media.fec_25g_cl108_support): fec_mode = nas_comm.get_value(nas_comm.yang_fec_mode, 'CL108-RS') else: fec_mode = nas_comm.get_value(nas_comm.yang_fec_mode, 'OFF') return fec_mode
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_handle_set_media_type(op, obj): nas_if.log_info('media obj: %s' % str(obj.get())) 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 ValueError: nas_if.log_info('missing npu,port or media type or non physical port cps obj request') nas_if.log_obj(obj.get()) return True # find npu, port in the _if_config if_name = if_config.if_config_get_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 False nas_if.log_info( "if name is " +str(if_name)) config = if_config.if_config_get(if_name) config.set_media_type(media_type) if check_if_media_supported(media_type, config) != True: config.set_is_media_supported(False) obj.del_attr(media_type_attr_name) return False if check_if_media_support_phy_mode(media_type, config) != True: config.set_is_media_supported(False) return False # Initialize default speed, hw_profile and negotiation to auto if not initialized if config.get_speed() is None: config.set_speed(_yang_auto_speed) if config.get_negotiation() is None: config.set_negotiation(_yang_auto_neg) config.set_is_media_supported(True) 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_speed() == _yang_auto_speed: speed = _get_default_speed(config) if speed is not None: obj.add_attr(speed_attr_name, speed) 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) if config.get_fec_mode() == nas_comm.get_value(nas_comm.yang_fec_mode, 'AUTO'): cfg_speed = config.get_cfg_speed() fec_cfg = _get_default_fec_mode(media_type, cfg_speed) if(fec_cfg is not None): obj.add_attr(fec_mode_attr_name,fec_cfg) _set_hw_profile(config, obj) # delete npu port attribute because NAS use them as flag for interface association obj.del_attr(npu_attr_name) obj.del_attr(port_attr_name) nas_if.log_info("media type setting is successful for " +str(if_name)) config.show() return True
shutdwn = False # Install signal handlers. import signal signal.signal(signal.SIGTERM, sigterm_hdlr) # Wait for base MAC address to be ready. the script will wait until # chassis object is registered. chassis_key = cps.key_from_name('observed','base-pas/chassis') while cps.enabled(chassis_key) == False: #wait for chassis object to be ready nas_if.log_err('Create Interface: Base MAC address is not yet ready') time.sleep(1) fp_utils.init() while cps.enabled(nas_comm.get_value(nas_comm.keys_id, 'physical_key')) == False: nas_if.log_info('Create Interface: Physical port service is not ready') time.sleep(1) port_list = port_utils.get_phy_port_list() port_utils.phy_port_cache_init(port_list) handle = cps.obj_init() # Register Front Panel POrt and HW port object handler fp_utils.nas_fp_cps_register(handle) # Register for Port Group handler pg_utils.nas_pg_cps_register(handle)
def create_interface(obj): ifobj = nas_if.make_interface_from_phy_port(obj) if if_cache.exists(ifobj.get_attr_data('if/interfaces/interface/name')): nas_if.log_err("Already exists.... " + str(ifobj.get_attr_data('if/interfaces/interface/name'))) return # create the object ch = {'operation': 'rpc', 'change': ifobj.get()} cps.transaction([ch]) nas_if.log_info("Interface Created : " + str(ifobj.get_attr_data('if/interfaces/interface/name'))) if __name__ == '__main__': while cps.enabled(nas_comm.get_value(nas_comm.keys_id, "fp_key")) == False: nas_if.log_err('fetch front panel port info not ready ') time.sleep(1) #in seconds front_panel_ports = nas_if.FpPortCache() if front_panel_ports.len() == 0: nas_if.log_err('front panel port info not present') while cps.enabled(nas_comm.get_value(nas_comm.keys_id, "physical_key")) == False: nas_if.log_err('physical port info not ready ') time.sleep(1) #in seconds port_cache = nas_if.PhyPortCache() if port_cache.len() ==0: nas_if.log_err('physical port info not present') if_cache = nas_if.IfCache()
def make_interface_from_phy_port(obj, mode = None, speed = None): npu = obj.get_attr_data('npu-id') hw_port_id = obj.get_attr_data('hardware-port-id') l = [] elem = cps_object.CPSObject(module=get_hw_key(), data={ 'npu-id': npu, 'hw-port': hw_port_id }) cps.get([elem.get()], l) if len(l) == 0: log_err('No object found for hardware port %d' % hw_port_id) log_err(str(elem.get())) raise Exception('Invalid port %d - no matching hardware-port' % hw_port_id) elem = cps_object.CPSObject(obj=l[0]) chassis_id = default_chassis_id slot_id = default_slot_id fp_port_id = elem.get_attr_data('front-panel-port') lane = elem.get_attr_data('subport-id') fp_obj = cps_object.CPSObject(module=get_fp_key(), data={ 'front-panel-port': fp_port_id }) l=[] cps.get([fp_obj.get()],l) if len(l) == 0: log_err('No object found for hardware port %d' % hw_port_id) log_err(str(elem.get())) raise Exception('Invalid port %d - no matching hardware-port' % hw_port_id) fp_obj = cps_object.CPSObject(obj=l[0]) if mode is None: mode = elem.get_attr_data('fanout-mode') if speed is None: speed = _yang_auto_speed _subport = lane_to_subport(mode, lane, is_40g_mode_on_100g_port(fp_obj)) if _subport is None: raise Exception('Failed to get subport id from br_mode %d lane %d' % ( mode, lane)) name = get_interface_name(chassis_id, slot_id, fp_port_id, _subport) # extract the port number from the phy port strcture (based on the hwid) port = obj.get_attr_data('port-id') # setting default MTU size during interface creation. _mtu = get_default_mtu() ifobj = cps_object.CPSObject(module='dell-base-if-cmn/set-interface', data={ 'dell-base-if-cmn/set-interface/input/operation': 1, 'if/interfaces/interface/name': name, 'base-if-phy/hardware-port/front-panel-port':fp_port_id, 'base-if-phy/hardware-port/subport-id':_subport, 'base-if-phy/if/interfaces/interface/npu-id': npu, 'base-if-phy/if/interfaces/interface/port-id': port, 'dell-if/if/interfaces/interface/mtu': _mtu, 'dell-if/if/interfaces/interface/negotiation':_yang_auto_neg, 'dell-if/if/interfaces/interface/speed':speed, 'dell-if/if/interfaces/interface/duplex':nas_comm.get_value(yang_duplex,'auto'), 'if/interfaces/interface/type':_g_if_eth_type}) return ifobj