OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [agent/] [v2_0/] [tests/] [snmpping.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      ./agent/current/tests/snmpping.c
4
//
5
//
6
//==========================================================================
7
//####ECOSGPLCOPYRIGHTBEGIN####
8
// -------------------------------------------
9
// This file is part of eCos, the Embedded Configurable Operating System.
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under
13
// the terms of the GNU General Public License as published by the Free
14
// Software Foundation; either version 2 or (at your option) any later version.
15
//
16
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19
// for more details.
20
//
21
// You should have received a copy of the GNU General Public License along
22
// with eCos; if not, write to the Free Software Foundation, Inc.,
23
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
//
25
// As a special exception, if other files instantiate templates or use macros
26
// or inline functions from this file, or you compile this file and link it
27
// with other works to produce a work based on this file, this file does not
28
// by itself cause the resulting work to be covered by the GNU General Public
29
// License. However the source code for this file must still be made available
30
// in accordance with section (3) of the GNU General Public License.
31
//
32
// This exception does not invalidate any other reasons why a work based on
33
// this file might be covered by the GNU General Public License.
34
//
35
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36
// at http://sources.redhat.com/ecos/ecos-license/
37
// -------------------------------------------
38
//####ECOSGPLCOPYRIGHTEND####
39
//####UCDSNMPCOPYRIGHTBEGIN####
40
//
41
// -------------------------------------------
42
//
43
// Portions of this software may have been derived from the UCD-SNMP
44
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
45
// California at Davis, which was originally based on the Carnegie Mellon
46
// University SNMP implementation.  Portions of this software are therefore
47
// covered by the appropriate copyright disclaimers included herein.
48
//
49
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
50
// -------------------------------------------
51
//
52
//####UCDSNMPCOPYRIGHTEND####
53
//==========================================================================
54
//#####DESCRIPTIONBEGIN####
55
//
56
// Author(s):    hmt
57
// Contributors: hmt
58
// Date:         2000-05-30
59
// Purpose:      Port of UCD-SNMP distribution to eCos.
60
// Description:  
61
//              
62
//
63
//####DESCRIPTIONEND####
64
//
65
//==========================================================================
66
/********************************************************************
67
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
68
 
69
                          Derivative Work -
70
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
71
 
72
                         All Rights Reserved
73
 
74
Permission to use, copy, modify and distribute this software and its
75
documentation for any purpose and without fee is hereby granted,
76
provided that the above copyright notice appears in all copies and
77
that both that copyright notice and this permission notice appear in
78
supporting documentation, and that the name of CMU and The Regents of
79
the University of California not be used in advertising or publicity
80
pertaining to distribution of the software without specific written
81
permission.
82
 
83
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
86
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91
*********************************************************************/
92
//==========================================================================
93
//
94
//      tests/snmpping.c
95
//
96
//      Simple test of PING (ICMP) and networking support
97
//
98
//==========================================================================
99
//####ECOSGPLCOPYRIGHTBEGIN####
100
// -------------------------------------------
101
// This file is part of eCos, the Embedded Configurable Operating System.
102
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
103
//
104
// eCos is free software; you can redistribute it and/or modify it under
105
// the terms of the GNU General Public License as published by the Free
106
// Software Foundation; either version 2 or (at your option) any later version.
107
//
108
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
109
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
110
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
111
// for more details.
112
//
113
// You should have received a copy of the GNU General Public License along
114
// with eCos; if not, write to the Free Software Foundation, Inc.,
115
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
116
//
117
// As a special exception, if other files instantiate templates or use macros
118
// or inline functions from this file, or you compile this file and link it
119
// with other works to produce a work based on this file, this file does not
120
// by itself cause the resulting work to be covered by the GNU General Public
121
// License. However the source code for this file must still be made available
122
// in accordance with section (3) of the GNU General Public License.
123
//
124
// This exception does not invalidate any other reasons why a work based on
125
// this file might be covered by the GNU General Public License.
126
//
127
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
128
// at http://sources.redhat.com/ecos/ecos-license/
129
// -------------------------------------------
130
//####ECOSGPLCOPYRIGHTEND####
131
//####BSDCOPYRIGHTBEGIN####
132
//
133
// -------------------------------------------
134
//
135
// Portions of this software may have been derived from OpenBSD or other sources,
136
// and are covered by the appropriate copyright disclaimers included herein.
137
//
138
// -------------------------------------------
139
//
140
//####BSDCOPYRIGHTEND####
141
//==========================================================================
142
//#####DESCRIPTIONBEGIN####
143
//
144
// Author(s):    gthomas
145
// Contributors: gthomas
146
// Date:         2000-01-10
147
// Purpose:      
148
// Description:  
149
//              
150
//
151
//####DESCRIPTIONEND####
152
//
153
//==========================================================================
154
 
155
 
156
// -------------------------------------------------------------------------
157
// Configuration of the test... now from CDL
158
 
159
// Do we test the interfaces in promiscuous mode?
160
//#define CYGSEM_SNMPAGENT_TESTS_PROMISCUOUS
161
 
162
// Do we make the test run forever?
163
//#define CYGNUM_SNMPAGENT_TESTS_ITERATIONS 999999
164
 
165
// Do we initialize SNMP v3 MIBs and authentication database?
166
//#define CYGSEM_SNMPAGENT_TESTS_SNMPv3
167
 
168
// ------------------------------------------------------------------------
169
 
170
 
171
// PING test code
172
 
173
#include <network.h>
174
#include <stdio.h>
175
 
176
#include <pkgconf/system.h>
177
#include <pkgconf/net.h>
178
#include <pkgconf/snmpagent.h>
179
 
180
#include <unistd.h>
181
 
182
#ifdef  CYGSEM_SNMPAGENT_TESTS_SNMPv3
183
#include <ucd-snmp/config.h>
184
#include <ucd-snmp/asn1.h>
185
#include <ucd-snmp/snmp_api.h>
186
#include <ucd-snmp/snmp_vars.h>
187
 
188
#include <ucd-snmp/snmpv3.h>
189
#include <ucd-snmp/usmUser.h>
190
#include <ucd-snmp/usmStats.h>
191
#include <ucd-snmp/snmpEngine.h>
192
#endif // CYGSEM_SNMPAGENT_TESTS_SNMPv3
193
 
194
#include <cyg/infra/testcase.h>
195
 
196
#ifdef CYGBLD_DEVS_ETH_DEVICE_H    // Get the device config if it exists
197
#include CYGBLD_DEVS_ETH_DEVICE_H  // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME
198
#endif
199
 
200
#ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test?
201
# ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists
202
#  include CYGTST_DEVS_ETH_TEST_NET_REALTIME
203
# endif
204
#endif
205
 
206
// Fill in the blanks if necessary
207
#ifndef TNR_OFF
208
# define TNR_OFF()
209
#endif
210
#ifndef TNR_ON
211
# define TNR_ON()
212
#endif
213
#ifndef TNR_INIT
214
# define TNR_INIT()
215
#endif
216
#ifndef TNR_PRINT_ACTIVITY
217
# define TNR_PRINT_ACTIVITY()
218
#endif
219
 
220
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
221
static char stack[STACK_SIZE];
222
static cyg_thread thread_data;
223
static cyg_handle_t thread_handle;
224
 
225
#define NUM_PINGS 16
226
#define MAX_PACKET 4096
227
#define MIN_PACKET   64
228
#define MAX_SEND   4000
229
 
230
#define PACKET_ADD  ((MAX_SEND - MIN_PACKET)/NUM_PINGS)
231
#define nPACKET_ADD  1 
232
 
233
static unsigned char pkt1[MAX_PACKET], pkt2[MAX_PACKET];
234
 
235
#define UNIQUEID 0x1234
236
 
237
// Compute INET checksum
238
int
239
inet_cksum(u_short *addr, int len)
240
{
241
    register int nleft = len;
242
    register u_short *w = addr;
243
    register u_short answer;
244
    register u_int sum = 0;
245
    u_short odd_byte = 0;
246
 
247
    /*
248
     *  Our algorithm is simple, using a 32 bit accumulator (sum),
249
     *  we add sequential 16 bit words to it, and at the end, fold
250
     *  back all the carry bits from the top 16 bits into the lower
251
     *  16 bits.
252
     */
253
    while( nleft > 1 )  {
254
        sum += *w++;
255
        nleft -= 2;
256
    }
257
 
258
    /* mop up an odd byte, if necessary */
259
    if( nleft == 1 ) {
260
        *(u_char *)(&odd_byte) = *(u_char *)w;
261
        sum += odd_byte;
262
    }
263
 
264
    /*
265
     * add back carry outs from top 16 bits to low 16 bits
266
     */
267
    sum = (sum >> 16) + (sum & 0x0000ffff); /* add hi 16 to low 16 */
268
    sum += (sum >> 16);                     /* add carry */
269
    answer = ~sum;                          /* truncate to 16 bits */
270
    return (answer);
271
}
272
 
273
static int
274
show_icmp(unsigned char *pkt, int len,
275
          struct sockaddr_in *from, struct sockaddr_in *to)
276
{
277
    cyg_tick_count_t *tp, tv;
278
    struct ip *ip;
279
    struct icmp *icmp;
280
    tv = cyg_current_time();
281
    ip = (struct ip *)pkt;
282
    if ((len < sizeof(*ip)) || ip->ip_v != IPVERSION) {
283
        diag_printf("%s: Short packet or not IP! - Len: %d, Version: %d\n",
284
                    inet_ntoa(from->sin_addr), len, ip->ip_v);
285
        return 0;
286
    }
287
    icmp = (struct icmp *)(pkt + sizeof(*ip));
288
    len -= (sizeof(*ip) + 8);
289
    if ( 0 >= len ) {
290
        diag_printf("%s: Completely bogus short packet%s\n",
291
                    inet_ntoa(from->sin_addr), 0 == len ? "" : " [no ICMP header]");
292
        return 0;
293
    }
294
    tp = (cyg_tick_count_t *)&icmp->icmp_data;
295
    if (icmp->icmp_type != ICMP_ECHOREPLY) {
296
        diag_printf("%s: Invalid ICMP - type: %d, len (databytes): %d\n",
297
                    inet_ntoa(from->sin_addr), icmp->icmp_type, len);
298
        return 0;
299
    }
300
    if (icmp->icmp_id != UNIQUEID) {
301
        diag_printf("%s: ICMP received for wrong id - sent: %x, recvd: %x\n",
302
                    inet_ntoa(from->sin_addr), UNIQUEID, icmp->icmp_id);
303
    }
304
    diag_printf("%d bytes from %s: ", len, inet_ntoa(from->sin_addr));
305
    diag_printf("icmp_seq=%d", icmp->icmp_seq);
306
    diag_printf(", time=%dms\n", (int)(tv - *tp)*10);
307
    return (from->sin_addr.s_addr == to->sin_addr.s_addr);
308
}
309
 
310
static void
311
ping_host(int s, struct sockaddr_in *host)
312
{
313
    struct icmp *icmp = (struct icmp *)pkt1;
314
    int icmp_len = MIN_PACKET;
315
    int seq, ok_recv, bogus_recv;
316
    cyg_tick_count_t *tp;
317
    long *dp;
318
    struct sockaddr_in from;
319
    int i, len, fromlen;
320
 
321
    ok_recv = 0;
322
    bogus_recv = 0;
323
    TNR_OFF();
324
    diag_printf("PING server %s\n", inet_ntoa(host->sin_addr));
325
    for (seq = 0;  seq < NUM_PINGS;  seq++, icmp_len += PACKET_ADD ) {
326
        TNR_ON();
327
        // Build ICMP packet
328
        icmp->icmp_type = ICMP_ECHO;
329
        icmp->icmp_code = 0;
330
        icmp->icmp_cksum = 0;
331
        icmp->icmp_seq = seq;
332
        icmp->icmp_id = 0x1234;
333
        // Set up ping data
334
        tp = (cyg_tick_count_t *)&icmp->icmp_data;
335
        *tp++ = cyg_current_time();
336
        dp = (long *)tp;
337
        for (i = sizeof(*tp);  i < icmp_len;  i += sizeof(*dp)) {
338
            *dp++ = i;
339
        }
340
        // Add checksum
341
        icmp->icmp_cksum = inet_cksum( (u_short *)icmp, icmp_len+8);
342
        // Send it off
343
        if (sendto(s, icmp, icmp_len+8, 0, (struct sockaddr *)host, sizeof(*host)) < 0) {
344
            TNR_OFF();
345
            perror("sendto");
346
            continue;
347
        }
348
        // Wait for a response
349
        fromlen = sizeof(from);
350
        len = recvfrom(s, pkt2, sizeof(pkt2), 0, (struct sockaddr *)&from, &fromlen);
351
        TNR_OFF();
352
        if (len < 0) {
353
            perror("recvfrom");
354
            icmp_len = MIN_PACKET - PACKET_ADD; // just in case - long routes
355
        } else {
356
            if (show_icmp(pkt2, len, &from, host)) {
357
                ok_recv++;
358
            } else {
359
                bogus_recv++;
360
            }
361
        }
362
    }
363
    TNR_OFF();
364
    diag_printf("Sent %d packets, received %d OK, %d bad\n", NUM_PINGS, ok_recv, bogus_recv);
365
}
366
 
367
static void
368
ping_test(struct bootp *bp)
369
{
370
    struct protoent *p;
371
    struct timeval tv;
372
    struct sockaddr_in host;
373
    int s;
374
 
375
    if ((p = getprotobyname("icmp")) == (struct protoent *)0) {
376
        perror("getprotobyname");
377
        return;
378
    }
379
    s = socket(AF_INET, SOCK_RAW, p->p_proto);
380
    if (s < 0) {
381
        perror("socket");
382
        return;
383
    }
384
    tv.tv_sec = 1;
385
    tv.tv_usec = 0;
386
    setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
387
    // Set up host address
388
    host.sin_family = AF_INET;
389
    host.sin_len = sizeof(host);
390
    host.sin_addr = bp->bp_siaddr;
391
    host.sin_port = 0;
392
    ping_host(s, &host);
393
    // Now try a bogus host
394
    // (also, map 76 <-> 191 so that if a pair runs they ping each other)
395
    host.sin_addr = bp->bp_yiaddr; // *my* address.
396
//    host.sin_addr.s_addr = htonl(ntohl(host.sin_addr.s_addr) ^ 0xf3);
397
    host.sin_addr.s_addr = htonl(ntohl(host.sin_addr.s_addr) ^ 2);
398
    ping_host(s, &host);
399
    close(s);
400
}
401
 
402
static void
403
ping_test_loopback( int lo )
404
{
405
    struct protoent *p;
406
    struct timeval tv;
407
    struct sockaddr_in host;
408
    int s;
409
 
410
    if ((p = getprotobyname("icmp")) == (struct protoent *)0) {
411
        perror("getprotobyname");
412
        return;
413
    }
414
    s = socket(AF_INET, SOCK_RAW, p->p_proto);
415
    if (s < 0) {
416
        perror("socket");
417
        return;
418
    }
419
    tv.tv_sec = 1;
420
    tv.tv_usec = 0;
421
    setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
422
    // Set up host address
423
    host.sin_family = AF_INET;
424
    host.sin_len = sizeof(host);
425
    host.sin_addr.s_addr = htonl(INADDR_LOOPBACK + (0x100 * lo));
426
    host.sin_port = 0;
427
    ping_host(s, &host);
428
    // Now try a bogus host
429
    host.sin_addr.s_addr = htonl(ntohl(host.sin_addr.s_addr) + 32);
430
    ping_host(s, &host);
431
    close(s);
432
}
433
 
434
#ifdef CYGSEM_SNMPAGENT_TESTS_PROMISCUOUS
435
static void
436
interface_promisc(const char *intf)
437
{
438
  struct ifreq ifr;
439
  int s;
440
 
441
  s = socket(AF_INET, SOCK_DGRAM, 0);
442
  if (s < 0) {
443
    perror("socket");
444
    return;
445
  }
446
 
447
  strcpy(ifr.ifr_name, intf);
448
  ifr.ifr_flags = IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_PROMISC;
449
  if (ioctl(s, SIOCSIFFLAGS, &ifr)) {
450
    perror("SIOCSIFFLAGS");
451
  }
452
  close(s);
453
}
454
#endif // CYGSEM_SNMPAGENT_TESTS_PROMISCUOUS
455
 
456
void snmp_do_reinit( void )
457
{
458
    diag_printf( "SNMP re-init function\n" );
459
#ifdef  CYGSEM_SNMPAGENT_TESTS_SNMPv3
460
    // Initialisation for USM is now invoked from mib_module_inits.h
461
    //init_usmUser();             /* MIBs to support SNMPv3             */
462
    //init_usmStats();
463
    //init_snmpEngine();
464
    usm_parse_create_usmUser(NULL, "root MD5 md5passwd DES DESpasswd");
465
#endif //  CYGSEM_SNMPAGENT_TESTS_SNMPv3
466
}
467
 
468
int create_snmpd_conf (void) {
469
#ifdef CYGSEM_SNMPAGENT_TESTS_SNMPv3
470
#ifdef CYGPKG_SNMPLIB_FILESYSTEM_SUPPORT 
471
#ifdef CYGPKG_FS_RAM
472
  int c;
473
  FILE *fd;
474
 
475
  diag_printf ("\nStarting creation of snmpd.conf\n");
476
 
477
  /* Mount RAM-FS */
478
  if (mount ("", "/", "ramfs") != 0) {
479
    diag_printf ("File system mount failed; errno=%d \n", errno);
480
    return -1;
481
  }
482
 
483
  if (mkdir ("/etc", 0) != 0) {
484
    diag_printf ("mkdir (etc) failed;  errno=%d\n", errno);
485
    return -1;
486
  }
487
 
488
  if (chdir ("/etc") != 0) {
489
    diag_printf ("... Change-dir (etc) failed; errno=%d\n", errno);
490
    return -1;
491
  } else {
492
    diag_printf ("chdir-etc done\n");
493
  }
494
 
495
  if (mkdir ("snmp", 0) != 0) {
496
    diag_printf ("mkdir failed (snmp);  errno=%d\n", errno);
497
    return -1;
498
  } else {
499
    diag_printf ("mkdir-snmp done\n");
500
  }
501
 
502
  if (chdir ("snmp") != 0) {
503
    diag_printf ("... Change-dir (snmp) failed; errno=%d\n", errno);
504
    return -1;
505
  } else {
506
    diag_printf ("... Change-dir (snmp) done \n");
507
  }
508
 
509
  /* Open File & Write to it  */
510
  if ((fd = fopen( "snmpd.conf", "w" )) == NULL) {
511
    diag_printf ("fopen failed\n");
512
    return -1;
513
  }
514
 
515
  fprintf (fd, "#        sec.name     source       community\n");
516
  fprintf (fd, "com2sec   public     default       crux\n");
517
  fprintf (fd, "com2sec   root       default       crux\n");
518
  fprintf (fd, "#                 sec.model   sec.name\n");
519
  fprintf (fd, "group     public    v1        public\n");
520
  fprintf (fd, "group     public    v2c       public\n");
521
  fprintf (fd, "group     public    usm       root\n");
522
  fprintf (fd, "view      all  included  .1\n");
523
  fprintf (fd, "access    public    \"\"   any  noauth    exact     all  none none\n");
524
  fprintf (fd, "\n\n");
525
 
526
  if (fclose (fd)) {
527
    diag_printf ("fclose failed\n");
528
    return -1;
529
  }
530
 
531
  /* Read Back */
532
  fd = fopen( "/etc/snmp/snmpd.conf", "r" );
533
  if (fd == NULL) {
534
    diag_printf ("fopen failed\n");
535
    return -1;
536
  }
537
 
538
  while ((c=fgetc (fd)) != EOF) {
539
    diag_printf ("%c", c);
540
  }
541
 
542
  if (fclose (fd))  {
543
    diag_printf ("fclose failed\n");
544
    return -1;
545
  }
546
#endif
547
#endif
548
#endif
549
  return 0;
550
}
551
 
552
void
553
net_test(cyg_addrword_t p)
554
{
555
    int i = CYGNUM_SNMPAGENT_TESTS_ITERATIONS;
556
    int ieth0_up = 0, ieth1_up = 0;
557
    int j;
558
 
559
    diag_printf("Start PING test\n");
560
    TNR_INIT();
561
    init_all_network_interfaces();
562
#ifdef CYGHWR_NET_DRIVER_ETH0
563
    ieth0_up = eth0_up;
564
#endif
565
#ifdef CYGHWR_NET_DRIVER_ETH1
566
    ieth1_up = eth1_up;
567
#endif
568
#ifdef CYGSEM_SNMPAGENT_TESTS_PROMISCUOUS
569
#ifdef CYGHWR_NET_DRIVER_ETH0
570
        if (eth0_up)
571
            interface_promisc("eth0");
572
#endif
573
#ifdef CYGHWR_NET_DRIVER_ETH1
574
        if (eth1_up)
575
            interface_promisc("eth1");
576
#endif
577
#endif // CYGSEM_SNMPAGENT_TESTS_PROMISCUOUS
578
    {
579
        extern void cyg_net_snmp_init(void);
580
        extern void (*snmpd_reinit_function)( void );
581
 
582
        snmpd_reinit_function = snmp_do_reinit;
583
 
584
        if (create_snmpd_conf ()) {
585
          CYG_TEST_FAIL_EXIT("create_snmpd_conf() error\n");
586
        }
587
        cyg_net_snmp_init();
588
    }
589
    do {
590
        TNR_ON();
591
#ifdef CYGHWR_NET_DRIVER_ETH0
592
        if (eth0_up) {
593
            ping_test(&eth0_bootp_data);
594
            cyg_thread_delay(500);
595
        }
596
#endif
597
#if NLOOP > 0
598
        for ( j = 0; j < NLOOP; j++ ) {
599
            ping_test_loopback( j );
600
            cyg_thread_delay(500);
601
        }
602
#endif
603
#ifdef CYGHWR_NET_DRIVER_ETH1
604
        if (eth1_up) {
605
            ping_test(&eth1_bootp_data);
606
            cyg_thread_delay(500);
607
        }
608
#endif
609
        TNR_OFF();
610
        TNR_PRINT_ACTIVITY();
611
 
612
        // If an interface has gone down eg. due to DHCP timing out,
613
        // re-initialize everything:
614
        if (0
615
#ifdef CYGHWR_NET_DRIVER_ETH0
616
            || ieth0_up != eth0_up
617
#endif
618
#ifdef CYGHWR_NET_DRIVER_ETH1
619
            || ieth1_up != eth1_up
620
#endif
621
            ) {
622
            diag_printf( "Re-initializing the world: eth0 %d/%d eth1 %d/%d!\n",
623
                         ieth0_up, 0
624
#ifdef CYGHWR_NET_DRIVER_ETH0
625
                         | eth0_up
626
#endif
627
                         , ieth1_up, 0
628
#ifdef CYGHWR_NET_DRIVER_ETH1
629
                         | eth1_up
630
#endif
631
                );
632
            init_all_network_interfaces();
633
            for ( j = 0; j < CYGPKG_NET_NLOOP; j++ )
634
                init_loopback_interface( j );
635
 
636
            diag_printf( "Re-initialized the world: eth0 %d/%d eth1 %d/%d!\n",
637
                         ieth0_up, 0
638
#ifdef CYGHWR_NET_DRIVER_ETH0
639
                         | eth0_up
640
#endif
641
                         , ieth1_up, 0
642
#ifdef CYGHWR_NET_DRIVER_ETH1
643
                         | eth1_up
644
#endif
645
                );
646
        }
647
    } while ( i-- > 0 );
648
    CYG_TEST_PASS_FINISH( "Done pinging while SNMP looks on" );
649
}
650
 
651
void
652
cyg_start(void)
653
{
654
    // Create a main thread, so we can run the scheduler and have time 'pass'
655
    cyg_thread_create(10,                // Priority - just a number
656
                      net_test,          // entry
657
                      0,                 // entry parameter
658
                      "Network test",    // Name
659
                      &stack[0],         // Stack
660
                      STACK_SIZE,        // Size
661
                      &thread_handle,    // Handle
662
                      &thread_data       // Thread data structure
663
            );
664
    cyg_thread_resume(thread_handle);  // Start it
665
    cyg_scheduler_start();
666
}
667
 
668
// EOF snmpping.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.