Mercurial > flash_v2
comparison packages/net/snmp/agent/current/tests/snmpping.c @ 119:77cec8369160 ecos-sw-2000-09-01
Merge from eCos master repository on 2000-09-01-07:47:03-BST
| author | jlarmour |
|---|---|
| date | Fri, 01 Sep 2000 13:45:23 +0000 |
| parents | 6ed91473a1cd |
| children | 0d0f03f76f6a |
comparison
equal
deleted
inserted
replaced
| 118:59c1a83fb200 | 119:77cec8369160 |
|---|---|
| 136 | 136 |
| 137 // PING test code | 137 // PING test code |
| 138 | 138 |
| 139 #include <network.h> | 139 #include <network.h> |
| 140 | 140 |
| 141 #include <pkgconf/system.h> | |
| 142 #include <pkgconf/net.h> | |
| 143 | |
| 141 #include <cyg/infra/testcase.h> | 144 #include <cyg/infra/testcase.h> |
| 145 | |
| 146 #ifdef CYGBLD_DEVS_ETH_DEVICE_H // Get the device config if it exists | |
| 147 #include CYGBLD_DEVS_ETH_DEVICE_H // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME | |
| 148 #endif | |
| 149 | |
| 150 #ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test? | |
| 151 # ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists | |
| 152 # include CYGTST_DEVS_ETH_TEST_NET_REALTIME | |
| 153 # endif | |
| 154 #endif | |
| 155 | |
| 156 // Fill in the blanks if necessary | |
| 157 #ifndef TNR_OFF | |
| 158 # define TNR_OFF() | |
| 159 #endif | |
| 160 #ifndef TNR_ON | |
| 161 # define TNR_ON() | |
| 162 #endif | |
| 163 #ifndef TNR_INIT | |
| 164 # define TNR_INIT() | |
| 165 #endif | |
| 166 #ifndef TNR_PRINT_ACTIVITY | |
| 167 # define TNR_PRINT_ACTIVITY() | |
| 168 #endif | |
| 142 | 169 |
| 143 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000) | 170 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000) |
| 144 static char stack[STACK_SIZE]; | 171 static char stack[STACK_SIZE]; |
| 145 static cyg_thread thread_data; | 172 static cyg_thread thread_data; |
| 146 static cyg_handle_t thread_handle; | 173 static cyg_handle_t thread_handle; |
| 230 struct sockaddr_in from; | 257 struct sockaddr_in from; |
| 231 int i, len, fromlen; | 258 int i, len, fromlen; |
| 232 | 259 |
| 233 ok_recv = 0; | 260 ok_recv = 0; |
| 234 bogus_recv = 0; | 261 bogus_recv = 0; |
| 262 TNR_OFF(); | |
| 235 diag_printf("PING server %s\n", inet_ntoa(host->sin_addr)); | 263 diag_printf("PING server %s\n", inet_ntoa(host->sin_addr)); |
| 236 for (seq = 0; seq < NUM_PINGS; seq++) { | 264 for (seq = 0; seq < NUM_PINGS; seq++) { |
| 265 TNR_ON(); | |
| 237 // Build ICMP packet | 266 // Build ICMP packet |
| 238 icmp->icmp_type = ICMP_ECHO; | 267 icmp->icmp_type = ICMP_ECHO; |
| 239 icmp->icmp_code = 0; | 268 icmp->icmp_code = 0; |
| 240 icmp->icmp_cksum = 0; | 269 icmp->icmp_cksum = 0; |
| 241 icmp->icmp_seq = seq; | 270 icmp->icmp_seq = seq; |
| 249 } | 278 } |
| 250 // Add checksum | 279 // Add checksum |
| 251 icmp->icmp_cksum = inet_cksum( (u_short *)icmp, icmp_len+8); | 280 icmp->icmp_cksum = inet_cksum( (u_short *)icmp, icmp_len+8); |
| 252 // Send it off | 281 // Send it off |
| 253 if (sendto(s, icmp, icmp_len+8, 0, (struct sockaddr *)host, sizeof(*host)) < 0) { | 282 if (sendto(s, icmp, icmp_len+8, 0, (struct sockaddr *)host, sizeof(*host)) < 0) { |
| 283 TNR_OFF(); | |
| 254 perror("sendto"); | 284 perror("sendto"); |
| 255 continue; | 285 continue; |
| 256 } | 286 } |
| 257 // Wait for a response | 287 // Wait for a response |
| 258 fromlen = sizeof(from); | 288 fromlen = sizeof(from); |
| 259 len = recvfrom(s, pkt2, sizeof(pkt2), 0, (struct sockaddr *)&from, &fromlen); | 289 len = recvfrom(s, pkt2, sizeof(pkt2), 0, (struct sockaddr *)&from, &fromlen); |
| 290 TNR_OFF(); | |
| 260 if (len < 0) { | 291 if (len < 0) { |
| 261 perror("recvfrom"); | 292 perror("recvfrom"); |
| 262 } else { | 293 } else { |
| 263 if (show_icmp(pkt2, len, &from, host)) { | 294 if (show_icmp(pkt2, len, &from, host)) { |
| 264 ok_recv++; | 295 ok_recv++; |
| 265 } else { | 296 } else { |
| 266 bogus_recv++; | 297 bogus_recv++; |
| 267 } | 298 } |
| 268 } | 299 } |
| 269 } | 300 } |
| 301 TNR_OFF(); | |
| 270 diag_printf("Sent %d packets, received %d OK, %d bad\n", NUM_PINGS, ok_recv, bogus_recv); | 302 diag_printf("Sent %d packets, received %d OK, %d bad\n", NUM_PINGS, ok_recv, bogus_recv); |
| 271 } | 303 } |
| 272 | 304 |
| 273 static void | 305 static void |
| 274 ping_test(struct bootp *bp) | 306 ping_test(struct bootp *bp) |
| 336 net_test(cyg_addrword_t p) | 368 net_test(cyg_addrword_t p) |
| 337 { | 369 { |
| 338 int i = 0; | 370 int i = 0; |
| 339 int j; | 371 int j; |
| 340 diag_printf("Start PING test\n"); | 372 diag_printf("Start PING test\n"); |
| 373 TNR_INIT(); | |
| 341 init_all_network_interfaces(); | 374 init_all_network_interfaces(); |
| 342 #ifdef CYGPKG_SNMPAGENT | 375 #ifdef CYGPKG_SNMPAGENT |
| 343 { | 376 { |
| 344 extern void cyg_net_snmp_init(void); | 377 extern void cyg_net_snmp_init(void); |
| 345 cyg_net_snmp_init(); | 378 cyg_net_snmp_init(); |
| 346 } | 379 } |
| 347 #endif | 380 #endif |
| 348 do { | 381 do { |
| 382 TNR_ON(); | |
| 349 #ifdef CYGHWR_NET_DRIVER_ETH0 | 383 #ifdef CYGHWR_NET_DRIVER_ETH0 |
| 350 if (eth0_up) { | 384 if (eth0_up) { |
| 351 ping_test(ð0_bootp_data); | 385 ping_test(ð0_bootp_data); |
| 352 cyg_thread_delay(500); | 386 cyg_thread_delay(500); |
| 353 } | 387 } |
| 362 if (eth1_up) { | 396 if (eth1_up) { |
| 363 ping_test(ð1_bootp_data); | 397 ping_test(ð1_bootp_data); |
| 364 cyg_thread_delay(500); | 398 cyg_thread_delay(500); |
| 365 } | 399 } |
| 366 #endif | 400 #endif |
| 401 TNR_OFF(); | |
| 402 TNR_PRINT_ACTIVITY(); | |
| 367 } while ( i-- > 0 ); | 403 } while ( i-- > 0 ); |
| 368 CYG_TEST_PASS_FINISH( "Done pinging while SNMP looks on" ); | 404 CYG_TEST_PASS_FINISH( "Done pinging while SNMP looks on" ); |
| 369 } | 405 } |
| 370 | 406 |
| 371 void | 407 void |
