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, cMessage *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 |
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.
00064 { 00065 numSentPackets = 0; 00066 00067 I3BaseApp::initializeApp(stage); 00068 }
void I3HostMobility::initializeI3 | ( | ) | [private, virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
00075 { 00076 checkedPartners = false; 00077 00078 poolId.createFromHash("HostMobility"); 00079 poolId.setName("HostMobility"); 00080 poolId.createRandomSuffix(); 00081 insertTrigger(poolId); 00082 00083 closestId = retrieveClosestIdentifier(); 00084 insertTrigger(closestId); 00085 00086 cMessage *msg = new cMessage(); 00087 msg->setKind(MSG_TIMER); 00088 scheduleAt(simulation.simTime() + 5, msg); 00089 00090 cMessage *nmsg = new cMessage(); 00091 msg->setKind(MSG_TIMER_REDISCOVER); 00092 scheduleAt(simulation.simTime() + 60, nmsg); 00093 }
void I3HostMobility::handleTimerEvent | ( | cMessage * | msg | ) | [private, virtual] |
Handles timers - should be overwritten by application.
msg | Timer to be handled |
Reimplemented from I3BaseApp.
00130 { 00131 switch (msg->kind()) { 00132 case MSG_TIMER: 00133 if (checkedPartners) { 00134 // partners.size() != NUM_PARTNERS in the unlikely event 00135 // that not all id queries have returned 00136 //if (partners.size() == 0) { 00137 // opp_error("Wtf?!"); 00138 //} 00139 for (unsigned int i = 0; i < partners.size(); i++) { 00140 cMessage *cmsg = new cMessage(); 00141 MessageContent *mc = new MessageContent(); 00142 00143 packets.insert(numSentPackets); 00144 mc->id = numSentPackets++; 00145 mc->source = closestId; 00146 cmsg->setContextPointer(mc); 00147 cmsg->setKind(MSG_PING); 00148 cmsg->setLength((32 + intrand(512)) * 8); 00149 00150 sendPacket(partners[i], cmsg, true); 00151 } 00152 scheduleAt(simulation.simTime() + truncnormal(0.5, 0.1), msg); 00153 } else { 00154 discoverPartners(); 00155 scheduleAt(simulation.simTime() + 10, msg); 00156 } 00157 break; 00158 case MSG_TIMER_RESET_ID: 00159 closestId = retrieveClosestIdentifier(); 00160 insertTrigger(closestId); 00161 delete msg; 00162 break; 00163 case MSG_TIMER_REDISCOVER: 00164 checkedPartners = false; 00165 scheduleAt(simulation.simTime() + 60, msg); 00166 default: 00167 break; 00168 } 00169 }
void I3HostMobility::handleUDPMessage | ( | cMessage * | msg | ) | [private, virtual] |
Handles messages incoming from UDP gate.
msg | Message sent |
Reimplemented from I3BaseApp.
00095 { 00096 I3BaseApp::handleUDPMessage(msg); 00097 }
void I3HostMobility::deliver | ( | I3Trigger & | trigger, | |
I3IdentifierStack & | stack, | |||
cMessage * | 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.
00100 { 00101 MessageContent *mc = (MessageContent*)msg->contextPointer(); 00102 switch (msg->kind()) { 00103 case MSG_QUERY_ID: 00104 { 00105 I3Identifier otherId = mc->source; 00106 mc->source = closestId; 00107 msg->setKind(MSG_REPLY_ID); 00108 sendPacket(otherId, msg); 00109 break; 00110 } 00111 case MSG_REPLY_ID: 00112 partners.push_back(mc->source); 00113 delete mc; 00114 delete msg; 00115 break; 00116 case MSG_PING: 00117 msg->setKind(MSG_REPLY); 00118 sendPacket(mc->source, msg); 00119 break; 00120 case MSG_REPLY: 00121 packets.erase(mc->id); 00122 delete mc; 00123 delete msg; 00124 break; 00125 default: 00126 break; 00127 } 00128 }
void I3HostMobility::doMobilityEvent | ( | I3MobilityStage | stage | ) | [private, virtual] |
Reimplemented from I3BaseApp.
00191 { 00192 if (stage == I3_MOBILITY_UPDATED) { 00193 cMessage *msg = new cMessage(); 00194 msg->setKind(MSG_TIMER_RESET_ID); 00195 scheduleAt(simulation.simTime() + 10, msg); 00196 } 00197 }
void I3HostMobility::discoverPartners | ( | ) | [private] |
00172 { 00173 partners.clear(); 00174 for (int i = 0; i < NUM_PARTNERS; i++) { 00175 cMessage *cmsg = new cMessage(); 00176 MessageContent *mc = new MessageContent(); 00177 I3Identifier partner; 00178 00179 mc->source = closestId; 00180 mc->id = -1; 00181 cmsg->setContextPointer(mc); 00182 cmsg->setKind(MSG_QUERY_ID); 00183 00184 partner.createFromHash("HostMobility"); 00185 partner.createRandomSuffix(); 00186 sendPacket(partner, cmsg); 00187 } 00188 checkedPartners = true; 00189 }
void I3HostMobility::finish | ( | ) | [private] |
00070 { 00071 recordScalar("Number of sent packets", numSentPackets); 00072 recordScalar("Number of lost packets", packets.size()); 00073 }
bool I3HostMobility::checkedPartners [private] |
int I3HostMobility::numSentPackets [private] |
std::set<int> I3HostMobility::packets [private] |
std::vector<I3Identifier> I3HostMobility::partners [private] |
I3Identifier I3HostMobility::poolId [private] |
I3Identifier I3HostMobility::closestId [private] |