a polymophic address class More...
#include "address.h"
Public Types | |
enum | MaxSize_e { MAX_SIZE = 20 } |
The maximum size of a byte buffer which can be stored in an Address instance. More... | |
Public Member Functions | |
Address () | |
Create an invalid address. More... | |
Address (uint8_t type, const uint8_t *buffer, uint8_t len) | |
Create an address from a type and a buffer. More... | |
Address (const Address &address) | |
Create an address from another address. More... | |
bool | CheckCompatible (uint8_t type, uint8_t len) const |
uint32_t | CopyAllFrom (const uint8_t *buffer, uint8_t len) |
uint32_t | CopyAllTo (uint8_t *buffer, uint8_t len) const |
uint32_t | CopyFrom (const uint8_t *buffer, uint8_t len) |
uint32_t | CopyTo (uint8_t buffer[MAX_SIZE]) const |
Copy the address bytes into a buffer. More... | |
void | Deserialize (TagBuffer buffer) |
uint8_t | GetLength (void) const |
Get the length of the underlying address. More... | |
uint32_t | GetSerializedSize (void) const |
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + 2. More... | |
bool | IsInvalid (void) const |
bool | IsMatchingType (uint8_t type) const |
Address & | operator= (const Address &address) |
Basic assignment operator. More... | |
void | Serialize (TagBuffer buffer) const |
Serialize this address in host byte order to a byte buffer. More... | |
Static Public Member Functions | |
static uint8_t | Register (void) |
Allocate a new type id for a new type of address. More... | |
Private Attributes | |
uint8_t | m_data [MAX_SIZE] |
The address value. More... | |
uint8_t | m_len |
Length of the address. More... | |
uint8_t | m_type |
Type of the address. More... | |
Friends | |
bool | operator!= (const Address &a, const Address &b) |
Not equal to operator. More... | |
bool | operator< (const Address &a, const Address &b) |
Less than operator. More... | |
std::ostream & | operator<< (std::ostream &os, const Address &address) |
Stream insertion operator. More... | |
bool | operator== (const Address &a, const Address &b) |
Equal to operator. More... | |
std::istream & | operator>> (std::istream &is, Address &address) |
Stream extraction operator. More... | |
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:
ns3::Address::Address | ( | ) |
ns3::Address::Address | ( | uint8_t | type, |
const uint8_t * | buffer, | ||
uint8_t | len | ||
) |
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.
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. |
Definition at line 41 of file address.cc.
References m_data, m_len, MAX_SIZE, NS_ASSERT, and NS_LOG_FUNCTION.
ns3::Address::Address | ( | const Address & | address | ) |
Create an address from another address.
address | the address to copy |
Definition at line 49 of file address.cc.
References first::address, m_data, m_len, MAX_SIZE, and NS_ASSERT.
bool ns3::Address::CheckCompatible | ( | uint8_t | type, |
uint8_t | len | ||
) | const |
type | a type id as returned by Address::Register |
len | the length associated to this type id. |
Definition at line 122 of file address.cc.
References m_len, m_type, MAX_SIZE, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by ns3::Inet6SocketAddress::ConvertFrom(), and ns3::Inet6SocketAddress::IsMatchingType().
uint32_t ns3::Address::CopyAllFrom | ( | const uint8_t * | buffer, |
uint8_t | len | ||
) |
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 |
The inverse of CopyAllTo().
Definition at line 110 of file address.cc.
References m_data, m_len, m_type, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by ns3::PacketSocketAddress::ConvertFrom().
uint32_t ns3::Address::CopyAllTo | ( | uint8_t * | buffer, |
uint8_t | len | ||
) | const |
buffer | buffer to copy the whole address data structure to |
len | the size of the buffer |
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 90 of file address.cc.
References m_data, m_len, m_type, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by ns3::PacketSocketAddress::ConvertTo().
uint32_t ns3::Address::CopyFrom | ( | const uint8_t * | buffer, |
uint8_t | len | ||
) |
buffer | pointer to a buffer of bytes which contain a serialized representation of the address in network byte order. |
len | length of buffer |
Copy the address bytes from buffer into to the internal buffer of this address instance.
Definition at line 101 of file address.cc.
References m_data, m_len, MAX_SIZE, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by ns3::DhcpServer::AddStaticDhcpEntry(), ns3::Icmpv6OptionLinkLayerAddress::Deserialize(), ns3::DhcpHeader::GetChaddr(), ns3::ReadFrom(), and ns3::DhcpClient::StartApplication().
uint32_t ns3::Address::CopyTo | ( | uint8_t | buffer[MAX_SIZE] | ) | const |
Copy the address bytes into a buffer.
buffer | buffer to copy the address bytes to. |
Definition at line 82 of file address.cc.
References m_data, m_len, MAX_SIZE, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by ns3::DhcpServer::AddStaticDhcpEntry(), ns3::Inet6SocketAddress::ConvertFrom(), ns3::ArpQueueDiscItem::Hash(), ns3::UanNetDevice::Send(), ns3::Icmpv6OptionLinkLayerAddress::Serialize(), ns3::DhcpHeader::SetChaddr(), ns3::DhcpClient::StartApplication(), and ns3::WriteTo().
void ns3::Address::Deserialize | ( | TagBuffer | buffer | ) |
buffer | buffer to read address from |
The input address buffer is expected to be in host byte order format.
Definition at line 163 of file address.cc.
References m_data, m_len, m_type, MAX_SIZE, NS_ASSERT, NS_LOG_FUNCTION, ns3::TagBuffer::Read(), and ns3::TagBuffer::ReadU8().
Referenced by ns3::PacketSocketTag::Deserialize().
uint8_t ns3::Address::GetLength | ( | void | ) | const |
Get the length of the underlying address.
Definition at line 75 of file address.cc.
References m_len, MAX_SIZE, NS_ASSERT, and NS_LOG_FUNCTION.
Referenced by ns3::ArpHeader::GetSerializedSize(), ns3::ArpQueueDiscItem::Hash(), ns3::Icmpv6OptionLinkLayerAddress::Icmpv6OptionLinkLayerAddress(), ns3::operator<(), ns3::Icmpv6L4Protocol::SendRedirection(), ns3::ArpHeader::Serialize(), ns3::Icmpv6OptionLinkLayerAddress::Serialize(), ns3::DhcpHeader::SetChaddr(), and ns3::WriteTo().
uint32_t ns3::Address::GetSerializedSize | ( | void | ) | const |
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + 2.
Definition at line 147 of file address.cc.
References m_len, and NS_LOG_FUNCTION.
Referenced by ns3::PacketSocketTag::GetSerializedSize().
bool ns3::Address::IsInvalid | ( | void | ) | const |
An address is invalid if and only if it was created through the default constructor and it was never re-initialized.
Definition at line 68 of file address.cc.
References m_len, m_type, and NS_LOG_FUNCTION.
Referenced by DualStackTestCase::DoRun().
bool ns3::Address::IsMatchingType | ( | uint8_t | type | ) | const |
type | a type id as returned by Address::Register |
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 131 of file address.cc.
References m_type, and NS_LOG_FUNCTION.
Basic assignment operator.
address | the address to copy |
Definition at line 57 of file address.cc.
References first::address, m_data, m_len, m_type, MAX_SIZE, and NS_ASSERT.
|
static |
Allocate a new type id for a new type of address.
Definition at line 138 of file address.cc.
References NS_LOG_FUNCTION_NOARGS.
Referenced by ns3::Mac16Address::GetType(), ns3::Mac64Address::GetType(), ns3::PacketSocketAddress::GetType(), ns3::Mac8Address::GetType(), ns3::Inet6SocketAddress::GetType(), ns3::InetSocketAddress::GetType(), ns3::Mac48Address::GetType(), ns3::Ipv4Address::GetType(), and ns3::Ipv6Address::GetType().
void ns3::Address::Serialize | ( | TagBuffer | buffer | ) | const |
Serialize this address in host byte order to a byte buffer.
buffer | output buffer that gets written with this Address |
Definition at line 154 of file address.cc.
References m_data, m_len, m_type, NS_LOG_FUNCTION, ns3::TagBuffer::Write(), and ns3::TagBuffer::WriteU8().
Referenced by ns3::PacketSocketTag::Serialize().
Not equal to operator.
a | the first operand |
b | the first operand |
Definition at line 198 of file address.cc.
Less than operator.
a | the first operand |
b | the first operand |
Definition at line 202 of file address.cc.
|
friend |
Stream insertion operator.
os | the stream |
address | the address |
Definition at line 235 of file address.cc.
Equal to operator.
a | the first operand |
b | the first operand |
Definition at line 175 of file address.cc.
|
friend |
Stream extraction operator.
is | the stream |
address | the address |
Definition at line 251 of file address.cc.
|
private |
The address value.
Definition at line 275 of file address.h.
Referenced by Address(), CopyAllFrom(), CopyAllTo(), CopyFrom(), CopyTo(), Deserialize(), ns3::operator<(), operator=(), ns3::operator==(), and Serialize().
|
private |
Length of the address.
Definition at line 274 of file address.h.
Referenced by Address(), CheckCompatible(), CopyAllFrom(), CopyAllTo(), CopyFrom(), CopyTo(), Deserialize(), GetLength(), GetSerializedSize(), IsInvalid(), ns3::operator<(), operator=(), ns3::operator==(), and Serialize().
|
private |
Type of the address.
Definition at line 273 of file address.h.
Referenced by CheckCompatible(), CopyAllFrom(), CopyAllTo(), Deserialize(), IsInvalid(), IsMatchingType(), ns3::operator<(), operator=(), ns3::operator==(), and Serialize().