2
dtpcsend.c: Sender for DTPC benchmark test.
4
Authors: Giorgos Papastergiou, SPICE
5
Ioannis Alexiadis, SPICE
7
Copyright (c) 2011, Space Internetworking Center,
8
Democritus University of Thrace. ALL RIGHTS RESERVED.
13
#define BUF_SIZE (50000)
14
#define MIN_RATE (1000)
15
#define MAX_RATE (200000000)
16
#define MIN_PAYLOADSIZE (2)
17
#define MAX_PAYLOADSIZE (1000000)
20
static DtpcSAP _dtpcsap(DtpcSAP *newSAP)
22
static DtpcSAP sap = NULL;
27
sm_TaskVar((void **) &sap);
33
static int checkElision(Object recordsList)
35
Sdr sdr = getIonsdr();
43
CHKZERO(sdr_begin_xn(sdr));
45
for (elt = sdr_list_first(sdr, recordsList); elt; elt = nextElt)
47
nextElt = sdr_list_next(sdr, elt);
48
obj = sdr_list_data(sdr, elt);
49
sdr_read(sdr, (char *) &item, obj, sizeof(PayloadRecord));
50
oK(decodeSdnv(&length, item.length.text));
57
if (length == firstLength) /* Duplicate. */
59
sdr_list_delete(sdr, elt, NULL, NULL);
60
sdr_free(sdr, item.payload);
65
return sdr_end_xn(sdr);
68
static int _running(int *newState)
80
static void handleQuit()
87
static int run_dtpcsend(int cycles, int rate, int recordLength,
88
int topicID, int profileID, char *dstEid)
90
static char buffer[BUF_SIZE] = "this is a testfile created by \
94
char randomLength = 0; /* Boolean */
108
DtpcElisionFn elisionFn;
110
elisionFn = checkElision;
111
if (cycles < 1 || rate < MIN_RATE || rate > MAX_RATE ||
112
(recordLength < MIN_PAYLOADSIZE && recordLength != 1) ||
113
recordLength > MAX_PAYLOADSIZE || topicID < 1 ||
114
profileID < 1 || dstEid == NULL)
116
PUTS("Usage: dtpcsend <number of cycles> <rate(bits/sec)> \
117
<payload size(bytes)> <topic ID> <profile ID> <destination endpoint>");
119
PUTS(" Rate must be bewteen 1000 and 200000000 bits/sec.");
120
PUTS(" Payload size must be between 2 and 1000000 bytes.");
121
PUTS(" To use payload sizes chosen at random from the");
122
PUTS(" range 1 to 65536, specify payload size 1.");
127
if (dtpc_attach() < 0)
129
putErrmsg("Can't attach to DTPC.", NULL);
133
if (dtpc_open(topicID, elisionFn, &sap) < 0)
135
putErrmsg("Can't open own topic.", itoa(topicID));
141
if (recordLength == 1)
144
srand((unsigned int) time(NULL));
147
isignal(SIGINT, handleQuit);
148
cyclesRemaining = cycles;
149
startTime = time(NULL);
150
while (_running(NULL) && cyclesRemaining > 0)
154
recordLength = (rand() % 65536) + 1;
157
bytesRemaining = recordLength;
158
if (sdr_begin_xn(sdr) == 0)
160
putErrmsg("Can't begin ION transaction.", NULL);
165
aduObj = sdr_malloc(sdr, recordLength);
169
putErrmsg("No space in SDR for adu.", NULL);
175
while (bytesRemaining > 0)
177
if (bytesRemaining > BUF_SIZE)
179
bytesToWrite = BUF_SIZE;
183
bytesToWrite = bytesRemaining;
186
sdr_write(sdr, addr, (char *) buffer, bytesToWrite);
187
bytesRemaining -= bytesToWrite;
188
addr += bytesToWrite;
191
if (sdr_end_xn(sdr) < 0)
193
putErrmsg("Can't create adu object in SDR.", NULL);
198
switch (dtpc_send(profileID, sap, dstEid, 0, 0, 0, 0, NULL, 0,
199
0, NULL, 0, aduObj, recordLength))
202
putErrmsg("Can't send adu.", NULL);
206
case 0: /* This payload does not fit in an adu */
207
if (sdr_begin_xn(sdr) == 0)
209
putErrmsg("Can't discard payload.", NULL);
214
sdr_free(sdr, aduObj);
215
if (sdr_end_xn(sdr) < 0)
217
putErrmsg("Can't discard payload.", NULL);
225
bytesSent += recordLength;
231
sleepSecs = (1.0 / ((float) rate)) * ((float) recordLength) * 8;
232
usecs = (unsigned int)( sleepSecs * 1000000 );
235
if ((cyclesRemaining % 1000) == 0 && cyclesRemaining != 0)
237
printf("Cycles remaining: %d\n",cyclesRemaining);
242
endTime = time(NULL);
244
PUTS("Stopping dtpcsend.");
245
interval = endTime - startTime;
246
PUTMEMO("Time (seconds)", itoa(interval));
247
PUTMEMO("Total payloads", itoa(cycles - cyclesRemaining));
248
isprintf(totalbytes, sizeof totalbytes, "%li", bytesSent);
249
PUTMEMO("Total bytes", totalbytes);
252
PUTS("Interval is too short to measure rate.");
256
PUTMEMO("Throughput (bytes per second)",
257
itoa(bytesSent / interval));
264
#if defined (VXWORKS) || defined (RTEMS)
265
int dtpcsend(int a1, int a2, int a3, int a4, int a5,
266
int a6, int a7, int a8, int a9, int a10)
268
int cycles = atoi((char *) a1);
269
int rate = atoi((char *) a2);
270
int recordLength = atoi((char *) a3);
271
int topicID = atoi((char *) a4);
272
int profileID = atoi((char *) a5);
273
char *dstEid = (char *) a6;
275
int main(int argc, char **argv)
279
int recordLength = 0;
284
if (argc > 7) argc = 7;
290
profileID = atoi(argv[5]);
292
topicID = atoi(argv[4]);
294
recordLength = atoi(argv[3]);
296
rate = atoi(argv[2]);
298
cycles = atoi(argv[1]);
303
return run_dtpcsend(cycles, rate, recordLength, topicID, profileID,