ns-3
|
a polymophic address class More...
#include <address.h>
Public Types | |
enum | MaxSize_e { MAX_SIZE = 20 } |
Public Member Functions | |
Address () | |
Address (uint8_t type, const uint8_t *buffer, uint8_t len) | |
Address (const Address &address) | |
Address & | operator= (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) |
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) |
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:
The maximum size of a byte buffer which can be stored in an Address instance.
ns3::Address::Address | ( | ) |
Create an invalid address
ns3::Address::Address | ( | uint8_t | type, |
const uint8_t * | buffer, | ||
uint8_t | len | ||
) |
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.
References 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. |
References NS_ASSERT.
Referenced by ns3::Mac64Address::ConvertFrom(), ns3::Mac48Address::ConvertFrom(), ns3::InetSocketAddress::ConvertFrom(), ns3::Inet6SocketAddress::ConvertFrom(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), ns3::UanAddress::IsMatchingType(), ns3::Mac64Address::IsMatchingType(), ns3::Mac48Address::IsMatchingType(), ns3::InetSocketAddress::IsMatchingType(), ns3::Inet6SocketAddress::IsMatchingType(), ns3::Ipv4Address::IsMatchingType(), and ns3::Ipv6Address::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().
References NS_ASSERT.
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.
References NS_ASSERT.
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.
References NS_ASSERT.
Referenced by ns3::Icmpv6OptionLinkLayerAddress::Deserialize().
uint32_t ns3::Address::CopyTo | ( | uint8_t | buffer[MAX_SIZE] | ) | const |
buffer | buffer to copy the address bytes to. |
References NS_ASSERT.
Referenced by ns3::UanAddress::ConvertFrom(), ns3::PacketSocketAddress::ConvertFrom(), ns3::Mac64Address::ConvertFrom(), ns3::Mac48Address::ConvertFrom(), ns3::InetSocketAddress::ConvertFrom(), ns3::Inet6SocketAddress::ConvertFrom(), ns3::Ipv4Address::ConvertFrom(), ns3::Ipv6Address::ConvertFrom(), and ns3::Icmpv6OptionLinkLayerAddress::Serialize().
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.
References NS_ASSERT, ns3::TagBuffer::Read(), and ns3::TagBuffer::ReadU8().
Referenced by ns3::SocketAddressTag::Deserialize().
uint8_t ns3::Address::GetLength | ( | void | ) | const |
References NS_ASSERT.
Referenced by ns3::ArpHeader::GetSerializedSize(), ns3::Icmpv6OptionLinkLayerAddress::GetSerializedSize(), ns3::Icmpv6L4Protocol::SendRedirection(), ns3::ArpHeader::Serialize(), and ns3::Icmpv6OptionLinkLayerAddress::Serialize().
uint32_t ns3::Address::GetSerializedSize | ( | void | ) | const |
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + 2
Referenced by ns3::SocketAddressTag::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.
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.
Referenced by ns3::PacketSocketAddress::IsMatchingType().
|
static |
Allocate a new type id for a new type of address.
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 |
References ns3::TagBuffer::Write(), and ns3::TagBuffer::WriteU8().
Referenced by ns3::SocketAddressTag::Serialize().