Signed-off-by: Wei-Li Tang <[email protected]>
---
ryu/lib/ofctl_v1_2.py | 27 +++++++++++++++++++++++----
ryu/lib/ofctl_v1_3.py | 27 +++++++++++++++++++++++----
2 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
index c8b9174..5e056d1 100644
--- a/ryu/lib/ofctl_v1_2.py
+++ b/ryu/lib/ofctl_v1_2.py
@@ -17,7 +17,6 @@ import base64
import struct
import socket
import logging
-import netaddr
from ryu.ofproto import ether
from ryu.ofproto import inet
@@ -284,10 +283,30 @@ def to_match_eth(value):
def to_match_ip(value):
+ # NOTE: We don't use netaddr.ip.IPNetwork() to resolve address here
+ # because it doesn't support arbitrary bitmask.
if '/' in value:
- ip = netaddr.ip.IPNetwork(value)
- ip_addr = str(ip.ip)
- ip_mask = str(ip.netmask)
+ (ip_addr, ip_mask) = value.split('/')
+
+ # Convert ip_mask into dotted-decimal or colon-hexadecimal format
+ # if value is represented in CIDR notation.
+ if ip_mask.isdigit():
+ # Identify the family of the address.
+ if ':' in ip_addr:
+ # IPv6 CIDR
+ UINT128_MAX = (1 << 128) - 1
+ ip_mask_int = UINT128_MAX & UINT128_MAX << 128 - int(ip_mask)
+ ip_mask_h = ip_mask_int >> 64
+ ip_mask_l = ip_mask_int & ofproto_v1_2_parser.UINT64_MAX
+ ip_mask = socket.inet_ntop(socket.AF_INET6,
+ struct.pack('!2Q',
+ ip_mask_h, ip_mask_l))
+ else:
+ # IPv4 CIDR
+ ip_mask_int = ofproto_v1_2_parser.UINT32_MAX & \
+ ofproto_v1_2_parser.UINT32_MAX << 32 - int(ip_mask)
+ ip_mask = socket.inet_ntoa(struct.pack('!I', ip_mask_int))
+
return ip_addr, ip_mask
else:
return value
diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py
index 485a3b4..698d7b1 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -17,7 +17,6 @@ import base64
import struct
import socket
import logging
-import netaddr
from ryu.ofproto import ether
from ryu.ofproto import inet
@@ -305,10 +304,30 @@ def to_match_eth(value):
def to_match_ip(value):
+ # NOTE: We don't use netaddr.ip.IPNetwork() to resolve address here
+ # because it doesn't support arbitrary bitmask.
if '/' in value:
- ip = netaddr.ip.IPNetwork(value)
- ip_addr = str(ip.ip)
- ip_mask = str(ip.netmask)
+ (ip_addr, ip_mask) = value.split('/')
+
+ # Convert ip_mask into dotted-decimal or colon-hexadecimal format
+ # if value is represented in CIDR notation.
+ if ip_mask.isdigit():
+ # Identify the family of the address.
+ if ':' in ip_addr:
+ # IPv6 CIDR
+ UINT128_MAX = (1 << 128) - 1
+ ip_mask_int = UINT128_MAX & UINT128_MAX << 128 - int(ip_mask)
+ ip_mask_h = ip_mask_int >> 64
+ ip_mask_l = ip_mask_int & ofproto_v1_3_parser.UINT64_MAX
+ ip_mask = socket.inet_ntop(socket.AF_INET6,
+ struct.pack('!2Q',
+ ip_mask_h, ip_mask_l))
+ else:
+ # IPv4 CIDR
+ ip_mask_int = ofproto_v1_3_parser.UINT32_MAX & \
+ ofproto_v1_3_parser.UINT32_MAX << 32 - int(ip_mask)
+ ip_mask = socket.inet_ntoa(struct.pack('!I', ip_mask_int))
+
return ip_addr, ip_mask
else:
return value
--
1.9.1
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel