Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 1 | /* OsmoBSC interface to quagga VTY for handover parameters */ |
Neels Hofmeyr | 5f2204a | 2018-02-16 16:07:02 +0100 | [diff] [blame] | 2 | /* (C) 2009-2010 by Andreas Eversberg <jolly@eversberg.eu> |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 3 | * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Neels Hofmeyr | 5f2204a | 2018-02-16 16:07:02 +0100 | [diff] [blame] | 4 | * (C) 2017-2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 5 | * |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
Neels Hofmeyr | 5f2204a | 2018-02-16 16:07:02 +0100 | [diff] [blame] | 8 | * Author: Andreas Eversberg <jolly@eversberg.eu> |
| 9 | * Neels Hofmeyr <nhofmeyr@sysmocom.de> |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU Affero General Public License as published by |
| 13 | * the Free Software Foundation; either version 3 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU Affero General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Affero General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <osmocom/bsc/gsm_data.h> |
| 27 | #include <osmocom/bsc/vty.h> |
| 28 | #include <osmocom/bsc/handover_cfg.h> |
Neels Hofmeyr | 909e972 | 2017-12-07 03:54:01 +0100 | [diff] [blame] | 29 | #include <osmocom/bsc/handover_decision_2.h> |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 30 | |
| 31 | static struct handover_cfg *ho_cfg_from_vty(struct vty *vty) |
| 32 | { |
| 33 | switch (vty->node) { |
| 34 | case GSMNET_NODE: |
| 35 | return gsmnet_from_vty(vty)->ho; |
| 36 | case BTS_NODE: |
| 37 | OSMO_ASSERT(vty->index); |
| 38 | return ((struct gsm_bts *)vty->index)->ho; |
| 39 | default: |
| 40 | OSMO_ASSERT(false); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | |
| 45 | #define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, \ |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 46 | VTY_CMD_PREFIX, VTY_CMD, VTY_CMD_ARG, VTY_ARG_EVAL, \ |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 47 | VTY_WRITE_FMT, VTY_WRITE_CONV, \ |
| 48 | VTY_DOC) \ |
| 49 | DEFUN(cfg_ho_##NAME, cfg_ho_##NAME##_cmd, \ |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 50 | VTY_CMD_PREFIX VTY_CMD " (" VTY_CMD_ARG "|default)", \ |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 51 | VTY_DOC \ |
| 52 | "Use default (" #DEFAULT_VAL "), remove explicit setting on this node\n") \ |
| 53 | { \ |
| 54 | struct handover_cfg *ho = ho_cfg_from_vty(vty); \ |
| 55 | const char *val = argv[0]; \ |
| 56 | if (!strcmp(val, "default")) { \ |
| 57 | const char *msg; \ |
| 58 | if (ho_isset_##NAME(ho)) {\ |
| 59 | ho_clear_##NAME(ho); \ |
| 60 | msg = "setting removed, now is"; \ |
| 61 | } else \ |
| 62 | msg = "already was unset, still is"; \ |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 63 | vty_out(vty, "%% '" VTY_CMD_PREFIX VTY_CMD "' %s " VTY_WRITE_FMT "%s%s", \ |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 64 | msg, VTY_WRITE_CONV( ho_get_##NAME(ho) ), \ |
| 65 | ho_isset_on_parent_##NAME(ho)? " (set on higher level node)" : "", \ |
| 66 | VTY_NEWLINE); \ |
| 67 | } \ |
| 68 | else \ |
| 69 | ho_set_##NAME(ho, VTY_ARG_EVAL(val)); \ |
| 70 | return CMD_SUCCESS; \ |
| 71 | } |
| 72 | |
| 73 | HO_CFG_ALL_MEMBERS |
| 74 | #undef HO_CFG_ONE_MEMBER |
| 75 | |
| 76 | |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 77 | /* Aliases of 'handover' for 'handover1' for backwards compat */ |
| 78 | #define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, \ |
| 79 | VTY_CMD_PREFIX, VTY_CMD, VTY_CMD_ARG, VTY_ARG_EVAL, \ |
| 80 | VTY_WRITE_FMT, VTY_WRITE_CONV, \ |
| 81 | VTY_DOC) \ |
Neels Hofmeyr | bedbef4 | 2018-02-19 17:17:11 +0100 | [diff] [blame] | 82 | ALIAS_DEPRECATED(cfg_ho_##NAME, cfg_ho_##NAME##_cmd_alias, \ |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 83 | "handover " VTY_CMD " (" VTY_CMD_ARG "|default)", \ |
Neels Hofmeyr | bedbef4 | 2018-02-19 17:17:11 +0100 | [diff] [blame] | 84 | "Legacy alias for 'handover1': " VTY_DOC \ |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 85 | "Use default (" #DEFAULT_VAL "), remove explicit setting on this node\n"); |
| 86 | |
| 87 | HODEC1_CFG_ALL_MEMBERS |
| 88 | #undef HO_CFG_ONE_MEMBER |
| 89 | |
Neels Hofmeyr | 909e972 | 2017-12-07 03:54:01 +0100 | [diff] [blame] | 90 | static inline const int a2congestion_check_interval(const char *arg) |
| 91 | { |
| 92 | if (!strcmp(arg, "disabled")) |
| 93 | return 0; |
| 94 | return atoi(arg); |
| 95 | } |
| 96 | |
| 97 | static inline const char *congestion_check_interval2a(int val) |
| 98 | { |
| 99 | static char str[9]; |
| 100 | if (val < 1 |
| 101 | || snprintf(str, sizeof(str), "%d", val) >= sizeof(str)) |
| 102 | return "disabled"; |
| 103 | return str; |
| 104 | } |
| 105 | |
| 106 | DEFUN(cfg_net_ho_congestion_check_interval, cfg_net_ho_congestion_check_interval_cmd, |
| 107 | "handover2 congestion-check (disabled|<1-999>|now)", |
| 108 | HO_CFG_STR_HANDOVER2 |
| 109 | "Configure congestion check interval" HO_CFG_STR_2 |
| 110 | "Disable congestion checking, do not handover based on cell overload\n" |
| 111 | "Congestion check interval in seconds (default " |
| 112 | OSMO_STRINGIFY_VAL(HO_CFG_CONGESTION_CHECK_DEFAULT) ")\n" |
| 113 | "Manually trigger a congestion check to run right now\n") |
| 114 | { |
| 115 | if (!strcmp(argv[0], "now")) { |
| 116 | hodec2_congestion_check(gsmnet_from_vty(vty)); |
| 117 | return CMD_SUCCESS; |
| 118 | } |
| 119 | |
| 120 | hodec2_on_change_congestion_check_interval(gsmnet_from_vty(vty), |
| 121 | a2congestion_check_interval(argv[0])); |
| 122 | return CMD_SUCCESS; |
| 123 | } |
| 124 | |
Neels Hofmeyr | dfd36da | 2018-02-12 16:48:45 +0100 | [diff] [blame] | 125 | static void ho_vty_write(struct vty *vty, const char *indent, struct handover_cfg *ho) |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 126 | { |
| 127 | #define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, \ |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 128 | VTY_CMD_PREFIX, VTY_CMD, VTY_CMD_ARG, VTY_ARG_EVAL, \ |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 129 | VTY_WRITE_FMT, VTY_WRITE_CONV, \ |
| 130 | VTY_DOC) \ |
| 131 | if (ho_isset_##NAME(ho)) \ |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 132 | vty_out(vty, "%s" VTY_CMD_PREFIX VTY_CMD " " VTY_WRITE_FMT "%s", indent, \ |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 133 | VTY_WRITE_CONV( ho_get_##NAME(ho) ), VTY_NEWLINE); |
| 134 | |
| 135 | HO_CFG_ALL_MEMBERS |
| 136 | #undef HO_CFG_ONE_MEMBER |
| 137 | } |
| 138 | |
Neels Hofmeyr | dfd36da | 2018-02-12 16:48:45 +0100 | [diff] [blame] | 139 | void ho_vty_write_bts(struct vty *vty, struct gsm_bts *bts) |
| 140 | { |
| 141 | ho_vty_write(vty, " ", bts->ho); |
| 142 | } |
| 143 | |
| 144 | void ho_vty_write_net(struct vty *vty, struct gsm_network *net) |
| 145 | { |
| 146 | ho_vty_write(vty, " ", net->ho); |
| 147 | |
Neels Hofmeyr | 909e972 | 2017-12-07 03:54:01 +0100 | [diff] [blame] | 148 | if (net->hodec2.congestion_check_interval_s != HO_CFG_CONGESTION_CHECK_DEFAULT) |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 149 | vty_out(vty, " handover2 congestion-check %s%s", |
Neels Hofmeyr | 909e972 | 2017-12-07 03:54:01 +0100 | [diff] [blame] | 150 | congestion_check_interval2a(net->hodec2.congestion_check_interval_s), |
| 151 | VTY_NEWLINE); |
Neels Hofmeyr | dfd36da | 2018-02-12 16:48:45 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 154 | static void ho_vty_init_cmds(int parent_node) |
| 155 | { |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 156 | #define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, VTY0, VTY1, VTY2, VTY3, VTY4, VTY5, VTY6) \ |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 157 | install_element(parent_node, &cfg_ho_##NAME##_cmd); |
| 158 | |
| 159 | HO_CFG_ALL_MEMBERS |
| 160 | #undef HO_CFG_ONE_MEMBER |
Neels Hofmeyr | 444f9e2 | 2018-02-15 03:59:17 +0100 | [diff] [blame] | 161 | |
| 162 | /* Aliases of 'handover' for 'handover1' for backwards compat */ |
| 163 | #define HO_CFG_ONE_MEMBER(TYPE, NAME, DEFAULT_VAL, VTY0, VTY1, VTY2, VTY3, VTY4, VTY5, VTY6) \ |
| 164 | install_element(parent_node, &cfg_ho_##NAME##_cmd_alias); |
| 165 | |
| 166 | HODEC1_CFG_ALL_MEMBERS |
| 167 | #undef HO_CFG_ONE_MEMBER |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void ho_vty_init() |
| 171 | { |
| 172 | ho_vty_init_cmds(GSMNET_NODE); |
Neels Hofmeyr | 909e972 | 2017-12-07 03:54:01 +0100 | [diff] [blame] | 173 | install_element(GSMNET_NODE, &cfg_net_ho_congestion_check_interval_cmd); |
| 174 | |
Neels Hofmeyr | e25018b | 2017-11-27 21:29:33 +0100 | [diff] [blame] | 175 | ho_vty_init_cmds(BTS_NODE); |
| 176 | } |
| 177 | |