From 3cddad79ccf98ab8139b0c517e2c1e3d5a585812 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 5 Oct 2018 10:12:31 +0100 Subject: [PATCH] Adding ability to configure names of TUN interfaces. (#277) * added config option for tun dev names vs fixed names added config option for M1-U interface addr * Added options to sgi_mb tun name. * Added some comments to mbms.conf.example * Added some comments to example configs to explain the new values. --- srsepc/epc.conf.example | 5 ++++- srsepc/hdr/mbms-gw/mbms-gw.h | 1 + srsepc/hdr/spgw/spgw.h | 1 + srsepc/mbms.conf.example | 9 +++++++-- srsepc/src/main.cc | 3 +++ srsepc/src/mbms-gw/main.cc | 3 +++ srsepc/src/mbms-gw/mbms-gw.cc | 20 ++++++++++---------- srsepc/src/spgw/spgw.cc | 3 +-- srsue/hdr/ue_base.h | 1 + srsue/hdr/upper/gw.h | 2 ++ srsue/src/main.cc | 4 ++++ srsue/src/ue.cc | 1 + srsue/src/upper/gw.cc | 10 +++++++--- srsue/ue.conf.example | 2 ++ 14 files changed, 47 insertions(+), 18 deletions(-) diff --git a/srsepc/epc.conf.example b/srsepc/epc.conf.example index 6d857f78a..12562f1f0 100644 --- a/srsepc/epc.conf.example +++ b/srsepc/epc.conf.example @@ -40,13 +40,16 @@ db_file = user_db.csv ##################################################################### # SP-GW configuration # -# gtpu_bind_addr: GTP-U bind adress. +# gtpu_bind_addr: GTP-U bind address. +# sgi_if_addr: SGi TUN interface IP address. +# sgi_if_name: SGi TUN interface name. # ##################################################################### [spgw] gtpu_bind_addr = 127.0.1.100 sgi_if_addr = 172.16.0.1 +sgi_if_name = srs_spgw_sgi #################################################################### # PCAP configuration diff --git a/srsepc/hdr/mbms-gw/mbms-gw.h b/srsepc/hdr/mbms-gw/mbms-gw.h index ba1641c27..58bfcc277 100644 --- a/srsepc/hdr/mbms-gw/mbms-gw.h +++ b/srsepc/hdr/mbms-gw/mbms-gw.h @@ -48,6 +48,7 @@ const uint16_t GTPU_RX_PORT = 2152; typedef struct { std::string name; + std::string sgi_mb_if_name; std::string sgi_mb_if_addr; std::string sgi_mb_if_mask; std::string m1u_multi_addr; diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 98ad59403..3222f5120 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -50,6 +50,7 @@ const uint16_t GTPU_RX_PORT = 2152; typedef struct { std::string gtpu_bind_addr; std::string sgi_if_addr; + std::string sgi_if_name; } spgw_args_t; diff --git a/srsepc/mbms.conf.example b/srsepc/mbms.conf.example index 3c0a03696..19993e1fa 100644 --- a/srsepc/mbms.conf.example +++ b/srsepc/mbms.conf.example @@ -1,17 +1,22 @@ ##################################################################### -# srsEPC configuration file +# srsMBMS configuration file ##################################################################### ##################################################################### # MBMS-GW configuration # # name: MBMS-GW name +# sgi_mb_if_name: SGi-mb TUN interface name # sgi_mb_if_addr: SGi-mb interface IP address -# m1u_addr: Multicast group for eNBs (FIXME this should be setup with M2/M3) +# sgi_mb_if_mask: SGi-mb interface IP mask +# m1u_multi_addr: Multicast group for eNBs (FIXME this should be setup with M2/M3) +# m1u_multi_if: IP of local interface for multicast traffic +# m1u_multi_ttl: TTL for M1-U multicast traffic # ##################################################################### [mbms_gw] name = srsmbmsgw01 +sgi_mb_if_name = sgi_mb sgi_mb_if_addr = 172.16.0.254 sgi_mb_if_mask = 255.255.255.255 m1u_multi_addr = 239.255.0.1 diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 984f81dd6..6131c4457 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -87,6 +87,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { string mme_apn; string spgw_bind_addr; string sgi_if_addr; + string sgi_if_name; string dns_addr; string hss_db_file; string hss_auth_algo; @@ -116,6 +117,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { ("hss.auth_algo", bpo::value(&hss_auth_algo)->default_value("milenage"), "HSS uthentication algorithm.") ("spgw.gtpu_bind_addr", bpo::value(&spgw_bind_addr)->default_value("127.0.0.1"), "IP address of SP-GW for the S1-U connection") ("spgw.sgi_if_addr", bpo::value(&sgi_if_addr)->default_value("176.16.0.1"), "IP address of TUN interface for the SGi connection") + ("spgw.sgi_if_name", bpo::value(&sgi_if_name)->default_value("srs_spgw_sgi"), "Name of TUN interface for the SGi connection") ("pcap.enable", bpo::value(&args->mme_args.s1ap_args.pcap_enable)->default_value(false), "Enable S1AP PCAP") ("pcap.filename", bpo::value(&args->mme_args.s1ap_args.pcap_filename)->default_value("/tmp/epc.pcap"), "PCAP filename") @@ -219,6 +221,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { args->mme_args.s1ap_args.mme_apn = mme_apn; args->spgw_args.gtpu_bind_addr = spgw_bind_addr; args->spgw_args.sgi_if_addr = sgi_if_addr; + args->spgw_args.sgi_if_name = sgi_if_name; args->hss_args.db_file = hss_db_file; args->hss_args.auth_algo = hss_auth_algo; diff --git a/srsepc/src/mbms-gw/main.cc b/srsepc/src/mbms-gw/main.cc index 64037c0ad..02d16d65d 100644 --- a/srsepc/src/mbms-gw/main.cc +++ b/srsepc/src/mbms-gw/main.cc @@ -82,6 +82,7 @@ void parse_args(all_args_t *args, int argc, char* argv[]) { string mbms_gw_name; + string mbms_gw_sgi_mb_if_name; string mbms_gw_sgi_mb_if_addr; string mbms_gw_sgi_mb_if_mask; string mbms_gw_m1u_multi_addr; @@ -101,6 +102,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { common.add_options() ("mbms_gw.name", bpo::value(&mbms_gw_name)->default_value("srsmbmsgw01"), "MBMS-GW Name") + ("mbms_gw.sgi_mb_if_name", bpo::value(&mbms_gw_sgi_mb_if_name)->default_value("sgi_mb"), "SGi-mb TUN interface Address.") ("mbms_gw.sgi_mb_if_addr", bpo::value(&mbms_gw_sgi_mb_if_addr)->default_value("172.16.1.1"), "SGi-mb TUN interface Address.") ("mbms_gw.sgi_mb_if_mask", bpo::value(&mbms_gw_sgi_mb_if_mask)->default_value("255.255.255.255"), "SGi-mb TUN interface mask.") ("mbms_gw.m1u_multi_addr", bpo::value(&mbms_gw_m1u_multi_addr)->default_value("239.255.0.1"), "M1-u GTPu destination multicast address.") @@ -156,6 +158,7 @@ parse_args(all_args_t *args, int argc, char* argv[]) { bpo::notify(vm); args->mbms_gw_args.name = mbms_gw_name; + args->mbms_gw_args.sgi_mb_if_name = mbms_gw_sgi_mb_if_name; args->mbms_gw_args.sgi_mb_if_addr = mbms_gw_sgi_mb_if_addr; args->mbms_gw_args.sgi_mb_if_mask = mbms_gw_sgi_mb_if_mask; args->mbms_gw_args.m1u_multi_addr = mbms_gw_m1u_multi_addr; diff --git a/srsepc/src/mbms-gw/mbms-gw.cc b/srsepc/src/mbms-gw/mbms-gw.cc index eed2f5b95..bec61596b 100644 --- a/srsepc/src/mbms-gw/mbms-gw.cc +++ b/srsepc/src/mbms-gw/mbms-gw.cc @@ -126,7 +126,6 @@ mbms_gw::stop() srslte::error_t mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args) { - char dev[IFNAMSIZ] = "sgi_mb"; struct ifreq ifr; if(m_sgi_mb_up) @@ -138,22 +137,22 @@ mbms_gw::init_sgi_mb_if(mbms_gw_args_t *args) // Construct the TUN device m_sgi_mb_if = open("/dev/net/tun", O_RDWR); m_mbms_gw_log->info("TUN file descriptor = %d\n", m_sgi_mb_if); - if(m_sgi_mb_if < 0) - { + if (m_sgi_mb_if < 0) { m_mbms_gw_log->error("Failed to open TUN device: %s\n", strerror(errno)); return(srslte::ERROR_CANT_START); } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ-1); + strncpy(ifr.ifr_ifrn.ifrn_name, args->sgi_mb_if_name.c_str(), std::min(args->sgi_mb_if_name.length(), (size_t)IFNAMSIZ-1) ); ifr.ifr_ifrn.ifrn_name[IFNAMSIZ-1]='\0'; - if(ioctl(m_sgi_mb_if, TUNSETIFF, &ifr) < 0) - { - m_mbms_gw_log->error("Failed to set TUN device name: %s\n", strerror(errno)); - close(m_sgi_mb_if); - return(srslte::ERROR_CANT_START); + if (ioctl(m_sgi_mb_if, TUNSETIFF, &ifr) < 0) { + m_mbms_gw_log->error("Failed to set TUN device name: %s\n", strerror(errno)); + close(m_sgi_mb_if); + return(srslte::ERROR_CANT_START); + } else { + m_mbms_gw_log->debug("Set TUN device name: %s\n", args->sgi_mb_if_name.c_str()); } // Bring up the interface @@ -236,7 +235,8 @@ mbms_gw::init_m1_u(mbms_gw_args_t *args) struct in_addr local_if; local_if.s_addr = inet_addr(args->m1u_multi_if.c_str()); if(setsockopt(m_m1u, IPPROTO_IP, IP_MULTICAST_IF, (char*)&local_if, sizeof(struct in_addr))<0){ - perror("Error setting multicast interface.\n"); + m_mbms_gw_log->error("Error %s setting multicast interface %s.\n", strerror(errno), args->m1u_multi_if.c_str()); + return srslte::ERROR_CANT_START; } else { printf("Multicast interface specified. Address: %s\n", args->m1u_multi_if.c_str()); } diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 0a867d51c..ed706ba85 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -157,7 +157,6 @@ spgw::stop() srslte::error_t spgw::init_sgi_if(spgw_args_t *args) { - char dev[IFNAMSIZ] = "srs_spgw_sgi"; struct ifreq ifr; if(m_sgi_up) @@ -177,7 +176,7 @@ spgw::init_sgi_if(spgw_args_t *args) memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ-1); + strncpy(ifr.ifr_ifrn.ifrn_name, args->sgi_if_name.c_str(), std::min(args->sgi_if_name.length(), (size_t)(IFNAMSIZ-1))); ifr.ifr_ifrn.ifrn_name[IFNAMSIZ-1]='\0'; if(ioctl(m_sgi_if, TUNSETIFF, &ifr) < 0) diff --git a/srsue/hdr/ue_base.h b/srsue/hdr/ue_base.h index 0f362160a..af487a406 100644 --- a/srsue/hdr/ue_base.h +++ b/srsue/hdr/ue_base.h @@ -111,6 +111,7 @@ typedef struct { typedef struct { std::string ip_netmask; + std::string ip_devname; phy_args_t phy; float metrics_period_secs; bool pregenerate_signals; diff --git a/srsue/hdr/upper/gw.h b/srsue/hdr/upper/gw.h index 46059b517..ed3ae4fbb 100644 --- a/srsue/hdr/upper/gw.h +++ b/srsue/hdr/upper/gw.h @@ -52,6 +52,7 @@ public: void get_metrics(gw_metrics_t &m); void set_netmask(std::string netmask); + void set_tundevname(const std::string & devname); // PDCP interface void write_pdu(uint32_t lcid, srslte::byte_buffer_t *pdu); @@ -67,6 +68,7 @@ private: bool default_netmask; std::string netmask; + std::string tundevname; static const int GW_THREAD_PRIO = 7; diff --git a/srsue/src/main.cc b/srsue/src/main.cc index a79fbd710..861c1ded5 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -142,6 +142,10 @@ void parse_args(all_args_t *args, int argc, char *argv[]) { bpo::value(&args->expert.ip_netmask)->default_value("255.255.255.0"), "Netmask of the tun_srsue device") + ("expert.ip_devname", + bpo::value(&args->expert.ip_devname)->default_value("tun_srsue"), + "Name of the tun_srsue device") + ("expert.mbms_service", bpo::value(&args->expert.mbms_service)->default_value(-1), "automatically starts an mbms service of the number given") diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index 2a6b05425..882f29f1d 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -225,6 +225,7 @@ bool ue::init(all_args_t *args_) { nas.init(usim, &rrc, &gw, &nas_log, nas_cfg); gw.init(&pdcp, &nas, &gw_log, 3 /* RB_ID_DRB1 */); gw.set_netmask(args->expert.ip_netmask); + gw.set_tundevname(args->expert.ip_devname); // Get current band from provided EARFCN args->rrc.supported_bands[0] = srslte_band_get_band(args->rf.dl_earfcn); diff --git a/srsue/src/upper/gw.cc b/srsue/src/upper/gw.cc index e78bd70bb..62d1e84a8 100644 --- a/srsue/src/upper/gw.cc +++ b/srsue/src/upper/gw.cc @@ -45,6 +45,7 @@ gw::gw() { current_ip_addr = 0; default_netmask = true; + tundevname = ""; } void gw::init(pdcp_interface_gw *pdcp_, nas_interface_gw *nas_, srslte::log *gw_log_, srslte::srslte_gw_config_t cfg_) @@ -125,6 +126,11 @@ void gw::set_netmask(std::string netmask) this->netmask = netmask; } +void gw::set_tundevname(const std::string & devname) +{ + tundevname = devname; +} + /******************************************************************************* PDCP interface @@ -242,8 +248,6 @@ srslte::error_t gw::init_if(char *err_str) return(srslte::ERROR_ALREADY_STARTED); } - char dev[IFNAMSIZ] = "tun_srsue"; - // Construct the TUN device tun_fd = open("/dev/net/tun", O_RDWR); gw_log->info("TUN file descriptor = %d\n", tun_fd); @@ -255,7 +259,7 @@ srslte::error_t gw::init_if(char *err_str) } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ-1); + strncpy(ifr.ifr_ifrn.ifrn_name, tundevname.c_str(), std::min(tundevname.length(), (size_t)(IFNAMSIZ-1))); ifr.ifr_ifrn.ifrn_name[IFNAMSIZ-1] = 0; if(0 > ioctl(tun_fd, TUNSETIFF, &ifr)) { diff --git a/srsue/ue.conf.example b/srsue/ue.conf.example index d2bc4bb12..1209fe89d 100644 --- a/srsue/ue.conf.example +++ b/srsue/ue.conf.example @@ -137,6 +137,7 @@ enable = false # Expert configuration options # # ip_netmask: Netmask of the tun_srsue device. Default: 255.255.255.0 +# ip_devname: Nanme of the tun_srsue device. Default: tun_srsue # rssi_sensor_enabled: Enable or disable RF frontend RSSI sensor. Required for RSRP metrics but # can cause UHD instability for long-duration testing. Default true. # rx_gain_offset: RX Gain offset to add to rx_gain to calibrate RSRP readings @@ -209,6 +210,7 @@ enable = false ##################################################################### [expert] #ip_netmask = 255.255.255.0 +#ip_devname = tun_srsue #mbms_service = -1 #rssi_sensor_enabled = false #rx_gain_offset = 62