open5gs/test/enb_setup_test.c

174 lines
3.6 KiB
C
Raw Normal View History

2017-02-13 07:26:07 +00:00
#include "core.h"
#include "core_errno.h"
#include "core_general.h"
#include "core_debug.h"
#include "core_pkbuf.h"
#include "testutil.h"
2017-02-15 11:16:50 +00:00
#include "s1ap_contents.h"
2017-02-13 07:26:07 +00:00
#include "s1ap_enb_message.h"
#include "s1ap_conv.h"
#include "s1ap_path.h"
net_sock_t *enb_net_open(void)
2017-02-13 07:26:07 +00:00
{
status_t rv;
mme_ctx_t *mme = mme_self();
net_sock_t *sock = NULL;
if (!mme) return NULL;
rv = net_open_with_addr(&sock, mme->enb_local_addr, "127.0.0.1", 0,
mme->enb_s1_port, SOCK_SEQPACKET, IPPROTO_SCTP, 0);
2017-02-13 07:26:07 +00:00
if (rv != CORE_OK) return NULL;
return sock;
}
status_t enb_net_close(net_sock_t *sock)
2017-02-13 07:26:07 +00:00
{
return net_close(sock);
}
int enb_net_send(net_sock_t *sock, pkbuf_t *sendbuf)
{
return s1ap_send(sock, sendbuf);
}
2017-02-14 13:39:04 +00:00
int enb_net_read(net_sock_t *sock, pkbuf_t *recvbuf)
2017-02-13 07:26:07 +00:00
{
2017-02-14 13:39:04 +00:00
int rc = 0;
2017-02-13 07:26:07 +00:00
while(1)
{
2017-02-14 13:39:04 +00:00
rc = net_read(sock, recvbuf->payload, recvbuf->len, 0);
if (rc == -2)
{
2017-02-13 07:26:07 +00:00
continue;
2017-02-14 13:39:04 +00:00
}
else if (rc <= 0)
{
if (sock->sndrcv_errno == EAGAIN)
{
continue;
}
break;
}
else
{
2017-02-13 07:26:07 +00:00
break;
2017-02-14 13:39:04 +00:00
}
2017-02-13 07:26:07 +00:00
}
return rc;
}
2017-02-13 12:56:03 +00:00
#define NUM_OF_TEST_DUPLICATED_ENB 4
2017-02-13 12:31:03 +00:00
#define TEST_S1_SETUP_RESPONSE_SIZE 27
#define TEST_S1_SETUP_FAILURE_SIZE 12
2017-02-13 07:26:07 +00:00
static void enb_setup_test1(abts_case *tc, void *data)
{
status_t rv;
2017-02-13 12:56:03 +00:00
net_sock_t *sock[NUM_OF_TEST_DUPLICATED_ENB];
2017-02-13 07:26:07 +00:00
pkbuf_t *sendbuf;
pkbuf_t *recvbuf = pkbuf_alloc(0, S1AP_SDU_SIZE);
s1ap_message message;
int rc;
int i;
2017-02-13 12:56:03 +00:00
for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++)
{
sock[i] = enb_net_open();
ABTS_PTR_NOTNULL(tc, sock[i]);
}
2017-02-13 07:26:07 +00:00
2017-02-13 12:56:03 +00:00
for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++)
{
rv = s1ap_build_setup_req(&sendbuf, 0x54f64);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
2017-02-13 07:26:07 +00:00
rv = enb_net_send(sock[i], sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
2017-02-13 07:26:07 +00:00
pkbuf_free(sendbuf);
2017-02-13 07:26:07 +00:00
2017-02-14 13:39:04 +00:00
rc = enb_net_read(sock[i], recvbuf);
ABTS_INT_NEQUAL(tc, 0, rc);
2017-02-13 07:26:07 +00:00
rv = s1ap_decode_pdu(&message, recvbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
s1ap_free_pdu(&message);
}
2017-02-13 12:56:03 +00:00
for (i = 0; i < NUM_OF_TEST_DUPLICATED_ENB; i++)
{
rv = enb_net_close(sock[i]);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
}
2017-02-13 07:26:07 +00:00
pkbuf_free(recvbuf);
2017-02-15 00:17:44 +00:00
core_sleep(time_from_msec(300));
2017-02-13 12:31:03 +00:00
}
2017-02-13 13:40:42 +00:00
#define NUM_OF_TEST_ENB 32
2017-02-13 12:56:03 +00:00
2017-02-13 12:31:03 +00:00
static void enb_setup_test2(abts_case *tc, void *data)
{
status_t rv;
net_sock_t *sock[NUM_OF_TEST_ENB];
pkbuf_t *sendbuf;
pkbuf_t *recvbuf = pkbuf_alloc(0, S1AP_SDU_SIZE);
s1ap_message message;
int rc;
int i;
for (i = 0; i < NUM_OF_TEST_ENB; i++)
{
sock[i] = enb_net_open();
ABTS_PTR_NOTNULL(tc, sock[i]);
}
for (i = 0; i < NUM_OF_TEST_ENB; i++)
{
rv = s1ap_build_setup_req(&sendbuf, 0x54f64+i);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
rv = enb_net_send(sock[i], sendbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
pkbuf_free(sendbuf);
2017-02-14 13:39:04 +00:00
rc = enb_net_read(sock[i], recvbuf);
ABTS_INT_NEQUAL(tc, 0, rc);
2017-02-13 12:31:03 +00:00
rv = s1ap_decode_pdu(&message, recvbuf);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
s1ap_free_pdu(&message);
}
for (i = 0; i < NUM_OF_TEST_ENB; i++)
{
rv = enb_net_close(sock[i]);
ABTS_INT_EQUAL(tc, CORE_OK, rv);
}
pkbuf_free(recvbuf);
2017-02-15 00:17:44 +00:00
core_sleep(time_from_sec(1));
2017-02-13 07:26:07 +00:00
}
abts_suite *test_enb_setup(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, enb_setup_test1, NULL);
2017-02-13 12:31:03 +00:00
abts_run_test(suite, enb_setup_test2, NULL);
2017-02-13 07:26:07 +00:00
return suite;
}