1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2012 Isaku Yamahata <yamahata at valinux co jp>
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 OpenFlow 1.2 definitions.
21 from ryu.lib import type_desc
22 from ryu.ofproto import nicira_ext
23 from ryu.ofproto import ofproto_utils
24 from ryu.ofproto import oxm_fields
26 from struct import calcsize
29 OFP_HEADER_PACK_STR = '!BBHI'
31 assert calcsize(OFP_HEADER_PACK_STR) == OFP_HEADER_SIZE
34 OFPT_HELLO = 0 # Symmetric message
35 OFPT_ERROR = 1 # Symmetric message
36 OFPT_ECHO_REQUEST = 2 # Symmetric message
37 OFPT_ECHO_REPLY = 3 # Symmetric message
38 OFPT_EXPERIMENTER = 4 # Symmetric message
40 OFPT_FEATURES_REQUEST = 5 # Controller/switch message
41 OFPT_FEATURES_REPLY = 6 # Controller/switch message
42 OFPT_GET_CONFIG_REQUEST = 7 # Controller/switch message
43 OFPT_GET_CONFIG_REPLY = 8 # Controller/switch message
44 OFPT_SET_CONFIG = 9 # Controller/switch message
46 OFPT_PACKET_IN = 10 # Async message
47 OFPT_FLOW_REMOVED = 11 # Async message
48 OFPT_PORT_STATUS = 12 # Async message
50 OFPT_PACKET_OUT = 13 # Controller/switch message
51 OFPT_FLOW_MOD = 14 # Controller/switch message
52 OFPT_GROUP_MOD = 15 # Controller/switch message
53 OFPT_PORT_MOD = 16 # Controller/switch message
54 OFPT_TABLE_MOD = 17 # Controller/switch message
56 OFPT_STATS_REQUEST = 18 # Controller/switch message
57 OFPT_STATS_REPLY = 19 # Controller/switch message
59 OFPT_BARRIER_REQUEST = 20 # Controller/switch message
60 OFPT_BARRIER_REPLY = 21 # Controller/switch message
62 OFPT_QUEUE_GET_CONFIG_REQUEST = 22 # Controller/switch message
63 OFPT_QUEUE_GET_CONFIG_REPLY = 23 # Controller/switch message
65 OFPT_ROLE_REQUEST = 24 # Controller/switch message
66 OFPT_ROLE_REPLY = 25 # Controller/switch message
69 OFP_MAX_PORT_NAME_LEN = 16
71 OFP_ETH_ALEN_STR = str(OFP_ETH_ALEN)
72 _OFP_PORT_PACK_STR = 'I4x' + OFP_ETH_ALEN_STR + 's' + '2x' + \
73 str(OFP_MAX_PORT_NAME_LEN) + 's' + 'IIIIIIII'
74 OFP_PORT_PACK_STR = '!' + _OFP_PORT_PACK_STR
76 assert calcsize(OFP_PORT_PACK_STR) == OFP_PORT_SIZE
78 # enum ofp_port_config
79 OFPPC_PORT_DOWN = 1 << 0 # Port is administratively down.
80 OFPPC_NO_RECV = 1 << 2 # Drop all packets recieved by port.
81 OFPPC_NO_FWD = 1 << 5 # Drop packets forwarded to port.
82 OFPPC_NO_PACKET_IN = 1 << 6 # Do not send packet-in msgs for port.
85 OFPPS_LINK_DOWN = 1 << 0 # No physical link present.
86 OFPPS_BLOCKED = 1 << 1 # Port is blocked.
87 OFPPS_LIVE = 1 << 2 # Live for Fast Failover Group.
91 OFPP_IN_PORT = 0xfffffff8 # Send the packet out the input port. This
92 # virtual port must be explicitly used
93 # in order to send back out of the input
95 OFPP_TABLE = 0xfffffff9 # Perform actions in flow table.
96 # NB: This can only be the destination
97 # port for packet-out messages.
98 OFPP_NORMAL = 0xfffffffa # Process with normal L2/L3 switching.
99 OFPP_FLOOD = 0xfffffffb # All physical ports except input port and
100 # those disabled by STP.
101 OFPP_ALL = 0xfffffffc # All physical ports except input port.
102 OFPP_CONTROLLER = 0xfffffffd # Send to controller.
103 OFPP_LOCAL = 0xfffffffe # Local openflow "port".
104 OFPP_ANY = 0xffffffff # Not associated with a physical port.
106 # All ones is used to indicate all queues in a port (for stats retrieval).
107 OFPQ_ALL = 0xffffffff
109 # enum ofp_port_features
110 OFPPF_10MB_HD = 1 << 0 # 10 Mb half-duplex rate support.
111 OFPPF_10MB_FD = 1 << 1 # 10 Mb full-duplex rate support.
112 OFPPF_100MB_HD = 1 << 2 # 100 Mb half-duplex rate support.
113 OFPPF_100MB_FD = 1 << 3 # 100 Mb full-duplex rate support.
114 OFPPF_1GB_HD = 1 << 4 # 1 Gb half-duplex rate support.
115 OFPPF_1GB_FD = 1 << 5 # 1 Gb full-duplex rate support.
116 OFPPF_10GB_FD = 1 << 6 # 10 Gb full-duplex rate support.
117 OFPPF_40GB_FD = 1 << 7 # 40 Gb full-duplex rate support.
118 OFPPF_100GB_FD = 1 << 8 # 100 Gb full-duplex rate support.
119 OFPPF_1TB_FD = 1 << 9 # 1 Tb full-duplex rate support.
120 OFPPF_OTHER = 1 << 10 # Other rate, not in the list.
121 OFPPF_COPPER = 1 << 11 # Copper medium.
122 OFPPF_FIBER = 1 << 12 # Fiber medium.
123 OFPPF_AUTONEG = 1 << 13 # Auto-negotiation.
124 OFPPF_PAUSE = 1 << 14 # Pause.
125 OFPPF_PAUSE_ASYM = 1 << 15 # Asymmetric pause.
127 # struct ofp_packet_queue
128 OFP_PACKET_QUEUE_PACK_STR = '!IIH6x'
129 OFP_PACKET_QUEUE_SIZE = 16
130 assert calcsize(OFP_PACKET_QUEUE_PACK_STR) == OFP_PACKET_QUEUE_SIZE
132 # enum ofp_queue_properties
133 OFPQT_MIN_RATE = 1 # Minimum datarate guaranteed.
134 OFPQT_MAX_RATE = 2 # Maximum datarate.
135 OFPQT_EXPERIMENTER = 0xffff # Experimenter defined property.
137 # struct ofp_queue_prop_header
138 OFP_QUEUE_PROP_HEADER_PACK_STR = '!HH4x'
139 OFP_QUEUE_PROP_HEADER_SIZE = 8
140 assert calcsize(OFP_QUEUE_PROP_HEADER_PACK_STR) == OFP_QUEUE_PROP_HEADER_SIZE
142 # struct ofp_queue_prop_min_rate
143 OFP_QUEUE_PROP_MIN_RATE_PACK_STR = '!H6x'
144 OFP_QUEUE_PROP_MIN_RATE_SIZE = 16
145 assert (calcsize(OFP_QUEUE_PROP_MIN_RATE_PACK_STR) +
146 OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_MIN_RATE_SIZE
148 # struct ofp_queue_prop_max_rate
149 OFP_QUEUE_PROP_MAX_RATE_PACK_STR = '!H6x'
150 OFP_QUEUE_PROP_MAX_RATE_SIZE = 16
151 assert (calcsize(OFP_QUEUE_PROP_MAX_RATE_PACK_STR) +
152 OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_MAX_RATE_SIZE
154 # struct ofp_queue_prop_experimenter
155 OFP_QUEUE_PROP_EXPERIMENTER_PACK_STR = '!I4x'
156 OFP_QUEUE_PROP_EXPERIMENTER_SIZE = 16
157 assert (calcsize(OFP_QUEUE_PROP_EXPERIMENTER_PACK_STR) +
158 OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_EXPERIMENTER_SIZE
161 _OFP_MATCH_PACK_STR = 'HHBBBB'
162 OFP_MATCH_PACK_STR = '!' + _OFP_MATCH_PACK_STR
164 assert calcsize(OFP_MATCH_PACK_STR) == OFP_MATCH_SIZE
166 # enum ofp_match_type
167 OFPMT_STANDARD = 0 # Deprecated
168 OFPMT_OXM = 1 # OpenFlow Extensible Match
171 OFPXMC_NXM_0 = 0x0000 # Backward compatibility with NXM
172 OFPXMC_NXM_1 = 0x0001 # Backward compatibility with NXM
173 OFPXMC_OPENFLOW_BASIC = 0x8000 # Basic class for OpenFlow
174 OFPXMC_EXPERIMENTER = 0xFFFF # Experimenter class
177 OFPVID_PRESENT = 0x1000 # bit that indicate that a VLAN id is set.
178 OFPVID_NONE = 0x0000 # No VLAN id was set.
180 # struct ofp_oxm_experimenter_header
181 OFP_OXM_EXPERIMENTER_HEADER_PACK_STR = '!II'
182 OFP_OXM_EXPERIMENTER_HEADER_SIZE = 8
183 assert (calcsize(OFP_OXM_EXPERIMENTER_HEADER_PACK_STR) ==
184 OFP_OXM_EXPERIMENTER_HEADER_SIZE)
186 # enum ofp_instruction_type
187 OFPIT_GOTO_TABLE = 1 # Setup the next table in the lookup pipeline.
188 OFPIT_WRITE_METADATA = 2 # Setup the metadata field for use later in
190 OFPIT_WRITE_ACTIONS = 3 # Write the action(s) onto the datapath
192 OFPIT_APPLY_ACTIONS = 4 # Applies the action(s) immediately
193 OFPIT_CLEAR_ACTIONS = 5 # Clears all actions from the datapath action
195 OFPIT_EXPERIMENTER = 0xFFFF # Experimenter instruction
197 # struct ofp_instruction_goto_table
198 OFP_INSTRUCTION_GOTO_TABLE_PACK_STR = '!HHB3x'
199 OFP_INSTRUCTION_GOTO_TABLE_SIZE = 8
200 assert (calcsize(OFP_INSTRUCTION_GOTO_TABLE_PACK_STR) ==
201 OFP_INSTRUCTION_GOTO_TABLE_SIZE)
203 # struct ofp_instruction_write_metadata
204 OFP_INSTRUCTION_WRITE_METADATA_PACK_STR = '!HH4xQQ'
205 OFP_INSTRUCTION_WRITE_METADATA_SIZE = 24
206 assert (calcsize(OFP_INSTRUCTION_WRITE_METADATA_PACK_STR) ==
207 OFP_INSTRUCTION_WRITE_METADATA_SIZE)
209 # struct ofp_instaruction_actions
210 OFP_INSTRUCTION_ACTIONS_PACK_STR = '!HH4x'
211 OFP_INSTRUCTION_ACTIONS_SIZE = 8
212 assert (calcsize(OFP_INSTRUCTION_ACTIONS_PACK_STR) ==
213 OFP_INSTRUCTION_ACTIONS_SIZE)
215 # enum ofp_action_type
216 OFPAT_OUTPUT = 0 # Output to switch port.
217 OFPAT_COPY_TTL_OUT = 11 # Copy TTL "outwards" -- from
218 # next-to-outermost to outermost
219 OFPAT_COPY_TTL_IN = 12 # Copy TTL "inwards" -- from outermost to
221 OFPAT_SET_MPLS_TTL = 15 # MPLS TTL.
222 OFPAT_DEC_MPLS_TTL = 16 # Decrement MPLS TTL
223 OFPAT_PUSH_VLAN = 17 # Push a new VLAN tag
224 OFPAT_POP_VLAN = 18 # Pop the outer VLAN tag
225 OFPAT_PUSH_MPLS = 19 # Push a new MPLS tag
226 OFPAT_POP_MPLS = 20 # Pop the outer MPLS tag
227 OFPAT_SET_QUEUE = 21 # Set queue id when outputting to a port
228 OFPAT_GROUP = 22 # Apply group
229 OFPAT_SET_NW_TTL = 23 # IP TTL.
230 OFPAT_DEC_NW_TTL = 24 # Decrement IP TTL.
231 OFPAT_SET_FIELD = 25 # Set a header field using OXM TLV format.
232 OFPAT_EXPERIMENTER = 0xffff
234 # struct ofp_action_header
235 OFP_ACTION_HEADER_PACK_STR = '!HH4x'
236 OFP_ACTION_HEADER_SIZE = 8
237 assert calcsize(OFP_ACTION_HEADER_PACK_STR) == OFP_ACTION_HEADER_SIZE
239 # struct ofp_action_output
240 OFP_ACTION_OUTPUT_PACK_STR = '!HHIH6x'
241 OFP_ACTION_OUTPUT_SIZE = 16
242 assert calcsize(OFP_ACTION_OUTPUT_PACK_STR) == OFP_ACTION_OUTPUT_SIZE
244 # enum ofp_controller_max_len
245 OFPCML_MAX = 0xffe5 # maximum max_len value which can be used to
246 # request a specific byte length.
247 OFPCML_NO_BUFFER = 0xffff # indicates that no buffering should be
248 # applied and the whole packet is to be
249 # sent to the controller.
251 # struct ofp_action_group
252 OFP_ACTION_GROUP_PACK_STR = '!HHI'
253 OFP_ACTION_GROUP_SIZE = 8
254 assert calcsize(OFP_ACTION_GROUP_PACK_STR) == OFP_ACTION_GROUP_SIZE
256 # struct ofp_action_set_queue
257 OFP_ACTION_SET_QUEUE_PACK_STR = '!HHI'
258 OFP_ACTION_SET_QUEUE_SIZE = 8
259 assert calcsize(OFP_ACTION_SET_QUEUE_PACK_STR) == OFP_ACTION_SET_QUEUE_SIZE
261 # struct ofp_aciton_mpls_ttl
262 OFP_ACTION_MPLS_TTL_PACK_STR = '!HHB3x'
263 OFP_ACTION_MPLS_TTL_SIZE = 8
264 assert calcsize(OFP_ACTION_MPLS_TTL_PACK_STR) == OFP_ACTION_MPLS_TTL_SIZE
266 # struct ofp_action_nw_ttl
267 OFP_ACTION_NW_TTL_PACK_STR = '!HHB3x'
268 OFP_ACTION_NW_TTL_SIZE = 8
269 assert calcsize(OFP_ACTION_NW_TTL_PACK_STR) == OFP_ACTION_NW_TTL_SIZE
271 # struct ofp_action_push
272 OFP_ACTION_PUSH_PACK_STR = '!HHH2x'
273 OFP_ACTION_PUSH_SIZE = 8
274 assert calcsize(OFP_ACTION_PUSH_PACK_STR) == OFP_ACTION_PUSH_SIZE
276 # struct ofp_action_pop_mpls
277 OFP_ACTION_POP_MPLS_PACK_STR = '!HHH2x'
278 OFP_ACTION_POP_MPLS_SIZE = 8
279 assert calcsize(OFP_ACTION_POP_MPLS_PACK_STR) == OFP_ACTION_POP_MPLS_SIZE
281 # struct ofp_action_set_field
282 OFP_ACTION_SET_FIELD_PACK_STR = '!HH4B'
283 OFP_ACTION_SET_FIELD_SIZE = 8
284 assert calcsize(OFP_ACTION_SET_FIELD_PACK_STR) == OFP_ACTION_SET_FIELD_SIZE
286 # struct ofp_action_experimenter_header
287 OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR = '!HHI'
288 OFP_ACTION_EXPERIMENTER_HEADER_SIZE = 8
289 assert (calcsize(OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR) ==
290 OFP_ACTION_EXPERIMENTER_HEADER_SIZE)
292 # struct ofp_switch_feature
293 OFP_SWITCH_FEATURES_PACK_STR = '!QIB3xII'
294 OFP_SWITCH_FEATURES_SIZE = 32
295 assert (calcsize(OFP_SWITCH_FEATURES_PACK_STR) + OFP_HEADER_SIZE ==
296 OFP_SWITCH_FEATURES_SIZE)
298 # enum ofp_capabilities
299 OFPC_FLOW_STATS = 1 << 0 # Flow statistics.
300 OFPC_TABLE_STATS = 1 << 1 # Table statistics.
301 OFPC_PORT_STATS = 1 << 2 # Port statistics.
302 OFPC_GROUP_STATS = 1 << 3 # Group statistics.
303 OFPC_IP_REASM = 1 << 5 # Can reassemble IP fragments.
304 OFPC_QUEUE_STATS = 1 << 6 # Queue statistics.
305 OFPC_PORT_BLOCKED = 1 << 8 # Switch will block looping ports.
307 # struct ofp_switch_config
308 OFP_SWITCH_CONFIG_PACK_STR = '!HH'
309 OFP_SWITCH_CONFIG_SIZE = 12
310 assert (calcsize(OFP_SWITCH_CONFIG_PACK_STR) + OFP_HEADER_SIZE ==
311 OFP_SWITCH_CONFIG_SIZE)
313 # enum ofp_config_flags
314 OFPC_FRAG_NORMAL = 0 # No special handling for fragments.
315 OFPC_FRAG_DROP = 1 # Drop fragments.
316 OFPC_FRAG_REASM = 2 # Reassemble (only if OFPC_IP_REASM set).
318 OFPC_INVALID_TTL_TO_CONTROLLER = 1 << 2 # Send packets with invalid
319 # TTL to the controller.
325 # struct ofp_table_mod
326 OFP_TABLE_MOD_PACK_STR = '!B3xI'
327 OFP_TABLE_MOD_SIZE = 16
328 assert (calcsize(OFP_TABLE_MOD_PACK_STR) + OFP_HEADER_SIZE ==
331 # enum ofp_table_config
332 OFPTC_TABLE_MISS_CONTROLLER = 0
333 OFPTC_TABLE_MISS_CONTINUE = 1 << 0
334 OFPTC_TABLE_MISS_DROP = 1 << 1
335 OFPTC_TABLE_MISS_MASK = 3
337 # struct ofp_flow_mod
338 _OFP_FLOW_MOD_PACK_STR0 = 'QQBBHHHIIIH2x'
339 OFP_FLOW_MOD_PACK_STR = '!' + _OFP_FLOW_MOD_PACK_STR0 + _OFP_MATCH_PACK_STR
340 OFP_FLOW_MOD_PACK_STR0 = '!' + _OFP_FLOW_MOD_PACK_STR0
341 OFP_FLOW_MOD_SIZE = 56
342 assert (calcsize(OFP_FLOW_MOD_PACK_STR) + OFP_HEADER_SIZE == OFP_FLOW_MOD_SIZE)
344 # enum ofp_flow_mod_command
345 OFPFC_ADD = 0 # New flow.
346 OFPFC_MODIFY = 1 # Modify all matching flows.
347 OFPFC_MODIFY_STRICT = 2 # Modify entry strictly matching wildcards
348 OFPFC_DELETE = 3 # Delete all matching flows.
349 OFPFC_DELETE_STRICT = 4 # Strictly match wildcards and priority.
351 # enum ofp_flow_mod_flags
352 OFPFF_SEND_FLOW_REM = 1 << 0 # Send flow removed message when flow
353 # expires or is deleted.
354 OFPFF_CHECK_OVERLAP = 1 << 1 # Check for overlapping entries first.
355 OFPFF_RESET_COUNTS = 1 << 2 # Reset flow packet and byte counts.
357 # struct ofp_group_mod
358 OFP_GROUP_MOD_PACK_STR = '!HBxI'
359 OFP_GROUP_MOD_SIZE = 16
360 assert (calcsize(OFP_GROUP_MOD_PACK_STR) + OFP_HEADER_SIZE ==
364 OFPG_MAX = 0xffffff00
365 OFPG_ALL = 0xfffffffc
366 OFPG_ANY = 0xffffffff
368 # enum ofp_group_mod_command
369 OFPGC_ADD = 0 # New group.
370 OFPGC_MODIFY = 1 # Modify all matching groups.
371 OFPGC_DELETE = 2 # Deletes all matching groups.
373 # enum ofp_group_type
374 OFPGT_ALL = 0 # All (multicast/broadcast) group.
375 OFPGT_SELECT = 1 # Select group.
376 OFPGT_INDIRECT = 2 # Indirect group.
377 OFPGT_FF = 3 # Fast failover group.
380 OFP_BUCKET_PACK_STR = '!HHII4x'
382 assert calcsize(OFP_BUCKET_PACK_STR) == OFP_BUCKET_SIZE
384 # struct ofp_port_mod
385 OFP_PORT_MOD_PACK_STR = '!I4x' + OFP_ETH_ALEN_STR + 's' + '2xIII4x'
386 OFP_PORT_MOD_SIZE = 40
387 assert calcsize(OFP_PORT_MOD_PACK_STR) + OFP_HEADER_SIZE == OFP_PORT_MOD_SIZE
389 # sturct ofp_stats_request
390 OFP_STATS_REQUEST_PACK_STR = '!HH4x'
391 OFP_STATS_REQUEST_SIZE = 16
392 assert (calcsize(OFP_STATS_REQUEST_PACK_STR) + OFP_HEADER_SIZE ==
393 OFP_STATS_REQUEST_SIZE)
395 # enum ofp_stats_reply_flags
396 OFPSF_REPLY_MORE = 1 << 0 # More replies to follow.
398 # struct ofp_stats_reply
399 OFP_STATS_REPLY_PACK_STR = '!HH4x'
400 OFP_STATS_REPLY_SIZE = 16
401 assert (calcsize(OFP_STATS_REPLY_PACK_STR) + OFP_HEADER_SIZE ==
402 OFP_STATS_REPLY_SIZE)
404 # enum ofp_stats_types
413 OFPST_GROUP_FEATURES = 8
414 OFPST_EXPERIMENTER = 0xffff
416 # struct ofp_desc_stats
418 DESC_STR_LEN_STR = str(DESC_STR_LEN)
420 SERIAL_NUM_LEN_STR = str(SERIAL_NUM_LEN)
421 OFP_DESC_STATS_PACK_STR = '!' + \
422 DESC_STR_LEN_STR + 's' + \
423 DESC_STR_LEN_STR + 's' + \
424 DESC_STR_LEN_STR + 's' + \
425 SERIAL_NUM_LEN_STR + 's' + \
426 DESC_STR_LEN_STR + 's'
427 OFP_DESC_STATS_SIZE = 1056
428 assert calcsize(OFP_DESC_STATS_PACK_STR) == OFP_DESC_STATS_SIZE
430 # struct ofp_flow_stats_request
431 OFP_FLOW_STATS_REQUEST_PACK_STR = '!B3xII4xQQ'
432 OFP_FLOW_STATS_REQUEST_SIZE = 40
433 assert (calcsize(OFP_FLOW_STATS_REQUEST_PACK_STR) + OFP_MATCH_SIZE ==
434 OFP_FLOW_STATS_REQUEST_SIZE)
436 # struct ofp_flow_stats
437 OFP_FLOW_STATS_PACK_STR = '!HBxIIHHH6xQQQ'
438 OFP_FLOW_STATS_SIZE = 56
439 assert (calcsize(OFP_FLOW_STATS_PACK_STR) + OFP_MATCH_SIZE ==
442 # struct ofp_aggregate_stats_request
443 OFP_AGGREGATE_STATS_REQUEST_PACK_STR = '!B3xII4xQQ'
444 OFP_AGGREGATE_STATS_REQUEST_SIZE = 40
445 assert (calcsize(OFP_AGGREGATE_STATS_REQUEST_PACK_STR) + OFP_MATCH_SIZE ==
446 OFP_AGGREGATE_STATS_REQUEST_SIZE)
448 # struct ofp_aggregate_stats_reply
449 OFP_AGGREGATE_STATS_REPLY_PACK_STR = '!QQI4x'
450 OFP_AGGREGATE_STATS_REPLY_SIZE = 24
451 assert (calcsize(OFP_AGGREGATE_STATS_REPLY_PACK_STR) ==
452 OFP_AGGREGATE_STATS_REPLY_SIZE)
454 # sturct ofp_table_stats
455 OFP_TABLE_STATS_SIZE = 128
456 OFP_MAX_TABLE_NAME_LEN = 32
457 OFP_MAX_TABLE_NAME_LEN_STR = str(OFP_MAX_TABLE_NAME_LEN)
458 OFP_TABLE_STATS_PACK_STR = '!B7x' + OFP_MAX_TABLE_NAME_LEN_STR + \
460 assert calcsize(OFP_TABLE_STATS_PACK_STR) == OFP_TABLE_STATS_SIZE
462 # struct ofp_port_stats_request
463 OFP_PORT_STATS_REQUEST_PACK_STR = '!I4x'
464 OFP_PORT_STATS_REQUEST_SIZE = 8
465 assert calcsize(OFP_PORT_STATS_REQUEST_PACK_STR) == OFP_PORT_STATS_REQUEST_SIZE
467 # struct ofp_port_stats
468 OFP_PORT_STATS_PACK_STR = '!I4xQQQQQQQQQQQQ'
469 OFP_PORT_STATS_SIZE = 104
470 assert calcsize(OFP_PORT_STATS_PACK_STR) == OFP_PORT_STATS_SIZE
472 # struct ofp_queue_stats_request
473 OFP_QUEUE_STATS_REQUEST_PACK_STR = '!II'
474 OFP_QUEUE_STATS_REQUEST_SIZE = 8
475 assert (calcsize(OFP_QUEUE_STATS_REQUEST_PACK_STR) ==
476 OFP_QUEUE_STATS_REQUEST_SIZE)
478 # struct ofp_queue_stats
479 OFP_QUEUE_STATS_PACK_STR = '!IIQQQ'
480 OFP_QUEUE_STATS_SIZE = 32
481 assert calcsize(OFP_QUEUE_STATS_PACK_STR) == OFP_QUEUE_STATS_SIZE
483 # struct ofp_group_stats_request
484 OFP_GROUP_STATS_REQUEST_PACK_STR = '!I4x'
485 OFP_GROUP_STATS_REQUEST_SIZE = 8
486 assert (calcsize(OFP_GROUP_STATS_REQUEST_PACK_STR) ==
487 OFP_GROUP_STATS_REQUEST_SIZE)
489 # struct ofp_group_stats
490 OFP_GROUP_STATS_PACK_STR = '!H2xII4xQQ'
491 OFP_GROUP_STATS_SIZE = 32
492 assert calcsize(OFP_GROUP_STATS_PACK_STR) == OFP_GROUP_STATS_SIZE
494 # struct ofp_bucket_counter
495 OFP_BUCKET_COUNTER_PACK_STR = '!QQ'
496 OFP_BUCKET_COUNTER_SIZE = 16
497 assert calcsize(OFP_BUCKET_COUNTER_PACK_STR) == OFP_BUCKET_COUNTER_SIZE
499 # struct ofp_group_desc_stats
500 OFP_GROUP_DESC_STATS_PACK_STR = '!HBxI'
501 OFP_GROUP_DESC_STATS_SIZE = 8
502 assert calcsize(OFP_GROUP_DESC_STATS_PACK_STR) == OFP_GROUP_DESC_STATS_SIZE
504 # struct ofp_group_features_stats
505 OFP_GROUP_FEATURES_STATS_PACK_STR = '!II4I4I'
506 OFP_GROUP_FEATURES_STATS_SIZE = 40
507 assert (calcsize(OFP_GROUP_FEATURES_STATS_PACK_STR) ==
508 OFP_GROUP_FEATURES_STATS_SIZE)
510 # enmu ofp_group_capabilities
511 OFPGFC_SELECT_WEIGHT = 1 << 0 # Support weight for select groups.
512 OFPGFC_SELECT_LIVENESS = 1 << 1 # Support liveness for select groups.
513 OFPGFC_CHAINING = 1 << 2 # Support chaining groups.
514 OFPGFC_CHAINING_CHECKS = 1 << 3 # Check chaining for loops and delete
516 # struct ofp_experimenter_stats_header
517 OFP_EXPERIMENTER_STATS_HEADER_PACK_STR = '!II'
518 OFP_EXPERIMENTER_STATS_HEADER_SIZE = 8
519 assert (calcsize(OFP_EXPERIMENTER_STATS_HEADER_PACK_STR) ==
520 OFP_EXPERIMENTER_STATS_HEADER_SIZE)
522 # struct opf_queue_get_config_request
523 OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR = '!I4x'
524 OFP_QUEUE_GET_CONFIG_REQUEST_SIZE = 16
525 assert (calcsize(OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR) + OFP_HEADER_SIZE ==
526 OFP_QUEUE_GET_CONFIG_REQUEST_SIZE)
528 # struct ofp_queue_get_config_reply
529 OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR = '!I4x'
530 OFP_QUEUE_GET_CONFIG_REPLY_SIZE = 16
531 assert (calcsize(OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR) + OFP_HEADER_SIZE ==
532 OFP_QUEUE_GET_CONFIG_REPLY_SIZE)
534 # struct ofp_packet_out
535 OFP_PACKET_OUT_PACK_STR = '!IIH6x'
536 OFP_PACKET_OUT_SIZE = 24
537 assert (calcsize(OFP_PACKET_OUT_PACK_STR) + OFP_HEADER_SIZE ==
540 # struct ofp_role_request
541 OFP_ROLE_REQUEST_PACK_STR = '!I4xQ'
542 OFP_ROLE_REQUEST_SIZE = 24
543 assert (calcsize(OFP_ROLE_REQUEST_PACK_STR) + OFP_HEADER_SIZE ==
544 OFP_ROLE_REQUEST_SIZE)
546 # enum ofp_controller_role
547 OFPCR_ROLE_NOCHANGE = 0 # Don't change current role.
548 OFPCR_ROLE_EQUAL = 1 # Default role, full access.
549 OFPCR_ROLE_MASTER = 2 # Full access, at most one master.
550 OFPCR_ROLE_SLAVE = 3 # Read-only access.
552 # struct ofp_packet_in
553 OFP_PACKET_IN_PACK_STR = '!IHBB'
554 OFP_PACKET_IN_SIZE = 24
555 assert (calcsize(OFP_PACKET_IN_PACK_STR) + OFP_MATCH_SIZE + OFP_HEADER_SIZE ==
558 # enum ofp_packet_in_reason
559 OFPR_NO_MATCH = 0 # No matching flow.
560 OFPR_ACTION = 1 # Action explicitly output to controller.
561 OFPR_INVALID_TTL = 2 # Packet has invalid TTL.
563 # struct ofp_flow_removed
564 _OFP_FLOW_REMOVED_PACK_STR0 = 'QHBBIIHHQQ'
565 OFP_FLOW_REMOVED_PACK_STR = '!' + _OFP_FLOW_REMOVED_PACK_STR0 + \
567 OFP_FLOW_REMOVED_PACK_STR0 = '!' + _OFP_FLOW_REMOVED_PACK_STR0
568 OFP_FLOW_REMOVED_SIZE = 56
569 assert (calcsize(OFP_FLOW_REMOVED_PACK_STR) + OFP_HEADER_SIZE ==
570 OFP_FLOW_REMOVED_SIZE)
572 # enum ofp_flow_removed_reason
573 OFPRR_IDLE_TIMEOUT = 0 # Flow idle time exceeded idle_timeout.
574 OFPRR_HARD_TIMEOUT = 1 # Time exceeded hard_timeout.
575 OFPRR_DELETE = 2 # Evicted by a DELETE flow mod.
576 OFPRR_GROUP_DELETE = 3 # Group was removed.
578 # struct ofp_port_status
579 OFP_PORT_STATUS_PACK_STR = '!B7x' + _OFP_PORT_PACK_STR
580 OFP_PORT_STATUS_DESC_OFFSET = OFP_HEADER_SIZE + 8
581 OFP_PORT_STATUS_SIZE = 80
582 assert (calcsize(OFP_PORT_STATUS_PACK_STR) + OFP_HEADER_SIZE ==
583 OFP_PORT_STATUS_SIZE)
585 # enum ofp_port_reason
586 OFPPR_ADD = 0 # The port was added.
587 OFPPR_DELETE = 1 # The port was removed.
588 OFPPR_MODIFY = 2 # Some attribute of the port has changed.
590 # struct ofp_error_msg
591 OFP_ERROR_MSG_PACK_STR = '!HH'
592 OFP_ERROR_MSG_SIZE = 12
593 assert calcsize(OFP_ERROR_MSG_PACK_STR) + OFP_HEADER_SIZE == OFP_ERROR_MSG_SIZE
595 # enum ofp_error_type
596 OFPET_HELLO_FAILED = 0 # Hello protocol failed.
597 OFPET_BAD_REQUEST = 1 # Request was not understood.
598 OFPET_BAD_ACTION = 2 # Error in action description.
599 OFPET_BAD_INSTRUCTION = 3 # Error in instruction list.
600 OFPET_BAD_MATCH = 4 # Error in match.
601 OFPET_FLOW_MOD_FAILED = 5 # Problem modifying flow entry.
602 OFPET_GROUP_MOD_FAILED = 6 # Problem modifying group entry.
603 OFPET_PORT_MOD_FAILED = 7 # OFPT_PORT_MOD failed.
604 OFPET_TABLE_MOD_FAILED = 8 # Table mod request failed.
605 OFPET_QUEUE_OP_FAILED = 9 # Queue operation failed.
606 OFPET_SWITCH_CONFIG_FAILED = 10 # Switch config request failed.
607 OFPET_ROLE_REQUEST_FAILED = 11 # Controller Role request failed.
608 OFPET_EXPERIMENTER = 0xffff # Experimenter error messages.
610 # enum ofp_hello_failed_code
611 OFPHFC_INCOMPATIBLE = 0 # No compatible version.
612 OFPHFC_EPERM = 1 # Permissions error.
614 # enum ofp_bad_request_code
615 OFPBRC_BAD_VERSION = 0 # ofp_header.version not supported.
616 OFPBRC_BAD_TYPE = 1 # ofp_header.type not supported.
617 OFPBRC_BAD_STAT = 2 # ofp_stats_msg.type not supported.
618 OFPBRC_BAD_EXPERIMENTER = 3 # Experimenter id not supported
619 # (in ofp_experimenter_header
620 # or ofp_stats_request or ofp_stats_reply).
621 OFPBRC_BAD_EXP_TYPE = 4 # Experimenter type not supported.
622 OFPBRC_EPERM = 5 # Permissions error.
623 OFPBRC_BAD_LEN = 6 # Wrong request length for type.
624 OFPBRC_BUFFER_EMPTY = 7 # Specified buffer has already been used.
625 OFPBRC_BUFFER_UNKNOWN = 8 # Specified buffer does not exist.
626 OFPBRC_BAD_TABLE_ID = 9 # Specified table-id invalid or does not exist.
627 OFPBRC_IS_SLAVE = 10 # Denied because controller is slave.
628 OFPBRC_BAD_PORT = 11 # Invalid port.
629 OFPBRC_BAD_PACKET = 12 # Invalid packet in packet-out
631 # enum ofp_bad_action_code
632 OFPBAC_BAD_TYPE = 0 # Unknown action type.
633 OFPBAC_BAD_LEN = 1 # Length problem in actions.
634 OFPBAC_BAD_EXPERIMENTER = 2 # Unknown experimenter id specified.
635 OFPBAC_BAD_EXP_TYPE = 3 # Unknown action type for experimenter id.
636 OFPBAC_BAD_OUT_PORT = 4 # Problem validating output action.
637 OFPBAC_BAD_ARGUMENT = 5 # Bad action argument.
638 OFPBAC_EPERM = 6 # Permissions error.
639 OFPBAC_TOO_MANY = 7 # Can't handle this many actions.
640 OFPBAC_BAD_QUEUE = 8 # Problem validating output queue.
641 OFPBAC_BAD_OUT_GROUP = 9 # Invalid group id in forward action.
642 OFPBAC_MATCH_INCONSISTENT = 10 # Action can't apply for this match,
643 # or Set-Field missing prerequisite.
644 OFPBAC_UNSUPPORTED_ORDER = 11 # Action order is unsupported for
645 # the action list in an Apply-Actions
647 OFPBAC_BAD_TAG = 12 # Actions uses an unsupported tag/encap.
648 OFPBAC_BAD_SET_TYPE = 13 # Unsupported type in SET_FIELD action.
649 OFPBAC_BAD_SET_LEN = 14 # Length problem in SET_FIELD action.
650 OFPBAC_BAD_SET_ARGUMENT = 15 # Bad arguement in SET_FIELD action.
652 # enum ofp_bad_instruction_code
653 OFPBIC_UNKNOWN_INST = 0 # Unknown instruction.
654 OFPBIC_UNSUP_INST = 1 # Switch or table does not support
656 OFPBIC_BAD_TABLE_ID = 2 # Invalid Table-Id specified
657 OFPBIC_UNSUP_METADATA = 3 # Metadata value unsupported by datapath.
658 OFPBIC_UNSUP_METADATA_MASK = 4 # Metadata mask value unsupported by
660 OFPBIC_BAD_EXPERIMENTER = 5 # Unknown experimenter id specified.
661 OFPBIC_BAD_EXP_TYPE = 6 # Unknown instruction for experimenter id.
662 OFPBIC_BAD_LEN = 7 # Length problem in instrucitons.
663 OFPBIC_EPERM = 8 # Permissions error.
665 # enum ofp_bad_match_code
666 OFPBMC_BAD_TYPE = 0 # Unsupported match type apecified by
668 OFPBMC_BAD_LEN = 1 # Length problem in math.
669 OFPBMC_BAD_TAG = 2 # Match uses an unsupported tag/encap.
670 OFPBMC_BAD_DL_ADDR_MASK = 3 # Unsupported datalink addr mask -
671 # switch does not support arbitrary
672 # datalink address mask.
673 OFPBMC_BAD_NW_ADDR_MASK = 4 # Unsupported network addr mask -
674 # switch does not support arbitrary
675 # network addres mask.
676 OFPBMC_BAD_WILDCARDS = 5 # Unsupported combination of fields
677 # masked or omitted in the match.
678 OFPBMC_BAD_FIELD = 6 # Unsupported field type in the match.
679 OFPBMC_BAD_VALUE = 7 # Unsupported value in a match field.
680 OFPBMC_BAD_MASK = 8 # Unsupported mask specified in the
682 OFPBMC_BAD_PREREQ = 9 # A prerequisite was not met.
683 OFPBMC_DUP_FIELD = 10 # A field type was duplicated.
684 OFPBMC_EPERM = 11 # Permissions error.
686 # enum ofp_flow_mod_failed_code
687 OFPFMFC_UNKNOWN = 0 # Unspecified error.
688 OFPFMFC_TABLE_FULL = 1 # Flow not added because table was full.
689 OFPFMFC_BAD_TABLE_ID = 2 # Table does not exist
690 OFPFMFC_OVERLAP = 3 # Attempted to add overlapping flow
691 # with CHECK_OVERLAP flag set.
692 OFPFMFC_EPERM = 4 # Permissions error.
693 OFPFMFC_BAD_TIMEOUT = 5 # Flow not added because of
694 # unsupported idle/hard timeout.
695 OFPFMFC_BAD_COMMAND = 6 # Unsupported or unknown command.
696 OFPFMFC_BAD_FLAGS = 7 # Unsupported or unknown flags.
698 # enum ofp_group_mod_failed_code
699 OFPGMFC_GROUP_EXISTS = 0
700 OFPGMFC_INVALID_GROUP = 1
701 OFPGMFC_WEIGHT_UNSUPPORTED = 2 # Switch does not support unequal load
702 # sharing with select groups.
703 OFPGMFC_OUT_OF_GROUPS = 3 # The group table is full.
704 OFPGMFC_OUT_OF_BUCKETS = 4 # The maximum number of action buckets
705 # for a group has been exceeded.
706 OFPGMFC_CHAINING_UNSUPPORTED = 5 # Switch does not support groups that
708 OFPGMFC_WATCH_UNSUPPORTED = 6 # This group cannot watch the
709 # watch_port or watch_group specified.
710 OFPGMFC_LOOP = 7 # Group entry would cause a loop.
711 OFPGMFC_UNKNOWN_GROUP = 8 # Group not modified because a group
712 # MODIFY attempted to modify a
713 # non-existent group.
714 OFPGMFC_CHAINED_GROUP = 9 # Group not deleted because another
715 # group is forwarding to it.
716 OFPGMFC_BAD_TYPE = 10 # Unsupported or unknown group type.
717 OFPGMFC_BAD_COMMAND = 11 # Unsupported or unknown command.
718 OFPGMFC_BAD_BUCKET = 12 # Error in bucket.
719 OFPGMFC_BAD_WATCH = 13 # Error in watch port/group.
720 OFPGMFC_EPERM = 14 # Permissions error.
722 # enum ofp_port_mod_failed_code
723 OFPPMFC_BAD_PORT = 0 # Specified port does not exist.
724 OFPPMFC_BAD_HW_ADDR = 1 # Specified hardware address does not
725 # match the port number.
726 OFPPMFC_BAD_CONFIG = 2 # Specified config is invalid.
727 OFPPMFC_BAD_ADVERTISE = 3 # Specified advertise is invalid.
728 OFPPMFC_EPERM = 4 # Permissions error.
730 # enum ofp_table_mod_failed_code
731 OFPTMFC_BAD_TABLE = 0 # Specified table does not exist.
732 OFPTMFC_BAD_CONFIG = 1 # Specified config is invalid.
733 OFPTMFC_EPERM = 2 # Permissions error
735 # enum ofp_queue_op_failed_code
736 OFPQOFC_BAD_PORT = 0 # Invalid port (or port does not exist).
737 OFPQOFC_BAD_QUEUE = 1 # Queue does not exist.
738 OFPQOFC_EPERM = 2 # Permissions error.
740 # enum ofp_switch_config_failed_code
741 OFPSCFC_BAD_FLAGS = 0 # Specified flags is invalid.
742 OFPSCFC_BAD_LEN = 1 # Specified len is invalid.
743 OFPQCFC_EPERM = 2 # Permissions error (depracated).
744 # New or updated Ryu applications shall use
745 # OFPSCFC_EPERM. The variable name is a typo of
746 # in specifications before v1.3.1 (EXT-208).
747 OFPSCFC_EPERM = 2 # Permissions error.
748 # Ported back to ofproto_v1_2 for consistency with
749 # later OF specs (EXT-208).
751 # enum ofp_role_request_failed_code
752 OFPRRFC_STALE = 0 # Stale Message: old generation_id.
753 OFPRRFC_UNSUP = 1 # Controller role change unsupported.
754 OFPRRFC_BAD_ROLE = 2 # Invalid role.
756 # struct ofp_error_experimenter_msg
757 OFP_ERROR_EXPERIMENTER_MSG_PACK_STR = '!HHI'
758 OFP_ERROR_EXPERIMENTER_MSG_SIZE = 16
759 assert (calcsize(OFP_ERROR_EXPERIMENTER_MSG_PACK_STR) + OFP_HEADER_SIZE ==
760 OFP_ERROR_EXPERIMENTER_MSG_SIZE)
762 # struct ofp_experimenter_header
763 OFP_EXPERIMENTER_HEADER_PACK_STR = '!II'
764 OFP_EXPERIMENTER_HEADER_SIZE = 16
765 assert (calcsize(OFP_EXPERIMENTER_HEADER_PACK_STR) + OFP_HEADER_SIZE ==
766 OFP_EXPERIMENTER_HEADER_SIZE)
772 def _oxm_tlv_header(class_, field, hasmask, length):
773 return (class_ << 16) | (field << 9) | (hasmask << 8) | length
776 def oxm_tlv_header(field, length):
777 return _oxm_tlv_header(OFPXMC_OPENFLOW_BASIC, field, 0, length)
780 def oxm_tlv_header_w(field, length):
781 return _oxm_tlv_header(OFPXMC_OPENFLOW_BASIC, field, 1, length * 2)
784 def oxm_tlv_header_extract_hasmask(header):
785 return (header >> 8) & 1
788 def oxm_tlv_header_extract_length(header):
789 if oxm_tlv_header_extract_hasmask(header):
790 length = (header & 0xff) // 2
792 length = header & 0xff
797 oxm_fields.OpenFlowBasic('in_port', 0, type_desc.Int4),
798 oxm_fields.OpenFlowBasic('in_phy_port', 1, type_desc.Int4),
799 oxm_fields.OpenFlowBasic('metadata', 2, type_desc.Int8),
800 oxm_fields.OpenFlowBasic('eth_dst', 3, type_desc.MacAddr),
801 oxm_fields.OpenFlowBasic('eth_src', 4, type_desc.MacAddr),
802 oxm_fields.OpenFlowBasic('eth_type', 5, type_desc.Int2),
803 oxm_fields.OpenFlowBasic('vlan_vid', 6, type_desc.Int2),
804 oxm_fields.OpenFlowBasic('vlan_pcp', 7, type_desc.Int1),
805 oxm_fields.OpenFlowBasic('ip_dscp', 8, type_desc.Int1),
806 oxm_fields.OpenFlowBasic('ip_ecn', 9, type_desc.Int1),
807 oxm_fields.OpenFlowBasic('ip_proto', 10, type_desc.Int1),
808 oxm_fields.OpenFlowBasic('ipv4_src', 11, type_desc.IPv4Addr),
809 oxm_fields.OpenFlowBasic('ipv4_dst', 12, type_desc.IPv4Addr),
810 oxm_fields.OpenFlowBasic('tcp_src', 13, type_desc.Int2),
811 oxm_fields.OpenFlowBasic('tcp_dst', 14, type_desc.Int2),
812 oxm_fields.OpenFlowBasic('udp_src', 15, type_desc.Int2),
813 oxm_fields.OpenFlowBasic('udp_dst', 16, type_desc.Int2),
814 oxm_fields.OpenFlowBasic('sctp_src', 17, type_desc.Int2),
815 oxm_fields.OpenFlowBasic('sctp_dst', 18, type_desc.Int2),
816 oxm_fields.OpenFlowBasic('icmpv4_type', 19, type_desc.Int1),
817 oxm_fields.OpenFlowBasic('icmpv4_code', 20, type_desc.Int1),
818 oxm_fields.OpenFlowBasic('arp_op', 21, type_desc.Int2),
819 oxm_fields.OpenFlowBasic('arp_spa', 22, type_desc.IPv4Addr),
820 oxm_fields.OpenFlowBasic('arp_tpa', 23, type_desc.IPv4Addr),
821 oxm_fields.OpenFlowBasic('arp_sha', 24, type_desc.MacAddr),
822 oxm_fields.OpenFlowBasic('arp_tha', 25, type_desc.MacAddr),
823 oxm_fields.OpenFlowBasic('ipv6_src', 26, type_desc.IPv6Addr),
824 oxm_fields.OpenFlowBasic('ipv6_dst', 27, type_desc.IPv6Addr),
825 oxm_fields.OpenFlowBasic('ipv6_flabel', 28, type_desc.Int4),
826 oxm_fields.OpenFlowBasic('icmpv6_type', 29, type_desc.Int1),
827 oxm_fields.OpenFlowBasic('icmpv6_code', 30, type_desc.Int1),
828 oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, type_desc.IPv6Addr),
829 oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, type_desc.MacAddr),
830 oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, type_desc.MacAddr),
831 oxm_fields.OpenFlowBasic('mpls_label', 34, type_desc.Int4),
832 oxm_fields.OpenFlowBasic('mpls_tc', 35, type_desc.Int1),
833 # EXT-256 Old version of ONF Extension
834 oxm_fields.OldONFExperimenter('pbb_uca', 2560, type_desc.Int1),
835 # EXT-109 TCP flags match field Extension
836 oxm_fields.ONFExperimenter('tcp_flags', 42, type_desc.Int2),
837 # EXT-233 Output match Extension
838 # NOTE(yamamoto): The spec says uint64_t but I assume it's an error.
839 oxm_fields.ONFExperimenter('actset_output', 43, type_desc.Int4),
840 ] + nicira_ext.oxm_types
842 oxm_fields.generate(__name__)
844 # generate utility methods
845 ofproto_utils.generate(__name__)
853 OFP_NO_BUFFER = 0xffffffff