Skip to content

Commit e21b0c5

Browse files
frankistcodebot
authored andcommitted
e1ap: implement E1 SCTP Gateway unit test
1 parent 567437d commit e21b0c5

File tree

7 files changed

+387
-1
lines changed

7 files changed

+387
-1
lines changed

include/srsran/e1ap/gateways/e1_local_connector_factory.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace srsran {
1717

1818
class dlt_pcap;
19+
class io_broker;
1920

2021
class e1_local_connector : public srs_cu_up::e1_connection_client, public srs_cu_cp::e1_connection_server
2122
{};
@@ -29,4 +30,16 @@ struct e1_local_connector_config {
2930
/// E1AP PDUs or any socket send/recv.
3031
std::unique_ptr<e1_local_connector> create_e1_local_connector(const e1_local_connector_config& cfg);
3132

33+
struct e1_local_sctp_connector_config {
34+
/// PCAP writer for the E1AP messages.
35+
dlt_pcap& pcap;
36+
/// IO broker to handle the SCTP Rx data and notifications.
37+
io_broker& broker;
38+
};
39+
40+
/// Creates an E1 local connector using an SCTP socket as channel.
41+
///
42+
/// Note: This class is useful for testing.
43+
std::unique_ptr<e1_local_connector> create_e1_local_connector(const e1_local_sctp_connector_config& cfg);
44+
3245
} // namespace srsran

include/srsran/gateways/sctp_network_gateway.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace srsran {
1818

1919
constexpr uint16_t NGAP_PPID = 60; // NGAP PPID, see TS 38.412, section 7.
2020
constexpr uint16_t F1AP_PPID = 62; // F1AP PPID, see TS 38.472, section 7.
21+
constexpr uint16_t E1AP_PPID = 64; // E1AP PPID, see TS 37.482, section 7.
2122
constexpr uint16_t E2_CP_PPID = 70; // E2-CP PPID assigned by IANA
2223
constexpr uint16_t E2_UP_PPID = 71; // E2-UP PPID assigned by IANA
2324
constexpr uint16_t E2_DU_PPID = 72; // E2-DU PPID assigned by IANA

lib/e1ap/gateways/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ add_library(srsran_e1_gateway
1010
e1_local_connector_factory.cpp
1111
e1_network_client_factory.cpp
1212
e1_network_server_factory.cpp)
13-
target_link_libraries(srsran_e1_gateway srsran_support srsran_e1ap_common e1ap_asn1)
13+
target_link_libraries(srsran_e1_gateway srsran_support srsran_e1ap_common e1ap_asn1 srsran_pcap)

lib/e1ap/gateways/e1_local_connector_factory.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "srsran/e1ap/gateways/e1_local_connector_factory.h"
1212
#include "srsran/cu_cp/cu_cp_e1_handler.h"
1313
#include "srsran/e1ap/common/e1ap_message.h"
14+
#include "srsran/e1ap/gateways/e1_network_client_factory.h"
15+
#include "srsran/e1ap/gateways/e1_network_server_factory.h"
1416
#include "srsran/pcap/dlt_pcap.h"
1517

1618
using namespace srsran;
@@ -87,9 +89,64 @@ class e1_local_connector_impl final : public e1_local_connector
8789
srs_cu_cp::cu_cp_e1_handler* cu_cp_e1_mng = nullptr;
8890
};
8991

92+
/// Implementation of a CU-UP and CU-CP E1 SCTP-based gateway for the case that the DU and CU-CP are co-located.
93+
///
94+
/// Note: This class should only be used for testing purposes.
95+
class e1_sctp_connector_impl final : public e1_local_connector
96+
{
97+
public:
98+
e1_sctp_connector_impl(const e1_local_sctp_connector_config& cfg) : broker(cfg.broker), pcap_writer(cfg.pcap)
99+
{
100+
// Create SCTP server.
101+
sctp_network_gateway_config sctp;
102+
sctp.if_name = "E1";
103+
sctp.ppid = E1AP_PPID;
104+
sctp.bind_address = "127.0.0.1";
105+
// Use any bind port available.
106+
sctp.bind_port = 0;
107+
server = create_e1_gateway_server(e1_cu_sctp_gateway_config{sctp, broker, pcap_writer});
108+
}
109+
110+
void attach_cu_cp(srs_cu_cp::cu_cp_e1_handler& cu_e1_handler_) override
111+
{
112+
server->attach_cu_cp(cu_e1_handler_);
113+
114+
// Create SCTP client.
115+
sctp_network_connector_config sctp_client;
116+
sctp_client.if_name = "E1";
117+
sctp_client.dest_name = "CU-CP";
118+
sctp_client.connect_address = "127.0.0.1";
119+
sctp_client.connect_port = server->get_listen_port().value();
120+
sctp_client.ppid = E1AP_PPID;
121+
// Note: We only need to save the PCAPs in one side of the connection.
122+
client = create_e1_gateway_client(e1_du_sctp_gateway_config{sctp_client, broker, *null_pcap_writer});
123+
}
124+
125+
std::optional<uint16_t> get_listen_port() const override { return server->get_listen_port(); }
126+
127+
std::unique_ptr<e1ap_message_notifier>
128+
handle_cu_up_connection_request(std::unique_ptr<e1ap_message_notifier> cu_up_rx_pdu_notifier) override
129+
{
130+
// Connect client to server automatically.
131+
return client->handle_cu_up_connection_request(std::move(cu_up_rx_pdu_notifier));
132+
}
133+
134+
private:
135+
io_broker& broker;
136+
dlt_pcap& pcap_writer;
137+
std::unique_ptr<dlt_pcap> null_pcap_writer = create_null_dlt_pcap();
138+
std::unique_ptr<srs_cu_cp::e1_connection_server> server;
139+
std::unique_ptr<srs_cu_up::e1_connection_client> client;
140+
};
141+
90142
} // namespace
91143

92144
std::unique_ptr<e1_local_connector> srsran::create_e1_local_connector(const e1_local_connector_config& cfg)
93145
{
94146
return std::make_unique<e1_local_connector_impl>(cfg);
95147
}
148+
149+
std::unique_ptr<e1_local_connector> srsran::create_e1_local_connector(const e1_local_sctp_connector_config& cfg)
150+
{
151+
return std::make_unique<e1_sctp_connector_impl>(cfg);
152+
}

tests/unittests/e1ap/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ include_directories(../../..)
1313
add_subdirectory(common)
1414
add_subdirectory(cu_cp)
1515
add_subdirectory(cu_up)
16+
add_subdirectory(gateways)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright 2021-2024 Software Radio Systems Limited
3+
#
4+
# By using this file, you agree to the terms and conditions set
5+
# forth in the LICENSE file which can be found at the top level of
6+
# the distribution.
7+
#
8+
9+
add_executable(e1_gateway_test e1_gateway_test.cpp)
10+
target_link_libraries(e1_gateway_test
11+
srsran_e1_gateway
12+
srsran_gateway
13+
e1ap_test_helpers
14+
srsran_e1ap_common
15+
srsran_support
16+
srsran_network
17+
srslog
18+
e1ap_asn1
19+
gtest
20+
gtest_main)
21+
add_test(e1_gateway_test e1_gateway_test)

0 commit comments

Comments
 (0)