forest-net
an overlay networks for large-scale virtual worlds
|
Maintains information about a Forest router's virtual links. More...
#include <LinkTable.h>
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... | |
Entry & | getEntry (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 # | |
Maintains information about a Forest router's virtual links.
Definition at line 24 of file LinkTable.h.
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.
int forest::LinkTable::addEntry | ( | int | lnk, |
ipa_t | peerIp, | ||
ipp_t | peerPort, | ||
uint64_t | nonce | ||
) |
Add a link table entry.
lnk | is the number of the link for which an entry is requested; |
peerIp | is the IP address of the peer node. |
peerPort | is the port number of the peer node. |
nonce | is the nonce that is used to connect the link. |
lnk | is 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 |
peerIp | is the IP address of the peer node |
peerPort | is the port number of the peer node |
Definition at line 37 of file LinkTable.cpp.
bool forest::LinkTable::checkEntry | ( | int | lnk) |
Check if a table entry is consistent.
lnk | is the link number for the entry to be checked |
Definition at line 100 of file LinkTable.cpp.
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
peerIp | is the IP address of this link's peer |
peerPort | is the port number of this link's peer |
Definition at line 59 of file LinkTable.cpp.
|
inline |
Get the "first" link.
This method is used to iterate through the links. The order of the links is arbitrary.
Definition at line 138 of file LinkTable.h.
|
inline |
Get the table entry for a given link.
lnk | is a valid link number |
Definition at line 190 of file LinkTable.h.
|
inlineprivate |
Compute key for hash lookup.
ipa | is an IP address |
ipp | is an IP port number |
Definition at line 153 of file LinkTable.h.
string & forest::LinkTable::link2string | ( | int | lnk) | const |
Create a string representing a table entry.
lnk | is the number of the link to be written out |
s | is a reference to a string in which the result is returned |
Definition at line 192 of file LinkTable.cpp.
|
inline |
Get the link number on which a packet arrived.
ipa | is an IP address |
ipp | is an IP port number |
Definition at line 163 of file LinkTable.h.
|
inline |
Get the link number based on a nonce.
nonce | is a value used to identify a new leaf when connecting. |
Definition at line 172 of file LinkTable.h.
|
inline |
Get the link number based on the peer's forest address.
This method is only defined for links going to leaf nodes.
nonce | is a value used to identify a new leaf when connecting. |
Definition at line 182 of file LinkTable.h.
|
inline |
Get the "next" link.
This method is used to iterate through the links. The order of the links is arbitrary.
lnk | is a link number |
Definition at line 147 of file LinkTable.h.
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.
Definition at line 277 of file LinkTable.cpp.
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.
in | is an open input stream |
Definition at line 172 of file LinkTable.cpp.
|
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.
in | is an open input stream |
Definition at line 129 of file LinkTable.cpp.
bool forest::LinkTable::remapEntry | ( | int | lnk, |
ipa_t | peerIp, | ||
ipp_t | peerPort | ||
) |
Remap an entry added earlier using a nonce.
peerIp | is the IP address of this link's peer |
peerPort | is the port number of this link's peer |
Definition at line 64 of file LinkTable.cpp.
void forest::LinkTable::removeEntry | ( | int | lnk) |
Remove the table entry for a link.
lnk | is the link number for the entry to be deleted |
lnk | is the link number for the entry to be deleted |
Definition at line 73 of file LinkTable.cpp.
bool forest::LinkTable::revertEntry | ( | int | lnk) |
Revert an entry that was remapped earlier.
Definition at line 79 of file LinkTable.cpp.
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.
lnk | is a valid link number |
adr | is a Forest unicast address |
lnk | is a valid link number |
peerPort | is the port number of the peer node |
lnk | is a valid link number |
adr | is a Forest unicast address |
Definition at line 87 of file LinkTable.cpp.
string & forest::LinkTable::toString | ( | ) | const |
Create a string representing the table.
s | is a reference to a string in which result is returned |
Definition at line 204 of file LinkTable.cpp.
char * forest::LinkTable::unpack | ( | int | lnk, |
char * | buf | ||
) |
Unpack a link table entry from a packet buffer.
Definition at line 309 of file LinkTable.cpp.
|
inline |
Determine if a link number is valid.
lnk | is a link number |
Definition at line 130 of file LinkTable.h.