|
|
|
@ -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)
|
|
|
|
|