1 #include "tx_api.h"
2 #include "nx_api.h"
3
4 extern void test_control_return(UINT status);
5 #if defined __PRODUCT_NETXDUO__ && !defined NX_DISABLE_IPV4
6 #include "nxd_mdns.h"
7
8 #define DEMO_STACK_SIZE 2048
9 #define BUFFER_SIZE 10240
10
11 /* Define the ThreadX and NetX object control blocks... */
12
13 static TX_THREAD ntest_0;
14
15 static NX_PACKET_POOL pool_0;
16 static NX_IP ip_0;
17
18 /* Define the NetX MDNS object control blocks. */
19
20 static NX_MDNS mdns_0;
21 static UCHAR buffer[BUFFER_SIZE];
22 static ULONG current_buffer_size;
23
24 /* Define the counters used in the test application... */
25
26 static ULONG error_counter;
27 static CHAR *pointer;
28
29 /* Define thread prototypes. */
30
31 static void ntest_0_entry(ULONG thread_input);
32 extern VOID _nx_ram_network_driver(NX_IP_DRIVER *driver_req_ptr);
33
34 /* Define what the initial system looks like. */
35
36 #ifdef CTEST
test_application_define(void * first_unused_memory)37 VOID test_application_define(void *first_unused_memory)
38 #else
39 void netx_mdns_buffer_size_test(void *first_unused_memory)
40 #endif
41 {
42 UINT status;
43
44 /* Setup the working pointer. */
45 pointer = (CHAR *) first_unused_memory;
46 error_counter = 0;
47
48 /* Initialize the NetX system. */
49 nx_system_initialize();
50
51 /* Create a packet pool. */
52 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
53 pointer = pointer + 8192;
54
55 if(status)
56 error_counter++;
57
58 /* Create an IP instance. */
59 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0,
60 _nx_ram_network_driver, pointer, 2048, 1);
61 pointer = pointer + 2048;
62
63 if(status)
64 error_counter++;
65
66 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
67 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
68 pointer = pointer + 1024;
69 if(status)
70 error_counter++;
71
72 /* Enable TCP processing for both IP instances. */
73 status = nx_tcp_enable(&ip_0);
74
75 /* Check TCP enable status. */
76 if(status)
77 error_counter++;
78
79 /* Enable UDP processing for both IP instances. */
80 status = nx_udp_enable(&ip_0);
81
82 /* Check UDP enable status. */
83 if(status)
84 error_counter++;
85
86 status = nx_igmp_enable(&ip_0);
87
88 /* Check status. */
89 if(status)
90 error_counter++;
91
92 /* Create the test thread. */
93 tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, (ULONG)(pointer + DEMO_STACK_SIZE),
94 pointer, DEMO_STACK_SIZE,
95 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
96 }
97
98 /* Define the test threads. */
99
ntest_0_entry(ULONG thread_input)100 static void ntest_0_entry(ULONG thread_input)
101 {
102 UINT status;
103 ULONG actual_status;
104 CHAR *pointer = (CHAR*)thread_input;
105 NX_MDNS_RR *rr;
106
107 printf("NetX Test: MDNS Buffer Size Test.....................................");
108
109 /* Ensure the IP instance has been initialized. */
110 status = nx_ip_status_check(&ip_0, NX_IP_INITIALIZE_DONE, &actual_status, 100);
111
112 /* Check status. */
113 if(status != NX_SUCCESS)
114 {
115 printf("ERROR!\n");
116 test_control_return(1);
117 }
118
119 for(current_buffer_size = 8; current_buffer_size < 1000; current_buffer_size += 60)
120 {
121
122 /* Create */
123 nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, "NETX-MDNS",
124 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, NX_NULL);
125
126 #ifndef NX_MDNS_DISABLE_SERVER
127 /* Use local buffer. */
128 nx_mdns_service_add(&mdns_0, (CHAR *)"ARMMDNSTest", (CHAR *)"_ipp._tcp", NX_NULL, NX_NULL, 100, 0, 0, 80, NX_MDNS_RR_SET_UNIQUE, 0);
129 #endif /* NX_MDNS_DISABLE_SERVER */
130
131 #ifndef NX_MDNS_DISABLE_CLIENT
132 /* Use remote buffer. */
133 nx_mdns_service_continuous_query(&mdns_0, "_printer", "_tcp.local", NX_NULL);
134
135 /* Wait two seconds for probing and announcement. */
136 tx_thread_sleep(200);
137
138 /* Delete the query. */
139 nx_mdns_service_query_stop(&mdns_0, "_printer", "_tcp.local", NX_NULL);
140 #endif /* NX_MDNS_DISABLE_CLIENT */
141
142 #ifndef NX_MDNS_DISABLE_SERVER
143 nx_mdns_service_delete(&mdns_0, (CHAR *)"ARMMDNSTest", (CHAR *)"_ipp._tcp", NX_NULL);
144 #endif /* NX_MDNS_DISABLE_SERVER */
145
146 /* Delete the mDNS. */
147 nx_mdns_delete(&mdns_0);
148
149 /* Wait one second for goodbye packets sent. */
150 tx_thread_sleep(100);
151 }
152
153 /* Determine if the test was successful. */
154 if(error_counter)
155 {
156 printf("ERROR!\n");
157 test_control_return(1);
158 }
159 else
160 {
161 printf("SUCCESS!\n");
162 test_control_return(0);
163 }
164 }
165 #else
166
167 #ifdef CTEST
test_application_define(void * first_unused_memory)168 VOID test_application_define(void *first_unused_memory)
169 #else
170 void netx_mdns_buffer_size_test(void *first_unused_memory)
171 #endif
172 {
173 printf("NetX Test: MDNS Buffer Size Test.....................................N/A\n");
174 test_control_return(3);
175 }
176 #endif
177