blob: f29d5b80d473f3e807e7c71cc0e9b2ef6bcc25ca [file] [log] [blame]
Holger Hans Peter Freytherf0bc0752011-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 Freyther49e170b2011-02-28 14:37:03 +010021#include <openbsc/mgcp_internal.h>
Holger Hans Peter Freytherf0bc0752011-01-06 19:32:52 +010022
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +020023#include <osmocom/core/application.h>
Pablo Neira Ayusodd5fff42011-03-22 16:47:59 +010024#include <osmocom/core/talloc.h>
Holger Hans Peter Freytherf0bc0752011-01-06 19:32:52 +010025#include <string.h>
26
27static struct msgb *create_auep1()
28{
29 struct msgb *msg;
30
31 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
Holger Hans Peter Freyther72026c12011-01-07 11:30:21 +010032 int len = sprintf((char *)msg->data, "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n");
Holger Hans Peter Freytherf0bc0752011-01-06 19:32:52 +010033 msg->l2h = msgb_put(msg, len);
34 return msg;
35}
36
37static struct msgb *create_auep2()
38{
39 struct msgb *msg;
40
41 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
Holger Hans Peter Freyther72026c12011-01-07 11:30:21 +010042 int len = sprintf((char *)msg->data, "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n");
Holger Hans Peter Freytherf0bc0752011-01-06 19:32:52 +010043 msg->l2h = msgb_put(msg, len);
44 return msg;
45}
46
47static void test_auep(void)
48{
49 struct msgb *inp;
50 struct msgb *msg;
Holger Hans Peter Freyther38484aa2012-01-06 15:04:43 +010051 struct mgcp_config *cfg;
52
53 printf("Testing AUEP\n");
54
55 cfg = mgcp_config_alloc();
Holger Hans Peter Freytherab56ce12011-02-28 00:56:17 +010056 cfg->trunk.number_endpoints = 64;
Holger Hans Peter Freyther49e170b2011-02-28 14:37:03 +010057 mgcp_endpoints_allocate(&cfg->trunk);
58
59 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
Holger Hans Peter Freytherf0bc0752011-01-06 19:32:52 +010060
61 inp = create_auep1();
62 msg = mgcp_handle_message(cfg, inp);
63 msgb_free(inp);
64 if (strcmp((char *) msg->data, "200 158663169 OK\r\n") != 0)
65 printf("Result1 failed '%s'\n", (char *) msg->data);
66 /* Verify that the endpoint is fine */
67 msgb_free(msg);
68
69 inp = create_auep2();
70 msg = mgcp_handle_message(cfg, inp);
71 msgb_free(inp);
72 /* Verify that the endpoint is not fine */
73 if (strcmp((char *) msg->data, "500 18983213 FAIL\r\n") != 0)
74 printf("Result2 failed '%s'\n", (char *) msg->data);
75 msgb_free(msg);
76
77 talloc_free(cfg);
78}
79
80int main(int argc, char **argv)
81{
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +020082 osmo_init_logging(&log_info);
Holger Hans Peter Freytherf0bc0752011-01-06 19:32:52 +010083
84 test_auep();
Holger Hans Peter Freyther38484aa2012-01-06 15:04:43 +010085
86 printf("Done\n");
87 return EXIT_SUCCESS;
Holger Hans Peter Freytherf0bc0752011-01-06 19:32:52 +010088}