blob: c63a7860fe8ae291e9fe598c94762d73f3d6b741 [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>
21
22#include <osmocore/talloc.h>
23#include <string.h>
24
25static struct msgb *create_auep1()
26{
27 struct msgb *msg;
28
29 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
Holger Hans Peter Freytherf43f2fc2011-01-07 11:30:21 +010030 int len = sprintf((char *)msg->data, "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n");
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010031 msg->l2h = msgb_put(msg, len);
32 return msg;
33}
34
35static struct msgb *create_auep2()
36{
37 struct msgb *msg;
38
39 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
Holger Hans Peter Freytherf43f2fc2011-01-07 11:30:21 +010040 int len = sprintf((char *)msg->data, "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n");
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010041 msg->l2h = msgb_put(msg, len);
42 return msg;
43}
44
45static void test_auep(void)
46{
47 struct msgb *inp;
48 struct msgb *msg;
49 struct mgcp_config *cfg = mgcp_config_alloc();
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +010050 cfg->trunk.number_endpoints = 64;
Holger Hans Peter Freyther9f239a22011-01-06 19:32:52 +010051 mgcp_endpoints_allocate(cfg);
52
53 inp = create_auep1();
54 msg = mgcp_handle_message(cfg, inp);
55 msgb_free(inp);
56 if (strcmp((char *) msg->data, "200 158663169 OK\r\n") != 0)
57 printf("Result1 failed '%s'\n", (char *) msg->data);
58 /* Verify that the endpoint is fine */
59 msgb_free(msg);
60
61 inp = create_auep2();
62 msg = mgcp_handle_message(cfg, inp);
63 msgb_free(inp);
64 /* Verify that the endpoint is not fine */
65 if (strcmp((char *) msg->data, "500 18983213 FAIL\r\n") != 0)
66 printf("Result2 failed '%s'\n", (char *) msg->data);
67 msgb_free(msg);
68
69 talloc_free(cfg);
70}
71
72int main(int argc, char **argv)
73{
74 struct log_target *stderr_target;
75 log_init(&log_info);
76 stderr_target = log_target_create_stderr();
77 log_add_target(stderr_target);
78 log_set_all_filter(stderr_target, 1);
79
80 test_auep();
81 return 0;
82}