[Ns-bugs] [Bug 634] [PATCH] Feature to grab Network Length out of Ipv4Mask

code@nsnam.ece.gatech.edu code at nsnam.ece.gatech.edu
Thu Jul 9 21:47:51 PDT 2009


http://www.nsnam.org/bugzilla/show_bug.cgi?id=634


Tom Henderson <tomh at tomh.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tomh at tomh.org




--- Comment #2 from Tom Henderson <tomh at tomh.org>  2009-07-10 00:47:50 EDT ---
(In reply to comment #0)
> Created an attachment (id=524)
 --> (http://www.nsnam.org/bugzilla/attachment.cgi?id=524) [details]
> Adds GetMaskLength-method.
> 
> For some stuff, I need to check what size a given network is, "prefix length",
> ie. the CIDR notation, or 1.2.3.0/24 and similar. This patch adds a
> GetMaskLength() method to Ipv4Mask that obtains it. Documentation included. 
> 
> This notation is also used in IPv6 prefixes. (Weirdly, there is no Ipv4Prefix
> class).
> 
> For example,
> 
> std::cout << Ipv4Mask ("255.255.255.255").GetMaskLength() 
> 
> prints 32,
> 
> std::cout << Ipv4Mask ("255.255.255.240").GetMaskLength() 
> 
> prints 28
> 
> std::cout << Ipv4Mask ("128.0.0.0").GetMaskLength() 
> 
> prints 1
> 
> std::cout << Ipv4Mask ("0.0.0.0").GetMaskLength() 
> 
> prints 0.
> 
> Anyway, just in case it seems a good addition.
> 
> Unfortunately, the constructor for Ipv4Mask that takes an integer as a
> parameter, thus it cannot easily be adapted into specifying length instead,
> it's simply copying a 32-bit number as the mask. I would like to enter
> Ipv4masks in prefix format.

What about improving the implementation to detect a leading slash, and also
allow these strings?

Ipv4Mask ("/32")
Ipv4Mask ("/24")
etc.
> 
> (Ipv6Prefix::Ipv6Prefix(uint8_t) DOES exist). 
> 
> Also Ipv6Prefix class didn't seem to have a convention for function name to
> simply get the length, so I used this one.
> 
I didn't quite understand the above comment-- you are saying that you invented
"GetMaskLength()" because there was no corresponding "GetPrefixLength()"
function in IPv6?  Should you also add a similar length function to Ipv6Prefix?


    /**
+    * \brief Get Prefix length of mask (the yy in x.x.x.x/yy notation)
+    *
+    * Prints mask in Prefix Length notation
+    */
+    
+   uint16_t GetMaskLength (void) const;

For this doxygen, I would use \return instead of \brief and delete the "Prints
mask in Prefix Length notation" statement.


-- 
Configure bugmail: http://www.nsnam.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Ns-bugs mailing list