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
|
/***************************************************************************/
/* 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 */
/***************************************************************************/
#include "tx_api.h"
#include "nx_api.h"
#include "netxtestcontrol.h"
extern void test_control_return(UINT);
#if !defined(NX_DISABLE_IPV4) && defined(__PRODUCT_NETXDUO__) && !defined(NX_DISABLE_PACKET_CHAIN)
#include "nx_rtp_sender.h"
#define DEMO_STACK_SIZE 4096
#define NUM_PACKETS 10
#define PACKET_SIZE 1536
#define PACKET_POOL_SIZE (NUM_PACKETS * (PACKET_SIZE + sizeof(NX_PACKET)))
#define RTP_SERVER_ADDRESS IP_ADDRESS(1,2,3,4)
#define RTP_CLIENT_ADDRESS IP_ADDRESS(1,2,3,5)
#define RTP_CLIENT_RTP_PORT 6002
#define RTP_CLIENT_RTCP_PORT 6003
#define RTP_PAYLOAD_TYPE 96
#define CNAME "[email protected]"
/* Define test data. */
#define TEST_TIMESTAMP 1234
#define TEST_MSW 123
#define TEST_LSW 456
static UCHAR test_rtp_packet_data[] = "test rtp packet data";
/* Define the ThreadX object control blocks... */
static TX_THREAD ntest_0;
static TX_THREAD ntest_1;
static NX_PACKET_POOL pool_0;
static NX_IP ip_0;
static NX_IP ip_1;
static NX_UDP_SOCKET rtp_client_socket;
static TX_SEMAPHORE semaphore_test_0_done;
static TX_SEMAPHORE semaphore_test_1_done;
/* Define rtp sender control block. */
static NX_RTP_SENDER rtp_0;
static NX_RTP_SESSION rtp_session_0;
static UINT rtp_port;
static UINT rtcp_port;
/* Define thread prototypes. */
static void ntest_0_entry(ULONG thread_input);
static void ntest_1_entry(ULONG thread_input);
extern void _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
extern void test_control_return(UINT status);
#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void netx_rtp_basic_test_application_define(void *first_unused_memory)
#endif
{
CHAR *pointer;
UINT status;
/* Print out test information banner. */
printf("NetX Test: RTP Basic Test............................................");
/* Setup the working pointer. */
pointer = (CHAR *)first_unused_memory;
/* Create the server thread. */
tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,
pointer, DEMO_STACK_SIZE,
4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
pointer = pointer + DEMO_STACK_SIZE;
/* Create the client thread. */
tx_thread_create(&ntest_1, "thread 1", ntest_1_entry, 0,
pointer, DEMO_STACK_SIZE,
3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
pointer = pointer + DEMO_STACK_SIZE;
/* Initialize the NetX system. */
nx_system_initialize();
/* Create a packet pool. */
status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", PACKET_SIZE, pointer, PACKET_POOL_SIZE);
pointer = pointer + PACKET_POOL_SIZE;
CHECK_STATUS(0, status);
/* Create server IP instance. */
status = nx_ip_create(&ip_0, "NetX IP Instance 0", RTP_SERVER_ADDRESS, 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
pointer, 2048, 1);
pointer = pointer + 2048;
CHECK_STATUS(0, status);
/* Create client IP instance. */
status = nx_ip_create(&ip_1, "NetX IP Instance 1", RTP_CLIENT_ADDRESS, 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
pointer, 2048, 1);
pointer = pointer + 2048;
CHECK_STATUS(0, status);
/* Enable ARP and supply ARP cache memory for IP Instance 0. */
status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
pointer = pointer + 1024;
CHECK_STATUS(0, status);
/* Enable ARP and supply ARP cache memory for IP Instance 1. */
status = nx_arp_enable(&ip_1, (void *) pointer, 1024);
pointer = pointer + 1024;
CHECK_STATUS(0, status);
/* Enable UDP processing for both IP instances. */
status = nx_udp_enable(&ip_0);
CHECK_STATUS(0, status);
status = nx_udp_enable(&ip_1);
CHECK_STATUS(0, status);
/* Create semaphores for test done notification */
tx_semaphore_create(&semaphore_test_0_done, "semaphore test 0", 0);
tx_semaphore_create(&semaphore_test_1_done, "semaphore test 1", 0);
}
/* Define server threads. */
static void ntest_0_entry(ULONG thread_input)
{
UINT status;
NXD_ADDRESS client_ip_address;
NX_PACKET *send_packet;
UINT time_start;
/* Create RTP sender. */
status = nx_rtp_sender_create(&rtp_0, &ip_0, &pool_0, CNAME, sizeof(CNAME) - 1);
CHECK_STATUS(0, status);
/* Get the udp port pair for rtp and rtcp */
status = nx_rtp_sender_port_get(&rtp_0, &rtp_port, &rtcp_port);
CHECK_STATUS(0, status);
/* Setup rtp sender session. */
client_ip_address.nxd_ip_version = NX_IP_VERSION_V4;
client_ip_address.nxd_ip_address.v4 = RTP_CLIENT_ADDRESS;
status = nx_rtp_sender_session_create(&rtp_0, &rtp_session_0, RTP_PAYLOAD_TYPE,
0, &client_ip_address,
RTP_CLIENT_RTP_PORT, RTP_CLIENT_RTCP_PORT);
CHECK_STATUS(0, status);
/* If more than one rtp packet is sent during the first tick, rtcp packet will also be sent more than once.
To make a stable test result, wait for a tick here to avoid this situation. */
tx_thread_sleep(1);
/* Allocate a packet */
status = nx_rtp_sender_session_packet_allocate(&rtp_session_0, &send_packet, 5 * NX_IP_PERIODIC_RATE);
CHECK_STATUS(0, status);
/* Copy payload data into the packet. */
status = nx_packet_data_append(send_packet, (void*)test_rtp_packet_data, sizeof(test_rtp_packet_data), rtp_0.nx_rtp_sender_ip_ptr->nx_ip_default_packet_pool, 5 * NX_IP_PERIODIC_RATE);
CHECK_STATUS(0, status);
status = nx_rtp_sender_session_packet_send(&rtp_session_0, send_packet, TEST_TIMESTAMP, TEST_MSW, TEST_LSW, 1);
CHECK_STATUS(0, status);
/* Wait for the check in test thread 1 done. */
status = tx_semaphore_get(&semaphore_test_1_done, 5 * NX_IP_PERIODIC_RATE);
CHECK_STATUS(0, status);
/* Delete and release resources */
status = nx_rtp_sender_session_delete(&rtp_session_0);
CHECK_STATUS(0, status);
status = nx_rtp_sender_delete(&rtp_0);
CHECK_STATUS(0, status);
/* Put the semaphore to notify thread 1 it is fine to check resource leakage. */
tx_semaphore_put(&semaphore_test_0_done);
}
/* Define the client threads. */
static void ntest_1_entry(ULONG thread_input)
{
NX_PACKET *received_packet;
UINT status;
UCHAR *data;
/* Create the rtp client socket. */
status = nx_udp_socket_create(&ip_1, &rtp_client_socket, "RTCP Client Socket", NX_IP_NORMAL, NX_FRAGMENT_OKAY, 0x80, 5);
CHECK_STATUS(0, status);
status = nx_udp_socket_bind(&rtp_client_socket, RTP_CLIENT_RTP_PORT, NX_IP_PERIODIC_RATE);
CHECK_STATUS(0, status);
/* Receive rtp data packet. */
status = nx_udp_socket_receive(&rtp_client_socket, &received_packet, 5 * TX_TIMER_TICKS_PER_SECOND);
CHECK_STATUS(0, status);
/* Validate RTP payload data */
data = received_packet -> nx_packet_prepend_ptr;
/* Check RTP version byte */
CHECK_STATUS(0x80, *data);
/* Move to check RTP data byte for payload type with marker */
data++;
CHECK_STATUS((0x80 | RTP_PAYLOAD_TYPE), *data);
/* Move to check RTP data bytes for sequence number */
data++;
CHECK_STATUS((rtp_session_0.nx_rtp_session_sequence_number - 1), (data[0] << 8 | data[1]));
/* Move to check RTP data bytes for time stamp */
data += 2;
CHECK_STATUS(rtp_session_0.nx_rtp_session_rtp_timestamp, (ULONG)(data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]));
/* Move to check RTP data bytes for ssrc */
data += 4;
CHECK_STATUS(rtp_session_0.nx_rtp_session_ssrc, (ULONG)(data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]));
/* Move to check RTP data bytes for data payload */
data += 4;
for (UINT i = 0; i < sizeof(test_rtp_packet_data); i++)
{
CHECK_STATUS(*(test_rtp_packet_data + i), data[i]);
}
/* Release the receive packet when the check finishes. */
nx_packet_release(received_packet);
/* Set the flag to notify test thread 0 that the check finishes. */
tx_semaphore_put(&semaphore_test_1_done);
/* Wait for the check in test thread 0 done. */
status = tx_semaphore_get(&semaphore_test_0_done, 5 * NX_IP_PERIODIC_RATE);
CHECK_STATUS(0, status);
/* Check if there is memory leak. */
CHECK_STATUS(pool_0.nx_packet_pool_total, pool_0.nx_packet_pool_available);
/* Return the test result. */
printf("SUCCESS!\n");
test_control_return(0);
}
#else
#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void netx_rtp_basic_test_application_define(void *first_unused_memory)
#endif
{
/* Print out test information banner. */
printf("NetX Test: RTP Basic Test............................................N/A\n");
test_control_return(3);
}
#endif
|