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