~ubuntu-branches/debian/sid/ion/sid

« back to all changes in this revision

Viewing changes to dtpc/test/dtpcsend.c

  • Committer: Package Import Robot
  • Author(s): Leo Iannacone
  • Date: 2013-07-09 16:22:20 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20130709162220-vfrvtfbl78wqzn9x
Tags: 3.2.0~dfsg1-1
* New upstream release.
* Updated debian/ion-tools.pod and debian/ion.links
  with new binaries.
* Updated fix-manpages-errors.patch (closes: #724143).
* Refreshed old patches.
* Removed fix-gcc4.8-errors.patch. Applied to upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        dtpcsend.c:     Sender for DTPC benchmark test.
 
3
 
 
4
        Authors: Giorgos Papastergiou, SPICE
 
5
                 Ioannis Alexiadis, SPICE
 
6
 
 
7
        Copyright (c) 2011, Space Internetworking Center,
 
8
        Democritus University of Thrace. ALL RIGHTS RESERVED.
 
9
                                                                        */
 
10
 
 
11
#include "dtpc.h"
 
12
 
 
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)
 
18
 
 
19
 
 
20
static DtpcSAP  _dtpcsap(DtpcSAP *newSAP)
 
21
{
 
22
        static DtpcSAP  sap = NULL;
 
23
 
 
24
        if (newSAP)
 
25
        {
 
26
                sap = *newSAP;
 
27
                sm_TaskVar((void **) &sap);
 
28
        }
 
29
 
 
30
        return sap;
 
31
}
 
32
 
 
33
static int      checkElision(Object recordsList)
 
34
{
 
35
        Sdr             sdr = getIonsdr();
 
36
        Object          elt;
 
37
        Object          nextElt;
 
38
        Object          obj;
 
39
        PayloadRecord   item;
 
40
        uvast           firstLength;
 
41
        uvast           length;
 
42
 
 
43
        CHKZERO(sdr_begin_xn(sdr));
 
44
        firstLength = 0;
 
45
        for (elt = sdr_list_first(sdr, recordsList); elt; elt = nextElt)
 
46
        {
 
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));
 
51
                if (firstLength == 0)
 
52
                {
 
53
                        firstLength = length;
 
54
                        continue;
 
55
                }
 
56
 
 
57
                if (length == firstLength)      /*      Duplicate.      */
 
58
                {
 
59
                        sdr_list_delete(sdr, elt, NULL, NULL);
 
60
                        sdr_free(sdr, item.payload);
 
61
                        sdr_free(sdr, obj);
 
62
                }
 
63
        }
 
64
 
 
65
        return sdr_end_xn(sdr);
 
66
}
 
67
 
 
68
static int      _running(int *newState)
 
69
{
 
70
        static int      state = 1;
 
71
 
 
72
        if (newState)
 
73
        {
 
74
                state = *newState;
 
75
        }
 
76
 
 
77
        return state;
 
78
}
 
79
 
 
80
static void     handleQuit()
 
81
{
 
82
        int     stop = 0;
 
83
 
 
84
        oK(_running(&stop));
 
85
}
 
86
 
 
87
static int      run_dtpcsend(int cycles, int rate, int recordLength,
 
88
                        int topicID, int profileID, char *dstEid)
 
89
{
 
90
        static char     buffer[BUF_SIZE] = "this is a testfile created by \
 
91
dtpcsend";
 
92
        int             stop = 0;
 
93
        int             cyclesRemaining;
 
94
        char            randomLength = 0;       /*      Boolean         */
 
95
        int             bytesRemaining;
 
96
        int             bytesToWrite;
 
97
        unsigned int    usecs;
 
98
        float           sleepSecs;
 
99
        time_t          startTime;
 
100
        time_t          endTime;
 
101
        int             interval;
 
102
        int             bytesSent = 0;
 
103
        char            totalbytes[21];
 
104
        DtpcSAP         sap;
 
105
        Sdr             sdr;
 
106
        Object          aduObj;
 
107
        Address         addr;
 
108
        DtpcElisionFn   elisionFn;
 
109
 
 
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)
 
115
        {
 
116
                PUTS("Usage: dtpcsend <number of cycles> <rate(bits/sec)> \
 
117
<payload size(bytes)> <topic ID> <profile ID> <destination endpoint>");
 
118
                PUTS("");
 
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.");
 
123
                PUTS("");
 
124
                return 0;
 
125
        }
 
126
 
 
127
        if (dtpc_attach() < 0)
 
128
        {
 
129
                putErrmsg("Can't attach to DTPC.", NULL);
 
130
                return 0;
 
131
        }
 
132
 
 
133
        if (dtpc_open(topicID, elisionFn, &sap) < 0)
 
134
        {
 
135
                putErrmsg("Can't open own topic.", itoa(topicID));
 
136
                return 0;
 
137
        }
 
138
 
 
139
        oK(_dtpcsap(&sap));
 
140
        sdr = getIonsdr();
 
141
        if (recordLength == 1)
 
142
        {
 
143
                randomLength = 1;
 
144
                srand((unsigned int) time(NULL));
 
145
        }
 
146
 
 
147
        isignal(SIGINT, handleQuit);
 
148
        cyclesRemaining = cycles;
 
149
        startTime = time(NULL);
 
150
        while (_running(NULL) && cyclesRemaining > 0)
 
151
        {
 
152
                if (randomLength)
 
153
                {
 
154
                        recordLength = (rand() % 65536) + 1;
 
155
                }
 
156
 
 
157
                bytesRemaining = recordLength;
 
158
                if (sdr_begin_xn(sdr) == 0)
 
159
                {
 
160
                        putErrmsg("Can't begin ION transaction.", NULL);
 
161
                        oK(_running(&stop));
 
162
                        continue;
 
163
                }
 
164
 
 
165
                aduObj = sdr_malloc(sdr, recordLength);
 
166
                if (aduObj == 0)
 
167
                {
 
168
                        sdr_cancel_xn(sdr);
 
169
                        putErrmsg("No space in SDR for adu.", NULL);
 
170
                        oK(_running(&stop));
 
171
                        continue;
 
172
                }
 
173
 
 
174
                addr = aduObj;
 
175
                while (bytesRemaining > 0)
 
176
                {
 
177
                        if (bytesRemaining > BUF_SIZE)
 
178
                        {
 
179
                                bytesToWrite = BUF_SIZE;
 
180
                        }
 
181
                        else
 
182
                        {
 
183
                                bytesToWrite = bytesRemaining;
 
184
                        }
 
185
 
 
186
                        sdr_write(sdr, addr, (char *) buffer, bytesToWrite);
 
187
                        bytesRemaining -= bytesToWrite;
 
188
                        addr += bytesToWrite;
 
189
                }
 
190
 
 
191
                if (sdr_end_xn(sdr) < 0)
 
192
                {
 
193
                        putErrmsg("Can't create adu object in SDR.", NULL);
 
194
                        oK(_running(&stop));
 
195
                        continue;
 
196
                }
 
197
 
 
198
                switch (dtpc_send(profileID, sap, dstEid, 0, 0, 0, 0, NULL, 0,
 
199
                                0, NULL, 0, aduObj, recordLength))
 
200
                {
 
201
                case -1:
 
202
                        putErrmsg("Can't send adu.", NULL);
 
203
                        oK(_running(&stop));
 
204
                        continue;
 
205
 
 
206
                case 0:         /* This payload does not fit in an adu  */
 
207
                        if (sdr_begin_xn(sdr) == 0)
 
208
                        {
 
209
                                putErrmsg("Can't discard payload.", NULL);
 
210
                                oK(_running(&stop));
 
211
                                continue;
 
212
                        }
 
213
 
 
214
                        sdr_free(sdr, aduObj);
 
215
                        if (sdr_end_xn(sdr) < 0)
 
216
                        {
 
217
                                putErrmsg("Can't discard payload.", NULL);
 
218
                                oK(_running(&stop));
 
219
                                continue;
 
220
                        }
 
221
 
 
222
                        break;
 
223
 
 
224
                case 1:
 
225
                        bytesSent += recordLength;
 
226
 
 
227
                default:
 
228
                        break;
 
229
                }
 
230
 
 
231
                sleepSecs = (1.0 / ((float) rate)) * ((float) recordLength) * 8;
 
232
                usecs = (unsigned int)( sleepSecs * 1000000 );
 
233
                microsnooze(usecs);
 
234
                cyclesRemaining--;
 
235
                if ((cyclesRemaining % 1000) == 0 && cyclesRemaining != 0)
 
236
                {
 
237
                        printf("Cycles remaining: %d\n",cyclesRemaining);
 
238
                }
 
239
        }
 
240
 
 
241
        dtpc_close(sap);
 
242
        endTime = time(NULL);
 
243
        writeErrmsgMemos();
 
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);
 
250
        if (interval <= 0)
 
251
        {
 
252
                PUTS("Interval is too short to measure rate.");
 
253
        }
 
254
        else
 
255
        {
 
256
                PUTMEMO("Throughput (bytes per second)",
 
257
                                itoa(bytesSent / interval));
 
258
        }
 
259
 
 
260
        ionDetach();
 
261
        return 0;
 
262
}
 
263
 
 
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)
 
267
{
 
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;
 
274
#else
 
275
int     main(int argc, char **argv)
 
276
{
 
277
        int     cycles = 0;
 
278
        int     rate = 0;
 
279
        int     recordLength = 0;
 
280
        int     topicID = 0;
 
281
        int     profileID = 0;
 
282
        char    *dstEid = NULL;
 
283
 
 
284
        if (argc > 7) argc = 7;
 
285
        switch (argc)
 
286
        {
 
287
        case 7:
 
288
                dstEid = argv[6];
 
289
        case 6:
 
290
                profileID = atoi(argv[5]);
 
291
        case 5:
 
292
                topicID = atoi(argv[4]);
 
293
        case 4:
 
294
                recordLength = atoi(argv[3]);
 
295
        case 3:
 
296
                rate = atoi(argv[2]);
 
297
        case 2:
 
298
                cycles = atoi(argv[1]);
 
299
        default:
 
300
                break;
 
301
        }
 
302
#endif
 
303
        return run_dtpcsend(cycles, rate, recordLength, topicID, profileID,
 
304
                        dstEid);
 
305
}