TransportAddress Class Reference

#include <TransportAddress.h>

Inheritance diagram for TransportAddress:

NodeHandle BrooseHandle List of all members.

Detailed Description

This class implements a common transport address.


It covers the complete node information, like IP-Address, and port. The information can be sparse, so parts can be omited by setting the property to an unspecified value.

Author:
Markus Mauch

Sebastian Mies


Public Types

typedef hash_set< TransportAddress,
hashFcn
Set
 a hashed set of TransportAddresses

Public Member Functions

 TransportAddress ()
 Constructs a unspecified TransportAddress.
virtual ~TransportAddress ()
 Standard destructor.
 TransportAddress (const TransportAddress &handle)
 Copy constructor.
 TransportAddress (const IPvXAddress &ip, int port=-1)
 Complete constructor.
bool operator== (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator!= (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator< (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator> (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator<= (const TransportAddress &rhs) const
 compares this to a given TransportAddress
bool operator>= (const TransportAddress &rhs) const
 compares this to a given TransportAddress
TransportAddressoperator= (const TransportAddress &rhs)
 assigns ip and port of rhs to this->ip and this->port
void setAddress (const IPvXAddress &ip, int port=-1)
 sets this->ip to ip and port to -1 if unspecified
void setPort (int port)
 sets this->port to the given port
const IPvXAddress & getAddress () const
 returns ip address
int getPort () const
 returns port
bool isUnspecified () const
 indicates if TransportAddress is specified
size_t hash () const
 creates a hash value of ip and port
virtual void netPack (cCommBuffer *b)
 serializes the object into a buffer
virtual void netUnpack (cCommBuffer *b)
 deserializes the object from a buffer

Public Attributes

IPvXAddress ip
 the ip of this TransportAddress object
int port
 the port of this TransportAddress object

Static Public Attributes

static const TransportAddress UNSPECIFIED_NODE
 TransportAddress without specified ip and port.

Private Member Functions

void assertUnspecified (const TransportAddress &handle) const
 throws an opp_error if this or handle is unspecified

Friends

std::ostream & operator<< (std::ostream &os, const TransportAddress &n)
 standard output stream for TransportAddress, gives out ip and port

Classes

class  hashFcn
 defines a hash function for TransportAddress More...


Member Typedef Documentation

typedef hash_set<TransportAddress, hashFcn> TransportAddress::Set

a hashed set of TransportAddresses

Reimplemented in NodeHandle.


Constructor & Destructor Documentation

TransportAddress::TransportAddress (  ) 

Constructs a unspecified TransportAddress.

00051 {
00052     port = -1;
00053 }

virtual TransportAddress::~TransportAddress (  )  [inline, virtual]

Standard destructor.

00085 {};

TransportAddress::TransportAddress ( const TransportAddress handle  ) 

Copy constructor.

Parameters:
handle The TransportAddress to copy
00057 {
00058     port = handle.port;
00059     ip = handle.ip;
00060 }

TransportAddress::TransportAddress ( const IPvXAddress &  ip,
int  port = -1 
)

Complete constructor.

Parameters:
ip The IPvXAddress
port The UDP-Port
00065 {
00066     this->ip = ip;
00067     this->port = port;
00068 }


Member Function Documentation

bool TransportAddress::operator== ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if both IPvXAddress and port are equal, false otherwise
00087 {
00088     assertUnspecified(rhs);
00089     return (this->ip == rhs.ip && this->port == rhs.port);
00090 }

bool TransportAddress::operator!= ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if both IPvXAddress and port are not equal, false otherwise
00094 {
00095     assertUnspecified(rhs);
00096     return !(this->ip == rhs.ip && this->port == rhs.port );
00097 }

bool TransportAddress::operator< ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is smaller than rhs->ip, false otherwise
00101 {
00102     assertUnspecified(rhs);
00103     return this->ip < rhs.ip;
00104 }

bool TransportAddress::operator> ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is greater than rhs->ip, false otherwise
00108 {
00109     assertUnspecified(rhs);
00110     return !(this->ip < rhs.ip || this->ip == rhs.ip);
00111 }

bool TransportAddress::operator<= ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is smaller than or equal to rhs->ip, false otherwise
00115 {
00116     assertUnspecified(rhs);
00117     return this->ip < rhs.ip || this->ip == rhs.ip;
00118 }

bool TransportAddress::operator>= ( const TransportAddress rhs  )  const

compares this to a given TransportAddress

Parameters:
rhs the TransportAddress this is compared to
Returns:
true if this->ip is greater than or equal to rhs->ip, false otherwise
00122 {
00123     assertUnspecified(rhs);
00124     return !(this->ip < rhs.ip);
00125 }

TransportAddress & TransportAddress::operator= ( const TransportAddress rhs  ) 

assigns ip and port of rhs to this->ip and this->port

Parameters:
rhs the TransportAddress with the defined ip and port
Returns:
this TransportAddress object
00078 {
00079     this->ip = rhs.ip;
00080     this->port = rhs.port;
00081 
00082     return *this;
00083 }

void TransportAddress::setAddress ( const IPvXAddress &  ip,
int  port = -1 
)

sets this->ip to ip and port to -1 if unspecified

Parameters:
ip the new IPvXAddress
port the new port
00129 {
00130     this->ip = ip;
00131     if (port!=-1)
00132         this->port = port;
00133 }

void TransportAddress::setPort ( int  port  ) 

sets this->port to the given port

Parameters:
port the new port
00137 {
00138     this->port = port;
00139 }

const IPvXAddress & TransportAddress::getAddress (  )  const

returns ip address

Returns:
this->ip
00143 {
00144     return ip;
00145 }

int TransportAddress::getPort (  )  const

returns port

Returns:
this->port
00149 {
00150     return port;
00151 }

bool TransportAddress::isUnspecified (  )  const

indicates if TransportAddress is specified

Returns:
true, if TransportAddress has no ip or port specified, false otherwise

Reimplemented in NodeHandle.

00072 {
00073     return (ip.isUnspecified() || (port == -1));
00074 }

size_t TransportAddress::hash (  )  const

creates a hash value of ip and port

Returns:
the hash value
00155 {
00156     size_t iphash;
00157     if (ip.isIPv6()) {
00158         uint32_t* addr = (uint32_t*) ip.get6().words();
00159         iphash = (size_t)(addr[0]^addr[1]^addr[2]^addr[3]);
00160     } else {
00161         iphash = (size_t)ip.get4().getInt();
00162     }
00163 
00164     return (size_t)(iphash^port);
00165 }

void TransportAddress::assertUnspecified ( const TransportAddress handle  )  const [inline, private]

throws an opp_error if this or handle is unspecified

Parameters:
handle the TransportAddress to check
00170 {
00171     if ( this->isUnspecified() || handle.isUnspecified() )
00172         opp_error("TransportAddress: Trying to compare unspecified TransportAddress!");
00173 }

void TransportAddress::netPack ( cCommBuffer *  b  )  [virtual]

serializes the object into a buffer

Parameters:
b the buffer

Reimplemented in NodeHandle.

00216 {
00217     //cMessage::netPack(b);
00218     doPacking(b,this->ip);
00219     doPacking(b,this->port);
00220 }

void TransportAddress::netUnpack ( cCommBuffer *  b  )  [virtual]

deserializes the object from a buffer

Parameters:
b the buffer

Reimplemented in NodeHandle.

00223 {
00224     //cMessage::netUnpack(b);
00225     doUnpacking(b,this->ip);
00226     doUnpacking(b,this->port);
00227 }


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const TransportAddress n 
) [friend]

standard output stream for TransportAddress, gives out ip and port

Parameters:
os the ostream
n the TransportAddress
Returns:
the output stream
00038 {
00039     if (n.isUnspecified()) {
00040         os << "<unspec>";
00041     } else {
00042         os << n.ip << ":" << n.port;
00043     }
00044 
00045     return os;
00046 };


Member Data Documentation

IPvXAddress TransportAddress::ip

the ip of this TransportAddress object

int TransportAddress::port

the port of this TransportAddress object

const TransportAddress TransportAddress::UNSPECIFIED_NODE [static]

TransportAddress without specified ip and port.

Reimplemented in NodeHandle, and BrooseHandle.


The documentation for this class was generated from the following files:
Generated on Tue Jul 24 16:51:19 2007 for ITM OverSim by  doxygen 1.5.1