blob: 41a51dea0d1feae68bae51886d7498b736584126 [file] [log] [blame]
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +01001/*
2 * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * (C) 2011 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <openbsc/mgcp.h>
Holger Hans Peter Freyther1f0c5b42011-02-28 14:37:03 +010021#include <openbsc/mgcp_internal.h>
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010022
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +020023#include <osmocom/core/application.h>
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010024#include <osmocom/core/talloc.h>
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010025#include <string.h>
26
Harald Welte8819d822012-01-27 00:00:44 +010027#define AUEP1 "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n"
Harald Weltef74da142012-01-27 00:36:56 +010028#define AUEP1_RET "200 158663169 OK\r\n"
Harald Welte8819d822012-01-27 00:00:44 +010029#define AUEP2 "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n"
Harald Weltef74da142012-01-27 00:36:56 +010030#define AUEP2_RET "500 18983213 FAIL\r\n"
Holger Hans Peter Freytherd77023b2012-03-16 09:53:49 +010031#define EMPTY "\r\n"
32#define EMPTY_RET NULL
33#define SHORT "CRCX \r\n"
34#define SHORT_RET "510 000000 FAIL\r\n"
35
36#define SHORT2 "CRCX 1"
37#define SHORT2_RET "510 000000 FAIL\r\n"
38#define SHORT3 "CRCX 1 1@mgw"
39#define SHORT4 "CRCX 1 1@mgw MGCP"
40#define SHORT5 "CRCX 1 1@mgw MGCP 1.0"
Harald Weltef74da142012-01-27 00:36:56 +010041
Harald Welte27fa7902012-01-27 00:37:23 +010042#define CRCX "CRCX 2 1@mgw MGCP 1.0\r\n" \
43 "M: sendrecv\r\n" \
44 "C: 2\r\n" \
45 "\r\n" \
46 "v=0\r\n" \
47 "c=IN IP4 123.12.12.123\r\n" \
48 "m=audio 5904 RTP/AVP 97\r\n" \
49 "a=rtpmap:97 GSM-EFR/8000\r\n"
50
51#define CRCX_RET "200 2 OK\r\n" \
52 "I: 1\n" \
53 "\n" \
54 "v=0\r\n" \
55 "o=- 1 23 IN IP4 0.0.0.0\r\n" \
56 "c=IN IP4 0.0.0.0\r\n" \
57 "t=0 0\r\n" \
58 "m=audio 0 RTP/AVP 126\r\n" \
59 "a=rtpmap:126 AMR/8000\r\n"
60
61
62#define CRCX_ZYN "CRCX 2 1@mgw MGCP 1.0\r" \
63 "M: sendrecv\r" \
64 "C: 2\r\r" \
65 "v=0\r" \
66 "c=IN IP4 123.12.12.123\r" \
67 "m=audio 5904 RTP/AVP 97\r" \
68 "a=rtpmap:97 GSM-EFR/8000\r"
Harald Weltef74da142012-01-27 00:36:56 +010069
Holger Hans Peter Freyther0bf15a82012-09-14 17:18:12 +020070#define DLCX "DLCX 7 1@mgw MGCP 1.0\r\n" \
71 "C: 2\r\n"
72
73#define DLCX_RET "250 7 OK\r\n" \
74 "P: PS=0, OS=0, PR=0, OR=0\r\n"
75
76
Harald Weltef74da142012-01-27 00:36:56 +010077struct mgcp_test {
78 const char *name;
79 const char *req;
80 const char *exp_resp;
81};
82
83const struct mgcp_test tests[] = {
84 { "AUEP1", AUEP1, AUEP1_RET },
85 { "AUEP2", AUEP2, AUEP2_RET },
Harald Welte27fa7902012-01-27 00:37:23 +010086 { "CRCX", CRCX, CRCX_RET },
87 { "CRCX_ZYN", CRCX_ZYN, CRCX_RET },
Holger Hans Peter Freytherd77023b2012-03-16 09:53:49 +010088 { "EMPTY", EMPTY, EMPTY_RET },
89 { "SHORT1", SHORT, SHORT_RET },
90 { "SHORT2", SHORT2, SHORT2_RET },
91 { "SHORT3", SHORT3, SHORT2_RET },
92 { "SHORT4", SHORT4, SHORT2_RET },
Holger Hans Peter Freyther0bf15a82012-09-14 17:18:12 +020093 { "DLCX", DLCX, DLCX_RET },
Harald Weltef74da142012-01-27 00:36:56 +010094};
Harald Welte8819d822012-01-27 00:00:44 +010095
96static struct msgb *create_msg(const char *str)
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010097{
98 struct msgb *msg;
99
100 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
Harald Welte8819d822012-01-27 00:00:44 +0100101 int len = sprintf((char *)msg->data, str);
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100102 msg->l2h = msgb_put(msg, len);
103 return msg;
104}
105
Holger Hans Peter Freyther5563e6c2012-03-16 09:45:13 +0100106static void test_messages(void)
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100107{
Holger Hans Peter Freytherd5b3ca62012-01-06 15:04:43 +0100108 struct mgcp_config *cfg;
Harald Weltef74da142012-01-27 00:36:56 +0100109 int i;
Holger Hans Peter Freytherd5b3ca62012-01-06 15:04:43 +0100110
111 cfg = mgcp_config_alloc();
Harald Weltef74da142012-01-27 00:36:56 +0100112
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100113 cfg->trunk.number_endpoints = 64;
Holger Hans Peter Freyther1f0c5b42011-02-28 14:37:03 +0100114 mgcp_endpoints_allocate(&cfg->trunk);
115
116 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100117
Harald Weltef74da142012-01-27 00:36:56 +0100118 for (i = 0; i < ARRAY_SIZE(tests); i++) {
119 const struct mgcp_test *t = &tests[i];
120 struct msgb *inp;
121 struct msgb *msg;
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100122
Harald Weltef74da142012-01-27 00:36:56 +0100123 printf("Testing %s\n", t->name);
124
125 inp = create_msg(t->req);
126 msg = mgcp_handle_message(cfg, inp);
127 msgb_free(inp);
Holger Hans Peter Freytherd77023b2012-03-16 09:53:49 +0100128 if (!t->exp_resp) {
129 if (msg)
130 printf("%s failed '%s'\n", t->name, (char *) msg->data);
131 } else if (strcmp((char *) msg->data, t->exp_resp) != 0)
Harald Weltef74da142012-01-27 00:36:56 +0100132 printf("%s failed '%s'\n", t->name, (char *) msg->data);
133 msgb_free(msg);
134 }
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100135
136 talloc_free(cfg);
137}
138
139int main(int argc, char **argv)
140{
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +0200141 osmo_init_logging(&log_info);
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100142
Holger Hans Peter Freyther5563e6c2012-03-16 09:45:13 +0100143 test_messages();
Holger Hans Peter Freytherd5b3ca62012-01-06 15:04:43 +0100144
145 printf("Done\n");
146 return EXIT_SUCCESS;
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100147}