OverSim
SimpleGameClient Class Reference

SimpleGameClient class. More...

#include <SimpleGameClient.h>

Inheritance diagram for SimpleGameClient:
BaseApp BaseRpc BaseTcpSupport RpcListener

Public Member Functions

virtual ~SimpleGameClient ()
virtual void initializeApp (int stage)
 initializes derived class-attributes
virtual void handleTimerEvent (cMessage *msg)
virtual void handleLowerMessage (cMessage *msg)
 processes self-messages
virtual void handleReadyMessage (CompReadyMessage *msg)
 method to handle ready messages from the overlay
virtual void finishApp ()
 collects statistical data of derived app
Vector2D getPosition ()
double getAOI ()
bool isOverlayReady ()
NodeHandle getThisNode ()
 Returns the NodeHandle of this node.
- Public Member Functions inherited from BaseApp
 BaseApp ()
virtual ~BaseApp ()
 virtual destructor
- Public Member Functions inherited from BaseRpc
 BaseRpc ()
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)

Public Attributes

NeighborMap Neighbors

Protected Member Functions

void updateNeighbors (GameAPIListMessage *sgcMsg)
void updatePosition ()
void handleRealworldPacket (char *buf, uint32_t len)
- Protected Member Functions inherited from BaseApp
int numInitStages () const
 method to set InitStage
void initialize (int stage)
 initializes base 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
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 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 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 Member Functions inherited from BaseRpc
virtual void internalHandleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 Handles rpc timeouts internal in base classes

void initRpcs ()
 Initializes Remote-Procedure state.
void finishRpcs ()
 Deinitializes Remote-Procedure state.
virtual void internalHandleRpcMessage (BaseRpcMessage *msg)
 Handles incoming rpc messages and delegates them to the corresponding listeners or handlers.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message using the overlay's UDP port
This replaces ROUTE_DIRECT calls!
uint32_t sendUdpRpcCall (const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message to the underlay

uint32_t sendInternalRpcCall (CompType destComp, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends an internal Remote-Procedure-Call between two tiers

void cancelRpcMessage (uint32_t nonce)
 Cancels a Remote-Procedure-Call.
void cancelAllRpcs ()
 Cancels all RPCs.
void sendRpcResponse (TransportType transportType, CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message and deletes call message.
void sendRpcResponse (BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message to UDP and deletes call message.
int pingNode (const TransportAddress &dest, simtime_t timeout=-1, int retries=0, cPolymorphic *context=NULL, const char *caption="PING", RpcListener *rpcListener=NULL, int rpcId=-1, TransportType transportType=INVALID_TRANSPORT)
 ping a node by its TransportAddress
virtual bool handleRpcCall (BaseCallMessage *msg)
 Processes Remote-Procedure-Call invocation messages.
virtual void pingResponse (PingResponse *pingResponse, cPolymorphic *context, int rpcId, simtime_t rtt)
virtual void pingTimeout (PingCall *pingCall, const TransportAddress &dest, cPolymorphic *context, int rpcId)
bool internalHandleMessage (cMessage *msg)
- Protected Member Functions inherited from RpcListener
virtual void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcResponse (BaseResponseMessage *msg, const RpcState &rpcState, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 This method is called if an RPC timeout has been reached.
virtual void handleRpcTimeout (const RpcState &rpcState)
 This method is called if an RPC timeout has been reached.
- Protected Member Functions inherited from BaseTcpSupport
void handleTCPMessage (cMessage *msg)
 Member function to handle incoming TCP messages.
void bindAndListenTcp (int port)
 Member function to bind service to the specified port and listen afterwards.
bool isAlreadyConnected (TransportAddress address)
 Member function to check if the service is already connected.
void establishTcpConnection (TransportAddress address)
 Member function to establish a connection to the specified node.
void sendTcpData (cPacket *msg, TransportAddress address)
 Member function to send TCP data to the specified node.
virtual void handleConnectionEvent (EvCode code, TransportAddress address)
 Member function to handle passive connection events.
virtual void handleDataReceived (TransportAddress address, cPacket *msg, bool urgent)
 Member function to handle incoming data.
virtual void handleIncomingConnection (TransportAddress address)
 Member function to handle newly opened connections.
void closeTcpConnection (TransportAddress address)
 Member function to close an established connection.
void setTcpOut (cGate *gate)
 Member function to set local gate towards the TCP module during init phase.
cGate * getTcpOut ()
 Member function to get local gate towards the TCP module.

Protected Attributes

GlobalCoordinatorcoordinator
CollisionList CollisionRect
simtime_t movementDelay
double areaDimension
double movementSpeed
double movementRate
double AOIWidth
bool useScenery
bool overlayReady
Vector2D position
MovementGeneratorGenerator
bool logAOI
NeighborMap::iterator itNeighbors
std::string GeneratorType
cMessage * move_timer
cMessage * packetNotification
PacketBuffer packetBuffer
RealtimeSchedulerscheduler
unsigned int mtu
SOCKET appFd
bool doRealworld
bool frozen
double startAOI
bool useHotspots
bool lastInHotspot
bool lastFarFromHotspot
simtime_t lastAOImeasure
double avgAOI
simtime_t nonHotspotTime
simtime_t farFromHotspotTime
double avgFarFromHotspotAOI
simtime_t hotspotTime
double avgHotspotAOI
- 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
- Protected Attributes inherited from BaseRpc
NodeHandle thisNode
 NodeHandle to this node.
BaseOverlayoverlay
bool debugOutput
 debug output ?
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
CompType thisCompType
NeighborCacheneighborCache
 pointer to the neighbor cache
CryptoModulecryptoModule
 pointer to CryptoModule
int numPingSent
int bytesPingSent
int numPingResponseSent
int bytesPingResponseSent

Additional Inherited Members

- Public Types inherited from BaseTcpSupport
enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}

Detailed Description

SimpleGameClient class.

A simple test application, which simulates node movement based on different movement generators.

Definition at line 55 of file SimpleGameClient.h.

Constructor & Destructor Documentation

SimpleGameClient::~SimpleGameClient ( )
virtual

Definition at line 492 of file SimpleGameClient.cc.

{
// destroy self timer messages
cancelAndDelete(move_timer);
cancelAndDelete(packetNotification);
delete Generator;
}

Member Function Documentation

void SimpleGameClient::finishApp ( )
virtual

collects statistical data of derived app

Reimplemented from BaseApp.

Definition at line 476 of file SimpleGameClient.cc.

{
globalStatistics->addStdDev("SimpleGameClient: average non-hotspot AOI",
}
globalStatistics->addStdDev("SimpleGameClient: average far-from-hotspot AOI",
}
globalStatistics->addStdDev("SimpleGameClient: average hotspot AOI",
}
}
double SimpleGameClient::getAOI ( )
inline

Definition at line 67 of file SimpleGameClient.h.

{return AOIWidth;};
Vector2D SimpleGameClient::getPosition ( )
inline

Definition at line 66 of file SimpleGameClient.h.

{return position;};
NodeHandle SimpleGameClient::getThisNode ( )
inline

Returns the NodeHandle of this node.

Returns
the NodeHandle of this node.

Reimplemented from BaseRpc.

Definition at line 69 of file SimpleGameClient.h.

Referenced by ConnectivityProbeApp::extractTopology().

{return overlay->getThisNode();};
void SimpleGameClient::handleLowerMessage ( cMessage *  msg)
virtual

processes self-messages

method to handle self-messages should be overwritten in derived application if needed

Parameters
msgself-message method to handle non-commonAPI messages from the overlay
msgmessage to handle

Reimplemented from BaseApp.

Definition at line 239 of file SimpleGameClient.cc.

{
if(dynamic_cast<GameAPIMessage*>(msg)) {
GameAPIMessage* gameAPIMsg = check_and_cast<GameAPIMessage*>(msg);
if(gameAPIMsg->getCommand() == MOVEMENT_REQUEST) {
}
else if(gameAPIMsg->getCommand() == NEIGHBOR_UPDATE) {
GameAPIListMessage* gameAPIListMsg = check_and_cast<GameAPIListMessage*>(msg);
updateNeighbors(gameAPIListMsg);
}
else if(gameAPIMsg->getCommand() == RESIZE_AOI) {
GameAPIResizeAOIMessage* gameAPIResizeMsg = check_and_cast<GameAPIResizeAOIMessage*>(msg);
// Measure average AOI sizes
if( startAOI != 0 )
{
simtime_t elapsed = simTime() - lastAOImeasure;
avgHotspotAOI += AOIWidth*elapsed.dbl();
hotspotTime += elapsed;
} else {
avgAOI += AOIWidth*elapsed.dbl();
nonHotspotTime += elapsed;
avgFarFromHotspotAOI += AOIWidth*elapsed.dbl();
farFromHotspotTime += elapsed;
}
}
);
} else {
startAOI = gameAPIResizeMsg->getAOIsize();
}
lastAOImeasure = simTime();
if( useHotspots ){
lastInHotspot = dynamic_cast<hotspotRoaming*>(Generator)->getDistanceFromHotspot() <= 0;
lastFarFromHotspot = dynamic_cast<hotspotRoaming*>(Generator)->getDistanceFromHotspot() > startAOI;
}
AOIWidth = gameAPIResizeMsg->getAOIsize();
if( logAOI ){
GlobalStatisticsAccess().get()->recordOutVector( "SimpleGameClient: AOI width", AOIWidth );
}
SCAOIPacket packet;
packet.AOI = AOIWidth;
int packetlen = sizeof(SCAOIPacket);
scheduler->sendBytes((const char*)&packetlen, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)&packet, packetlen, 0, 0, true, appFd);
}
}
else if(gameAPIMsg->getCommand() == GAMEEVENT_CHAT) {
GameAPIChatMessage* chatMsg = check_and_cast<GameAPIChatMessage*>(msg);
const char* msg = chatMsg->getMsg();
int packetlen = sizeof(SCChatPacket) + strlen(msg) + 1;
SCChatPacket* pack = (SCChatPacket*)malloc(packetlen);
pack->ip = chatMsg->getSrc().getIp().get4().getInt();
strcpy(pack->msg, msg);
scheduler->sendBytes((const char*)&packetlen, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)pack, packetlen, 0, 0, true, appFd);
free(pack);
}
}
else if(gameAPIMsg->getCommand() == GAMEEVENT_SNOW) {
GameAPISnowMessage* snowMsg = check_and_cast<GameAPISnowMessage*>(gameAPIMsg);
SCSnowPacket packet;
packet.ip = snowMsg->getSrc().getIp().get4().getInt();
packet.startX = snowMsg->getStart().x;
packet.startY = snowMsg->getStart().y;
packet.endX = snowMsg->getEnd().x;
packet.endY = snowMsg->getEnd().y;
packet.time_sec = snowMsg->getTimeSec();
packet.time_usec = snowMsg->getTimeUsec();
int packetlen = sizeof(SCSnowPacket);
scheduler->sendBytes((const char*)&packetlen, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)&packet, packetlen, 0, 0, true, appFd);
}
SCSnowTimer* snowTimer = new SCSnowTimer("Snowball landing");
snowTimer->setPosition(snowMsg->getEnd());
snowTimer->setIp(snowMsg->getSrc().getIp().get4().getInt());
timeval snowTime;
snowTime.tv_sec = snowMsg->getTimeSec();
snowTime.tv_usec = snowMsg->getTimeUsec();
simtime_t snow_t = snowTime.tv_sec + snowTime.tv_usec / 1000000.0;
scheduleAt(simTime() + snow_t, snowTimer);
}
else if(gameAPIMsg->getCommand() == GAMEEVENT_FROZEN) {
GameAPIFrozenMessage* frozenMsg = check_and_cast<GameAPIFrozenMessage*>(gameAPIMsg);
SCFrozenPacket scfreeze;
scfreeze.ip = frozenMsg->getSrc().getIp().get4().getInt();
scfreeze.source = frozenMsg->getThrower();
scfreeze.time_sec = frozenMsg->getTimeSec();
scfreeze.time_usec = frozenMsg->getTimeUsec();
int packetlen = sizeof(scfreeze);
scheduler->sendBytes((const char*)&packetlen, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)&scfreeze, packetlen, 0, 0, true, appFd);
}
}
}
delete msg;
}
void SimpleGameClient::handleReadyMessage ( CompReadyMessage msg)
virtual

method to handle ready messages from the overlay

Parameters
msgmessage to handle

Reimplemented from BaseApp.

Definition at line 349 of file SimpleGameClient.cc.

{
// process only ready messages from the tier below
if( getThisCompType() - msg->getComp() == 1 ){
if(msg->getReady()) {
overlayReady = true;
if(!move_timer->isScheduled()) {
scheduleAt(simTime() + movementDelay, move_timer);
}
}
else {
overlayReady = false;
}
}
delete msg;
}
void SimpleGameClient::handleRealworldPacket ( char *  buf,
uint32_t  len 
)
protected

Definition at line 366 of file SimpleGameClient.cc.

Referenced by handleTimerEvent().

{
SCBasePacket *type = (SCBasePacket*)buf;
SCParamPacket packet;
packet.speed = movementSpeed;
packet.AOI = AOIWidth;
packet.delay = SIMTIME_DBL(movementDelay);
packet.startX = position.x;
packet.startY = position.y;
packet.ip = thisNode.getIp().get4().getInt();
packet.seed = coordinator->getSeed();
int packetSize = sizeof(packet);
scheduler->sendBytes((const char*)&packetSize, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)&packet, packetSize, 0, 0, true, appFd);
doRealworld = true;
}
else if(type->packetType == SC_MOVE_INDICATION) {
SCMovePacket *packet = (SCMovePacket*)type;
Vector2D temp;
temp.x = packet->posX;
temp.y = packet->posY;
dynamic_cast<realWorldRoaming*>(Generator)->setPosition(temp);
}
else if(type->packetType == SC_EV_CHAT) {
SCChatPacket* packet = (SCChatPacket*)type;
GameAPIChatMessage* chatMsg = new GameAPIChatMessage("ChatMsg");
chatMsg->setSrc(thisNode);
chatMsg->setMsg(packet->msg);
}
else if(type->packetType == SC_EV_SNOWBALL) {
SCSnowPacket* packet = (SCSnowPacket*)type;
GameAPISnowMessage* snowMsg = new GameAPISnowMessage("Throw Snowball");
snowMsg->setSrc(thisNode);
snowMsg->setStart(Vector2D(packet->startX, packet->startY));
snowMsg->setEnd(Vector2D(packet->endX, packet->endY));
snowMsg->setTimeSec(packet->time_sec);
snowMsg->setTimeUsec(packet->time_usec);
}
}
void SimpleGameClient::handleTimerEvent ( cMessage *  msg)
virtual

Reimplemented from BaseRpc.

Definition at line 157 of file SimpleGameClient.cc.

{
if(msg->isName("move_timer")) {
//reset timer
cancelEvent(move_timer);
scheduleAt(simTime() + movementDelay, msg);
}
// handle event
}
else if(msg->isName("packetNotification")) {
while(packetBuffer.size() > 0) {
// get packet from buffer and parse it
PacketBufferEntry packet = *(packetBuffer.begin());
packetBuffer.pop_front();
switch (packet.func) {
if(packet.fd != appFd) {
error("SimpleClient::handleMessage(): Received packet from unknown socket!");
}
} break;
if(appFd != INVALID_SOCKET) {
error("SimpleClient::handleMessage(): Multiple connections not supported yet!");
}
if (packet.addr != NULL) {
delete packet.addr;
packet.addr = NULL;
}
appFd = packet.fd;
} break;
if(packet.fd != appFd) {
error("SimpleClient::handleMessage(): Trying to close unknown connection!");
}
appFd = INVALID_SOCKET;
} break;
default:
// Unknown socket function, ignore
break;
}
delete packet.data;
}
}
else if(msg->isName("Snowball landing")) {
SCSnowTimer* snowTimer = check_and_cast<SCSnowTimer*>(msg);
if(!frozen && position.distanceSqr(snowTimer->getPosition() / 32 ) < 2) {
// freeze me!
frozen = true;
cMessage* unfreeze = new cMessage("unfreeze me");
scheduleAt(simTime() + 5, unfreeze);
GameAPIFrozenMessage* freeze = new GameAPIFrozenMessage("I'm frozen");
freeze->setSrc(overlay->getThisNode());
freeze->setThrower(snowTimer->getIp());
freeze->setTimeSec(5);
freeze->setTimeUsec(0);
SCFrozenPacket scfreeze;
scfreeze.ip = overlay->getThisNode().getIp().get4().getInt();
scfreeze.source = snowTimer->getIp();
scfreeze.time_sec = 5;
scfreeze.time_usec = 0;
int packetlen = sizeof(scfreeze);
scheduler->sendBytes((const char*)&packetlen, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)&scfreeze, packetlen, 0, 0, true, appFd);
}
}
delete msg;
}
else if(msg->isName("unfreeze me")) {
frozen = false;
delete msg;
}
}
void SimpleGameClient::initializeApp ( int  stage)
virtual

initializes derived class-attributes

Parameters
stagethe init stage

Reimplemented from BaseApp.

Definition at line 29 of file SimpleGameClient.cc.

{
// all initialization is done in the first stage
if (stage != MIN_STAGE_APP) {
return;
}
// fetch parameters
areaDimension = par("areaDimension");
useScenery = par("useScenery");
movementRate = par("movementRate");
movementSpeed = par("movementSpeed");
AOIWidth = 0.0;
logAOI = false;
int groupSize = (int)par("groupSize");
if(groupSize < 1) {
groupSize = 1;
}
GeneratorType = par("movementGenerator").stdstringValue();
WATCH_MAP(Neighbors);
WATCH_LIST(CollisionRect);
WATCH(position);
WATCH(GeneratorType);
WATCH(overlayReady);
doRealworld = false;
coordinator = check_and_cast<GlobalCoordinator*>(simulation.getModuleByPath("globalObserver.globalFunctions[0].function.coordinator"));
scheduler = NULL;
frozen = false;
useHotspots = false;
lastInHotspot = false;
lastAOImeasure = simTime();
startAOI = 0;
avgAOI = 0;
CollisionList* listPtr = NULL;
if(useScenery == true) {
listPtr = &CollisionRect;
}
double speed = SIMTIME_DBL(movementDelay) * movementSpeed;
if(strcmp(GeneratorType.c_str(), "greatGathering") == 0) {
EV << "[SimpleGameClient::initializeApp() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " SIMPLECLIENT: Movement generator: greatGathering"
<< endl;
}
}
else if(strcmp(GeneratorType.c_str(), "groupRoaming") == 0) {
EV << "[SimpleGameClient::initializeApp() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " SIMPLECLIENT: Movement generator: groupRoaming"
<< endl;
}
Generator = new groupRoaming(areaDimension, speed, &Neighbors, coordinator, listPtr, groupSize);
}
else if(strcmp(GeneratorType.c_str(), "hotspotRoaming") == 0) {
EV << "[SimpleGameClient::initializeApp() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " SIMPLECLIENT: Movement generator: hotspotRoaming"
<< endl;
}
useHotspots = true;
}
else if(strcmp(GeneratorType.c_str(), "traverseRoaming") == 0) {
EV << "[SimpleGameClient::initializeApp() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " SIMPLECLIENT: Movement generator: traverseRoaming"
<< endl;
}
logAOI = true;
}
else if(strcmp(GeneratorType.c_str(), "realWorldRoaming") == 0) {
EV << "[SimpleGameClient::initializeApp() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " SIMPLECLIENT: Movement generator: realWorldRoaming"
<< endl;
}
mtu = par("mtu");
packetNotification = new cMessage("packetNotification");
scheduler = check_and_cast<RealtimeScheduler*>(simulation.getScheduler());
appFd = INVALID_SOCKET;
}
else {
// debug output
if(strcmp(GeneratorType.c_str(), "randomRoaming") == 0) {
EV << "[SimpleGameClient::initializeApp() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " SIMPLECLIENT: Movement generator: randomRoaming"
<< endl;
}
else {
EV << "[SimpleGameClient::initializeApp() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " SIMPLECLIENT: Movement generator: <unknown>. Defaulting to: randomRoaming"
<< endl;
}
}
}
// self-messages
move_timer = new cMessage("move_timer");
overlayReady = false;
}
bool SimpleGameClient::isOverlayReady ( )
inline

Definition at line 68 of file SimpleGameClient.h.

Referenced by ConnectivityProbeApp::extractTopology().

{return overlayReady;};
void SimpleGameClient::updateNeighbors ( GameAPIListMessage sgcMsg)
protected

Definition at line 413 of file SimpleGameClient.cc.

Referenced by handleLowerMessage().

{
unsigned int i;
int packetSize;
SCRemovePacket removePacket;
packetSize = sizeof(removePacket);
for(i=0; i<sgcMsg->getRemoveNeighborArraySize(); ++i) {
removePacket.ip = sgcMsg->getRemoveNeighbor(i).getIp().get4().getInt();
scheduler->sendBytes((const char*)&packetSize, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)&removePacket, packetSize, 0, 0, true, appFd);
}
SCAddPacket addPacket;
packetSize = sizeof(addPacket);
for(i=0; i<sgcMsg->getAddNeighborArraySize(); ++i) {
addPacket.ip = sgcMsg->getAddNeighbor(i).getIp().get4().getInt();
if( addPacket.ip == thisNode.getIp().get4().getInt() ) continue;
addPacket.posX = sgcMsg->getNeighborPosition(i).x;
addPacket.posY = sgcMsg->getNeighborPosition(i).y;
scheduler->sendBytes((const char*)&packetSize, sizeof(int), 0, 0, true, appFd);
scheduler->sendBytes((const char*)&addPacket, packetSize, 0, 0, true, appFd);
}
}
for(i=0; i<sgcMsg->getRemoveNeighborArraySize(); ++i)
Neighbors.erase(sgcMsg->getRemoveNeighbor(i));
for(i=0; i<sgcMsg->getAddNeighborArraySize(); ++i) {
Vector2D newPos;
newPos = sgcMsg->getNeighborPosition(i);
itNeighbors = Neighbors.find(sgcMsg->getAddNeighbor(i));
if(itNeighbors != Neighbors.end()) {
Vector2D temp = newPos - itNeighbors->second.position;
temp.normalize();
itNeighbors->second.direction = temp;
itNeighbors->second.position = newPos;
}
else {
entry.position = newPos;
Neighbors.insert(std::make_pair(sgcMsg->getAddNeighbor(i), entry));
}
}
}
void SimpleGameClient::updatePosition ( )
protected

Definition at line 464 of file SimpleGameClient.cc.

Referenced by handleLowerMessage(), and handleTimerEvent().

Member Data Documentation

double SimpleGameClient::AOIWidth
protected
SOCKET SimpleGameClient::appFd
protected
double SimpleGameClient::areaDimension
protected

Definition at line 82 of file SimpleGameClient.h.

Referenced by handleRealworldPacket(), and initializeApp().

double SimpleGameClient::avgAOI
protected

Definition at line 111 of file SimpleGameClient.h.

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

double SimpleGameClient::avgFarFromHotspotAOI
protected

Definition at line 114 of file SimpleGameClient.h.

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

double SimpleGameClient::avgHotspotAOI
protected

Definition at line 116 of file SimpleGameClient.h.

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

CollisionList SimpleGameClient::CollisionRect
protected

Definition at line 75 of file SimpleGameClient.h.

Referenced by initializeApp().

GlobalCoordinator* SimpleGameClient::coordinator
protected

Definition at line 74 of file SimpleGameClient.h.

Referenced by handleRealworldPacket(), and initializeApp().

bool SimpleGameClient::doRealworld
protected
simtime_t SimpleGameClient::farFromHotspotTime
protected

Definition at line 113 of file SimpleGameClient.h.

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

bool SimpleGameClient::frozen
protected

Definition at line 103 of file SimpleGameClient.h.

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

MovementGenerator* SimpleGameClient::Generator
protected
std::string SimpleGameClient::GeneratorType
protected

Definition at line 90 of file SimpleGameClient.h.

Referenced by initializeApp().

simtime_t SimpleGameClient::hotspotTime
protected

Definition at line 115 of file SimpleGameClient.h.

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

NeighborMap::iterator SimpleGameClient::itNeighbors
protected

Definition at line 89 of file SimpleGameClient.h.

Referenced by updateNeighbors().

simtime_t SimpleGameClient::lastAOImeasure
protected

Definition at line 110 of file SimpleGameClient.h.

Referenced by handleLowerMessage(), and initializeApp().

bool SimpleGameClient::lastFarFromHotspot
protected

Definition at line 109 of file SimpleGameClient.h.

Referenced by handleLowerMessage(), and initializeApp().

bool SimpleGameClient::lastInHotspot
protected

Definition at line 108 of file SimpleGameClient.h.

Referenced by handleLowerMessage(), and initializeApp().

bool SimpleGameClient::logAOI
protected

Definition at line 87 of file SimpleGameClient.h.

Referenced by handleLowerMessage(), and initializeApp().

cMessage* SimpleGameClient::move_timer
protected
simtime_t SimpleGameClient::movementDelay
protected
double SimpleGameClient::movementRate
protected

Definition at line 82 of file SimpleGameClient.h.

Referenced by initializeApp().

double SimpleGameClient::movementSpeed
protected

Definition at line 82 of file SimpleGameClient.h.

Referenced by handleRealworldPacket(), and initializeApp().

unsigned int SimpleGameClient::mtu
protected

Definition at line 100 of file SimpleGameClient.h.

Referenced by initializeApp().

NeighborMap SimpleGameClient::Neighbors

Definition at line 69 of file SimpleGameClient.h.

Referenced by initializeApp(), and updateNeighbors().

simtime_t SimpleGameClient::nonHotspotTime
protected

Definition at line 112 of file SimpleGameClient.h.

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

bool SimpleGameClient::overlayReady
protected
PacketBuffer SimpleGameClient::packetBuffer
protected

Definition at line 98 of file SimpleGameClient.h.

Referenced by handleTimerEvent(), and initializeApp().

cMessage* SimpleGameClient::packetNotification
protected

Definition at line 97 of file SimpleGameClient.h.

Referenced by initializeApp(), and ~SimpleGameClient().

Vector2D SimpleGameClient::position
protected
RealtimeScheduler* SimpleGameClient::scheduler
protected
double SimpleGameClient::startAOI
protected

Definition at line 106 of file SimpleGameClient.h.

Referenced by handleLowerMessage(), and initializeApp().

bool SimpleGameClient::useHotspots
protected

Definition at line 107 of file SimpleGameClient.h.

Referenced by handleLowerMessage(), and initializeApp().

bool SimpleGameClient::useScenery
protected

Definition at line 83 of file SimpleGameClient.h.

Referenced by initializeApp().


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