IPprefix Module

This Module (ipp) provides methods to store and use IPv4 and IPv6 addresses.

When you use python-libtrace (import plt),  IPprefix is automatically 
loaded - you don't need to import ipp as well.

Class IPprefix

Represents an IP adress or prefix.

Instance Variables
version 4 for IPv4, 6 for IPv6
addr 4- or 16-byte array containing actual address; the array bytes contain the actual bytes of the address
length Number of bits in prefix. If length is None the IPprefix represents just an IP address

Class Methods
from_s() ipp.from_s(aString)-> aNewIPprefix

Parses str to find version and address, e.g.
   p = ipp.from_s('')
   p = ipp.from_s('fe80::20d:60ff:fe38:18b/64')
IPprefix -> aString

Returns a string containing a printable version of the IPprefix's address (and /width, if width is not None)
ipp will convert an IPprefix to a python string by calling its (built-in) str() function

Instance Methods
<, <=, ==, >=, >, !=
IPprefix op OtherIPprefix -> True or False

'Rich compare' operators: comparisions use the versions, addresses and lengths of two IPprefixes.  These can be used to sort IPprefixes into ascending or descending order, IPprefixes with the same addr compare based on their lengths.
IPprefix(v, a)
IPprefix(version,address) -> aNewIPprefix

Returns an IPprefix conatining an IP address, e.g.
   version  = 4 for IPv4, 6 for IPv6
   address = 4- or 16-byte array containing
                    actual address
IPprefix(v, a, len) IPprefix(version, address, length) -> aNewIPprefix

Returns an IPprefix containing a network prefix, e.g.
   version, address - as above
   length = number of bits in prefix
version IPprefix.version -> anIinteger
addr IPprefix.addr -> aString
length IPprefix.length-> anIinteger

Read values of the instance variables.
length= IPprefix.length = anInteger -> anIinteger

Sets value for an IPprefix width.

Instance Methods for prefix testing
is_prefix IPprefix .is_prefix(OtherIPprefix) -> True or False

Returns true if this IPprefix is a prefix of OtherIPprefix, i.e. their first IPprefix.length bits are the same.
equal IPprefix.equal(OtherIPprefix) -> True or False

Two IPprefixes are equal if they have the same version and addr.
width IPprefix.width -> anInteger

Returns IPprefix.length - 1
has_bit_set IPprefix.has_bit_set(Integer) -> True or False

Returns true if the bit specified by Integer is 1.
For example, if Integer is 0, has_bit_set is true if the leftmost bit of IPprefix is 1.
first_bit_different IPprefix.first_bit_different(OtherIPprefix) -> anInteger

Returns an Integer, the (0-origin) bit position where the two IPprefixes are different.
complement IPprefix.complement -> OtherIPprefix

Returns the complement of an IPprefix, i.e. one having the same length, but all bits the ones-complement of those in IPprefix.
is_rfc1918 IPprefix.is_rfc1918 -> True or False

Returns True if the IPprefix's address is in the IPv4 range specified in RFC 1918, i.e. in one of the Private prefixes below.

Global Constants
'Private'  prefixes
See RFC 1918 for more details




Nevil Brownlee
Tue, 4 Nov 14 (NZDT)