summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYuichi Ito <ito.yuichi0@gmail.com>2013-12-27 10:56:56 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-12-27 15:24:19 +0900
commit8597df8a00efe120850c02e86d959aee2ce89bd1 (patch)
tree469d5bb9d87ffb3513360e7fb3de3f1e5d05bc4b
parent988475f503fb8c65099d1718c6f4e4aebcbb4a57 (diff)
ofctl_v1_2/3: support OXM field names
this patch gets match field names to support OXM field names. NOTE: OpenFlow1.0 does not support OXM field names. the compatibility is as follows: dl_src eth_src dl_dst eth_dst dl_type eth_type dl_vlan vlan_vid nw_src ipv4_src nw_dst ipv4_dst nw_proto ip_proto tp_src tcp_src or udp_src tp_dst tcp_dst or udp_dst for example, the following commands for ofctl_rest install the same flow entry. curl -X POST -d '{"dpid": 1, "match": {"dl_type": 2048, "nw_src": "192.168.1.1"}, "actions": [{"type": "OUTPUT", "port": 2}]}' http://localhost:8080/stats/flowentry/add curl -X POST -d '{"dpid": 1, "match": {"eth_type": 2048, "ipv4_src": 192.168.1.1"}, "actions": [{"type": "OUTPUT", "port": 2}]}' http://localhost:8080/stats/flowentry/add Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
-rw-r--r--ryu/lib/ofctl_v1_2.py37
-rw-r--r--ryu/lib/ofctl_v1_3.py37
2 files changed, 62 insertions, 12 deletions
diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
index 1591c35e..c0da95a0 100644
--- a/ryu/lib/ofctl_v1_2.py
+++ b/ryu/lib/ofctl_v1_2.py
@@ -79,7 +79,18 @@ def to_match(dp, attrs):
'nw_dst': to_match_ip,
'nw_proto': int,
'tp_src': int,
- 'tp_dst': int}
+ 'tp_dst': int,
+ 'eth_src': mac.haddr_to_bin,
+ 'eth_dst': mac.haddr_to_bin,
+ 'eth_type': int,
+ 'vlan_vid': int,
+ 'ipv4_src': to_match_ip,
+ 'ipv4_dst': to_match_ip,
+ 'ip_proto': int,
+ 'tcp_src': int,
+ 'tcp_dst': int,
+ 'udp_src': int,
+ 'udp_dst': int}
match_append = {'in_port': match.set_in_port,
'dl_src': match.set_dl_src,
@@ -90,18 +101,32 @@ def to_match(dp, attrs):
'nw_dst': match.set_ipv4_dst_masked,
'nw_proto': match.set_ip_proto,
'tp_src': to_match_tpsrc,
- 'tp_dst': to_match_tpdst}
+ 'tp_dst': to_match_tpdst,
+ 'eth_src': match.set_dl_src,
+ 'eth_dst': match.set_dl_dst,
+ 'eth_type': match.set_dl_type,
+ 'vlan_vid': match.set_vlan_vid,
+ 'ipv4_src': match.set_ipv4_src_masked,
+ 'ipv4_dst': match.set_ipv4_dst_masked,
+ 'ip_proto': match.set_ip_proto,
+ 'tcp_src': to_match_tpsrc,
+ 'tcp_dst': to_match_tpdst,
+ 'udp_src': to_match_tpsrc,
+ 'udp_dst': to_match_tpdst}
for key, value in attrs.items():
if key in convert:
value = convert[key](value)
if key in match_append:
- if key == 'nw_src' or key == 'nw_dst':
+ if key == 'nw_src' or key == 'nw_dst' or \
+ key == 'ipv4_src' or key == 'ipv4_dst':
# IP address
ip = value[0]
mask = value[1]
match_append[key](ip, mask)
- elif key == 'tp_src' or key == 'tp_dst':
+ elif key == 'tp_src' or key == 'tp_dst' or \
+ key == 'tcp_src' or key == 'tcp_dst' or \
+ key == 'udp_src' or key == 'udp_dst':
# tp_src/dst
match = match_append[key](value, match, attrs)
else:
@@ -115,7 +140,7 @@ def to_match_tpsrc(value, match, rest):
match_append = {inet.IPPROTO_TCP: match.set_tcp_src,
inet.IPPROTO_UDP: match.set_udp_src}
- nw_proto = rest.get('nw_proto', 0)
+ nw_proto = rest.get('nw_proto', rest.get('ip_proto', 0))
if nw_proto in match_append:
match_append[nw_proto](value)
@@ -126,7 +151,7 @@ def to_match_tpdst(value, match, rest):
match_append = {inet.IPPROTO_TCP: match.set_tcp_dst,
inet.IPPROTO_UDP: match.set_udp_dst}
- nw_proto = rest.get('nw_proto', 0)
+ nw_proto = rest.get('nw_proto', rest.get('ip_proto', 0))
if nw_proto in match_append:
match_append[nw_proto](value)
diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py
index 107220c1..4516a569 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -212,7 +212,18 @@ def to_match(dp, attrs):
'tp_src': int,
'tp_dst': int,
'mpls_label': int,
- 'metadata': to_match_metadata}
+ 'metadata': to_match_metadata,
+ 'eth_src': mac.haddr_to_bin,
+ 'eth_dst': mac.haddr_to_bin,
+ 'eth_type': int,
+ 'vlan_vid': int,
+ 'ipv4_src': to_match_ip,
+ 'ipv4_dst': to_match_ip,
+ 'ip_proto': int,
+ 'tcp_src': int,
+ 'tcp_dst': int,
+ 'udp_src': int,
+ 'udp_dst': int}
match_append = {'in_port': match.set_in_port,
'dl_src': match.set_dl_src,
@@ -225,18 +236,32 @@ def to_match(dp, attrs):
'tp_src': to_match_tpsrc,
'tp_dst': to_match_tpdst,
'mpls_label': match.set_mpls_label,
- 'metadata': match.set_metadata_masked}
+ 'metadata': match.set_metadata_masked,
+ 'eth_src': match.set_dl_src,
+ 'eth_dst': match.set_dl_dst,
+ 'eth_type': match.set_dl_type,
+ 'vlan_vid': match.set_vlan_vid,
+ 'ipv4_src': match.set_ipv4_src_masked,
+ 'ipv4_dst': match.set_ipv4_dst_masked,
+ 'ip_proto': match.set_ip_proto,
+ 'tcp_src': to_match_tpsrc,
+ 'tcp_dst': to_match_tpdst,
+ 'udp_src': to_match_tpsrc,
+ 'udp_dst': to_match_tpdst}
for key, value in attrs.items():
if key in convert:
value = convert[key](value)
if key in match_append:
- if key == 'nw_src' or key == 'nw_dst':
+ if key == 'nw_src' or key == 'nw_dst' or \
+ key == 'ipv4_src' or key == 'ipv4_dst':
# IP address
ip = value[0]
mask = value[1]
match_append[key](ip, mask)
- elif key == 'tp_src' or key == 'tp_dst':
+ elif key == 'tp_src' or key == 'tp_dst' or \
+ key == 'tcp_src' or key == 'tcp_dst' or \
+ key == 'udp_src' or key == 'udp_dst':
# tp_src/dst
match_append[key](value, match, attrs)
elif key == 'metadata':
@@ -255,7 +280,7 @@ def to_match_tpsrc(value, match, rest):
match_append = {inet.IPPROTO_TCP: match.set_tcp_src,
inet.IPPROTO_UDP: match.set_udp_src}
- nw_proto = rest.get('nw_proto', 0)
+ nw_proto = rest.get('nw_proto', rest.get('ip_proto', 0))
if nw_proto in match_append:
match_append[nw_proto](value)
@@ -266,7 +291,7 @@ def to_match_tpdst(value, match, rest):
match_append = {inet.IPPROTO_TCP: match.set_tcp_dst,
inet.IPPROTO_UDP: match.set_udp_dst}
- nw_proto = rest.get('nw_proto', 0)
+ nw_proto = rest.get('nw_proto', rest.get('ip_proto', 0))
if nw_proto in match_append:
match_append[nw_proto](value)