Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes

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.

                         {
        I3_MOBILITY_BEFORE_UPDATE,
        I3_MOBILITY_UPDATED
    };


Constructor & Destructor Documentation

I3BaseApp::I3BaseApp (  ) 

Constructor.

Definition at line 58 of file I3BaseApp.cc.

{
}

I3BaseApp::~I3BaseApp (  ) 

Destructor.

Definition at line 62 of file I3BaseApp.cc.

{
}


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().

{
    I3IPAddress myAddress(nodeIPAddress, par("clientPort"));

    // TODO: use BootstrapList instead of GlobalNodeList
    const NodeHandle handle = GlobalNodeListAccess().get()->getBootstrapNode();
    gateway.address = I3IPAddress(handle.getIp(), par("serverPort"));

    int cacheSize = par("cacheSize");
    for (int i = 0; i < cacheSize; i++) {
        I3Identifier id;

        id.createRandomKey();

        ostringstream os;
        os << myAddress << " sample" << i;
        id.setName(os.str());

        samplingCache[id] = I3CachedServer(); // placeholder

        insertTrigger(id, false);
    }

    refreshTriggersTimer = new cMessage();
    refreshTriggersTime = par("triggerRefreshTime");
    scheduleAt(simTime() + truncnormal(refreshTriggersTime, refreshTriggersTime / 10),
               refreshTriggersTimer);

    refreshSamplesTimer = new cMessage();
    refreshSamplesTime = par("sampleRefreshTime");
    scheduleAt(simTime() + truncnormal(refreshSamplesTime, refreshSamplesTime / 10),
               refreshSamplesTimer);
}

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().

{
    delete msg;
}

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

Reimplemented in I3HostMobility.

Definition at line 547 of file I3BaseApp.cc.

{
}

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

Returns the list of inserted triggers.

Definition at line 472 of file I3BaseApp.cc.

{
    return insertedTriggers;
}

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

Handles incoming messages.

Parameters:
msg Incoming message

Definition at line 160 of file I3BaseApp.cc.

{
    if (msg->isSelfMessage()) {
        if (msg == bootstrapTimer) {
            bootstrapI3();
            delete msg;
            bootstrapTimer = 0;
        } else if (msg == initializeTimer)  {
            initializeI3();
            delete msg;
            initializeTimer = 0;
        } else if (msg == refreshTriggersTimer) {
            refreshTriggers();
            scheduleAt(simTime() + truncnormal(refreshTriggersTime, refreshTriggersTime / 10),
                       refreshTriggersTimer);
        } else if (msg == refreshSamplesTimer) {
            refreshSamples();
            scheduleAt(simTime() + truncnormal(refreshSamplesTime, refreshSamplesTime / 10),
                       refreshSamplesTimer);
        } else {
            handleTimerEvent(msg);
        }
    } else if (msg->arrivedOn("udpIn")) {
        handleUDPMessage(msg);
    } else {
        delete msg;
    }
}

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().

{
    delete msg;
}

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().

{
    I3Message *i3msg;

    i3msg = dynamic_cast<I3Message*>(msg);
    if (i3msg) {
        switch (i3msg->getType()) {
        case SEND_PACKET:
        {
            I3SendPacketMessage *smsg;

            smsg = check_and_cast<I3SendPacketMessage*>(msg);
            numReceived++;
            receivedBytes += smsg->getByteLength();

            /* deliver to app */
            cPacket *newMessage = smsg->decapsulate();
            deliver(smsg->getMatchedTrigger(), smsg->getIdentifierStack(), newMessage);

            break;
        }
        case QUERY_REPLY:
        {
            I3QueryReplyMessage *pmsg;
            pmsg = check_and_cast<I3QueryReplyMessage*>(msg);
            I3Identifier &id = pmsg->getIdentifier();

            identifierCache[id].address = pmsg->getSource();
            identifierCache[id].lastReply = simTime();
            identifierCache[id].roundTripTime = simTime() - pmsg->getSendingTime();

            if (samplingCache.count(id) != 0) {
                samplingCache[id] = identifierCache[id];
            }
            break;
        }
        default:
            /* shouldn't get here */
            break;
        }
    }
    delete msg;
}

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

Basic initialization.

Definition at line 71 of file I3BaseApp.cc.

{
    if (stage != MIN_STAGE_APP) return;

    nodeIPAddress = IPAddressResolver().addressOf(getParentModule());

    bindToPort(par("clientPort"));
    /*    NotificationBoardAccess().get()->subscribe(this, NF_HOSTPOSITION_BEFOREUPDATE);
        NotificationBoardAccess().get()->subscribe(this, NF_HOSTPOSITION_UPDATED);*/

    getDisplayString().setTagArg("i", 0, "i3c");
    getParentModule()->getDisplayString().removeTag("i2");

    if (int(par("bootstrapTime")) >= int(par("initTime"))) {
        opp_error("Parameter bootstrapTime must be smaller than initTime");
    }

    bootstrapTimer = new cMessage();
    scheduleAt(simTime() + int(par("bootstrapTime")), bootstrapTimer);

    initializeTimer = new cMessage();
    scheduleAt(simTime() + int(par("initTime")), initializeTimer);

    numSent = 0;
    sentBytes = 0;
    numReceived = 0;
    receivedBytes = 0;
    numIsolations = 0;
    mobilityInStages = false;

    WATCH(nodeIPAddress);
    WATCH(numSent);
    WATCH(sentBytes);
    WATCH(numReceived);
    WATCH(receivedBytes);
    WATCH(numIsolations);


    WATCH_SET(insertedTriggers);
    WATCH(gateway);
    WATCH_MAP(samplingCache);
    WATCH_MAP(identifierCache);

    initializeApp(stage);
}

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().

{
}

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().

{

}

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().

{
    I3Trigger trigger;
    I3IPAddress add(nodeIPAddress, par("clientPort"));;

    trigger.getIdentifierStack().push(add);
    trigger.setIdentifier(identifier);
    insertTrigger(trigger, store);
}

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.

{
    I3Trigger trigger;

    trigger.setIdentifier(identifier);
    trigger.getIdentifierStack() = stack;
    insertTrigger(trigger, store);
}

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.

                                                            {

    if (store) {
        if (insertedTriggers.count(t) != 0) return;
        insertedTriggers.insert(t);
    }

    I3InsertTriggerMessage *msg = new I3InsertTriggerMessage();
    I3IPAddress myAddress(nodeIPAddress, par("clientPort"));

    msg->setTrigger(t);
    msg->setSendReply(true);
    msg->setSource(myAddress);
    msg->setBitLength(INSERT_TRIGGER_L(msg));

    sendThroughUDP(msg, gateway.address);
}

int I3BaseApp::numInitStages (  )  const [protected]

Returns number of init stages required.

Definition at line 66 of file I3BaseApp.cc.

{
    return MAX_STAGE_APP + 1;
}

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

Definition at line 477 of file I3BaseApp.cc.

{
    Enter_Method_Silent();

    /* Mobility is happening (the only event we are subscribed to). We have two things to do:
    * 1) Insert triggers with new IP
    * 2) Delete triggers with old IP
    * If it's one staged mobility, we just get told the IP after it's changed, and we need to make sure
    * step 1 and 2 are done. If it's two staged mobility, we need to make sure we do step 1 first and then
    * step 2. */

//     if (!mobilityInStages) { /* if the flag isn't set, mobility isn't done in stages or this is stage 1 */
//         if (category == NF_HOSTPOSITION_BEFOREUPDATE) {
//             mobilityInStages = true; /* set the flag so we don't land here in stage 2 again */
//         }
//         /* do part 1! */
//         cMessage *msg = check_and_cast<cMessage*>(details);
//         IPvXAddress *ipAddr = (IPvXAddress*)msg->getContextPointer();
//
//         ostringstream os;
//         os << "Mobility first stage - actual IP is " << nodeIPAddress << ", future IP is " << *ipAddr << endl;
//         getParentModule()->bubble(os.str().c_str());
//
//         std::cout << "In advance from " << nodeIPAddress << " to " << *ipAddr << endl;
//         I3IPAddress oldAddress(nodeIPAddress, par("clientPort"));
//         I3IPAddress newAddress(*ipAddr, par("clientPort"));
//
//         delete ipAddr;
//         delete msg;
//
//         for (set<I3Trigger>::iterator it = insertedTriggers.begin(); it != insertedTriggers.end(); it++) {
//             I3Trigger trigger(*it); /* create copy */
//             trigger.getIdentifierStack().replaceAddress(oldAddress, newAddress); /* replace old address with new */
//             insertTrigger(trigger, false); /* insert trigger in I3, but don't store it in our list yet - that's done in part 2 */
//         }
//
//         doMobilityEvent(I3_MOBILITY_BEFORE_UPDATE);
//     }
//     if (category == NF_HOSTPOSITION_UPDATED) { /* part 2: both for 1-stage and stage 2 of 2-stage mobility */
//         I3IPAddress oldAddress(nodeIPAddress, par("clientPort"));
//         nodeIPAddress = IPAddressResolver().addressOf(getParentModule()).get4();
//         I3IPAddress newAddress(nodeIPAddress, par("clientPort"));
//
//         cout << "After from " << oldAddress << " to " << newAddress << endl;
//
//         ostringstream os;
//         os << "Mobility second stage - setting IP as " << newAddress << endl;
//         getParentModule()->bubble(os.str().c_str());
//
//         set<I3Trigger> newSet; /* list of new triggers (that we already inserted in I3 in stage 1) */
//
//         for (set<I3Trigger>::iterator it = insertedTriggers.begin(); it != insertedTriggers.end(); it++) {
//             I3Trigger trigger(*it); /* create copy */
//
//             trigger.getIdentifierStack().replaceAddress(oldAddress, newAddress); /* replace old address with new */
//             newSet.insert(trigger); /* insert in new list */
//
//             removeTrigger(*it);  /* remove trigger from I3 and out list */
//
//         }
//         insertedTriggers = newSet; /* replace old list with updated one */
//
//         mobilityInStages = false; /* reset variable */
//         refreshTriggers(); /* to get new trigger round-trip times, new cache list */
//      refreshSamples();
//
//         doMobilityEvent(I3_MOBILITY_UPDATED);
//     }
}

void I3BaseApp::refreshSamples (  )  [protected]

Refreshes sampling triggers and selects fastest server as gateway.

Definition at line 332 of file I3BaseApp.cc.

Referenced by handleMessage().

                               {
    map<I3Identifier, I3CachedServer>::iterator mit;

    EV << "I3BaseApp::refreshSamples()]\n"
       << "    Refresh samples!"
       << endl;
    /* reinsert sample triggers */
    for (mit = samplingCache.begin(); mit != samplingCache.end(); mit++) {
        insertTrigger(mit->first, false);
    }
}

void I3BaseApp::refreshTriggers (  )  [protected]

Refreshes (reinserts) stored triggers.

Definition at line 264 of file I3BaseApp.cc.

Referenced by handleMessage().

{
    I3IPAddress myAddress(nodeIPAddress, par("clientPort"));
    map<I3Identifier, I3CachedServer>::iterator mit;


    // pick fastest I3 server as gateway
    int serverTimeout = par("serverTimeout");
    gateway.roundTripTime = serverTimeout;
    I3Identifier gatewayId;
    for (mit = samplingCache.begin(); mit != samplingCache.end(); mit++) {
        if (gateway.roundTripTime > mit->second.roundTripTime) {
            gatewayId = mit->first;
            gateway = mit->second;
        }
    }

    // check if gateway has timeout'ed
    if (simTime() - gateway.lastReply >= serverTimeout) {
        // We have a small problem here: if the fastest server has timeout,
        // that means the previous gateway had stopped responding some time before and no triggers were refreshed.
        // 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.
        int random = intrand(samplingCache.size()), i;

        EV << "I3BaseApp::refreshTriggers()]\n"
           << "    Gateway timeout at " << nodeIPAddress
           << ", time " << simTime()
           << "; expired gateway is " << gateway << "(" << gatewayId << ") "
           << " with last reply at " << gateway.lastReply
           << endl;

        for (i = 0, mit = samplingCache.begin(); i < random; i++, mit++);
        gateway = mit->second;
        EV << "I3BaseApp::refreshTriggers()]\n"
           << "    New gateway for " << nodeIPAddress << " is " << gateway
           << endl;

        if (gateway.roundTripTime > 2 * serverTimeout) {
            EV << "I3BaseApp::refreshTriggers()]\n"
               << "    New gateway's (" << gateway << ") rtt for " << nodeIPAddress
               << " too high... marking as isolated!"
               << endl;
            numIsolations++;
            const NodeHandle handle = GlobalNodeListAccess().get()->getBootstrapNode();
            gateway.address = I3IPAddress(handle.getIp(), par("serverPort"));
        }
    }

    /* ping gateway */
    insertTrigger(gatewayId, false);
//    cout << "Client " << nodeIPAddress << " pings " << gatewayId << endl;

    /* reinsert stored triggers */
    set<I3Trigger>::iterator it;
    for (it = insertedTriggers.begin(); it != insertedTriggers.end(); it++) {
        insertTrigger(*it, false);
    }

    /* now that we are refreshing stuff, might as well erase old identifier cache entries */
    int idStoreTime = par("idStoreTime");
    for (mit = identifierCache.begin(); mit != identifierCache.end(); mit++) {
        if (mit->second.lastReply - simTime() > idStoreTime) {
            identifierCache.erase(mit);
        }
    }

}

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.

{
    I3RemoveTriggerMessage *msg = new I3RemoveTriggerMessage();
    msg->setTrigger(t);
    msg->setBitLength(REMOVE_TRIGGER_L(msg));
    sendThroughUDP(msg, gateway.address);

    insertedTriggers.erase(t);
}

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().

{
    I3Trigger dummy;
    dummy.setIdentifier(identifier);

    set<I3Trigger>::iterator it = insertedTriggers.lower_bound(dummy);
    if (it == insertedTriggers.end()) return; /* no matches */

    for (; it != insertedTriggers.end() && it->getIdentifier() == identifier; it++) {
        removeTrigger(*it);
    }
}

I3Identifier I3BaseApp::retrieveClosestIdentifier (  )  [protected]

Definition at line 344 of file I3BaseApp.cc.

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

{
    simtime_t time;
    I3Identifier id;
    map<I3Identifier, I3CachedServer>::iterator mit;
    I3IPAddress myAddress(nodeIPAddress, par("clientPort"));

    time = MAXTIME;
    for (mit = samplingCache.begin(); mit != samplingCache.end(); mit++) {
        if (time > mit->second.roundTripTime) {
            time = mit->second.roundTripTime;
            id = mit->first;
        }
    }
    samplingCache.erase(id);

    I3Identifier rid;
    rid.createRandomKey();

    ostringstream os;
    os << myAddress << " sample";
    rid.setName(os.str());

    samplingCache[rid] = I3CachedServer(); // placeholder
    insertTrigger(rid, false);

    return id;
}

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.

{
    I3SendPacketMessage *smsg;

    smsg = new I3SendPacketMessage();
    smsg->setBitLength(SEND_PACKET_L(smsg));
    smsg->encapsulate(msg);
    smsg->setIdentifierStack(stack);

    smsg->setSendReply(useHint);
    if (useHint) {
        I3IPAddress add(nodeIPAddress, par("clientPort"));
        smsg->setSource(add);
    }

    numSent++;
    sentBytes += smsg->getByteLength();

    I3SubIdentifier subid = stack.peek(); // first check where the packet should go
    if (subid.getType() == I3SubIdentifier::IPAddress) { // if it's an IP address
        smsg->getIdentifierStack().pop(); // pop it
        sendThroughUDP(smsg, subid.getIPAddress()); // and send directly to host
    } else { // else if it's an identifier
        // check if we have the I3 server cached
        I3IPAddress address = (useHint && identifierCache.count(subid.getIdentifier()) != 0) ?
                              identifierCache[subid.getIdentifier()].address :
                              gateway.address;
        sendThroughUDP(smsg, address); // send it directly
    }
}

void I3BaseApp::sendPacket ( const I3Identifier id,
cPacket *  msg,
bool  useHint = false 
) [protected]
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().

{
    msg->removeControlInfo();
    msg->setKind(UDP_C_DATA);

    UDPControlInfo* udpControlInfo = new UDPControlInfo();
    udpControlInfo->setSrcAddr(nodeIPAddress);
    udpControlInfo->setSrcPort(par("clientPort"));

    udpControlInfo->setDestAddr(add.getIp());
    udpControlInfo->setDestPort(add.getPort());

    msg->setControlInfo(udpControlInfo);
    send(msg, "udpOut");
}

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.


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().

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: