1 /* This NetX test concentrates on the ARP dynamic entry operation.  */
2 
3 #include   "tx_api.h"
4 #include   "nx_api.h"
5 
6 extern void    test_control_return(UINT status);
7 
8 #if defined(__PRODUCT_NETXDUO__) && !defined(NX_DISABLE_IPV4)
9 
10 #define     DEMO_STACK_SIZE         2048
11 #define     ARP_ENTRY_COUNT         35
12 
13 /* Define the ThreadX and NetX object control blocks...  */
14 
15 static TX_THREAD               ntest_0;
16 static NX_PACKET_POOL          pool_0;
17 static NX_IP                   ip_0;
18 
19 
20 
21 /* Define the counters used in the test application...  */
22 
23 static ULONG                   error_counter;
24 
25 
26 /* Define thread prototypes.  */
27 
28 static void    ntest_0_entry(ULONG thread_input);
29 extern void    _nx_ram_network_driver_256(struct NX_IP_DRIVER_STRUCT *driver_req);
30 
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_arp_entry_cache_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(&ntest_0, "thread 0", ntest_0_entry, 0,
52             pointer, DEMO_STACK_SIZE,
53             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
54 
55     pointer =  pointer + DEMO_STACK_SIZE;
56 
57     /* Initialize the NetX system.  */
58     nx_system_initialize();
59 
60     /* Create a packet pool.  */
61     status =  nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
62     pointer = pointer + 8192;
63 
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), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_256,
69                     pointer, 2048, 1);
70     pointer =  pointer + 2048;
71 
72     /* Enable ARP and supply ARP cache memory for IP Instance 0, the ARP cache can store five entries.  */
73     status =  nx_arp_enable(&ip_0, (void *) pointer, ARP_ENTRY_COUNT * sizeof(NX_ARP));
74     pointer = pointer + ARP_ENTRY_COUNT * sizeof(NX_ARP);
75     if (status)
76         error_counter++;
77 }
78 
79 
80 /* Define the test threads.  */
81 
ntest_0_entry(ULONG thread_input)82 static void    ntest_0_entry(ULONG thread_input)
83 {
84 
85 INT         i;
86 UINT        status;
87 ULONG       physical_msw;
88 ULONG       physical_lsw;
89 ULONG       address;
90 
91 
92     /* Print out some test information banners.  */
93     printf("NetX Test:   ARP Entry CACHE Processing Test...........................");
94 
95     /* Check for earlier error.  */
96     if (error_counter)
97     {
98 
99         printf("ERROR!\n");
100         test_control_return(1);
101     }
102 
103     /* Set the IP address.   */
104     address = 5;
105 
106     /* Set the physical address.   */
107     physical_msw = 0x0011;
108     physical_lsw = 0x22334457;
109 
110     /* Loop to added the dynamic entries, the dynamic entry can be replaced. .  */
111     for (i = 0; i < 3 * ARP_ENTRY_COUNT; i++)
112     {
113 
114         /* Set a dynamic ARP entry.  */
115         status =  nx_arp_dynamic_entry_set(&ip_0, IP_ADDRESS(1, 2, 3, address), physical_msw, physical_lsw);
116         if (status)
117         {
118 
119             printf("ERROR!\n");
120             test_control_return(1);
121         }
122         else
123         {
124 
125             /* Update the IP address.  */
126             address ++;
127 
128             /* Update the physical address.  */
129             physical_lsw ++;
130         }
131     }
132 
133     /* Delete the entry that does not exist.  */
134     status =  nx_arp_entry_delete(&ip_0, IP_ADDRESS(1, 2, 3, address));
135     if (status != NX_ENTRY_NOT_FOUND)
136     {
137 
138         printf("ERROR!\n");
139         test_control_return(1);
140     }
141     else
142     {
143 
144         /* Update the IP address.  */
145         address --;
146 
147         /* Update the physical address.  */
148         physical_lsw --;
149 
150         /* Update the idex.  */
151         i --;
152     }
153 
154     /* Loop to delete the dynamic entries, the dynamic entry can be replaced. .  */
155     for (; i >= 2 * ARP_ENTRY_COUNT; i--)
156     {
157 
158         /* Delete a dynamic ARP entry.  */
159         status =  nx_arp_entry_delete(&ip_0, IP_ADDRESS(1, 2, 3, address));
160         if (status)
161         {
162 
163             printf("ERROR!\n");
164             test_control_return(1);
165         }
166         else
167         {
168 
169             /* Update the IP address.  */
170             address --;
171 
172             /* Update the physical address.  */
173             physical_lsw --;
174         }
175     }
176 
177     /* Loop to delete the replaced dynamic entries.  */
178     for (; i >= 0; i--)
179     {
180 
181         /* Delete a dynamic ARP entry.  */
182         status =  nx_arp_entry_delete(&ip_0, IP_ADDRESS(1, 2, 3, address));
183         if (status != NX_ENTRY_NOT_FOUND)
184         {
185 
186             printf("ERROR!\n");
187             test_control_return(1);
188         }
189         else
190         {
191 
192             /* Update the IP address.  */
193             address --;
194 
195             /* Update the physical address.  */
196             physical_lsw --;
197         }
198     }
199 
200     /* Set the IP address.   */
201     address = 5;
202 
203     /* Set the physical address.   */
204     physical_msw = 0x0011;
205     physical_lsw = 0x22334457;
206 
207     /* Loop to added the dynamic entries, 35.  */
208     for (i = 0; i < ARP_ENTRY_COUNT; i++)
209     {
210 
211         /* Set a dynamic ARP entry.  */
212         status =  nx_arp_dynamic_entry_set(&ip_0, IP_ADDRESS(1, 2, 3, address), physical_msw, physical_lsw);
213         if (status)
214         {
215 
216             printf("ERROR!\n");
217             test_control_return(1);
218         }
219         else
220         {
221 
222             /* Update the IP address.  */
223             address ++;
224 
225             /* Update the physical address.  */
226             physical_lsw ++;
227         }
228     }
229 
230     /* Loop to added the static entries, 35.  */
231     for (; i < 2 * ARP_ENTRY_COUNT; i++)
232     {
233 
234         /* Set a static ARP entry.  */
235         status =  nx_arp_static_entry_create(&ip_0, IP_ADDRESS(1, 2, 3, address), physical_msw, physical_lsw);
236         if (status)
237         {
238 
239             printf("ERROR!\n");
240             test_control_return(1);
241         }
242         else
243         {
244 
245             /* Update the IP address.  */
246             address ++;
247 
248             /* Update the physical address.  */
249             physical_lsw ++;
250         }
251     }
252 
253     /* Set a static ARP entry, should be fail.  */
254     status =  nx_arp_static_entry_create(&ip_0, IP_ADDRESS(1, 2, 3, address), physical_msw, physical_lsw);
255     if (status != NX_NO_MORE_ENTRIES)
256     {
257 
258         printf("ERROR!\n");
259         test_control_return(1);
260     }
261 
262     /* Set a dynamic ARP entry, should be fail.  */
263     status =  nx_arp_dynamic_entry_set(&ip_0, IP_ADDRESS(1, 2, 3, address), physical_msw, physical_lsw);
264     if (status != NX_NO_MORE_ENTRIES)
265     {
266 
267         printf("ERROR!\n");
268         test_control_return(1);
269     }
270 
271     /* Update the IP address.  */
272     address --;
273 
274     /* Update the physical address.  */
275     physical_lsw --;
276 
277     /* Update the idex.  */
278     i --;
279 
280     /* Loop to delete the static entries.  */
281     for (; i >= ARP_ENTRY_COUNT; i--)
282     {
283 
284         /* Delete a static ARP entry.  */
285         status =  nx_arp_entry_delete(&ip_0, IP_ADDRESS(1, 2, 3, address));
286         if (status)
287         {
288 
289             printf("ERROR!\n");
290             test_control_return(1);
291         }
292         else
293         {
294 
295             /* Update the IP address.  */
296             address --;
297 
298             /* Update the physical address.  */
299             physical_lsw --;
300         }
301     }
302 
303     /* Loop to delete the replaced dynamic entries.  */
304     for (; i >= 0; i--)
305     {
306 
307         /* Delete a dynamic ARP entry.  */
308         status =  nx_arp_entry_delete(&ip_0, IP_ADDRESS(1, 2, 3, address));
309         if (status != NX_ENTRY_NOT_FOUND)
310         {
311 
312             printf("ERROR!\n");
313             test_control_return(1);
314         }
315         else
316         {
317 
318             /* Update the IP address.  */
319             address --;
320 
321             /* Update the physical address.  */
322             physical_lsw --;
323         }
324     }
325 
326     /* Set the IP address.   */
327     address = 5;
328 
329     /* Set the physical address.   */
330     physical_msw = 0x0011;
331     physical_lsw = 0x22334457;
332 
333     /* Loop to added the dynamic entries, 35.  */
334     for (i = 0; i < ARP_ENTRY_COUNT; i++)
335     {
336 
337         /* Set a dynamic ARP entry.  */
338         status =  nx_arp_dynamic_entry_set(&ip_0, IP_ADDRESS(1, 2, 3, address), physical_msw, physical_lsw);
339         if (status)
340         {
341 
342             printf("ERROR!\n");
343             test_control_return(1);
344         }
345         else
346         {
347 
348             /* Update the IP address.  */
349             address ++;
350 
351             /* Update the physical address.  */
352             physical_lsw ++;
353         }
354     }
355 
356     /* Invalidate all dynamic entries. */
357     status = nx_arp_dynamic_entries_invalidate(&ip_0);
358     if (status)
359     {
360 
361         printf("ERROR!\n");
362         test_control_return(1);
363     }
364 
365     /* Output successful.  */
366     printf("SUCCESS!\n");
367     test_control_return(0);
368 }
369 #else
370 #ifdef CTEST
test_application_define(void * first_unused_memory)371 VOID test_application_define(void *first_unused_memory)
372 #else
373 void    netx_arp_entry_cache_test_application_define(void *first_unused_memory)
374 #endif
375 {
376 
377     /* Print out test information banner.  */
378     printf("NetX Test:   ARP Entry CACHE Processing Test...........................N/A\n");
379 
380     test_control_return(3);
381 }
382 #endif /* __PRODUCT_NETXDUO__ */
383 
384