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

Maintains information about a Forest router's virtual links. More...

#include <LinkTable.h>

Collaboration diagram for forest::LinkTable:

Classes

class  Entry
 link table entry More...
 

Public Member Functions

 LinkTable (int)
 Constructor for LinkTable, allocates space and initializes table. More...
 
 ~LinkTable ()
 Destructor for LinkTable, frees dynamic storage. More...
 
bool valid (int) const
 Determine if a link number is valid. More...
 
bool checkEntry (int)
 Check if a table entry is consistent. More...
 
int firstLink () const
 Get the "first" link. More...
 
int nextLink (int) const
 Get the "next" link. More...
 
int lookup (ipa_t, ipp_t) const
 Get the link number on which a packet arrived. More...
 
int lookup (uint64_t) const
 Get the link number based on a nonce. More...
 
int lookup (fAdr_t) const
 Get the link number based on the peer's forest address. More...
 
EntrygetEntry (int) const
 Get the table entry for a given link. More...
 
void setPeerAdr (int, fAdr_t)
 Set the Forest address of the peer for a given link. More...
 
int addEntry (int, ipa_t, ipp_t, uint64_t)
 Add a link table entry. More...
 
bool remapEntry (int, ipa_t, ipp_t)
 Remap an entry added earlier using a nonce. More...
 
bool remapEntry (int, ipa_t, ipp_t, uint64_t)
 
bool revertEntry (int)
 Revert an entry that was remapped earlier. More...
 
bool removeEntry (int)
 Remove the table entry for a link. More...
 
bool connect (int lnk, ipa_t peerIp, ipp_t peerPort)
 Connect a link that was previously disconnected. More...
 
bool read (istream &)
 Read link table entries from the input. More...
 
string link2string (int) const
 Create a string representing a table entry. More...
 
string toString () const
 Create a string representing the table. More...
 
char * pack (int, char *) const
 Pack a link table entry into a packet buffer. More...
 
char * unpack (int, char *)
 Unpack a link table entry from a packet buffer. More...
 

Private Member Functions

uint64_t hashkey (ipa_t, ipp_t) const
 Compute key for hash lookup. More...
 
int readEntry (istream &)
 Read an entry from an input stream and store it in the link table. More...
 

Private Attributes

int maxLnk
 maximum link number
 
HashMap< uint64_t, Entry,
Hash::u64 > * 
map
 map from remote peer's (ip,port) pair to entry
 
HashSet< fAdr_t, Hash::s32 > * padrMap
 extra map from peer addr to link #
 

Detailed Description

Maintains information about a Forest router's virtual links.

Definition at line 24 of file LinkTable.h.

Constructor & Destructor Documentation

forest::LinkTable::LinkTable ( int  maxLnk1)

Constructor for LinkTable, allocates space and initializes table.

Definition at line 14 of file LinkTable.cpp.

forest::LinkTable::~LinkTable ( )

Destructor for LinkTable, frees dynamic storage.

Definition at line 20 of file LinkTable.cpp.

Member Function Documentation

int forest::LinkTable::addEntry ( int  lnk,
ipa_t  peerIp,
ipp_t  peerPort,
uint64_t  nonce 
)

Add a link table entry.

Parameters
lnkis the number of the link for which an entry is requested;
peerIpis the IP address of the peer node.
peerPortis the port number of the peer node.
nonceis the nonce that is used to connect the link.
Returns
the link number of the entry on success, or 0 on failure. if the lnk == 0, a free link is allocated for this entry; if lnk != 0, it must specify a link that is not already in use; the link is created in the disconnected state and when in this state, the hash table entry used to lookup the link number is based on the nonce; when the link becomes connected, this hash table entry is replaced with one based on the peerIp and peerPort
Parameters
lnkis the number of the link for which an entry is requested; if the lnk == 0, a free link is allocated for this entry; if lnk != 0, it must specify a link that is not already in use
peerIpis the IP address of the peer node
peerPortis the port number of the peer node
Returns
the link number of the entry on success, or 0 on failure.

Definition at line 37 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::LinkTable::checkEntry ( int  lnk)

Check if a table entry is consistent.

Parameters
lnkis the link number for the entry to be checked
Returns
true if entry is consistent, else false

Definition at line 100 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::LinkTable::connect ( int  lnk,
ipa_t  peerIp,
ipp_t  peerPort 
)

Connect a link that was previously disconnected.

This involves removing the nonce-based hash-table entry and replacing it with an entry using the peerIp and peerPort

Parameters
peerIpis the IP address of this link's peer
peerPortis the port number of this link's peer
Returns
true on success, false on failure

Definition at line 59 of file LinkTable.cpp.

Here is the call graph for this function:

int forest::LinkTable::firstLink ( ) const
inline

Get the "first" link.

This method is used to iterate through the links. The order of the links is arbitrary.

Returns
the link number of the first link, or 0 if there are no links

Definition at line 138 of file LinkTable.h.

Here is the caller graph for this function:

LinkTable::Entry & forest::LinkTable::getEntry ( int  lnk) const
inline

Get the table entry for a given link.

Parameters
lnkis a valid link number
Returns
a reference to the entry for lnk

Definition at line 190 of file LinkTable.h.

Here is the caller graph for this function:

uint64_t forest::LinkTable::hashkey ( ipa_t  ipa,
ipp_t  ipp 
) const
inlineprivate

Compute key for hash lookup.

Parameters
ipais an IP address
ippis an IP port number

Definition at line 153 of file LinkTable.h.

Here is the caller graph for this function:

string & forest::LinkTable::link2string ( int  lnk) const

Create a string representing a table entry.

Parameters
lnkis the number of the link to be written out
sis a reference to a string in which the result is returned
Returns
a reference to s

Definition at line 192 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int forest::LinkTable::lookup ( ipa_t  ipa,
ipp_t  ipp 
) const
inline

Get the link number on which a packet arrived.

Parameters
ipais an IP address
ippis an IP port number
Returns
the number of the link that matches the given IP address and port, or 0 if there is no matching link

Definition at line 163 of file LinkTable.h.

Here is the call graph for this function:

Here is the caller graph for this function:

int forest::LinkTable::lookup ( uint64_t  nonce) const
inline

Get the link number based on a nonce.

Parameters
nonceis a value used to identify a new leaf when connecting.
Returns
the number of the link that matches the given nonce, or 0 if there is no matching link

Definition at line 172 of file LinkTable.h.

int forest::LinkTable::lookup ( fAdr_t  peerAdr) const
inline

Get the link number based on the peer's forest address.

This method is only defined for links going to leaf nodes.

Parameters
nonceis a value used to identify a new leaf when connecting.
Returns
the number of the link that matches the given nonce, or 0 if there is no matching link

Definition at line 182 of file LinkTable.h.

int forest::LinkTable::nextLink ( int  lnk) const
inline

Get the "next" link.

This method is used to iterate through the links. The order of the links is arbitrary.

Parameters
lnkis a link number
Returns
the link number of the link following lnk, or 0 if there are no more links

Definition at line 147 of file LinkTable.h.

Here is the caller graph for this function:

char * forest::LinkTable::pack ( int  lnk,
char *  buf 
) const

Pack a link table entry into a packet buffer.

Omit the comtSet, but include the number of elements it contains.

Returns
true on success, false on failure

Definition at line 277 of file LinkTable.cpp.

Here is the call graph for this function:

bool forest::LinkTable::read ( istream &  in)

Read link table entries from the input.

The first line must contain an integer, giving the number of entries to be read. The input may include blank lines and comment lines (any text starting with '#'). Each entry must be on a line by itself (possibly with a trailing comment). If an error is encountered, a message is sent to cerr identifying the the input entry that caused the error.

Parameters
inis an open input stream
Returns
true on success, false on failure

Definition at line 172 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int forest::LinkTable::readEntry ( istream &  in)
private

Read an entry from an input stream and store it in the link table.

Each entry must be on its own line, possibly followed by a comment. A comment begins with a # sign and continues to the end of the link. A non-blank line that does not being with a comment is assumed to contain an entry. Each entry consists of a link#, the IP address of the local endpoint, the IP address and port number of the peer, the type of the peer, the forest address of the peer, the maximum bit rate for the link (in Kb/s) and its maximum packet rate (in p/s).

If the link number specified in the input is already in use, the call to readEntry will fail, in which case 0 is returned. The call can also fail if the input is not formatted correctly.

Parameters
inis an open input stream
Returns
the link number of the entry, or 0 if the operation fails

Definition at line 129 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::LinkTable::remapEntry ( int  lnk,
ipa_t  peerIp,
ipp_t  peerPort 
)

Remap an entry added earlier using a nonce.

Parameters
peerIpis the IP address of this link's peer
peerPortis the port number of this link's peer
Returns
true on success, false on failure

Definition at line 64 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::LinkTable::removeEntry ( int  lnk)

Remove the table entry for a link.

Parameters
lnkis the link number for the entry to be deleted
Returns
true on success, else false
Parameters
lnkis the link number for the entry to be deleted

Definition at line 73 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::LinkTable::revertEntry ( int  lnk)

Revert an entry that was remapped earlier.

Returns
true on success, false on failure

Definition at line 79 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::LinkTable::setPeerAdr ( int  lnk,
fAdr_t  adr 
)

Set the Forest address of the peer for a given link.

Set the port number for the peer at the far end of a link.

Parameters
lnkis a valid link number
adris a Forest unicast address
lnkis a valid link number
peerPortis the port number of the peer node
Returns
true on success, false on failure bool LinkTable::setPeerIpPort(int lnk, ipa_t peerIp, ipp_t peerPort) { if (!valid(lnk)) return false; ht->remove(hashkey(getPeerIpAdr(lnk),getPeerPort(lnk))); if (!ht->insert(hashkey(peerIp, peerPort),lnk)) { ht->insert(hashkey(getPeerIpAdr(lnk), getPeerPort(lnk)),lnk); return false; } lnkTbl[lnk].peerIp = peerIp; lnkTbl[lnk].peerPort = peerPort; return true; }Set the Forest address of the peer for a given link.
Parameters
lnkis a valid link number
adris a Forest unicast address

Definition at line 87 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

string & forest::LinkTable::toString ( ) const

Create a string representing the table.

Parameters
sis a reference to a string in which result is returned
Returns
a reference to s

Definition at line 204 of file LinkTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

char * forest::LinkTable::unpack ( int  lnk,
char *  buf 
)

Unpack a link table entry from a packet buffer.

Returns
true on success, false on failure

Definition at line 309 of file LinkTable.cpp.

Here is the call graph for this function:

bool forest::LinkTable::valid ( int  lnk) const
inline

Determine if a link number is valid.

Parameters
lnkis a link number
Returns
true if a link has been defined with the specified link number, else false

Definition at line 130 of file LinkTable.h.

Here is the caller graph for this function:


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