refactor - removal of stack-gtpu interface, and use of socket manager interface instead

master
Francisco 4 years ago committed by Francisco Paisana
parent c24e382c19
commit 046633674a

@ -21,13 +21,6 @@ namespace srsenb {
class stack_interface_phy_lte;
class stack_interface_gtpu_lte
{
public:
virtual void add_gtpu_s1u_socket_handler(int fd) = 0;
virtual void add_gtpu_m1u_socket_handler(int fd) = 0;
};
} // namespace srsenb
#endif // SRSRAN_ENB_INTERFACES_H

@ -33,10 +33,7 @@
namespace srsenb {
class enb_stack_lte final : public enb_stack_base,
public stack_interface_phy_lte,
public stack_interface_gtpu_lte,
public srsran::thread
class enb_stack_lte final : public enb_stack_base, public stack_interface_phy_lte, public srsran::thread
{
public:
enb_stack_lte(srslog::sink& log_sink);
@ -96,9 +93,6 @@ public:
}
void tti_clock() override;
void add_gtpu_s1u_socket_handler(int fd) override;
void add_gtpu_m1u_socket_handler(int fd) override;
private:
static const int STACK_MAIN_THREAD_PRIO = 4;
// thread loop

@ -17,6 +17,7 @@
#include "srsran/adt/bounded_vector.h"
#include "srsran/adt/circular_map.h"
#include "srsran/common/buffer_pool.h"
#include "srsran/common/network_utils.h"
#include "srsran/common/task_scheduler.h"
#include "srsran/common/threads.h"
#include "srsran/interfaces/enb_gtpu_interfaces.h"
@ -128,16 +129,17 @@ using gtpu_tunnel = gtpu_tunnel_manager::tunnel;
class gtpu final : public gtpu_interface_rrc, public gtpu_interface_pdcp
{
public:
explicit gtpu(srsran::task_sched_handle task_sched_, srslog::basic_logger& logger);
explicit gtpu(srsran::task_sched_handle task_sched_,
srslog::basic_logger& logger,
srsran::socket_manager_itf* rx_socket_handler_);
~gtpu();
int init(std::string gtp_bind_addr_,
std::string mme_addr_,
std::string m1u_multiaddr_,
std::string m1u_if_addr_,
pdcp_interface_gtpu* pdcp_,
stack_interface_gtpu_lte* stack_,
bool enable_mbsfn = false);
int init(std::string gtp_bind_addr_,
std::string mme_addr_,
std::string m1u_multiaddr_,
std::string m1u_if_addr_,
pdcp_interface_gtpu* pdcp_,
bool enable_mbsfn = false);
void stop();
// gtpu_interface_rrc
@ -163,7 +165,8 @@ private:
void rem_tunnel(uint32_t teidin);
stack_interface_gtpu_lte* stack = nullptr;
srsran::socket_manager_itf* rx_socket_handler = nullptr;
srsran::task_queue_handle gtpu_queue;
bool enable_mbsfn = false;
std::string gtp_bind_addr;

@ -33,7 +33,7 @@ enb_stack_lte::enb_stack_lte(srslog::sink& log_sink) :
pdcp(&task_sched, pdcp_logger),
mac(&task_sched, mac_logger),
rlc(rlc_logger),
gtpu(&task_sched, gtpu_logger),
gtpu(&task_sched, gtpu_logger, &rx_sockets),
s1ap(&task_sched, s1ap_logger, &rx_sockets),
rrc(&task_sched),
mac_pcap(),
@ -132,7 +132,6 @@ int enb_stack_lte::init(const stack_args_t& args_, const rrc_cfg_t& rrc_cfg_)
args.embms.m1u_multiaddr,
args.embms.m1u_if_addr,
&pdcp,
this,
args.embms.enable)) {
stack_logger.error("Couldn't initialize GTPU");
return SRSRAN_ERROR;
@ -225,21 +224,4 @@ void enb_stack_lte::run_thread()
}
}
void enb_stack_lte::add_gtpu_s1u_socket_handler(int fd)
{
auto gtpu_s1u_handler = [this](srsran::unique_byte_buffer_t pdu, const sockaddr_in& from) {
gtpu.handle_gtpu_s1u_rx_packet(std::move(pdu), from);
};
rx_sockets.add_socket_handler(fd, srsran::make_sdu_handler(gtpu_logger, gtpu_task_queue, gtpu_s1u_handler));
}
void enb_stack_lte::add_gtpu_m1u_socket_handler(int fd)
{
auto gtpu_m1u_handler = [this](srsran::unique_byte_buffer_t pdu, const sockaddr_in& from) {
gtpu.handle_gtpu_m1u_rx_packet(std::move(pdu), from);
};
rx_sockets.add_socket_handler(fd, srsran::make_sdu_handler(gtpu_logger, gtpu_task_queue, gtpu_m1u_handler));
}
} // namespace srsenb

@ -287,9 +287,17 @@ void gtpu_tunnel_manager::setup_forwarding(uint32_t rx_teid, uint32_t tx_teid)
* GTPU class
*******************/
gtpu::gtpu(srsran::task_sched_handle task_sched_, srslog::basic_logger& logger) :
m1u(this), task_sched(task_sched_), logger(logger), tunnels(task_sched_, logger)
{}
gtpu::gtpu(srsran::task_sched_handle task_sched_,
srslog::basic_logger& logger,
srsran::socket_manager_itf* rx_socket_handler_) :
m1u(this),
task_sched(task_sched_),
logger(logger),
tunnels(task_sched_, logger),
rx_socket_handler(rx_socket_handler_)
{
gtpu_queue = task_sched.make_task_queue();
}
gtpu::~gtpu()
{
@ -301,13 +309,11 @@ int gtpu::init(std::string gtp_bind_addr_,
std::string m1u_multiaddr_,
std::string m1u_if_addr_,
srsenb::pdcp_interface_gtpu* pdcp_,
stack_interface_gtpu_lte* stack_,
bool enable_mbsfn_)
{
pdcp = pdcp_;
gtp_bind_addr = gtp_bind_addr_;
mme_addr = mme_addr_;
stack = stack_;
tunnels.init(pdcp);
@ -342,7 +348,11 @@ int gtpu::init(std::string gtp_bind_addr_,
return SRSRAN_ERROR;
}
stack->add_gtpu_s1u_socket_handler(fd);
// Assign a handler to rx S1U packets
auto rx_callback = [this](srsran::unique_byte_buffer_t pdu, const sockaddr_in& from) {
handle_gtpu_s1u_rx_packet(std::move(pdu), from);
};
rx_socket_handler->add_socket_handler(fd, srsran::make_sdu_handler(logger, gtpu_queue, rx_callback));
// Start MCH socket if enabled
enable_mbsfn = enable_mbsfn_;
@ -851,8 +861,12 @@ bool gtpu::m1u_handler::init(std::string m1u_multiaddr_, std::string m1u_if_addr
initiated = true;
lcid_counter = 1;
// Register socket in stack rx sockets thread
parent->stack->add_gtpu_m1u_socket_handler(m1u_sd);
// Assign a handler to rx M1U packets
auto rx_callback = [this](srsran::unique_byte_buffer_t pdu, const sockaddr_in& from) {
parent->handle_gtpu_m1u_rx_packet(std::move(pdu), from);
};
parent->rx_socket_handler->add_socket_handler(m1u_sd,
srsran::make_sdu_handler(logger, parent->gtpu_queue, rx_callback));
return true;
}

@ -25,14 +25,6 @@ namespace srsenb {
static const size_t PDU_HEADER_SIZE = 20;
class stack_tester : public stack_interface_gtpu_lte
{
public:
int s1u_fd = -1;
void add_gtpu_s1u_socket_handler(int fd) { s1u_fd = fd; }
void add_gtpu_m1u_socket_handler(int fd) {}
};
class pdcp_tester : public pdcp_dummy
{
public:
@ -67,7 +59,35 @@ public:
uint32_t last_lcid = 0;
};
int GTPU_PORT = 2152;
struct dummy_socket_manager : public srsran::socket_manager_itf {
dummy_socket_manager() : srsran::socket_manager_itf(srslog::fetch_basic_logger("TEST")) {}
/// Register (fd, callback). callback is called within socket thread when fd has data.
bool add_socket_handler(int fd, recv_callback_t handler) final
{
if (s1u_fd > 0) {
return false;
}
s1u_fd = fd;
callback = std::move(handler);
return true;
}
/// remove registered socket fd
bool remove_socket(int fd) final
{
if (s1u_fd < 0) {
return false;
}
s1u_fd = -1;
return true;
}
int s1u_fd;
recv_callback_t callback;
};
const int GTPU_PORT = 2152;
srsran::unique_byte_buffer_t encode_ipv4_packet(srsran::span<uint8_t> data,
uint32_t teid,
@ -209,11 +229,11 @@ int test_gtpu_direct_tunneling(tunnel_test_event event)
srslog::basic_logger& logger2 = srslog::fetch_basic_logger("GTPU2");
logger2.set_hex_dump_max_size(2048);
srsran::task_scheduler task_sched;
srsenb::gtpu senb_gtpu(&task_sched, logger1), tenb_gtpu(&task_sched, logger2);
stack_tester senb_stack, tenb_stack;
pdcp_tester senb_pdcp, tenb_pdcp;
senb_gtpu.init(senb_addr_str, sgw_addr_str, "", "", &senb_pdcp, &senb_stack, false);
tenb_gtpu.init(tenb_addr_str, sgw_addr_str, "", "", &tenb_pdcp, &tenb_stack, false);
dummy_socket_manager senb_rx_sockets, tenb_rx_sockets;
srsenb::gtpu senb_gtpu(&task_sched, logger1, &senb_rx_sockets), tenb_gtpu(&task_sched, logger2, &tenb_rx_sockets);
pdcp_tester senb_pdcp, tenb_pdcp;
senb_gtpu.init(senb_addr_str, sgw_addr_str, "", "", &senb_pdcp, false);
tenb_gtpu.init(tenb_addr_str, sgw_addr_str, "", "", &tenb_pdcp, false);
// create tunnels MME-SeNB and MME-TeNB
uint32_t senb_teid_in = senb_gtpu.add_bearer(rnti, drb1, sgw_addr, sgw_teidout1).value();
@ -244,9 +264,9 @@ int test_gtpu_direct_tunneling(tunnel_test_event event)
srsran::span<uint8_t> pdu_view{};
// TEST: GTPU buffers incoming PDCP buffered SNs until the TEID is explicitly activated
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_stack.s1u_fd), senb_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_rx_sockets.s1u_fd), senb_sockaddr);
TESTASSERT(tenb_pdcp.last_sdu == nullptr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_stack.s1u_fd), senb_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_rx_sockets.s1u_fd), senb_sockaddr);
TESTASSERT(tenb_pdcp.last_sdu == nullptr);
tenb_gtpu.set_tunnel_status(dl_tenb_teid_in, true);
pdu_view = srsran::make_span(tenb_pdcp.last_sdu);
@ -257,7 +277,7 @@ int test_gtpu_direct_tunneling(tunnel_test_event event)
// TEST: verify that PDCP buffered SNs have been forwarded through SeNB->TeNB tunnel
for (size_t sn = 8; sn < 10; ++sn) {
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_stack.s1u_fd), senb_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_rx_sockets.s1u_fd), senb_sockaddr);
pdu_view = srsran::make_span(tenb_pdcp.last_sdu);
TESTASSERT(std::count(pdu_view.begin() + PDU_HEADER_SIZE, pdu_view.end(), sn) == 10);
TESTASSERT(tenb_pdcp.last_rnti == rnti2);
@ -270,7 +290,7 @@ int test_gtpu_direct_tunneling(tunnel_test_event event)
pdu = encode_gtpu_packet(data_vec, senb_teid_in, sgw_sockaddr, senb_sockaddr);
encoded_data.assign(pdu->msg + 8u, pdu->msg + pdu->N_bytes);
senb_gtpu.handle_gtpu_s1u_rx_packet(std::move(pdu), sgw_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_stack.s1u_fd), senb_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_rx_sockets.s1u_fd), senb_sockaddr);
pdu_view = srsran::make_span(tenb_pdcp.last_sdu);
TESTASSERT(pdu_view.size() == encoded_data.size() and
std::equal(pdu_view.begin(), pdu_view.end(), encoded_data.begin()));
@ -292,7 +312,7 @@ int test_gtpu_direct_tunneling(tunnel_test_event event)
pdu = encode_gtpu_packet(data_vec, senb_teid_in, sgw_sockaddr, senb_sockaddr);
encoded_data.assign(pdu->msg + 8u, pdu->msg + pdu->N_bytes);
senb_gtpu.handle_gtpu_s1u_rx_packet(std::move(pdu), sgw_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_stack.s1u_fd), senb_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_rx_sockets.s1u_fd), senb_sockaddr);
TESTASSERT(tenb_pdcp.last_sdu->N_bytes == encoded_data.size() and
memcmp(tenb_pdcp.last_sdu->msg, encoded_data.data(), encoded_data.size()) == 0);
tenb_pdcp.clear();
@ -307,7 +327,7 @@ int test_gtpu_direct_tunneling(tunnel_test_event event)
// TEST: EndMarker is forwarded via MME->SeNB->TeNB, and TeNB buffered PDUs are flushed
pdu = encode_end_marker(senb_teid_in);
senb_gtpu.handle_gtpu_s1u_rx_packet(std::move(pdu), sgw_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_stack.s1u_fd), senb_sockaddr);
tenb_gtpu.handle_gtpu_s1u_rx_packet(read_socket(tenb_rx_sockets.s1u_fd), senb_sockaddr);
}
srsran::span<uint8_t> encoded_data2{tenb_pdcp.last_sdu->msg + 20u, tenb_pdcp.last_sdu->msg + 30u};
TESTASSERT(std::all_of(encoded_data2.begin(), encoded_data2.end(), [N_pdus](uint8_t b) { return b == N_pdus - 1; }));

Loading…
Cancel
Save