def get_mac_offset_from_fp(fp_port, sub_port, fp_cache=None):
    nas_if.log_info(
        'Trying to get npu port based on front-panel %d subport %d' %
        (fp_port, sub_port))
    if fp_cache is None:
        # Use local front-panel-port db
        port_obj = fp.find_front_panel_port(fp_port)
        if port_obj is None:
            raise ValueError('Front-panel-port %d not found in cache' %
                             fp_port)
        br_mode = port_obj.get_breakout_mode()
        mac_offset = port_obj.mac_offset
    else:
        cps_port_obj = fp_cache.get(fp_port)
        if cps_port_obj is None:
            raise ValueError('Front-panel-port %d not found in cps cache' %
                             fp_port)
        br_mode = nas_if.get_cps_attr(cps_port_obj, _fp_attr('breakout-mode'))
        mac_offset = nas_if.get_cps_attr(cps_port_obj, _fp_attr('mac-offset'))
        if br_mode is None or mac_offset is None:
            raise ValueError('Mandatory attributes not found in cps object')

    nas_if.log_info('Cached breakout mode of front panel port %d is %d' %
                    (fp_port, br_mode))
    lane_id = nas_comm.subport_to_lane(br_mode, sub_port)
    if lane_id is 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))

    return mac_offset + lane_id
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)