1 # Copyright (C) 2016 Rackspace US, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 from ryu.ofproto import nicira_ext
22 LOG = logging.getLogger(__name__)
25 def action_to_str(act, ofctl_action_to_str):
26 sub_type = act.subtype
28 if sub_type == nicira_ext.NXAST_RESUBMIT:
29 return 'NX_RESUBMIT: {port: %s, table: %s}' % (act.in_port,
32 elif sub_type == nicira_ext.NXAST_REG_MOVE:
33 src_start = act.src_ofs
34 dst_start = act.dst_ofs
35 src_end = src_start + act.n_bits
36 dst_end = dst_start + act.n_bits
37 return 'NX_MOVE: {%s[%s..%s]: %s[%s..%s]}' % (act.dst_field, dst_start,
38 dst_end, act.src_field,
41 elif sub_type == nicira_ext.NXAST_REG_LOAD:
43 end = start + act.nbits
44 return 'NX_LOAD: {%s[%s..%s]: %x}' % (act.dst, start, end, act.value)
46 elif sub_type == nicira_ext.NXAST_LEARN:
48 add_spec = specs.append
50 for spec in act.specs:
51 dst_type = spec._dst_type
53 if dst_type == 0: # match
54 if isinstance(spec.src, (tuple, list)):
57 end = start + spec.n_bits
58 start_end = '%s..%s' % (start, end)
64 add_spec('%s[%s]' % (src, start_end))
66 elif dst_type == 1: # load
67 if isinstance(spec.src, (tuple, list)):
70 end = start + spec.n_bits
71 src_start_end = '[%s..%s]' % (start, end)
77 if isinstance(spec.dst, (tuple, list)):
80 end = start + spec.n_bits
81 dst_start_end = '[%s..%s]' % (start, end)
87 add_spec('NX_LOAD {%s%s: %s%s}' % (dst, dst_start_end,
90 elif dst_type == 2: # output
91 if isinstance(spec.src, (tuple, list)):
94 end = start + spec.n_bits
95 start_end = '%s..%s' % (start, end)
101 add_spec('output:%s%s' % (src, start_end))
103 return ('NX_LEARN: {idle_timeout: %s, '
104 'hard_timeouts: %s, '
109 'fin_idle_timeout: %s, '
110 'fin_hard_timeout: %s, '
118 act.fin_idle_timeout,
119 act.self.fin_hard_timeout,
122 elif sub_type == nicira_ext.NXAST_CONJUNCTION:
123 return ('NX_CONJUNCTION: {clause: %s, number_of_clauses: %s, id: %s}' %
124 (act.clause, act.n_clauses, act.id))
126 elif sub_type == nicira_ext.NXAST_CT:
127 if act.zone_ofs_nbits != 0:
128 start = act.zone_ofs_nbits
130 zone = act.zone_src + ('[%s..%s]' % (start, end))
135 actions = [ofctl_action_to_str(action) for action in act.actions]
137 return ('NX_CT: {flags: %s, '
141 'actions: %s}' % (act.flags, zone, act.recirc_table, act.alg,
144 elif sub_type == nicira_ext.NXAST_NAT:
145 return ('NX_NAT: {flags: %s, '
146 'range_ipv4_min: %s, '
147 'range_ipv4_max: %s, '
148 'range_ipv6_min: %s, '
149 'range_ipv6_max: %s, '
150 'range_proto_min: %s, '
151 'range_proto_max: %s}' % (act.flags,
157 act.range_proto_max))
159 data_str = base64.b64encode(act.data)
160 return 'NX_UNKNOWN: {subtype: %s, data: %s}' % (sub_type,
161 data_str.decode('utf-8'))