RINASim  October 2016
Documentation of framework for OMNeT++
DCInfection.cc
Go to the documentation of this file.
1 #include "DCInfection.h"
2 
3 using namespace std;
4 
5 
6 namespace Infection {
7 
9 
10 
11  void DCInfection::initialize() {
12  double iniT = par("iniTime").doubleValue();
13  loopRem = par("loop").longValue();
14 
15  if(loopRem <= 0 || iniT<0 || par("infectedIPC").stdstringValue() == "") { return; }
16 
17  toTors = par("toTors");
18  toFabric = par("toFabric");
19  toSpines = par("toSpines");
20  toEdges = par("toEdges");
21 
22  if(toTors || toFabric || toSpines) {
23  scheduleAt(iniT, new cMessage());
24  } else { return; }
25 
26  interTime = par("interTime").doubleValue();
27 
28  mod = this->getParentModule()->getSubmodule(par("infectedIPC").stringValue());
29  if(mod==NULL) { return; }
30 
31  rmt = mod->getSubmodule("relayAndMux")->getSubmodule("rmt");
32 
33  rmt->addGate("infGate", cGate::INOUT, false);
34  cGate * modIn = rmt->gateHalf("infGate", cGate::INPUT);
35  cGate * modOut = rmt->gateHalf("infGate", cGate::OUTPUT);
36 
37  cGate * In = gateHalf("g", cGate::INPUT);
38  cGate * Out = gateHalf("g", cGate::OUTPUT);
39 
40  modOut->connectTo(In);
41  Out->connectTo(modIn);
42 
43 
44  string DIF = mod->par("difName");
45  string SRC = mod->par("ipcAddress");
46  Im = DCAddr(SRC);
47  current = Im;
48 
49  string qosId = par("qosId");
50 
51  srcAddr = Address(SRC.c_str(), DIF.c_str());
52  dstAddr = srcAddr;
53  connID.setSrcCepId(-1);
54  connID.setDstCepId(-1);
55  connID.setQoSId(qosId);
56 
57  pods = par("pods").longValue();
58  torXpod = par("torXpod").longValue();
59  fabricXpod = par("fabricXpod").longValue();
60  spineXfabric = par("spineXfabric").longValue();
61  edgeSets = par("edgeSets").longValue();
62 
63  if(pods < 1) { pods = 1; }
64  if(torXpod < 1) { torXpod = 1; }
65  if(fabricXpod < 1) { fabricXpod = 1; }
66  if(spineXfabric < 1) { spineXfabric = 1; }
67  if(edgeSets < 0) { edgeSets = 0; }
68  }
69 
70 
71  void DCInfection::handleMessage(cMessage *msg) {
72  simtime_t now = simTime();
73  if(loopRem <= 0) { delete msg; return; }
74 
75  PDU * pdu = getPDU();
76  if(pdu != nullptr) {
77  scheduleAt(now + interTime, msg);
78  send(pdu, "g$o");
79  } else { delete msg; }
80  }
81 
82 
83  void DCInfection::setNext() {
84  DCAddr tCurr = current;
85  switch(current.type) {
86  case 0:
87  if(!toTors) {
88  current.type = 1;
89  current.a = 0;
90  current.b = -1;
91  setNext();
92  return;
93  }
94  current.b++;
95  if(current.b == torXpod) {
96  current.b = 0;
97  current.a++;
98  }
99  if(current.a == pods) {
100  current.type = 1;
101  current.a = 0;
102  current.b = -1;
103  setNext();
104  return;
105  }
106  break;
107  case 1:
108  if(!toFabric) {
109  current.type = 2;
110  current.a = 0;
111  current.b = -1;
112  setNext();
113  return;
114  }
115  current.b += 1;
116  if(current.b == fabricXpod) {
117  current.b = 0;
118  current.a++;
119  }
120  if(current.a == pods) {
121  current.type = 2;
122  current.a = 0;
123  current.b = -1;
124  setNext();
125  return;
126  }
127  break;
128  case 2:
129  if(!toSpines) {
130  current.type = 3;
131  current.a = 0;
132  current.b = -1;
133  setNext();
134  return;
135  }
136  current.b += 1;
137  if(current.b == spineXfabric) {
138  current.b = 0;
139  current.a++;
140  }
141  if(current.a == fabricXpod) {
142  current.type = 3;
143  current.a = 0;
144  current.b = -1;
145  setNext();
146  return;
147  }
148  break;
149  case 3:
150  if(!toEdges) {
151  current.type = 0;
152  current.a = 0;
153  current.b = -1;
154  setNext();
155  return;
156  }
157  current.b += 1;
158  if(current.b == fabricXpod) {
159  current.b = 0;
160  current.a++;
161  }
162  if(current.a == edgeSets) {
163  current.type = 0;
164  current.a = 0;
165  current.b = -1;
166  setNext();
167  return;
168  }
169  break;
170  }
171 
172  if(current == Im && tCurr != Im) { loopRem--; setNext(); }
173  else {
174  dstAddr = Address(current.toString().c_str(), dstAddr.getDifName().getName().c_str());
175  // cout << Im << " -> " << current << endl;
176  }
177  }
178 
179  PDU * DCInfection::getPDU() {
180  setNext();
181 
182  DataTransferPDU * pdu = new DataTransferPDU( "DCInfectedPDU");
183 
184  pdu->setConnId(connID);
185  pdu->setSrcAddr(srcAddr);
186  pdu->setDstAddr(dstAddr);
187  pdu->setSrcApn(srcAddr.getApn());
188  pdu->setDstApn(dstAddr.getApn());
189  pdu->setSeqNum(0);
190 
191  UserDataField * ud = new UserDataField();
192 
193  ud->setCompleteSDU(true);
194  ud->setNoLength(false);
195  ud->setSduSeqNumPresent(true);
196  ud->setSduSeqNum(0);
197  pdu->encapsulate(ud);
198 
199  pdu->setByteLength(0);
200  pdu->setHopCount(0);
201 
202  return pdu;
203 
204  }
205 }
virtual void setNoLength(bool noLength)
virtual void setSduSeqNumPresent(bool sduSeqNumPresent)
Define_Module(DCInfection)
virtual void setDstApn(const APN &dstApn)
Definition: PDU_m.cc:331
virtual void setHopCount(unsigned int hopCount)
Definition: PDU_m.cc:391
virtual void setSrcAddr(const Address &srcAddr)
Definition: PDU_m.cc:301
virtual void setDstAddr(const Address &dstAddr)
Definition: PDU_m.cc:311
Definition: PDU.h:42
void setSduSeqNum(unsigned int sduSeqNum)
virtual void setSeqNum(unsigned int seqNum)
Definition: PDU_m.cc:381
virtual void setSrcApn(const APN &srcApn)
Definition: PDU_m.cc:321
virtual void setCompleteSDU(bool completeSDU)
virtual void setConnId(const ConnectionId &connId)
Definition: PDU_m.cc:341
Address class holds IPC Process identification.
Definition: Address.h:42