merge with ns-3-dev
This commit is contained in:
@@ -24,31 +24,31 @@
|
||||
namespace ns3 {
|
||||
|
||||
Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6, uint16_t port)
|
||||
: m_ipv6(ipv6),
|
||||
: m_ipv6(ipv6),
|
||||
m_port(port)
|
||||
{
|
||||
}
|
||||
|
||||
Inet6SocketAddress::Inet6SocketAddress (Ipv6Address ipv6)
|
||||
: m_ipv6(ipv6),
|
||||
: m_ipv6(ipv6),
|
||||
m_port(0)
|
||||
{
|
||||
}
|
||||
|
||||
Inet6SocketAddress::Inet6SocketAddress (const char* ipv6, uint16_t port)
|
||||
: m_ipv6(Ipv6Address(ipv6)),
|
||||
Inet6SocketAddress::Inet6SocketAddress (const char* ipv6, uint16_t port)
|
||||
: m_ipv6(Ipv6Address(ipv6)),
|
||||
m_port(port)
|
||||
{
|
||||
}
|
||||
|
||||
Inet6SocketAddress::Inet6SocketAddress (const char* ipv6)
|
||||
: m_ipv6(Ipv6Address(ipv6)),
|
||||
Inet6SocketAddress::Inet6SocketAddress (const char* ipv6)
|
||||
: m_ipv6(Ipv6Address(ipv6)),
|
||||
m_port(0)
|
||||
{
|
||||
}
|
||||
|
||||
Inet6SocketAddress::Inet6SocketAddress (uint16_t port)
|
||||
: m_ipv6(Ipv6Address::GetAny()),
|
||||
Inet6SocketAddress::Inet6SocketAddress (uint16_t port)
|
||||
: m_ipv6(Ipv6Address::GetAny()),
|
||||
m_port(port)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \ingroup address
|
||||
* \class Inet6SocketAddress
|
||||
* \brief An Inet6 address class.
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "ns3/log.h"
|
||||
#include "ipv4-address.h"
|
||||
#include "ns3/assert.h"
|
||||
@@ -28,26 +29,29 @@ namespace ns3 {
|
||||
|
||||
#define ASCII_DOT (0x2e)
|
||||
#define ASCII_ZERO (0x30)
|
||||
#define ASCII_SLASH (0x2f)
|
||||
|
||||
static uint32_t
|
||||
AsciiToIpv4Host (char const *address)
|
||||
{
|
||||
uint32_t host = 0;
|
||||
while (true) {
|
||||
uint8_t byte = 0;
|
||||
while (*address != ASCII_DOT &&
|
||||
*address != 0) {
|
||||
byte *= 10;
|
||||
byte += *address - ASCII_ZERO;
|
||||
while (true)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
while (*address != ASCII_DOT && *address != 0)
|
||||
{
|
||||
byte *= 10;
|
||||
byte += *address - ASCII_ZERO;
|
||||
address++;
|
||||
}
|
||||
host <<= 8;
|
||||
host |= byte;
|
||||
if (*address == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
address++;
|
||||
}
|
||||
host <<= 8;
|
||||
host |= byte;
|
||||
if (*address == 0) {
|
||||
break;
|
||||
}
|
||||
address++;
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
@@ -63,9 +67,18 @@ Ipv4Mask::Ipv4Mask ()
|
||||
Ipv4Mask::Ipv4Mask (uint32_t mask)
|
||||
: m_mask (mask)
|
||||
{}
|
||||
|
||||
Ipv4Mask::Ipv4Mask (char const *mask)
|
||||
{
|
||||
m_mask = AsciiToIpv4Host (mask);
|
||||
if (*mask == ASCII_SLASH)
|
||||
{
|
||||
m_mask = static_cast<uint32_t> (atoi (++mask));
|
||||
NS_ASSERT (m_mask <= 32);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mask = AsciiToIpv4Host (mask);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -133,6 +146,20 @@ Ipv4Mask::GetOnes (void)
|
||||
return ones;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
Ipv4Mask::GetPrefixLength (void) const
|
||||
{
|
||||
uint16_t tmp = 0;
|
||||
uint32_t mask = m_mask;
|
||||
while (mask != 0 )
|
||||
{
|
||||
mask = mask << 1;
|
||||
tmp++;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
Ipv4Address::Ipv4Address ()
|
||||
: m_address (0x66666666)
|
||||
{}
|
||||
|
||||
@@ -198,11 +198,26 @@ private:
|
||||
* \ingroup address
|
||||
*
|
||||
* \brief a class to represent an Ipv4 address mask
|
||||
*
|
||||
* The constructor takes arguments according to a few formats.
|
||||
* Ipv4Mask ("255.255.255.255"), Ipv4Mask ("/32"), and Ipv4Mask (0xffffffff)
|
||||
* are all equivalent.
|
||||
*/
|
||||
class Ipv4Mask {
|
||||
public:
|
||||
/**
|
||||
* Will initialize to a garbage value (0x66666666)
|
||||
*/
|
||||
Ipv4Mask ();
|
||||
/**
|
||||
* param mask bitwise integer representation of the mask
|
||||
*
|
||||
* For example, the integer input 0xffffff00 yields a 24-bit mask
|
||||
*/
|
||||
Ipv4Mask (uint32_t mask);
|
||||
/**
|
||||
* \param mask String constant either in "255.255.255.0" or "/24" format
|
||||
*/
|
||||
Ipv4Mask (char const *mask);
|
||||
/**
|
||||
* \param a first address to compare
|
||||
@@ -237,6 +252,10 @@ public:
|
||||
* \param os The output stream to which this Ipv4Address is printed
|
||||
*/
|
||||
void Print (std::ostream &os) const;
|
||||
/**
|
||||
* \return the prefix length of mask (the yy in x.x.x.x/yy notation)
|
||||
*/
|
||||
uint16_t GetPrefixLength (void) const;
|
||||
/**
|
||||
* \return the 255.0.0.0 mask corresponding to a typical loopback address
|
||||
*/
|
||||
|
||||
@@ -33,119 +33,141 @@ namespace ns3 {
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
{ /* } */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Get a hash key.
|
||||
* \param k the key
|
||||
* \param length the length of the key
|
||||
* \param level the previous hash, or an arbitrary value
|
||||
* \return hash
|
||||
* \note Adpated from Jens Jakobsen implementation (chillispot).
|
||||
*/
|
||||
static uint32_t lookuphash (unsigned char* k, uint32_t length, uint32_t level)
|
||||
/**
|
||||
* \brief Get a hash key.
|
||||
* \param k the key
|
||||
* \param length the length of the key
|
||||
* \param level the previous hash, or an arbitrary value
|
||||
* \return hash
|
||||
* \note Adapted from Jens Jakobsen implementation (chillispot).
|
||||
*/
|
||||
static uint32_t lookuphash (unsigned char* k, uint32_t length, uint32_t level)
|
||||
{
|
||||
#define mix(a, b, c) \
|
||||
({ \
|
||||
(a) -= (b); (a) -= (c); (a) ^= ((c) >> 13); \
|
||||
(b) -= (c); (b) -= (a); (b) ^= ((a) << 8); \
|
||||
(c) -= (a); (c) -= (b); (c) ^= ((b) >> 13); \
|
||||
(a) -= (b); (a) -= (c); (a) ^= ((c) >> 12); \
|
||||
(b) -= (c); (b) -= (a); (b) ^= ((a) << 16); \
|
||||
(c) -= (a); (c) -= (b); (c) ^= ((b) >> 5); \
|
||||
(a) -= (b); (a) -= (c); (a) ^= ((c) >> 3); \
|
||||
(b) -= (c); (b) -= (a); (b) ^= ((a) << 10); \
|
||||
(c) -= (a); (c) -= (b); (c) ^= ((b) >> 15); \
|
||||
})
|
||||
|
||||
typedef uint32_t ub4; /* unsigned 4-byte quantities */
|
||||
typedef unsigned char ub1; /* unsigned 1-byte quantities */
|
||||
uint32_t a = 0;
|
||||
uint32_t b = 0;
|
||||
uint32_t c = 0;
|
||||
uint32_t len = 0;
|
||||
|
||||
/* Set up the internal state */
|
||||
len = length;
|
||||
a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
|
||||
c = level; /* the previous hash value */
|
||||
|
||||
/* handle most of the key */
|
||||
while (len >= 12)
|
||||
{
|
||||
#define mix(a,b,c) \
|
||||
{ \
|
||||
a -= b; a -= c; a ^= (c>>13); \
|
||||
b -= c; b -= a; b ^= (a<<8); \
|
||||
c -= a; c -= b; c ^= (b>>13); \
|
||||
a -= b; a -= c; a ^= (c>>12); \
|
||||
b -= c; b -= a; b ^= (a<<16); \
|
||||
c -= a; c -= b; c ^= (b>>5); \
|
||||
a -= b; a -= c; a ^= (c>>3); \
|
||||
b -= c; b -= a; b ^= (a<<10); \
|
||||
c -= a; c -= b; c ^= (b>>15); \
|
||||
}
|
||||
|
||||
typedef uint32_t ub4; /* unsigned 4-byte quantities */
|
||||
typedef unsigned char ub1; /* unsigned 1-byte quantities */
|
||||
uint32_t a,b,c,len;
|
||||
|
||||
/* Set up the internal state */
|
||||
len = length;
|
||||
a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
|
||||
c = level; /* the previous hash value */
|
||||
|
||||
/*---------------------------------------- handle most of the key */
|
||||
while (len >= 12)
|
||||
{
|
||||
a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24));
|
||||
b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24));
|
||||
c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24));
|
||||
mix(a,b,c);
|
||||
k += 12; len -= 12;
|
||||
}
|
||||
|
||||
/*------------------------------------- handle the last 11 bytes */
|
||||
c += length;
|
||||
switch(len) /* all the case statements fall through */
|
||||
{
|
||||
case 11: c+=((ub4)k[10]<<24);
|
||||
case 10: c+=((ub4)k[9]<<16);
|
||||
case 9 : c+=((ub4)k[8]<<8);
|
||||
/* the first byte of c is reserved for the length */
|
||||
case 8 : b+=((ub4)k[7]<<24);
|
||||
case 7 : b+=((ub4)k[6]<<16);
|
||||
case 6 : b+=((ub4)k[5]<<8);
|
||||
case 5 : b+=k[4];
|
||||
case 4 : a+=((ub4)k[3]<<24);
|
||||
case 3 : a+=((ub4)k[2]<<16);
|
||||
case 2 : a+=((ub4)k[1]<<8);
|
||||
case 1 : a+=k[0];
|
||||
/* case 0: nothing left to add */
|
||||
}
|
||||
mix(a,b,c);
|
||||
/*-------------------------------------------- report the result */
|
||||
return c;
|
||||
a += (k[0] + ((ub4)k[1] << 8) + ((ub4)k[2] << 16) + ((ub4)k[3] << 24));
|
||||
b += (k[4] + ((ub4)k[5] << 8) + ((ub4)k[6] << 16) + ((ub4)k[7] << 24));
|
||||
c += (k[8] + ((ub4)k[9] << 8) + ((ub4)k[10] << 16) + ((ub4)k[11] << 24));
|
||||
mix (a, b, c);
|
||||
k += 12;
|
||||
len -= 12;
|
||||
}
|
||||
|
||||
/* handle the last 11 bytes */
|
||||
c += length;
|
||||
switch (len) /* all the case statements fall through */
|
||||
{
|
||||
case 11: c += ((ub4)k[10] << 24);
|
||||
case 10: c += ((ub4)k[9] << 16);
|
||||
case 9 : c += ((ub4)k[8] << 8); /* the first byte of c is reserved for the length */
|
||||
case 8 : b += ((ub4)k[7] << 24);
|
||||
case 7 : b += ((ub4)k[6] << 16);
|
||||
case 6 : b += ((ub4)k[5] << 8);
|
||||
case 5 : b += k[4];
|
||||
case 4 : a += ((ub4)k[3] << 24);
|
||||
case 3 : a += ((ub4)k[2] << 16);
|
||||
case 2 : a += ((ub4)k[1] << 8);
|
||||
case 1 : a += k[0];
|
||||
/* case 0: nothing left to add */
|
||||
}
|
||||
mix (a, b, c);
|
||||
|
||||
#undef mix
|
||||
|
||||
/* report the result */
|
||||
return c;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Convert an IPv6 C-string into a 128-bit representation.
|
||||
* \return 1 if OK, 0 if failure (bad format, ...)
|
||||
* \return true if success, false otherwise (bad format, ...)
|
||||
* \note This function is strongly inspired by inet_pton6() from Paul Vixie.
|
||||
* \todo Handle IPv6 address with decimal value for last four bytes.
|
||||
*/
|
||||
static int AsciiToIpv6Host (char const *address, uint8_t addr[16])
|
||||
static bool AsciiToIpv6Host (const char *address, uint8_t addr[16])
|
||||
{
|
||||
static const char xdigits_l[] = "0123456789abcdef",
|
||||
xdigits_u[] = "0123456789ABCDEF";
|
||||
unsigned char tmp[16 /*NS_IN6ADDRSZ*/], *tp, *endp, *colonp;
|
||||
const char *xdigits, *curtok;
|
||||
int ch, seen_xdigits;
|
||||
unsigned int val;
|
||||
static const char xdigits_l[] = "0123456789abcdef";
|
||||
static const char xdigits_u[] = "0123456789ABCDEF";
|
||||
unsigned char tmp[16];
|
||||
unsigned char* tp = tmp;
|
||||
unsigned char* endp = 0;
|
||||
unsigned char* colonp = 0;
|
||||
const char* xdigits = 0;
|
||||
const char* curtok = 0;
|
||||
int ch = 0;
|
||||
int seen_xdigits = 0;
|
||||
unsigned int val = 0;
|
||||
|
||||
memset (tp, 0x00, 16);
|
||||
endp = tp + 16;
|
||||
|
||||
memset((tp = tmp), '\0', 16 /* NS_IN6ADDRSZ*/);
|
||||
endp = tp + 16 /*NS_IN6ADDRSZ*/;
|
||||
colonp = NULL;
|
||||
/* Leading :: requires some special handling. */
|
||||
if (*address == ':')
|
||||
{
|
||||
if (*++address != ':')
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
curtok = address;
|
||||
seen_xdigits = 0;
|
||||
val = 0;
|
||||
|
||||
while ((ch = *address++) != '\0')
|
||||
{
|
||||
const char *pch;
|
||||
const char *pch = 0;
|
||||
|
||||
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
||||
pch = strchr((xdigits = xdigits_u), ch);
|
||||
if (pch != NULL)
|
||||
if ((pch = strchr ((xdigits = xdigits_l), ch)) == 0)
|
||||
{
|
||||
pch = strchr ((xdigits = xdigits_u), ch);
|
||||
}
|
||||
|
||||
if (pch != 0)
|
||||
{
|
||||
val <<= 4;
|
||||
val |= (pch - xdigits);
|
||||
|
||||
if (++seen_xdigits > 4)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (ch == ':')
|
||||
{
|
||||
curtok = address;
|
||||
|
||||
if (!seen_xdigits)
|
||||
{
|
||||
if (colonp)
|
||||
@@ -153,8 +175,12 @@ static int AsciiToIpv6Host (char const *address, uint8_t addr[16])
|
||||
colonp = tp;
|
||||
continue;
|
||||
}
|
||||
if (tp + 2 /*NS_INT16SZ*/ > endp)
|
||||
|
||||
if (tp + 2 > endp)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
seen_xdigits = 0;
|
||||
@@ -174,52 +200,62 @@ static int AsciiToIpv6Host (char const *address, uint8_t addr[16])
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (seen_xdigits)
|
||||
{
|
||||
if (tp + 2/* NS_INT16SZ*/ > endp)
|
||||
if (tp + 2 > endp)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
||||
*tp++ = (unsigned char) val & 0xff;
|
||||
}
|
||||
if (colonp != NULL)
|
||||
|
||||
if (colonp != 0)
|
||||
{
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* Since some memmove ()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
const int n = tp - colonp;
|
||||
int i;
|
||||
int i = 0;
|
||||
|
||||
if (tp == endp)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
endp[- i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
|
||||
tp = endp;
|
||||
}
|
||||
if (tp != endp)
|
||||
return (0);
|
||||
|
||||
/* memcpy(dst, tmp, NS_IN6ADDRSZ); */
|
||||
memcpy(addr, tmp, 16);
|
||||
if (tp != endp)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
memcpy (addr, tmp, 16);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Ipv6Address::Ipv6Address ()
|
||||
{
|
||||
memset(m_address, 0x00, 16);
|
||||
memset (m_address, 0x00, 16);
|
||||
}
|
||||
|
||||
Ipv6Address::Ipv6Address (Ipv6Address const& addr)
|
||||
{
|
||||
memcpy(m_address, addr.m_address, 16);
|
||||
memcpy (m_address, addr.m_address, 16);
|
||||
}
|
||||
|
||||
Ipv6Address::Ipv6Address (Ipv6Address const* addr)
|
||||
{
|
||||
memcpy(m_address, addr->m_address, 16);
|
||||
memcpy (m_address, addr->m_address, 16);
|
||||
}
|
||||
|
||||
Ipv6Address::Ipv6Address (char const* address)
|
||||
@@ -230,7 +266,7 @@ Ipv6Address::Ipv6Address (char const* address)
|
||||
Ipv6Address::Ipv6Address (uint8_t address[16])
|
||||
{
|
||||
/* 128 bit => 16 bytes */
|
||||
memcpy(m_address, address, 16);
|
||||
memcpy (m_address, address, 16);
|
||||
}
|
||||
|
||||
Ipv6Address::~Ipv6Address ()
|
||||
@@ -246,12 +282,12 @@ void Ipv6Address::Set (char const* address)
|
||||
void Ipv6Address::Set (uint8_t address[16])
|
||||
{
|
||||
/* 128 bit => 16 bytes */
|
||||
memcpy(m_address, address, 16);
|
||||
memcpy (m_address, address, 16);
|
||||
}
|
||||
|
||||
void Ipv6Address::Serialize (uint8_t buf[16]) const
|
||||
{
|
||||
memcpy(buf, m_address, 16);
|
||||
memcpy (buf, m_address, 16);
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::Deserialize (const uint8_t buf[16])
|
||||
@@ -266,16 +302,16 @@ Ipv6Address Ipv6Address::MakeAutoconfiguredAddress (Mac48Address addr, Ipv6Addre
|
||||
uint8_t buf[16];
|
||||
uint8_t buf2[16];
|
||||
|
||||
addr.CopyTo(buf);
|
||||
prefix.GetBytes(buf2);
|
||||
addr.CopyTo (buf);
|
||||
prefix.GetBytes (buf2);
|
||||
|
||||
memcpy(buf2 + 8, buf, 3);
|
||||
memcpy (buf2 + 8, buf, 3);
|
||||
buf2[11] = 0xff;
|
||||
buf2[12] = 0xfe;
|
||||
memcpy(buf2 + 13, buf + 3, 3);
|
||||
memcpy (buf2 + 13, buf + 3, 3);
|
||||
buf2[8] |= 0x02;
|
||||
|
||||
ret.Set(buf2);
|
||||
ret.Set (buf2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -285,18 +321,18 @@ Ipv6Address Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac48Address addr)
|
||||
uint8_t buf[16];
|
||||
uint8_t buf2[16];
|
||||
|
||||
addr.CopyTo(buf);
|
||||
addr.CopyTo (buf);
|
||||
|
||||
memset(buf2, 0x00, sizeof(buf2));
|
||||
memset (buf2, 0x00, sizeof (buf2));
|
||||
buf2[0] = 0xfe;
|
||||
buf2[1] = 0x80;
|
||||
memcpy(buf2 + 8, buf, 3);
|
||||
memcpy (buf2 + 8, buf, 3);
|
||||
buf2[11] = 0xff;
|
||||
buf2[12] = 0xfe;
|
||||
memcpy(buf2 + 13, buf + 3, 3);
|
||||
memcpy (buf2 + 13, buf + 3, 3);
|
||||
buf2[8] |= 0x02;
|
||||
|
||||
ret.Set(buf2);
|
||||
ret.Set (buf2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -306,9 +342,9 @@ Ipv6Address Ipv6Address::MakeSolicitedAddress (Ipv6Address addr)
|
||||
uint8_t buf2[16];
|
||||
Ipv6Address ret;
|
||||
|
||||
addr.Serialize(buf2);
|
||||
addr.Serialize (buf2);
|
||||
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
memset (buf, 0x00, sizeof (buf));
|
||||
buf[0] = 0xff;
|
||||
buf[1] = 0x02;
|
||||
buf[11] = 0x01;
|
||||
@@ -317,62 +353,62 @@ Ipv6Address Ipv6Address::MakeSolicitedAddress (Ipv6Address addr)
|
||||
buf[14] = buf2[14];
|
||||
buf[15] = buf2[15];
|
||||
|
||||
ret.Set(buf);
|
||||
ret.Set (buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Ipv6Address::Print (std::ostream& os) const
|
||||
{
|
||||
os << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[0]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[1] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[2]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[3] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[4]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[5] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[6]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[7] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[8]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[9] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[10]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[11] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[12]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[13] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[14]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_address[15]
|
||||
<< std::dec << std::setfill(' ');
|
||||
os << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[0]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[1] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[2]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[3] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[4]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[5] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[6]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[7] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[8]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[9] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[10]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[11] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[12]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[13] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[14]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_address[15]
|
||||
<< std::dec << std::setfill (' ');
|
||||
}
|
||||
|
||||
bool Ipv6Address::IsLocalhost () const
|
||||
{
|
||||
static Ipv6Address localhost("::1");
|
||||
static Ipv6Address localhost ("::1");
|
||||
return (*this == localhost);
|
||||
}
|
||||
|
||||
bool Ipv6Address::IsMulticast () const
|
||||
{
|
||||
if(m_address[0] == 0xff)
|
||||
if (m_address[0] == 0xff)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::CombinePrefix (Ipv6Prefix const & prefix)
|
||||
Ipv6Address Ipv6Address::CombinePrefix (Ipv6Prefix const& prefix)
|
||||
{
|
||||
Ipv6Address ipv6;
|
||||
uint8_t addr[16];
|
||||
uint8_t pref[16];
|
||||
unsigned int i = 0;
|
||||
|
||||
memcpy(addr, m_address, 16);
|
||||
((Ipv6Prefix)prefix).GetBytes(pref);
|
||||
memcpy (addr, m_address, 16);
|
||||
((Ipv6Prefix)prefix).GetBytes (pref);
|
||||
|
||||
/* a little bit ugly... */
|
||||
for(i = 0 ; i < 16 ; i++)
|
||||
for (i = 0 ; i < 16 ; i++)
|
||||
{
|
||||
addr[i] = addr[i] & pref[i];
|
||||
}
|
||||
ipv6.Set(addr);
|
||||
ipv6.Set (addr);
|
||||
return ipv6;
|
||||
}
|
||||
|
||||
@@ -380,9 +416,9 @@ bool Ipv6Address::IsSolicitedMulticast () const
|
||||
{
|
||||
uint8_t buf[16];
|
||||
|
||||
Serialize(buf);
|
||||
Serialize (buf);
|
||||
|
||||
if(buf[0] == 0xff &&
|
||||
if (buf[0] == 0xff &&
|
||||
buf[1] == 0x02 &&
|
||||
buf[11] == 0x01 &&
|
||||
buf[12] == 0xff)
|
||||
@@ -394,31 +430,31 @@ bool Ipv6Address::IsSolicitedMulticast () const
|
||||
|
||||
bool Ipv6Address::IsAllNodesMulticast () const
|
||||
{
|
||||
static Ipv6Address allnodes("ff02::1");
|
||||
static Ipv6Address allnodes ("ff02::1");
|
||||
return (*this == allnodes);
|
||||
}
|
||||
|
||||
bool Ipv6Address::IsAllRoutersMulticast () const
|
||||
{
|
||||
static Ipv6Address allrouters("ff02::2");
|
||||
static Ipv6Address allrouters ("ff02::2");
|
||||
return (*this == allrouters);
|
||||
}
|
||||
|
||||
bool Ipv6Address::IsAllHostsMulticast () const
|
||||
{
|
||||
static Ipv6Address allhosts("ff02::3");
|
||||
static Ipv6Address allhosts ("ff02::3");
|
||||
return (*this == allhosts);
|
||||
}
|
||||
|
||||
bool Ipv6Address::IsAny () const
|
||||
{
|
||||
static Ipv6Address any("::");
|
||||
static Ipv6Address any ("::");
|
||||
return (*this == any);
|
||||
}
|
||||
|
||||
bool Ipv6Address::IsMatchingType (const Address& address)
|
||||
{
|
||||
return address.CheckCompatible(GetType(), 16);
|
||||
return address.CheckCompatible (GetType (), 16);
|
||||
}
|
||||
|
||||
Ipv6Address::operator Address () const
|
||||
@@ -430,7 +466,7 @@ Address Ipv6Address::ConvertTo (void) const
|
||||
{
|
||||
uint8_t buf[16];
|
||||
Serialize (buf);
|
||||
return Address(GetType(), buf, 16);
|
||||
return Address (GetType (), buf, 16);
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::ConvertFrom (const Address &address)
|
||||
@@ -443,55 +479,61 @@ Ipv6Address Ipv6Address::ConvertFrom (const Address &address)
|
||||
|
||||
uint8_t Ipv6Address::GetType (void)
|
||||
{
|
||||
static uint8_t type = Address::Register();
|
||||
static uint8_t type = Address::Register ();
|
||||
return type;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetZero ()
|
||||
{
|
||||
Ipv6Address zero("::");
|
||||
return zero;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetAny ()
|
||||
{
|
||||
Ipv6Address any("::");
|
||||
return any;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetAllNodesMulticast ()
|
||||
{
|
||||
Ipv6Address nmc("ff02::1");
|
||||
static Ipv6Address nmc ("ff02::1");
|
||||
return nmc;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetAllRoutersMulticast ()
|
||||
{
|
||||
Ipv6Address rmc("ff02::2");
|
||||
static Ipv6Address rmc ("ff02::2");
|
||||
return rmc;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetAllHostsMulticast ()
|
||||
{
|
||||
Ipv6Address hmc("ff02::3");
|
||||
static Ipv6Address hmc ("ff02::3");
|
||||
return hmc;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetLoopback ()
|
||||
{
|
||||
static Ipv6Address loopback("::1");
|
||||
static Ipv6Address loopback ("::1");
|
||||
return loopback;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetZero ()
|
||||
{
|
||||
static Ipv6Address zero ("::");
|
||||
return zero;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetAny ()
|
||||
{
|
||||
static Ipv6Address any ("::");
|
||||
return any;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Address::GetOnes ()
|
||||
{
|
||||
static Ipv6Address ones ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
||||
return ones;
|
||||
}
|
||||
|
||||
void Ipv6Address::GetBytes (uint8_t buf[16]) const
|
||||
{
|
||||
memcpy(buf, m_address, 16);
|
||||
memcpy (buf, m_address, 16);
|
||||
}
|
||||
|
||||
bool Ipv6Address::IsLinkLocal () const
|
||||
{
|
||||
Ipv6Address linkLocal("fe80::0");
|
||||
if(!IsMulticast() && ((Ipv6Address*)this)->CombinePrefix(Ipv6Prefix(64))==linkLocal)
|
||||
Ipv6Address linkLocal ("fe80::0");
|
||||
if (!IsMulticast () && ((Ipv6Address*)this)->CombinePrefix (Ipv6Prefix (64)) == linkLocal)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -500,7 +542,7 @@ bool Ipv6Address::IsLinkLocal () const
|
||||
|
||||
bool Ipv6Address::IsEqual (const Ipv6Address& other) const
|
||||
{
|
||||
if(!memcmp(m_address, other.m_address, 16))
|
||||
if (!memcmp (m_address, other.m_address, 16))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -509,7 +551,7 @@ bool Ipv6Address::IsEqual (const Ipv6Address& other) const
|
||||
|
||||
std::ostream& operator << (std::ostream& os, Ipv6Address const& address)
|
||||
{
|
||||
address.Print(os);
|
||||
address.Print (os);
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -523,17 +565,17 @@ std::istream& operator >> (std::istream& is, Ipv6Address& address)
|
||||
|
||||
Ipv6Prefix::Ipv6Prefix ()
|
||||
{
|
||||
memset(m_prefix, 0x00, 16);
|
||||
memset (m_prefix, 0x00, 16);
|
||||
}
|
||||
|
||||
Ipv6Prefix::Ipv6Prefix (char const* prefix)
|
||||
{
|
||||
AsciiToIpv6Host(prefix, m_prefix);
|
||||
AsciiToIpv6Host (prefix, m_prefix);
|
||||
}
|
||||
|
||||
Ipv6Prefix::Ipv6Prefix (uint8_t prefix[16])
|
||||
{
|
||||
memcpy(m_prefix, prefix, 16);
|
||||
memcpy (m_prefix, prefix, 16);
|
||||
}
|
||||
|
||||
Ipv6Prefix::Ipv6Prefix (uint8_t prefix)
|
||||
@@ -542,24 +584,24 @@ Ipv6Prefix::Ipv6Prefix (uint8_t prefix)
|
||||
unsigned int mod=0;
|
||||
unsigned int i=0;
|
||||
|
||||
memset(m_prefix, 0x00, 16);
|
||||
memset (m_prefix, 0x00, 16);
|
||||
|
||||
NS_ASSERT(prefix <= 128);
|
||||
NS_ASSERT (prefix <= 128);
|
||||
|
||||
nb = prefix / 8;
|
||||
mod = prefix % 8;
|
||||
|
||||
memset(m_prefix, 0xff, nb);
|
||||
memset (m_prefix, 0xff, nb);
|
||||
|
||||
if(mod)
|
||||
if (mod)
|
||||
{
|
||||
m_prefix[nb] = 0xff << (8-mod);
|
||||
}
|
||||
|
||||
if(nb < 16)
|
||||
if (nb < 16)
|
||||
{
|
||||
nb++;
|
||||
for(i = nb; i < 16 ; i++)
|
||||
for (i = nb; i < 16 ; i++)
|
||||
{
|
||||
m_prefix[i] = 0x00;
|
||||
}
|
||||
@@ -568,12 +610,12 @@ Ipv6Prefix::Ipv6Prefix (uint8_t prefix)
|
||||
|
||||
Ipv6Prefix::Ipv6Prefix (Ipv6Prefix const& prefix)
|
||||
{
|
||||
memcpy(m_prefix, prefix.m_prefix, 16);
|
||||
memcpy (m_prefix, prefix.m_prefix, 16);
|
||||
}
|
||||
|
||||
Ipv6Prefix::Ipv6Prefix (Ipv6Prefix const* prefix)
|
||||
{
|
||||
memcpy(m_prefix, prefix->m_prefix, 16);
|
||||
memcpy (m_prefix, prefix->m_prefix, 16);
|
||||
}
|
||||
|
||||
Ipv6Prefix::~Ipv6Prefix ()
|
||||
@@ -587,13 +629,13 @@ bool Ipv6Prefix::IsMatch (Ipv6Address a, Ipv6Address b) const
|
||||
uint8_t addrB[16];
|
||||
unsigned int i = 0;
|
||||
|
||||
a.GetBytes(addrA);
|
||||
b.GetBytes(addrB);
|
||||
a.GetBytes (addrA);
|
||||
b.GetBytes (addrB);
|
||||
|
||||
/* a little bit ugly... */
|
||||
for(i = 0 ; i < 16 ; i++)
|
||||
for (i = 0 ; i < 16 ; i++)
|
||||
{
|
||||
if((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
|
||||
if ((addrA[i] & m_prefix[i]) != (addrB[i] & m_prefix[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -603,51 +645,76 @@ bool Ipv6Prefix::IsMatch (Ipv6Address a, Ipv6Address b) const
|
||||
|
||||
void Ipv6Prefix::Print (std::ostream &os) const
|
||||
{
|
||||
os << std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[0]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[1] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[2]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[3] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[4]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[5] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[6]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[7] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[8]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[9] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[10]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[11] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[12]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[13] << ":"
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[14]
|
||||
<< std::hex << std::setw(2) << std::setfill('0') << (unsigned int) m_prefix[15];
|
||||
os << std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[0]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[1] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[2]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[3] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[4]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[5] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[6]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[7] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[8]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[9] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[10]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[11] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[12]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[13] << ":"
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[14]
|
||||
<< std::hex << std::setw (2) << std::setfill ('0') << (unsigned int) m_prefix[15];
|
||||
}
|
||||
|
||||
Ipv6Prefix Ipv6Prefix::GetLoopback ()
|
||||
{
|
||||
Ipv6Prefix prefix((uint8_t)128);
|
||||
static Ipv6Prefix prefix ((uint8_t)128);
|
||||
return prefix;
|
||||
}
|
||||
|
||||
Ipv6Prefix Ipv6Prefix::GetOnes ()
|
||||
{
|
||||
static Ipv6Prefix ones ((uint8_t)128);
|
||||
return ones;
|
||||
}
|
||||
|
||||
Ipv6Prefix Ipv6Prefix::GetZero ()
|
||||
{
|
||||
Ipv6Prefix prefix((uint8_t)0);
|
||||
static Ipv6Prefix prefix ((uint8_t)0);
|
||||
return prefix;
|
||||
}
|
||||
|
||||
void Ipv6Prefix::GetBytes (uint8_t buf[16]) const
|
||||
{
|
||||
memcpy(buf, m_prefix, 16);
|
||||
memcpy (buf, m_prefix, 16);
|
||||
}
|
||||
|
||||
uint8_t Ipv6Prefix::GetPrefixLength () const
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t prefixLength = 0;
|
||||
|
||||
for(i = 0 ; i < 16 ; i++)
|
||||
{
|
||||
uint8_t mask = m_prefix[i];
|
||||
|
||||
while(mask != 0)
|
||||
{
|
||||
mask = mask << 1;
|
||||
prefixLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return prefixLength;
|
||||
}
|
||||
|
||||
bool Ipv6Prefix::IsEqual (const Ipv6Prefix& other) const
|
||||
{
|
||||
if(!memcmp(m_prefix, other.m_prefix, 16))
|
||||
if (!memcmp (m_prefix, other.m_prefix, 16))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv6Prefix const& prefix)
|
||||
std::ostream& operator << (std::ostream& os, Ipv6Prefix const& prefix)
|
||||
{
|
||||
prefix.Print (os);
|
||||
return os;
|
||||
@@ -671,13 +738,13 @@ bool operator != (Ipv6Prefix const &a, Ipv6Prefix const &b)
|
||||
return !a.IsEqual (b);
|
||||
}
|
||||
|
||||
size_t Ipv6AddressHash::operator() (Ipv6Address const &x) const
|
||||
size_t Ipv6AddressHash::operator () (Ipv6Address const &x) const
|
||||
{
|
||||
uint8_t buf[16];
|
||||
|
||||
x.GetBytes(buf);
|
||||
x.GetBytes (buf);
|
||||
|
||||
return lookuphash(buf, sizeof(buf), 0);
|
||||
return lookuphash (buf, sizeof (buf), 0);
|
||||
}
|
||||
|
||||
ATTRIBUTE_HELPER_CPP (Ipv6Address);
|
||||
|
||||
@@ -35,6 +35,7 @@ class Ipv6Prefix;
|
||||
class Mac48Address;
|
||||
|
||||
/**
|
||||
* \ingroup address
|
||||
* \class Ipv6Address
|
||||
* \brief Describes an IPv6 address.
|
||||
* \see Ipv6Prefix
|
||||
@@ -253,6 +254,12 @@ class Ipv6Address
|
||||
*/
|
||||
static Ipv6Address GetLoopback ();
|
||||
|
||||
/**
|
||||
* \brief Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
|
||||
* \return all-1 Ipv6Address representation
|
||||
*/
|
||||
static Ipv6Address GetOnes ();
|
||||
|
||||
/**
|
||||
* \brief Get the bytes corresponding to the address.
|
||||
* \param buf buffer to store the data
|
||||
@@ -284,6 +291,7 @@ class Ipv6Address
|
||||
};
|
||||
|
||||
/**
|
||||
* \ingroup address
|
||||
* \class Ipv6Prefix
|
||||
* \brief Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
|
||||
* \see Ipv6Address
|
||||
@@ -346,6 +354,12 @@ class Ipv6Prefix
|
||||
*/
|
||||
void GetBytes (uint8_t buf[16]) const;
|
||||
|
||||
/**
|
||||
* \brief Get prefix length.
|
||||
* \return prefix length
|
||||
*/
|
||||
uint8_t GetPrefixLength () const;
|
||||
|
||||
/**
|
||||
* \brief Comparison operation between two Ipv6Prefix.
|
||||
* \param other the IPv6 prefix to which to compare this prefix
|
||||
@@ -367,6 +381,12 @@ class Ipv6Prefix
|
||||
*/
|
||||
static Ipv6Prefix GetLoopback ();
|
||||
|
||||
/**
|
||||
* \brief Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
|
||||
* \return /128 Ipv6Prefix representation
|
||||
*/
|
||||
static Ipv6Prefix GetOnes ();
|
||||
|
||||
/**
|
||||
* \brief Get the zero prefix ( /0).
|
||||
* \return an Ipv6Prefix
|
||||
@@ -415,7 +435,7 @@ inline bool operator < (const Ipv6Address& a, const Ipv6Address& b)
|
||||
class Ipv6AddressHash : public std::unary_function<Ipv6Address, size_t>
|
||||
{
|
||||
public:
|
||||
size_t operator() (Ipv6Address const &x) const;
|
||||
size_t operator () (Ipv6Address const &x) const;
|
||||
};
|
||||
|
||||
bool operator == (Ipv6Prefix const &a, Ipv6Prefix const &b);
|
||||
|
||||
@@ -31,16 +31,15 @@ namespace ns3 {
|
||||
NS_OBJECT_ENSURE_REGISTERED (Ipv6Header);
|
||||
|
||||
Ipv6Header::Ipv6Header ()
|
||||
: m_version (6),
|
||||
: m_version (6),
|
||||
m_trafficClass (0),
|
||||
m_flowLabel (1),
|
||||
m_payloadLength (0),
|
||||
m_nextHeader (0),
|
||||
m_hopLimit (0)
|
||||
{
|
||||
|
||||
SetSourceAddress (Ipv6Address("::"));
|
||||
SetDestinationAddress(Ipv6Address ("::"));
|
||||
SetSourceAddress (Ipv6Address ("::"));
|
||||
SetDestinationAddress (Ipv6Address ("::"));
|
||||
}
|
||||
|
||||
void Ipv6Header::SetTrafficClass (uint8_t traffic)
|
||||
@@ -157,8 +156,8 @@ void Ipv6Header::Serialize (Buffer::Iterator start) const
|
||||
i.WriteU8(m_nextHeader);
|
||||
i.WriteU8(m_hopLimit);
|
||||
|
||||
WriteTo(i, m_sourceAddress);
|
||||
WriteTo(i, m_destinationAddress);
|
||||
WriteTo (i, m_sourceAddress);
|
||||
WriteTo (i, m_destinationAddress);
|
||||
}
|
||||
|
||||
uint32_t Ipv6Header::Deserialize (Buffer::Iterator start)
|
||||
@@ -169,7 +168,7 @@ uint32_t Ipv6Header::Deserialize (Buffer::Iterator start)
|
||||
vTcFl = i.ReadNtohU32();
|
||||
m_version = vTcFl >> 28;
|
||||
|
||||
NS_ASSERT((m_version) == 6);
|
||||
NS_ASSERT ((m_version) == 6);
|
||||
|
||||
m_trafficClass = (uint8_t)((vTcFl >> 20) & 0x000000ff);
|
||||
m_flowLabel = vTcFl & 0xfff00000;
|
||||
@@ -177,10 +176,10 @@ uint32_t Ipv6Header::Deserialize (Buffer::Iterator start)
|
||||
m_nextHeader = i.ReadU8();
|
||||
m_hopLimit = i.ReadU8();
|
||||
|
||||
ReadFrom(i, m_sourceAddress);
|
||||
ReadFrom(i, m_destinationAddress);
|
||||
ReadFrom (i, m_sourceAddress);
|
||||
ReadFrom (i, m_destinationAddress);
|
||||
|
||||
return GetSerializedSize();
|
||||
return GetSerializedSize ();
|
||||
}
|
||||
|
||||
} /* namespace ns3 */
|
||||
|
||||
@@ -39,21 +39,21 @@ class Ipv6Header : public Header
|
||||
*/
|
||||
enum NextHeader_e
|
||||
{
|
||||
IPV6_EXT_HOP_BY_HOP=0,
|
||||
IPV6_IPV4=4,
|
||||
IPV6_TCP=6,
|
||||
IPV6_UDP=17,
|
||||
IPV6_IPV6=41,
|
||||
IPV6_EXT_ROUTING=43,
|
||||
IPV6_EXT_FRAGMENTATION=44,
|
||||
IPV6_EXT_CONFIDENTIALITY=50,
|
||||
IPV6_EXT_AUTHENTIFICATION,
|
||||
IPV6_ICMPV6=58,
|
||||
IPV6_EXT_END,
|
||||
IPV6_EXT_DESTINATION,
|
||||
IPV6_SCTP=135,
|
||||
IPV6_EXT_MOBILITY=135,
|
||||
IPV6_UDP_LITE,
|
||||
IPV6_EXT_HOP_BY_HOP = 0,
|
||||
IPV6_IPV4 = 4,
|
||||
IPV6_TCP = 6,
|
||||
IPV6_UDP = 17,
|
||||
IPV6_IPV6 = 41,
|
||||
IPV6_EXT_ROUTING = 43,
|
||||
IPV6_EXT_FRAGMENTATION = 44,
|
||||
IPV6_EXT_CONFIDENTIALITY = 50,
|
||||
IPV6_EXT_AUTHENTIFICATION = 51,
|
||||
IPV6_ICMPV6 = 58,
|
||||
IPV6_EXT_END = 59,
|
||||
IPV6_EXT_DESTINATION = 60,
|
||||
IPV6_SCTP = 135,
|
||||
IPV6_EXT_MOBILITY = 135,
|
||||
IPV6_UDP_LITE = 136,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
170
src/node/ipv6-interface-address.cc
Normal file
170
src/node/ipv6-interface-address.cc
Normal file
@@ -0,0 +1,170 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007-2009 Strasbourg University
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "ipv6-interface-address.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("Ipv6InterfaceAddress");
|
||||
|
||||
Ipv6InterfaceAddress::Ipv6InterfaceAddress ()
|
||||
: m_address (Ipv6Address ()),
|
||||
m_prefix (Ipv6Prefix ()),
|
||||
m_state (TENTATIVE_OPTIMISTIC),
|
||||
m_scope (HOST),
|
||||
m_nsDadUid (0)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
Ipv6InterfaceAddress::Ipv6InterfaceAddress (Ipv6Address address)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << address);
|
||||
m_prefix = Ipv6Prefix (64);
|
||||
SetAddress (address);
|
||||
SetState (TENTATIVE_OPTIMISTIC);
|
||||
m_nsDadUid = 0;
|
||||
}
|
||||
|
||||
Ipv6InterfaceAddress::Ipv6InterfaceAddress (Ipv6Address address, Ipv6Prefix prefix)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << address << prefix);
|
||||
m_prefix = prefix;
|
||||
SetAddress (address);
|
||||
SetState (TENTATIVE_OPTIMISTIC);
|
||||
m_nsDadUid = 0;
|
||||
}
|
||||
|
||||
Ipv6InterfaceAddress::Ipv6InterfaceAddress (const Ipv6InterfaceAddress& o)
|
||||
: m_address (o.m_address),
|
||||
m_prefix (o.m_prefix),
|
||||
m_state (o.m_state),
|
||||
m_scope (o.m_scope),
|
||||
m_nsDadUid (o.m_nsDadUid)
|
||||
{}
|
||||
|
||||
Ipv6InterfaceAddress::~Ipv6InterfaceAddress ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6InterfaceAddress::GetAddress () const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
return m_address;
|
||||
}
|
||||
|
||||
void Ipv6InterfaceAddress::SetAddress (Ipv6Address address)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << address);
|
||||
m_address = address;
|
||||
|
||||
if (address.IsLocalhost ())
|
||||
{
|
||||
m_scope = HOST;
|
||||
/* localhost address is always /128 prefix */
|
||||
m_prefix = Ipv6Prefix (128);
|
||||
}
|
||||
if (address.IsLinkLocal ())
|
||||
{
|
||||
m_scope = LINKLOCAL;
|
||||
/* link-local address is always /64 prefix */
|
||||
m_prefix = Ipv6Prefix (64);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_scope = GLOBAL;
|
||||
}
|
||||
}
|
||||
|
||||
Ipv6Prefix Ipv6InterfaceAddress::GetPrefix () const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
return m_prefix;
|
||||
}
|
||||
|
||||
void Ipv6InterfaceAddress::SetState (Ipv6InterfaceAddress::State_e state)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << state);
|
||||
m_state = state;
|
||||
}
|
||||
|
||||
Ipv6InterfaceAddress::State_e Ipv6InterfaceAddress::GetState () const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
return m_state;
|
||||
}
|
||||
|
||||
void Ipv6InterfaceAddress::SetScope (Ipv6InterfaceAddress::Scope_e scope)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << scope);
|
||||
m_scope = scope;
|
||||
}
|
||||
|
||||
Ipv6InterfaceAddress::Scope_e Ipv6InterfaceAddress::GetScope () const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
return m_scope;
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, const Ipv6InterfaceAddress &addr)
|
||||
{
|
||||
os << "address=" << addr.GetAddress () << "; prefix=" <<
|
||||
addr.GetPrefix () << "; scope=" << addr.GetScope ();
|
||||
return os;
|
||||
}
|
||||
|
||||
uint32_t Ipv6InterfaceAddress::GetNsDadUid () const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
return m_nsDadUid;
|
||||
}
|
||||
|
||||
void Ipv6InterfaceAddress::SetNsDadUid (uint32_t nsDadUid)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << nsDadUid);
|
||||
m_nsDadUid = nsDadUid;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void Ipv6InterfaceAddress::StartDadTimer (Ptr<Ipv6Interface> interface)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << interface);
|
||||
m_dadTimer.SetFunction (&Icmpv6L4Protocol::FunctionDadTimeout);
|
||||
m_dadTimer.SetArguments (interface, m_address);
|
||||
m_dadTimer.Schedule (Seconds (1));
|
||||
m_dadId = Simulator::Schedule (Seconds (1.), &Icmpv6L4Protocol::FunctionDadTimeout, interface, m_address);
|
||||
}
|
||||
|
||||
void Ipv6InterfaceAddress::StopDadTimer ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
m_dadTimer.Cancel ();
|
||||
Simulator::Cancel (m_dadId);
|
||||
}
|
||||
#endif
|
||||
|
||||
} /* namespace ns3 */
|
||||
|
||||
209
src/node/ipv6-interface-address.h
Normal file
209
src/node/ipv6-interface-address.h
Normal file
@@ -0,0 +1,209 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007-2009 Strasbourg University
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
|
||||
*/
|
||||
|
||||
#ifndef IPV6_INTERFACE_ADDRESS_H
|
||||
#define IPV6_INTERFACE_ADDRESS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ipv6-address.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
/**
|
||||
* \ingroup address
|
||||
* \class Ipv6InterfaceAddress
|
||||
* \brief IPv6 address associated with an interface.
|
||||
*/
|
||||
class Ipv6InterfaceAddress
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \enum State_e
|
||||
* \brief State of an address associated with an interface.
|
||||
*/
|
||||
enum State_e
|
||||
{
|
||||
TENTATIVE, /**< Address is tentative, no packet can be sent unless DAD finished */
|
||||
DEPRECATED, /**< Address is deprecated and should not be used */
|
||||
PREFERRED, /**< Preferred address */
|
||||
PERMANENT, /**< Permanent address */
|
||||
HOMEADDRESS, /**< Address is a HomeAddress */
|
||||
TENTATIVE_OPTIMISTIC, /**< Address is tentative but we are optimistic so we can send packet even if DAD is not yet finished */
|
||||
INVALID, /**< Invalid state (after a DAD failed) */
|
||||
};
|
||||
|
||||
/**
|
||||
* \enum Scope_e
|
||||
* \brief Scope of address.
|
||||
*/
|
||||
enum Scope_e
|
||||
{
|
||||
HOST, /**< Localhost (::1/128) */
|
||||
LINKLOCAL, /**< Link-local address (fe80::/64) */
|
||||
GLOBAL, /**< Global address (2000::/3) */
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Default constructor.
|
||||
*/
|
||||
Ipv6InterfaceAddress ();
|
||||
|
||||
/**
|
||||
* \brief Constructor. Prefix is 64 by default.
|
||||
* \param address the IPv6 address to set
|
||||
*/
|
||||
Ipv6InterfaceAddress (Ipv6Address address);
|
||||
|
||||
/**
|
||||
* \brief Constructor.
|
||||
* \param address IPv6 address to set
|
||||
* \param prefix IPv6 prefix
|
||||
*/
|
||||
Ipv6InterfaceAddress (Ipv6Address address, Ipv6Prefix prefix);
|
||||
|
||||
/**
|
||||
* \brief Copy constructor.
|
||||
* \param o object to copy
|
||||
*/
|
||||
Ipv6InterfaceAddress (const Ipv6InterfaceAddress& o);
|
||||
|
||||
/**
|
||||
* \brief Destructor.
|
||||
*/
|
||||
~Ipv6InterfaceAddress ();
|
||||
|
||||
/**
|
||||
* \brief Set IPv6 address (and scope).
|
||||
* \param address IPv6 address to set
|
||||
*/
|
||||
void SetAddress (Ipv6Address address);
|
||||
|
||||
/**
|
||||
* \brief Get the IPv6 address.
|
||||
* \return IPv6 address
|
||||
*/
|
||||
Ipv6Address GetAddress () const;
|
||||
|
||||
/**
|
||||
* \brief Get the IPv6 prefix.
|
||||
* \return IPv6 prefix
|
||||
*/
|
||||
Ipv6Prefix GetPrefix () const;
|
||||
|
||||
/**
|
||||
* \brief Set the state.
|
||||
* \param state the state
|
||||
*/
|
||||
void SetState (Ipv6InterfaceAddress::State_e state);
|
||||
|
||||
/**
|
||||
* \brief Get the address state.
|
||||
* \return address state
|
||||
*/
|
||||
Ipv6InterfaceAddress::State_e GetState () const;
|
||||
|
||||
/**
|
||||
* \brief Set the scope.
|
||||
* \param scope the scope of address
|
||||
*/
|
||||
void SetScope (Ipv6InterfaceAddress::Scope_e scope);
|
||||
|
||||
/**
|
||||
* \brief Get address scope.
|
||||
* \return scope
|
||||
*/
|
||||
Ipv6InterfaceAddress::Scope_e GetScope () const;
|
||||
|
||||
/**
|
||||
* \brief Set the latest DAD probe packet UID.
|
||||
* \param uid packet uid
|
||||
*/
|
||||
void SetNsDadUid (uint32_t uid);
|
||||
|
||||
/**
|
||||
* \brief Get the latest DAD probe packet UID.
|
||||
* \return uid
|
||||
*/
|
||||
uint32_t GetNsDadUid () const;
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* \brief Start the DAD timer.
|
||||
* \param interface interface
|
||||
*/
|
||||
void StartDadTimer (Ptr<Ipv6Interface> interface);
|
||||
|
||||
/**
|
||||
* \brief Stop the DAD timer.
|
||||
*/
|
||||
void StopDadTimer ();
|
||||
#endif
|
||||
|
||||
private:
|
||||
/**
|
||||
* \brief The IPv6 address.
|
||||
*/
|
||||
Ipv6Address m_address;
|
||||
|
||||
/**
|
||||
* \brief The IPv6 prefix.
|
||||
*/
|
||||
Ipv6Prefix m_prefix;
|
||||
|
||||
/**
|
||||
* \brief State of the address.
|
||||
*/
|
||||
State_e m_state;
|
||||
|
||||
/**
|
||||
* \brief Scope of the address.
|
||||
*/
|
||||
Scope_e m_scope;
|
||||
|
||||
friend bool operator == (Ipv6InterfaceAddress const& a, Ipv6InterfaceAddress const& b);
|
||||
friend bool operator != (Ipv6InterfaceAddress const& a, Ipv6InterfaceAddress const& b);
|
||||
|
||||
/**
|
||||
* \brief Last DAD probe packet UID.
|
||||
*/
|
||||
uint32_t m_nsDadUid;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, const Ipv6InterfaceAddress &addr);
|
||||
|
||||
/* follow Ipv6InterfaceAddress way, maybe not inline them */
|
||||
inline bool operator == (const Ipv6InterfaceAddress& a, const Ipv6InterfaceAddress& b)
|
||||
{
|
||||
return (a.m_address == b.m_address && a.m_prefix == b.m_prefix &&
|
||||
a.m_state == b.m_state && a.m_scope == b.m_scope);
|
||||
}
|
||||
|
||||
inline bool operator != (const Ipv6InterfaceAddress& a, const Ipv6InterfaceAddress& b)
|
||||
{
|
||||
return (a.m_address != b.m_address || a.m_prefix != b.m_prefix ||
|
||||
a.m_state != b.m_state || a.m_scope != b.m_scope);
|
||||
}
|
||||
|
||||
} /* namespace ns3 */
|
||||
|
||||
#endif /* IPV6_INTERFACE_ADDRESS_H */
|
||||
|
||||
37
src/node/ipv6-raw-socket-factory.cc
Normal file
37
src/node/ipv6-raw-socket-factory.cc
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include "ipv6-raw-socket-factory.h"
|
||||
#include "ns3/uinteger.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (Ipv6RawSocketFactory);
|
||||
|
||||
TypeId Ipv6RawSocketFactory::GetTypeId ()
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv6RawSocketFactory")
|
||||
.SetParent<SocketFactory> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
52
src/node/ipv6-raw-socket-factory.h
Normal file
52
src/node/ipv6-raw-socket-factory.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef IPV6_RAW_SOCKET_FACTORY_H
|
||||
#define IPV6_RAW_SOCKET_FACTORY_H
|
||||
|
||||
#include "socket-factory.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
class Socket;
|
||||
|
||||
/**
|
||||
* \ingroup socket
|
||||
*
|
||||
* \brief API to create IPv6 RAW socket instances
|
||||
*
|
||||
* This abstract class defines the API for IPv6 RAW socket factory.
|
||||
*
|
||||
*/
|
||||
class Ipv6RawSocketFactory : public SocketFactory
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Get the type ID of this class.
|
||||
* \return type ID
|
||||
*/
|
||||
static TypeId GetTypeId (void);
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* IPV6_RAW_SOCKET_FACTORY_H */
|
||||
|
||||
147
src/node/ipv6-route.cc
Normal file
147
src/node/ipv6-route.cc
Normal file
@@ -0,0 +1,147 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007-2009 Strasbourg University
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "net-device.h"
|
||||
|
||||
#include "ipv6-route.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
Ipv6Route::Ipv6Route ()
|
||||
{
|
||||
}
|
||||
|
||||
Ipv6Route::~Ipv6Route ()
|
||||
{
|
||||
}
|
||||
|
||||
void Ipv6Route::SetDestination (Ipv6Address dest)
|
||||
{
|
||||
m_dest = dest;
|
||||
}
|
||||
|
||||
Ipv6Address
|
||||
Ipv6Route::GetDestination () const
|
||||
{
|
||||
return m_dest;
|
||||
}
|
||||
|
||||
void Ipv6Route::SetSource (Ipv6Address src)
|
||||
{
|
||||
m_source = src;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Route::GetSource () const
|
||||
{
|
||||
return m_source;
|
||||
}
|
||||
|
||||
void Ipv6Route::SetGateway (Ipv6Address gw)
|
||||
{
|
||||
m_gateway = gw;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6Route::GetGateway () const
|
||||
{
|
||||
return m_gateway;
|
||||
}
|
||||
|
||||
void Ipv6Route::SetOutputDevice (Ptr<NetDevice> outputDevice)
|
||||
{
|
||||
m_outputDevice = outputDevice;
|
||||
}
|
||||
|
||||
Ptr<NetDevice> Ipv6Route::GetOutputDevice () const
|
||||
{
|
||||
return m_outputDevice;
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv6Route const& route)
|
||||
{
|
||||
os << "source=" << route.GetSource () << " dest="<< route.GetDestination () <<" gw=" << route.GetGateway ();
|
||||
return os;
|
||||
}
|
||||
|
||||
Ipv6MulticastRoute::Ipv6MulticastRoute ()
|
||||
{
|
||||
uint32_t initial_ttl = MAX_TTL;
|
||||
|
||||
/* Initialize array to MAX_TTL, which means that all interfaces are "off" */
|
||||
for (uint32_t i = 0; i < MAX_INTERFACES; i++)
|
||||
{
|
||||
m_ttls.push_back (initial_ttl);
|
||||
}
|
||||
}
|
||||
|
||||
Ipv6MulticastRoute::~Ipv6MulticastRoute ()
|
||||
{
|
||||
}
|
||||
|
||||
void Ipv6MulticastRoute::SetGroup (const Ipv6Address group)
|
||||
{
|
||||
m_group = group;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6MulticastRoute::GetGroup () const
|
||||
{
|
||||
return m_group;
|
||||
}
|
||||
|
||||
void Ipv6MulticastRoute::SetOrigin (const Ipv6Address origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
}
|
||||
|
||||
Ipv6Address Ipv6MulticastRoute::GetOrigin () const
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
void Ipv6MulticastRoute::SetParent (uint32_t parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
uint32_t Ipv6MulticastRoute::GetParent () const
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
void Ipv6MulticastRoute::SetOutputTtl (uint32_t oif, uint32_t ttl)
|
||||
{
|
||||
m_ttls[oif] = ttl;
|
||||
}
|
||||
|
||||
uint32_t Ipv6MulticastRoute::GetOutputTtl (uint32_t oif) const
|
||||
{
|
||||
return m_ttls[oif];
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv6MulticastRoute const& route)
|
||||
{
|
||||
os << "origin=" << route.GetOrigin () << " group="<< route.GetGroup () <<" parent=" << route.GetParent ();
|
||||
return os;
|
||||
}
|
||||
|
||||
} /* namespace ns3 */
|
||||
|
||||
227
src/node/ipv6-route.h
Normal file
227
src/node/ipv6-route.h
Normal file
@@ -0,0 +1,227 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007-2009 Strasbourg University
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
|
||||
*/
|
||||
|
||||
#ifndef IPV6_ROUTE_H
|
||||
#define IPV6_ROUTE_H
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
#include "ns3/ref-count-base.h"
|
||||
#include "ipv6-address.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
class NetDevice;
|
||||
|
||||
/**
|
||||
* \ingroup ipv6Routing
|
||||
* \class Ipv6Route
|
||||
* \brief IPv6 route cache entry.
|
||||
*/
|
||||
class Ipv6Route : public RefCountBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Constructor.
|
||||
*/
|
||||
Ipv6Route ();
|
||||
|
||||
/**
|
||||
* \brief Destructor.
|
||||
*/
|
||||
virtual ~Ipv6Route ();
|
||||
|
||||
/**
|
||||
* \brief Set destination address.
|
||||
* \param dest IPv6 destination address
|
||||
*/
|
||||
void SetDestination (Ipv6Address dest);
|
||||
|
||||
/**
|
||||
* \brief Get destination address.
|
||||
* \return destination address
|
||||
*/
|
||||
Ipv6Address GetDestination () const;
|
||||
|
||||
/**
|
||||
* \brief Set source address.
|
||||
* \param src IPv6 source address
|
||||
*/
|
||||
void SetSource (Ipv6Address src);
|
||||
|
||||
/**
|
||||
* \brief Get source address.
|
||||
* \return source address
|
||||
*/
|
||||
Ipv6Address GetSource () const;
|
||||
|
||||
/**
|
||||
* \brief Set gateway address.
|
||||
* \param gw IPv6 gateway address
|
||||
*/
|
||||
void SetGateway (Ipv6Address gw);
|
||||
|
||||
/**
|
||||
* \brief Get gateway address.
|
||||
* \return gateway address
|
||||
*/
|
||||
Ipv6Address GetGateway () const;
|
||||
|
||||
/**
|
||||
* \brief Set output device for outgoing packets.
|
||||
* \param outputDevice output device
|
||||
*/
|
||||
void SetOutputDevice (Ptr<NetDevice> outputDevice);
|
||||
|
||||
/**
|
||||
* \brief Get output device.
|
||||
* \return output device
|
||||
*/
|
||||
Ptr<NetDevice> GetOutputDevice () const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* \brief Destination address.
|
||||
*/
|
||||
Ipv6Address m_dest;
|
||||
|
||||
/**
|
||||
* \brief source address.
|
||||
*/
|
||||
Ipv6Address m_source;
|
||||
|
||||
/**
|
||||
* \brief Gateway address.
|
||||
*/
|
||||
Ipv6Address m_gateway;
|
||||
|
||||
/**
|
||||
* \brief Output device.
|
||||
*/
|
||||
Ptr<NetDevice> m_outputDevice;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv6Route const& route);
|
||||
|
||||
/**
|
||||
* \ingroup ipv6Routing
|
||||
* \class Ipv6MulticastRoute
|
||||
* \brief IPv6 multicast route entry.
|
||||
*/
|
||||
class Ipv6MulticastRoute : public RefCountBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Maximum number of multicast interfaces on a router.
|
||||
*/
|
||||
static const uint32_t MAX_INTERFACES = 16;
|
||||
|
||||
/**
|
||||
* \brief Maximum Time-To-Live (TTL).
|
||||
*/
|
||||
static const uint32_t MAX_TTL = 255;
|
||||
|
||||
/**
|
||||
* \brief Constructor.
|
||||
*/
|
||||
Ipv6MulticastRoute ();
|
||||
|
||||
/**
|
||||
* \brief Destructor.
|
||||
*/
|
||||
virtual ~Ipv6MulticastRoute ();
|
||||
|
||||
/**
|
||||
* \brief Set IPv6 group.
|
||||
* \param group Ipv6Address of the multicast group
|
||||
*/
|
||||
void SetGroup (const Ipv6Address group);
|
||||
|
||||
/**
|
||||
* \brief Get IPv6 group.
|
||||
* \return Ipv6Address of the multicast group
|
||||
*/
|
||||
Ipv6Address GetGroup (void) const;
|
||||
|
||||
/**
|
||||
* \brief Set origin address.
|
||||
* \param origin Ipv6Address of the origin address
|
||||
*/
|
||||
void SetOrigin (const Ipv6Address origin);
|
||||
|
||||
/**
|
||||
* \brief Get source address.
|
||||
* \return Ipv6Address of the origin address
|
||||
*/
|
||||
Ipv6Address GetOrigin (void) const;
|
||||
|
||||
/**
|
||||
* \param iif Parent (input interface) for this route
|
||||
*/
|
||||
void SetParent (uint32_t iif);
|
||||
/**
|
||||
* \return Parent (input interface) for this route
|
||||
*/
|
||||
uint32_t GetParent (void) const;
|
||||
|
||||
/**
|
||||
* \param oif Outgoing interface index
|
||||
* \param ttl time-to-live for this route
|
||||
*/
|
||||
void SetOutputTtl (uint32_t oif, uint32_t ttl);
|
||||
|
||||
/**
|
||||
* \brief Get output TTL.
|
||||
* \param oif outgoing interface
|
||||
* \return TTL for this route
|
||||
*/
|
||||
uint32_t GetOutputTtl (uint32_t oif) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* \brief IPv6 group.
|
||||
*/
|
||||
Ipv6Address m_group;
|
||||
|
||||
/**
|
||||
* \brief IPv6 origin (source).
|
||||
*/
|
||||
Ipv6Address m_origin;
|
||||
|
||||
/**
|
||||
* \brief Source interface.
|
||||
*/
|
||||
uint32_t m_parent;
|
||||
|
||||
/**
|
||||
* \brief TTLs;
|
||||
*/
|
||||
std::vector<uint32_t> m_ttls;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv6MulticastRoute const& route);
|
||||
|
||||
} /* namespace ns3 */
|
||||
|
||||
#endif /* IPV6_ROUTE_H */
|
||||
|
||||
39
src/node/ipv6-routing-protocol.cc
Normal file
39
src/node/ipv6-routing-protocol.cc
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* taken from src/node/ipv4-routing-protocol.cc and adapted to IPv6 */
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ipv6-route.h"
|
||||
#include "ipv6-routing-protocol.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (Ipv6RoutingProtocol);
|
||||
|
||||
TypeId Ipv6RoutingProtocol::GetTypeId ()
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv6RoutingProtocol")
|
||||
.SetParent<Object> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
} /* namespace ns3 */
|
||||
|
||||
173
src/node/ipv6-routing-protocol.h
Normal file
173
src/node/ipv6-routing-protocol.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/* taken from src/node/ipv4-routing-protocol.h and adapted to IPv6 */
|
||||
|
||||
#ifndef IPV6_ROUTING_PROTOCOL_H
|
||||
#define IPV6_ROUTING_PROTOCOL_H
|
||||
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/socket.h"
|
||||
#include "ipv6-header.h"
|
||||
#include "ipv6-interface-address.h"
|
||||
#include "ipv6.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv6MulticastRoute;
|
||||
class Ipv6Route;
|
||||
class NetDevice;
|
||||
|
||||
/**
|
||||
* \ingroup node
|
||||
* \defgroup ipv6Routing Ipv6RoutingProtocol
|
||||
*/
|
||||
/**
|
||||
* \ingroup ipv6Routing
|
||||
* \brief Abstract base class for Ipv6 routing protocols.
|
||||
*
|
||||
* Defines two virtual functions for packet routing and forwarding. The first,
|
||||
* RouteOutput (), is used for locally originated packets, and the second,
|
||||
* RouteInput (), is used for forwarding and/or delivering received packets.
|
||||
* Also defines the signatures of four callbacks used in RouteInput ().
|
||||
*/
|
||||
class Ipv6RoutingProtocol : public Object
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
typedef Callback<void, Ptr<Ipv6Route>, Ptr<const Packet>, const Ipv6Header &> UnicastForwardCallback;
|
||||
typedef Callback<void, Ptr<Ipv6MulticastRoute>, Ptr<const Packet>, const Ipv6Header &> MulticastForwardCallback;
|
||||
typedef Callback<void, Ptr<const Packet>, const Ipv6Header &, uint32_t > LocalDeliverCallback;
|
||||
typedef Callback<void, Ptr<const Packet>, const Ipv6Header &, Socket::SocketErrno > ErrorCallback;
|
||||
|
||||
/**
|
||||
* \brief Query routing cache for an existing route, for an outbound packet
|
||||
*
|
||||
* This lookup is used by transport protocols. It does not cause any
|
||||
* packet to be forwarded, and is synchronous. Can be used for
|
||||
* multicast or unicast. The Linux equivalent is ip_route_output ()
|
||||
*
|
||||
* \param p packet to be routed. Note that this method may modify the packet.
|
||||
* Callers may also pass in a null pointer.
|
||||
* \param header input parameter (used to form key to search for the route)
|
||||
* \param oif Output interface index. May be zero, or may be bound via
|
||||
* socket options to a particular output interface.
|
||||
* \param sockerr Output parameter; socket errno
|
||||
*
|
||||
* \returns a code that indicates what happened in the lookup
|
||||
*/
|
||||
virtual Ptr<Ipv6Route> RouteOutput (Ptr<Packet> p, const Ipv6Header &header, uint32_t oif, Socket::SocketErrno &sockerr) = 0;
|
||||
|
||||
/**
|
||||
* \brief Route an input packet (to be forwarded or locally delivered)
|
||||
*
|
||||
* This lookup is used in the forwarding process. The packet is
|
||||
* handed over to the Ipv6RoutingProtocol, and will get forwarded onward
|
||||
* by one of the callbacks. The Linux equivalent is ip_route_input ().
|
||||
* There are four valid outcomes, and a matching callbacks to handle each.
|
||||
*
|
||||
* \param p received packet
|
||||
* \param header input parameter used to form a search key for a route
|
||||
* \param idev Pointer to ingress network device
|
||||
* \param ucb Callback for the case in which the packet is to be forwarded
|
||||
* as unicast
|
||||
* \param mcb Callback for the case in which the packet is to be forwarded
|
||||
* as multicast
|
||||
* \param lcb Callback for the case in which the packet is to be locally
|
||||
* delivered
|
||||
* \param ecb Callback to call if there is an error in forwarding
|
||||
* \returns true if the Ipv6RoutingProtocol takes responsibility for
|
||||
* forwarding or delivering the packet, false otherwise
|
||||
*/
|
||||
virtual bool RouteInput (Ptr<const Packet> p, const Ipv6Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) = 0;
|
||||
|
||||
/**
|
||||
* \param interface the index of the interface we are being notified about
|
||||
*
|
||||
* Protocols are expected to implement this method to be notified of the state change of
|
||||
* an interface in a node.
|
||||
*/
|
||||
virtual void NotifyInterfaceUp (uint32_t interface) = 0;
|
||||
/**
|
||||
* \param interface the index of the interface we are being notified about
|
||||
*
|
||||
* Protocols are expected to implement this method to be notified of the state change of
|
||||
* an interface in a node.
|
||||
*/
|
||||
virtual void NotifyInterfaceDown (uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \param interface the index of the interface we are being notified about
|
||||
* \param address a new address being added to an interface
|
||||
*
|
||||
* Protocols are expected to implement this method to be notified whenever
|
||||
* a new address is added to an interface. Typically used to add a 'network route' on an
|
||||
* interface. Can be invoked on an up or down interface.
|
||||
*/
|
||||
virtual void NotifyAddAddress (uint32_t interface, Ipv6InterfaceAddress address) = 0;
|
||||
|
||||
/**
|
||||
* \param interface the index of the interface we are being notified about
|
||||
* \param address a new address being added to an interface
|
||||
*
|
||||
* Protocols are expected to implement this method to be notified whenever
|
||||
* a new address is removed from an interface. Typically used to remove the 'network route' of an
|
||||
* interface. Can be invoked on an up or down interface.
|
||||
*/
|
||||
virtual void NotifyRemoveAddress (uint32_t interface, Ipv6InterfaceAddress address) = 0;
|
||||
|
||||
/**
|
||||
* \brief Notify a new route.
|
||||
*
|
||||
* Typically this is used to add another route from IPv6 stack (i.e. ICMPv6
|
||||
* redirect case, ...).
|
||||
* \param dst destination address
|
||||
* \param mask destination mask
|
||||
* \param nextHop nextHop for this destination
|
||||
* \param interface output interface
|
||||
* \param prefixToUse prefix to use as source with this route
|
||||
*/
|
||||
virtual void NotifyAddRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ()) = 0;
|
||||
|
||||
/**
|
||||
* \brief Notify route removing.
|
||||
* \param dst destination address
|
||||
* \param mask destination mask
|
||||
* \param nextHop nextHop for this destination
|
||||
* \param interface output interface
|
||||
* \param prefixToUse prefix to use as source with this route
|
||||
*/
|
||||
virtual void NotifyRemoveRoute (Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse = Ipv6Address::GetZero ()) = 0;
|
||||
|
||||
/**
|
||||
* \param ipv6 the ipv6 object this routing protocol is being associated with
|
||||
*
|
||||
* Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol
|
||||
*/
|
||||
virtual void SetIpv6 (Ptr<Ipv6> ipv6) = 0;
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
#endif /* IPV6_ROUTING_PROTOCOL_H */
|
||||
|
||||
60
src/node/ipv6.cc
Normal file
60
src/node/ipv6.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
/* taken from src/node/ipv4.h and adapted to IPv6 */
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/boolean.h"
|
||||
#include "ipv6.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (Ipv6);
|
||||
|
||||
TypeId Ipv6::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv6")
|
||||
.SetParent<Object> ()
|
||||
.AddAttribute ("IpForward", "Globally enable or disable IP forwarding for all current and future IPv6 devices.",
|
||||
BooleanValue (false),
|
||||
MakeBooleanAccessor (&Ipv6::SetIpForward,
|
||||
&Ipv6::GetIpForward),
|
||||
MakeBooleanChecker ())
|
||||
#if 0
|
||||
.AddAttribute ("MtuDiscover", "If enabled, every outgoing IPv6 packet will have the DF flag set.",
|
||||
BooleanValue (false),
|
||||
MakeBooleanAccessor (&UdpSocket::SetMtuDiscover,
|
||||
&UdpSocket::GetMtuDiscover),
|
||||
MakeBooleanChecker ())
|
||||
#endif
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
Ipv6::Ipv6 ()
|
||||
{}
|
||||
|
||||
Ipv6::~Ipv6 ()
|
||||
{}
|
||||
|
||||
} /* namespace ns3 */
|
||||
|
||||
289
src/node/ipv6.h
Normal file
289
src/node/ipv6.h
Normal file
@@ -0,0 +1,289 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 INRIA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
/* taken from src/node/ipv4.h and adapted to IPv6 */
|
||||
|
||||
#ifndef IPV6_H
|
||||
#define IPV6_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "ipv6-address.h"
|
||||
#include "ipv6-interface-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class NetDevice;
|
||||
class Packet;
|
||||
class Ipv6RoutingProtocol;
|
||||
|
||||
/**
|
||||
* \ingroup node
|
||||
* \defgroup ipv6 Ipv6
|
||||
*/
|
||||
|
||||
/**
|
||||
* \ingroup ipv6
|
||||
* \brief Access to the IPv6 forwarding table, interfaces, and configuration
|
||||
*
|
||||
* This class defines the API to manipulate the following aspects of
|
||||
* the IPv6 implementation:
|
||||
* -# set/get an Ipv6RoutingProtocol
|
||||
* -# register a NetDevice for use by the IPv6 layer (basically, to
|
||||
* create IPv6-related state such as addressing and neighbor cache that
|
||||
* is associated with a NetDevice)
|
||||
* -# manipulate the status of the NetDevice from the IPv6 perspective,
|
||||
* such as marking it as Up or Down,
|
||||
* -# adding, deleting, and getting addresses associated to the IPv6
|
||||
* interfaces.
|
||||
* -# exporting IPv6 configuration attributes
|
||||
*
|
||||
* Each NetDevice has conceptually a single IPv6 interface associated
|
||||
* with it (the corresponding structure in the Linux IPv6 implementation
|
||||
* is struct in_device). Each interface may have one or more IPv6
|
||||
* addresses associated with it. Each IPv6 address may have different
|
||||
* subnet mask, scope, etc., so all of this per-address information
|
||||
* is stored in an Ipv6InterfaceAddress class (the corresponding
|
||||
* structure in Linux is struct in6_ifaddr)
|
||||
*
|
||||
* IPv6 attributes such as whether IP forwarding is enabled and disabled
|
||||
* are also stored in this class
|
||||
*
|
||||
* TO DO: Add API to allow access to the IPv6 neighbor table
|
||||
*
|
||||
* \see Ipv6RoutingProtocol
|
||||
* \see Ipv6InterfaceAddress
|
||||
*/
|
||||
class Ipv6 : public Object
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
/**
|
||||
* \brief Constructor.
|
||||
*/
|
||||
Ipv6 ();
|
||||
|
||||
/**
|
||||
* \brief Destructor.
|
||||
*/
|
||||
virtual ~Ipv6 ();
|
||||
|
||||
/**
|
||||
* \brief Register a new routing protocol to be used by this IPv6 stack
|
||||
*
|
||||
* This call will replace any routing protocol that has been previously
|
||||
* registered. If you want to add multiple routing protocols, you must
|
||||
* add them to a Ipv6ListRoutingProtocol directly.
|
||||
*
|
||||
* \param routingProtocol smart pointer to Ipv6RoutingProtocol object
|
||||
*/
|
||||
virtual void SetRoutingProtocol (Ptr<Ipv6RoutingProtocol> routingProtocol) = 0;
|
||||
|
||||
/**
|
||||
* \brief Get the routing protocol to be used by this IPv6 stack
|
||||
*
|
||||
* \returns smart pointer to Ipv6RoutingProtocol object, or null pointer if none
|
||||
*/
|
||||
virtual Ptr<Ipv6RoutingProtocol> GetRoutingProtocol (void) const = 0;
|
||||
|
||||
/**
|
||||
* \param device device to add to the list of IPv6 interfaces
|
||||
* which can be used as output interfaces during packet forwarding.
|
||||
* \returns the index of the IPv6 interface added.
|
||||
*
|
||||
* Once a device has been added, it can never be removed: if you want
|
||||
* to disable it, you can invoke Ipv6::SetDown which will
|
||||
* make sure that it is never used during packet forwarding.
|
||||
*/
|
||||
virtual uint32_t AddInterface (Ptr<NetDevice> device) = 0;
|
||||
|
||||
/**
|
||||
* \returns the number of interfaces added by the user.
|
||||
*/
|
||||
virtual uint32_t GetNInterfaces (void) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Return the interface number of the interface that has been
|
||||
* assigned the specified IP address.
|
||||
*
|
||||
* \param address The IP address being searched for
|
||||
* \returns The interface number of the IPv6 interface with the given
|
||||
* address or -1 if not found.
|
||||
*
|
||||
* Each IP interface has one or more IP addresses associated with it.
|
||||
* This method searches the list of interfaces for one that holds a
|
||||
* particular address. This call takes an IP address as a parameter and
|
||||
* returns the interface number of the first interface that has been assigned
|
||||
* that address, or -1 if not found. There must be an exact match.
|
||||
*/
|
||||
virtual int32_t GetInterfaceForAddress (Ipv6Address address) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Return the interface number of first interface found that
|
||||
* has an IPv6 address within the prefix specified by the input
|
||||
* address and mask parameters
|
||||
*
|
||||
* \param address The IP address assigned to the interface of interest.
|
||||
* \param mask The IP prefix to use in the mask
|
||||
* \returns The interface number of the IPv6 interface with the given
|
||||
* address or -1 if not found.
|
||||
*
|
||||
* Each IP interface has one or more IP addresses associated with it.
|
||||
* This method searches the list of interfaces for the first one found
|
||||
* that holds an address that is included within the prefix
|
||||
* formed by the input address and mask parameters. The value -1 is
|
||||
* returned if no match is found.
|
||||
*/
|
||||
virtual int32_t GetInterfaceForPrefix (Ipv6Address address,
|
||||
Ipv6Prefix mask) const = 0;
|
||||
|
||||
/**
|
||||
* \param interface The interface number of an IPv6 interface.
|
||||
* \returns The NetDevice associated with the IPv6 interface number.
|
||||
*/
|
||||
virtual Ptr<NetDevice> GetNetDevice (uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \param device The NetDevice for an Ipv6Interface
|
||||
* \returns The interface number of an IPv6 interface or -1 if not found.
|
||||
*/
|
||||
virtual int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of an IPv6 interface
|
||||
* \param address Ipv6InterfaceAddress address to associate with the underlying IPv6 interface
|
||||
* \returns true if the operation succeeded
|
||||
*/
|
||||
virtual bool AddAddress (uint32_t interface, Ipv6InterfaceAddress address) = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of an IPv6 interface
|
||||
* \returns the number of Ipv6InterfaceAddress entries for the interface.
|
||||
*/
|
||||
virtual uint32_t GetNAddresses (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* Because addresses can be removed, the addressIndex is not guaranteed
|
||||
* to be static across calls to this method.
|
||||
*
|
||||
* \param interface Interface number of an IPv6 interface
|
||||
* \param addressIndex index of Ipv6InterfaceAddress
|
||||
* \returns the Ipv6InterfaceAddress associated to the interface and addresIndex
|
||||
*/
|
||||
virtual Ipv6InterfaceAddress GetAddress (uint32_t interface, uint32_t addressIndex) const = 0;
|
||||
|
||||
/**
|
||||
* Remove the address at addressIndex on named interface. The addressIndex
|
||||
* for all higher indices will decrement by one after this method is called;
|
||||
* so, for example, to remove 5 addresses from an interface i, one could
|
||||
* call RemoveAddress (i, 0); 5 times.
|
||||
*
|
||||
* \param interface Interface number of an IPv6 interface
|
||||
* \param addressIndex index of Ipv6InterfaceAddress to remove
|
||||
* \returns true if the operation succeeded
|
||||
*/
|
||||
virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex) = 0;
|
||||
|
||||
/**
|
||||
* \param interface The interface number of an IPv6 interface
|
||||
* \param metric routing metric (cost) associated to the underlying
|
||||
* IPv6 interface
|
||||
*/
|
||||
virtual void SetMetric (uint32_t interface, uint16_t metric) = 0;
|
||||
|
||||
/**
|
||||
* \param interface The interface number of an IPv6 interface
|
||||
* \returns routing metric (cost) associated to the underlying
|
||||
* IPv6 interface
|
||||
*/
|
||||
virtual uint16_t GetMetric (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of IPv6 interface
|
||||
* \returns the Maximum Transmission Unit (in bytes) associated
|
||||
* to the underlying IPv6 interface
|
||||
*/
|
||||
virtual uint16_t GetMtu (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of IPv6 interface
|
||||
* \returns true if the underlying interface is in the "up" state,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool IsUp (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of IPv6 interface
|
||||
*
|
||||
* Set the interface into the "up" state. In this state, it is
|
||||
* considered valid during IPv6 forwarding.
|
||||
*/
|
||||
virtual void SetUp (uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of IPv6 interface
|
||||
*
|
||||
* Set the interface into the "down" state. In this state, it is
|
||||
* ignored during IPv6 forwarding.
|
||||
*/
|
||||
virtual void SetDown (uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of IPv6 interface
|
||||
* \returns true if IPv6 forwarding enabled for input datagrams on this device
|
||||
*/
|
||||
virtual bool IsForwarding (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of IPv6 interface
|
||||
* \param val Value to set the forwarding flag
|
||||
*
|
||||
* If set to true, IPv6 forwarding is enabled for input datagrams on this device
|
||||
*/
|
||||
virtual void SetForwarding (uint32_t interface, bool val) = 0;
|
||||
|
||||
/**
|
||||
* \brief Any interface magic number.
|
||||
*/
|
||||
static const uint32_t IF_ANY = 0xffffffff;
|
||||
|
||||
private:
|
||||
// Indirect the IPv6 attributes through private pure virtual methods
|
||||
/**
|
||||
* \brief Set IPv6 forwarding state.
|
||||
* \param forward IPv6 forwarding enabled or not
|
||||
*/
|
||||
virtual void SetIpForward (bool forward) = 0;
|
||||
|
||||
/**
|
||||
* \brief Get IPv6 forwarding state.
|
||||
* \return forwarding state (enabled or not)
|
||||
*/
|
||||
virtual bool GetIpForward (void) const = 0;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* IPV6_H */
|
||||
|
||||
@@ -128,12 +128,12 @@ public:
|
||||
/**
|
||||
* \param callback the callback to invoke
|
||||
*
|
||||
* Register a callback invoked whenever the link
|
||||
* Add a callback invoked whenever the link
|
||||
* status changes to UP. This callback is typically used
|
||||
* by the IP/ARP layer to flush the ARP cache
|
||||
* whenever the link goes up.
|
||||
* by the IP/ARP layer to flush the ARP cache and by IPv6 stack
|
||||
* to flush NDISC cache whenever the link goes up.
|
||||
*/
|
||||
virtual void SetLinkChangeCallback (Callback<void> callback) = 0;
|
||||
virtual void AddLinkChangeCallback (Callback<void> callback) = 0;
|
||||
/**
|
||||
* \return true if this interface supports a broadcast address,
|
||||
* false otherwise.
|
||||
|
||||
@@ -121,7 +121,7 @@ SimpleNetDevice::IsLinkUp (void) const
|
||||
return true;
|
||||
}
|
||||
void
|
||||
SimpleNetDevice::SetLinkChangeCallback (Callback<void> callback)
|
||||
SimpleNetDevice::AddLinkChangeCallback (Callback<void> callback)
|
||||
{}
|
||||
bool
|
||||
SimpleNetDevice::IsBroadcast (void) const
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
virtual bool SetMtu (const uint16_t mtu);
|
||||
virtual uint16_t GetMtu (void) const;
|
||||
virtual bool IsLinkUp (void) const;
|
||||
virtual void SetLinkChangeCallback (Callback<void> callback);
|
||||
virtual void AddLinkChangeCallback (Callback<void> callback);
|
||||
virtual bool IsBroadcast (void) const;
|
||||
virtual Address GetBroadcast (void) const;
|
||||
virtual bool IsMulticast (void) const;
|
||||
|
||||
@@ -34,13 +34,18 @@ def build(bld):
|
||||
'tcp-socket.cc',
|
||||
'tcp-socket-factory.cc',
|
||||
'ipv4.cc',
|
||||
'ipv4-raw-socket-factory.cc',
|
||||
'application.cc',
|
||||
'simple-channel.cc',
|
||||
'simple-net-device.cc',
|
||||
'inet6-socket-address.cc',
|
||||
'ipv6-address.cc',
|
||||
'ipv6-header.cc',
|
||||
'ipv4-raw-socket-factory.cc',
|
||||
'ipv6-interface-address.cc',
|
||||
'ipv6-route.cc',
|
||||
'ipv6.cc',
|
||||
'ipv6-raw-socket-factory.cc',
|
||||
'ipv6-routing-protocol.cc',
|
||||
]
|
||||
|
||||
headers = bld.new_task_gen('ns3header')
|
||||
@@ -57,7 +62,7 @@ def build(bld):
|
||||
'ipv4-address-generator.h',
|
||||
'ipv4-header.h',
|
||||
'net-device.h',
|
||||
'address-utils.h',
|
||||
'address-utils.h',
|
||||
'ipv4-route.h',
|
||||
'ipv4-routing-protocol.h',
|
||||
'queue.h',
|
||||
@@ -76,11 +81,16 @@ def build(bld):
|
||||
'tcp-socket.h',
|
||||
'tcp-socket-factory.h',
|
||||
'ipv4.h',
|
||||
'ipv4-raw-socket-factory.h',
|
||||
'application.h',
|
||||
'simple-channel.h',
|
||||
'simple-net-device.h',
|
||||
'inet6-socket-address.h',
|
||||
'ipv6-address.h',
|
||||
'ipv6-header.h',
|
||||
'ipv4-raw-socket-factory.h',
|
||||
'ipv6-interface-address.h',
|
||||
'ipv6-route.h',
|
||||
'ipv6.h',
|
||||
'ipv6-raw-socket-factory.h',
|
||||
'ipv6-routing-protocol.h',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user