diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2017-03-24 17:59:26 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-04-08 07:44:45 +0000 |
commit | 22401433aad9f19074229f00d4f3b091de4804ce (patch) | |
tree | 4155e659ad957a9b475762a2d78a8ba8b409e3f6 /tests/gsm0808 | |
parent | f7add0889c80f9f94af9985a752375e13f713cd9 (diff) |
gsm0808: Add utils for AoIP Transport Layer Address
The planned support for true A over IP requires the encoding and
decoding of a so called "AoIP Transport Layer Address" element.
This commt adds parsing functionality and tests for the element
mentioned above, however, it is not yet actively used.
Change-Id: I57933b0a06a3f54ec2a41e6ecb6ced9fbbc89332
Diffstat (limited to 'tests/gsm0808')
-rw-r--r-- | tests/gsm0808/gsm0808_test.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c index 98502b75..26bd1d60 100644 --- a/tests/gsm0808/gsm0808_test.c +++ b/tests/gsm0808/gsm0808_test.c @@ -19,9 +19,14 @@ */ #include <osmocom/gsm/gsm0808.h> +#include <osmocom/gsm/gsm0808_utils.h> +#include <osmocom/gsm/protocol/gsm_08_08.h> #include <stdio.h> #include <stdlib.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> #define VERIFY(msg, data, len) \ if (msgb_l3len(msg) != len) { \ @@ -247,6 +252,63 @@ static void test_prepend_dtap() msgb_free(in_msg); } +static void test_enc_dec_aoip_trasp_addr_v4() +{ + struct sockaddr_storage enc_addr; + struct sockaddr_storage dec_addr; + struct sockaddr_in enc_addr_in; + struct msgb *msg; + uint8_t rc_enc; + int rc_dec; + + memset(&enc_addr_in, 0, sizeof(enc_addr_in)); + enc_addr_in.sin_family = AF_INET; + enc_addr_in.sin_port = htons(1234); + inet_aton("255.0.255.255", &enc_addr_in.sin_addr); + + memset(&enc_addr, 0, sizeof(enc_addr)); + memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in)); + + msg = msgb_alloc(1024, "output buffer"); + rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr); + OSMO_ASSERT(rc_enc == 8); + rc_dec = + gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2); + OSMO_ASSERT(rc_dec == 6); + OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0); + + msgb_free(msg); +} + +static void test_enc_dec_aoip_trasp_addr_v6() +{ + struct sockaddr_storage enc_addr; + struct sockaddr_storage dec_addr; + struct sockaddr_in6 enc_addr_in; + struct msgb *msg; + uint8_t rc_enc; + int rc_dec; + + memset(&enc_addr_in, 0, sizeof(enc_addr_in)); + enc_addr_in.sin6_family = AF_INET6; + enc_addr_in.sin6_port = htons(4567); + inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344", + &enc_addr_in.sin6_addr); + + memset(&enc_addr, 0, sizeof(enc_addr)); + memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in)); + + msg = msgb_alloc(1024, "output buffer"); + rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr); + OSMO_ASSERT(rc_enc == 20); + rc_dec = + gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2); + OSMO_ASSERT(rc_dec == 18); + OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0); + + msgb_free(msg); +} + int main(int argc, char **argv) { printf("Testing generation of GSM0808 messages\n"); @@ -263,6 +325,8 @@ int main(int argc, char **argv) test_create_clear_rqst(); test_create_dtap(); test_prepend_dtap(); + test_enc_dec_aoip_trasp_addr_v4(); + test_enc_dec_aoip_trasp_addr_v6(); printf("Done\n"); return EXIT_SUCCESS; |