I3SessionClient Class Reference

Inheritance diagram for I3SessionClient:

I3BaseApp I3SessionClientStarter

List of all members.

Public Member Functions

void initializeApp (int stage)
 App initialization - should be overwritten by application.
virtual void initializeI3 ()
 Application I3 initialize - should be overwritten by application.
void deliver (I3Trigger &trigger, I3IdentifierStack &stack, cMessage *msg)
 Delivers packets coming from I3 - should be overwritten by application.
void handleTimerEvent (cMessage *msg)
 Handles timers - should be overwritten by application.
void finish ()

Public Attributes

cStdDev myStats [NUM_STATS]
int numForeignPackets
int numSessions
int numExchanged
bool holdsSession
double actualValue
I3Identifier clientIdentifier
I3Identifier serverIdentifier
I3Identifier poolIdentifier


Member Function Documentation

void I3SessionClient::initializeApp ( int  stage  )  [virtual]

App initialization - should be overwritten by application.

I3 related commands should go in initializeI3.

Parameters:
stage Initialization stage passed from initialize()

Reimplemented from I3BaseApp.

00106 {
00107     holdsSession = false;
00108     numForeignPackets = 0;
00109     numSessions = 0;
00110     numExchanged = 0;
00111     WATCH(numForeignPackets);
00112     clientIdentifier.createFromHash("Client");
00113     serverIdentifier.createFromHash("Server");
00114 }

void I3SessionClient::initializeI3 (  )  [virtual]

Application I3 initialize - should be overwritten by application.

Reimplemented from I3BaseApp.

Reimplemented in I3SessionClientStarter.

Referenced by I3SessionClientStarter::initializeI3().

void I3SessionClient::deliver ( I3Trigger trigger,
I3IdentifierStack stack,
cMessage *  msg 
) [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 from I3BaseApp.

00123 {
00124     SessionMsg *smsg = check_and_cast<SessionMsg*>(msg);
00125 
00126     if (smsg->getType() == PAYLOAD) {
00127         if (holdsSession) {
00128             //std::cout << "Got value " << smsg->getValue() << ", resending..." << endl;
00129             numExchanged++;
00130             actualValue = smsg->getValue();
00131             sendPacket(serverIdentifier, msg);
00132         } else {
00133             numForeignPackets++;
00134             //std::cout << "Foreign packet at " << nodeIPAddress << endl;
00135             delete msg;
00136         }
00137 
00138     } else if (smsg->getType() == CHANGE_SESSION) {
00139 
00140         //cout << "Insert new trigger" << nodeIPAddress << endl;
00141         /* resume session */
00142         insertTrigger(clientIdentifier, int(par("sessionMobilityType")) != DONT_REMOVE); // renew only if type != DONT_REMOVE
00143         holdsSession = true;
00144 
00145         SessionMsg *newMsg = new SessionMsg();
00146         newMsg->setType(PAYLOAD);
00147         newMsg->setValue(smsg->getValue());
00148         sendPacket(serverIdentifier, newMsg);
00149 
00150         if (int(par("sessionMobilityType")) == WAIT_CONFIRMATION) {
00151             // send confirmation
00152             SessionMsg *newMsg = new SessionMsg();
00153             newMsg->setType(TRIGGER_CONFIRMATION);
00154             newMsg->setValue(0);
00155             newMsg->setSource(poolIdentifier);
00156             sendPacket(smsg->getSource(), newMsg);
00157         }
00158         delete smsg;
00159 
00160         cMessage *msg = new cMessage();
00161         msg->setKind(TYPE_CHANGE_SESSION);
00162         scheduleAt(simulation.simTime() + int(par("sessionTime")), msg);
00163         numSessions++;
00164 
00165         parentModule()->bubble("Got session!");
00166 
00167     } else if (smsg->getType() == TRIGGER_CONFIRMATION) { // only for WAIT_CONFIRMATION
00168         removeTrigger(clientIdentifier);
00169         parentModule()->bubble("Got confirmation for erase.");
00170         delete smsg;
00171 
00172     } else {
00173         // ??
00174         delete smsg;
00175     }
00176 }

void I3SessionClient::handleTimerEvent ( cMessage *  msg  )  [virtual]

Handles timers - should be overwritten by application.

Parameters:
msg Timer to be handled

Reimplemented from I3BaseApp.

00185                                                     {
00186     if (msg->kind() == TYPE_CHANGE_SESSION) {
00187         myStats[STAT_CHANGE].collect(simulation.simTime());
00188         switch (int(par("sessionMobilityType"))) {
00189         case DONT_REMOVE:
00190         case WAIT_CONFIRMATION:
00191             break;
00192         case REMOVE_AT_ONCE:
00193             removeTrigger(clientIdentifier);
00194             break;
00195         case WAIT_STATIC:
00196             cMessage *msg = new cMessage();
00197             msg->setKind(TYPE_REMOVE_TRIGGER);
00198             scheduleAt(simulation.simTime() + int(par("sessionMobilityWait")), msg);
00199             break;
00200         }
00201         holdsSession = false;
00202 
00203         /* cede session */
00204         I3Identifier sessionId;
00205 
00206         sessionId.createFromHash("Pool");
00207         sessionId.createRandomSuffix();
00208 
00209         SessionMsg *newMsg = new SessionMsg();
00210         newMsg->setType(CHANGE_SESSION);
00211         newMsg->setValue(actualValue);
00212         newMsg->setSource(poolIdentifier);
00213         sendPacket(sessionId, newMsg);
00214 
00215         parentModule()->bubble("Ceding session...");
00216         delete msg;
00217 
00218     } else if (msg->kind() == TYPE_REMOVE_TRIGGER) { // for WAIT_STATIC only
00219         parentModule()->bubble("Timer ticked for erase.");
00220         removeTrigger(clientIdentifier);
00221         //cout << "Delete old trigger " << nodeIPAddress << endl;
00222         delete msg;
00223     }
00224 }

void I3SessionClient::finish (  ) 

00178                              {
00179     recordScalar("Client packets received", numExchanged);
00180     recordScalar("Client wrong received  ", numForeignPackets);
00181     recordScalar("Client session changed ", numSessions);
00182 
00183 }


Member Data Documentation

cStdDev I3SessionClient::myStats[NUM_STATS]

Referenced by handleTimerEvent().

Referenced by deliver(), finish(), and initializeApp().

Referenced by deliver(), finish(), and initializeApp().

Referenced by deliver(), finish(), and initializeApp().

Referenced by deliver(), and handleTimerEvent().


The documentation for this class was generated from the following file:

Generated on Fri Sep 19 13:05:07 2008 for ITM OverSim by  doxygen 1.5.5