1 /* This NetX test concentrates on the basic IP operation. */
2
3 #include "tx_api.h"
4 #include "nx_api.h"
5 #include "nx_ip.h"
6
7 extern void test_control_return(UINT status);
8
9 #if !defined(NX_DISABLE_IPV4)
10
11 #define DEMO_STACK_SIZE 2048
12
13
14 /* Define the ThreadX and NetX object control blocks... */
15
16 static TX_THREAD ntest_0;
17
18 static NX_PACKET_POOL pool_0;
19 static NX_IP ip_0;
20 static NX_IP ip_1;
21
22
23 /* Define the counters used in the test application... */
24
25 static ULONG error_counter;
26 static CHAR *ip_0_memory_ptr;
27 static CHAR *ip_1_memory_ptr;
28 static CHAR *arp_0_memory_ptr;
29 static CHAR *arp_1_memory_ptr;
30
31
32 /* Define thread prototypes. */
33
34 static void ntest_0_entry(ULONG thread_input);
35 extern void _nx_ram_network_driver_256(struct NX_IP_DRIVER_STRUCT *driver_req);
36 extern ULONG simulated_address_msw;
37 extern ULONG simulated_address_lsw;
38
39
40 /* Define what the initial system looks like. */
41
42 #ifdef CTEST
test_application_define(void * first_unused_memory)43 VOID test_application_define(void *first_unused_memory)
44 #else
45 void netx_ip_basic_test_application_define(void *first_unused_memory)
46 #endif
47 {
48
49 CHAR *pointer;
50 UINT status;
51
52
53 /* Setup the working pointer. */
54 pointer = (CHAR *) first_unused_memory;
55
56 /* Create the main thread. */
57 tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,
58 pointer, DEMO_STACK_SIZE,
59 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
60 pointer = pointer + DEMO_STACK_SIZE;
61
62 /* Initialize the NetX system. */
63 nx_system_initialize();
64
65 /* Create a packet pool. */
66 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
67 pointer = pointer + 8192;
68
69 if (status)
70 error_counter++;
71
72 /* Create IP instances. */
73 ip_0_memory_ptr = pointer;
74 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 9), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_256,
75 pointer, 2048, 1);
76 pointer = pointer + 2048;
77 ip_1_memory_ptr = pointer;
78 status = nx_ip_create(&ip_1, "NetX IP Instance 1", IP_ADDRESS(1, 2, 3, 10), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_256,
79 pointer, 2048, 2);
80 pointer = pointer + 2048;
81
82 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
83 arp_0_memory_ptr = pointer;
84 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
85 pointer = pointer + 1024;
86 arp_1_memory_ptr = pointer;
87 status += nx_arp_enable(&ip_1, (void *) pointer, 1024);
88 pointer = pointer + 1024;
89 if (status)
90 error_counter++;
91 }
92
93
94
95 /* Define the test threads. */
96
ntest_0_entry(ULONG thread_input)97 static void ntest_0_entry(ULONG thread_input)
98 {
99
100 UINT status;
101 ULONG ip_address;
102 ULONG mask;
103 ULONG value;
104 ULONG ip_total_packets_sent;
105 ULONG ip_total_bytes_sent;
106 ULONG ip_total_packets_received;
107 ULONG ip_total_bytes_received;
108 ULONG ip_invalid_packets;
109 ULONG ip_receive_packets_dropped;
110 ULONG ip_receive_checksum_errors;
111 ULONG ip_send_packets_dropped;
112 ULONG ip_total_fragments_sent;
113 ULONG ip_total_fragments_received;
114 #ifdef __PRODUCT_NETXDUO__
115 ULONG physical_msw;
116 ULONG physical_lsw;
117 ULONG gateway_addr_getted;
118 #endif /* __PRODUCT_NETXDUO__ */
119 #ifdef NX_ENABLE_IP_STATIC_ROUTING
120 NX_INTERFACE
121 *if_ptr = NX_NULL;
122 ULONG next_hop_address;
123
124
125 /* Test static routing. */
126 /* Add static route. */
127 nx_ip_static_route_add(&ip_0, IP_ADDRESS(1, 2, 3, 0), 0xFFFFFF00UL, IP_ADDRESS(1, 2, 3, 2));
128
129 nx_ip_static_route_add(&ip_0, IP_ADDRESS(1, 2, 3, 0), 0xFFFFFF00UL, IP_ADDRESS(1, 2, 3, 1));
130
131 nx_ip_static_route_add(&ip_0, IP_ADDRESS(1, 2, 4, 0), 0xFFFFFF00UL, IP_ADDRESS(1, 2, 3, 1));
132
133 /* Find route. */
134 _nx_ip_route_find(&ip_0, IP_ADDRESS(1, 2, 3, 2), &if_ptr, &next_hop_address);
135
136 /* Check interface and next hop address. */
137 if((if_ptr != &ip_0.nx_ip_interface[0]) ||
138 (next_hop_address != IP_ADDRESS(1, 2, 3, 1)))
139 error_counter++;
140 #endif /* NX_ENABLE_IP_STATIC_ROUTING */
141
142
143 /* Print out test information banner. */
144 printf("NetX Test: IP Basic Operation Test...................................");
145
146 /* Check for earlier error. */
147 if (error_counter)
148 {
149
150 printf("ERROR!\n");
151 test_control_return(1);
152 }
153
154 /* Pickup the IP address. */
155 status = nx_ip_address_get(&ip_0, &ip_address, &mask);
156
157 /* Check for an error. */
158 if ((status) || (ip_address != IP_ADDRESS(1, 2, 3, 9)))
159 {
160
161 printf("ERROR!\n");
162 test_control_return(1);
163 }
164
165 /* Set the IP address. */
166 status = nx_ip_address_set(&ip_0, IP_ADDRESS(1, 2, 3, 13), 0xFFFFFF00UL);
167 status += nx_ip_address_get(&ip_0, &ip_address, &mask);
168
169 /* Check for an error. */
170 if ((status) || (ip_address != IP_ADDRESS(1, 2, 3, 13)))
171 {
172
173 printf("ERROR!\n");
174 test_control_return(1);
175 }
176
177 #ifdef NX_ENABLE_IP_STATIC_ROUTING
178 /* Delete a static route. */
179 status = nx_ip_static_route_delete(&ip_0, IP_ADDRESS(1,2,4,0), 0xFFFFFF00UL);
180 if(status != NX_SUCCESS)
181 {
182 printf("ERROR!\n");
183 test_control_return(1);
184 }
185 #endif
186
187
188 /* Delete both IP instances. */
189 status = nx_ip_delete(&ip_0);
190 status += nx_ip_delete(&ip_1);
191
192 /* Check for an error. */
193 if (status)
194 {
195
196 printf("ERROR!\n");
197 test_control_return(1);
198 }
199
200 /* Create IP instances. */
201 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_256,
202 ip_0_memory_ptr, 2048, 1);
203 status += nx_ip_create(&ip_1, "NetX IP Instance 1", IP_ADDRESS(1, 2, 3, 5), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_256,
204 ip_1_memory_ptr, 2048, 1);
205 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
206 status += nx_arp_enable(&ip_0, (void *) arp_0_memory_ptr, 1024);
207 status += nx_arp_enable(&ip_1, (void *) arp_1_memory_ptr, 1024);
208
209 /* Check the status of the IP instances. */
210 status += nx_ip_status_check(&ip_0, NX_IP_INITIALIZE_DONE, &value, NX_IP_PERIODIC_RATE);
211
212 /* Check for an error. */
213 if ((status) || (value != NX_IP_INITIALIZE_DONE))
214 {
215
216 printf("ERROR!\n");
217 test_control_return(1);
218 }
219
220 /* Call driver directly. */
221 status = nx_ip_driver_direct_command(&ip_0, NX_LINK_GET_STATUS, &value);
222
223 /* Check for an error. */
224 if (status)
225 {
226
227 printf("ERROR!\n");
228 test_control_return(1);
229 }
230
231 /* Call driver directly specifying the interface. */
232 status = nx_ip_driver_interface_direct_command(&ip_0, NX_LINK_GET_STATUS, 0, &value);
233
234 /* Check for an error. */
235 if (status)
236 {
237 printf("ERROR!\n");
238 test_control_return(1);
239 }
240
241 /* Enable and disable forwarding. */
242 status = nx_ip_forwarding_enable(&ip_0);
243 status += nx_ip_forwarding_disable(&ip_0);
244
245 /* Check for an error. */
246 if (status)
247 {
248
249 printf("ERROR!\n");
250 test_control_return(1);
251 }
252
253 #ifdef __PRODUCT_NETXDUO__
254 /* Enable fragment feature. */
255 status = nx_ip_fragment_enable(&ip_0);
256
257 #ifndef NX_DISABLE_FRAGMENTATION
258 /* Check the status. */
259 if (status)
260 {
261
262 printf("ERROR!\n");
263 test_control_return(1);
264 }
265 #else
266 /* Check the status. */
267 if (status != NX_NOT_ENABLED)
268 {
269
270 printf("ERROR!\n");
271 test_control_return(1);
272 }
273 #endif
274
275 /* Disable fragment feature. */
276 status = nx_ip_fragment_disable(&ip_0);
277
278 #ifndef NX_DISABLE_FRAGMENTATION
279 /* Check the status. */
280 if (status)
281 {
282
283 printf("ERROR!\n");
284 test_control_return(1);
285 }
286 #else
287 /* Check the status. */
288 if (status != NX_NOT_ENABLED)
289 {
290
291 printf("ERROR!\n");
292 test_control_return(1);
293 }
294 #endif
295 #endif
296
297 /* Set the gateway address. */
298 status = nx_ip_gateway_address_set(&ip_0, IP_ADDRESS(1, 2, 3, 87));
299
300 /* Check for an error. */
301 if (status)
302 {
303 printf("ERROR!\n");
304 test_control_return(1);
305 }
306
307 #ifdef __PRODUCT_NETXDUO__
308 status = nx_ip_gateway_address_get(&ip_0, &gateway_addr_getted);
309 if((status != NX_SUCCESS) || gateway_addr_getted != IP_ADDRESS(1,2,3,87))
310 {
311 printf("ERROR!\n");
312 test_control_return(1);
313 }
314 #endif /* __PRODUCT_NETXDUO__ */
315
316 #ifdef __PRODUCT_NETXDUO__
317 /* Get Mac address. */
318 status = nx_ip_interface_physical_address_get(&ip_0, 0, &physical_msw, &physical_lsw);
319 if((status != NX_SUCCESS) ||
320 (physical_msw != simulated_address_msw) ||
321 (physical_lsw != simulated_address_lsw))
322 {
323 printf("ERROR!\n");
324 test_control_return(1);
325 }
326
327 status = nx_ip_gateway_address_clear(&ip_0);
328 if(status != NX_SUCCESS)
329 {
330 printf("ERROR!\n");
331 test_control_return(1);
332 }
333 #endif /* __PRODUCT_NETXDUO__ */
334
335 /* Get nothing from IP info. */
336 status = nx_ip_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL);
337
338 if(status != NX_SUCCESS)
339 {
340 printf("ERROR!\n");
341 test_control_return(1);
342 }
343
344 /* Get IP info. */
345 status = nx_ip_info_get(&ip_0, &ip_total_packets_sent,
346 &ip_total_bytes_sent,
347 &ip_total_packets_received,
348 &ip_total_bytes_received,
349 &ip_invalid_packets,
350 &ip_receive_packets_dropped,
351 &ip_receive_checksum_errors,
352 &ip_send_packets_dropped,
353 &ip_total_fragments_sent,
354 &ip_total_fragments_received);
355
356 /* Check status. */
357 if ((status) || (ip_total_packets_sent) || (ip_total_bytes_sent) || (ip_total_packets_received) ||
358 (ip_total_bytes_received) || (ip_invalid_packets) || (ip_receive_packets_dropped) || (ip_receive_checksum_errors) ||
359 (ip_send_packets_dropped) || (ip_total_fragments_sent) || (ip_total_fragments_received))
360 {
361
362 printf("ERROR!\n");
363 test_control_return(1);
364 }
365 else
366 {
367
368 printf("SUCCESS!\n");
369 test_control_return(0);
370 }
371 }
372 #else
373
374 #ifdef CTEST
test_application_define(void * first_unused_memory)375 VOID test_application_define(void *first_unused_memory)
376 #else
377 void netx_ip_basic_test_application_define(void *first_unused_memory)
378 #endif
379 {
380
381 /* Print out test information banner. */
382 printf("NetX Test: IP Basic Operation Test...................................N/A\n");
383
384 test_control_return(3);
385 }
386 #endif
387