13
13
14
14
#include " teststructs.h"
15
15
16
- #define MAXELEMENTNAME 1024
17
-
18
- #ifdef TESTUDT
19
- # include " udtc.h"
20
- # include < netdb.h>
21
- # include < pthread.h>
22
-
23
- typedef int bool ;
24
- int g_IP_Version = AF_INET; // IPv4 family of addresses
25
- int g_Socket_Type = SOCK_STREAM; // use reliable transport layer protocol with Aknowledgements (default TCP)
26
-
27
- char g_Localhost[] = " 192.168.16.88" ; // "192.168.16.125"; //"127.0.0.1"; // "192.168.16.88"; // Client IP address
28
- // (*** passed as a parameter)
29
- int g_Server_Port = 50000 ; // port number (*** passed as a parameter)
30
-
31
- int g_TotalNum = 1000000 ; // Test data
32
-
33
- int tcp_connect (SYSSOCKET* ssock, int port);
34
- int c_connect (UDTSOCKET* usock, int port);
35
- int createUDTSocket (int * usock, int port, int rendezvous);
36
- int createTCPSocket (SYSSOCKET* ssock, int port, bool rendezvous);
37
- #endif
16
+ namespace {
17
+ constexpr int MaxElementName = 1024 ;
18
+ }
38
19
39
20
UDA_PLUGIN_INFO UDA_PLUGIN_INFO_FUNCTION_NAME ()
40
21
{
@@ -110,9 +91,6 @@ class TestPlugin : public UDAPluginBase
110
91
int long_capnp_test (UDA_PLUGIN_INTERFACE* plugin_interface);
111
92
int large_capnp_test (UDA_PLUGIN_INTERFACE* plugin_interface);
112
93
#endif // CAPNP_ENABLED
113
- #ifdef TESTUDT
114
- int testudt (UDA_PLUGIN_INTERFACE* plugin_interface);
115
- #endif // TESTUDT
116
94
117
95
void init (UDA_PLUGIN_INTERFACE* plugin_interface) override {}
118
96
void reset () override {}
@@ -182,9 +160,6 @@ TestPlugin::TestPlugin()
182
160
register_method (" long_capnp_test" , static_cast <UDAPluginBase::plugin_member_type>(&TestPlugin::long_capnp_test));
183
161
register_method (" large_capnp_test" , static_cast <UDAPluginBase::plugin_member_type>(&TestPlugin::large_capnp_test));
184
162
#endif // CAPNP_ENABLED
185
- #ifdef TESTUDT
186
- register_method (" testudt" , static_cast <UDAPluginBase::plugin_member_type>(&TestPlugin::testudt));
187
- #endif // TESTUDT
188
163
}
189
164
190
165
extern " C" int testPlugin (UDA_PLUGIN_INTERFACE* plugin_interface)
@@ -1699,12 +1674,12 @@ int TestPlugin::test50(UDA_PLUGIN_INTERFACE* plugin_interface)
1699
1674
// will have to deal with the type conversion.
1700
1675
1701
1676
typedef struct EnumMember60 {
1702
- char name[MAXELEMENTNAME ]; // The Enumeration member name
1677
+ char name[MaxElementName ]; // The Enumeration member name
1703
1678
long long value; // The value of the member
1704
1679
} ENUMMEMBER60;
1705
1680
1706
1681
typedef struct EnumList60 {
1707
- char name[MAXELEMENTNAME ]; // The Enumeration name
1682
+ char name[MaxElementName ]; // The Enumeration name
1708
1683
int type; // The original integer base type
1709
1684
int count; // The number of members of this enumeration class
1710
1685
ENUMMEMBER60* enummember; // Array of enum members
@@ -1719,7 +1694,7 @@ int register_enumlist(UDA_PLUGIN_INTERFACE* plugin_interface, ENUMLIST60* enum_l
1719
1694
COMPOUNDFIELD* enummember60_fields[2 ] = {nullptr };
1720
1695
int offset = 0 ;
1721
1696
1722
- int shape[1 ] = {MAXELEMENTNAME };
1697
+ int shape[1 ] = {MaxElementName };
1723
1698
enummember60_fields[0 ] =
1724
1699
udaNewCompoundField (" name" , " char array structure element" , &offset, UDA_TYPE_CHAR, 1 , shape);
1725
1700
enummember60_fields[1 ] = udaNewCompoundField (" value" , " long long structure element" , &offset, UDA_TYPE_LONG64, 0 ,
@@ -2202,250 +2177,3 @@ int TestPlugin::large_capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface)
2202
2177
return 0 ;
2203
2178
}
2204
2179
#endif // CAPNP_ENABLED
2205
-
2206
- #ifdef TESTUDT
2207
-
2208
- // rendezvous == false is default
2209
- int createUDTSocket (int * usock, int port, int rendezvous)
2210
- {
2211
- struct addrinfo hints;
2212
- struct addrinfo * res;
2213
- memset (&hints, 0 , sizeof (struct addrinfo ));
2214
- hints.ai_flags = AI_PASSIVE;
2215
- hints.ai_family = g_IP_Version;
2216
- hints.ai_socktype = g_Socket_Type;
2217
-
2218
- char service[16 ];
2219
- sprintf (service, " %d" , port);
2220
-
2221
- if (0 != getaddrinfo (nullptr , service, &hints, &res)) {
2222
- int err = 9991 ;
2223
- addIdamError (ErrorType::Code, " testplugin:createUDTSocket" , err, " Illegal port number or port is busy" );
2224
- addIdamError (ErrorType::Code, " testplugin:createUDTSocket" , err, (char *)udt_getlasterror_desc ());
2225
- return -1 ;
2226
- }
2227
-
2228
- *usock = udt_socket (res->ai_family , res->ai_socktype ,
2229
- res->ai_protocol ); // AF_INET, SOCK_STREAM, default protocol
2230
-
2231
- // since we will start a lot of connections, we set the buffer size to smaller value.
2232
-
2233
- // UDT buffer size limit (default 10MB)
2234
- int snd_buf = 16000 ;
2235
- int rcv_buf = 16000 ;
2236
- udt_setsockopt (*usock, 0 , UDT_UDT_SNDBUF, &snd_buf, sizeof (int ));
2237
- udt_setsockopt (*usock, 0 , UDT_UDT_RCVBUF, &rcv_buf, sizeof (int ));
2238
-
2239
- // UDP buffer size limit (default 1MB)
2240
- snd_buf = 8192 ;
2241
- rcv_buf = 8192 ;
2242
- udt_setsockopt (*usock, 0 , UDT_UDP_SNDBUF, &snd_buf, sizeof (int ));
2243
- udt_setsockopt (*usock, 0 , UDT_UDP_RCVBUF, &rcv_buf, sizeof (int ));
2244
-
2245
- // Maximum window size (packets) (default 25600) *** change with care!
2246
- int fc = 16 ;
2247
- udt_setsockopt (*usock, 0 , UDT_UDT_FC, &fc, sizeof (int ));
2248
-
2249
- // Reuse an existing address or create a new one (default true)
2250
- bool reuse = 1 ;
2251
- udt_setsockopt (*usock, 0 , UDT_UDT_REUSEADDR, &reuse, sizeof (bool ));
2252
-
2253
- // Rendezvous connection setup (default false)
2254
- udt_setsockopt (*usock, 0 , UDT_UDT_RENDEZVOUS, &rendezvous, sizeof (bool ));
2255
-
2256
- // Bind socket to port
2257
- int err;
2258
- udt_bind (*usock, res->ai_addr , res->ai_addrlen );
2259
- /*
2260
- if((err= udt_bind(*usock, res->ai_addr, res->ai_addrlen)) != UDT_SUCCESS){
2261
- fprintf(stderr, "UDT bind: [{}]\n",udt_getlasterror_desc());
2262
- return -1;
2263
- }
2264
- */
2265
- freeaddrinfo (res);
2266
- return 0 ;
2267
- }
2268
-
2269
- // rendezvous = false is default
2270
- // port = 0 is default
2271
- int createTCPSocket (SYSSOCKET* ssock, int port, bool rendezvous)
2272
- {
2273
- struct addrinfo hints;
2274
- struct addrinfo * res;
2275
- memset (&hints, 0 , sizeof (struct addrinfo ));
2276
- hints.ai_flags = AI_PASSIVE;
2277
- hints.ai_family = g_IP_Version;
2278
- hints.ai_socktype = g_Socket_Type;
2279
-
2280
- char service[16 ];
2281
- sprintf (service, " {}" , port);
2282
-
2283
- if (0 != getaddrinfo (nullptr , service, &hints, &res)) {
2284
- int err = 999 ;
2285
- addIdamError (ErrorType::Code, " testplugin:createTCPSocket" , err, " Illegal port number or port is busy" );
2286
- addIdamError (ErrorType::Code, " testplugin:createTCPSocket" , err, (char *)udt_getlasterror_desc ());
2287
- return -1 ;
2288
- }
2289
-
2290
- *ssock = socket (res->ai_family , res->ai_socktype , res->ai_protocol );
2291
-
2292
- if (bind (*ssock, res->ai_addr , res->ai_addrlen ) != 0 ) {
2293
- int err = 999 ;
2294
- addIdamError (ErrorType::Code, " testplugin:createTCPSocket" , err, " Socket Bind error" );
2295
- addIdamError (ErrorType::Code, " testplugin:createTCPSocket" , err, (char *)udt_getlasterror_desc ());
2296
- return -1 ;
2297
- }
2298
-
2299
- freeaddrinfo (res);
2300
- return 0 ;
2301
- }
2302
-
2303
- // connect conflicts with system function
2304
- int c_connect (UDTSOCKET* usock, int port)
2305
- {
2306
- struct addrinfo hints, *peer;
2307
- memset (&hints, 0 , sizeof (struct addrinfo ));
2308
- hints.ai_flags = AI_PASSIVE;
2309
- hints.ai_family = g_IP_Version;
2310
- hints.ai_socktype = g_Socket_Type;
2311
-
2312
- char buffer[16 ];
2313
- sprintf (buffer, " %d" , port);
2314
-
2315
- if (0 != getaddrinfo (g_Localhost, buffer, &hints, &peer)) {
2316
- int err = 999 ;
2317
- addIdamError (ErrorType::Code, " testplugin:c_connect" , err, " Socket Connect error" );
2318
- addIdamError (ErrorType::Code, " testplugin:c_connect" , err, (char *)udt_getlasterror_desc ());
2319
- return -1 ;
2320
- }
2321
-
2322
- udt_connect (*usock, peer->ai_addr , peer->ai_addrlen );
2323
-
2324
- freeaddrinfo (peer);
2325
- return 0 ;
2326
- }
2327
-
2328
- int tcp_connect (SYSSOCKET* ssock, int port)
2329
- {
2330
- struct addrinfo hints, *peer;
2331
- memset (&hints, 0 , sizeof (struct addrinfo ));
2332
- hints.ai_flags = AI_PASSIVE;
2333
- hints.ai_family = g_IP_Version;
2334
- hints.ai_socktype = g_Socket_Type;
2335
-
2336
- char buffer[16 ];
2337
- sprintf (buffer, " %d" , port);
2338
-
2339
- if (0 != getaddrinfo (g_Localhost, buffer, &hints, &peer)) {
2340
- int err = 999 ;
2341
- addIdamError (ErrorType::Code, " testplugin:tcp_connect" , err, " Socket Connect error" );
2342
- addIdamError (ErrorType::Code, " testplugin:tcp_connect" , err, (char *)udt_getlasterror_desc ());
2343
- return -1 ;
2344
- }
2345
-
2346
- connect (*ssock, peer->ai_addr , peer->ai_addrlen );
2347
-
2348
- freeaddrinfo (peer);
2349
- return 0 ;
2350
- }
2351
-
2352
- // ======================================================================================
2353
- // Test UDT (UDP/IP) Communication: data transfer from server to client
2354
-
2355
- // The IDAM server uses a regular TCP socket to instance the server via XINETD
2356
- // TCP has performance issues in high bandwidth high latency (RTT) networks
2357
- // UDP has better performance but data packets may get lost - it is not reliable
2358
- // UDT is an application level protocol, based on UDP, that is reliable and has the performance of UDP
2359
- // The IDAM server acts as a UDT client and the IDAM client acts as the UDT server!
2360
- int TestPlugin::testudt (UDA_PLUGIN_INTERFACE* plugin_interface)
2361
- {
2362
- // Start a mini server loop and create a separate communiation channel with the client bye-passing the TCP socket
2363
-
2364
- int client; // listening socket id
2365
- int false = 0 ;
2366
- int err = 0 ;
2367
-
2368
- // Create a UDT socket without specifying the port number
2369
-
2370
- if (createUDTSocket (&client, 0 , false ) < 0 ) {
2371
- ;
2372
- err = 9990 ;
2373
- addIdamError (ErrorType::Code, " testplugin:udt" , err, " Unable to create a UDT Socket" );
2374
- return err;
2375
- }
2376
-
2377
- // Connect to the IDAM client on a specific port
2378
- // Client and server sockets are connected
2379
-
2380
- c_connect (&client, g_Server_Port);
2381
-
2382
- // Create data to send
2383
-
2384
- int32_t buffer[g_TotalNum];
2385
- int32_t sum = 0 ;
2386
- for (int i = 0 ; i < g_TotalNum; ++i) {
2387
- buffer[i] = i;
2388
- sum += buffer[i];
2389
- }
2390
-
2391
- // Send the data (*** NOT Architecture independent ***)
2392
-
2393
- struct timeval tm1, tm2;
2394
- gettimeofday (&tm1, nullptr );
2395
-
2396
- time_t ticks = time (nullptr );
2397
- char sendBuff[1025 ];
2398
- snprintf (sendBuff, sizeof (sendBuff), " %.24s" , ctime (&ticks));
2399
- int tosend = strlen (sendBuff) + 1 ;
2400
- int sent = udt_send (client, sendBuff, tosend, 0 );
2401
-
2402
- tosend = g_TotalNum * sizeof (int32_t );
2403
- while (tosend > 0 ) {
2404
- int sent = udt_send (client, (char *)buffer + g_TotalNum * sizeof (int32_t ) - tosend, tosend, 0 );
2405
- if (sent < 0 ) {
2406
- err = 9990 ;
2407
- addIdamError (ErrorType::Code, " testplugin:udt" , err, " Unable to Send Data" );
2408
- addIdamError (ErrorType::Code, " testplugin:udt" , err, (char *)udt_getlasterror_desc ());
2409
- break ;
2410
- }
2411
- tosend -= sent;
2412
- }
2413
-
2414
- gettimeofday (&tm2, nullptr );
2415
- int dsecs = (int )(tm2.tv_sec - tm1.tv_sec );
2416
- int dmics = (int )(tm2.tv_usec - tm1.tv_usec );
2417
-
2418
- buffer[0 ] = dsecs;
2419
- buffer[1 ] = dmics;
2420
- tosend = 2 * sizeof (int32_t );
2421
- sent = udt_send (client, (char *)buffer, tosend, 0 );
2422
-
2423
- ticks = time (nullptr );
2424
- snprintf (sendBuff, sizeof (sendBuff), " %.24s" , ctime (&ticks));
2425
- tosend = (int )strlen (sendBuff) + 1 ;
2426
- sent = udt_send (client, sendBuff, tosend, 0 );
2427
-
2428
- // Close the connection
2429
-
2430
- udt_close (client);
2431
-
2432
- // Return IDAM status
2433
-
2434
- init_data_block (data_block);
2435
-
2436
- data_block->rank = 0 ;
2437
- data_block->data_n = 1 ;
2438
- data_block->data_type = UDA_TYPE_INT;
2439
-
2440
- int * status = (int *)malloc (sizeof (int ));
2441
- status[0 ] = 0 ;
2442
- data_block->data = (char *)status;
2443
-
2444
- strcpy (data_block->data_desc , " testplugins:udt status" );
2445
- strcpy (data_block->data_label , " " );
2446
- strcpy (data_block->data_units , " " );
2447
-
2448
- return err;
2449
- }
2450
-
2451
- #endif // TESTUDT
0 commit comments