snmp.c (9682B)
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 * SNMP Statistics Retrieval test. 8 * 9 * For every port, and every speed possible on that port, can 10 * we retrieve SNMP statistics without an error? This test will 11 * confirm that this is the case. 12 */ 13 14 #include <stdarg.h> 15 #include <sal/types.h> 16 17 #include <appl/diag/system.h> 18 #include <appl/diag/parse.h> 19 #include <soc/debug.h> 20 #include <sal/appl/pci.h> 21 #include <bcm/error.h> 22 #include <bcm/link.h> 23 #include <bcm/stat.h> 24 #include <appl/diag/test.h> 25 #include <shared/bsl.h> 26 #include "testlist.h" 27 28 #if defined (BCM_ESW_SUPPORT) || defined (BCM_PETRA_SUPPORT) 29 30 #undef min 31 #define min(x, y) ((x) <= (y) ? (x) : (y)) 32 33 typedef struct snmp_test_s { 34 35 int unit; 36 int speed; 37 int failures; 38 int not_impl; 39 int linkscan_enable; 40 bcm_port_info_t snmp_save_port[SOC_MAX_NUM_PORTS]; 41 bcm_pbmp_t snmp_multi_set_pbmp; 42 } snmp_test_t; 43 44 int 45 snmp_test_done(int u, void *pa) 46 { 47 int port, rv; 48 snmp_test_t *b = (snmp_test_t *) pa; 49 50 PBMP_PORT_ITER(b->unit, port) { 51 if (BCM_PBMP_MEMBER(b->snmp_multi_set_pbmp, port)) { 52 /* for multi_set ports, use speed=0 to recover the default configurations */ 53 } else { 54 if ((rv = bcm_port_info_set(b->unit, port, 55 &b->snmp_save_port[port])) < 0) { 56 test_error(b->unit, 57 "Port %d: Could not set port info: %s\n", 58 port + 1, bcm_errmsg(rv)); 59 return -1; 60 } 61 } 62 } 63 64 sal_free(b); 65 66 return 0; 67 } 68 69 int 70 snmp_test_init(int u, args_t *a, void **pa) 71 { 72 snmp_test_t *b = 0; 73 int port, rv = -1; 74 75 if ((b = sal_alloc(sizeof (snmp_test_t), "snmp")) == 0) { 76 goto done; 77 } 78 79 sal_memset(b, 0, sizeof (*b)); 80 b->unit = u; 81 82 *pa = (void *) b; 83 84 /* Save port states */ 85 PBMP_PORT_ITER(b->unit, port) { 86 if ((rv = bcm_port_info_get(b->unit, port, 87 &b->snmp_save_port[port])) < 0) { 88 test_error(b->unit, 89 "Port %d: Could not get port info: %s\n", 90 port + 1, bcm_errmsg(rv)); 91 return -1; 92 } 93 } 94 95 rv = 0; 96 97 done: 98 if (rv < 0) { 99 snmp_test_done(u, *pa); 100 } 101 102 return rv; 103 } 104 105 static int 106 snmp_test_begin(snmp_test_t *b, 107 int speed) 108 { 109 uint64 v64; 110 int port, rv, speedToUse = 0; 111 bcm_stat_val_t object; 112 bcm_port_ability_t ability; 113 int nport = 0, p = 0; 114 int alloc_sz; 115 bcm_port_resource_t *resource = NULL; 116 117 b->failures = 0; 118 b->not_impl = 0; 119 BCM_PBMP_CLEAR(b->snmp_multi_set_pbmp); 120 121 if (SOC_IS_TOMAHAWK2(b->unit)) { 122 BCM_PBMP_ASSIGN(b->snmp_multi_set_pbmp, PBMP_PORT_ALL(b->unit)); 123 BCM_PBMP_REMOVE(b->snmp_multi_set_pbmp, PBMP_MANAGEMENT(b->unit)); 124 } 125 126 if (BCM_PBMP_NOT_NULL(b->snmp_multi_set_pbmp)) { 127 BCM_PBMP_COUNT(b->snmp_multi_set_pbmp, nport); 128 alloc_sz = sizeof(bcm_port_resource_t) * nport * 2; 129 resource = sal_alloc(alloc_sz, "port_resource"); 130 if (resource == NULL) { 131 return BCM_E_MEMORY; 132 } 133 sal_memset(resource, 0, alloc_sz); 134 } 135 136 p = 0; 137 /* Set up all port speeds */ 138 PBMP_PORT_ITER(b->unit, port) { 139 rv = bcm_port_ability_local_get(b->unit, port, &ability); 140 141 switch(speed) { 142 case 10: 143 if ((ability.speed_full_duplex & SOC_PA_SPEED_10MB) || 144 (ability.speed_half_duplex & SOC_PA_SPEED_10MB)){ 145 speedToUse = 10; 146 break; 147 } 148 /* fall through */ 149 case 100: 150 if ((ability.speed_full_duplex & SOC_PA_SPEED_100MB) || 151 (ability.speed_half_duplex & SOC_PA_SPEED_100MB)){ 152 speedToUse = 100; 153 break; 154 } 155 /* fall through */ 156 case 1000: 157 if ((ability.speed_full_duplex & SOC_PA_SPEED_1000MB) || 158 (ability.speed_half_duplex & SOC_PA_SPEED_1000MB)){ 159 speedToUse = 1000; 160 break; 161 } 162 /* fall through */ 163 case 2500: 164 if ((ability.speed_full_duplex & SOC_PA_SPEED_2500MB) || 165 (ability.speed_half_duplex & SOC_PA_SPEED_2500MB)){ 166 speedToUse = 2500; 167 break; 168 } 169 /* fall through */ 170 case 3000: 171 if ((ability.speed_full_duplex & SOC_PA_SPEED_3000MB) || 172 (ability.speed_half_duplex & SOC_PA_SPEED_3000MB)){ 173 speedToUse = 3000; 174 break; 175 } 176 /* fall through */ 177 case 10000: 178 if ((ability.speed_full_duplex & SOC_PA_SPEED_10GB) || 179 (ability.speed_half_duplex & SOC_PA_SPEED_10GB) || 180 (b->snmp_save_port[port].port_ability.speed_full_duplex & SOC_PA_SPEED_10GB) || 181 (b->snmp_save_port[port].port_ability.speed_half_duplex & SOC_PA_SPEED_10GB)){ 182 speedToUse = 10000; 183 break; 184 } 185 /* fall through */ 186 default: 187 rv = bcm_port_speed_max(b->unit, port, &speedToUse); 188 if (speedToUse < b->snmp_save_port[port].speed_max) { 189 speedToUse = b->snmp_save_port[port].speed_max; 190 } 191 } 192 193 if (bsl_check(bslLayerAppl, bslSourceTests, bslSeverityNormal, b->unit)) { 194 LOG_INFO(BSL_LS_APPL_TESTS, 195 (BSL_META_U(b->unit, 196 "Port %d: full 0x%x half 0x%x actual speed %d\n"), 197 port, ability.speed_full_duplex, ability.speed_half_duplex, 198 speedToUse)); 199 } 200 201 if (BCM_FAILURE(rv) || (!speedToUse)) { 202 test_error(b->unit, 203 "Port %d: Could not configure speed : %d\n", 204 port, speed); 205 } 206 207 if (BCM_PBMP_NOT_NULL(b->snmp_multi_set_pbmp) && 208 BCM_PBMP_MEMBER(b->snmp_multi_set_pbmp, port)) { 209 /* 210 * Build port resource 211 */ 212 /* Keep encap, lanes, phy_port the same */ 213 resource[p].port = port; 214 resource[p].physical_port = -1; 215 216 bcm_port_resource_t_init(&resource[p+nport]); 217 rv = bcm_port_resource_get(b->unit, port, &resource[p+nport]); 218 if (BCM_SUCCESS(rv)) { 219 resource[p+nport].speed = speedToUse; 220 p++; 221 } else { 222 test_error(b->unit, 223 "Port %d: Could not get port resouce on speed %d: %s\n", 224 port, speedToUse, bcm_errmsg(rv)); 225 } 226 } else { 227 if ((rv = bcm_port_speed_set(b->unit, port, speedToUse)) < 0) { 228 test_error(b->unit, 229 "Port %d: Could not set speed to %d: %s\n", 230 port, speedToUse, bcm_errmsg(rv)); 231 } 232 } 233 } 234 235 if (BCM_PBMP_NOT_NULL(b->snmp_multi_set_pbmp)) { 236 (void)bcm_linkscan_enable_get(b->unit, &b->linkscan_enable); 237 (void)bcm_linkscan_enable_set(b->unit, 0); 238 PBMP_ITER(b->snmp_multi_set_pbmp, port) { 239 (void)bcm_port_enable_set(b->unit, port, 0); 240 } 241 rv = bcm_port_resource_multi_set(b->unit, nport * 2, resource); 242 if (BCM_FAILURE(rv)) { 243 test_error(b->unit, 244 "Port resouce configuration failed! %s\n", 245 bcm_errmsg(rv)); 246 } 247 PBMP_ITER(b->snmp_multi_set_pbmp, port) { 248 (void)bcm_port_enable_set(b->unit, port, 1); 249 } 250 (void)bcm_linkscan_enable_set(b->unit, b->linkscan_enable); 251 sal_free(resource); 252 } 253 254 b->speed = speed; 255 256 /* Now, call bcm_stat_get() for every stat on every port */ 257 258 PBMP_PORT_ITER(b->unit, port) { 259 /* 260 * Now, for every object, find out if it generates an error on 261 * that port. 262 */ 263 for (object = 0; object < snmpValCount; object++) { 264 rv = bcm_stat_get(b->unit, port, object, &v64); 265 266 if (rv == BCM_E_UNAVAIL) { 267 b->not_impl++; 268 } else if (rv < 0) { 269 cli_out("FAIL: u=%d:speed=%d:port=%d:object=%d:rv=%d: %s\n", 270 b->unit, b->speed,port, object, rv, bcm_errmsg(rv)); 271 b->failures++; 272 } else { 273 /* No output */ 274 LOG_VERBOSE(BSL_LS_SOC_COMMON, 275 (BSL_META_U(b->unit, 276 "PASS: u=%d:speed=%d:port=%d:object=%d:rv=%d: %s\n"), 277 b->unit, b->speed, port, object, rv, bcm_errmsg(rv))); 278 } 279 } 280 } 281 282 return 1; 283 } 284 285 static void 286 snmp_test_end(snmp_test_t *b) 287 { 288 cli_out("All Ports: Max speed=%d: %d failures; %d vars not implemented\n", 289 b->speed, b->failures, b->not_impl); 290 } 291 292 int 293 snmp_test_test(int unit, args_t *a, void *pa) 294 { 295 snmp_test_t *b = (snmp_test_t *) pa; 296 int i, speeds[] = {10000, 10, 100, 1000, 10000, 0, -1}; 297 int rc = 0; 298 299 COMPILER_REFERENCE(a); 300 301 for (i = 0; speeds[i] >= 0; i++) { 302 snmp_test_begin(b, speeds[i]); 303 snmp_test_end(b); 304 305 if (b->failures > 0) { 306 rc = -1; 307 } 308 } 309 310 return rc; 311 } 312 313 #endif /* BCM_ESW_SUPPORT */