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

trunk.c (3847B)


      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:     trunk.c
      8  * Purpose:  BCMX trunking commands
      9  */
     10 
     11 #include <sal/appl/io.h>
     12 
     13 #include <bcm/trunk.h>
     14 
     15 #include <bcm/error.h>
     16 #include <bcmx/bcmx.h>
     17 #include <bcmx/trunk.h>
     18 
     19 #include <appl/diag/shell.h>
     20 #include <appl/diag/system.h>
     21 #include <appl/diag/parse.h>
     22 
     23 #include "bcmx.h"
     24 #include <appl/diag/diag.h>
     25 
     26 char bcmx_cmd_trunk_usage[] =
     27     "BCMX Trunk Usages:\n"
     28     "    trunk create <tid>               - Create a trunk\n"
     29     "    trunk destroy <tid>              - Destroy a trunk\n"
     30     "    trunk set <tid> <uport-list>     - Add ports to a trunk\n"
     31     "    trunk show <tid>                 - Display trunk information\n";
     32 
     33 cmd_result_t
     34 bcmx_cmd_trunk(int unit, args_t *args)
     35 {
     36     char *subcmd, *ch;
     37     bcmx_trunk_add_info_t tai;
     38     int lplist_given, tid;
     39     int rv = BCM_E_NONE;
     40 
     41     if ((subcmd = ARG_GET(args)) == NULL) {
     42         sal_printf("%s: Subcommand required\n", ARG_CMD(args));
     43         return CMD_USAGE;
     44     }
     45 
     46     if ((ch = ARG_GET(args)) == NULL) {
     47         sal_printf("%s: trunk ID not specified\n", ARG_CMD(args));
     48         return CMD_FAIL;
     49     } else {
     50         tid = parse_integer(ch);
     51     }
     52 
     53     bcmx_trunk_add_info_t_init(&tai);
     54 
     55     if ((ch = ARG_GET(args)) == NULL) {
     56         lplist_given = 0;
     57     } else {
     58         if (bcmx_lplist_parse(&tai.ports, ch) < 0) {
     59             sal_printf("%s: could not parse plist: %s\n", ARG_CMD(args), ch);
     60             bcmx_trunk_add_info_t_free(&tai);
     61             return CMD_FAIL;
     62         }
     63 	lplist_given = 1;
     64     }
     65 
     66     if (sal_strcasecmp(subcmd, "create") == 0) {
     67 	if (tid < 0) {
     68 	    rv = bcmx_trunk_create(&tid);
     69 	    if (rv >= 0) {
     70 		sal_printf("%s: trunk %d created\n", ARG_CMD(args), tid);
     71 	    }
     72 	} else {
     73 	    rv = bcmx_trunk_create_id(tid);
     74 	}
     75         goto done;
     76     }
     77 
     78     if (sal_strcasecmp(subcmd, "destroy") == 0) {
     79         rv = bcmx_trunk_destroy(tid);
     80         goto done;
     81     }
     82 
     83     if (sal_strcasecmp(subcmd, "set") == 0) {
     84         if (!lplist_given) {
     85             sal_printf("%s: Bad port list or not specified\n", ARG_CMD(args));
     86             bcmx_trunk_add_info_t_free(&tai);
     87             return CMD_USAGE;
     88         }
     89 
     90 	/* default lots of things, lets bcm trunk code choose */
     91         tai.psc = -1;
     92         tai.dlf_port = BCMX_LPORT_INVALID;
     93         tai.mc_port = BCMX_LPORT_INVALID;
     94         tai.ipmc_port = BCMX_LPORT_INVALID;
     95 
     96         rv = bcmx_trunk_set(tid, &tai);
     97 
     98         goto done;
     99     }
    100 
    101     if (sal_strcasecmp(subcmd, "show") == 0) {
    102         bcmx_lplist_free(&tai.ports);
    103 
    104         if ((rv = bcmx_trunk_get(tid, &tai)) == BCM_E_NONE) {
    105             bcmx_lport_t  lport;
    106             int           count;
    107 
    108             sal_printf("trunk %d psc=%d ", tid, tai.psc);
    109             sal_printf("dlf=%s ", bcmx_lport_to_uport_str(tai.dlf_port));
    110             sal_printf("mc=%s ", bcmx_lport_to_uport_str(tai.mc_port));
    111             sal_printf("ipmc=%s ", bcmx_lport_to_uport_str(tai.ipmc_port));
    112 
    113             sal_printf("uports=");
    114             BCMX_LPLIST_ITER(tai.ports, lport, count) {
    115                 sal_printf("%s%s", count == 0 ? "" : ",",
    116                            bcmx_lport_to_uport_str(lport));
    117             }
    118             if (count == 0) {
    119                 sal_printf("none\n");
    120             } else {
    121                 sal_printf("\n");
    122             }
    123         }
    124         goto done;
    125     }
    126 
    127     sal_printf("%s: ERROR: unknown subcommand: %s\n", ARG_CMD(args), subcmd);
    128     bcmx_lplist_free(&tai.ports);
    129     return CMD_USAGE;
    130 	
    131  done:
    132     if (rv < 0) {
    133         sal_printf("%s: ERROR: %s\n", ARG_CMD(args), bcm_errmsg(rv));
    134         bcmx_trunk_add_info_t_free(&tai);
    135 	    return CMD_FAIL;
    136     }
    137 
    138     bcmx_trunk_add_info_t_free(&tai);
    139 
    140     return CMD_OK;
    141 }