summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_format.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_format.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_format.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_format.py b/src/vpp-api/python/vpp_papi/vpp_format.py
index fec0667862c..2c2345a3f76 100644
--- a/src/vpp-api/python/vpp_papi/vpp_format.py
+++ b/src/vpp-api/python/vpp_papi/vpp_format.py
@@ -13,11 +13,16 @@
# limitations under the License.
#
-from socket import inet_pton, inet_ntop, AF_INET6, AF_INET
+from socket import inet_pton, AF_INET6, AF_INET
import socket
import ipaddress
from . import macaddress
+try:
+ text_type = unicode
+except NameError:
+ text_type = str
+
# Copies from vl_api_address_t definition
ADDRESS_IP4 = 0
ADDRESS_IP6 = 1
@@ -37,18 +42,28 @@ def format_vl_api_address_t(args):
def format_vl_api_prefix_t(args):
+ if isinstance(args, (ipaddress.IPv4Network, ipaddress.IPv6Network)):
+ return {'prefix': format_vl_api_address_t(
+ text_type(args.network_address)),
+ 'len': int(args.prefixlen)}
p, length = args.split('/')
return {'address': format_vl_api_address_t(p),
'address_length': int(length)}
def format_vl_api_ip6_prefix_t(args):
+ if isinstance(args, ipaddress.IPv6Network):
+ return {'prefix': args.network_address.packed,
+ 'len': int(args.prefixlen)}
p, length = args.split('/')
return {'prefix': inet_pton(AF_INET6, p),
'len': int(length)}
def format_vl_api_ip4_prefix_t(args):
+ if isinstance(args, ipaddress.IPv4Network):
+ return {'prefix': args.network_address.packed,
+ 'len': int(args.prefixlen)}
p, length = args.split('/')
return {'prefix': inet_pton(AF_INET, p),
'len': int(length)}