From aae266e848467b85f5b1c49da1b55a5b24b7f484 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 11 Jun 2021 14:41:19 +0100 Subject: [PATCH] Added configuration option for S1AP SCTP bind port --- lib/include/srsran/common/network_utils.h | 2 +- lib/include/srsran/interfaces/enb_s1ap_interfaces.h | 1 + lib/src/common/network_utils.cc | 4 ++-- lib/test/common/network_utils_test.cc | 4 ++-- srsenb/enb.conf.example | 2 ++ srsenb/src/main.cc | 1 + srsenb/src/stack/ngap/ngap.cc | 2 +- srsenb/src/stack/s1ap/s1ap.cc | 2 +- 8 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/include/srsran/common/network_utils.h b/lib/include/srsran/common/network_utils.h index d897dc9fb..8f19dd5d2 100644 --- a/lib/include/srsran/common/network_utils.h +++ b/lib/include/srsran/common/network_utils.h @@ -86,7 +86,7 @@ protected: namespace net_utils { -bool sctp_init_client(unique_socket* socket, net_utils::socket_type socktype, const char* bind_addr_str); +bool sctp_init_client(unique_socket* socket, net_utils::socket_type socktype, const char* bind_addr_str, int bind_port); bool sctp_init_server(unique_socket* socket, net_utils::socket_type socktype, const char* bind_addr_str, int port); } // namespace net_utils diff --git a/lib/include/srsran/interfaces/enb_s1ap_interfaces.h b/lib/include/srsran/interfaces/enb_s1ap_interfaces.h index 6bb07f353..233857470 100644 --- a/lib/include/srsran/interfaces/enb_s1ap_interfaces.h +++ b/lib/include/srsran/interfaces/enb_s1ap_interfaces.h @@ -28,6 +28,7 @@ struct s1ap_args_t { std::string gtp_bind_addr; std::string gtp_advertise_addr; std::string s1c_bind_addr; + uint16_t s1c_bind_port; std::string enb_name; }; diff --git a/lib/src/common/network_utils.cc b/lib/src/common/network_utils.cc index 0ff7f26ad..bd21546c4 100644 --- a/lib/src/common/network_utils.cc +++ b/lib/src/common/network_utils.cc @@ -309,9 +309,9 @@ bool sctp_init_socket(unique_socket* socket, net_utils::socket_type socktype, co return true; } -bool sctp_init_client(unique_socket* socket, net_utils::socket_type socktype, const char* bind_addr_str) +bool sctp_init_client(unique_socket* socket, net_utils::socket_type socktype, const char* bind_addr_str, int bind_port) { - return sctp_init_socket(socket, socktype, bind_addr_str, 0); + return sctp_init_socket(socket, socktype, bind_addr_str, bind_port); } bool sctp_init_server(unique_socket* socket, net_utils::socket_type socktype, const char* bind_addr_str, int port) diff --git a/lib/test/common/network_utils_test.cc b/lib/test/common/network_utils_test.cc index 5701e1d89..3e36508fa 100644 --- a/lib/test/common/network_utils_test.cc +++ b/lib/test/common/network_utils_test.cc @@ -55,8 +55,8 @@ int test_socket_handler() TESTASSERT(sctp_init_server(&server_socket, socket_type::seqpacket, server_addr, server_port)); logger.info("Listening from fd=%d", server_socket.fd()); - TESTASSERT(sctp_init_client(&client_socket, socket_type::seqpacket, "127.0.0.1")); - TESTASSERT(sctp_init_client(&client_socket2, socket_type::seqpacket, "127.0.0.2")); + TESTASSERT(sctp_init_client(&client_socket, socket_type::seqpacket, "127.0.0.1", 0)); + TESTASSERT(sctp_init_client(&client_socket2, socket_type::seqpacket, "127.0.0.2", 0)); TESTASSERT(client_socket.connect_to(server_addr, server_port)); TESTASSERT(client_socket2.connect_to(server_addr, server_port)); diff --git a/srsenb/enb.conf.example b/srsenb/enb.conf.example index 36b3ee83e..4eacc23e1 100644 --- a/srsenb/enb.conf.example +++ b/srsenb/enb.conf.example @@ -12,6 +12,7 @@ # gtp_bind_addr: Local IP address to bind for GTP connection # gtp_advertise_addr: IP address of eNB to advertise for DL GTP-U Traffic # s1c_bind_addr: Local IP address to bind for S1AP connection +# s1c_bind_port: Source port for S1AP connection (0 means any) # n_prb: Number of Physical Resource Blocks (6,15,25,50,75,100) # tm: Transmission mode 1-4 (TM1 default) # nof_ports: Number of Tx ports (1 port default, set to 2 for TM2/3/4) @@ -24,6 +25,7 @@ mnc = 01 mme_addr = 127.0.1.100 gtp_bind_addr = 127.0.1.1 s1c_bind_addr = 127.0.1.1 +s1c_bind_port = 0 n_prb = 50 #tm = 4 #nof_ports = 2 diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index 1d9119457..3b264fe74 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -74,6 +74,7 @@ void parse_args(all_args_t* args, int argc, char* argv[]) ("enb.gtp_bind_addr", bpo::value(&args->stack.s1ap.gtp_bind_addr)->default_value("192.168.3.1"), "Local IP address to bind for GTP connection") ("enb.gtp_advertise_addr", bpo::value(&args->stack.s1ap.gtp_advertise_addr)->default_value(""), "IP address of eNB to advertise for DL GTP-U Traffic") ("enb.s1c_bind_addr", bpo::value(&args->stack.s1ap.s1c_bind_addr)->default_value("192.168.3.1"), "Local IP address to bind for S1AP connection") + ("enb.s1c_bind_port", bpo::value(&args->stack.s1ap.s1c_bind_port)->default_value(0), "Source port for S1AP connection (0 means any)") ("enb.n_prb", bpo::value(&args->enb.n_prb)->default_value(25), "Number of PRB") ("enb.nof_ports", bpo::value(&args->enb.nof_ports)->default_value(1), "Number of ports") ("enb.tm", bpo::value(&args->enb.transmission_mode)->default_value(1), "Transmission mode (1-8)") diff --git a/srsenb/src/stack/ngap/ngap.cc b/srsenb/src/stack/ngap/ngap.cc index 75fec27c6..8cbca6fee 100644 --- a/srsenb/src/stack/ngap/ngap.cc +++ b/srsenb/src/stack/ngap/ngap.cc @@ -505,7 +505,7 @@ bool ngap::connect_amf() logger.info("Connecting to AMF %s:%d", args.amf_addr.c_str(), int(AMF_PORT)); // Init SCTP socket and bind it - if (not sctp_init_client(&amf_socket, socket_type::seqpacket, args.ngc_bind_addr.c_str())) { + if (not sctp_init_client(&amf_socket, socket_type::seqpacket, args.ngc_bind_addr.c_str(), 0)) { return false; } logger.info("SCTP socket opened. fd=%d", amf_socket.fd()); diff --git a/srsenb/src/stack/s1ap/s1ap.cc b/srsenb/src/stack/s1ap/s1ap.cc index 82cd36707..9ad267ea4 100644 --- a/srsenb/src/stack/s1ap/s1ap.cc +++ b/srsenb/src/stack/s1ap/s1ap.cc @@ -476,7 +476,7 @@ bool s1ap::connect_mme() logger.info("Connecting to MME %s:%d", args.mme_addr.c_str(), int(MME_PORT)); // Init SCTP socket and bind it - if (not sctp_init_client(&mme_socket, socket_type::seqpacket, args.s1c_bind_addr.c_str())) { + if (not sctp_init_client(&mme_socket, socket_type::seqpacket, args.s1c_bind_addr.c_str(), args.s1c_bind_port)) { return false; } logger.info("SCTP socket opened. fd=%d", mme_socket.fd());