s1ap - extend s1ap unit test to setup a full ue connection and modify bearer

master
Francisco 4 years ago committed by Francisco Paisana
parent 90bba3b85e
commit a68c50a282

@ -1366,7 +1366,7 @@ bool s1ap::ue::send_erab_release_response(const std::vector<uint16_t>& erabs_suc
}
}
return s1ap_ptr->sctp_send_s1ap_pdu(tx_pdu, ctxt.rnti, "E_RABReleaseResponse");
return s1ap_ptr->sctp_send_s1ap_pdu(tx_pdu, ctxt.rnti, "E-RABReleaseResponse");
}
bool s1ap::ue::send_erab_modify_response(const std::vector<uint16_t>& erabs_successfully_modified,
@ -1407,7 +1407,7 @@ bool s1ap::ue::send_erab_modify_response(const std::vector<uint16_t>& erabs_succ
}
}
return s1ap_ptr->sctp_send_s1ap_pdu(tx_pdu, ctxt.rnti, "E_RABReleaseResponse");
return s1ap_ptr->sctp_send_s1ap_pdu(tx_pdu, ctxt.rnti, "E-RABModifyResponse");
}
bool s1ap::ue::send_erab_release_indication(const std::vector<uint16_t>& erabs_successfully_released)

@ -13,6 +13,7 @@
#ifndef SRSENB_DUMMY_CLASSES_H
#define SRSENB_DUMMY_CLASSES_H
#include "srsran/interfaces/enb_gtpu_interfaces.h"
#include "srsran/interfaces/enb_interfaces.h"
#include "srsran/interfaces/enb_mac_interfaces.h"
#include "srsran/interfaces/enb_pdcp_interfaces.h"
@ -145,7 +146,7 @@ public:
void complete_config(uint16_t rnti) override{};
};
class gtpu_dummy : public gtpu_interface_rrc
class gtpu_dummy : public srsenb::gtpu_interface_rrc
{
public:
srsran::expected<uint32_t>
@ -159,6 +160,40 @@ public:
void rem_user(uint16_t rnti) override {}
};
class rrc_dummy : public rrc_interface_s1ap
{
public:
void write_dl_info(uint16_t rnti, srsran::unique_byte_buffer_t sdu) override {}
void release_complete(uint16_t rnti) override {}
bool setup_ue_ctxt(uint16_t rnti, const asn1::s1ap::init_context_setup_request_s& msg) override { return true; }
bool modify_ue_ctxt(uint16_t rnti, const asn1::s1ap::ue_context_mod_request_s& msg) override { return true; }
bool setup_ue_erabs(uint16_t rnti, const asn1::s1ap::erab_setup_request_s& msg) override { return true; }
void modify_erabs(uint16_t rnti,
const asn1::s1ap::erab_modify_request_s& msg,
std::vector<uint16_t>* erabs_modified,
std::vector<uint16_t>* erabs_failed_to_modify) override
{}
bool release_erabs(uint32_t rnti) override { return true; }
void release_erabs(uint32_t rnti,
const asn1::s1ap::erab_release_cmd_s& msg,
std::vector<uint16_t>* erabs_released,
std::vector<uint16_t>* erabs_failed_to_release) override
{}
void add_paging_id(uint32_t ueid, const asn1::s1ap::ue_paging_id_c& ue_paging_id) override {}
void ho_preparation_complete(uint16_t rnti,
bool is_success,
const asn1::s1ap::ho_cmd_s& msg,
srsran::unique_byte_buffer_t container) override
{}
uint16_t
start_ho_ue_resource_alloc(const asn1::s1ap::ho_request_s& msg,
const asn1::s1ap::sourceenb_to_targetenb_transparent_container_s& container) override
{
return SRSRAN_INVALID_RNTI;
}
void set_erab_status(uint16_t rnti, const asn1::s1ap::bearers_subject_to_status_transfer_list_l& erabs) override {}
};
} // namespace srsenb
#endif // SRSENB_DUMMY_CLASSES_H

@ -25,6 +25,9 @@ target_link_libraries(rrc_meascfg_test test_helpers)
add_executable(gtpu_test gtpu_test.cc)
target_link_libraries(gtpu_test srsran_common s1ap_asn1 srsenb_upper srsran_upper ${SCTP_LIBRARIES})
add_executable(s1ap_test s1ap_test.cc)
target_link_libraries(s1ap_test srsran_common s1ap_asn1 srsenb_upper srsran_upper s1ap_asn1 ${SCTP_LIBRARIES})
add_test(rrc_mobility_test rrc_mobility_test -i ${CMAKE_CURRENT_SOURCE_DIR}/../..)
add_test(erab_setup_test erab_setup_test -i ${CMAKE_CURRENT_SOURCE_DIR}/../..)
add_test(rrc_meascfg_test rrc_meascfg_test -i ${CMAKE_CURRENT_SOURCE_DIR}/../..)

@ -12,6 +12,7 @@
#include "srsenb/hdr/stack/upper/s1ap.h"
#include "srsenb/test/common/dummy_classes.h"
#include "srsran/common/network_utils.h"
#include "srsran/common/test_common.h"
using namespace srsenb;
@ -23,13 +24,131 @@ public:
void remove_mme_socket(int fd) {}
};
struct mme_dummy {
mme_dummy(const char* addr_str_, int port_) : addr_str(addr_str_), port(port_)
{
srsran::net_utils::set_sockaddr(&mme_sockaddr, addr_str, port);
{
using namespace srsran::net_utils;
fd = open_socket(addr_family::ipv4, socket_type::seqpacket, protocol_type::SCTP);
TESTASSERT(fd > 0);
TESTASSERT(bind_addr(fd, mme_sockaddr));
}
srsran_assert(listen(fd, SOMAXCONN) == 0, "Failed to listen to incoming SCTP connections");
}
~mme_dummy()
{
if (fd > 0) {
close(fd);
}
}
srsran::unique_byte_buffer_t read_msg(sockaddr_in* sockfrom = nullptr)
{
srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer();
sockaddr_in from = {};
socklen_t fromlen = sizeof(from);
sctp_sndrcvinfo sri = {};
int flags = 0;
ssize_t n_recv = sctp_recvmsg(fd, pdu->msg, pdu->get_tailroom(), (struct sockaddr*)&from, &fromlen, &sri, &flags);
if (n_recv > 0) {
if (sockfrom != nullptr) {
*sockfrom = from;
}
pdu->N_bytes = n_recv;
}
return pdu;
}
const char* addr_str;
int port;
struct sockaddr_in mme_sockaddr = {};
int fd;
srsran::unique_byte_buffer_t last_sdu;
};
void run_s1_setup(s1ap& s1ap_obj, mme_dummy& mme)
{
asn1::s1ap::s1ap_pdu_c s1ap_pdu;
// eNB -> MME: S1 Setup Request
srsran::unique_byte_buffer_t sdu = mme.read_msg();
TESTASSERT(sdu->N_bytes > 0);
asn1::cbit_ref cbref(sdu->msg, sdu->N_bytes);
TESTASSERT(s1ap_pdu.unpack(cbref) == asn1::SRSASN_SUCCESS);
TESTASSERT(s1ap_pdu.type().value == asn1::s1ap::s1ap_pdu_c::types_opts::init_msg);
TESTASSERT(s1ap_pdu.init_msg().proc_code == ASN1_S1AP_ID_S1_SETUP);
// MME -> eNB: S1 Setup Response
sockaddr_in mme_addr = {};
sctp_sndrcvinfo rcvinfo = {};
int flags = 0;
uint8_t s1_setup_resp[] = {0x20, 0x11, 0x00, 0x25, 0x00, 0x00, 0x03, 0x00, 0x3d, 0x40, 0x0a, 0x03, 0x80, 0x73,
0x72, 0x73, 0x6d, 0x6d, 0x65, 0x30, 0x31, 0x00, 0x69, 0x00, 0x0b, 0x00, 0x00, 0x00,
0xf1, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x00, 0x57, 0x40, 0x01, 0xff};
memcpy(sdu->msg, s1_setup_resp, sizeof(s1_setup_resp));
sdu->N_bytes = sizeof(s1_setup_resp);
TESTASSERT(s1ap_obj.handle_mme_rx_msg(std::move(sdu), mme_addr, rcvinfo, flags));
}
void add_rnti(s1ap& s1ap_obj)
{
asn1::s1ap::s1ap_pdu_c s1ap_pdu;
// New UE
uint8_t nas_msg[] = {0x00, 0x1a, 0x00, 0x21, 0x20, 0x17, 0x82, 0xa8, 0x64, 0x46, 0x04, 0x07, 0x41,
0x01, 0x0b, 0xf6, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x1a, 0x5e, 0xa4, 0x54, 0x47,
0x02, 0xf0, 0x70, 0x00, 0x04, 0x02, 0x01, 0xd0, 0x11, 0x91, 0xe0};
srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer();
memcpy(sdu->msg, nas_msg, sizeof(nas_msg));
sdu->N_bytes = sizeof(nas_msg);
s1ap_obj.initial_ue(0x46, 0, asn1::s1ap::rrc_establishment_cause_opts::mo_data, std::move(sdu));
// InitialContextSetupRequest (skip all NAS exchange)
sockaddr_in mme_addr = {};
sctp_sndrcvinfo rcvinfo = {};
int flags = 0;
uint8_t icsr_msg[] = {
0x00, 0x09, 0x00, 0x80, 0xac, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x08, 0x00, 0x02,
0x00, 0x01, 0x00, 0x42, 0x00, 0x0a, 0x18, 0x3b, 0x9a, 0xca, 0x00, 0x60, 0x3b, 0x9a, 0xca, 0x00, 0x00, 0x18,
0x00, 0x5e, 0x00, 0x00, 0x34, 0x00, 0x59, 0x45, 0x00, 0x09, 0x3c, 0x0f, 0x80, 0x7f, 0x00, 0x01, 0x64, 0x00,
0x00, 0x00, 0x01, 0x4a, 0x27, 0x9b, 0x6d, 0xe9, 0x42, 0x01, 0x07, 0x42, 0x01, 0x3e, 0x06, 0x00, 0x00, 0xf1,
0x10, 0x00, 0x07, 0x00, 0x1d, 0x52, 0x01, 0xc1, 0x01, 0x09, 0x07, 0x06, 0x73, 0x72, 0x73, 0x61, 0x70, 0x6e,
0x05, 0x01, 0xc0, 0xa8, 0x0a, 0x02, 0x27, 0x08, 0x80, 0x00, 0x0d, 0x04, 0x08, 0x08, 0x08, 0x08, 0x50, 0x0b,
0xf6, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x1a, 0x32, 0xdd, 0x59, 0x35, 0x13, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x23,
0x05, 0xf4, 0x32, 0xdd, 0x59, 0x35, 0x00, 0x6b, 0x00, 0x05, 0x18, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x49, 0x00,
0x20, 0x84, 0xa4, 0xea, 0x15, 0x55, 0xb3, 0xe0, 0xf4, 0x55, 0xbe, 0x1f, 0x41, 0x52, 0x92, 0xfc, 0x04, 0xd8,
0x02, 0x38, 0x0d, 0xe0, 0x81, 0x29, 0xe1, 0xaa, 0xd7, 0xc4, 0x7b, 0x12, 0x95, 0x72, 0xbe};
sdu = srsran::make_byte_buffer();
memcpy(sdu->msg, icsr_msg, sizeof(icsr_msg));
sdu->N_bytes = sizeof(icsr_msg);
TESTASSERT(s1ap_obj.handle_mme_rx_msg(std::move(sdu), mme_addr, rcvinfo, flags));
// InitialContextSetupResponse
uint8_t icsresp[] = {0x20, 0x09, 0x00, 0x22, 0x00, 0x00, 0x03, 0x00, 0x00, 0x40, 0x02, 0x00, 0x01,
0x00, 0x08, 0x40, 0x02, 0x00, 0x01, 0x00, 0x33, 0x40, 0x0f, 0x00, 0x00, 0x32,
0x40, 0x0a, 0x0a, 0x1f, 0x7f, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01};
asn1::cbit_ref cbref(icsresp, sizeof(icsresp));
TESTASSERT(s1ap_pdu.unpack(cbref) == SRSRAN_SUCCESS);
s1ap_obj.ue_ctxt_setup_complete(0x46, s1ap_pdu.successful_outcome().value.init_context_setup_resp());
}
void test_s1ap_erab_setup()
{
srsran::task_scheduler task_sched;
srslog::basic_logger& logger = srslog::fetch_basic_logger("S1AP");
s1ap s1ap_obj(&task_sched, logger);
rrc_dummy rrc;
stack_dummy stack;
srsran::task_scheduler task_sched;
srslog::basic_logger& logger = srslog::fetch_basic_logger("S1AP");
s1ap s1ap_obj(&task_sched, logger);
rrc_dummy rrc;
stack_dummy stack;
asn1::s1ap::s1ap_pdu_c s1ap_pdu;
srsran::unique_byte_buffer_t sdu;
const char* mme_addr_str = "127.0.0.1";
const uint32_t MME_PORT = 36412;
mme_dummy mme(mme_addr_str, MME_PORT);
s1ap_args_t args = {};
args.cell_id = 0x01;
@ -39,9 +158,25 @@ void test_s1ap_erab_setup()
args.s1c_bind_addr = "127.0.0.100";
args.tac = 7;
args.gtp_bind_addr = "127.0.0.100";
args.mme_addr = "127.0.0.1";
args.mme_addr = mme_addr_str;
args.enb_name = "srsenb01";
TESTASSERT(s1ap_obj.init(args, &rrc, &stack) == SRSRAN_SUCCESS);
run_s1_setup(s1ap_obj, mme);
add_rnti(s1ap_obj);
// E-RAB Modify Request
sockaddr_in mme_addr = {};
sctp_sndrcvinfo rcvinfo = {};
int flags = 0;
uint8_t mod_req_msg[] = {0x00, 0x06, 0x00, 0x1E, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00,
0x01, 0x00, 0x08, 0x00, 0x02, 0x00, 0x01, 0x00, 0x1E, 0x00, 0x0B, 0x00,
0x00, 0x24, 0x00, 0x06, 0x0A, 0x00, 0x09, 0x3C, 0x01, 0x00};
sdu = srsran::make_byte_buffer();
memcpy(sdu->msg, mod_req_msg, sizeof(mod_req_msg));
sdu->N_bytes = sizeof(mod_req_msg);
TESTASSERT(s1ap_obj.handle_mme_rx_msg(std::move(sdu), mme_addr, rcvinfo, flags));
}
int main(int argc, char** argv)

Loading…
Cancel
Save