blob: 6e0df753d23fd3cfe094692a9c56ec07f10c4434 [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"
31
Harald Welte27fa7902012-01-27 00:37:23 +010032#define CRCX "CRCX 2 1@mgw MGCP 1.0\r\n" \
33 "M: sendrecv\r\n" \
34 "C: 2\r\n" \
35 "\r\n" \
36 "v=0\r\n" \
37 "c=IN IP4 123.12.12.123\r\n" \
38 "m=audio 5904 RTP/AVP 97\r\n" \
39 "a=rtpmap:97 GSM-EFR/8000\r\n"
40
41#define CRCX_RET "200 2 OK\r\n" \
42 "I: 1\n" \
43 "\n" \
44 "v=0\r\n" \
45 "o=- 1 23 IN IP4 0.0.0.0\r\n" \
46 "c=IN IP4 0.0.0.0\r\n" \
47 "t=0 0\r\n" \
48 "m=audio 0 RTP/AVP 126\r\n" \
49 "a=rtpmap:126 AMR/8000\r\n"
50
51
52#define CRCX_ZYN "CRCX 2 1@mgw MGCP 1.0\r" \
53 "M: sendrecv\r" \
54 "C: 2\r\r" \
55 "v=0\r" \
56 "c=IN IP4 123.12.12.123\r" \
57 "m=audio 5904 RTP/AVP 97\r" \
58 "a=rtpmap:97 GSM-EFR/8000\r"
Harald Weltef74da142012-01-27 00:36:56 +010059
60struct mgcp_test {
61 const char *name;
62 const char *req;
63 const char *exp_resp;
64};
65
66const struct mgcp_test tests[] = {
67 { "AUEP1", AUEP1, AUEP1_RET },
68 { "AUEP2", AUEP2, AUEP2_RET },
Harald Welte27fa7902012-01-27 00:37:23 +010069 { "CRCX", CRCX, CRCX_RET },
70 { "CRCX_ZYN", CRCX_ZYN, CRCX_RET },
Harald Weltef74da142012-01-27 00:36:56 +010071};
Harald Welte8819d822012-01-27 00:00:44 +010072
73static struct msgb *create_msg(const char *str)
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010074{
75 struct msgb *msg;
76
77 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
Harald Welte8819d822012-01-27 00:00:44 +010078 int len = sprintf((char *)msg->data, str);
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010079 msg->l2h = msgb_put(msg, len);
80 return msg;
81}
82
Holger Hans Peter Freyther5563e6c2012-03-16 09:45:13 +010083static void test_messages(void)
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010084{
Holger Hans Peter Freytherd5b3ca62012-01-06 15:04:43 +010085 struct mgcp_config *cfg;
Harald Weltef74da142012-01-27 00:36:56 +010086 int i;
Holger Hans Peter Freytherd5b3ca62012-01-06 15:04:43 +010087
88 cfg = mgcp_config_alloc();
Harald Weltef74da142012-01-27 00:36:56 +010089
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +010090 cfg->trunk.number_endpoints = 64;
Holger Hans Peter Freyther1f0c5b42011-02-28 14:37:03 +010091 mgcp_endpoints_allocate(&cfg->trunk);
92
93 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010094
Harald Weltef74da142012-01-27 00:36:56 +010095 for (i = 0; i < ARRAY_SIZE(tests); i++) {
96 const struct mgcp_test *t = &tests[i];
97 struct msgb *inp;
98 struct msgb *msg;
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010099
Harald Weltef74da142012-01-27 00:36:56 +0100100 printf("Testing %s\n", t->name);
101
102 inp = create_msg(t->req);
103 msg = mgcp_handle_message(cfg, inp);
104 msgb_free(inp);
105 if (strcmp((char *) msg->data, t->exp_resp) != 0)
106 printf("%s failed '%s'\n", t->name, (char *) msg->data);
107 msgb_free(msg);
108 }
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100109
110 talloc_free(cfg);
111}
112
113int main(int argc, char **argv)
114{
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +0200115 osmo_init_logging(&log_info);
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100116
Holger Hans Peter Freyther5563e6c2012-03-16 09:45:13 +0100117 test_messages();
Holger Hans Peter Freytherd5b3ca62012-01-06 15:04:43 +0100118
119 printf("Done\n");
120 return EXIT_SUCCESS;
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +0100121}