6 from ipaddress import ip_address
14 INVALID_INDEX = 0xffffffff
17 def compare_ip_address(api_address, py_address):
18 if 4 is py_address.version:
19 if py_address.packed == api_address.ip4.address:
22 if py_address.packed == api_address.ip6.address:
27 class VppIpAddressUnion():
28 def __init__(self, addr):
30 self.ip_addr = ip_address(unicode(self.addr))
34 return self.ip_addr.version
41 if self.ip_addr.version is 6:
44 'address': self.ip_addr.packed
50 'address': self.ip_addr.packed
56 def __init__(self, addr):
57 self.addr = VppIpAddressUnion(addr)
60 if self.addr.version is 6:
62 'af': IpAddressFamily.ADDRESS_IP6,
63 'un': self.addr.encode()
67 'af': IpAddressFamily.ADDRESS_IP4,
68 'un': self.addr.encode()
73 return self.addr.address
77 def __init__(self, addr, len):
78 self.addr = VppIpAddress(addr)
81 def __eq__(self, other):
82 if self.addr == other.addr and self.len == other.len:
87 return {'address': self.addr.encode(),
88 'address_length': self.len}
92 return self.addr.address
96 def __init__(self, saddr, gaddr, len):
100 self.ip_saddr = ip_address(unicode(self.saddr))
101 self.ip_gaddr = ip_address(unicode(self.gaddr))
105 if 6 is self.ip_saddr.version:
107 'af': IpAddressFamily.ADDRESS_IP6,
110 'address': self.ip_gaddr.packed
115 'address': self.ip_saddr.packed
118 'grp_address_length': self.len,
122 'af': IpAddressFamily.ADDRESS_IP4,
125 'address': self.ip_gaddr.packed
130 'address': self.ip_saddr.packed
133 'grp_address_length': self.len,