Switch to unified view

a/src/DAF/AE/AESender.cc b/src/DAF/AE/AESender.cc
1
//
1
// The MIT License (MIT)
2
// This program is free software: you can redistribute it and/or modify
3
// it under the terms of the GNU Lesser General Public License as published by
4
// the Free Software Foundation, either version 3 of the License, or
5
// (at your option) any later version.
6
// 
2
//
7
// This program is distributed in the hope that it will be useful,
3
// Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
// GNU Lesser General Public License for more details.
11
// 
4
//
12
// You should have received a copy of the GNU Lesser General Public License
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
13
// along with this program.  If not, see http://www.gnu.org/licenses/.
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
14
// 
11
//
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
// THE SOFTWARE.
15
22
16
#include "AESender.h"
23
#include "AESender.h"
17
24
18
Define_Module(AESender);
25
Define_Module(AESender);
26
27
PingMsg::PingMsg(){
28
    pingAt = simTime();
29
}
30
PongMsg::PongMsg(simtime_t _pingAt){
31
    pingAt = _pingAt;
32
    pongAt = simTime();
33
}
19
34
20
35
21
AESender::AESender() : AE() {
36
AESender::AESender() : AE() {
22
    S_TIM_START           = "StartCommunication";
37
    S_TIM_START           = "StartCommunication";
23
    S_TIM_COM             = "MakeCommunication";
38
    S_TIM_COM             = "MakeCommunication";
...
...
115
    minDelay = 999;
130
    minDelay = 999;
116
    maxDelay = -1;
131
    maxDelay = -1;
117
    firstR = -1;
132
    firstR = -1;
118
    lastR = 0;
133
    lastR = 0;
119
134
135
    recTimes = par("recTimes").boolValue();
136
137
    pduburst = par("pduburst").longValue();
138
    if(pduburst<1) { pduburst = 1; }
139
120
    //Watchers
140
    //Watchers
121
    WATCH(FlowObject);
141
    WATCH(FlowObject);
122
    WATCH(send);
142
    WATCH(send);
123
    WATCH(received);
143
    WATCH(received);
124
    WATCH(pingreceived);
144
    WATCH(pingreceived);
...
...
129
    WATCH(maxDelay);
149
    WATCH(maxDelay);
130
}
150
}
131
151
132
void AESender::finish()
152
void AESender::finish()
133
{
153
{
154
    if(par("printAtEnd").boolValue()){
134
    EV << "At "<<this->getApni()<<endl;
155
        EV << "At "<<this->getApni()<<endl;
156
        if(FlowObject != NULL) {
157
            EV << "With QoS " << FlowObject->getConId().getQoSId() <<endl;
158
        }
135
    EV << send << " ("<<sendSize << ")"<<endl;
159
        EV << "send " << send << " ("<<sendSize << ")"<<endl;
136
    EV << received << " ("<<receivedSize << ")"<<endl;
137
    EV << pingreceived << " ("<<pingreceivedSize << ")"<<endl;
160
  //      EV << "pingsRcv "  << pingreceived << " ("<<pingreceivedSize << ")"<<endl;
161
        EV << "pongsRcv "  << received << " ("<<receivedSize << ")"<<endl;
138
    EV << minDelay << " / "<<maxDelay<<endl;
162
        EV << "delay "  << minDelay << " / "<<maxDelay<<endl;
139
    EV << firstR << " -> "<<lastR<<endl;
163
        EV << "timestamps "  << firstR << " -> "<<lastR<<endl;
164
165
        if(recTimes){
166
            EV << "-----------------"<<endl;
167
            for(std::map<double, int>::iterator it = times.begin(); it!=times.end(); it++) {
168
                EV << "  " << it->first << " " << it->second <<endl;
169
            }
170
            EV << "-----------------"<<endl;
171
        }
140
    EV << "-----------------"<<endl;
172
        EV << "-----------------"<<endl;
173
    }
141
}
174
}
142
175
143
void AESender::handleSelfMessage(cMessage *msg) {
176
void AESender::handleSelfMessage(cMessage *msg) {
144
    //EV << flows.back().info() << endl;
177
    //EV << flows.back().info() << endl;
145
    if ( !strcmp(msg->getName(), S_TIM_START) ) {
178
    if ( !strcmp(msg->getName(), S_TIM_START) ) {
...
...
149
        APNamingInfo src = this->getApni();
182
        APNamingInfo src = this->getApni();
150
        APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance,
183
        APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance,
151
                                         this->dstAeName, this->dstAeInstance);
184
                                         this->dstAeName, this->dstAeInstance);
152
185
153
        FlowObject = new Flow(src, dst);
186
        FlowObject = new Flow(src, dst);
154
        FlowObject->setQosParameters(this->getQoSRequirements());
187
        FlowObject->setQosRequirements(this->getQoSRequirements());
155
188
156
        //Insert it to the Flows ADT
189
        //Insert it to the Flows ADT
157
        insertFlow();
190
        insertFlow();
158
191
159
        sendAllocationRequest(FlowObject);
192
        sendAllocationRequest(FlowObject);
160
193
161
        //Schedule ComRequest
194
        //Schedule ComRequest
162
        cMessage* m = new cMessage(S_TIM_COM);
195
        cMessage* m = new cMessage(S_TIM_COM);
163
        scheduleAt(simTime()+sendAfter, m);
196
        scheduleAt(simTime()+sendAfter+uniform(0,rate), m);
164
    }
197
    }
165
    else if ( !strcmp(msg->getName(), S_TIM_STOP) ) {
198
    else if ( !strcmp(msg->getName(), S_TIM_STOP) ) {
166
        sendDeallocationRequest(FlowObject);
199
        sendDeallocationRequest(FlowObject);
167
    }
200
    }
168
    else if ( !strcmp(msg->getName(), S_TIM_COM) ) {
201
    else if ( !strcmp(msg->getName(), S_TIM_COM) ) {
169
        if(stopAt > simTime()){
202
        if(stopAt > simTime()){
203
            int tburst = intuniform(1,pduburst);
204
205
            double msgWait = tburst*rate;
206
            for(int i = 0; i < tburst; i++){
170
            int msgSize = size + intuniform(-sizevar,sizevar);
207
                int msgSize = size + intuniform(-sizevar,sizevar);
171
            double msgWait = rate + intuniform(-ratevar,ratevar);
208
                msgWait += uniform(-ratevar,ratevar);
172
173
            //Create PING messsage
209
                //Create PING messsage
174
            CDAP_M_Read* ping = new CDAP_M_Read(S_VAL_MODULEPATH);
210
                CDAP_M_Read* ping = new PingMsg();
175
            object_t obj;
176
            obj.objectName = S_VAL_MODULEPATH;
177
            obj.objectClass = "string";
178
            obj.objectInstance = -1;
179
            obj.objectVal = (cObject*)(&myPath);
180
            ping->setObject(obj);
181
211
182
            ping->setByteLength(msgSize);
212
                ping->setByteLength(msgSize);
183
213
184
            //Send message
214
                //Send message
185
            sendData(FlowObject, ping);
215
                sendData(FlowObject, ping);
186
            send++;
216
                send++;
187
            sendSize += msgSize;
217
                sendSize += msgSize;
188
218
            }
189
            //Schedule ComRequest
219
            //Schedule ComRequest
190
            cMessage* m = new cMessage(S_TIM_COM);
220
            cMessage* m = new cMessage(S_TIM_COM);
191
            scheduleAt(simTime()+msgWait, m);
221
            scheduleAt(simTime()+msgWait, m);
192
        }
222
        }
193
    }
223
    }
...
...
201
    if ( msg->isSelfMessage() )
231
    if ( msg->isSelfMessage() )
202
            this->handleSelfMessage(msg);
232
            this->handleSelfMessage(msg);
203
}
233
}
204
234
205
void AESender::processMRead(CDAPMessage* msg) {
235
void AESender::processMRead(CDAPMessage* msg) {
206
    CDAP_M_Read* msg1 = check_and_cast<CDAP_M_Read*>(msg);
236
    PingMsg* ping = check_and_cast<PingMsg*>(msg);
207
237
    if(ping){
208
    EV << "Received M_Read";
238
        PongMsg* pong = new PongMsg(ping->pingAt);
209
    object_t object = msg1->getObject();
210
    EV << " with object '" << object.objectClass << "'" << endl;
211
212
    if ( strstr(object.objectName.c_str(), S_VAL_MODULEPATH) ) {
213
        std::string* source = (std::string*)(object.objectVal);
214
        std::ostringstream os;
215
        os << "Ping requested by " <<  *source << endl;
216
        bubble(os.str().c_str());
217
        EV << os.str().c_str();
218
219
        //Create PING response
220
        CDAP_M_Read_R* pong = new CDAP_M_Read_R(S_VAL_MODULEPATH);
221
        object_t obj;
222
        obj.objectName = S_VAL_MODULEPATH;
223
        obj.objectClass = "string";
224
        obj.objectInstance = -1;
225
        obj.objectVal = (cObject*)(&myPath);
226
        pong->setObject(obj);
227
        pong->setByteLength(msg->getByteLength());
239
        pong->setByteLength(msg->getByteLength());
228
240
229
        sendData(FlowObject, pong);
241
        sendData(FlowObject, pong);
230
242
/*
231
        pingreceived++;
243
        pingreceived++;
232
        pingreceivedSize += msg->getByteLength();
244
        pingreceivedSize += msg->getByteLength();
233
        simtime_t delay = simTime() - msg->getCreationTime();
245
        simtime_t delay = simTime() - ping->pingAt;
234
        if(minDelay>delay){
246
        if(minDelay>delay){
235
            minDelay = delay;
247
            minDelay = delay;
236
        }
248
        }
237
        if(maxDelay<delay){
249
        if(maxDelay<delay){
238
            maxDelay = delay;
250
            maxDelay = delay;
239
        }
251
        }
240
        if(firstR<0)  {
252
        if(firstR<0)  {
241
            firstR = simTime();
253
            firstR = simTime();
242
        }
254
        }
243
        lastR = simTime();
255
        lastR = simTime();
256
*/
244
    }
257
    }
245
}
258
}
246
259
247
void AESender::processMReadR(CDAPMessage* msg) {
260
void AESender::processMReadR(CDAPMessage* msg) {
248
    CDAP_M_Read_R* msg1 = check_and_cast<CDAP_M_Read_R*>(msg);
261
    PongMsg* pong = check_and_cast<PongMsg*>(msg);
249
262
    if(pong){
250
    EV << "Received M_Read_R";
251
    object_t object = msg1->getObject();
252
    EV << " with object '" << object.objectClass << "'" << endl;
253
254
    if ( strstr(object.objectName.c_str(), S_VAL_MODULEPATH) ) {
255
        std::string* source = (std::string*)(object.objectVal);
256
        std::ostringstream os;
257
        os << "Ping replied by " <<  *source << endl;
258
        bubble(os.str().c_str());
259
        EV << os.str().c_str();
260
261
        received++;
263
        received++;
262
        receivedSize += msg->getByteLength();
264
        receivedSize += msg->getByteLength();
263
        simtime_t delay = simTime() - msg->getCreationTime();
265
        simtime_t delay = simTime() - pong->pingAt;
264
        if(minDelay>delay){
266
        if(minDelay>delay){
265
            minDelay = delay;
267
            minDelay = delay;
266
        }
268
        }
267
        if(maxDelay<delay){
269
        if(maxDelay<delay){
268
            maxDelay = delay;
270
            maxDelay = delay;
269
        }
271
        }
270
        if(firstR<0)  {
272
        if(firstR<0)  {
271
            firstR = simTime();
273
            firstR = simTime();
272
        }
274
        }
273
        lastR = simTime();
275
        lastR = simTime();
276
277
        if(recTimes){
278
            double dl = dround(delay.dbl(), 3);
279
            times[dl]++;
274
    }
280
        }
281
    }
275
}
282
}
283
284
285
double AESender::dround(double a, int ndigits) {
286
287
  int    exp_base10 = round(log10(a));
288
  double man_base10 = a*pow(10.0,-exp_base10);
289
  double factor     = pow(10.0,-ndigits+1);
290
  double truncated_man_base10 = man_base10 - fmod(man_base10,factor);
291
  double rounded_remainder    = fmod(man_base10,factor)/factor;
292
293
  rounded_remainder = rounded_remainder > 0.5 ? 1.0*factor : 0.0;
294
295
  return (truncated_man_base10 + rounded_remainder)*pow(10.0,exp_base10) ;
296
}