1 /* This NetX test concentrates on the basic UDP operation.  */
2 
3 
4 #include   "tx_api.h"
5 #include   "nx_api.h"
6 #include   "nx_ip.h"
7 
8 extern void  test_control_return(UINT status);
9 
10 #if !defined NX_DISABLE_ERROR_CHECKING && defined FEATURE_NX_IPV6
11 #include   "nx_nd_cache.h"
12 
13 #define     DEMO_STACK_SIZE         2048
14 
15 /* Define the ThreadX and NetX object control blocks...  */
16 
17 static TX_THREAD               thread_0;
18 
19 static NX_PACKET_POOL          pool_0;
20 static NX_IP                   ip_0;
21 static NX_IP                   invalid_ip;
22 
23 /* Define the counters used in the demo application...  */
24 
25 static ULONG                   error_counter;
26 
27 /* Define thread prototypes.  */
28 
29 static void    thread_0_entry(ULONG thread_input);
30 extern void    _nx_ram_network_driver_256(struct NX_IP_DRIVER_STRUCT *driver_req);
31 
32 /* Define what the initial system looks like.  */
33 
34 #ifdef CTEST
test_application_define(void * first_unused_memory)35 VOID test_application_define(void *first_unused_memory)
36 #else
37 void    netx_nd_cache_nxe_api_test_application_define(void *first_unused_memory)
38 #endif
39 {
40 
41 CHAR    *pointer;
42 UINT    status;
43 
44 
45     /* Setup the working pointer.  */
46     pointer =  (CHAR *) first_unused_memory;
47 
48     error_counter =  0;
49 
50     /* Create the main thread.  */
51     tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
52             pointer, DEMO_STACK_SIZE,
53             3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
54     pointer =  pointer + DEMO_STACK_SIZE;
55 
56     /* Initialize the NetX system.  */
57     nx_system_initialize();
58 
59     /* Create a packet pool.  */
60     status =  nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 2048);
61     pointer = pointer + 2048;
62 
63     /* Check for pool creation error.  */
64     if (status)
65         error_counter++;
66 
67     /* Create an IP instance.  */
68     status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFF000UL, &pool_0, _nx_ram_network_driver_256,
69                     pointer, 2048, 1);
70     pointer =  pointer + 2048;
71 
72     /* Check for IP create errors.  */
73     if (status)
74         error_counter++;
75 }
76 
77 /* Define the test threads.  */
78 
thread_0_entry(ULONG thread_input)79 static void    thread_0_entry(ULONG thread_input)
80 {
81 
82 UINT        status;
83 NXD_ADDRESS ipv6_address;
84 CHAR        mac_addr[6];
85 ULONG       physical_msw;
86 ULONG       physical_lsw;
87 UINT        interface_index;
88 
89     /* Print out some test information banners.  */
90     printf("NetX Test:   ND CACHE NXE API Test.....................................");
91 
92     /* Check for earlier error.  */
93     if (error_counter)
94     {
95 
96         printf("ERROR!\n");
97         test_control_return(1);
98     }
99 
100     /* Set the IPv6 address.  */
101     ipv6_address.nxd_ip_version = NX_IP_VERSION_V6;
102     ipv6_address.nxd_ip_address.v6[0] = 0x20020000;
103     ipv6_address.nxd_ip_address.v6[1] = 0x00000000;
104     ipv6_address.nxd_ip_address.v6[2] = 0x00000000;
105     ipv6_address.nxd_ip_address.v6[3] = 0x01020306;
106 
107     /* Set the MAC address.  */
108     mac_addr[0] = 0x00;
109     mac_addr[0] = 0x11;
110     mac_addr[0] = 0x22;
111     mac_addr[0] = 0x33;
112     mac_addr[0] = 0x44;
113     mac_addr[0] = 0x58;
114 
115     /************************************************/
116     /* Tested the nxe_arp_entry_delete api          */
117     /************************************************/
118 
119     /* Delete the entry for NULL IP instance.  */
120     status = nxd_nd_cache_entry_delete(NX_NULL, &ipv6_address.nxd_ip_address.v6[0]);
121 
122     /* Check for error.  */
123     if (status != NX_PTR_ERROR)
124     {
125 
126         printf("ERROR!\n");
127         test_control_return(1);
128     }
129 
130     /* Delete the entry for invalid IP instance.  */
131     status = nxd_nd_cache_entry_delete(&invalid_ip, &ipv6_address.nxd_ip_address.v6[0]);
132 
133     /* Check for error.  */
134     if (status != NX_PTR_ERROR)
135     {
136 
137         printf("ERROR!\n");
138         test_control_return(1);
139     }
140 
141     /* Delete the entry with NULL IP address pointer.  */
142     status = nxd_nd_cache_entry_delete(&ip_0, NX_NULL);
143 
144     /* Check for error.  */
145     if (status != NX_PTR_ERROR)
146     {
147 
148         printf("ERROR!\n");
149         test_control_return(1);
150     }
151 
152     /**********************************************/
153     /* Tested the nxde_nd_cache_entry_set api     */
154     /**********************************************/
155 
156     /* Set the ND CACHE entry for NULL IP instance.  */
157     status = nxd_nd_cache_entry_set(NX_NULL, &ipv6_address.nxd_ip_address.v6[0], 0, mac_addr);
158 
159     /* Check for error.  */
160     if (status != NX_PTR_ERROR)
161     {
162 
163         printf("ERROR!\n");
164         test_control_return(1);
165     }
166 
167     /* Clear the ID for invalid IP instance.  */
168     invalid_ip.nx_ip_id = NX_NULL;
169 
170     /* Set the ND CACHE entry for invalid IP instance.  */
171     status = nxd_nd_cache_entry_set(&invalid_ip, &ipv6_address.nxd_ip_address.v6[0], 0, mac_addr);
172 
173     /* Check for error.  */
174     if (status != NX_PTR_ERROR)
175     {
176 
177         printf("ERROR!\n");
178         test_control_return(1);
179     }
180 
181     /* Set the ND CACHE entry with NULL ipv6 address pointer.  */
182     status = nxd_nd_cache_entry_set(&ip_0, NX_NULL, 0, mac_addr);
183 
184     /* Check for error.  */
185     if (status != NX_PTR_ERROR)
186     {
187 
188         printf("ERROR!\n");
189         test_control_return(1);
190     }
191 
192     /* Set the ND CACHE entry with NULL mac address pointer.  */
193     status = nxd_nd_cache_entry_set(&ip_0, &ipv6_address.nxd_ip_address.v6[0], 0, NX_NULL);
194 
195     /* Check for error.  */
196     if (status != NX_PTR_ERROR)
197     {
198 
199         printf("ERROR!\n");
200         test_control_return(1);
201     }
202 
203     /* Set the ND CACHE entry with MAX interface index.  */
204     status = nxd_nd_cache_entry_set(&ip_0, &ipv6_address.nxd_ip_address.v6[0], NX_MAX_PHYSICAL_INTERFACES, mac_addr);
205 
206     /* Check for error.  */
207     if (status != NX_INVALID_INTERFACE)
208     {
209 
210         printf("ERROR!\n");
211         test_control_return(1);
212     }
213 
214     /******************************************************/
215     /* Tested the nxde_nd_cache_hardware_address_find api */
216     /******************************************************/
217 
218     /* Find the hardware address for NULL IP instance.  */
219     status = nxd_nd_cache_hardware_address_find(NX_NULL, &ipv6_address, &physical_msw, &physical_lsw, &interface_index);
220 
221     /* Check for error.  */
222     if (status != NX_PTR_ERROR)
223     {
224 
225         printf("ERROR!\n");
226         test_control_return(1);
227     }
228 
229     /* Clear the ID for invalid IP instance.  */
230     invalid_ip.nx_ip_id = NX_NULL;
231 
232     /* Find the hardware address for invalid IP instance.  */
233     status = nxd_nd_cache_hardware_address_find(&invalid_ip, &ipv6_address, &physical_msw, &physical_lsw, &interface_index);
234 
235     /* Check for error.  */
236     if (status != NX_PTR_ERROR)
237     {
238 
239         printf("ERROR!\n");
240         test_control_return(1);
241     }
242 
243     /* Find the hardware address with NULL address pointer.  */
244     status = nxd_nd_cache_hardware_address_find(&ip_0, NX_NULL, &physical_msw, &physical_lsw, &interface_index);
245 
246     /* Check for error.  */
247     if (status != NX_PTR_ERROR)
248     {
249 
250         printf("ERROR!\n");
251         test_control_return(1);
252     }
253 
254     /* Find the hardware address for valid IP instance with invalid physical_msw pointer.  */
255     status = nxd_nd_cache_hardware_address_find(&ip_0, &ipv6_address, NX_NULL, &physical_lsw, &interface_index);
256 
257     /* Check for error.  */
258     if (status != NX_PTR_ERROR)
259     {
260 
261         printf("ERROR!\n");
262         test_control_return(1);
263     }
264 
265     /* Find the hardware address for valid IP instance with invalid physical_msw pointer.  */
266     status = nxd_nd_cache_hardware_address_find(&ip_0, &ipv6_address, &physical_msw, NX_NULL, &interface_index);
267 
268     /* Check for error.  */
269     if (status != NX_PTR_ERROR)
270     {
271 
272         printf("ERROR!\n");
273         test_control_return(1);
274     }
275 
276     /* Find the hardware address for valid IP instance with NULL interface index pointer.  */
277     status = nxd_nd_cache_hardware_address_find(&ip_0, &ipv6_address, &physical_msw, &physical_lsw, NX_NULL);
278 
279     /* Check for error.  */
280     if (status != NX_PTR_ERROR)
281     {
282 
283         printf("ERROR!\n");
284         test_control_return(1);
285     }
286 
287     /* Set the IPv6 address with invalid version.  */
288     ipv6_address.nxd_ip_version = NX_IP_VERSION_V4;
289 
290     /* Find the hardware address with invalid address version.  */
291     status = nxd_nd_cache_hardware_address_find(&ip_0, &ipv6_address, &physical_msw, &physical_lsw, &interface_index);
292 
293     /* Check for error.  */
294     if (status != NX_INVALID_PARAMETERS)
295     {
296 
297         printf("ERROR!\n");
298         test_control_return(1);
299     }
300 
301     /*******************************************/
302     /* Tested the nxde_nd_cache_invalidate api */
303     /*******************************************/
304 
305     /* Delete the ND Cache entries for NULL IP instance.  */
306     status = nxd_nd_cache_invalidate(NX_NULL);
307 
308     /* Check for error.  */
309     if (status != NX_PTR_ERROR)
310     {
311 
312         printf("ERROR!\n");
313         test_control_return(1);
314     }
315 
316     /* Set the ID for invalid IP instance.  */
317     invalid_ip.nx_ip_id = NX_NULL;
318 
319     /* Delete the ND Cache entries for invalid IP instance.  */
320     status = nxd_nd_cache_invalidate(&invalid_ip);
321 
322     /* Check for error.  */
323     if (status != NX_PTR_ERROR)
324     {
325 
326         printf("ERROR!\n");
327         test_control_return(1);
328     }
329 
330     /************************************************/
331     /* Tested the nxde_nd_cache_ip_address_find api */
332     /************************************************/
333 
334     /* Find the ip address for NULL IP instance.  */
335     status = nxd_nd_cache_ip_address_find(NX_NULL, &ipv6_address, 0x0011, 0x22334456, &interface_index);
336 
337     /* Check for error.  */
338     if (status != NX_PTR_ERROR)
339     {
340 
341         printf("ERROR!\n");
342         test_control_return(1);
343     }
344 
345     /* Clear the ID for invalid IP instance.  */
346     invalid_ip.nx_ip_id = NX_NULL;
347 
348     /* Find the ip address for invalid IP instance.  */
349     status = nxd_nd_cache_ip_address_find(&invalid_ip, &ipv6_address, 0x0011, 0x22334456, &interface_index);
350 
351     /* Check for error.  */
352     if (status != NX_PTR_ERROR)
353     {
354 
355         printf("ERROR!\n");
356         test_control_return(1);
357     }
358 
359     /* Find the ip address with NULL ip address pointer.  */
360     status = nxd_nd_cache_ip_address_find(&ip_0, NX_NULL, 0x0011, 0x22334456, &interface_index);
361 
362     /* Check for error.  */
363     if (status != NX_PTR_ERROR)
364     {
365 
366         printf("ERROR!\n");
367         test_control_return(1);
368     }
369 
370     /* Find the ip address with NULL interface index pointer.  */
371     status = nxd_nd_cache_ip_address_find(&ip_0, &ipv6_address, 0x0011, 0x22334456, NX_NULL);
372 
373     /* Check for error.  */
374     if (status != NX_PTR_ERROR)
375     {
376 
377         printf("ERROR!\n");
378         test_control_return(1);
379     }
380 
381     /* Find the ip address with invalid physcial address.  */
382     status = nxd_nd_cache_ip_address_find(&ip_0, &ipv6_address, 0, 0, &interface_index);
383 
384     /* Check for error.  */
385     if (status != NX_INVALID_PARAMETERS)
386     {
387 
388         printf("ERROR!\n");
389         test_control_return(1);
390     }
391 
392     /* Find the ip address with valid physcial address.  */
393     status = nxd_nd_cache_ip_address_find(&ip_0, &ipv6_address, 0, 1, &interface_index);
394 
395     /* Check for error.  */
396     if (status != NX_ENTRY_NOT_FOUND)
397     {
398 
399         printf("ERROR!\n");
400         test_control_return(1);
401     }
402 
403     /* Output success.  */
404     printf("SUCCESS!\n");
405     test_control_return(0);
406 }
407 #else
408 #ifdef CTEST
test_application_define(void * first_unused_memory)409 VOID test_application_define(void *first_unused_memory)
410 #else
411 void    netx_nd_cache_nxe_api_test_application_define(void *first_unused_memory)
412 #endif
413 {
414 
415     /* Print out test information banner.  */
416     printf("NetX Test:   ND CACHE NXE API Test.....................................N/A\n");
417 
418     test_control_return(3);
419 }
420 #endif
421