Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | <:copyright-BRCM:2016:DUAL/GPL:standard |
| 3 | |
| 4 | Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Unless you and Broadcom execute a separate written software license |
| 8 | agreement governing use of this software, this software is licensed |
| 9 | to you under the terms of the GNU General Public License version 2 |
| 10 | (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 11 | with the following added to such license: |
| 12 | |
| 13 | As a special exception, the copyright holders of this software give |
| 14 | you permission to link this software with independent modules, and |
| 15 | to copy and distribute the resulting executable under terms of your |
| 16 | choice, provided that you also meet, for each linked independent |
| 17 | module, the terms and conditions of the license of that module. |
| 18 | An independent module is a module which is not derived from this |
| 19 | software. The special exception does not apply to any modifications |
| 20 | of the software. |
| 21 | |
| 22 | Not withstanding the above, under no circumstances may you combine |
| 23 | this software in any way with any other Broadcom software provided |
| 24 | under a license other than the GPL, without Broadcom's express prior |
| 25 | written consent. |
| 26 | |
| 27 | :> |
| 28 | */ |
| 29 | |
| 30 | #include <bcmos_system.h> |
| 31 | #include <bcmcli.h> |
| 32 | #include "bcmolt_user_appl_ps_cli.h" |
| 33 | #include "bcmolt_user_appl_ps.h" |
| 34 | |
| 35 | static bcmos_errno ps_cmd_start(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| 36 | { |
| 37 | bcmcli_cmd_parm *parm; |
| 38 | bcmolt_ps_global_cfg cfg = {}; |
| 39 | |
| 40 | parm = bcmcli_find_named_parm(session, "max_pairs"); |
| 41 | if (parm != NULL) |
| 42 | { |
| 43 | cfg.max_num_pairs = (uint16_t)parm->value.number; |
| 44 | } |
| 45 | |
| 46 | parm = bcmcli_find_named_parm(session, "switch_condition"); |
| 47 | if (parm != NULL) |
| 48 | { |
| 49 | cfg.switch_condition = (bcmolt_ps_switch_condition)parm->value.number; |
| 50 | } |
| 51 | |
| 52 | parm = bcmcli_find_named_parm(session, "switch_sequence"); |
| 53 | if (parm != NULL) |
| 54 | { |
| 55 | cfg.switch_sequence = (bcmolt_ps_switch_sequence)parm->value.number; |
| 56 | } |
| 57 | |
| 58 | parm = bcmcli_find_named_parm(session, "mirror_mode"); |
| 59 | if (parm != NULL) |
| 60 | { |
| 61 | cfg.mirror_mode = (bcmolt_ps_mirror_mode)parm->value.number; |
| 62 | } |
| 63 | |
| 64 | parm = bcmcli_find_named_parm(session, "mirror_mac_entries"); |
| 65 | if (parm != NULL) |
| 66 | { |
| 67 | cfg.mirror_mac_entries = (bcmos_bool)parm->value.number; |
| 68 | } |
| 69 | |
| 70 | parm = bcmcli_find_named_parm(session, "static_mac_entries"); |
| 71 | if (parm != NULL) |
| 72 | { |
| 73 | cfg.static_mac_entries = (bcmos_bool)parm->value.number; |
| 74 | } |
| 75 | |
| 76 | parm = bcmcli_find_named_parm(session, "trx_warming_delay"); |
| 77 | if (parm != NULL) |
| 78 | { |
| 79 | cfg.trx_warming_delay = parm->value.number; |
| 80 | } |
| 81 | |
| 82 | return bcmolt_ps_appl_start(&cfg); |
| 83 | } |
| 84 | |
| 85 | static bcmos_errno ps_cmd_stop(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| 86 | { |
| 87 | return bcmolt_ps_appl_stop(); |
| 88 | } |
| 89 | |
| 90 | static bcmos_errno ps_cmd_get_cfg(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| 91 | { |
| 92 | bcmos_errno err; |
| 93 | bcmolt_ps_global_cfg cfg; |
| 94 | |
| 95 | err = bcmolt_ps_global_cfg_get(&cfg); |
| 96 | if (err != BCM_ERR_OK) |
| 97 | { |
| 98 | return err; |
| 99 | } |
| 100 | |
| 101 | bcmcli_session_print(session, "max_pairs=%d\n", cfg.max_num_pairs); |
| 102 | bcmcli_session_print( |
| 103 | session, |
| 104 | "switch_condition=%s\n", |
| 105 | cfg.switch_condition == BCMOLT_PS_SWITCH_CONDITION_LOS ? "los" : "manual"); |
| 106 | bcmcli_session_print( |
| 107 | session, |
| 108 | "switch_sequence=%s\n", |
| 109 | cfg.switch_sequence == BCMOLT_PS_SWITCH_SEQUENCE_STANDARD ? "std" : "trx_first"); |
| 110 | bcmcli_session_print( |
| 111 | session, |
| 112 | "mirror_mode=%s\n", |
| 113 | cfg.mirror_mode == BCMOLT_PS_MIRROR_MODE_AUTO ? "auto" : "none"); |
| 114 | bcmcli_session_print(session, "mirror_mac_entries=%s\n", cfg.mirror_mac_entries ? "yes" : "no"); |
| 115 | bcmcli_session_print(session, "static_mac_entries=%s\n", cfg.static_mac_entries ? "yes" : "no"); |
| 116 | bcmcli_session_print(session, "trx_warming_delay=%u\n", cfg.trx_warming_delay); |
| 117 | |
| 118 | return BCM_ERR_OK; |
| 119 | } |
| 120 | |
| 121 | static bcmos_errno ps_cmd_show_pairs(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| 122 | { |
| 123 | bcmos_errno err; |
| 124 | bcmolt_ps_global_cfg cfg; |
| 125 | bcmolt_ps_pair *pairs; |
| 126 | uint16_t num_written; |
| 127 | |
| 128 | err = bcmolt_ps_global_cfg_get(&cfg); |
| 129 | if (err != BCM_ERR_OK) |
| 130 | { |
| 131 | return err; |
| 132 | } |
| 133 | |
| 134 | pairs = bcmos_calloc(sizeof(*pairs) * cfg.max_num_pairs); |
| 135 | |
| 136 | err = bcmolt_ps_pairs_get(cfg.max_num_pairs, pairs, &num_written); |
| 137 | if (err == BCM_ERR_OK) |
| 138 | { |
| 139 | uint16_t i; |
| 140 | |
| 141 | bcmcli_session_print(session, " working | standby\n"); |
| 142 | bcmcli_session_print(session, " =========+=========\n"); |
| 143 | for (i = 0; i < num_written; i++) |
| 144 | { |
| 145 | bcmcli_session_print( |
| 146 | session, |
| 147 | "[%2d]: %2d.%2d.%2d | %2d.%2d.%2d\n", |
| 148 | i, |
| 149 | pairs[i].working.device_id, |
| 150 | pairs[i].working.pon_id, |
| 151 | pairs[i].working.transceiver_id, |
| 152 | pairs[i].standby.device_id, |
| 153 | pairs[i].standby.pon_id, |
| 154 | pairs[i].standby.transceiver_id); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | bcmos_free(pairs); |
| 159 | return err; |
| 160 | } |
| 161 | |
| 162 | static bcmos_errno ps_cmd_add_pair(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| 163 | { |
| 164 | bcmcli_cmd_parm *working_device = bcmcli_find_named_parm(session, "working.device"); |
| 165 | bcmcli_cmd_parm *working_pon = bcmcli_find_named_parm(session, "working.pon"); |
| 166 | bcmcli_cmd_parm *working_transceiver = bcmcli_find_named_parm(session, "working.transceiver"); |
| 167 | bcmcli_cmd_parm *standby_device = bcmcli_find_named_parm(session, "standby.device"); |
| 168 | bcmcli_cmd_parm *standby_pon = bcmcli_find_named_parm(session, "standby.pon"); |
| 169 | bcmcli_cmd_parm *standby_transceiver = bcmcli_find_named_parm(session, "standby.transceiver"); |
| 170 | |
| 171 | bcmolt_ps_pair pair = |
| 172 | { |
| 173 | .working = |
| 174 | { |
| 175 | .device_id = (bcmolt_devid)working_device->value.number, |
| 176 | .pon_id = (bcmolt_pon_ni)working_pon->value.number, |
| 177 | .transceiver_id = (bcmolt_pon_ni)working_transceiver->value.number |
| 178 | }, |
| 179 | .standby = |
| 180 | { |
| 181 | .device_id = (bcmolt_devid)standby_device->value.number, |
| 182 | .pon_id = (bcmolt_pon_ni)standby_pon->value.number, |
| 183 | .transceiver_id = (bcmolt_pon_ni)standby_transceiver->value.number |
| 184 | }, |
| 185 | }; |
| 186 | |
| 187 | // Set transceiver_id to pon_id if default |
| 188 | if (pair.working.transceiver_id == (bcmolt_pon_ni)-1) |
| 189 | { |
| 190 | pair.working.transceiver_id = pair.working.pon_id; |
| 191 | } |
| 192 | if (pair.standby.transceiver_id == (bcmolt_pon_ni)-1) |
| 193 | { |
| 194 | pair.standby.transceiver_id = pair.standby.pon_id; |
| 195 | } |
| 196 | |
| 197 | return bcmolt_ps_pair_add(&pair); |
| 198 | } |
| 199 | |
| 200 | static bcmos_errno ps_cmd_remove_pon(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| 201 | { |
| 202 | bcmcli_cmd_parm *device = bcmcli_find_named_parm(session, "device"); |
| 203 | bcmcli_cmd_parm *pon = bcmcli_find_named_parm(session, "pon"); |
| 204 | |
| 205 | bcmolt_ps_pon ps_pon = |
| 206 | { |
| 207 | .device_id = (bcmolt_devid)device->value.number, |
| 208 | .pon_id = (bcmolt_pon_ni)pon->value.number |
| 209 | }; |
| 210 | |
| 211 | return bcmolt_ps_pon_remove(&ps_pon); |
| 212 | } |
| 213 | |
| 214 | static bcmos_errno ps_cmd_perform_switch(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| 215 | { |
| 216 | bcmcli_cmd_parm *device = bcmcli_find_named_parm(session, "device"); |
| 217 | bcmcli_cmd_parm *pon = bcmcli_find_named_parm(session, "pon"); |
| 218 | |
| 219 | bcmolt_ps_pon ps_pon = |
| 220 | { |
| 221 | .device_id = (bcmolt_devid)device->value.number, |
| 222 | .pon_id = (bcmolt_pon_ni)pon->value.number |
| 223 | }; |
| 224 | |
| 225 | return bcmolt_ps_switch_perform(&ps_pon); |
| 226 | } |
| 227 | |
| 228 | bcmos_errno bcmolt_user_appl_ps_cli_init(bcmcli_entry *top_dir) |
| 229 | { |
| 230 | static bcmcli_enum_val switch_cond_table[] = |
| 231 | { |
| 232 | { .name = "los", .val = BCMOLT_PS_SWITCH_CONDITION_LOS }, |
| 233 | { .name = "manual", .val = BCMOLT_PS_SWITCH_CONDITION_MANUAL }, |
| 234 | BCMCLI_ENUM_LAST |
| 235 | }; |
| 236 | |
| 237 | static bcmcli_enum_val switch_seq_table[] = |
| 238 | { |
| 239 | { .name = "std", .val = BCMOLT_PS_SWITCH_SEQUENCE_STANDARD }, |
| 240 | { .name = "trx_first", .val = BCMOLT_PS_SWITCH_SEQUENCE_TRX_FIRST }, |
| 241 | BCMCLI_ENUM_LAST |
| 242 | }; |
| 243 | |
| 244 | static bcmcli_enum_val mirror_mode_table[] = |
| 245 | { |
| 246 | { .name = "auto", .val = BCMOLT_PS_MIRROR_MODE_AUTO }, |
| 247 | { .name = "none", .val = BCMOLT_PS_MIRROR_MODE_NONE }, |
| 248 | BCMCLI_ENUM_LAST |
| 249 | }; |
| 250 | |
| 251 | bcmcli_entry *dir = |
| 252 | bcmcli_dir_add(top_dir, "ps", "Protection switching user application", BCMCLI_ACCESS_ADMIN, NULL); |
| 253 | BCMOS_CHECK_RETURN_ERROR(!dir, BCM_ERR_NOMEM); |
| 254 | |
| 255 | BCMCLI_MAKE_CMD(dir, "start", "Start protection switching application", ps_cmd_start, |
| 256 | BCMCLI_MAKE_PARM("max_pairs", "Max number of protected pairs", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL), |
| 257 | BCMCLI_MAKE_PARM_ENUM("switch_condition", "Switch condition", switch_cond_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| 258 | BCMCLI_MAKE_PARM_ENUM("switch_sequence", "Switch sequence", switch_seq_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| 259 | BCMCLI_MAKE_PARM_ENUM("mirror_mode", "Mirror mode", mirror_mode_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| 260 | BCMCLI_MAKE_PARM_ENUM( |
| 261 | "mirror_mac_entries", "Mirror MAC entries", bcmcli_enum_bool_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| 262 | BCMCLI_MAKE_PARM_ENUM( |
| 263 | "static_mac_entries", "Static MAC entries", bcmcli_enum_bool_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| 264 | BCMCLI_MAKE_PARM("trx_warming_delay", "TRX warming delay (in usec)", BCMCLI_PARM_UDECIMAL, BCMCLI_PARM_FLAG_OPTIONAL)); |
| 265 | |
| 266 | BCMCLI_MAKE_CMD_NOPARM(dir, "stop", "Stop protection switching application", ps_cmd_stop); |
| 267 | |
| 268 | BCMCLI_MAKE_CMD_NOPARM(dir, "get_cfg", "Show running configuration parameters", ps_cmd_get_cfg); |
| 269 | |
| 270 | BCMCLI_MAKE_CMD_NOPARM(dir, "show_pairs", "Show current protected pairs", ps_cmd_show_pairs); |
| 271 | |
| 272 | BCMCLI_MAKE_CMD(dir, "add_pair", "Add protected pair", ps_cmd_add_pair, |
| 273 | BCMCLI_MAKE_PARM("working.device", "Device ID of the working PON", BCMCLI_PARM_NUMBER, 0), |
| 274 | BCMCLI_MAKE_PARM("working.pon", "PON NI of the working PON", BCMCLI_PARM_NUMBER, 0), |
| 275 | BCMCLI_MAKE_PARM_DEFVAL("working.transceiver", "Transceiver Id of the working PON", |
| 276 | BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, -1), |
| 277 | BCMCLI_MAKE_PARM("standby.device", "Device ID of the standby PON", BCMCLI_PARM_NUMBER, 0), |
| 278 | BCMCLI_MAKE_PARM("standby.pon", "PON NI of the standby PON", BCMCLI_PARM_NUMBER, 0), |
| 279 | BCMCLI_MAKE_PARM_DEFVAL("standby.transceiver", "Transceiver Id of the standby PON", |
| 280 | BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, -1)); |
| 281 | |
| 282 | BCMCLI_MAKE_CMD(dir, "remove_pon", "Remove protected pair for (either) PON", ps_cmd_remove_pon, |
| 283 | BCMCLI_MAKE_PARM("device", "Device ID of the either working/standby PON", BCMCLI_PARM_NUMBER, 0), |
| 284 | BCMCLI_MAKE_PARM("pon", "PON NI of the either working/standby PON", BCMCLI_PARM_NUMBER, 0)); |
| 285 | |
| 286 | BCMCLI_MAKE_CMD(dir, "perform_switch", "Perform protection switch manually", ps_cmd_perform_switch, |
| 287 | BCMCLI_MAKE_PARM("device", "Device ID of the either working/standby PON", BCMCLI_PARM_NUMBER, 0), |
| 288 | BCMCLI_MAKE_PARM("pon", "PON NI of the either working/standby PON", BCMCLI_PARM_NUMBER, 0)); |
| 289 | |
| 290 | return BCM_ERR_OK; |
| 291 | } |