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