diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2012-12-10 15:50:09 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2012-12-16 11:33:27 +0100 |
commit | 2d115d4bbb5b725c84bb00e7dd9ac9130e3b0789 (patch) | |
tree | b48cd8709c9e3fa0d68a06ded33cecd895f14e46 /tests/mgcp | |
parent | d74ac335748ad2fe4971fd7dcca653284b9bbc17 (diff) |
mgcp: Merge the current MGCP code from OpenBSC
There were several changes in the upstream code. These include
statistics, DTMF/RQNT, changes in the parsing code and re-transmission
handling. The last item is the main reason to do the merge now.
Diffstat (limited to 'tests/mgcp')
-rw-r--r-- | tests/mgcp/Makefile.am | 2 | ||||
-rw-r--r-- | tests/mgcp/mgcp_patch_test.c | 238 | ||||
-rw-r--r-- | tests/mgcp/mgcp_patch_test.ok | 27 |
3 files changed, 262 insertions, 5 deletions
diff --git a/tests/mgcp/Makefile.am b/tests/mgcp/Makefile.am index e4aee29..9d60529 100644 --- a/tests/mgcp/Makefile.am +++ b/tests/mgcp/Makefile.am @@ -8,4 +8,4 @@ mgcp_patch_test_SOURCES = mgcp_patch_test.c $(top_srcdir)/src/mgcp_patch.c \ $(top_srcdir)/src/mgcp/mgcp_protocol.c \ $(top_srcdir)/src/mgcp/mgcp_network.c \ $(top_srcdir)/src/debug.c -mgcp_patch_test_LDADD = $(LIBOSMOCORE_LIBS) +mgcp_patch_test_LDADD = $(LIBOSMOCORE_LIBS) -lrt diff --git a/tests/mgcp/mgcp_patch_test.c b/tests/mgcp/mgcp_patch_test.c index 834b3e4..68d163d 100644 --- a/tests/mgcp/mgcp_patch_test.c +++ b/tests/mgcp/mgcp_patch_test.c @@ -28,6 +28,7 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <limits.h> static const char mgcp_in[] = "MDCX 23213 14@mgw MGCP 1.0\r\n" @@ -67,6 +68,36 @@ static const char mgcp_out[] = "a=T38FaxVersion:0\r\n" "a=T38MaxBitRate:14400\r\n"; +#define AUEP1 "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n" +#define AUEP1_RET "200 158663169 OK\r\n" +#define AUEP2 "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n" +#define AUEP2_RET "500 18983213 FAIL\r\n" +#define EMPTY "\r\n" +#define EMPTY_RET NULL +#define SHORT "CRCX \r\n" +#define SHORT_RET "510 000000 FAIL\r\n" + +#define MDCX_WRONG_EP "MDCX 18983213 ds/e1-3/1@172.16.6.66 MGCP 1.0\r\n" +#define MDCX_ERR_RET "510 18983213 FAIL\r\n" +#define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n" +#define MDCX_RET "400 18983214 FAIL\r\n" +#define MDCX3 "MDCX 18983215 1@mgw MGCP 1.0\r\n" +#define MDCX3_RET "200 18983215 OK\r\n" \ + "I: 1\n" \ + "\n" \ + "v=0\r\n" \ + "o=- 1 23 IN IP4 0.0.0.0\r\n" \ + "c=IN IP4 0.0.0.0\r\n" \ + "t=0 0\r\n" \ + "m=audio 0 RTP/AVP 126\r\n" \ + "a=rtpmap:126 AMR/8000\r\n" + +#define SHORT2 "CRCX 1" +#define SHORT2_RET "510 000000 FAIL\r\n" +#define SHORT3 "CRCX 1 1@mgw" +#define SHORT4 "CRCX 1 1@mgw MGCP" +#define SHORT5 "CRCX 1 1@mgw MGCP 1.0" + #define CRCX "CRCX 2 1@mgw MGCP 1.0\r\n" \ "M: sendrecv\r\n" \ "C: 2\r\n" \ @@ -76,18 +107,51 @@ static const char mgcp_out[] = "m=audio 5904 RTP/AVP 97\r\n" \ "a=rtpmap:97 GSM-EFR/8000\r\n" +#define CRCX_RET "200 2 OK\r\n" \ + "I: 1\n" \ + "\n" \ + "v=0\r\n" \ + "o=- 1 23 IN IP4 0.0.0.0\r\n" \ + "c=IN IP4 0.0.0.0\r\n" \ + "t=0 0\r\n" \ + "m=audio 0 RTP/AVP 126\r\n" \ + "a=rtpmap:126 AMR/8000\r\n" + + +#define CRCX_ZYN "CRCX 2 1@mgw MGCP 1.0\r" \ + "M: sendrecv\r" \ + "C: 2\r\r" \ + "v=0\r" \ + "c=IN IP4 123.12.12.123\r" \ + "m=audio 5904 RTP/AVP 97\r" \ + "a=rtpmap:97 GSM-EFR/8000\r" + +#define CRCX_ZYN_RET "200 2 OK\r\n" \ + "I: 2\n" \ + "\n" \ + "v=0\r\n" \ + "o=- 2 23 IN IP4 0.0.0.0\r\n" \ + "c=IN IP4 0.0.0.0\r\n" \ + "t=0 0\r\n" \ + "m=audio 0 RTP/AVP 126\r\n" \ + "a=rtpmap:126 AMR/8000\r\n" + #define DLCX "DLCX 7 1@mgw MGCP 1.0\r\n" \ "C: 2\r\n" +#define DLCX_RET "250 7 OK\r\n" \ + "P: PS=0, OS=0, PR=0, OR=0, PL=0, JI=0\r\n" + #define RQNT "RQNT 186908780 1@mgw MGCP 1.0\r\n" \ "X: B244F267488\r\n" \ "S: D/9\r\n" -#define RQNT2 "RQNT 186908780 1@mgw MGCP 1.0\r\n" \ +#define RQNT2 "RQNT 186908781 1@mgw MGCP 1.0\r\n" \ "X: ADD4F26746F\r\n" \ "R: D/[0-9#*](N), G/ft, fxr/t38\r\n" -#define RQNT_RET "200 186908780 OK\r\n" +#define RQNT1_RET "200 186908780 OK\r\n" +#define RQNT2_RET "200 186908781 OK\r\n" #define ASSERT(a, cmp, b, text) \ if (!((a) cmp (b))) { \ @@ -95,6 +159,39 @@ static const char mgcp_out[] = abort(); \ } +struct mgcp_test { + const char *name; + const char *req; + const char *exp_resp; +}; + +static const struct mgcp_test tests[] = { + { "AUEP1", AUEP1, AUEP1_RET }, + { "AUEP2", AUEP2, AUEP2_RET }, + { "MDCX1", MDCX_WRONG_EP, MDCX_ERR_RET }, + { "MDCX2", MDCX_UNALLOCATED, MDCX_RET }, + { "CRCX", CRCX, CRCX_RET }, + { "MDCX3", MDCX3, MDCX3_RET }, + { "DLCX", DLCX, DLCX_RET }, + { "CRCX_ZYN", CRCX_ZYN, CRCX_ZYN_RET }, + { "EMPTY", EMPTY, EMPTY_RET }, + { "SHORT1", SHORT, SHORT_RET }, + { "SHORT2", SHORT2, SHORT2_RET }, + { "SHORT3", SHORT3, SHORT2_RET }, + { "SHORT4", SHORT4, SHORT2_RET }, + { "RQNT1", RQNT, RQNT1_RET }, + { "RQNT2", RQNT2, RQNT2_RET }, + { "DLCX", DLCX, DLCX_RET }, +}; + +static const struct mgcp_test retransmit[] = { + { "CRCX", CRCX, CRCX_RET }, + { "RQNT1", RQNT, RQNT1_RET }, + { "RQNT2", RQNT2, RQNT2_RET }, + { "MDCX3", MDCX3, MDCX3_RET }, + { "DLCX", DLCX, DLCX_RET }, +}; + static struct msgb *create_msg(const char *str) { struct msgb *msg; @@ -132,7 +229,82 @@ static void test_endp_name_rewriting() ASSERT(strcmp((const char *)msg_out->l2h, mgcp_out), ==, 0, "Text don't match"); } -static int rqnt_cb(struct mgcp_endpoint *endp, char _tone, const char *data) +static void test_messages(void) +{ + struct mgcp_config *cfg; + struct mgcp_trunk_config *tcfg; + int i; + + cfg = mgcp_config_alloc(); + + tcfg = mgcp_vtrunk_alloc(cfg, "mgw"); + tcfg->number_endpoints = 64; + mgcp_endpoints_allocate(tcfg); + mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); + + for (i = 0; i < ARRAY_SIZE(tests); i++) { + const struct mgcp_test *t = &tests[i]; + struct msgb *inp; + struct msgb *msg; + + printf("Testing %s\n", t->name); + + inp = create_msg(t->req); + msg = mgcp_handle_message(cfg, inp); + msgb_free(inp); + if (!t->exp_resp) { + if (msg) + printf("%s failed '%s'\n", t->name, (char *) msg->data); + } else if (strcmp((char *) msg->data, t->exp_resp) != 0) + printf("%s failed '%s'\n", t->name, (char *) msg->data); + msgb_free(msg); + } + + talloc_free(cfg); +} + +static void test_retransmission(void) +{ + struct mgcp_config *cfg; + struct mgcp_trunk_config *tcfg; + int i; + + cfg = mgcp_config_alloc(); + + tcfg = mgcp_vtrunk_alloc(cfg, "mgw"); + tcfg->number_endpoints = 64; + mgcp_endpoints_allocate(tcfg); + + mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); + + for (i = 0; i < ARRAY_SIZE(retransmit); i++) { + const struct mgcp_test *t = &retransmit[i]; + struct msgb *inp; + struct msgb *msg; + + printf("Testing %s\n", t->name); + + inp = create_msg(t->req); + msg = mgcp_handle_message(cfg, inp); + msgb_free(inp); + if (strcmp((char *) msg->data, t->exp_resp) != 0) + printf("%s failed '%s'\n", t->name, (char *) msg->data); + msgb_free(msg); + + /* Retransmit... */ + printf("Re-transmitting %s\n", t->name); + inp = create_msg(t->req); + msg = mgcp_handle_message(cfg, inp); + msgb_free(inp); + if (strcmp((char *) msg->data, t->exp_resp) != 0) + printf("%s failed '%s'\n", t->name, (char *) msg->data); + msgb_free(msg); + } + + talloc_free(cfg); +} + +static int rqnt_cb(struct mgcp_endpoint *endp, char _tone) { ptrdiff_t tone = _tone; endp->cfg->data = (void *) tone; @@ -141,8 +313,8 @@ static int rqnt_cb(struct mgcp_endpoint *endp, char _tone, const char *data) static void test_rqnt_cb(void) { - struct mgcp_config *cfg; struct mgcp_trunk_config *tcfg; + struct mgcp_config *cfg; struct msgb *inp, *msg; cfg = mgcp_config_alloc(); @@ -152,6 +324,8 @@ static void test_rqnt_cb(void) tcfg->number_endpoints = 64; mgcp_endpoints_allocate(tcfg); + mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); + inp = create_msg(CRCX); msgb_free(mgcp_handle_message(cfg, inp)); msgb_free(inp); @@ -178,11 +352,67 @@ static void test_rqnt_cb(void) talloc_free(cfg); } +struct pl_test { + int cycles; + uint16_t base_seq; + uint16_t max_seq; + uint32_t packets; + + uint32_t expected; + int loss; +}; + +static const struct pl_test pl_test_dat[] = { + /* basic.. just one package */ + { .cycles = 0, .base_seq = 0, .max_seq = 0, .packets = 1, .expected = 1, .loss = 0}, + /* some packages and a bit of loss */ + { .cycles = 0, .base_seq = 0, .max_seq = 100, .packets = 100, .expected = 101, .loss = 1}, + /* wrap around */ + { .cycles = 1<<16, .base_seq = 0xffff, .max_seq = 2, .packets = 4, .expected = 4, .loss = 0}, + /* min loss */ + { .cycles = 0, .base_seq = 0, .max_seq = 0, .packets = UINT_MAX, .expected = 1, .loss = INT_MIN }, + /* max loss, with wrap around on expected max */ + { .cycles = INT_MAX, .base_seq = 0, .max_seq = UINT16_MAX, .packets = 0, .expected = ((uint32_t)(INT_MAX) + UINT16_MAX + 1), .loss = INT_MAX }, +}; + +static void test_packet_loss_calc(void) +{ + int i; + printf("Testing packet loss calculation.\n"); + + for (i = 0; i < ARRAY_SIZE(pl_test_dat); ++i) { + uint32_t expected; + int loss; + struct mgcp_rtp_state state; + struct mgcp_rtp_end rtp; + memset(&state, 0, sizeof(state)); + memset(&rtp, 0, sizeof(rtp)); + + state.initialized = 1; + state.base_seq = pl_test_dat[i].base_seq; + state.max_seq = pl_test_dat[i].max_seq; + state.cycles = pl_test_dat[i].cycles; + + rtp.packets = pl_test_dat[i].packets; + mgcp_state_calc_loss(&state, &rtp, &expected, &loss); + + if (loss != pl_test_dat[i].loss || expected != pl_test_dat[i].expected) { + printf("FAIL: Wrong exp/loss at idx(%d) Loss(%d vs. %d) Exp(%u vs. %u)\n", + i, loss, pl_test_dat[i].loss, + expected, pl_test_dat[i].expected); + } + } +} + int main(int argc, char **argv) { osmo_init_logging(&log_info); test_endp_name_rewriting(); + + test_messages(); + test_retransmission(); + test_packet_loss_calc(); test_rqnt_cb(); printf("All tests passed.\n"); diff --git a/tests/mgcp/mgcp_patch_test.ok b/tests/mgcp/mgcp_patch_test.ok index d59bd28..7847169 100644 --- a/tests/mgcp/mgcp_patch_test.ok +++ b/tests/mgcp/mgcp_patch_test.ok @@ -39,4 +39,31 @@ a=T38MaxBitRate:14400 ' 4d 44 43 58 20 32 33 32 31 33 20 31 34 40 66 6f 6f 32 20 4d 47 43 50 20 31 2e 30 0d 0a 43 3a 20 34 61 38 34 61 64 35 64 32 35 66 0d 0a 49 3a 20 25 64 0d 0a 4c 3a 20 70 3a 32 30 2c 20 61 3a 47 53 4d 2d 45 46 52 2c 20 6e 74 3a 49 4e 0d 0a 4d 3a 20 72 65 63 76 6f 6e 6c 79 0d 0a 0d 0a 76 3d 30 0d 0a 6f 3d 2d 20 32 35 38 36 39 36 34 37 37 20 30 20 49 4e 20 49 50 34 20 31 37 32 2e 31 36 2e 31 2e 31 30 37 0d 0a 73 3d 2d 0d 0a 63 3d 49 4e 20 49 50 34 20 31 37 32 2e 31 36 2e 31 2e 31 30 37 0d 0a 74 3d 30 20 30 0d 0a 6d 3d 61 75 64 69 6f 20 36 36 36 36 20 52 54 50 2f 41 56 50 20 31 32 37 0d 0a 61 3d 72 74 70 6d 61 70 3a 31 32 37 20 47 53 4d 2d 45 46 52 2f 38 30 30 30 2f 31 0d 0a 61 3d 70 74 69 6d 65 3a 32 30 0d 0a 61 3d 72 65 63 76 6f 6e 6c 79 0d 0a 6d 3d 69 6d 61 67 65 20 34 34 30 32 20 75 64 70 74 6c 20 74 33 38 0d 0a 61 3d 54 33 38 46 61 78 56 65 72 73 69 6f 6e 3a 30 0d 0a 61 3d 54 33 38 4d 61 78 42 69 74 52 61 74 65 3a 31 34 34 30 30 0d 0a 4d 44 43 58 20 32 33 32 31 33 20 31 34 40 66 6f 6f 32 20 4d 47 43 50 20 31 2e 30 0d 0a 43 3a 20 34 61 38 34 61 64 35 64 32 35 66 0d 0a 49 3a 20 25 64 0d 0a 4c 3a 20 70 3a 32 30 2c 20 61 3a 47 53 4d 2d 45 46 52 2c 20 6e 74 3a 49 4e 0d 0a 4d 3a 20 72 65 63 76 6f 6e 6c 79 0d 0a 0d 0a 76 3d 30 0d 0a 6f 3d 2d 20 32 35 38 36 39 36 34 37 37 20 30 20 49 4e 20 49 50 34 20 31 37 32 2e 31 36 2e 31 2e 31 30 37 0d 0a 73 3d 2d 0d 0a 63 3d 49 4e 20 49 50 34 20 31 37 32 2e 31 36 2e 31 2e 31 30 37 0d 0a 74 3d 30 20 30 0d 0a 6d 3d 61 75 64 69 6f 20 36 36 36 36 20 52 54 50 2f 41 56 50 20 31 32 37 0d 0a 61 3d 72 74 70 6d 61 70 3a 31 32 37 20 47 53 4d 2d 45 46 52 2f 38 30 30 30 2f 31 0d 0a 61 3d 70 74 69 6d 65 3a 32 30 0d 0a 61 3d 72 65 63 76 6f 6e 6c 79 0d 0a 6d 3d 69 6d 61 67 65 20 34 34 30 32 20 75 64 70 74 6c 20 74 33 38 0d 0a 61 3d 54 33 38 46 61 78 56 65 72 73 69 6f 6e 3a 30 0d 0a 61 3d 54 33 38 4d 61 78 42 69 74 52 61 74 65 3a 31 34 34 30 30 0d 0a +Testing AUEP1 +Testing AUEP2 +Testing MDCX1 +Testing MDCX2 +Testing CRCX +Testing MDCX3 +Testing DLCX +Testing CRCX_ZYN +Testing EMPTY +Testing SHORT1 +Testing SHORT2 +Testing SHORT3 +Testing SHORT4 +Testing RQNT1 +Testing RQNT2 +Testing DLCX +Testing CRCX +Re-transmitting CRCX +Testing RQNT1 +Re-transmitting RQNT1 +Testing RQNT2 +Re-transmitting RQNT2 +Testing MDCX3 +Re-transmitting MDCX3 +Testing DLCX +Re-transmitting DLCX +Testing packet loss calculation. All tests passed. |