1 |
786 |
skrzyp |
//==========================================================================
|
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 |
|
|
// Copyright (C) 2003 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): gthomas
|
50 |
|
|
// Contributors: gthomas
|
51 |
|
|
// Date: 2000-01-10
|
52 |
|
|
// Purpose:
|
53 |
|
|
// Description:
|
54 |
|
|
//
|
55 |
|
|
//
|
56 |
|
|
//####DESCRIPTIONEND####
|
57 |
|
|
//
|
58 |
|
|
//==========================================================================
|
59 |
|
|
|
60 |
|
|
#ifndef _TESTS_NC_TEST_FRAMEWORK_H_
|
61 |
|
|
#define _TESTS_NC_TEST_FRAMEWORK_H_
|
62 |
|
|
|
63 |
|
|
#ifdef __ECOS
|
64 |
|
|
#include <network.h>
|
65 |
|
|
#else
|
66 |
|
|
#undef _KERNEL
|
67 |
|
|
#include <sys/param.h>
|
68 |
|
|
#include <sys/socket.h>
|
69 |
|
|
#include <sys/ioctl.h>
|
70 |
|
|
#include <sys/errno.h>
|
71 |
|
|
#include <sys/time.h>
|
72 |
|
|
|
73 |
|
|
#include <net/if.h>
|
74 |
|
|
#include <netinet/in_systm.h>
|
75 |
|
|
#include <netinet/in.h>
|
76 |
|
|
#include <netinet/ip.h>
|
77 |
|
|
#include <netinet/ip_icmp.h>
|
78 |
|
|
|
79 |
|
|
#include <netdb.h>
|
80 |
|
|
#ifndef EAI_NONE
|
81 |
|
|
#define EAI_NONE 0
|
82 |
|
|
#endif
|
83 |
|
|
#endif
|
84 |
|
|
|
85 |
|
|
#ifdef __ECOS
|
86 |
|
|
#define test_printf diag_printf
|
87 |
|
|
typedef cyg_addrword_t test_param_t;
|
88 |
|
|
#else
|
89 |
|
|
#define test_printf printf
|
90 |
|
|
typedef void *test_param_t;
|
91 |
|
|
#endif
|
92 |
|
|
|
93 |
|
|
#ifndef true
|
94 |
|
|
#define false 0
|
95 |
|
|
#define true 1
|
96 |
|
|
#endif
|
97 |
|
|
|
98 |
|
|
#define NC_SLAVE_PORT 7777
|
99 |
|
|
#define NC_MASTER_PORT 7776
|
100 |
|
|
|
101 |
|
|
#define NC_TESTING_SLAVE_PORT 8770
|
102 |
|
|
#define NC_TESTING_MASTER_PORT 8771
|
103 |
|
|
|
104 |
|
|
#define __string(s) #s
|
105 |
|
|
#define _string(s) __string(s)
|
106 |
|
|
|
107 |
|
|
//
|
108 |
|
|
// The basic idea behind this test structure is that one end will run
|
109 |
|
|
// in "slave" mode and the other in "master" mode. Typically, the slave
|
110 |
|
|
// will run on a target platform with the master running on a host.
|
111 |
|
|
//
|
112 |
|
|
// The slave starts up by listening for a connection on the "SLAVE_PORT".
|
113 |
|
|
// In order for the testing to require the minimum stack support, this
|
114 |
|
|
// connection (and the protocol) will use UDP.
|
115 |
|
|
//
|
116 |
|
|
// The master will connect to the slave and send it a request over this
|
117 |
|
|
// connection. Once the slave accepts the request, then master and slave
|
118 |
|
|
// will execute the operation, typically a test. The control connection
|
119 |
|
|
// will remain active until the master sends a 'disconnect' request. The
|
120 |
|
|
// control connection will be broken after the reply to this request has
|
121 |
|
|
// been sent.
|
122 |
|
|
//
|
123 |
|
|
|
124 |
|
|
#define MAX_ERRORS 5 // Give up after this many errors
|
125 |
|
|
|
126 |
|
|
#define NC_REPLY_TIMEOUT 10 // The slave may be slow
|
127 |
|
|
#define NC_TEST_TIMEOUT 3 // More generous for tests
|
128 |
|
|
#define NC_RESULTS_TIMEOUT (MAX_ERRORS+2)*NC_TEST_TIMEOUT
|
129 |
|
|
|
130 |
|
|
struct nc_request {
|
131 |
|
|
int type; // Description of request
|
132 |
|
|
int seq; // Sequence number, used to build response
|
133 |
|
|
int nbufs; // Number of "buffers" to send
|
134 |
|
|
int buflen; // Length of each buffer
|
135 |
|
|
int slave_port; // Network ports to use
|
136 |
|
|
int master_port;
|
137 |
|
|
int timeout; // Max time to wait for any packet
|
138 |
|
|
};
|
139 |
|
|
|
140 |
|
|
#define NC_REQUEST_DISCONNECT 0x0001
|
141 |
|
|
#define NC_REQUEST_UDP_SEND 0x0010 // Slave to send UDP data
|
142 |
|
|
#define NC_REQUEST_UDP_RECV 0x0011 // Slave to receive UDP data
|
143 |
|
|
#define NC_REQUEST_UDP_ECHO 0x0012 // Master->slave->master
|
144 |
|
|
#define NC_REQUEST_TCP_SEND 0x0020 // Slave to send TCP data
|
145 |
|
|
#define NC_REQUEST_TCP_RECV 0x0021 // Slave to receive TCP data
|
146 |
|
|
#define NC_REQUEST_TCP_ECHO 0x0022 // Master->slave->master
|
147 |
|
|
#define NC_REQUEST_START_IDLE 0x0100 // Start some idle processing
|
148 |
|
|
#define NC_REQUEST_STOP_IDLE 0x0101 // Stop idle processing
|
149 |
|
|
#define NC_REQUEST_SET_LOAD 0x0200 // Set the background load level
|
150 |
|
|
|
151 |
|
|
struct nc_reply {
|
152 |
|
|
int response; // ACK or NAK
|
153 |
|
|
int seq; // Must match request
|
154 |
|
|
int reason; // If NAK, why request turned down
|
155 |
|
|
union { // Miscellaneous data, depending on request
|
156 |
|
|
struct {
|
157 |
|
|
long elapsed_time; // In 10ms "ticks"
|
158 |
|
|
long count[2]; // Result
|
159 |
|
|
} idle_results;
|
160 |
|
|
} misc;
|
161 |
|
|
};
|
162 |
|
|
|
163 |
|
|
#define NC_REPLY_ACK 0x0001 // Request accepted
|
164 |
|
|
#define NC_REPLY_NAK 0x0000 // Request denied
|
165 |
|
|
|
166 |
|
|
#define NC_REPLY_NAK_UNKNOWN_REQUEST 0x0001
|
167 |
|
|
#define NC_REPLY_NAK_BAD_REQUEST 0x0002 // Slave can't handle
|
168 |
|
|
#define NC_REPLY_NAK_NO_BACKGROUND 0x0003 // Slave can't do background/idle
|
169 |
|
|
|
170 |
|
|
//
|
171 |
|
|
// Test data 'packets' look like this
|
172 |
|
|
|
173 |
|
|
struct nc_test_data {
|
174 |
|
|
long key1;
|
175 |
|
|
int seq;
|
176 |
|
|
int len;
|
177 |
|
|
long key2;
|
178 |
|
|
char data[0]; // Actual data
|
179 |
|
|
};
|
180 |
|
|
|
181 |
|
|
#define NC_TEST_DATA_KEY1 0xC0DEADC0
|
182 |
|
|
#define NC_TEST_DATA_KEY2 0xC0DEADC1
|
183 |
|
|
|
184 |
|
|
struct nc_test_results {
|
185 |
|
|
long key1; // Identify uniquely as a response record
|
186 |
|
|
int seq; // Matches request
|
187 |
|
|
int nsent;
|
188 |
|
|
int nrecvd;
|
189 |
|
|
long key2; // Additional verification
|
190 |
|
|
};
|
191 |
|
|
|
192 |
|
|
#define NC_TEST_RESULT_KEY1 0xDEADC0DE
|
193 |
|
|
#define NC_TEST_RESULT_KEY2 0xDEADC1DE
|
194 |
|
|
|
195 |
|
|
#endif // _TESTS_NC_TEST_FRAMEWORK_H_
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|