Commit 8386f73a authored by Raphael Defosseux's avatar Raphael Defosseux

[CLEANUP] apply clang-format

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@openairinterface.org>
parent e2412c05
......@@ -41,10 +41,14 @@ The text for `OAI Public License V1.1` is also available under [LICENSE](LICENSE
openair-spgwu-tiny
├── build : Build directory, contains targets and object files generated by compilation of network functions.
│ ├── log : Directory containing build log files.
│ ├── scripts : Directory containing scripts for building network functions
│ ├── scripts : Directory containing scripts for building network functions.
│ └── spgw_u : Directory containing CMakefile.txt and object files generated by compilation of SPGW-U network function.
├── ci-scripts : Directory containing scripts for the CI process
├── ci-scripts : Directory containing scripts for the CI process.
├── docker : Directory containing dockerfiles to create images.
├── docs : Directory containing documentation on the supported feature set.
├── etc : Directory containing the configuration files to be deployed for each network function.
├── openshift : Directory containing YAML files for build within OpenShift context.
├── scripts : Directory containing entrypoint script for container images.
└── src : Source files of network functions.
├── common : Common header files
│   ├── msg : ITTI messages definitions.
......
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -37,60 +37,54 @@
#include <string.h>
class endpoint {
public :
public:
struct sockaddr_storage addr_storage;
socklen_t addr_storage_len;
endpoint() : addr_storage(), addr_storage_len(sizeof(struct sockaddr_storage)) {};
endpoint(const endpoint& e) : addr_storage(e.addr_storage), addr_storage_len(e.addr_storage_len) {};
endpoint(const struct sockaddr_storage& addr, const socklen_t len) : addr_storage(addr), addr_storage_len(len) {};
endpoint(const struct in_addr& addr, const uint16_t port)
{
struct sockaddr_in * addr_in = (struct sockaddr_in *)&addr_storage;
addr_in->sin_family = AF_INET;
addr_in->sin_port = htons(port);
addr_in->sin_addr.s_addr = addr.s_addr;
socklen_t addr_storage_len;
endpoint()
: addr_storage(), addr_storage_len(sizeof(struct sockaddr_storage)){};
endpoint(const endpoint& e)
: addr_storage(e.addr_storage), addr_storage_len(e.addr_storage_len){};
endpoint(const struct sockaddr_storage& addr, const socklen_t len)
: addr_storage(addr), addr_storage_len(len){};
endpoint(const struct in_addr& addr, const uint16_t port) {
struct sockaddr_in* addr_in = (struct sockaddr_in*) &addr_storage;
addr_in->sin_family = AF_INET;
addr_in->sin_port = htons(port);
addr_in->sin_addr.s_addr = addr.s_addr;
addr_storage_len = sizeof(struct sockaddr_in);
};
endpoint(const struct in6_addr& addr6, const uint16_t port)
{
struct sockaddr_in6 * addr_in6 = (struct sockaddr_in6 *)&addr_storage;
addr_in6->sin6_family = AF_INET6;
addr_in6->sin6_port = htons(port);
addr_in6->sin6_flowinfo = 0;
endpoint(const struct in6_addr& addr6, const uint16_t port) {
struct sockaddr_in6* addr_in6 = (struct sockaddr_in6*) &addr_storage;
addr_in6->sin6_family = AF_INET6;
addr_in6->sin6_port = htons(port);
addr_in6->sin6_flowinfo = 0;
memcpy(&addr_in6->sin6_addr, &addr6, sizeof(struct in6_addr));
addr_in6->sin6_scope_id = 0;
addr_storage_len = sizeof(struct sockaddr_in6);
};
uint16_t port() const
{
return ntohs(((struct sockaddr_in *)&addr_storage)->sin_port);
uint16_t port() const {
return ntohs(((struct sockaddr_in*) &addr_storage)->sin_port);
}
sa_family_t family() const
{
return addr_storage.ss_family;
}
sa_family_t family() const { return addr_storage.ss_family; }
std::string toString() const
{
std::string toString() const {
std::string str;
if (addr_storage.ss_family == AF_INET) {
struct sockaddr_in * addr_in = (struct sockaddr_in *)&addr_storage;
struct sockaddr_in* addr_in = (struct sockaddr_in*) &addr_storage;
str.append(conv::toString(addr_in->sin_addr));
str.append(":").append(std::to_string(ntohs(addr_in->sin_port)));
}
else if (addr_storage.ss_family == AF_INET6) {
struct sockaddr_in6 * addr_in6 = (struct sockaddr_in6 *)&addr_storage;
str.append(":").append(std::to_string(ntohs(addr_in->sin_port)));
} else if (addr_storage.ss_family == AF_INET6) {
struct sockaddr_in6* addr_in6 = (struct sockaddr_in6*) &addr_storage;
str.append(conv::toString(addr_in6->sin6_addr));
str.append(":").append(std::to_string(ntohs(addr_in6->sin6_port)));
str.append(":").append(std::to_string(ntohs(addr_in6->sin6_port)));
}
return str;
}
};
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -31,18 +31,29 @@
#include "itti_msg.hpp"
class itti_async_shell_cmd : public itti_msg {
public:
itti_async_shell_cmd(const task_id_t origin, const task_id_t destination, const std::string& system_cmd, bool is_abort_on_error, const char * src_file, const int src_line):
itti_msg( ASYNC_SHELL_CMD, origin, destination), system_command(system_cmd), is_abort_on_error(is_abort_on_error), src_file(src_file), src_line(src_line) {}
itti_async_shell_cmd(const itti_async_shell_cmd& i) :
itti_msg(i), system_command(i.system_command), is_abort_on_error(i.is_abort_on_error), src_file(i.src_file), src_line(i.src_line) {}
const char* get_msg_name() {return typeid( itti_msg_ping).name();};
std::string system_command;
bool is_abort_on_error;
class itti_async_shell_cmd : public itti_msg {
public:
itti_async_shell_cmd(
const task_id_t origin, const task_id_t destination,
const std::string& system_cmd, bool is_abort_on_error,
const char* src_file, const int src_line)
: itti_msg(ASYNC_SHELL_CMD, origin, destination),
system_command(system_cmd),
is_abort_on_error(is_abort_on_error),
src_file(src_file),
src_line(src_line) {}
itti_async_shell_cmd(const itti_async_shell_cmd& i)
: itti_msg(i),
system_command(i.system_command),
is_abort_on_error(i.is_abort_on_error),
src_file(i.src_file),
src_line(i.src_line) {}
const char* get_msg_name() { return typeid(itti_msg_ping).name(); };
std::string system_command;
bool is_abort_on_error;
// debug
std::string src_file;
int src_line;
} ;
std::string src_file;
int src_line;
};
#endif /* FILE_ITTI_ASYNC_SHELL_CMD_SEEN */
This diff is collapsed.
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -36,137 +36,149 @@
#include <sys/socket.h>
class itti_s1u_msg : public itti_msg {
public:
itti_s1u_msg(const itti_msg_type_t msg_type, const task_id_t orig, const task_id_t dest):
itti_msg(msg_type, orig, dest) {}
public:
itti_s1u_msg(
const itti_msg_type_t msg_type, const task_id_t orig,
const task_id_t dest)
: itti_msg(msg_type, orig, dest) {}
itti_s1u_msg& operator=(itti_s1u_msg other)
{
itti_s1u_msg& operator=(itti_s1u_msg other) {
this->itti_msg::operator=(other);
return *this;
}
itti_s1u_msg(const itti_s1u_msg& i) : itti_msg(i) {}
itti_s1u_msg(const itti_s1u_msg& i) : itti_msg(i) {}
itti_s1u_msg(const itti_s1u_msg& i, const task_id_t orig, const task_id_t dest) : itti_s1u_msg(i) {
origin = orig;
itti_s1u_msg(
const itti_s1u_msg& i, const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(i) {
origin = orig;
destination = dest;
}
};
//------------------------------------------------------------------------------
class itti_s1u_echo_request : public itti_s1u_msg {
public:
itti_s1u_echo_request(const task_id_t orig, const task_id_t dest):
itti_s1u_msg(S1U_ECHO_REQUEST, orig, dest) {
}
explicit itti_s1u_echo_request(const itti_s1u_echo_request& i) : itti_s1u_msg(i) {
public:
itti_s1u_echo_request(const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(S1U_ECHO_REQUEST, orig, dest) {}
explicit itti_s1u_echo_request(const itti_s1u_echo_request& i)
: itti_s1u_msg(i) {
gtp_ies = i.gtp_ies;
}
itti_s1u_echo_request& operator=(itti_s1u_echo_request other)
{
itti_s1u_echo_request& operator=(itti_s1u_echo_request other) {
this->itti_s1u_msg::operator=(other);
std::swap(gtp_ies, other.gtp_ies);
return *this;
}
itti_s1u_echo_request(const itti_s1u_echo_request& i, const task_id_t orig, const task_id_t dest) :
itti_s1u_msg(i, orig, dest) {
itti_s1u_echo_request(
const itti_s1u_echo_request& i, const task_id_t orig,
const task_id_t dest)
: itti_s1u_msg(i, orig, dest) {
gtp_ies = i.gtp_ies;
}
const char* get_msg_name() {return "S1U_ECHO_REQUEST";};
const char* get_msg_name() { return "S1U_ECHO_REQUEST"; };
gtpv1u::gtpv1u_echo_request gtp_ies;
};
//------------------------------------------------------------------------------
class itti_s1u_echo_response : public itti_s1u_msg {
public:
itti_s1u_echo_response(const task_id_t orig, const task_id_t dest):
itti_s1u_msg(S1U_ECHO_RESPONSE, orig, dest) {
}
explicit itti_s1u_echo_response(const itti_s1u_echo_response& i) : itti_s1u_msg(i) {
public:
itti_s1u_echo_response(const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(S1U_ECHO_RESPONSE, orig, dest) {}
explicit itti_s1u_echo_response(const itti_s1u_echo_response& i)
: itti_s1u_msg(i) {
gtp_ies = i.gtp_ies;
}
itti_s1u_echo_response& operator=(itti_s1u_echo_response other)
{
itti_s1u_echo_response& operator=(itti_s1u_echo_response other) {
this->itti_s1u_msg::operator=(other);
std::swap(gtp_ies, other.gtp_ies);
return *this;
}
itti_s1u_echo_response(const itti_s1u_echo_response& i, const task_id_t orig, const task_id_t dest) :
itti_s1u_msg(i, orig, dest) {
itti_s1u_echo_response(
const itti_s1u_echo_response& i, const task_id_t orig,
const task_id_t dest)
: itti_s1u_msg(i, orig, dest) {
gtp_ies = i.gtp_ies;
}
const char* get_msg_name() {return "S1U_ECHO_RESPONSE";};
const char* get_msg_name() { return "S1U_ECHO_RESPONSE"; };
gtpv1u::gtpv1u_echo_response gtp_ies;
};
//------------------------------------------------------------------------------
class itti_s1u_error_indication : public itti_s1u_msg {
public:
itti_s1u_error_indication(const task_id_t orig, const task_id_t dest):
itti_s1u_msg(S1U_ERROR_INDICATION, orig, dest) {
}
explicit itti_s1u_error_indication(const itti_s1u_error_indication& i) : itti_s1u_msg(i) {
public:
itti_s1u_error_indication(const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(S1U_ERROR_INDICATION, orig, dest) {}
explicit itti_s1u_error_indication(const itti_s1u_error_indication& i)
: itti_s1u_msg(i) {
gtp_ies = i.gtp_ies;
}
itti_s1u_error_indication& operator=(itti_s1u_error_indication other)
{
itti_s1u_error_indication& operator=(itti_s1u_error_indication other) {
this->itti_s1u_msg::operator=(other);
std::swap(gtp_ies, other.gtp_ies);
return *this;
}
itti_s1u_error_indication(const itti_s1u_error_indication& i, const task_id_t orig, const task_id_t dest) :
itti_s1u_msg(i, orig, dest) {
itti_s1u_error_indication(
const itti_s1u_error_indication& i, const task_id_t orig,
const task_id_t dest)
: itti_s1u_msg(i, orig, dest) {
gtp_ies = i.gtp_ies;
}
const char* get_msg_name() {return "S1U_ERROR_INDICATION";};
const char* get_msg_name() { return "S1U_ERROR_INDICATION"; };
gtpv1u::gtpv1u_error_indication gtp_ies;
};
//------------------------------------------------------------------------------
class itti_s1u_supported_extension_headers_notification : public itti_s1u_msg {
public:
itti_s1u_supported_extension_headers_notification(const task_id_t orig, const task_id_t dest):
itti_s1u_msg(S1U_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION, orig, dest) {
}
explicit itti_s1u_supported_extension_headers_notification(const itti_s1u_supported_extension_headers_notification& i) : itti_s1u_msg(i) {
public:
itti_s1u_supported_extension_headers_notification(
const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(S1U_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION, orig, dest) {
}
explicit itti_s1u_supported_extension_headers_notification(
const itti_s1u_supported_extension_headers_notification& i)
: itti_s1u_msg(i) {
gtp_ies = i.gtp_ies;
}
itti_s1u_supported_extension_headers_notification& operator=(itti_s1u_supported_extension_headers_notification other)
{
itti_s1u_supported_extension_headers_notification& operator=(
itti_s1u_supported_extension_headers_notification other) {
this->itti_s1u_msg::operator=(other);
std::swap(gtp_ies, other.gtp_ies);
return *this;
}
itti_s1u_supported_extension_headers_notification(const itti_s1u_supported_extension_headers_notification& i, const task_id_t orig, const task_id_t dest) :
itti_s1u_msg(i, orig, dest) {
itti_s1u_supported_extension_headers_notification(
const itti_s1u_supported_extension_headers_notification& i,
const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(i, orig, dest) {
gtp_ies = i.gtp_ies;
}
const char* get_msg_name() {return "S1U_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION";};
const char* get_msg_name() {
return "S1U_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION";
};
gtpv1u::gtpv1u_supported_extension_headers_notification gtp_ies;
};
//------------------------------------------------------------------------------
class itti_s1u_end_marker : public itti_s1u_msg {
public:
itti_s1u_end_marker(const task_id_t orig, const task_id_t dest):
itti_s1u_msg(S1U_END_MARKER, orig, dest) {
}
explicit itti_s1u_end_marker(const itti_s1u_end_marker& i) : itti_s1u_msg(i) {
public:
itti_s1u_end_marker(const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(S1U_END_MARKER, orig, dest) {}
explicit itti_s1u_end_marker(const itti_s1u_end_marker& i) : itti_s1u_msg(i) {
gtp_ies = i.gtp_ies;
}
itti_s1u_end_marker& operator=(itti_s1u_end_marker other)
{
itti_s1u_end_marker& operator=(itti_s1u_end_marker other) {
this->itti_s1u_msg::operator=(other);
std::swap(gtp_ies, other.gtp_ies);
return *this;
}
itti_s1u_end_marker(const itti_s1u_end_marker& i, const task_id_t orig, const task_id_t dest) :
itti_s1u_msg(i, orig, dest) {
itti_s1u_end_marker(
const itti_s1u_end_marker& i, const task_id_t orig, const task_id_t dest)
: itti_s1u_msg(i, orig, dest) {
gtp_ies = i.gtp_ies;
}
const char* get_msg_name() {return "S1U_END_MARKER";};
const char* get_msg_name() { return "S1U_END_MARKER"; };
gtpv1u::gtpv1u_end_marker gtp_ies;
};
......
This diff is collapsed.
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -34,17 +34,20 @@
#include <set>
class itti_sx_restore : public itti_msg {
public:
itti_sx_restore(const task_id_t origin, const task_id_t destination):
itti_msg(RESTORE_SX_SESSIONS, origin, destination), sessions() {}
itti_sx_restore(const itti_sx_restore& i) : itti_msg(i), sessions(i.sessions) {}
itti_sx_restore(const itti_sx_restore& i, const task_id_t orig, const task_id_t dest) : itti_sx_restore(i) {
origin = orig;
public:
itti_sx_restore(const task_id_t origin, const task_id_t destination)
: itti_msg(RESTORE_SX_SESSIONS, origin, destination), sessions() {}
itti_sx_restore(const itti_sx_restore& i)
: itti_msg(i), sessions(i.sessions) {}
itti_sx_restore(
const itti_sx_restore& i, const task_id_t orig, const task_id_t dest)
: itti_sx_restore(i) {
origin = orig;
destination = dest;
}
const char* get_msg_name() {return "SX_RESTORE";};
const char* get_msg_name() { return "SX_RESTORE"; };
std::set<pfcp::fseid_t> sessions;
std::set<pfcp::fseid_t> sessions;
};
#endif /* ITTI_MSG_SX_RESTORE_HPP_INCLUDED_ */
This diff is collapsed.
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -33,10 +33,10 @@
#include <iostream>
class stream_serializable {
public:
virtual void dump_to(std::ostream& os) = 0;
public:
virtual void dump_to(std::ostream& os) = 0;
virtual void load_from(std::istream& is) = 0;
//virtual ~serializable() = 0;
// virtual ~serializable() = 0;
};
#endif /* FILE_SERIALIZABLE_HPP_SEEN */
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -34,78 +34,73 @@
#include <inttypes.h>
//------------------------------------------------------------------------------
void xgpp_conv::paa_to_pfcp_ue_ip_address(const paa_t& paa, pfcp::ue_ip_address_t& ue_ip_address)
{
void xgpp_conv::paa_to_pfcp_ue_ip_address(
const paa_t& paa, pfcp::ue_ip_address_t& ue_ip_address) {
switch (paa.pdn_type.pdn_type) {
case PDN_TYPE_E_IPV4:
ue_ip_address.v4 = 1;
ue_ip_address.ipv4_address = paa.ipv4_address;
break;
case PDN_TYPE_E_IPV6:
ue_ip_address.v6 = 1;
ue_ip_address.ipv6_address = paa.ipv6_address;
break;
case PDN_TYPE_E_IPV4V6:
ue_ip_address.v4 = 1;
ue_ip_address.v6 = 1;
ue_ip_address.ipv4_address = paa.ipv4_address;
ue_ip_address.ipv6_address = paa.ipv6_address;
break;
case PDN_TYPE_E_NON_IP:
default:
;
case PDN_TYPE_E_IPV4:
ue_ip_address.v4 = 1;
ue_ip_address.ipv4_address = paa.ipv4_address;
break;
case PDN_TYPE_E_IPV6:
ue_ip_address.v6 = 1;
ue_ip_address.ipv6_address = paa.ipv6_address;
break;
case PDN_TYPE_E_IPV4V6:
ue_ip_address.v4 = 1;
ue_ip_address.v6 = 1;
ue_ip_address.ipv4_address = paa.ipv4_address;
ue_ip_address.ipv6_address = paa.ipv6_address;
break;
case PDN_TYPE_E_NON_IP:
default:;
}
}
//------------------------------------------------------------------------------
void xgpp_conv::pdn_ip_to_pfcp_ue_ip_address(const pdn_type_t& pdn_type,
const struct in_addr& ipv4_address,
const struct in6_addr ipv6_address,
pfcp::ue_ip_address_t& ue_ip_address)
{
void xgpp_conv::pdn_ip_to_pfcp_ue_ip_address(
const pdn_type_t& pdn_type, const struct in_addr& ipv4_address,
const struct in6_addr ipv6_address, pfcp::ue_ip_address_t& ue_ip_address) {
switch (pdn_type.pdn_type) {
case PDN_TYPE_E_IPV4:
ue_ip_address.v4 = 1;
ue_ip_address.ipv4_address = ipv4_address;
break;
case PDN_TYPE_E_IPV6:
ue_ip_address.v6 = 1;
ue_ip_address.ipv6_address = ipv6_address;
break;
case PDN_TYPE_E_IPV4V6:
ue_ip_address.v4 = 1;
ue_ip_address.v6 = 1;
ue_ip_address.ipv4_address = ipv4_address;
ue_ip_address.ipv6_address = ipv6_address;
break;
case PDN_TYPE_E_NON_IP:
default:
;
case PDN_TYPE_E_IPV4:
ue_ip_address.v4 = 1;
ue_ip_address.ipv4_address = ipv4_address;
break;
case PDN_TYPE_E_IPV6:
ue_ip_address.v6 = 1;
ue_ip_address.ipv6_address = ipv6_address;
break;
case PDN_TYPE_E_IPV4V6:
ue_ip_address.v4 = 1;
ue_ip_address.v6 = 1;
ue_ip_address.ipv4_address = ipv4_address;
ue_ip_address.ipv6_address = ipv6_address;
break;
case PDN_TYPE_E_NON_IP:
default:;
}
}
//------------------------------------------------------------------------------
void xgpp_conv::pfcp_to_core_fteid(const pfcp::fteid_t& pfteid, fteid_t& fteid)
{
fteid.v4 = pfteid.v4;
fteid.v6 = pfteid.v6;
void xgpp_conv::pfcp_to_core_fteid(
const pfcp::fteid_t& pfteid, fteid_t& fteid) {
fteid.v4 = pfteid.v4;
fteid.v6 = pfteid.v6;
fteid.ipv4_address.s_addr = pfteid.ipv4_address.s_addr;
fteid.ipv6_address = pfteid.ipv6_address;
fteid.teid_gre_key = pfteid.teid;
fteid.ipv6_address = pfteid.ipv6_address;
fteid.teid_gre_key = pfteid.teid;
}
//------------------------------------------------------------------------------
void xgpp_conv::pfcp_from_core_fteid(pfcp::fteid_t& pfteid, const fteid_t& fteid)
{
pfteid.chid = 0;
pfteid.ch = 0;
pfteid.choose_id = 0;
pfteid.v4 = fteid.v4;
pfteid.v6 = fteid.v6;
void xgpp_conv::pfcp_from_core_fteid(
pfcp::fteid_t& pfteid, const fteid_t& fteid) {
pfteid.chid = 0;
pfteid.ch = 0;
pfteid.choose_id = 0;
pfteid.v4 = fteid.v4;
pfteid.v6 = fteid.v6;
pfteid.ipv4_address.s_addr = fteid.ipv4_address.s_addr;
pfteid.ipv6_address = fteid.ipv6_address;
pfteid.teid = fteid.teid_gre_key;
pfteid.ipv6_address = fteid.ipv6_address;
pfteid.teid = fteid.teid_gre_key;
}
//------------------------------------------------------------------------------
void xgpp_conv::pfcp_cause_to_core_cause(const pfcp::cause_t& pc, cause_t& c)
{
void xgpp_conv::pfcp_cause_to_core_cause(const pfcp::cause_t& pc, cause_t& c) {
switch (pc.cause_value) {
case pfcp::CAUSE_VALUE_REQUEST_ACCEPTED:
c.cause_value = REQUEST_ACCEPTED;
......@@ -122,39 +117,38 @@ void xgpp_conv::pfcp_cause_to_core_cause(const pfcp::cause_t& pc, cause_t& c)
case pfcp::CAUSE_VALUE_INVALID_FTEID_ALLOCATION_OPTION:
case pfcp::CAUSE_VALUE_NO_ESTABLISHED_PFCP_ASSOCIATION:
case pfcp::CAUSE_VALUE_RULE_CREATION_MODIFICATION_FAILURE:
c.cause_value = SYSTEM_FAILURE; // ?
c.cause_value = SYSTEM_FAILURE; // ?
break;
case pfcp::CAUSE_VALUE_PFCP_ENTITY_IN_CONGESTION:
c.cause_value = APN_CONGESTION; // ? ...
c.cause_value = APN_CONGESTION; // ? ...
break;
case pfcp::CAUSE_VALUE_NO_RESOURCES_AVAILABLE:
case pfcp::CAUSE_VALUE_SERVICE_NOT_SUPPORTED:
case pfcp::CAUSE_VALUE_SYSTEM_FAILURE:
default:
c.cause_value = SYSTEM_FAILURE; // ? ...
c.cause_value = SYSTEM_FAILURE; // ? ...
}
}
//------------------------------------------------------------------------------
bool xgpp_conv::endpoint_to_gtp_u_peer_address(const endpoint& ep, gtp_u_peer_address_t& peer_address)
{
bool xgpp_conv::endpoint_to_gtp_u_peer_address(
const endpoint& ep, gtp_u_peer_address_t& peer_address) {
switch (ep.family()) {
case AF_INET: {
const struct sockaddr_in * const sin = reinterpret_cast<const sockaddr_in* const>(&ep.addr_storage);
const struct sockaddr_in* const sin =
reinterpret_cast<const sockaddr_in* const>(&ep.addr_storage);
peer_address.ipv4_address.s_addr = sin->sin_addr.s_addr;
peer_address.is_v4 = true;
peer_address.is_v4 = true;
return true;
}
break;
} break;
case AF_INET6: {
const struct sockaddr_in6 * const sin6 = reinterpret_cast<const sockaddr_in6* const>(&ep.addr_storage);
const struct sockaddr_in6* const sin6 =
reinterpret_cast<const sockaddr_in6* const>(&ep.addr_storage);
peer_address.ipv6_address = sin6->sin6_addr;
peer_address.is_v4 = false;
peer_address.is_v4 = false;
return true;
}
break;
} break;
default:
return false;
}
}
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -35,15 +35,16 @@
namespace xgpp_conv {
void paa_to_pfcp_ue_ip_address(const paa_t& paa, pfcp::ue_ip_address_t& ue_ip_address);
void pdn_ip_to_pfcp_ue_ip_address(const pdn_type_t& pdn_type,
const struct in_addr& ipv4_address,
const struct in6_addr ipv6_address,
pfcp::ue_ip_address_t& ue_ip_address);
void pfcp_to_core_fteid(const pfcp::fteid_t& pfteid, fteid_t& fteid);
void pfcp_from_core_fteid(pfcp::fteid_t& pfteid, const fteid_t& fteid);
void pfcp_cause_to_core_cause(const pfcp::cause_t& pc, cause_t& c);
bool endpoint_to_gtp_u_peer_address(const endpoint& ep, gtp_u_peer_address_t& gpa);
}
void paa_to_pfcp_ue_ip_address(
const paa_t& paa, pfcp::ue_ip_address_t& ue_ip_address);
void pdn_ip_to_pfcp_ue_ip_address(
const pdn_type_t& pdn_type, const struct in_addr& ipv4_address,
const struct in6_addr ipv6_address, pfcp::ue_ip_address_t& ue_ip_address);
void pfcp_to_core_fteid(const pfcp::fteid_t& pfteid, fteid_t& fteid);
void pfcp_from_core_fteid(pfcp::fteid_t& pfteid, const fteid_t& fteid);
void pfcp_cause_to_core_cause(const pfcp::cause_t& pc, cause_t& c);
bool endpoint_to_gtp_u_peer_address(
const endpoint& ep, gtp_u_peer_address_t& gpa);
} // namespace xgpp_conv
#endif /* FILE_3GPP_CONVERSIONS_HPP_SEEN */
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -47,84 +47,93 @@
using namespace util;
extern itti_mw *itti_inst;
void async_cmd_task (void*);
extern itti_mw* itti_inst;
void async_cmd_task(void*);
//------------------------------------------------------------------------------
void async_cmd_task (void* args_p)
{
void async_cmd_task(void* args_p) {
const task_id_t task_id = TASK_ASYNC_SHELL_CMD;
const thread_sched_params* const sched_params = (const util::thread_sched_params* const)args_p;
const thread_sched_params* const sched_params =
(const util::thread_sched_params* const) args_p;
sched_params->apply(task_id, Logger::async_cmd());
itti_inst->notify_task_ready(task_id);
do {
std::shared_ptr<itti_msg> shared_msg = itti_inst->receive_msg(task_id);
auto *msg = shared_msg.get();
auto* msg = shared_msg.get();
switch (msg->msg_type) {
case ASYNC_SHELL_CMD:
if (itti_async_shell_cmd* to =
dynamic_cast<itti_async_shell_cmd*>(msg)) {
int rc = system((const char*) to->system_command.c_str());
if (rc) {
Logger::async_cmd().error(
"Failed cmd from %d: %s ", to->origin,
(const char*) to->system_command.c_str());
if (to->is_abort_on_error) {
Logger::async_cmd().error(
"Terminate cause failed cmd %s at %s:%d",
to->system_command.c_str(), to->src_file.c_str(),
to->src_line);
itti_inst->send_terminate_msg(to->origin);
}
}
}
break;
case ASYNC_SHELL_CMD:
if (itti_async_shell_cmd* to = dynamic_cast<itti_async_shell_cmd*>(msg)) {
int rc = system ((const char*)to->system_command.c_str());
case TIME_OUT:
if (itti_msg_timeout* to = dynamic_cast<itti_msg_timeout*>(msg)) {
Logger::async_cmd().info("TIME-OUT event timer id %d", to->timer_id);
}
break;
if (rc) {
Logger::async_cmd().error( "Failed cmd from %d: %s ", to->origin, (const char*)to->system_command.c_str());
if (to->is_abort_on_error) {
Logger::async_cmd().error( "Terminate cause failed cmd %s at %s:%d", to->system_command.c_str(), to->src_file.c_str(), to->src_line);
itti_inst->send_terminate_msg(to->origin);
}
case TERMINATE:
if (itti_msg_terminate* terminate =
dynamic_cast<itti_msg_terminate*>(msg)) {
Logger::async_cmd().info("Received terminate message");
return;
}
}
break;
case TIME_OUT:
if (itti_msg_timeout* to = dynamic_cast<itti_msg_timeout*>(msg)) {
Logger::async_cmd().info( "TIME-OUT event timer id %d", to->timer_id);
}
break;
case TERMINATE:
if (itti_msg_terminate *terminate = dynamic_cast<itti_msg_terminate*>(msg)) {
Logger::async_cmd().info( "Received terminate message");
return;
}
break;
case HEALTH_PING:
break;
default:
Logger::sgwc_app().info( "no handler for msg type %d", msg->msg_type);
break;
case HEALTH_PING:
break;
default:
Logger::sgwc_app().info("no handler for msg type %d", msg->msg_type);
}
} while (true);
}
//------------------------------------------------------------------------------
async_shell_cmd::async_shell_cmd (util::thread_sched_params& sched_params)
{
Logger::async_cmd().startup( "Starting..." );
async_shell_cmd::async_shell_cmd(util::thread_sched_params& sched_params) {
Logger::async_cmd().startup("Starting...");
if (itti_inst->create_task(TASK_ASYNC_SHELL_CMD, async_cmd_task, &sched_params) ) {
Logger::async_cmd().error( "Cannot create task TASK_ASYNC_SHELL_CMD" );
throw std::runtime_error( "Cannot create task TASK_ASYNC_SHELL_CMD" );
if (itti_inst->create_task(
TASK_ASYNC_SHELL_CMD, async_cmd_task, &sched_params)) {
Logger::async_cmd().error("Cannot create task TASK_ASYNC_SHELL_CMD");
throw std::runtime_error("Cannot create task TASK_ASYNC_SHELL_CMD");
}
Logger::async_cmd().startup( "Started" );
Logger::async_cmd().startup("Started");
}
//------------------------------------------------------------------------------
int async_shell_cmd::run_command (const task_id_t sender_itti_task, const bool is_abort_on_error, const char* src_file, const int src_line, const std::string& cmd_str)
{
itti_async_shell_cmd cmd(sender_itti_task, TASK_ASYNC_SHELL_CMD, cmd_str, is_abort_on_error, src_file, src_line);
std::shared_ptr<itti_async_shell_cmd> msg = std::make_shared<itti_async_shell_cmd>(cmd);
int async_shell_cmd::run_command(
const task_id_t sender_itti_task, const bool is_abort_on_error,
const char* src_file, const int src_line, const std::string& cmd_str) {
itti_async_shell_cmd cmd(
sender_itti_task, TASK_ASYNC_SHELL_CMD, cmd_str, is_abort_on_error,
src_file, src_line);
std::shared_ptr<itti_async_shell_cmd> msg =
std::make_shared<itti_async_shell_cmd>(cmd);
int ret = itti_inst->send_msg(msg);
if (RETURNok != ret) {
Logger::async_cmd().error( "Could not send ITTI message to task TASK_ASYNC_SHELL_CMD");
Logger::async_cmd().error(
"Could not send ITTI message to task TASK_ASYNC_SHELL_CMD");
return RETURNerror;
}
return RETURNok;
}
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -20,12 +20,12 @@
*/
/*! \file async_shell_cmd.hpp
\brief We still use some unix commands for convenience, and we did not have to replace them by system calls
\ Instead of calling C system(...) that can take a lot of time (creation of a process, etc), in many cases
\ it doesn't hurt to do this asynchronously, may be we must tweak thread priority, pin it to a CPU, etc (TODO later)
\author Lionel GAUTHIER
\date 2017
\email: lionel.gauthier@eurecom.fr
\brief We still use some unix commands for convenience, and we did not have
to replace them by system calls \ Instead of calling C system(...) that can
take a lot of time (creation of a process, etc), in many cases \ it doesn't
hurt to do this asynchronously, may be we must tweak thread priority, pin it
to a CPU, etc (TODO later) \author Lionel GAUTHIER \date 2017 \email:
lionel.gauthier@eurecom.fr
*/
#ifndef FILE_ASYNC_SHELL_CMD_HPP_SEEN
......@@ -39,19 +39,20 @@
namespace util {
class async_shell_cmd {
private:
std::thread::id thread_id;
std::thread thread;
private:
std::thread::id thread_id;
std::thread thread;
public:
public:
explicit async_shell_cmd(util::thread_sched_params& sched_params);
~async_shell_cmd() {}
async_shell_cmd(async_shell_cmd const&) = delete;
void operator=(async_shell_cmd const&) = delete;
int run_command (const task_id_t sender_itti_task, const bool is_abort_on_error, const char* src_file, const int src_line, const std::string& cmd_str);
async_shell_cmd(async_shell_cmd const&) = delete;
void operator=(async_shell_cmd const&) = delete;
int run_command(
const task_id_t sender_itti_task, const bool is_abort_on_error,
const char* src_file, const int src_line, const std::string& cmd_str);
};
}
} // namespace util
#endif /* FILE_ASYNC_SHELL_CMD_HPP_SEEN */
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -33,122 +33,103 @@
#include <inttypes.h>
#include <arpa/inet.h>
static const char hex_to_ascii_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
static const char hex_to_ascii_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
};
static const signed char ascii_to_hex_table[0x100] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
void conv::hexa_to_ascii (
uint8_t * from,
char *to,
size_t length)
{
size_t i;
static const signed char ascii_to_hex_table[0x100] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1};
void conv::hexa_to_ascii(uint8_t* from, char* to, size_t length) {
size_t i;
for (i = 0; i < length; i++) {
uint8_t upper = (from[i] & 0xf0) >> 4;
uint8_t lower = from[i] & 0x0f;
uint8_t upper = (from[i] & 0xf0) >> 4;
uint8_t lower = from[i] & 0x0f;
to[2 * i] = hex_to_ascii_table[upper];
to[2 * i] = hex_to_ascii_table[upper];
to[2 * i + 1] = hex_to_ascii_table[lower];
}
}
int conv::ascii_to_hex (
uint8_t * dst,
const char *h)
{
const unsigned char *hex = (const unsigned char *)h;
unsigned i = 0;
int conv::ascii_to_hex(uint8_t* dst, const char* h) {
const unsigned char* hex = (const unsigned char*) h;
unsigned i = 0;
for (;;) {
int high,
low;
int high, low;
while (*hex && isspace (*hex))
hex++;
while (*hex && isspace(*hex)) hex++;
if (!*hex)
return 1;
if (!*hex) return 1;
high = ascii_to_hex_table[*hex++];
if (high < 0)
return 0;
if (high < 0) return 0;
while (*hex && isspace (*hex))
hex++;
while (*hex && isspace(*hex)) hex++;
if (!*hex)
return 0;
if (!*hex) return 0;
low = ascii_to_hex_table[*hex++];
if (low < 0)
return 0;
if (low < 0) return 0;
dst[i++] = (high << 4) | low;
}
}
//------------------------------------------------------------------------------
std::string conv::mccToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3)
{
std::string s = {};
uint16_t mcc16 = digit1*100+digit2*10+digit3;
//s.append(std::to_string(digit1)).append(std::to_string(digit2)).append(std::to_string(digit3));
std::string conv::mccToString(
const uint8_t digit1, const uint8_t digit2, const uint8_t digit3) {
std::string s = {};
uint16_t mcc16 = digit1 * 100 + digit2 * 10 + digit3;
// s.append(std::to_string(digit1)).append(std::to_string(digit2)).append(std::to_string(digit3));
s.append(std::to_string(mcc16));
return s;
}
//------------------------------------------------------------------------------
std::string conv::mncToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3)
{
std::string s = {};
std::string conv::mncToString(
const uint8_t digit1, const uint8_t digit2, const uint8_t digit3) {
std::string s = {};
uint16_t mcc16 = 0;
if (digit3 == 0x0F) {
mcc16 = digit1*10+digit2;
mcc16 = digit1 * 10 + digit2;
} else {
mcc16 = digit1*100+digit2*10+digit3;
mcc16 = digit1 * 100 + digit2 * 10 + digit3;
}
s.append(std::to_string(mcc16));
return s;
}
//------------------------------------------------------------------------------
struct in_addr conv::fromString(const std::string addr4)
{
struct in_addr conv::fromString(const std::string addr4) {
unsigned char buf[sizeof(struct in6_addr)] = {};
int s = inet_pton(AF_INET, addr4.c_str(), buf);
struct in_addr * ia = (struct in_addr *)buf;
int s = inet_pton(AF_INET, addr4.c_str(), buf);
struct in_addr* ia = (struct in_addr*) buf;
return *ia;
}
//------------------------------------------------------------------------------
std::string conv::toString(const struct in_addr& inaddr)
{
std::string s = {};
std::string conv::toString(const struct in_addr& inaddr) {
std::string s = {};
char str[INET6_ADDRSTRLEN] = {};
if (inet_ntop(AF_INET, (const void *)&inaddr, str, INET6_ADDRSTRLEN) == NULL) {
if (inet_ntop(AF_INET, (const void*) &inaddr, str, INET6_ADDRSTRLEN) ==
NULL) {
s.append("Error in_addr");
} else {
s.append(str);
......@@ -156,16 +137,14 @@ std::string conv::toString(const struct in_addr& inaddr)
return s;
}
//------------------------------------------------------------------------------
std::string conv::toString(const struct in6_addr& in6addr)
{
std::string s = {};
std::string conv::toString(const struct in6_addr& in6addr) {
std::string s = {};
char str[INET6_ADDRSTRLEN] = {};
if (inet_ntop(AF_INET6, (const void *)&in6addr, str, INET6_ADDRSTRLEN) == nullptr) {
if (inet_ntop(AF_INET6, (const void*) &in6addr, str, INET6_ADDRSTRLEN) ==
nullptr) {
s.append("Error in6_addr");
} else {
s.append(str);
}
return s;
}
......@@ -3,9 +3,9 @@
* 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
* 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
*
......@@ -32,27 +32,27 @@
#include <string>
#include <netinet/in.h>
/* Used to format an uint32_t containing an ipv4 address */
#define IN_ADDR_FMT "%u.%u.%u.%u"
#define PRI_IN_ADDR(aDDRESS) \
(uint8_t)((aDDRESS.s_addr) & 0x000000ff), \
(uint8_t)(((aDDRESS.s_addr) & 0x0000ff00) >> 8 ), \
(uint8_t)(((aDDRESS.s_addr) & 0x00ff0000) >> 16), \
(uint8_t)(((aDDRESS.s_addr) & 0xff000000) >> 24)
#define IPV4_ADDR_DISPLAY_8(aDDRESS) \
(aDDRESS)[0], (aDDRESS)[1], (aDDRESS)[2], (aDDRESS)[3]
#define IN_ADDR_FMT "%u.%u.%u.%u"
#define PRI_IN_ADDR(aDDRESS) \
(uint8_t)((aDDRESS.s_addr) & 0x000000ff), \
(uint8_t)(((aDDRESS.s_addr) & 0x0000ff00) >> 8), \
(uint8_t)(((aDDRESS.s_addr) & 0x00ff0000) >> 16), \
(uint8_t)(((aDDRESS.s_addr) & 0xff000000) >> 24)
#define IPV4_ADDR_DISPLAY_8(aDDRESS) \
(aDDRESS)[0], (aDDRESS)[1], (aDDRESS)[2], (aDDRESS)[3]
class conv {
public:
static void hexa_to_ascii(uint8_t *from, char *to, size_t length);
static int ascii_to_hex(uint8_t *dst, const char *h);
static struct in_addr fromString(const std::string addr4);
static std::string toString(const struct in_addr& inaddr);
static std::string toString(const struct in6_addr& in6addr);
static std::string mccToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
static std::string mncToString(const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
public:
static void hexa_to_ascii(uint8_t* from, char* to, size_t length);
static int ascii_to_hex(uint8_t* dst, const char* h);
static struct in_addr fromString(const std::string addr4);
static std::string toString(const struct in_addr& inaddr);
static std::string toString(const struct in6_addr& in6addr);
static std::string mccToString(
const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
static std::string mncToString(
const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
This diff is collapsed.
......@@ -11,7 +11,7 @@
* 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 <sys/socket.h>
#include <stdlib.h>
......@@ -23,8 +23,7 @@
#include <unistd.h>
#include <net/if.h>
#include <fstream> // std::ifstream
#include <fstream> // std::ifstream
#include <string>
#include "common_defs.h"
......@@ -36,45 +35,45 @@
using namespace std;
//------------------------------------------------------------------------------
bool util::get_iface_l2_addr(const std::string& iface, std::string& mac)
{
std::string mac_address_path = fmt::format("/sys/class/net/{}/address", iface);
std::ifstream mac_address_in(mac_address_path.c_str(), ios_base::in | ios_base::binary );
bool util::get_iface_l2_addr(const std::string& iface, std::string& mac) {
std::string mac_address_path =
fmt::format("/sys/class/net/{}/address", iface);
std::ifstream mac_address_in(
mac_address_path.c_str(), ios_base::in | ios_base::binary);
char wb[32];
mac_address_in.get(wb, 32);
mac.assign(wb);
Logger::pfcp_switch().error("Found IFace %s MAC %s", iface.c_str(), mac.c_str());
Logger::pfcp_switch().error(
"Found IFace %s MAC %s", iface.c_str(), mac.c_str());
mac.erase(std::remove(mac.begin(), mac.end(), ':'), mac.end());
return true;
// ifr = {};
// strncpy ((char *) ifr.ifr_name, ifname, IFNAMSIZ);
// if (ioctl(sd, SIOCGIFFLAGS, &ifr) == 0) {
// if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
// if (ioctl(sd, SIOCGIFHWADDR, &ifr) == 0) {
// memcpy(pdn_mac_address, ifr.ifr_hwaddr.sa_data, 6);
// }
// }
// }
// ifr = {};
// strncpy ((char *) ifr.ifr_name, ifname, IFNAMSIZ);
// if (ioctl(sd, SIOCGIFFLAGS, &ifr) == 0) {
// if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
// if (ioctl(sd, SIOCGIFHWADDR, &ifr) == 0) {
// memcpy(pdn_mac_address, ifr.ifr_hwaddr.sa_data, 6);
// }
// }
// }
}
//------------------------------------------------------------------------------
bool util::get_gateway_and_iface(std::string& gw, std::string& iface)
{
int received_bytes = 0, msg_len = 0, route_attribute_len = 0;
int sock = -1, msgseq = 0;
struct nlmsghdr *nlh, *nlmsg;
struct rtmsg *route_entry;
bool util::get_gateway_and_iface(std::string& gw, std::string& iface) {
int received_bytes = 0, msg_len = 0, route_attribute_len = 0;
int sock = -1, msgseq = 0;
struct nlmsghdr *nlh, *nlmsg;
struct rtmsg* route_entry;
// This struct contain route attributes (route type)
struct rtattr *route_attribute;
char gateway_address[INET_ADDRSTRLEN], interface[IF_NAMESIZE+1];
char msgbuf[BUFFER_SIZE], buffer[BUFFER_SIZE];
char *ptr = buffer;
struct rtattr* route_attribute;
char gateway_address[INET_ADDRSTRLEN], interface[IF_NAMESIZE + 1];
char msgbuf[BUFFER_SIZE], buffer[BUFFER_SIZE];
char* ptr = buffer;
struct timeval tv;
int rv = RETURNok;
int rv = RETURNok;
if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
perror("socket failed");
return false;
perror("socket failed");
return false;
}
memset(msgbuf, 0, sizeof(msgbuf));
......@@ -83,81 +82,83 @@ bool util::get_gateway_and_iface(std::string& gw, std::string& iface)
memset(buffer, 0, sizeof(buffer));
/* point the header and the msg structure pointers into the buffer */
nlmsg = (struct nlmsghdr *)msgbuf;
nlmsg = (struct nlmsghdr*) msgbuf;
/* Fill in the nlmsg header*/
nlmsg->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
nlmsg->nlmsg_type = RTM_GETROUTE; // Get the routes from kernel routing table .
nlmsg->nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; // The message is a request for dump.
nlmsg->nlmsg_seq = msgseq++; // Sequence of the message packet.
nlmsg->nlmsg_pid = getpid(); // PID of process sending the request.
nlmsg->nlmsg_type =
RTM_GETROUTE; // Get the routes from kernel routing table .
nlmsg->nlmsg_flags =
NLM_F_DUMP | NLM_F_REQUEST; // The message is a request for dump.
nlmsg->nlmsg_seq = msgseq++; // Sequence of the message packet.
nlmsg->nlmsg_pid = getpid(); // PID of process sending the request.
/* 1 Sec Timeout to avoid stall */
tv.tv_sec = 1;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv, sizeof(struct timeval));
setsockopt(
sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval*) &tv,
sizeof(struct timeval));
/* send msg */
if (send(sock, nlmsg, nlmsg->nlmsg_len, 0) < 0) {
perror("send failed");
return false;
perror("send failed");
return false;
}
/* receive response */
do {
received_bytes = recv(sock, ptr, sizeof(buffer) - msg_len, 0);
if (received_bytes < 0) {
perror("Error in recv");
return false;
perror("Error in recv");
return false;
}
nlh = (struct nlmsghdr *) ptr;
nlh = (struct nlmsghdr*) ptr;
/* Check if the header is valid */
if((NLMSG_OK(nlmsg, received_bytes) == 0) ||
(nlmsg->nlmsg_type == NLMSG_ERROR))
{
perror("Error in received packet");
return false;
if ((NLMSG_OK(nlmsg, received_bytes) == 0) ||
(nlmsg->nlmsg_type == NLMSG_ERROR)) {
perror("Error in received packet");
return false;
}
/* If we received all data break */
if (nlh->nlmsg_type == NLMSG_DONE)
break;
break;
else {
ptr += received_bytes;
msg_len += received_bytes;
ptr += received_bytes;
msg_len += received_bytes;
}
/* Break if its not a multi part message */
if ((nlmsg->nlmsg_flags & NLM_F_MULTI) == 0)
break;
if ((nlmsg->nlmsg_flags & NLM_F_MULTI) == 0) break;
} while ((nlmsg->nlmsg_seq != msgseq) || (nlmsg->nlmsg_pid != getpid()));
/* parse response */
for ( ; NLMSG_OK(nlh, received_bytes); nlh = NLMSG_NEXT(nlh, received_bytes)) {
for (; NLMSG_OK(nlh, received_bytes); nlh = NLMSG_NEXT(nlh, received_bytes)) {
/* Get the route data */
route_entry = (struct rtmsg *) NLMSG_DATA(nlh);
route_entry = (struct rtmsg*) NLMSG_DATA(nlh);
/* We are just interested in main routing table */
if (route_entry->rtm_table != RT_TABLE_MAIN)
continue;
if (route_entry->rtm_table != RT_TABLE_MAIN) continue;
route_attribute = (struct rtattr *) RTM_RTA(route_entry);
route_attribute = (struct rtattr*) RTM_RTA(route_entry);
route_attribute_len = RTM_PAYLOAD(nlh);
/* Loop through all attributes */
for ( ; RTA_OK(route_attribute, route_attribute_len);
route_attribute = RTA_NEXT(route_attribute, route_attribute_len)) {
switch(route_attribute->rta_type) {
for (; RTA_OK(route_attribute, route_attribute_len);
route_attribute = RTA_NEXT(route_attribute, route_attribute_len)) {
switch (route_attribute->rta_type) {
case RTA_OIF:
if_indextoname(*(int *)RTA_DATA(route_attribute), interface);
break;
if_indextoname(*(int*) RTA_DATA(route_attribute), interface);
break;
case RTA_GATEWAY:
inet_ntop(AF_INET, RTA_DATA(route_attribute),
gateway_address, sizeof(gateway_address));
break;
inet_ntop(
AF_INET, RTA_DATA(route_attribute), gateway_address,
sizeof(gateway_address));
break;
default:
break;
}
break;
}
}
if ((*gateway_address) && (*interface)) {
......@@ -171,4 +172,3 @@ bool util::get_gateway_and_iface(std::string& gw, std::string& iface)
close(sock);
return true;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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