I3BaseApp Class Reference

Basic template class for I3 applications. More...

#include <I3BaseApp.h>

Inheritance diagram for I3BaseApp:
I3Anycast I3Composite I3HostMobility I3LatencyStretch I3Multicast I3SessionClient I3SessionServer I3Triggers I3TRTClient

List of all members.

Classes

struct  I3CachedServer

Public Member Functions

 I3BaseApp ()
 Constructor.
 ~I3BaseApp ()
 Destructor.

Protected Types

enum  I3MobilityStage { I3_MOBILITY_BEFORE_UPDATE, I3_MOBILITY_UPDATED }

Protected Member Functions

int numInitStages () const
 Returns number of init stages required.
void initialize (int stage)
 Basic initialization.
virtual void initializeApp (int stage)
 App initialization - should be overwritten by application.
void bootstrapI3 ()
 Internal I3 bootstrap - connects to I3, inserts sampling triggers and initializes timers.
virtual void initializeI3 ()
 Application I3 initialize - should be overwritten by application.
virtual void handleTimerEvent (cMessage *msg)
 Handles timers - should be overwritten by application.
virtual void handleUDPMessage (cMessage *msg)
 Handles messages incoming from UDP gate.
void handleMessage (cMessage *msg)
 Handles incoming messages.
virtual void deliver (I3Trigger &trigger, I3IdentifierStack &stack, cPacket *msg)
 Delivers packets coming from I3 - should be overwritten by application.
void sendToI3 (I3Message *msg)
 Sends a message to I3.
void sendThroughUDP (cMessage *msg, const I3IPAddress &ip)
 Sends a message through UDP.
void refreshTriggers ()
 Refreshes (reinserts) stored triggers.
void refreshSamples ()
 Refreshes sampling triggers and selects fastest server as gateway.
I3Identifier retrieveClosestIdentifier ()
void sendPacket (const I3Identifier &id, cPacket *msg, bool useHint=false)
 Routes a packet through I3, passing an identifier stack composed of a single identifier.
void sendPacket (const I3IdentifierStack &stack, cPacket *msg, bool useHint=false)
 Routes a packet through I3.
void insertTrigger (const I3Identifier &identifier, bool store=true)
 Inserts a trigger into I3, composed by the given identifier and an identifier stack containing only this node's IP address.
void insertTrigger (const I3Identifier &identifier, const I3IdentifierStack &stack, bool store=true)
 Inserts a trigger into I3 with the given identifier and identifier stack.
void insertTrigger (const I3Trigger &t, bool store=true)
 Inserts the given trigger into I3.
void removeTrigger (const I3Identifier &identifier)
 Removes all triggers from the list of inserted triggers whose identifiers equal the one given.
void removeTrigger (const I3Trigger &trigger)
 Removes a trigger from I3.
std::set< I3Trigger > & getInsertedTriggers ()
 Returns the list of inserted triggers.
void receiveChangeNotification (int category, const cPolymorphic *details)
virtual void doMobilityEvent (I3MobilityStage stage)

Protected Attributes

int numSent
 Number of sent messages.
int sentBytes
int numReceived
 Number of received messages.
int receivedBytes
int numIsolations
 Number of times this node has been isolated - i.e.
IPvXAddress nodeIPAddress
 Cached IP address of this node.
std::set< I3TriggerinsertedTriggers
 Stored I3 triggers sent from this node, to be refreshed automatically.
std::map< I3Identifier,
I3CachedServer
samplingCache
std::map< I3Identifier,
I3CachedServer
identifierCache
I3CachedServer gateway
cMessage * refreshTriggersTimer
int refreshTriggersTime
cMessage * refreshSamplesTimer
int refreshSamplesTime
cMessage * initializeTimer
cMessage * bootstrapTimer

Private Attributes

bool mobilityInStages

Detailed Description

Basic template class for I3 applications.

Definition at line 41 of file I3BaseApp.h.


Member Enumeration Documentation

enum I3BaseApp::I3MobilityStage [protected]
Enumerator:
I3_MOBILITY_BEFORE_UPDATE 
I3_MOBILITY_UPDATED 

Definition at line 62 of file I3BaseApp.h.

00062                          {
00063         I3_MOBILITY_BEFORE_UPDATE,
00064         I3_MOBILITY_UPDATED
00065     };


Constructor & Destructor Documentation

I3BaseApp::I3BaseApp (  ) 

Constructor.

Definition at line 58 of file I3BaseApp.cc.

00059 {
00060 }

I3BaseApp::~I3BaseApp (  ) 

Destructor.

Definition at line 62 of file I3BaseApp.cc.

00063 {
00064 }


Member Function Documentation

void I3BaseApp::bootstrapI3 (  )  [protected]

Internal I3 bootstrap - connects to I3, inserts sampling triggers and initializes timers.

Definition at line 121 of file I3BaseApp.cc.

Referenced by handleMessage().

00122 {
00123     I3IPAddress myAddress(nodeIPAddress, par("clientPort"));
00124 
00125     // TODO: use BootstrapList instead of GlobalNodeList
00126     const NodeHandle handle = GlobalNodeListAccess().get()->getBootstrapNode();
00127     gateway.address = I3IPAddress(handle.getAddress(), par("serverPort"));
00128 
00129     int cacheSize = par("cacheSize");
00130     for (int i = 0; i < cacheSize; i++) {
00131         I3Identifier id;
00132 
00133         id.createRandomKey();
00134 
00135         ostringstream os;
00136         os << myAddress << " sample" << i;
00137         id.setName(os.str());
00138 
00139         samplingCache[id] = I3CachedServer(); // placeholder
00140 
00141         insertTrigger(id, false);
00142     }
00143 
00144     refreshTriggersTimer = new cMessage();
00145     refreshTriggersTime = par("triggerRefreshTime");
00146     scheduleAt(simTime() + truncnormal(refreshTriggersTime, refreshTriggersTime / 10),
00147                refreshTriggersTimer);
00148 
00149     refreshSamplesTimer = new cMessage();
00150     refreshSamplesTime = par("sampleRefreshTime");
00151     scheduleAt(simTime() + truncnormal(refreshSamplesTime, refreshSamplesTime / 10),
00152                refreshSamplesTimer);
00153 }

void I3BaseApp::deliver ( I3Trigger trigger,
I3IdentifierStack stack,
cPacket *  msg 
) [protected, virtual]

Delivers packets coming from I3 - should be overwritten by application.

Parameters:
trigger Application trigger to which the packet was sent
stack Identifier stack passed from I3
msg Arriving message

Reimplemented in I3Anycast, I3Composite, I3HostMobility, I3LatencyStretch, I3Multicast, I3SessionServer, I3SessionClient, and I3Triggers.

Definition at line 189 of file I3BaseApp.cc.

Referenced by handleUDPMessage().

00190 {
00191     delete msg;
00192 }

void I3BaseApp::doMobilityEvent ( I3MobilityStage  stage  )  [protected, virtual]

Reimplemented in I3HostMobility.

Definition at line 547 of file I3BaseApp.cc.

00548 {
00549 }

set< I3Trigger > & I3BaseApp::getInsertedTriggers (  )  [protected]

Returns the list of inserted triggers.

Definition at line 472 of file I3BaseApp.cc.

00473 {
00474     return insertedTriggers;
00475 }

void I3BaseApp::handleMessage ( cMessage *  msg  )  [protected]

Handles incoming messages.

Parameters:
msg Incoming message

Definition at line 160 of file I3BaseApp.cc.

00161 {
00162     if (msg->isSelfMessage()) {
00163         if (msg == bootstrapTimer) {
00164             bootstrapI3();
00165             delete msg;
00166             bootstrapTimer = 0;
00167         } else if (msg == initializeTimer)  {
00168             initializeI3();
00169             delete msg;
00170             initializeTimer = 0;
00171         } else if (msg == refreshTriggersTimer) {
00172             refreshTriggers();
00173             scheduleAt(simTime() + truncnormal(refreshTriggersTime, refreshTriggersTime / 10),
00174                        refreshTriggersTimer);
00175         } else if (msg == refreshSamplesTimer) {
00176             refreshSamples();
00177             scheduleAt(simTime() + truncnormal(refreshSamplesTime, refreshSamplesTime / 10),
00178                        refreshSamplesTimer);
00179         } else {
00180             handleTimerEvent(msg);
00181         }
00182     } else if (msg->arrivedOn("udpIn")) {
00183         handleUDPMessage(msg);
00184     } else {
00185         delete msg;
00186     }
00187 }

void I3BaseApp::handleTimerEvent ( cMessage *  msg  )  [protected, virtual]

Handles timers - should be overwritten by application.

Parameters:
msg Timer to be handled

Reimplemented in I3Anycast, I3Composite, I3HostMobility, I3LatencyStretch, I3Multicast, I3SessionClient, I3TRTClient, and I3Triggers.

Definition at line 194 of file I3BaseApp.cc.

Referenced by handleMessage().

00195 {
00196     delete msg;
00197 }

void I3BaseApp::handleUDPMessage ( cMessage *  msg  )  [protected, virtual]

Handles messages incoming from UDP gate.

Parameters:
msg Message sent

Reimplemented in I3HostMobility, and I3LatencyStretch.

Definition at line 199 of file I3BaseApp.cc.

Referenced by handleMessage().

00200 {
00201     I3Message *i3msg;
00202 
00203     i3msg = dynamic_cast<I3Message*>(msg);
00204     if (i3msg) {
00205         switch (i3msg->getType()) {
00206         case SEND_PACKET:
00207         {
00208             I3SendPacketMessage *smsg;
00209 
00210             smsg = check_and_cast<I3SendPacketMessage*>(msg);
00211             numReceived++;
00212             receivedBytes += smsg->getByteLength();
00213 
00214             /* deliver to app */
00215             cPacket *newMessage = smsg->decapsulate();
00216             deliver(smsg->getMatchedTrigger(), smsg->getIdentifierStack(), newMessage);
00217 
00218             break;
00219         }
00220         case QUERY_REPLY:
00221         {
00222             I3QueryReplyMessage *pmsg;
00223             pmsg = check_and_cast<I3QueryReplyMessage*>(msg);
00224             I3Identifier &id = pmsg->getIdentifier();
00225 
00226             identifierCache[id].address = pmsg->getSource();
00227             identifierCache[id].lastReply = simTime();
00228             identifierCache[id].roundTripTime = simTime() - pmsg->getSendingTime();
00229 
00230             if (samplingCache.count(id) != 0) {
00231                 samplingCache[id] = identifierCache[id];
00232             }
00233             break;
00234         }
00235         default:
00236             /* shouldn't get here */
00237             break;
00238         }
00239     }
00240     delete msg;
00241 }

void I3BaseApp::initialize ( int  stage  )  [protected]

Basic initialization.

Definition at line 71 of file I3BaseApp.cc.

00072 {
00073     if (stage != MIN_STAGE_APP) return;
00074 
00075     nodeIPAddress = IPAddressResolver().addressOf(getParentModule());
00076 
00077     bindToPort(par("clientPort"));
00078     /*    NotificationBoardAccess().get()->subscribe(this, NF_HOSTPOSITION_BEFOREUPDATE);
00079         NotificationBoardAccess().get()->subscribe(this, NF_HOSTPOSITION_UPDATED);*/
00080 
00081     getDisplayString().setTagArg("i", 0, "i3c");
00082     getParentModule()->getDisplayString().removeTag("i2");
00083 
00084     if (int(par("bootstrapTime")) >= int(par("initTime"))) {
00085         opp_error("Parameter bootstrapTime must be smaller than initTime");
00086     }
00087 
00088     bootstrapTimer = new cMessage();
00089     scheduleAt(simTime() + int(par("bootstrapTime")), bootstrapTimer);
00090 
00091     initializeTimer = new cMessage();
00092     scheduleAt(simTime() + int(par("initTime")), initializeTimer);
00093 
00094     numSent = 0;
00095     sentBytes = 0;
00096     numReceived = 0;
00097     receivedBytes = 0;
00098     numIsolations = 0;
00099     mobilityInStages = false;
00100 
00101     WATCH(nodeIPAddress);
00102     WATCH(numSent);
00103     WATCH(sentBytes);
00104     WATCH(numReceived);
00105     WATCH(receivedBytes);
00106     WATCH(numIsolations);
00107 
00108 
00109     WATCH_SET(insertedTriggers);
00110     WATCH(gateway);
00111     WATCH_MAP(samplingCache);
00112     WATCH_MAP(identifierCache);
00113 
00114     initializeApp(stage);
00115 }

void I3BaseApp::initializeApp ( int  stage  )  [protected, virtual]

App initialization - should be overwritten by application.

I3 related commands should go in initializeI3.

Parameters:
stage Initialization stage passed from initialize()

Reimplemented in I3Anycast, I3Composite, I3HostMobility, I3LatencyStretch, I3Multicast, I3SessionClient, and I3Triggers.

Definition at line 117 of file I3BaseApp.cc.

Referenced by initialize().

00118 {
00119 }

void I3BaseApp::initializeI3 (  )  [protected, virtual]

Application I3 initialize - should be overwritten by application.

Reimplemented in I3Anycast, I3Composite, I3HostMobility, I3LatencyStretch, I3Multicast, I3SessionServer, I3SessionClient, I3SessionClientStarter, I3TRTClient, and I3Triggers.

Definition at line 155 of file I3BaseApp.cc.

Referenced by handleMessage().

00156 {
00157 
00158 }

void I3BaseApp::insertTrigger ( const I3Trigger t,
bool  store = true 
) [protected]

Inserts the given trigger into I3.

Parameters:
t Trigger to be inserted
store Sets whether to store the trigger for auto-refresh

Definition at line 431 of file I3BaseApp.cc.

00431                                                             {
00432 
00433     if (store) {
00434         if (insertedTriggers.count(t) != 0) return;
00435         insertedTriggers.insert(t);
00436     }
00437 
00438     I3InsertTriggerMessage *msg = new I3InsertTriggerMessage();
00439     I3IPAddress myAddress(nodeIPAddress, par("clientPort"));
00440 
00441     msg->setTrigger(t);
00442     msg->setSendReply(true);
00443     msg->setSource(myAddress);
00444     msg->setBitLength(INSERT_TRIGGER_L(msg));
00445 
00446     sendThroughUDP(msg, gateway.address);
00447 }

void I3BaseApp::insertTrigger ( const I3Identifier identifier,
const I3IdentifierStack stack,
bool  store = true 
) [protected]

Inserts a trigger into I3 with the given identifier and identifier stack.

Parameters:
identifier Trigger's identifier
stack Trigger's identifier stack
store Sets whether to store the trigger for auto-refresh

Definition at line 422 of file I3BaseApp.cc.

00423 {
00424     I3Trigger trigger;
00425 
00426     trigger.setIdentifier(identifier);
00427     trigger.getIdentifierStack() = stack;
00428     insertTrigger(trigger, store);
00429 }

void I3BaseApp::insertTrigger ( const I3Identifier identifier,
bool  store = true 
) [protected]

Inserts a trigger into I3, composed by the given identifier and an identifier stack containing only this node's IP address.

Parameters:
identifier Trigger's identifier
store Sets whether to store the trigger for auto-refresh

Definition at line 412 of file I3BaseApp.cc.

Referenced by bootstrapI3(), I3Triggers::deliver(), I3SessionClient::deliver(), I3HostMobility::handleTimerEvent(), I3Triggers::initializeI3(), I3SessionClientStarter::initializeI3(), I3SessionClient::initializeI3(), I3SessionServer::initializeI3(), I3Multicast::initializeI3(), I3LatencyStretch::initializeI3(), I3HostMobility::initializeI3(), I3Composite::initializeI3(), I3Anycast::initializeI3(), insertTrigger(), refreshSamples(), refreshTriggers(), and retrieveClosestIdentifier().

00413 {
00414     I3Trigger trigger;
00415     I3IPAddress add(nodeIPAddress, par("clientPort"));;
00416 
00417     trigger.getIdentifierStack().push(add);
00418     trigger.setIdentifier(identifier);
00419     insertTrigger(trigger, store);
00420 }

int I3BaseApp::numInitStages (  )  const [protected]

Returns number of init stages required.

Definition at line 66 of file I3BaseApp.cc.

00067 {
00068     return MAX_STAGE_APP + 1;
00069 }

void I3BaseApp::receiveChangeNotification ( int  category,
const cPolymorphic *  details 
) [protected]

Definition at line 477 of file I3BaseApp.cc.

00478 {
00479     Enter_Method_Silent();
00480 
00481     /* Mobility is happening (the only event we are subscribed to). We have two things to do:
00482     * 1) Insert triggers with new IP
00483     * 2) Delete triggers with old IP
00484     * If it's one staged mobility, we just get told the IP after it's changed, and we need to make sure
00485     * step 1 and 2 are done. If it's two staged mobility, we need to make sure we do step 1 first and then
00486     * step 2. */
00487 
00488 //     if (!mobilityInStages) { /* if the flag isn't set, mobility isn't done in stages or this is stage 1 */
00489 //         if (category == NF_HOSTPOSITION_BEFOREUPDATE) {
00490 //             mobilityInStages = true; /* set the flag so we don't land here in stage 2 again */
00491 //         }
00492 //         /* do part 1! */
00493 //         cMessage *msg = check_and_cast<cMessage*>(details);
00494 //         IPvXAddress *ipAddr = (IPvXAddress*)msg->getContextPointer();
00495 //
00496 //         ostringstream os;
00497 //         os << "Mobility first stage - actual IP is " << nodeIPAddress << ", future IP is " << *ipAddr << endl;
00498 //         getParentModule()->bubble(os.str().c_str());
00499 //
00500 //         std::cout << "In advance from " << nodeIPAddress << " to " << *ipAddr << endl;
00501 //         I3IPAddress oldAddress(nodeIPAddress, par("clientPort"));
00502 //         I3IPAddress newAddress(*ipAddr, par("clientPort"));
00503 //
00504 //         delete ipAddr;
00505 //         delete msg;
00506 //
00507 //         for (set<I3Trigger>::iterator it = insertedTriggers.begin(); it != insertedTriggers.end(); it++) {
00508 //             I3Trigger trigger(*it); /* create copy */
00509 //             trigger.getIdentifierStack().replaceAddress(oldAddress, newAddress); /* replace old address with new */
00510 //             insertTrigger(trigger, false); /* insert trigger in I3, but don't store it in our list yet - that's done in part 2 */
00511 //         }
00512 //
00513 //         doMobilityEvent(I3_MOBILITY_BEFORE_UPDATE);
00514 //     }
00515 //     if (category == NF_HOSTPOSITION_UPDATED) { /* part 2: both for 1-stage and stage 2 of 2-stage mobility */
00516 //         I3IPAddress oldAddress(nodeIPAddress, par("clientPort"));
00517 //         nodeIPAddress = IPAddressResolver().addressOf(getParentModule()).get4();
00518 //         I3IPAddress newAddress(nodeIPAddress, par("clientPort"));
00519 //
00520 //         cout << "After from " << oldAddress << " to " << newAddress << endl;
00521 //
00522 //         ostringstream os;
00523 //         os << "Mobility second stage - setting IP as " << newAddress << endl;
00524 //         getParentModule()->bubble(os.str().c_str());
00525 //
00526 //         set<I3Trigger> newSet; /* list of new triggers (that we already inserted in I3 in stage 1) */
00527 //
00528 //         for (set<I3Trigger>::iterator it = insertedTriggers.begin(); it != insertedTriggers.end(); it++) {
00529 //             I3Trigger trigger(*it); /* create copy */
00530 //
00531 //             trigger.getIdentifierStack().replaceAddress(oldAddress, newAddress); /* replace old address with new */
00532 //             newSet.insert(trigger); /* insert in new list */
00533 //
00534 //             removeTrigger(*it);  /* remove trigger from I3 and out list */
00535 //
00536 //         }
00537 //         insertedTriggers = newSet; /* replace old list with updated one */
00538 //
00539 //         mobilityInStages = false; /* reset variable */
00540 //         refreshTriggers(); /* to get new trigger round-trip times, new cache list */
00541 //      refreshSamples();
00542 //
00543 //         doMobilityEvent(I3_MOBILITY_UPDATED);
00544 //     }
00545 }

void I3BaseApp::refreshSamples (  )  [protected]

Refreshes sampling triggers and selects fastest server as gateway.

Definition at line 332 of file I3BaseApp.cc.

Referenced by handleMessage().

00332                                {
00333     map<I3Identifier, I3CachedServer>::iterator mit;
00334 
00335     EV << "I3BaseApp::refreshSamples()]\n"
00336        << "    Refresh samples!"
00337        << endl;
00338     /* reinsert sample triggers */
00339     for (mit = samplingCache.begin(); mit != samplingCache.end(); mit++) {
00340         insertTrigger(mit->first, false);
00341     }
00342 }

void I3BaseApp::refreshTriggers (  )  [protected]

Refreshes (reinserts) stored triggers.

Definition at line 264 of file I3BaseApp.cc.

Referenced by handleMessage().

00265 {
00266     I3IPAddress myAddress(nodeIPAddress, par("clientPort"));
00267     map<I3Identifier, I3CachedServer>::iterator mit;
00268 
00269 
00270     // pick fastest I3 server as gateway
00271     int serverTimeout = par("serverTimeout");
00272     gateway.roundTripTime = serverTimeout;
00273     I3Identifier gatewayId;
00274     for (mit = samplingCache.begin(); mit != samplingCache.end(); mit++) {
00275         if (gateway.roundTripTime > mit->second.roundTripTime) {
00276             gatewayId = mit->first;
00277             gateway = mit->second;
00278         }
00279     }
00280 
00281     // check if gateway has timeout'ed
00282     if (simTime() - gateway.lastReply >= serverTimeout) {
00283         // We have a small problem here: if the fastest server has timeout,
00284         // that means the previous gateway had stopped responding some time before and no triggers were refreshed.
00285         // Since all servers have timeout'ed by now and we can't trust return times, pick a random server and hope that one is alive.
00286         int random = intrand(samplingCache.size()), i;
00287 
00288         EV << "I3BaseApp::refreshTriggers()]\n"
00289            << "    Gateway timeout at " << nodeIPAddress
00290            << ", time " << simTime()
00291            << "; expired gateway is " << gateway << "(" << gatewayId << ") "
00292            << " with last reply at " << gateway.lastReply
00293            << endl;
00294 
00295         for (i = 0, mit = samplingCache.begin(); i < random; i++, mit++);
00296         gateway = mit->second;
00297         EV << "I3BaseApp::refreshTriggers()]\n"
00298            << "    New gateway for " << nodeIPAddress << " is " << gateway
00299            << endl;
00300 
00301         if (gateway.roundTripTime > 2 * serverTimeout) {
00302             EV << "I3BaseApp::refreshTriggers()]\n"
00303                << "    New gateway's (" << gateway << ") rtt for " << nodeIPAddress
00304                << " too high... marking as isolated!"
00305                << endl;
00306             numIsolations++;
00307             const NodeHandle handle = GlobalNodeListAccess().get()->getBootstrapNode();
00308             gateway.address = I3IPAddress(handle.getAddress(), par("serverPort"));
00309         }
00310     }
00311 
00312     /* ping gateway */
00313     insertTrigger(gatewayId, false);
00314 //    cout << "Client " << nodeIPAddress << " pings " << gatewayId << endl;
00315 
00316     /* reinsert stored triggers */
00317     set<I3Trigger>::iterator it;
00318     for (it = insertedTriggers.begin(); it != insertedTriggers.end(); it++) {
00319         insertTrigger(*it, false);
00320     }
00321 
00322     /* now that we are refreshing stuff, might as well erase old identifier cache entries */
00323     int idStoreTime = par("idStoreTime");
00324     for (mit = identifierCache.begin(); mit != identifierCache.end(); mit++) {
00325         if (mit->second.lastReply - simTime() > idStoreTime) {
00326             identifierCache.erase(mit);
00327         }
00328     }
00329 
00330 }

void I3BaseApp::removeTrigger ( const I3Trigger trigger  )  [protected]

Removes a trigger from I3.

Parameters:
trigger Trigger to be removed

Definition at line 462 of file I3BaseApp.cc.

00463 {
00464     I3RemoveTriggerMessage *msg = new I3RemoveTriggerMessage();
00465     msg->setTrigger(t);
00466     msg->setBitLength(REMOVE_TRIGGER_L(msg));
00467     sendThroughUDP(msg, gateway.address);
00468 
00469     insertedTriggers.erase(t);
00470 }

void I3BaseApp::removeTrigger ( const I3Identifier identifier  )  [protected]

Removes all triggers from the list of inserted triggers whose identifiers equal the one given.

Parameters:
identifier Identifier to be compared against

Definition at line 449 of file I3BaseApp.cc.

Referenced by I3SessionClient::deliver(), and I3SessionClient::handleTimerEvent().

00450 {
00451     I3Trigger dummy;
00452     dummy.setIdentifier(identifier);
00453 
00454     set<I3Trigger>::iterator it = insertedTriggers.lower_bound(dummy);
00455     if (it == insertedTriggers.end()) return; /* no matches */
00456 
00457     for (; it != insertedTriggers.end() && it->getIdentifier() == identifier; it++) {
00458         removeTrigger(*it);
00459     }
00460 }

I3Identifier I3BaseApp::retrieveClosestIdentifier (  )  [protected]

Definition at line 344 of file I3BaseApp.cc.

Referenced by I3HostMobility::handleTimerEvent(), I3LatencyStretch::initializeI3(), and I3HostMobility::initializeI3().

00345 {
00346     simtime_t time;
00347     I3Identifier id;
00348     map<I3Identifier, I3CachedServer>::iterator mit;
00349     I3IPAddress myAddress(nodeIPAddress, par("clientPort"));
00350 
00351     time = MAXTIME;
00352     for (mit = samplingCache.begin(); mit != samplingCache.end(); mit++) {
00353         if (time > mit->second.roundTripTime) {
00354             time = mit->second.roundTripTime;
00355             id = mit->first;
00356         }
00357     }
00358     samplingCache.erase(id);
00359 
00360     I3Identifier rid;
00361     rid.createRandomKey();
00362 
00363     ostringstream os;
00364     os << myAddress << " sample";
00365     rid.setName(os.str());
00366 
00367     samplingCache[rid] = I3CachedServer(); // placeholder
00368     insertTrigger(rid, false);
00369 
00370     return id;
00371 }

void I3BaseApp::sendPacket ( const I3IdentifierStack stack,
cPacket *  msg,
bool  useHint = false 
) [protected]

Routes a packet through I3.

Parameters:
stack Destination identifier stack
msg Message to be sent
useHint Use address in server cache if existant

Definition at line 381 of file I3BaseApp.cc.

00382 {
00383     I3SendPacketMessage *smsg;
00384 
00385     smsg = new I3SendPacketMessage();
00386     smsg->setBitLength(SEND_PACKET_L(smsg));
00387     smsg->encapsulate(msg);
00388     smsg->setIdentifierStack(stack);
00389 
00390     smsg->setSendReply(useHint);
00391     if (useHint) {
00392         I3IPAddress add(nodeIPAddress, par("clientPort"));
00393         smsg->setSource(add);
00394     }
00395 
00396     numSent++;
00397     sentBytes += smsg->getByteLength();
00398 
00399     I3SubIdentifier subid = stack.peek(); // first check where the packet should go
00400     if (subid.getType() == I3SubIdentifier::IPAddress) { // if it's an IP address
00401         smsg->getIdentifierStack().pop(); // pop it
00402         sendThroughUDP(smsg, subid.getIPAddress()); // and send directly to host
00403     } else { // else if it's an identifier
00404         // check if we have the I3 server cached
00405         I3IPAddress address = (useHint && identifierCache.count(subid.getIdentifier()) != 0) ?
00406                               identifierCache[subid.getIdentifier()].address :
00407                               gateway.address;
00408         sendThroughUDP(smsg, address); // send it directly
00409     }
00410 }

void I3BaseApp::sendPacket ( const I3Identifier id,
cPacket *  msg,
bool  useHint = false 
) [protected]

Routes a packet through I3, passing an identifier stack composed of a single identifier.

Parameters:
id Destination identifier
msg Message to be sent
useHint Use address in server cache if existant

Definition at line 373 of file I3BaseApp.cc.

Referenced by I3Composite::createMessage(), I3Triggers::deliver(), I3SessionClient::deliver(), I3SessionServer::deliver(), I3LatencyStretch::deliver(), I3HostMobility::deliver(), I3Composite::deliver(), I3Anycast::deliver(), I3HostMobility::discoverPartners(), I3Triggers::handleTimerEvent(), I3SessionClient::handleTimerEvent(), I3Multicast::handleTimerEvent(), I3LatencyStretch::handleTimerEvent(), I3HostMobility::handleTimerEvent(), I3Anycast::handleTimerEvent(), and I3SessionClientStarter::initializeI3().

00374 {
00375     I3IdentifierStack stack;
00376 
00377     stack.push(id);
00378     sendPacket(stack, msg, useHint);
00379 }

void I3BaseApp::sendThroughUDP ( cMessage *  msg,
const I3IPAddress ip 
) [protected]

Sends a message through UDP.

Parameters:
msg Message to be sent
ip IP of destination

Definition at line 248 of file I3BaseApp.cc.

Referenced by I3TRTClient::handleTimerEvent(), I3LatencyStretch::handleTimerEvent(), insertTrigger(), removeTrigger(), sendPacket(), and sendToI3().

00249 {
00250     msg->removeControlInfo();
00251     msg->setKind(UDP_C_DATA);
00252 
00253     UDPControlInfo* udpControlInfo = new UDPControlInfo();
00254     udpControlInfo->setSrcAddr(nodeIPAddress);
00255     udpControlInfo->setSrcPort(par("clientPort"));
00256 
00257     udpControlInfo->setDestAddr(add.getAddress());
00258     udpControlInfo->setDestPort(add.getPort());
00259 
00260     msg->setControlInfo(udpControlInfo);
00261     send(msg, "udpOut");
00262 }

void I3BaseApp::sendToI3 ( I3Message *  msg  )  [protected]

Sends a message to I3.

Parameters:
msg Message to be sent

Definition at line 243 of file I3BaseApp.cc.

00244 {
00245     sendThroughUDP(msg, gateway.address);
00246 }


Member Data Documentation

cMessage* I3BaseApp::bootstrapTimer [protected]

Definition at line 102 of file I3BaseApp.h.

Referenced by handleMessage(), and initialize().

Definition at line 88 of file I3BaseApp.h.

Referenced by handleUDPMessage(), initialize(), refreshTriggers(), and sendPacket().

cMessage* I3BaseApp::initializeTimer [protected]

Definition at line 100 of file I3BaseApp.h.

Referenced by handleMessage(), and initialize().

std::set<I3Trigger> I3BaseApp::insertedTriggers [protected]

Stored I3 triggers sent from this node, to be refreshed automatically.

Definition at line 84 of file I3BaseApp.h.

Referenced by getInsertedTriggers(), initialize(), insertTrigger(), refreshTriggers(), and removeTrigger().

Definition at line 216 of file I3BaseApp.h.

Referenced by initialize().

IPvXAddress I3BaseApp::nodeIPAddress [protected]
int I3BaseApp::numIsolations [protected]

Number of times this node has been isolated - i.e.

without any I3 servers known

Definition at line 78 of file I3BaseApp.h.

Referenced by initialize(), and refreshTriggers().

int I3BaseApp::numReceived [protected]

Number of received messages.

Definition at line 73 of file I3BaseApp.h.

Referenced by handleUDPMessage(), and initialize().

int I3BaseApp::numSent [protected]

Number of sent messages.

Definition at line 68 of file I3BaseApp.h.

Referenced by initialize(), and sendPacket().

int I3BaseApp::receivedBytes [protected]

Definition at line 75 of file I3BaseApp.h.

Referenced by handleUDPMessage(), and initialize().

Definition at line 98 of file I3BaseApp.h.

Referenced by bootstrapI3(), and handleMessage().

cMessage* I3BaseApp::refreshSamplesTimer [protected]

Definition at line 96 of file I3BaseApp.h.

Referenced by bootstrapI3(), and handleMessage().

Definition at line 94 of file I3BaseApp.h.

Referenced by bootstrapI3(), and handleMessage().

cMessage* I3BaseApp::refreshTriggersTimer [protected]

Definition at line 92 of file I3BaseApp.h.

Referenced by bootstrapI3(), and handleMessage().

int I3BaseApp::sentBytes [protected]

Definition at line 70 of file I3BaseApp.h.

Referenced by initialize(), and sendPacket().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3