1 /* This test case validates nxd_ipv6_address_set. */
2
3 #include "tx_api.h"
4 #include "nx_api.h"
5 extern void test_control_return(UINT status);
6 #if defined(__PRODUCT_NETXDUO__) && defined(FEATURE_NX_IPV6)
7 #include "nx_tcp.h"
8 #include "nx_ip.h"
9 #include "nx_ipv6.h"
10
11
12 #define DEMO_STACK_SIZE 2048
13 #define TEST_INTERFACE 0
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
22
23 /* Define the counters used in the demo application... */
24
25 static ULONG error_counter;
26 static ULONG notify_counter;
27
28 static NXD_ADDRESS if0_ga0;
29 static NXD_ADDRESS if0_ga1;
30
31 #define PRIMARY_INTERFACE 0
32
33 /* Define thread prototypes. */
34 static void thread_0_entry(ULONG thread_input);
35
36 extern void _nx_ram_network_driver_1500(struct NX_IP_DRIVER_STRUCT *driver_req);
37 #ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
38 static void my_ipv6_addrress_change_notify(NX_IP *ip_tr, UINT type, UINT interface_index, UINT addr_index, ULONG *addr_ptr);
39 #endif
40
41 /* Define what the initial system looks like. */
42
43 #ifdef CTEST
test_application_define(void * first_unused_memory)44 VOID test_application_define(void *first_unused_memory)
45 #else
46 void netx_ipv6_address_get_test_application_define(void *first_unused_memory)
47 #endif
48 {
49 CHAR *pointer;
50 UINT status;
51
52 /* Setup the working pointer. */
53 pointer = (CHAR *) first_unused_memory;
54
55 error_counter = 0;
56 notify_counter = 0;
57
58 /* Create the main thread. */
59 tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
60 pointer, DEMO_STACK_SIZE,
61 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
62
63 pointer = pointer + DEMO_STACK_SIZE;
64
65 /* Initialize the NetX system. */
66 nx_system_initialize();
67
68 /* Create a packet pool. */
69 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 1536, pointer, 1536*16);
70 pointer = pointer + 1536*16;
71
72 if(status)
73 error_counter++;
74
75 /* Create an IP instance. */
76 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1,2,3,4), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_1500,
77 pointer, 2048, 1);
78 pointer = pointer + 2048;
79
80
81 /* Set up IF0 GA0 */
82 if0_ga0.nxd_ip_version = NX_IP_VERSION_V6;
83 if0_ga0.nxd_ip_address.v6[0] = 0x20010000;
84 if0_ga0.nxd_ip_address.v6[1] = 0x00000000;
85 if0_ga0.nxd_ip_address.v6[2] = 0x00000000;
86 if0_ga0.nxd_ip_address.v6[3] = 0x00010001;
87
88 /* Set up IF0 GA1 */
89 if0_ga1.nxd_ip_version = NX_IP_VERSION_V6;
90 if0_ga1.nxd_ip_address.v6[0] = 0x20010000;
91 if0_ga1.nxd_ip_address.v6[1] = 0x00000000;
92 if0_ga1.nxd_ip_address.v6[2] = 0x00000000;
93 if0_ga1.nxd_ip_address.v6[3] = 0x00010002;
94
95 /* Enable IPv6 */
96 status = nxd_ipv6_enable(&ip_0);
97 if(status != NX_SUCCESS)
98 error_counter++;
99
100 status = nxd_icmp_enable(&ip_0);
101 if(status != NX_SUCCESS)
102 error_counter++;
103
104 }
105
106 /* Define the test threads. */
107
thread_0_entry(ULONG thread_input)108 static void thread_0_entry(ULONG thread_input)
109 {
110 UINT status;
111
112 ULONG prefix_length;
113 UINT interface_index;
114 NXD_ADDRESS ipv6_addr;
115
116 /* Print out test information banner. */
117 printf("NetX Test: IPv6 Address Get Test.....................................");
118
119 /* Check for earlier error. */
120 if(error_counter)
121 {
122 printf("ERROR!\n");
123 test_control_return(1);
124 }
125
126 #ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
127 status = nxd_ipv6_address_change_notify(&ip_0, my_ipv6_addrress_change_notify);
128 if(status != NX_SUCCESS)
129 {
130 printf("ERROR!\n");
131 test_control_return(1);
132 }
133 #endif
134
135 /* Set Global address0 on the 1st interface. */
136 status = nxd_ipv6_address_set(&ip_0, PRIMARY_INTERFACE, &if0_ga0, 64, NX_NULL);
137 if(status != NX_SUCCESS)
138 {
139 printf("ERROR!\n");
140 test_control_return(1);
141 }
142
143 /* Set Global address1 on the 1st interface. */
144 status = nxd_ipv6_address_set(&ip_0, PRIMARY_INTERFACE, &if0_ga1, 64, NX_NULL);
145 if(status != NX_SUCCESS)
146 {
147 printf("ERROR!\n");
148 test_control_return(1);
149 }
150
151 /* DAD */
152 tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);
153
154 status = nxd_ipv6_address_get(&ip_0, 0, &ipv6_addr, &prefix_length, &interface_index);
155 if(status != NX_SUCCESS)
156 {
157 printf("ERROR!\n");
158 test_control_return(1);
159 }
160
161 if((ipv6_addr.nxd_ip_version != NX_IP_VERSION_V6) ||
162 (ipv6_addr.nxd_ip_address.v6[0] != 0x20010000) ||
163 (ipv6_addr.nxd_ip_address.v6[1] != 0x0) ||
164 (ipv6_addr.nxd_ip_address.v6[2] != 0x0) ||
165 (ipv6_addr.nxd_ip_address.v6[3] != 0x00010001))
166 {
167 printf("ERROR!\n");
168 test_control_return(1);
169 }
170
171 status = nxd_ipv6_address_get(&ip_0, 1, &ipv6_addr, &prefix_length, &interface_index);
172 if(status != NX_SUCCESS)
173 {
174 printf("ERROR!\n");
175 test_control_return(1);
176 }
177
178 if((ipv6_addr.nxd_ip_version != NX_IP_VERSION_V6) ||
179 (ipv6_addr.nxd_ip_address.v6[0] != 0x20010000) ||
180 (ipv6_addr.nxd_ip_address.v6[1] != 0x0) ||
181 (ipv6_addr.nxd_ip_address.v6[2] != 0x0) ||
182 (ipv6_addr.nxd_ip_address.v6[3] != 0x00010002))
183 {
184 printf("ERROR!\n");
185 test_control_return(1);
186 }
187
188 status = nxd_ipv6_address_get(&ip_0, 2, &ipv6_addr, &prefix_length, &interface_index);
189 if(status != NX_NO_INTERFACE_ADDRESS)
190 {
191 printf("ERROR!\n");
192 test_control_return(1);
193 }
194
195 /* Disable IPv6 */
196 status = nxd_ipv6_disable(&ip_0);
197
198 /* notify counter should be 4, ipv6_address_set (ip_0, ip_1), DAD (ip_0, ip_1) calls. */
199 if((status != NX_SUCCESS)
200 #ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
201 || (notify_counter != 4)
202 #endif
203 )
204 {
205 printf("ERROR!\n");
206 test_control_return(1);
207
208 }
209
210 printf("SUCCESS!\n");
211 test_control_return(0);
212
213 }
214
215 #ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
my_ipv6_addrress_change_notify(NX_IP * ip_tr,UINT type,UINT interface_index,UINT addr_index,ULONG * addr_ptr)216 static void my_ipv6_addrress_change_notify(NX_IP *ip_tr, UINT type, UINT interface_index, UINT addr_index, ULONG *addr_ptr)
217 {
218 notify_counter++;
219 }
220 #endif
221
222 #else
223
224 #ifdef CTEST
test_application_define(void * first_unused_memory)225 VOID test_application_define(void *first_unused_memory)
226 #else
227 void netx_ipv6_address_get_test_application_define(void *first_unused_memory)
228 #endif
229 {
230
231 /* Print out test information banner. */
232 printf("NetX Test: IPv6 Address Get Test.....................................N/A\n");
233
234 test_control_return(3);
235
236 }
237 #endif
238