backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / ofproto / ofproto_v1_0.py
1 # Copyright (C) 2011, 2012 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2011, 2012 Isaku Yamahata <yamahata at valinux co jp>
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """
18 OpenFlow 1.0 definitions.
19 """
20
21 from ryu.ofproto import ofproto_utils
22 from ryu.ofproto.nicira_ext import *  # For API compat
23
24 MAX_XID = 0xffffffff
25
26 # define constants
27 OFP_VERSION = 0x01
28 OFP_MAX_TABLE_NAME_LEN = 32
29 OFP_MAX_TABLE_NAME_LEN_STR = str(OFP_MAX_TABLE_NAME_LEN)
30 OFP_MAX_PORT_NAME_LEN = 16
31 OFP_TCP_PORT = 6633
32 OFP_SSL_PORT = 6633
33 OFP_ETH_ALEN = 6
34 OFP_ETH_ALEN_STR = str(OFP_ETH_ALEN)
35
36 OFP_NO_BUFFER = 0xffffffff
37
38 # enum ofp_port
39 OFPP_MAX = 0xff00
40 OFPP_IN_PORT = 0xfff8   # Send the packet out the input port. This
41                         # virtual port must be explicitly used
42                         # in order to send back out of the input
43                         # port.
44 OFPP_TABLE = 0xfff9     # Perform actions in flow table.
45                         # NB: This can only be the destination
46                         # port for packet-out messages.
47 OFPP_NORMAL = 0xfffa    # Process with normal L2/L3 switching.
48 OFPP_FLOOD = 0xfffb     # All physical ports except input port and
49                         # those disabled by STP.
50 OFPP_ALL = 0xfffc       # All physical ports except input port.
51 OFPP_CONTROLLER = 0xfffd        # Send to controller.
52 OFPP_LOCAL = 0xfffe     # Local openflow "port".
53 OFPP_NONE = 0xffff      # Not associated with a physical port.
54
55 # enum ofp_type
56 OFPT_HELLO = 0  # Symmetric message
57 OFPT_ERROR = 1  # Symmetric message
58 OFPT_ECHO_REQUEST = 2   # Symmetric message
59 OFPT_ECHO_REPLY = 3     # Symmetric message
60 OFPT_VENDOR = 4         # Symmetric message
61 OFPT_FEATURES_REQUEST = 5       # Controller/switch message
62 OFPT_FEATURES_REPLY = 6         # Controller/switch message
63 OFPT_GET_CONFIG_REQUEST = 7     # Controller/switch message
64 OFPT_GET_CONFIG_REPLY = 8       # Controller/switch message
65 OFPT_SET_CONFIG = 9      # Controller/switch message
66 OFPT_PACKET_IN = 10      # Async message
67 OFPT_FLOW_REMOVED = 11   # Async message
68 OFPT_PORT_STATUS = 12    # Async message
69 OFPT_PACKET_OUT = 13     # Controller/switch message
70 OFPT_FLOW_MOD = 14       # Controller/switch message
71 OFPT_PORT_MOD = 15       # Controller/switch message
72 OFPT_STATS_REQUEST = 16  # Controller/switch message
73 OFPT_STATS_REPLY = 17    # Controller/switch message
74 OFPT_BARRIER_REQUEST = 18       # Controller/switch message
75 OFPT_BARRIER_REPLY = 19  # Controller/switch message
76 OFPT_QUEUE_GET_CONFIG_REQUEST = 20      # Controller/switch message
77 OFPT_QUEUE_GET_CONFIG_REPLY = 21        # Controller/switch message
78
79 OFP_HEADER_PACK_STR = '!BBHI'
80 OFP_HEADER_SIZE = 8
81 OFP_MSG_SIZE_MAX = 65535
82 assert calcsize(OFP_HEADER_PACK_STR) == OFP_HEADER_SIZE
83
84 # define constants
85 OFP_DEFAULT_MISS_SEND_LEN = 128
86
87 # enum ofp_config_flags
88 OFPC_FRAG_NORMAL = 0    # No special handling for fragments.
89 OFPC_FRAG_DROP = 1      # Drop fragments.
90 OFPC_FRAG_REASM = 2     # Reassemble (only if OFPC_IP_REASM set).
91 OFPC_FRAG_NX_MATCH = 3  # Make first fragments available for matching.
92 OFPC_FRAG_MASK = 3
93
94 OFP_SWITCH_CONFIG_PACK_STR = '!HH'
95 OFP_SWITCH_CONFIG_SIZE = 12
96 assert (calcsize(OFP_SWITCH_CONFIG_PACK_STR) + OFP_HEADER_SIZE ==
97         OFP_SWITCH_CONFIG_SIZE)
98
99 # enum ofp_capabilities
100 OFPC_FLOW_STATS = 1 << 0        # Flow statistics.
101 OFPC_TABLE_STATS = 1 << 1       # Table statistics.
102 OFPC_PORT_STATS = 1 << 2        # Port statistics.
103 OFPC_STP = 1 << 3               # 802.1d spanning tree.
104 OFPC_RESERVED = 1 << 4          # Reserved, must not be set.
105 OFPC_IP_REASM = 1 << 5          # Can reassemble IP fragments.
106 OFPC_QUEUE_STATS = 1 << 6       # Queue statistics.
107 OFPC_ARP_MATCH_IP = 1 << 7      # Match IP addresses in ARP pkts.
108
109 # enum ofp_port_config
110 OFPPC_PORT_DOWN = 1 << 0        # Port is administratively down.
111 OFPPC_NO_STP = 1 << 1           # Disable 802.1D spanning tree on port.
112 OFPPC_NO_RECV = 1 << 2          # Drop all packets except 802.1D
113                                 # spanning tree packets
114 OFPPC_NO_RECV_STP = 1 << 3      # Drop received 802.1D STP packets.
115 OFPPC_NO_FLOOD = 1 << 4         # Do not include this port when flooding.
116 OFPPC_NO_FWD = 1 << 5           # Drop packets forwarded to port.
117 OFPPC_NO_PACKET_IN = 1 << 6     # Do not send packet-in msgs for port.
118
119 # enum ofp_port_state
120 OFPPS_LINK_DOWN = 1 << 0        # No physical link present.
121 OFPPS_STP_LISTEN = 0 << 8       # Not learning or relaying frames.
122 OFPPS_STP_LEARN = 1 << 8        # Learning but not relaying frames.
123 OFPPS_STP_FORWARD = 2 << 8      # Learning and relaying frames.
124 OFPPS_STP_BLOCK = 3 << 8        # Not part of spanning tree.
125 OFPPS_STP_MASK = 3 << 8         # Bit mask for OFPPS_STP_* values.
126
127 # enum ofp_port_features
128 OFPPF_10MB_HD = 1 << 0          # 10 Mb half-duplex rate support.
129 OFPPF_10MB_FD = 1 << 1          # 10 Mb full-duplex rate support.
130 OFPPF_100MB_HD = 1 << 2         # 100 Mb half-duplex rate support.
131 OFPPF_100MB_FD = 1 << 3         # 100 Mb full-duplex rate support.
132 OFPPF_1GB_HD = 1 << 4           # 1 Gb half-duplex rate support.
133 OFPPF_1GB_FD = 1 << 5           # 1 Gb full-duplex rate support.
134 OFPPF_10GB_FD = 1 << 6          # 10 Gb full-duplex rate support.
135 OFPPF_COPPER = 1 << 7           # Copper medium.
136 OFPPF_FIBER = 1 << 8            # Fiber medium.
137 OFPPF_AUTONEG = 1 << 9          # Auto-negotiation.
138 OFPPF_PAUSE = 1 << 10           # Pause.
139 OFPPF_PAUSE_ASYM = 1 << 11      # Asymmetric pause.
140
141 _OFP_PHY_PORT_PACK_STR = 'H' + OFP_ETH_ALEN_STR + 's' + \
142                          str(OFP_MAX_PORT_NAME_LEN) + 'sIIIIII'
143 OFP_PHY_PORT_PACK_STR = '!' + _OFP_PHY_PORT_PACK_STR
144 OFP_PHY_PORT_SIZE = 48
145 assert calcsize(OFP_PHY_PORT_PACK_STR) == OFP_PHY_PORT_SIZE
146
147 OFP_SWITCH_FEATURES_PACK_STR = '!QIB3xII'
148 OFP_SWITCH_FEATURES_SIZE = 32
149 assert (calcsize(OFP_SWITCH_FEATURES_PACK_STR) + OFP_HEADER_SIZE ==
150         OFP_SWITCH_FEATURES_SIZE)
151
152 # enum ofp_port_reason
153 OFPPR_ADD = 0           # The port was added.
154 OFPPR_DELETE = 1        # The port was removed.
155 OFPPR_MODIFY = 2        # Some attribute of the port has changed.
156
157 OFP_PORT_STATUS_PACK_STR = '!B7x' + _OFP_PHY_PORT_PACK_STR
158 OFP_PORT_STATUS_DESC_OFFSET = OFP_HEADER_SIZE + 8
159 OFP_PORT_STATUS_SIZE = 64
160 assert (calcsize(OFP_PORT_STATUS_PACK_STR) + OFP_HEADER_SIZE ==
161         OFP_PORT_STATUS_SIZE)
162
163 OFP_PORT_MOD_PACK_STR = '!H' + OFP_ETH_ALEN_STR + 'sIII4x'
164 OFP_PORT_MOD_SIZE = 32
165 assert calcsize(OFP_PORT_MOD_PACK_STR) + OFP_HEADER_SIZE == OFP_PORT_MOD_SIZE
166
167 # enum ofp_packet_in_reason
168 OFPR_NO_MATCH = 0       # No matching flow.
169 OFPR_ACTION = 1         # Action explicitly output to controller.
170
171 # OF1.0 spec says OFP_ASSERT(sizeof(struct ofp_packet_in) == 20).
172 # It's quite bogus as it assumes a specific class of C implementations.
173 # (well, if it was C.  it's unclear from the spec itself.)
174 # We just use the real size of the structure as this is not C.  This
175 # agrees with on-wire messages OpenFlow Reference Release and Open vSwitch
176 # produce.
177 OFP_PACKET_IN_PACK_STR = '!IHHBx'
178 OFP_PACKET_IN_SIZE = 18
179 assert calcsize(OFP_PACKET_IN_PACK_STR) + OFP_HEADER_SIZE == OFP_PACKET_IN_SIZE
180
181 # enum ofp_action_type
182 OFPAT_OUTPUT = 0        # Output to switch port.
183 OFPAT_SET_VLAN_VID = 1  # Set the 802.1q VLAN id.
184 OFPAT_SET_VLAN_PCP = 2  # Set the 802.1q priority.
185 OFPAT_STRIP_VLAN = 3    # Strip the 802.1q header.
186 OFPAT_SET_DL_SRC = 4    # Ethernet source address.
187 OFPAT_SET_DL_DST = 5    # Ethernet destination address.
188 OFPAT_SET_NW_SRC = 6    # IP source address.
189 OFPAT_SET_NW_DST = 7    # IP destination address.
190 OFPAT_SET_NW_TOS = 8    # IP ToS (DSCP field, 6 bits).
191 OFPAT_SET_TP_SRC = 9    # TCP/UDP source port.
192 OFPAT_SET_TP_DST = 10   # TCP/UDP destination port.
193 OFPAT_ENQUEUE = 11      # Output to queue.
194 OFPAT_VENDOR = 0xffff
195
196 OFP_ACTION_OUTPUT_PACK_STR = '!HHHH'
197 OFP_ACTION_OUTPUT_SIZE = 8
198 assert calcsize(OFP_ACTION_OUTPUT_PACK_STR) == OFP_ACTION_OUTPUT_SIZE
199
200 OFP_ACTION_VLAN_VID_PACK_STR = '!HHH2x'
201 OFP_ACTION_VLAN_VID_SIZE = 8
202 assert calcsize(OFP_ACTION_VLAN_VID_PACK_STR) == OFP_ACTION_VLAN_VID_SIZE
203
204 OFP_ACTION_VLAN_PCP_PACK_STR = '!HHB3x'
205 OFP_ACTION_VLAN_PCP_SIZE = 8
206 assert calcsize(OFP_ACTION_VLAN_PCP_PACK_STR) == OFP_ACTION_VLAN_PCP_SIZE
207
208 OFP_ACTION_DL_ADDR_PACK_STR = '!HH' + OFP_ETH_ALEN_STR + 's6x'
209 OFP_ACTION_DL_ADDR_SIZE = 16
210 assert calcsize(OFP_ACTION_DL_ADDR_PACK_STR) == OFP_ACTION_DL_ADDR_SIZE
211
212 OFP_ACTION_NW_ADDR_PACK_STR = '!HHI'
213 OFP_ACTION_NW_ADDR_SIZE = 8
214 assert calcsize(OFP_ACTION_NW_ADDR_PACK_STR) == OFP_ACTION_NW_ADDR_SIZE
215
216 OFP_ACTION_NW_TOS_PACK_STR = '!HHB3x'
217 OFP_ACTION_NW_TOS_SIZE = 8
218 assert calcsize(OFP_ACTION_NW_TOS_PACK_STR) == OFP_ACTION_NW_TOS_SIZE
219
220 OFP_ACTION_TP_PORT_PACK_STR = '!HHH2x'
221 OFP_ACTION_TP_PORT_SIZE = 8
222 assert calcsize(OFP_ACTION_TP_PORT_PACK_STR) == OFP_ACTION_TP_PORT_SIZE
223
224 OFP_ACTION_VENDOR_HEADER_PACK_STR = '!HHI'
225 OFP_ACTION_VENDOR_HEADER_SIZE = 8
226 assert (calcsize(OFP_ACTION_VENDOR_HEADER_PACK_STR) ==
227         OFP_ACTION_VENDOR_HEADER_SIZE)
228 # OpenFlow1.2 or later compatible
229 OFP_ACTION_EXPERIMENTER_HEADER_SIZE = OFP_ACTION_VENDOR_HEADER_SIZE
230
231 OFP_ACTION_HEADER_PACK_STR = '!HH4x'
232 OFP_ACTION_HEADER_SIZE = 8
233 assert calcsize(OFP_ACTION_HEADER_PACK_STR) == OFP_ACTION_HEADER_SIZE
234
235 OFP_ACTION_ENQUEUE_PACK_STR = '!HHH6xI'
236 OFP_ACTION_ENQUEUE_SIZE = 16
237 assert calcsize(OFP_ACTION_ENQUEUE_PACK_STR) == OFP_ACTION_ENQUEUE_SIZE
238
239 OFP_ACTION_PACK_STR = '!H'
240 # because of union ofp_action
241 # OFP_ACTION_SIZE = 8
242 # assert calcsize(OFP_ACTION_PACK_STR) == OFP_ACTION_SIZE
243
244 OFP_PACKET_OUT_PACK_STR = '!IHH'
245 OFP_PACKET_OUT_SIZE = 16
246 assert (calcsize(OFP_PACKET_OUT_PACK_STR) + OFP_HEADER_SIZE ==
247         OFP_PACKET_OUT_SIZE)
248
249 # enum ofp_flow_mod_command
250 OFPFC_ADD = 0               # New flow.
251 OFPFC_MODIFY = 1            # Modify all matching flows.
252 OFPFC_MODIFY_STRICT = 2     # Modify entry strictly matching wildcards
253 OFPFC_DELETE = 3            # Delete all matching flows.
254 OFPFC_DELETE_STRICT = 4     # Strictly match wildcards and priority.
255
256 # enum ofp_flow_wildcards
257 OFPFW_IN_PORT = 1 << 0      # Switch input port.
258 OFPFW_DL_VLAN = 1 << 1      # VLAN vid.
259 OFPFW_DL_SRC = 1 << 2       # Ethernet source address.
260 OFPFW_DL_DST = 1 << 3       # Ethernet destination address.
261 OFPFW_DL_TYPE = 1 << 4      # Ethernet frame type.
262 OFPFW_NW_PROTO = 1 << 5     # IP protocol.
263 OFPFW_TP_SRC = 1 << 6       # TCP/UDP source port.
264 OFPFW_TP_DST = 1 << 7       # TCP/UDP destination port.
265 OFPFW_NW_SRC_SHIFT = 8
266 OFPFW_NW_SRC_BITS = 6
267 OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT
268 OFPFW_NW_SRC = OFPFW_NW_SRC_MASK  # IP source address (not in OF Spec).
269 OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT
270 OFPFW_NW_DST_SHIFT = 14
271 OFPFW_NW_DST_BITS = 6
272 OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT
273 OFPFW_NW_DST = OFPFW_NW_DST_MASK  # IP destination address (not in OF Spec).
274 OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT
275 OFPFW_DL_VLAN_PCP = 1 << 20     # VLAN priority.
276 OFPFW_NW_TOS = 1 << 21  # IP ToS (DSCP field, 6 bits).
277 OFPFW_ALL = ((1 << 22) - 1)
278
279 # define constants
280 OFPFW_ICMP_TYPE = OFPFW_TP_SRC
281 OFPFW_ICMP_CODE = OFPFW_TP_DST
282 OFP_DL_TYPE_ETH2_CUTOFF = 0x0600
283 OFP_DL_TYPE_NOT_ETH_TYPE = 0x05ff
284 OFP_VLAN_NONE = 0xffff
285
286 _OFP_MATCH_PACK_STR = 'IH' + OFP_ETH_ALEN_STR + 's' + OFP_ETH_ALEN_STR + \
287                       'sHBxHBB2xIIHH'
288 OFP_MATCH_PACK_STR = '!' + _OFP_MATCH_PACK_STR
289 OFP_MATCH_SIZE = 40
290 assert calcsize(OFP_MATCH_PACK_STR) == OFP_MATCH_SIZE
291
292 OFP_FLOW_PERMANENT = 0
293 OFP_DEFAULT_PRIORITY = 0x8000
294
295 # enum ofp_flow_mod_flags
296 OFPFF_SEND_FLOW_REM = 1 << 0    # Send flow removed message when flow
297                                 # expires or is deleted.
298 OFPFF_CHECK_OVERLAP = 1 << 1    # Check for overlapping entries first.
299 OFPFF_EMERG = 1 << 2            # Ramark this is for emergency.
300
301 _OFP_FLOW_MOD_PACK_STR0 = 'QHHHHIHH'
302 OFP_FLOW_MOD_PACK_STR = '!' + _OFP_MATCH_PACK_STR + _OFP_FLOW_MOD_PACK_STR0
303 OFP_FLOW_MOD_PACK_STR0 = '!' + _OFP_FLOW_MOD_PACK_STR0
304 OFP_FLOW_MOD_SIZE = 72
305 assert calcsize(OFP_FLOW_MOD_PACK_STR) + OFP_HEADER_SIZE == OFP_FLOW_MOD_SIZE
306
307 # enum ofp_flow_removed_reason
308 OFPRR_IDLE_TIMEOUT = 0  # Flow idle time exceeded idle_timeout.
309 OFPRR_HARD_TIMEOUT = 1  # Time exceeded hard_timeout.
310 OFPRR_DELETE = 2        # Evicted by a DELETE flow mod.
311
312 _OFP_FLOW_REMOVED_PACK_STR0 = 'QHBxIIH2xQQ'
313 OFP_FLOW_REMOVED_PACK_STR = '!' + _OFP_MATCH_PACK_STR + \
314                             _OFP_FLOW_REMOVED_PACK_STR0
315 OFP_FLOW_REMOVED_PACK_STR0 = '!' + _OFP_FLOW_REMOVED_PACK_STR0
316 OFP_FLOW_REMOVED_SIZE = 88
317 assert (calcsize(OFP_FLOW_REMOVED_PACK_STR) + OFP_HEADER_SIZE ==
318         OFP_FLOW_REMOVED_SIZE)
319
320
321 # enum ofp_error_type
322 OFPET_HELLO_FAILED = 0  # Hello protocol failed.
323 OFPET_BAD_REQUEST = 1   # Request was not understood.
324 OFPET_BAD_ACTION = 2    # Error in action description.
325 OFPET_FLOW_MOD_FAILED = 3       # Problem modifying flow entry.
326 OFPET_PORT_MOD_FAILED = 4       # OFPT_PORT_MOD failed.
327 OFPET_QUEUE_OP_FAILED = 5       # Queue operation failed.
328
329 # enum ofp_hello_failed_code
330 OFPHFC_INCOMPATIBLE = 0  # No compatible version.
331 OFPHFC_EPERM = 1         # Permissions error.
332
333 # enum ofp_bad_request_code
334 OFPBRC_BAD_VERSION = 0          # ofp_header.version not supported.
335 OFPBRC_BAD_TYPE = 1             # ofp_header.type not supported.
336 OFPBRC_BAD_STAT = 2             # ofp_stats_msg.type not supported.
337 OFPBRC_BAD_VENDOR = 3           # Vendor not supported (in ofp_vendor_header
338                                 # or ofp_stats_msg).
339 OFPBRC_BAD_SUBTYPE = 4          # Vendor subtype not supported.
340 OFPBRC_EPERM = 5                # Permissions error.
341 OFPBRC_BAD_LEN = 6              # Wrong request length for type.
342 OFPBRC_BUFFER_EMPTY = 7         # Specified buffer has already been used.
343 OFPBRC_BUFFER_UNKNOWN = 8       # Specified buffer does not exist.
344
345 # enum ofp_bad_action_code
346 OFPBAC_BAD_TYPE = 0         # Unknown action type.
347 OFPBAC_BAD_LEN = 1          # Length problem in actions.
348 OFPBAC_BAD_VENDOR = 2       # Unknown vendor id specified.
349 OFPBAC_BAD_VENDOR_TYPE = 3  # Unknown action type for vendor id.
350 OFPBAC_BAD_OUT_PORT = 4     # Problem validating output action.
351 OFPBAC_BAD_ARGUMENT = 5     # Bad action argument.
352 OFPBAC_EPERM = 6            # Permissions error.
353 OFPBAC_TOO_MANY = 7         # Can't handle this many actions.
354 OFPBAC_BAD_QUEUE = 8        # Problem validating output queue.
355
356 # enum ofp_flow_mod_failed_code
357 OFPFMFC_ALL_TABLES_FULL = 0     # Flow not added because of full tables.
358 OFPFMFC_OVERLAP = 1             # Attempted to add overlapping flow with
359                                 # CHECK_OVERLAP flags set.
360 OFPFMFC_EPERM = 2               # Permissions error.
361 OFPFMFC_BAD_EMERG_TIMEOUT = 3   # Flow not added because of non-zero idle/hard
362                                 # timeout.
363 OFPFMFC_BAD_COMMAND = 4         # Unknown command.
364 OFPFMFC_UNSUPPORTED = 5         # Unsupported action list - cannot process in
365                                 # the order specified.
366
367 # enum ofp_port_mod_failed_code
368 OFPPMFC_BAD_PORT = 0        # Specified port does not exist.
369 OFPPMFC_BAD_HW_ADDR = 1     # Specified hardware address is wrong.
370
371 # enum ofp_queue_op_failed_code
372 OFPQOFC_BAD_PORT = 0    # Invalid port (or port does not exist).
373 OFPQOFC_BAD_QUEUE = 1   # Queue does not exist.
374 OFPQOFC_EPERM = 2       # Permissions error.
375
376 OFP_ERROR_MSG_PACK_STR = '!HH'
377 OFP_ERROR_MSG_SIZE = 12
378 assert calcsize(OFP_ERROR_MSG_PACK_STR) + OFP_HEADER_SIZE == OFP_ERROR_MSG_SIZE
379
380 # enum ofp_stats_types
381 OFPST_DESC = 0
382 OFPST_FLOW = 1
383 OFPST_AGGREGATE = 2
384 OFPST_TABLE = 3
385 OFPST_PORT = 4
386 OFPST_QUEUE = 5
387 OFPST_VENDOR = 0xffff
388
389 _OFP_STATS_MSG_PACK_STR = 'HH'
390 OFP_STATS_MSG_PACK_STR = '!' + _OFP_STATS_MSG_PACK_STR
391 OFP_STATS_MSG_SIZE = 12
392 assert calcsize(OFP_STATS_MSG_PACK_STR) + OFP_HEADER_SIZE == OFP_STATS_MSG_SIZE
393
394 # enum ofp_stats_reply_flags
395 OFPSF_REPLY_MORE = 1 << 0       # More replies to follow.
396
397 # define constants
398 DESC_STR_LEN = 256
399 DESC_STR_LEN_STR = str(DESC_STR_LEN)
400 SERIAL_NUM_LEN = 32
401 SERIAL_NUM_LEN_STR = str(SERIAL_NUM_LEN)
402
403 OFP_DESC_STATS_PACK_STR = '!' + \
404                           DESC_STR_LEN_STR + 's' + \
405                           DESC_STR_LEN_STR + 's' + \
406                           DESC_STR_LEN_STR + 's' + \
407                           SERIAL_NUM_LEN_STR + 's' + \
408                           DESC_STR_LEN_STR + 's'
409 OFP_DESC_STATS_SIZE = 1068
410 assert (calcsize(OFP_DESC_STATS_PACK_STR) + OFP_STATS_MSG_SIZE ==
411         OFP_DESC_STATS_SIZE)
412
413 _OFP_FLOW_STATS_REQUEST_ID_PORT_STR = 'BxH'
414 OFP_FLOW_STATS_REQUEST_ID_PORT_STR = '!' + _OFP_FLOW_STATS_REQUEST_ID_PORT_STR
415 OFP_FLOW_STATS_REQUEST_PACK_STR = '!' + _OFP_MATCH_PACK_STR + \
416                                   _OFP_FLOW_STATS_REQUEST_ID_PORT_STR
417 OFP_FLOW_STATS_REQUEST_SIZE = 56
418 assert (calcsize(OFP_FLOW_STATS_REQUEST_PACK_STR) + OFP_STATS_MSG_SIZE ==
419         OFP_FLOW_STATS_REQUEST_SIZE)
420
421 _OFP_FLOW_STATS_0_PACK_STR = 'HBx'
422 OFP_FLOW_STATS_0_PACK_STR = '!' + _OFP_FLOW_STATS_0_PACK_STR
423 OFP_FLOW_STATS_0_SIZE = 4
424 assert calcsize(OFP_FLOW_STATS_0_PACK_STR) == OFP_FLOW_STATS_0_SIZE
425 _OFP_FLOW_STATS_1_PACK_STR = 'IIHHH6xQQQ'
426 OFP_FLOW_STATS_1_PACK_STR = '!' + _OFP_FLOW_STATS_1_PACK_STR
427 OFP_FLOW_STATS_1_SIZE = 44
428 assert calcsize(OFP_FLOW_STATS_1_PACK_STR) == OFP_FLOW_STATS_1_SIZE
429 OFP_FLOW_STATS_PACK_STR = '!' + _OFP_FLOW_STATS_0_PACK_STR +\
430                           _OFP_MATCH_PACK_STR + _OFP_FLOW_STATS_1_PACK_STR
431 OFP_FLOW_STATS_SIZE = 88
432 assert calcsize(OFP_FLOW_STATS_PACK_STR) == OFP_FLOW_STATS_SIZE
433
434 OFP_AGGREGATE_STATS_REPLY_PACK_STR = '!QQI4x'
435 OFP_AGGREGATE_STATS_REPLY_SIZE = 36
436 assert (calcsize(OFP_AGGREGATE_STATS_REPLY_PACK_STR) +
437         OFP_STATS_MSG_SIZE == OFP_AGGREGATE_STATS_REPLY_SIZE)
438
439 OFP_TABLE_STATS_PACK_STR = '!B3x' + OFP_MAX_TABLE_NAME_LEN_STR + 'sIIIQQ'
440 OFP_TABLE_STATS_SIZE = 64
441 assert calcsize(OFP_TABLE_STATS_PACK_STR) == OFP_TABLE_STATS_SIZE
442
443 OFP_PORT_STATS_REQUEST_PACK_STR = '!H6x'
444 OFP_PORT_STATS_REQUEST_SIZE = 20
445 assert (calcsize(OFP_PORT_STATS_REQUEST_PACK_STR) + OFP_STATS_MSG_SIZE ==
446         OFP_PORT_STATS_REQUEST_SIZE)
447
448 OFP_PORT_STATS_PACK_STR = '!H6xQQQQQQQQQQQQ'
449 OFP_PORT_STATS_SIZE = 104
450 assert calcsize(OFP_PORT_STATS_PACK_STR) == OFP_PORT_STATS_SIZE
451
452 OFPQ_ALL = 0xffffffff
453
454 OFP_QUEUE_STATS_REQUEST_PACK_STR = '!HxxI'
455 OFP_QUEUE_STATS_REQUEST_SIZE = 8
456 assert (calcsize(OFP_QUEUE_STATS_REQUEST_PACK_STR) ==
457         OFP_QUEUE_STATS_REQUEST_SIZE)
458
459 OFP_QUEUE_STATS_PACK_STR = '!H2xIQQQ'
460 OFP_QUEUE_STATS_SIZE = 32
461 assert calcsize(OFP_QUEUE_STATS_PACK_STR) == OFP_QUEUE_STATS_SIZE
462
463 OFP_VENDOR_STATS_MSG_PACK_STR = '!I'
464 OFP_VENDOR_STATS_MSG_SIZE = 16
465 assert (calcsize(OFP_VENDOR_STATS_MSG_PACK_STR) + OFP_STATS_MSG_SIZE ==
466         OFP_VENDOR_STATS_MSG_SIZE)
467
468 OFP_VENDOR_HEADER_PACK_STR = '!I'
469 OFP_VENDOR_HEADER_SIZE = 12
470 assert (calcsize(OFP_VENDOR_HEADER_PACK_STR) + OFP_HEADER_SIZE ==
471         OFP_VENDOR_HEADER_SIZE)
472
473 OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR = '!H2x'
474 OFP_QUEUE_GET_CONFIG_REQUEST_SIZE = 12
475 assert (calcsize(OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR) + OFP_HEADER_SIZE ==
476         OFP_QUEUE_GET_CONFIG_REQUEST_SIZE)
477
478 OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR = '!H6x'
479 OFP_QUEUE_GET_CONFIG_REPLY_SIZE = 16
480 assert (calcsize(OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR) + OFP_HEADER_SIZE ==
481         OFP_QUEUE_GET_CONFIG_REPLY_SIZE)
482
483 OFP_PACKET_QUEUE_PQCK_STR = '!IH2x'
484 OFP_PACKET_QUEUE_SIZE = 8
485 assert calcsize(OFP_PACKET_QUEUE_PQCK_STR) == OFP_PACKET_QUEUE_SIZE
486
487 OFPQT_NONE = 0
488 OFPQT_MIN_RATE = 1
489
490 OFP_QUEUE_PROP_HEADER_PACK_STR = '!HH4x'
491 OFP_QUEUE_PROP_HEADER_SIZE = 8
492 assert calcsize(OFP_QUEUE_PROP_HEADER_PACK_STR) == OFP_QUEUE_PROP_HEADER_SIZE
493
494 OFP_QUEUE_PROP_MIN_RATE_PACK_STR = '!H6x'
495 OFP_QUEUE_PROP_MIN_RATE_SIZE = 16
496 assert (calcsize(OFP_QUEUE_PROP_MIN_RATE_PACK_STR) +
497         OFP_QUEUE_PROP_HEADER_SIZE == OFP_QUEUE_PROP_MIN_RATE_SIZE)
498
499 # OXM
500
501 # enum ofp_oxm_class
502 OFPXMC_OPENFLOW_BASIC = 0x8000  # Basic class for OpenFlow
503
504
505 def _oxm_tlv_header(class_, field, hasmask, length):
506     return (class_ << 16) | (field << 9) | (hasmask << 8) | length
507
508
509 def oxm_tlv_header(field, length):
510     return _oxm_tlv_header(OFPXMC_OPENFLOW_BASIC, field, 0, length)
511
512
513 def oxm_tlv_header_w(field, length):
514     return _oxm_tlv_header(OFPXMC_OPENFLOW_BASIC, field, 1, length * 2)
515
516
517 def oxm_tlv_header_extract_hasmask(header):
518     return (header >> 8) & 1
519
520
521 def oxm_tlv_header_extract_length(header):
522     if oxm_tlv_header_extract_hasmask(header):
523         length = (header & 0xff) // 2
524     else:
525         length = header & 0xff
526     return length
527
528
529 oxm_fields.generate(__name__)
530
531 # generate utility methods
532 ofproto_utils.generate(__name__)