コード例 #1
0
ファイル: enodeb_status.py プロジェクト: go-magma/magma
def get_enb_status(enodeb: EnodebAcsStateMachine) -> EnodebStatus:
    """
    Returns a dict representing the status of an enodeb

    The returned dictionary will be a subset of the following keys:
        - enodeb_connected
        - enodeb_configured
        - opstate_enabled
        - rf_tx_on
        - rf_tx_desired
        - gps_connected
        - ptp_connected
        - mme_connected
        - gps_latitude
        - gps_longitude

    The set of keys returned will depend on the connection status of the
    enodeb. A missing key indicates that the value is unknown.

    Returns:
        Status dictionary for the enodeb state
    """
    enodeb_configured = enodeb.is_enodeb_configured()

    # We cache GPS coordinates so try to read them before the early return
    # if the enB is not connected
    gps_lat, gps_lon = _get_and_cache_gps_coords(enodeb)

    enodeb_connected = enodeb.is_enodeb_connected()
    opstate_enabled = _parse_param_as_bool(enodeb, ParameterName.OP_STATE)
    rf_tx_on = _parse_param_as_bool(enodeb, ParameterName.RF_TX_STATUS)
    rf_tx_on = rf_tx_on and enodeb_connected
    try:
        enb_serial = \
            enodeb.device_cfg.get_parameter(ParameterName.SERIAL_NUMBER)
        rf_tx_desired = get_enb_rf_tx_desired(enodeb.mconfig, enb_serial)
    except (KeyError, ConfigurationError):
        rf_tx_desired = False
    mme_connected = _parse_param_as_bool(enodeb, ParameterName.MME_STATUS)
    gps_connected = _get_gps_status_as_bool(enodeb)
    try:
        ptp_connected = _parse_param_as_bool(enodeb, ParameterName.PTP_STATUS)
    except ConfigurationError:
        ptp_connected = False

    return EnodebStatus(enodeb_configured=enodeb_configured,
                        gps_latitude=gps_lat,
                        gps_longitude=gps_lon,
                        enodeb_connected=enodeb_connected,
                        opstate_enabled=opstate_enabled,
                        rf_tx_on=rf_tx_on,
                        rf_tx_desired=rf_tx_desired,
                        gps_connected=gps_connected,
                        ptp_connected=ptp_connected,
                        mme_connected=mme_connected,
                        fsm_state=enodeb.get_state())
コード例 #2
0
ファイル: enodeb_status.py プロジェクト: sriprasads/magma
def _parse_param_as_bool(enodeb: EnodebAcsStateMachine,
                         param_name: ParameterName) -> str:
    """ Returns '1' for true, and '0' for false """
    try:
        return _format_bool(enodeb.get_parameter(param_name), param_name)
    except (KeyError, ConfigurationError):
        return '0'
コード例 #3
0
def _parse_param_as_bool(
        enodeb: EnodebAcsStateMachine,
        param_name: ParameterName
) -> bool:
    try:
        return _format_as_bool(enodeb.get_parameter(param_name), param_name)
    except (KeyError, ConfigurationError):
        return False
コード例 #4
0
ファイル: enodeb_status.py プロジェクト: go-magma/magma
def _get_gps_status_as_bool(enodeb: EnodebAcsStateMachine) -> bool:
    try:
        if not enodeb.has_parameter(ParameterName.GPS_STATUS):
            return False
        else:
            param = enodeb.get_parameter(ParameterName.GPS_STATUS)
            stripped_value = param.lower().strip()
            if stripped_value == '0' or stripped_value == '2':
                # 2 = GPS locking
                return False
            elif stripped_value == '1':
                return True
            else:
                logger.warning('GPS status parameter not understood (%s)',
                               param)
                return False
    except (KeyError, ConfigurationError):
        return False
コード例 #5
0
ファイル: enodeb_status.py プロジェクト: tcirstea/magma
def _get_and_cache_gps_coords(enodeb: EnodebAcsStateMachine) -> tuple:
    """
    Read the GPS coordinates of the enB from its configuration or the
    cached coordinate file if the preceding read fails. If reading from
    enB configuration succeeds, this method will cache the new coordinates.

    Returns:
        (str, str): GPS latitude, GPS longitude
    """
    lat, lon = '', ''
    try:
        lat = enodeb.get_parameter(ParameterName.GPS_LAT)
        lon = enodeb.get_parameter(ParameterName.GPS_LONG)

        if lat != _gps_lat_cached or lon != _gps_lon_cached:
            _cache_new_gps_coords(lat, lon)
        return lat, lon
    except (KeyError, ConfigurationError):
        return _get_cached_gps_coords()
    except ValueError:
        logging.warning('GPS lat/long not understood (%s/%s)', lat, lon)
        return '0', '0'
コード例 #6
0
ファイル: enodeb_status.py プロジェクト: shmurthy62/magma
def _parse_param_as_bool(enodeb: EnodebAcsStateMachine,
                         param_name: ParameterName) -> str:
    """
    Returns '1' for true, and '0' for false
    """
    try:
        param = enodeb.get_parameter(param_name)
        pval = str(param).lower().strip()
        if pval in {'true', '1'}:
            return '1'
        elif pval in {'false', '0'}:
            return '0'
        else:
            logging.warning('%s parameter not understood (%s)', param_name,
                            param)
            return '0'
    except (KeyError, ConfigurationError):
        return '0'
コード例 #7
0
ファイル: enodeb_status.py プロジェクト: tcirstea/magma
def get_enb_status(enodeb: EnodebAcsStateMachine) -> EnodebStatus:
    """
    Returns a dict representing the status of an enodeb

    The returned dictionary will be a subset of the following keys:
        - enodeb_connected
        - enodeb_configured
        - opstate_enabled
        - rf_tx_on
        - gps_connected
        - ptp_connected
        - mme_connected
        - gps_latitude
        - gps_longitude

    The set of keys returned will depend on the connection status of the
    enodeb. A missing key indicates that the value is unknown.

    Returns:
        Status dictionary for the enodeb state
    """
    enodeb_configured = '1' if enodeb.is_enodeb_configured() else '0'

    # We cache GPS coordinates so try to read them before the early return
    # if the enB is not connected
    gps_lat, gps_lon = _get_and_cache_gps_coords(enodeb)

    enodeb_connected = '1' if enodeb.is_enodeb_connected() else '0'
    opstate_enabled = _parse_param_as_bool(enodeb, ParameterName.OP_STATE)
    rf_tx_on = _parse_param_as_bool(enodeb, ParameterName.RF_TX_STATUS)
    mme_connected = _parse_param_as_bool(enodeb, ParameterName.MME_STATUS)

    try:
        if not enodeb.has_parameter(ParameterName.GPS_STATUS):
            gps_connected = '0'
        else:
            param = enodeb.get_parameter(ParameterName.GPS_STATUS)
            pval = param.lower().strip()
            if pval == '0' or pval == '1':
                gps_connected = pval
            elif pval == '2':
                # 2 = GPS locking
                gps_connected = '0'
            else:
                logging.warning(
                    'GPS status parameter not understood (%s)', param)
                gps_connected = '0'
    except (KeyError, ConfigurationError):
        gps_connected = '0'

    try:
        if not enodeb.has_parameter(ParameterName.PTP_STATUS):
            ptp_connected = '0'
        else:
            param = enodeb.get_parameter(ParameterName.PTP_STATUS)
            pval = param.lower().strip()
            if pval == '0' or pval == '1':
                ptp_connected = pval
            else:
                logging.warning(
                    'PTP status parameter not understood (%s)', param)
                ptp_connected = '0'
    except (KeyError, ConfigurationError):
        ptp_connected = '0'

    return EnodebStatus(enodeb_configured=enodeb_configured,
                        gps_latitude=gps_lat,
                        gps_longitude=gps_lon,
                        enodeb_connected=enodeb_connected,
                        opstate_enabled=opstate_enabled,
                        rf_tx_on=rf_tx_on,
                        gps_connected=gps_connected,
                        ptp_connected=ptp_connected,
                        mme_connected=mme_connected,
                        enodeb_state=enodeb.get_state())