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

bfd.c (8973B)


      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 #if defined(INCLUDE_BFD)
     10 
     11 #include <appl/diag/system.h>
     12 #include <appl/diag/parse.h>
     13 #include <shared/bsl.h>
     14 #include <bcm/error.h>
     15 #include <bcm/bfd.h>
     16 #include <bcm_int/esw/bfd.h>
     17 #include <bcm_int/esw/port.h>
     18 #if defined(BCM_ENDURO_SUPPORT)
     19 #include <bcm/rx.h>
     20 #include <soc/higig.h>
     21 #endif
     22 
     23 #define CLEAN_UP_AND_RETURN(_result) \
     24     parse_arg_eq_done(&parse_table); \
     25     return (_result);
     26 
     27 #define _isprintable(_c) (((_c) > 32) && ((_c) < 127))
     28 
     29 #define ENDPOINT_LIST_HEADER \
     30     "ID  Type  VRF  GPORT V6  IPADDR  DISCRIMINATOR  CpuPri  IntPri \n" \
     31     "--  ----  ---  ----- --  ------  -------------  ------  ------ \n"
     32 
     33 char cmd_esw_bfd_usage[] = 
     34 #ifdef COMPILER_STRING_CONST_LIMIT
     35     "Usage: bfd <option> [args...]\n"
     36 #else
     37     "\n"
     38     "  bfd init\n"
     39     "  bfd endpoint add [GPORT=<id>] [TYPE=<type>] [VRF=<id>] [INTPRI=<intpri>]\n"
     40     "                   [CPUPRI=<qid>] [DISCRIMINATOR=<id>] [V6] [IP=<val>]\n"
     41     "  bfd endpoint update [ID=<id>] [TYPE=<type>] [VRF=<id>] [INTPRI=<intpri>]\n"
     42     "                       [CPUPRI=<qid>] [DISCRIMINATOR=<id>] [V6] [IP=<val>]\n"
     43     "  bfd endpoint delete [ID=<id>]\n"
     44     "  bfd endpoint show [ID=<id>] \n"
     45 #if defined(BCM_KATANA_SUPPORT)
     46     "  bfd tx ID=<endpointid> \n"
     47 #endif
     48     "  bfd trace \n"
     49 #endif
     50     ;
     51 
     52 cmd_result_t cmd_esw_bfd(int unit, args_t *args)
     53 {
     54     char *arg_string_p = NULL;
     55     parse_table_t parse_table;
     56     bcm_bfd_endpoint_info_t endpoint_info;
     57     int int_pri;
     58     int result;
     59     int gport, type, vrf,qid, disc_id, v6, src_ip, dst_ip, label;
     60     
     61     arg_string_p = ARG_GET(args);
     62 
     63     if (arg_string_p == NULL)
     64     {
     65         return CMD_USAGE;
     66     }
     67 
     68     if (!sh_check_attached(ARG_CMD(args), unit))
     69     {
     70         return CMD_FAIL;
     71     }
     72 
     73     if (sal_strcasecmp(arg_string_p, "init") == 0)
     74     {
     75         result = bcm_bfd_init(unit);
     76 
     77         if (BCM_FAILURE(result))
     78         {
     79             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
     80 
     81             return CMD_FAIL;
     82         }
     83 
     84         cli_out("BFD module initialized.\n");
     85     }
     86     
     87 #if defined(BCM_KATANA_SUPPORT)
     88     else if (sal_strcasecmp(arg_string_p, "tx") == 0)
     89     {    
     90 #if 0
     91         parse_table_init(unit, &parse_table);
     92 
     93         parse_table_add(&parse_table, "ID", PQ_INT,
     94             (void *) BCM_OAM_GROUP_INVALID, &endpoint_info.id, NULL);
     95 
     96         parse_table_add(&parse_table, "DMAC", PQ_MAC | PQ_DFL, 0,
     97                 &mac_dst, NULL);
     98 
     99         parse_table_add(&parse_table, "SMAC", PQ_MAC | PQ_DFL, 0,
    100                 &mac_src, NULL);
    101 
    102         if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    103         {
    104             cli_out("Invalid option: %s\n", ARG_CUR(args));
    105 
    106             CLEAN_UP_AND_RETURN(CMD_FAIL);
    107         }
    108 
    109         result = bcm_bfd_endpoint_get(unit, endpoint_info.id, &endpoint_info);
    110         
    111         if (BCM_FAILURE(result))
    112         {
    113             cli_out("Command failed.  %s.\n", bcm_errmsg(result));
    114         
    115             CLEAN_UP_AND_RETURN(CMD_FAIL);
    116         }
    117 
    118         parse_arg_eq_done(&parse_table);
    119 #endif
    120     }
    121 #endif /* BCM_KATANA_SUPPORT */
    122     else if (sal_strcasecmp(arg_string_p, "endpoint") == 0)
    123     {
    124         arg_string_p = ARG_GET(args);
    125 
    126         bcm_bfd_endpoint_info_t_init(&endpoint_info);
    127 
    128         if (arg_string_p == NULL ||
    129             sal_strcasecmp(arg_string_p, "show") == 0)
    130         {
    131             parse_table_init(unit, &parse_table);
    132             
    133             parse_table_add(&parse_table, "ID", PQ_INT,
    134 			(void *) BCM_BFD_ENDPOINT_INVALID, &endpoint_info.id, NULL);
    135 
    136             if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    137             {
    138                 cli_out("Invalid option: %s\n", ARG_CUR(args));
    139 
    140                 CLEAN_UP_AND_RETURN(CMD_FAIL);
    141             }
    142             
    143             result = bcm_bfd_endpoint_get(unit, endpoint_info.id, &endpoint_info);
    144             if (BCM_FAILURE(result))
    145             {
    146                 cli_out("Command failed. %s\n", bcm_errmsg(result));
    147 
    148                 CLEAN_UP_AND_RETURN(CMD_FAIL);
    149             }
    150 
    151 	    cli_out(ENDPOINT_LIST_HEADER);
    152 
    153 	    cli_out("%1d  ", endpoint_info.id);
    154 	    cli_out("%4d  ", endpoint_info.type);
    155             cli_out("%4d  ", endpoint_info.vrf_id);
    156 	    cli_out("%4d  ", endpoint_info.gport);
    157 	    cli_out("%2d  ", ((endpoint_info.flags & BCM_BFD_ENDPOINT_IPV6) != 0));
    158 	    cli_out("0x%x ",  endpoint_info.src_ip_addr);
    159 	    cli_out("0x%x ",  endpoint_info.dst_ip_addr);
    160 	    cli_out("%10d ",  endpoint_info.local_discr);
    161 	    cli_out("%12d ",  endpoint_info.cpu_qid);
    162 	    cli_out("%6d \n",  endpoint_info.int_pri);
    163 
    164             CLEAN_UP_AND_RETURN(CMD_OK);
    165 
    166         }
    167         else if (sal_strcasecmp(arg_string_p, "delete") == 0)
    168         {
    169             parse_table_init(unit, &parse_table);
    170 
    171             parse_table_add(&parse_table, "ID", PQ_INT,
    172                 (void *) BCM_BFD_ENDPOINT_INVALID, &endpoint_info.id, NULL);
    173 
    174             if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    175             {
    176                 cli_out("Invalid option: %s\n", ARG_CUR(args));
    177 
    178                 CLEAN_UP_AND_RETURN(CMD_FAIL);
    179             }
    180 
    181             result = bcm_bfd_endpoint_destroy(unit, endpoint_info.id);
    182             
    183             if (BCM_FAILURE(result))
    184             {
    185                 cli_out("Command failed. %s\n", bcm_errmsg(result));
    186 
    187                 CLEAN_UP_AND_RETURN(CMD_FAIL);
    188             }
    189 
    190             CLEAN_UP_AND_RETURN(CMD_OK);
    191         }
    192         else
    193         {
    194             bcm_bfd_endpoint_info_t_init(&endpoint_info);
    195 
    196             if (sal_strcasecmp(arg_string_p, "update") == 0)
    197             {
    198                 endpoint_info.flags |= BCM_BFD_ENDPOINT_UPDATE;
    199             }
    200             else if (sal_strcasecmp(arg_string_p, "add") != 0)
    201             {
    202                 cli_out("Invalid BFD endpoint command: %s\n", arg_string_p);
    203 
    204                 return CMD_FAIL;
    205             }
    206           
    207             parse_table_init(unit, &parse_table);
    208 
    209             parse_table_add(&parse_table, "ID", PQ_INT,
    210                (void *) BCM_BFD_ENDPOINT_INVALID, &endpoint_info.id, NULL);
    211 
    212             parse_table_add(&parse_table, "GPORT", PQ_INT,
    213                 0, &gport, NULL);
    214             parse_table_add(&parse_table, "TYPE", PQ_INT,
    215                 0, &type, NULL);
    216             parse_table_add(&parse_table, "VRF", PQ_INT,
    217                 0, &vrf, NULL);
    218             parse_table_add(&parse_table, "INTPRI", PQ_INT, 
    219                 0, &int_pri, NULL);
    220             parse_table_add(&parse_table, "CPUPRI", PQ_INT, 
    221                 0, &qid, NULL);
    222             parse_table_add(&parse_table, "DISCRIMINATOR", PQ_INT, 
    223                 0, &disc_id, NULL);
    224             parse_table_add(&parse_table, "V6", PQ_INT, 
    225                 0, &v6, NULL);
    226             parse_table_add(&parse_table, "SIP", PQ_INT, 
    227                 0, &src_ip, NULL);            
    228             parse_table_add(&parse_table, "DIP", PQ_INT, 
    229                 0, &dst_ip, NULL);            
    230             parse_table_add(&parse_table, "LABEL", PQ_INT, 
    231                 0, &label, NULL);            
    232 
    233             if (parse_arg_eq(args, &parse_table) < 0 || ARG_CNT(args) > 0)
    234             {
    235                 cli_out("Invalid option: %s\n", ARG_CUR(args));
    236 
    237                 CLEAN_UP_AND_RETURN(CMD_FAIL);
    238             }
    239 
    240             if (endpoint_info.id != BCM_BFD_ENDPOINT_INVALID)
    241             {
    242                 endpoint_info.flags |= BCM_BFD_ENDPOINT_WITH_ID;
    243             }
    244 
    245             if (v6) {
    246                 endpoint_info.flags |= BCM_BFD_ENDPOINT_IPV6;
    247             }
    248 
    249             if (int_pri < 0)
    250             {
    251                  cli_out("An internal priority is required.\n");
    252 
    253                  CLEAN_UP_AND_RETURN(CMD_FAIL);
    254             }
    255 
    256             endpoint_info.gport = BCM_GPORT_LOCAL_SET(gport, gport);
    257             endpoint_info.type = type;
    258             endpoint_info.vrf_id = vrf;
    259             endpoint_info.local_discr = disc_id;
    260             endpoint_info.cpu_qid = qid;
    261             endpoint_info.int_pri = int_pri;
    262             endpoint_info.label = label;
    263             endpoint_info.src_ip_addr = src_ip;
    264             endpoint_info.dst_ip_addr = dst_ip;
    265 
    266             result = bcm_bfd_endpoint_create(unit, &endpoint_info);
    267 
    268             if (BCM_FAILURE(result))
    269             {
    270                 cli_out("Command failed. %s\n", bcm_errmsg(result));
    271 
    272                 CLEAN_UP_AND_RETURN(CMD_FAIL);
    273             }
    274 
    275             parse_arg_eq_done(&parse_table);
    276             
    277             cli_out("BFD endpoint %d created.\n", endpoint_info.id);
    278           }
    279 
    280         }
    281     else if (sal_strcasecmp(arg_string_p, "trace") == 0) {
    282         _bcm_bfd_dump_trace(unit);
    283     }
    284     else
    285     {
    286         cli_out("Invalid BFD subcommand: %s\n", arg_string_p);
    287 
    288         return CMD_FAIL;
    289     }
    290 
    291     return CMD_OK;
    292 }
    293 
    294 #else
    295     int  __no_complilation_complaints_about_bfd__1;
    296 #endif /* INCLUDE_BFD */