1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// autotest/current/tests/snmpwalk.c
|
4 |
|
|
//
|
5 |
|
|
// Simple pinging test, the server pings me and little else.
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
// ####BSDALTCOPYRIGHTBEGIN####
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
// Portions of this software may have been derived from FreeBSD, OpenBSD,
|
42 |
|
|
// or other sources, and if so are covered by the appropriate copyright
|
43 |
|
|
// and license included herein.
|
44 |
|
|
// -------------------------------------------
|
45 |
|
|
// ####BSDALTCOPYRIGHTEND####
|
46 |
|
|
//==========================================================================
|
47 |
|
|
//#####DESCRIPTIONBEGIN####
|
48 |
|
|
//
|
49 |
|
|
// Author(s): hmt,gthomas
|
50 |
|
|
// Contributors: hmt,gthomas
|
51 |
|
|
// Date: 2000-10-23
|
52 |
|
|
// Purpose:
|
53 |
|
|
// Description:
|
54 |
|
|
//
|
55 |
|
|
//
|
56 |
|
|
//####DESCRIPTIONEND####
|
57 |
|
|
//
|
58 |
|
|
//==========================================================================
|
59 |
|
|
|
60 |
|
|
#include <pkgconf/system.h>
|
61 |
|
|
|
62 |
|
|
#include <cyg/infra/testcase.h> // testing infrastructure
|
63 |
|
|
|
64 |
|
|
#include <pkgconf/net.h>
|
65 |
|
|
|
66 |
|
|
#ifdef CYGPKG_SNMPAGENT // Do we support SNMP at all?
|
67 |
|
|
|
68 |
|
|
#ifdef CYGBLD_DEVS_ETH_DEVICE_H // Get the device config if it exists
|
69 |
|
|
#include CYGBLD_DEVS_ETH_DEVICE_H // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME
|
70 |
|
|
#endif
|
71 |
|
|
|
72 |
|
|
#ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test?
|
73 |
|
|
# ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists
|
74 |
|
|
# include CYGTST_DEVS_ETH_TEST_NET_REALTIME
|
75 |
|
|
# endif
|
76 |
|
|
#endif
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
// Fill in the blanks if necessary
|
80 |
|
|
#ifndef TNR_OFF
|
81 |
|
|
# define TNR_OFF()
|
82 |
|
|
#endif
|
83 |
|
|
#ifndef TNR_ON
|
84 |
|
|
# define TNR_ON()
|
85 |
|
|
#endif
|
86 |
|
|
#ifndef TNR_INIT
|
87 |
|
|
# define TNR_INIT()
|
88 |
|
|
#endif
|
89 |
|
|
#ifndef TNR_PRINT_ACTIVITY
|
90 |
|
|
# define TNR_PRINT_ACTIVITY()
|
91 |
|
|
#endif
|
92 |
|
|
|
93 |
|
|
// ------------------------------------------------------------------------
|
94 |
|
|
|
95 |
|
|
#include <errno.h>
|
96 |
|
|
#include <network.h>
|
97 |
|
|
|
98 |
|
|
#include "autohost.inl"
|
99 |
|
|
|
100 |
|
|
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x10000)
|
101 |
|
|
static char stack[STACK_SIZE];
|
102 |
|
|
static cyg_thread thread_data;
|
103 |
|
|
static cyg_handle_t thread_handle;
|
104 |
|
|
|
105 |
|
|
static void
|
106 |
|
|
do_snmp_tests(struct bootp *bp, int N, int testtime)
|
107 |
|
|
{
|
108 |
|
|
int i;
|
109 |
|
|
char order[256];
|
110 |
|
|
diag_printf( "INFO: telling %s to run %d snmpwalks for %d seconds\n",
|
111 |
|
|
inet_ntoa(bp->bp_siaddr), N, testtime );
|
112 |
|
|
|
113 |
|
|
#ifdef XFAIL
|
114 |
|
|
// reduce the time to run so that we get a result
|
115 |
|
|
testtime *= 3;
|
116 |
|
|
testtime /= 4;
|
117 |
|
|
#endif
|
118 |
|
|
for ( i = 0; i < N; i++ ) {
|
119 |
|
|
sprintf( order, "%s %s %d", "SNMP_WALK",
|
120 |
|
|
inet_ntoa(bp->bp_yiaddr),
|
121 |
|
|
testtime );
|
122 |
|
|
autohost_tell( bp, order );
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
#define TESTTIME (5 * 60) // Seconds
|
127 |
|
|
|
128 |
|
|
#define NUM_SESSIONS 10 // why not?
|
129 |
|
|
|
130 |
|
|
void
|
131 |
|
|
net_test(cyg_addrword_t param)
|
132 |
|
|
{
|
133 |
|
|
extern void cyg_net_snmp_init(void);
|
134 |
|
|
|
135 |
|
|
CYG_TEST_INIT();
|
136 |
|
|
CYG_TEST_INFO("Start simple SNMP server test");
|
137 |
|
|
init_all_network_interfaces();
|
138 |
|
|
|
139 |
|
|
autohost_init();
|
140 |
|
|
|
141 |
|
|
cyg_net_snmp_init();
|
142 |
|
|
|
143 |
|
|
TNR_INIT();
|
144 |
|
|
|
145 |
|
|
// Now command the host to do ping to us...
|
146 |
|
|
#ifdef CYGHWR_NET_DRIVER_ETH0
|
147 |
|
|
if (eth0_up) {
|
148 |
|
|
do_snmp_tests(ð0_bootp_data, 1, TESTTIME);
|
149 |
|
|
}
|
150 |
|
|
#endif
|
151 |
|
|
#ifdef CYGHWR_NET_DRIVER_ETH1
|
152 |
|
|
if (eth1_up) {
|
153 |
|
|
do_snmp_tests(ð1_bootp_data, 1, TESTTIME);
|
154 |
|
|
}
|
155 |
|
|
#endif
|
156 |
|
|
// Let the server run for 5 minutes
|
157 |
|
|
cyg_thread_delay(2*100); // let the stuff start up first
|
158 |
|
|
TNR_ON();
|
159 |
|
|
cyg_thread_delay(TESTTIME*100); // FIXME - assume cS clock.
|
160 |
|
|
// Additional delay 'cos host may be slower than us - and it has to
|
161 |
|
|
// complete a transfer anyway:
|
162 |
|
|
cyg_thread_delay( 30 *100); // FIXME - assume cS clock.
|
163 |
|
|
TNR_OFF();
|
164 |
|
|
|
165 |
|
|
autohost_end( 0
|
166 |
|
|
#ifdef CYGHWR_NET_DRIVER_ETH0
|
167 |
|
|
+ eth0_up
|
168 |
|
|
#endif
|
169 |
|
|
#ifdef CYGHWR_NET_DRIVER_ETH1
|
170 |
|
|
+ eth1_up
|
171 |
|
|
#endif
|
172 |
|
|
); // check for 2 pass messages from hosts
|
173 |
|
|
|
174 |
|
|
TNR_PRINT_ACTIVITY();
|
175 |
|
|
CYG_TEST_EXIT("Done");
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
#endif // CYGPKG_SNMPAGENT - Do we support SNMP at all?
|
179 |
|
|
|
180 |
|
|
void
|
181 |
|
|
cyg_start(void)
|
182 |
|
|
{
|
183 |
|
|
#ifdef CYGPKG_SNMPAGENT // Do we support SNMP at all?
|
184 |
|
|
// Create a main thread, so we can run the scheduler and have time 'pass'
|
185 |
|
|
cyg_thread_create(10, // Priority - just a number
|
186 |
|
|
net_test, // entry
|
187 |
|
|
0, // entry parameter
|
188 |
|
|
"Network test", // Name
|
189 |
|
|
&stack[0], // Stack
|
190 |
|
|
STACK_SIZE, // Size
|
191 |
|
|
&thread_handle, // Handle
|
192 |
|
|
&thread_data // Thread data structure
|
193 |
|
|
);
|
194 |
|
|
cyg_thread_resume(thread_handle); // Start it
|
195 |
|
|
cyg_scheduler_start();
|
196 |
|
|
#else
|
197 |
|
|
CYG_TEST_NA( "No SNMP agent in this configuration" );
|
198 |
|
|
#endif // CYGPKG_SNMPAGENT - Do we support SNMP at all?
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
// EOF snmpwalk.c
|