diff options
author | Jason Kölker <jason@koelker.net> | 2016-03-29 19:18:37 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-30 08:08:48 +0900 |
commit | 110118586fae83187d3558b02b434c549a5c865a (patch) | |
tree | 7ac36ff7628feb0919621dae07fab906e2261319 | |
parent | 429a6bc5468d1379df31a76484bdf3d1de247f95 (diff) |
lib/ofctl_v1_3: Support nicira extensions
Signed-off-by: Jason Kölker <jason@koelker.net>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/ofctl_nicira_ext.py | 156 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_3.py | 9 | ||||
-rw-r--r-- | ryu/tests/unit/lib/ofctl_json/of13/4-12-ofp_flow_stats_reply.packet.json | 2 |
3 files changed, 166 insertions, 1 deletions
diff --git a/ryu/lib/ofctl_nicira_ext.py b/ryu/lib/ofctl_nicira_ext.py new file mode 100644 index 00000000..3a5c6be1 --- /dev/null +++ b/ryu/lib/ofctl_nicira_ext.py @@ -0,0 +1,156 @@ +# Copyright (C) 2016 Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import base64 +import logging + +from ryu.ofproto import nicira_ext + + +LOG = logging.getLogger(__name__) + + +def action_to_str(act, ofctl_action_to_str): + sub_type = act.subtype + + if sub_type == nicira_ext.NXAST_RESUBMIT: + return 'NX_RESUBMIT: {port: %s, table: %s}' % (act.in_port, + act.table_id) + + elif sub_type == nicira_ext.NXAST_REG_MOVE: + src_start = act.src_ofs + dst_start = act.dst_ofs + src_end = src_start + act.n_bits + dst_end = dst_start + act.n_bits + return 'NX_MOVE: {%s[%s..%s]: %s[%s..%s]}' % (act.dst_field, dst_start, + dst_end, act.src_field, + src_start, src_end) + + elif sub_type == nicira_ext.NXAST_REG_LOAD: + start = act.ofs + end = start + act.nbits + return 'NX_LOAD: {%s[%s..%s]: %x}' % (act.dst, start, end, act.value) + + elif sub_type == nicira_ext.NXAST_LEARN: + specs = [] + add_spec = specs.append + + for spec in act.specs: + dst_type = spec._dst_type + + if dst_type == 0: # match + if isinstance(spec.src, (tuple, list)): + src = spec.src[0] + start = spec.src[1] + end = start + spec.n_bits + start_end = '%s..%s' % (start, end) + + else: + src = spec.src + start_end = '[]' + + add_spec('%s[%s]' % (src, start_end)) + + elif dst_type == 1: # load + if isinstance(spec.src, (tuple, list)): + src = spec.src[0] + start = spec.src[1] + end = start + spec.n_bits + src_start_end = '[%s..%s]' % (start, end) + + else: + src = spec.src + start_end = '' + + if isinstance(spec.dst, (tuple, list)): + dst = spec.dst[0] + start = spec.dst[1] + end = start + spec.n_bits + dst_start_end = '[%s..%s]' % (start, end) + + else: + dst = spec.dst + start_end = '[]' + + add_spec('NX_LOAD {%s%s: %s%s}' % (dst, dst_start_end, + src, src_start_end)) + + elif dst_type == 2: # output + if isinstance(spec.src, (tuple, list)): + src = spec.src[0] + start = spec.src[1] + end = start + spec.n_bits + start_end = '%s..%s' % (start, end) + + else: + src = spec.src + start_end = '[]' + + add_spec('output:%s%s' % (src, start_end)) + + return ('NX_LEARN: {idle_timeout: %s, ' + 'hard_timeouts: %s, ' + 'priority: %s, ' + 'cookie: %s, ' + 'flags: %s, ' + 'table_id: %s, ' + 'fin_idle_timeout: %s, ' + 'fin_hard_timeout: %s, ' + 'specs: %s}' % (act.idle_timeout, act.hard_timeout, + act.priority, act.cookie, act.flags, + act.fin_idle_timeout, + act.self.fin_hard_timeout, + specs)) + + elif sub_type == nicira_ext.NXAST_CONJUNCTION: + return ('NX_CONJUNCTION: {clause: %s, number_of_clauses: %s, id: %s}' % + (act.clause, act.n_clauses, act.id)) + + elif sub_type == nicira_ext.NXAST_CT: + if act.zone_ofs_nbits != 0: + start = act.zone_ofs_nbits + end = start + 16 + zone = act.zone_src + ('[%s..%s]' % (start, end)) + + else: + zone = act.zone_src + + actions = [ofctl_action_to_str(action) for action in act.actions] + + return ('NX_CT: {flags: %s, ' + 'zone: %s, ' + 'table: %s, ' + 'alg: %s, ' + 'actions: %s}' % (act.flags, zone, act.recirc_table, act.alg, + actions)) + + elif sub_type == nicira_ext.NXAST_NAT: + return ('NX_NAT: {flags: %s, ' + 'range_ipv4_min: %s, ' + 'range_ipv4_max: %s, ' + 'range_ipv6_min: %s, ' + 'range_ipv6_max: %s, ' + 'range_proto_min: %s, ' + 'range_proto_max: %s}' % (act.flags, + act.range_ipv4_min, + act.range_ipv4_max, + act.range_ipv6_min, + act.range_ipv6_max, + act.range_proto_min, + act.range_proto_max)) + + data_str = base64.b64encode(act.data) + return 'NX_UNKNOWN: {subtype: %s, data: %s}' % (sub_type, + data_str.decode('utf-8')) diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py index be1776b5..987e8f60 100644 --- a/ryu/lib/ofctl_v1_3.py +++ b/ryu/lib/ofctl_v1_3.py @@ -19,8 +19,10 @@ import netaddr from ryu.ofproto import ether from ryu.ofproto import inet +from ryu.ofproto import ofproto_common from ryu.ofproto import ofproto_v1_3 from ryu.ofproto import ofproto_v1_3_parser +from ryu.lib import ofctl_nicira_ext from ryu.lib import ofctl_utils @@ -187,6 +189,13 @@ def action_to_str(act): elif action_type == ofproto_v1_3.OFPAT_POP_PBB: buf = 'POP_PBB' elif action_type == ofproto_v1_3.OFPAT_EXPERIMENTER: + if act.experimenter == ofproto_common.NX_EXPERIMENTER_ID: + try: + return ofctl_nicira_ext.action_to_str(act, action_to_str) + except: + LOG.debug('Error parsing NX_ACTION(%s)', + act.__class__.__name__, exc_info=True) + data_str = base64.b64encode(act.data) buf = 'EXPERIMENTER: {experimenter:%s, data:%s}' % \ (act.experimenter, data_str.decode('utf-8')) diff --git a/ryu/tests/unit/lib/ofctl_json/of13/4-12-ofp_flow_stats_reply.packet.json b/ryu/tests/unit/lib/ofctl_json/of13/4-12-ofp_flow_stats_reply.packet.json index a9cdfa92..f9b8e68f 100644 --- a/ryu/tests/unit/lib/ofctl_json/of13/4-12-ofp_flow_stats_reply.packet.json +++ b/ryu/tests/unit/lib/ofctl_json/of13/4-12-ofp_flow_stats_reply.packet.json @@ -76,7 +76,7 @@ "GROUP:99", "OUTPUT:6", "EXPERIMENTER: {experimenter:98765432, data:ZXhwX2RhdGE=}", - "EXPERIMENTER: {experimenter:8992, data:cF9kYXRh}" + "NX_UNKNOWN: {subtype: 25976, data: cF9kYXRh}" ] }, "SET_FIELD: {eth_src:01:02:03:04:05:06}", |