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.3 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_MULTIPART_REQUEST = 18 # Controller/switch message
57 OFPT_MULTIPART_REPLY = 19 # Controller/switch message
59 OFPT_BARRIER_REQUEST = 20 # Controller/switch message
60 OFPT_BARRIER_REPLY = 21 # Controller/switch message
61 OFPT_QUEUE_GET_CONFIG_REQUEST = 22 # Controller/switch message
62 OFPT_QUEUE_GET_CONFIG_REPLY = 23 # Controller/switch message
64 OFPT_ROLE_REQUEST = 24 # Controller/switch message
65 OFPT_ROLE_REPLY = 25 # Controller/switch message
67 OFPT_GET_ASYNC_REQUEST = 26 # Controller/switch message
68 OFPT_GET_ASYNC_REPLY = 27 # Controller/switch message
69 OFPT_SET_ASYNC = 28 # Controller/switch message
71 OFPT_METER_MOD = 29 # Controller/switch message
74 OFP_MAX_PORT_NAME_LEN = 16
76 OFP_ETH_ALEN_STR = str(OFP_ETH_ALEN)
77 _OFP_PORT_PACK_STR = 'I4x' + OFP_ETH_ALEN_STR + 's' + '2x' + \
78 str(OFP_MAX_PORT_NAME_LEN) + 's' + 'IIIIIIII'
79 OFP_PORT_PACK_STR = '!' + _OFP_PORT_PACK_STR
81 assert calcsize(OFP_PORT_PACK_STR) == OFP_PORT_SIZE
83 # enum ofp_port_config
84 OFPPC_PORT_DOWN = 1 << 0 # Port is administratively down.
85 OFPPC_NO_RECV = 1 << 2 # Drop all packets recieved by port.
86 OFPPC_NO_FWD = 1 << 5 # Drop packets forwarded to port.
87 OFPPC_NO_PACKET_IN = 1 << 6 # Do not send packet-in msgs for port.
90 OFPPS_LINK_DOWN = 1 << 0 # No physical link present.
91 OFPPS_BLOCKED = 1 << 1 # Port is blocked.
92 OFPPS_LIVE = 1 << 2 # Live for Fast Failover Group.
96 OFPP_IN_PORT = 0xfffffff8 # Send the packet out the input port. This
97 # virtual port must be explicitly used
98 # in order to send back out of the input
100 OFPP_TABLE = 0xfffffff9 # Perform actions in flow table.
101 # NB: This can only be the destination
102 # port for packet-out messages.
103 OFPP_NORMAL = 0xfffffffa # Process with normal L2/L3 switching.
104 OFPP_FLOOD = 0xfffffffb # All physical ports except input port and
105 # those disabled by STP.
106 OFPP_ALL = 0xfffffffc # All physical ports except input port.
107 OFPP_CONTROLLER = 0xfffffffd # Send to controller.
108 OFPP_LOCAL = 0xfffffffe # Local openflow "port".
109 OFPP_ANY = 0xffffffff # Not associated with a physical port.
111 # All ones is used to indicate all queues in a port (for stats retrieval).
112 OFPQ_ALL = 0xffffffff
114 # enum ofp_port_features
115 OFPPF_10MB_HD = 1 << 0 # 10 Mb half-duplex rate support.
116 OFPPF_10MB_FD = 1 << 1 # 10 Mb full-duplex rate support.
117 OFPPF_100MB_HD = 1 << 2 # 100 Mb half-duplex rate support.
118 OFPPF_100MB_FD = 1 << 3 # 100 Mb full-duplex rate support.
119 OFPPF_1GB_HD = 1 << 4 # 1 Gb half-duplex rate support.
120 OFPPF_1GB_FD = 1 << 5 # 1 Gb full-duplex rate support.
121 OFPPF_10GB_FD = 1 << 6 # 10 Gb full-duplex rate support.
122 OFPPF_40GB_FD = 1 << 7 # 40 Gb full-duplex rate support.
123 OFPPF_100GB_FD = 1 << 8 # 100 Gb full-duplex rate support.
124 OFPPF_1TB_FD = 1 << 9 # 1 Tb full-duplex rate support.
125 OFPPF_OTHER = 1 << 10 # Other rate, not in the list.
126 OFPPF_COPPER = 1 << 11 # Copper medium.
127 OFPPF_FIBER = 1 << 12 # Fiber medium.
128 OFPPF_AUTONEG = 1 << 13 # Auto-negotiation.
129 OFPPF_PAUSE = 1 << 14 # Pause.
130 OFPPF_PAUSE_ASYM = 1 << 15 # Asymmetric pause.
132 # struct ofp_packet_queue
133 OFP_PACKET_QUEUE_PACK_STR = '!IIH6x'
134 OFP_PACKET_QUEUE_SIZE = 16
135 assert calcsize(OFP_PACKET_QUEUE_PACK_STR) == OFP_PACKET_QUEUE_SIZE
137 # enum ofp_queue_properties
138 OFPQT_MIN_RATE = 1 # Minimum datarate guaranteed.
139 OFPQT_MAX_RATE = 2 # Maximum datarate.
140 OFPQT_EXPERIMENTER = 0xffff # Experimenter defined property.
142 # struct ofp_queue_prop_header
143 OFP_QUEUE_PROP_HEADER_PACK_STR = '!HH4x'
144 OFP_QUEUE_PROP_HEADER_SIZE = 8
145 assert calcsize(OFP_QUEUE_PROP_HEADER_PACK_STR) == OFP_QUEUE_PROP_HEADER_SIZE
147 # struct ofp_queue_prop_min_rate
148 OFP_QUEUE_PROP_MIN_RATE_PACK_STR = '!H6x'
149 OFP_QUEUE_PROP_MIN_RATE_SIZE = 16
150 assert (calcsize(OFP_QUEUE_PROP_MIN_RATE_PACK_STR) +
151 OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_MIN_RATE_SIZE
153 # struct ofp_queue_prop_max_rate
154 OFP_QUEUE_PROP_MAX_RATE_PACK_STR = '!H6x'
155 OFP_QUEUE_PROP_MAX_RATE_SIZE = 16
156 assert (calcsize(OFP_QUEUE_PROP_MAX_RATE_PACK_STR) +
157 OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_MAX_RATE_SIZE
159 # struct ofp_queue_prop_experimenter
160 OFP_QUEUE_PROP_EXPERIMENTER_PACK_STR = '!I4x'
161 OFP_QUEUE_PROP_EXPERIMENTER_SIZE = 16
162 assert (calcsize(OFP_QUEUE_PROP_EXPERIMENTER_PACK_STR) +
163 OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_EXPERIMENTER_SIZE
166 _OFP_MATCH_PACK_STR = 'HHBBBB'
167 OFP_MATCH_PACK_STR = '!' + _OFP_MATCH_PACK_STR
169 assert calcsize(OFP_MATCH_PACK_STR) == OFP_MATCH_SIZE
171 # enum ofp_match_type
172 OFPMT_STANDARD = 0 # Deprecated
173 OFPMT_OXM = 1 # OpenFlow Extensible Match
176 OFPXMC_NXM_0 = 0x0000 # Backward compatibility with NXM
177 OFPXMC_NXM_1 = 0x0001 # Backward compatibility with NXM
178 OFPXMC_OPENFLOW_BASIC = 0x8000 # Basic class for OpenFlow
179 OFPXMC_EXPERIMENTER = 0xFFFF # Experimenter class
182 OFPVID_PRESENT = 0x1000 # bit that indicate that a VLAN id is set.
183 OFPVID_NONE = 0x0000 # No VLAN id was set.
185 # enum ofp_ipv6exthdr_flags
186 OFPIEH_NONEXT = 1 << 0 # "No next header" encountered.
187 OFPIEH_ESP = 1 << 1 # Encrypted Sec Payload header present.
188 OFPIEH_AUTH = 1 << 2 # Authentication header present.
189 OFPIEH_DEST = 1 << 3 # 1 or 2 dest headers present.
190 OFPIEH_FRAG = 1 << 4 # Fragment header present.
191 OFPIEH_ROUTER = 1 << 5 # Router header present.
192 OFPIEH_HOP = 1 << 6 # Hop-by-hop header present.
193 OFPIEH_UNREP = 1 << 7 # Unexpected repeats encountered.
194 OFPIEH_UNSEQ = 1 << 8 # Unexpected sequencing encountered.
196 # ofp_oxm_experimenter_header
197 OFP_OXM_EXPERIMENTER_HEADER_PACK_STR = '!II'
198 OFP_OXM_EXPERIMENTER_HEADER_SIZE = 8
199 assert (calcsize(OFP_OXM_EXPERIMENTER_HEADER_PACK_STR) ==
200 OFP_OXM_EXPERIMENTER_HEADER_SIZE)
202 # enum ofp_instruction_type
203 OFPIT_GOTO_TABLE = 1 # Setup the next table in the lookup pipeline.
204 OFPIT_WRITE_METADATA = 2 # Setup the metadata field for use later in
206 OFPIT_WRITE_ACTIONS = 3 # Write the action(s) onto the datapath
208 OFPIT_APPLY_ACTIONS = 4 # Applies the action(s) immediately
209 OFPIT_CLEAR_ACTIONS = 5 # Clears all actions from the datapath action
211 OFPIT_METER = 6 # Apply meter (rate limiter)
212 OFPIT_EXPERIMENTER = 0xFFFF # Experimenter instruction
214 # struct ofp_instruction_goto_table
215 OFP_INSTRUCTION_GOTO_TABLE_PACK_STR = '!HHB3x'
216 OFP_INSTRUCTION_GOTO_TABLE_SIZE = 8
217 assert (calcsize(OFP_INSTRUCTION_GOTO_TABLE_PACK_STR) ==
218 OFP_INSTRUCTION_GOTO_TABLE_SIZE)
220 # struct ofp_instruction_write_metadata
221 OFP_INSTRUCTION_WRITE_METADATA_PACK_STR = '!HH4xQQ'
222 OFP_INSTRUCTION_WRITE_METADATA_SIZE = 24
223 assert (calcsize(OFP_INSTRUCTION_WRITE_METADATA_PACK_STR) ==
224 OFP_INSTRUCTION_WRITE_METADATA_SIZE)
226 # struct ofp_instruction_actions
227 OFP_INSTRUCTION_ACTIONS_PACK_STR = '!HH4x'
228 OFP_INSTRUCTION_ACTIONS_SIZE = 8
229 assert (calcsize(OFP_INSTRUCTION_ACTIONS_PACK_STR) ==
230 OFP_INSTRUCTION_ACTIONS_SIZE)
232 # struct ofp_instruction_meter
233 OFP_INSTRUCTION_METER_PACK_STR = '!HHI'
234 OFP_INSTRUCTION_METER_SIZE = 8
235 assert calcsize(OFP_INSTRUCTION_METER_PACK_STR) == OFP_INSTRUCTION_METER_SIZE
237 # enum ofp_action_type
238 OFPAT_OUTPUT = 0 # Output to switch port.
239 OFPAT_COPY_TTL_OUT = 11 # Copy TTL "outwards" -- from
240 # next-to-outermost to outermost
241 OFPAT_COPY_TTL_IN = 12 # Copy TTL "inwards" -- from outermost to
243 OFPAT_SET_MPLS_TTL = 15 # MPLS TTL.
244 OFPAT_DEC_MPLS_TTL = 16 # Decrement MPLS TTL
245 OFPAT_PUSH_VLAN = 17 # Push a new VLAN tag
246 OFPAT_POP_VLAN = 18 # Pop the outer VLAN tag
247 OFPAT_PUSH_MPLS = 19 # Push a new MPLS tag
248 OFPAT_POP_MPLS = 20 # Pop the outer MPLS tag
249 OFPAT_SET_QUEUE = 21 # Set queue id when outputting to a port
250 OFPAT_GROUP = 22 # Apply group
251 OFPAT_SET_NW_TTL = 23 # IP TTL.
252 OFPAT_DEC_NW_TTL = 24 # Decrement IP TTL.
253 OFPAT_SET_FIELD = 25 # Set a header field using OXM TLV format.
254 OFPAT_PUSH_PBB = 26 # Push a new PBB service tag (I-TAG)
255 OFPAT_POP_PBB = 27 # Pop the outer PBB service tag (I-TAG)
256 OFPAT_EXPERIMENTER = 0xffff
258 # struct ofp_action_header
259 OFP_ACTION_HEADER_PACK_STR = '!HH4x'
260 OFP_ACTION_HEADER_SIZE = 8
261 assert calcsize(OFP_ACTION_HEADER_PACK_STR) == OFP_ACTION_HEADER_SIZE
263 # struct ofp_action_output
264 OFP_ACTION_OUTPUT_PACK_STR = '!HHIH6x'
265 OFP_ACTION_OUTPUT_SIZE = 16
266 assert calcsize(OFP_ACTION_OUTPUT_PACK_STR) == OFP_ACTION_OUTPUT_SIZE
268 # enum ofp_controller_max_len
269 OFPCML_MAX = 0xffe5 # maximum max_len value which can be used to
270 # request a specific byte length.
271 OFPCML_NO_BUFFER = 0xffff # indicates that no buffering should be
272 # applied and the whole packet is to be
273 # sent to the controller.
275 # struct ofp_action_group
276 OFP_ACTION_GROUP_PACK_STR = '!HHI'
277 OFP_ACTION_GROUP_SIZE = 8
278 assert calcsize(OFP_ACTION_GROUP_PACK_STR) == OFP_ACTION_GROUP_SIZE
280 # struct ofp_action_set_queue
281 OFP_ACTION_SET_QUEUE_PACK_STR = '!HHI'
282 OFP_ACTION_SET_QUEUE_SIZE = 8
283 assert calcsize(OFP_ACTION_SET_QUEUE_PACK_STR) == OFP_ACTION_SET_QUEUE_SIZE
285 # struct ofp_action_mpls_ttl
286 OFP_ACTION_MPLS_TTL_PACK_STR = '!HHB3x'
287 OFP_ACTION_MPLS_TTL_SIZE = 8
288 assert calcsize(OFP_ACTION_MPLS_TTL_PACK_STR) == OFP_ACTION_MPLS_TTL_SIZE
290 # struct ofp_action_nw_ttl
291 OFP_ACTION_NW_TTL_PACK_STR = '!HHB3x'
292 OFP_ACTION_NW_TTL_SIZE = 8
293 assert calcsize(OFP_ACTION_NW_TTL_PACK_STR) == OFP_ACTION_NW_TTL_SIZE
295 # struct ofp_action_push
296 OFP_ACTION_PUSH_PACK_STR = '!HHH2x'
297 OFP_ACTION_PUSH_SIZE = 8
298 assert calcsize(OFP_ACTION_PUSH_PACK_STR) == OFP_ACTION_PUSH_SIZE
300 # struct ofp_action_pop_mpls
301 OFP_ACTION_POP_MPLS_PACK_STR = '!HHH2x'
302 OFP_ACTION_POP_MPLS_SIZE = 8
303 assert calcsize(OFP_ACTION_POP_MPLS_PACK_STR) == OFP_ACTION_POP_MPLS_SIZE
305 # struct ofp_action_set_field
306 OFP_ACTION_SET_FIELD_PACK_STR = '!HH4x'
307 OFP_ACTION_SET_FIELD_SIZE = 8
308 assert calcsize(OFP_ACTION_SET_FIELD_PACK_STR) == OFP_ACTION_SET_FIELD_SIZE
310 # struct ofp_action_experimenter_header
311 OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR = '!HHI'
312 OFP_ACTION_EXPERIMENTER_HEADER_SIZE = 8
313 assert (calcsize(OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR) ==
314 OFP_ACTION_EXPERIMENTER_HEADER_SIZE)
316 # ofp_switch_features
317 OFP_SWITCH_FEATURES_PACK_STR = '!QIBB2xII'
318 OFP_SWITCH_FEATURES_SIZE = 32
319 assert (calcsize(OFP_SWITCH_FEATURES_PACK_STR) + OFP_HEADER_SIZE ==
320 OFP_SWITCH_FEATURES_SIZE)
322 # enum ofp_capabilities
323 OFPC_FLOW_STATS = 1 << 0 # Flow statistics.
324 OFPC_TABLE_STATS = 1 << 1 # Table statistics.
325 OFPC_PORT_STATS = 1 << 2 # Port statistics.
326 OFPC_GROUP_STATS = 1 << 3 # Group statistics.
327 OFPC_IP_REASM = 1 << 5 # Can reassemble IP fragments.
328 OFPC_QUEUE_STATS = 1 << 6 # Queue statistics.
329 OFPC_PORT_BLOCKED = 1 << 8 # Switch will block looping ports.
331 # struct ofp_switch_config
332 OFP_SWITCH_CONFIG_PACK_STR = '!HH'
333 OFP_SWITCH_CONFIG_SIZE = 12
334 assert (calcsize(OFP_SWITCH_CONFIG_PACK_STR) + OFP_HEADER_SIZE ==
335 OFP_SWITCH_CONFIG_SIZE)
337 # enum ofp_config_flags
338 OFPC_FRAG_NORMAL = 0 # No special handling for fragments.
339 OFPC_FRAG_DROP = 1 # Drop fragments.
340 OFPC_FRAG_REASM = 2 # Reassemble (only if OFPC_IP_REASM set).
347 # struct ofp_table_mod
348 OFP_TABLE_MOD_PACK_STR = '!B3xI'
349 OFP_TABLE_MOD_SIZE = 16
350 assert (calcsize(OFP_TABLE_MOD_PACK_STR) + OFP_HEADER_SIZE ==
353 _OFP_FLOW_MOD_PACK_STR0 = 'QQBBHHHIIIH2x'
354 OFP_FLOW_MOD_PACK_STR = '!' + _OFP_FLOW_MOD_PACK_STR0 + _OFP_MATCH_PACK_STR
355 OFP_FLOW_MOD_PACK_STR0 = '!' + _OFP_FLOW_MOD_PACK_STR0
356 OFP_FLOW_MOD_SIZE = 56
357 assert (calcsize(OFP_FLOW_MOD_PACK_STR) + OFP_HEADER_SIZE ==
360 # enum ofp_flow_mod_command
361 OFPFC_ADD = 0 # New flow.
362 OFPFC_MODIFY = 1 # Modify all matching flows.
363 OFPFC_MODIFY_STRICT = 2 # Modify entry strictly matching wildcards
364 OFPFC_DELETE = 3 # Delete all matching flows.
365 OFPFC_DELETE_STRICT = 4 # Strictly match wildcards and priority.
367 # By default, choose a priority in the middle.
368 OFP_DEFAULT_PRIORITY = 0x8000
370 # enum ofp_flow_mod_flags
371 OFPFF_SEND_FLOW_REM = 1 << 0 # Send flow removed message when flow
372 # expires or is deleted.
373 OFPFF_CHECK_OVERLAP = 1 << 1 # Check for overlapping entries first.
374 OFPFF_RESET_COUNTS = 1 << 2 # Reset flow packet and byte counts.
375 OFPFF_NO_PKT_COUNTS = 1 << 3 # Don't keep track of packet count.
376 OFPFF_NO_BYT_COUNTS = 1 << 4 # Don't keep track of byte count.
378 # struct ofp_group_mod
379 OFP_GROUP_MOD_PACK_STR = '!HBxI'
380 OFP_GROUP_MOD_SIZE = 16
381 assert (calcsize(OFP_GROUP_MOD_PACK_STR) + OFP_HEADER_SIZE ==
384 # enum ofp_group_mod_command
385 OFPGC_ADD = 0 # New group.
386 OFPGC_MODIFY = 1 # Modify all matching groups.
387 OFPGC_DELETE = 2 # Delete all matching groups.
390 OFPG_MAX = 0xffffff00 # Last usable group number.
392 OFPG_ALL = 0xfffffffc # Represents all groups for group delete commands.
393 OFPG_ANY = 0xffffffff # Wildcard group used only for flow stats requests.
394 # Selects all flows regardless of group
395 # (including flows with no group).
397 # enum ofp_group_type
398 OFPGT_ALL = 0 # All (multicast/broadcast) group.
399 OFPGT_SELECT = 1 # Select group.
400 OFPGT_INDIRECT = 2 # Indirect group.
401 OFPGT_FF = 3 # Fast failover group.
404 OFP_BUCKET_PACK_STR = '!HHII4x'
406 assert calcsize(OFP_BUCKET_PACK_STR) == OFP_BUCKET_SIZE
408 # struct ofp_port_mod
409 OFP_PORT_MOD_PACK_STR = '!I4x' + OFP_ETH_ALEN_STR + 's2xIII4x'
410 OFP_PORT_MOD_SIZE = 40
411 assert (calcsize(OFP_PORT_MOD_PACK_STR) + OFP_HEADER_SIZE ==
414 # struct ofp_meter_mod
415 OFP_METER_MOD_PACK_STR = '!HHI'
416 OFP_METER_MOD_SIZE = 16
417 assert (calcsize(OFP_METER_MOD_PACK_STR) + OFP_HEADER_SIZE ==
421 OFPM_MAX = 0xffff0000
422 OFPM_SLOWPATH = 0xfffffffd # Meter for slow datapath, if any.
423 OFPM_CONTROLLER = 0xfffffffe # Meter for controller connection.
424 OFPM_ALL = 0xffffffff # Represents all meters for stat requests
427 # enum ofp_meter_mod_command
428 OFPMC_ADD = 0 # New meter.
429 OFPMC_MODIFY = 1 # Modify specified meter.
430 OFPMC_DELETE = 2 # Delete specified meter.
432 # enum ofp_meter_flags
433 OFPMF_KBPS = 1 << 0 # Rate value in kb/s (kilo-bit per second).
434 OFPMF_PKTPS = 1 << 1 # Rate value in packet/sec.
435 OFPMF_BURST = 1 << 2 # Do burst size.
436 OFPMF_STATS = 1 << 3 # Collect statistics.
438 # struct ofp_meter_band_header
439 OFP_METER_BAND_HEADER_PACK_STR = '!HHII'
440 OFP_METER_BAND_HEADER_SIZE = 12
441 assert (calcsize(OFP_METER_BAND_HEADER_PACK_STR) ==
442 OFP_METER_BAND_HEADER_SIZE)
444 # enum ofp_meter_band_type
445 OFPMBT_DROP = 1 # Drop packet.
446 OFPMBT_DSCP_REMARK = 2 # Remark DSCP in the IP header.
447 OFPMBT_EXPERIMENTER = 0xFFFF # Experimenter meter band.
449 # struct ofp_meter_band_drop
450 OFP_METER_BAND_DROP_PACK_STR = '!HHII4x'
451 OFP_METER_BAND_DROP_SIZE = 16
452 assert (calcsize(OFP_METER_BAND_DROP_PACK_STR) ==
453 OFP_METER_BAND_DROP_SIZE)
455 # struct ofp_meter_band_dscp_remark
456 OFP_METER_BAND_DSCP_REMARK_PACK_STR = '!HHIIB3x'
457 OFP_METER_BAND_DSCP_REMARK_SIZE = 16
458 assert (calcsize(OFP_METER_BAND_DSCP_REMARK_PACK_STR) ==
459 OFP_METER_BAND_DSCP_REMARK_SIZE)
461 # struct ofp_meter_band_experimenter
462 OFP_METER_BAND_EXPERIMENTER_PACK_STR = '!HHIII'
463 OFP_METER_BAND_EXPERIMENTER_SIZE = 16
464 assert (calcsize(OFP_METER_BAND_EXPERIMENTER_PACK_STR) ==
465 OFP_METER_BAND_EXPERIMENTER_SIZE)
467 # struct ofp_multipart_request
468 OFP_MULTIPART_REQUEST_PACK_STR = '!HH4x'
469 OFP_MULTIPART_REQUEST_SIZE = 16
470 assert (calcsize(OFP_MULTIPART_REQUEST_PACK_STR) + OFP_HEADER_SIZE ==
471 OFP_MULTIPART_REQUEST_SIZE)
473 # enum ofp_multipart_request_flags
474 OFPMPF_REQ_MORE = 1 << 0 # More requests to follow.
476 # struct ofp_multipart_reply
477 OFP_MULTIPART_REPLY_PACK_STR = '!HH4x'
478 OFP_MULTIPART_REPLY_SIZE = 16
479 assert (calcsize(OFP_MULTIPART_REPLY_PACK_STR) + OFP_HEADER_SIZE ==
480 OFP_MULTIPART_REPLY_SIZE)
482 # enum ofp_multipart_reply_flags
483 OFPMPF_REPLY_MORE = 1 << 0 # More replies to follow.
485 # enum ofp_multipart_types
494 OFPMP_GROUP_FEATURES = 8
496 OFPMP_METER_CONFIG = 10
497 OFPMP_METER_FEATURES = 11
498 OFPMP_TABLE_FEATURES = 12
500 OFPMP_EXPERIMENTER = 0xffff
504 DESC_STR_LEN_STR = str(DESC_STR_LEN)
506 SERIAL_NUM_LEN_STR = str(SERIAL_NUM_LEN)
507 OFP_DESC_PACK_STR = '!' + \
508 DESC_STR_LEN_STR + 's' + \
509 DESC_STR_LEN_STR + 's' + \
510 DESC_STR_LEN_STR + 's' + \
511 SERIAL_NUM_LEN_STR + 's' + \
512 DESC_STR_LEN_STR + 's'
514 assert calcsize(OFP_DESC_PACK_STR) == OFP_DESC_SIZE
517 # struct ofp_flow_stats_request
518 _OFP_FLOW_STATS_REQUEST_0_PACK_STR = 'B3xII4xQQ'
519 OFP_FLOW_STATS_REQUEST_0_PACK_STR = '!' + _OFP_FLOW_STATS_REQUEST_0_PACK_STR
520 OFP_FLOW_STATS_REQUEST_0_SIZE = 32
521 assert (calcsize(OFP_FLOW_STATS_REQUEST_0_PACK_STR) ==
522 OFP_FLOW_STATS_REQUEST_0_SIZE)
523 OFP_FLOW_STATS_REQUEST_PACK_STR = (OFP_FLOW_STATS_REQUEST_0_PACK_STR +
525 OFP_FLOW_STATS_REQUEST_SIZE = 40
526 assert (calcsize(OFP_FLOW_STATS_REQUEST_PACK_STR) ==
527 OFP_FLOW_STATS_REQUEST_SIZE)
529 # struct ofp_flow_stats
530 _OFP_FLOW_STATS_0_PACK_STR = 'HBxIIHHHH4xQQQ'
531 OFP_FLOW_STATS_0_PACK_STR = '!' + _OFP_FLOW_STATS_0_PACK_STR
532 OFP_FLOW_STATS_0_SIZE = 48
533 assert calcsize(OFP_FLOW_STATS_0_PACK_STR) == OFP_FLOW_STATS_0_SIZE
534 OFP_FLOW_STATS_PACK_STR = (OFP_FLOW_STATS_0_PACK_STR +
536 OFP_FLOW_STATS_SIZE = 56
537 assert calcsize(OFP_FLOW_STATS_PACK_STR) == OFP_FLOW_STATS_SIZE
539 # struct ofp_flow_stats_request
540 _OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR = 'B3xII4xQQ'
541 OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR = '!' + \
542 _OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR
543 OFP_AGGREGATE_STATS_REQUEST_0_SIZE = 32
544 assert (calcsize(OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR) ==
545 OFP_AGGREGATE_STATS_REQUEST_0_SIZE)
546 OFP_AGGREGATE_STATS_REQUEST_PACK_STR = \
547 OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR + _OFP_MATCH_PACK_STR
548 OFP_AGGREGATE_STATS_REQUEST_SIZE = 40
549 assert (calcsize(OFP_AGGREGATE_STATS_REQUEST_PACK_STR) ==
550 OFP_AGGREGATE_STATS_REQUEST_SIZE)
552 # struct ofp_aggregate_stats_request
553 OFP_AGGREGATE_STATS_REQUEST_PACK_STR = '!B3xII4xQQ' + _OFP_MATCH_PACK_STR
554 OFP_AGGREGATE_STATS_REQUEST_SIZE = 40
555 assert (calcsize(OFP_AGGREGATE_STATS_REQUEST_PACK_STR) ==
556 OFP_AGGREGATE_STATS_REQUEST_SIZE)
558 # struct ofp_aggregate_stats_reply
559 OFP_AGGREGATE_STATS_REPLY_PACK_STR = '!QQI4x'
560 OFP_AGGREGATE_STATS_REPLY_SIZE = 24
561 assert (calcsize(OFP_AGGREGATE_STATS_REPLY_PACK_STR) ==
562 OFP_AGGREGATE_STATS_REPLY_SIZE)
564 # struct ofp_table_stats
565 OFP_TABLE_STATS_PACK_STR = '!B3xIQQ'
566 OFP_TABLE_STATS_SIZE = 24
567 assert calcsize(OFP_TABLE_STATS_PACK_STR) == OFP_TABLE_STATS_SIZE
569 # struct ofp_table_features
570 OFP_MAX_TABLE_NAME_LEN = 32
571 OFP_MAX_TABLE_NAME_LEN_STR = str(OFP_MAX_TABLE_NAME_LEN)
572 OFP_TABLE_FEATURES_PACK_STR = '!HB5x' + OFP_MAX_TABLE_NAME_LEN_STR + \
574 OFP_TABLE_FEATURES_SIZE = 64
575 assert (calcsize(OFP_TABLE_FEATURES_PACK_STR) ==
576 OFP_TABLE_FEATURES_SIZE)
578 # enum ofp_table_feature_prop_type
579 OFPTFPT_INSTRUCTIONS = 0
580 OFPTFPT_INSTRUCTIONS_MISS = 1
581 OFPTFPT_NEXT_TABLES = 2
582 OFPTFPT_NEXT_TABLES_MISS = 3
583 OFPTFPT_WRITE_ACTIONS = 4
584 OFPTFPT_WRITE_ACTIONS_MISS = 5
585 OFPTFPT_APPLY_ACTIONS = 6
586 OFPTFPT_APPLY_ACTIONS_MISS = 7
588 OFPTFPT_WILDCARDS = 10
589 OFPTFPT_WRITE_SETFIELD = 12
590 OFPTFPT_WRITE_SETFIELD_MISS = 13
591 OFPTFPT_APPLY_SETFIELD = 14
592 OFPTFPT_APPLY_SETFIELD_MISS = 15
593 OFPTFPT_EXPERIMENTER = 0xFFFE
594 OFPTFPT_EXPERIMENTER_MISS = 0xFFFF
596 # struct ofp_table_feature_prop_instructions
597 OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_PACK_STR = '!HH'
598 OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_SIZE = 4
599 assert (calcsize(OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_PACK_STR) ==
600 OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_SIZE)
602 # struct ofp_table_feature_prop_next_tables
603 OFP_TABLE_FEATURE_PROP_NEXT_TABLES_PACK_STR = '!HH'
604 OFP_TABLE_FEATURE_PROP_NEXT_TABLES_SIZE = 4
605 assert (calcsize(OFP_TABLE_FEATURE_PROP_NEXT_TABLES_PACK_STR) ==
606 OFP_TABLE_FEATURE_PROP_NEXT_TABLES_SIZE)
608 # struct ofp_table_feature_prop_actions
609 OFP_TABLE_FEATURE_PROP_ACTIONS_PACK_STR = '!HH'
610 OFP_TABLE_FEATURE_PROP_ACTIONS_SIZE = 4
611 assert (calcsize(OFP_TABLE_FEATURE_PROP_ACTIONS_PACK_STR) ==
612 OFP_TABLE_FEATURE_PROP_ACTIONS_SIZE)
614 # struct ofp_table_feature_prop_oxm
615 OFP_TABLE_FEATURE_PROP_OXM_PACK_STR = '!HH'
616 OFP_TABLE_FEATURE_PROP_OXM_SIZE = 4
617 assert (calcsize(OFP_TABLE_FEATURE_PROP_OXM_PACK_STR) ==
618 OFP_TABLE_FEATURE_PROP_OXM_SIZE)
620 # struct ofp_port_stats_request
621 OFP_PORT_STATS_REQUEST_PACK_STR = '!I4x'
622 OFP_PORT_STATS_REQUEST_SIZE = 8
623 assert (calcsize(OFP_PORT_STATS_REQUEST_PACK_STR) ==
624 OFP_PORT_STATS_REQUEST_SIZE)
626 # struct ofp_port_stats
627 OFP_PORT_STATS_PACK_STR = '!I4xQQQQQQQQQQQQII'
628 OFP_PORT_STATS_SIZE = 112
629 assert calcsize(OFP_PORT_STATS_PACK_STR) == OFP_PORT_STATS_SIZE
631 # struct ofp_queue_stats_request
632 OFP_QUEUE_STATS_REQUEST_PACK_STR = '!II'
633 OFP_QUEUE_STATS_REQUEST_SIZE = 8
634 assert (calcsize(OFP_QUEUE_STATS_REQUEST_PACK_STR) ==
635 OFP_QUEUE_STATS_REQUEST_SIZE)
637 # struct ofp_queue_stats
638 OFP_QUEUE_STATS_PACK_STR = '!IIQQQII'
639 OFP_QUEUE_STATS_SIZE = 40
640 assert calcsize(OFP_QUEUE_STATS_PACK_STR) == OFP_QUEUE_STATS_SIZE
642 # struct ofp_group_stats_request
643 OFP_GROUP_STATS_REQUEST_PACK_STR = '!I4x'
644 OFP_GROUP_STATS_REQUEST_SIZE = 8
645 assert (calcsize(OFP_GROUP_STATS_REQUEST_PACK_STR) ==
646 OFP_GROUP_STATS_REQUEST_SIZE)
648 # struct ofp_group_stats
649 OFP_GROUP_STATS_PACK_STR = '!H2xII4xQQII'
650 OFP_GROUP_STATS_SIZE = 40
651 assert calcsize(OFP_GROUP_STATS_PACK_STR) == OFP_GROUP_STATS_SIZE
653 # struct ofp_bucket_counter
654 OFP_BUCKET_COUNTER_PACK_STR = '!QQ'
655 OFP_BUCKET_COUNTER_SIZE = 16
656 assert calcsize(OFP_BUCKET_COUNTER_PACK_STR) == OFP_BUCKET_COUNTER_SIZE
658 # struct ofp_group_desc
659 OFP_GROUP_DESC_PACK_STR = '!HBxI'
660 OFP_GROUP_DESC_SIZE = 8
661 assert calcsize(OFP_GROUP_DESC_PACK_STR) == OFP_GROUP_DESC_SIZE
663 # struct ofp_group_desc_stats
664 OFP_GROUP_DESC_STATS_PACK_STR = OFP_GROUP_DESC_PACK_STR
665 OFP_GROUP_DESC_STATS_SIZE = OFP_GROUP_DESC_SIZE
666 assert calcsize(OFP_GROUP_DESC_STATS_PACK_STR) == OFP_GROUP_DESC_STATS_SIZE
668 # struct ofp_group_features
669 OFP_GROUP_FEATURES_PACK_STR = '!II4I4I'
670 OFP_GROUP_FEATURES_SIZE = 40
671 assert calcsize(OFP_GROUP_FEATURES_PACK_STR) == OFP_GROUP_FEATURES_SIZE
673 # enum ofp_group_capabilities
674 OFPGFC_SELECT_WEIGHT = 1 << 0 # Support weight for select groups.
675 OFPGFC_SELECT_LIVENESS = 1 << 1 # Support liveness for select groups.
676 OFPGFC_CHAINING = 1 << 2 # Support chaining groups.
677 OFPGFC_CHAINING_CHECKS = 1 << 3 # Check chaining for loops and delete
679 # struct ofp_meter_multipart_request
680 OFP_METER_MULTIPART_REQUEST_PACK_STR = '!I4x'
681 OFP_METER_MULTIPART_REQUEST_SIZE = 8
682 assert (calcsize(OFP_METER_MULTIPART_REQUEST_PACK_STR) ==
683 OFP_METER_MULTIPART_REQUEST_SIZE)
685 # struct ofp_meter_stats
686 OFP_METER_STATS_PACK_STR = '!IH6xIQQII'
687 OFP_METER_STATS_SIZE = 40
688 assert calcsize(OFP_METER_STATS_PACK_STR) == OFP_METER_STATS_SIZE
690 # struct ofp_meter_band_stats
691 OFP_METER_BAND_STATS_PACK_STR = '!QQ'
692 OFP_METER_BAND_STATS_SIZE = 16
693 assert (calcsize(OFP_METER_BAND_STATS_PACK_STR) ==
694 OFP_METER_BAND_STATS_SIZE)
696 # struct ofp_meter_config
697 OFP_METER_CONFIG_PACK_STR = '!HHI'
698 OFP_METER_CONFIG_SIZE = 8
699 assert calcsize(OFP_METER_CONFIG_PACK_STR) == OFP_METER_CONFIG_SIZE
701 # struct ofp_meter_features
702 OFP_METER_FEATURES_PACK_STR = '!IIIBB2x'
703 OFP_METER_FEATURES_SIZE = 16
704 assert (calcsize(OFP_METER_FEATURES_PACK_STR) ==
705 OFP_METER_FEATURES_SIZE)
707 # struct ofp_experimenter_multipart_header
708 OFP_EXPERIMENTER_MULTIPART_HEADER_PACK_STR = '!II'
709 OFP_EXPERIMENTER_MULTIPART_HEADER_SIZE = 8
710 assert (calcsize(OFP_EXPERIMENTER_MULTIPART_HEADER_PACK_STR) ==
711 OFP_EXPERIMENTER_MULTIPART_HEADER_SIZE)
713 # struct ofp_queue_get_config_request
714 OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR = '!I4x'
715 OFP_QUEUE_GET_CONFIG_REQUEST_SIZE = 16
716 assert (calcsize(OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR) +
717 OFP_HEADER_SIZE) == OFP_QUEUE_GET_CONFIG_REQUEST_SIZE
719 # struct ofp_queue_get_config_reply
720 OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR = '!I4x'
721 OFP_QUEUE_GET_CONFIG_REPLY_SIZE = 16
722 assert (calcsize(OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR) +
723 OFP_HEADER_SIZE) == OFP_QUEUE_GET_CONFIG_REPLY_SIZE
725 # struct ofp_packet_out
726 OFP_PACKET_OUT_PACK_STR = '!IIH6x'
727 OFP_PACKET_OUT_SIZE = 24
728 assert (calcsize(OFP_PACKET_OUT_PACK_STR) + OFP_HEADER_SIZE ==
731 # struct ofp_role_request
732 OFP_ROLE_REQUEST_PACK_STR = '!I4xQ'
733 OFP_ROLE_REQUEST_SIZE = 24
734 assert (calcsize(OFP_ROLE_REQUEST_PACK_STR) + OFP_HEADER_SIZE ==
735 OFP_ROLE_REQUEST_SIZE)
737 # enum ofp_controller_role
738 OFPCR_ROLE_NOCHANGE = 0 # Don't change current role.
739 OFPCR_ROLE_EQUAL = 1 # Default role, full access.
740 OFPCR_ROLE_MASTER = 2 # Full access, at most one master.
741 OFPCR_ROLE_SLAVE = 3 # Read-only access.
743 # struct ofp_async_config
744 OFP_ASYNC_CONFIG_PACK_STR = '!2I2I2I'
745 OFP_ASYNC_CONFIG_SIZE = 32
746 assert (calcsize(OFP_ASYNC_CONFIG_PACK_STR) + OFP_HEADER_SIZE ==
747 OFP_ASYNC_CONFIG_SIZE)
749 # struct ofp_packet_in
750 OFP_PACKET_IN_PACK_STR = '!IHBBQ'
751 OFP_PACKET_IN_SIZE = 32
752 assert (calcsize(OFP_PACKET_IN_PACK_STR) + OFP_MATCH_SIZE + OFP_HEADER_SIZE ==
755 # enum ofp_packet_in_reason
756 OFPR_NO_MATCH = 0 # No matching flow.
757 OFPR_ACTION = 1 # Action explicitly output to controller.
758 OFPR_INVALID_TTL = 2 # Packet has invalid TTL.
760 # struct ofp_flow_removed
761 _OFP_FLOW_REMOVED_PACK_STR0 = 'QHBBIIHHQQ'
762 OFP_FLOW_REMOVED_PACK_STR = '!' + _OFP_FLOW_REMOVED_PACK_STR0 + \
764 OFP_FLOW_REMOVED_PACK_STR0 = '!' + _OFP_FLOW_REMOVED_PACK_STR0
765 OFP_FLOW_REMOVED_SIZE = 56
766 assert (calcsize(OFP_FLOW_REMOVED_PACK_STR) + OFP_HEADER_SIZE ==
767 OFP_FLOW_REMOVED_SIZE)
769 # enum ofp_flow_removed_reason
770 OFPRR_IDLE_TIMEOUT = 0 # Flow idle time exceeded idle_timeout.
771 OFPRR_HARD_TIMEOUT = 1 # Time exceeded hard_timeout.
772 OFPRR_DELETE = 2 # Evicted by a DELETE flow mod.
773 OFPRR_GROUP_DELETE = 3 # Group was removed.
775 # struct ofp_port_status
776 OFP_PORT_STATUS_PACK_STR = '!B7x' + _OFP_PORT_PACK_STR
777 OFP_PORT_STATUS_DESC_OFFSET = OFP_HEADER_SIZE + 8
778 OFP_PORT_STATUS_SIZE = 80
779 assert (calcsize(OFP_PORT_STATUS_PACK_STR) + OFP_HEADER_SIZE ==
780 OFP_PORT_STATUS_SIZE)
782 # enum ofp_port_reason
783 OFPPR_ADD = 0 # The port was added.
784 OFPPR_DELETE = 1 # The port was removed.
785 OFPPR_MODIFY = 2 # Some attribute of the port has changed.
788 # struct onf_experimenter_multipart_msg
789 # (experimenter == ONF_EXPERIMENTER_ID)
790 ONFMP_FLOW_MONITOR = 1870
792 # EXT-187 seems to have a lot of flaws.
793 # XXX the spec mentions ONFST_FLOW_MONITOR in some places.
794 # we assume it's same as ONFMP_FLOW_MONITOR.
795 # XXX the spec uses OFPP_NONE. we assume it means OFPP_ANY.
796 # XXX onf_flow_update_full.length is commented to be 24.
797 # but it needs to tell the actual length of instructions.
798 # we assume it's variable.
799 # XXX the spec seems confused between instructions and actions
800 # for onf_flow_update_full/ONFFMF_ACTIONS. we assume they all
802 # XXX the spec does not define payload structures for any of
803 # ONFT_FLOW_MONITOR_CANCEL, ONFT_FLOW_MONITOR_PAUSED, or
804 # ONFT_FLOW_MONITOR_RESUMED. we assume they are same as NX.
805 # according to NX spec (OVS nicira-ext.h and ofp-msg.h):
806 # NXT_FLOW_MONITOR_CANCEL: a single u32 'id'.
807 # NXT_FLOW_MONITOR_PAUSED/RESUMED: empty payload
808 # (OF1.4 uses something different; OFPFMC_DELETE for CANCEL and
809 # OFPFME_ for PAUSED/RESUMED.)
810 # XXX onf_flow_monitor_request and onf_flow_update_full use
811 # match_len + oxm_fields instead of ofp_match. this pointless
812 # diverge from OF1.4 looks like a botch when updating from OF1.0.
813 # XXX the spec mentions "the current implementation of Open vSwitch"
814 # but, as of writing this, it doesn't have this extension implemented
815 # at all. we assume that it is about OF1.0 NX.
816 # XXX the spec mentions nx13_flow_monitor_request but i couldn't find
817 # it in OVS nicira-ext.h.
819 # onf_flow_monitor_request
820 # ONFMP_FLOW_MONITOR request's body is zero or more instances of this.
821 # id, flags, match_len, out_put, table_id, zeros[3]
822 ONF_FLOW_MONITOR_REQUEST_PACK_STR = '!IHHIB3x'
823 ONF_FLOW_MONITOR_REQUEST_SIZE = 16
824 assert (calcsize(ONF_FLOW_MONITOR_REQUEST_PACK_STR) ==
825 ONF_FLOW_MONITOR_REQUEST_SIZE)
827 # onf_flow_monitor_request.flags
828 ONFFMF_INITIAL = 1 << 0
830 ONFFMF_DELETE = 1 << 2
831 ONFFMF_MODIFY = 1 << 3
832 ONFFMF_ACTIONS = 1 << 4
835 # onf_flow_update_header
836 # ONFMP_FLOW_MONITOR request's body is an array of this
838 ONF_FLOW_UPDATE_HEADER_PACK_STR = '!HH'
839 ONF_FLOW_UPDATE_HEADER_SIZE = 4
840 assert (calcsize(ONF_FLOW_UPDATE_HEADER_PACK_STR) ==
841 ONF_FLOW_UPDATE_HEADER_SIZE)
843 # onf_flow_update_full, excluding onf_flow_update_header
844 # reason, priority, idle_timeout, hard_timeout, match_len, table_id,
846 ONF_FLOW_UPDATE_FULL_PACK_STR = '!HHHHHBxQ'
847 ONF_FLOW_UPDATE_FULL_SIZE = 24 - ONF_FLOW_UPDATE_HEADER_SIZE
848 assert (calcsize(ONF_FLOW_UPDATE_FULL_PACK_STR) ==
849 ONF_FLOW_UPDATE_FULL_SIZE)
851 # onf_flow_update_abbrev, excluding onf_flow_update_header
853 ONF_FLOW_UPDATE_ABBREV_PACK_STR = '!I'
854 ONF_FLOW_UPDATE_ABBREV_SIZE = 8 - ONF_FLOW_UPDATE_HEADER_SIZE
855 assert (calcsize(ONF_FLOW_UPDATE_ABBREV_PACK_STR) ==
856 ONF_FLOW_UPDATE_ABBREV_SIZE)
858 # enum onf_flow_udpate_event
859 ONFFME_ADDED = 0 # some variations in the spec; ONFMFE_ADD, ONFFME_ADD
864 # enum onf_flow_monitor_msg_type
865 ONFT_FLOW_MONITOR_CANCEL = 1870 # controller -> switch
866 ONFT_FLOW_MONITOR_PAUSED = 1871 # switch -> controller
867 ONFT_FLOW_MONITOR_RESUMED = 1872 # switch -> controller
869 # EXT-230 Bundle extension
872 ONF_ET_BUNDLE_CONTROL = 2300
873 ONF_ET_BUNDLE_ADD_MESSAGE = 2301
875 ONF_BUNDLE_CTRL_PACK_STR = '!IHH'
876 ONF_BUNDLE_CTRL_SIZE = 8
877 assert (calcsize(ONF_BUNDLE_CTRL_PACK_STR) ==
878 ONF_BUNDLE_CTRL_SIZE)
880 ONF_BUNDLE_ADD_MSG_PACK_STR = '!I2xH'
881 ONF_BUNDLE_ADD_MSG_SIZE = 16 - OFP_HEADER_SIZE
882 assert (calcsize(ONF_BUNDLE_ADD_MSG_PACK_STR) ==
883 ONF_BUNDLE_ADD_MSG_SIZE)
885 # enum onf_bundle_ctrl_type
886 ONF_BCT_OPEN_REQUEST = 0
887 ONF_BCT_OPEN_REPLY = 1
888 ONF_BCT_CLOSE_REQUEST = 2
889 ONF_BCT_CLOSE_REPLY = 3
890 ONF_BCT_COMMIT_REQUEST = 4
891 ONF_BCT_COMMIT_REPLY = 5
892 ONF_BCT_DISCARD_REQUEST = 6
893 ONF_BCT_DISCARD_REPLY = 7
895 # enum onf_bundle_flags
896 ONF_BF_ATOMIC = 1 << 0
897 ONF_BF_ORDERED = 1 << 1
899 # enum onf_bundle_prop_type
900 ONF_ET_BPT_EXPERIMENTER = 0xffff
902 # struct ofp_error_msg
903 OFP_ERROR_MSG_PACK_STR = '!HH'
904 OFP_ERROR_MSG_SIZE = 12
905 assert (calcsize(OFP_ERROR_MSG_PACK_STR) + OFP_HEADER_SIZE ==
908 # enum ofp_error_type
909 OFPET_HELLO_FAILED = 0 # Hello protocol failed.
910 OFPET_BAD_REQUEST = 1 # Request was not understood.
911 OFPET_BAD_ACTION = 2 # Error in action description.
912 OFPET_BAD_INSTRUCTION = 3 # Error in instruction list.
913 OFPET_BAD_MATCH = 4 # Error in match.
914 OFPET_FLOW_MOD_FAILED = 5 # Problem modifying flow entry.
915 OFPET_GROUP_MOD_FAILED = 6 # Problem modifying group entry.
916 OFPET_PORT_MOD_FAILED = 7 # OFPT_PORT_MOD failed.
917 OFPET_TABLE_MOD_FAILED = 8 # Table mod request failed.
918 OFPET_QUEUE_OP_FAILED = 9 # Queue operation failed.
919 OFPET_SWITCH_CONFIG_FAILED = 10 # Switch config request failed.
920 OFPET_ROLE_REQUEST_FAILED = 11 # Controller Role request failed.
921 OFPET_METER_MOD_FAILED = 12 # Error in meter.
922 OFPET_TABLE_FEATURES_FAILED = 13 # Setting table features failed.
923 OFPET_EXPERIMENTER = 0xffff # Experimenter error messages.
925 # enum ofp_hello_failed_code
926 OFPHFC_INCOMPATIBLE = 0 # No compatible version.
927 OFPHFC_EPERM = 1 # Permissions error.
929 # enum ofp_bad_request_code
930 OFPBRC_BAD_VERSION = 0 # ofp_header.version not supported.
931 OFPBRC_BAD_TYPE = 1 # ofp_header.type not supported.
932 OFPBRC_BAD_MULTIPART = 2 # ofp_multipart_request.type not
934 OFPBRC_BAD_EXPERIMENTER = 3 # Experimenter id not supported
935 # (in ofp_experimenter_header
936 # or ofp_multipart_request or
937 # ofp_multipart_reply).
938 OFPBRC_BAD_EXP_TYPE = 4 # Experimenter type not supported.
939 OFPBRC_EPERM = 5 # Permissions error.
940 OFPBRC_BAD_LEN = 6 # Wrong request length for type.
941 OFPBRC_BUFFER_EMPTY = 7 # Specified buffer has already been
943 OFPBRC_BUFFER_UNKNOWN = 8 # Specified buffer does not exist.
944 OFPBRC_BAD_TABLE_ID = 9 # Specified table-id invalid or does
946 OFPBRC_IS_SLAVE = 10 # Denied because controller is slave.
947 OFPBRC_BAD_PORT = 11 # Invalid port.
948 OFPBRC_BAD_PACKET = 12 # Invalid packet in packet-out
949 OFPBRC_MULTIPART_BUFFER_OVERFLOW = 13 # ofp_multipart_request
950 # overflowed the assigned buffer.
952 # enum ofp_bad_action_code
953 OFPBAC_BAD_TYPE = 0 # Unknown action type.
954 OFPBAC_BAD_LEN = 1 # Length problem in actions.
955 OFPBAC_BAD_EXPERIMENTER = 2 # Unknown experimenter id specified.
956 OFPBAC_BAD_EXP_TYPE = 3 # Unknown action type for experimenter id.
957 OFPBAC_BAD_OUT_PORT = 4 # Problem validating output action.
958 OFPBAC_BAD_ARGUMENT = 5 # Bad action argument.
959 OFPBAC_EPERM = 6 # Permissions error.
960 OFPBAC_TOO_MANY = 7 # Can't handle this many actions.
961 OFPBAC_BAD_QUEUE = 8 # Problem validating output queue.
962 OFPBAC_BAD_OUT_GROUP = 9 # Invalid group id in forward action.
963 OFPBAC_MATCH_INCONSISTENT = 10 # Action can't apply for this match,
964 # or Set-Field missing prerequisite.
965 OFPBAC_UNSUPPORTED_ORDER = 11 # Action order is unsupported for
966 # the action list in an Apply-Actions
968 OFPBAC_BAD_TAG = 12 # Actions uses an unsupported tag/encap.
969 OFPBAC_BAD_SET_TYPE = 13 # Unsupported type in SET_FIELD action.
970 OFPBAC_BAD_SET_LEN = 14 # Length problem in SET_FIELD action.
971 OFPBAC_BAD_SET_ARGUMENT = 15 # Bad arguement in SET_FIELD action.
973 # enum ofp_bad_instruction_code
974 OFPBIC_UNKNOWN_INST = 0 # Unknown instruction.
975 OFPBIC_UNSUP_INST = 1 # Switch or table does not support
977 OFPBIC_BAD_TABLE_ID = 2 # Invalid Table-Id specified
978 OFPBIC_UNSUP_METADATA = 3 # Metadata value unsupported by datapath.
979 OFPBIC_UNSUP_METADATA_MASK = 4 # Metadata mask value unsupported by
981 OFPBIC_BAD_EXPERIMENTER = 5 # Unknown experimenter id specified.
982 OFPBIC_BAD_EXP_TYPE = 6 # Unknown instruction for experimenter id.
983 OFPBIC_BAD_LEN = 7 # Length problem in instrucitons.
984 OFPBIC_EPERM = 8 # Permissions error.
986 # enum ofp_bad_match_code
987 OFPBMC_BAD_TYPE = 0 # Unsupported match type apecified by
989 OFPBMC_BAD_LEN = 1 # Length problem in math.
990 OFPBMC_BAD_TAG = 2 # Match uses an unsupported tag/encap.
991 OFPBMC_BAD_DL_ADDR_MASK = 3 # Unsupported datalink addr mask -
992 # switch does not support arbitrary
993 # datalink address mask.
994 OFPBMC_BAD_NW_ADDR_MASK = 4 # Unsupported network addr mask -
995 # switch does not support arbitrary
996 # network addres mask.
997 OFPBMC_BAD_WILDCARDS = 5 # Unsupported combination of fields
998 # masked or omitted in the match.
999 OFPBMC_BAD_FIELD = 6 # Unsupported field type in the match.
1000 OFPBMC_BAD_VALUE = 7 # Unsupported value in a match field.
1001 OFPBMC_BAD_MASK = 8 # Unsupported mask specified in the
1003 OFPBMC_BAD_PREREQ = 9 # A prerequisite was not met.
1004 OFPBMC_DUP_FIELD = 10 # A field type was duplicated.
1005 OFPBMC_EPERM = 11 # Permissions error.
1007 # enum ofp_flow_mod_failed_code
1008 OFPFMFC_UNKNOWN = 0 # Unspecified error.
1009 OFPFMFC_TABLE_FULL = 1 # Flow not added because table was full.
1010 OFPFMFC_BAD_TABLE_ID = 2 # Table does not exist
1011 OFPFMFC_OVERLAP = 3 # Attempted to add overlapping flow
1012 # with CHECK_OVERLAP flag set.
1013 OFPFMFC_EPERM = 4 # Permissions error.
1014 OFPFMFC_BAD_TIMEOUT = 5 # Flow not added because of
1015 # unsupported idle/hard timeout.
1016 OFPFMFC_BAD_COMMAND = 6 # Unsupported or unknown command.
1017 OFPFMFC_BAD_FLAGS = 7 # Unsupported or unknown flags.
1019 # enum ofp_group_mod_failed_code
1020 OFPGMFC_GROUP_EXISTS = 0
1021 OFPGMFC_INVALID_GROUP = 1
1022 OFPGMFC_WEIGHT_UNSUPPORTED = 2 # Switch does not support unequal load
1023 # sharing with select groups.
1024 OFPGMFC_OUT_OF_GROUPS = 3 # The group table is full.
1025 OFPGMFC_OUT_OF_BUCKETS = 4 # The maximum number of action buckets
1026 # for a group has been exceeded.
1027 OFPGMFC_CHAINING_UNSUPPORTED = 5 # Switch does not support groups that
1028 # forward to groups.
1029 OFPGMFC_WATCH_UNSUPPORTED = 6 # This group cannot watch the
1030 # watch_port or watch_group specified.
1031 OFPGMFC_LOOP = 7 # Group entry would cause a loop.
1032 OFPGMFC_UNKNOWN_GROUP = 8 # Group not modified because a group
1033 # MODIFY attempted to modify a
1034 # non-existent group.
1035 OFPGMFC_CHAINED_GROUP = 9 # Group not deleted because another
1036 # group is forwarding to it.
1037 OFPGMFC_BAD_TYPE = 10 # Unsupported or unknown group type.
1038 OFPGMFC_BAD_COMMAND = 11 # Unsupported or unknown command.
1039 OFPGMFC_BAD_BUCKET = 12 # Error in bucket.
1040 OFPGMFC_BAD_WATCH = 13 # Error in watch port/group.
1041 OFPGMFC_EPERM = 14 # Permissions error.
1043 # enum ofp_port_mod_failed_code
1044 OFPPMFC_BAD_PORT = 0 # Specified port does not exist.
1045 OFPPMFC_BAD_HW_ADDR = 1 # Specified hardware address does not
1046 # match the port number.
1047 OFPPMFC_BAD_CONFIG = 2 # Specified config is invalid.
1048 OFPPMFC_BAD_ADVERTISE = 3 # Specified advertise is invalid.
1049 OFPPMFC_EPERM = 4 # Permissions error.
1051 # enum ofp_table_mod_failed_code
1052 OFPTMFC_BAD_TABLE = 0 # Specified table does not exist.
1053 OFPTMFC_BAD_CONFIG = 1 # Specified config is invalid.
1054 OFPTMFC_EPERM = 2 # Permissions error
1056 # enum ofp_queue_op_failed_code
1057 OFPQOFC_BAD_PORT = 0 # Invalid port (or port does not exist).
1058 OFPQOFC_BAD_QUEUE = 1 # Queue does not exist.
1059 OFPQOFC_EPERM = 2 # Permissions error.
1061 # enum ofp_switch_config_failed_code
1062 OFPSCFC_BAD_FLAGS = 0 # Specified flags is invalid.
1063 OFPSCFC_BAD_LEN = 1 # Specified len is invalid.
1064 OFPQCFC_EPERM = 2 # Permissions error (depracated).
1065 # New or updated Ryu applications shall use
1066 # OFPSCFC_EPERM. The variable name is a typo of
1067 # in specifications before v1.3.1 (EXT-208).
1068 OFPSCFC_EPERM = 2 # Permissions error.
1070 # enum ofp_role_request_failed_code
1071 OFPRRFC_STALE = 0 # Stale Message: old generation_id.
1072 OFPRRFC_UNSUP = 1 # Controller role change unsupported.
1073 OFPRRFC_BAD_ROLE = 2 # Invalid role.
1075 # enum ofp_meter_mod_failed_code
1076 OFPMMFC_UNKNOWN = 0 # Unspecified error.
1077 OFPMMFC_METER_EXISTS = 1 # Meter not added because a Meter ADD
1078 # attempted to replace an existing Meter.
1079 OFPMMFC_INVALID_METER = 2 # Meter not added because Meter specified
1081 OFPMMFC_UNKNOWN_METER = 3 # Meter not modified because a Meter
1082 # MODIFY attempted to modify a non-existent
1084 OFPMMFC_BAD_COMMAND = 4 # Unsupported or unknown command.
1085 OFPMMFC_BAD_FLAGS = 5 # Flag configuration unsupported.
1086 OFPMMFC_BAD_RATE = 6 # Rate unsupported.
1087 OFPMMFC_BAD_BURST = 7 # Burst size unsupported.
1088 OFPMMFC_BAD_BAND = 8 # Band unsupported.
1089 OFPMMFC_BAD_BAND_VALUE = 9 # Band value unsupported.
1090 OFPMMFC_OUT_OF_METERS = 10 # No more meters availabile.
1091 OFPMMFC_OUT_OF_BANDS = 11 # The maximum number of properties
1092 # for a meter has been exceeded.
1094 # enum ofp_table_features_failed_code
1095 OFPTFFC_BAD_TABLE = 0 # Specified table does not exist.
1096 OFPTFFC_BAD_METADATA = 1 # Invalid metadata mask.
1097 OFPTFFC_BAD_TYPE = 2 # Unknown property type.
1098 OFPTFFC_BAD_LEN = 3 # Length problem in properties.
1099 OFPTFFC_BAD_ARGUMENT = 4 # Unsupported property value.
1100 OFPTFFC_EPERM = 5 # Permissions error.
1102 # struct ofp_error_experimenter_msg
1103 OFP_ERROR_EXPERIMENTER_MSG_PACK_STR = '!HHI'
1104 OFP_ERROR_EXPERIMENTER_MSG_SIZE = 16
1105 assert (calcsize(OFP_ERROR_EXPERIMENTER_MSG_PACK_STR) +
1106 OFP_HEADER_SIZE) == OFP_ERROR_EXPERIMENTER_MSG_SIZE
1108 # struct ofp_experimenter_header
1109 OFP_EXPERIMENTER_HEADER_PACK_STR = '!II'
1110 OFP_EXPERIMENTER_HEADER_SIZE = 16
1111 assert (calcsize(OFP_EXPERIMENTER_HEADER_PACK_STR) + OFP_HEADER_SIZE
1112 == OFP_EXPERIMENTER_HEADER_SIZE)
1114 # exp_type values for OFPET_EXPERIMENTER (experimenter=ONF_EXPERIMENTER_ID)
1115 ONFERR_ET_UNKNOWN = 2300
1116 ONFERR_ET_EPERM = 2301
1117 ONFERR_ET_BAD_ID = 2302
1118 ONFERR_ET_BUNDLE_EXIST = 2303
1119 ONFERR_ET_BUNDLE_CLOSED = 2304
1120 ONFERR_ET_OUT_OF_BUNDLES = 2305
1121 ONFERR_ET_BAD_TYPE = 2306
1122 ONFERR_ET_BAD_FLAGS = 2307
1123 ONFERR_ET_MSG_BAD_LEN = 2308
1124 ONFERR_ET_MSG_BAD_XID = 2309
1125 ONFERR_ET_MSG_UNSUP = 2310
1126 ONFERR_ET_MSG_CONFLICT = 2311
1127 ONFERR_ET_MSG_TOO_MANY = 2312
1128 ONFERR_ET_FAILED = 2313
1129 ONFERR_ET_TIMEOUT = 2314
1130 ONFERR_ET_BUNDLE_IN_PROGRESS = 2315
1131 ONFERR_ET_CANT_SYNC = 2320
1132 ONFERR_ET_BAD_PRIORITY = 2360
1133 ONFERR_ET_ASYNC_INVALUD = 2370
1134 ONFERR_ET_ASYNC_UNSUPPORTED = 2371
1135 ONFERR_ET_ASYNC_EPERM = 2372
1136 ONFERR_DUP_INSTRUCTION = 2600 # the lack of _ET_ is per spec
1137 ONFERR_ET_MPART_REQUEST_TIMEOUT = 2640
1138 ONFERR_ET_MPART_REPLY_TIMEOUT = 2641
1141 OFP_HELLO_HEADER_SIZE = 8
1143 # struct ofp_hello_elem_header
1144 OFP_HELLO_ELEM_HEADER_PACK_STR = '!HH'
1145 OFP_HELLO_ELEM_HEADER_SIZE = 4
1146 assert (calcsize(OFP_HELLO_ELEM_HEADER_PACK_STR) == OFP_HELLO_ELEM_HEADER_SIZE)
1148 # enum ofp_hello_elem_type
1149 OFPHET_VERSIONBITMAP = 1
1151 # struct ofp_hello_elem_versionbitmap
1152 OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_PACK_STR = '!HH'
1153 OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_SIZE = 4
1154 assert (calcsize(OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_PACK_STR) ==
1155 OFP_HELLO_ELEM_VERSIONBITMAP_HEADER_SIZE)
1160 def _oxm_tlv_header(class_, field, hasmask, length):
1161 return (class_ << 16) | (field << 9) | (hasmask << 8) | length
1164 def oxm_tlv_header(field, length):
1165 return _oxm_tlv_header(OFPXMC_OPENFLOW_BASIC, field, 0, length)
1168 def oxm_tlv_header_w(field, length):
1169 return _oxm_tlv_header(OFPXMC_OPENFLOW_BASIC, field, 1, length * 2)
1172 def oxm_tlv_header_extract_hasmask(header):
1173 return (header >> 8) & 1
1176 def oxm_tlv_header_extract_length(header):
1177 if oxm_tlv_header_extract_hasmask(header):
1178 length = (header & 0xff) // 2
1180 length = header & 0xff
1185 oxm_fields.OpenFlowBasic('in_port', 0, type_desc.Int4),
1186 oxm_fields.OpenFlowBasic('in_phy_port', 1, type_desc.Int4),
1187 oxm_fields.OpenFlowBasic('metadata', 2, type_desc.Int8),
1188 oxm_fields.OpenFlowBasic('eth_dst', 3, type_desc.MacAddr),
1189 oxm_fields.OpenFlowBasic('eth_src', 4, type_desc.MacAddr),
1190 oxm_fields.OpenFlowBasic('eth_type', 5, type_desc.Int2),
1191 oxm_fields.OpenFlowBasic('vlan_vid', 6, type_desc.Int2),
1192 oxm_fields.OpenFlowBasic('vlan_pcp', 7, type_desc.Int1),
1193 oxm_fields.OpenFlowBasic('ip_dscp', 8, type_desc.Int1),
1194 oxm_fields.OpenFlowBasic('ip_ecn', 9, type_desc.Int1),
1195 oxm_fields.OpenFlowBasic('ip_proto', 10, type_desc.Int1),
1196 oxm_fields.OpenFlowBasic('ipv4_src', 11, type_desc.IPv4Addr),
1197 oxm_fields.OpenFlowBasic('ipv4_dst', 12, type_desc.IPv4Addr),
1198 oxm_fields.OpenFlowBasic('tcp_src', 13, type_desc.Int2),
1199 oxm_fields.OpenFlowBasic('tcp_dst', 14, type_desc.Int2),
1200 oxm_fields.OpenFlowBasic('udp_src', 15, type_desc.Int2),
1201 oxm_fields.OpenFlowBasic('udp_dst', 16, type_desc.Int2),
1202 oxm_fields.OpenFlowBasic('sctp_src', 17, type_desc.Int2),
1203 oxm_fields.OpenFlowBasic('sctp_dst', 18, type_desc.Int2),
1204 oxm_fields.OpenFlowBasic('icmpv4_type', 19, type_desc.Int1),
1205 oxm_fields.OpenFlowBasic('icmpv4_code', 20, type_desc.Int1),
1206 oxm_fields.OpenFlowBasic('arp_op', 21, type_desc.Int2),
1207 oxm_fields.OpenFlowBasic('arp_spa', 22, type_desc.IPv4Addr),
1208 oxm_fields.OpenFlowBasic('arp_tpa', 23, type_desc.IPv4Addr),
1209 oxm_fields.OpenFlowBasic('arp_sha', 24, type_desc.MacAddr),
1210 oxm_fields.OpenFlowBasic('arp_tha', 25, type_desc.MacAddr),
1211 oxm_fields.OpenFlowBasic('ipv6_src', 26, type_desc.IPv6Addr),
1212 oxm_fields.OpenFlowBasic('ipv6_dst', 27, type_desc.IPv6Addr),
1213 oxm_fields.OpenFlowBasic('ipv6_flabel', 28, type_desc.Int4),
1214 oxm_fields.OpenFlowBasic('icmpv6_type', 29, type_desc.Int1),
1215 oxm_fields.OpenFlowBasic('icmpv6_code', 30, type_desc.Int1),
1216 oxm_fields.OpenFlowBasic('ipv6_nd_target', 31, type_desc.IPv6Addr),
1217 oxm_fields.OpenFlowBasic('ipv6_nd_sll', 32, type_desc.MacAddr),
1218 oxm_fields.OpenFlowBasic('ipv6_nd_tll', 33, type_desc.MacAddr),
1219 oxm_fields.OpenFlowBasic('mpls_label', 34, type_desc.Int4),
1220 oxm_fields.OpenFlowBasic('mpls_tc', 35, type_desc.Int1),
1221 oxm_fields.OpenFlowBasic('mpls_bos', 36, type_desc.Int1),
1222 oxm_fields.OpenFlowBasic('pbb_isid', 37, type_desc.Int3),
1223 oxm_fields.OpenFlowBasic('tunnel_id', 38, type_desc.Int8),
1224 oxm_fields.OpenFlowBasic('ipv6_exthdr', 39, type_desc.Int2),
1225 # EXT-256 Old version of ONF Extension
1226 oxm_fields.OldONFExperimenter('pbb_uca', 2560, type_desc.Int1),
1227 # EXT-109 TCP flags match field Extension
1228 oxm_fields.ONFExperimenter('tcp_flags', 42, type_desc.Int2),
1229 # EXT-233 Output match Extension
1230 # NOTE(yamamoto): The spec says uint64_t but I assume it's an error.
1231 oxm_fields.ONFExperimenter('actset_output', 43, type_desc.Int4),
1232 ] + nicira_ext.oxm_types
1234 oxm_fields.generate(__name__)
1237 # Note: struct ofp_prop_experimenter is specific to this implementation.
1238 # It does not have a corresponding structure in the specification.
1239 # This structure defines common structure for ofp_*_prop_experimenter.
1240 # struct ofp_prop_experimenter
1241 OFP_PROP_EXPERIMENTER_PACK_STR = '!HHII'
1242 OFP_PROP_EXPERIMENTER_SIZE = 12
1243 assert (calcsize(OFP_PROP_EXPERIMENTER_PACK_STR) ==
1244 OFP_PROP_EXPERIMENTER_SIZE)
1246 # generate utility methods
1247 ofproto_utils.generate(__name__)
1252 MAX_XID = 0xffffffff
1254 OFP_NO_BUFFER = 0xffffffff