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