summaryrefslogtreecommitdiff
path: root/ecos/packages/net/ppp/current/tests/nc_test_framework.h
blob: 3153f825b47ca2cdc39ab6892ee3d29e9358633c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//==========================================================================
//
//      tests/nc_test_framework.h
//
//      Network characterization tests framework
//
//==========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
// -------------------------------------------                              
// This file is part of eCos, the Embedded Configurable Operating System.   
// Copyright (C) 2003 Free Software Foundation, Inc.                        
//
// eCos is free software; you can redistribute it and/or modify it under    
// the terms of the GNU General Public License as published by the Free     
// Software Foundation; either version 2 or (at your option) any later      
// version.                                                                 
//
// eCos is distributed in the hope that it will be useful, but WITHOUT      
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
// for more details.                                                        
//
// You should have received a copy of the GNU General Public License        
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
//
// As a special exception, if other files instantiate templates or use      
// macros or inline functions from this file, or you compile this file      
// and link it with other works to produce a work based on this file,       
// this file does not by itself cause the resulting work to be covered by   
// the GNU General Public License. However the source code for this file    
// must still be made available in accordance with section (3) of the GNU   
// General Public License v2.                                               
//
// This exception does not invalidate any other reasons why a work based    
// on this file might be covered by the GNU General Public License.         
// -------------------------------------------                              
// ####ECOSGPLCOPYRIGHTEND####                                              
// ####BSDALTCOPYRIGHTBEGIN####                                             
// -------------------------------------------                              
// Portions of this software may have been derived from FreeBSD, OpenBSD,   
// or other sources, and if so are covered by the appropriate copyright     
// and license included herein.                                             
// -------------------------------------------                              
// ####BSDALTCOPYRIGHTEND####                                               
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    gthomas
// Contributors: gthomas
// Date:         2000-01-10
// Purpose:      
// Description:  
//              
//
//####DESCRIPTIONEND####
//
//==========================================================================

#ifndef _TESTS_NC_TEST_FRAMEWORK_H_
#define _TESTS_NC_TEST_FRAMEWORK_H_

#ifdef __ECOS
#include <network.h>
#else
#undef _KERNEL
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/time.h>

#include <net/if.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>

#include <netdb.h>
#ifndef EAI_NONE
#define EAI_NONE 0
#endif
#endif

#ifdef __ECOS
#define test_printf diag_printf
typedef cyg_addrword_t test_param_t;
#else
#define test_printf printf
typedef void *test_param_t;
#endif

#ifndef true
#define false 0
#define true  1
#endif

#define NC_SLAVE_PORT  7777
#define NC_MASTER_PORT 7776

#define NC_TESTING_SLAVE_PORT  8770
#define NC_TESTING_MASTER_PORT 8771

#define __string(s) #s
#define _string(s) __string(s)

//
// The basic idea behind this test structure is that one end will run
// in "slave" mode and the other in "master" mode.  Typically, the slave
// will run on a target platform with the master running on a host.
//
// The slave starts up by listening for a connection on the "SLAVE_PORT".
// In order for the testing to require the minimum stack support, this
// connection (and the protocol) will use UDP.
//
// The master will connect to the slave and send it a request over this
// connection.  Once the slave accepts the request, then master and slave
// will execute the operation, typically a test.  The control connection
// will remain active until the master sends a 'disconnect' request.  The
// control connection will be broken after the reply to this request has
// been sent.
//

#define MAX_ERRORS          5   // Give up after this many errors

#define NC_REPLY_TIMEOUT    10  // The slave may be slow
#define NC_TEST_TIMEOUT     3   // More generous for tests
#define NC_RESULTS_TIMEOUT  (MAX_ERRORS+2)*NC_TEST_TIMEOUT

struct nc_request {
    int type;          // Description of request
    int seq;           // Sequence number, used to build response
    int nbufs;         // Number of "buffers" to send
    int buflen;        // Length of each buffer
    int slave_port;    // Network ports to use
    int master_port;
    int timeout;       // Max time to wait for any packet
};

#define NC_REQUEST_DISCONNECT 0x0001
#define NC_REQUEST_UDP_SEND   0x0010  // Slave to send UDP data
#define NC_REQUEST_UDP_RECV   0x0011  // Slave to receive UDP data
#define NC_REQUEST_UDP_ECHO   0x0012  // Master->slave->master
#define NC_REQUEST_TCP_SEND   0x0020  // Slave to send TCP data
#define NC_REQUEST_TCP_RECV   0x0021  // Slave to receive TCP data
#define NC_REQUEST_TCP_ECHO   0x0022  // Master->slave->master
#define NC_REQUEST_START_IDLE 0x0100  // Start some idle processing
#define NC_REQUEST_STOP_IDLE  0x0101  // Stop idle processing
#define NC_REQUEST_SET_LOAD   0x0200  // Set the background load level

struct nc_reply {
    int  response; // ACK or NAK
    int  seq;      // Must match request
    int  reason;   // If NAK, why request turned down
    union {        // Miscellaneous data, depending on request
        struct {
            long      elapsed_time;  // In 10ms "ticks"
            long      count[2];      // Result 
        } idle_results;
    } misc;
};

#define NC_REPLY_ACK  0x0001    // Request accepted
#define NC_REPLY_NAK  0x0000    // Request denied

#define NC_REPLY_NAK_UNKNOWN_REQUEST 0x0001
#define NC_REPLY_NAK_BAD_REQUEST     0x0002  // Slave can't handle
#define NC_REPLY_NAK_NO_BACKGROUND   0x0003  // Slave can't do background/idle

//
// Test data 'packets' look like this

struct nc_test_data {
    long  key1;
    int   seq;
    int   len;
    long  key2;
    char  data[0];  // Actual data
};

#define NC_TEST_DATA_KEY1 0xC0DEADC0
#define NC_TEST_DATA_KEY2 0xC0DEADC1

struct nc_test_results {
    long key1;         // Identify uniquely as a response record
    int  seq;          // Matches request
    int  nsent;
    int  nrecvd;
    long key2;         // Additional verification
};

#define NC_TEST_RESULT_KEY1 0xDEADC0DE
#define NC_TEST_RESULT_KEY2 0xDEADC1DE

#endif // _TESTS_NC_TEST_FRAMEWORK_H_