diff options
author | OHMURA Kei <ohmura.kei@lab.ntt.co.jp> | 2012-06-23 07:37:25 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-06-23 08:30:36 +0900 |
commit | 40e378ae11531b240277760a91797152c1a78ec8 (patch) | |
tree | b9afe9c03ed6a22cbb50b50a7b6d31b4bee55eba | |
parent | 24410d4482a0515fb21de1a91a491d5845e7a5e0 (diff) |
of1.3: initial OF1.3 support
Signed-off-by: OHMURA Kei <ohmura.kei@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_3.py | 1009 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_v1_3_parser.py | 1568 |
2 files changed, 2577 insertions, 0 deletions
diff --git a/ryu/ofproto/ofproto_v1_3.py b/ryu/ofproto/ofproto_v1_3.py new file mode 100644 index 00000000..b5008e6f --- /dev/null +++ b/ryu/ofproto/ofproto_v1_3.py @@ -0,0 +1,1009 @@ +# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2012 Isaku Yamahata <yamahata at valinux co jp> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from struct import calcsize + +# struct ofp_header +OFP_HEADER_PACK_STR = '!BBHI' +OFP_HEADER_SIZE = 8 +assert calcsize(OFP_HEADER_PACK_STR) == OFP_HEADER_SIZE + +# enum ofp_type +OFPT_HELLO = 0 # Symmetric message +OFPT_ERROR = 1 # Symmetric message +OFPT_ECHO_REQUEST = 2 # Symmetric message +OFPT_ECHO_REPLY = 3 # Symmetric message +OFPT_EXPERIMENTER = 4 # Symmetric message + +OFPT_FEATURES_REQUEST = 5 # Controller/switch message +OFPT_FEATURES_REPLY = 6 # Controller/switch message +OFPT_GET_CONFIG_REQUEST = 7 # Controller/switch message +OFPT_GET_CONFIG_REPLY = 8 # Controller/switch message +OFPT_SET_CONFIG = 9 # Controller/switch message + +OFPT_PACKET_IN = 10 # Async message +OFPT_FLOW_REMOVED = 11 # Async message +OFPT_PORT_STATUS = 12 # Async message + +OFPT_PACKET_OUT = 13 # Controller/switch message +OFPT_FLOW_MOD = 14 # Controller/switch message +OFPT_GROUP_MOD = 15 # Controller/switch message +OFPT_PORT_MOD = 16 # Controller/switch message +OFPT_TABLE_MOD = 17 # Controller/switch message + +OFPT_MULTIPART_REQUEST = 18 # Controller/switch message +OFPT_MULTIPART_REPLY = 19 # Controller/switch message + +OFPT_BARRIER_REQUEST = 20 # Controller/switch message +OFPT_BARRIER_REPLY = 21 # Controller/switch message +OFPT_QUEUE_GET_CONFIG_REQUEST = 22 # Controller/switch message +OFPT_QUEUE_GET_CONFIG_REPLY = 23 # Controller/switch message + +OFPT_ROLE_REQUEST = 24 # Controller/switch message +OFPT_ROLE_REPLY = 25 # Controller/switch message + +OFPT_GET_ASYNC_REQUEST = 26 # Controller/switch message +OFPT_GET_ASYNC_REPLY = 27 # Controller/switch message +OFPT_GET_ASYNC = 28 # Controller/switch message + +OFPT_METER_MOD = 29 # Controller/switch message + +# struct ofp_port +OFP_MAX_PORT_NAME_LEN = 16 +OFP_ETH_ALEN = 6 +OFP_ETH_ALEN_STR = str(OFP_ETH_ALEN) +_OFP_PORT_PACK_STR = 'I4x' + OFP_ETH_ALEN_STR + 'B' + '2x' + \ + str(OFP_MAX_PORT_NAME_LEN) + 's' + 'IIIIIIII' +OFP_PORT_PACK_STR = '!' + _OFP_PORT_PACK_STR +OFP_PORT_SIZE = 64 +assert calcsize(OFP_PORT_PACK_STR) == OFP_PORT_SIZE + +# enum ofp_port_config +OFPPC_PORT_DOWN = 1 << 0 # Port is administratively down. +OFPPC_NO_RECV = 1 << 2 # Drop all packets recieved by port. +OFPPC_NO_FWD = 1 << 5 # Drop packets forwarded to port. +OFPPC_NO_PACKET_IN = 1 << 6 # Do not send packet-in msgs for port. + +# enum ofp_port_state +OFPPS_LINK_DOWN = 1 << 0 # No physical link present. +OFPPS_BLOCKED = 1 << 1 # Port is blocked. +OFPPS_LIVE = 1 << 2 # Live for Fast Failover Group. + +# enum ofp_port_no +OFPP_MAX = 0xffffff00 +OFPP_IN_PORT = 0xfffffff8 # Send the packet out the input port. This + # virtual port must be explicitly used + # in order to send back out of the input + # port. +OFPP_TABLE = 0xfffffff9 # Perform actions in flow table. + # NB: This can only be the destination + # port for packet-out messages. +OFPP_NORMAL = 0xfffffffa # Process with normal L2/L3 switching. +OFPP_FLOOD = 0xfffffffb # All physical ports except input port and + # those disabled by STP. +OFPP_ALL = 0xfffffffc # All physical ports except input port. +OFPP_CONTROLLER = 0xfffffffd # Send to controller. +OFPP_LOCAL = 0xfffffffe # Local openflow "port". +OFPP_ANY = 0xffffffff # Not associated with a physical port. + +# enum ofp_port_features +OFPPF_10MB_HD = 1 << 0 # 10 Mb half-duplex rate support. +OFPPF_10MB_FD = 1 << 1 # 10 Mb full-duplex rate support. +OFPPF_100MB_HD = 1 << 2 # 100 Mb half-duplex rate support. +OFPPF_100MB_FD = 1 << 3 # 100 Mb full-duplex rate support. +OFPPF_1GB_HD = 1 << 4 # 1 Gb half-duplex rate support. +OFPPF_1GB_FD = 1 << 5 # 1 Gb full-duplex rate support. +OFPPF_10GB_FD = 1 << 6 # 10 Gb full-duplex rate support. +OFPPF_40GB_FD = 1 << 7 # 40 Gb full-duplex rate support. +OFPPF_100GB_FD = 1 << 8 # 100 Gb full-duplex rate support. +OFPPF_1TB_FD = 1 << 9 # 1 Tb full-duplex rate support. +OFPPF_OTHER = 1 << 10 # Other rate, not in the list. +OFPPF_COPPER = 1 << 11 # Copper medium. +OFPPF_FIBER = 1 << 12 # Fiber medium. +OFPPF_AUTONEG = 1 << 13 # Auto-negotiation. +OFPPF_PAUSE = 1 << 14 # Pause. +OFPPF_PAUSE_ASYM = 1 << 15 # Asymmetric pause. + +# struct ofp_packet_queue +OFP_PACKET_QUEUE_PACK_STR = '!IIH6x' +OFP_PACKET_QUEUE_SIZE = 16 +assert calcsize(OFP_PACKET_QUEUE_PACK_STR) == OFP_PACKET_QUEUE_SIZE + +# enum ofp_queue_properties +OFPQT_MIN_RATE = 1 # Minimum datarate guaranteed. +OFPQT_MAX_RATE = 2 # Maximum datarate. +OFPQT_EXPERIMENTER = 0xffff # Experimenter defined property. + +# struct ofp_queue_prop_header +OFP_QUEUE_PROP_HEADER_PACK_STR = '!HH4x' +OFP_QUEUE_PROP_HEADER_SIZE = 8 +assert calcsize(OFP_QUEUE_PROP_HEADER_PACK_STR) == OFP_QUEUE_PROP_HEADER_SIZE + +# struct ofp_queue_prop_min_rate +OFP_QUEUE_PROP_MIN_RATE_PACK_STR = '!H6x' +OFP_QUEUE_PROP_MIN_RATE_SIZE = 16 +assert (calcsize(OFP_QUEUE_PROP_MIN_RATE_PACK_STR) + + OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_MIN_RATE_SIZE + +# struct ofp_queue_prop_max_rate +OFP_QUEUE_PROP_MAX_RATE_PACK_STR = '!H6x' +OFP_QUEUE_PROP_MAX_RATE_SIZE = 16 +assert (calcsize(OFP_QUEUE_PROP_MAX_RATE_PACK_STR) + + OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_MAX_RATE_SIZE + +# struct ofp_queue_prop_experimenter +OFP_QUEUE_PROP_EXPERIMENTER_PACK_STR = '!I4x' +OFP_QUEUE_PROP_EXPERIMENTER_SIZE = 16 +assert (calcsize(OFP_QUEUE_PROP_EXPERIMENTER_PACK_STR) + + OFP_QUEUE_PROP_HEADER_SIZE) == OFP_QUEUE_PROP_EXPERIMENTER_SIZE + +# struct ofp_match +_OFP_MATCH_PACK_STR = 'HHBBBB' +OFP_MATCH_PACK_STR = '!' + _OFP_MATCH_PACK_STR +OFP_MATCH_SIZE = 8 +assert calcsize(OFP_MATCH_PACK_STR) == OFP_MATCH_SIZE + +# enum ofp_match_type +OFPMT_STANDARD = 0 # Deprecated +OFPMT_OXM = 1 # OpenFlow Extensible Match + +# enum ofp_oxm_class +OFPXMC_NXM_0 = 0x0000 # Backward compatibility with NXM +OFPXMC_NXM_1 = 0x0001 # Backward compatibility with NXM +OFPXMC_OPENFLOW_BASIC = 0x8000 # Basic class for OpenFlow +OFPXMC_EXPERIMENTER = 0xFFFF # Experimenter class + +# enmu oxm_ofb_match_fields +OFPXMT_OFB_IN_PORT = 0 # Switch input port. +OFPXMT_OFB_IN_PHY_PORT = 1 # Switch physical input port. +OFPXMT_OFB_METADATA = 2 # Metadata passed between tables. +OFPXMT_OFB_ETH_DST = 3 # Ethernet destination address. +OFPXMT_OFB_ETH_SRC = 4 # Ethernet source address. +OFPXMT_OFB_ETH_TYPE = 5 # Ethernet frame type. +OFPXMT_OFB_VLAN_VID = 6 # VLAN id. +OFPXMT_OFB_VLAN_PCP = 7 # VLAN priority. +OFPXMT_OFB_IP_DSCP = 8 # IP DSCP (6 bits in ToS field). +OFPXMT_OFB_IP_ECN = 9 # IP ECN (2 bits in ToS field). +OFPXMT_OFB_IP_PROTO = 10 # IP protocol. +OFPXMT_OFB_IPV4_SRC = 11 # IPv4 source address. +OFPXMT_OFB_IPV4_DST = 12 # IPv4 destination address. +OFPXMT_OFB_TCP_SRC = 13 # TCP source port. +OFPXMT_OFB_TCP_DST = 14 # TCP destination port. +OFPXMT_OFB_UDP_SRC = 15 # UDP source port. +OFPXMT_OFB_UDP_DST = 16 # UDP destination port. +OFPXMT_OFB_SCTP_SRC = 17 # SCTP source port. +OFPXMT_OFB_SCTP_DST = 18 # SCTP destination port. +OFPXMT_OFB_ICMPV4_TYPE = 19 # ICMP type. +OFPXMT_OFB_ICMPV4_CODE = 20 # ICMP code. +OFPXMT_OFB_ARP_OP = 21 # ARP opcode. +OFPXMT_OFB_ARP_SPA = 22 # ARP source IPv4 address. +OFPXMT_OFB_ARP_TPA = 23 # ARP target IPv4 address. +OFPXMT_OFB_ARP_SHA = 24 # ARP source hardware address. +OFPXMT_OFB_ARP_THA = 25 # ARP target hardware address. +OFPXMT_OFB_IPV6_SRC = 26 # IPv6 source address. +OFPXMT_OFB_IPV6_DST = 27 # IPv6 destination address. +OFPXMT_OFB_IPV6_FLABEL = 28 # IPv6 Flow Label +OFPXMT_OFB_ICMPV6_TYPE = 29 # ICMPv6 type. +OFPXMT_OFB_ICMPV6_CODE = 30 # ICMPv6 code. +OFPXMT_OFB_IPV6_ND_TARGET = 31 # Target address for ND. +OFPXMT_OFB_IPV6_ND_SLL = 32 # Source link-layer for ND. +OFPXMT_OFB_IPV6_ND_TLL = 33 # Target link-layer for ND. +OFPXMT_OFB_MPLS_LABEL = 34 # MPLS label. +OFPXMT_OFB_MPLS_TC = 35 # MPLS TC. +OFPXMT_OFP_MPLS_BOS = 36 # MPLS BoS bit. +OFPXMT_OFB_PBB_ISID = 37 # PBB I-SID. +OFPXMT_OFB_TUNNEL_ID = 38 # Logical Port Metadata. +OFPXMT_OFB_IPV6_EXTHDR = 39 # IPv6 Extension Header pseudo-field + +# enum ofp_vlan_id +OFPVID_PRESENT = 0x1000 # bit that indicate that a VLAN id is set. +OFPVID_NONE = 0x0000 # No VLAN id was set. + +# enum ofp_ipv6exthdr_flags +OFPIEH_NONEXT = 1 << 0 # "No next header" encountered. +OFPIEH_ESP = 1 << 1 # Encrypted Sec Payload header present. +OFPIEH_AUTH = 1 << 2 # Authentication header present. +OFPIEH_DEST = 1 << 3 # 1 or 2 dest headers present. +OFPIEH_FRAG = 1 << 4 # Fragment header present. +OFPIEH_ROUTER = 1 << 5 # Router header present. +OFPIEH_HOP = 1 << 6 # Hop-by-hop header present. +OFPIEH_UNREP = 1 << 7 # Unexpected repeats encountered. +OFPIEH_UNSEQ = 1 << 8 # Unexpected sequencing encountered. + +# ofp_oxm_experimenter_header +OFP_OXM_EXPERIMENTER_HEADER_PACK_STR = '!II' +OFP_OXM_EXPERIMENTER_HEADER_SIZE = 8 +assert (calcsize(OFP_OXM_EXPERIMENTER_HEADER_PACK_STR) + + OFP_OXM_EXPERIMENTER_HEADER_SIZE) == OFP_OXM_EXPERIMENTER_HEADER_SIZE + +# enum ofp_instruction_type +OFPID_GOTO_TABLE = 1 # Setup the next table in the lookup pipeline. +OFPIT_WRITE_METADATA = 2 # Setup the metadata field for use later in + # pipeline. +OFPIT_WRITE_ACTIONS = 3 # Write the action(s) onto the datapath + # action set +OFPIT_APPLY_ACTIONS = 4 # Applies the action(s) immediately +OFPIT_CLEAR_ACTIONS = 5 # Clears all actions from the datapath action + # set +OFPIT_METER = 6 # Apply meter (rate limiter) +OFPIT_EXPERIMENTER = 0xFFFF # Experimenter instruction + +# struct ofp_instruction_goto_table +OFP_INSTRUCTION_GOTO_TABLE_PACK_STR = '!HHB3x' +OFP_INSTRUCTION_GOTO_TABLE_SIZE = 8 +assert (calcsize(OFP_INSTRUCTION_GOTO_TABLE_PACK_STR) == + OFP_INSTRUCTION_GOTO_TABLE_SIZE) + +# struct ofp_instruction_write_metadata +OFP_INSTRUCTION_WRITE_METADATA_PACK_STR = '!HH4xQQ' +OFP_INSTRUCTION_WRITE_METADATA_SIZE = 24 +assert (calcsize(OFP_INSTRUCTION_WRITE_METADATA_PACK_STR) == + OFP_INSTRUCTION_WRITE_METADATA_SIZE) + +# struct ofp_instruction_actions +OFP_INSTRUCTION_ACTIONS_PACK_STR = '!HH4x' +OFP_INSTRUCTION_ACTIONS_SIZE = 8 +assert (calcsize(OFP_INSTRUCTION_ACTIONS_PACK_STR) == + OFP_INSTRUCTION_ACTIONS_SIZE) + +# struct ofp_instruction_meter +OFP_INSTRUCTION_METER_PACK_STR = '!HHI' +OFP_INSTRUCTION_METER_SIZE = 8 +assert calcsize(OFP_INSTRUCTION_METER_PACK_STR) == OFP_INSTRUCTION_METER_SIZE + +# enum ofp_action_type +OFPAT_OUTPUT = 0 # Output to switch port. +OFPAT_COPY_TTL_OUT = 11 # Copy TTL "outwards" -- from + # next-to-outermost to outermost +OFPAT_COPY_TTL_IN = 12 # Copy TTL "inwards" -- from outermost to + # next-to-outermost +OFPAT_SET_MPLS_TTL = 15 # MPLS TTL. +OFPAT_DEC_MPLS_TTL = 16 # Decrement MPLS TTL +OFPAT_PUSH_VLAN = 17 # Push a new VLAN tag +OFPAT_POP_VLAN = 18 # Pop the outer VLAN tag +OFPAT_PUSH_MPLS = 19 # Push a new MPLS tag +OFPAT_POP_MPLS = 20 # Pop the outer MPLS tag +OFPAT_SET_QUEUE = 21 # Set queue id when outputting to a port +OFPAT_GROUP = 22 # Apply group +OFPAT_SET_NW_TTL = 23 # IP TTL. +OFPAT_DEC_NW_TTL = 24 # Decrement IP TTL. +OFPAT_SET_FIELD = 25 # Set a header field using OXM TLV format. +OFPAT_PUSH_PBB = 26 # Push a new PBB service tag (I-TAG) +OFPAT_POP_PBB = 27 # Pop the outer PBB service tag (I-TAG) +OFPAT_EXPERIMENTER = 0xffff + +# struct ofp_action_header +OFP_ACTION_HEADER_PACK_STR = '!HH4x' +OFP_ACTION_HEADER_SIZE = 8 +assert calcsize(OFP_ACTION_HEADER_PACK_STR) == OFP_ACTION_HEADER_SIZE + +# struct ofp_action_output +OFP_ACTION_OUTPUT_PACK_STR = '!HHIH6x' +OFP_ACTION_OUTPUT_SIZE = 16 +assert calcsize(OFP_ACTION_OUTPUT_PACK_STR) == OFP_ACTION_OUTPUT_SIZE + +# enum ofp_controller_max_len +OFPCML_MAX = 0xffe5 # maximum max_len value which can be used to + # request a specific byte length. +OFPCML_NO_BUFFER = 0xffff # indicates that no buffering should be + # applied and the whole packet is to be + # sent to the controller. + +# struct ofp_action_group +OFP_ACTION_GROUP_PACK_STR = '!HHI' +OFP_ACTION_GROUP_SIZE = 8 +assert calcsize(OFP_ACTION_GROUP_PACK_STR) == OFP_ACTION_GROUP_SIZE + +# struct ofp_action_set_queue +OFP_ACTION_SET_QUEUE_PACK_STR = '!HHI' +OFP_ACTION_SET_QUEUE_SIZE = 8 +assert calcsize(OFP_ACTION_SET_QUEUE_PACK_STR) == OFP_ACTION_SET_QUEUE_SIZE + +# struct ofp_action_mpls_ttl +OFP_ACTION_MPLS_TTL_PACK_STR = '!HHB3x' +OFP_ACTION_MPLS_TTL_SIZE = 8 +assert calcsize(OFP_ACTION_MPLS_TTL_PACK_STR) == OFP_ACTION_MPLS_TTL_SIZE + +# struct ofp_action_nw_ttl +OFP_ACTION_NW_TTL_PACK_STR = '!HHB3x' +OFP_ACTION_NW_TTL_SIZE = 8 +assert calcsize(OFP_ACTION_NW_TTL_PACK_STR) == OFP_ACTION_NW_TTL_SIZE + +# struct ofp_action_push +OFP_ACTION_PUSH_PACK_STR = '!HHH2x' +OFP_ACTION_PUSH_SIZE = 8 +assert calcsize(OFP_ACTION_PUSH_PACK_STR) == OFP_ACTION_PUSH_SIZE + +# struct ofp_action_pop_mpls +OFP_ACTION_POP_MPLS_PACK_STR = '!HHH2x' +OFP_ACTION_POP_MPLS_SIZE = 8 +assert calcsize(OFP_ACTION_POP_MPLS_PACK_STR) == OFP_ACTION_POP_MPLS_SIZE + +# struct ofp_action_set_field +OFP_ACTION_SET_FIELD_PACK_STR = '!HH4x' +OFP_ACTION_SET_FIELD_SIZE = 8 +assert calcsize(OFP_ACTION_SET_FIELD_PACK_STR) == OFP_ACTION_SET_FIELD_SIZE + +# struct ofp_action_experimenter_header +OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR = '!HHI' +OFP_ACTION_EXPERIMENTER_HEADER_SIZE = 8 +assert (calcsize(OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR) == + OFP_ACTION_EXPERIMENTER_HEADER_SIZE) + +# ofp_switch_features +OFP_SWITCH_FEATURES_PACK_STR = '!QIBB2xII' +OFP_SWITCH_FEATURES_SIZE = 32 +assert (calcsize(OFP_SWITCH_FEATURES_PACK_STR) + OFP_HEADER_SIZE == + OFP_SWITCH_FEATURES_SIZE) + +# enum ofp_capabilities +OFPC_FLOW_STATS = 1 << 0 # Flow statistics. +OFPC_TABLE_STATS = 1 << 1 # Table statistics. +OFPC_PORT_STATS = 1 << 2 # Port statistics. +OFPC_GROUP_STATS = 1 << 3 # 802.1d spanning tree. +OFPC_IP_REASM = 1 << 5 # Can reassemble IP fragments. +OFPC_QUEUE_STATS = 1 << 6 # Queue statistics. +OFPC_PORT_BLOCKED = 1 << 8 # Match IP addresses in ARP pkts. + +# struct ofp_switch_config +OFP_SWITCH_CONFIG_PACK_STR = '!HH' +OFP_SWITCH_CONFIG_SIZE = 12 +assert (calcsize(OFP_SWITCH_CONFIG_PACK_STR) + OFP_HEADER_SIZE == + OFP_SWITCH_CONFIG_SIZE) + +# enum ofp_config_flags +OFPC_FRAG_NORMAL = 0 # No special handling for fragments. +OFPC_FRAG_DROP = 1 # Drop fragments. +OFPC_FRAG_REASM = 2 # Reassemble (only if OFPC_IP_REASM set). +OFPC_FRAG_MASK = 3 + +# enum ofp_table +OFPTT_MAX = 0xfe +OFPTT_ALL = 0xff + +# struct ofp_table_mod +OFP_TABLE_MOD_PACK_STR = '!B3xI' +OFP_TABLE_MOD_SIZE = 16 +assert (calcsize(OFP_TABLE_MOD_PACK_STR + OFP_HEADER_SIZE) == + OFP_TABLE_MOD_SIZE) + +_OFP_FLOW_MOD_PACK_STR0 = 'QQBBHHHIIIH2x' +OFP_FLOW_MOD_PACK_STR = '!' + _OFP_FLOW_MOD_PACK_STR0 + _OFP_MATCH_PACK_STR +OFP_FLOW_MOD_PACK_STR0 = '!' + _OFP_FLOW_MOD_PACK_STR0 +OFP_FLOW_MOD_SIZE = 56 +assert (calcsize(OFP_FLOW_MOD_PACK_STR) + OFP_HEADER_SIZE == + OFP_FLOW_MOD_SIZE) + +# enum ofp_flow_mod_command +OFPFC_ADD = 0 # New flow. +OFPFC_MODIFY = 1 # Modify all matching flows. +OFPFC_MODIFY_STRICT = 2 # Modify entry strictly matching wildcards +OFPFC_DELETE = 3 # Delete all matching flows. +OFPFC_DELETE_STRICT = 4 # Strictly match wildcards and priority. + +# enum ofp_flow_mod_flags +OFPFF_SEND_FLOW_REM = 1 << 0 # Send flow removed message when flow + # expires or is deleted. +OFPFF_CHECK_OVERLAP = 1 << 1 # Check for overlapping entries first. +OFPFF_RESET_COUNT = 1 << 2 # Reset flow packet and byte counts. +OFPFF_NO_PKT_COUNTS = 1 << 3 # Don't keep track of packet count. +OFPFF_NO_BYT_COUNTS = 1 << 4 # Don't keep track of byte count. + +# struct ofp_group_mod +OFP_GROUP_MOD_PACK_STR = '!HBBI' +OFP_GROUP_MOD_SIZE = 16 +assert (calcsize(OFP_GROUP_MOD_PACK_STR) + OFP_HEADER_SIZE == + OFP_GROUP_MOD_SIZE) + +# enum ofp_group_mod_command +OFPGC_ADD = 0 # New group. +OFPGC_MODIFY = 1 # Modify all matching groups. +OFPGC_DELETE = 2 # Delete all matching groups. + +# enum ofp_group_type +OFPGT_ALL = 0 # All (multicast/broadcast) group. +OFPGT_SELECT = 1 # Select group. +OFPGT_INDIRECT = 2 # Indirect group. +OFPGT_FF = 3 # Fast failover group. + +# struct ofp_bucket +OFP_BUCKET_PACK_STR = '!HHII4x' +OFP_BUCKET_SIZE = 16 +assert calcsize(OFP_BUCKET_PACK_STR) == OFP_BUCKET_SIZE + +# struct ofp_port_mod +OFP_PORT_MOD_PACK_STR = '!I4x' + OFP_ETH_ALEN_STR + 'B2xIII4x' +OFP_PORT_MOD_SIZE = 40 +assert (calcsize(OFP_PORT_MOD_PACK_STR) + OFP_HEADER_SIZE == + OFP_PORT_MOD_SIZE) + +# struct ofp_meter_mod +OFP_METER_MOD_PACK_STR = '!HHI' +OFP_METER_MOD_SIZE = 16 +assert (calcsize(OFP_METER_MOD_PACK_STR) + OFP_HEADER_SIZE == + OFP_METER_MOD_SIZE) + +# enum ofp_meter +OFPM_MAX = 0xffff0000 +OFPM_SLOWPATH = 0xfffffffd # Meter for slow datapath, if any. +OFPM_CONTROLLER = 0xfffffffe # Meter for controller connection. +OFPM_ALL = 0xffffffff # Represents all meters for stat requests commands. + +# enum ofp_meter_mod_command +OFPMC_ADD = 0 # New meter. +OFPMC_MODIFY = 1 # Modify specified meter. +OFPMC_DELETE = 2 # Delete specified meter. + +# enum ofp_meter_flags +OFPMF_KBPS = 1 << 0 # Rate value in kb/s (kilo-bit per second). +OFPMF_PKTPS = 1 << 1 # Rate value in packet/sec. +OFPMF_BURST = 1 << 2 # Do burst size. +OFPMF_STATS = 1 << 3 # Collect statistics. + +# struct ofp_meter_band_header +OFP_METER_BAND_HEADER_PACK_STR = '!HHII' +OFP_METER_BAND_HEADER_SIZE = 12 +assert (calcsize(OFP_METER_BAND_HEADER_PACK_STR) == + OFP_METER_BAND_HEADER_SIZE) + +# enum ofp_meter_band_type +OFPMBT_DROP = 1 # Drop packet. +OFPMBT_DSCP_REMARK = 2 # Remark DSCP in the IP header. +OFPMBT_EXPERIMENTER = 0xFFFF # Experimenter meter band. + +# struct ofp_meter_band_drop +OFP_METER_BAND_DROP_PACK_STR = '!HHII4x' +OFP_METER_BAND_DROP_SIZE = 16 +assert (calcsize(OFP_METER_BAND_DROP_PACK_STR) == + OFP_METER_BAND_DROP_SIZE) + +# struct ofp_meter_band_dscp_remark +OFP_METER_BAND_DSCP_REMARK_PACK_STR = '!HHIIH3x' +OFP_METER_BAND_DSCP_REMARK_SIZE = 16 +assert (calcsize(OFP_METER_BAND_DSCP_REMARK_PACK_STR) == + OFP_METER_BAND_DSCP_REMARK_SIZE) + +# struct ofp_meter_band_experimenter +OFP_METER_BAND_EXPERIMENTER_PACK_STR = '!HHIII' +OFP_METER_BAND_EXPERIMENTER_SIZE = 16 +assert (calcsize(OFP_METER_BAND_EXPERIMENTER_PACK_STR) == + OFP_METER_BAND_EXPERIMENTER_SIZE) + +# struct ofp_multipart_request +OFP_MULTIPART_REQUEST_PACK_STR = '!HH4x' +OFP_MULTIPART_REQUEST_SIZE = 16 +assert (calcsize(OFP_MULTIPART_REQUEST_PACK_STR) + OFP_HEADER_SIZE == + OFP_MULTIPART_REQUEST_SIZE) + +# enum ofp_multipart_request_flags +OFPMPF_REQ_MORE = 1 << 0 # More requests to follow. + +# struct ofp_multipart_reply +OFP_MULTIPART_REPLY_PACK_STR = '!HH4x' +OFP_MULTIPART_REPLY_SIZE = 16 +assert (calcsize(OFP_MULTIPART_REPLY_PACK_STR) + OFP_HEADER_SIZE == + OFP_MULTIPART_REPLY_SIZE) + +# enum ofp_multipart_reply_flags +OFPMPF_REPLY_MORE = 1 << 0 # More replies to follow. + +# enum ofp_multipart_types +OFPMP_DESC = 0 +OFPMP_FLOW = 1 +OFPMP_AGGREGATE = 2 +OFPMP_TABLE = 3 +OFPMP_PORT_STATS = 4 +OFPMP_QUEUE = 5 +OFPMP_GROUP = 6 +OFPMP_GROUP_DESC = 7 +OFPMP_GROUP_FEATURES = 8 +OFPMP_METER = 9 +OFPMP_METER_CONFIG = 10 +OFPMP_METER_FEATURES = 11 +OFPMP_TABLE_FEATURES = 12 +OFPMP_PORT_DESC = 13 +OFPMP_EXPERIMENTER = 0xffff + +# struct ofp_desc +DESC_STR_LEN = 256 +DESC_STR_LEN_STR = str(DESC_STR_LEN) +SERIAL_NUM_LEN = 32 +SERIAL_NUM_LEN_STR = str(SERIAL_NUM_LEN) +OFP_DESC_PACK_STR = '!' + \ + DESC_STR_LEN + 'c' + \ + DESC_STR_LEN + 'c' + \ + DESC_STR_LEN + 'c' + \ + SERIAL_NUM_LEN + 'c' + \ + DESC_STR_LEN + 'c' +OFP_DESC_SIZE = 1056 +assert calcsize(OFP_DESC_PACK_STR) == OFP_DESC_SIZE + + +# struct ofp_flow_stats_request +_OFP_FLOW_STATS_REQUEST_0_PACK_STR = 'B3xII4xQQ' +OFP_FLOW_STATS_REQUEST_0_PACK_STR = '!' + _OFP_FLOW_STATS_REQUEST_0_PACK_STR +OFP_FLOW_STATS_REQUEST_0_SIZE = 32 +assert (calcsize(OFP_FLOW_STATS_REQUEST_0_PACK_STR) == + OFP_FLOW_STATS_REQUEST_0_SIZE) +OFP_FLOW_STATS_REQUEST_PACK_STR = (OFP_FLOW_STATS_REQUEST_0_PACK_STR + + _OFP_MATCH_PACK_STR) +OFP_FLOW_STATS_REQUEST_SIZE = 40 +assert (calcsize(OFP_FLOW_STATS_REQUEST_PACK_STR) == + OFP_FLOW_STATS_REQUEST_SIZE) + +# struct ofp_flow_stats +_OFP_FLOW_STATS_0_PACK_STR = 'HBxIIHHHH4xQQQ' +OFP_FLOW_STATS_0_PACK_STR = '!' + _OFP_FLOW_STATS_0_PACK_STR +OFP_FLOW_STATS_0_SIZE = 48 +assert calcsize(OFP_FLOW_STATS_0_PACK_STR) == OFP_FLOW_STATS_0_SIZE +OFP_FLOW_STATS_PACK_STR = (OFP_FLOW_STATS_0_PACK_STR + + _OFP_MATCH_PACK_STR) +OFP_FLOW_STATS_SIZE = 56 +assert calcsize(OFP_FLOW_STATS_PACK_STR) == OFP_FLOW_STATS_SIZE + +# struct ofp_flow_stats_request +_OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR = 'B3xII4xQQ' +OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR = '!' + \ + _OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR +OFP_AGGREGATE_STATS_REQUEST_0_SIZE = 32 +assert (calcsize(OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR) == + OFP_AGGREGATE_STATS_REQUEST_0_SIZE) +OFP_AGGREGATE_STATS_REQUEST_PACK_STR = \ + OFP_AGGREGATE_STATS_REQUEST_0_PACK_STR + _OFP_MATCH_PACK_STR +OFP_AGGREGATE_STATS_REQUEST_SIZE = 40 +assert (calcsize(OFP_AGGREGATE_STATS_REQUEST_PACK_STR) == + OFP_AGGREGATE_STATS_REQUEST_SIZE) + +# struct ofp_aggregate_stats_request +OFP_AGGREGATE_STATS_REQUEST_PACK_STR = '!B3xII4xQQ' + _OFP_MATCH_PACK_STR +OFP_AGGREGATE_STATS_REQUEST_SIZE = 40 +assert (calcsize(OFP_AGGREGATE_STATS_REQUEST_PACK_STR) == + OFP_AGGREGATE_STATS_REQUEST_SIZE) + +# struct ofp_aggregate_stats_reply +OFP_AGGREGATE_STATS_REPLY_PACK_STR = '!QQI4x' +OFP_AGGREGATE_STATS_REPLY_SIZE = 24 +assert (calcsize(OFP_AGGREGATE_STATS_REPLY_PACK_STR) == + OFP_AGGREGATE_STATS_REPLY_SIZE) + +# struct ofp_table_stats +OFP_TABLE_STATS_PACK_STR = '!B3xIQQ' +OFP_TABLE_STATS_SIZE = 24 +assert calcsize(OFP_TABLE_STATS_PACK_STR) == OFP_TABLE_STATS_SIZE + +# struct ofp_table_features +OFP_MAX_TABLE_NAME_LEN = 32 +OFP_MAX_TABLE_NAME_LEN_STR = str(OFP_MAX_TABLE_NAME_LEN) +OFP_TABLE_FEATURES_PACK_STR = '!HB5x' + OFP_MAX_TABLE_NAME_LEN_STR + \ + 'c' + 'QQII' +OFP_TABLE_FEATURES_SIZE = 64 +assert (calcsize(OFP_TABLE_FEATURES_PACK_STR) == + OFP_TABLE_FEATURES_SIZE) + +# enum ofp_table_feature_prop_type +OFPTFPT_INSTRUCTIONS = 0 +OFPTFPT_INSTRUCTIONS_MISS = 1 +OFPTFPT_NEXT_TABLES = 2 +OFPTFPT_NEXT_TABLES_MISS = 3 +OFPTFPT_WRITE_ACTIONS = 4 +OFPTFPT_WRITE_ACTIONS_MISS = 5 +OFPTFPT_APPLY_ACTIONS = 6 +OFPTFPT_APPLY_ACTIONS_MISS = 7 +OFPTFPT_MATCH = 8 +OFPTFPT_WILDCARDS = 10 +OFPTFPT_WRITE_SETFIELD = 12 +OFPTFPT_WRITE_SETFIELD_MISS = 13 +OFPTFPT_APPLY_SETFIELD = 14 +OFPTFPT_APPLY_SETFIELD_MISS = 15 +OFPTFPT_EXPERIMENTER = 0xFFFE +OFPTFPT_EXPERIMENTER_MISS = 0xFFFF + +# struct ofp_table_feature_prop_instructions +OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_PACK_STR = '!HH' +OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_SIZE = 4 +assert (calcsize(OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_PACK_STR) == + OFP_TABLE_FEATURE_PROP_INSTRUCTIONS_SIZE) + +# struct ofp_table_feature_prop_next_tables +OFP_TABLE_FEATURE_PROP_NEXT_TABLES_PACK_STR = '!HH' +OFP_TABLE_FEATURE_PROP_NEXT_TABLES_SIZE = 4 +assert (calcsize(OFP_TABLE_FEATURE_PROP_NEXT_TABLES_PACK_STR) == + OFP_TABLE_FEATURE_PROP_NEXT_TABLES_SIZE) + +# struct ofp_table_feature_prop_actions +OFP_TABLE_FEATURE_PROP_ACTIONS_PACK_STR = '!HH' +OFP_TABLE_FEATURE_PROP_ACTIONS_SIZE = 4 +assert (calcsize(OFP_TABLE_FEATURE_PROP_ACTIONS_PACK_STR) == + OFP_TABLE_FEATURE_PROP_ACTIONS_SIZE) + +# struct ofp_table_feature_prop_oxm +OFP_TABLE_FEATURE_PROP_OXM_PACK_STR = '!HH' +OFP_TABLE_FEATURE_PROP_OXM_SIZE = 4 +assert (calcsize(OFP_TABLE_FEATURE_PROP_OXM_PACK_STR) == + OFP_TABLE_FEATURE_PROP_OXM_SIZE) + +# struct ofp_port_stats_reuqest +OFP_PORT_STATS_REQUEST_PACK_STR = '!I4x' +OFP_PORT_STATS_REQUEST_SIZE = 8 +assert (calcsize(OFP_PORT_STATS_REQUEST_PACK_STR) == + OFP_PORT_STATS_REQUEST_SIZE) + +# struct ofp_port_stats +OFP_PORT_STATS_PACK_STR = '!I4xQQQQQQQQQQQQII' +OFP_PORT_STATS_SIZE = 112 +assert calcsize(OFP_PORT_STATS_PACK_STR) == OFP_PORT_STATS_SIZE + +# struct ofp_queue_stats_request +OFP_QUEUE_STATS_REQUEST_PACK_STR = '!II' +OFP_QUEUE_STATS_REQUEST_SIZE = 8 +assert (calcsize(OFP_QUEUE_STATS_REQUEST_PACK_STR) == + OFP_QUEUE_STATS_REQUEST_SIZE) + +# struct ofp_queue_stats +OFP_QUEUE_STATS_PACK_STR = '!IIQQQII' +OFP_QUEUE_STATS_SIZE = 40 +assert calcsize(OFP_QUEUE_STATS_PACK_STR) == OFP_QUEUE_STATS_SIZE + +# struct ofp_group_stats_request +OFP_GROUP_STATS_REQUEST_PACK_STR = '!I4x' +OFP_GROUP_STATS_REQUEST_SIZE = 8 +assert (calcsize(OFP_GROUP_STATS_REQUEST_PACK_STR) == + OFP_GROUP_STATS_REQUEST_SIZE) + +# struct ofp_group_stats +OFP_GROUP_STATS_PACK_STR = '!H2xII4xQQII' +OFP_GROUP_STATS_SIZE = 40 +assert calcsize(OFP_GROUP_STATS_PACK_STR) == OFP_GROUP_STATS_SIZE + +# struct ofp_bucket_counter +OFP_BUCKET_COUNTER_PACK_STR = '!QQ' +OFP_BUCKET_COUNTER_SIZE = 16 +assert calcsize(OFP_BUCKET_COUNTER_PACK_STR) == OFP_BUCKET_COUNTER_SIZE + +# struct ofp_group_desc_stats +OFP_GROUP_DESC_STATS_PACK_STR = '!HBBI' +OFP_GROUP_DESC_STATS_SIZE = 8 +assert calcsize(OFP_GROUP_DESC_STATS_PACK_STR) == OFP_GROUP_DESC_STATS_SIZE + +# struct ofp_group_features +OFP_GROUP_FEATURES_PACK_STR = '!II4I4I' +OFP_GROUP_FEATURES_SIZE = 40 +assert calcsize(OFP_GROUP_FEATURES_PACK_STR) == OFP_GROUP_FEATURES_SIZE + +# enum ofp_group_capabilities +OFPGFC_SELECT_WEIGHT = 1 << 0 # Support weight for select groups. +OFPGFC_SELECT_LIVENESS = 1 << 1 # Support liveness for select groups. +OFPGFC_CHAINING = 1 << 2 # Support chaining groups. +OFPGFC_CHAINING_CHECKS = 1 << 3 # Check chaining for loops and delete + +# struct ofp_meter_multipart_request +OFP_METER_MULTIPART_REQUEST_PACK_STR = '!I4B' +OFP_METER_MULTIPART_REQUEST_SIZE = 8 +assert (calcsize(OFP_METER_MULTIPART_REQUEST_PACK_STR) == + OFP_METER_MULTIPART_REQUEST_SIZE) + +# struct ofp_meter_stats +OFP_METER_STATS_PACK_STR = '!IH6xIQQII' +OFP_METER_STATS_SIZE = 40 +assert calcsize(OFP_METER_STATS_PACK_STR) == OFP_METER_STATS_SIZE + +# struct ofp_meter_band_stats +OFP_METER_BAND_STATS_PACK_STR = '!QQ' +OFP_METER_BAND_STATS_SIZE = 16 +assert (calcsize(OFP_METER_BAND_STATS_PACK_STR) == + OFP_METER_BAND_STATS_SIZE) + +# struct ofp_meter_config +OFP_METER_CONFIG_PACK_STR = '!HHI' +OFP_METER_CONFIG_SIZE = 8 +assert calcsize(OFP_METER_CONFIG_PACK_STR) == OFP_METER_CONFIG_SIZE + +# struct ofp_meter_features +OFP_METER_FEATURES_PACK_STR = '!IIIBB2x' +OFP_METER_FEATURES_SIZE = 16 +assert (calcsize(OFP_METER_FEATURES_PACK_STR) == + OFP_METER_FEATURES_SIZE) + +# struct ofp_experimenter_multipart_header +OFP_EXPERIMENTER_MULTIPART_HEADER_PACK_STR = '!II' +OFP_EXPERIMENTER_MULTIPART_HEADER_SIZE = 8 +assert (calcsize(OFP_EXPERIMENTER_MULTIPART_HEADER_PACK_STR) == + OFP_EXPERIMENTER_MULTIPART_HEADER_SIZE) + +# struct ofp_queue_get_config_request +OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR = '!I4x' +OFP_QUEUE_GET_CONFIG_REQUEST_SIZE = 16 +assert (calcsize(OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR) + + OFP_HEADER_SIZE) == OFP_QUEUE_GET_CONFIG_REQUEST_SIZE + +# struct ofp_queue_get_config_reply +OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR = '!I4x' +OFP_QUEUE_GET_CONFIG_REPLY_SIZE = 16 +assert (calcsize(OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR) + + OFP_HEADER_SIZE) == OFP_QUEUE_GET_CONFIG_REPLY_SIZE + +# struct ofp_packet_out +OFP_PACKET_OUT_PACK_STR = '!IIH6x' +OFP_PACKET_OUT_SIZE = 24 +assert (calcsize(OFP_PACKET_OUT_PACK_STR) + OFP_HEADER_SIZE == + OFP_PACKET_OUT_SIZE) + +# struct ofp_role_request +OFP_ROLE_REQUEST_PACK_STR = '!I4xQ' +OFP_ROLE_REQUEST_SIZE = 24 +assert (calcsize(OFP_ROLE_REQUEST_PACK_STR) + OFP_HEADER_SIZE == + OFP_ROLE_REQUEST_SIZE) + +# enum ofp_controller_role +OFPCR_ROLE_NOCHANGE = 0 # Don't change current role. +OFPCR_ROLE_EQUAL = 1 # Default role, full access. +OFPCR_ROLE_MASTER = 2 # Full access, at most one master. +OFPCR_ROLE_SLAVE = 3 # Read-only access. + +# struct ofp_async_config +OFP_ASYNC_CONFIG_PACK_STR = '!2I2I2I' +OFP_ASYNC_CONFIG_SIZE = 32 +assert (calcsize(OFP_ASYNC_CONFIG_PACK_STR) + OFP_HEADER_SIZE == + OFP_ASYNC_CONFIG_SIZE) + +# struct ofp_packet_in +OFP_PACKET_IN_PACK_STR = '!IHBBQ' + _OFP_MATCH_PACK_STR +OFP_PACKET_IN_SIZE = 32 +OFP_PACKET_IN_DATA_OFFSET = 18 +assert (calcsize(OFP_PACKET_IN_PACK_STR) + OFP_HEADER_SIZE == + OFP_PACKET_IN_SIZE) + +# enum ofp_packet_in_reason +OFPR_NO_MATCH = 0 # No matching flow. +OFPR_ACTION = 1 # Action explicitly output to controller. +OFPR_INVALID_TTL = 2 # Packet has invalid TTL. + +# struct ofp_flow_removed +_OFP_FLOW_REMOVED_PACK_STR0 = 'QHBBIIHHQQ' +OFP_FLOW_REMOVED_PACK_STR = '!' + _OFP_FLOW_REMOVED_PACK_STR0 + \ + _OFP_MATCH_PACK_STR +OFP_FLOW_REMOVED_PACK_STR0 = '!' + _OFP_FLOW_REMOVED_PACK_STR0 +OFP_FLOW_REMOVED_SIZE = 56 +assert (calcsize(OFP_FLOW_REMOVED_PACK_STR) + OFP_HEADER_SIZE == + OFP_FLOW_REMOVED_SIZE) + +# enum ofp_flow_removed_reason +OFPRR_IDLE_TIMEOUT = 0 # Flow idle time exceeded idle_timeout. +OFPRR_HARD_TIMEOUT = 1 # Time exceeded hard_timeout. +OFPRR_DELETE = 2 # Evicted by a DELETE flow mod. +OFPRR_GROUP_DELETE = 3 # Group was removed. + +# struct ofp_port_status +OFP_PORT_STATUS_PACK_STR = '!B7x' + _OFP_PORT_PACK_STR +OFP_PORT_STATUS_DESC_OFFSET = OFP_HEADER_SIZE + 8 +OFP_PORT_STATUS_SIZE = 80 +assert (calcsize(OFP_PORT_STATUS_PACK_STR) + OFP_HEADER_SIZE == + OFP_PORT_STATUS_SIZE) + +# enum ofp_port_reason +OFPPR_ADD = 0 # The port was added. +OFPPR_DELETE = 1 # The port was removed. +OFPPR_MODIFY = 2 # Some attribute of the port has changed. + +# struct ofp_error_msg +OFP_ERROR_MSG_PACK_STR = '!HH' +OFP_ERROR_MSG_SIZE = 12 +assert (calcsize(OFP_ERROR_MSG_PACK_STR) + OFP_HEADER_SIZE == + OFP_ERROR_MSG_SIZE) + +# enum ofp_error_type +OFPET_HELLO_FAILED = 0 # Hello protocol failed. +OFPET_BAD_REQUEST = 1 # Request was not understood. +OFPET_BAD_ACTION = 2 # Error in action description. +OFPET_BAD_INSTRUCTION = 3 # Error in instruction list. +OFPET_BAD_MATCH = 4 # Error in match. +OFPET_FLOW_MOD_FAILED = 5 # Problem modifying flow entry. +OFPET_GROUP_MOD_FAILED = 6 # Problem modifying group entry. +OFPET_PORT_MOD_FAILED = 7 # OFPT_PORT_MOD failed. +OFPET_TABLE_MOD_FAILED = 8 # Table mod request failed. +OFPET_QUEUE_OP_FAILED = 9 # Queue operation failed. +OFPET_SWITCH_CONFIG_FAILED = 10 # Switch config request failed. +OFPET_ROLE_REQUEST_FAILED = 11 # Controller Role request failed. +OFPET_METER_MOD_FAILED = 12 # Error in meter. +OFPET_TABLE_FEATURES_FAILED = 13 # Setting table features failed. +OFPET_EXPERIMENTER = 0xffff # Experimenter error messages. + +# enum ofp_hello_failed_code +OFPHFC_INCOMPATIBLE = 0 # No compatible version. +OFPHFC_EPERM = 1 # Permissions error. + +# enum ofp_bad_request_code +OFPBRC_BAD_VERSION = 0 # ofp_header.version not supported. +OFPBRC_BAD_TYPE = 1 # ofp_header.type not supported. +OFPBRC_BAD_MULTIPART = 2 # ofp_stats_msg.type not supported. +OFPBRC_BAD_EXPERIMENTER = 3 # Experimenter id not supported + # (in ofp_experimenter_header + # or ofp_stats_request or + # ofp_stats_reply). +OFPBRC_BAD_EXP_TYPE = 4 # Experimenter type not supported. +OFPBRC_EPERM = 5 # Permissions error. +OFPBRC_BAD_LEN = 6 # Wrong request length for type. +OFPBRC_BUFFER_EMPTY = 7 # Specified buffer has already been used. +OFPBRC_BUFFER_UNKNOWN = 8 # Specified buffer does not exist. +OFPBRC_BAD_TABLE_ID = 9 # Specified table-id invalid or does not exist. +OFPBRC_IS_SLAVE = 10 # Denied because controller is slave. +OFPBRC_BAD_PORT = 11 # Invalid port. +OFBRC_BAD_PACKET = 12 # Invalid packet in packet-out +OFPBRC_MULTIPART_BUFFER_OVERFLOW = 13 # ofp_multipart_request + # overflowed the assigned buffer. + +# enum ofp_bad_action_code +OFPBAC_BAD_TYPE = 0 # Unknown action type. +OFPBAC_BAD_LEN = 1 # Length problem in actions. +OFPBAC_BAD_EXPERIMENTER = 2 # Unknown experimenter id specified. +OFPBAC_BAD_EXP_TYPE = 3 # Unknown action type for experimenter id. +OFPBAC_BAD_OUT_PORT = 4 # Problem validating output action. +OFPBAC_BAD_ARGUMENT = 5 # Bad action argument. +OFPBAC_EPERM = 6 # Permissions error. +OFPBAC_TOO_MANY = 7 # Can't handle this many actions. +OFPBAC_BAD_QUEUE = 8 # Problem validating output queue. +OFPBAC_BAD_OUT_GROUP = 9 # Invalid group id in forward action. +OFPBAC_MATCH_INCONSISTENT = 10 # Action can't apply for this match, + # or Set-Field missing prerequisite. +OFPBAC_UNSUPPORTED_ORDER = 11 # Action order is unsupported for + # the action list in an Apply-Actions + # instruction +OFPBAC_BAD_TAG = 12 # Actions uses an unsupported tag/encap. +OFBAC_BAD_SET_TYPE = 13 # Unsupported type in SET_FIELD action. +OFPBAC_BAD_SET_LEN = 14 # Length problem in SET_FIELD action. +OFPBAC_BAD_SET_ARGUMENT = 15 # Bad arguement in SET_FIELD action. + +# enum ofp_bad_instruction_code +OFPBIC_UNKNOWN_INST = 0 # Unknown instruction. +OFPBIC_UNSUP_INST = 1 # Switch or table does not support + # the instruction. +OFPBIC_BAD_TABLE_ID = 2 # Invalid Table-Id specified +OFPBIC_UNSUP_METADATA = 3 # Metadata value unsupported by datapath. +OFPBIC_UNSUP_METADATA_MASK = 4 # Metadata mask value unsupported by + # datapath. +OFPBIC_BAD_EXPERIMENTER = 5 # Unknown experimenter id specified. +OFPBIC_BAD_EXP_TYPE = 6 # Unknown instruction for experimenter id. +OFPBIC_BAD_EXP_LEN = 7 # Length problem in instrucitons. +OFPBIC_EPERM = 8 # Permissions error. + +# enum ofp_bad_match_code +OFPBMC_BAD_TYPE = 0 # Unsupported match type apecified by + # the match. +OFPBMC_BAD_LEN = 1 # Length problem in math. +OFPBMC_BAD_TAG = 2 # Match uses an unsupported tag/encap. +OFPBMC_BAD_DL_ADDR_MASK = 3 # Unsupported datalink addr mask - + # switch does not support arbitrary + # datalink address mask. +OFPBMC_BAD_NW_ADDR_MASK = 4 # Unsupported network addr mask - + # switch does not support arbitrary + # network addres mask. +OFPBMC_BAD_WILDCARDS = 5 # Unsupported combination of fields + # masked or omitted in the match. +OFPBMC_BAD_FIELD = 6 # Unsupported field type in the match. +OFPBMC_BAD_VALUE = 7 # Unsupported value in a match field. +OFPBMC_BAD_MASK = 8 # Unsupported mask specified in the + # match. +OFPBMC_BAD_PREREQ = 9 # A prerequisite was not met. +OFPBMC_DUP_FIELD = 10 # A field type was duplicated. +OFPBMC_EPERM = 11 # Permissions error. + +# enum ofp_flow_mod_failed_code +OFPFMFC_UNKNOWN = 0 # Unspecified error. +OFPFMFC_TABLES_FULL = 1 # Flow not added because table was full. +OFPFMFC_BAD_TABLE_ID = 2 # Table does not exist +OFPFMFC_OVERLAP = 3 # Attempted to add overlapping flow + # with CHECK_OVERLAP flag set. +OFPFMFC_EPERM = 4 # Permissions error. +OFPFMFC_BAD_TIMEOUT = 5 # Flow not added because of + # unsupported idle/hard timeout. +OFPFMFC_BAD_COMMAND = 6 # Unsupported or unknown command. +OFPFMFC_BAD_FLAGS = 7 # Unsupported or unknown flags. + +# enum ofp_group_mod_failed_code +OFPGMFC_GROUP_EXISTS = 0 +OFPGMFC_INVALID_GROUP = 1 +OFPGMFC_WEIGHT_UNSUPPORTED = 2 # Switch does not support unequal load + # sharing with select groups. +OFPGMFC_OUT_OF_GROUPS = 3 # The group table is full. +OFPGMFC_OUT_OF_BUCKETS = 4 # The maximum number of action buckets + # for a group has been exceeded. +OFPGMFC_CHAINING_UNSUPPORTED = 5 # Switch does not support groups that + # forward to groups. +OFPGMFC_WATCH_UNSUPPORTED = 6 # This group cannot watch the + # watch_port or watch_group specified. +OFPGMFC_LOOP = 7 # Group entry would cause a loop. +OFPGMFC_UNKNOWN_GROUP = 8 # Group not modified because a group + # MODIFY attempted to modify a + # non-existent group. +OFPGMFC_CHAINED_GROUP = 9 # Group not deleted because another + # group is forwarding to it. +OFPGMFC_BAD_TYPE = 10 # Unsupported or unknown group type. +OFPGMFC_BAD_COMMAND = 11 # Unsupported or unknown command. +OFPGMFC_BAD_BUCKET = 12 # Error in bucket. +OFPGMFC_BAD_WATCH = 13 # Error in watch port/group. +OFPGMFC_EPERM = 14 # Permissions error. + +# enum ofp_port_mod_failed_code +OFPPMFC_BAD_PORT = 0 # Specified port does not exist. +OFPPMFC_BAD_HW_ADDR = 1 # Specified hardware address does not + # match the port number. +OFPPMFC_BAD_CONFIG = 2 # Specified config is invalid. +OFPPMFC_BAD_ADVERTISE = 3 # Specified advertise is invalid. +OFPPMFC_EPERM = 4 # Permissions error. + +# enum ofp_table_mod_failed_code +OFPTMFC_BAD_TABLE = 0 # Specified table does not exist. +OFPTMFC_BAD_CONFIG = 1 # Specified config is invalid. +OFPTMFC_EPERM = 2 # Permissions error + +# enum ofp_queue_op_failed_code +OFPQOFC_BAD_PORT = 0 # Invalid port (or port does not exist). +OFPQOFC_BAD_QUEUE = 1 # Queue does not exist. +OFPQOFC_EPERM = 2 # Permissions error. + +# enum ofp_switch_config_failed_code +OFPSCFC_BAD_FLAGS = 0 # Specified flags is invalid. +OFPSCFC_BAD_LEN = 1 # Specified len is invalid. +OFPQCFC_EPERM = 2 # Permissions error. + +# enum ofp_role_request_failed_code +OFPRRFC_STALE = 0 # Stale Message: old generation_id. +OFPRRFC_UNSUP = 1 # Controller role change unsupported. +OFPRRFC_BAD_ROLE = 2 # Invalid role. + +# enum ofp_meter_mod_failed_code +OFPMMFC_UNKNOWN = 0 # Unspecified error. +OFPMMFC_METER_EXISTS = 1 # Meter not added because a Meter ADD + # attempted to replace an existing Meter. +OFPMMFC_INVALID_METER = 2 # Meter not added because Meter specified + # is invalid. +OFPMMFC_UNKNOWN_METER = 3 # Meter not modified because a Meter + # MODIFY attempted to modify a non-existent + # Meter. +OFPMMFC_BAD_COMMAND = 4 # Unsupported or unknown command. +OFPMMFC_BAD_FLAGS = 5 # Flag configuration unsupported. +OFPMMFC_BAD_RATE = 6 # Rate unsupported. +OFPMMFC_BAD_BURST = 7 # Burst size unsupported. +OFPMMFC_BAD_BAND = 8 # Band unsupported. +OFPMMFC_BAD_BAND_VALUE = 9 # Band value unsupported. +OFPMMFC_OUT_OF_METERS = 10 # No more meters availabile. +OFPMMFC_OUT_OF_BANDS = 11 # The maximum number of properties + # for a meter has been exceeded. + +# enum ofp_table_features_failed_code +OFPTFFC_BAD_TABLE = 0 # Specified table does not exist. +OFPTFFC_BAD_METADATA = 1 # Invalid metadata mask. +OFPTFFC_BAD_TYPE = 2 # Unknown property type. +OFPTFFC_BAD_LEN = 3 # Length problem in properties. +OFPTFFC_BAD_ARGUMENT = 4 # Unsupported property value. +OFPTFFC_EPERM = 5 # Permissions error. + +# struct ofp_error_experimenter_msg +OFP_ERROR_EXPERIMENTER_MSG_PACK_STR = '!HHI' +OFP_ERROR_EXPERIMENTER_MSG_SIZE = 16 +assert (calcsize(OFP_ERROR_EXPERIMENTER_MSG_PACK_STR) + + OFP_HEADER_SIZE) == OFP_ERROR_EXPERIMENTER_MSG_SIZE + +# struct ofp_experimenter_header +OFP_EXPERIMENTER_HEADER_PACK_STR = '!II' +OFP_EXPERIMENTER_HEADER_SIZE = 16 +assert (calcsize(OFP_EXPERIMENTER_HEADER_PACK_STR) + OFP_HEADER_SIZE + == OFP_EXPERIMENTER_HEADER_SIZE) + +# define constants +OFP_VERSION = 0x04 +OFP_TCP_PORT = 6633 +MAX_XID = 0xffffffff diff --git a/ryu/ofproto/ofproto_v1_3_parser.py b/ryu/ofproto/ofproto_v1_3_parser.py new file mode 100644 index 00000000..1bca5997 --- /dev/null +++ b/ryu/ofproto/ofproto_v1_3_parser.py @@ -0,0 +1,1568 @@ +# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2012 Isaku Yamahata <yamahata at valinux co jp> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import collections +import struct + +from ofproto_parser import MsgBase, msg_pack_into, msg_str_attr +from . import ofproto_parser +from . import ofproto_v1_3 + +import logging +LOG = logging.getLogger('ryu.ofproto.ofproto_v1_3_parser') + +_MSG_PARSERS = {} + + +def _set_msg_type(msg_type): + def _set_cls_msg_type(cls): + cls.cls_msg_type = msg_type + return cls + return _set_cls_msg_type + + +def _register_parser(cls): + '''class decorator to register msg parser''' + assert cls.cls_msg_type is not None + assert cls.cls_msg_type not in _MSG_PARSERS + _MSG_PARSERS[cls.cls_msg_type] = cls.parser + return cls + + +@ofproto_parser.register_msg_parser(ofproto_v1_3.OFP_VERSION) +def msg_parser(datapath, version, msg_type, msg_len, xid, buf): + parser = _MSG_PARSERS.get(msg_type) + return parser(datapath, version, msg_type, msg_len, xid, buf) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_HELLO) +class OFPHello(MsgBase): + def __init__(self, datapath): + super(OFPHello, self).__init__(datapath) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_ERROR) +class OFPErrorMsg(MsgBase): + def __init__(self, datapath): + super(OFPErrorMsg, self).__init__(datapath) + self.type = None + self.code = None + self.data = None + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPErrorMsg, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + msg.type, msg.code = struct.unpack_from( + ofproto_v1_3.OFP_ERROR_MSG_PACK_STR, msg.buf, + ofproto_v1_3.OFP_HEADER_SIZE) + msg.data = msg.buf[ofproto_v1_3.OFP_ERROR_MSG_SIZE:] + return msg + + def _serialize_body(self): + assert self.data is not None + msg_pack_into(ofproto_v1_3.OFP_ERROR_MSG_PACK_STR, self.buf, + ofproto_v1_3.OFP_HEADER_SIZE, self.type, self.code) + self.buf += self.data + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_ECHO_REQUEST) +class OFPEchoRequest(MsgBase): + def __init__(self, datapath): + super(OFPEchoRequest, self).__init__(datapath) + self.data = None + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPEchoRequest, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + msg.data = msg.buf[ofproto_v1_3.OFP_HEADER_SIZE:] + return msg + + def _serialize_body(self): + assert self.data is not None + self.buf += self.data + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_ECHO_REPLY) +class OFPEchoReply(MsgBase): + def __init__(self, datapath): + super(OFPEchoReply, self).__init__(datapath) + self.data = None + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPEchoReply, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + msg.data = msg.buf[ofproto_v1_3.OFP_HEADER_SIZE:] + return msg + + def _serialize_body(self): + assert self.data is not None + self.buf += self.data + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_EXPERIMENTER) +class OFPExperimenter(MsgBase): + def __init__(self, datapath, experimenter=None, exp_type=None): + super(OFPExperimenter, self).__init__(datapath) + self.experimenter = experimenter + self.exp_type = exp_type + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPExperimenter, cls).parser(datapath, version, + msg_type, msg_len, + xid, buf) + (msg.experimenter, msg.exp_type) = struct.unpack_from( + ofproto_v1_3.OFP_EXPERIMENTER_HEADER_PACK_STR, msg.buf, + ofproto_v1_3.OFP_HEADER_SIZE) + return msg + + def _serialize_body(self): + msg.pack_into(ofproto_v1_3.OFP_EXPERIMENTER_HEADERPACK_STR, + self.buf, ofproto_v1_3.OFP_HEADER_SIZE, + self.experimenter, self.exp_type) + + +@_set_msg_type(ofproto_v1_3.OFPT_FEATURES_REQUEST) +class OFPFeaturesRequest(MsgBase): + def __init__(self, datapath): + super(OFPFeaturesRequest, self).__init__(datapath) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_FEATURES_REPLY) +class OFPSwitchFeatures(MsgBase): + def __init__(self, datapath): + super(OFPSwitchFeatures, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPSwitchFeatures, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + (msg.datapath_id, + msg.n_buffers, + msg.n_tables, + msg.auxiliary_id, + msg.capabilities, + msg.reserved) = struct.unpack_from( + ofproto_v1_3.OFP_SWITCH_FEATURES_PACK_STR, msg.buf, + ofproto_v1_3.OFP_HEADER_SIZE) + return msg + + +@_set_msg_type(ofproto_v1_3.OFPT_GET_CONFIG_REQUEST) +class OFPGetConfigRequest(MsgBase): + def __init__(self, datapath): + super(OFPGetConfigRequest, self).__init__(datapath) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_GET_CONFIG_REPLY) +class OFPGetConfigReply(MsgBase): + def __init__(self, datapath): + super(OFPGetConfigReply, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPGetConfigReply, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + msg.flags, msg.miss_send_len = struct.unpack_from( + ofproto_v1_3.OFP_SWITCH_CONFIG_PACK_STR, buf, + ofproto_v1_3.OFP_HEADER_SIZE) + return msg + + +@_set_msg_type(ofproto_v1_3.OFPT_SET_CONFIG) +class OFPSetConfig(MsgBase): + def __init__(self, datapath, flags=None, miss_send_len=None): + super(OFPSetConfig, self).__init__(datapath) + self.flags = flags + self.miss_send_len = miss_send_len + + def _serialize_body(self): + assert self.flags is not None + assert self.miss_send_len is not None + msg_pack_into(ofproto_v1_3.OFP_SWITCH_CONFIG_PACK_STR, + self.buf, ofproto_v1_3.OFP_HEADER_SIZE, + self.flags, self.miss_send_len) + + +class OFPMatch(object): + def __init__(self): + super(OFPMatch, self).__init__() + + @classmethod + def parser(cls, buf, offset): + pass + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_PACKET_IN) +class OFPPacketIn(MsgBase): + def __init__(self, datapath): + super(OFPPacketIn, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPPacketIn, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + (msg.buffer_id, msg.total_len, msg.reason, + msg.table_id, msg.cookie) = struct.unpack_from( + ofproto_v1_3.OFP_PACKET_IN_PACK_STR, + msg.buf, ofproto_v1_3.OFP_HEADER_SIZE) + + offset = ofproto_v1_3.OFP_HEADER_SIZE + ofproto_v1_3.OFP_PACKET_IN_SIZE + msg.match = OFPMatch.parser(buf, offset - ofproto_v1_3.OFP_MATCH_SIZE) + return msg + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_FLOW_REMOVED) +class OFPFlowRemoved(MsgBase): + def __init__(self, datapath): + super(OFPFlowRemoved, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPFlowRemoved, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + + (msg.cookie, msg.priority, msg.reason, + msg.table_id, msg.duration_sec, msg.duration_nsec, + msg.idle_timeout, msg.hard_timeout, msg.packet_count, + msg.byte_count) = struct.unpack_from( + ofproto_v1_3.OFP_FLOW_REMOVED_PACK_STR0, + msg.buf, ofproto_v1_3.OFP_HEADER_SIZE) + + offset = (ofproto_v1_3.OFP_FLOW_REMOVED_SIZE - + ofproto_v1_3.OFP_MATCH_SIZE) + + msg.match = OFPMatch(buf, offset) + + return msg + + +class OFPPort(collections.namedtuple('OFPPort', ( + 'port_no', 'hw_addr', 'name', 'config', 'state', 'curr', + 'advertised', 'supported', 'peer', 'curr_speed', 'max_speed'))): + + @classmethod + def parser(cls, buf, offset): + port = struct.unpack_from(ofproto_v1_3.OFP_PORT_PACK_STR, buf, offset) + return cls(*port) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_PORT_STATUS) +class OFPPortStatus(MsgBase): + def __init__(self, datapath): + super(OFPPortStatus, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPPortStatus, cls).parser(datapath, version, msg_type, + msg_len, xid, buf) + (msg.reason,) = struct.unpack_from( + ofproto_v1_3.OFP_PORT_STATUS_PACK_STR, msg.buf, + ofproto_v1_3.OFP_HEADER_SIZE) + msg.desc = OFPPort.parser(msg.buf, + ofproto_v1_3.OFP_PORT_STATUS_DESC_OFFSET) + return msg + + +@_set_msg_type(ofproto_v1_3.OFPT_PACKET_OUT) +class OFPPacketOut(MsgBase): + def __init__(self, datapath, buffer_id=None, inport=None, actions=None, + data=None): + assert in_port is not None + + super(OFPPacketOut, self).__init__(datapath) + self.buffer_id = buffer_id + self.in_port = in_port + self.actions_len = 0 + self.actions = actions + self.data = data + + def _serialize_body(self): + self.actions_len = 0 + offset = ofproto_v1_3.OFP_PACKET_OUT_SIZE + for a in self.actions: + a.serialize(self.buf, offset) + offset += a.len + self.actions_len += a.len + + if self.data is not None: + assert self.buffer_id == 0xffffffff + self.buf += self.data + + msg_pack_into(ofproto_v1_3.OFP_PACKET_OUT_PACK_STR, + self.buf, ofproto_v1_3.OFP_HEADER_SIZE, + self.buffer_id, self.in_port, self.actions_len) + + +@_set_msg_type(ofproto_v1_3.OFPT_FLOW_MOD) +class OFPFlowMod(MsgBase): + def __init__(self, datapath, cookie, cookie_mask, table_id, command, + idle_timeout, hard_timeout, priority, buffer_id, out_port, + out_group, flags, match): + super(OFPFlowMod, self).__init__(datapath) + self.cookie = cookie + self.cookie_mask = cookie_mask + self.table_id = table_id + self.command = command + self.idle_timeout = idle_timeout + self.hard_timeout = hard_timeout + self.priority = priority + self.buffer_id = buffer_id + self.out_port = out_port + self.out_group = out_group + self.flags = flags + self.match = match + + def _serialize_body(self): + msg_pack_into(ofproto_v1_3.OFP_FLOW_MOD_PACK_STR0, self.buf, + ofproto_v1_3.OFP_HEADER_SIZE, + self.cookie, self.cookie_mask, self.table_id, + self.command, self.idle_timeout, self.hard_timeout, + self.priority, self.buffer_id, self.out_port, + self.out_group, self.flags) + + offset = (ofproto_v1_3.OFP_OFP_FLOW_MOD_SIZE - + ofproto_v1_3.OFP_MATCH_SIZE - ofproto_v1_3.OFP_HEADER_SIZE) + self.match.serialize(self.buf, offset) + + +class OFPActionHeader(object): + def __init__(self, type_, len_): + self.type = type_ + self.len = len_ + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_HEADER_PACK_STR, + buf, offset, self.type, self.len) + + +class OFPAction(OFPActionHeader): + _ACTION_TYPES = {} + + @staticmethod + def register_action_type(type_, len_): + def _register_action_type(cls): + cls.cls_action_type = type_ + cls.cls_action_len = len_ + OFPAction._ACTION_TYPES[cls.cls_action_type] = cls + return cls + return _register_action_type + + def __init__(self): + cls = self.__class__ + super(OFPAction, self).__init__(cls.cls_action_type, + cls.cls_action_len) + + @classmethod + def parser(cls, buf, offset): + type_, len_ = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_HEADER_PACK_STR, buf, offset) + cls_ = cls._ACTION_TYPES.get(type_) + assert cls_ is not None + return cls_.parser(buf, offset) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_OUTPUT, + ofproto_v1_3.OFP_ACTION_OUTPUT_SIZE) +class OFPActionOutput(OFPAction): + def __init__(self, port, max_len): + super(OFPActionOutput, self).__init__() + self.port = port + self.max_len = max_len + + @classmethod + def parser(cls, buf, offset): + type_, len_, port, max_len = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_OUTPUT_PACK_STR, buf, offset) + return cls(port, max_len) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_OUTPUT_PACK_STR, buf, + offset, self.type, self.len, self.port, self.max_len) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_GROUP, + ofproto_v1_3.OFP_ACTION_GROUP_SIZE) +class OFPActionGroup(OFPAction): + def __init__(self, group_id): + super(OFPActionGroup, self).__init__() + self.group_id = group_id + + @classmethod + def parser(cls, buf, offset): + (type_, len_, group_id) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_GROUP_PACK_STR, buf, offset) + return cls(group_id) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_GROUP_PACK_STR, buf, + offset, self.type, self.len, self.group_id) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_SET_QUEUE, + ofproto_v1_3.OFP_ACTION_SET_QUEUE_SIZE) +class OFPActionSetQueue(OFPAction): + def __init__(self, queue_id): + super(OFPActionSetQueue, self).__init__() + self.queue_id = queue_id + + @classmethod + def parser(cls, buf, offset): + (type_, len_, queue_id) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_SET_QUEUE_PACK_STR, buf, offset) + return cls(queue_id) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_SET_QUEUE_PACK_STR, buf, + offset, self.type, self.len, self.queue_id) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_SET_MPLS_TTL, + ofproto_v1_3.OFP_ACTION_MPLS_TTL_SIZE) +class OFPActionSetMplsTtl(OFPAction): + def __init__(self, mpls_ttl): + super(OFPActionSetMplsTtl, self).__init__() + self.mpls_ttl = mpls_ttl + + @classmethod + def parser(cls, buf, offset): + (type_, len_, mpls_ttl) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_MPLS_TTL_PACK_STR, buf, offset) + return cls(mpls_ttl) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_MPLS_TTL_PACK_STR, buf, + offset, self.type, self.len, self.mpls_ttl) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_DEC_MPLS_TTL, + ofproto_v1_3.OFP_ACTION_HEADER_SIZE) +class OFPActionDecMplsTtl(OFPAction): + def __init__(self): + super(OFPActionDecMplsTtl, self).__init__() + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_SET_NW_TTL, + ofproto_v1_3.OFP_ACTION_NW_TTL_SIZE) +class OFPActionSetNwTtl(OFPAction): + def __init__(self, nw_ttl): + super(OFPActionSetNwTtl, self).__init__() + self.nw_ttl = nw_ttl + + @classmethod + def parser(cls, buf, offset): + (type_, len_, nw_ttl) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_NW_TTL_PACK_STR, buf, offset) + return cls(nw_ttl) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_NW_TTL_PACK_STR, buf, offset, + self.type, self.len, self.nw_ttl) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_DEC_NW_TTL, + ofproto_v1_3.OFP_ACTION_HEADER_SIZE) +class OFPActionDecNwTtl(OFPAction): + def __init__(self): + super(OFPActionDecNwTtl, self).__init__() + + @classmethod + def parser(cls, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_HEADER_PACK_STR, buf, offset) + return cls() + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_COPY_TTL_OUT, + ofproto_v1_3.OFP_ACTION_HEADER_SIZE) +class OFPActionCopyTtlOut(OFPAction): + def __init__(self): + super(OFPActionCopyTtlOut, self).__init__() + + @classmethod + def parser(cls, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_HEADER_PACK_STR, buf, offset) + return cls() + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_COPY_TTL_IN, + ofproto_v1_3.OFP_ACTION_HEADER_SIZE) +class OFPActionCopyTtlIn(OFPAction): + def __init__(self): + super(OFPActionCopyTtlIn, self).__init__() + + @classmethod + def parser(cls, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_HEADER_PACK_STR, buf, offset) + return cls() + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_PUSH_VLAN, + ofproto_v1_3.OFP_ACTION_PUSH_SIZE) +class OFPActionPushVlan(OFPAction): + def __init__(self, ethertype): + super(OFPActionPushVlan, self).__init__() + self.ethertype = ethertype + + @classmethod + def parser(cls, buf, offset): + (type_, len_, ethertype) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_PUSH_PACK_STR, buf, offset) + return cls(ethertype) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_PUSH_PACK_STR, buf, offset, + self.type, self.len, self.ethertype) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_PUSH_MPLS, + ofproto_v1_3.OFP_ACTION_PUSH_SIZE) +class OFPActionPushMpls(OFPAction): + def __init__(self, ethertype): + super(OFPActionPushMpls, self).__init__() + self.ethertype = ethertype + + @classmethod + def parser(cls, buf, offset): + (type_, len_, ethertype) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_PUSH_PACK_STR, buf, offset) + return cls(ethertype) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_PUSH_PACK_STR, buf, offset, + self.ethertype) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_POP_VLAN, + ofproto_v1_3.OFP_ACTION_HEADER_SIZE) +class OFPActionPopVlan(OFPAction): + def __init__(self): + super(OFPActionPopVlan, self).__init__() + + @classmethod + def parser(cls, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_HEADER_PACK_STR, buf, offset) + return cls() + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_POP_MPLS, + ofproto_v1_3.OFP_ACTION_POP_MPLS_SIZE) +class OFPActionPopMpls(OFPAction): + def __init__(self, ethertype): + super(OFPActionPopMpls, self).__init__() + self.ethertype = ethertype + + @classmethod + def parser(cls, buf, offset): + (type_, len_, ethertype) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_POP_MPLS_PACK_STR, buf, offset) + return cls(ethertype) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_POP_MPLS_PACK_STR, buff, offset, + self.ethertype) + + +@OFPAction.register_action_type(ofproto_v1_3.OFPAT_SET_FIELD, + ofproto_v1_3.OFP_ACTION_SET_FIELD_SIZE) +class OFPActionSetField(OFPAction): + def __init__(self): + super(OFPActionSetField, self).__init__() + + @classmethod + def parser(cls, buf, offset): + (type_, len_) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_SET_FIELD_PACK_STR, buf, offset) + action = cls() + # TODO: parse OXM + return action + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_SET_FIELD_PACK_STR, buf, offset) + # TODO: serialize OXM + + +@OFPAction.register_action_type( + ofproto_v1_3.OFPAT_EXPERIMENTER, + ofproto_v1_3.OFP_ACTION_EXPERIMENTER_HEADER_SIZE) +class OFPActionExperimenter(OFPAction): + def __init__(self, experimenter): + super(OFPActionExperimenter, self).__init__() + self.experimenter = experimenter + + @classmethod + def parser(cls, buf, offset): + (type_, len_, experimenter) = struct.unpack_from( + ofproto_v1_3.OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR, buf, offset) + return cls(experimenter) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_ACTION_EXPERIMENTER_HEADER_PACK_STR, + buf, offset, self.type, self.len, self.experimenter) + + +class OFPBucket(object): + def __init__(self, len_, weight, watch_port, watch_group, actions): + super(OFPBucket, self).__init__() + self.len = len_ + self.weight = weight + self.watch_port = watch_port + self.watch_group = watch_group + self.actions = actions + + @classmethod + def parser(cls, buf, offset): + (msg.len, msg.weigth, msg.watch_port, + msg.watch_group) = struct.unpack_from( + ofproto_v1_3.OFP_BUCKET_PACK_STR, buf, offset) + + length = ofproto_v1_3.OFP_BUCKET_SIZE + offset += ofproto_v1_3.OFP_BUCKET_SIZE + msg.actions = [] + while length < msg.len: + action = OFPAction.parser(buf, offset) + msg.actions.append(action) + offset += action.len + length += action.len + + return msg + + +@_set_msg_type(ofproto_v1_3.OFPT_GROUP_MOD) +class OFPGroupMod(MsgBase): + def __init__(self, datapath, command, type_, group_id, buckets): + super(OFPGroupMod, self).__init__(datapath) + self.command = command + self.type = type_ + self.group_id = group_id + self.buckets = buckets + + def _serialize_body(self): + msg_pack_into(ofproto_v1_3.OFP_GROUP_MOD_PACK_STR, self.buf, + ofproto_v1_3.OFP_HEADER_SIZE, + self.command, self.type, self.group_id) + + offset = ofproto_v1_3.OFP_HEADER_SIZE + ofproto_v1_3.OFP_GROUP_MOD_SIZE + for b in self.buckets: + b.serialize(self, buf, offset) + offset += b.len + + +@_set_msg_type(ofproto_v1_3.OFPT_PORT_MOD) +class OFPPortMod(MsgBase): + def __init__(self, datapath, port_no, hw_addr, config, mask, advertise): + super(OFPPortMod, self).__init__(datapath) + self.port_no = port_no + self.hw_addr = hw_addr + self.config = config + self.mask = mask + self.advertise = advertise + + def _serialize_body(self): + msg_pack_into(ofproto_v1_3.OFP_PORT_MOD_PACK_STR, self.buf, + ofproto_v1_3.OFP_HEADER_SIZE, + self.port_no, self.hw_addr, self.config, + self.mask, self.advertise) + + +@_set_msg_type(ofproto_v1_3.OFPT_TABLE_MOD) +class OFPTableMod(MsgBase): + def __init__(self, datapath, table_id, config): + super(OFPTableMod, self).__init__(datapath) + self.table_id = table_id + self.config = config + + def _serialize_body(self): + msg_pack_into(ofproto_v1_3.OFP_TABLE_MOD_PACK_STR, self.buf, + ofproto_v1_3.OFP_HEADER_SIZE, + self.table_id, self.config) + + +def _set_stats_type(stats_type, stats_body_cls): + def _set_cls_stats_type(cls): + cls.cls_stats_type = stats_type + cls.cls_stats_body_cls = stats_body_cls + return cls + return _set_cls_stats_type + + +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPMultipartRequest(MsgBase): + def __init__(self, datapath, flags): + assert flags == 0 # none yet defined + + super(OFPMultipartRequest, self).__init__(datapath) + self.type = self.__class__cls.stats_type + self.flags = flags + + def _serialize_stats_body(): + pass + + def _serialize_body(self): + msg_pack_into(ofproto_v1_3.OFP_MULTIPART_REQUEST_PACK_STR, + self.buf, ofproto_v1_3.OFP_HEADER_SIZE, + self.type, self.flags) + self._serialize_stats_body() + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPMultipartReply(MsgBase): + _STATS_MSG_TYPES = {} + + @staticmethod + def register_stats_type(body_single_struct=False): + def _register_stats_type(cls): + assert cls.cls_stats_type is not None + assert cls.cls_stats_type not in OFPMultipartReply._STATS_MSG_TYPES + assert cls.cls_stats_body_cls is not None + cls.cls_body_single_struct = body_single_struct + OFPMultipartReply._STATS_MSG_TYPES[cls.cls_stats_type] = cls + return cls + return _register_stats_type + + def __init__(self, datapath, type_, flags): + super(OFPMultipartReply, self).__init__(datapath) + self.type = type_ + self.flags = flags + self.body = None + + @classmethod + def parser_stats_body(cls, buf, msg_len, offset): + body_cls = cls.cls_stats_body_cls + body = [] + while offset < msg_len: + entry = body_cls.parser(buf, offset) + body.append(entry) + offset += entry.length + + if cls.cls_body_single_struct: + return body[0] + return body + + @classmethod + def parser_stats(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = MsgBase.parser.__func__( + cls, datapath, version, msg_type, msg_len, xid, buf) + msg.body = msg.parser_stats_body(msg.buf, msg.msg_len, + ofproto_v1_3.OFP_MULTIPART_REPLY_SIZE) + return msg + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + type_, flags = struct.unpack_from( + ofproto_v1_3.OFP_MULTIPART_REPLY_PACK_STR, buffer(buf), + ofproto_v1_3.OFP_HEADER_SIZE) + stats_type_cls = cls._STATS_MSG_TYPES.get(type_) + msg = stats_type_cls.parser_stats( + datapath, version, msg_type, msg_len, xid, buf) + msg.type = type_ + msg.flags = flags + return msg + + +class OFPDescStats(collections.namedtuple('OFPDescStats', + ('mfr_desc', 'hw_desc', 'sw_desc', 'serial_num', 'dp_desc'))): + @classmethod + def parser(cls, buf, offset): + desc = struct.unpack_from(ofproto_v1_3.OFP_DESC_PACK_STR, + buf, offset) + stats = cls(*desc) + stats.length = ofproto_v1_3.OFP_DESC_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_DESC, OFPDescStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPDescStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags): + super(OFPDescStatsRequest, self).__init__(datapath, flags) + + +@OFPMultipartReply.register_stats_type(body_single_struct=True) +@_set_stats_type(ofproto_v1_3.OFPMP_DESC, OFPDescStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPDescStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPDescStatsReply, self).__init__(datapath) + + +class OFPFlowStats(object): + def __init__(self): + super(OFPFlowStats, self).__init__() + self.length = None + self.table_id = None + self.duration_sec = None + self.duration_nsec = None + self.priority = None + self.idle_timeout = None + self.hard_timeout = None + self.flags + self.cookie = None + self.packet_count = None + self.byte_count = None + self.match = None + + @classmethod + def parser(cls, buf, offset): + flow_stats = cls() + + (flow_stats.length, flow_stats.table_id, + flow_stats.duration_sec, flow_stats.duration_nsec, + flow_stats.priority, flow_stats.idle_timeout, + flow_stats.cookie, flow_stats.packet_count, + flow_stats.byte_count) = struct.unpack_from( + ofproto_v1_3.OFP_FLOW_STATS_0_PACK_STR, buf, offset) + offset += ofproto_v1_3.OFP_FLOW_STATS_0_SIZE + + flow_stats.match = OFPMatch.parse(buf, offset) + + return flow_stats + + +class OFPFlowStatsRequestBase(OFPMultipartRequest): + def __init__(self, datapath, flags, table_id, out_port, out_group, + cookie, cookie_mask): + super(OFPFlowStatsRequestBase, self).__init__(datapath, flags) + self.table_id = table_id + self.out_port = out_port + self.out_group = out_group + self.cookie = cookie + self.cookie_mask = cookie_mask + self.match = match + + def _serialize_stats_body(self): + offset = ofproto_v1_3.OFP_MULTIPART_REQUEST_SIZE + msg_pack_into(ofproto_v1_3.OFP_FLOW_STATS_REQUEST_0_PACK_STR, + self.buf, offset, self.table_id, self.out_port, + self.out_group, self.cookie, self.cookie_mask) + + offset += OFP_FLOWSTAT_REQUEST_0_SIZE + self.match.serialize(self.buf, offset) + + +@_set_stats_type(ofproto_v1_3.OFPMP_FLOW, OFPFlowStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPFlowStatsRequest(OFPFlowStatsRequestBase): + def __init__(self, datapath, flags, table_id, out_port, out_group, + cookie, cookie_mask): + super(OFPFlowStatsRequest, self).__init__(datapath, table_id, + out_port, out_group, + cookie, cookie_mask) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_FLOW, OFPFlowStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPFlowStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPFlowStatsReply, self).__init__(datapath) + + +class OFPAggregateStats(collections.namedtuple('OFPAggregateStats', + ('packet_count', 'byte_count', 'flow_count'))): + @classmethod + def parser(cls, buf, offset): + agg = struct.unpack_from( + ofproto_v1_3.OFP_AGGREGATE_STATS_REPLY_PACK_STR, buf, offset) + stats = cls(*agg) + stats.length = ofproto_v1_3.OFP_AGGREGATE_STATS_REPLY_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPST_AGGREGATE, OFPAggregateStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPAggregateStatsRequest(OFPFlowStatsRequestBase): + def __init__(self, datapath, flags, table_id, out_port, out_group, + cookie, cookie_mask): + super(OFPAggregateStatsRequest, self).__init__(datapath, + table_id, + out_port, + out_group, + cookie, + cookie_mask) + + +@OFPmultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_AGGREGATE, OFPAggregateStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPAggregateStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPAggregateStatsReply, self).__init__(datapath) + + +class OFPTableStats(collections.namedtuple('OFPTableStats', + ('table_id', 'active_count', 'lookup_count', + 'matched_count'))): + @classmethod + def parser(cls, buf, offset): + tbl = struct.unpack_from(ofproto_v1_3.OFP_TABLE_STATS_PACK_STR, + buf, offset) + stats = cls(*tbl) + stats.length = ofproto_v1_3.OFP_TABLE_STATS_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_TABLE, OFPTableStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPTableStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags): + super(OFPTableStatsRequest, self).__init__(datapath, flags) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_TABLE, OFPTableStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPTableStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPTableStatsReply, self).__init__(datapath) + + +class OFPPortStats(collections.namedtuple('OFPPortStats', + ('port_no', 'rx_packets', 'tx_packets', 'rx_bytes', 'tx_bytes', + 'rx_dropped', 'tx_dropped', 'rx_errors', 'tx_errors', + 'rx_frame_err', 'rx_over_err', 'rx_crc_err', 'collisions', + 'duration_sec', 'duration_nsec'))): + @classmethod + def parser(cls, buf, offset): + port = struct.unpack_from(ofproto_v1_3.OFP_PORT_STATS_PACK_STR, + buf, offset) + stats = cls(*port) + stats.length = ofproto_v1_3.OFP_PORT_STATS_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_PORT_STATS, OFPPortStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPPortStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, port_no): + super(OFPPortStatsRequest, self).__init__(datapath, flags) + self.port_no = port_no + + def _serialize_stats_body(self): + msg_pack_into(ofproto_v1_3.OFP_PORT_STATS_REQUEST_PACK_STR, + self.buf, + ofproto_v1_3.OFP_MULTIPART_REQUEST_SIZE, + self.port_no) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_PORT_STATS, OFPPortStats) +@_set_msg_type(ofproto_v1_0.OFPT_STATS_REPLY) +class OFPPortStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPPortStatsReply, self).__init__(datapath) + + +class OFPQueueStats(collections.namedtuple('OFPQueueStats', + ('port_no', 'queue_id', 'tx_bytes', 'tx_packets', 'tx_errors', + 'duration_sec', 'duration_nsec'))): + @classmethod + def parser(cls, buf, offset): + queue = struct.unpack_from(ofproto_v1_3.OFP_QUEUE_STATS_PACK_STR, + buf, offset) + stats = cls(*queue) + stats.length = ofproto_v1_3.OFP_QUEUE_STATS_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_QUEUE, OFPQueueStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPQueueStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, port_no, queue_id): + super(OFPQueueStatsRequest, self).__init__(datapath, flags) + self.port_no = port_no + self.queue_id = queue_id + + def _serialize_stats_body(self): + msg_pack_into(ofproto_v1_3.OFP_QUEUE_STATS_REQUEST_PACK_STR, + self.buf, + ofproto_v1_3.OFP_MULTIPART_REQUEST_SIZE, + self.port_no, self.queue_id) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_QUEUE, OFPQueueStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPQueueStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPQueueStatsReply, self).__init__(datapath) + + +class OFPGroupStats(collections.namedtuple('OFPGroupStats', + ('length', 'group_id', 'ref_count', 'packet_count', + 'byte_count', 'duration_sec', 'duration_nsec'))): + @classmethod + def parser(cls, buf, offset): + group = struct.unpack_from(ofproto_v1_3.OFP_GROUP_STATS_PACK_STR, + buf, offset) + stats = cls(*group) + stats.length = ofproto_v1_3.OFP_GROUP_STATS_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_GROUP, OFPGroupStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPGroupStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, group_id): + super(OFPGroupStatsRequest, self).__init__(datapath, flags) + self.group_id = group_id + + def _serialize_stats_body(self): + msg_pack_into(ofproto_v1_3.OFP_GROUP_STATS_REQUEST_PACK_STR, + self.buf, + ofproto_v1_3.OFP_MULTIPART_REQUEST_SIZE, + self.group_id) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_GROUP, OFPGroupStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPGroupStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPGroupStatsReply, self).__init__(datapath) + + +class OFPGroupDescStats(object): + def __init__(self): + super(OFPGroupDescStats).__init__() + self.length = None + self.type = None + self.group_id = None + self.ofp_bucket = None + + @classmethod + def parser(cls, buf, offset): + stats = cls() + + (stats.length, stats.type, stats.group_id) = struct.unpack_from( + ofproto_v1_3.OFP_GROUP_DESC_STATS_PACK_STR, buf, offset) + offset += ofproto_v1_3.OFP_GROUP_DESC_STATS_SIZE + + stats.bucket = [] + length = ofproto_v1_3.OFP_GROUP_DESC_STATS_SIZE + while length < stats.length: + bucket = OFPBucket.parser(buf, offset) + stats.bucket.append(bucket) + + offset += bucket.len + length += bucket.len + + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_GROUP_DESC, OFPGroupDescStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPGroupDescStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, port_no): + super(OFPGroupDescStatsRequest, self).__init__(datapath, flags) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_GROUP_DESC, OFPGroupDescStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPGroupDescStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPGroupDescStatsReply, self).__init__(datapath) + + +class OFPGroupFeaturesStats(collections.namedtuple('OFPGroupFeaturesStats', + ('types', 'capabilities', 'max_groups', 'actions'))): + @classmethod + def parser(cls, buf, offset): + group_features = struct.unpack_from( + ofproto_v1_3.OFP_GROUP_FEATURES_PACK_STR, buf, offset) + stats = cls(*group_features) + stats.length = ofproto_v1_3.OFP_GROUP_FEATURES_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_GROUP_FEATURES, OFPGroupFeaturesStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPGroupFeaturesStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, port_no): + super(OFPGroupFeaturesRequest, self).__init__(datapath, flags) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_GROUP_FEATURES, OFPGroupFeaturesStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPGroupFeaturesStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPGroupFeaturesStatsReply, self).__init__(datapath) + + +class OFPMeterBandStats(object): + def __init__(self, packet_band_count, byte_band_count): + super(OFPMeterBandStats, self).__init__() + self.packet_band_count = packet_bound_count + self.byte_band_count = byte_band_count + + @classmethod + def parser(cls, buf, offset): + band_stats = struct.unpack_from( + ofproto_v1_3.OFP_METER_BAND_STATS_PACK_STR, buf, offset) + return cls(*band_stats) + + +class OFPMeterStats(object): + def __init__(self): + super(OFPMeterStats, self).__init__() + self.meter_id = None + self.len = None + self.flow_count = None + self.packet_in_count = None + self.byte_in_count = None + self.duration_sec = None + self.duration_nsec = None + self.band_stats = None + + @classmethod + def parser(cls, buf, offset): + meter_stats = cls() + + (meter_stats.meter_id, meter_stats.len, + meter_stats.flow_count, meter_stats.packet_in_count, + meter_stats.byte_in_count, meter_stats.duration_sec, + meter_stats.duration_nsec) = struct.unpack_from( + ofproto_v1_3.OFP_METER_STATS_PACK_STR, buf, offset) + offset += ofproto_v1_3.OFP_METER_STATS_SIZE + + meter_stats.band_stats = [] + length = ofproto_v1_3.OFP_METER_STATS_SIZE + while length < meter_stats.len: + band_stats = OFPMeterBandStats.parser(buf, offset) + meter_stats.band_stats.append(band_stats) + offset += ofproto_v1_3.OFP_METER_BAND_STATS_SIZE + length += ofproto_v1_3.OFP_METER_BAND_STATS_SIZE + + return meter_stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_METER, OFPMeterStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPMeterStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, meter_id): + super(OFPMeterStatsRequest, self).__init__(datapath, flags) + self.meter_id = meter_id + + def _serialize_stats_body(self): + msg_pack_into(ofproto_v1_3.OFP_METER_MULTIPART_REQUEST_PACK_STR, + self.buf, + ofproto_v1_3.OFP_MULTIPART_REQUEST_SIZE, + self.meter_id) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_METER, OFPMeterStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPMeterStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPMeterStatsReply, self).__init__(datapath) + + +class OFPMeterBandHeader(object): + def __init__(self, type_, len_, rate, burst_size): + self.type = type_ + self.len = len_ + self.rate = rate + self.burst_size = burst_size + + @classmethod + def parser(cls, buf, offset): + band_header = struct.unpack_from( + ofproto_v1_3.OFP_METER_BAND_HEADER_PACK_STR, buf, offset) + return cls(*band_header) + + +class OFPMeterConfigStats(object): + def __init__(self): + super(OFPMeterConfigStats, self).__init__() + self.length = None + self.flags = None + self.meter_id = None + self.bands = None + + @classmethod + def parser(cls, buf, offset): + meter_config = cls() + + (meter_config.length, meter_config.flags, + meter_config.meter_id) = struct.unpack_from( + ofproto_v1_3.OFP_METER_CONFIG_PACK_STR, buf, offset) + offset += ofproto_v1_3.OFP_METER_CONFIG_SIZE + + meter_config.bands = [] + length = ofproto_v1_3.OFP_METER_CONFIG_SIZE + while length < meter_config.length: + band_header = OFPMeterBandHeader.parser(buf, offset) + meter_config.bands.append(band_header) + offset += band_header.len + length += band_header.len + + return meter_config + + +@_set_stats_type(ofproto_v1_3.OFPMP_METER_CONFIG, OFPMeterConfigStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPMeterConfigStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, meter_id): + super(OFPMeterConfigStatsRequest, self).__init__(datapath, flags) + self.meter_id = meter_id + + def _serialize_stats_body(self): + msg_pack_into(ofproto_v1_3.OFP_METER_MULTIPART_REQUEST_PACK_STR, + self.buf, + ofproto_v1_3.OFP_MULTIPART_REQUEST_SIZE, + self.meter_id) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_METER_CONFIG, OFPMeterCOnfigStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPMeterConfigStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPMeterConfigStatsReply, self).__init__(datapath) + + +class OFPMeterFeaturesStats(collections.namedtuple('OFPMeterFeaturesStats', + ('max_meter', 'band_types', 'capabilities', 'max_band', + 'max_color'))): + @classmethod + def parser(cls, buf, offset): + meter_features = struct.unpack_from( + ofproto_v1_3.OFP_METER_FEATURES_PACK_STR, buf, offset) + stats = cls(*meter_features) + stats.length = ofproto_v1_3.OFP_METER_FEATURES_SIZE + return stats + + +@_set_stats_type(ofproto_v1_3.OFPMP_METER_FEATUERS, OFPMeterFeaturesStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPMeterFeaturesStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, port_no): + super(OFPMeterFeaturesStatsRequest, self).__init__(datapath, flags) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_METER_FEATURES, OFPMeterFeaturesStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPMeterFeaturesStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPMeterFeaturesStatsReply, self).__init__(datapath) + + +class OFPTableFeaturesStats(object): + def __init__(self): + super(OFPTableFeaturesStats, self).__init__() + self.length = None + self.table_id = None + self.name = None + self.metadata_match = None + self.metadata_write = None + self.config = None + self.max_entries = None + self.properties = None + + @classmethod + def parser(cls, buf, offset): + table_features = cls() + (table_features.length, table_features.table_id, + table_features.name, table_features.metadata_match, + table_features.write, table_features.config, + table_features.max_entries, table_features.properties) = \ + struct.unpack_from(ofproto_v1_3.OFP_TABLE_FEATURES_PACK_STR, + buf, offset) + offset += ofproto_v1_3.OFP_TABLE_FEATURES_SIZE + + # TODO: parse ofp_table_feature_prop_header + + return table_features + + +@_set_stats_type(ofproto_v1_3.OFPMP_TABLE_FEATURES, OFPTableFeaturesStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPTableFeaturesStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, length, table_id, name, + metadata_match, metadata_write, config, max_entries, + properties): + super(OFPTableFeaturesStatsRequest, self).__init__(datapath, flags) + self.length = length + self.table_id = table_id + self.name = name + self.metadata_match = metadata_match + self.metadata_write = metadata_write + self.config = config + self.max_entries = max_entries + + def _serialize_stats_body(self): + # TODO + pass + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_TABLE_FEATURES, OFPTableFeaturesStats) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPTableFeaturesStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPTableFeaturesStatsReply, self).__init__(datapath) + + +@_set_stats_type(ofproto_v1_3.OFPMP_PORT_DESC, OFPPort) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REQUEST) +class OFPPortDescStatsRequest(OFPMultipartRequest): + def __init__(self, datapath, flags, port_no): + super(OFPPortDescStatsRequest, self).__init__(datapath, flags) + + +@OFPMultipartReply.register_stats_type() +@_set_stats_type(ofproto_v1_3.OFPMP_PORT_DESC, OFPPort) +@_set_msg_type(ofproto_v1_3.OFPT_MULTIPART_REPLY) +class OFPPortDescStatsReply(OFPMultipartReply): + def __init__(self, datapath): + super(OFPPortDescStatsReply, self).__init__(datapath) + + +# TODO: OFPMP_EXPERIMENTER + + +@_set_msg_type(ofproto_v1_3.OFPT_BARRIER_REQUEST) +class OFPBarrierRequest(MsgBase): + def __init__(self, datapath): + super(OFPBarrierRequest, self).__init__(datapath) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_BARRIER_REPLY) +class OFPBarrierReply(MsgBase): + def __init__(self, datapath): + super(OFPBarrierReply, self).__init__(datapath) + + +@_set_msg_type(ofproto_v1_3.OFPT_QUEUE_GET_CONFIG_REQUEST) +class OFPQueueGetConfigRequest(MsgBase): + def __init__(self, datapath, port): + super(OFPQueueGetConfigRequest, self).__init__(datapath) + self.port = port + + def _serialized_body(self): + msg_pack_into(ofproto_v1_3.OFP_QUEUE_GET_CONFIG_REQUEST_PACK_STR, + self.buf, ofproto_v1_3.OFP_HEADER_SIZE, self.port) + + +class OFPQueuePropHeader(object): + def __init__(self, property_, len_): + self.property = property_ + self.len = len_ + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_3.OFP_QUEUE_PROP_HEADER_PACK_STR, + buf, offset, self.property, self.len) + + +class OFPQueueProp(OFPQueuePropHeader): + _QUEUE_PROP_PROPERTIES = {} + + @staticmethod + def register_queue_property(property_, len_): + def _register_property(cls): + cls.cls_property = property_ + cls.cls_len = len_ + OFPQueueProp._QUEUE_PROP_PROPERTIES[cls.cls_property] = cls + return cls + return _register_queue_property + + def __init__(self): + cls = self.__class__ + super(OFPQueueProp, self).__init__(cls.cls_property, + cls.cls_len) + + @classmethod + def parser(cls, buf, offset): + (property_, len_) = struct.unpack_from( + ofproto_v1_3.OFP_QUEUE_PROP_HEADER_PACK_STR, + buf, offset) + cls_ = cls._QUEUE_PROP_PROPERTIES.get(property_) + return cls_.parser(buf, offset) + + +@OFPQueueProp.register_queue_property( + ofproto_v1_3.OFPQT_MIN_RATE, + ofproto_v1_3.OFP_QUEUE_PROP_MIN_RATE_SIZE) +class OFPQueuePropMinRate(OFPQueueProp): + def __init__(self, rate): + super(OFPQueuePropMinRate, self).__init__() + self.rate = rate + + @classmethod + def parser(cls, buf, offset): + msg = super(OFPQueuePropMinRate, cls).parser(cls, buf, offset) + offset += ofproto_v1_3.OFP_QUEUE_PROP_MIN_RATE_SIZE + (msg.rate,) = struct.unpack_from( + ofproto_v1_3.OFP_QUEUE_PROP_MIN_RATE_PACK_STR, buf, + offset) + return msg + + +@OFPQueueProp.register_queue_property( + ofproto_v1_3.OFPQT_MAX_RATE, + ofproto_v1_3.OFP_QUEUE_PROP_MAX_RATE_SIZE) +class OFPQueuePropMaxRate(OFPQueueProp): + def __init__(self, rate): + super(OFPQueuePropMinRate, self).__init__() + self.rate = rate + + @classmethod + def parser(cls, buf, offset): + msg = super(OFPQueuePropMinRate, cls).parser(cls, buf, offset) + offset += ofproto_v1_3.OFP_QUEUE_PROP_MIN_RATE_SIZE + (msg.rate,) = struct.unpack_from( + ofproto_v1_3.OFP_QUEUE_PROP_MIN_RATE_PACK_STR, buf, + offset) + return msg + + +# TODO: add ofp_queue_prop_experimenter + + +class OFPPacketQueue(MsgBase): + def __init__(self, datapath): + super(OFPPacketQueue, self).__init__(datapath) + + @clasmethod + def parser(cls, buf, offset): + (msg.queue_id, msg.port, msg.len) = struct.unpack_from( + ofproto_v1_3.OFP_PACKET_QUEUE_PACK_STR, buf, offset) + + length = ofproto_v1_3.OFP_PACKET_QUEUE_SIZE + offset += ofproto_v1_3.OFP_PACKET_QUEUE_SIZE + msg.properties = [] + while length < msg.len: + properties = OFPQueueProp.parser(buf, offset) + msg.properties.append(properties) + offset += properties.len + length += properties.len + + return msg + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_QUEUE_GET_CONFIG_REPLY) +class OFPQueueGetConfigReply(MsgBase): + def __init__(self, datapath): + super(OFPQueueGetConfigReply, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPQueueGetConfigReply, cls).parser(datapath, version, + msg_type, + msg_len, xid, buf) + offset = ofproto_v1_3.OFP_HEADER_SIZE + (msg.port,) = struct.unpack_from( + ofproto_v1_3.OFP_QUEUE_GET_CONFIG_REPLY_PACK_STR, msg.buf, + offset) + + msg.queues = [] + offset += ofproto_v1_3.OFP_QUEUE_GET_CONFIG_REPLY_SIZE + while offset < msg.length: + queue = OFPPacketQueue.parser(buf, offset) + msg.queues.append(queue) + offset += queue.len + + return msg + + +@_set_msg_type(ofproto_v1_3.OFPT_ROLE_REQUEST) +class OFPRoleRequest(MsgBase): + def __init__(self, datapath, role=None, generation_id=None): + super(OFPRoleRequest, self).__init__(datapath) + self.role = role + self.generation_id = generation_id + + def __serialize_body(self): + assert self.role is not None + assert self.generation_id is not None + msg_pack_into(ofproto_v1_3.OFP_ROLE_REQUEST_PACK_STR, + self.buf, ofproto_v1_3.OFP_HEADER_SIZE, + self.role, self.generation_id) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_ROLE_REPLY) +class OFPRoleReply(MsgBase): + def __init__(self, datapath): + super(OFPRoleReply, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPRoleReply, cls).parser(datapath, version, + msg_type, msg_len, xid, + buf) + (msg.role, msg.generation_id) = struct.unpack_from( + ofproto_v1_3.OFP_ROLE_REQUEST_PACK_STR, msg.buf, + ofproto_v1_3.OFP_HEADER_SIZE) + + +@_set_msg_type(ofproto_v1_3.OFPT_GET_ASYNC_REQUEST) +class OFPGetAsyncRequest(MsgBase): + def __init__(self, datapath): + super(OFPGetAsyncRequest, self).__init__(datapath) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_GET_ASYNC_REPLY) +class OFPGetAsyncReply(MsgBase): + def __init__(self, datapath): + super(OFPGetAsyncReply, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPGetAsyncReply, cls).parser(datapath, version, + msg_type, msg_len, + xid, buf) + (msg.packet_in_mask, msg.port_status_mask, + msg.flow_removed_mask) = struct.unpack_from( + ofproto_v1_3.OFP_ASYNC_CONFIG_PACK_STR, msg.buf, + ofproto_v1_3.OFP_HEADER_SIZE) + + +@_register_parser +@_set_msg_type(ofproto_v1_3.OFPT_SET_ASYNC) +class OFPGetAsyncReply(MsgBase): + def __init__(self, datapath): + super(OFPSetAsync, self).__init__(datapath) + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPSetAsync, cls).parser(datapath, version, + msg_type, msg_len, + xid, buf) + (msg.packet_in_mask, msg.port_status_mask, + msg.flow_removed_mask) = struct.unpack_from( + ofproto_v1_3.OFP_ASYNC_CONFIG_PACK_STR, msg.buf, + ofproto_v1_3.OFP_HEADER_SIZE) |