def get_port_queue_id_list(port_name, queue_type): cps_data_list = [] ret_data_list = [] ifindex = nas_os_if_utils.name_to_ifindex(port_name) if ifindex is None: print 'Failed to get ifindex for port ', port_name return None if queue_type == 'ALL': queue_type = None queue_obj = nas_qos.QueueCPSObj(port_id=ifindex, queue_type=queue_type, queue_number=None) ret = cps.get([queue_obj.data()], cps_data_list) if ret == False: print 'Failed to get queue list' return None print '-' * 36 print '%-16s %-10s %s' % ('id', 'type', 'number') print '-' * 36 for cps_data in cps_data_list: m = nas_qos.QueueCPSObj(None, None, None, cps_data=cps_data) queue_id = m.extract_id() type_val = m.extract_attr('type') local_num = m.extract_attr('queue-number') if queue_type is None or queue_type == type_val: print '%-16x %-10s %s' % (queue_id, type_val, local_num) ret_data_list.append(queue_id) return ret_data_list
def init_interfaces(ifnames): if 'DN_QOS_CFG_PATH' in os.environ.keys(): qos_cfg_path = os.environ['DN_QOS_CFG_PATH'] else: qos_cfg_path = target_cfg_path xnode_root = ET.parse(get_cfg()).getroot() lookup_sched_prof = {} try: for xnode_obj in xnode_root: if xnode_obj.tag == 'SWITCH-GLOBALS': for xnode_glb_obj in xnode_obj: if xnode_glb_obj.tag == 'scheduler-profile': prof_id = create_scheduler_profile(xnode_glb_obj) lookup_sched_prof[xnode_glb_obj.attrib['tag']] = prof_id elif xnode_obj.tag == 'FRONT-PANEL-PORTS': for xnode_port_obj in xnode_obj: if xnode_port_obj.tag == 'scheduler-hierarchy-tree': for ifname in ifnames: ifidx = nas_os_if_utils.name_to_ifindex(ifname) init_sched_tree_on_port( xnode_port_obj, lookup_sched_prof, ifidx, ifname) except RuntimeError as r: syslog.syslog("Runtime Error: " + str(r)) sys.exit(1) if err_detected: sys.exit(1)
def to_cps_val(cls, name, val): if cls.is_attr_enum(name): der_val = nas_acl_utils.enum_get(cls.attr_enum_prefix(name) + val) der_val = bytearray_utils.type_to_ba['uint32_t']('uint32_t', der_val) elif cls.is_attr_intf(name): if isinstance(val, str) and not val.isdigit(): ifindex = if_utl.name_to_ifindex(val) if ifindex is None: raise ValueError("Unknown interface name" + val) der_val = bytearray_utils.type_to_ba['uint32_t']('uint32_t', ifindex) else: der_val = bytearray_utils.type_to_ba['uint32_t']('uint32_t', val) else: attr_type = cls.attr_type(name) if attr_type == 'opaque': return val if attr_type in ['uint8_t', 'uint16_t', 'uint32_t', 'uint64_t']: if isinstance(val, str): val = int(val, 0) else: val = int(val) der_val = bytearray_utils.type_to_ba[attr_type](attr_type, val) return der_val
def to_cps_val(cls, name, val): if cls.is_attr_enum(name): der_val = nas_acl_utils.enum_get( cls.attr_enum_prefix(name) + val) der_val = bytearray_utils.type_to_ba[ 'uint32_t']('uint32_t', der_val) elif cls.is_attr_intf(name): if isinstance(val, str) and not val.isdigit(): ifindex = if_utl.name_to_ifindex(val) if ifindex is None: raise ValueError("Unknown interface name" + val) der_val = bytearray_utils.type_to_ba[ 'uint32_t']('uint32_t', ifindex) else: der_val = bytearray_utils.type_to_ba[ 'uint32_t']('uint32_t', val) else: attr_type = cls.attr_type(name) if attr_type == 'opaque': return val if attr_type in ['uint8_t', 'uint16_t', 'uint32_t', 'uint64_t']: if isinstance(val, str): val = int(val, 0) else: val = int(val) der_val = bytearray_utils.type_to_ba[attr_type](attr_type, val) return der_val
def init_interfaces(ifnames): xnode_root = ET.parse(get_cfg()).getroot() lookup_sched_prof = {} lookup_buf_prof = {} lookup_map = {} # build the profile list read_current_buf_prof(lookup_buf_prof) if lookup_sched_prof == {}: return read_current_sched_prof(lookup_sched_prof) if lookup_sched_prof == {}: return for map_type in map_types: read_current_map(lookup_map, map_type) if lookup_map == {}: return if (dbg_on): print lookup_buf_prof print lookup_sched_prof print lookup_map if (lookup_sched_prof == {} or lookup_buf_prof == {} or lookup_map == {}): return try: for xnode_obj in xnode_root: if xnode_obj.tag == 'FRONT-PANEL-PORTS': for ifname in ifnames: ifidx = nas_os_if_utils.name_to_ifindex(ifname) speed = 0 intf = nas_os_if_utils.nas_os_if_list({'if-index': ifidx}) if intf: obj = cps_object.CPSObject(obj=intf[0]) speed = get_max_speed(obj) init_port(ifidx, ifname, 'ianaift:ethernetCsmacd', speed, xnode_obj, lookup_map, lookup_sched_prof, lookup_buf_prof) except RuntimeError as r: syslog.syslog("Runtime Error: " + str(r)) sys.exit(1) if err_detected: sys.exit(1)