2
ltpdriver.c: sender for LTP benchmark test.
5
/* Copyright (c) 2007, California Institute of Technology. */
6
/* All rights reserved. */
7
/* Author: Scott Burleigh, Jet Propulsion Laboratory */
14
#define DEFAULT_ADU_LENGTH (60000)
16
static int run_ltpdriver(unsigned long destEngineId, int clientId,
17
int cyclesRemaining, int greenLength, int sduLength)
19
static char buffer[DEFAULT_ADU_LENGTH] = "test...";
23
int randomSduLength = 0;
28
LtpSessionId sessionId;
34
int cycles = cyclesRemaining;
36
if (destEngineId == 0 || clientId < 1
37
|| cyclesRemaining < 1 || greenLength < 0 || sduLength < 1)
39
PUTS("Usage: ltpdriver <destination engine ID> <client ID> \
40
<number of cycles> <'green' length> [<payload size>]");
41
PUTS(" Payload size defaults to 60000 bytes.");
43
PUTS(" To use payload sizes chosen at random from the");
44
PUTS(" range 1024 to 62464, in multiples of 1024,");
45
PUTS(" specify payload size 1.");
47
PUTS(" Expected destination (receiving) application is");
54
putErrmsg("ltpdriver can't initialize LTP.", NULL);
64
aduFile = iopen("ltpdriverSduFile", O_WRONLY | O_CREAT, 0666);
67
putSysErrmsg("Can't create ADU file", NULL);
73
bytesRemaining = 65536;
77
bytesRemaining = sduLength;
80
while (bytesRemaining > 0)
82
if (bytesRemaining < DEFAULT_ADU_LENGTH)
84
bytesToWrite = bytesRemaining;
88
bytesToWrite = DEFAULT_ADU_LENGTH;
91
if (write(aduFile, buffer, bytesToWrite) < 0)
94
putSysErrmsg("Error writing to ADU file", NULL);
98
bytesRemaining -= bytesToWrite;
101
//sdr_start_trace(sdr, 10000000, NULL);
104
fileRef = zco_create_file_ref(sdr, "ltpdriverSduFile", NULL);
105
if (sdr_end_xn(sdr) < 0 || fileRef == 0)
107
putErrmsg("ltpdriver can't create file ref.", NULL);
111
startTime = time(NULL);
112
while (running && cyclesRemaining > 0)
116
sduLength = ((rand() % 60) + 1) * 1024;
119
redLength = sduLength - greenLength;
126
zcoRef = zco_create(sdr, ZcoFileSource, fileRef, 0,
128
if (sdr_end_xn(sdr) < 0 || zcoRef == 0)
130
putErrmsg("ltpdriver can't create ZCO.", NULL);
134
switch (ltp_send(destEngineId, clientId, zcoRef, redLength,
138
putErrmsg("ltpdriver can't send SDU.",
140
break; /* Out of switch. */
143
putErrmsg("ltp_send failed.", NULL);
148
bytesSent += sduLength;
152
if ((cyclesRemaining % 100) == 0)
154
//sdr_clear_trace(sdr);
155
//sdr_print_trace(sdr, 0);
156
PUTS(itoa(cyclesRemaining));
160
endTime = time(NULL);
162
interval = endTime - startTime;
163
PUTMEMO("Time (seconds)", itoa(interval));
166
PUTS("Data size random.");
170
PUTMEMO("Data size (bytes)", itoa(sduLength));
173
PUTMEMO("Cycles", itoa(cycles));
174
PUTMEMO("Bytes", itoa(bytesSent));
177
PUTS("Interval is too short to measure rate.");
181
PUTMEMO("Throughput (bytes per second)",
182
itoa(bytesSent / interval));
185
//sdr_stop_trace(sdr);
187
zco_destroy_file_ref(sdr, fileRef);
188
if (sdr_end_xn(sdr) < 0)
190
putErrmsg("ltpdriver can't destroy file reference.", NULL);
197
#if defined (VXWORKS) || defined (RTEMS)
198
int ltpdriver(int a1, int a2, int a3, int a4, int a5,
199
int a6, int a7, int a8, int a9, int a10)
201
unsigned long destEngineId = (unsigned long) a1;
205
int aduLen = (a5 == 0 ? DEFAULT_ADU_LENGTH : a5);
207
int main(int argc, char **argv)
209
unsigned long destEngineId = 0;
213
int aduLen = DEFAULT_ADU_LENGTH;
215
if (argc > 6) argc = 6;
219
aduLen = strtol(argv[5], NULL, 0);
222
greenLen = strtol(argv[4], NULL, 0);
225
cycles = strtol(argv[3], NULL, 0);
228
clientId = strtol(argv[2], NULL, 0);
231
destEngineId = strtoul(argv[1], NULL, 0);
237
return run_ltpdriver(destEngineId, clientId, cycles, greenLen, aduLen);