Switch to unified view

a b/src/DAF/AE/AEPing.cc
1
//
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
// 
7
// This program is distributed in the hope that it will be useful,
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
// 
12
// You should have received a copy of the GNU Lesser General Public License
13
// along with this program.  If not, see http://www.gnu.org/licenses/.
14
// 
15
16
#include "AEPing.h"
17
18
Define_Module(AEPing);
19
20
//Consts
21
const char* TIM_START           = "StartCommunication";
22
const char* TIM_STOP            = "StopCommunication";
23
const char* MSG_PING            = "PING-";
24
const char* PAR_START           = "startAt";
25
const char* PAR_STOP            = "stopAt";
26
const char* PAR_PING            = "pingAt";
27
const char* PAR_RATE            = "rate";
28
const char* PAR_DSTAPNAME       = "dstApName";
29
const char* PAR_DSTAPINSTANCE   = "dstApInstance";
30
const char* PAR_DSTAENAME       = "dstAeName";
31
const char* PAR_DSTAEINSTANCE   = "dstAeInstance";
32
33
AEPing::AEPing() {
34
}
35
36
AEPing::~AEPing() {
37
38
}
39
40
void AEPing::prepareAllocateRequest() {
41
    //Schedule AllocateRequest
42
    cMessage* m1 = new cMessage(TIM_START);
43
    scheduleAt(startAt, m1);
44
}
45
46
void AEPing::preparePing() {
47
    //Schedule Data transfer
48
    for (int i = 0; i < rate && pingAt + i < stopAt; i++) {
49
        std::stringstream ss;
50
        ss << MSG_PING << i;
51
        cMessage* m2 = new cMessage(ss.str().c_str());
52
        scheduleAt(pingAt + i, m2);
53
    }
54
}
55
56
void AEPing::prepareDeallocateRequest() {
57
    //Schedule DeallocateRequest
58
    cMessage* m3 = new cMessage(TIM_STOP);
59
    scheduleAt(stopAt, m3);
60
}
61
62
void AEPing::initialize()
63
{
64
    //Init pointers
65
    initPointers();
66
    //Source info
67
    initNamingInfo();
68
    //Setup signals
69
    initSignalsAndListeners();
70
    //Init QoSRequirements
71
    initQoSRequiremets();
72
73
    //Timers
74
    startAt = simTime() + par(PAR_START);
75
    stopAt  = simTime() + par(PAR_STOP);
76
    pingAt  = simTime() + par(PAR_PING);
77
    rate    = par(PAR_RATE);
78
79
    //Destination for flow
80
    dstApName     = this->par(PAR_DSTAPNAME).stringValue();
81
    dstApInstance = this->par(PAR_DSTAPINSTANCE).stringValue();
82
    dstAeName     = this->par(PAR_DSTAENAME).stringValue();
83
    dstAeInstance = this->par(PAR_DSTAEINSTANCE).stringValue();
84
85
    //Flow
86
    APNamingInfo src = this->getApni();
87
    APNamingInfo dst = APNamingInfo( APN(this->dstApName), this->dstApInstance,
88
                                     this->dstAeName, this->dstAeInstance);
89
    Flow fl = Flow(src, dst);
90
    fl.setQosParameters(this->getQoSRequirements());
91
92
    //Insert it to the Flows ADT
93
    insertFlow(fl);
94
95
    //Schedule AllocateRequest
96
    if (startAt > 0)
97
        prepareAllocateRequest();
98
    //Schedule Data transfer
99
    if (pingAt > 0)
100
        preparePing();
101
    //Schedule DeallocateRequest
102
    if (stopAt > 0)
103
        prepareDeallocateRequest();
104
105
    //Watchers
106
    WATCH_LIST(flows);
107
}
108
109
void AEPing::handleSelfMessage(cMessage *msg) {
110
    //EV << flows.back().info() << endl;
111
    if ( !strcmp(msg->getName(), "StartCommunication") ) {
112
        //signalizeAllocateRequest(&flows.back());
113
        //FIXME: Vesely - last flow in a list?!
114
        Irm->receiveAllocationRequest(&flows.back());
115
    }
116
    else if ( !strcmp(msg->getName(), "StopCommunication") )
117
        //signalizeDeallocateRequest(&flows.back());
118
        //Irm->receiveDeallocationRequest(&flows.back());
119
        EV << "StopCommunication";
120
    else if ( strstr(msg->getName(), "PING") ) {
121
        //TODO: Vesely - Send M_READ
122
        std::stringstream ss;
123
        ss << "M_READ(" << msg->getName() << ")";
124
        cMessage* ping = new cMessage(ss.str().c_str());
125
        send(ping , "dataIo$o", 0);
126
    }
127
    else
128
        EV << this->getFullPath() << " received unknown self-message " << msg->getName();
129
    delete(msg);
130
}
131
132
void AEPing::handleMessage(cMessage *msg)
133
{
134
    if ( msg->isSelfMessage() )
135
            this->handleSelfMessage(msg);
136
}