|
1586
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // tests/nc_test_framework.h |
|
|
4 // |
|
|
5 // Network characterization tests framework |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####ECOSGPLCOPYRIGHTBEGIN#### |
|
|
9 // ------------------------------------------- |
|
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
|
11 // Portions created by Nick Garnett are |
|
|
12 // Copyright (C) 2003 eCosCentric Ltd. |
|
|
13 // |
|
|
14 // eCos is free software; you can redistribute it and/or modify it under |
|
|
15 // the terms of the GNU General Public License as published by the Free |
|
|
16 // Software Foundation; either version 2 or (at your option) any later version. |
|
|
17 // |
|
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
|
|
19 // 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 along |
|
|
24 // with eCos; if not, write to the Free Software Foundation, Inc., |
|
|
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
|
26 // |
|
|
27 // As a special exception, if other files instantiate templates or use macros |
|
|
28 // or inline functions from this file, or you compile this file and link it |
|
|
29 // with other works to produce a work based on this file, this file does not |
|
|
30 // by itself cause the resulting work to be covered by the GNU General Public |
|
|
31 // License. However the source code for this file must still be made available |
|
|
32 // in accordance with section (3) of the GNU General Public License. |
|
|
33 // |
|
|
34 // This exception does not invalidate any other reasons why a work based on |
|
|
35 // this file might be covered by the GNU General Public License. |
|
|
36 // |
|
|
37 // ------------------------------------------- |
|
|
38 //####ECOSGPLCOPYRIGHTEND#### |
|
|
39 //####BSDCOPYRIGHTBEGIN#### |
|
|
40 // |
|
|
41 // ------------------------------------------- |
|
|
42 // |
|
|
43 // Portions of this software may have been derived from OpenBSD, |
|
|
44 // FreeBSD or other sources, and are covered by the appropriate |
|
|
45 // copyright disclaimers included herein. |
|
|
46 // |
|
|
47 // ------------------------------------------- |
|
|
48 // |
|
|
49 //####BSDCOPYRIGHTEND#### |
|
|
50 //========================================================================== |
|
|
51 //#####DESCRIPTIONBEGIN#### |
|
|
52 // |
|
|
53 // Author(s): gthomas |
|
|
54 // Contributors: gthomas |
|
|
55 // Date: 2000-01-10 |
|
|
56 // Purpose: |
|
|
57 // Description: |
|
|
58 // |
|
|
59 // |
|
|
60 //####DESCRIPTIONEND#### |
|
|
61 // |
|
|
62 //========================================================================== |
|
|
63 |
|
|
64 #ifndef _TESTS_NC_TEST_FRAMEWORK_H_ |
|
|
65 #define _TESTS_NC_TEST_FRAMEWORK_H_ |
|
|
66 |
|
|
67 #ifdef __ECOS |
|
|
68 #include <network.h> |
|
|
69 #else |
|
|
70 #undef _KERNEL |
|
|
71 #include <sys/param.h> |
|
|
72 #include <sys/socket.h> |
|
|
73 #include <sys/ioctl.h> |
|
|
74 #include <sys/errno.h> |
|
|
75 #include <sys/time.h> |
|
|
76 |
|
|
77 #include <net/if.h> |
|
|
78 #include <netinet/in_systm.h> |
|
|
79 #include <netinet/in.h> |
|
|
80 #include <netinet/ip.h> |
|
|
81 #include <netinet/ip_icmp.h> |
|
|
82 |
|
|
83 #include <netdb.h> |
|
|
84 #ifndef EAI_NONE |
|
|
85 #define EAI_NONE 0 |
|
|
86 #endif |
|
|
87 #endif |
|
|
88 |
|
|
89 #ifdef __ECOS |
|
|
90 #define test_printf diag_printf |
|
|
91 typedef cyg_addrword_t test_param_t; |
|
|
92 #else |
|
|
93 #define test_printf printf |
|
|
94 typedef void *test_param_t; |
|
|
95 #endif |
|
|
96 |
|
|
97 #ifndef true |
|
|
98 #define false 0 |
|
|
99 #define true 1 |
|
|
100 #endif |
|
|
101 |
|
|
102 #define NC_SLAVE_PORT 7777 |
|
|
103 #define NC_MASTER_PORT 7776 |
|
|
104 |
|
|
105 #define NC_TESTING_SLAVE_PORT 8770 |
|
|
106 #define NC_TESTING_MASTER_PORT 8771 |
|
|
107 |
|
|
108 #define __string(s) #s |
|
|
109 #define _string(s) __string(s) |
|
|
110 |
|
|
111 // |
|
|
112 // The basic idea behind this test structure is that one end will run |
|
|
113 // in "slave" mode and the other in "master" mode. Typically, the slave |
|
|
114 // will run on a target platform with the master running on a host. |
|
|
115 // |
|
|
116 // The slave starts up by listening for a connection on the "SLAVE_PORT". |
|
|
117 // In order for the testing to require the minimum stack support, this |
|
|
118 // connection (and the protocol) will use UDP. |
|
|
119 // |
|
|
120 // The master will connect to the slave and send it a request over this |
|
|
121 // connection. Once the slave accepts the request, then master and slave |
|
|
122 // will execute the operation, typically a test. The control connection |
|
|
123 // will remain active until the master sends a 'disconnect' request. The |
|
|
124 // control connection will be broken after the reply to this request has |
|
|
125 // been sent. |
|
|
126 // |
|
|
127 |
|
|
128 #define MAX_ERRORS 5 // Give up after this many errors |
|
|
129 |
|
|
130 #define NC_REPLY_TIMEOUT 10 // The slave may be slow |
|
|
131 #define NC_TEST_TIMEOUT 3 // More generous for tests |
|
|
132 #define NC_RESULTS_TIMEOUT (MAX_ERRORS+2)*NC_TEST_TIMEOUT |
|
|
133 |
|
|
134 struct nc_request { |
|
|
135 int type; // Description of request |
|
|
136 int seq; // Sequence number, used to build response |
|
|
137 int nbufs; // Number of "buffers" to send |
|
|
138 int buflen; // Length of each buffer |
|
|
139 int slave_port; // Network ports to use |
|
|
140 int master_port; |
|
|
141 int timeout; // Max time to wait for any packet |
|
|
142 }; |
|
|
143 |
|
|
144 #define NC_REQUEST_DISCONNECT 0x0001 |
|
|
145 #define NC_REQUEST_UDP_SEND 0x0010 // Slave to send UDP data |
|
|
146 #define NC_REQUEST_UDP_RECV 0x0011 // Slave to receive UDP data |
|
|
147 #define NC_REQUEST_UDP_ECHO 0x0012 // Master->slave->master |
|
|
148 #define NC_REQUEST_TCP_SEND 0x0020 // Slave to send TCP data |
|
|
149 #define NC_REQUEST_TCP_RECV 0x0021 // Slave to receive TCP data |
|
|
150 #define NC_REQUEST_TCP_ECHO 0x0022 // Master->slave->master |
|
|
151 #define NC_REQUEST_START_IDLE 0x0100 // Start some idle processing |
|
|
152 #define NC_REQUEST_STOP_IDLE 0x0101 // Stop idle processing |
|
|
153 #define NC_REQUEST_SET_LOAD 0x0200 // Set the background load level |
|
|
154 |
|
|
155 struct nc_reply { |
|
|
156 int response; // ACK or NAK |
|
|
157 int seq; // Must match request |
|
|
158 int reason; // If NAK, why request turned down |
|
|
159 union { // Miscellaneous data, depending on request |
|
|
160 struct { |
|
|
161 long elapsed_time; // In 10ms "ticks" |
|
|
162 long count[2]; // Result |
|
|
163 } idle_results; |
|
|
164 } misc; |
|
|
165 }; |
|
|
166 |
|
|
167 #define NC_REPLY_ACK 0x0001 // Request accepted |
|
|
168 #define NC_REPLY_NAK 0x0000 // Request denied |
|
|
169 |
|
|
170 #define NC_REPLY_NAK_UNKNOWN_REQUEST 0x0001 |
|
|
171 #define NC_REPLY_NAK_BAD_REQUEST 0x0002 // Slave can't handle |
|
|
172 #define NC_REPLY_NAK_NO_BACKGROUND 0x0003 // Slave can't do background/idle |
|
|
173 |
|
|
174 // |
|
|
175 // Test data 'packets' look like this |
|
|
176 |
|
|
177 struct nc_test_data { |
|
|
178 long key1; |
|
|
179 int seq; |
|
|
180 int len; |
|
|
181 long key2; |
|
|
182 char data[0]; // Actual data |
|
|
183 }; |
|
|
184 |
|
|
185 #define NC_TEST_DATA_KEY1 0xC0DEADC0 |
|
|
186 #define NC_TEST_DATA_KEY2 0xC0DEADC1 |
|
|
187 |
|
|
188 struct nc_test_results { |
|
|
189 long key1; // Identify uniquely as a response record |
|
|
190 int seq; // Matches request |
|
|
191 int nsent; |
|
|
192 int nrecvd; |
|
|
193 long key2; // Additional verification |
|
|
194 }; |
|
|
195 |
|
|
196 #define NC_TEST_RESULT_KEY1 0xDEADC0DE |
|
|
197 #define NC_TEST_RESULT_KEY2 0xDEADC1DE |
|
|
198 |
|
|
199 #endif // _TESTS_NC_TEST_FRAMEWORK_H_ |
|
|
200 |
|
|
201 |
|
|
202 |