mim.c (27873B)
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 * MIM CLI commands 8 */ 9 10 #include <shared/bsl.h> 11 12 #include <appl/diag/system.h> 13 #include <appl/diag/parse.h> 14 #include <shared/bsl.h> 15 #include <soc/debug.h> 16 #if defined(BCM_TRIUMPH2_SUPPORT) 17 #include <soc/triumph2.h> 18 #endif /* BCM_TRIUMPH2_SUPPORT */ 19 20 #include <bcm/error.h> 21 #include <bcm/debug.h> 22 #include <bcm/l3.h> 23 #include <bcm/mim.h> 24 #include <bcm/l2.h> 25 #include <bcm_int/esw/l3.h> 26 #include <bcm_int/esw/port.h> 27 28 #ifdef INCLUDE_L3 29 #if defined(BCM_TRIUMPH2_SUPPORT) 30 31 #define ENV_VPN_TYPE_ID "vpn_type_id" 32 #define ENV_MIM_TYPE_ID "mim_port_id" 33 #define ENV_MCAST_TYPE_ID "mcast_type_id" 34 35 36 enum _mim_tr2_cmd_t { 37 MIM_INIT = 1, 38 MIM_DETACH, 39 MIM_VPN_CREATE, 40 MIM_VPN_DESTROY, 41 MIM_VPN_SHOW, 42 MIM_VPN_PORT_ADD, 43 MIM_VPN_PORT_DEL, 44 MIM_TUNNEL_L2_ADD, 45 MIM_MCAST_GROUP_CREATE, 46 MIM_MCAST_GROUP_DEL, 47 MIM_MCAST_GROUP_PORT_ADD, 48 MIM_MCAST_GROUP_PORT_DEL, 49 MIM_MCAST_GROUP_ADDR, 50 MIM_OPTIONS 51 }; 52 53 #define BCM_MIM_PORT 1 54 #define BCM_MIM_PORT_MATCH 2 55 #define BCM_MIM_SWITCH 3 56 #define BCM_MIM_EGRESS_LABEL 4 57 #define BCM_MIM_SWITCH_ACTION 5 58 #define MAX_FLAG_LENGTH 35 59 60 #define MIM_ROE(op, arg) \ 61 do { \ 62 int __rv__; \ 63 __rv__ = op arg; \ 64 if (BCM_FAILURE(__rv__)) { \ 65 cli_out("MIM_CLI: Error: " #op " failed, %s\n", \ 66 bcm_errmsg(__rv__)); \ 67 return CMD_FAIL; \ 68 } \ 69 } while(0) 70 #define MIM_CMD(_s) \ 71 if ((cmd = ARG_CUR(a)) == NULL) { \ 72 ARG_PREV(a); \ 73 cli_out("MIM_CLI: Error: Missing arg after %s\n", ARG_CUR(a)); \ 74 return CMD_USAGE; \ 75 } else if(sal_strcasecmp(cmd, _s) == 0) 76 77 #define PT_ADD(_pt, _id, _typ, _arg) \ 78 parse_table_add(&_pt, (_id), PQ_DFL | (_typ), \ 79 (void *)(_arg), (void*)(_arg), 0) 80 81 #define PT_INIT(_u, _pt) parse_table_init(_u, &_pt); \ 82 83 #define PT_DONE(_pt) parse_arg_eq_done(&pt); 84 85 #define PT_PARSE(_a, _pt) \ 86 do { \ 87 if (parse_arg_eq(_a, &_pt) < 0) { \ 88 cli_out("MIM_CLI: Error: Invalid option or expression: %s\n", \ 89 ARG_CUR(_a)); \ 90 PT_DONE(_pt); \ 91 return CMD_USAGE; \ 92 } \ 93 } while(0) 94 95 typedef struct _bcm_tr2_mim_flag_s { 96 char *name; 97 uint32 val; 98 } _bcm_tr2_mim_flag_t; 99 100 STATIC _bcm_tr2_mim_flag_t mim_port_flags[] = { 101 {"RePLace", BCM_MIM_PORT_REPLACE}, 102 {"WithID", BCM_MIM_PORT_WITH_ID}, 103 {"DRop", BCM_MIM_PORT_DROP}, 104 {"Access", BCM_MIM_PORT_TYPE_ACCESS}, 105 {"BackBone", BCM_MIM_PORT_TYPE_BACKBONE}, 106 {"Peer", BCM_MIM_PORT_TYPE_PEER}, 107 {"MatchServiceVlanTpid", BCM_MIM_PORT_MATCH_SERVICE_VLAN_TPID}, 108 {"EgressTunnelServiceVlanReplace", BCM_MIM_PORT_EGRESS_TUNNEL_SERVICE_REPLACE}, 109 {"EgressLabel", BCM_MIM_PORT_EGRESS_LABEL}, 110 {"EgressServiceVlanTagged", BCM_MIM_PORT_EGRESS_SERVICE_VLAN_TAGGED}, 111 {"EgressServiceVlanAdd", BCM_MIM_PORT_EGRESS_SERVICE_VLAN_ADD}, 112 {"EgressServiceVlanReplace", BCM_MIM_PORT_EGRESS_SERVICE_VLAN_REPLACE}, 113 {"EgressServiceVlanDelete", BCM_MIM_PORT_EGRESS_SERVICE_VLAN_DELETE}, 114 {"EgressServiceVlanTpidReplace",BCM_MIM_PORT_EGRESS_SERVICE_VLAN_TPID_REPLACE}, 115 {"EgressTunnelDestMacUseService", BCM_MIM_PORT_EGRESS_TUNNEL_DEST_MAC_USE_SERVICE}, 116 {NULL, 0} 117 }; 118 119 STATIC _bcm_tr2_mim_flag_t mim_port_match_flags[] = { 120 {"Port", BCM_MIM_PORT_MATCH_PORT}, 121 {"PortVlan", BCM_MIM_PORT_MATCH_PORT_VLAN}, 122 {"PortVlanStacked", BCM_MIM_PORT_MATCH_PORT_VLAN_STACKED}, 123 {"TunnelVlanSrcMac", BCM_MIM_PORT_MATCH_TUNNEL_VLAN_SRCMAC}, 124 {"Label", BCM_MIM_PORT_MATCH_LABEL}, 125 {NULL, 0} 126 }; 127 128 int _bcm_tr2_mim_cli_vpn_create(int unit, args_t * a); 129 int _bcm_tr2_mim_cli_vpn_destroy(int unit, args_t * a); 130 int _bcm_tr2_mim_cli_vpn_show(int unit, args_t * a); 131 int _bcm_tr2_mim_cli_vpn_port_add(int unit, args_t * a); 132 int _bcm_tr2_mim_cli_vpn_port_del(int unit, args_t * a); 133 int _bcm_tr2_mim_cli_tunnel_l2_add(int unit, args_t * a); 134 int _bcm_tr2_mim_cli_mcast_group_create(int unit, args_t * a); 135 int _bcm_tr2_mim_cli_mcast_group_del(int unit, args_t * a); 136 int _bcm_tr2_mim_cli_mcast_group_port_add_del(int unit, args_t * a); 137 int _bcm_tr2_mim_cli_mcast_group_addr(int unit, args_t * a); 138 int _bcm_tr2_mim_cli_print_options(int unit, args_t * a); 139 int _bcm_tr2_mim_cli_action(int unit, args_t * a); 140 int _bcm_tr2_mim_cli_parse_flags(char *elo_s, int type); 141 142 143 char if_tr2_mim_usage[] = "Only for XGS4 devices.\n\t" 144 #ifdef COMPILER_STRING_CONST_LIMIT 145 " mim <option> [args...]\n" 146 #else 147 " mim init\n\t" 148 " - Init MIM software system.\n\t" 149 " mim detach\n\t" 150 " - Detach MIM software system.\n\t" 151 " mim vpn create VPN=<vpn_id> BroadcastGroup=<bcast_id>\n\t" 152 " UnknownMulticastGroup=<umc_id>\n\t" 153 " UnknownUnicastGroup=<uuc_id>\n\t" 154 " LookupId=<isid>\n\t" 155 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 156 " Policer=<policer_id>\n\t" 157 #endif 158 " - Create vpn with the given id, the ISID, broadcast group,\n\t" 159 " unknown multicast group and unknown unicast group.\n\t" 160 " mim vpn port add VPN=<vpn_id> Port=<Mim_port> PhysPort=<port>\n\t" 161 " PortMatch=<pm> IntfFlaGs=<flags> IntfCLass=<class>\n\t" 162 " MatchVlan=<vid> MatchInnerVlan=<ivid>\n\t" 163 " MatchLabel=<label> MatchTunnelVlan=<vlan>\n\t" 164 " MatchTunnelSrcMAC=<mac> MatchServiceTPID=<tpid>\n\t" 165 " EgressTunnelVlan=<vlan> EgressTunnelSrcMAC=<mac>\n\t" 166 " EgressTunnelDstMAC=<mac> EgressTunnelService=<isid>\n\t" 167 " EgressServiceTPID=<tpid> EgressServiceVID=<vid>\n\t" 168 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 169 " Policer=<policer_id>\n\t" 170 #endif 171 " - Add a port to VPN.\n\t" 172 " mim vpn port delete VPN=<vpn_id> MimPort=<mim_port_id>\n\t" 173 " - Delete an MIM port from vpn.\n\t" 174 " mim vpn destroy VPN=<vpn_id>\n\t" 175 " - Destroy a vpn.\n\t" 176 " mim vpn show VPN=<vpn_id>\n\t" 177 " - Show VPN info.\n\t" 178 " mim tunnel l2 add Mac=<mac> Vlan=<vlan>\n\t" 179 " - Add L2 address for MIM lookup.\n\t" 180 " mim mcast group create [l2|mim] McastGroup=<mcast_group>\n\t" 181 " - Create a multicast group.\n\t" 182 " mim mcast group delete McastGroup=<mcast_group>\n\t" 183 " - Delete a multicast group.\n\t" 184 " mim mcast group port add McastGroup=<mcast_type_id>\n\t" 185 " MimPort=<mim_port_id>\n\t" 186 " - Add MIM port to multicast group.\n\t" 187 " mim mcast group port delete McastGroup=<mcast_type_id>\n\t" 188 " MimPort=<mim_port_id>\n\t" 189 " - Delete MIM port from multicast group\n\t" 190 " mim mcast group addr McastGroup=<mcast_type_id>\n\t" 191 " Mac=<mcast mac> VPN=<vpn_type_id>\n\t" 192 " - Add multicast group Mac address.\n\t" 193 " mim options Type=[PORT|PortMatch]\n\t" 194 " - List various options/flags used in mim commands.\n\t" "\n" 195 #endif 196 ; 197 198 cmd_result_t 199 if_tr2_mim(int unit, args_t * a) 200 { 201 int action = 0; 202 cmd_result_t cmd_rv = CMD_OK; 203 204 if (!sh_check_attached(ARG_CMD(a), unit)) { 205 return CMD_FAIL; 206 } 207 208 if (ARG_CUR(a) == NULL) { 209 return CMD_USAGE; 210 } 211 212 action = _bcm_tr2_mim_cli_action(unit, a); 213 214 switch (action) { 215 case MIM_INIT: 216 MIM_ROE(bcm_mim_init, (unit)); 217 break; 218 case MIM_DETACH: 219 MIM_ROE(bcm_mim_detach, (unit)); 220 break; 221 case MIM_VPN_CREATE: 222 cmd_rv = _bcm_tr2_mim_cli_vpn_create(unit, a); 223 break; 224 case MIM_VPN_DESTROY: 225 cmd_rv = _bcm_tr2_mim_cli_vpn_destroy(unit, a); 226 break; 227 case MIM_VPN_SHOW: 228 cmd_rv = _bcm_tr2_mim_cli_vpn_show(unit, a); 229 break; 230 case MIM_VPN_PORT_ADD: 231 cmd_rv = _bcm_tr2_mim_cli_vpn_port_add(unit, a); 232 break; 233 case MIM_VPN_PORT_DEL: 234 cmd_rv = _bcm_tr2_mim_cli_vpn_port_del(unit, a); 235 break; 236 case MIM_TUNNEL_L2_ADD: 237 cmd_rv = _bcm_tr2_mim_cli_tunnel_l2_add(unit, a); 238 break; 239 case MIM_MCAST_GROUP_CREATE: 240 cmd_rv = _bcm_tr2_mim_cli_mcast_group_create(unit, a); 241 break; 242 case MIM_MCAST_GROUP_DEL: 243 cmd_rv = _bcm_tr2_mim_cli_mcast_group_del(unit, a); 244 break; 245 case MIM_MCAST_GROUP_PORT_ADD: 246 case MIM_MCAST_GROUP_PORT_DEL: 247 cmd_rv = _bcm_tr2_mim_cli_mcast_group_port_add_del(unit, a); 248 break; 249 case MIM_MCAST_GROUP_ADDR: 250 cmd_rv = _bcm_tr2_mim_cli_mcast_group_addr(unit, a); 251 break; 252 case MIM_OPTIONS: 253 cmd_rv = _bcm_tr2_mim_cli_print_options(unit, a); 254 break; 255 default: 256 cli_out("Error:Unknown MIM command %d\n", action); 257 return CMD_USAGE; 258 } 259 260 ARG_DISCARD(a); 261 return cmd_rv; 262 } 263 264 int 265 _bcm_tr2_mim_cli_vpn_create(int unit, args_t * a) 266 { 267 parse_table_t pt; 268 int lkid, vpn_id = BCM_VLAN_INVALID; 269 bcm_mim_vpn_config_t vpn_info; 270 bcm_multicast_t temp, bcast_group = BCM_VLAN_INVALID; 271 bcm_multicast_t umc_group = BCM_VLAN_INVALID; 272 bcm_multicast_t uuc_group = BCM_VLAN_INVALID; 273 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 274 bcm_policer_t policer_id=0; 275 #endif 276 bcm_mim_vpn_config_t_init(&vpn_info); 277 278 ARG_NEXT(a); 279 if (ARG_CNT(a) < 5) { 280 cli_out("MIM_CLI: Missing arguments\n"); 281 return CMD_USAGE; 282 } 283 PT_INIT(unit, pt); 284 PT_ADD(pt, "VPN", PQ_INT, &vpn_id); 285 PT_ADD(pt, "LookupId", PQ_INT, &lkid); 286 PT_ADD(pt, "BcastGroup", PQ_INT, &bcast_group); 287 PT_ADD(pt, "UnknownMcastGroup", PQ_INT, &umc_group); 288 PT_ADD(pt, "UnknownUcastGroup", PQ_INT, &uuc_group); 289 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 290 PT_ADD(pt, "Policer", PQ_INT, &policer_id); 291 #endif 292 PT_PARSE(a, pt); 293 PT_DONE(pt); 294 temp = bcast_group; 295 MIM_ROE(bcm_multicast_create, 296 (unit, BCM_MULTICAST_TYPE_MIM | 297 BCM_MULTICAST_WITH_ID, &bcast_group)); 298 if (umc_group != temp) { 299 MIM_ROE(bcm_multicast_create, 300 (unit, BCM_MULTICAST_TYPE_MIM | 301 BCM_MULTICAST_WITH_ID, &umc_group)); 302 } else { 303 umc_group = bcast_group; 304 } 305 if (uuc_group != temp) { 306 MIM_ROE(bcm_multicast_create, 307 (unit, BCM_MULTICAST_TYPE_MIM | 308 BCM_MULTICAST_WITH_ID, &uuc_group)); 309 } else { 310 uuc_group = bcast_group; 311 } 312 vpn_info.vpn = vpn_id; 313 vpn_info.flags = BCM_MIM_VPN_MIM | BCM_MIM_VPN_WITH_ID; 314 vpn_info.lookup_id = lkid; 315 vpn_info.broadcast_group = bcast_group; 316 vpn_info.unknown_unicast_group = uuc_group; 317 vpn_info.unknown_multicast_group = umc_group; 318 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 319 vpn_info.policer_id = policer_id; 320 #endif 321 MIM_ROE(bcm_mim_vpn_create, (unit, &vpn_info)); 322 var_set_integer(ENV_VPN_TYPE_ID, vpn_info.vpn, TRUE, FALSE); 323 cli_out("env var added : $vpn_type_id=0x%08x\n", vpn_info.vpn); 324 var_set_integer(ENV_MCAST_TYPE_ID, bcast_group, TRUE, FALSE); 325 cli_out("env var added : $bcast_type_id=0x%08x\n", bcast_group); 326 var_set_integer(ENV_MCAST_TYPE_ID, umc_group, TRUE, FALSE); 327 cli_out("env var added : $umc_type_id=0x%08x\n", umc_group); 328 var_set_integer(ENV_MCAST_TYPE_ID, uuc_group, TRUE, FALSE); 329 cli_out("env var added : $uuc_type_id=0x%08x\n", uuc_group); 330 return CMD_OK; 331 } 332 333 int 334 _bcm_tr2_mim_cli_vpn_destroy(int unit, args_t * a) 335 { 336 parse_table_t pt; 337 int vpn_id = BCM_VLAN_INVALID; 338 339 ARG_NEXT(a); 340 if (ARG_CUR(a) == NULL) { 341 cli_out("MIM_CLI: Missing arguments\n"); 342 return CMD_USAGE; 343 } 344 PT_INIT(unit, pt); 345 PT_ADD(pt, "VPN", PQ_INT, &vpn_id); 346 PT_PARSE(a, pt); 347 PT_DONE(pt); 348 MIM_ROE(bcm_mim_vpn_destroy, (unit, vpn_id)); 349 cli_out("Destroyed vpn id=0x%08x\n", vpn_id); 350 351 return CMD_OK; 352 } 353 354 int 355 _bcm_tr2_mim_cli_vpn_show(int unit, args_t * a) 356 { 357 int i; 358 int count; 359 int max = 10; 360 parse_table_t pt; 361 int vpn_id = BCM_VLAN_INVALID; 362 bcm_mim_port_t port_array[10]; 363 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 364 bcm_mim_vpn_config_t vpn_info; 365 bcm_mim_vpn_config_t_init(&vpn_info); 366 #endif 367 368 ARG_NEXT(a); 369 if (ARG_CUR(a) == NULL) { 370 cli_out("MIM_CLI: Missing arguments\n"); 371 return CMD_USAGE; 372 } 373 PT_INIT(unit, pt); 374 PT_ADD(pt, "VPN", PQ_INT, &vpn_id); 375 PT_PARSE(a, pt); 376 PT_DONE(pt); 377 MIM_ROE(bcm_mim_port_get_all, (unit, vpn_id, max, 378 port_array, &count)); 379 cli_out("VPN id=0x%08x, Ports :%d\n", vpn_id, count); 380 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 381 MIM_ROE(bcm_mim_vpn_get, (unit, vpn_id, &vpn_info)); 382 cli_out("Policer id=0x%x\n", vpn_info.policer_id); 383 #endif 384 for (i = 0; i < count; i++) { 385 cli_out("\n MIM Port ID: %x", port_array[i].mim_port_id); 386 cli_out("\n flags: %x", port_array[i].flags); 387 cli_out("\n criteria: %d", port_array[i].criteria); 388 cli_out("\n port: %x", port_array[i].port); 389 cli_out("\n match_vlan: %d", port_array[i].match_vlan); 390 cli_out("\n match_inner_vlan: %d", port_array[i].match_inner_vlan); 391 cli_out("\n match_label: %d", port_array[i].match_label); 392 cli_out("\n encap_id: %d\n", port_array[i].encap_id); 393 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 394 cli_out("\nPolicer id=0x%x\n", port_array[i].policer_id); 395 #endif 396 } 397 398 return CMD_OK; 399 } 400 401 int 402 _bcm_tr2_mim_cli_vpn_port_add(int unit, args_t * a) 403 { 404 parse_table_t pt; 405 int vlan = BCM_VLAN_INVALID; 406 int ivlan = BCM_VLAN_INVALID; 407 int mtvlan = BCM_VLAN_INVALID; 408 int etvlan = BCM_VLAN_INVALID; 409 int esvid = BCM_VLAN_INVALID; 410 bcm_port_t port = -1; 411 bcm_port_t phys_port = -1; 412 int icl = 0; 413 char *pm_s = 0; 414 uint32 pm = 0; 415 char *ifl_s = 0; 416 uint32 ifl = 0; 417 int mstpid = 0x8100; 418 int estpid = 0x8100; 419 bcm_mim_port_t mport; 420 int vpn_id = BCM_VLAN_INVALID; 421 bcm_mac_t mtsmac, etsmac, etdmac; 422 int elkid = 0; 423 bcm_mpls_label_t label = 0; 424 bcm_gport_t gp = BCM_GPORT_INVALID; 425 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 426 bcm_policer_t policer_id=0; 427 #endif 428 429 sal_memset(mtsmac, 0, sizeof(bcm_mac_t)); 430 sal_memset(etsmac, 0, sizeof(bcm_mac_t)); 431 sal_memset(etdmac, 0, sizeof(bcm_mac_t)); 432 ARG_NEXT(a); 433 PT_INIT(unit, pt); 434 PT_ADD(pt, "VPN", PQ_INT, &vpn_id); 435 PT_ADD(pt, "Port", PQ_INT, &port); 436 PT_ADD(pt, "PhysPort", PQ_INT, &phys_port); 437 PT_ADD(pt, "PortMatch", PQ_STRING, &pm_s); 438 PT_ADD(pt, "IntfFlaGs", PQ_STRING, &ifl_s); 439 PT_ADD(pt, "IntfCLass", PQ_INT, &icl); 440 PT_ADD(pt, "MatchVlan", PQ_INT, &vlan); 441 PT_ADD(pt, "MatchInnerVlan", PQ_INT, &ivlan); 442 PT_ADD(pt, "MatchLabel", PQ_INT, &label); 443 PT_ADD(pt, "MatchTunnelVlan", PQ_INT, &mtvlan); 444 PT_ADD(pt, "MatchTunnelSrcMAC", PQ_MAC, mtsmac); 445 PT_ADD(pt, "MatchServiceTPID", PQ_INT, &mstpid); 446 PT_ADD(pt, "EgressTunnelVlan", PQ_INT, &etvlan); 447 PT_ADD(pt, "EgressTunnelSrcMAC", PQ_MAC, etsmac); 448 PT_ADD(pt, "EgressTunnelDstMAC", PQ_MAC, etdmac); 449 PT_ADD(pt, "EgressTunnelService", PQ_INT, &elkid); 450 PT_ADD(pt, "EgressServiceTPID", PQ_INT, &estpid); 451 PT_ADD(pt, "EgressServiceVID", PQ_INT, &esvid); 452 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 453 PT_ADD(pt, "Policer", PQ_INT, &policer_id); 454 #endif 455 456 PT_PARSE(a, pt); 457 458 if (pm_s) { 459 pm = _bcm_tr2_mim_cli_parse_flags(pm_s, BCM_MIM_PORT_MATCH); 460 } 461 if (ifl_s) { 462 ifl = _bcm_tr2_mim_cli_parse_flags(ifl_s, BCM_MIM_PORT); 463 } 464 LOG_INFO(BSL_LS_APPL_TESTS, 465 (BSL_META_U(unit, 466 "Adding port %d to vpn 0x%08x, PhysPort=%d, PortMatch=%s," 467 "IntfFLaGs=%s MatchVlan=%d MatchInnerVlan=%d\n" 468 "MatchLabel=0x%x MatchTunnelVlan=%d icl=%d\n" 469 "MatchTunnelSrcMAC=%02x:%02x:%02x:%02x:%02x:%02x\n" 470 "MatchServiceTPID=%04x EgressTunnelVlan=%d\n" 471 "EgressTunnelSrcMAC=%02x:%02x:%02x:%02x:%02x:%02x\n" 472 "EgressTunnelDstMAC=%02x:%02x:%02x:%02x:%02x:%02x\n" 473 "EgressTunnelService=%d\n" 474 "EgressServiceTPID=%04x EgressServiceVID=%d\n"), 475 port, vpn_id, phys_port, pm_s, ifl_s, vlan, ivlan, 476 label, mtvlan, icl, mtsmac[0], mtsmac[1], mtsmac[2], 477 mtsmac[3], mtsmac[4], mtsmac[5], mstpid, etvlan, etsmac[0], 478 etsmac[1], etsmac[2], etsmac[3], etsmac[4], etsmac[5], 479 etdmac[0], etdmac[1], etdmac[2], etdmac[3], etdmac[4], 480 etdmac[5], elkid, estpid, esvid)); 481 482 PT_DONE(pt); 483 bcm_mim_port_t_init(&mport); 484 if (ifl & (BCM_MIM_PORT_REPLACE | BCM_MIM_PORT_WITH_ID)) { 485 BCM_GPORT_MIM_PORT_ID_SET(mport.mim_port_id, port); 486 LOG_INFO(BSL_LS_APPL_TESTS, 487 (BSL_META_U(unit, 488 "mim port=%08x\n"), port)); 489 } 490 MIM_ROE(bcm_port_gport_get, (unit, phys_port, &gp)); 491 mport.port = gp; 492 LOG_INFO(BSL_LS_APPL_TESTS, 493 (BSL_META_U(unit, 494 "gport_get gp=%08x\n"), gp)); 495 mport.criteria = pm; 496 mport.flags = ifl; 497 mport.if_class = icl; 498 mport.match_vlan = vlan; 499 mport.match_inner_vlan = ivlan; 500 mport.match_label = label; 501 mport.match_tunnel_vlan = mtvlan; 502 memcpy(mport.match_tunnel_srcmac, mtsmac, sizeof(sal_mac_addr_t)); 503 mport.match_service_tpid = mstpid; 504 mport.egress_tunnel_vlan = etvlan; 505 memcpy(mport.egress_tunnel_srcmac, etsmac, sizeof(sal_mac_addr_t)); 506 memcpy(mport.egress_tunnel_dstmac, etdmac, sizeof(sal_mac_addr_t)); 507 mport.egress_tunnel_service = elkid; 508 mport.egress_service_tpid = estpid; 509 mport.egress_service_vlan = esvid; 510 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT) 511 mport.policer_id = policer_id; 512 #endif 513 MIM_ROE(bcm_mim_port_add, (unit, vpn_id, &mport)); 514 var_set_integer(ENV_MIM_TYPE_ID, mport.mim_port_id, TRUE, FALSE); 515 cli_out("env var added : $mim_port_id=0x%08x\n", mport.mim_port_id); 516 517 return CMD_OK; 518 } 519 520 int 521 _bcm_tr2_mim_cli_vpn_port_del(int unit, args_t * a) 522 { 523 parse_table_t pt; 524 int vpn_id = BCM_VLAN_INVALID; 525 bcm_gport_t gp = BCM_GPORT_INVALID; 526 ARG_NEXT(a); 527 528 PT_INIT(unit, pt); 529 PT_ADD(pt, "VPN", PQ_INT, &vpn_id); 530 PT_ADD(pt, "MimPort", PQ_INT, &gp); 531 PT_PARSE(a, pt); 532 PT_DONE(pt); 533 MIM_ROE(bcm_mim_port_delete, (unit, vpn_id, gp)); 534 535 return CMD_OK; 536 } 537 538 int 539 _bcm_tr2_mim_cli_tunnel_l2_add(int unit, args_t * a) 540 { 541 bcm_mac_t mac; 542 parse_table_t pt; 543 int vlan = BCM_VLAN_INVALID; 544 545 ARG_NEXT(a); 546 PT_INIT(unit, pt); 547 PT_ADD(pt, "Mac", PQ_MAC, &mac); 548 PT_ADD(pt, "Vlan", PQ_INT, &vlan); 549 PT_PARSE(a, pt); 550 LOG_INFO(BSL_LS_APPL_TESTS, 551 (BSL_META_U(unit, 552 "l2 add mac=%02x:%02x:%02x:%02x:%02x:%02x vlan=%d\n"), 553 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], vlan)); 554 PT_DONE(pt); 555 MIM_ROE(bcm_l2_tunnel_add, (unit, mac, vlan)); 556 557 return CMD_OK; 558 559 } 560 561 int 562 _bcm_tr2_mim_cli_mcast_group_create(int unit, args_t * a) 563 { 564 int flags = -1; 565 int mcast_group = BCM_VLAN_INVALID; 566 char *cmd; 567 parse_table_t pt; 568 569 ARG_NEXT(a); /* mim,l2 etc. */ 570 MIM_CMD("l2") { 571 flags = BCM_MULTICAST_TYPE_L2; 572 } 573 MIM_CMD("mim") { 574 flags = BCM_MULTICAST_TYPE_MIM; 575 } 576 ARG_NEXT(a); 577 PT_INIT(unit, pt); 578 PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group); 579 PT_PARSE(a, pt); 580 LOG_INFO(BSL_LS_APPL_TESTS, 581 (BSL_META_U(unit, 582 "mcast group %d\n"), mcast_group)); 583 flags |= BCM_MULTICAST_WITH_ID; 584 PT_DONE(pt); 585 MIM_ROE(bcm_multicast_create, (unit, flags, &mcast_group)); 586 var_set_integer(ENV_MCAST_TYPE_ID, mcast_group, TRUE, FALSE); 587 cli_out("env var added : $mcast_type_id=0x%08x\n", mcast_group); 588 589 return CMD_OK; 590 } 591 592 int 593 _bcm_tr2_mim_cli_mcast_group_del(int unit, args_t * a) 594 { 595 int mcast_group = BCM_VLAN_INVALID; 596 parse_table_t pt; 597 598 ARG_NEXT(a); 599 PT_INIT(unit, pt); 600 PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group); 601 PT_PARSE(a, pt); 602 PT_DONE(pt); 603 MIM_ROE(bcm_multicast_destroy, (unit, mcast_group)); 604 LOG_INFO(BSL_LS_APPL_TESTS, 605 (BSL_META_U(unit, 606 "mcast group %d destroyed\n"), mcast_group)); 607 608 return CMD_OK; 609 } 610 611 int 612 _bcm_tr2_mim_cli_mcast_group_port_add_del(int unit, args_t * a) 613 { 614 int add = 0; 615 int mcast_group = BCM_VLAN_INVALID; 616 bcm_module_t modid; 617 bcm_port_t port; 618 bcm_trunk_t trunk_id; 619 int id; 620 bcm_gport_t gp = BCM_GPORT_INVALID; 621 bcm_gport_t mim_port; 622 bcm_if_t encap_id; 623 parse_table_t pt; 624 char *cmd; 625 626 ARG_NEXT(a); 627 MIM_CMD("add") { 628 add = 1; 629 } 630 MIM_CMD("delete") { 631 add = 0; 632 } 633 ARG_NEXT(a); 634 PT_INIT(unit, pt); 635 PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group); 636 PT_ADD(pt, "MimPort", PQ_INT, &mim_port); 637 PT_PARSE(a, pt); 638 PT_DONE(pt); 639 MIM_ROE(_bcm_esw_gport_resolve, 640 (unit, mim_port, &modid, &port, &trunk_id, &id)); 641 MIM_ROE(bcm_port_gport_get, (unit, port, &gp)); 642 MIM_ROE(bcm_multicast_mim_encap_get, 643 (unit, mcast_group, gp, mim_port, &encap_id)); 644 LOG_INFO(BSL_LS_APPL_TESTS, 645 (BSL_META_U(unit, 646 "MIM_CLI: mim mcast group port %s mim" 647 "group 0x%x gport 0x%0x mim_port 0x%08xnh %d\n"), 648 add ? "add" : "delete", mcast_group, gp, mim_port, 649 encap_id)); 650 if (add) { 651 MIM_ROE(bcm_multicast_egress_add, 652 (unit, mcast_group, gp, encap_id)); 653 } else { 654 MIM_ROE(bcm_multicast_egress_delete, 655 (unit, mcast_group, gp, encap_id)); 656 } 657 658 return CMD_OK; 659 } 660 661 int 662 _bcm_tr2_mim_cli_mcast_group_addr(int unit, args_t * a) 663 { 664 int mcast_group = BCM_VLAN_INVALID; 665 int vpn; 666 bcm_mac_t mac; 667 bcm_l2_addr_t l2_addr; 668 parse_table_t pt; 669 670 ARG_NEXT(a); 671 PT_INIT(unit, pt); 672 PT_ADD(pt, "McastGroup", PQ_INT, &mcast_group); 673 PT_ADD(pt, "Mac", PQ_MAC, mac); 674 PT_ADD(pt, "VPN", PQ_INT, &vpn); 675 PT_PARSE(a, pt); 676 677 bcm_l2_addr_t_init(&l2_addr, mac, vpn); 678 l2_addr.flags = BCM_L2_STATIC | BCM_L2_MCAST; 679 l2_addr.l2mc_group = mcast_group; 680 PT_DONE(pt); 681 MIM_ROE(bcm_l2_addr_add, (unit, &l2_addr)); 682 LOG_INFO(BSL_LS_APPL_TESTS, 683 (BSL_META_U(unit, 684 "mcast l2 addr add=%02x:%02x:%02x:%02x:%02x:%02x \n"), 685 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])); 686 cli_out("MIM_CLI: mc_group 0x%08x vpn 0x%08x\n", mcast_group, vpn); 687 PT_DONE(pt); 688 689 return CMD_OK; 690 } 691 692 int 693 _bcm_tr2_mim_cli_print_options(int unit, args_t * a) 694 { 695 int i; 696 char *type_s = 0; 697 parse_table_t pt; 698 _bcm_tr2_mim_flag_t *flags = 0; 699 700 ARG_NEXT(a); 701 PT_INIT(unit, pt); 702 PT_ADD(pt, "Type", PQ_STRING, &type_s); 703 PT_PARSE(a, pt); 704 705 if (parse_cmp("PortMatch", type_s, '\0')) { 706 flags = mim_port_match_flags; 707 } else if (parse_cmp(type_s, "PORT", '\0')) { 708 flags = mim_port_flags; 709 } 710 PT_DONE(pt); 711 712 if (flags) { 713 for (i = 0; flags[i].name != NULL; i++) { 714 cli_out("\t%-25s 0x%08x\n", flags[i].name, flags[i].val); 715 } 716 } else { 717 cli_out("Port Flags:\n\t"); 718 for (i = 0; mim_port_flags[i].name != NULL; i++) { 719 cli_out("%-35s 0x%08x\n\t", mim_port_flags[i].name, 720 mim_port_flags[i].val); 721 } 722 cli_out("\nPort Match Flags:\n\t"); 723 for (i = 0; mim_port_match_flags[i].name != NULL; i++) { 724 cli_out("%-35s 0x%08x\n\t", mim_port_match_flags[i].name, 725 mim_port_match_flags[i].val); 726 } 727 cli_out("\n"); 728 } 729 730 return CMD_OK; 731 } 732 733 int 734 _bcm_tr2_mim_cli_action(int unit, args_t * a) 735 { 736 char *cmd; 737 int action = -1; 738 739 MIM_CMD("init") { 740 action = MIM_INIT; 741 } 742 743 MIM_CMD("detach") { 744 action = MIM_DETACH; 745 } 746 747 MIM_CMD("options") { 748 action = MIM_OPTIONS; 749 } 750 751 MIM_CMD("vpn") { 752 ARG_NEXT(a); 753 MIM_CMD("create") { 754 action = MIM_VPN_CREATE; 755 } 756 MIM_CMD("destroy") { 757 action = MIM_VPN_DESTROY; 758 } 759 MIM_CMD("show") { 760 action = MIM_VPN_SHOW; 761 } 762 MIM_CMD("port") { 763 ARG_NEXT(a); 764 MIM_CMD("add") { 765 action = MIM_VPN_PORT_ADD; 766 } 767 MIM_CMD("delete") { 768 action = MIM_VPN_PORT_DEL; 769 } 770 } 771 } 772 773 MIM_CMD("tunnel") { 774 ARG_NEXT(a); 775 MIM_CMD("l2") { 776 ARG_NEXT(a); 777 MIM_CMD("add") { 778 action = MIM_TUNNEL_L2_ADD; 779 } 780 } 781 } 782 783 MIM_CMD("mcast") { 784 ARG_NEXT(a); 785 MIM_CMD("group") { 786 ARG_NEXT(a); 787 MIM_CMD("create") { 788 action = MIM_MCAST_GROUP_CREATE; 789 } 790 MIM_CMD("delete") { 791 action = MIM_MCAST_GROUP_DEL; 792 } 793 MIM_CMD("port") { 794 action = MIM_MCAST_GROUP_PORT_ADD; 795 } 796 MIM_CMD("addr") { 797 action = MIM_MCAST_GROUP_ADDR; 798 } 799 } 800 } 801 802 return action; 803 } 804 805 int 806 _bcm_tr2_mim_cli_parse_flags(char *input_s, int type) 807 { 808 int cnt; 809 int len; 810 char *p; 811 char f_name[MAX_FLAG_LENGTH]; 812 _bcm_tr2_mim_flag_t *flags; 813 uint32 result = 0; 814 int done = 0; 815 int found = 0; 816 817 if (isint(input_s)) { 818 result = parse_integer(input_s); 819 return result; 820 } 821 822 switch (type) { 823 case BCM_MIM_PORT: 824 flags = mim_port_flags; 825 break; 826 case BCM_MIM_PORT_MATCH: 827 flags = mim_port_match_flags; 828 break; 829 default: 830 flags = 0; 831 } /* switch (type) */ 832 833 if(!flags) { 834 cli_out("MIM CLI: Error: Discarded unrecognized Flags\n\t %s\n", 835 input_s); 836 return 0; 837 } 838 839 while (!done) { 840 p = (char*)strcaseindex(input_s,","); 841 sal_memset(f_name, 0, MAX_FLAG_LENGTH); 842 if (p) { 843 strncpy(f_name, input_s, p-input_s); 844 input_s = p + 1; 845 } else { 846 len = (sal_strlen(input_s) >= MAX_FLAG_LENGTH) ? 847 (MAX_FLAG_LENGTH - 1) : sal_strlen(input_s); 848 strncpy(f_name, input_s, len); 849 done = 1; 850 } 851 found = 0; 852 for (cnt = 0; flags[cnt].name ; cnt++) { 853 if (parse_cmp(flags[cnt].name, f_name, '\0')) { 854 result |= flags[cnt].val; 855 found = 1; 856 } 857 } 858 if (!found) { 859 cli_out("MIM_CLI: flag %s not recognized, discarded\n", f_name); 860 } 861 } 862 return result; 863 864 } 865 #endif /* BCM_TRIUMPH2_SUPPORT */ 866 #endif /* INCLUDE_L3 */