ns3::Address Class Reference
[Address]

a polymophic address class More...

#include <address.h>

List of all members.

Public Types

enum  MaxSize_e { MAX_SIZE = 30 }

Public Member Functions

 Address ()
 Address (uint8_t type, const uint8_t *buffer, uint8_t len)
 Address (const Address &address)
Addressoperator= (const Address &address)
bool IsInvalid (void) const
uint8_t GetLength (void) const
uint32_t CopyTo (uint8_t buffer[MAX_SIZE]) const
uint32_t CopyAllTo (uint8_t *buffer, uint8_t len) const
uint32_t CopyFrom (const uint8_t *buffer, uint8_t len)
uint32_t CopyAllFrom (const uint8_t *buffer, uint8_t len)
bool CheckCompatible (uint8_t type, uint8_t len) const
bool IsMatchingType (uint8_t type) const
uint32_t GetSerializedSize (void) const
void Serialize (TagBuffer buffer) const
void Deserialize (TagBuffer buffer)

Static Public Member Functions

static uint8_t Register (void)

Private Attributes

uint8_t m_type
uint8_t m_len
uint8_t m_data [MAX_SIZE]

Friends

bool operator== (const Address &a, const Address &b)
bool operator< (const Address &a, const Address &b)
std::ostream & operator<< (std::ostream &os, const Address &address)
std::istream & operator>> (std::istream &is, Address &address)

Detailed Description

a polymophic address class

This class is very similar in design and spirit to the BSD sockaddr structure: they are both used to hold multiple types of addresses together with the type of the address.

A new address class defined by a user needs to:

Typical code to create a new class type looks like:

 // this class represents addresses which are 2 bytes long.
 class MyAddress
 {
 public:
   Address ConvertTo (void) const;
   static MyAddress ConvertFrom (void);
 private:
   static uint8_t GetType (void);
 };

 Address MyAddress::ConvertTo (void) const
 {
   return Address (GetType (), m_buffer, 2);
 }
 MyAddress MyAddress::ConvertFrom (const Address &address)
 {
   MyAddress ad;
   NS_ASSERT (address.CheckCompatible (GetType (), 2));
   address.CopyTo (ad.m_buffer, 2);
   return ad;
 }
 uint8_t MyAddress::GetType (void)
 {
   static uint8_t type = Address::Register ();
   return type;
 }

Definition at line 86 of file address.h.


Member Enumeration Documentation

The maximum size of a byte buffer which can be stored in an Address instance.

Enumerator:
MAX_SIZE 

Definition at line 93 of file address.h.


Constructor & Destructor Documentation

ns3::Address::Address (  ) 

Create an invalid address

Definition at line 29 of file address.cc.

ns3::Address::Address ( uint8_t  type,
const uint8_t *  buffer,
uint8_t  len 
)
Parameters:
type the type of the Address to create
buffer a pointer to a buffer of bytes which hold a serialized representation of the address in network byte order.
len the length of the buffer.

Create an address from a type and a buffer. This constructor is typically invoked from the conversion functions of various address types when they have to convert themselves to an Address instance.

Definition at line 36 of file address.cc.

References m_data, m_len, MAX_SIZE, and NS_ASSERT.

ns3::Address::Address ( const Address address  ) 

Definition at line 43 of file address.cc.

References m_data, m_len, MAX_SIZE, and NS_ASSERT.


Member Function Documentation

bool ns3::Address::CheckCompatible ( uint8_t  type,
uint8_t  len 
) const
Parameters:
type a type id as returned by Address::Register
len the length associated to this type id.
Returns:
true if the type of the address stored internally is compatible with the requested type, false otherwise.

Definition at line 110 of file address.cc.

References m_len, m_type, MAX_SIZE, and NS_ASSERT.

Referenced by ns3::Mac48Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Ipv4Address::ConvertFrom(), ns3::Mac48Address::IsMatchingType(), ns3::Ipv6Address::IsMatchingType(), ns3::Ipv4Address::IsMatchingType(), ns3::InetSocketAddress::IsMatchingType(), and ns3::Mac64Address::operator Address().

uint32_t ns3::Address::CopyAllFrom ( const uint8_t *  buffer,
uint8_t  len 
)
Parameters:
buffer pointer to a buffer of bytes which contain a copy of all the members of this Address class.
len the length of the buffer
Returns:
the number of bytes copied.

The inverse of CopyAllTo().

See also:
CopyAllTo

Definition at line 99 of file address.cc.

References m_data, m_len, m_type, and NS_ASSERT.

uint32_t ns3::Address::CopyAllTo ( uint8_t *  buffer,
uint8_t  len 
) const
Parameters:
buffer buffer to copy the whole address data structure to
len the size of the buffer
Returns:
the number of bytes copied.

Copies the type to buffer[0], the length of the address internal buffer to buffer[1] and copies the internal buffer starting at buffer[2]. len must be at least the size of the internal buffer plus a byte for the type and a byte for the length.

Definition at line 81 of file address.cc.

References m_data, m_len, m_type, and NS_ASSERT.

Referenced by ns3::PacketSocketAddress::ConvertTo().

uint32_t ns3::Address::CopyFrom ( const uint8_t *  buffer,
uint8_t  len 
)
Parameters:
buffer pointer to a buffer of bytes which contain a serialized representation of the address in network byte order.
len length of buffer
Returns:
the number of bytes copied.

Copy the address bytes from buffer into to the internal buffer of this address instance.

Definition at line 91 of file address.cc.

References m_data, m_len, MAX_SIZE, and NS_ASSERT.

uint32_t ns3::Address::CopyTo ( uint8_t  buffer[MAX_SIZE]  )  const
Parameters:
buffer buffer to copy the address bytes to.
Returns:
the number of bytes copied.

Definition at line 74 of file address.cc.

References m_data, m_len, and NS_ASSERT.

Referenced by ns3::Mac48Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::Ipv4Address::ConvertFrom(), and ns3::CsmaNetDevice::Receive().

void ns3::Address::Deserialize ( TagBuffer  buffer  ) 
Parameters:
buffer buffer to read address from

The input address buffer is expected to be in host byte order format.

Definition at line 144 of file address.cc.

References m_data, m_len, m_type, MAX_SIZE, NS_ASSERT, ns3::TagBuffer::Read(), and ns3::TagBuffer::ReadU8().

Referenced by ns3::SocketAddressTag::Deserialize().

uint8_t ns3::Address::GetLength ( void   )  const
Returns:
the length of the underlying address.

Definition at line 68 of file address.cc.

References m_len, MAX_SIZE, and NS_ASSERT.

Referenced by ns3::ArpHeader::Serialize().

uint32_t ns3::Address::GetSerializedSize ( void   )  const

Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + 2

Returns:
the number of bytes required for an Address in serialized form

Definition at line 130 of file address.cc.

References m_len.

Referenced by ns3::SocketAddressTag::GetSerializedSize().

bool ns3::Address::IsInvalid ( void   )  const
Returns:
true if this address is invalid, false otherwise.

An address is invalid if and only if it was created through the default constructor and it was never re-initialized.

Definition at line 62 of file address.cc.

References m_len, and m_type.

bool ns3::Address::IsMatchingType ( uint8_t  type  )  const
Parameters:
type a type id as returned by Address::Register
Returns:
true if the type of the address stored internally is compatible with the requested type, false otherwise.

This method checks that the types are _exactly_ equal. This method is really used only by the PacketSocketAddress and there is little point in using it otherwise so, you have been warned: DO NOT USE THIS METHOD.

Definition at line 116 of file address.cc.

References m_type.

Address & ns3::Address::operator= ( const Address address  ) 

Definition at line 51 of file address.cc.

References m_data, m_len, m_type, MAX_SIZE, and NS_ASSERT.

uint8_t ns3::Address::Register ( void   )  [static]

Allocate a new type id for a new type of address.

Returns:
a new type id.

Definition at line 122 of file address.cc.

Referenced by ns3::Mac48Address::GetType(), ns3::Ipv6Address::GetType(), and ns3::Ipv4Address::GetType().

void ns3::Address::Serialize ( TagBuffer  buffer  )  const

Serialize this address in host byte order to a byte buffer

Parameters:
buffer output buffer that gets written with this Address

Definition at line 136 of file address.cc.

References m_data, m_len, m_type, ns3::TagBuffer::Write(), and ns3::TagBuffer::WriteU8().

Referenced by ns3::SocketAddressTag::Serialize().


Friends And Related Function Documentation

bool operator< ( const Address a,
const Address b 
) [friend]
std::ostream& operator<< ( std::ostream &  os,
const Address address 
) [friend]
bool operator== ( const Address a,
const Address b 
) [friend]
std::istream& operator>> ( std::istream &  is,
Address address 
) [friend]

Member Data Documentation

uint8_t ns3::Address::m_data[MAX_SIZE] [private]
uint8_t ns3::Address::m_len [private]
uint8_t ns3::Address::m_type [private]

The documentation for this class was generated from the following files:
Generated on Thu Dec 3 14:11:59 2009 for NS-3 by  doxygen 1.6.3