1 /* This NetX test concentrates on the basic IGMP 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(NX_DISABLE_IGMP_INFO) && !defined(NX_DISABLE_IPV4)
9 
10 #define     DEMO_STACK_SIZE         2048
11 
12 
13 /* Define the ThreadX and NetX object control blocks...  */
14 
15 static TX_THREAD               ntest_0;
16 
17 static NX_PACKET_POOL          pool_0;
18 static NX_IP                   ip_0;
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 
30 extern void    _nx_ram_network_driver_256(struct NX_IP_DRIVER_STRUCT *driver_req);
31 
32 
33 /* Define what the initial system looks like.  */
34 
35 #ifdef CTEST
test_application_define(void * first_unused_memory)36 VOID test_application_define(void *first_unused_memory)
37 #else
38 void    netx_igmp_basic_test_application_define(void *first_unused_memory)
39 #endif
40 {
41 
42 CHAR    *pointer;
43 UINT    status;
44 
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(&ntest_0, "thread 0", ntest_0_entry, 0,
53             pointer, DEMO_STACK_SIZE,
54             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
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.  */
73     status =  nx_arp_enable(&ip_0, (void *) pointer, 1024);
74     pointer = pointer + 1024;
75     if (status)
76         error_counter++;
77 
78     /* Enable IGMP processing for both this IP instance.  */
79     status =  nx_igmp_enable(&ip_0);
80 
81     /* Check enable status.  */
82     if (status)
83         error_counter++;
84 }
85 
86 
87 
88 /* Define the test threads.  */
89 
ntest_0_entry(ULONG thread_input)90 static void    ntest_0_entry(ULONG thread_input)
91 {
92 
93 UINT        status;
94 ULONG       igmp_reports_sent;
95 ULONG       igmp_queries_received;
96 ULONG       igmp_checksum_errors;
97 ULONG       current_groups_joined;
98 
99 
100     /* Print out test information banner.  */
101     printf("NetX Test:   IGMP Basic Operation Test.................................");
102 
103     /* Check for earlier error.  */
104     if (error_counter)
105     {
106 
107         printf("ERROR!\n");
108         test_control_return(1);
109     }
110 
111     /* Perform 7 IGMP join operations.  */
112     status =   nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,1));
113     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,2));
114     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,3));
115     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,4));
116     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,5));
117     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,6));
118     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,7));
119 
120     /* Join one group another 4 times to test the counting operation.  */
121     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,4));
122     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,4));
123     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,4));
124     status +=  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,4));
125 
126     /* Determine if there is an error.  */
127     if (status)
128     {
129 
130         printf("ERROR!\n");
131         test_control_return(1);
132     }
133 
134     /* Call the IGMP information get routine to see if all the groups are there.  */
135     status =  nx_igmp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL);
136 
137     /* Check for status.  */
138     if (status)
139     {
140 
141         printf("ERROR!\n");
142         test_control_return(1);
143     }
144 
145     status =  nx_igmp_info_get(&ip_0, &igmp_reports_sent, &igmp_queries_received, &igmp_checksum_errors, &current_groups_joined);
146 
147     /* Check for status.  */
148     if ((status) || (igmp_reports_sent) || (igmp_queries_received) || (igmp_checksum_errors) || (current_groups_joined != 7))
149     {
150 
151         printf("ERROR!\n");
152         test_control_return(1);
153     }
154 
155     /* Wait for the periodic event to test igmp_periodic_processing. */
156     tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);
157 
158     /* Attempt to join a new group. This should result in an error.  */
159     status =  nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,8));
160 
161     /* Determine if an error has occurred.  */
162     if (status != NX_NO_MORE_ENTRIES)
163     {
164 
165         printf("ERROR!\n");
166         test_control_return(1);
167     }
168 
169     /* Now leave all the groups to make sure that processing works properly.  */
170     status =   nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,1));
171     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,2));
172     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,3));
173     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,4));
174     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,5));
175     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,6));
176     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,7));
177     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,4));
178     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,4));
179     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,4));
180     status +=  nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,4));
181 
182     /* Determine if there is an error.  */
183     if (status)
184     {
185 
186         printf("ERROR!\n");
187         test_control_return(1);
188     }
189 
190     /* Call the IGMP information get routine to see if all the groups are there.  */
191     status =  nx_igmp_info_get(&ip_0, &igmp_reports_sent, &igmp_queries_received, &igmp_checksum_errors, &current_groups_joined);
192 
193     /* Check for status.  */
194     if ((status) || (igmp_queries_received) || (igmp_checksum_errors) || (current_groups_joined))
195     {
196 
197         printf("ERROR!\n");
198         test_control_return(1);
199     }
200     else
201     {
202 
203         printf("SUCCESS!\n");
204         test_control_return(0);
205     }
206 }
207 #else
208 #ifdef CTEST
test_application_define(void * first_unused_memory)209 VOID test_application_define(void *first_unused_memory)
210 #else
211 void    netx_igmp_basic_test_application_define(void *first_unused_memory)
212 #endif
213 {
214 
215     printf("NetX Test:   IGMP Basic Operation Test.................................N/A\n");
216     test_control_return(3);
217 
218 }
219 #endif /* NX_DISABLE_IGMP_INFO */
220