1 /* This case test if the gateway has been cleared after interface detachment. */
2 
3 #include   "nx_api.h"
4 #include   "nx_ram_network_driver_test_1500.h"
5 extern void    test_control_return(UINT status);
6 #if defined(__PRODUCT_NETXDUO__) && (NX_MAX_PHYSICAL_INTERFACES > 1) && !defined(NX_DISABLE_IPV4)
7 #define     DEMO_STACK_SIZE         2048
8 
9 /* Define the ThreadX and NetX object control blocks...  */
10 
11 static TX_THREAD               ntest_0;
12 static NX_PACKET_POOL          pool_0;
13 static NX_IP                   ip_0;
14 
15 /* Define the counters used in the test application...  */
16 
17 static ULONG                   error_counter;
18 
19 /* Define thread prototypes.  */
20 
21 static void    ntest_0_entry(ULONG thread_input);
22 extern void    _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
23 
24 /* Define what the initial system looks like.  */
25 
26 #ifdef CTEST
test_application_define(void * first_unused_memory)27 VOID test_application_define(void *first_unused_memory)
28 #else
29 void    netx_ip_interface_detachment_gateway_test_application_define(void *first_unused_memory)
30 #endif
31 {
32 
33 CHAR    *pointer;
34 UINT    status;
35 
36     /* Setup the working pointer.  */
37     pointer =  (CHAR *) first_unused_memory;
38 
39     error_counter    = 0;
40 
41     /* Create the main threads.  */
42     tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,
43             pointer, DEMO_STACK_SIZE,
44             3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
45     pointer =  pointer + DEMO_STACK_SIZE;
46 
47     /* Initialize the NetX system.  */
48     nx_system_initialize();
49 
50     /* Create a packet pool.  */
51     status =  nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
52     pointer = pointer + 8192;
53 
54     if (status)
55         error_counter++;
56 
57     /* Create an IP instance.  */
58     status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
59             pointer, 2048, 1);
60     pointer =  pointer + 2048;
61 
62     /* Attach the 2nd interface to IP instance0 */
63     status = nx_ip_interface_attach(&ip_0, "2nd interface", IP_ADDRESS(4, 3, 2, 10), 0xFF000000, _nx_ram_network_driver);
64     if(status != NX_SUCCESS)
65         error_counter++;
66 }
67 
68 
69 
70 /* Define the test threads.  */
71 
ntest_0_entry(ULONG thread_input)72 static void    ntest_0_entry(ULONG thread_input)
73 {
74 UINT    status;
75 ULONG   actual_status;
76 ULONG   gateway_address;
77 
78     printf("NetX Test:   IP Interface Detachment Gateway Test......................");
79 
80     /* Check earlier error. */
81     if(error_counter)
82     {
83         printf("ERROR!\n");
84         test_control_return(1);
85     }
86 
87     /* Ensure the IP instance has been initialized.  */
88     status = nx_ip_status_check(&ip_0, NX_IP_INITIALIZE_DONE, &actual_status, NX_IP_PERIODIC_RATE);
89     if(status)
90         error_counter++;
91 
92     /* Set gateway address. */
93     status = nx_ip_gateway_address_set(&ip_0, IP_ADDRESS(1, 2, 3, 1));
94     if(status)
95         error_counter++;
96 
97     /* Get gateway address. */
98     status = nx_ip_gateway_address_get(&ip_0, &gateway_address);
99     if((status) || (gateway_address != IP_ADDRESS(1, 2, 3, 1)))
100         error_counter++;
101 
102     /* Detach the interface from ip_0. */
103     status = nx_ip_interface_detach(&ip_0, 0);
104     if(status)
105         error_counter++;
106 
107     /* Get gateway address. */
108     status = nx_ip_gateway_address_get(&ip_0, &gateway_address);
109     if(status == NX_SUCCESS)
110         error_counter++;
111 
112     if(error_counter)
113     {
114         printf("ERROR!\n");
115         test_control_return(1);
116     }
117     else
118     {
119         printf("SUCCESS!\n");
120         test_control_return(0);
121     }
122 
123 }
124 
125 #else
126 #ifdef CTEST
test_application_define(void * first_unused_memory)127 VOID test_application_define(void *first_unused_memory)
128 #else
129 void    netx_ip_interface_detachment_gateway_test_application_define(void *first_unused_memory)
130 #endif
131 {
132     printf("NetX Test:   IP Interface Detachment Gateway Test......................N/A\n");
133     test_control_return(3);
134 
135 }
136 #endif
137