def print_stats(obj):
    if len(filters) != 0:
        for item in filters:
            if item in obj:
                print '{:40s} {:d}'.format(item.split("/")[-1], ba.from_ba(obj[item], "uint64_t"))
    else:
        for item in obj:
            print item + ':  ' + str(ba.from_ba(obj[item], "uint64_t"))
    print "\n\n"
def print_ether_stats(obj):
    print "Ether statistics:" + "\n"
    for stat in ether_stats:
        oid = ether_stats_oid_mapping[stat]
        print '    ' + stat + ': ' + str(ba.from_ba(obj['data'][oid], "uint64_t"))
    val1 = ba.from_ba(obj['data']['if/interfaces-state/interface/statistics/out-discards'], "uint64_t")
    val2 = ba.from_ba(obj['data']['if/interfaces-state/interface/statistics/in-discards'], "uint64_t")
    print '    buffer-overrun errors: ', (val1+val2)
    print "\n\n"
def print_ether_stats(obj):
    print "Ether statistics:" + "\n"
    for stat in ether_stats:
        oid = ether_stats_oid_mapping[stat]
        print '    ' + stat + ': ' + str(
            ba.from_ba(obj['data'][oid], "uint64_t"))
    print "\n\n"
Example #4
0
def if_media_type_set(pas_media_obj):
    try:
        media_id = pas_media_obj.get_attr_data('port')
        media_type = pas_media_obj.get_attr_data('type')
    except:
        nas_if.log_info(
            "media Id or media type is not present in the media event")
        return
    # fetch FP info from media ID
    l = nas_if.nas_os_fp_list(d={'media-id': media_id})
    if len(l) == 0:
        nas_if.log_err("No such port found... for media  " + str(media_id))
        return

    #fetching 2 front panel port object from 1 phy media id for QSFP28-DD ports
    port_list = []
    for fp_obj in l:
        obj = cps_object.CPSObject(obj=fp_obj)
        if _fp_port_key == obj.get_key():
            port_list = port_list + nas_if.physical_ports_for_front_panel_port(
                obj)

    if len(port_list) == 0:
        nas_if.log_err("There are no physical ports for front panel port ")
        nas_if.log_err(l[0])
        return

    # create interface set RPC obj for each phy port in the list and send it
    for p in port_list:
        npu = p.get_attr_data('npu-id')
        port = p.get_attr_data('port-id')
        hwport_list = p.get_attr_data('hardware-port-list')

        nas_if.log_info("send if rpc for media id set for phy port " +
                        str(port))
        ifobj = cps_object.CPSObject(
            module='dell-base-if-cmn/set-interface',
            data={
                'dell-base-if-cmn/set-interface/input/operation': 3,
                'base-if-phy/if/interfaces/interface/npu-id': npu,
                'base-if-phy/if/interfaces/interface/port-id': port,
                'base-if-phy/if/interfaces/interface/phy-media': media_type,
                'if/interfaces/interface/type': "ianaift:ethernetCsmacd"
            })
        ch = {'operation': 'rpc', 'change': ifobj.get()}
        cps.transaction([ch])
        if_name = str(
            ch['change']['data']['if/interfaces/interface/name'])[:-1]
        if_details = nas_if.nas_os_if_list(
            d={'if/interfaces/interface/name': if_name})
        enable = ba.from_ba(
            if_details[0]['data']['if/interfaces/interface/enabled'],
            "uint64_t")
        for hwport in hwport_list:
            fp_details = fp.find_port_by_hwport(npu, hwport)
            _lane = fp_details.lane
            media_transceiver_set(1, fp_details.media_id, _lane, enable)
    nas_if.log_info("setting media id: " + str(media_id) + " media type: " +
                    str(media_type))
def if_media_type_set(pas_media_obj):
    try:
        media_id = pas_media_obj.get_attr_data('port')
        media_type = pas_media_obj.get_attr_data('type')
    except:
        nas_if.log_err(
            "media Id or media type is not present in the media event")
        return
    # fetch FP info from media ID
    l = nas_if.nas_os_fp_list(d={'media-id': media_id})
    if len(l) == 0:
        nas_if.log_err("No such port found... for media  " + str(media_id))
        return

    # fetch PHY port list for the FP port
    port_list = nas_if.physical_ports_for_front_panel_port(
        cps_object.CPSObject(obj=l[0]))
    if len(port_list) == 0:
        nas_if.log_err("There are no physical ports for front panel port ")
        nas_if.log_err(l[0])
        return

    # create interface set RPC obj for each phy port in the list and send it
    for p in port_list:
        npu = p.get_attr_data('npu-id')
        port = p.get_attr_data('port-id')
        fanout = p.get_attr_data('fanout-mode')
        hwport = p.get_attr_data('hardware-port-id')

        nas_if.log_info("send if rpc for media id set for phy port " +
                        str(port))
        ifobj = cps_object.CPSObject(
            module='dell-base-if-cmn/set-interface',
            data={
                'dell-base-if-cmn/set-interface/input/operation': 3,
                'base-if-phy/if/interfaces/interface/npu-id': npu,
                'base-if-phy/if/interfaces/interface/port-id': port,
                'base-if-phy/if/interfaces/interface/phy-media': media_type,
                'if/interfaces/interface/type': "ianaift:ethernetCsmacd"
            })
        ch = {'operation': 'rpc', 'change': ifobj.get()}
        cps.transaction([ch])
        if_name = ba.ba_to_str(
            ch['change']['data']['if/interfaces/interface/name'],
            len(_if_name))
        if_details = nas_if.nas_os_if_list(
            d={'if/interfaces/interface/name': if_name})
        enable = ba.from_ba(
            if_details[0]['data']['if/interfaces/interface/enabled'],
            "uint64_t")
        fp_details = fp.find_port_by_hwport(npu, hwport)
        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_transceiver_set(1, fp_details.media_id, _lane, enable)
    nas_if.log_info("setting media id: " + str(media_id) + " media type: " +
                    str(media_type))
Example #6
0
def extract_cps_attr(qos_obj, cps_data, attr_name, yang_name=None):
    """
    Get value for attr from the CPS data returned by Create or Get

    @cps_data - CPS data returned by Create or Get
    """
    if yang_name is None:
        yang_name = qos_obj.yang_name

    type_map = qos_obj.get_type_map()

    cps_obj = extract_cps_obj(cps_data)
    path = name_to_path(yang_name, attr_name)

    if 'cps/key_data' in cps_obj and \
            path in cps_obj['cps/key_data']:
        return extract_cps_attr(qos_obj, cps_obj['cps/key_data'], attr_name)

    if path not in cps_obj:
        return None

    val = cps_obj[path]

    prfx = enum_prefix(type_map, attr_name)
    atype = attr_type(type_map, attr_name)

    if prfx is not None:
        der_val = ba_utils.from_ba(val, 'uint32_t')
        der_val = enum_reverse_get(der_val, enum_prefix(type_map, attr_name))
    elif atype is not None:
        if isinstance(val, list):
            der_val = []
            for ba_val in val:
                attr_val = ba_utils.from_ba(ba_val, atype)
                der_val.append(attr_val)
        else:
            if atype != 'string':
                der_val = ba_utils.from_ba(val, atype)
            else:
                der_val = ba_utils.ba_to_str(val, len(val))
    else:
        return val
    return der_val
Example #7
0
 def get_npu_list(self):
     cps_obj = utl.extract_cps_obj(self.data())
     path = utl.name_to_path(self.yang_name, 'npu-id-list')
     if path not in cps_obj:
         return None
     cps_id_list = cps_obj[path]
     npu_id_list = []
     for npu_id in cps_id_list:
         val = ba_utils.from_ba(npu_id, 'uint32_t')
         npu_id_list.append(val)
     return npu_id_list
Example #8
0
 def get_npu_list(self):
     cps_obj = utl.extract_cps_obj(self.data())
     path = utl.name_to_path(self.yang_name, 'npu-id-list')
     if path not in cps_obj:
         return None
     cps_id_list = cps_obj[path]
     npu_id_list = []
     for npu_id in cps_id_list:
         val = ba_utils.from_ba(npu_id, 'uint32_t')
         npu_id_list.append(val)
     return npu_id_list
Example #9
0
def extract_cps_attr(qos_obj, cps_data, attr_name, yang_name=None):
    """
    Get value for attr from the CPS data returned by Create or Get

    @cps_data - CPS data returned by Create or Get
    """
    if yang_name is None:
        yang_name = qos_obj.yang_name

    type_map = qos_obj.get_type_map()

    cps_obj = extract_cps_obj(cps_data)
    path = name_to_path(yang_name, attr_name)

    if 'cps/key_data' in cps_obj and \
            path in cps_obj['cps/key_data']:
        return extract_cps_attr(qos_obj, cps_obj['cps/key_data'], attr_name)

    if path not in cps_obj:
        return None

    val = cps_obj[path]

    prfx = enum_prefix(type_map, attr_name)
    atype = attr_type(type_map, attr_name)

    if prfx is not None:
        der_val = ba_utils.from_ba(val, 'uint32_t')
        der_val = enum_reverse_get(der_val, enum_prefix(type_map, attr_name))
    elif atype is not None:
        if isinstance(val, list):
            der_val = []
            for ba_val in val:
                attr_val = ba_utils.from_ba(ba_val, atype)
                der_val.append(attr_val)
        else:
            der_val = ba_utils.from_ba(val, atype)
    else:
        return val
    return der_val
Example #10
0
def set_intf_request(pas_media_obj):
    try:
        media_id = pas_media_obj.get_attr_data('port')
        display_str = pas_media_obj.get_attr_data(
            'base-pas/media/display-string')
    except:
        nas_if.log_info("Media String is not present in the media event")
        return

    # fetch FP info from media ID
    o = cps_object.CPSObject(
        module='base-if-phy/front-panel-port',
        data={'base-if-phy/front-panel-port/media-id': media_id})
    l = []
    fp_utils.gen_fp_port_list(o, l)
    if len(l) == 0:
        nas_if.log_err("No such port found... for media  " + str(media_id))
        return

    #fetching 2 front panel port object from 1 phy media id for QSFP28-DD ports
    port_list = []
    for fp_obj in l:
        obj = cps_object.CPSObject(obj=fp_obj)
        if nas_comm.yang.get_value('fp_key', 'keys_id') == obj.get_key():
            port_list = port_list + nas_if.physical_ports_for_front_panel_port(
                obj)

    if len(port_list) == 0:
        nas_if.log_err("There are no physical ports for front panel port ")
        nas_if.log_err(str(l[0]))
        return

    # create interface set RPC obj for each phy port in the list and send it
    for p in port_list:
        npu = p.get_attr_data('npu-id')
        port = p.get_attr_data('port-id')
        process_media_event(npu, port, pas_media_obj)
        hwport_list = p.get_attr_data('hardware-port-list')

        nas_if.log_info("send if obj for media id set for phy port " +
                        str(port))
        ifobj = cps_object.CPSObject(
            module='dell-base-if-cmn/if/interfaces/interface',
            data={
                'base-if-phy/if/interfaces/interface/npu-id': npu,
                'base-if-phy/if/interfaces/interface/port-id': port,
                'if/interfaces/interface/type': "ianaift:ethernetCsmacd"
            })
        if if_lib.set_media_setting(None, ifobj) == False:
            return
        ch = {'operation': 'set', 'change': ifobj.get()}
        cps.transaction([ch])
        if_name = if_config.if_config_get_by_npu_port(npu, port)
        if_details = nas_if.nas_os_if_list(
            d={'if/interfaces/interface/name': if_name})
        enable = ba.from_ba(
            if_details[0]['data']['if/interfaces/interface/enabled'],
            "uint64_t")
        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)
Example #11
0
    def check_statistics(self):

        switchid = dh.get_switch_by_physaddres()
        queryget = self.db_operations.GET_INTERFACE_NAMES
        names = self.db_operations.db_select_operation(queryget, switchid)
        octetsout = 0
        octetsin = 0
        timestamp = 0

        for name in names:
            nameenc = ''.join(chr(i) for i in name["name"])
            data = {'if/interfaces-state/interface/name': nameenc}
            obj = cps_object.CPSObject(
                qual='observed',
                module=
                'dell-base-if-cmn/if/interfaces-state/interface/statistics',
                data=data,
            )
            response = []
            if cps.get([obj.get()], response):
                for entry in response:
                    octetsinbytes = entry["data"][
                        "if/interfaces-state/interface/statistics/in-octets"]
                    octetsin = octetsin + bytearray_utils.from_ba(
                        octetsinbytes, "uint8_t")

                    octetsoutbytes = entry["data"][
                        "if/interfaces-state/interface/statistics/out-octets"]
                    octetsout = octetsout + bytearray_utils.from_ba(
                        octetsoutbytes, "uint8_t")

                    timestampbytes = entry["data"][
                        "dell-base-if-cmn/if/interfaces-state/interface/statistics/time-stamp"]
                    timestamp = bytearray_utils.from_ba(
                        timestampbytes, "uint8_t")

        octetsoutquery = 0
        octetsinquery = 0

        if self.secondscounter != 0:
            queryget = self.db_operations.GET_STATISTICS
            results = self.db_operations.db_select_operation(
                queryget, switchid)
            octetsoutquery = results[0]["packetsouthundredseconds"]
            octetsinquery = results[0]["packetsinhundredseconds"]

        self.secondscounter = self.secondscounter + 1
        queryinsert = self.db_operations.INSERT_STATISTICS

        if (self.secondscounter <= 10):
            queryargs2 = queryinsert.format(switchid, timestamp,
                                            self.secondscounter,
                                            self.lasttotalin - octetsin,
                                            octetsin,
                                            self.lasttotalout - octetsout,
                                            octetsout)
        else:
            queryargs2 = queryinsert.format(switchid, timestamp,
                                            self.secondscounter,
                                            self.lasttotalin - octetsin,
                                            octetsinquery,
                                            self.lasttotalout - octetsout,
                                            octetsoutquery)

        self.lasttotalin = octetsin
        self.lasttotalout = octetsout

        operations = []
        operations.append(queryargs2)
        self.db_operations.db_insert_operations(operations)
        self.log("Updated Statistics " + str(self.secondscounter) + " times.")