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 | doMobilityEvent (I3MobilityStage stage) |
void | discoverPartners () |
void | finish () |
Private Attributes | |
bool | checkedPartners |
int | numSentPackets |
std::set< int > | packets |
std::vector< I3Identifier > | partners |
I3Identifier | poolId |
I3Identifier | closestId |
Definition at line 45 of file I3HostMobility.cc.
void I3HostMobility::deliver | ( | I3Trigger & | trigger, | |
I3IdentifierStack & | stack, | |||
cPacket * | msg | |||
) | [private, virtual] |
Delivers packets coming from I3 - should be overwritten by application.
trigger | Application trigger to which the packet was sent | |
stack | Identifier stack passed from I3 | |
msg | Arriving message |
Reimplemented from I3BaseApp.
Definition at line 102 of file I3HostMobility.cc.
00103 { 00104 MessageContent *mc = (MessageContent*)msg->getContextPointer(); 00105 switch (msg->getKind()) { 00106 case MSG_QUERY_ID: 00107 { 00108 I3Identifier otherId = mc->source; 00109 mc->source = closestId; 00110 msg->setKind(MSG_REPLY_ID); 00111 sendPacket(otherId, msg); 00112 break; 00113 } 00114 case MSG_REPLY_ID: 00115 partners.push_back(mc->source); 00116 delete mc; 00117 delete msg; 00118 break; 00119 case MSG_PING: 00120 msg->setKind(MSG_REPLY); 00121 sendPacket(mc->source, msg); 00122 break; 00123 case MSG_REPLY: 00124 packets.erase(mc->id); 00125 delete mc; 00126 delete msg; 00127 break; 00128 default: 00129 break; 00130 } 00131 }
void I3HostMobility::discoverPartners | ( | ) | [private] |
Definition at line 174 of file I3HostMobility.cc.
Referenced by handleTimerEvent().
00175 { 00176 partners.clear(); 00177 for (int i = 0; i < NUM_PARTNERS; i++) { 00178 cPacket *cmsg = new cPacket(); 00179 MessageContent *mc = new MessageContent(); 00180 I3Identifier partner; 00181 00182 mc->source = closestId; 00183 mc->id = -1; 00184 cmsg->setContextPointer(mc); 00185 cmsg->setKind(MSG_QUERY_ID); 00186 00187 partner.createFromHash("HostMobility"); 00188 partner.createRandomSuffix(); 00189 sendPacket(partner, cmsg); 00190 } 00191 checkedPartners = true; 00192 }
void I3HostMobility::doMobilityEvent | ( | I3MobilityStage | stage | ) | [private, virtual] |
Reimplemented from I3BaseApp.
Definition at line 194 of file I3HostMobility.cc.
00194 { 00195 if (stage == I3_MOBILITY_UPDATED) { 00196 cMessage *msg = new cMessage(); 00197 msg->setKind(MSG_TIMER_RESET_ID); 00198 scheduleAt(simTime() + 10, msg); 00199 } 00200 }
void I3HostMobility::finish | ( | ) | [private] |
Definition at line 73 of file I3HostMobility.cc.
00073 { 00074 recordScalar("Number of sent packets", numSentPackets); 00075 recordScalar("Number of lost packets", packets.size()); 00076 }
void I3HostMobility::handleTimerEvent | ( | cMessage * | msg | ) | [private, virtual] |
Handles timers - should be overwritten by application.
msg | Timer to be handled |
Reimplemented from I3BaseApp.
Definition at line 133 of file I3HostMobility.cc.
00133 { 00134 switch (msg->getKind()) { 00135 case MSG_TIMER: 00136 if (checkedPartners) { 00137 // partners.size() != NUM_PARTNERS in the unlikely event 00138 // that not all id queries have returned 00139 //if (partners.size() == 0) { 00140 // opp_error("Wtf?!"); 00141 //} 00142 for (unsigned int i = 0; i < partners.size(); i++) { 00143 cPacket *cmsg = new cPacket(); 00144 MessageContent *mc = new MessageContent(); 00145 00146 packets.insert(numSentPackets); 00147 mc->id = numSentPackets++; 00148 mc->source = closestId; 00149 cmsg->setContextPointer(mc); 00150 cmsg->setKind(MSG_PING); 00151 cmsg->setBitLength((32 + intrand(512)) * 8); 00152 00153 sendPacket(partners[i], cmsg, true); 00154 } 00155 scheduleAt(simTime() + truncnormal(0.5, 0.1), msg); 00156 } else { 00157 discoverPartners(); 00158 scheduleAt(simTime() + 10, msg); 00159 } 00160 break; 00161 case MSG_TIMER_RESET_ID: 00162 closestId = retrieveClosestIdentifier(); 00163 insertTrigger(closestId); 00164 delete msg; 00165 break; 00166 case MSG_TIMER_REDISCOVER: 00167 checkedPartners = false; 00168 scheduleAt(simTime() + 60, msg); 00169 default: 00170 break; 00171 } 00172 }
void I3HostMobility::handleUDPMessage | ( | cMessage * | msg | ) | [private, virtual] |
Handles messages incoming from UDP gate.
msg | Message sent |
Reimplemented from I3BaseApp.
Definition at line 98 of file I3HostMobility.cc.
00098 { 00099 I3BaseApp::handleUDPMessage(msg); 00100 }
void I3HostMobility::initializeApp | ( | int | stage | ) | [private, virtual] |
App initialization - should be overwritten by application.
I3 related commands should go in initializeI3.
stage | Initialization stage passed from initialize() |
Reimplemented from I3BaseApp.
Definition at line 67 of file I3HostMobility.cc.
00067 { 00068 numSentPackets = 0; 00069 00070 I3BaseApp::initializeApp(stage); 00071 }
void I3HostMobility::initializeI3 | ( | ) | [private, virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
Definition at line 78 of file I3HostMobility.cc.
00078 { 00079 checkedPartners = false; 00080 00081 poolId.createFromHash("HostMobility"); 00082 poolId.setName("HostMobility"); 00083 poolId.createRandomSuffix(); 00084 insertTrigger(poolId); 00085 00086 closestId = retrieveClosestIdentifier(); 00087 insertTrigger(closestId); 00088 00089 cMessage *msg = new cMessage(); 00090 msg->setKind(MSG_TIMER); 00091 scheduleAt(simTime() + 5, msg); 00092 00093 cMessage *nmsg = new cMessage(); 00094 msg->setKind(MSG_TIMER_REDISCOVER); 00095 scheduleAt(simTime() + 60, nmsg); 00096 }
bool I3HostMobility::checkedPartners [private] |
Definition at line 46 of file I3HostMobility.cc.
Referenced by discoverPartners(), handleTimerEvent(), and initializeI3().
I3Identifier I3HostMobility::closestId [private] |
Definition at line 52 of file I3HostMobility.cc.
Referenced by deliver(), discoverPartners(), handleTimerEvent(), and initializeI3().
int I3HostMobility::numSentPackets [private] |
Definition at line 48 of file I3HostMobility.cc.
Referenced by finish(), handleTimerEvent(), and initializeApp().
std::set<int> I3HostMobility::packets [private] |
Definition at line 49 of file I3HostMobility.cc.
Referenced by deliver(), finish(), and handleTimerEvent().
std::vector<I3Identifier> I3HostMobility::partners [private] |
Definition at line 50 of file I3HostMobility.cc.
Referenced by deliver(), discoverPartners(), and handleTimerEvent().
I3Identifier I3HostMobility::poolId [private] |
Definition at line 51 of file I3HostMobility.cc.
Referenced by initializeI3().