OverSim
I3Anycast.cc
Go to the documentation of this file.
1 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 
23 #include "I3BaseApp.h"
24 
25 using namespace std;
26 
34 class I3Anycast : public I3BaseApp
35 {
36 private:
37  static int index; //HACK Change to use index module when it's done
38 public:
39  int myIndex;
40  cMessage *sendPacketTimer;
41 
42  void initializeApp(int stage);
43  void initializeI3();
44  void deliver(I3Trigger &trigger, I3IdentifierStack &stack, cPacket *msg);
45  void handleTimerEvent(cMessage *msg);
46 };
47 
48 int I3Anycast::index = 0;
49 
50 void I3Anycast::initializeApp(int stage) {
51  myIndex = index++;
52 }
53 
54 
56 {
57  sendPacketTimer = new cMessage("packet timer");
58  scheduleAt(simTime() + 20, sendPacketTimer);
59 
60  I3Identifier identifier("I3 Anycast test"); // create an identifier with the given string hash as prefix
61  identifier.createRandomSuffix(); // set the suffix as random
62  insertTrigger(identifier); // and insert a trigger with that id
63 
64 }
65 
66 void I3Anycast::handleTimerEvent(cMessage *msg)
67 {
68  if (myIndex == 0) { // only the first node
69  cPacket *cmsg = new cPacket("woot");
70 
71  I3Identifier id("I3 Anycast test"); // create an identifier with the previously used hash as prefix
72  id.createRandomSuffix(); // and a random suffix
73 
74  //cout << "Send message!" << endl;
75  getParentModule()->bubble("Sending message!");
76  sendPacket(id, cmsg); // send the first message with that identifier
77  }
78  delete msg;
79 }
80 
81 void I3Anycast::deliver(I3Trigger &trigger, I3IdentifierStack &stack, cPacket *msg)
82 {
83  // after arrival, repeat the same process
84  I3Identifier id("I3 Anycast test"); // create an identifier with the previously used hash as prefix
85  id.createRandomSuffix(); // and a random suffix
86 
87  getParentModule()->bubble("Got message - sending back!");
88  sendPacket(id, msg); // and send back to I3
89 }
90 
91 
93 
94