Private Member Functions | |
void | initializeApp (int stage) |
App initialization - should be overwritten by application. | |
void | initializeI3 () |
Application I3 initialize - should be overwritten by application. | |
void | handleTimerEvent (cMessage *msg) |
Handles timers - should be overwritten by application. | |
void | handleUDPMessage (cMessage *msg) |
Handles messages incoming from UDP gate. | |
void | deliver (I3Trigger &trigger, I3IdentifierStack &stack, cMessage *msg) |
Delivers packets coming from I3 - should be overwritten by application. | |
void | finish () |
Private Attributes | |
int | samplingType |
I3Identifier | generalId |
I3Identifier | myId |
NodeIdentity | partner |
bool | foundPartner |
cStdDev | myStats [NUM_STATS] |
std::map < I3IPAddress, LatencyInfo > | latencies |
void I3LatencyStretch::initializeApp | ( | int | stage | ) | [private, virtual] |
App initialization - should be overwritten by application.
I3 related commands should go in initializeI3.
stage | Initialization stage passed from initialize() |
Reimplemented from I3BaseApp.
00085 { 00086 statsDumped = false; 00087 I3BaseApp::initializeApp(stage); 00088 }
void I3LatencyStretch::initializeI3 | ( | ) | [private, virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
00132 { 00133 foundPartner = false; 00134 samplingType = par("useSampling"); 00135 00136 generalId.createFromHash("LatencyStretch"); 00137 generalId.setName("LatencyStretch"); 00138 generalId.createRandomSuffix(); 00139 insertTrigger(generalId); 00140 00141 if (samplingType & USE_CLOSEST_ID) { 00142 myId = retrieveClosestIdentifier(); 00143 } else { 00144 myId.createRandomKey(); 00145 } 00146 insertTrigger(myId); 00147 00148 cMessage *msg = new cMessage(); 00149 msg->setKind(TRIGGER_TIMER); 00150 scheduleAt(simulation.simTime() + 5, msg); 00151 }
void I3LatencyStretch::handleTimerEvent | ( | cMessage * | msg | ) | [private, virtual] |
Handles timers - should be overwritten by application.
msg | Timer to be handled |
Reimplemented from I3BaseApp.
00223 { 00224 if (msg->kind() == TRIGGER_TIMER) { 00225 if (!foundPartner) { 00226 I3Identifier otherId; 00227 00228 otherId.createFromHash("LatencyStretch"); 00229 otherId.createRandomSuffix(); 00230 00231 cMessage *hmsg = new cMessage(); 00232 NodeIdentity *nid = new NodeIdentity(); 00233 00234 nid->id = myId; 00235 nid->address = I3IPAddress(nodeIPAddress, par("clientPort")); 00236 00237 hmsg->setKind(STRETCH_HELLO); 00238 hmsg->setContextPointer(nid); 00239 sendPacket(otherId, hmsg, samplingType & USE_QUERY_FLAG); 00240 00241 } else { 00242 int length = (intrand(512) + 32) * 8; 00243 00244 MsgContent *mc1 = new MsgContent(); 00245 mc1->creationTime = simulation.simTime(); 00246 mc1->sourceId = myId; 00247 mc1->sourceIp = I3IPAddress(nodeIPAddress, par("clientPort")); 00248 00249 cMessage *i3msg = new cMessage(); 00250 i3msg->setKind(STRETCH_I3MSG); 00251 i3msg->setContextPointer(mc1); 00252 i3msg->setLength(length); 00253 00254 MsgContent *mc2 = new MsgContent(*mc1); 00255 cMessage *ipmsg = new cMessage(); 00256 ipmsg->setKind(STRETCH_IPMSG); 00257 ipmsg->setContextPointer(mc2); 00258 ipmsg->setLength(length); 00259 00260 sendPacket(partner.id, i3msg, samplingType & USE_QUERY_FLAG); 00261 sendThroughUDP(ipmsg, partner.address); 00262 00263 } 00264 00265 scheduleAt(simulation.simTime() + truncnormal(15, 5), msg); 00266 00267 } 00268 }
void I3LatencyStretch::handleUDPMessage | ( | cMessage * | msg | ) | [private, virtual] |
Handles messages incoming from UDP gate.
msg | Message sent |
Reimplemented from I3BaseApp.
00153 { 00154 if (msg->contextPointer() != 0) { 00155 MsgContent *mc = (MsgContent*)msg->contextPointer(); 00156 00157 if (!latencies.count(mc->sourceIp)) opp_error("Unknown Id!"); 00158 00159 LatencyInfo &info = latencies[mc->sourceIp]; 00160 00161 info.ipTime = simulation.simTime() - mc->creationTime; 00162 delete mc; 00163 delete msg; 00164 } else { 00165 I3BaseApp::handleUDPMessage(msg); 00166 } 00167 }
void I3LatencyStretch::deliver | ( | I3Trigger & | trigger, | |
I3IdentifierStack & | stack, | |||
cMessage * | msg | |||
) | [private, virtual] |
Delivers packets coming from I3 - should be overwritten by application.
trigger | Application trigger to which the packet was sent | |
stack | Identifier stack passed from I3 | |
msg | Arriving message |
Reimplemented from I3BaseApp.
00170 { 00171 if (msg->kind() == STRETCH_HELLO) { 00172 NodeIdentity *nid = (NodeIdentity*)msg->contextPointer(); 00173 I3Identifier otherId = nid->id; 00174 00175 latencies[nid->address] = LatencyInfo(); 00176 latencies[nid->address].i3Time = 0; 00177 latencies[nid->address].ipTime = 0; 00178 00179 msg->setKind(STRETCH_HELLOACK); 00180 nid->id = myId; 00181 nid->address = I3IPAddress(nodeIPAddress, par("clientPort")); 00182 msg->setContextPointer(nid); 00183 sendPacket(otherId, msg, samplingType & USE_QUERY_FLAG); 00184 00185 } else if (msg->kind() == STRETCH_HELLOACK) { 00186 00187 NodeIdentity *nid = (NodeIdentity*)msg->contextPointer(); 00188 partner = *nid; 00189 foundPartner = true; 00190 delete nid; 00191 delete msg; 00192 00193 } else if (msg->kind() == STRETCH_I3MSG) { 00194 00195 MsgContent *mc = (MsgContent*)msg->contextPointer(); 00196 00197 if (!latencies.count(mc->sourceIp)) opp_error("Unknown Id!"); 00198 00199 LatencyInfo &info = latencies[ mc->sourceIp ]; 00200 00201 info.i3Time = simulation.simTime() - mc->creationTime; 00202 00203 if (info.ipTime != 0) { 00204 if (simulation.simTime() > 100) { 00205 stats[STAT_IP].collect(info.ipTime); 00206 stats[STAT_I3].collect(info.i3Time ); 00207 stats[STAT_RATIO].collect(info.i3Time / info.ipTime); 00208 00209 myStats[STAT_IP].collect(info.ipTime); 00210 myStats[STAT_I3].collect(info.i3Time ); 00211 myStats[STAT_RATIO].collect(info.i3Time / info.ipTime); 00212 } 00213 info.i3Time = 0; 00214 info.ipTime = 0; 00215 } 00216 00217 00218 delete mc; 00219 delete msg; 00220 } 00221 }
void I3LatencyStretch::finish | ( | ) | [private] |
00090 { 00091 recordScalar("Number of samples", myStats[STAT_RATIO].samples()); 00092 00093 recordScalar("IP Min ", myStats[STAT_IP].min()); 00094 recordScalar("IP Max ", myStats[STAT_IP].max()); 00095 recordScalar("IP Mean ", myStats[STAT_IP].mean()); 00096 recordScalar("IP Stdev", myStats[STAT_IP].stddev()); 00097 00098 recordScalar("I3 Min ", myStats[STAT_I3].min()); 00099 recordScalar("I3 Max ", myStats[STAT_I3].max()); 00100 recordScalar("I3 Mean ", myStats[STAT_I3].mean()); 00101 recordScalar("I3 Stdev", myStats[STAT_I3].stddev()); 00102 00103 recordScalar("Ratio Min ", myStats[STAT_RATIO].min()); 00104 recordScalar("Ratio Max ", myStats[STAT_RATIO].max()); 00105 recordScalar("Ratio Mean ", myStats[STAT_RATIO].mean()); 00106 recordScalar("Ratio Stdev", myStats[STAT_RATIO].stddev()); 00107 00108 if (!statsDumped) { 00109 statsDumped = true; 00110 recordScalar("General Number of samples", stats[STAT_RATIO].samples()); 00111 00112 recordScalar("General IP Min ", stats[STAT_IP].min()); 00113 recordScalar("General IP Max ", stats[STAT_IP].max()); 00114 recordScalar("General IP Mean ", stats[STAT_IP].mean()); 00115 recordScalar("General IP Stdev", stats[STAT_IP].stddev()); 00116 stats[STAT_IP].clearResult(); 00117 00118 recordScalar("General I3 Min ", stats[STAT_I3].min()); 00119 recordScalar("General I3 Max ", stats[STAT_I3].max()); 00120 recordScalar("General I3 Mean ", stats[STAT_I3].mean()); 00121 recordScalar("General I3 Stdev", stats[STAT_I3].stddev()); 00122 stats[STAT_I3].clearResult(); 00123 00124 recordScalar("General Ratio Min ", stats[STAT_RATIO].min()); 00125 recordScalar("General Ratio Max ", stats[STAT_RATIO].max()); 00126 recordScalar("General Ratio Mean ", stats[STAT_RATIO].mean()); 00127 recordScalar("General Ratio Stdev", stats[STAT_RATIO].stddev()); 00128 stats[STAT_RATIO].clearResult(); 00129 } 00130 }
int I3LatencyStretch::samplingType [private] |
I3Identifier I3LatencyStretch::generalId [private] |
I3Identifier I3LatencyStretch::myId [private] |
NodeIdentity I3LatencyStretch::partner [private] |
bool I3LatencyStretch::foundPartner [private] |
cStdDev I3LatencyStretch::myStats[NUM_STATS] [private] |
std::map<I3IPAddress, LatencyInfo> I3LatencyStretch::latencies [private] |