This enables to_match_ip() to accept IPv4 address with dotted decimal
subnet mask or ACL hybrid CIDR.
Given 3 match field values below:
'192.168.1.0/24'
'192.168.1.0/255.255.255.0'
'192.168.1.0/0.0.0.255'
These addresses are logically equivalent.
Signed-off-by: Wei-Li Tang <[email protected]>
---
ryu/lib/ofctl_v1_2.py | 13 ++-----------
ryu/lib/ofctl_v1_3.py | 13 ++-----------
2 files changed, 4 insertions(+), 22 deletions(-)
diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
index 273b387..6b1d447 100644
--- a/ryu/lib/ofctl_v1_2.py
+++ b/ryu/lib/ofctl_v1_2.py
@@ -326,17 +326,8 @@ def to_match_tpdst(value, match, rest):
def to_match_ip(value):
- ip_mask = value.split('/')
- # ip
- ipv4 = struct.unpack('!I', socket.inet_aton(ip_mask[0]))[0]
- # netmask
- mask = 32
- if len(ip_mask) == 2:
- mask = int(ip_mask[1])
- netmask = ofproto_v1_2_parser.UINT32_MAX << 32 - mask\
- & ofproto_v1_2_parser.UINT32_MAX
-
- return ipv4, netmask
+ ip = netaddr.IPNetwork(value)
+ return ip.ip.value, ip.netmask.value
def to_match_ipv6(value):
diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py
index 3e2713e..403c82e 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -368,17 +368,8 @@ def to_match_tpdst(value, match, rest):
def to_match_ip(value):
- ip_mask = value.split('/')
- # ip
- ipv4 = struct.unpack('!I', socket.inet_aton(ip_mask[0]))[0]
- # netmask
- mask = 32
- if len(ip_mask) == 2:
- mask = int(ip_mask[1])
- netmask = ofproto_v1_3_parser.UINT32_MAX << 32 - mask\
- & ofproto_v1_3_parser.UINT32_MAX
-
- return ipv4, netmask
+ ip = netaddr.IPNetwork(value)
+ return ip.ip.value, ip.netmask.value
def to_match_ipv6(value):
--
1.7.9.5
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel