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, cPacket *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 |
Definition at line 66 of file I3LatencyStretch.cc.
| void I3LatencyStretch::deliver | ( | I3Trigger & | trigger, | |
| I3IdentifierStack & | stack, | |||
| cPacket * | 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.
Definition at line 172 of file I3LatencyStretch.cc.
{
if (msg->getKind() == STRETCH_HELLO) {
NodeIdentity *nid = (NodeIdentity*)msg->getContextPointer();
I3Identifier otherId = nid->id;
latencies[nid->address] = LatencyInfo();
latencies[nid->address].i3Time = 0;
latencies[nid->address].ipTime = 0;
msg->setKind(STRETCH_HELLOACK);
nid->id = myId;
nid->address = I3IPAddress(nodeIPAddress, par("clientPort"));
msg->setContextPointer(nid);
sendPacket(otherId, msg, samplingType & USE_QUERY_FLAG);
} else if (msg->getKind() == STRETCH_HELLOACK) {
NodeIdentity *nid = (NodeIdentity*)msg->getContextPointer();
partner = *nid;
foundPartner = true;
delete nid;
delete msg;
} else if (msg->getKind() == STRETCH_I3MSG) {
MsgContent *mc = (MsgContent*)msg->getContextPointer();
if (!latencies.count(mc->sourceIp)) opp_error("Unknown Id!");
LatencyInfo &info = latencies[ mc->sourceIp ];
info.i3Time = simTime() - mc->creationTime;
if (info.ipTime != 0) {
if (simTime() > 100) {
stats[STAT_IP].collect(info.ipTime);
stats[STAT_I3].collect(info.i3Time );
stats[STAT_RATIO].collect(info.i3Time / info.ipTime);
myStats[STAT_IP].collect(info.ipTime);
myStats[STAT_I3].collect(info.i3Time );
myStats[STAT_RATIO].collect(info.i3Time / info.ipTime);
}
info.i3Time = 0;
info.ipTime = 0;
}
delete mc;
delete msg;
}
}
| void I3LatencyStretch::finish | ( | ) | [private] |
Definition at line 93 of file I3LatencyStretch.cc.
{
recordScalar("Number of samples", myStats[STAT_RATIO].getCount());
recordScalar("IP Min ", myStats[STAT_IP].getMin());
recordScalar("IP Max ", myStats[STAT_IP].getMax());
recordScalar("IP Mean ", myStats[STAT_IP].getMean());
recordScalar("IP Stdev", myStats[STAT_IP].getStddev());
recordScalar("I3 Min ", myStats[STAT_I3].getMin());
recordScalar("I3 Max ", myStats[STAT_I3].getMax());
recordScalar("I3 Mean ", myStats[STAT_I3].getMean());
recordScalar("I3 Stdev", myStats[STAT_I3].getStddev());
recordScalar("Ratio Min ", myStats[STAT_RATIO].getMin());
recordScalar("Ratio Max ", myStats[STAT_RATIO].getMax());
recordScalar("Ratio Mean ", myStats[STAT_RATIO].getMean());
recordScalar("Ratio Stdev", myStats[STAT_RATIO].getStddev());
if (!statsDumped) {
statsDumped = true;
recordScalar("General Number of samples", stats[STAT_RATIO].getCount());
recordScalar("General IP Min ", stats[STAT_IP].getMin());
recordScalar("General IP Max ", stats[STAT_IP].getMax());
recordScalar("General IP Mean ", stats[STAT_IP].getMean());
recordScalar("General IP Stdev", stats[STAT_IP].getStddev());
stats[STAT_IP].clearResult();
recordScalar("General I3 Min ", stats[STAT_I3].getMin());
recordScalar("General I3 Max ", stats[STAT_I3].getMax());
recordScalar("General I3 Mean ", stats[STAT_I3].getMean());
recordScalar("General I3 Stdev", stats[STAT_I3].getStddev());
stats[STAT_I3].clearResult();
recordScalar("General Ratio Min ", stats[STAT_RATIO].getMin());
recordScalar("General Ratio Max ", stats[STAT_RATIO].getMax());
recordScalar("General Ratio Mean ", stats[STAT_RATIO].getMean());
recordScalar("General Ratio Stdev", stats[STAT_RATIO].getStddev());
stats[STAT_RATIO].clearResult();
}
}
| void I3LatencyStretch::handleTimerEvent | ( | cMessage * | msg | ) | [private, virtual] |
Handles timers - should be overwritten by application.
| msg | Timer to be handled |
Reimplemented from I3BaseApp.
Definition at line 226 of file I3LatencyStretch.cc.
{
if (msg->getKind() == TRIGGER_TIMER) {
if (!foundPartner) {
I3Identifier otherId;
otherId.createFromHash("LatencyStretch");
otherId.createRandomSuffix();
cPacket *hmsg = new cPacket();
NodeIdentity *nid = new NodeIdentity();
nid->id = myId;
nid->address = I3IPAddress(nodeIPAddress, par("clientPort"));
hmsg->setKind(STRETCH_HELLO);
hmsg->setContextPointer(nid);
sendPacket(otherId, hmsg, samplingType & USE_QUERY_FLAG);
} else {
int length = (intrand(512) + 32) * 8;
MsgContent *mc1 = new MsgContent();
mc1->creationTime = simTime();
mc1->sourceId = myId;
mc1->sourceIp = I3IPAddress(nodeIPAddress, par("clientPort"));
cPacket *i3msg = new cPacket();
i3msg->setKind(STRETCH_I3MSG);
i3msg->setContextPointer(mc1);
i3msg->setBitLength(length);
MsgContent *mc2 = new MsgContent(*mc1);
cPacket *ipmsg = new cPacket();
ipmsg->setKind(STRETCH_IPMSG);
ipmsg->setContextPointer(mc2);
ipmsg->setBitLength(length);
sendPacket(partner.id, i3msg, samplingType & USE_QUERY_FLAG);
sendThroughUDP(ipmsg, partner.address);
}
scheduleAt(simTime() + truncnormal(15, 5), msg);
}
}
| void I3LatencyStretch::handleUDPMessage | ( | cMessage * | msg | ) | [private, virtual] |
Handles messages incoming from UDP gate.
| msg | Message sent |
Reimplemented from I3BaseApp.
Definition at line 156 of file I3LatencyStretch.cc.
{
if (msg->getContextPointer() != 0) {
MsgContent *mc = (MsgContent*)msg->getContextPointer();
if (!latencies.count(mc->sourceIp)) opp_error("Unknown Id!");
LatencyInfo &info = latencies[mc->sourceIp];
info.ipTime = simTime() - mc->creationTime;
delete mc;
delete msg;
} else {
I3BaseApp::handleUDPMessage(msg);
}
}
| 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.
Definition at line 88 of file I3LatencyStretch.cc.
{
statsDumped = false;
I3BaseApp::initializeApp(stage);
}
| void I3LatencyStretch::initializeI3 | ( | ) | [private, virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
Definition at line 135 of file I3LatencyStretch.cc.
{
foundPartner = false;
samplingType = par("useSampling");
generalId.createFromHash("LatencyStretch");
generalId.setName("LatencyStretch");
generalId.createRandomSuffix();
insertTrigger(generalId);
if (samplingType & USE_CLOSEST_ID) {
myId = retrieveClosestIdentifier();
} else {
myId.createRandomKey();
}
insertTrigger(myId);
cMessage *msg = new cMessage();
msg->setKind(TRIGGER_TIMER);
scheduleAt(simTime() + 5, msg);
}
bool I3LatencyStretch::foundPartner [private] |
Definition at line 71 of file I3LatencyStretch.cc.
Referenced by deliver(), handleTimerEvent(), and initializeI3().
I3Identifier I3LatencyStretch::generalId [private] |
Definition at line 68 of file I3LatencyStretch.cc.
Referenced by initializeI3().
std::map<I3IPAddress, LatencyInfo> I3LatencyStretch::latencies [private] |
Definition at line 74 of file I3LatencyStretch.cc.
Referenced by deliver(), and handleUDPMessage().
I3Identifier I3LatencyStretch::myId [private] |
Definition at line 69 of file I3LatencyStretch.cc.
Referenced by deliver(), handleTimerEvent(), and initializeI3().
cStdDev I3LatencyStretch::myStats[NUM_STATS] [private] |
Definition at line 72 of file I3LatencyStretch.cc.
NodeIdentity I3LatencyStretch::partner [private] |
Definition at line 70 of file I3LatencyStretch.cc.
Referenced by deliver(), and handleTimerEvent().
int I3LatencyStretch::samplingType [private] |
Definition at line 67 of file I3LatencyStretch.cc.
Referenced by deliver(), handleTimerEvent(), and initializeI3().
1.7.1