Commit 7f351d8e authored by gauthier's avatar gauthier

common files

parent e8bb5f3b
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file 3gpp_29.281.h
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_3GPP_29_281_SEEN
#define FILE_3GPP_29_281_SEEN
#include "3gpp_29.274.h"
#include "3gpp_commons.h"
#include "common_root_types.h"
#include "logger.hpp" // for fmt::format in spdlog
#include <arpa/inet.h>
#include <stdint.h>
#include <string>
#include <vector>
namespace oai::cn::proto::gtpv1u {
struct gtpu_exception : public std::exception {
gtpu_exception() throw() {
cause = 0;
phrase.assign("GTPV1-U Exception unknown cause");
}
gtpu_exception(int acause) throw() {
cause = acause;
phrase = fmt::format("GTPV1-U Exception cause {}", cause);
}
const char * what () const throw () {
return phrase.c_str();
}
public:
int cause;
std::string phrase;
};
struct gtpu_msg_bad_length_exception : public gtpu_exception {
public:
gtpu_msg_bad_length_exception(const uint8_t msg_type, const uint16_t msg_size) throw() {
phrase = fmt::format("GTPV1-U msg {} Bad Length {} Exception", msg_type, msg_size);
}
gtpu_msg_bad_length_exception(std::string& aphrase) throw() {
phrase = aphrase;
}
virtual ~gtpu_msg_bad_length_exception() throw(){}
};
struct gtpu_msg_unimplemented_ie_exception : public gtpu_exception {
public:
gtpu_msg_unimplemented_ie_exception(const uint8_t msg_type, const uint8_t ie_type, const uint8_t instance = 0) throw() {
phrase = fmt::format("GTPV1-U msg {} Unimplemented {} IE Instance {} Exception", msg_type, ie_type, instance);
}
gtpu_msg_unimplemented_ie_exception(std::string& aphrase) throw() {
phrase = aphrase;
}
virtual ~gtpu_msg_unimplemented_ie_exception() throw(){}
};
struct gtpu_msg_illegal_ie_exception : public gtpu_exception {
public:
gtpu_msg_illegal_ie_exception(const uint8_t msg_type, const uint8_t ie_type) throw() {
phrase = fmt::format("GTPV1-U msg {} Illegal {} Exception", msg_type, ie_type);
}
gtpu_msg_illegal_ie_exception(std::string& aphrase) throw() {
phrase = aphrase;
}
virtual ~gtpu_msg_illegal_ie_exception() throw(){}
};
struct gtpu_ie_exception : public gtpu_exception {
public:
gtpu_ie_exception(uint8_t ie_type) throw() {
phrase = fmt::format("GTPV1-U IE {} Exception", ie_type);
}
gtpu_ie_exception(std::string& aphrase) throw() {
phrase = aphrase;
}
virtual ~gtpu_ie_exception() throw(){}
};
struct gtpu_ie_unimplemented_exception : public gtpu_ie_exception {
public:
gtpu_ie_unimplemented_exception(uint8_t ie_type) throw() : gtpu_ie_exception(ie_type) {
phrase = fmt::format("GTPV1-U IE {} Unimplemented Exception", ie_type);
}
virtual ~gtpu_ie_unimplemented_exception() throw(){}
};
struct gtpu_tlv_exception : public gtpu_ie_exception {
public:
gtpu_tlv_exception(uint8_t ie_type) throw() : gtpu_ie_exception(ie_type) {
phrase = fmt::format("GTPV1-U IE TLV {} Exception", ie_type);
}
virtual ~gtpu_tlv_exception() throw(){}
};
struct gtpu_tlv_bad_length_exception : public gtpu_tlv_exception {
public:
gtpu_tlv_bad_length_exception(uint8_t ie_type, uint16_t ie_length) throw() : gtpu_tlv_exception(ie_type){
phrase = fmt::format("GTPV1-U IE TLV {} Bad Length {} Exception", ie_type);
}
virtual ~gtpu_tlv_bad_length_exception() throw(){}
};
struct gtpu_ie_value_exception : public gtpu_ie_exception {
public:
gtpu_ie_value_exception(uint8_t ie_type, const char* field) throw() : gtpu_ie_exception(ie_type){
phrase = fmt::format("GTPV1-U IE {} Bad Value of {} Exception", ie_type, field);
}
virtual ~gtpu_ie_value_exception() throw(){}
};
#define GTPU_IE_RECOVERY 14
#define GTPU_IE_TUNNEL_ENDPOINT_IDENTIFIER_DATA_I 16
#define GTPU_IE_GTP_U_PEER_ADDRESS 133
#define GTPU_IE_EXTENSION_HEADER_TYPE_LIST 141
#define GTPU_IE_PRIVATE_EXTENSION 255
#define GTPU_ECHO_REQUEST (1)
#define GTPU_ECHO_RESPONSE (2)
#define GTPU_ERROR_INDICATION (26)
#define GTPU_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION (31)
#define GTPU_END_MARKER (254)
#define GTPU_G_PDU (255)
} // namespace
namespace oai::cn::core {
// 8.2 Recovery
// 8.3 Tunnel Endpoint Identifier Data I
typedef struct tunnel_endpoint_identifier_data_i_s {
uint32_t tunnel_endpoint_identifier_data_i;
} tunnel_endpoint_identifier_data_i_t;
// 8.4 GTP-U Peer Address
typedef struct gtp_u_peer_address_s {
// may use variant if can stay with C++17
struct in_addr ipv4_address;
struct in6_addr ipv6_address;
bool is_v4;
} gtp_u_peer_address_t;
// 8.5 Extension Header Type List
typedef struct extension_header_type_list_s {
uint8_t length;
std::vector<uint8_t> extension_types_list;
} extension_header_type_list_t;
// 8.6 Private Extension defined in 3gpp_29.274.h
//typedef struct private_extension_s {
// uint16_t extension_identifier;
// std::string extension_value;
//} private_extension_t;
}
#endif /* FILE_3GPP_29_281_SEEN */
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file 3gpp_commons.h
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_3GPP_COMMONS_SEEN
#define FILE_3GPP_COMMONS_SEEN
#include "common_root_types.h"
#include "logger.hpp" // for fmt::format in spdlog
#include <arpa/inet.h>
#include <stdint.h>
#include <string>
#include <vector>
namespace oai::cn::core {
// 8.2 Recovery
typedef struct recovery_s {
uint8_t restart_counter;
} recovery_t;
}
#endif /* FILE_3GPP_29_281_SEEN */
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file common_defs.h
\brief
\author Sebastien ROUX, Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_COMMON_DEFS_SEEN
#define FILE_COMMON_DEFS_SEEN
#include <arpa/inet.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RETURNclear (int)2
#define RETURNerror (int)1
#define RETURNok (int)0
//------------------------------------------------------------------------------
#define DECODE_U8(bUFFER, vALUE, sIZE) \
vALUE = *(uint8_t*)(bUFFER); \
sIZE += sizeof(uint8_t)
#define DECODE_U16(bUFFER, vALUE, sIZE) \
vALUE = ntohs(*(uint16_t*)(bUFFER)); \
sIZE += sizeof(uint16_t)
#define DECODE_U24(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)) >> 8; \
sIZE += sizeof(uint8_t) + sizeof(uint16_t)
#define DECODE_U32(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)); \
sIZE += sizeof(uint32_t)
#if (BYTE_ORDER == LITTLE_ENDIAN)
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = ((*(bUFFER)) << 8) | (*((bUFFER) + 1)); \
sIZE += sizeof(uint16_t)
#else
# define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \
vALUE = (*(bUFFER)) | (*((bUFFER) + 1) << 8); \
sIZE += sizeof(uint16_t)
#endif
#define ENCODE_U8(buffer, value, size) \
*(uint8_t*)(buffer) = value; \
size += sizeof(uint8_t)
#define ENCODE_U16(buffer, value, size) \
*(uint16_t*)(buffer) = htons(value); \
size += sizeof(uint16_t)
#define ENCODE_U24(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint8_t) + sizeof(uint16_t)
#define ENCODE_U32(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
size += sizeof(uint32_t)
#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR,InAdDr,MeSsAgE ) do {\
if ( inet_aton(AdDr_StR, &InAdDr ) <= 0 ) {\
throw (MeSsAgE);\
}\
} while (0)
#define NIPADDR(addr) \
(uint8_t)(addr & 0x000000FF), \
(uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)((addr & 0x00FF0000) >> 16), \
(uint8_t)((addr & 0xFF000000) >> 24)
#define HIPADDR(addr) \
(uint8_t)((addr & 0xFF000000) >> 24),\
(uint8_t)((addr & 0x00FF0000) >> 16),\
(uint8_t)((addr & 0x0000FF00) >> 8), \
(uint8_t)(addr & 0x000000FF)
#define NIP6ADDR(addr) \
ntohs((addr)->s6_addr16[0]), \
ntohs((addr)->s6_addr16[1]), \
ntohs((addr)->s6_addr16[2]), \
ntohs((addr)->s6_addr16[3]), \
ntohs((addr)->s6_addr16[4]), \
ntohs((addr)->s6_addr16[5]), \
ntohs((addr)->s6_addr16[6]), \
ntohs((addr)->s6_addr16[7])
#define IN6_ARE_ADDR_MASKED_EQUAL(a,b,m) \
(((((__const uint32_t *) (a))[0] & (((__const uint32_t *) (m))[0])) == (((__const uint32_t *) (b))[0] & (((__const uint32_t *) (m))[0]))) \
&& ((((__const uint32_t *) (a))[1] & (((__const uint32_t *) (m))[1])) == (((__const uint32_t *) (b))[1] & (((__const uint32_t *) (m))[1]))) \
&& ((((__const uint32_t *) (a))[2] & (((__const uint32_t *) (m))[2])) == (((__const uint32_t *) (b))[2] & (((__const uint32_t *) (m))[2]))) \
&& ((((__const uint32_t *) (a))[3] & (((__const uint32_t *) (m))[3])) == (((__const uint32_t *) (b))[3] & (((__const uint32_t *) (m))[3]))))
#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif
#ifdef __cplusplus
}
#endif
#endif /* FILE_COMMON_DEFS_SEEN */
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file common_root_types.c
\brief
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#include "common_root_types.h"
#include "3gpp_23.003.h"
#ifdef __cplusplus
extern "C" {
#endif
//------------------------------------------------------------------------------
imsi64_t imsi_to_imsi64(imsi_t * const imsi)
{
imsi64_t imsi64 = INVALID_IMSI64;
if (imsi) {
imsi64 = 0;
for (int i=0; i < IMSI_BCD8_SIZE; i++) {
uint8_t d2 = imsi->u.value[i];
uint8_t d1 = (d2 & 0xf0) >> 4;
d2 = d2 & 0x0f;
if (10 > d1) {
imsi64 = imsi64*10 + d1;
if (10 > d2) {
imsi64 = imsi64*10 + d2;
} else {
break;
}
} else {
break;
}
}
}
return imsi64;
}
#ifdef __cplusplus
}
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file common_root_types.h
\brief
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_COMMON_ROOT_TYPES_SEEN
#define FILE_COMMON_ROOT_TYPES_SEEN
#include <stdint.h>
#include <inttypes.h>
#include <arpa/inet.h>
#ifdef __cplusplus
extern "C" {
#endif
//------------------------------------------------------------------------------
#define PRIORITY_LEVEL_MAX (15)
#define PRIORITY_LEVEL_MIN (1)
#define BEARERS_PER_UE (11)
#define IMEI_DIGITS_MAX (15)
#define IMEISV_DIGITS_MAX (16)
#define MAX_APN_PER_UE (5)
// TEIDs
typedef uint32_t teid_t;
#define TEID_FMT "0x%" PRIx32
#define TEID_SCAN_FMT SCNx32
#define INVALID_TEID ((teid_t)0x00000000)
#define UNASSIGNED_TEID ((teid_t)0x00000000)
// SEIDs
typedef uint64_t seid_t;
#define SEID_FMT "0x%" PRIx64
#define SEID_SCAN_FMT SCNx64
#define INVALID_SEID ((seid_t)0x00000000)
#define UNASSIGNED_SEID ((seid_t)0x00000000)
//------------------------------------------------------------------------------
// IMSI
typedef uint64_t imsi64_t;
#define IMSI_64_FMT "%" SCNu64
#define INVALID_IMSI64 (imsi64_t)0
//------------------------------------------------------------------------------
typedef uint64_t bitrate_t;
#define PRIORITY_LEVEL_FMT "0x%" PRIu8
#define QCI_FMT "0x%" PRIu8
#define QCI_SCAN_FMT SCNu8
#define PRE_EMPTION_CAPABILITY_FMT "0x%" PRIu8
#define PRE_EMPTION_VULNERABILITY_FMT "0x%" PRIu8
#ifdef __cplusplus
}
#endif
#endif /* FILE_COMMON_ROOT_TYPES_SEEN */
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "logger.hpp"
#include <iostream>
#include <sstream>
#include <string>
#include <memory>
Logger *Logger::m_singleton = NULL;
void Logger::_init( const char *app )
{
spdlog::set_async_mode( 2048 );
#if TRACE_IS_ON
spdlog::level::level_enum llevel = spdlog::level::trace;
m_sinks.push_back( std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>() );
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back( std::make_shared<spdlog::sinks::rotating_file_sink_mt>( filename, 5 * 1024 * 1024, 3 ) );
m_sinks[0].get()->set_level( llevel );
m_sinks[1].get()->set_level( llevel );
#elif DEBUG_IS_ON
spdlog::level::level_enum llevel = spdlog::level::debug;
m_sinks.push_back( std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>() );
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back( std::make_shared<spdlog::sinks::rotating_file_sink_mt>( filename, 5 * 1024 * 1024, 3 ) );
m_sinks[0].get()->set_level( llevel );
m_sinks[1].get()->set_level( llevel );
#elif INFO_IS_ON
spdlog::level::level_enum llevel = spdlog::level::info;
m_sinks.push_back( std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>() );
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back( std::make_shared<spdlog::sinks::rotating_file_sink_mt>( filename, 5 * 1024 * 1024, 3 ) );
m_sinks[0].get()->set_level( llevel );
m_sinks[1].get()->set_level( llevel );
#else
spdlog::level::level_enum llevel = spdlog::level::warn;
std::string filename = fmt::format("./{}.log", app);
m_sinks.push_back( std::make_shared<spdlog::sinks::rotating_file_sink_mt>( filename, 5 * 1024 * 1024, 3 ) );
m_sinks[0].get()->set_level( llevel );
#endif
//m_sinks.push_back( std::make_shared<spdlog::sinks::syslog_sink>() );
std::stringstream ss;
ss << "[%Y-%m-%dT%H:%M:%S.%f] [" << app << "] [%n] [%l] %v";
m_async_cmd = new _Logger( "async_c ", m_sinks, ss.str().c_str() );
m_enb_s1u = new _Logger( "enb_s1u ", m_sinks, ss.str().c_str() );
m_gtpv1_u = new _Logger( "gtpv1_u ", m_sinks, ss.str().c_str() );
m_gtpv2_c = new _Logger( "gtpv2_c ", m_sinks, ss.str().c_str() );
//m_gx = new _Logger( "gx ", m_sinks, ss.str().c_str() );
m_itti = new _Logger( "itti ", m_sinks, ss.str().c_str() );
m_mme_s11 = new _Logger( "mme_s11 ", m_sinks, ss.str().c_str() );
m_pgwc_app = new _Logger( "pgwc_app ", m_sinks, ss.str().c_str() );
//m_pgwu_app = new _Logger( "pgwu_app", m_sinks, ss.str().c_str() );
m_pgwc_s5s8 = new _Logger( "pgwc_s5 ", m_sinks, ss.str().c_str() );
m_pgwc_sx = new _Logger( "pgwc_sx ", m_sinks, ss.str().c_str() );
//m_pgwu_sx = new _Logger( "pgwu_sx ", m_sinks, ss.str().c_str() );
//m_pgw_udp = new _Logger( "pgw_udp ", m_sinks, ss.str().c_str() );
m_sgwc_app = new _Logger( "sgwc_app ", m_sinks, ss.str().c_str() );
//m_sgwu_app = new _Logger( "sgwu_app", m_sinks, ss.str().c_str() );
//m_sgwu_sx = new _Logger( "sgwu_sx ", m_sinks, ss.str().c_str() );
m_sgwc_s11 = new _Logger( "sgwc_s11 ", m_sinks, ss.str().c_str() );
m_sgwc_s5s8 = new _Logger( "sgwc_s5 ", m_sinks, ss.str().c_str() );
m_sgwc_sx = new _Logger( "sgwc_sx ", m_sinks, ss.str().c_str() );
//m_sgw_udp = new _Logger( "sgw_udp ", m_sinks, ss.str().c_str() );
m_spgwu_app = new _Logger( "spgwu_app", m_sinks, ss.str().c_str() );
m_spgwu_s1u = new _Logger( "spgwu_s1u", m_sinks, ss.str().c_str() );
m_spgwu_sx = new _Logger( "spgwu_sx ", m_sinks, ss.str().c_str() );
m_system = new _Logger( "system ", m_sinks, ss.str().c_str() );
m_udp = new _Logger( "udp ", m_sinks, ss.str().c_str() );
m_pfcp = new _Logger( "pfcp ", m_sinks, ss.str().c_str() );
m_pfcp_switch = new _Logger( "pfcp_sw ", m_sinks, ss.str().c_str() );
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
_Logger::_Logger( const char *category, std::vector<spdlog::sink_ptr> &sinks, const char *pattern )
: m_log( category, sinks.begin(), sinks.end() )
{
m_log.set_pattern( pattern );
#if TRACE_IS_ON
m_log.set_level( spdlog::level::trace );
#elif DEBUG_IS_ON
m_log.set_level( spdlog::level::debug );
#elif INFO_IS_ON
m_log.set_level( spdlog::level::info );
#else
m_log.set_level( spdlog::level::warn );
#endif
}
void _Logger::trace( const char *format, ... )
{
#if TRACE_IS_ON
va_list args;
va_start( args, format );
log( _ltTrace, format, args );
va_end( args );
#endif
}
void _Logger::trace( const std::string &format, ... )
{
#if TRACE_IS_ON
va_list args;
va_start( args, format );
log( _ltTrace, format.c_str(), args );
va_end( args );
#endif
}
void _Logger::debug( const char *format, ... )
{
#if DEBUG_IS_ON
va_list args;
va_start( args, format );
log( _ltDebug, format, args );
va_end( args );
#endif
}
void _Logger::debug( const std::string &format, ... )
{
#if DEBUG_IS_ON
va_list args;
va_start( args, format );
log( _ltDebug, format.c_str(), args );
va_end( args );
#endif
}
void _Logger::info( const char *format, ... )
{
#if INFO_IS_ON
va_list args;
va_start( args, format );
log( _ltInfo, format, args );
va_end( args );
#endif
}
void _Logger::info( const std::string &format, ... )
{
#if INFO_IS_ON
va_list args;
va_start( args, format );
log( _ltInfo, format.c_str(), args );
va_end( args );
#endif
}
void _Logger::startup( const char *format, ... )
{
va_list args;
va_start( args, format );
log( _ltStartup, format, args );
va_end( args );
}
void _Logger::startup( const std::string &format, ... )
{
va_list args;
va_start( args, format );
log( _ltStartup, format.c_str(), args );
va_end( args );
}
void _Logger::warn( const char *format, ... )
{
va_list args;
va_start( args, format );
log( _ltWarn, format, args );
va_end( args );
}
void _Logger::warn( const std::string &format, ... )
{
va_list args;
va_start( args, format );
log( _ltWarn, format.c_str(), args );
va_end( args );
}
void _Logger::error( const char *format, ... )
{
va_list args;
va_start( args, format );
log( _ltError, format, args );
va_end( args );
}
void _Logger::error( const std::string &format, ... )
{
va_list args;
va_start( args, format );
log( _ltError, format.c_str(), args );
va_end( args );
}
void _Logger::log( _LogType lt, const char *format, va_list &args )
{
char buffer[ 2048 ];
vsnprintf( buffer, sizeof(buffer), format, args );
switch ( lt )
{
case _ltTrace: m_log.trace( buffer ); break;
case _ltDebug: m_log.debug( buffer ); break;
case _ltInfo: m_log.info( buffer ); break;
case _ltStartup: m_log.warn( buffer ); break;
case _ltWarn: m_log.error( buffer ); break;
case _ltError: m_log.critical( buffer ); break;
}
}
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __LOGGER_H
#define __LOGGER_H
#include <cstdarg>
#include <stdexcept>
#include <vector>
//#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" };
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info ", "start", "warn ", "error", "off " };
#define SPDLOG_ENABLE_SYSLOG
#include "spdlog/spdlog.h"
class LoggerException : public std::runtime_error
{
public:
LoggerException(const char *m) : std::runtime_error(m) {}
LoggerException(const std::string &m) : std::runtime_error(m) {}
};
class _Logger
{
public:
_Logger( const char *category, std::vector<spdlog::sink_ptr> &sinks, const char *pattern );
void trace( const char *format, ... );
void trace( const std::string &format, ... );
void debug( const char *format, ... );
void debug( const std::string &format, ... );
void info( const char *format, ... );
void info( const std::string &format, ... );
void startup( const char *format, ... );
void startup( const std::string &format, ... );
void warn( const char *format, ... );
void warn( const std::string &format, ... );
void error( const char *format, ... );
void error( const std::string &format, ... );
private:
_Logger();
enum _LogType
{
_ltTrace,
_ltDebug,
_ltInfo,
_ltStartup,
_ltWarn,
_ltError
};
void log( _LogType lt, const char *format, va_list &args );
spdlog::logger m_log;
};
class Logger
{
public:
static void init( const char *app ) { singleton()._init( app ); }
static void init( const std::string &app ) { init( app.c_str() ); }
static _Logger &async_cmd() { return *singleton().m_async_cmd; }
static _Logger &enb_s1u() { return *singleton().m_enb_s1u; }
static _Logger &gtpv1_u() { return *singleton().m_gtpv1_u; }
static _Logger &gtpv2_c() { return *singleton().m_gtpv2_c; }
//static _Logger &gx() { return *singleton().m_gx; }
static _Logger &itti() { return *singleton().m_itti; }
static _Logger &mme_s11() { return *singleton().m_mme_s11; }
static _Logger &pgwc_app() { return *singleton().m_pgwc_app; }
//static _Logger &pgwu_app() { return *singleton().m_pgwu_app; }
static _Logger &pgwc_s5s8() { return *singleton().m_pgwc_s5s8; }
static _Logger &pgwc_sx() { return *singleton().m_pgwc_sx; }
//static _Logger &pgwu_sx() { return *singleton().m_pgwu_sx; }
//static _Logger &pgw_udp() { return *singleton().m_pgw_udp; }
static _Logger &sgwc_app() { return *singleton().m_sgwc_app; }
//static _Logger &sgwu_app() { return *singleton().m_sgwu_app; }
//static _Logger &sgwu_sx() { return *singleton().m_sgwu_sx; }
static _Logger &sgwc_s11() { return *singleton().m_sgwc_s11; }
static _Logger &sgwc_s5s8() { return *singleton().m_sgwc_s5s8; }
static _Logger &sgwc_sx() { return *singleton().m_sgwc_sx; }
//static _Logger &sgw_udp() { return *singleton().m_sgw_udp; }
static _Logger &spgwu_app() { return *singleton().m_spgwu_app; }
static _Logger &spgwu_s1u() { return *singleton().m_spgwu_s1u; }
static _Logger &spgwu_sx() { return *singleton().m_spgwu_sx; }
static _Logger &system() { return *singleton().m_system; }
static _Logger &udp() { return *singleton().m_udp; }
static _Logger &pfcp() { return *singleton().m_pfcp; }
static _Logger &pfcp_switch() { return *singleton().m_pfcp_switch; }
private:
static Logger *m_singleton;
static Logger &singleton() { if (!m_singleton) m_singleton = new Logger(); return *m_singleton; }
Logger() {}
~Logger() {}
void _init( const char *app );
std::vector<spdlog::sink_ptr> m_sinks;
std::string m_pattern;
_Logger *m_async_cmd;
_Logger *m_enb_s1u;
_Logger *m_gtpv1_u;
_Logger *m_gtpv2_c;
//_Logger *m_gx;
_Logger *m_itti;
_Logger *m_mme_s11;
_Logger *m_pgwc_app;
//_Logger *m_pgwu_app;
_Logger *m_pgwc_s5s8;
_Logger *m_pgwc_sx;
//_Logger *m_pgwu_sx;
//_Logger *m_pgw_udp;
_Logger *m_sgwc_app;
//_Logger *m_sgwu_app;
//_Logger *m_sgwu_sx;
_Logger *m_sgwc_s11;
_Logger *m_sgwc_s5s8;
_Logger *m_sgwc_sx;
//_Logger *m_sgw_udp;
_Logger *m_spgwu_app;
_Logger *m_spgwu_s1u;
_Logger *m_spgwu_sx;
_Logger *m_system;
_Logger *m_udp;
_Logger *m_pfcp;
_Logger *m_pfcp_switch;
};
#endif // __LOGGER_H
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file rfc_1332.h
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_RFC_1332_SEEN
#define FILE_RFC_1332_SEEN
// 2 A PPP Network Control Protocol (NCP) for IP
// Data Link Layer Protocol Field
// Exactly one IPCP packet is encapsulated in the Information field
// of PPP Data Link Layer frames where the Protocol field indicates
// type hex 8021 (IP Control Protocol)
// Code field
// Only Codes 1 through 7 (Configure-Request, Configure-Ack,
// Configure-Nak, Configure-Reject, Terminate-Request, Terminate-Ack
// and Code-Reject) are used. Other Codes should be treated as
// unrecognized and should result in Code-Rejects.
#define IPCP_CODE_CONFIGURE_REQUEST (0x01)
#define IPCP_CODE_CONFIGURE_ACK (0x02)
#define IPCP_CODE_CONFIGURE_NACK (0x03)
#define IPCP_CODE_CONFIGURE_REJECT (0x04)
#define IPCP_CODE_TERMINATE_REQUEST (0x05)
#define IPCP_CODE_TERMINATE_ACK (0x06)
#define IPCP_CODE_REJECT (0x07)
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file rfc_1877.h
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_RFC_1877_SEEN
#define FILE_RFC_1877_SEEN
#define IPCP_OPTION_PRIMARY_DNS_SERVER_IP_ADDRESS (0x81)
#define IPCP_OPTION_PRIMARY_NBNS_SERVER_IP_ADDRESS (0x82)
#define IPCP_OPTION_SECONDARY_DNS_SERVER_IP_ADDRESS (0x83)
#define IPCP_OPTION_SECONDARY_NBNS_SERVER_IP_ADDRESS (0x84)
#endif
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file serializable.hpp
\brief
\author Lionel Gauthier
\company Eurecom
\email: lionel.gauthier@eurecom.fr
*/
#ifndef FILE_SERIALIZABLE_HPP_SEEN
#define FILE_SERIALIZABLE_HPP_SEEN
#include <string>
#include <iostream>
namespace oai::cn {
class stream_serializable {
public:
virtual void dump_to(std::ostream& os) = 0;
virtual void load_from(std::istream& is) = 0;
//virtual ~serializable() = 0;
};
}
#endif /* FILE_SERIALIZABLE_HPP_SEEN */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment