summaryrefslogtreecommitdiff
path: root/test/regression/dhcp_test/netx_dhcpv6_server_process_repeated_msgs_test.c
blob: d5b37f43b975c88972ec8b618d3d72071907927f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

/* This is a small demo of the NetX Duo DHCPv6 Client and Server for the high-performance
   NetX Duo stack.  */

#include    <stdio.h>
#include   "tx_api.h"
#include   "nx_api.h"
#include   "nx_ip.h"
#include   "nx_udp.h"
extern void test_control_return(UINT status);

#if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_FRAGMENTATION)
#include   "nx_ipv6.h"
#include   "nxd_dhcpv6_client.h"
#include   "nxd_dhcpv6_server.h"

#define     DEMO_STACK_SIZE                     2048
#define     NX_DHCPV6_THREAD_STACK_SIZE         2048
#define     NX_PACKET_SIZE                      1536
#define     NX_PACKET_POOL_SIZE                 (NX_PACKET_SIZE * 8)

/* Define the ThreadX and NetX object control blocks...  */

static NX_PACKET_POOL          pool_0;
static TX_THREAD               thread_client;
static TX_THREAD               thread_server;
static NX_IP                   client_ip;
static NX_IP                   server_ip;

/* Define the Client and Server instances. */

static NX_DHCPV6               dhcp_client;
static NX_DHCPV6_SERVER        dhcp_server;

/* Define the error counter used in the demo application...  */
static ULONG                   error_counter;
static CHAR                    *pointer;
static UCHAR                   advertise_message_count = 0;
static UCHAR                   reply_message_count = 0;

static NXD_ADDRESS             server_address;
static NXD_ADDRESS             dns_ipv6_address;
static NXD_ADDRESS             start_ipv6_address;
static NXD_ADDRESS             end_ipv6_address;

static UCHAR                   client_xid[3] = {0, 0, 0};
static UCHAR                   server_xid[3] = {0, 0, 0};


/* Define thread prototypes.  */

static void    thread_client_entry(ULONG thread_input);
static void    thread_server_entry(ULONG thread_input);

/******** Optionally substitute your Ethernet driver here. ***********/

extern void    _nx_ram_network_driver_1024(struct NX_IP_DRIVER_STRUCT *driver_req);
extern UINT    (*advanced_packet_process_callback)(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr);
static UINT    my_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr);


/* Define some DHCPv6 parameters.  */

#define DHCPV6_IANA_ID                  0xC0DEDBAD
#define DHCPV6_T1                       NX_DHCPV6_INFINITE_LEASE
#define DHCPV6_T2                       NX_DHCPV6_INFINITE_LEASE
#define NX_DHCPV6_REFERRED_LIFETIME     NX_DHCPV6_INFINITE_LEASE
#define NX_DHCPV6_VALID_LIFETIME        NX_DHCPV6_INFINITE_LEASE

/* Define the cycle times for repeating the test. */
#define TEST_REPEATING_CYCLE            2

/* Define what the initial system looks like.  */

#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void    netx_dhcpv6_server_process_repeated_msg_test_application_define(void *first_unused_memory)
#endif
{

UINT    status;

    /* Setup the working pointer.  */
    pointer =  (CHAR *) first_unused_memory;

    /* Initialize the NetX system.  */
    nx_system_initialize();

    /* Create the Client thread.  */
    status = tx_thread_create(&thread_client, "Client thread", thread_client_entry, 0,
                              pointer, DEMO_STACK_SIZE,
                              4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);

    pointer =  pointer + DEMO_STACK_SIZE;

    /* Check for IP create errors.  */
    if (status)
    {
        error_counter++;
    }

    /* Create the Server thread.  */
    status = tx_thread_create(&thread_server, "Server thread", thread_server_entry, 0,
                              pointer, DEMO_STACK_SIZE,
                              3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
    pointer =  pointer + DEMO_STACK_SIZE;

    /* Check for IP create errors.  */
    if (status)
    {
        error_counter++;
    }

    /* Create a packet pool.  */
    status =  nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 1024, pointer, NX_PACKET_POOL_SIZE);
    pointer = pointer + NX_PACKET_POOL_SIZE;

    /* Check for pool creation error.  */
    if (status)
        error_counter++;

    /* Create a Client IP instance.  */
    status = nx_ip_create(&client_ip, "Client IP", IP_ADDRESS(0, 0, 0, 0),
                          0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_1024,
                          pointer, 2048, 1);

    pointer =  pointer + 2048;

    /* Check for IP create errors.  */
    if (status)
    {
        error_counter++;
    }

    /* Create a Server IP instance.  */
    status = nx_ip_create(&server_ip, "Server IP", IP_ADDRESS(1, 2, 3, 4),
                          0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_1024,
                          pointer, 2048, 1);

    pointer =  pointer + 2048;

    /* Check for IP create errors.  */
    if (status)
    {
        error_counter++;
    }

    /* Enable UDP traffic for sending DHCPv6 messages.  */
    status =  nx_udp_enable(&client_ip);
    status +=  nx_udp_enable(&server_ip);

    /* Check for UDP enable errors.  */
    if (status)
    {
        error_counter++;
    }

    /* Enable the IPv6 services. */
    status = nxd_ipv6_enable(&client_ip);
    status += nxd_ipv6_enable(&server_ip);

    /* Check for IPv6 enable errors.  */
    if (status)
    {
        error_counter++;
    }

    /* Enable the ICMPv6 services. */
    status = nxd_icmp_enable(&client_ip);
    status += nxd_icmp_enable(&server_ip);

    /* Check for ICMP enable errors.  */
    if (status)
    {
        error_counter++;
    }

    /* Enable the fragment feature.  */
    status = nx_ip_fragment_enable(&client_ip);
    status += nx_ip_fragment_enable(&server_ip);

    /* Check for ICMP enable errors.  */
    if (status)
    {
        error_counter++;
    }
}

/* Define the Client host application thread. */

void    thread_client_entry(ULONG thread_input)
{

UINT        status;
NXD_ADDRESS ipv6_address;
NXD_ADDRESS dns_address;
ULONG       prefix_length;
UINT        interface_index;
ULONG       T1, T2, preferred_lifetime, valid_lifetime;
UINT        address_count;
UINT        address_index;
NX_PACKET   *my_packet;


    /* Print out test information banner.  */
    printf("NetX Test:   DHCPv6 Server Process Repeated Msg Test.........................................");

    /* Check for earlier error.  */
    if(error_counter)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Establish the link local address for the host. The RAM driver creates
       a virtual MAC address of 0x1122334456. */
    status = nxd_ipv6_address_set(&client_ip, 0, NX_NULL, 10, NULL);

    /* Let NetX Duo and the network driver get initialized. Also give the server time to get set up. */
    tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);

    /* Create the DHCPv6 Client. */
    status =  nx_dhcpv6_client_create(&dhcp_client, &client_ip, "DHCPv6 Client", &pool_0, pointer, NX_DHCPV6_THREAD_STACK_SIZE,
                                      NX_NULL, NX_NULL);
    pointer = pointer + NX_DHCPV6_THREAD_STACK_SIZE;

    /* Check for errors.  */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Create a Link Layer Plus Time DUID for the DHCPv6 Client. Set time ID field
       to NULL; the DHCPv6 Client API will supply one. */
    status = nx_dhcpv6_create_client_duid(&dhcp_client, NX_DHCPV6_DUID_TYPE_LINK_TIME,
                                          NX_DHCPV6_HW_TYPE_IEEE_802, 0);

    /* Check for errors.  */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Create the DHCPv6 client's Identity Association (IA-NA) now.

       Note that if this host had already been assigned in IPv6 lease, it
       would have to use the assigned T1 and T2 values in loading the DHCPv6
       client with an IANA block.
    */
    status = nx_dhcpv6_create_client_iana(&dhcp_client, DHCPV6_IANA_ID, DHCPV6_T1,  DHCPV6_T2);

    /* Check for errors.  */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Starting up the NetX DHCPv6 Client. */
    status =  nx_dhcpv6_start(&dhcp_client);

    /* Check for errors.  */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* If the host also want to get the option message, set the list of desired options to enabled. */
    nx_dhcpv6_request_option_timezone(&dhcp_client, NX_TRUE);
    nx_dhcpv6_request_option_DNS_server(&dhcp_client, NX_TRUE);
    nx_dhcpv6_request_option_time_server(&dhcp_client, NX_TRUE);
    nx_dhcpv6_request_option_domain_name(&dhcp_client, NX_TRUE);

    /* Set the callback function to process the Message packet from DHCPv6 Server.  */
    advanced_packet_process_callback = my_packet_process;

    /* Now, the host send the solicit message to get the IPv6 address and other options from the DHCPv6 server. */
    status = nx_dhcpv6_request_solicit(&dhcp_client);

    /* Check for errors.  */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Waiting for get the IPv6 address and do the duplicate address detection. */
    tx_thread_sleep(6 * NX_IP_PERIODIC_RATE);

    /* Get the valid IPv6 address count which the DHCPv6 server assigned .  */
    status = nx_dhcpv6_get_valid_ip_address_count(&dhcp_client, &address_count);

    /* Check for errors.  */
    if ((status) || (address_count != 1))
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Get the IPv6 address, preferred lifetime and valid lifetime according to the address index. */
    address_index = 0;
    status = nx_dhcpv6_get_valid_ip_address_lease_time(&dhcp_client, address_index, &ipv6_address, &preferred_lifetime, &valid_lifetime);

    /* Check for errors.  */
    if ((status) || (address_count != 1))
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Get the IPv6 address by DHCPv6 API. */
    status = nx_dhcpv6_get_IP_address(&dhcp_client, &ipv6_address);

    /* Check status.  */
    if (status != NX_SUCCESS)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Check the address.  */
    if ((ipv6_address.nxd_ip_version != start_ipv6_address.nxd_ip_version) ||
        (ipv6_address.nxd_ip_address.v6[0] != start_ipv6_address.nxd_ip_address.v6[0]) ||
        (ipv6_address.nxd_ip_address.v6[1] != start_ipv6_address.nxd_ip_address.v6[1]) ||
        (ipv6_address.nxd_ip_address.v6[2] != start_ipv6_address.nxd_ip_address.v6[2]) ||
        (ipv6_address.nxd_ip_address.v6[3] != start_ipv6_address.nxd_ip_address.v6[3]))
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Get the IPv6 address by NetX Duo API. */
    status = nxd_ipv6_address_get(&client_ip, 1, &ipv6_address, &prefix_length, &interface_index);

    /* Check status.  */
    if (status != NX_SUCCESS)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Check the IPv6 address.  */
    if ((prefix_length != 64) || (interface_index != 0) ||
        (ipv6_address.nxd_ip_version != start_ipv6_address.nxd_ip_version) ||
        (ipv6_address.nxd_ip_address.v6[0] != start_ipv6_address.nxd_ip_address.v6[0]) ||
        (ipv6_address.nxd_ip_address.v6[1] != start_ipv6_address.nxd_ip_address.v6[1]) ||
        (ipv6_address.nxd_ip_address.v6[2] != start_ipv6_address.nxd_ip_address.v6[2]) ||
        (ipv6_address.nxd_ip_address.v6[3] != start_ipv6_address.nxd_ip_address.v6[3]))
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Get IP address lease time.
       Note, This API only applies to one IA. */
    status = nx_dhcpv6_get_lease_time_data(&dhcp_client, &T1, &T2, &preferred_lifetime, &valid_lifetime);

    /* Check status.  */
    if (status != NX_SUCCESS)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Check the value.  */
    if ((T1 != NX_DHCPV6_DEFAULT_T1_TIME) ||
        (T2 != NX_DHCPV6_DEFAULT_T2_TIME) ||
        (preferred_lifetime != NX_DHCPV6_DEFAULT_PREFERRED_TIME) ||
        (valid_lifetime != NX_DHCPV6_DEFAULT_VALID_TIME))
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Get the DNS Server address. */
    status = nx_dhcpv6_get_DNS_server_address(&dhcp_client, 0, &dns_address);

    /* Check status.  */
    if (status != NX_SUCCESS)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Check the IPv6 DNS address.  */
    if ((dns_address.nxd_ip_version != dns_ipv6_address.nxd_ip_version) ||
        (dns_address.nxd_ip_address.v6[0] != dns_ipv6_address.nxd_ip_address.v6[0]) ||
        (dns_address.nxd_ip_address.v6[1] != dns_ipv6_address.nxd_ip_address.v6[1]) ||
        (dns_address.nxd_ip_address.v6[2] != dns_ipv6_address.nxd_ip_address.v6[2]) ||
        (dns_address.nxd_ip_address.v6[3] != dns_ipv6_address.nxd_ip_address.v6[3]))
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    for (UINT i = 0; i < TEST_REPEATING_CYCLE; i++)
    {

        /* Now, send the confirm message multiple-times. */
        status = nx_dhcpv6_request_confirm(&dhcp_client);

        /* Check for errors.  */
        if(status)
        {
            printf("ERROR!\n");
            test_control_return(1);
        }

        /* Waiting for get the IPv6 address and do the duplicate address detection. */
        tx_thread_sleep(10 * NX_IP_PERIODIC_RATE);
    }

    /* Check reply message count so far: */
    if (reply_message_count != 3)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Release the address.  */
    status = nx_dhcpv6_request_release(&dhcp_client);

    /* Check status.  */
    if (status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Waiting for release the IPv6 address. */
    tx_thread_sleep(NX_IP_PERIODIC_RATE);

    /* Get the IPv6 address by DHCPv6 API. */
    status = nx_dhcpv6_get_IP_address(&dhcp_client, &ipv6_address);

    /* Check status.  */
    if (status == NX_SUCCESS)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Get the IPv6 address by NetX Duo API. */
    status = nxd_ipv6_address_get(&client_ip, 1, &ipv6_address, &prefix_length, &interface_index);

    /* Check status.  */
    if (status == NX_SUCCESS)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Stop the Client task. */
    status = nx_dhcpv6_stop(&dhcp_client);

    /* Check status.  */
    if (status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Delete the DHCPv6 client. */
    status = nx_dhcpv6_client_delete(&dhcp_client);

    /* Check status.  */
    if (status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Output successfully.  */
    printf("SUCCESS!\n");
    test_control_return(0);
}

/* Define the test server thread. */
void    thread_server_entry(ULONG thread_input)
{

UINT        status;
ULONG       duid_time;
UINT        addresses_added;

    /* Set the IPv6 address of DHCPv6 Server.  */
    server_address.nxd_ip_version = NX_IP_VERSION_V6 ;
    server_address.nxd_ip_address.v6[0] = 0x20010db8;
    server_address.nxd_ip_address.v6[1] = 0xf101;
    server_address.nxd_ip_address.v6[2] = 0x00000000;
    server_address.nxd_ip_address.v6[3] = 0x00000101;

    /* Set the link local and global addresses. */
    status = nxd_ipv6_address_set(&server_ip, 0, NX_NULL, 10, NULL);
    status += nxd_ipv6_address_set(&server_ip, 0, &server_address, 64, NULL);

    /* Check for errors. */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Validate the link local and global addresses. */
    tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);

    /* Create the DHCPv6 Server. */
    status =  nx_dhcpv6_server_create(&dhcp_server, &server_ip, "DHCPv6 Server", &pool_0, pointer, NX_DHCPV6_SERVER_THREAD_STACK_SIZE, NX_NULL, NX_NULL);
    pointer += NX_DHCPV6_SERVER_THREAD_STACK_SIZE;

    /* Check for errors.  */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Set up the DNS IPv6 server address. */
    dns_ipv6_address.nxd_ip_version = NX_IP_VERSION_V6 ;
    dns_ipv6_address.nxd_ip_address.v6[0] = 0x20010db8;
    dns_ipv6_address.nxd_ip_address.v6[1] = 0x0000f101;
    dns_ipv6_address.nxd_ip_address.v6[2] = 0x00000000;
    dns_ipv6_address.nxd_ip_address.v6[3] = 0x00000107;

    status = nx_dhcpv6_create_dns_address(&dhcp_server, &dns_ipv6_address);

    /* Check for errors. */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

     /* Note: For DUID types that do not require time, the 'duid_time' input can be left at zero.
        The DUID_TYPE and HW_TYPE are configurable options that are user defined in nx_dhcpv6_server.h.  */

    /* Set the DUID time as the start of the millenium. */
    duid_time = SECONDS_SINCE_JAN_1_2000_MOD_32;
    status = nx_dhcpv6_set_server_duid(&dhcp_server,
                                    NX_DHCPV6_SERVER_DUID_TYPE, NX_DHCPV6_SERVER_HW_TYPE,
                                    dhcp_server.nx_dhcpv6_ip_ptr -> nx_ip_arp_physical_address_msw,
                                    dhcp_server.nx_dhcpv6_ip_ptr -> nx_ip_arp_physical_address_lsw,
                                    duid_time);

    /* Check for errors. */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Set the IPv6 start address.  */
    start_ipv6_address.nxd_ip_version = NX_IP_VERSION_V6 ;
    start_ipv6_address.nxd_ip_address.v6[0] = 0x20010db8;
    start_ipv6_address.nxd_ip_address.v6[1] = 0x00000f101;
    start_ipv6_address.nxd_ip_address.v6[2] = 0x0;
    start_ipv6_address.nxd_ip_address.v6[3] = 0x00000110;

    /* Set the IPv6 end address.  */
    end_ipv6_address.nxd_ip_version = NX_IP_VERSION_V6 ;
    end_ipv6_address.nxd_ip_address.v6[0] = 0x20010db8;
    end_ipv6_address.nxd_ip_address.v6[1] = 0x0000f101;
    end_ipv6_address.nxd_ip_address.v6[2] = 0x00000000;
    end_ipv6_address.nxd_ip_address.v6[3] = 0x00000120;

    /* Set the IPv6 address range.  */
    status = nx_dhcpv6_create_ip_address_range(&dhcp_server, &start_ipv6_address, &end_ipv6_address, &addresses_added);

    /* Check for errors. */
    if ((status) || (addresses_added != 16))
    {
        printf("ERROR!\n");
        test_control_return(1);
    }

    /* Start the NetX DHCPv6 server!  */
    status =  nx_dhcpv6_server_start(&dhcp_server);

    /* Check for errors. */
    if(status)
    {
        printf("ERROR!\n");
        test_control_return(1);
    }
}

static UINT my_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr)
{

UCHAR message_type;
static UCHAR last_client_message_type;
static UCHAR confirm_msg_cnt = 0;
NX_UDP_HEADER *udp_header_ptr;
NX_IPV6_HEADER *ip_header;
ULONG checksum;
ULONG *ip_src_addr, *ip_dest_addr;


    /* Get the message type.  */
    message_type = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 8);
    switch (message_type)
    {

        case NX_DHCPV6_MESSAGE_TYPE_SOLICIT:
        case NX_DHCPV6_MESSAGE_TYPE_REQUEST:
        case NX_DHCPV6_MESSAGE_TYPE_RELEASE:
        {
            if (ip_ptr != &client_ip)
            {
                return(NX_FALSE);
            }

            /* Store the message type for server reply message to know. */
            last_client_message_type = message_type;

            /* Get the xid. */
            client_xid[0] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 9);
            client_xid[1] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 10);
            client_xid[2] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 11);

            break;
        }

        case NX_DHCPV6_MESSAGE_TYPE_CONFIRM:
        {
            if (ip_ptr != &client_ip)
            {
                return(NX_FALSE);
            }

            /* Store the message type for server reply message to know. */
            last_client_message_type = message_type;

            /* Get the xid. */
            client_xid[0] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 9);
            client_xid[1] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 10);
            client_xid[2] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 11);

            /* Increase the sent confirm msg number, and hack the second msg. */
            confirm_msg_cnt++;
            if (confirm_msg_cnt == 2)
            {

                // /* Get IP address for checksum computing. */
                ip_header = (NX_IPV6_HEADER *)(packet_ptr -> nx_packet_ip_header);
                NX_IPV6_ADDRESS_CHANGE_ENDIAN(ip_header -> nx_ip_header_source_ip);
                NX_IPV6_ADDRESS_CHANGE_ENDIAN(ip_header -> nx_ip_header_destination_ip);
                ip_src_addr  = &(ip_header -> nx_ip_header_source_ip[0]);
                ip_dest_addr = &(ip_header -> nx_ip_header_destination_ip[0]);

                packet_ptr -> nx_packet_prepend_ptr += 40;
                packet_ptr -> nx_packet_length -= 40;

                /* Modify the elapse time. */
                *(packet_ptr -> nx_packet_prepend_ptr + 8 + 26) = 0x01;
                *(packet_ptr -> nx_packet_prepend_ptr + 8 + 27) = 0x02;

                /* Compute the checksum. */
                udp_header_ptr = (NX_UDP_HEADER*)(packet_ptr -> nx_packet_prepend_ptr + 40);
                NX_CHANGE_ULONG_ENDIAN(udp_header_ptr -> nx_udp_header_word_1);
                udp_header_ptr -> nx_udp_header_word_1 = udp_header_ptr -> nx_udp_header_word_1 & 0xFFFF0000;
                NX_CHANGE_ULONG_ENDIAN(udp_header_ptr -> nx_udp_header_word_1);

                /* Yes, we need to compute the UDP checksum.  */
                checksum = _nx_ip_checksum_compute(packet_ptr,
                                                    NX_PROTOCOL_UDP,
                                                    packet_ptr -> nx_packet_length,
                                                    ip_src_addr,
                                                    ip_dest_addr);
                checksum = ~checksum & NX_LOWER_16_MASK;

                /* If the computed checksum is zero, it is transmitted as all ones. */
                /* RFC 768, page 2. */
                if(checksum == 0)
                    checksum = 0xFFFF;

                NX_CHANGE_ULONG_ENDIAN(udp_header_ptr -> nx_udp_header_word_1);
                udp_header_ptr -> nx_udp_header_word_1 = udp_header_ptr -> nx_udp_header_word_1 & 0xFFFF0000;
                udp_header_ptr -> nx_udp_header_word_1 = udp_header_ptr -> nx_udp_header_word_1 | checksum;
                NX_CHANGE_ULONG_ENDIAN(udp_header_ptr -> nx_udp_header_word_1);

                packet_ptr -> nx_packet_prepend_ptr -= 40;
                packet_ptr -> nx_packet_length += 40;

                NX_IPV6_ADDRESS_CHANGE_ENDIAN(ip_header -> nx_ip_header_source_ip);
                NX_IPV6_ADDRESS_CHANGE_ENDIAN(ip_header -> nx_ip_header_destination_ip);
            }
            break;
        }

        /* Check if it is Advertise message from DHCPv6 Server.  */
        case NX_DHCPV6_MESSAGE_TYPE_ADVERTISE:
        {
            if (ip_ptr != &server_ip)
            {
                return(NX_FALSE);
            }

            /* Get the xid. */
            server_xid[0] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 9);
            server_xid[1] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 10);
            server_xid[2] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 11);

            /* Compare the server xid with previous client xid. */
            if (memcmp(client_xid, server_xid, 3))
            {
                return(NX_FALSE);
            }

            /* Yes, add the count for advertise message.  */
            advertise_message_count++;
            break;
        }

        case NX_DHCPV6_MESSAGE_TYPE_REPLY:
        {
            if (ip_ptr != &server_ip)
            {
                return(NX_FALSE);
            }

            /* Get the xid. */
            server_xid[0] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 9);
            server_xid[1] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 10);
            server_xid[2] = *(packet_ptr -> nx_packet_prepend_ptr + 40 + 11);

            /* Compare the server xid with previous client xid. */
            if (memcmp(client_xid, server_xid, 3))
            {
                return(NX_FALSE);
            }

            if (last_client_message_type == NX_DHCPV6_MESSAGE_TYPE_CONFIRM)
            {
                if (confirm_msg_cnt >= 2)
                {
                    if (dhcp_server.nx_dhcpv6_clients[0].nx_dhcpv6_elapsed_time.nx_session_time == 0)
                    {
                        return(NX_FALSE);
                    }
                }
            }

            /* Yes, add the count for next time to send reply message.  */
            reply_message_count++;
            break;
        }

        default:
        {
            break;
        }
    }

    return(NX_TRUE);
}

#else
#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void netx_dhcpv6_server_process_repeated_msg_test_application_define(void * first_unused_memory)
#endif
{
    printf("NetX Test:   DHCPv6 Server Process Repeated Msg Test.........................................N/A\n");
    test_control_return(3);
}
#endif /* FEATURE_NX_IPV6 */