changes to replaces known usages of ipaddress, leaving only ipaddress.MacAddress
This commit is contained in:
parent
f431254e15
commit
fd10663323
15 changed files with 354 additions and 380 deletions
|
@ -7,9 +7,10 @@ import threading
|
|||
from contextlib import contextmanager
|
||||
|
||||
import grpc
|
||||
import netaddr
|
||||
|
||||
from core.api.grpc import core_pb2, core_pb2_grpc
|
||||
from core.nodes.ipaddress import Ipv4Prefix, Ipv6Prefix, MacAddress
|
||||
from core.nodes.ipaddress import MacAddress
|
||||
|
||||
|
||||
class InterfaceHelper:
|
||||
|
@ -30,10 +31,10 @@ class InterfaceHelper:
|
|||
|
||||
self.ip4 = None
|
||||
if ip4_prefix:
|
||||
self.ip4 = Ipv4Prefix(ip4_prefix)
|
||||
self.ip4 = netaddr.IPNetwork(ip4_prefix)
|
||||
self.ip6 = None
|
||||
if ip6_prefix:
|
||||
self.ip6 = Ipv6Prefix(ip6_prefix)
|
||||
self.ip6 = netaddr.IPNetwork(ip6_prefix)
|
||||
|
||||
def ip4_address(self, node_id):
|
||||
"""
|
||||
|
@ -45,7 +46,7 @@ class InterfaceHelper:
|
|||
"""
|
||||
if not self.ip4:
|
||||
raise ValueError("ip4 prefixes have not been set")
|
||||
return str(self.ip4.addr(node_id))
|
||||
return str(self.ip4[node_id])
|
||||
|
||||
def ip6_address(self, node_id):
|
||||
"""
|
||||
|
@ -57,7 +58,7 @@ class InterfaceHelper:
|
|||
"""
|
||||
if not self.ip6:
|
||||
raise ValueError("ip6 prefixes have not been set")
|
||||
return str(self.ip6.addr(node_id))
|
||||
return str(self.ip6[node_id])
|
||||
|
||||
def create_interface(self, node_id, interface_id, name=None, mac=None):
|
||||
"""
|
||||
|
@ -75,14 +76,14 @@ class InterfaceHelper:
|
|||
ip4 = None
|
||||
ip4_mask = None
|
||||
if self.ip4:
|
||||
ip4 = str(self.ip4.addr(node_id))
|
||||
ip4 = self.ip4_address(node_id)
|
||||
ip4_mask = self.ip4.prefixlen
|
||||
|
||||
# generate ip6 data
|
||||
ip6 = None
|
||||
ip6_mask = None
|
||||
if self.ip6:
|
||||
ip6 = str(self.ip6.addr(node_id))
|
||||
ip6 = self.ip6_address(node_id)
|
||||
ip6_mask = self.ip6.prefixlen
|
||||
|
||||
# random mac
|
||||
|
|
|
@ -24,7 +24,7 @@ from core.emulator.enumerations import (
|
|||
RegisterTlvs,
|
||||
SessionTlvs,
|
||||
)
|
||||
from core.nodes.ipaddress import IpAddress, MacAddress
|
||||
from core.nodes.ipaddress import MacAddress
|
||||
|
||||
|
||||
class CoreTlvData:
|
||||
|
@ -258,7 +258,7 @@ class CoreTlvDataIpv4Addr(CoreTlvDataObj):
|
|||
Utility class for packing/unpacking Ipv4 addresses.
|
||||
"""
|
||||
|
||||
data_type = IpAddress.from_string
|
||||
data_type = str
|
||||
data_format = "!2x4s"
|
||||
pad_len = 2
|
||||
|
||||
|
@ -267,21 +267,22 @@ class CoreTlvDataIpv4Addr(CoreTlvDataObj):
|
|||
"""
|
||||
Retrieve Ipv4 address value from object.
|
||||
|
||||
:param core.misc.ipaddress.IpAddress obj: ip address to get value from
|
||||
:return:
|
||||
:param str obj: ip address to get value from
|
||||
:return: packed address
|
||||
:rtype: bytes
|
||||
"""
|
||||
return obj.addr
|
||||
return socket.inet_pton(socket.AF_INET, obj)
|
||||
|
||||
@staticmethod
|
||||
def new_obj(value):
|
||||
"""
|
||||
Retrieve Ipv4 address from a string representation.
|
||||
|
||||
:param str value: value to get Ipv4 address from
|
||||
:param bytes value: value to get Ipv4 address from
|
||||
:return: Ipv4 address
|
||||
:rtype: core.nodes.ipaddress.IpAddress
|
||||
:rtype: str
|
||||
"""
|
||||
return IpAddress(af=socket.AF_INET, address=value)
|
||||
return socket.inet_ntop(socket.AF_INET, value)
|
||||
|
||||
|
||||
class CoreTlvDataIPv6Addr(CoreTlvDataObj):
|
||||
|
@ -290,7 +291,7 @@ class CoreTlvDataIPv6Addr(CoreTlvDataObj):
|
|||
"""
|
||||
|
||||
data_format = "!16s2x"
|
||||
data_type = IpAddress.from_string
|
||||
data_type = str
|
||||
pad_len = 2
|
||||
|
||||
@staticmethod
|
||||
|
@ -298,21 +299,22 @@ class CoreTlvDataIPv6Addr(CoreTlvDataObj):
|
|||
"""
|
||||
Retrieve Ipv6 address value from object.
|
||||
|
||||
:param core.nodes.ipaddress.IpAddress obj: ip address to get value from
|
||||
:return:
|
||||
:param str obj: ip address to get value from
|
||||
:return: packed address
|
||||
:rtype: bytes
|
||||
"""
|
||||
return obj.addr
|
||||
return socket.inet_pton(socket.AF_INET6, obj)
|
||||
|
||||
@staticmethod
|
||||
def new_obj(value):
|
||||
"""
|
||||
Retrieve Ipv6 address from a string representation.
|
||||
|
||||
:param str value: value to get Ipv4 address from
|
||||
:param bytes value: value to get Ipv4 address from
|
||||
:return: Ipv4 address
|
||||
:rtype: core.nodes.ipaddress.IpAddress
|
||||
:rtype: str
|
||||
"""
|
||||
return IpAddress(af=socket.AF_INET6, address=value)
|
||||
return socket.inet_ntop(socket.AF_INET6, value)
|
||||
|
||||
|
||||
class CoreTlvDataMacAddr(CoreTlvDataObj):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue