Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 1 | /* |
| 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 Freyther | 1f0c5b4 | 2011-02-28 14:37:03 +0100 | [diff] [blame] | 21 | #include <openbsc/mgcp_internal.h> |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 22 | |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 23 | #include <osmocom/core/application.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 24 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 25 | #include <string.h> |
| 26 | |
Harald Welte | 8819d82 | 2012-01-27 00:00:44 +0100 | [diff] [blame^] | 27 | #define AUEP1 "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n" |
| 28 | #define AUEP2 "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n" |
| 29 | |
| 30 | static struct msgb *create_msg(const char *str) |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 31 | { |
| 32 | struct msgb *msg; |
| 33 | |
| 34 | msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); |
Harald Welte | 8819d82 | 2012-01-27 00:00:44 +0100 | [diff] [blame^] | 35 | int len = sprintf((char *)msg->data, str); |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 36 | msg->l2h = msgb_put(msg, len); |
| 37 | return msg; |
| 38 | } |
| 39 | |
| 40 | static void test_auep(void) |
| 41 | { |
| 42 | struct msgb *inp; |
| 43 | struct msgb *msg; |
Holger Hans Peter Freyther | d5b3ca6 | 2012-01-06 15:04:43 +0100 | [diff] [blame] | 44 | struct mgcp_config *cfg; |
| 45 | |
| 46 | printf("Testing AUEP\n"); |
| 47 | |
| 48 | cfg = mgcp_config_alloc(); |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 49 | cfg->trunk.number_endpoints = 64; |
Holger Hans Peter Freyther | 1f0c5b4 | 2011-02-28 14:37:03 +0100 | [diff] [blame] | 50 | mgcp_endpoints_allocate(&cfg->trunk); |
| 51 | |
| 52 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 53 | |
Harald Welte | 8819d82 | 2012-01-27 00:00:44 +0100 | [diff] [blame^] | 54 | inp = create_msg(AUEP1); |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 55 | msg = mgcp_handle_message(cfg, inp); |
| 56 | msgb_free(inp); |
| 57 | if (strcmp((char *) msg->data, "200 158663169 OK\r\n") != 0) |
| 58 | printf("Result1 failed '%s'\n", (char *) msg->data); |
| 59 | /* Verify that the endpoint is fine */ |
| 60 | msgb_free(msg); |
| 61 | |
Harald Welte | 8819d82 | 2012-01-27 00:00:44 +0100 | [diff] [blame^] | 62 | inp = create_msg(AUEP2); |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 63 | msg = mgcp_handle_message(cfg, inp); |
| 64 | msgb_free(inp); |
| 65 | /* Verify that the endpoint is not fine */ |
| 66 | if (strcmp((char *) msg->data, "500 18983213 FAIL\r\n") != 0) |
| 67 | printf("Result2 failed '%s'\n", (char *) msg->data); |
| 68 | msgb_free(msg); |
| 69 | |
| 70 | talloc_free(cfg); |
| 71 | } |
| 72 | |
| 73 | int main(int argc, char **argv) |
| 74 | { |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 75 | osmo_init_logging(&log_info); |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 76 | |
| 77 | test_auep(); |
Holger Hans Peter Freyther | d5b3ca6 | 2012-01-06 15:04:43 +0100 | [diff] [blame] | 78 | |
| 79 | printf("Done\n"); |
| 80 | return EXIT_SUCCESS; |
Holger Hans Peter Freyther | 9f239a2 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 81 | } |