blob: 3ebdc0fea8d3b7aa732ad30314fed4e81b2b0c46 [file] [log] [blame]
Neels Hofmeyre25018b2017-11-27 21:29:33 +01001/* OsmoBSC interface to quagga VTY for handover parameters */
2/* (C) 2017 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
3 * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
4 * All Rights Reserved
5 *
6 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <osmocom/bsc/gsm_data.h>
24#include <osmocom/bsc/vty.h>
25#include <osmocom/bsc/handover_cfg.h>
26
27static struct handover_cfg *ho_cfg_from_vty(struct vty *vty)
28{
29 switch (vty->node) {
30 case GSMNET_NODE:
31 return gsmnet_from_vty(vty)->ho;
32 case BTS_NODE:
33 OSMO_ASSERT(vty->index);
34 return ((struct gsm_bts *)vty->index)->ho;
35 default:
36 OSMO_ASSERT(false);
37 }
38}
39
40
41#define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, \
42 VTY_CMD, VTY_CMD_ARG, VTY_ARG_EVAL, \
43 VTY_WRITE_FMT, VTY_WRITE_CONV, \
44 VTY_DOC) \
45DEFUN(cfg_ho_##NAME, cfg_ho_##NAME##_cmd, \
46 VTY_CMD " (" VTY_CMD_ARG "|default)", \
47 VTY_DOC \
48 "Use default (" #DEFAULT_VAL "), remove explicit setting on this node\n") \
49{ \
50 struct handover_cfg *ho = ho_cfg_from_vty(vty); \
51 const char *val = argv[0]; \
52 if (!strcmp(val, "default")) { \
53 const char *msg; \
54 if (ho_isset_##NAME(ho)) {\
55 ho_clear_##NAME(ho); \
56 msg = "setting removed, now is"; \
57 } else \
58 msg = "already was unset, still is"; \
59 vty_out(vty, "%% '" VTY_CMD "' %s " VTY_WRITE_FMT "%s%s", \
60 msg, VTY_WRITE_CONV( ho_get_##NAME(ho) ), \
61 ho_isset_on_parent_##NAME(ho)? " (set on higher level node)" : "", \
62 VTY_NEWLINE); \
63 } \
64 else \
65 ho_set_##NAME(ho, VTY_ARG_EVAL(val)); \
66 return CMD_SUCCESS; \
67}
68
69HO_CFG_ALL_MEMBERS
70#undef HO_CFG_ONE_MEMBER
71
72
Neels Hofmeyrdfd36da2018-02-12 16:48:45 +010073static void ho_vty_write(struct vty *vty, const char *indent, struct handover_cfg *ho)
Neels Hofmeyre25018b2017-11-27 21:29:33 +010074{
75#define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, \
76 VTY_CMD, VTY_CMD_ARG, VTY_ARG_EVAL, \
77 VTY_WRITE_FMT, VTY_WRITE_CONV, \
78 VTY_DOC) \
79 if (ho_isset_##NAME(ho)) \
80 vty_out(vty, "%s" VTY_CMD " " VTY_WRITE_FMT "%s", indent, \
81 VTY_WRITE_CONV( ho_get_##NAME(ho) ), VTY_NEWLINE);
82
83 HO_CFG_ALL_MEMBERS
84#undef HO_CFG_ONE_MEMBER
85}
86
Neels Hofmeyrdfd36da2018-02-12 16:48:45 +010087void ho_vty_write_bts(struct vty *vty, struct gsm_bts *bts)
88{
89 ho_vty_write(vty, " ", bts->ho);
90}
91
92void ho_vty_write_net(struct vty *vty, struct gsm_network *net)
93{
94 ho_vty_write(vty, " ", net->ho);
95
96 /* future: net specific vty commands */
97}
98
Neels Hofmeyre25018b2017-11-27 21:29:33 +010099static void ho_vty_init_cmds(int parent_node)
100{
101#define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, VTY1, VTY2, VTY3, VTY4, VTY5, VTY6) \
102 install_element(parent_node, &cfg_ho_##NAME##_cmd);
103
104 HO_CFG_ALL_MEMBERS
105#undef HO_CFG_ONE_MEMBER
106}
107
108void ho_vty_init()
109{
110 ho_vty_init_cmds(GSMNET_NODE);
111 ho_vty_init_cmds(BTS_NODE);
112}
113