forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
forest::Monitor Class Reference

Monitor observes status reports sent by Avatars in a virtual world and reports them to a remote client that implements a graphical display of the moving Avatars. More...

#include <Monitor.h>

Collaboration diagram for forest::Monitor:

Public Member Functions

 Monitor (ipa_t, ipa_t, int)
 
bool init (const string &, const string &)
 open and setup socket More...
 
void run (uint32_t)
 run avatar More...
 

Private Types

enum  STATE { IDLE, JOINING, LEAVING }
 

Private Member Functions

bool login (const string &, const string &)
 Send username and password to the Client manager, and receive. More...
 
int groupNum (int, int)
 Return the multicast group number associated with a virtual world position. More...
 
bool connect ()
 Send initial connect packet to forest router Uses comtree 1, which is for user signalling.
 
bool disconnect ()
 Send final disconnect packet to forest router.
 
comt_t check4command ()
 Check for a new command from remote display program. More...
 
void sendToRouter (int)
 Send packet to Forest router (connect, disconnect, sub_unsub).
 
int receiveFromRouter ()
 Check for next Avatar report packet and return it if there is one. More...
 
void forwardReport (int, int)
 If the given packet is a status report and there is a remote display connected, then forward the status info to the remote display. More...
 
void startComtSwitch (comt_t, uint32_t)
 Start the process of switching to a new comtree. More...
 
bool completeComtSwitch (pktx, uint32_t)
 Attempt to complete the process of switching to a new comtree. More...
 
void send2comtCtl (CtlPkt::CpType, bool=false)
 Send join or leave packet packet to the ComtreeController. More...
 
void switchComtrees (int)
 Switch from the current comtree to newComt. More...
 
void updateSubs ()
 Update subscriptions without changing comtrees. More...
 
void subscribeAll ()
 Subscribe to all multicasts for regions in our current view, that we're not already subscribed to.
 
void unsubscribeAll ()
 Unsubscribe from all multicasts that we're currently subscribed to.
 
void subscribe (list< int > &)
 Subscribe to a list of multicast groups. More...
 
void unsubscribe (list< int > &)
 Unsubscribe from a list of multicast groups. More...
 

Private Attributes

int worldSize
 

of squares in x and y directions


 
fAdr_t myAdr
 forest address of host
 
ipa_t myIp
 IP address to bind to sockets.
 
fAdr_t rtrAdr
 forest address of router
 
ipa_t rtrIp
 IP address of router.
 
ipp_t rtrPort
 port number of router
 
ipa_t cmIp
 IP address of client manager.
 
fAdr_t ccAdr
 address of ComtCtl
 
uint64_t nonce
 used when connecting
 
int dgSock
 datagram socket number
 
int listenSock
 listening socket for remote GUI
 
int connSock
 connection socket
 
int cornerX
 lower-left corner of current view
 
int cornerY
 
int viewSize
 size of current view
 
set< int > * mySubs
 current multicast subscriptions
 
PacketStoreps
 pointer to packet store
 
STATE switchState
 current state
 
uint32_t switchTimer
 time last signalling packet sent
 
int switchCnt
 number of attempts so far
 
comt_t nextComt
 comtree we're switching to
 
comt_t comt
 current comtree number
 
int seqNum
 sequence number of control packet
 

Static Private Attributes

static const short MON_PORT = 30124
 port# for connection to GUI
 
static const int NUMITEMS = 9
 

distinct items in status packet


 
static const int GRID = 10000
 xy extent of one grid square
 
static const int MAX_AVATARS = 1000
 max # of avatars to monitor
 
static const int MAX_WORLD = 30000
 max extent of virtual world
 
static const int MAX_VIEW = 1000
 max extent of view
 
static const int UPDATE_PERIOD = 50
 

ms between status updates


 
static const uint32_t SWITCH_TIMEOUT = 500000
 500 ms timeout
 
static const bool RETRY = true
 flag used to signal retry
 

Detailed Description

Monitor observes status reports sent by Avatars in a virtual world and reports them to a remote client that implements a graphical display of the moving Avatars.

Definition at line 29 of file Monitor.h.

Member Function Documentation

comt_t forest::Monitor::check4command ( )
private

Check for a new command from remote display program.

Check to see if the remote display has sent a comand and respond appropriately. Commands take the form of pairs (c,i) where c is a character that identifies a specific command, and i is an integer that provides an optional parameter value for the command. The current commands are defined below.

x set x coordinate of lower left corner of current view to paramater value y set y coordinate of lower left corner of current view to paramater value v set view size to value specified by paramater value c switch to comtree identified by parameter value

For the aswd commands, there are corresponding ASWD commands that shift by a larger amount. Also, there are OP commands that half/double the window size.

Note that the integer parameter must be sent even when the command doesn't use it

Returns
the requested comtree number if the 'c' command is received; else 0

Definition at line 380 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::Monitor::completeComtSwitch ( pktx  px,
uint32_t  now 
)
private

Attempt to complete the process of switching to a new comtree.

This involves completing signalling interactions with ComtCtl, including re-sending signalling packets when timeouts occur.

Parameters
pis a packet number, or 0 if the caller just wants to check for a timeout
nowis the current time
Returns
true if the switch has been completed, or if the switch has failed (either because the ComtCtl sent a negative response or because it never responded after repeated attempts); otherwise, return false

Definition at line 248 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::Monitor::forwardReport ( int  px,
int  now 
)
private

If the given packet is a status report and there is a remote display connected, then forward the status info to the remote display.

Filter out packets that are not in our current "view".

Parameters
pis the packet number for a packet from the Forest network
nowis the current time

Definition at line 590 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int forest::Monitor::groupNum ( int  x1,
int  y1 
)
private

Return the multicast group number associated with a virtual world position.

Parameters
x1is x coordinate
y1is y coordinate
Returns
the group number for the grid square containing (x1,y1)

Definition at line 434 of file Monitor.cpp.

Here is the caller graph for this function:

bool forest::Monitor::init ( const string &  uname,
const string &  pword 
)

open and setup socket

Initialize sockets and open log file for writing.

Returns
true on success, false on failure

Definition at line 82 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::Monitor::login ( const string &  uname,
const string &  pword 
)
private

Send username and password to the Client manager, and receive.

Parameters
cmIpAdris the IP address of the client manager
unameis the username to log in with
pwordis the password to log in with
Returns
true on success, false on failure

Definition at line 105 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int forest::Monitor::receiveFromRouter ( )
private

Check for next Avatar report packet and return it if there is one.

Returns
next report packet or 0, if no report has been received.

Definition at line 345 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::Monitor::run ( uint32_t  finishTime)

run avatar

Run the monitor, stopping after finishTime Operate on a cycle with a period of UPDATE_PERIOD milliseconds, Each cycle, process all the packets that came in during that period and store results.

Print a record of all avatar's status, once per second.

Definition at line 174 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::Monitor::send2comtCtl ( CtlPkt::CpType  joinLeave,
bool  retry = false 
)
private

Send join or leave packet packet to the ComtreeController.

Parameters
joinLeaveis either CLIENT_JOIN_COMTREE or CLIENT_LEAVE_COMTREE, depending on whether we want to join or leave the comtree

Definition at line 311 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::Monitor::startComtSwitch ( comt_t  newComt,
uint32_t  now 
)
private

Start the process of switching to a new comtree.

Unsubscribe to the current comtree and leave send signalling message to leave the current comtree.

Parameters
newComtis the number of the comtree we're switching to
nowis the current time

Definition at line 222 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::Monitor::subscribe ( list< int > &  glist)
private

Subscribe to a list of multicast groups.

Parameters
glistis a reference to a list of multicast group numbers.

Definition at line 479 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::Monitor::switchComtrees ( int  newComt)
private

Switch from the current comtree to newComt.

This requires unsubscribing from all current multicasts and subscribing to multicasts in new comtree. Currently, Monitor is statically configured as a member of all comtrees.

Definition at line 443 of file Monitor.cpp.

Here is the call graph for this function:

void forest::Monitor::unsubscribe ( list< int > &  glist)
private

Unsubscribe from a list of multicast groups.

Parameters
glistis a reference to a list of multicast group numbers.

Definition at line 514 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::Monitor::updateSubs ( )
private

Update subscriptions without changing comtrees.

Unsubscribe to all multicasts that are not in current view, then subscribe to all missing multicasts that are in current view.

Definition at line 550 of file Monitor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


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