OverSim
|
This class implements a event scheduler for OMNeT++ It makes the simulation run in realtime (i.e. More...
#include <realtimescheduler.h>
Classes | |
class | SocketContext |
Public Member Functions | |
RealtimeScheduler () | |
Constructor. | |
virtual | ~RealtimeScheduler () |
Destructor. | |
virtual void | startRun () |
Called at the beginning of a simulation run. | |
virtual void | endRun () |
Called at the end of a simulation run. | |
virtual void | executionResumed () |
Recalculates "base time" from current wall clock time. | |
virtual void | setInterfaceModule (cModule *module, cMessage *notificationMsg, PacketBuffer *buffer, int mtu, bool isApp=false) |
To be called from the module which wishes to receive data from the tun device. | |
void | registerSocket (SOCKET fd, cModule *mod, cMessage *notifMsg, PacketBuffer *buffer, int mtu) |
virtual cMessage * | getNextEvent () |
Scheduler function – it comes from cScheduler interface. | |
void | sendNotificationMsg (cMessage *msg, cModule *mod) |
send notification msg to module | |
virtual ssize_t | sendBytes (const char *buf, size_t numBytes, sockaddr *addr=0, socklen_t addrlen=0, bool isApp=false, SOCKET fd=INVALID_SOCKET) |
Send data to network. | |
void | closeAppSocket (SOCKET fd) |
Close the application TCP socket. | |
virtual SOCKET | getAppTunFd () |
Returns the FD for the application TUN socket. |
Protected Member Functions | |
virtual int | initializeNetwork ()=0 |
Initialize the network. | |
virtual void | additionalFD () |
This function is called from main loop if data is accessible from "additional_fd". | |
virtual bool | receiveWithTimeout (long usec) |
Waits for incoming data on the tun device. | |
virtual int | receiveUntil (const timeval &targetTime) |
Tries to read data until the given time is up. |
Protected Attributes | |
std::map< SOCKET, SocketContext > | socketContextMap |
fd_set | all_fds |
SOCKET | maxfd |
SOCKET | netw_fd |
SOCKET | apptun_fd |
cModule * | module |
cMessage * | notificationMsg |
PacketBuffer * | packetBuffer |
size_t | buffersize |
cModule * | appModule |
cMessage * | appNotificationMsg |
PacketBuffer * | appPacketBuffer |
size_t | appBuffersize |
int | appConnectionLimit |
SOCKET | additional_fd |
timeval | baseTime |
This class implements a event scheduler for OMNeT++ It makes the simulation run in realtime (i.e.
1 simsec == 1 sec) It must be subclassed; its subclasses must handle network traffic from/to the simulation
Definition at line 65 of file realtimescheduler.h.
RealtimeScheduler::RealtimeScheduler | ( | ) |
Constructor.
Definition at line 34 of file realtimescheduler.cc.
|
virtual |
|
inlineprotectedvirtual |
This function is called from main loop if data is accessible from "additional_fd".
This FD can be set in initializeNetwork by concrete implementations.
Reimplemented in AppTunOutScheduler, TunOutScheduler, and UdpOutScheduler.
Definition at line 117 of file realtimescheduler.h.
Referenced by receiveWithTimeout().
void RealtimeScheduler::closeAppSocket | ( | SOCKET | fd | ) |
Close the application TCP socket.
Definition at line 370 of file realtimescheduler.cc.
Referenced by receiveWithTimeout().
|
virtual |
|
virtual |
Recalculates "base time" from current wall clock time.
Definition at line 68 of file realtimescheduler.cc.
|
inlinevirtual |
Returns the FD for the application TUN socket.
Definition at line 225 of file realtimescheduler.h.
|
virtual |
Scheduler function – it comes from cScheduler interface.
Definition at line 327 of file realtimescheduler.cc.
|
protectedpure virtual |
Initialize the network.
Implemented in AppTunOutScheduler, TunOutScheduler, and UdpOutScheduler.
Referenced by startRun().
|
protectedvirtual |
Tries to read data until the given time is up.
targetTime | stop waiting after this time is up |
Definition at line 300 of file realtimescheduler.cc.
Referenced by getNextEvent().
|
protectedvirtual |
Waits for incoming data on the tun device.
usec | Timeout after which to quit waiting (in µsec) |
Definition at line 121 of file realtimescheduler.cc.
Referenced by receiveUntil().
void RealtimeScheduler::registerSocket | ( | SOCKET | fd, |
cModule * | mod, | ||
cMessage * | notifMsg, | ||
PacketBuffer * | buffer, | ||
int | mtu | ||
) |
Definition at line 104 of file realtimescheduler.cc.
|
virtual |
Send data to network.
buf | A pointer to the data to be send |
numBytes | the length of the data |
isApp | set to "true" if called from a realworldApp |
addr | If needed, the destination address |
addrlen | The length of the address |
fd | If connected to more than one external app, set to the corresponding FD. If left to default and multiple apps are connected, the data will be send to one arbitrarily chosen app. |
Definition at line 408 of file realtimescheduler.cc.
Referenced by SimpleGameClient::handleLowerMessage(), SimpleGameClient::handleRealworldPacket(), SimpleGameClient::handleTimerEvent(), RealworldConnector::transmitToNetwork(), and SimpleGameClient::updateNeighbors().
void RealtimeScheduler::sendNotificationMsg | ( | cMessage * | msg, |
cModule * | mod | ||
) |
send notification msg to module
msg | The notification Message |
mod | The destination |
Definition at line 391 of file realtimescheduler.cc.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), closeAppSocket(), and receiveWithTimeout().
|
virtual |
To be called from the module which wishes to receive data from the tun device.
The method must be called from the module's initialize() function.
module | Pointer to the module that wants to receive the data |
notificationMsg | A pointer to a message that will be scheduled if there is data to read |
buffer | A pointer to the buffer the data will be written into |
mtu | Max allowed packet size |
isApp | set to "true" if called from a realworldApp |
Definition at line 74 of file realtimescheduler.cc.
Referenced by RealworldConnector::initialize(), SimpleGameClient::initializeApp(), and XmlRpcInterface::initializeApp().
|
virtual |
Called at the beginning of a simulation run.
Definition at line 46 of file realtimescheduler.cc.
|
protected |
Definition at line 104 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), UdpOutScheduler::initializeNetwork(), TunOutScheduler::initializeNetwork(), AppTunOutScheduler::initializeNetwork(), RealtimeScheduler(), receiveWithTimeout(), sendBytes(), AppTunOutScheduler::~AppTunOutScheduler(), TunOutScheduler::~TunOutScheduler(), and UdpOutScheduler::~UdpOutScheduler().
|
protected |
Definition at line 86 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), closeAppSocket(), UdpOutScheduler::initializeNetwork(), TunOutScheduler::initializeNetwork(), AppTunOutScheduler::initializeNetwork(), RealtimeScheduler(), receiveWithTimeout(), registerSocket(), and sendBytes().
|
protected |
Definition at line 101 of file realtimescheduler.h.
Referenced by receiveWithTimeout(), sendBytes(), and setInterfaceModule().
|
protected |
Definition at line 102 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), and startRun().
|
protected |
Definition at line 98 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), closeAppSocket(), receiveWithTimeout(), setInterfaceModule(), and startRun().
|
protected |
Definition at line 99 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), closeAppSocket(), receiveWithTimeout(), setInterfaceModule(), and startRun().
|
protected |
Definition at line 100 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), closeAppSocket(), receiveWithTimeout(), and setInterfaceModule().
|
protected |
Definition at line 91 of file realtimescheduler.h.
Referenced by getAppTunFd(), AppTunOutScheduler::initializeNetwork(), RealtimeScheduler(), receiveWithTimeout(), and sendBytes().
|
protected |
Definition at line 107 of file realtimescheduler.h.
Referenced by executionResumed(), getNextEvent(), sendNotificationMsg(), and startRun().
|
protected |
Definition at line 95 of file realtimescheduler.h.
Referenced by receiveWithTimeout(), sendBytes(), and setInterfaceModule().
|
protected |
Definition at line 87 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), UdpOutScheduler::initializeNetwork(), TunOutScheduler::initializeNetwork(), AppTunOutScheduler::initializeNetwork(), RealtimeScheduler(), receiveWithTimeout(), registerSocket(), and sendBytes().
|
protected |
Definition at line 92 of file realtimescheduler.h.
Referenced by getNextEvent(), receiveWithTimeout(), setInterfaceModule(), and startRun().
|
protected |
Definition at line 90 of file realtimescheduler.h.
Referenced by UdpOutScheduler::additionalFD(), TunOutScheduler::additionalFD(), AppTunOutScheduler::additionalFD(), UdpOutScheduler::initializeNetwork(), TunOutScheduler::initializeNetwork(), AppTunOutScheduler::initializeNetwork(), RealtimeScheduler(), receiveWithTimeout(), and sendBytes().
|
protected |
Definition at line 93 of file realtimescheduler.h.
Referenced by receiveWithTimeout(), setInterfaceModule(), and startRun().
|
protected |
Definition at line 94 of file realtimescheduler.h.
Referenced by receiveWithTimeout(), and setInterfaceModule().
|
protected |
Definition at line 83 of file realtimescheduler.h.
Referenced by closeAppSocket(), receiveWithTimeout(), registerSocket(), and sendBytes().