def set_port_egr_map(port_name, map_id, eg_map_name): # Set the TC to Q map for port e00-1 op = nas_qos.EgPortCPSObj(ifname=port_name) op.set_attr(eg_map_name, map_id) upd = ('set', op.data()) if cps_utils.CPSTransaction([upd]).commit() == False: print "Failed to set " + eg_map_name + " for port " + port_name else: print "Successfully set " + eg_map_name + " for port " + port_name
def bind_obj_to_port(attr_name, obj_id, direction, ifname): dbg_print('{0} Binding on port {1}: {2} = {3}'.format( direction, ifname, attr_name, str(obj_id))) port = None if direction == 'ingress': port = nas_qos.IngPortCPSObj(ifname=ifname, list_of_attr_value_pairs=[(attr_name, obj_id)]) else: port = nas_qos.EgPortCPSObj(ifname=ifname, list_of_attr_value_pairs=[(attr_name, obj_id)]) upd = ('set', port.data()) ret_cps_data = cps_utils.CPSTransaction([upd]).commit() if ret_cps_data == False: raise RuntimeError("Failed to bind " + attr_name + " to port " + ifname)
def test_qos_port_egress(port_name): print 'Test qos port-egress for port %s' % port_name """ print 'Start to create port-egress map profiles' tc_color_dot1p_entries = [(0, 'RED', 0), (0, 'GREEN', 1), (5, 'RED', 2)] tc_color_dot1p_id = create_map_example('tc-color-to-dot1p-map', tc_color_dot1p_entries) if tc_color_dot1p_id == None: print 'Failed to cread tc-color-to-dot1p map' return False get_map_example('tc-color-to-dot1p-map', tc_color_dot1p_id) tc_color_dscp_entries = [(0, 'GREEN', 0), (1, 'YELLOW', 1), (2, 'RED', 2)] tc_color_dscp_id = create_map_example('tc-color-to-dscp-map', tc_color_dscp_entries) if tc_color_dscp_id == None: print 'Failed to cread tc-color-to-dscp map' return False get_map_example('tc-color-to-dscp-map', tc_color_dscp_id) """ print 'Start to create scheduler profile' sched_id = scheduler_profile_create_example( 'WRR', 50, 10000, 200, 50000, 200) if sched_id is None: print 'Failed to create scheduler profile' return False scheduler_profile_get_example(sched_id) print 'Setup port egress porfile with maps and scheduler' attr_entries = [ # ('tc-color-to-dot1p-map', tc_color_dot1p_id), #('tc-color-to-dscp-map', tc_color_dscp_id), ('scheduler-profile-id', sched_id)] port_eg_obj = nas_qos.EgPortCPSObj(ifname=port_name, list_of_attr_value_pairs=attr_entries) upd = ('set', port_eg_obj.data()) if cps_utils.CPSTransaction([upd]).commit() == False: print 'Failed to set maps and scheduler for port %s' % port_name return False return_data_list = [] ret = cps.get([port_eg_obj.data()], return_data_list) if ret: print '#### Port Egress Profile ####' for cps_ret_data in return_data_list: m = nas_qos.EgPortCPSObj(cps_data=cps_ret_data) m.print_obj() else: print 'Error in get' return False print 'Reset map and scheduler in port egress profile' attr_entries = [ # ('tc-color-to-dot1p-map', 0), #('tc-color-to-dscp-map', 0), ('scheduler-profile-id', 0)] port_eg_obj = nas_qos.EgPortCPSObj(ifname=port_name, list_of_attr_value_pairs=attr_entries) upd = ('set', port_eg_obj.data()) if cps_utils.CPSTransaction([upd]).commit() == False: print 'Failed to set maps and scheduler for port %s' % port_name return False return_data_list = [] ret = cps.get([port_eg_obj.data()], return_data_list) if ret: print '#### Port Egress Profile ####' for cps_ret_data in return_data_list: m = nas_qos.EgPortCPSObj(cps_data=cps_ret_data) m.print_obj() else: print 'Error in get' return False """ print 'Start to delete port-egress map profiles' ret = delete_map_example('tc-color-to-dot1p-map', tc_color_dot1p_id) if ret == False: print 'Failed to delete tc-color-to-dot1p map' return False ret = delete_map_example('tc-color-to-dscp-map', tc_color_dscp_id) if ret == False: print 'Failed to delete tc-color-to-dscp map' return False """ print 'Start to delete scheduler profile' ret = scheduler_profile_delete_example(sched_id) if ret is None: print 'Failed to delete scheduler profile' return False return True