1 #include "tx_api.h"
2 #include "nx_api.h"
3 #include "netxtestcontrol.h"
4
5 extern void test_control_return(UINT);
6
7 #if !defined(NX_DISABLE_IPV4) && defined(__PRODUCT_NETXDUO__) && !defined(NX_DISABLE_PACKET_CHAIN)
8 #include "nx_rtp_sender.h"
9
10 #define DEMO_STACK_SIZE 4096
11
12 #define NUM_PACKETS 24
13 #define PACKET_SIZE 1536
14 #define PACKET_POOL_SIZE (NUM_PACKETS * (PACKET_SIZE + sizeof(NX_PACKET)))
15
16 #define RTP_SERVER_ADDRESS IP_ADDRESS(1,2,3,4)
17 #define RTP_CLIENT_ADDRESS IP_ADDRESS(1,2,3,5)
18 #define RTP_CLIENT_RTP_PORT 6002
19 #define RTP_CLIENT_RTCP_PORT 6003
20 #define RTP_PAYLOAD_TYPE_VIDEO 96
21 #define CNAME "AzureRTOS@microsoft.com"
22
23 /* Define test data. */
24 #define TEST_TIMESTAMP 1234
25 #define TEST_MSW 123
26 #define TEST_LSW 456
27
28 static UCHAR test_rtp_packet_data[] = "test rtp packet data";
29 static UCHAR test_rtcp_packet_data[] = {0x80, 0xc8, 0x0, 0x6, 0x0, 0x0, 0x2c, 0xd6, 0x0, 0x0, 0x0, 0x7b, 0x0, 0x0, 0x1, 0xc8, 0x0, 0x0, 0x4, 0xd2,
30 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x81, 0xca, 0x0, 0x8, 0x0, 0x0, 0x2c, 0xd6, 0x1, 0x17, 0x41, 0x7a, 0x75,
31 0x72, 0x65, 0x52, 0x54, 0x4f, 0x53, 0x40, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x0, 0x0, 0x0};
32
33 /* Define the ThreadX object control blocks... */
34
35 static TX_THREAD ntest_0;
36 static TX_THREAD ntest_1;
37
38 static NX_PACKET_POOL pool_0;
39 static NX_IP ip_0;
40 static NX_IP ip_1;
41 static NX_UDP_SOCKET rtcp_client_socket;
42
43 /* Define rtp sender control block. */
44 static NX_RTP_SENDER rtp_0;
45 static NX_RTP_SESSION rtp_session_0;
46
47 /* Define the counters used in the test application... */
48
49 static TX_SEMAPHORE semaphore_test_done;
50
51 /* Define thread prototypes. */
52
53 static void ntest_0_entry(ULONG thread_input);
54 static void ntest_1_entry(ULONG thread_input);
55 extern void _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
56 extern void test_control_return(UINT status);
57
58 #ifdef CTEST
test_application_define(void * first_unused_memory)59 VOID test_application_define(void *first_unused_memory)
60 #else
61 void netx_rtcp_packet_send_test_application_define(void *first_unused_memory)
62 #endif
63 {
64
65 CHAR *pointer;
66 UINT status;
67
68 /* Print out test information banner. */
69 printf("NetX Test: RTCP Packet Send Test............................................");
70
71 /* Setup the working pointer. */
72 pointer = (CHAR *) first_unused_memory;
73
74 /* Create the server thread. */
75 tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,
76 pointer, DEMO_STACK_SIZE,
77 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
78
79 pointer = pointer + DEMO_STACK_SIZE;
80
81 /* Create the client thread. */
82 tx_thread_create(&ntest_1, "thread 1", ntest_1_entry, 0,
83 pointer, DEMO_STACK_SIZE,
84 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
85
86 pointer = pointer + DEMO_STACK_SIZE;
87
88 /* Initialize the NetX system. */
89 nx_system_initialize();
90
91 /* Create a packet pool. */
92 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", PACKET_SIZE, pointer, PACKET_POOL_SIZE);
93 pointer = pointer + PACKET_POOL_SIZE;
94 CHECK_STATUS(0, status);
95
96 /* Create server IP instance. */
97 status = nx_ip_create(&ip_0, "NetX IP Instance 0", RTP_SERVER_ADDRESS, 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
98 pointer, 2048, 1);
99 pointer = pointer + 2048;
100 CHECK_STATUS(0, status);
101
102 /* Create client IP instance. */
103 status = nx_ip_create(&ip_1, "NetX IP Instance 1", RTP_CLIENT_ADDRESS, 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
104 pointer, 2048, 1);
105 pointer = pointer + 2048;
106 CHECK_STATUS(0, status);
107
108 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
109 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
110 pointer = pointer + 1024;
111 CHECK_STATUS(0, status);
112
113 /* Enable ARP and supply ARP cache memory for IP Instance 1. */
114 status = nx_arp_enable(&ip_1, (void *) pointer, 1024);
115 pointer = pointer + 1024;
116 CHECK_STATUS(0, status);
117
118 /* Enable UDP processing for both IP instances. */
119 status = nx_udp_enable(&ip_0);
120 CHECK_STATUS(0, status);
121 status = nx_udp_enable(&ip_1);
122 CHECK_STATUS(0, status);
123
124 tx_semaphore_create(&semaphore_test_done, "semaphore test done", 0);
125 }
126
127 /* Define server threads. */
ntest_0_entry(ULONG thread_input)128 static void ntest_0_entry(ULONG thread_input)
129 {
130 UINT status;
131 NXD_ADDRESS client_ip_address;
132 NX_PACKET *send_packet;
133
134 /* Create RTP sender. */
135 status = nx_rtp_sender_create(&rtp_0, &ip_0, &pool_0, CNAME, sizeof(CNAME) - 1);
136 CHECK_STATUS(0, status);
137
138 /* Setup rtp sender session. */
139 client_ip_address.nxd_ip_version = NX_IP_VERSION_V4;
140 client_ip_address.nxd_ip_address.v4 = RTP_CLIENT_ADDRESS;
141 status = nx_rtp_sender_session_create(&rtp_0, &rtp_session_0, RTP_PAYLOAD_TYPE_VIDEO,
142 0, &client_ip_address,
143 RTP_CLIENT_RTP_PORT, RTP_CLIENT_RTCP_PORT);
144 rtp_session_0.nx_rtp_session_ssrc = 11478;
145
146 /* Allocate a packet */
147 status = nx_rtp_sender_session_packet_allocate(&rtp_session_0, &send_packet, 5 * NX_IP_PERIODIC_RATE);
148 CHECK_STATUS(0, status);
149
150 /* Copy payload data into the packet. */
151 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);
152 CHECK_STATUS(0, status);
153
154 status = nx_rtp_sender_session_packet_send(&rtp_session_0, send_packet, TEST_TIMESTAMP, TEST_MSW, TEST_LSW, 1);
155
156 CHECK_STATUS(0, status);
157
158 status = tx_semaphore_get(&semaphore_test_done, 5 * NX_IP_PERIODIC_RATE);
159 CHECK_STATUS(0, status);
160
161 /* Return the test result. */
162 printf("SUCCESS!\n");
163 test_control_return(0);
164 }
165
166 /* Define the client threads. */
ntest_1_entry(ULONG thread_input)167 static void ntest_1_entry(ULONG thread_input)
168 {
169 NX_PACKET *received_packet;
170 UINT status;
171
172 /* Create the rtp client socket. */
173 status = nx_udp_socket_create(&ip_1, &rtcp_client_socket, "RTCP Client Socket", NX_IP_NORMAL, NX_FRAGMENT_OKAY, 0x80, 5);
174 CHECK_STATUS(0, status);
175
176 status = nx_udp_socket_bind(&rtcp_client_socket, RTP_CLIENT_RTCP_PORT, NX_IP_PERIODIC_RATE);
177 CHECK_STATUS(0, status);
178
179 status = nx_udp_socket_receive(&rtcp_client_socket, &received_packet, 5 * NX_IP_PERIODIC_RATE);
180 if ((status == NX_SUCCESS) &&
181 (received_packet->nx_packet_length == sizeof(test_rtcp_packet_data)) &&
182 (memcmp(received_packet->nx_packet_prepend_ptr, test_rtcp_packet_data, sizeof(test_rtcp_packet_data)) == 0))
183 {
184 tx_semaphore_put(&semaphore_test_done);
185 }
186 }
187
188 #else
189
190 #ifdef CTEST
test_application_define(void * first_unused_memory)191 VOID test_application_define(void *first_unused_memory)
192 #else
193 void netx_rtcp_packet_send_test_application_define(void *first_unused_memory)
194 #endif
195 {
196
197 /* Print out test information banner. */
198 printf("NetX Test: RTCP Packet Send Test............................................N/A\n");
199
200 test_control_return(3);
201 }
202 #endif
203
204