Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/include/srsran/common/network_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ class unique_socket
bool connect_to(const char* dest_addr_str, int dest_port, sockaddr_in* dest_sockaddr = nullptr);
bool start_listen();
bool reuse_addr();
bool nodelay(int enable);
bool sctp_subscribe_to_events();
bool sctp_set_rto_opts(int rto_max);
bool sctp_set_init_msg_opts(int max_init_attempts, int max_init_timeo);
int get_socket() const { return sockfd; };

protected:
sockaddr_in addr = {};
int sockfd = -1;
net_utils::protocol_type proto = net_utils::protocol_type::NONE;
sockaddr_in addr = {};
int sockfd = -1;
};

namespace net_utils {
Expand Down
1 change: 1 addition & 0 deletions lib/include/srsran/interfaces/enb_s1ap_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct s1ap_args_t {
int32_t max_s1_setup_retries;
uint32_t s1_connect_timer;
bool sctp_reuse_addr;
bool sctp_nodelay;
int32_t sctp_rto_max;
int32_t sctp_init_max_attempts;
int32_t sctp_max_init_timeo;
Expand Down
41 changes: 41 additions & 0 deletions lib/src/common/network_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,34 @@ bool reuse_addr(int fd)
return true;
}

bool tcp_nodelay(int fd, int enable)
{
if (fd < 0) {
srslog::fetch_basic_logger(LOGSERVICE).error("Trying set nodelay for a closed socket. Socket=%d", fd);
return false;
}
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(int)) < 0) {
srslog::fetch_basic_logger(LOGSERVICE).error("Failed to set TCP_NODELAY. Socket=%d", fd);
return false;
}
srslog::fetch_basic_logger(LOGSERVICE).debug("Successfully set TCP_NODELAY. Socket=%d", fd);
return true;
}

bool sctp_nodelay(int fd, int enable)
{
if (fd < 0) {
srslog::fetch_basic_logger(LOGSERVICE).error("Trying set nodelay for a closed socket. Socket=%d", fd);
return false;
}
if (setsockopt(fd, IPPROTO_SCTP, SCTP_NODELAY, &enable, sizeof(int)) < 0) {
srslog::fetch_basic_logger(LOGSERVICE).error("Failed to set SCTP_NODELAY. Socket=%d", fd);
return false;
}
srslog::fetch_basic_logger(LOGSERVICE).debug("Successfully set SCTP_NODELAY. Socket=%d", fd);
return true;
}

bool sctp_subscribe_to_events(int fd)
{
if (fd < 0) {
Expand Down Expand Up @@ -338,6 +366,7 @@ bool unique_socket::open_socket(net_utils::addr_family ip_type,
return false;
}
sockfd = net_utils::open_socket(ip_type, socket_type, protocol);
proto = protocol;
return is_open();
}

Expand Down Expand Up @@ -376,6 +405,18 @@ bool unique_socket::reuse_addr()
return net_utils::reuse_addr(sockfd);
}

bool unique_socket::nodelay(int enable)
{
switch (proto) {
case net_utils::protocol_type::SCTP:
return net_utils::sctp_nodelay(sockfd, enable);
case net_utils::protocol_type::TCP:
return net_utils::tcp_nodelay(sockfd, enable);
default:
return false;
}
}

bool unique_socket::sctp_subscribe_to_events()
{
return net_utils::sctp_subscribe_to_events(sockfd);
Expand Down
1 change: 1 addition & 0 deletions srsenb/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ void parse_args(all_args_t* args, int argc, char* argv[])
("expert.max_s1_setup_retries", bpo::value<int32_t>(&args->stack.s1ap.max_s1_setup_retries)->default_value(-1), "Max S1 setup retries")
("expert.s1_connect_timer", bpo::value<uint32_t>(&args->stack.s1ap.s1_connect_timer)->default_value(10), "Connection Retry Timer for S1 connection (seconds)")
("expert.sctp_reuse_addr", bpo::value<bool>(&args->stack.s1ap.sctp_reuse_addr)->default_value(false), "Use SO_REUSE_ADDR on S1-C interface.")
("expert.sctp_nodelay", bpo::value<bool>(&args->stack.s1ap.sctp_nodelay)->default_value(false), "Use SCTP_NODELAY on S1-C interface.")
("expert.sctp_rto_max", bpo::value<int32_t>(&args->stack.s1ap.sctp_rto_max)->default_value(6000), "SCTP maximum RTO.")
("expert.sctp_init_max_attempts", bpo::value<int32_t>(&args->stack.s1ap.sctp_init_max_attempts)->default_value(3), "Maximum SCTP init attempts.")
("expert.sctp_max_init_timeo)", bpo::value<int32_t>(&args->stack.s1ap.sctp_max_init_timeo)->default_value(5000), "Maximum SCTP init timeout.")
Expand Down
8 changes: 8 additions & 0 deletions srsenb/src/stack/s1ap/s1ap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ bool s1ap::connect_mme()
}
}

// Set SCTP_NODELAY if necessary
if (args.sctp_nodelay) {
if (not mme_socket.nodelay(1)) {
mme_socket.close();
return false;
}
}

// Subscribe to shutdown events
if (not mme_socket.sctp_subscribe_to_events()) {
mme_socket.close();
Expand Down