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

mpls.c (45648B)


      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  * MPLS CLI commands
      8  */
      9 
     10 #include <appl/diag/system.h>
     11 #include <appl/diag/parse.h>
     12 #include <shared/bsl.h>
     13 #include <soc/debug.h>
     14 #if defined(BCM_TRIUMPH_SUPPORT)
     15 #include <soc/triumph.h>
     16 #endif /* BCM_TRIUMPH_SUPPORT */
     17 
     18 #include <bcm/error.h>
     19 #include <bcm/debug.h>
     20 #include <bcm/l3.h>
     21 #include <bcm/mpls.h>
     22 #include <bcm/l2.h>
     23 #include <bcm_int/esw/l3.h>
     24 #include <bcm_int/esw/port.h>
     25 #include <bcm_int/esw/mpls.h>
     26 
     27 #ifdef INCLUDE_L3
     28 
     29 #if defined(BCM_TRIUMPH_SUPPORT)
     30 
     31 #define ENV_VPN_TYPE_ID "vpn_type_id"
     32 #define ENV_MPLS_TYPE_ID "mpls_port_id"
     33 #define ENV_MCAST_TYPE_ID "mcast_type_id"
     34 
     35 
     36 enum _mpls_tr_cmd_t {
     37     MPLS_INIT = 1,
     38     MPLS_CLEANUP,
     39     MPLS_VPN_CREATE_VPLS,
     40     MPLS_VPN_CREATE_VPWS,
     41     MPLS_VPN_CREATE_L3,
     42     MPLS_VPN_DESTROY,
     43     MPLS_VPN_SHOW,
     44     MPLS_VPN_PORT_ADD,
     45     MPLS_VPN_PORT_DEL,
     46     MPLS_TUNNEL_INIT_SET,
     47     MPLS_TUNNEL_INIT_CLEAR,
     48     MPLS_TUNNEL_SWITCH_ADD,
     49     MPLS_TUNNEL_SWITCH_DEL,
     50     MPLS_TUNNEL_L2_ADD,
     51     MPLS_EXPMAP_CREATE,
     52     MPLS_EXPMAP_DESTROY,
     53     MPLS_EXPMAP_SET,
     54     MPLS_EXPMAP_SHOW,
     55     MPLS_MCAST_GROUP_CREATE,
     56     MPLS_MCAST_GROUP_DEL,
     57     MPLS_MCAST_GROUP_PORT_ADD,
     58     MPLS_MCAST_GROUP_PORT_DEL,
     59     MPLS_MCAST_GROUP_ADDR,
     60     MPLS_OPTIONS
     61 };
     62 
     63 #define BCM_MPLS_PORT                   1
     64 #define BCM_MPLS_PORT_MATCH             2
     65 #define BCM_MPLS_SWITCH                 3
     66 #define BCM_MPLS_EGRESS_LABEL           4
     67 #define BCM_MPLS_SWITCH_ACTION          5
     68 #define MAX_FLAG_LENGTH                 25
     69 
     70 #define MPLS_ROE(op, arg)     \
     71     do {               \
     72         int __rv__;    \
     73         __rv__ = op arg;    \
     74         if (BCM_FAILURE(__rv__)) { \
     75             cli_out("MPLS_CLI: Error: " #op " failed, %s\n", \
     76                     bcm_errmsg(__rv__)); \
     77             return CMD_FAIL; \
     78         } \
     79     } while(0)
     80 #define MPLS_CMD(_s)                         \
     81     if ((cmd = ARG_CUR(a)) == NULL) {        \
     82         ARG_PREV(a);  \
     83         cli_out("MPLS_CLI: Error: Missing arg after %s\n", ARG_CUR(a)); \
     84         return CMD_USAGE;                    \
     85     } else if(sal_strcasecmp(cmd, _s) == 0)
     86 
     87 #define PT_ADD(_pt, _id, _typ, _arg) \
     88     parse_table_add(&_pt, (_id), PQ_DFL | (_typ), \
     89                     (void *)(_arg), (void*)(_arg), 0)
     90 
     91 #define PT_INIT(_u, _pt) parse_table_init(_u, &_pt); \
     92 
     93 #define PT_DONE(_pt) parse_arg_eq_done(&pt);
     94 
     95 #define PT_PARSE(_a, _pt) \
     96     do {     \
     97         if (parse_arg_eq(_a, &_pt) < 0) { \
     98             cli_out("MPLS_CLI: Error: Invalid option or expression: %s\n", \
     99                     ARG_CUR(_a)); \
    100             PT_DONE(_pt); \
    101             return CMD_USAGE; \
    102         } \
    103     } while(0)
    104 
    105 typedef struct _bcm_tr_mpls_flag_s {
    106     char      *name;
    107     uint32     val; 
    108 } _bcm_tr_mpls_flag_t;
    109 
    110 _bcm_tr_mpls_flag_t port_flags[] = {
    111     {"RePLace", BCM_MPLS_PORT_REPLACE},
    112     {"WithID", BCM_MPLS_PORT_WITH_ID},
    113     {"DRop", BCM_MPLS_PORT_DROP},
    114     {"NetWork", BCM_MPLS_PORT_NETWORK},
    115     {"ControlWord", BCM_MPLS_PORT_CONTROL_WORD},
    116     {"SEQuenced", BCM_MPLS_PORT_SEQUENCED},
    117     {"CouNTed",  BCM_MPLS_PORT_COUNTED},
    118     {"IntPriSet", BCM_MPLS_PORT_INT_PRI_SET},
    119     {"IntPriMap",  BCM_MPLS_PORT_INT_PRI_MAP},
    120     {"ColorMap", BCM_MPLS_PORT_COLOR_MAP},
    121     {"EgressTunnel", BCM_MPLS_PORT_EGRESS_TUNNEL},
    122     {"ServiceTagged", BCM_MPLS_PORT_SERVICE_TAGGED},
    123     {"ServiceVlanAdd",BCM_MPLS_PORT_SERVICE_VLAN_ADD},
    124     {"ServiceVlanReplace", BCM_MPLS_PORT_SERVICE_VLAN_REPLACE},
    125     {"ServiceVlanDelete",  BCM_MPLS_PORT_SERVICE_VLAN_DELETE},
    126     {"ServiceVlanTpidReplace", BCM_MPLS_PORT_SERVICE_VLAN_TPID_REPLACE},
    127     {"InnerVlanPreserve", BCM_MPLS_PORT_INNER_VLAN_PRESERVE},
    128     {NULL, 0}
    129 };
    130 
    131 _bcm_tr_mpls_flag_t port_match_flags[] = {
    132     {"Port", BCM_MPLS_PORT_MATCH_PORT},
    133     {"PortVlan", BCM_MPLS_PORT_MATCH_PORT_VLAN},
    134     {"PortVlanStacked", BCM_MPLS_PORT_MATCH_PORT_VLAN_STACKED},
    135     {"Label", BCM_MPLS_PORT_MATCH_LABEL},
    136     {"LabelPort", BCM_MPLS_PORT_MATCH_LABEL_PORT},
    137     {"LabelVlan", BCM_MPLS_PORT_MATCH_LABEL_VLAN},
    138     {NULL, 0}
    139 };
    140 
    141 _bcm_tr_mpls_flag_t switch_flags[] = {
    142     {"LookupInnerLabel", BCM_MPLS_SWITCH_LOOKUP_SECOND_LABEL},
    143     {"CouNTed", BCM_MPLS_SWITCH_COUNTED},
    144     {"IntPriSet", BCM_MPLS_SWITCH_INT_PRI_SET},
    145     {"IntPriMap", BCM_MPLS_SWITCH_INT_PRI_MAP},
    146     {"ColorMap", BCM_MPLS_SWITCH_COLOR_MAP},
    147     {"OUTerEXP", BCM_MPLS_SWITCH_OUTER_EXP},
    148     {"OUTerTTL", BCM_MPLS_SWITCH_OUTER_TTL},
    149     {"INnerEXP", BCM_MPLS_SWITCH_INNER_EXP},
    150     {"INnerTTL", BCM_MPLS_SWITCH_INNER_TTL},
    151     {"TTLDECrement", BCM_MPLS_SWITCH_TTL_DECREMENT},
    152     {NULL, 0},
    153 };
    154 
    155 _bcm_tr_mpls_flag_t egr_label_flags[] = {
    156     {"TTLSET", BCM_MPLS_EGRESS_LABEL_TTL_SET},
    157     {"TTLCoPy", BCM_MPLS_EGRESS_LABEL_TTL_COPY},
    158     {"TTLDECrement", BCM_MPLS_EGRESS_LABEL_TTL_DECREMENT},
    159     {"EXPSET", BCM_MPLS_EGRESS_LABEL_EXP_SET},
    160     {"EXPREMark", BCM_MPLS_EGRESS_LABEL_EXP_REMARK},
    161     {"EXPCoPy", BCM_MPLS_EGRESS_LABEL_EXP_COPY},
    162     {"PRISET", BCM_MPLS_EGRESS_LABEL_PRI_SET},
    163     {"PRIREMark", BCM_MPLS_EGRESS_LABEL_PRI_REMARK},
    164     {NULL, 0}
    165 };
    166 
    167 _bcm_tr_mpls_flag_t action_flags[] = {
    168     {"SWAP", BCM_MPLS_SWITCH_ACTION_SWAP},
    169     {"PHP", BCM_MPLS_SWITCH_ACTION_PHP},
    170     {"POP", BCM_MPLS_SWITCH_ACTION_POP},
    171     {NULL, 0}
    172 };
    173 
    174 
    175 int        _bcm_tr_mpls_cli_vpn_create_vpws(int unit, args_t * a);
    176 int        _bcm_tr_mpls_cli_vpn_create_vpls(int unit, args_t * a);
    177 int        _bcm_tr_mpls_cli_vpn_create_l3(int unit, args_t * a);
    178 int        _bcm_tr_mpls_cli_vpn_destroy(int unit, args_t * a);
    179 int        _bcm_tr_mpls_cli_vpn_show(int unit, args_t * a);
    180 int        _bcm_tr_mpls_cli_vpn_port_add(int unit, args_t * a);
    181 int        _bcm_tr_mpls_cli_vpn_port_del(int unit, args_t * a);
    182 int        _bcm_tr_mpls_cli_tunnel_init_set(int unit, args_t * a);
    183 int        _bcm_tr_mpls_cli_tunnel_init_clear(int unit, args_t * a);
    184 int        _bcm_tr_mpls_cli_tunnel_switch_add(int unit, args_t * a);
    185 int        _bcm_tr_mpls_cli_tunnel_switch_del(int unit, args_t * a);
    186 int        _bcm_tr_mpls_cli_tunnel_l2_add(int unit, args_t * a);
    187 int        _bcm_tr_mpls_cli_expmap_create(int unit, args_t * a);
    188 int        _bcm_tr_mpls_cli_expmap_destroy(int unit, args_t * a);
    189 int        _bcm_tr_mpls_cli_expmap_set(int unit, args_t * a);
    190 int        _bcm_tr_mpls_cli_expmap_show(int unit, args_t * a);
    191 int        _bcm_tr_mpls_cli_mcast_group_create(int unit, args_t * a);
    192 int        _bcm_tr_mpls_cli_mcast_group_del(int unit, args_t * a);
    193 int        _bcm_tr_mpls_cli_mcast_group_port_add_del(int unit, args_t * a);
    194 int        _bcm_tr_mpls_cli_mcast_group_addr(int unit, args_t * a);
    195 int        _bcm_tr_mpls_cli_print_options(int unit, args_t * a);
    196 int        _bcm_tr_mpls_cli_action(int unit, args_t * a);
    197 int        _bcm_tr_mpls_cli_parse_flags(char *elo_s, int type);
    198 
    199 
    200 char       if_tr_mpls_usage[] = "Only for XGS4 devices.\n\t"
    201 #ifdef COMPILER_STRING_CONST_LIMIT
    202     "  mpls <option> [args...]\n"
    203 #else
    204     "  mpls init\n\t"
    205     "        - Init MPLS software system.\n\t"
    206     "  mpls cleanup\n\t"
    207     "        - Detach MPLS software system.\n\t"
    208     "  mpls vpn create vpws VPN=<vpn_id>\n\t"
    209     "        - Create VPWS vpn with given id.\n\t"
    210     "  mpls vpn create l3 VPN=<vpn_id>\n\t"
    211     "        - Create L3 vpn with given id.\n\t"
    212 #if !defined(BCM_KATANA_SUPPORT) || !defined(BCM_TRIUMPH3_SUPPORT)
    213     "  mpls vpn create vpls VPN=<vpn_id> BroadcastGroup=<bcast_id>\n\t"
    214     "        - Create VPLS vpn with given id  and broadcast group.\n\t"
    215     "  mpls vpn port add VPN=<vpn_id> Port=<port> PortMatch=<pm>\n\t"
    216     "                    IntfFlaGs=<flags> VCInitLabel=<vcinit_label>\n\t"
    217     "                    EgrLabelOptions=<labelopt>\n\t"
    218     "                    VCTermLabel=<vcterm_label> Vlan=<vlan>\n\t"
    219     "                    EgrTTL=<egress_ttl> QoSMapID=<qos_map_id>\n\t"
    220     "                    ServiceVID=<vlan> ServiceTPID=<tpid>\n\t"
    221     "                    IntfCLass=<val> EXPMapPtr=<exp_ptr> IntPRI=<pri>\n\t"
    222     "                    InnerVLAN=<vid> MTU=<val>EgrObj=<egress_obj_id>\n\t"
    223     "        - Add a port to VPN.\n\t"
    224 #else
    225     "  mpls vpn create vpls VPN=<vpn_id> BroadcastGroup=<bcast_id>\n\t"
    226     "                    [Policer=<policer_id>]\n\t"
    227     "        - Create VPLS vpn with given id  and broadcast group.\n\t"
    228     "  mpls vpn port add VPN=<vpn_id> Port=<port> PortMatch=<pm>\n\t"
    229     "                    IntfFlaGs=<flags> VCInitLabel=<vcinit_label>\n\t"
    230     "                    EgrLabelOptions=<labelopt>\n\t"
    231     "                    VCTermLabel=<vcterm_label> Vlan=<vlan>\n\t"
    232     "                    EgrTTL=<egress_ttl> QoSMapID=<qos_map_id>\n\t"
    233     "                    ServiceVID=<vlan> ServiceTPID=<tpid>\n\t"
    234     "                    IntfCLass=<val> EXPMapPtr=<exp_ptr> IntPRI=<pri>\n\t"
    235     "                    InnerVLAN=<vid> MTU=<val>EgrObj=<egress_obj_id>\n\t"
    236     "                    Policer=<policer_id>\n\t"
    237     "        - Add a port to VPN.\n\t"
    238 #endif /* BCM_KATANA_SUPPORT or BCM_TRIUMPH3_SUPPORT */
    239     "  mpls vpn port delete VPN=<vpn_id> MplsPort=<mpls_port_id>\n\t"
    240     "        - Delete an MPLS port from vpn.\n\t"
    241     "  mpls vpn destroy VPN=<vpn_id>\n\t"
    242     "        - Destroy a vpn.\n\t"
    243     "  mpls vpn show VPN=<vpn_id>\n\t"
    244     "        - Show VPN info.\n\t"
    245     "  mpls tunnel init set EgrTunnelLabel=<egr_tun_label>\n\t"
    246     "                       EgrLabelOptions=<egr_label_opt>\n\t"
    247     "                       EgrTTL=<egre_ttl> INtf=<intf_id>\n\t"
    248     "        - Initiate tunnel.\n\t"
    249     "  mpls tunnel init clear INtf=<intf_id>\n\t"
    250     "        - Clear tunnel.\n\t"
    251     "  mpls tunnel switch add SwitchOptions=<label_switch_opt>\n\t"
    252     "                         ACTion=<act> Port=<gport>\n\t"
    253     "                         EXPMapPtr=<exp_ptr> IntPRI=<pri>\n\t"
    254     "                         IngLabel=<label> IngInnerLabel=<inner_label>\n\t"
    255     "                         IngIntf=<ingress_interface>\n\t"
    256     "                         EgrLabel=<egr_label>\n\t"
    257     "                         EgrLabelOptions=<labelopt> EgrLabelTTL=<ttl>\n\t"
    258     "                         EgrLabelEXP=<exp>\n\t"
    259     "                         EgrObject=<egr_object_id> VPN=<vpn_id>\n\t"
    260     "        - Add ILM for ingress label.\n\t"
    261     "  mpls tunnel switch del IngLabel=<label>\n\t"
    262     "        - Delete ILM.\n\t"
    263     "  mpls tunnel l2 add Mac=<mac> Vlan=<vlan>\n\t"
    264     "        - Add L2 address for MPLS lookup.\n\t"
    265     "  mpls expmap create [ing|egr] ExpMapID=<id>\n\t"
    266     "        - Create EXP map.\n\t"
    267     "  mpls expmap destroy [ing|egr] ExpMapID=<id>\n\t"
    268     "        - Delete EXP map.\n\t"
    269     "  mpls expmap set [ing|egr] ExpMapID=<expid> PRIority=<pri>\n\t"
    270     "                            Color=<color> PKtPriority=<pri>\n\t"
    271     "                            EXP=<exp> PKtCfi=<cfi>\n\t"
    272     "        - Set exp map.\n\t"
    273     "  mpls expmap show [ing|egr] ExpMapID=<expid> PRIority=<pri>\n\t"
    274     "        - Show exp map.\n\t"
    275     "  mpls mcast group create [l2|vpls] McastGroup=<mcast_group>\n\t"
    276     "        - Create a multicast group.\n\t"
    277     "  mpls mcast group delete McastGroup=<mcast_group>\n\t"
    278     "        - Delete a multicast group.\n\t"
    279     "  mpls mcast group port add McastGroup=<mcast_type_id>\n\t"
    280     "                            MplsPort=<mpls_port_id>\n\t"
    281     "        - Add MPLS port to multicast group.\n\t"
    282     "  mpls mcast group port delete  McastGroup=<mcast_type_id>\n\t"
    283     "                                MplsPort=<mpls_port_id>\n\t"
    284     "        - Delete MPLS port from multicast group\n\t"
    285     "  mpls mcast group addr McastGroup=<mcast_type_id>\n\t"
    286     "                        Mac=<mcast mac> VPN=<vpn_type_id>\n\t"
    287     "        - Add multicast group Mac address.\n\t"
    288     "  mpls options Type=[PORT|PortMatch|MplsSwitch|MplsEgressLabel]\n\t"
    289     "        - List various options/flags used in mpls commands.\n\t" "\n"
    290 #endif
    291           ;
    292 
    293 cmd_result_t
    294 if_tr_mpls(int unit, args_t * a)
    295 {
    296     int        action = 0;
    297     cmd_result_t cmd_rv = CMD_OK;
    298 
    299     if (!sh_check_attached(ARG_CMD(a), unit)) {
    300         return CMD_FAIL;
    301     }
    302 
    303     if (ARG_CUR(a) == NULL) {
    304         return CMD_USAGE;
    305     }
    306 
    307     action = _bcm_tr_mpls_cli_action(unit, a);
    308 
    309     switch (action) {
    310         case MPLS_INIT:
    311             MPLS_ROE(bcm_mpls_init, (unit));
    312             break;
    313 
    314         case MPLS_CLEANUP:
    315             MPLS_ROE(bcm_mpls_cleanup, (unit));
    316             break;
    317 
    318         case MPLS_VPN_CREATE_VPWS:
    319             cmd_rv = _bcm_tr_mpls_cli_vpn_create_vpws(unit, a);
    320             break;
    321         case MPLS_VPN_CREATE_VPLS:
    322             cmd_rv = _bcm_tr_mpls_cli_vpn_create_vpls(unit, a);
    323             break;
    324         case MPLS_VPN_CREATE_L3:
    325             cmd_rv = _bcm_tr_mpls_cli_vpn_create_l3(unit, a);
    326             break;
    327         case MPLS_VPN_DESTROY:
    328             cmd_rv = _bcm_tr_mpls_cli_vpn_destroy(unit, a);
    329             break;
    330         case MPLS_VPN_SHOW:
    331             cmd_rv = _bcm_tr_mpls_cli_vpn_show(unit, a);
    332             break;
    333         case MPLS_VPN_PORT_ADD:
    334             cmd_rv = _bcm_tr_mpls_cli_vpn_port_add(unit, a);
    335             break;
    336         case MPLS_VPN_PORT_DEL:
    337             cmd_rv = _bcm_tr_mpls_cli_vpn_port_del(unit, a);
    338             break;
    339         case MPLS_TUNNEL_INIT_SET:
    340             cmd_rv = _bcm_tr_mpls_cli_tunnel_init_set(unit, a);
    341             break;
    342         case MPLS_TUNNEL_INIT_CLEAR:
    343             cmd_rv = _bcm_tr_mpls_cli_tunnel_init_clear(unit, a);
    344             break;
    345         case MPLS_TUNNEL_SWITCH_ADD:
    346             cmd_rv = _bcm_tr_mpls_cli_tunnel_switch_add(unit, a);
    347             break;
    348         case MPLS_TUNNEL_SWITCH_DEL:
    349             cmd_rv = _bcm_tr_mpls_cli_tunnel_switch_del(unit, a);
    350             break;
    351         case MPLS_TUNNEL_L2_ADD:
    352             cmd_rv = _bcm_tr_mpls_cli_tunnel_l2_add(unit, a);
    353             break;
    354         case MPLS_EXPMAP_CREATE:
    355             cmd_rv = _bcm_tr_mpls_cli_expmap_create(unit, a);
    356             break;
    357         case MPLS_EXPMAP_DESTROY:
    358             cmd_rv = _bcm_tr_mpls_cli_expmap_destroy(unit, a);
    359             break;
    360         case MPLS_EXPMAP_SET:
    361             cmd_rv = _bcm_tr_mpls_cli_expmap_set(unit, a);
    362             break;
    363         case MPLS_EXPMAP_SHOW:
    364             cmd_rv = _bcm_tr_mpls_cli_expmap_show(unit, a);
    365             break;
    366         case MPLS_MCAST_GROUP_CREATE:
    367             cmd_rv = _bcm_tr_mpls_cli_mcast_group_create(unit, a);
    368             break;
    369         case MPLS_MCAST_GROUP_DEL:
    370             cmd_rv = _bcm_tr_mpls_cli_mcast_group_del(unit, a);
    371             break;
    372         case MPLS_MCAST_GROUP_PORT_ADD:
    373         case MPLS_MCAST_GROUP_PORT_DEL:
    374             cmd_rv = _bcm_tr_mpls_cli_mcast_group_port_add_del(unit, a);
    375             break;
    376         case MPLS_MCAST_GROUP_ADDR:
    377             cmd_rv = _bcm_tr_mpls_cli_mcast_group_addr(unit, a);
    378             break;
    379         case MPLS_OPTIONS:
    380             cmd_rv = _bcm_tr_mpls_cli_print_options(unit, a);
    381             break;
    382         default:
    383             cli_out("Error:Unknown MPLS command %d\n", action);
    384             return CMD_USAGE;
    385     }
    386 
    387     ARG_DISCARD(a);
    388     return cmd_rv;
    389 }
    390 
    391 int
    392 _bcm_tr_mpls_cli_vpn_create_vpws(int unit, args_t * a)
    393 {
    394     parse_table_t pt;
    395     int        vpn_id = BCM_VLAN_INVALID;
    396     bcm_mpls_vpn_config_t vpn_info;
    397     bcm_mpls_vpn_config_t_init(&vpn_info);
    398 
    399     ARG_NEXT(a);
    400     if (ARG_CUR(a) == NULL) {
    401         cli_out("MPLS_CLI: Missing arguments\n");
    402         return CMD_USAGE;
    403     }
    404     PT_INIT(unit, pt);
    405     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    406     PT_PARSE(a, pt);
    407     vpn_info.vpn = vpn_id;
    408     vpn_info.flags = BCM_MPLS_VPN_VPWS | BCM_MPLS_VPN_WITH_ID;
    409     PT_DONE(pt);
    410     MPLS_ROE(bcm_mpls_vpn_id_create, (unit, &vpn_info));
    411     var_set_integer(ENV_VPN_TYPE_ID, vpn_info.vpn, TRUE, FALSE);
    412     cli_out("env var added: $vpn_type_id=0x%08x\n", vpn_info.vpn);
    413 
    414     return CMD_OK;
    415 }
    416 
    417 int
    418 _bcm_tr_mpls_cli_vpn_create_vpls(int unit, args_t * a)
    419 {
    420     parse_table_t pt;
    421     int        vpn_id = BCM_VLAN_INVALID;
    422 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    423     bcm_policer_t policer_id=0;
    424 #endif
    425     bcm_mpls_vpn_config_t vpn_info;
    426     bcm_multicast_t bcast_group = BCM_VLAN_INVALID;
    427     bcm_mpls_vpn_config_t_init(&vpn_info);
    428 
    429     ARG_NEXT(a);
    430 #if !defined(BCM_KATANA_SUPPORT) || !defined(BCM_TRIUMPH3_SUPPORT)
    431     if (ARG_CNT(a) != 2) 
    432     {
    433         cli_out("MPLS_CLI: Missing arguments\n");
    434         return CMD_USAGE;
    435     }
    436 #else
    437     if (ARG_CNT(a) < 2) 
    438     {
    439         cli_out("MPLS_CLI: Missing arguments\n");
    440         return CMD_USAGE;
    441     }
    442 #endif
    443     PT_INIT(unit, pt);
    444     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    445     PT_ADD(pt, "BcastGroup", PQ_INT, &bcast_group);
    446 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    447     PT_ADD(pt, "Policer", PQ_HEX, &policer_id);
    448 #endif
    449     PT_PARSE(a, pt);
    450     PT_DONE(pt);
    451     MPLS_ROE(bcm_multicast_create,
    452              (unit, BCM_MULTICAST_TYPE_VPLS |
    453               BCM_MULTICAST_WITH_ID, &bcast_group));
    454     vpn_info.vpn = vpn_id;
    455     vpn_info.flags = BCM_MPLS_VPN_VPLS | BCM_MPLS_VPN_WITH_ID;
    456     vpn_info.broadcast_group = bcast_group;
    457     vpn_info.unknown_unicast_group = bcast_group;
    458     vpn_info.unknown_multicast_group = bcast_group;
    459 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    460     vpn_info.policer_id = policer_id;
    461 #endif
    462     MPLS_ROE(bcm_mpls_vpn_id_create, (unit, &vpn_info));
    463     var_set_integer(ENV_VPN_TYPE_ID, vpn_info.vpn, TRUE, FALSE);
    464     cli_out("env var added : $vpn_type_id=0x%08x\n", vpn_info.vpn);
    465 
    466     return CMD_OK;
    467 }
    468 
    469 int
    470 _bcm_tr_mpls_cli_vpn_create_l3(int unit, args_t * a)
    471 {
    472     parse_table_t pt;
    473     int        vpn_id = BCM_VLAN_INVALID;
    474     bcm_mpls_vpn_config_t vpn_info;
    475     bcm_mpls_vpn_config_t_init(&vpn_info);
    476 
    477     ARG_NEXT(a);
    478     if (ARG_CUR(a) == NULL) {
    479         cli_out("MPLS_CLI: Missing arguments\n");
    480         return CMD_USAGE;
    481     }
    482     PT_INIT(unit, pt);
    483     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    484     PT_PARSE(a, pt);
    485     PT_DONE(pt);
    486     vpn_info.vpn = vpn_id;
    487     vpn_info.flags = BCM_MPLS_VPN_L3 | BCM_MPLS_VPN_WITH_ID;
    488     MPLS_ROE(bcm_mpls_vpn_id_create, (unit, &vpn_info));
    489     var_set_integer(ENV_VPN_TYPE_ID, vpn_info.vpn, TRUE, FALSE);
    490     cli_out("env var added : $vpn_type_id=0x%08x\n", vpn_info.vpn);
    491 
    492     return CMD_OK;
    493 }
    494 
    495 int
    496 _bcm_tr_mpls_cli_vpn_destroy(int unit, args_t * a)
    497 {
    498     parse_table_t pt;
    499     int        vpn_id = BCM_VLAN_INVALID;
    500 
    501     ARG_NEXT(a);
    502     if (ARG_CUR(a) == NULL) {
    503         cli_out("MPLS_CLI: Missing arguments\n");
    504         return CMD_USAGE;
    505     }
    506     PT_INIT(unit, pt);
    507     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    508     PT_PARSE(a, pt);
    509     PT_DONE(pt);
    510     MPLS_ROE(bcm_mpls_vpn_id_destroy, (unit, vpn_id));
    511     cli_out("Destroyed vpn id=0x%08x\n", vpn_id);
    512 
    513     return CMD_OK;
    514 }
    515 
    516 int
    517 _bcm_tr_mpls_cli_vpn_show(int unit, args_t * a)
    518 {
    519     int        i;
    520     int        count;
    521     int        max = 10;
    522     parse_table_t pt;
    523     int        vpn_id = BCM_VLAN_INVALID;
    524     bcm_mpls_port_t port_array[10];
    525 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    526     bcm_mpls_vpn_config_t vpn_info;
    527     bcm_mpls_vpn_config_t_init(&vpn_info);
    528 #endif
    529 
    530     ARG_NEXT(a);
    531     if (ARG_CUR(a) == NULL) {
    532         cli_out("MPLS_CLI: Missing arguments\n");
    533         return CMD_USAGE;
    534     }
    535     PT_INIT(unit, pt);
    536     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    537     PT_PARSE(a, pt);
    538     PT_DONE(pt);
    539     MPLS_ROE(bcm_mpls_port_get_all, (unit, vpn_id, max,
    540                                      port_array, &count));
    541     cli_out("VPN id=0x%08x, Ports :%d\n", vpn_id, count);
    542 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    543     MPLS_ROE(bcm_mpls_vpn_id_get, (unit, vpn_id, &vpn_info));
    544     cli_out("Policer id=0x%x\n", vpn_info.policer_id);
    545 #endif
    546     for (i = 0; i < count; i++) {
    547         cli_out("\n MPLS Port ID: %d", port_array[i].mpls_port_id);
    548         cli_out("\n Egress Tunnel If: %d", port_array[i].egress_tunnel_if);
    549         cli_out("\n flags: %X", port_array[i].flags);
    550         cli_out("\n service_tpid: %d", port_array[i].service_tpid);
    551         cli_out("\n match_vlan: %d", port_array[i].match_vlan);
    552         cli_out("\n mpls_label: %d", port_array[i].match_label);
    553         cli_out("\n encap_id: %d", port_array[i].encap_id);
    554         cli_out("\n failover_id: %d", port_array[i].failover_id);
    555         cli_out("\n failover_port_id: %d\n", port_array[i].failover_port_id);
    556 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    557         cli_out("Policer id=0x%x\n", port_array[i].policer_id);
    558 #endif
    559     }
    560 
    561     return CMD_OK;
    562 }
    563 
    564 int
    565 _bcm_tr_mpls_cli_vpn_port_add(int unit, args_t * a)
    566 {
    567     bcm_port_t port = -1;
    568     int        icl = 0;
    569     int        exp = 0;
    570     int        ipri = 0;
    571     int        ivlan = BCM_VLAN_INVALID;
    572     int        mtu = 0;
    573     char      *pm_s = 0;
    574     uint32     pm = 0;
    575     char      *ifl_s = 0;
    576     uint32     ifl = 0;
    577     uint32     vcil = 0;
    578     char      *elo_s = 0;
    579     uint32     elo = 0;
    580     uint32     vctl = 0;
    581     int        vlan = BCM_VLAN_INVALID;
    582     int        svid = BCM_VLAN_INVALID;
    583     int        stpid = 0x8100;
    584     uint32     ettl = 0;
    585     int        qosMapId=0;
    586     uint32     eo = 0;
    587     bcm_mpls_port_t mport;
    588     bcm_gport_t gp = BCM_GPORT_INVALID;
    589     parse_table_t pt;
    590     int        vpn_id = BCM_VLAN_INVALID;
    591 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    592     bcm_policer_t policer_id=0;
    593 #endif
    594 
    595     ARG_NEXT(a);
    596     PT_INIT(unit, pt);
    597     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    598     PT_ADD(pt, "Port", PQ_PORT, &port);
    599     PT_ADD(pt, "PortMatch", PQ_STRING, &pm_s);
    600     PT_ADD(pt, "IntfFlaGs", PQ_STRING, &ifl_s);
    601     PT_ADD(pt, "VCInitLabel", PQ_INT, &vcil);
    602     PT_ADD(pt, "EgrLabelOptions", PQ_STRING, &elo_s);
    603     PT_ADD(pt, "VCTermLabel", PQ_INT, &vctl);
    604     PT_ADD(pt, "Vlan", PQ_INT, &vlan);
    605     PT_ADD(pt, "EgrTTL", PQ_INT, &ettl);
    606     PT_ADD(pt, "QoSMapID", PQ_INT, &qosMapId);
    607     PT_ADD(pt, "ServiceVID", PQ_INT, &svid);
    608     PT_ADD(pt, "ServiceTPID", PQ_INT, &stpid);
    609     PT_ADD(pt, "IntfCLass", PQ_INT, &icl);
    610     PT_ADD(pt, "EXPMapPtr", PQ_INT, &exp);
    611     PT_ADD(pt, "IntPRI", PQ_INT, &ipri);
    612     PT_ADD(pt, "InnerVLAN", PQ_INT, &ivlan);
    613     PT_ADD(pt, "MTU", PQ_INT, &mtu);
    614     PT_ADD(pt, "EgrObj", PQ_INT, &eo);
    615 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    616     PT_ADD(pt, "Policer", PQ_INT, &policer_id);
    617 #endif
    618     PT_PARSE(a, pt);
    619 
    620     if (pm_s) {
    621         pm = _bcm_tr_mpls_cli_parse_flags(pm_s, BCM_MPLS_PORT_MATCH);
    622     }
    623     if (elo_s) {
    624         elo = _bcm_tr_mpls_cli_parse_flags(elo_s, BCM_MPLS_EGRESS_LABEL);
    625     }
    626     if (ifl_s) {
    627         ifl = _bcm_tr_mpls_cli_parse_flags(ifl_s, BCM_MPLS_PORT);
    628     }
    629     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    630                 (BSL_META_U(unit,
    631                             "Adding port %d to vpn 0x%08x, PortMatch=%s,"
    632                             "IntfFLaGs=%s VCInitLabel=0x%x\n"
    633                             "EgrLabelOptions=%s elo=%x VCTermLabel=0x%x"
    634                             "Vlan=%d EgrTTL=%d QoSMapID=%d EgrObj=%d ServiceVID=%d\n"
    635                             "ServiceTPID=%04x icl=%d exp=%d ipri=%d"
    636                             "ivlan=%d mtu=%d\n"),
    637                  port, vpn_id, pm_s, ifl_s, vcil, elo_s,
    638                  elo, vctl, vlan, ettl, qosMapId, eo, svid, stpid,
    639                  icl, exp, ipri, ivlan, mtu));
    640 
    641     PT_DONE(pt);
    642     bcm_mpls_port_t_init(&mport);
    643     if (ifl & (BCM_MPLS_PORT_REPLACE | BCM_MPLS_PORT_WITH_ID)) {
    644         mport.mpls_port_id = port;
    645         LOG_VERBOSE(BSL_LS_SOC_COMMON,
    646                     (BSL_META_U(unit,
    647                                 "mpls port=%08x\n"), port));
    648     } else if (BCM_GPORT_IS_SET(port)) {
    649         gp = port;
    650     } else {
    651         MPLS_ROE(bcm_port_gport_get, (unit, port, &gp));
    652     }
    653     mport.port = gp;
    654     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    655                 (BSL_META_U(unit,
    656                             "gport_get gp=%08x\n"), gp));
    657 
    658     mport.criteria = pm;
    659     mport.flags = ifl;
    660     mport.if_class = icl;
    661     mport.exp_map = exp;
    662     mport.int_pri = ipri;
    663     mport.match_inner_vlan = ivlan;
    664     mport.mtu = mtu;
    665     mport.match_label = vctl;
    666     mport.match_vlan = vlan;
    667     mport.service_tpid = stpid;
    668     mport.egress_service_vlan = svid;
    669     mport.egress_tunnel_if = eo;
    670     mport.egress_label.label = vcil;
    671     mport.egress_label.flags = elo;
    672     mport.egress_label.ttl = ettl;
    673     mport.egress_label.qos_map_id = qosMapId;
    674 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    675     mport.policer_id = policer_id;
    676 #endif
    677     MPLS_ROE(bcm_mpls_port_add, (unit, vpn_id, &mport));
    678     var_set_integer(ENV_MPLS_TYPE_ID, mport.mpls_port_id, TRUE, FALSE);
    679     cli_out("env var added : $mpls_port_id=0x%08x\n", mport.mpls_port_id);
    680 
    681     return CMD_OK;
    682 
    683 }
    684 
    685 int
    686 _bcm_tr_mpls_cli_vpn_port_del(int unit, args_t * a)
    687 {
    688     parse_table_t pt;
    689     int        vpn_id = BCM_VLAN_INVALID;
    690     bcm_gport_t gp = BCM_GPORT_INVALID;
    691     ARG_NEXT(a);
    692 
    693     PT_INIT(unit, pt);
    694     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    695     PT_ADD(pt, "MplsPort", PQ_INT, &gp);
    696     PT_PARSE(a, pt);
    697     PT_DONE(pt);
    698     MPLS_ROE(bcm_mpls_port_delete, (unit, vpn_id, gp));
    699 
    700     return CMD_OK;
    701 }
    702 
    703 int
    704 _bcm_tr_mpls_cli_tunnel_init_set(int unit, args_t * a)
    705 {
    706     uint32     elo = 0;
    707     char      *elo_s = 0;
    708     uint32     etl = 0;
    709     uint32     ettl = 0;
    710     uint32     intf_id = 0;
    711     bcm_mpls_egress_label_t tunnel_label;
    712     parse_table_t pt;
    713 
    714     ARG_NEXT(a);
    715     PT_INIT(unit, pt);
    716     PT_ADD(pt, "EgrTunnelLabel", PQ_INT, &etl);
    717     PT_ADD(pt, "EgrLabelOptions", PQ_STRING, &elo_s);
    718     PT_ADD(pt, "EgrTTL", PQ_INT, &ettl);
    719     PT_ADD(pt, "INtf", PQ_INT, &intf_id);
    720     PT_PARSE(a, pt);
    721     if (elo_s) {
    722         elo = _bcm_tr_mpls_cli_parse_flags(elo_s, BCM_MPLS_EGRESS_LABEL);
    723     }
    724     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    725                 (BSL_META_U(unit,
    726                             "Adding INtf=0x%x EgrTunnelLabel=0x%x "
    727                             "EgrLabelOptions=%s elo=%d EgrTTL=%d\n"),
    728                  intf_id, etl, elo_s, elo, ettl));
    729     bcm_mpls_egress_label_t_init(&tunnel_label);
    730     tunnel_label.flags = elo;
    731     tunnel_label.label = etl;
    732     tunnel_label.ttl = ettl;
    733     PT_DONE(pt);
    734     MPLS_ROE(bcm_mpls_tunnel_initiator_set,
    735              (unit, intf_id, 1, &tunnel_label));
    736 
    737     return CMD_OK;
    738 }
    739 
    740 int
    741 _bcm_tr_mpls_cli_tunnel_init_clear(int unit, args_t * a)
    742 {
    743     parse_table_t pt;
    744     uint32     intf_id = 0;
    745 
    746     ARG_NEXT(a);
    747     PT_INIT(unit, pt);
    748     PT_ADD(pt, "INtf", PQ_INT, &intf_id);
    749     PT_PARSE(a, pt);
    750     PT_DONE(pt);
    751     MPLS_ROE(bcm_mpls_tunnel_initiator_clear, (unit, intf_id));
    752     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    753                 (BSL_META_U(unit,
    754                             "Tunnel init clear intf_id=%d\n"), intf_id));
    755 
    756     return CMD_OK;
    757 }
    758 
    759 int
    760 _bcm_tr_mpls_cli_tunnel_switch_add(int unit, args_t * a)
    761 {
    762     uint32     so = 0;
    763     char      *so_s = 0;
    764     uint32     act = 0;
    765     char      *act_s = 0;
    766     bcm_gport_t gp = BCM_GPORT_INVALID;
    767     int        exp_ptr = 0;
    768     int        ipri = 0;
    769     int        il = 0;
    770     int        iil = 0;
    771     int        el = 0;
    772     int        elo = 0;
    773     int        elttl = 0;
    774     int        elexp = 0;
    775     int        eo = 0;
    776     char      *elo_s = 0;
    777     bcm_mpls_tunnel_switch_t msw;
    778     parse_table_t pt;
    779     int        vpn_id = BCM_VLAN_INVALID;
    780     int        ing_intf = -1;
    781     int        mode = 0;
    782 
    783     ARG_NEXT(a);
    784     PT_INIT(unit, pt);
    785     PT_ADD(pt, "SwitchOptions", PQ_STRING, &so_s);
    786     PT_ADD(pt, "ACTion", PQ_STRING, &act_s);
    787     PT_ADD(pt, "Port", PQ_PORT, &gp);
    788     PT_ADD(pt, "EXPMapPtr", PQ_INT, &exp_ptr);
    789     PT_ADD(pt, "IntPRI", PQ_INT, &ipri);
    790     PT_ADD(pt, "IngLabel", PQ_HEX, &il);
    791     PT_ADD(pt, "IngInnerLabel", PQ_HEX, &iil);
    792     PT_ADD(pt, "IngIntf", PQ_INT, &ing_intf);
    793     PT_ADD(pt, "EgrLabel", PQ_INT, &el);
    794     PT_ADD(pt, "EgrLabelOptions", PQ_STRING, &elo_s);
    795     PT_ADD(pt, "EgrLabelTTL", PQ_INT, &elttl);
    796     PT_ADD(pt, "EgrLabelEXP", PQ_INT, &elexp);
    797     PT_ADD(pt, "EgrObject", PQ_HEX, &eo);
    798     PT_ADD(pt, "VPN", PQ_INT, &vpn_id);
    799     PT_PARSE(a, pt);
    800     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    801                 (BSL_META_U(unit,
    802                             "switch_add  so=0x%x so_s=%s act=%d il=0x%x "
    803                             "iil=0x%x el=0x%x elttl=%d elexp=%d elo_s=%s\n"
    804                             "elo=%x eo=%d gp=%x exp_ptr=%d ipri=%d\n"),
    805                  so, so_s, act, il, iil, el, elttl, elexp, elo_s,
    806                  elo, eo, gp, exp_ptr, ipri));
    807 
    808     if (act_s) {
    809         act = _bcm_tr_mpls_cli_parse_flags(act_s, BCM_MPLS_SWITCH_ACTION);
    810     }
    811     if (so_s) {
    812         so = _bcm_tr_mpls_cli_parse_flags(so_s, BCM_MPLS_SWITCH);
    813     }
    814     if (elo_s) {
    815         elo = _bcm_tr_mpls_cli_parse_flags(elo_s, BCM_MPLS_EGRESS_LABEL);
    816     }
    817     bcm_mpls_tunnel_switch_t_init(&msw);
    818     msw.flags = so;
    819     msw.action = act;
    820     msw.label = il;
    821     msw.port = gp;
    822     msw.exp_map = exp_ptr;
    823     msw.int_pri = ipri;
    824     msw.egress_label.label = el;
    825     msw.egress_label.flags = elo;
    826     msw.egress_label.ttl = elttl;
    827     msw.egress_label.exp = elexp;
    828     msw.egress_if = eo;
    829     msw.vpn = vpn_id;
    830 
    831     BCM_IF_ERROR_RETURN(bcm_switch_control_get(unit, 
    832                                                bcmSwitchL3IngressMode, 
    833                                                &mode));
    834 
    835     /* L3 Ingress Mode enabled */
    836     if (mode) {
    837         if (ing_intf == -1) {
    838             cli_out("L3IngressMode is set - "
    839                     "Invalid ingress interface(IngIntf)\n");
    840             return CMD_FAIL;
    841         }
    842         msw.ingress_if = ing_intf;
    843     } 
    844 
    845     PT_DONE(pt);
    846     MPLS_ROE(bcm_mpls_tunnel_switch_add, (unit, &msw));
    847 
    848     return CMD_OK;
    849 }
    850 
    851 int
    852 _bcm_tr_mpls_cli_tunnel_switch_del(int unit, args_t * a)
    853 {
    854     int        il = 0;
    855     bcm_mpls_tunnel_switch_t msw;
    856     parse_table_t pt;
    857 
    858     ARG_NEXT(a);
    859     PT_INIT(unit, pt);
    860     PT_ADD(pt, "IngLabel", PQ_HEX, &il);
    861     PT_PARSE(a, pt);
    862     bcm_mpls_tunnel_switch_t_init(&msw);
    863     msw.label = il;
    864     msw.port = BCM_GPORT_INVALID;
    865     PT_DONE(pt);
    866     MPLS_ROE(bcm_mpls_tunnel_switch_delete, (unit, &msw));
    867 
    868     return CMD_OK;
    869 }
    870 
    871 int
    872 _bcm_tr_mpls_cli_tunnel_l2_add(int unit, args_t * a)
    873 {
    874     bcm_mac_t  mac;
    875     parse_table_t pt;
    876     int        vlan = BCM_VLAN_INVALID;
    877 
    878     ARG_NEXT(a);
    879     PT_INIT(unit, pt);
    880     PT_ADD(pt, "Mac", PQ_MAC, &mac);
    881     PT_ADD(pt, "Vlan", PQ_INT, &vlan);
    882     PT_PARSE(a, pt);
    883     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    884                 (BSL_META_U(unit,
    885                             "l2 add mac=%02x:%02x:%02x:%02x:%02x:%02x vlan=%d\n"),
    886                  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vlan));
    887     PT_DONE(pt);
    888     MPLS_ROE(bcm_l2_tunnel_add, (unit, mac, vlan));
    889 
    890     return CMD_OK;
    891 
    892 }
    893 
    894 int
    895 _bcm_tr_mpls_cli_expmap_create(int unit, args_t * a)
    896 {
    897     char      *cmd;
    898     int        flags = 0;
    899     int        exp_map_id = BCM_VLAN_INVALID;
    900     parse_table_t pt;
    901 
    902     ARG_NEXT(a);                /* ing/egr */
    903     MPLS_CMD("ing") {
    904         flags = BCM_MPLS_EXP_MAP_INGRESS;
    905     }
    906     MPLS_CMD("egr") {
    907         flags = BCM_MPLS_EXP_MAP_EGRESS;
    908     }
    909     ARG_NEXT(a);                /* ing/egr */
    910     PT_INIT(unit, pt);
    911     PT_ADD(pt, "ExpMapID", PQ_INT, &exp_map_id);
    912     PT_PARSE(a, pt);
    913     flags |= BCM_MPLS_EXP_MAP_WITH_ID;
    914     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    915                 (BSL_META_U(unit,
    916                             "exp_map_id %d\n"), exp_map_id));
    917     PT_DONE(pt);
    918     MPLS_ROE(bcm_mpls_exp_map_create, (unit, flags, &exp_map_id));
    919 
    920     return CMD_OK;
    921 }
    922 
    923 int
    924 _bcm_tr_mpls_cli_expmap_destroy(int unit, args_t * a)
    925 {
    926     char      *cmd;
    927     int        type = 0;
    928     int        exp_map_id = BCM_VLAN_INVALID;
    929     parse_table_t pt;
    930 
    931     ARG_NEXT(a);                /* ing/egr */
    932     MPLS_CMD("ing") {
    933         type = _BCM_TR_MPLS_EXP_MAP_TABLE_TYPE_INGRESS;
    934     }
    935     MPLS_CMD("egr") {
    936         type = _BCM_TR_MPLS_EXP_MAP_TABLE_TYPE_EGRESS;
    937     }
    938     ARG_NEXT(a);                /* ing/egr */
    939     PT_INIT(unit, pt);
    940     PT_ADD(pt, "ExpMapID", PQ_INT, &exp_map_id);
    941     PT_PARSE(a, pt);
    942     exp_map_id |= type;
    943     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    944                 (BSL_META_U(unit,
    945                             "exp_map_id %d\n"), exp_map_id));
    946     PT_DONE(pt);
    947     MPLS_ROE(bcm_mpls_exp_map_destroy, (unit, exp_map_id));
    948 
    949     return CMD_OK;
    950 }
    951 
    952 int
    953 _bcm_tr_mpls_cli_expmap_set(int unit, args_t * a)
    954 {
    955     char      *cmd;
    956     int        type = 0;
    957     int        color = 0;
    958     int        priority = 0;
    959     int        exp = 0;
    960     int        pkt_pri = 0;
    961     int        pkt_cfi = 0;
    962     int        exp_map_id = BCM_VLAN_INVALID;
    963     bcm_mpls_exp_map_t map;
    964     parse_table_t pt;
    965 
    966     ARG_NEXT(a);                /* ing/egr */
    967     MPLS_CMD("ing") {
    968         type = 0x100;/*_BCM_TR_MPLS_EXP_MAP_TABLE_TYPE_INGRESS;*/
    969     }
    970     MPLS_CMD("egr") {
    971         type = 0;/*_BCM_TR_MPLS_EXP_MAP_TABLE_TYPE_EGRESS;*/
    972     }
    973     ARG_NEXT(a);                /* ing/egr */
    974     PT_INIT(unit, pt);
    975     PT_ADD(pt, "ExpMapID", PQ_INT, &exp_map_id);
    976     PT_ADD(pt, "PRIority", PQ_INT, &priority);
    977     PT_ADD(pt, "EXP", PQ_INT, &exp);
    978     PT_ADD(pt, "Color", PQ_INT, &color);
    979     PT_ADD(pt, "PKtPriority", PQ_INT, &pkt_pri);
    980     PT_ADD(pt, "PKtCfi", PQ_INT, &pkt_cfi);
    981     PT_PARSE(a, pt);
    982     exp_map_id |= type;
    983     bcm_mpls_exp_map_t_init(&map);
    984     map.priority = priority;
    985     map.exp = exp;
    986     map.color = color;
    987     map.pkt_pri = pkt_pri;
    988     map.pkt_cfi = pkt_cfi;
    989     LOG_VERBOSE(BSL_LS_SOC_COMMON,
    990                 (BSL_META_U(unit,
    991                             "exp_map_id %d priority %d exp %d\n"
    992                             "Color %d PKtPriority %d PKtCfi %d\n"),
    993                  exp_map_id, priority, exp, color, pkt_pri, pkt_cfi));
    994     PT_DONE(pt);
    995     MPLS_ROE(bcm_mpls_exp_map_set, (unit, exp_map_id, &map));
    996 
    997     return CMD_OK;
    998 }
    999 
   1000 int
   1001 _bcm_tr_mpls_cli_expmap_show(int unit, args_t * a)
   1002 {
   1003     int        type = 0;
   1004     int        exp = 0;
   1005     int        priority = 0;
   1006     int        color = 0;
   1007     int        exp_map_id = BCM_VLAN_INVALID;
   1008     bcm_mpls_exp_map_t map;
   1009     char      *cmd;
   1010     parse_table_t pt;
   1011 
   1012     ARG_NEXT(a);                /* ing/egr */
   1013     MPLS_CMD("ing") {
   1014         type = 0x100;/*_BCM_TR_MPLS_EXP_MAP_TABLE_TYPE_INGRESS;*/
   1015         ARG_NEXT(a);
   1016         PT_INIT(unit, pt);
   1017         PT_ADD(pt, "ExpMapID", PQ_INT, &exp_map_id);
   1018         PT_ADD(pt, "EXP", PQ_INT, &exp);
   1019         PT_PARSE(a, pt);
   1020         exp_map_id |= type;
   1021         bcm_mpls_exp_map_t_init(&map);
   1022         map.exp = exp;
   1023         PT_DONE(pt);
   1024         MPLS_ROE(bcm_mpls_exp_map_get, (unit, exp_map_id, &map));
   1025         cli_out("exp_map_id %d priority %d Color %d\n",
   1026                 exp_map_id, map.priority,map.color);
   1027         cli_out("PKtPriority %d PKtCfi %d exp %d\n",
   1028                 map.pkt_pri, map.pkt_cfi, map.exp);
   1029         return CMD_OK;
   1030     }
   1031 
   1032     MPLS_CMD("egr") {
   1033         type = 0;/*_BCM_TR_MPLS_EXP_MAP_TABLE_TYPE_EGRESS;*/
   1034         ARG_NEXT(a);
   1035         PT_INIT(unit, pt);
   1036         PT_ADD(pt, "ExpMapID", PQ_INT, &exp_map_id);
   1037         PT_ADD(pt, "PRIority", PQ_INT, &priority);
   1038         PT_ADD(pt, "Color", PQ_INT, &color);
   1039         PT_PARSE(a, pt);
   1040         exp_map_id |= type;
   1041         bcm_mpls_exp_map_t_init(&map);
   1042         map.priority = priority;
   1043         map.color = color;
   1044         PT_DONE(pt);
   1045         MPLS_ROE(bcm_mpls_exp_map_get, (unit, exp_map_id, &map));
   1046         cli_out("exp_map_id %d priority %d Color %d\n",
   1047                 exp_map_id, map.priority, map.color);
   1048         cli_out("PKtPriority %d PKtCfi %d exp %d\n",
   1049                 map.pkt_pri, map.pkt_cfi, map.exp);
   1050     }
   1051 
   1052     return CMD_OK;
   1053 }
   1054 
   1055 int
   1056 _bcm_tr_mpls_cli_mcast_group_create(int unit, args_t * a)
   1057 {
   1058     int        flags = -1;
   1059     int        mcast_group = BCM_VLAN_INVALID;
   1060     char      *cmd;
   1061     parse_table_t pt;
   1062 
   1063     ARG_NEXT(a);                /* vpls,l2 etc. */
   1064     MPLS_CMD("l2") {
   1065         flags = BCM_MULTICAST_TYPE_L2;
   1066     }
   1067     MPLS_CMD("vpls") {
   1068         flags = BCM_MULTICAST_TYPE_VPLS;
   1069     }
   1070     ARG_NEXT(a);
   1071     PT_INIT(unit, pt);
   1072     PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group);
   1073     PT_PARSE(a, pt);
   1074     LOG_VERBOSE(BSL_LS_SOC_COMMON,
   1075                 (BSL_META_U(unit,
   1076                             "mcast group %d\n"), mcast_group));
   1077     flags |= BCM_MULTICAST_WITH_ID;
   1078     PT_DONE(pt);
   1079     MPLS_ROE(bcm_multicast_create, (unit, flags, &mcast_group));
   1080     var_set_integer(ENV_MCAST_TYPE_ID, mcast_group, TRUE, FALSE);
   1081     cli_out("env var added : $mcast_type_id=0x%08x\n", mcast_group);
   1082 
   1083     return CMD_OK;
   1084 }
   1085 
   1086 int
   1087 _bcm_tr_mpls_cli_mcast_group_del(int unit, args_t * a)
   1088 {
   1089     int        mcast_group = BCM_VLAN_INVALID;
   1090     parse_table_t pt;
   1091 
   1092     ARG_NEXT(a);
   1093     PT_INIT(unit, pt);
   1094     PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group);
   1095     PT_PARSE(a, pt);
   1096     PT_DONE(pt);
   1097     MPLS_ROE(bcm_multicast_destroy, (unit, mcast_group));
   1098     LOG_VERBOSE(BSL_LS_SOC_COMMON,
   1099                 (BSL_META_U(unit,
   1100                             "mcast group %d destroyed\n"),
   1101                             mcast_group));
   1102 
   1103     return CMD_OK;
   1104 }
   1105 
   1106 int
   1107 _bcm_tr_mpls_cli_mcast_group_port_add_del(int unit, args_t * a)
   1108 {
   1109     int        add = 0;
   1110     int        mcast_group = BCM_VLAN_INVALID;
   1111     bcm_module_t modid;
   1112     bcm_port_t port;
   1113     bcm_trunk_t trunk_id;
   1114     int        id;
   1115     bcm_gport_t gp = BCM_GPORT_INVALID;
   1116     bcm_gport_t mpls_port;
   1117     bcm_if_t   encap_id;
   1118     parse_table_t pt;
   1119     char      *cmd;
   1120 
   1121     ARG_NEXT(a);
   1122     MPLS_CMD("add") {
   1123         add = 1;
   1124     }
   1125     MPLS_CMD("delete") {
   1126         add = 0;
   1127     }
   1128     ARG_NEXT(a);
   1129     PT_INIT(unit, pt);
   1130     PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group);
   1131     PT_ADD(pt, "MplsPort", PQ_INT, &mpls_port);
   1132     PT_PARSE(a, pt);
   1133     PT_DONE(pt);
   1134     MPLS_ROE(_bcm_esw_gport_resolve,
   1135              (unit, mpls_port, &modid, &port, &trunk_id, &id));
   1136     MPLS_ROE(bcm_port_gport_get, (unit, port, &gp));
   1137     MPLS_ROE(bcm_multicast_vpls_encap_get,
   1138              (unit, mcast_group, gp, mpls_port, &encap_id));
   1139     LOG_VERBOSE(BSL_LS_SOC_COMMON,
   1140                 (BSL_META_U(unit,
   1141                             "MPLS_CLI: mpls mcast group port %s vpls"
   1142                             "group 0x%x gport 0x%0x mpls_port 0x%08xnh %d\n"),
   1143                  add ? "add" : "delete", mcast_group, gp, mpls_port,
   1144                  encap_id));
   1145     if (add) {
   1146         MPLS_ROE(bcm_multicast_egress_add,
   1147                  (unit, mcast_group, gp, encap_id));
   1148     } else {
   1149         MPLS_ROE(bcm_multicast_egress_delete,
   1150                  (unit, mcast_group, gp, encap_id));
   1151     }
   1152 
   1153     return CMD_OK;
   1154 }
   1155 
   1156 int
   1157 _bcm_tr_mpls_cli_mcast_group_addr(int unit, args_t * a)
   1158 {
   1159     int        mcast_group = BCM_VLAN_INVALID;
   1160     int        vpn;
   1161     bcm_mac_t  mac;
   1162     bcm_l2_addr_t l2_addr;
   1163     parse_table_t pt;
   1164 
   1165     ARG_NEXT(a);
   1166     PT_INIT(unit, pt);
   1167     PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group);
   1168     PT_ADD(pt, "Mac", PQ_MAC, mac);
   1169     PT_ADD(pt, "VPN", PQ_INT, &vpn);
   1170     PT_PARSE(a, pt);
   1171 
   1172     bcm_l2_addr_t_init(&l2_addr, mac, vpn);
   1173     l2_addr.flags = BCM_L2_STATIC | BCM_L2_MCAST;
   1174     l2_addr.l2mc_group = mcast_group;
   1175     PT_DONE(pt);
   1176     MPLS_ROE(bcm_l2_addr_add, (unit, &l2_addr));
   1177     LOG_VERBOSE(BSL_LS_SOC_COMMON,
   1178                 (BSL_META_U(unit,
   1179                             "mcast l2 addr add=%02x:%02x:%02x:%02x:%02x:%02x \n"),
   1180                  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]));
   1181     cli_out("MPLS_CLI: mc_group 0x%08x vpn 0x%08x\n", mcast_group, vpn);
   1182     PT_DONE(pt);
   1183 
   1184     return CMD_OK;
   1185 }
   1186 
   1187 int        
   1188 _bcm_tr_mpls_cli_print_options(int unit, args_t * a)
   1189 {
   1190     int i;
   1191     char     *type_s = 0;
   1192     parse_table_t pt;
   1193     _bcm_tr_mpls_flag_t *flags = 0;
   1194 
   1195     ARG_NEXT(a);
   1196     if (ARG_CUR(a) == NULL) {
   1197         cli_out("MPLS_CLI: Missing arguments\n");
   1198         return CMD_USAGE;
   1199     }
   1200     PT_INIT(unit, pt);
   1201     PT_ADD(pt, "Type", PQ_STRING, &type_s);
   1202     PT_PARSE(a, pt);
   1203 
   1204     if (parse_cmp("PortMatch", type_s, '\0')) {
   1205         flags = port_match_flags;
   1206     } else if (parse_cmp(type_s, "PORT", '\0')) {
   1207         flags = port_flags;
   1208     } else if (parse_cmp("MplsSwitch", type_s, '\0')) {
   1209         flags = switch_flags;
   1210     } else if (parse_cmp("MplsEgressLabel", type_s, '\0')) {
   1211         flags = egr_label_flags;
   1212     } else if (parse_cmp("MplsSwitchAction", type_s, '\0')) {
   1213         flags = action_flags;
   1214     }
   1215     PT_DONE(pt);
   1216 
   1217     if (flags) {
   1218         for (i = 0; flags[i].name != NULL; i++) {
   1219             cli_out("\t%-25s  0x%08x\n", flags[i].name, flags[i].val);
   1220         }
   1221     } else {
   1222         cli_out("Port Flags:\n\t");
   1223         for (i = 0; port_flags[i].name != NULL; i++) {
   1224             cli_out("%-25s  0x%08x\n\t", port_flags[i].name, 
   1225                     port_flags[i].val);
   1226         }
   1227         cli_out("\nPort Match Flags:\n\t");
   1228         for (i = 0; port_match_flags[i].name != NULL; i++) {
   1229             cli_out("%-25s  0x%08x\n\t", port_match_flags[i].name, 
   1230                     port_match_flags[i].val);
   1231         }
   1232         cli_out("\nSwitch Flags:\n\t");
   1233         for (i = 0; switch_flags[i].name != NULL; i++) {
   1234             cli_out("%-25s  0x%08x\n\t", switch_flags[i].name, 
   1235                     switch_flags[i].val);
   1236         }
   1237         cli_out("\nEgress Label Flags:\n\t");
   1238         for (i = 0; egr_label_flags[i].name != NULL; i++) {
   1239             cli_out("%-25s  0x%08x\n\t", egr_label_flags[i].name, 
   1240                     egr_label_flags[i].val);
   1241         }
   1242         cli_out("\nSwitch Action Flags:\n\t");
   1243         for (i = 0; action_flags[i].name != NULL; i++) {
   1244             cli_out("%-25s  0x%08x\n\t", action_flags[i].name, 
   1245                     action_flags[i].val);
   1246         }
   1247         cli_out("\n");
   1248     }
   1249 
   1250     return CMD_OK;
   1251 }
   1252 
   1253 int
   1254 _bcm_tr_mpls_cli_action(int unit, args_t * a)
   1255 {
   1256     char      *cmd;
   1257     int        action = -1;
   1258 
   1259     MPLS_CMD("init") {
   1260         action = MPLS_INIT;
   1261     }
   1262 
   1263     MPLS_CMD("cleanup") {
   1264         action = MPLS_CLEANUP;
   1265     }
   1266 
   1267     MPLS_CMD("options") {
   1268         action = MPLS_OPTIONS;
   1269     }
   1270 
   1271     MPLS_CMD("vpn") {
   1272         ARG_NEXT(a);
   1273         MPLS_CMD("create") {
   1274             ARG_NEXT(a);
   1275             MPLS_CMD("vpws") {
   1276                 action = MPLS_VPN_CREATE_VPWS;
   1277             }
   1278             MPLS_CMD("vpls") {
   1279                 action = MPLS_VPN_CREATE_VPLS;
   1280             }
   1281             MPLS_CMD("l3") {
   1282                 action = MPLS_VPN_CREATE_L3;
   1283             }
   1284         }
   1285         MPLS_CMD("destroy") {
   1286             action = MPLS_VPN_DESTROY;
   1287         }
   1288         MPLS_CMD("show") {
   1289             action = MPLS_VPN_SHOW;
   1290         }
   1291         MPLS_CMD("port") {
   1292             ARG_NEXT(a);
   1293             MPLS_CMD("add") {
   1294                 action = MPLS_VPN_PORT_ADD;
   1295             }
   1296             MPLS_CMD("delete") {
   1297                 action = MPLS_VPN_PORT_DEL;
   1298             }
   1299         }
   1300     }
   1301 
   1302     MPLS_CMD("tunnel") {
   1303         ARG_NEXT(a);
   1304         MPLS_CMD("init") {
   1305             ARG_NEXT(a);
   1306             MPLS_CMD("set") {
   1307                 action = MPLS_TUNNEL_INIT_SET;
   1308             }
   1309             MPLS_CMD("clear") {
   1310                 action = MPLS_TUNNEL_INIT_CLEAR;
   1311             }
   1312         }
   1313         MPLS_CMD("switch") {
   1314             ARG_NEXT(a);
   1315             MPLS_CMD("add") {
   1316                 action = MPLS_TUNNEL_SWITCH_ADD;
   1317             }
   1318             MPLS_CMD("del") {
   1319                 action = MPLS_TUNNEL_SWITCH_DEL;
   1320             }
   1321         }
   1322         MPLS_CMD("l2") {
   1323             ARG_NEXT(a);
   1324             MPLS_CMD("add") {
   1325                 action = MPLS_TUNNEL_L2_ADD;
   1326             }
   1327         }
   1328     }
   1329 
   1330     MPLS_CMD("expmap") {
   1331         ARG_NEXT(a);
   1332         MPLS_CMD("create") {
   1333             action = MPLS_EXPMAP_CREATE;
   1334         }
   1335         MPLS_CMD("destroy") {
   1336             action = MPLS_EXPMAP_DESTROY;
   1337         }
   1338         MPLS_CMD("set") {
   1339             action = MPLS_EXPMAP_SET;
   1340         }
   1341         MPLS_CMD("show") {
   1342             action = MPLS_EXPMAP_SHOW;
   1343         }
   1344     }
   1345 
   1346     MPLS_CMD("mcast") {
   1347         ARG_NEXT(a);
   1348         MPLS_CMD("group") {
   1349             ARG_NEXT(a);
   1350             MPLS_CMD("create") {
   1351                 action = MPLS_MCAST_GROUP_CREATE;
   1352             }
   1353             MPLS_CMD("delete") {
   1354                 action = MPLS_MCAST_GROUP_DEL;
   1355             }
   1356             MPLS_CMD("port") {
   1357                 action = MPLS_MCAST_GROUP_PORT_ADD;
   1358             }
   1359             MPLS_CMD("addr") {
   1360                 action = MPLS_MCAST_GROUP_ADDR;
   1361             }
   1362         }
   1363     }
   1364 
   1365     return action;
   1366 }
   1367 
   1368 int
   1369 _bcm_tr_mpls_cli_parse_flags(char *input_s, int type)
   1370 {
   1371     int cnt;
   1372     char *p;
   1373     char f_name[MAX_FLAG_LENGTH];
   1374     _bcm_tr_mpls_flag_t *flags;
   1375     uint32 result = 0;
   1376     int done = 0;
   1377     int found = 0;
   1378 
   1379     if (isint(input_s)) {
   1380         result = parse_integer(input_s);
   1381         return result;
   1382     }
   1383 
   1384     switch (type) {
   1385         case BCM_MPLS_PORT:
   1386             flags = port_flags;
   1387             break;
   1388         case BCM_MPLS_PORT_MATCH:
   1389             flags = port_match_flags;
   1390             break;
   1391         case BCM_MPLS_SWITCH:
   1392             flags = switch_flags;
   1393             break;
   1394         case BCM_MPLS_EGRESS_LABEL:
   1395             flags = egr_label_flags;
   1396             break;
   1397         case BCM_MPLS_SWITCH_ACTION:
   1398             flags = action_flags;
   1399             break;
   1400         default:
   1401             flags = 0;
   1402     } /* switch (type) */
   1403 
   1404     if(!flags) {
   1405         cli_out("MPLS CLI: Error: Discarded unrecognized Flags\n\t %s\n", 
   1406                 input_s);
   1407         return 0;
   1408     }
   1409 
   1410     while (!done) {
   1411         p = (char*)strcaseindex(input_s,",");
   1412         sal_memset(f_name, 0, MAX_FLAG_LENGTH); 
   1413         if (p) {
   1414             strncpy(f_name, input_s, p-input_s);
   1415             input_s = p + 1;
   1416         } else {
   1417     /*    coverity[parameter_as_source]    */
   1418             strcpy(f_name, input_s);
   1419             done = 1;
   1420         }
   1421         found = 0;
   1422         for (cnt = 0; flags[cnt].name ; cnt++) {
   1423             if (parse_cmp(flags[cnt].name, f_name, '\0')) {
   1424                 result |= flags[cnt].val;
   1425                 found = 1;
   1426             }
   1427         }
   1428         if (!found) {
   1429             cli_out("MPLS_CLI: flag %s not recognized, discarded\n", f_name);
   1430         }
   1431     }
   1432     return result;
   1433 
   1434 }
   1435 #endif /* BCM_TRIUMPH_SUPPORT */
   1436 #endif /* INCLUDE_L3 */