diff options
author | Wei-Li Tang <alextwl@xinguard.com> | 2014-03-11 13:49:23 +0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-03-16 18:06:01 +0900 |
commit | d5ec1f20797627bcedb64b1d3362e350f012a025 (patch) | |
tree | 8c17983b7fb9f3808048fc6c33d27a4659fcbf6e | |
parent | 5ce9e31b65785ceef8d57d68fa5213d2e140303d (diff) |
ofctl_v1_2/3: IPv4 dotted decimal subnet mask support
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 <alextwl@xinguard.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/ofctl_v1_2.py | 13 | ||||
-rw-r--r-- | 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 273b387c..6b1d4478 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 3e2713e8..403c82e2 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): |