def get_npu_port_from_fp(fp_port, sub_port): nas_if.log_info( 'Trying to get npu port based on front-panel %d subport %d' % (fp_port, sub_port)) port_obj = fp.find_front_panel_port(fp_port) if port_obj == None: raise ValueError('Front-panel-port %d not found in cache' % fp_port) br_mode = port_obj.get_breakout_mode() nas_if.log_info('Cached breakout mode of front panel port %s is %s' % (str(fp_port), str(br_mode))) lane_id = nas_comm.subport_to_lane(br_mode, sub_port) if lane_id == 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)) npu_id = port_obj.npu hw_port = port_obj.hwports[lane_id] nas_if.log_info('Front panel port %d lane %d hw-port %d' % (fp_port, lane_id, hw_port)) port_list = port_utils.get_phy_port_list() port_id = port_utils.hw_port_to_phy_port(port_list, npu_id, hw_port) if port_id == -1: raise ValueError( 'There is no physical mapped to hw_port %d for subport %d' % (hw_port, sub_port)) return (npu_id, port_id, hw_port)
def set_fp_port_config(fr_port, br_mode, phy_port_speed, phy_mode): nas_if.log_info( 'Front-panel-port %d config request: br_mode %s speed %s phy_mode %s' % (fr_port, br_mode, phy_port_speed, phy_mode)) fp_port_obj = fp.find_front_panel_port(fr_port) if fp_port_obj is None: nas_if.log_err('Front-panel-port %d not found' % fr_port) return False npu = fp_port_obj.npu if phy_mode == None: phy_mode = nas_comm.yang.get_value('ether', 'yang-phy-mode') #Check if breakout mode is same as current breakout mode if (br_mode == fp_port_obj.get_breakout_mode() and fp_port_obj.get_phy_mode() == phy_mode and fp_port_obj.get_port_speed() == phy_port_speed): nas_if.log_info('FP config is same as current config') return True #check if breakout mode is supported by the FP port ( not now) # TODO port_list = port_utils.get_phy_port_list() #convert FP port to Hwport list ( control port) hwports = fp_port_obj.hwports[:] deleted_phy_ports = {} for hwport in hwports: phy_port_obj = port_utils.get_phy_port_by_hw_port( port_list, npu, hwport) if phy_port_obj == None: continue if port_utils.cps_del_nas_port(phy_port_obj): port_utils.del_phy_port(port_list, phy_port_obj) deleted_phy_ports[hwport] = phy_port_obj else: nas_if.log_err('Failed to delete physical port') return False # Create new phy ports based on the new breakout mode created_phy_ports = {} if port_utils.create_nas_ports(npu, hwports, br_mode, phy_port_speed, phy_mode, fr_port, created_phy_ports) == True: for port in created_phy_ports: port_utils.add_phy_port(port_list, created_phy_ports[port]) else: nas_if.log_err( 'Failed to create physical port, rollback to previous status') port_utils.rollback_port_add_del(port_list, created_phy_ports, deleted_phy_ports, fp_port_obj.get_port_speed(), fp_port_obj.get_phy_mode()) return False #set new breakout mode and new port speed fp_port_obj.set_breakout_mode(br_mode) fp_port_obj.set_port_speed(phy_port_speed) send_fp_event(fp_port_obj) return True
def _gen_npu_lanes(obj, resp): port_list = port_utils.get_phy_port_list() for npu in fp.get_npu_list(): key_dict = {_lane_attr('npu-id'): npu.id} if not obj.key_compare(key_dict): continue for p in npu.ports: port = npu.ports[p] for h in port.hwports: if not obj.key_compare({_lane_attr('hw-port'): h}): continue elem = cps_object.CPSObject(module='base-if-phy/hardware-port', data={ 'npu-id': npu.id, 'hw-port': h, 'front-panel-port': port.id, 'hw-control-port': port.control_port(), 'subport-id': port.lane(h), 'fanout-mode': port.get_breakout_mode() }) nas_if.log_info(str(elem.get())) resp.append(elem.get())
def set_fp_to_hwp_mapping(fr_port, br_mode, port_speed, phy_mode, hwports): # If hwports is empty then delete all phy ports under the FP and set the hwport list to NOne port_detail = fp.find_front_panel_port(fr_port) if port_detail == None: return False hwp_list = port_detail.get_hwports() port_list = port_utils.get_phy_port_list() if len(hwports) == 0: npu = port_detail.npu if hwp_list != None: for hwp in hwp_list: phy_obj = port_utils.get_phy_port_by_hw_port( port_list, npu, hwp) if phy_obj != None: # delete the physical port ret = port_utils.cps_del_nas_port(phy_obj) if ret == False: nas_if.log_err(' failed to delete Phy port') return False # Delete hwp to phy port mapping port_utils.del_phy_port(port_list, phy_obj) hwports += hwp_list # set the hw port list to None port_detail.set_hwports(None) # set breakout mode to None port_detail.set_breakout_mode(None) return True else: # hwports is not empty. It means add the hwport to the fp port # create phy port corresponding to the hwport # check if hwport list is empty if hwp_list != None and len(hwp_list) > 0: # hw port list is not empty, return False print 'port list is not empty' return False port_detail.set_hwports(hwports) # Now create phy ports base on the new hw port list. ret = set_fp_port_config(fr_port, br_mode, port_speed, phy_mode) if not ret: # Rollback port_detail.set_hwports(None) return ret return True
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) # Register for Hybrid Group handler hg_utils.nas_hg_cps_register(handle)