Build issue after https://gerrit.fd.io/r/#/c/16508/.
[vpp.git] / test / vpp_ip.py
index e44e6b5..055e6d7 100644 (file)
@@ -5,11 +5,7 @@
 
 from ipaddress import ip_address
 from socket import AF_INET, AF_INET6
-
-
-class IpAddressFamily:
-    ADDRESS_IP4 = 0
-    ADDRESS_IP6 = 1
+from vpp_papi import VppEnum
 
 
 class DpoProto:
@@ -31,17 +27,9 @@ class VppIpAddressUnion():
 
     def encode(self):
         if self.version is 6:
-            return {
-                'ip6': {
-                    'address': self.ip_addr.packed
-                },
-            }
+            return {'ip6': self.ip_addr.packed}
         else:
-            return {
-                'ip4': {
-                    'address': self.ip_addr.packed
-                },
-            }
+            return {'ip4': self.ip_addr.packed}
 
     @property
     def version(self):
@@ -68,9 +56,9 @@ class VppIpAddressUnion():
         elif hasattr(other, "ip4") and hasattr(other, "ip6"):
             # vl_api_address_union_t
             if 4 is self.version:
-                return self.ip_addr.packed == other.ip4.address
+                return self.ip_addr.packed == other.ip4
             else:
-                return self.ip_addr.packed == other.ip6.address
+                return self.ip_addr.packed == other.ip6
         else:
             raise Exception("Comparing VppIpAddresUnions:%s"
                             " with unknown type: %s" %
@@ -86,12 +74,12 @@ class VppIpAddress():
     def encode(self):
         if self.addr.version is 6:
             return {
-                'af': IpAddressFamily.ADDRESS_IP6,
+                'af': VppEnum.vl_api_address_family_t.ADDRESS_IP6,
                 'un': self.addr.encode()
             }
         else:
             return {
-                'af': IpAddressFamily.ADDRESS_IP4,
+                'af': VppEnum.vl_api_address_family_t.ADDRESS_IP4,
                 'un': self.addr.encode()
             }
 
@@ -101,10 +89,12 @@ class VppIpAddress():
         elif hasattr(other, "af") and hasattr(other, "un"):
             # a vp_api_address_t
             if 4 is self.version:
-                return other.af == IpAddressFamily.ADDRESS_IP4 and \
+                return other.af == \
+                    VppEnum.vl_api_address_family_t.ADDRESS_IP4 and \
                     other.un == self.addr
             else:
-                return other.af == IpAddressFamily.ADDRESS_IP6 and \
+                return other.af == \
+                    VppEnum.vl_api_address_family_t.ADDRESS_IP6 and \
                     other.un == self.addr
         else:
             raise Exception("Comparing VppIpAddress:%s with unknown type: %s" %
@@ -121,6 +111,10 @@ class VppIpAddress():
     def bytes(self):
         return self.addr.bytes
 
+    @property
+    def bytes(self):
+        return self.addr.bytes
+
     @property
     def address(self):
         return self.addr.address
@@ -170,10 +164,18 @@ class VppIpPrefix():
     def address(self):
         return self.addr.address
 
+    @property
+    def bytes(self):
+        return self.addr.bytes
+
     @property
     def length(self):
         return self.len
 
+    @property
+    def is_ip6(self):
+        return self.addr.is_ip6
+
     def __str__(self):
         return "%s/%d" % (self.address, self.length)
 
@@ -202,32 +204,16 @@ class VppIpMPrefix():
 
         if 6 is self.ip_saddr.version:
             prefix = {
-                'af': IpAddressFamily.ADDRESS_IP6,
-                'grp_address': {
-                    'ip6': {
-                        'address': self.ip_gaddr.packed
-                    },
-                },
-                'src_address': {
-                    'ip6': {
-                        'address': self.ip_saddr.packed
-                    },
-                },
+                'af': VppEnum.vl_api_address_family_t.ADDRESS_IP6,
+                'grp_address': {'ip6': self.ip_gaddr.packed},
+                'src_address': {'ip6': self.ip_saddr.packed},
                 'grp_address_length': self.len,
             }
         else:
             prefix = {
-                'af': IpAddressFamily.ADDRESS_IP4,
-                'grp_address': {
-                    'ip4': {
-                        'address': self.ip_gaddr.packed
-                    },
-                },
-                'src_address': {
-                    'ip4': {
-                        'address': self.ip_saddr.packed
-                    },
-                },
+                'af': VppEnum.vl_api_address_family_t.ADDRESS_IP4,
+                'grp_address': {'ip4': self.ip_gaddr.packed},
+                'src_address': {'ip4': self.ip_saddr.packed},
                 'grp_address_length': self.len,
             }
         return prefix