2 ======================================================================
3 Copyright (c) 2019 Nokia
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions andlimitations under the License.
17 ======================================================================
32 struct timespec ts_start_tx;
34 int read_pdu(const char* filename, unsigned char* buffer) {
36 FILE* f = fopen(filename, "r");
39 fprintf(stderr, "abort: unable to open PDU file: %s\n",
44 return fread(buffer, sizeof(unsigned char), 2048, f);
48 int main(int argc, char** argv) {
50 char* proto_port = "tcp:4545";
52 // data portion (payload) of the message
54 // total count of msgs sent
56 // cyced count used to generate type
58 // number of msgs per second
59 int rate = argc < 2 ? 10 : atoi(argv[1]);
60 // the number of msg types depends on the number of xAPPs
62 // rate in mu-seconds/message
63 double v = (1.0/(double)rate) * SEC2MUS;
64 // delay between messages
66 // PDU buffer to be copied to each msg
67 unsigned char pdu_li[2048];
68 unsigned char pdu_rs[2048];
69 char* pdufile1 = "PDU/pdu1.per";
70 char* pdufile2 = "PDU/pdu2.per";
76 int pdu_li_size = read_pdu(pdufile1, pdu_li);
77 int pdu_rs_size = read_pdu(pdufile2, pdu_rs);
79 if((mr = uta_init(proto_port, 4096, UTAFL_NONE)) == NULL) {
80 fprintf(stderr, "abort: unable to initialise the lib: %s\n",
84 // get an initial send buffer
85 msg = uta_alloc_msg(mr, sizeof(msg_t));
87 fprintf(stderr, "abort: couldn't allocate initial message\n");
90 //record starting time
91 clock_gettime(CLOCK_REALTIME, &ts_start_tx);
92 while(count < MAX_TX) {
93 //sleep to have an average msg/sec send rate
95 msg->mtype = cyc_count;
96 msg_data = (msg_t *) msg->payload;
97 msg_data->time_counter = count;
99 snprintf(msg->xaction, UTA_MAX_XID, "x%05d", count);
101 if(msg->mtype == 0) {
102 msg_data->pdu_length = pdu_li_size;
103 memcpy(msg_data->payload, pdu_li, sizeof(msg_data->payload));
106 if(msg->mtype == 1) {
107 msg_data->pdu_length = pdu_rs_size;
108 memcpy(msg_data->payload, pdu_rs, sizeof(msg_data->payload));
110 msg->len = sizeof(msg_t);
111 // set timestamp at the absolute last point
112 clock_gettime(CLOCK_REALTIME, &msg_data->ts);
114 msg = uta_send_msg(mr, msg);
117 clock_gettime(CLOCK_REALTIME, &ts);
118 elapse = (ts.tv_sec - ts_start_tx.tv_sec) * 1000000000
119 + ts.tv_nsec - ts_start_tx.tv_nsec;
120 elapse_s = (double) elapse / 1000000000;
122 fprintf(stderr, "\rsent %d msgs", count);
123 cyc_count = cyc_count < type_n - 1 ? cyc_count + 1 : 0;