File size: 6,810 Bytes
258fb37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
/*
* Copyright (C) 2019,2020 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "test-common.h"
#include "s2b-build.h"
#include "s2b-handler.h"
ogs_socknode_t *test_epdg_server(uint16_t port)
{
int rv;
ogs_sockaddr_t *addr = NULL;
ogs_socknode_t *node = NULL;
ogs_sock_t *sock = NULL;
ogs_assert(port);
#define TEST_EPDG_IPV4 "127.0.0.5"
rv = ogs_getaddrinfo(&addr, AF_UNSPEC, TEST_EPDG_IPV4, port, 0);
ogs_assert(rv == OGS_OK);
node = ogs_socknode_new(addr);
ogs_assert(node);
sock = ogs_udp_server(node->addr, NULL);
ogs_assert(sock);
node->sock = sock;
return node;
}
void test_epdg_close(ogs_socknode_t *node)
{
ogs_socknode_free(node);
}
ogs_pkbuf_t *test_epdg_read(ogs_socknode_t *node)
{
int rc = 0;
ogs_sockaddr_t from;
ogs_pkbuf_t *recvbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN);
ogs_assert(recvbuf);
ogs_pkbuf_put(recvbuf, OGS_MAX_SDU_LEN);
ogs_assert(node);
ogs_assert(node->sock);
while (1) {
rc = ogs_recvfrom(
node->sock->fd, recvbuf->data, recvbuf->len, 0, &from);
if (rc <= 0) {
ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno,
"ogs_recvfrom() failed");
}
break;
}
recvbuf->len = rc;
return recvbuf;
}
void test_s2b_recv(test_sess_t *sess, ogs_pkbuf_t *pkbuf)
{
int rv;
ogs_gtp2_message_t gtp_message;
ogs_gtp_xact_t *xact = NULL;
ogs_assert(sess);
ogs_assert(sess->gnode);
ogs_assert(pkbuf);
if (ogs_gtp2_parse_msg(>p_message, pkbuf) != OGS_OK) {
ogs_error("ogs_gtp2_parse_msg() failed");
ogs_pkbuf_free(pkbuf);
return;
}
rv = ogs_gtp_xact_receive(sess->gnode, >p_message.h, &xact);
if (rv != OGS_OK) {
ogs_error("ogs_gtp_xact_receive() failed");
ogs_pkbuf_free(pkbuf);
return;
}
switch (gtp_message.h.type) {
case OGS_GTP2_CREATE_SESSION_RESPONSE_TYPE:
test_s2b_handle_create_session_response(
xact, sess, >p_message.create_session_response);
break;
case OGS_GTP2_DELETE_SESSION_RESPONSE_TYPE:
test_s2b_handle_delete_session_response(
xact, sess, >p_message.delete_session_response);
break;
case OGS_GTP2_CREATE_BEARER_REQUEST_TYPE:
test_s2b_handle_create_bearer_request(
xact, sess, >p_message.create_bearer_request);
break;
case OGS_GTP2_DELETE_BEARER_REQUEST_TYPE:
test_s2b_handle_delete_bearer_request(
xact, sess, >p_message.delete_bearer_request);
break;
default:
ogs_error("Not implemented(type:%d)", gtp_message.h.type);
break;
}
ogs_pkbuf_free(pkbuf);
}
int test_s2b_send_create_session_request(test_sess_t *sess, bool handover_ind)
{
int rv;
ogs_gtp2_header_t h;
ogs_pkbuf_t *pkbuf = NULL;
ogs_gtp_xact_t *xact = NULL;
ogs_assert(sess);
memset(&h, 0, sizeof(ogs_gtp2_header_t));
h.type = OGS_GTP2_CREATE_SESSION_REQUEST_TYPE;
h.teid = sess->smf_s2b_c_teid;
pkbuf = test_s2b_build_create_session_request(h.type, sess, handover_ind);
if (!pkbuf) {
ogs_error("test_s2b_build_create_session_request() failed");
return OGS_ERROR;
}
xact = ogs_gtp_xact_local_create(sess->gnode, &h, pkbuf, NULL, sess);
if (!xact) {
ogs_error("ogs_gtp_xact_local_create() failed");
return OGS_ERROR;
}
rv = ogs_gtp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
}
int test_s2b_send_delete_session_request(test_sess_t *sess)
{
int rv;
ogs_gtp2_header_t h;
ogs_pkbuf_t *pkbuf = NULL;
ogs_gtp_xact_t *xact = NULL;
ogs_assert(sess);
memset(&h, 0, sizeof(ogs_gtp2_header_t));
h.type = OGS_GTP2_DELETE_SESSION_REQUEST_TYPE;
h.teid = sess->smf_s2b_c_teid;
pkbuf = test_s2b_build_delete_session_request(h.type, sess);
if (!pkbuf) {
ogs_error("test_s2b_build_delete_session_request() failed");
return OGS_ERROR;
}
xact = ogs_gtp_xact_local_create(sess->gnode, &h, pkbuf, NULL, sess);
if (!xact) {
ogs_error("ogs_gtp_xact_local_create() failed");
return OGS_ERROR;
}
rv = ogs_gtp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
}
int test_s2b_send_create_bearer_response(
test_bearer_t *bearer, ogs_gtp_xact_t *xact)
{
int rv;
ogs_gtp2_header_t h;
ogs_pkbuf_t *pkbuf = NULL;
test_sess_t *sess = NULL;
ogs_assert(xact);
ogs_assert(bearer);
sess = bearer->sess;
ogs_assert(sess);
memset(&h, 0, sizeof(ogs_gtp2_header_t));
h.type = OGS_GTP2_CREATE_BEARER_RESPONSE_TYPE;
h.teid = sess->smf_s2b_c_teid;
pkbuf = test_s2b_build_create_bearer_response(h.type, bearer);
if (!pkbuf) {
ogs_error("test_s2b_build_create_bearer_response() failed");
return OGS_ERROR;
}
rv = ogs_gtp_xact_update_tx(xact, &h, pkbuf);
if (rv != OGS_OK) {
ogs_error("ogs_gtp_xact_update_tx() failed");
return OGS_ERROR;
}
rv = ogs_gtp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
}
int test_s2b_send_delete_bearer_response(
test_bearer_t *bearer, ogs_gtp_xact_t *xact)
{
int rv;
ogs_gtp2_header_t h;
ogs_pkbuf_t *pkbuf = NULL;
test_sess_t *sess = NULL;
ogs_assert(xact);
ogs_assert(bearer);
sess = bearer->sess;
ogs_assert(sess);
memset(&h, 0, sizeof(ogs_gtp2_header_t));
h.type = OGS_GTP2_DELETE_BEARER_RESPONSE_TYPE;
h.teid = sess->smf_s2b_c_teid;
pkbuf = test_s2b_build_delete_bearer_response(h.type, bearer);
if (!pkbuf) {
ogs_error("test_s2b_build_delete_bearer_response() failed");
return OGS_ERROR;
}
rv = ogs_gtp_xact_update_tx(xact, &h, pkbuf);
if (rv != OGS_OK) {
ogs_error("ogs_gtp_xact_update_tx() failed");
return OGS_ERROR;
}
rv = ogs_gtp_xact_commit(xact);
ogs_expect(rv == OGS_OK);
return rv;
}
|