From 31bd9703b11415d6bebc8de2d9abb17fa8452e56 Mon Sep 17 00:00:00 2001 From: Stefan Spettel <stefan.spettel@phine.tech> Date: Sun, 2 Jun 2024 19:05:47 +0200 Subject: [PATCH] refact(pcf): remove unused code and resynch with utils from common-src Signed-off-by: Stefan Spettel <stefan.spettel@phine.tech> --- src/api-server/CMakeLists.txt | 2 + src/api-server/pcf-http2-server.hpp | 3 +- src/common/3gpp_23.003.h | 120 ----------- src/common/3gpp_29.510.h | 86 -------- src/common/3gpp_29.571.h | 49 ----- src/common/3gpp_commons.h | 39 ---- src/common/common_defs.h | 55 ----- src/common/common_root_types.c | 26 --- src/common/common_root_types.h | 74 ------- src/common/endpoint.hpp | 90 -------- src/common/pcf.h | 1 - src/common/utils/conversions.cpp | 166 -------------- src/common/utils/conversions.hpp | 59 ----- src/common/utils/get_gateway_netlink.cpp | 172 --------------- src/common/utils/get_gateway_netlink.hpp | 37 ---- src/common/utils/if.cpp | 263 ----------------------- src/common/utils/if.hpp | 40 ---- src/common/utils/string.cpp | 107 --------- src/common/utils/string.hpp | 45 ---- src/common/utils/uint_generator.hpp | 124 ----------- src/common/utils/utils.cmake | 5 - src/oai-cn5g-common-src | 2 +- src/oai_pcf/CMakeLists.txt | 1 + src/oai_pcf/main.cpp | 4 +- src/pcf_app/CMakeLists.txt | 17 +- src/pcf_app/pcf_app.hpp | 2 - src/pcf_app/pcf_nrf.hpp | 2 - src/pcf_app/pcf_profile.cpp | 29 +-- src/pcf_app/pcf_profile.hpp | 1 + src/pcf_app/pcf_sm_policy_control.hpp | 2 +- 30 files changed, 34 insertions(+), 1589 deletions(-) delete mode 100644 src/common/3gpp_23.003.h delete mode 100644 src/common/3gpp_29.510.h delete mode 100644 src/common/3gpp_29.571.h delete mode 100644 src/common/3gpp_commons.h delete mode 100644 src/common/common_defs.h delete mode 100644 src/common/common_root_types.c delete mode 100644 src/common/common_root_types.h delete mode 100644 src/common/endpoint.hpp delete mode 100644 src/common/utils/conversions.cpp delete mode 100644 src/common/utils/conversions.hpp delete mode 100644 src/common/utils/get_gateway_netlink.cpp delete mode 100644 src/common/utils/get_gateway_netlink.hpp delete mode 100644 src/common/utils/if.cpp delete mode 100644 src/common/utils/if.hpp delete mode 100644 src/common/utils/string.cpp delete mode 100644 src/common/utils/string.hpp delete mode 100644 src/common/utils/uint_generator.hpp diff --git a/src/api-server/CMakeLists.txt b/src/api-server/CMakeLists.txt index 4412458..0ec7a0e 100644 --- a/src/api-server/CMakeLists.txt +++ b/src/api-server/CMakeLists.txt @@ -33,6 +33,8 @@ include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/common_model/common_model.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/pcf/pcf_model.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/model/smf/smf_model.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils/utils.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/common/common.cmake) file(GLOB PCF_API_SERVER_src_files ${PCF_API_SERVER_DIR}/pcf-api-server.cpp diff --git a/src/api-server/pcf-http2-server.hpp b/src/api-server/pcf-http2-server.hpp index 6d3d2e8..6db65de 100644 --- a/src/api-server/pcf-http2-server.hpp +++ b/src/api-server/pcf-http2-server.hpp @@ -29,7 +29,6 @@ #pragma once -#include "conversions.hpp" #include "pcf.h" #include "pcf_app.hpp" #include "string.hpp" @@ -68,7 +67,7 @@ class pcf_http2_server { void stop(); private: - util::uint_generator<uint32_t> m_promise_id_generator; + oai::utils::uint_generator<uint32_t> m_promise_id_generator; std::string m_address; uint32_t m_port; bool running_server; diff --git a/src/common/3gpp_23.003.h b/src/common/3gpp_23.003.h deleted file mode 100644 index 9f47b7f..0000000 --- a/src/common/3gpp_23.003.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file 3gpp_23.003.h - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr - */ -#ifndef FILE_3GPP_23_003_SEEN -#define FILE_3GPP_23_003_SEEN - -#include <stdint.h> - -typedef struct plmn_s { - uint8_t mcc_digit2 : 4; - uint8_t mcc_digit1 : 4; - uint8_t mcc_digit3 : 4; - uint8_t mnc_digit3 : 4; - uint8_t mnc_digit2 : 4; - uint8_t mnc_digit1 : 4; -} plmn_t; - -#define INVALID_TAC_0000 (uint16_t) 0x0000 -#define INVALID_TAC_FFFE (uint16_t) 0xFFFE -#define INVALID_TAC (uint32_t) 0x00000000 - -#define INVALID_TMSI \ - UINT32_MAX /*!< \brief The network shall not allocate a TMSI with all 32 \ - bits equal to 1 (this is because the TMSI must be stored in \ - the SIM, and the SIM uses 4 octets with all bits \ - equal to 1 to indicate that no valid TMSI is \ - available). */ -typedef uint16_t tac_t; -typedef struct tai_s { - plmn_t plmn; /*!< \brief <MCC> + <MNC> */ - tac_t tac; /*!< \brief Tracking Area Code */ -} tai_t; - -typedef struct eci_s { - uint32_t gnb_id : 20; - uint32_t cell_id : 8; - uint32_t empty : 4; -} ci_t; - -typedef struct cgi_s { - plmn_t plmn; - ci_t cell_identity; // 28 bits -} cgi_t; - -typedef struct nr_tai_s /*5G ADD it*/ -{ - plmn_t plmn; - uint32_t tac : 24; -} nr_tai_t; - -typedef struct nr_cell_identity_s /*5G ADD it */ -{ - uint32_t gnb_id; - uint8_t cell_id : 4; -} nr_cell_identity_t; - -typedef struct nr_cgi_s /*5G ADD it */ -{ - plmn_t plmn; - nr_cell_identity_t cell_identity; -} nr_cgi_t; - -typedef struct fiveG_s_tmsi_s /*5G ADD it */ -{ - uint16_t amf_set_id : 10; - uint8_t amf_pointer : 6; - uint32_t fiveG_s_tmsi; // 32 -} fiveG_s_tmsi_t; - -typedef struct fiveG_s_gua_s /*5G ADD it */ -{ - plmn_t plmn; - uint8_t region_id; - uint16_t amf_set_id : 10; - uint8_t amf_pointer : 6; - -} fiveG_s_gua_t; - -typedef struct amf_set_id_s /*5G ADD it*/ -{ - uint16_t amf_set_id : 10; -} amf_set_id_t; - -typedef struct allowed_nssai /*5G ADD it*/ -{ - uint8_t sST; - uint32_t sD : 24; -} allowed_nssai; - -// typedef struct allowed_nssai_s /*5G ADD it*/ -// { -// allowed_nssai* s_nssai; -// uint32_t count; -// } allowed_nssai_t; - -#endif diff --git a/src/common/3gpp_29.510.h b/src/common/3gpp_29.510.h deleted file mode 100644 index 41eb5ad..0000000 --- a/src/common/3gpp_29.510.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#ifndef FILE_3GPP_29_510_PCF_SEEN -#define FILE_3GPP_29_510_PCF_SEEN - -#include <vector> -#include <nlohmann/json.hpp> -#include "3gpp_23.003.h" - -// Section 28.4, TS23.003 -typedef struct s_nssai { - uint8_t sST; - std::string sD; - s_nssai(const uint8_t& sst, const std::string sd) : sST(sst), sD(sd) {} - s_nssai() : sST(), sD() {} - s_nssai(const s_nssai& p) : sST(p.sST), sD(p.sD) {} - bool operator==(const struct s_nssai& s) const { - if ((s.sST == this->sST) && (s.sD.compare(this->sD) == 0)) { - return true; - } else { - return false; - } - } - s_nssai& operator=(const s_nssai& s) { - sST = s.sST; - sD = s.sD; - return *this; - } - -} snssai_t; - -typedef struct dnai_s { -} dnai_t; - -typedef struct patch_item_s { - std::string op; - std::string path; - // std::string from; - std::string value; - - nlohmann::json to_json() const { - nlohmann::json json_data = {}; - json_data["op"] = op; - json_data["path"] = path; - json_data["value"] = value; - return json_data; - } -} patch_item_t; - -#define NSSF_CURL_TIMEOUT_MS 100L -#define NNRF_NFM_BASE "/nnrf-nfm/" -#define NSSF_NF_REGISTER_URL "/nf-instances/" - -// #### new data types -typedef struct tac_range_s { - std::string start; - std::string end; - std::string pattern; -} tac_range_t; - -typedef struct tai_range_s { - plmn_t plmnid; - std::vector<tac_range_t> tac_range_list; - // std::string Nid; -} tai_range_t; - -#endif diff --git a/src/common/3gpp_29.571.h b/src/common/3gpp_29.571.h deleted file mode 100644 index 7668a1a..0000000 --- a/src/common/3gpp_29.571.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#ifndef FILE_3GPP_29_571_SEEN -#define FILE_3GPP_29_571_SEEN - -#include "3gpp_23.003.h" -#include "3gpp_29.510.h" - -#include <vector> - -enum access_type_e { ACESS_3GPP = 1, ACESS_NON_3GPP = 2 }; - -static const std::vector<std::string> access_type_e2str = { - "3GPP_ACCESS", "NON_3GPP_ACCESS"}; - -typedef struct sd_range_s { - std::string start; - std::string end; -} sd_range_t; - -typedef struct snssai_extension_s { - std::vector<sd_range_t> sd_ranges; - bool wildcard_sd; -} snssai_extension_t; - -typedef struct ext_snssai_s { - snssai_t snssai; - snssai_extension_t snssai_extension; -} ext_snssai_t; -#endif diff --git a/src/common/3gpp_commons.h b/src/common/3gpp_commons.h deleted file mode 100644 index bb61a25..0000000 --- a/src/common/3gpp_commons.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file 3gpp_commons.h - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_3GPP_COMMONS_SEEN -#define FILE_3GPP_COMMONS_SEEN - -#include <stdint.h> - -// 8.2 Recovery -typedef struct recovery_s { - uint8_t restart_counter; -} recovery_t; - -#endif /* FILE_3GPP_COMMONS_SEEN */ diff --git a/src/common/common_defs.h b/src/common/common_defs.h deleted file mode 100644 index 6e0f8c5..0000000 --- a/src/common/common_defs.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file common_defs.h - \brief - \author Sebastien ROUX, Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_COMMON_DEFS_SEEN -#define FILE_COMMON_DEFS_SEEN - -#include <arpa/inet.h> - -#define RETURNclear (int) 2 -#define RETURNerror (int) 1 -#define RETURNok (int) 0 - -//------------------------------------------------------------------------------ -#define IPV4_STR_ADDR_TO_INADDR(AdDr_StR, InAdDr, MeSsAgE) \ - do { \ - if (inet_aton(AdDr_StR, &InAdDr) <= 0) { \ - throw(MeSsAgE); \ - } \ - } while (0) - -#define NIPADDR(addr) \ - (uint8_t)(addr & 0x000000FF), (uint8_t) ((addr & 0x0000FF00) >> 8), \ - (uint8_t) ((addr & 0x00FF0000) >> 16), \ - (uint8_t) ((addr & 0xFF000000) >> 24) - -#ifndef UNUSED -#define UNUSED(x) (void) (x) -#endif - -#endif /* FILE_COMMON_DEFS_SEEN */ diff --git a/src/common/common_root_types.c b/src/common/common_root_types.c deleted file mode 100644 index d48e382..0000000 --- a/src/common/common_root_types.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file common_root_types.c - \brief - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ diff --git a/src/common/common_root_types.h b/src/common/common_root_types.h deleted file mode 100644 index 9692c8d..0000000 --- a/src/common/common_root_types.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file common_root_types.h - \brief - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_COMMON_ROOT_TYPES_SEEN -#define FILE_COMMON_ROOT_TYPES_SEEN - -#include <stdint.h> -#include <inttypes.h> -#include <arpa/inet.h> - -//------------------------------------------------------------------------------ -#define PRIORITY_LEVEL_MAX (15) -#define PRIORITY_LEVEL_MIN (1) -#define BEARERS_PER_UE (11) -#define IMEI_DIGITS_MAX (15) -#define IMEISV_DIGITS_MAX (16) -#define MAX_APN_PER_UE (5) - -#define PROC_ID_FMT "0x%" PRIx64 - -// TEIDs -typedef uint32_t teid_t; -#define TEID_FMT "0x%" PRIx32 -#define TEID_SCAN_FMT SCNx32 -#define INVALID_TEID ((teid_t) 0x00000000) -#define UNASSIGNED_TEID ((teid_t) 0x00000000) - -// SEIDs -typedef uint64_t seid_t; -#define SEID_FMT "0x%" PRIx64 -#define SEID_SCAN_FMT SCNx64 -#define INVALID_SEID ((seid_t) 0x00000000) -#define UNASSIGNED_SEID ((seid_t) 0x00000000) - -//------------------------------------------------------------------------------ -// IMSI -typedef uint64_t imsi64_t; -#define IMSI_64_FMT "%" SCNu64 -#define INVALID_IMSI64 (imsi64_t) 0 - -//------------------------------------------------------------------------------ -typedef uint64_t bitrate_t; -#define PRIORITY_LEVEL_FMT "0x%" PRIu8 -#define QCI_FMT "0x%" PRIu8 -#define QCI_SCAN_FMT SCNu8 - -#define PRE_EMPTION_CAPABILITY_FMT "0x%" PRIu8 -#define PRE_EMPTION_VULNERABILITY_FMT "0x%" PRIu8 - -#endif /* FILE_COMMON_ROOT_TYPES_SEEN */ diff --git a/src/common/endpoint.hpp b/src/common/endpoint.hpp deleted file mode 100644 index f265641..0000000 --- a/src/common/endpoint.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file endpoint.hpp - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_ENDPOINT_HPP_SEEN -#define FILE_ENDPOINT_HPP_SEEN - -#include "conversions.hpp" - -#include <arpa/inet.h> -#include <inttypes.h> -#include <sys/socket.h> -#include <string.h> - -class endpoint { - 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; - - 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; - 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); - } - - sa_family_t family() const { return addr_storage.ss_family; } - - std::string toString() const { - std::string str; - if (addr_storage.ss_family == AF_INET) { - 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(conv::toString(addr_in6->sin6_addr)); - str.append(":").append(std::to_string(ntohs(addr_in6->sin6_port))); - } - return str; - } -}; - -#endif diff --git a/src/common/pcf.h b/src/common/pcf.h index caa8722..9faead3 100644 --- a/src/common/pcf.h +++ b/src/common/pcf.h @@ -22,7 +22,6 @@ #ifndef FILE_PCF_SEEN #define FILE_PCF_SEEN -#include "3gpp_29.571.h" #include <nlohmann/json.hpp> #include <netinet/in.h> #include <arpa/inet.h> diff --git a/src/common/utils/conversions.cpp b/src/common/utils/conversions.cpp deleted file mode 100644 index 08ed483..0000000 --- a/src/common/utils/conversions.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file conversions.cpp - \brief - \author Sebastien ROUX - \company Eurecom -*/ -#include "conversions.hpp" -#include "logger.hpp" - -#include <stdlib.h> -#include <stdint.h> -#include <stdbool.h> -#include <ctype.h> -#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 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; - - 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; - - for (;;) { - int high, low; - - while (*hex && isspace(*hex)) hex++; - - if (!*hex) return 1; - - high = ascii_to_hex_table[*hex++]; - - if (high < 0) return 0; - - while (*hex && isspace(*hex)) hex++; - - if (!*hex) return 0; - - low = ascii_to_hex_table[*hex++]; - - 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)); - 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 = {}; - uint16_t mcc16 = 0; - - if (digit3 == 0x0F) { - mcc16 = digit1 * 10 + digit2; - } else { - mcc16 = digit1 * 100 + digit2 * 10 + digit3; - } - s.append(std::to_string(mcc16)); - return s; -} - -//------------------------------------------------------------------------------ -struct in_addr conv::fromString(const std::string addr4) { - unsigned char buf[sizeof(struct in6_addr)] = {}; - auto ret = inet_pton(AF_INET, addr4.c_str(), buf); - if (ret != 1) { - Logger::pcf_app().error( - __PRETTY_FUNCTION__ + std::string{" Failed to convert "} + addr4); - } - struct in_addr* ia = (struct in_addr*) buf; - return *ia; -} - -//------------------------------------------------------------------------------ -struct in6_addr conv::fromStringV6(const std::string& addr6) { - unsigned char buf[sizeof(struct in6_addr)] = {}; - struct in6_addr ipv6_addr {}; - if (inet_pton(AF_INET6, addr6.c_str(), buf) == 1) { - memcpy(&ipv6_addr, buf, sizeof(struct in6_addr)); - } - return ipv6_addr; -} - -//------------------------------------------------------------------------------ -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) { - s.append("Error in_addr"); - } else { - s.append(str); - } - return 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) { - s.append("Error in6_addr"); - } else { - s.append(str); - } - return s; -} diff --git a/src/common/utils/conversions.hpp b/src/common/utils/conversions.hpp deleted file mode 100644 index e35e9d6..0000000 --- a/src/common/utils/conversions.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file conversions.hpp - \brief - \author Sebastien ROUX, Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_CONVERSIONS_HPP_SEEN -#define FILE_CONVERSIONS_HPP_SEEN -#include <stdint.h> -#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] - -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 struct in6_addr fromStringV6(const std::string& addr6); - 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 */ diff --git a/src/common/utils/get_gateway_netlink.cpp b/src/common/utils/get_gateway_netlink.cpp deleted file mode 100644 index f257344..0000000 --- a/src/common/utils/get_gateway_netlink.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* From https://gist.github.com/javiermon/6272065#file-gateway_netlink-c */ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <sys/socket.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <net/if.h> - -#include <fstream> // std::ifstream -#include <string> - -#include "common_defs.h" -#include "get_gateway_netlink.hpp" -#include "logger.hpp" - -#define BUFFER_SIZE 4096 - -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); - char wb[32]; - mac_address_in.get(wb, 32); - mac.assign(wb); - Logger::pcf_app().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); - // } - // } - // } -} -//------------------------------------------------------------------------------ -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; - unsigned int 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 timeval tv; - - if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) { - perror("socket failed"); - return false; - } - - memset(msgbuf, 0, sizeof(msgbuf)); - memset(gateway_address, 0, sizeof(gateway_address)); - memset(interface, 0, sizeof(interface)); - memset(buffer, 0, sizeof(buffer)); - - /* point the header and the msg structure pointers into the buffer */ - 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. - - /* 1 Sec Timeout to avoid stall */ - tv.tv_sec = 1; - 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; - } - - /* receive response */ - do { - received_bytes = recv(sock, ptr, sizeof(buffer) - msg_len, 0); - if (received_bytes < 0) { - perror("Error in recv"); - return false; - } - - 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 we received all data break */ - if (nlh->nlmsg_type == NLMSG_DONE) - break; - else { - ptr += received_bytes; - msg_len += received_bytes; - } - - /* Break if its not a multi part message */ - if ((nlmsg->nlmsg_flags & NLM_F_MULTI) == 0) break; - } while ((nlmsg->nlmsg_seq != msgseq) || - (nlmsg->nlmsg_pid != static_cast<unsigned int>(getpid()))); - - /* parse response */ - for (; NLMSG_OK(nlh, received_bytes); nlh = NLMSG_NEXT(nlh, received_bytes)) { - /* Get the route data */ - route_entry = (struct rtmsg*) NLMSG_DATA(nlh); - - /* We are just interested in main routing table */ - if (route_entry->rtm_table != RT_TABLE_MAIN) continue; - - 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) { - case RTA_OIF: - 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; - default: - break; - } - } - - if ((*gateway_address) && (*interface)) { - gw.assign(gateway_address); - iface.assign(interface); - break; - } - } - close(sock); - return true; -} diff --git a/src/common/utils/get_gateway_netlink.hpp b/src/common/utils/get_gateway_netlink.hpp deleted file mode 100644 index b29d067..0000000 --- a/src/common/utils/get_gateway_netlink.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file get_gateway_netlink.hpp - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ -#ifndef FILE_GET_GATEWAY_NETLINK_HPP_SEEN -#define FILE_GET_GATEWAY_NETLINK_HPP_SEEN - -#include <string> - -namespace util { -bool get_iface_l2_addr(const std::string& iface, std::string& mac); -bool get_gateway_and_iface(std::string& gw, std::string& iface); -} // namespace util -#endif /* FILE_GET_GATEWAY_NETLINK_HPP_SEEN */ diff --git a/src/common/utils/if.cpp b/src/common/utils/if.cpp deleted file mode 100644 index 95e6477..0000000 --- a/src/common/utils/if.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* From https://gist.github.com/javiermon/6272065#file-gateway_netlink-c */ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "common_defs.h" -#include "if.hpp" -#include "logger.hpp" - -#include <errno.h> -#include <sys/socket.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <arpa/inet.h> -#include <unistd.h> -#include <net/if.h> -#include <sys/ioctl.h> - -#define BUFFER_SIZE 4096 - -//------------------------------------------------------------------------------ -int get_gateway_and_iface(std::string* gw, std::string* iface) { - int received_bytes = 0, msg_len = 0, route_attribute_len = 0; - int sock = -1; - unsigned int 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]; - char msgbuf[BUFFER_SIZE], buffer[BUFFER_SIZE]; - char* ptr = buffer; - struct timeval tv; - int rv = RETURNok; - - if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) { - Logger::system().error("socket raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - memset(msgbuf, 0, sizeof(msgbuf)); - memset(gateway_address, 0, sizeof(gateway_address)); - memset(interface, 0, sizeof(interface)); - memset(buffer, 0, sizeof(buffer)); - - /* point the header and the msg structure pointers into the buffer */ - 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. - - /* 1 Sec Timeout to avoid stall */ - tv.tv_sec = 1; - setsockopt( - sock, SOL_SOCKET, SO_RCVTIMEO, (struct timeval*) &tv, - sizeof(struct timeval)); - /* send msg */ - if (send(sock, nlmsg, nlmsg->nlmsg_len, 0) < 0) { - Logger::system().error("send socket raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - /* receive response */ - do { - received_bytes = recv(sock, ptr, sizeof(buffer) - msg_len, 0); - if (received_bytes < 0) { - Logger::system().error("recv socket raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - nlh = (struct nlmsghdr*) ptr; - - /* Check if the header is valid */ - if ((NLMSG_OK(nlmsg, received_bytes) == 0) || - (nlmsg->nlmsg_type == NLMSG_ERROR)) { - Logger::system().error("recv msg raw/NETLINK_ROUTE failed"); - return EXIT_FAILURE; - } - - /* If we received all data break */ - if (nlh->nlmsg_type == NLMSG_DONE) - break; - else { - ptr += received_bytes; - msg_len += received_bytes; - } - - /* Break if its not a multi part message */ - if ((nlmsg->nlmsg_flags & NLM_F_MULTI) == 0) break; - } while ((nlmsg->nlmsg_seq != msgseq) || - (nlmsg->nlmsg_pid != static_cast<unsigned int>(getpid()))); - - /* parse response */ - for (; NLMSG_OK(nlh, received_bytes); nlh = NLMSG_NEXT(nlh, received_bytes)) { - /* Get the route data */ - route_entry = (struct rtmsg*) NLMSG_DATA(nlh); - - /* We are just interested in main routing table */ - if (route_entry->rtm_table != RT_TABLE_MAIN) continue; - - 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) { - case RTA_OIF: - 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; - default: - break; - } - } - - if ((*gateway_address) && (*interface)) { - *gw = std::string(gateway_address); - if (iface) { - *iface = std::string(interface); - } - break; - } else { - rv = RETURNerror; - } - } - close(sock); - return rv; -} - -//------------------------------------------------------------------------------ -int get_inet_addr_from_iface( - const std::string& if_name, struct in_addr& inet_addr) { - struct ifreq ifr; - char str[INET_ADDRSTRLEN]; - - memset(&ifr, 0, sizeof(ifr)); - int fd = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFADDR, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s inet addr: error %s\n", if_name.c_str(), - strerror(errno)); - return RETURNerror; - } - close(fd); - struct sockaddr_in* ipaddr = (struct sockaddr_in*) &ifr.ifr_addr; - // check - if (inet_ntop( - AF_INET, (const void*) &ipaddr->sin_addr, str, INET_ADDRSTRLEN) == - NULL) { - return RETURNerror; - } - inet_addr.s_addr = ipaddr->sin_addr.s_addr; - return RETURNok; -} - -//------------------------------------------------------------------------------ -int get_mtu_from_iface(const std::string& if_name, uint32_t& mtu) { - struct ifreq ifr; - memset(&ifr, 0, sizeof(ifr)); - int fd = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFMTU, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s MTU: error %s\n", if_name.c_str(), strerror(errno)); - return RETURNerror; - } - close(fd); - mtu = ifr.ifr_mtu; - return RETURNok; -} - -//------------------------------------------------------------------------------ -int get_inet_addr_infos_from_iface( - const std::string& if_name, struct in_addr& inet_addr, - struct in_addr& inet_network, unsigned int& mtu) { - struct ifreq ifr; - char str[INET_ADDRSTRLEN]; - - inet_addr.s_addr = INADDR_ANY; - inet_network.s_addr = INADDR_ANY; - mtu = 0; - - memset(&ifr, 0, sizeof(ifr)); - int fd = socket(AF_INET, SOCK_DGRAM, 0); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFADDR, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s inet addr: error %s\n", if_name.c_str(), - strerror(errno)); - return RETURNerror; - } - struct sockaddr_in* ipaddr = (struct sockaddr_in*) &ifr.ifr_addr; - // check - if (inet_ntop( - AF_INET, (const void*) &ipaddr->sin_addr, str, INET_ADDRSTRLEN) == - NULL) { - close(fd); - return RETURNerror; - } - inet_addr.s_addr = ipaddr->sin_addr.s_addr; - - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFNETMASK, &ifr)) { - close(fd); - Logger::system().error( - "Failed to probe %s inet netmask: error %s\n", if_name.c_str(), - strerror(errno)); - return RETURNerror; - } - ipaddr = (struct sockaddr_in*) &ifr.ifr_netmask; - // check - if (inet_ntop( - AF_INET, (const void*) &ipaddr->sin_addr, str, INET_ADDRSTRLEN) == - NULL) { - close(fd); - return RETURNerror; - } - inet_network.s_addr = ipaddr->sin_addr.s_addr; - - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name, (const char*) if_name.c_str(), IFNAMSIZ - 1); - if (ioctl(fd, SIOCGIFMTU, &ifr)) { - Logger::system().error( - "Failed to probe %s MTU: error %s\n", if_name.c_str(), strerror(errno)); - } else { - mtu = ifr.ifr_mtu; - } - close(fd); - return RETURNok; -} diff --git a/src/common/utils/if.hpp b/src/common/utils/if.hpp deleted file mode 100644 index ede70f5..0000000 --- a/src/common/utils/if.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file get_gateway_netlink.h - \brief - \author Lionel Gauthier - \company Eurecom - \email: lionel.gauthier@eurecom.fr -*/ -#ifndef FILE_IF_HPP_SEEN -#define FILE_IF_HPP_SEEN -#include <string> - -int get_gateway_and_iface(std::string* gw /*OUT*/, std::string* iface /*OUT*/); -int get_inet_addr_from_iface( - const std::string& if_name, struct in_addr& inet_addr); -int get_mtu_from_iface(const std::string& if_name, uint32_t& mtu); -int get_inet_addr_infos_from_iface( - const std::string& if_name, struct in_addr& inet_addr, - struct in_addr& inet_netmask, unsigned int& mtu); - -#endif /* FILE_IF_HPP_SEEN */ diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp deleted file mode 100644 index 8846793..0000000 --- a/src/common/utils/string.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - *file except in compliance with the License. You may obtain a copy of the - *License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ -#include "string.hpp" -#include <iostream> - -#include <algorithm> -#include <functional> -#include <cctype> -#include <locale> -#include <stdarg.h> -#include <regex> - -template<class T> -class Buffer { - public: - explicit Buffer(size_t size) { - msize = size; - mbuf = new T[msize]; - } - ~Buffer() { - if (mbuf) delete[] mbuf; - } - T* get() { return mbuf; } - - private: - Buffer(); - size_t msize; - T* mbuf; -}; - -std::string util::string_format(const char* format, ...) { - va_list args; - - va_start(args, format); - size_t size = vsnprintf(NULL, 0, format, args) + 1; // Extra space for '\0' - va_end(args); - - Buffer<char> buf(size); - - va_start(args, format); - vsnprintf(buf.get(), size, format, args); - va_end(args); - - return std::string(buf.get(), size - 1); // We don't want the '\0' inside -} - -// Licence : https://creativecommons.org/licenses/by-sa/4.0/legalcode -// https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring#217605 - -// trim from start -std::string& util::ltrim(std::string& s) { - s.erase( - s.begin(), - std::find_if( - s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); - return s; -} - -// trim from end -std::string& util::rtrim(std::string& s) { - s.erase( - std::find_if( - s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))) - .base(), - s.end()); - return s; -} - -// trim from both ends -std::string& util::trim(std::string& s) { - return util::ltrim(util::rtrim(s)); -} - -// extract query param from given querystring -std::string query_param_tmp; -// -std::string util::get_query_param(std::string querystring, std::string param) { - std::regex reList("([^=]*)=([^&]*)&?"); - query_param_tmp.clear(); - std::for_each( - std::sregex_iterator(querystring.begin(), querystring.end(), reList), - std::sregex_iterator(), [param](std::smatch match) { - if (match[1] == param) { - query_param_tmp = match[2].str().c_str(); - return; - } - }); - return query_param_tmp; -} \ No newline at end of file diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp deleted file mode 100644 index 5be5c8c..0000000 --- a/src/common/utils/string.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - *file except in compliance with the License. You may obtain a copy of the - *License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file string.hpp - \brief - \author Lionel GAUTHIER - \date 2018 - \email: lionel.gauthier@eurecom.fr - */ -#ifndef FILE_STRING_HPP_FILE_SEEN -#define FILE_STRING_HPP_FILE_SEEN - -#include <string> - -namespace util { - -std::string string_format(const char* format, ...); - -std::string& ltrim(std::string& s); -// trim from end -std::string& rtrim(std::string& s); -// trim from both ends -std::string& trim(std::string& s); -// extract query param from given querystring -std::string get_query_param(std::string querystring, std::string param); -} // namespace util -#endif diff --git a/src/common/utils/uint_generator.hpp b/src/common/utils/uint_generator.hpp deleted file mode 100644 index 246373a..0000000 --- a/src/common/utils/uint_generator.hpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the - * License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file uint_uid_generator.hpp - \author Lionel GAUTHIER - \date 2019 - \email: lionel.gauthier@eurecom.fr -*/ - -#ifndef FILE_UINT_GENERATOR_HPP_SEEN -#define FILE_UINT_GENERATOR_HPP_SEEN - -#include <mutex> -#include <set> - -namespace util { - -template<class UINT> -class uint_generator { - private: - UINT uid_generator; - std::mutex m_uid_generator; - - std::set<UINT> uid_generated; - std::mutex m_uid_generated; - - public: - uint_generator() : m_uid_generator(), m_uid_generated() { - uid_generator = 0; - uid_generated = {}; - }; - - uint_generator(uint_generator const&) = delete; - void operator=(uint_generator const&) = delete; - - UINT get_uid() { - std::unique_lock<std::mutex> lr(m_uid_generator); - UINT uid = ++uid_generator; - while (true) { - // may happen race conditions here - std::unique_lock<std::mutex> ld(m_uid_generated); - if (uid_generated.count(uid) == 0) { - uid_generated.insert(uid); - ld.unlock(); - lr.unlock(); - return uid; - } - uid = ++uid_generator; - } - } - - void free_uid(UINT uid) { - std::unique_lock<std::mutex> l(m_uid_generated); - uid_generated.erase(uid); - l.unlock(); - } -}; - -template<class UINT> -class uint_uid_generator { - private: - UINT uid_generator; - std::mutex m_uid_generator; - - std::set<UINT> uid_generated; - std::mutex m_uid_generated; - - uint_uid_generator() : m_uid_generator(), m_uid_generated() { - uid_generator = 0; - uid_generated = {}; - }; - - public: - static uint_uid_generator& get_instance() { - static uint_uid_generator instance; - return instance; - } - - uint_uid_generator(uint_uid_generator const&) = delete; - void operator=(uint_uid_generator const&) = delete; - - UINT get_uid() { - std::unique_lock<std::mutex> lr(m_uid_generator); - UINT uid = ++uid_generator; - while (true) { - // may happen race conditions here - std::unique_lock<std::mutex> ld(m_uid_generated); - if (uid_generated.count(uid) == 0) { - uid_generated.insert(uid); - lr.unlock(); - ld.unlock(); - return uid; - } - uid = ++uid_generator; - } - } - - void free_uid(UINT uid) { - std::unique_lock<std::mutex> l(m_uid_generated); - uid_generated.erase(uid); - l.unlock(); - } -}; - -} // namespace util -#endif // FILE_UINT_GENERATOR_HPP_SEEN diff --git a/src/common/utils/utils.cmake b/src/common/utils/utils.cmake index 4184acb..b844f0e 100644 --- a/src/common/utils/utils.cmake +++ b/src/common/utils/utils.cmake @@ -21,14 +21,9 @@ SET(UTILS_DIR ${SRC_TOP_DIR}/common/utils) -## Logger used in NF_TARGET (main) -## TODO for now only use utils actually used by PCF target_include_directories(${NF_TARGET} PUBLIC ${UTILS_DIR}) target_sources(${NF_TARGET} PRIVATE - ${UTILS_DIR}/conversions.cpp - ${UTILS_DIR}/string.cpp ${UTILS_DIR}/fqdn.cpp - ${UTILS_DIR}/if.cpp ${UTILS_DIR}/nf_launch.cpp ${UTILS_DIR}/options.cpp ) diff --git a/src/oai-cn5g-common-src b/src/oai-cn5g-common-src index 411ea56..984f4d9 160000 --- a/src/oai-cn5g-common-src +++ b/src/oai-cn5g-common-src @@ -1 +1 @@ -Subproject commit 411ea5639784eb919a42d4bbfec4ba5b40b88d93 +Subproject commit 984f4d91f172fffb265420c0c7a3cfc42cd28020 diff --git a/src/oai_pcf/CMakeLists.txt b/src/oai_pcf/CMakeLists.txt index adcce54..97f48c8 100644 --- a/src/oai_pcf/CMakeLists.txt +++ b/src/oai_pcf/CMakeLists.txt @@ -292,6 +292,7 @@ add_executable(pcf include(${BUILD_TOP_DIR}/pcf/used_common_files.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger/logger.cmake) include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config/config.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils/utils.cmake) include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils) IF(STATIC_LINKING) diff --git a/src/oai_pcf/main.cpp b/src/oai_pcf/main.cpp index e6f085b..05b3083 100644 --- a/src/oai_pcf/main.cpp +++ b/src/oai_pcf/main.cpp @@ -22,12 +22,12 @@ #include "options.hpp" #include "pistache/http.h" #include "nf_launch.hpp" +#include "conversions.hpp" #include <iostream> #include <csignal> #include <thread> -using namespace util; using namespace std; using namespace oai::pcf::app; using namespace oai::config::pcf; @@ -111,7 +111,7 @@ int main(int argc, char** argv) { pcf_app_inst = std::make_unique<pcf_app>(ev); std::string v4_address = - conv::toString(pcf_cfg->local().get_sbi().get_addr4()); + oai::utils::conv::toString(pcf_cfg->local().get_sbi().get_addr4()); if (pcf_cfg->get_http_version() == 1) { // PCF Pistache API server (HTTP1) diff --git a/src/pcf_app/CMakeLists.txt b/src/pcf_app/CMakeLists.txt index a3a7e62..7d21d4b 100644 --- a/src/pcf_app/CMakeLists.txt +++ b/src/pcf_app/CMakeLists.txt @@ -27,8 +27,16 @@ include_directories(${SRC_TOP_DIR}/api-server/api) include_directories(${SRC_TOP_DIR}/api-server/impl) include_directories(${SRC_TOP_DIR}/api-server/) include_directories(${SRC_TOP_DIR}/pcf_app/sm_policy/) -include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger) -include_directories(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config) + +## Common modules +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/common/common.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/utils/utils.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/logger/logger.cmake) +include(${SRC_TOP_DIR}/${MOUNTED_COMMON}/config/config.cmake) +include(${SRC_TOP_DIR}/common/utils/utils.cmake) + + +include(${BUILD_TOP_DIR}/pcf/used_common_files.cmake) add_library (PCF STATIC pcf_config_types.cpp @@ -48,8 +56,3 @@ add_library (PCF STATIC sm_policy/policy_storage.cpp sm_policy/policy_provisioning_file.cpp ) - -## Common modules -include(${SRC_TOP_DIR}/common/utils/utils.cmake) - -include(${BUILD_TOP_DIR}/pcf/used_common_files.cmake) diff --git a/src/pcf_app/pcf_app.hpp b/src/pcf_app/pcf_app.hpp index ae97c65..8f74634 100644 --- a/src/pcf_app/pcf_app.hpp +++ b/src/pcf_app/pcf_app.hpp @@ -29,7 +29,6 @@ #pragma once -#include "common_root_types.h" #include <boost/atomic.hpp> #include <string> @@ -37,7 +36,6 @@ #include "pcf.h" #include "pcf_profile.hpp" #include "pcf_event.hpp" -#include "3gpp_29.510.h" #include "PatchItem.h" #include "pcf_sm_policy_control.hpp" #include "sm_policy/policy_storage.hpp" diff --git a/src/pcf_app/pcf_nrf.hpp b/src/pcf_app/pcf_nrf.hpp index 6905462..d040397 100644 --- a/src/pcf_app/pcf_nrf.hpp +++ b/src/pcf_app/pcf_nrf.hpp @@ -29,7 +29,6 @@ #pragma once -#include "common_root_types.h" #include <boost/atomic.hpp> #include <string> @@ -37,7 +36,6 @@ #include "pcf.h" #include "pcf_profile.hpp" #include "pcf_event.hpp" -#include "3gpp_29.510.h" #include "PatchItem.h" #include "pcf_client.hpp" diff --git a/src/pcf_app/pcf_profile.cpp b/src/pcf_app/pcf_profile.cpp index e3f7ed4..54b740d 100644 --- a/src/pcf_app/pcf_profile.cpp +++ b/src/pcf_app/pcf_profile.cpp @@ -204,7 +204,7 @@ void nf_profile::display() const { Logger::pcf_app().debug("\tSNSSAI:"); } for (auto s : snssais) { - Logger::pcf_app().debug("\t\t SST %d, SD %s", s.sST, s.sD.c_str()); + Logger::pcf_app().debug("\t\t SST %d, SD %d", s.sst, s.sd); } if (!fqdn.empty()) { Logger::pcf_app().debug("\tFQDN: %s", fqdn.c_str()); @@ -236,8 +236,8 @@ void nf_profile::to_json(nlohmann::json& data) const { data["sNssais"] = nlohmann::json::array(); for (auto s : snssais) { nlohmann::json tmp = {}; - tmp["sst"] = s.sST; - tmp["sd"] = s.sD; + tmp["sst"] = s.sst; + tmp["sd"] = s.sd; data["sNssais"].push_back(tmp); } if (!fqdn.empty()) { @@ -282,9 +282,8 @@ void nf_profile::from_json(const nlohmann::json& data) { // sNssais if (data.find("sNssais") != data.end()) { for (auto it : data["sNssais"]) { - snssai_t s = {}; - s.sST = it["sst"].get<int>(); - s.sD = it["sd"].get<std::string>(); + snssai_t s(it["sst"].get<int>(), it["sd"].get<std::string>()); + snssais.push_back(s); } } @@ -300,11 +299,13 @@ void nf_profile::from_json(const nlohmann::json& data) { struct in_addr addr4 = {}; std::string address = it.get<std::string>(); unsigned char buf_in_addr[sizeof(struct in_addr)]; - if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) { + if (inet_pton(AF_INET, oai::utils::trim(address).c_str(), buf_in_addr) == + 1) { memcpy(&addr4, buf_in_addr, sizeof(struct in_addr)); } else { Logger::pcf_app().warn( - "Address conversion: Bad value %s", util::trim(address).c_str()); + "Address conversion: Bad value %s", + oai::utils::trim(address).c_str()); } add_nf_ipv4_addresses(addr4); } @@ -373,7 +374,7 @@ void pcf_profile::display() const { Logger::pcf_app().debug(" SNSSAI:"); } for (auto s : snssais) { - Logger::pcf_app().debug(" SST, SD: %d, %s", s.sST, s.sD.c_str()); + Logger::pcf_app().debug(" SST, SD: %d, %d", s.sst, s.sd); } // IPv4 Addresses @@ -489,9 +490,7 @@ void pcf_profile::from_json(const nlohmann::json& data) { // sNssais if (data.find("sNssais") != data.end()) { for (auto it : data["sNssais"]) { - snssai_t s = {}; - s.sST = it["sst"].get<int>(); - s.sD = it["sd"].get<std::string>(); + snssai_t s(it["sst"].get<int>(), it["sd"].get<std::string>()); snssais.push_back(s); } } @@ -502,11 +501,13 @@ void pcf_profile::from_json(const nlohmann::json& data) { struct in_addr addr4 = {}; std::string address = it.get<std::string>(); unsigned char buf_in_addr[sizeof(struct in_addr)]; - if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) == 1) { + if (inet_pton(AF_INET, oai::utils::trim(address).c_str(), buf_in_addr) == + 1) { memcpy(&addr4, buf_in_addr, sizeof(struct in_addr)); } else { Logger::pcf_app().warn( - "Address conversion: Bad value %s", util::trim(address).c_str()); + "Address conversion: Bad value %s", + oai::utils::trim(address).c_str()); } add_nf_ipv4_addresses(addr4); } diff --git a/src/pcf_app/pcf_profile.hpp b/src/pcf_app/pcf_profile.hpp index 1576efb..063ae77 100644 --- a/src/pcf_app/pcf_profile.hpp +++ b/src/pcf_app/pcf_profile.hpp @@ -41,6 +41,7 @@ #include "logger.hpp" #include "pcf.h" +#include "3gpp_23.003.h" // namespace oai { // namespace pcf { diff --git a/src/pcf_app/pcf_sm_policy_control.hpp b/src/pcf_app/pcf_sm_policy_control.hpp index f098dd6..5be6ef4 100644 --- a/src/pcf_app/pcf_sm_policy_control.hpp +++ b/src/pcf_app/pcf_sm_policy_control.hpp @@ -125,7 +125,7 @@ class pcf_smpc { std::string& problem_details); private: - util::uint_generator<uint32_t> m_association_id_generator; + oai::utils::uint_generator<uint32_t> m_association_id_generator; std::unordered_map< std::string, oai::pcf::app::sm_policy::individual_sm_association> -- GitLab