bgp/utils/bgp: Use lib/ip for Python 3 compatibility
Utilities related to bgp data types and models.
"""
import logging
-import socket
import netaddr
+from ryu.lib import ip
from ryu.lib.packet.bgp import (
BGPUpdate,
RF_IPv4_UC,
@@ -107,8 +107,7 @@ def from_inet_ptoi(bgp_id):
"""
four_byte_id = None
try:
- packed_byte = socket.inet_pton(socket.AF_INET, bgp_id)
- four_byte_id = int(packed_byte.encode('hex'), 16)
+ four_byte_id = ip.ipv4_to_int(bgp_id)
except ValueError:
LOG.debug('Invalid bgp id given for conversion to integer value %s',
bgp_id)
