I3TriggerRoutingTime.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include "I3BaseApp.h"
00024 #include "I3.h"
00025
00026 using namespace std;
00027
00028 static cStdDev stats;
00029 static bool statsDumped = false;
00030
00031 class I3TRTServer : public I3 {
00032
00033 void initializeApp(int stage);
00034 void deliver(OverlayKey &key, cMessage *msg);
00035 void finish();
00036 };
00037
00038 Define_Module(I3TRTServer);
00039
00040 class I3TRTClient : public I3BaseApp {
00041 void initializeI3();
00042 void handleTimerEvent(cMessage *msg);
00043 };
00044
00045 Define_Module(I3TRTClient);
00046
00047
00048 void I3TRTServer::initializeApp(int stage) {
00049 statsDumped = false;
00050 I3::initializeApp(stage);
00051 }
00052
00053 void I3TRTServer::deliver(OverlayKey &key, cMessage *msg) {
00054 I3InsertTriggerMessage *i3msg;
00055
00056 i3msg = dynamic_cast<I3InsertTriggerMessage*>(msg);
00057 if (i3msg) {
00058 simtime_t *pt = (simtime_t*)i3msg->getContextPointer();
00059 if (pt) {
00060 stats.collect(simTime() - *pt);
00061
00062 delete pt;
00063 i3msg->setContextPointer(0);
00064 }
00065 }
00066 I3::deliver(key, msg);
00067 }
00068
00069 void I3TRTServer::finish() {
00070 if (!statsDumped) {
00071 statsDumped = true;
00072 recordScalar("I3Sim Number of samples", stats.getCount());
00073 recordScalar("I3Sim Min time", stats.getMin());
00074 recordScalar("I3Sim Max time", stats.getMax());
00075 recordScalar("I3Sim Mean time", stats.getMean());
00076 recordScalar("I3Sim Stardard dev", stats.getStddev());
00077 stats.clearResult();
00078 }
00079 }
00080
00081 #define TRIGGER_TIMER 12345
00082
00083 void I3TRTClient::initializeI3() {
00084 cMessage *msg = new cMessage();
00085 msg->setKind(TRIGGER_TIMER);
00086 scheduleAt(simTime() + int(par("triggerDelay")), msg);
00087 }
00088
00089 void I3TRTClient::handleTimerEvent(cMessage *msg) {
00090 if (msg->getKind() == TRIGGER_TIMER) {
00091
00092 I3Identifier id;
00093 I3Trigger t;
00094 I3InsertTriggerMessage *imsg = new I3InsertTriggerMessage();
00095 I3IPAddress myAddress(nodeIPAddress, par("clientPort"));
00096
00097 id.createRandomKey();
00098 t.setIdentifier(id);
00099 t.getIdentifierStack().push(myAddress);
00100
00101
00102 imsg->setTrigger(t);
00103 imsg->setSendReply(true);
00104 imsg->setSource(myAddress);
00105 imsg->setBitLength(INSERT_TRIGGER_L(imsg));
00106 imsg->setContextPointer(new simtime_t(simTime()));
00107
00108 sendThroughUDP(imsg, gateway.address);
00109 scheduleAt(simTime() + int(par("triggerDelay")), msg);
00110 }
00111 }