allow Ipv4Mask constructor to accept a string /32, /24 etc. in constructor
1.1 --- a/examples/static-routing-slash32.cc Sat Aug 22 14:58:27 2009 -0700
1.2 +++ b/examples/static-routing-slash32.cc Sat Aug 22 15:32:30 2009 -0700
1.3 @@ -87,12 +87,12 @@
1.4 int32_t ifIndexA = ipv4A->AddInterface (deviceA);
1.5 int32_t ifIndexC = ipv4C->AddInterface (deviceC);
1.6
1.7 - Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
1.8 + Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32"));
1.9 ipv4A->AddAddress (ifIndexA, ifInAddrA);
1.10 ipv4A->SetMetric (ifIndexA, 1);
1.11 ipv4A->SetUp (ifIndexA);
1.12
1.13 - Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
1.14 + Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("/32"));
1.15 ipv4C->AddAddress (ifIndexC, ifInAddrC);
1.16 ipv4C->SetMetric (ifIndexC, 1);
1.17 ipv4C->SetUp (ifIndexC);
2.1 --- a/src/node/ipv4-address.cc Sat Aug 22 14:58:27 2009 -0700
2.2 +++ b/src/node/ipv4-address.cc Sat Aug 22 15:32:30 2009 -0700
2.3 @@ -28,6 +28,7 @@
2.4
2.5 #define ASCII_DOT (0x2e)
2.6 #define ASCII_ZERO (0x30)
2.7 +#define ASCII_SLASH (0x2f)
2.8
2.9 static uint32_t
2.10 AsciiToIpv4Host (char const *address)
2.11 @@ -63,9 +64,18 @@
2.12 Ipv4Mask::Ipv4Mask (uint32_t mask)
2.13 : m_mask (mask)
2.14 {}
2.15 +
2.16 Ipv4Mask::Ipv4Mask (char const *mask)
2.17 {
2.18 - m_mask = AsciiToIpv4Host (mask);
2.19 + if (*mask == ASCII_SLASH)
2.20 + {
2.21 + m_mask = static_cast<uint32_t> (atoi (++mask));
2.22 + NS_ASSERT (m_mask <= 32);
2.23 + }
2.24 + else
2.25 + {
2.26 + m_mask = AsciiToIpv4Host (mask);
2.27 + }
2.28 }
2.29
2.30 bool
3.1 --- a/src/node/ipv4-address.h Sat Aug 22 14:58:27 2009 -0700
3.2 +++ b/src/node/ipv4-address.h Sat Aug 22 15:32:30 2009 -0700
3.3 @@ -198,11 +198,26 @@
3.4 * \ingroup address
3.5 *
3.6 * \brief a class to represent an Ipv4 address mask
3.7 + *
3.8 + * The constructor takes arguments according to a few formats.
3.9 + * Ipv4Mask ("255.255.255.255"), Ipv4Mask ("/32"), and Ipv4Mask (0xffffffff)
3.10 + * are all equivalent.
3.11 */
3.12 class Ipv4Mask {
3.13 public:
3.14 + /**
3.15 + * Will initialize to a garbage value (0x66666666)
3.16 + */
3.17 Ipv4Mask ();
3.18 + /**
3.19 + * param mask bitwise integer representation of the mask
3.20 + *
3.21 + * For example, the integer input 0xffffff00 yields a 24-bit mask
3.22 + */
3.23 Ipv4Mask (uint32_t mask);
3.24 + /**
3.25 + * \param mask String constant either in "255.255.255.0" or "/24" format
3.26 + */
3.27 Ipv4Mask (char const *mask);
3.28 /**
3.29 * \param a first address to compare