I3Anycast.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 
00025 using namespace std;
00026 
00034 class I3Anycast : public I3BaseApp
00035 {
00036 private:
00037     static int index; //HACK Change to use index module when it's done
00038 public:
00039     int myIndex;
00040     cMessage *sendPacketTimer;
00041 
00042     void initializeApp(int stage);
00043     void initializeI3();
00044     void deliver(I3Trigger &trigger, I3IdentifierStack &stack, cPacket *msg);
00045     void handleTimerEvent(cMessage *msg);
00046 };
00047 
00048 int I3Anycast::index = 0;
00049 
00050 void I3Anycast::initializeApp(int stage) {
00051     myIndex = index++;
00052 }
00053 
00054 
00055 void I3Anycast::initializeI3()
00056 {
00057     sendPacketTimer = new cMessage("packet timer");
00058     scheduleAt(simTime() + 20, sendPacketTimer);
00059 
00060     I3Identifier identifier("I3 Anycast test"); // create an identifier with the given string hash as prefix
00061     identifier.createRandomSuffix(); // set the suffix as random
00062     insertTrigger(identifier); // and insert a trigger with that id
00063 
00064 }
00065 
00066 void I3Anycast::handleTimerEvent(cMessage *msg)
00067 {
00068     if (myIndex == 0) { // only the first node
00069         cPacket *cmsg = new cPacket("woot");
00070 
00071         I3Identifier id("I3 Anycast test"); // create an identifier with the previously used hash as prefix
00072         id.createRandomSuffix(); // and a random suffix
00073 
00074         //cout << "Send message!" << endl;
00075         getParentModule()->bubble("Sending message!");
00076         sendPacket(id, cmsg); // send the first message with that identifier
00077     }
00078     delete msg;
00079 }
00080 
00081 void I3Anycast::deliver(I3Trigger &trigger, I3IdentifierStack &stack, cPacket *msg)
00082 {
00083     // after arrival, repeat the same process
00084     I3Identifier id("I3 Anycast test"); // create an identifier with the previously used hash as prefix
00085     id.createRandomSuffix(); // and a random suffix
00086 
00087     getParentModule()->bubble("Got message - sending back!");
00088     sendPacket(id, msg); // and send back to I3
00089 }
00090 
00091 
00092 Define_Module(I3Anycast);
00093 
00094 
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3