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.
{ MessageContent *mc = (MessageContent*)msg->getContextPointer(); switch (msg->getKind()) { case MSG_QUERY_ID: { I3Identifier otherId = mc->source; mc->source = closestId; msg->setKind(MSG_REPLY_ID); sendPacket(otherId, msg); break; } case MSG_REPLY_ID: partners.push_back(mc->source); delete mc; delete msg; break; case MSG_PING: msg->setKind(MSG_REPLY); sendPacket(mc->source, msg); break; case MSG_REPLY: packets.erase(mc->id); delete mc; delete msg; break; default: break; } }
void I3HostMobility::discoverPartners | ( | ) | [private] |
Definition at line 174 of file I3HostMobility.cc.
Referenced by handleTimerEvent().
{ partners.clear(); for (int i = 0; i < NUM_PARTNERS; i++) { cPacket *cmsg = new cPacket(); MessageContent *mc = new MessageContent(); I3Identifier partner; mc->source = closestId; mc->id = -1; cmsg->setContextPointer(mc); cmsg->setKind(MSG_QUERY_ID); partner.createFromHash("HostMobility"); partner.createRandomSuffix(); sendPacket(partner, cmsg); } checkedPartners = true; }
void I3HostMobility::doMobilityEvent | ( | I3MobilityStage | stage | ) | [private, virtual] |
Reimplemented from I3BaseApp.
Definition at line 194 of file I3HostMobility.cc.
{ if (stage == I3_MOBILITY_UPDATED) { cMessage *msg = new cMessage(); msg->setKind(MSG_TIMER_RESET_ID); scheduleAt(simTime() + 10, msg); } }
void I3HostMobility::finish | ( | ) | [private] |
Definition at line 73 of file I3HostMobility.cc.
{ recordScalar("Number of sent packets", numSentPackets); recordScalar("Number of lost packets", packets.size()); }
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.
{ switch (msg->getKind()) { case MSG_TIMER: if (checkedPartners) { // partners.size() != NUM_PARTNERS in the unlikely event // that not all id queries have returned //if (partners.size() == 0) { // opp_error("Wtf?!"); //} for (unsigned int i = 0; i < partners.size(); i++) { cPacket *cmsg = new cPacket(); MessageContent *mc = new MessageContent(); packets.insert(numSentPackets); mc->id = numSentPackets++; mc->source = closestId; cmsg->setContextPointer(mc); cmsg->setKind(MSG_PING); cmsg->setBitLength((32 + intrand(512)) * 8); sendPacket(partners[i], cmsg, true); } scheduleAt(simTime() + truncnormal(0.5, 0.1), msg); } else { discoverPartners(); scheduleAt(simTime() + 10, msg); } break; case MSG_TIMER_RESET_ID: closestId = retrieveClosestIdentifier(); insertTrigger(closestId); delete msg; break; case MSG_TIMER_REDISCOVER: checkedPartners = false; scheduleAt(simTime() + 60, msg); default: break; } }
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.
{ I3BaseApp::handleUDPMessage(msg); }
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.
{ numSentPackets = 0; I3BaseApp::initializeApp(stage); }
void I3HostMobility::initializeI3 | ( | ) | [private, virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
Definition at line 78 of file I3HostMobility.cc.
{ checkedPartners = false; poolId.createFromHash("HostMobility"); poolId.setName("HostMobility"); poolId.createRandomSuffix(); insertTrigger(poolId); closestId = retrieveClosestIdentifier(); insertTrigger(closestId); cMessage *msg = new cMessage(); msg->setKind(MSG_TIMER); scheduleAt(simTime() + 5, msg); cMessage *nmsg = new cMessage(); msg->setKind(MSG_TIMER_REDISCOVER); scheduleAt(simTime() + 60, nmsg); }
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().