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

txbeacon.c (7584B)


      1 /*
      2  * 
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7  */
      8 
      9 #include <appl/diag/system.h>
     10 #include <appl/diag/parse.h>
     11 #include <shared/bsl.h>
     12 #include <bcm/error.h>
     13 #include <bcm/txbeacon.h>
     14 
     15 #define CLEAN_UP_AND_RETURN(_result) \
     16     parse_arg_eq_done(&parse_table); \
     17     return (_result);
     18 
     19 char cmd_esw_txbeacon_usage[] = 
     20 #ifdef COMPILER_STRING_CONST_LIMIT
     21     "Usage: txbeacon <option> [args...]\n"
     22 #else
     23     "\n"
     24     "  txbeacon init\n"
     25     "  txbeacon add [PORT=<id>] [FLAGS=<flags>] [LEN=<len>] [MAXLEN=<maxlen>]\n"
     26     "                   [PKTID=<pkt_id>] [INTERVAL=<int>] [COUNT=<count>]\n"
     27     "                   [DATA=<repeat val>]\n"
     28 #endif
     29     ;
     30 
     31 int
     32 _txb_cb(int unit, bcm_txbeacon_t *tx, void *user_data)
     33 {
     34     cli_out("Got user=%p pktid=%x flags=%x len=%x port=%x interval=%x count=%x pkt_data=%x\n",
     35             user_data, tx->pkt_id, tx->flags, tx->len, tx->port, tx->interval, tx->count, tx->pkt_data[0]);
     36     return (SOC_E_NONE);
     37 }
     38 
     39 cmd_result_t cmd_esw_txbeacon(int unit, args_t *args)
     40 {
     41     char *arg_string_p = NULL;
     42     parse_table_t parse_table;
     43     int result;
     44     
     45     arg_string_p = ARG_GET(args);
     46 
     47     if (arg_string_p == NULL) {
     48         return CMD_USAGE;
     49     }
     50 
     51     if (!sh_check_attached(ARG_CMD(args), unit)) {
     52         return CMD_FAIL;
     53     }
     54 
     55     if (sal_strcasecmp(arg_string_p, "init") == 0) {
     56         result = bcm_txbeacon_init(unit, 0);
     57 
     58         if (BCM_FAILURE(result)) {
     59             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
     60 
     61             return CMD_FAIL;
     62         }
     63 
     64         cli_out("TXBeacon module initialized.\n");
     65         
     66     } else if (sal_strcasecmp(arg_string_p, "add") == 0) {
     67         uint32 flags, len, maxlen, pkt_id, port, interval, count, data, i;
     68         bcm_txbeacon_t txb;
     69         parse_table_init(unit, &parse_table);
     70 
     71         parse_table_add(&parse_table, "FLAGS", PQ_INT,
     72                         0, &flags, NULL);
     73 
     74         parse_table_add(&parse_table, "LEN", PQ_INT,
     75                         0, &len, NULL);
     76 
     77         parse_table_add(&parse_table, "MAXLEN", PQ_INT,
     78                         0, &maxlen, NULL);
     79 
     80         parse_table_add(&parse_table, "PKT_ID", PQ_INT,
     81                         0, &pkt_id, NULL);
     82 
     83         parse_table_add(&parse_table, "PORT", PQ_INT,
     84                         0, &port, NULL);
     85 
     86         parse_table_add(&parse_table, "INTERVAL", PQ_INT,
     87                         0, &interval, NULL);
     88 
     89         parse_table_add(&parse_table, "COUNT", PQ_INT,
     90                         0, &count, NULL);
     91 
     92         parse_table_add(&parse_table, "DATA", PQ_INT,
     93                         0, &data, NULL);
     94 
     95         if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
     96         {
     97             cli_out("Invalid option: %s\n", ARG_CUR(args));
     98 
     99             CLEAN_UP_AND_RETURN(CMD_FAIL);
    100         }
    101 
    102         txb.flags = flags;
    103         txb.len = len;
    104         txb.maxlen = maxlen;
    105         txb.pkt_id = pkt_id;
    106         txb.port = port;
    107         txb.interval = interval;
    108         txb.count = count;
    109         
    110         txb.pkt_data = sal_alloc(len, "TXB test packet");
    111         for (i = 0; i < len; i++) {
    112             txb.pkt_data[i] = (data + i) & 0xff;
    113         } 
    114         
    115         result = bcm_txbeacon_pkt_setup(unit, &txb);
    116         
    117         if (BCM_FAILURE(result))
    118         {
    119             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
    120         
    121             CLEAN_UP_AND_RETURN(CMD_FAIL);
    122         }
    123 
    124         parse_arg_eq_done(&parse_table);
    125 
    126         sal_free(txb.pkt_data);
    127 
    128         return CMD_OK;            
    129 
    130     } else if (sal_strcasecmp(arg_string_p, "get") == 0) {
    131         uint32 maxlen, pkt_id;
    132         bcm_txbeacon_t txb;
    133         parse_table_init(unit, &parse_table);
    134 
    135         parse_table_add(&parse_table, "MAXLEN", PQ_INT,
    136                         0, &maxlen, NULL);
    137 
    138         parse_table_add(&parse_table, "PKT_ID", PQ_INT,
    139                         0, &pkt_id, NULL);
    140 
    141         if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    142         {
    143             cli_out("Invalid option: %s\n", ARG_CUR(args));
    144 
    145             CLEAN_UP_AND_RETURN(CMD_FAIL);
    146         }
    147 
    148         txb.maxlen = maxlen;
    149         txb.pkt_id = pkt_id;
    150         txb.pkt_data = sal_alloc(maxlen, "TXB test packet");
    151         
    152         result = bcm_txbeacon_pkt_get(unit, &txb);
    153         
    154         if (BCM_FAILURE(result))
    155         {
    156             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
    157         
    158             CLEAN_UP_AND_RETURN(CMD_FAIL);
    159         }
    160 
    161         cli_out("Got flags=%x len=%x port=%x interval=%x count=%x pkt_data=%x\n",
    162                 txb.flags, txb.len, txb.port, txb.interval, txb.count, txb.pkt_data[0]);
    163 
    164         parse_arg_eq_done(&parse_table);
    165 
    166         sal_free(txb.pkt_data);
    167         
    168         return CMD_OK;            
    169 
    170     } else if (sal_strcasecmp(arg_string_p, "start") == 0) {
    171         uint32 pkt_id;
    172         parse_table_init(unit, &parse_table);
    173 
    174         parse_table_add(&parse_table, "PKT_ID", PQ_INT,
    175                         0, &pkt_id, NULL);
    176 
    177         if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    178         {
    179             cli_out("Invalid option: %s\n", ARG_CUR(args));
    180 
    181             CLEAN_UP_AND_RETURN(CMD_FAIL);
    182         }
    183 
    184         
    185         result = bcm_txbeacon_start(unit, pkt_id);
    186         
    187         if (BCM_FAILURE(result))
    188         {
    189             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
    190         
    191             CLEAN_UP_AND_RETURN(CMD_FAIL);
    192         }
    193         parse_arg_eq_done(&parse_table);
    194 
    195         return CMD_OK;            
    196 
    197     } else if (sal_strcasecmp(arg_string_p, "stop") == 0) {
    198         uint32 pkt_id;
    199         parse_table_init(unit, &parse_table);
    200 
    201         parse_table_add(&parse_table, "PKT_ID", PQ_INT,
    202                         0, &pkt_id, NULL);
    203 
    204         if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    205         {
    206             cli_out("Invalid option: %s\n", ARG_CUR(args));
    207 
    208             CLEAN_UP_AND_RETURN(CMD_FAIL);
    209         }
    210 
    211         
    212         result = bcm_txbeacon_stop(unit, pkt_id);
    213         
    214         if (BCM_FAILURE(result))
    215         {
    216             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
    217         
    218             CLEAN_UP_AND_RETURN(CMD_FAIL);
    219         }
    220         parse_arg_eq_done(&parse_table);
    221 
    222         return CMD_OK;            
    223 
    224         
    225     } else if (sal_strcasecmp(arg_string_p, "destroy") == 0) {
    226         uint32 pkt_id;
    227         parse_table_init(unit, &parse_table);
    228 
    229         parse_table_add(&parse_table, "PKT_ID", PQ_INT,
    230                         0, &pkt_id, NULL);
    231 
    232         if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    233         {
    234             cli_out("Invalid option: %s\n", ARG_CUR(args));
    235 
    236             CLEAN_UP_AND_RETURN(CMD_FAIL);
    237         }
    238 
    239         
    240         result = bcm_txbeacon_destroy(unit, pkt_id);
    241         
    242         if (BCM_FAILURE(result))
    243         {
    244             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
    245         
    246             CLEAN_UP_AND_RETURN(CMD_FAIL);
    247         }
    248         parse_arg_eq_done(&parse_table);
    249 
    250         return CMD_OK;            
    251 
    252         
    253     } else if (sal_strcasecmp(arg_string_p, "scan") == 0) {
    254         
    255         result = bcm_txbeacon_traverse(unit, &_txb_cb, (void *) 123);
    256         
    257         if (BCM_FAILURE(result))
    258         {
    259             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
    260 
    261             return CMD_FAIL;
    262         }
    263 
    264         return CMD_OK;            
    265         
    266     } else {
    267         cli_out("Invalid TXBEACON subcommand: %s\n", arg_string_p);
    268 
    269         return CMD_FAIL;
    270     }
    271 
    272     return CMD_OK;
    273 }
    274