1 /* This NetX test concentrates on the ICMP ping operation. */
2
3 #include "tx_api.h"
4 #include "nx_api.h"
5 #include "nx_ip.h"
6 extern void test_control_return(UINT status);
7
8 #if defined(__PRODUCT_NETXDUO__) && !defined(NX_DISABLE_IPV4)
9 #define DEMO_STACK_SIZE 2048
10
11
12 /* Define the ThreadX and NetX object control blocks... */
13
14 static TX_THREAD thread_0;
15 static TX_THREAD thread_1;
16
17 static NX_PACKET_POOL pool_0;
18 static NX_IP ip_0;
19 static NX_IP ip_1;
20 static NX_TCP_SOCKET client_socket;
21 static NX_TCP_SOCKET server_socket;
22
23
24
25 /* Define the counters used in the test application... */
26
27 static ULONG error_counter;
28
29
30 /* Define thread prototypes. */
31
32 static void thread_0_entry(ULONG thread_input);
33 static void thread_1_entry(ULONG thread_input);
34 extern void _nx_ram_network_driver_256(struct NX_IP_DRIVER_STRUCT *driver_req);
35 extern UINT (*packet_process_callback)(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
36
37
38 /* Define what the initial system looks like. */
39
40 #ifdef CTEST
test_application_define(void * first_unused_memory)41 VOID test_application_define(void *first_unused_memory)
42 #else
43 void netx_ip_link_local_address_test_application_define(void *first_unused_memory)
44 #endif
45 {
46
47 CHAR *pointer;
48 UINT status;
49
50 /* Setup the working pointer. */
51 pointer = (CHAR *) first_unused_memory;
52
53 tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
54 pointer, DEMO_STACK_SIZE,
55 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
56
57 pointer = pointer + DEMO_STACK_SIZE;
58
59
60 /* Create the main thread. */
61 tx_thread_create(&thread_1, "thread 1", thread_1_entry, 0,
62 pointer, DEMO_STACK_SIZE,
63 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
64
65 pointer = pointer + DEMO_STACK_SIZE;
66
67
68 /* Initialize the NetX system. */
69 nx_system_initialize();
70
71 /* Create a packet pool. */
72 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 2048);
73 pointer = pointer + 2048;
74
75 if (status)
76 error_counter++;
77
78 /* Create an IP instance. */
79 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(169, 254, 3, 4), 0xFFFF0000UL, &pool_0, _nx_ram_network_driver_256,
80 pointer, 2048, 1);
81 pointer = pointer + 2048;
82
83 /* Create another IP instance. */
84 status += nx_ip_create(&ip_1, "NetX IP Instance 1", IP_ADDRESS(1, 2, 3, 5), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_256,
85 pointer, 2048, 2);
86 pointer = pointer + 2048;
87 if (status)
88 error_counter++;
89
90 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
91 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
92 pointer = pointer + 1024;
93 if (status)
94 error_counter++;
95
96 /* Enable ARP and supply ARP cache memory for IP Instance 1. */
97 status = nx_arp_enable(&ip_1, (void *) pointer, 1024);
98 pointer = pointer + 1024;
99 if (status)
100 error_counter++;
101
102 /* Enable TCP processing for both IP instances. */
103 status = nx_tcp_enable(&ip_0);
104 status += nx_tcp_enable(&ip_1);
105
106 /* Check TCP enable status. */
107 if (status)
108 error_counter++;
109 }
110
111
112 /* Define the test threads. */
113
thread_0_entry(ULONG thread_input)114 static void thread_0_entry(ULONG thread_input)
115 {
116 UINT status;
117 UINT i;
118 ULONG server_addr;
119
120 /* Print out some test information banners. */
121 printf("NetX Test: IP Link-Local Address Test................................");
122
123 /* Check for earlier error. */
124 if (error_counter)
125 {
126
127 printf("ERROR!\n");
128 test_control_return(1);
129 }
130
131 server_addr = IP_ADDRESS(1, 2, 3, 5);
132
133 for (i = 0; i < 2; i++)
134 {
135
136 /* Create the client socket. */
137 status = nx_tcp_socket_create(&ip_0, &client_socket, "Client Socket",
138 NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 65535,
139 NX_NULL, NX_NULL);
140
141 /* Check for error */
142 if (status)
143 {
144 error_counter++;
145 }
146
147 /* Bind the socket. */
148 status = nx_tcp_client_socket_bind(&client_socket, 12, 5 * NX_IP_PERIODIC_RATE);
149
150 /* Check for error */
151 if (status)
152 {
153 error_counter++;
154 }
155
156 /* Connect to server. */
157 status = nx_tcp_client_socket_connect(&client_socket, server_addr, 12, 5 * NX_IP_PERIODIC_RATE);
158
159 /* Check for error */
160 if (status)
161 {
162 error_counter++;
163 }
164
165 /* Disconnect from server. */
166 status = nx_tcp_socket_disconnect(&client_socket, 5 * NX_IP_PERIODIC_RATE);
167
168 /* Check for error */
169 if (status)
170 {
171 error_counter++;
172 }
173
174 /* Unbind the client socket. */
175 status = nx_tcp_client_socket_unbind(&client_socket);
176
177 /* Check for error */
178 if (status)
179 {
180 error_counter++;
181 }
182
183 /* Delete the client socket. */
184 status = nx_tcp_socket_delete(&client_socket);
185
186 /* Check for error */
187 if (status)
188 {
189 error_counter++;
190 }
191
192 tx_thread_sleep(NX_IP_PERIODIC_RATE);
193
194 /* Modify the IP address to routable. */
195 nx_ip_address_set(&ip_0, IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00);
196 server_addr = IP_ADDRESS(169, 254, 3, 5);
197 }
198
199 if (error_counter)
200 {
201
202 printf("ERROR!\n");
203 test_control_return(1);
204 }
205 else
206 {
207
208 printf("SUCCESS!\n");
209 test_control_return(0);
210 }
211 }
212
213
thread_1_entry(ULONG thread_input)214 static void thread_1_entry(ULONG thread_input)
215 {
216 UINT status;
217 UINT i;
218
219 for (i = 0; i < 2; i++)
220 {
221
222 /* Create the server socket. */
223 status = nx_tcp_socket_create(&ip_1, &server_socket, "Server Socket",
224 NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 65535,
225 NX_NULL, NX_NULL);
226
227 /* Check for error */
228 if (status)
229 {
230 error_counter++;
231 }
232
233 /* Listen the socket. */
234 status = nx_tcp_server_socket_listen(&ip_1, 12, &server_socket, 5, NX_NULL);
235
236 /* Check for error */
237 if (status)
238 {
239 error_counter++;
240 }
241
242 /* Accept connection from client. */
243 status = nx_tcp_server_socket_accept(&server_socket, 5 * NX_IP_PERIODIC_RATE);
244
245 /* Check for error */
246 if (status)
247 {
248 error_counter++;
249 }
250
251 /* Disconnect from client. */
252 status = nx_tcp_socket_disconnect(&server_socket, 5);
253
254 /* Check for error */
255 if (status)
256 {
257 error_counter++;
258 }
259
260 /* Unaccept the server socket. */
261 status = nx_tcp_server_socket_unaccept(&server_socket);
262
263 /* Check for error */
264 if (status)
265 {
266 error_counter++;
267 }
268
269 /* Setup server socket for listening again. */
270 status = nx_tcp_server_socket_relisten(&ip_1, 12, &server_socket);
271
272 /* Check for error */
273 if (status)
274 {
275 error_counter++;
276 }
277
278 /* Unlisten on the server port. */
279 status = nx_tcp_server_socket_unlisten(&ip_1, 12);
280
281 /* Check for error */
282 if (status)
283 {
284 error_counter++;
285 }
286
287 /* Delete the client socket. */
288 status = nx_tcp_socket_delete(&server_socket);
289
290 /* Check for error */
291 if (status)
292 {
293 error_counter++;
294 }
295
296 /* Modify the IP address to link-local. */
297 nx_ip_address_set(&ip_1, IP_ADDRESS(169, 254, 3, 5), 0xFFFF0000);
298 }
299 }
300 #else
301 #ifdef CTEST
test_application_define(void * first_unused_memory)302 VOID test_application_define(void *first_unused_memory)
303 #else
304 void netx_ip_link_local_address_test_application_define(void *first_unused_memory)
305 #endif
306 {
307
308 /* Print out test information banner. */
309 printf("NetX Test: IP Link-Local Address Test................................N/A\n");
310
311 test_control_return(3);
312
313 }
314 #endif /* __PRODUCT_NETXDUO__ */
315