RINASim  October 2016
Documentation of framework for OMNeT++
Infection.cc
Go to the documentation of this file.
1 #include "Infection.h"
2 
3 #include "DataTransferPDU.h"
4 #include "InfectionSignals.h"
5 
6 using namespace std;
7 
8 namespace Infection {
9 
11 
12  unsigned int Flow::cepID = 1;
13 
15  string DIF,
16  string SRC,
17  string DST,
18  string _QoS,
19  double rate,
20  int avgPDU,
21  int varPDU,
22  int nParts,
23  int nRec) :
24  QoS (_QoS),
25  srcAddr(Address(SRC.c_str(), DIF.c_str())),
26  dstAddr(Address(DST.c_str(), DIF.c_str())),
27  avgWT(1.0/rate),
28  minS(avgPDU - varPDU),
29  maxS(avgPDU + varPDU),
30  current(0),
31  parts(nParts),
32  rec(nRec),
33  fcepID(Flow::cepID++),
34  secNum(0) {
36  connID.setDstCepId(-1);
37  connID.setQoSId(_QoS);
38  // cout << minS << " " << maxS << endl;
39  }
40 
41  pduT Flow::getPDU(bool record) {
42  //int size = 1024;
43  int size = intuniform(NULL,minS, maxS);
44 
45  pduT ret;
46  ret.wT = 8*(size+11) * avgWT * exponential(NULL,1);
47 
48  //size = 11;
49  //ret.wT = 100;
50 
51  // ret.wT = 8*(size+40) * avgWT * (4+ exponential(1))/5.0;
52  // ret.wT = 8*(size+22) * avgWT * uniform(0.9,1.15);
53  //ret.wT = 8*(size+20) * avgWT;
54  //ret.wT = size * avgWT;
55 
56  if(current == 0) { secNum++; }
57  DataTransferPDU * pdu = new InfectedDataTransferPDU( record && current < rec, fcepID, "InfectedPDU");
58 
59  pdu->setConnId(connID);
60  pdu->setSrcAddr(srcAddr);
61  pdu->setDstAddr(dstAddr);
62  pdu->setSrcApn(srcAddr.getApn());
63  pdu->setDstApn(dstAddr.getApn());
64  pdu->setSeqNum(secNum);
65 
66  UserDataField * ud = new UserDataField();
67 
68  ud->setCompleteSDU(true);
69  ud->setNoLength(false);
70  ud->setSduSeqNumPresent(true);
71  ud->setSduSeqNum(secNum);
72  pdu->encapsulate(ud);
73 
74  pdu->setByteLength(size);
75 
76  pdu->setHopCount(0);
77  // ret.wT = 5555555;
78  // pdu->setByteLength(0);
79 
80  ret.pdu = pdu;
81 
82  current++;
83  if(current >= parts) { current = 0;}
85 
86 
87  return ret;
88  }
89 
90  commMsg::commMsg(Flow * _f) : f(_f) {}
91 
92  void Infection::initialize() {
93  double iniT = par("iniTime").doubleValue();
94 
95  if(iniT<0 || par("infectedIPC").stdstringValue() == "") { return; }
96 
97  finTime = par("finTime").doubleValue();
98 
99  emitSignals = par("signal").boolValue();
100  if(emitSignals) { signal = registerSignal("InfectionSignal"); }
101 
102  markIniT = par("markIniT").doubleValue();
103  markFinT = par("markFinT").doubleValue();
104 
105  mod = this->getParentModule()->getSubmodule(par("infectedIPC").stringValue());
106  if(mod==NULL) { return; }
107 
108  rmt = mod->getSubmodule("relayAndMux")->getSubmodule("rmt");
109 
110  rmt->addGate("infGate", cGate::INOUT, false);
111  cGate * modIn = rmt->gateHalf("infGate", cGate::INPUT);
112  cGate * modOut = rmt->gateHalf("infGate", cGate::OUTPUT);
113 
114  cGate * In = gateHalf("g", cGate::INPUT);
115  cGate * Out = gateHalf("g", cGate::OUTPUT);
116 
117  modOut->connectTo(In);
118  Out->connectTo(modIn);
119 
120  string DIF = mod->par("difName");
121  string SRC = mod->par("ipcAddress");
122 
123  cXMLElement* Xml = NULL;
124  if (par("data").xmlValue() != NULL && par("data").xmlValue()->hasChildren()){
125  Xml = par("data").xmlValue();
126  } else { error("data parameter not initialized!"); }
127 
128  double linkRate = par("linkRate").doubleValue();
129  double usage = par("usage").doubleValue();
130 
131 // cout << "BaseRate : " << linkRate << " | Usage : "<< usage << endl;
132  double unitRate = linkRate * usage;
133 
134  cXMLElementList flowsXML = Xml->getChildrenByTagName("flow");
135  for(cXMLElement * n : flowsXML) {
136  string DST = "";
137  string QoS = VAL_MGMTQOSID;
138 
139  DST = n->getAttribute("dstAddr");
140  if (DST == "") {
141  error("Error parsing Infected flow. Its dstAddr is missing!"); }
142  if(DST == SRC) { continue; }
143 
144  if (n->getAttribute("qos")) { QoS = n->getAttribute("qos"); }
145 
146  int N = 1, rec = 1, pduS = 1024, pduSv = 0;
147  double rate = 1.0;
148 
149  if (n->getAttribute("N") && atoi(n->getAttribute("N")) > 0) {
150  N = atoi(n->getAttribute("N")); }
151  if (n->getAttribute("rec") && atoi(n->getAttribute("rec")) > 0) {
152  rec = atoi(n->getAttribute("rec")); }
153 
154  if (n->getAttribute("pduSize") && atoi(n->getAttribute("pduSize")) > 0) {
155  pduS = atoi(n->getAttribute("pduSize")); }
156  if(pduS < 50) { pduS = 50; }
157 
158  if (n->getAttribute("pduSizeVar") && atoi(n->getAttribute("pduSizeVar")) > 0) {
159  pduSv = atoi(n->getAttribute("pduSizeVar")); }
160  if(pduSv > pduS) { pduSv = pduS - 1; }
161 
162  if (n->getAttribute("rate") && atof(n->getAttribute("rate")) > 0) {
163  rate = atof(n->getAttribute("rate")); }
164  if(rate <= 0) { continue; }
165 
166  Flow * f = new Flow(DIF, SRC, DST, QoS, unitRate*rate, pduS, pduSv, N, rec);
167  flows.push_back(f);
168  scheduleAt(iniT + uniform(0, pduS/unitRate), new commMsg(f));
169 
170  // cout << "LinkRate : " << unitRate << " | FlowRate : "<< (unitRate*rate) << " (" << rate << ")" << endl;
171  }
172 
173  }
174 
175  void Infection::handleMessage(cMessage *msg) {
176  if(commMsg * m = dynamic_cast<commMsg *>(msg)) {
177  simtime_t now = simTime();
178  if(now >= finTime) { delete msg; return; }
179 
180  bool record = now >= markIniT && now < markFinT;
181 
182  pduT k = m->f->getPDU(record);
183 
184  scheduleAt(now + k.wT, msg);
185  send(k.pdu, "g$o");
186  if(emitSignals) { emit(signal, new SendInfMsg(
189  k.pdu->getConnId().getSrcCepId(),
190  m->f->QoS)
191  );}
192  return;
193  }
194  delete msg;
195  }
196 
197  void Infection::finish() {
198  for(Flow * f : flows) { delete f; }
199  }
200 }
virtual void setNoLength(bool noLength)
virtual void setSduSeqNumPresent(bool sduSeqNumPresent)
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
virtual void setDstApn(const APN &dstApn)
Definition: PDU_m.cc:331
virtual void setHopCount(unsigned int hopCount)
Definition: PDU_m.cc:391
int getSrcCepId() const
Getter of source Connection-Endpoint identifier.
Definition: ConnectionId.cc:54
const std::string VAL_MGMTQOSID
Definition: QoSCube.cc:37
virtual void setSrcAddr(const Address &srcAddr)
Definition: PDU_m.cc:301
virtual ConnectionId & getConnId()
Definition: PDU_m.cc:336
virtual void setDstAddr(const Address &dstAddr)
Definition: PDU_m.cc:311
Address dstAddr
Definition: Infection.h:29
void setDstCepId(int destCepId)
Setter of destination Connection-Endpoint identifier.
Definition: ConnectionId.cc:39
void setSduSeqNum(unsigned int sduSeqNum)
Flow()
Constructor for the flow with undefined values.
Definition: Flow.cc:32
virtual Address & getDstAddr()
Definition: PDU_m.cc:306
double avgWT
Definition: Infection.h:32
virtual Address & getSrcAddr()
Definition: PDU_m.cc:296
virtual void setSeqNum(unsigned int seqNum)
Definition: PDU_m.cc:381
virtual void setSrcApn(const APN &srcApn)
Definition: PDU_m.cc:321
Address srcAddr
Definition: Infection.h:29
Define_Module(Infection)
ConnectionId connID
Definition: Infection.h:28
virtual void setCompleteSDU(bool completeSDU)
void setQoSId(std::string qoSId)
Setter of selected QoS-cube identifier.
Definition: ConnectionId.cc:49
const APN & getApn() const
Getter of unique APN which is initialized during object construction.
Definition: Address.cc:119
void setSrcCepId(int srcCepId)
Setter of source Connection-Endpoint identifier.
Definition: ConnectionId.cc:59
unsigned int fcepID
Definition: Infection.h:35
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
commMsg(Flow *_f)
Definition: Infection.cc:90
unsigned int secNum
Definition: Infection.h:35
virtual void setConnId(const ConnectionId &connId)
Definition: PDU_m.cc:341
Address class holds IPC Process identification.
Definition: Address.h:42
pduT getPDU(bool record)
Definition: Infection.cc:41