| /* |
| <:copyright-BRCM:2016:DUAL/GPL:standard |
| |
| Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| All Rights Reserved |
| |
| Unless you and Broadcom execute a separate written software license |
| agreement governing use of this software, this software is licensed |
| to you under the terms of the GNU General Public License version 2 |
| (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| with the following added to such license: |
| |
| As a special exception, the copyright holders of this software give |
| you permission to link this software with independent modules, and |
| to copy and distribute the resulting executable under terms of your |
| choice, provided that you also meet, for each linked independent |
| module, the terms and conditions of the license of that module. |
| An independent module is a module which is not derived from this |
| software. The special exception does not apply to any modifications |
| of the software. |
| |
| Not withstanding the above, under no circumstances may you combine |
| this software in any way with any other Broadcom software provided |
| under a license other than the GPL, without Broadcom's express prior |
| written consent. |
| |
| :> |
| */ |
| |
| #include <bcmos_system.h> |
| #include <bcmcli.h> |
| #include "bcmolt_user_appl_ps_cli.h" |
| #include "bcmolt_user_appl_ps.h" |
| |
| static bcmos_errno ps_cmd_start(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| { |
| bcmcli_cmd_parm *parm; |
| bcmolt_ps_global_cfg cfg = {}; |
| |
| parm = bcmcli_find_named_parm(session, "max_pairs"); |
| if (parm != NULL) |
| { |
| cfg.max_num_pairs = (uint16_t)parm->value.number; |
| } |
| |
| parm = bcmcli_find_named_parm(session, "switch_condition"); |
| if (parm != NULL) |
| { |
| cfg.switch_condition = (bcmolt_ps_switch_condition)parm->value.number; |
| } |
| |
| parm = bcmcli_find_named_parm(session, "switch_sequence"); |
| if (parm != NULL) |
| { |
| cfg.switch_sequence = (bcmolt_ps_switch_sequence)parm->value.number; |
| } |
| |
| parm = bcmcli_find_named_parm(session, "mirror_mode"); |
| if (parm != NULL) |
| { |
| cfg.mirror_mode = (bcmolt_ps_mirror_mode)parm->value.number; |
| } |
| |
| parm = bcmcli_find_named_parm(session, "mirror_mac_entries"); |
| if (parm != NULL) |
| { |
| cfg.mirror_mac_entries = (bcmos_bool)parm->value.number; |
| } |
| |
| parm = bcmcli_find_named_parm(session, "static_mac_entries"); |
| if (parm != NULL) |
| { |
| cfg.static_mac_entries = (bcmos_bool)parm->value.number; |
| } |
| |
| parm = bcmcli_find_named_parm(session, "trx_warming_delay"); |
| if (parm != NULL) |
| { |
| cfg.trx_warming_delay = parm->value.number; |
| } |
| |
| return bcmolt_ps_appl_start(&cfg); |
| } |
| |
| static bcmos_errno ps_cmd_stop(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| { |
| return bcmolt_ps_appl_stop(); |
| } |
| |
| static bcmos_errno ps_cmd_get_cfg(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| { |
| bcmos_errno err; |
| bcmolt_ps_global_cfg cfg; |
| |
| err = bcmolt_ps_global_cfg_get(&cfg); |
| if (err != BCM_ERR_OK) |
| { |
| return err; |
| } |
| |
| bcmcli_session_print(session, "max_pairs=%d\n", cfg.max_num_pairs); |
| bcmcli_session_print( |
| session, |
| "switch_condition=%s\n", |
| cfg.switch_condition == BCMOLT_PS_SWITCH_CONDITION_LOS ? "los" : "manual"); |
| bcmcli_session_print( |
| session, |
| "switch_sequence=%s\n", |
| cfg.switch_sequence == BCMOLT_PS_SWITCH_SEQUENCE_STANDARD ? "std" : "trx_first"); |
| bcmcli_session_print( |
| session, |
| "mirror_mode=%s\n", |
| cfg.mirror_mode == BCMOLT_PS_MIRROR_MODE_AUTO ? "auto" : "none"); |
| bcmcli_session_print(session, "mirror_mac_entries=%s\n", cfg.mirror_mac_entries ? "yes" : "no"); |
| bcmcli_session_print(session, "static_mac_entries=%s\n", cfg.static_mac_entries ? "yes" : "no"); |
| bcmcli_session_print(session, "trx_warming_delay=%u\n", cfg.trx_warming_delay); |
| |
| return BCM_ERR_OK; |
| } |
| |
| static bcmos_errno ps_cmd_show_pairs(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| { |
| bcmos_errno err; |
| bcmolt_ps_global_cfg cfg; |
| bcmolt_ps_pair *pairs; |
| uint16_t num_written; |
| |
| err = bcmolt_ps_global_cfg_get(&cfg); |
| if (err != BCM_ERR_OK) |
| { |
| return err; |
| } |
| |
| pairs = bcmos_calloc(sizeof(*pairs) * cfg.max_num_pairs); |
| |
| err = bcmolt_ps_pairs_get(cfg.max_num_pairs, pairs, &num_written); |
| if (err == BCM_ERR_OK) |
| { |
| uint16_t i; |
| |
| bcmcli_session_print(session, " working | standby\n"); |
| bcmcli_session_print(session, " =========+=========\n"); |
| for (i = 0; i < num_written; i++) |
| { |
| bcmcli_session_print( |
| session, |
| "[%2d]: %2d.%2d.%2d | %2d.%2d.%2d\n", |
| i, |
| pairs[i].working.device_id, |
| pairs[i].working.pon_id, |
| pairs[i].working.transceiver_id, |
| pairs[i].standby.device_id, |
| pairs[i].standby.pon_id, |
| pairs[i].standby.transceiver_id); |
| } |
| } |
| |
| bcmos_free(pairs); |
| return err; |
| } |
| |
| static bcmos_errno ps_cmd_add_pair(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| { |
| bcmcli_cmd_parm *working_device = bcmcli_find_named_parm(session, "working.device"); |
| bcmcli_cmd_parm *working_pon = bcmcli_find_named_parm(session, "working.pon"); |
| bcmcli_cmd_parm *working_transceiver = bcmcli_find_named_parm(session, "working.transceiver"); |
| bcmcli_cmd_parm *standby_device = bcmcli_find_named_parm(session, "standby.device"); |
| bcmcli_cmd_parm *standby_pon = bcmcli_find_named_parm(session, "standby.pon"); |
| bcmcli_cmd_parm *standby_transceiver = bcmcli_find_named_parm(session, "standby.transceiver"); |
| |
| bcmolt_ps_pair pair = |
| { |
| .working = |
| { |
| .device_id = (bcmolt_devid)working_device->value.number, |
| .pon_id = (bcmolt_pon_ni)working_pon->value.number, |
| .transceiver_id = (bcmolt_pon_ni)working_transceiver->value.number |
| }, |
| .standby = |
| { |
| .device_id = (bcmolt_devid)standby_device->value.number, |
| .pon_id = (bcmolt_pon_ni)standby_pon->value.number, |
| .transceiver_id = (bcmolt_pon_ni)standby_transceiver->value.number |
| }, |
| }; |
| |
| // Set transceiver_id to pon_id if default |
| if (pair.working.transceiver_id == (bcmolt_pon_ni)-1) |
| { |
| pair.working.transceiver_id = pair.working.pon_id; |
| } |
| if (pair.standby.transceiver_id == (bcmolt_pon_ni)-1) |
| { |
| pair.standby.transceiver_id = pair.standby.pon_id; |
| } |
| |
| return bcmolt_ps_pair_add(&pair); |
| } |
| |
| static bcmos_errno ps_cmd_remove_pon(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| { |
| bcmcli_cmd_parm *device = bcmcli_find_named_parm(session, "device"); |
| bcmcli_cmd_parm *pon = bcmcli_find_named_parm(session, "pon"); |
| |
| bcmolt_ps_pon ps_pon = |
| { |
| .device_id = (bcmolt_devid)device->value.number, |
| .pon_id = (bcmolt_pon_ni)pon->value.number |
| }; |
| |
| return bcmolt_ps_pon_remove(&ps_pon); |
| } |
| |
| static bcmos_errno ps_cmd_perform_switch(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms) |
| { |
| bcmcli_cmd_parm *device = bcmcli_find_named_parm(session, "device"); |
| bcmcli_cmd_parm *pon = bcmcli_find_named_parm(session, "pon"); |
| |
| bcmolt_ps_pon ps_pon = |
| { |
| .device_id = (bcmolt_devid)device->value.number, |
| .pon_id = (bcmolt_pon_ni)pon->value.number |
| }; |
| |
| return bcmolt_ps_switch_perform(&ps_pon); |
| } |
| |
| bcmos_errno bcmolt_user_appl_ps_cli_init(bcmcli_entry *top_dir) |
| { |
| static bcmcli_enum_val switch_cond_table[] = |
| { |
| { .name = "los", .val = BCMOLT_PS_SWITCH_CONDITION_LOS }, |
| { .name = "manual", .val = BCMOLT_PS_SWITCH_CONDITION_MANUAL }, |
| BCMCLI_ENUM_LAST |
| }; |
| |
| static bcmcli_enum_val switch_seq_table[] = |
| { |
| { .name = "std", .val = BCMOLT_PS_SWITCH_SEQUENCE_STANDARD }, |
| { .name = "trx_first", .val = BCMOLT_PS_SWITCH_SEQUENCE_TRX_FIRST }, |
| BCMCLI_ENUM_LAST |
| }; |
| |
| static bcmcli_enum_val mirror_mode_table[] = |
| { |
| { .name = "auto", .val = BCMOLT_PS_MIRROR_MODE_AUTO }, |
| { .name = "none", .val = BCMOLT_PS_MIRROR_MODE_NONE }, |
| BCMCLI_ENUM_LAST |
| }; |
| |
| bcmcli_entry *dir = |
| bcmcli_dir_add(top_dir, "ps", "Protection switching user application", BCMCLI_ACCESS_ADMIN, NULL); |
| BCMOS_CHECK_RETURN_ERROR(!dir, BCM_ERR_NOMEM); |
| |
| BCMCLI_MAKE_CMD(dir, "start", "Start protection switching application", ps_cmd_start, |
| BCMCLI_MAKE_PARM("max_pairs", "Max number of protected pairs", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_ENUM("switch_condition", "Switch condition", switch_cond_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_ENUM("switch_sequence", "Switch sequence", switch_seq_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_ENUM("mirror_mode", "Mirror mode", mirror_mode_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_ENUM( |
| "mirror_mac_entries", "Mirror MAC entries", bcmcli_enum_bool_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_ENUM( |
| "static_mac_entries", "Static MAC entries", bcmcli_enum_bool_table, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM("trx_warming_delay", "TRX warming delay (in usec)", BCMCLI_PARM_UDECIMAL, BCMCLI_PARM_FLAG_OPTIONAL)); |
| |
| BCMCLI_MAKE_CMD_NOPARM(dir, "stop", "Stop protection switching application", ps_cmd_stop); |
| |
| BCMCLI_MAKE_CMD_NOPARM(dir, "get_cfg", "Show running configuration parameters", ps_cmd_get_cfg); |
| |
| BCMCLI_MAKE_CMD_NOPARM(dir, "show_pairs", "Show current protected pairs", ps_cmd_show_pairs); |
| |
| BCMCLI_MAKE_CMD(dir, "add_pair", "Add protected pair", ps_cmd_add_pair, |
| BCMCLI_MAKE_PARM("working.device", "Device ID of the working PON", BCMCLI_PARM_NUMBER, 0), |
| BCMCLI_MAKE_PARM("working.pon", "PON NI of the working PON", BCMCLI_PARM_NUMBER, 0), |
| BCMCLI_MAKE_PARM_DEFVAL("working.transceiver", "Transceiver Id of the working PON", |
| BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, -1), |
| BCMCLI_MAKE_PARM("standby.device", "Device ID of the standby PON", BCMCLI_PARM_NUMBER, 0), |
| BCMCLI_MAKE_PARM("standby.pon", "PON NI of the standby PON", BCMCLI_PARM_NUMBER, 0), |
| BCMCLI_MAKE_PARM_DEFVAL("standby.transceiver", "Transceiver Id of the standby PON", |
| BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, -1)); |
| |
| BCMCLI_MAKE_CMD(dir, "remove_pon", "Remove protected pair for (either) PON", ps_cmd_remove_pon, |
| BCMCLI_MAKE_PARM("device", "Device ID of the either working/standby PON", BCMCLI_PARM_NUMBER, 0), |
| BCMCLI_MAKE_PARM("pon", "PON NI of the either working/standby PON", BCMCLI_PARM_NUMBER, 0)); |
| |
| BCMCLI_MAKE_CMD(dir, "perform_switch", "Perform protection switch manually", ps_cmd_perform_switch, |
| BCMCLI_MAKE_PARM("device", "Device ID of the either working/standby PON", BCMCLI_PARM_NUMBER, 0), |
| BCMCLI_MAKE_PARM("pon", "PON NI of the either working/standby PON", BCMCLI_PARM_NUMBER, 0)); |
| |
| return BCM_ERR_OK; |
| } |