I3TriggerRoutingTime.cc

Go to the documentation of this file.
00001 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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             //cout << "Trigger reach time " << simTime() - *pt << endl;
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 }
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3