OverSim
MyApplication Class Reference

#include <MyApplication.h>

Inheritance diagram for MyApplication:
BaseApp BaseRpc BaseTcpSupport RpcListener

Public Member Functions

 MyApplication ()
 ~MyApplication ()
- Public Member Functions inherited from BaseApp
 BaseApp ()
virtual ~BaseApp ()
 virtual destructor
- Public Member Functions inherited from BaseRpc
 BaseRpc ()
const NodeHandlegetThisNode ()
 Returns the NodeHandle of this node.
simtime_t getUdpTimeout ()
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor
- Public Member Functions inherited from BaseTcpSupport
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent)
virtual void socketEstablished (int connId, void *yourPtr)
virtual void socketPeerClosed (int connId, void *yourPtr)
virtual void socketFailure (int connId, void *yourPtr, int code)
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)

Private Member Functions

void initializeApp (int stage)
void finishApp ()
void handleTimerEvent (cMessage *msg)
void deliver (OverlayKey &key, cMessage *msg)
void handleUDPMessage (cMessage *msg)

Private Attributes

simtime_t sendPeriod
int numToSend
int largestKey
int numSent
int numReceived
cMessage * timerMsg

Additional Inherited Members

- Public Types inherited from BaseTcpSupport
enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}
- Protected Member Functions inherited from BaseApp
int numInitStages () const
 method to set InitStage
void initialize (int stage)
 initializes base class-attributes
virtual void initializeApp (int stage)
 initializes derived class-attributes
void handleMessage (cMessage *msg)
 checks for message type and calls corresponding method
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 callback-method for events at the NotificationBoard
virtual void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
virtual void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
void finish ()
 collects statistical data
virtual void finishApp ()
 collects statistical data of derived app
void callRoute (const OverlayKey &key, cPacket *msg, const TransportAddress &hint=TransportAddress::UNSPECIFIED_NODE, RoutingType routingType=DEFAULT_ROUTING)
 Common API function: calls route-method in overlay.
void callRoute (const OverlayKey &key, cPacket *msg, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType=DEFAULT_ROUTING)
virtual void deliver (OverlayKey &key, cMessage *msg)
 Common API function: handles delivered messages from overlay.
virtual void forward (OverlayKey *key, cPacket **msg, NodeHandle *nextHopNode)
 Common API function: handles messages from overlay to be forwarded.
virtual void update (const NodeHandle &node, bool joined)
 Common API function: informs application about neighbors and own nodeID.
NodeVectorcallLocalLookup (const OverlayKey &key, int num, bool safe)
 Common API function: produces a list of nodes that can be used as next hops towards key.
NodeVectorcallNeighborSet (int num)
 Common API function: produces a list of neighbor nodes.
bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
 Query if a node is among the siblings for a given key.
virtual void handleLowerMessage (cMessage *msg)
 processes self-messages
virtual void handleUpperMessage (cMessage *msg)
 handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
virtual void handleUDPMessage (cMessage *msg)
 method to handle messages that come directly from the UDP gate
virtual void handleReadyMessage (CompReadyMessage *msg)
 method to handle ready messages from the overlay
virtual void bindToPort (int port)
 Tells UDP we want to get all packets arriving on the given port.
virtual void sendMessageToUDP (const TransportAddress &destAddr, cPacket *msg, simtime_t delay=SIMTIME_ZERO)
 Sends a packet over UDP.
virtual void handleTraceMessage (cMessage *msg)
 handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
void sendMessageToLowerTier (cPacket *msg)
 sends non-commonAPI message to the lower tier
bool internalHandleRpcCall (BaseCallMessage *msg)
 Handles internal rpc requests.
void internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes

void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
virtual CompType getThisCompType ()
 Return the component type of this module.
void sendReadyMessage (bool ready=true, const OverlayKey &nodeId=OverlayKey::UNSPECIFIED_KEY)
- Protected Attributes inherited from BaseApp
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
NotificationBoard * notificationBoard
 pointer to NotificationBoard in this node
bool debugOutput
 debug output yes/no?
int numOverlaySent
 number of sent packets to overlay
int bytesOverlaySent
 number of sent bytes to overlay
int numOverlayReceived
 number of received packets from overlay
int bytesOverlayReceived
 number of received bytes from overlay
int numUdpSent
 number of sent packets to UDP
int bytesUdpSent
 number of sent bytes to UDP
int numUdpReceived
 number of received packets from UDP
int bytesUdpReceived
 number of received bytes from UDP
simtime_t creationTime
 simTime when the App has been created

Detailed Description

Author
Antonio Zea

Definition at line 31 of file MyApplication.h.

Constructor & Destructor Documentation

MyApplication::MyApplication ( )
inline

Definition at line 53 of file MyApplication.h.

{ timerMsg = NULL; };
MyApplication::~MyApplication ( )
inline

Definition at line 54 of file MyApplication.h.

{ cancelAndDelete(timerMsg); };

Member Function Documentation

void MyApplication::deliver ( OverlayKey key,
cMessage *  msg 
)
private

Definition at line 117 of file MyApplication.cc.

{
// we are only expecting messages of type MyMessage, throw away any other
MyMessage *myMsg = dynamic_cast<MyMessage*>(msg);
if (myMsg == NULL) {
delete msg; // type unknown!
return;
}
// are we a PING? send a PONG!
if (myMsg->getType() == MYMSG_PING) {
myMsg->setType(MYMSG_PONG); // change type
EV << thisNode.getIp() << ": Got packet from "
<< myMsg->getSenderAddress() << ", sending back!"
<< std::endl;
// send it back to its owner
} else {
// only handle PING messages
delete msg;
}
}
void MyApplication::finishApp ( )
private

Definition at line 67 of file MyApplication.cc.

{
// finish() is usually used to save the module's statistics.
// We'll use globalStatistics->addStdDev(), which will calculate min, max, mean and deviation values.
// The first parameter is a name for the value, you can use any name you like (use a name you can find quickly!).
// In the end, the simulator will mix together all values, from all nodes, with the same name.
globalStatistics->addStdDev("MyApplication: Sent packets", numSent);
globalStatistics->addStdDev("MyApplication: Received packets", numReceived);
}
void MyApplication::handleTimerEvent ( cMessage *  msg)
private

Definition at line 80 of file MyApplication.cc.

{
// is this our timer?
if (msg == timerMsg) {
// reschedule our message
scheduleAt(simTime() + sendPeriod, timerMsg);
// if the simulator is still busy creating the network,
// let's wait a bit longer
for (int i = 0; i < numToSend; i++) {
// let's create a random key
OverlayKey randomKey(intuniform(1, largestKey));
MyMessage *myMessage; // the message we'll send
myMessage = new MyMessage();
myMessage->setType(MYMSG_PING); // set the message type to PING
myMessage->setSenderAddress(thisNode); // set the sender address to our own
myMessage->setByteLength(100); // set the message length to 100 bytes
numSent++; // update statistics
EV << thisNode.getIp() << ": Sending packet to "
<< randomKey << "!" << std::endl;
callRoute(randomKey, myMessage); // send it to the overlay
}
} else {
// unknown message types are discarded
delete msg;
}
}
void MyApplication::handleUDPMessage ( cMessage *  msg)
private

Definition at line 144 of file MyApplication.cc.

{
// we are only expecting messages of type MyMessage
MyMessage *myMsg = dynamic_cast<MyMessage*>(msg);
if (myMsg && myMsg->getType() == MYMSG_PONG) {
EV << thisNode.getIp() << ": Got reply!" << std::endl;
}
// Message isn't needed any more -> delete it
delete msg;
}
void MyApplication::initializeApp ( int  stage)
private

Definition at line 36 of file MyApplication.cc.

{
// initializeApp will be called twice, each with a different stage.
// stage can be either MIN_STAGE_APP (this module is being created),
// or MAX_STAGE_APP (all modules were created).
// We only care about MIN_STAGE_APP here.
if (stage != MIN_STAGE_APP) return;
// copy the module parameter values to our own variables
sendPeriod = par("sendPeriod");
numToSend = par("numToSend");
largestKey = par("largestKey");
// initialize our statistics variables
numSent = 0;
// tell the GUI to display our variables
WATCH(numSent);
WATCH(numReceived);
// start our timer!
timerMsg = new cMessage("MyApplication Timer");
scheduleAt(simTime() + sendPeriod, timerMsg);
bindToPort(2000);
}

Member Data Documentation

int MyApplication::largestKey
private

Definition at line 36 of file MyApplication.h.

Referenced by handleTimerEvent(), and initializeApp().

int MyApplication::numReceived
private

Definition at line 40 of file MyApplication.h.

Referenced by finishApp(), handleUDPMessage(), and initializeApp().

int MyApplication::numSent
private

Definition at line 39 of file MyApplication.h.

Referenced by finishApp(), handleTimerEvent(), and initializeApp().

int MyApplication::numToSend
private

Definition at line 35 of file MyApplication.h.

Referenced by handleTimerEvent(), and initializeApp().

simtime_t MyApplication::sendPeriod
private

Definition at line 34 of file MyApplication.h.

Referenced by handleTimerEvent(), and initializeApp().

cMessage* MyApplication::timerMsg
private

Definition at line 43 of file MyApplication.h.

Referenced by handleTimerEvent(), initializeApp(), MyApplication(), and ~MyApplication().


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