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