backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / lib / ofctl_nicira_ext.py
1 # Copyright (C) 2016 Rackspace US, Inc.
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import base64
17 import logging
18
19 from ryu.ofproto import nicira_ext
20
21
22 LOG = logging.getLogger(__name__)
23
24
25 def action_to_str(act, ofctl_action_to_str):
26     sub_type = act.subtype
27
28     if sub_type == nicira_ext.NXAST_RESUBMIT:
29         return 'NX_RESUBMIT: {port: %s, table: %s}' % (act.in_port,
30                                                        act.table_id)
31
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,
39                                                       src_start, src_end)
40
41     elif sub_type == nicira_ext.NXAST_REG_LOAD:
42         start = act.ofs
43         end = start + act.nbits
44         return 'NX_LOAD: {%s[%s..%s]: %x}' % (act.dst, start, end, act.value)
45
46     elif sub_type == nicira_ext.NXAST_LEARN:
47         specs = []
48         add_spec = specs.append
49
50         for spec in act.specs:
51             dst_type = spec._dst_type
52
53             if dst_type == 0:  # match
54                 if isinstance(spec.src, (tuple, list)):
55                     src = spec.src[0]
56                     start = spec.src[1]
57                     end = start + spec.n_bits
58                     start_end = '%s..%s' % (start, end)
59
60                 else:
61                     src = spec.src
62                     start_end = '[]'
63
64                 add_spec('%s[%s]' % (src, start_end))
65
66             elif dst_type == 1:  # load
67                 if isinstance(spec.src, (tuple, list)):
68                     src = spec.src[0]
69                     start = spec.src[1]
70                     end = start + spec.n_bits
71                     src_start_end = '[%s..%s]' % (start, end)
72
73                 else:
74                     src = spec.src
75                     src_start_end = '[]'
76
77                 if isinstance(spec.dst, (tuple, list)):
78                     dst = spec.dst[0]
79                     start = spec.dst[1]
80                     end = start + spec.n_bits
81                     dst_start_end = '[%s..%s]' % (start, end)
82
83                 else:
84                     dst = spec.dst
85                     dst_start_end = '[]'
86
87                 add_spec('NX_LOAD {%s%s: %s%s}' % (dst, dst_start_end,
88                                                    src, src_start_end))
89
90             elif dst_type == 2:  # output
91                 if isinstance(spec.src, (tuple, list)):
92                     src = spec.src[0]
93                     start = spec.src[1]
94                     end = start + spec.n_bits
95                     start_end = '%s..%s' % (start, end)
96
97                 else:
98                     src = spec.src
99                     start_end = '[]'
100
101                 add_spec('output:%s%s' % (src, start_end))
102
103         return ('NX_LEARN: {idle_timeout: %s, '
104                 'hard_timeouts: %s, '
105                 'priority: %s, '
106                 'cookie: %s, '
107                 'flags: %s, '
108                 'table_id: %s, '
109                 'fin_idle_timeout: %s, '
110                 'fin_hard_timeout: %s, '
111                 'specs: %s}' %
112                 (act.idle_timeout,
113                  act.hard_timeout,
114                  act.priority,
115                  act.cookie,
116                  act.flags,
117                  act.table_id,
118                  act.fin_idle_timeout,
119                  act.self.fin_hard_timeout,
120                  specs))
121
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))
125
126     elif sub_type == nicira_ext.NXAST_CT:
127         if act.zone_ofs_nbits != 0:
128             start = act.zone_ofs_nbits
129             end = start + 16
130             zone = act.zone_src + ('[%s..%s]' % (start, end))
131
132         else:
133             zone = act.zone_src
134
135         actions = [ofctl_action_to_str(action) for action in act.actions]
136
137         return ('NX_CT: {flags: %s, '
138                 'zone: %s, '
139                 'table: %s, '
140                 'alg: %s, '
141                 'actions: %s}' % (act.flags, zone, act.recirc_table, act.alg,
142                                   actions))
143
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,
152                                           act.range_ipv4_min,
153                                           act.range_ipv4_max,
154                                           act.range_ipv6_min,
155                                           act.range_ipv6_max,
156                                           act.range_proto_min,
157                                           act.range_proto_max))
158
159     data_str = base64.b64encode(act.data)
160     return 'NX_UNKNOWN: {subtype: %s, data: %s}' % (sub_type,
161                                                     data_str.decode('utf-8'))