From 168582b5a18499081e6cddb1897165c429336780 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Wed, 31 Jul 2024 15:43:59 +0200 Subject: [PATCH] Remove netlink_init.c, and move remaining functionality to tun_if.c Remove openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c, and move TUN interface creation functionality to tun_if.c. Remove SIMU_ETH target. --- CMakeLists.txt | 23 ++-- common/utils/tun_if.c | 95 ++++++++++++++ common/utils/tun_if.h | 6 + doc/Doxyfile | 2 - executables/lte-enb.c | 1 - executables/lte-ru.c | 2 - executables/lte-softmodem.h | 1 - executables/nr-gnb.c | 1 - executables/nr-ru.c | 1 - executables/nr-softmodem-common.h | 2 - executables/nr-softmodem.c | 2 - executables/nr-uesoftmodem.h | 3 - openair1/SIMULATION/ETH_TRANSPORT/README.txt | 25 ---- openair1/SIMULATION/ETH_TRANSPORT/extern.h | 60 --------- .../SIMULATION/ETH_TRANSPORT/netlink_init.c | 121 ------------------ openair1/SIMULATION/ETH_TRANSPORT/proto.h | 37 ------ openair2/LAYER2/PDCP_v10.1.0/pdcp.c | 11 +- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 4 +- openair3/NAS/NR_UE/nr_nas_msg_sim.c | 1 - 19 files changed, 117 insertions(+), 281 deletions(-) delete mode 100644 openair1/SIMULATION/ETH_TRANSPORT/README.txt delete mode 100644 openair1/SIMULATION/ETH_TRANSPORT/extern.h delete mode 100644 openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c delete mode 100644 openair1/SIMULATION/ETH_TRANSPORT/proto.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b19e884592..88233b943e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1878,11 +1878,6 @@ set (SIMUSRC add_library(SIMU STATIC ${SIMUSRC} ) target_include_directories(SIMU PUBLIC ${OPENAIR1_DIR}/SIMULATION/TOOLS ${OPENAIR1_DIR}/SIMULATION/RF) -add_library(SIMU_ETH STATIC - ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c -) -target_link_libraries(SIMU_ETH PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) - include_directories("${NFAPI_DIR}/nfapi/public_inc") include_directories("${NFAPI_DIR}/common/public_inc") include_directories("${NFAPI_DIR}/pnf/public_inc") @@ -1943,7 +1938,7 @@ target_link_libraries(lte-softmodem PRIVATE -Wl,--start-group lte_rrc nr_rrc s1ap m2ap x2ap m3ap GTPV1U SECURITY UTIL HASHTABLE SCTP_CLIENT MME_APP SCHED_LIB SCHED_RU_LIB PHY_COMMON PHY PHY_RU L2 L2_LTE NFAPI_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB MISC_NFAPI_LTE_LIB - ${NAS_UE_LIB} ITTI SIMU SIMU_ETH shlib_loader + ${NAS_UE_LIB} ITTI SIMU shlib_loader -Wl,--end-group z dl) target_link_libraries(lte-softmodem PRIVATE pthread m CONFIG_LIB rt sctp) @@ -1997,7 +1992,7 @@ target_link_libraries(lte-uesoftmodem PRIVATE -Wl,--start-group lte_rrc nr_rrc s1ap x2ap m2ap m3ap SECURITY UTIL HASHTABLE SCTP_CLIENT MME_APP SCHED_RU_LIB SCHED_UE_LIB PHY_COMMON - PHY_UE PHY_RU L2_UE L2_LTE SIMU SIMU_ETH NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB MISC_NFAPI_LTE_LIB + PHY_UE PHY_RU L2_UE L2_LTE SIMU NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB MISC_NFAPI_LTE_LIB ${NAS_UE_LIB} ITTI shlib_loader -Wl,--end-group z dl) @@ -2032,7 +2027,7 @@ target_link_libraries(nr-softmodem PRIVATE -Wl,--start-group UTIL HASHTABLE SCTP_CLIENT SCHED_LIB SCHED_RU_LIB SCHED_NR_LIB PHY_NR PHY PHY_COMMON PHY_NR_COMMON PHY_RU GTPV1U SECURITY ITTI ${NAS_UE_LIB} lte_rrc nr_rrc - ngap s1ap L2_LTE_NR L2_NR MAC_NR_COMMON NFAPI_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB SIMU SIMU_ETH + ngap s1ap L2_LTE_NR L2_NR MAC_NR_COMMON NFAPI_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB SIMU x2ap f1ap m2ap m3ap e1ap shlib_loader -Wl,--end-group z dl) @@ -2071,7 +2066,7 @@ add_executable(nr-cuup target_link_libraries(nr-cuup PRIVATE CONFIG_LIB ITTI SCTP_CLIENT - GTPV1U e1ap f1ap SIMU_ETH + GTPV1U e1ap f1ap z sctp dl pthread shlib_loader ${T_LIB}) target_link_libraries(nr-cuup PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) if(E2_AGENT) @@ -2100,7 +2095,7 @@ target_link_libraries(nr-uesoftmodem PRIVATE nr_rrc SECURITY UTIL HASHTABLE SCHED_RU_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_NR_COMMON PHY_NR_UE NR_L2_UE L2_UE_LTE_NR MAC_NR_COMMON NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB MISC_NFAPI_NR_LIB - ITTI LIB_5GNAS_GNB LIB_NAS_SIMUE ${NAS_SIM_LIB} SIMU SIMU_ETH shlib_loader + ITTI LIB_5GNAS_GNB LIB_NAS_SIMUE ${NAS_SIM_LIB} SIMU shlib_loader -Wl,--end-group z dl) target_link_libraries(nr-uesoftmodem PRIVATE pthread m CONFIG_LIB rt) @@ -2206,7 +2201,7 @@ add_executable(nr_psbchsim ${PHY_INTERFACE_DIR}/queue_t.c ) target_link_libraries(nr_psbchsim PRIVATE - -Wl,--start-group UTIL SIMU SIMU_ETH PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_UE_NR MAC_NR_COMMON CONFIG_LIB L2_NR -lz -Wl,--end-group + -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_UE_NR MAC_NR_COMMON CONFIG_LIB L2_NR -lz -Wl,--end-group m pthread ${T_LIB} ITTI dl shlib_loader ) target_link_libraries(nr_psbchsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) @@ -2232,7 +2227,7 @@ add_executable(nr_dlsim ${PHY_INTERFACE_DIR}/queue_t.c ) target_link_libraries(nr_dlsim PRIVATE - -Wl,--start-group UTIL SIMU SIMU_ETH PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_UE_NR MAC_NR_COMMON nr_rrc CONFIG_LIB L2_NR HASHTABLE x2ap SECURITY ngap -lz -Wl,--end-group + -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_UE_NR MAC_NR_COMMON nr_rrc CONFIG_LIB L2_NR HASHTABLE x2ap SECURITY ngap -lz -Wl,--end-group m pthread ${T_LIB} ITTI dl shlib_loader ) target_link_libraries(nr_dlsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) @@ -2272,7 +2267,7 @@ if (ENABLE_LDPC_T2) endif() target_link_libraries(nr_ulsim PRIVATE - -Wl,--start-group UTIL SIMU SIMU_ETH PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_UE_NR MAC_NR_COMMON nr_rrc CONFIG_LIB L2_NR HASHTABLE x2ap SECURITY ngap -lz -Wl,--end-group + -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_UE_NR MAC_NR_COMMON nr_rrc CONFIG_LIB L2_NR HASHTABLE x2ap SECURITY ngap -lz -Wl,--end-group m pthread ${T_LIB} ITTI dl shlib_loader ) target_link_libraries(nr_ulsim PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) @@ -2335,7 +2330,7 @@ if (${T_TRACER}) MISC_NFAPI_LTE_LIB MISC_NFAPI_NR_LIB PHY_COMMON PHY PHY_UE PHY_NR PHY_NR_COMMON PHY_NR_UE PHY_RU PHY_MEX L2 L2_LTE L2_NR L2_LTE_NR L2_UE NR_L2_UE L2_UE_LTE_NR MAC_NR_COMMON MAC_UE_NR ngap - CN_UTILS GTPV1U SCTP_CLIENT MME_APP LIB_NAS_UE NB_IoT SIMU SIMU_ETH OPENAIR0_LIB + CN_UTILS GTPV1U SCTP_CLIENT MME_APP LIB_NAS_UE NB_IoT SIMU OPENAIR0_LIB ldpc_orig ldpc_optim ldpc_optim8seg ldpc_t2 ldpc_cl ldpc_cuda ldpc dfts config_internals nr_common) if (TARGET ${i}) add_dependencies(${i} generate_T) diff --git a/common/utils/tun_if.c b/common/utils/tun_if.c index 4d6308c02d..4d04325998 100644 --- a/common/utils/tun_if.c +++ b/common/utils/tun_if.c @@ -27,11 +27,106 @@ #include #include #include +#include +#include #include "tun_if.h" +#include "common/platform_constants.h" #include "common/utils/LOG/log.h" #include "common/utils/system.h" +int nas_sock_fd[MAX_MOBILES_PER_ENB * 2]; // Allocated for both LTE UE and NR UE. +int nas_sock_mbms_fd; + +static int tun_alloc(char *dev) +{ + struct ifreq ifr; + int fd, err; + + if ((fd = open("/dev/net/tun", O_RDWR)) < 0) { + LOG_E(UTIL, "failed to open /dev/net/tun\n"); + return -1; + } + + memset(&ifr, 0, sizeof(ifr)); + /* Flags: IFF_TUN - TUN device (no Ethernet headers) + * IFF_TAP - TAP device + * + * IFF_NO_PI - Do not provide packet information + */ + ifr.ifr_flags = IFF_TUN | IFF_NO_PI; + + if (*dev) + strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1); + + if ((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) { + close(fd); + return err; + } + + strcpy(dev, ifr.ifr_name); + return fd; +} + +int tun_init_mbms(char *ifprefix, int id) +{ + int ret; + char ifname[64]; + + sprintf(ifname, "%s%d", ifprefix, id); + nas_sock_mbms_fd = tun_alloc(ifname); + + if (nas_sock_mbms_fd == -1) { + LOG_E(UTIL, "Error opening mbms socket %s (%d:%s)\n", ifname, errno, strerror(errno)); + exit(1); + } + + LOG_D(UTIL, "Opened socket %s with fd %d\n", ifname, nas_sock_mbms_fd); + ret = fcntl(nas_sock_mbms_fd, F_SETFL, O_NONBLOCK); + + if (ret == -1) { + LOG_E(UTIL, "Error fcntl (%d:%s)\n", errno, strerror(errno)); + return 0; + } + + struct sockaddr_nl nas_src_addr = {0}; + nas_src_addr.nl_family = AF_NETLINK; + nas_src_addr.nl_pid = 1; + nas_src_addr.nl_groups = 0; /* not in mcast groups */ + ret = bind(nas_sock_mbms_fd, (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr)); + + return 1; +} + +int tun_init(const char *ifprefix, int num_if, int id) +{ + int ret; + char ifname[64]; + + int begx = (id == 0) ? 0 : id - 1; + int endx = (id == 0) ? num_if : id; + for (int i = begx; i < endx; i++) { + sprintf(ifname, "%s%d", ifprefix, i + 1); + nas_sock_fd[i] = tun_alloc(ifname); + + if (nas_sock_fd[i] == -1) { + LOG_E(UTIL, "Error opening socket %s (%d:%s)\n", ifname, errno, strerror(errno)); + return 0; + } + + LOG_I(UTIL, "Opened socket %s with fd nas_sock_fd[%d]=%d\n", ifname, i, nas_sock_fd[i]); + ret = fcntl(nas_sock_fd[i], F_SETFL, O_NONBLOCK); + + if (ret == -1) { + LOG_E(UTIL, "Error fcntl (%d:%s)\n", errno, strerror(errno)); + + return 0; + } + } + + return 1; +} + /* * \brief set a genneric interface parameter * \param ifn the name of the interface to modify diff --git a/common/utils/tun_if.h b/common/utils/tun_if.h index 779d5e8102..45ae34983f 100644 --- a/common/utils/tun_if.h +++ b/common/utils/tun_if.h @@ -24,6 +24,12 @@ #include +/* TODO: doc */ +int tun_init(const char *ifprefix, int num_if, int id); + +/* TODO: doc */ +int tun_init_mbms(char *ifsuffix, int id); + /*! \fn int tun_config(char*, int, int) * \brief This function initializes the nasmesh interface using the basic values, * basic address, network mask and broadcast address, as the default configured diff --git a/doc/Doxyfile b/doc/Doxyfile index 0ea84a8d0f..5ae52a3c3a 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -2306,8 +2306,6 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/NR_ESTIMATION/nr_freq_equalization.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair1/SIMULATION/ETH_TRANSPORT/proto.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair1/SIMULATION/RF/adc.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair1/SIMULATION/RF/dac.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair1/SIMULATION/RF/rf.h \ diff --git a/executables/lte-enb.c b/executables/lte-enb.c index 8f50dfc63d..1a26644a43 100644 --- a/executables/lte-enb.c +++ b/executables/lte-enb.c @@ -85,7 +85,6 @@ #include "executables/lte-softmodem.h" #include "s1ap_eNB.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" #include "T.h" diff --git a/executables/lte-ru.c b/executables/lte-ru.c index 54747a9578..0ae8b86216 100644 --- a/executables/lte-ru.c +++ b/executables/lte-ru.c @@ -72,8 +72,6 @@ static int DEFRUTPCORES[] = {2,4,6,8}; #include "ENB_APP/enb_paramdef.h" #include "common/config/config_userapi.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" - #include "T.h" #include "executables/softmodem-common.h" diff --git a/executables/lte-softmodem.h b/executables/lte-softmodem.h index 6bc6d27f21..0f5559c7d3 100644 --- a/executables/lte-softmodem.h +++ b/executables/lte-softmodem.h @@ -26,7 +26,6 @@ #include "PHY/defs_eNB.h" #include "PHY/defs_UE.h" #include "s1ap_eNB.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" #include "executables/softmodem-common.h" diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c index 1f5fca077c..6efd26dfd7 100644 --- a/executables/nr-gnb.c +++ b/executables/nr-gnb.c @@ -75,7 +75,6 @@ #include "UTIL/OPT/opt.h" #include "gnb_paramdef.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" #include #include "T.h" diff --git a/executables/nr-ru.c b/executables/nr-ru.c index 24a1ecd719..aff3b5b8c2 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -65,7 +65,6 @@ static int DEFRUTPCORES[] = {-1,-1,-1,-1}; #include "GNB_APP/gnb_paramdef.h" #include "common/config/config_userapi.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" #include diff --git a/executables/nr-softmodem-common.h b/executables/nr-softmodem-common.h index c168a1ac0b..b50389e7d0 100644 --- a/executables/nr-softmodem-common.h +++ b/executables/nr-softmodem-common.h @@ -30,8 +30,6 @@ #include "PHY/types.h" #include -#include "SIMULATION/ETH_TRANSPORT/proto.h" - /* help strings definition for command line options, used in CMDLINE_XXX_DESC macros and printed when -h option is used */ #define CONFIG_HLP_RFCFGF "Configuration file for front-end (e.g. LMS7002M)\n" #define CONFIG_HLP_ULMAXE "set the eNodeB max ULSCH erros\n" diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index 3d3544dfc6..ac8a6c13ef 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -140,8 +140,6 @@ uint8_t nb_antenna_rx = 1; int otg_enabled; -#include - extern void reset_opp_meas(void); extern void print_opp_meas(void); diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h index 779f0049d8..204b16b109 100644 --- a/executables/nr-uesoftmodem.h +++ b/executables/nr-uesoftmodem.h @@ -3,9 +3,6 @@ #include #include #include "PHY/defs_nr_UE.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" - - #define CONFIG_HLP_IF_FREQ "IF frequency for RF, if needed\n" #define CONFIG_HLP_IF_FREQ_OFF "UL IF frequency offset for RF, if needed\n" diff --git a/openair1/SIMULATION/ETH_TRANSPORT/README.txt b/openair1/SIMULATION/ETH_TRANSPORT/README.txt deleted file mode 100644 index a1c1ed9562..0000000000 --- a/openair1/SIMULATION/ETH_TRANSPORT/README.txt +++ /dev/null @@ -1,25 +0,0 @@ -For reliable UDP multicast, the libpgm-dev should be installed on the machines, -otherwise the old multicast method using simply UDP will be used, resulting in -packet loss and unexpected behaviour of oaisim. - -To compile OAI with PGM: - -For Ubuntu 12.04 and earliers: - sudo apt-get install libpgm-dev - is sufficient - -For Ubuntu older than 12.04: - -wget http://openpgm.googlecode.com/files/libpgm-5.1.118.tar.gz -tar xvf libpgm-5.1.118.tar.gz -cd libpgm-5.1.118/openpgm/pgm -./configure --prefix=/usr -make -sudo make install - -We have to clean oaisim compilation and re-compile - - -When running OAI, the -D should be used to provide the NIC to bind. -Parameter can be either an interface name or an ip address (refer to this link -for more informations: http://code.google.com/p/openpgm/wiki/OpenPgmConceptsTransport) diff --git a/openair1/SIMULATION/ETH_TRANSPORT/extern.h b/openair1/SIMULATION/ETH_TRANSPORT/extern.h deleted file mode 100644 index ecd0d301d6..0000000000 --- a/openair1/SIMULATION/ETH_TRANSPORT/extern.h +++ /dev/null @@ -1,60 +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 extern.h - * \brief specifies the extern variables for phy emulation - * \author Navid Nikaein and Raymomd Knopp and Hicham Anouar - * \date 2011 - * \version 1.1 - * \company Eurecom - * \email: navid.nikaein@eurecom.fr - */ - -#ifndef __BYPASS_SESSION_LAYER_EXTERN_H__ -# define __BYPASS_SESSION_LAYER_EXTERN_H__ - -#include - - -extern unsigned char Emulation_status; -extern unsigned char emu_tx_status; -extern unsigned char emu_rx_status; -//extern unsigned int Master_list; -//extern unsigned short Master_id; -//extern unsigned int Is_primary_master; - -#if !defined(ENABLE_NEW_MULTICAST) -extern pthread_mutex_t Tx_mutex; -extern pthread_cond_t Tx_cond; -extern char Tx_mutex_var; -#endif - -extern rx_handler_t rx_handler; -extern tx_handler_t tx_handler; - -extern eNB_transport_info_t eNB_transport_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs]; -extern uint16_t eNB_transport_info_TB_index[NUMBER_OF_eNB_MAX][MAX_NUM_CCs]; - -extern UE_transport_info_t UE_transport_info[NUMBER_OF_UE_MAX][MAX_NUM_CCs]; - -extern UE_cntl ue_cntl_delay[NUMBER_OF_UE_MAX][MAX_NUM_CCs][2]; - -#endif diff --git a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c b/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c deleted file mode 100644 index 19c0fd8a19..0000000000 --- a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c +++ /dev/null @@ -1,121 +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 -#include -#include -#include -#include - -#include "common/platform_constants.h" -#include "common/utils/LOG/log.h" - -int nas_sock_fd[MAX_MOBILES_PER_ENB * 2]; // Allocated for both LTE UE and NR UE. -int nas_sock_mbms_fd; - -static int tun_alloc(char *dev) -{ - struct ifreq ifr; - int fd, err; - - if ((fd = open("/dev/net/tun", O_RDWR)) < 0) { - LOG_E(UTIL, "failed to open /dev/net/tun\n"); - return -1; - } - - memset(&ifr, 0, sizeof(ifr)); - /* Flags: IFF_TUN - TUN device (no Ethernet headers) - * IFF_TAP - TAP device - * - * IFF_NO_PI - Do not provide packet information - */ - ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - - if (*dev) - strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1); - - if ((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) { - close(fd); - return err; - } - - strcpy(dev, ifr.ifr_name); - return fd; -} - -int netlink_init_mbms_tun(char *ifprefix, int id) -{ - int ret; - char ifname[64]; - - sprintf(ifname, "%s%d", ifprefix, id); - nas_sock_mbms_fd = tun_alloc(ifname); - - if (nas_sock_mbms_fd == -1) { - LOG_E(UTIL, "Error opening mbms socket %s (%d:%s)\n", ifname, errno, strerror(errno)); - exit(1); - } - - LOG_D(UTIL, "Opened socket %s with fd %d\n", ifname, nas_sock_mbms_fd); - ret = fcntl(nas_sock_mbms_fd, F_SETFL, O_NONBLOCK); - - if (ret == -1) { - LOG_E(UTIL, "Error fcntl (%d:%s)\n", errno, strerror(errno)); - return 0; - } - - struct sockaddr_nl nas_src_addr = {0}; - nas_src_addr.nl_family = AF_NETLINK; - nas_src_addr.nl_pid = 1; - nas_src_addr.nl_groups = 0; /* not in mcast groups */ - ret = bind(nas_sock_mbms_fd, (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr)); - - return 1; -} - -int netlink_init_tun(const char *ifprefix, int num_if, int id) -{ - int ret; - char ifname[64]; - - int begx = (id == 0) ? 0 : id - 1; - int endx = (id == 0) ? num_if : id; - for (int i = begx; i < endx; i++) { - sprintf(ifname, "%s%d", ifprefix, i + 1); - nas_sock_fd[i] = tun_alloc(ifname); - - if (nas_sock_fd[i] == -1) { - LOG_E(UTIL, "Error opening socket %s (%d:%s)\n", ifname, errno, strerror(errno)); - return 0; - } - - LOG_I(UTIL, "Opened socket %s with fd nas_sock_fd[%d]=%d\n", ifname, i, nas_sock_fd[i]); - ret = fcntl(nas_sock_fd[i], F_SETFL, O_NONBLOCK); - - if (ret == -1) { - LOG_E(UTIL, "Error fcntl (%d:%s)\n", errno, strerror(errno)); - - return 0; - } - } - - return 1; -} diff --git a/openair1/SIMULATION/ETH_TRANSPORT/proto.h b/openair1/SIMULATION/ETH_TRANSPORT/proto.h deleted file mode 100644 index 647824cf05..0000000000 --- a/openair1/SIMULATION/ETH_TRANSPORT/proto.h +++ /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 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 proto.h -* \brief -* \author Navid Nikaein -* \date 2011 -* \version 1.0 -* \company Eurecom -* \email: navid.nikaein@eurecom.fr -*/ - -#ifndef EMU_PROTO_H_ -#define EMU_PROTO_H_ - -int netlink_init_tun(const char *ifprefix, int num_if, int id); -int netlink_init_mbms_tun(char *ifsuffix, int id); - -#endif /* EMU_PROTO_H_ */ diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c index 62f103add0..c63487e1ce 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c @@ -49,7 +49,6 @@ #include "common/ngran_types.h" #include "common/openairinterface5g_limits.h" #include "executables/lte-softmodem.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" #include "common/utils/tun_if.h" #include "intertask_interface.h" #include "openair3/S1AP/s1ap_eNB.h" @@ -2298,23 +2297,23 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask, int id) { if (UE_NAS_USE_TUN) { int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) ? MAX_MOBILES_PER_ENB : 1; - netlink_init_tun("oaitun_ue", num_if, id); + tun_init("oaitun_ue", num_if, id); if (IS_SOFTMODEM_NOS1) tun_config(1, "10.0.1.2", NULL, "oaitun_ue"); - netlink_init_mbms_tun("oaitun_uem", id + 1); + tun_init_mbms("oaitun_uem", id + 1); tun_config(1, "10.0.2.2", NULL, "oaitun_uem"); LOG_I(PDCP, "UE pdcp will use tun interface\n"); } else if (ENB_NAS_USE_TUN) { - netlink_init_tun("oaitun_enb", 1, 0); + tun_init("oaitun_enb", 1, 0); tun_config(1, "10.0.1.1", NULL, "oaitun_enb"); if (pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT) { - netlink_init_mbms_tun("oaitun_enm", 1); + tun_init_mbms("oaitun_enm", 1); tun_config(1, "10.0.2.1", NULL, "oaitun_enm"); LOG_I(PDCP, "ENB pdcp will use mbms tun interface\n"); } LOG_I(PDCP, "ENB pdcp will use tun interface\n"); } else if (pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT) { - netlink_init_mbms_tun("oaitun_enm", 0); + tun_init_mbms("oaitun_enm", 0); tun_config(1, "10.0.2.1", NULL, "oaitun_enm"); LOG_I(PDCP, "ENB pdcp will use mbms tun interface\n"); } diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index 71409833d3..d9efb52776 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -615,7 +615,7 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id) int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) ? MAX_MOBILES_PER_ENB : 1; - netlink_init_tun(ifprefix, num_if, id); + tun_init(ifprefix, num_if, id); if (IS_SOFTMODEM_NOS1) { const char *ip = !get_softmodem_params()->nsa ? "10.0.1.2" : "10.0.1.3"; tun_config(1, ip, NULL, ifprefix); @@ -625,7 +625,7 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id) start_pdcp_tun_ue(); } else if (ENB_NAS_USE_TUN) { char *ifprefix = get_softmodem_params()->nsa ? "oaitun_gnb" : "oaitun_enb"; - netlink_init_tun(ifprefix, 1, id); + tun_init(ifprefix, 1, id); tun_config(1, "10.0.1.1", NULL, ifprefix); LOG_I(PDCP, "ENB pdcp will use tun interface\n"); start_pdcp_tun_enb(); diff --git a/openair3/NAS/NR_UE/nr_nas_msg_sim.c b/openair3/NAS/NR_UE/nr_nas_msg_sim.c index 722a1ba1ec..ed0078b610 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg_sim.c +++ b/openair3/NAS/NR_UE/nr_nas_msg_sim.c @@ -48,7 +48,6 @@ #include "intertask_interface.h" #include "common/utils/tun_if.h" #include -#include #include "openair2/SDAP/nr_sdap/nr_sdap.h" #include "openair3/SECU/nas_stream_eia2.h" #include "openair3/UTILS/conversions.h"