openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

stg.c (5261B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:     stg.c
      8  * Purpose:  BCMX STG CLI
      9  */
     10 
     11 #include <sal/appl/io.h>
     12 #include <shared/bsl.h>
     13 #include <bcm/vlan.h>
     14 #include <bcm/error.h>
     15 #include <bcmx/bcmx.h>
     16 #include <bcmx/stg.h>
     17 
     18 #include <appl/diag/shell.h>
     19 #include <appl/diag/system.h>
     20 #include <appl/diag/parse.h>
     21 
     22 #include "bcmx.h"
     23 #include <appl/diag/diag.h>
     24 
     25 char bcmx_cmd_stg_usage[] =
     26     "BCMX STG Usages:\n"
     27     "    stg {create | destroy} <stg id>     - Create/destroy a STG\n"
     28     "    stg add <stg id> <vlan_id> [...]    - Add VLAN(s) to STG\n"
     29     "    stg remove <stg id> <vlan_id> [...] - Remove VLAN(s) from STG\n"
     30     "    stg stp <stg id> <uport-list>       - Show STP state of port\n"
     31     "    stg default <stg id>                - Set default STG\n"
     32     "    stg show                            - Display STG info\n"
     33     "NOTE: Don't attempt to add VLAN 1 to STG groups!\n";
     34 
     35 #define _BAD_SID  -1
     36 
     37 cmd_result_t
     38 bcmx_cmd_stg(int unit, args_t *args)
     39 {
     40     char *subcmd, *ch;
     41     bcm_stg_t sid;
     42     vlan_id_t vid;
     43     int stp_state;
     44     int rv = BCM_E_NONE;
     45     cmd_result_t cmd_rv = CMD_OK;
     46 
     47     if ((subcmd = ARG_GET(args)) == NULL) {
     48         sal_printf("Subcommand required\n");
     49         return CMD_USAGE;
     50     }
     51 
     52     /* Get STG id */
     53     if ((ch = ARG_GET(args)) == NULL) {
     54         sid = _BAD_SID;
     55     } else {
     56         sid = parse_integer(ch);
     57     }
     58 
     59     /* stg create <stg id> */
     60     if (sal_strcasecmp(subcmd, "create") == 0) {
     61         if (sid == _BAD_SID) {
     62             sal_printf("STG: stg ID not specified\n");
     63             return CMD_FAIL;
     64         }
     65 
     66         rv = bcmx_stg_create_id(sid);
     67     } else if (sal_strcasecmp(subcmd, "destroy") == 0) {
     68         /* stg destroy <stg id> */
     69         if (sid == _BAD_SID) {
     70             sal_printf("STG: stg ID not specified\n");
     71             return CMD_FAIL;
     72         }
     73 
     74         rv = bcmx_stg_destroy(sid);
     75     } else if (sal_strcasecmp(subcmd, "add") == 0) {
     76         /* stg add <stg id> <vlan_id> [...] */
     77         if (sid == _BAD_SID) {
     78             sal_printf("STG: stg ID not specified\n");
     79             return CMD_FAIL;
     80         }
     81 
     82         while ((ch = ARG_GET(args)) != NULL) {
     83             vid = parse_integer(ch);
     84             rv = bcmx_stg_vlan_add(sid, vid);
     85             if (rv < 0) {
     86                 return CMD_FAIL;
     87             }
     88         }
     89     } else if (sal_strcasecmp(subcmd, "remove") == 0) {
     90         /* stg remove <stg id> <vlan_id> [...] */
     91         if (sid == _BAD_SID) {
     92             sal_printf("STG: stg ID not specified\n");
     93             return CMD_FAIL;
     94         }
     95 
     96         while ((ch = ARG_GET(args)) != NULL) {
     97             vid = parse_integer(ch);
     98             rv = bcmx_stg_vlan_remove(sid, vid);
     99             if (rv < 0) {
    100                 return CMD_FAIL;
    101             }
    102         }
    103     } else if (sal_strcasecmp(subcmd, "stp") == 0) {
    104         bcmx_lplist_t ports;
    105         int count;
    106         bcmx_lport_t lport;
    107 
    108         /* stg stp <stg id> <uport-list> */
    109         if (sid == _BAD_SID) {
    110             sal_printf("STG: stg ID not specified\n");
    111             return CMD_USAGE;
    112         }
    113 
    114         if ((ch = ARG_GET(args)) == NULL) {
    115             return CMD_USAGE;
    116         }
    117 
    118         bcmx_lplist_init(&ports, 0, 0);
    119 
    120         if (bcmx_lplist_parse(&ports, ch) < 0) {
    121             cli_out("%s: Error: could not parse portlist: %s\n",
    122                     ARG_CMD(args), ch);
    123         } else if (ports.lp_last < 0) {
    124             cli_out("No ports specified.\n");
    125         } else {
    126             BCMX_LPLIST_IDX_ITER(&ports, lport, count) {
    127                 rv = bcmx_stg_stp_get(sid, lport, &stp_state);
    128                 if (rv == BCM_E_NONE) {
    129                     sal_printf("port %s STP state for STG %d = %d\n",
    130                                bcmx_lport_to_uport_str(lport), sid, stp_state);
    131                 } else {
    132                     sal_printf("Error getting STP state for port %s. %s\n",
    133                                bcmx_lport_to_uport_str(lport), bcm_errmsg(rv));
    134                 }
    135             }
    136         }
    137         bcmx_lplist_free(&ports);
    138     } else if (sal_strcasecmp(subcmd, "default") == 0) {
    139         /* stg default <stg id> */
    140         if (sid == _BAD_SID) {
    141             sal_printf("STG: stg ID not specified\n");
    142             return CMD_USAGE;
    143         }
    144 
    145         rv = bcmx_stg_default_set(sid);
    146     } else if (sal_strcasecmp(subcmd, "show") == 0) {
    147         /* stg show */
    148         bcm_stg_t *stg_list;
    149         int count, i;
    150 
    151         /* show list of all STG */
    152         rv = bcmx_stg_list(&stg_list, &count);
    153         if (rv == 0) {
    154             sal_printf("Existing STGs:");
    155             for (i = 0; i < count; i++) {
    156                 sal_printf(" %d", stg_list[i]);
    157             }
    158             sal_printf("\n");
    159             rv = bcmx_stg_list_destroy(stg_list, count);
    160             if (rv != BCM_E_NONE) {
    161                 sal_printf("Error:  STG list destroy failed %d: %s\n",
    162                            rv, bcm_errmsg(rv));
    163                 rv = BCM_E_NONE;
    164             }
    165         }
    166     }
    167 
    168     if (rv < 0) {
    169         sal_printf("Error: Command returned %s\n", bcm_errmsg(rv));
    170         cmd_rv = CMD_FAIL;
    171     }
    172 
    173     return cmd_rv;
    174 }
    175