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