blob: 1782ea1c7d3472372cc52dc64ae01ef058baad7b [file] [log] [blame]
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +08001/* VTY code for the Cellmgr */
2/*
3 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010 by On-Waves
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <bsc_data.h>
24
25#include <osmocore/talloc.h>
26
27#include <osmocom/vty/command.h>
28#include <osmocom/vty/vty.h>
29
30#include <unistd.h>
31#include <netdb.h>
32
33#undef PACKAGE_NAME
34#undef PACKAGE_VERSION
35#undef PACKAGE_BUGREPORT
36#undef PACKAGE_TARNAME
37#undef PACKAGE_STRING
38#include <cellmgr_config.h>
39
40extern struct bsc_data bsc;
41
42static struct vty_app_info vty_info = {
43 .name = "Cellmgr-ng",
44 .version = VERSION,
45 .go_parent_cb = NULL,
46};
47
48/* vty code */
49enum cellmgr_node {
50 CELLMGR_NODE = _LAST_OSMOVTY_NODE,
51};
52
53static struct cmd_node cell_node = {
54 CELLMGR_NODE,
55 "%s(cellmgr)#",
56 1,
57};
58
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080059static int config_write_cell(struct vty *vty)
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080060{
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080061 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
62 vty_out(vty, " mtp dpc %d%s", bsc.dpc, VTY_NEWLINE);
63 vty_out(vty, " mtp opc %d%s", bsc.opc, VTY_NEWLINE);
64 if (bsc.udp_ip)
65 vty_out(vty, " udp dest ip %s%s", bsc.udp_ip, VTY_NEWLINE);
66 vty_out(vty, " udp dest port %d%s", bsc.udp_port, VTY_NEWLINE);
67 vty_out(vty, " udp src port %d%s", bsc.src_port, VTY_NEWLINE);
68 vty_out(vty, " udp reset %d%s", bsc.link.udp.reset_timeout, VTY_NEWLINE);
69 vty_out(vty, " mtp sltm once %d%s", bsc.once, VTY_NEWLINE);
70 vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE);
71 vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE);
72 vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE);
73
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080074 return CMD_SUCCESS;
75}
76
77DEFUN(cfg_cell, cfg_cell_cmd,
78 "cellmgr", "Configure the Cellmgr")
79{
80 vty->node = CELLMGR_NODE;
81 return CMD_SUCCESS;
82}
83
84DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
85 "mtp dpc DPC_NR",
86 "Set the DPC to be used.")
87{
88 bsc.dpc = atoi(argv[0]);
89 return CMD_SUCCESS;
90}
91
92DEFUN(cfg_net_opc, cfg_net_opc_cmd,
93 "mtp opc OPC_NR",
94 "Set the OPC to be used.")
95{
96 bsc.opc = atoi(argv[0]);
97 return CMD_SUCCESS;
98}
99
100DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
101 "udp dest ip IP",
102 "Set the IP when UDP mode is supposed to be used.")
103{
104 struct hostent *hosts;
105 struct in_addr *addr;
106
107 hosts = gethostbyname(argv[0]);
108 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
109 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
110 return CMD_WARNING;
111 }
112
113 addr = (struct in_addr *) hosts->h_addr_list[0];
114 bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
115 return CMD_SUCCESS;
116}
117
118DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
119 "udp dest port PORT_NR",
120 "If UDP mode is used specify the UDP dest port")
121{
122 bsc.udp_port = atoi(argv[0]);
123 return CMD_SUCCESS;
124}
125
126DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
127 "udp src port PORT_NR",
128 "Set the UDP source port to be used.")
129{
130 bsc.src_port = atoi(argv[0]);
131 return CMD_SUCCESS;
132}
133
134DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
135 "udp reset TIMEOUT",
136 "Set the timeout to take the link down")
137{
138 bsc.link.udp.reset_timeout = atoi(argv[0]);
139 return CMD_SUCCESS;
140}
141
142DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
143 "mtp sltm once (0|1)",
144 "Send SLTMs until the link is established.")
145{
146 bsc.once = !!atoi(argv[0]);
147 return CMD_SUCCESS;
148}
149
150DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
151 "msc ip IP",
152 "Set the MSC IP")
153{
154 struct hostent *hosts;
155 struct in_addr *addr;
156
157 hosts = gethostbyname(argv[0]);
158 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
159 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
160 return CMD_WARNING;
161 }
162
163 addr = (struct in_addr *) hosts->h_addr_list[0];
164
165 bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr));
166 return CMD_SUCCESS;
167}
168
169DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
170 "msc ip-dscp <0-255>",
171 "Set the IP DSCP on the A-link\n"
172 "Set the DSCP in IP packets to the MSC")
173{
174 bsc.msc_ip_dscp = atoi(argv[0]);
175 return CMD_SUCCESS;
176}
177
178ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
179 "msc ip-tos <0-255>",
180 "Set the IP DSCP on the A-link\n"
181 "Set the DSCP in IP packets to the MSC")
182
183DEFUN(cfg_msc_token, cfg_msc_token_cmd,
184 "msc token TOKEN",
185 "Set the Token to be used for the MSC")
186{
187 bsc.token = talloc_strdup(NULL, argv[0]);
188 return CMD_SUCCESS;
189}
190
191DEFUN(cfg_ping_time, cfg_ping_time_cmd,
192 "timeout ping NR",
193 "Set the PING interval. Negative to disable it")
194{
195 bsc.ping_time = atoi(argv[0]);
196 return CMD_SUCCESS;
197}
198
199DEFUN(cfg_pong_time, cfg_pong_time_cmd,
200 "timeout pong NR",
201 "Set the PING interval. Negative to disable it")
202{
203 bsc.pong_time = atoi(argv[0]);
204 return CMD_SUCCESS;
205}
206
207DEFUN(cfg_msc_time, cfg_msc_time_cmd,
208 "timeout msc NR",
209 "Set the MSC connect timeout")
210{
211 bsc.msc_time = atoi(argv[0]);
212 return CMD_SUCCESS;
213}
214
215void cell_vty_init(void)
216{
217 cmd_init(1);
218 vty_init(&vty_info);
219
220 install_element(CONFIG_NODE, &cfg_cell_cmd);
221 install_node(&cell_node, config_write_cell);
222
223 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
224 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
225 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
226 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
227 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
228 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
229 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
230 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
231 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
232 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
233 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
234 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
235 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
236 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
237}
238
239const char *openbsc_copyright = "";