- if 4 is self.version:
- return self.ip_addr.packed == other.ip4.address
- else:
- return self.ip_addr.packed == other.ip6.address
- else:
- raise Exception("Comparing VppIpAddresUnions:%s"
- " with unknown type: %s" %
- (self, other))
-
- return False
-
-
-class VppIpAddress():
- def __init__(self, addr):
- self.addr = VppIpAddressUnion(addr)
-
- def encode(self):
- if self.addr.version is 6:
- return {
- 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP6,
- 'un': self.addr.encode()
- }
- else:
- return {
- 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP4,
- 'un': self.addr.encode()
- }
-
- def __eq__(self, other):
- if isinstance(other, self.__class__):
- return self.addr == other.addr
- elif hasattr(other, "af") and hasattr(other, "un"):
- # a vp_api_address_t
- if 4 is self.version:
- return other.af == \
- VppEnum.vl_api_address_family_t.ADDRESS_IP4 and \
- other.un == self.addr