I3LatencyStretch Class Reference

Inheritance diagram for I3LatencyStretch:
I3BaseApp

List of all members.

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

Detailed Description

Definition at line 66 of file I3LatencyStretch.cc.


Member Function Documentation

void I3LatencyStretch::deliver ( I3Trigger trigger,
I3IdentifierStack stack,
cPacket *  msg 
) [private, virtual]

Delivers packets coming from I3 - should be overwritten by application.

Parameters:
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.

00173 {
00174     if (msg->getKind() == STRETCH_HELLO) {
00175         NodeIdentity *nid = (NodeIdentity*)msg->getContextPointer();
00176         I3Identifier otherId = nid->id;
00177 
00178         latencies[nid->address] = LatencyInfo();
00179         latencies[nid->address].i3Time = 0;
00180         latencies[nid->address].ipTime = 0;
00181 
00182         msg->setKind(STRETCH_HELLOACK);
00183         nid->id = myId;
00184         nid->address = I3IPAddress(nodeIPAddress, par("clientPort"));
00185         msg->setContextPointer(nid);
00186         sendPacket(otherId, msg, samplingType & USE_QUERY_FLAG);
00187 
00188     } else if (msg->getKind() == STRETCH_HELLOACK) {
00189 
00190         NodeIdentity *nid = (NodeIdentity*)msg->getContextPointer();
00191         partner = *nid;
00192         foundPartner = true;
00193         delete nid;
00194         delete msg;
00195 
00196     } else if (msg->getKind() == STRETCH_I3MSG) {
00197 
00198         MsgContent *mc = (MsgContent*)msg->getContextPointer();
00199 
00200         if (!latencies.count(mc->sourceIp)) opp_error("Unknown Id!");
00201 
00202         LatencyInfo &info = latencies[ mc->sourceIp ];
00203 
00204         info.i3Time = simTime() - mc->creationTime;
00205 
00206         if (info.ipTime != 0) {
00207             if (simTime() > 100) {
00208                 stats[STAT_IP].collect(info.ipTime);
00209                 stats[STAT_I3].collect(info.i3Time );
00210                 stats[STAT_RATIO].collect(info.i3Time / info.ipTime);
00211 
00212                 myStats[STAT_IP].collect(info.ipTime);
00213                 myStats[STAT_I3].collect(info.i3Time );
00214                 myStats[STAT_RATIO].collect(info.i3Time / info.ipTime);
00215             }
00216             info.i3Time = 0;
00217             info.ipTime = 0;
00218         }
00219 
00220 
00221         delete mc;
00222         delete msg;
00223     }
00224 }

void I3LatencyStretch::finish (  )  [private]

Definition at line 93 of file I3LatencyStretch.cc.

00093                               {
00094     recordScalar("Number of samples", myStats[STAT_RATIO].getCount());
00095 
00096     recordScalar("IP Min  ", myStats[STAT_IP].getMin());
00097     recordScalar("IP Max  ", myStats[STAT_IP].getMax());
00098     recordScalar("IP Mean ", myStats[STAT_IP].getMean());
00099     recordScalar("IP Stdev", myStats[STAT_IP].getStddev());
00100 
00101     recordScalar("I3 Min  ", myStats[STAT_I3].getMin());
00102     recordScalar("I3 Max  ", myStats[STAT_I3].getMax());
00103     recordScalar("I3 Mean ", myStats[STAT_I3].getMean());
00104     recordScalar("I3 Stdev", myStats[STAT_I3].getStddev());
00105 
00106     recordScalar("Ratio Min  ", myStats[STAT_RATIO].getMin());
00107     recordScalar("Ratio Max  ", myStats[STAT_RATIO].getMax());
00108     recordScalar("Ratio Mean ", myStats[STAT_RATIO].getMean());
00109     recordScalar("Ratio Stdev", myStats[STAT_RATIO].getStddev());
00110 
00111     if (!statsDumped) {
00112         statsDumped = true;
00113         recordScalar("General Number of samples", stats[STAT_RATIO].getCount());
00114 
00115         recordScalar("General IP Min  ", stats[STAT_IP].getMin());
00116         recordScalar("General IP Max  ", stats[STAT_IP].getMax());
00117         recordScalar("General IP Mean ", stats[STAT_IP].getMean());
00118         recordScalar("General IP Stdev", stats[STAT_IP].getStddev());
00119         stats[STAT_IP].clearResult();
00120 
00121         recordScalar("General I3 Min  ", stats[STAT_I3].getMin());
00122         recordScalar("General I3 Max  ", stats[STAT_I3].getMax());
00123         recordScalar("General I3 Mean ", stats[STAT_I3].getMean());
00124         recordScalar("General I3 Stdev", stats[STAT_I3].getStddev());
00125         stats[STAT_I3].clearResult();
00126 
00127         recordScalar("General Ratio Min  ", stats[STAT_RATIO].getMin());
00128         recordScalar("General Ratio Max  ", stats[STAT_RATIO].getMax());
00129         recordScalar("General Ratio Mean ", stats[STAT_RATIO].getMean());
00130         recordScalar("General Ratio Stdev", stats[STAT_RATIO].getStddev());
00131         stats[STAT_RATIO].clearResult();
00132     }
00133 }

void I3LatencyStretch::handleTimerEvent ( cMessage *  msg  )  [private, virtual]

Handles timers - should be overwritten by application.

Parameters:
msg Timer to be handled

Reimplemented from I3BaseApp.

Definition at line 226 of file I3LatencyStretch.cc.

00226                                                      {
00227     if (msg->getKind() == TRIGGER_TIMER) {
00228         if (!foundPartner) {
00229             I3Identifier otherId;
00230 
00231             otherId.createFromHash("LatencyStretch");
00232             otherId.createRandomSuffix();
00233 
00234             cPacket *hmsg = new cPacket();
00235             NodeIdentity *nid = new NodeIdentity();
00236 
00237             nid->id = myId;
00238             nid->address = I3IPAddress(nodeIPAddress, par("clientPort"));
00239 
00240             hmsg->setKind(STRETCH_HELLO);
00241             hmsg->setContextPointer(nid);
00242             sendPacket(otherId, hmsg, samplingType & USE_QUERY_FLAG);
00243 
00244         } else {
00245             int length = (intrand(512) + 32) * 8;
00246 
00247             MsgContent *mc1 = new MsgContent();
00248             mc1->creationTime = simTime();
00249             mc1->sourceId = myId;
00250             mc1->sourceIp = I3IPAddress(nodeIPAddress, par("clientPort"));
00251 
00252             cPacket *i3msg = new cPacket();
00253             i3msg->setKind(STRETCH_I3MSG);
00254             i3msg->setContextPointer(mc1);
00255             i3msg->setBitLength(length);
00256 
00257             MsgContent *mc2 = new MsgContent(*mc1);
00258             cPacket *ipmsg = new cPacket();
00259             ipmsg->setKind(STRETCH_IPMSG);
00260             ipmsg->setContextPointer(mc2);
00261             ipmsg->setBitLength(length);
00262 
00263             sendPacket(partner.id, i3msg, samplingType & USE_QUERY_FLAG);
00264             sendThroughUDP(ipmsg, partner.address);
00265 
00266         }
00267 
00268         scheduleAt(simTime() + truncnormal(15, 5), msg);
00269 
00270     }
00271 }

void I3LatencyStretch::handleUDPMessage ( cMessage *  msg  )  [private, virtual]

Handles messages incoming from UDP gate.

Parameters:
msg Message sent

Reimplemented from I3BaseApp.

Definition at line 156 of file I3LatencyStretch.cc.

00156                                                      {
00157     if (msg->getContextPointer() != 0) {
00158         MsgContent *mc = (MsgContent*)msg->getContextPointer();
00159 
00160         if (!latencies.count(mc->sourceIp)) opp_error("Unknown Id!");
00161 
00162         LatencyInfo &info = latencies[mc->sourceIp];
00163 
00164         info.ipTime = simTime() - mc->creationTime;
00165         delete mc;
00166         delete msg;
00167     } else {
00168         I3BaseApp::handleUDPMessage(msg);
00169     }
00170 }

void I3LatencyStretch::initializeApp ( int  stage  )  [private, virtual]

App initialization - should be overwritten by application.

I3 related commands should go in initializeI3.

Parameters:
stage Initialization stage passed from initialize()

Reimplemented from I3BaseApp.

Definition at line 88 of file I3LatencyStretch.cc.

00088                                               {
00089     statsDumped = false;
00090     I3BaseApp::initializeApp(stage);
00091 }

void I3LatencyStretch::initializeI3 (  )  [private, virtual]

Application I3 initialize - should be overwritten by application.

Reimplemented from I3BaseApp.

Definition at line 135 of file I3LatencyStretch.cc.

00135                                     {
00136     foundPartner = false;
00137     samplingType = par("useSampling");
00138 
00139     generalId.createFromHash("LatencyStretch");
00140     generalId.setName("LatencyStretch");
00141     generalId.createRandomSuffix();
00142     insertTrigger(generalId);
00143 
00144     if (samplingType & USE_CLOSEST_ID) {
00145         myId = retrieveClosestIdentifier();
00146     } else {
00147         myId.createRandomKey();
00148     }
00149     insertTrigger(myId);
00150 
00151     cMessage *msg = new cMessage();
00152     msg->setKind(TRIGGER_TIMER);
00153     scheduleAt(simTime() + 5, msg);
00154 }


Member Data Documentation

Definition at line 71 of file I3LatencyStretch.cc.

Referenced by deliver(), handleTimerEvent(), and initializeI3().

Definition at line 68 of file I3LatencyStretch.cc.

Referenced by initializeI3().

Definition at line 74 of file I3LatencyStretch.cc.

Referenced by deliver(), and handleUDPMessage().

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.

Referenced by deliver(), and finish().

Definition at line 70 of file I3LatencyStretch.cc.

Referenced by deliver(), and handleTimerEvent().

Definition at line 67 of file I3LatencyStretch.cc.

Referenced by deliver(), handleTimerEvent(), and initializeI3().


The documentation for this class was generated from the following file:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3