openflow spec latest

Upload: alex-mihai-cio

Post on 03-Apr-2018

236 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/29/2019 Openflow Spec Latest

    1/36

    OpenFlow Switch Specication

    Version 0.9.0 ( Wire Protocol 0x98 )

    July 20, 2009

    Current Maintainer: Brandon Heller ([email protected])

    1 Introduction

    This document describes the requirements of an OpenFlow Switch. We rec-ommend that you read the latest version of the OpenFlow whitepaper beforereading this specication. The whitepaper is available on the OpenFlow Con-sortium website ( http://OpenFlowSwitch.org ). This specication covers thecomponents and the basic functions of the switch, and the OpenFlow protocolto manage an OpenFlow switch from a remote controller.

    Version 1.0 of this document will be the rst for which official vendor supportis expected. Versions before 1.0 will be marked Draft, and will include theheader: Do not build a switch from this specication! We hope to generatefeedback prior to Version 1.0 from switch designers and network researchers, sothat the set of features dened in Version 1.0 enables production deploymentson a variety of vendor hardware.

    2 Switch Components

    An OpenFlow Switch consists of a ow table , which performs packet lookup andforwarding, and a secure channel to an external controller (Figure 1). The con-troller manages the switch over the secure channel using the OpenFlow protocol.

    The ow table contains a set of ow entries (header values to match pack-ets against), activity counters, and a set of zero or more actions to apply tomatching packets. All packets processed by the switch are compared againstthe ow table. If a matching entry is found, any actions for that entry are

    performed on the packet (e.g., the action might be to forward a packet out aspecied port). If no match is found, the packet is forwarded to the controllerover the secure channel. The controller is responsible for determining how tohandle packets without valid ow entries, and it manages the switch ow tableby adding and removing ow entries.

    1

    http://openflowswitch.org/http://openflowswitch.org/
  • 7/29/2019 Openflow Spec Latest

    2/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    Figure 1: An OpenFlow switch communicates with a controller over a secureconnection using the OpenFlow protocol.

    3 Flow Table

    This section describes the components of ow table entries and the process bywhich incoming packets are matched against ow table entries.

    Header Fields Counters Actions

    Table 1: A ow entry consists of header elds, counters, and actions.

    Each ow table entry (see Table 1) contains:

    header elds to match against packets

    counters to update for matching packet

    actions to apply to matching packets

    3.1 Header Fields

    IngressPort

    Ethersource

    Etherdst

    Ethertype

    VLANid

    VLANpri-ority

    IPsrc

    IPdst

    IPproto

    TCP/UDPsrcport

    TCP/UDPdstport

    Table 2: Fields from packets used to match against ow entries.

    Table 2 shows the header elds an incoming packet is compared against.Each entry contains a specic value, or ANY, which matches any value. If the

    2

  • 7/29/2019 Openflow Spec Latest

    3/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    switch supports subnet masks on the IP source and/or destination elds, thesecan more precisely specify matches. The elds in the OpenFlow 11-tuple arelisted in Table 2 and details on the properties of each eld are described in Table3.

    Field Bits When applicable NotesIngress Port (Implementat ion

    dependent)All packets Numerical represen-

    tation of incomingport, starting at 1.

    Ethernet source ad-dress

    48 All packets on en-abled ports

    Ethernet destina-tion address

    48 All packets on en-abled ports

    Ethernet type 16 All packets on en-abled ports

    An OpenFlowswitch is requiredto match the typein both standard

    Ethernet and 802.2with a SNAPheader and OUIof 0x000000. Thespecial value of 0x05FF is used tomatch all 802.3packets withoutSNAP headers.

    VLAN id 12 All packets of Eth-ernet type 0x8100

    VLAN priority 3 All packets of Eth-ernet type 0x8100

    VLAN PCP eld

    IP source address 32 All IP packets Can be subnetmasked

    IP destination ad-

    dress

    32 All IP packets Can be subnet

    maskedIP protocol 8 All IP packetsTransport sourceport / ICMP Type

    16 All TCP, UDP, andICMP packets

    Only lower 8 bitsused for ICMPType

    Transport destina-tion port / ICMPCode

    16 All TCP, UDP, andICMP packets

    Only lower 8 bitsused for ICMPCode

    Table 3: Field lengths and the way they must be applied to ow entries.

    Switch designers are free to implement the internals in any way convenientprovided that correct functionality is preserved. For example, while a owmay have multiple forward actions, each specifying a different port, a switchdesigner may choose to implement this as a single bitmask within the hardwareforwarding table.

    3

  • 7/29/2019 Openflow Spec Latest

    4/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    3.2 Counters

    Counters are maintained per-table, per-ow, and per-port. OpenFlow-compliantcounters may be implemented in software and maintained by polling hardwarecounters with more limited ranges.

    Table 4 contains the required set of counters. Duration refers to the number of seconds a ow has been active. The Receive Errors eld includes all explicitlyspecied errors, including frame, overrun, and CRC errors, plus any others.

    Counter BitsPer Table

    Active Entries 32Packet Lookups 64Packet Matches 64

    Per Flow

    Received Packets 64Received Bytes 64Duration 32

    Per PortReceived Packets 64Transmitted Packets 64Received Bytes 64Transmitted Bytes 64Receive Drops 64Transmit Drops 64Receive Errors 64Transmit Errors 64Receive Frame Alignment Errors 64Receive Overrun Errors 64Receive CRC Errors 64Collisions 64

    Table 4: Required list of counters for use in statistics messages.

    3.3 Actions

    Each ow entry is associated with zero or more actions that dictate how theswitch handles matching packets. Actions need not be executed in the order inwhich they are specied in the ow entry. If no actions are present, the packetis dropped.

    A switch is not required to support all action types just those marked Re-quired Actions below. When connecting to the controller, a switch indicates

    which of the Optional Actions it supports. OpenFlow-compliant switchescome in two types: OpenFlow-only , and OpenFlow-enabled .

    OpenFlow-only switches support only the required actions below, while OpenFlow-enabled switches, routers, and access points may also support the NORMALaction. Either type of switch can also support the FLOOD action.

    4

  • 7/29/2019 Openflow Spec Latest

    5/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    Required Action: Forward . OpenFlow switches must support forwardingthe packet to physical ports and the following virtual ones:

    ALL: Send the packet out all interfaces, not including the incoming in-terface.

    CONTROLLER: Encapsulate and send the packet to the controller.

    LOCAL: Send the packet to the switchs local networking stack.

    TABLE: Perform actions in ow table. Only for packet-out messages.

    IN PORT: Send the packet out the input port.

    Optional Action: Forward . The switch may optionally support the followingvirtual ports:

    NORMAL: Process the packet using the traditional forwarding pathsupported by the switch (i.e., traditional L2, VLAN, and L3 processing.)The switch may check the VLAN eld to determine whether or not toforward the packet along the normal processing route. If the switch can-not forward entries for the OpenFlow-specic VLAN back to the normalprocessing route, it must indicate that it does not support this action.

    FLOOD: Flood the packet along the minimum spanning tree, not includ-ing the incoming interface.

    Ideally, a switch will support ow-entries that can forward packets to any com-bination of the physical and virtual ports. For example, this could be expressed

    internally in the switch with a bitmap that includes all the physical and virtualports.

    However, some switches will not be able to support any combination. There-fore, the requirement is that the switch support sending to any combination of physical ports and the Controller virtual port simultaneously. All other combi-nations are desired, but optional.

    The controller will only ask the switch to send to multiple physical ports simulta-neously if the switch indicates it supports this behavior in the initial handshake(see section 5.3.1).

    Required Action: Drop . A ow-entry with no specied action indicates that

    all matching packets should be dropped.

    Optional Action: Modify-Field . While not strictly required, the actions shownin Table 5 greatly increase the usefulness of an OpenFlow implementation. Toaid integration with existing networks, we suggest that VLAN modication ac-tions be supported.

    5

  • 7/29/2019 Openflow Spec Latest

    6/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    Action Associated Data DescriptionSet VLAN ID 12 bits If no VLAN is present, a

    new header is added withthe specied VLAN ID andpriority of zero.If a VLAN header alreadyexists, the VLAN ID is re-placed with the speciedvalue.

    Set VLAN priority 3 bits If no VLAN is present, anew header is added withthe specied priority and aVLAN ID of zero.If a VLAN header alreadyexists, the priority eld isreplaced with the speciedvalue.

    Strip VLAN header - Strip VLAN header if present.

    Modify Ethernet sourceMAC address

    48 bits: Value with whichto replace existing sourceMAC address

    Replace the existing Eth-ernet source MAC addresswith the new value

    Modify Ethernet destina-tion MAC address

    48 bits: Value with which toreplace existing destinationMAC address

    Replace the existing Eth-ernet destination MAC ad-dress with the new value.

    Modify IPv4 source address 32 bits: Value with which toreplace existing IPv4 sourceaddress

    Replace the existing IPsource address with newvalue and update the IPchecksum (and TCP/UDPchecksum if applicable).This action is only applica-ble to IPv4 packets.

    Modify IPv4 destinationaddress

    32 bits: Value with which toreplace existing IPv4 desti-nation address

    Replace the existing IP des-tination address with newvalue and update the IPchecksum (and TCP/UDPchecksum if applicable).This action is only appliedto IPv4 packets.

    Modify IPv4 ToS bits 6 bits: Value with whichto replace existing IPv4 ToSeld

    Replace the existing IP ToSeld. This action is only ap-plied to IPv4 packets.

    Modify transport sourceport

    16 bits: Value with whichto replace existing TCP orUDP source port

    Replace the existingTCP/UDP source portwith new value and updatethe TCP/UDP checksum.This action is only applica-ble to TCP and UDP pack-ets.

    Modify transport destina-tion port

    16 bits: Value with whichto replace existing TCP orUDP destination port

    Replace the existingTCP/UDP destinationport with new value andupdate the TCP/UDPchecksumThis action is only appliedto TCP and UDP packets.

    Table 5: Field-modify actions.

    6

  • 7/29/2019 Openflow Spec Latest

    7/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    3.4 Matching

    Figure 2: The functions performed on a packet as it moves through an OpenFlowswitch. As discussed in Section 4.5, support for 802.1D is optional.

    Figure 3: A ow table showing how a packet is matched against a ow entry.

    On receipt of a packet, an OpenFlow Switch performs the functions shownin Figure 2.

    The ow table is checked for a matching ow entry. The header elds usedfor the table lookup depend on the packet type as described below (and shownin Figure 3).

    Rules specifying an ingress port are matched against the physical portthat received the packet.

    The Ethernet headers as specied in Table 2 are used for all packets.

    7

  • 7/29/2019 Openflow Spec Latest

    8/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    If the packet is a VLAN (Ethernet type 0x8100), the VLAN ID and PCPelds are used in the lookup.

    For IP packets (Ethernet type equal to 0x0800), the lookup elds alsoinclude those in the IP header.

    For IP packets that are TCP or UDP (IP protocol is equal to 6 or 17),the lookup includes the transport ports.

    For IP packets that are ICMP (IP prototcol is equal to 1), the lookupincludes the Type and Code elds.

    For IP packets with nonzero fragment offset or More Fragments bit set,the transport ports are set to zero for the lookup.

    A packet matches a ow table entry if the values in the header elds used for

    the lookup (as dened above) match those dened in the ow table. If a owtable eld has a value of ANY, it matches all possible values in the header.

    To handle the various Ethernet framing types, matching the Ethernet type ishandled in a slightly different manner. If the packet is an Ethernet II frame, theEthernet type is handled in the expected way. If the packet is an 802.3 framewith a SNAP header and Organizationally Unique Identier (OUI) of 0x000000,the SNAP protocol id is matched against the ows Ethernet type. A ow entrythat species an Ethernet type of 0x05FF, matches all Ethernet 802.2 frameswithout a SNAP header and those with SNAP headers that do not have an OUIof 0x000000.

    Packets are matched against ow entries based on prioritization. An entry thatspecies an exact match (i.e., it has no wildcards) is always the highest priority.All wildcard entries have a priority associated with them. Higher priority entriesmust match before lower priority ones. If multiple entries have the same priority,the switch is free to choose any ordering. Higher numbers have higher priorities.

    For each packet that matches a ow entry, the associated counters for thatentry are updated. If no matching entry can be found for a packet, the packetis sent to the controller over the secure channel.

    4 Secure Channel

    The secure channel is the interface that connects each OpenFlow switch to a

    controller. Through this interface, the controller congures and manages theswitch, receives events from the switch, and send packets out the switch.

    Between the datapath and the secure channel, the interface is implementation-specic, however all secure channel messages must be formatted according tothe OpenFlow protocol.

    8

  • 7/29/2019 Openflow Spec Latest

    9/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    4.1 OpenFlow Protocol Overview

    The OpenFlow protocol supports three message types, controller-to-switch , asyn-chronous , and symmetric , each with multiple sub-types. Controller-to-switchmessages are initiated by the controller and used to directly manage or inspectthe state of the switch. Asynchronous messages are initiated by the switch andused to update the controller of network events and changes to the switch state.Symmetric messages are initiated by either the switch or the controller and sentwithout solicitation. The message types used by OpenFlow are described below.

    4.1.1 Controller-to-Switch

    Controller/switch messages are initiated by the controller and may or may notrequire a response from the switch.

    Features: Upon SSL session establishment, the controller sends a featuresrequest message to the switch. The switch must reply with a features reply thatspecies the capabilities supported by the switch.

    Conguration: The controller is able to set and query conguration parame-ters in the switch. The switch only responds to a query from the controller.

    Modify-State: Modify-State messages are sent by the controller to managestate on the switches. Their primary purpose is to add/delete and modify owsin the ow tables and to set switch port properties.

    Read-State: Read-State messages are used by the controller to collect statis-tics from the switchs ow-tables, ports and the individual ow entries.

    Send-Packet : These are used by the controller to send packets out of a speci-ed port on the switch.

    Barrier : Barrier request/reply messages are used by the controller to ensuremessage dependencies have been met or to receive notications for completedoperations.

    4.1.2 Asynchronous

    Asynchronous messages are sent without solicitation from the switch to thecontroller and denote a change in switch or network state. The four main asyn-chronous message types are described below.

    Packet-in: For all packets that do not have a matching ow entry, a packet-inevent is sent to the controller (or if a packet matches an entry with a sendto controller action). If the switch has sufficient memory to buffer packetsthat are sent to the controller, the packet-in events contain some fraction of the packet header (by default 128 bytes) and a buffer ID to be used by the

    9

  • 7/29/2019 Openflow Spec Latest

    10/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    controller when it is ready for the switch to forward the packet. Switches thatdo not support internal buffering (or have run out of internal buffering) mustsend the full packet to the controller as part of the event.

    Flow-Removed: When a ow entry is added to the switch by a ow mod-ify message, an idle timeout value indicates when the entry should be removeddue to a lack of activity, as well as a hard timeout value that indicates whenthe entry should be removed, regardless of activity. The ow modify messagealso species whether the switch should send a ow removed message to thecontroller when the ow expires. Delete messages may also cause ow removedmessages.

    Port-status: The switch is expected to send port-status messages to the con-troller as port conguration state changes. These events include change in portstatus (for example, if it was brought down directly by a user) or a change inport status as specied by 802.1D (see Section 4.5 for a description of 802.1Dsupport requirements).

    Error: The switch is able to notify the controller of problems using error mes-sages.

    4.1.3 Symmetric

    Symmetric messages are sent without solicitation, in either direction.

    Hello: Hello messages are exchanged between the switch and controller uponconnection startup.

    Echo: Echo request/reply messages can be sent from either the switch or thecontroller, and must return an echo reply. They can be used to indicate thelatency, bandwidth, and/or liveness of a controller-switch connection.

    Vendor: Vendor messages provide a standard way for OpenFlow switches tooffer additional functionality within the OpenFlow message type space. This isa staging area for features meant for future OpenFlow revisions.

    4.2 Connection Setup

    The switch must be able to establish the communication at a user-congurable(but otherwise xed) IP address, using a user-specied port. Traffic to and fromthe secure channel is not checked against the ow table. Therefore, the switchmust identify incoming traffic as local before checking it against the ow table.Future versions of the protocol specication will describe a dynamic controllerdiscovery protocol in which the IP address and port for communicating withthe controller is determined at runtime.

    10

  • 7/29/2019 Openflow Spec Latest

    11/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    When an OpenFlow connection is rst established, each side of the connectionmust immediately send an OFPT_HELLOmessage with the version eld set tothe highest OpenFlow protocol version supported by the sender. Upon receiptof this message, the recipient may calculate the OpenFlow protocol version tobe used as the smaller of the version number that it sent and the one that itreceived.

    If the negotiated version is supported by the recipient, then the connection pro-ceeds. Otherwise, the recipient must reply with an OFPT_ERRORmessage with atype eld of OFPET_HELLO_FAILED, a code eld of OFPHFC_COMPATIBLE, andoptionally an ASCII string explaining the situation in data , and then terminatethe connection.

    4.3 Connection Interruption

    In the case that a switch loses contact with the controller, as a result of a echorequest timeout, SSL session timeout, or other disconnection, it should attemptto contact one or more backup controllers. The ordering of the controller IPaddresses is not specied by the protocol.

    If some number of attempts to contact a controller (zero or more) fail, theswitch must enter emergency mode and immediately reset the current TCPconnection. In emergency mode, the matching process is dictated by the emer-gency ow table entries (those marked with the emergency bit when added tothe switch). All normal entries are deleted when entering emergency mode.

    Upon connecting to a controller again, the emergency ow entries remain. The

    controller then has the option of deleting all ow entries, if desired.The rst time a switch starts up, it is considered to be in emergency mode.Conguration of the default set of ow entries is outside the scope of the Open-Flow protocol.

    4.4 Encryption

    The switch and controller communicate through an SSL connection. The SSLconnection is initiated by the switch on startup to the controllers server, whichis located by default on TCP port 6633 . The switch and controller mutually au-thenticate by exchanging certicates signed by a site-specic private key. Eachswitch must be user-congurable with one certicate for authenticating the con-

    troller (controller certicate) and the other for authenticating to the controller(switch certicate).

    11

  • 7/29/2019 Openflow Spec Latest

    12/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    4.5 Spanning Tree

    OpenFlow switches may optionally support 802.1D Spanning Tree Protocol.Those switches that do support it are expected to process all 802.1D packetslocally before performing ow lookup. A switch that implements STP mustset the OFPC_STPbit in the capabilities eld of its OFPT_FEATURES_REPLYmes-sage. A switch that implements STP must make it available on all of its physicalports, but it need not implement it on virtual ports (e.g. OFPP_LOCAL).

    Port status, as specied by the spanning tree protocol, is then used to limitpackets forwarded to the OFP_FLOODport to only those ports along the span-ning tree. Port changes as a result of the spanning tree are sent to the controllervia port-update messages. Note that forward actions that specify the outgoingport or OFP_ALLignore the port status set by the spanning tree protocol. Pack-ets received on ports that are disabled by spanning tree must follow the normal

    ow table processing path.

    Switches that do not support 802.1D spanning tree must allow the controller tospecify the port status for packet ooding through the port-mod messages.

    4.6 Flow Table Modication MessagesFlow table modication messages can have the following types:

    enum ofp_flow_mod_command {OFPFC_ADD, /* New flow. */OFPFC_MODIFY, /* Modify all matching flows . */OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */OFPFC_DELETE, /* Delete all matching flows . */OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */

    };

    For ADD requests with the OFPFF_CHECK_OVERLAPag set, the switch mustrst check for any overlapping ow entries. An overlapping entry is one withsame priority as the request and at least one wildcard eld, such that someow entry exists that could match both. If an overlap conict is found, theswitch must refuse the addition and respond with an ofp_error_msg withOFPET_FLOW_MOD_FAILEDtype and OFPFMFC_OVERLAPcode.

    For valid (non-overlapping) ADD requests, or those with no overlap checking,the switch must insert the ow entry at the lowest numbered table for which theswitch supports all wildcards set in the flow_match struct, and for which thepriority would be observed during the matching process. If a ow entry with

    identical header elds and priority already resides in any table, then that entry,including its counters, must be removed, and the new ow entry added.

    If a switch cannot nd any table in which to add the incoming ow entry,the switch should send an ofp_error_msg with OFPET_FLOW_MOD_FAILEDtypeand OFPFMFC_ALL_TABLES_FULLcode.

    12

  • 7/29/2019 Openflow Spec Latest

    13/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    For MODIFY requests, if a ow entry with identical header elds does notcurrent reside in any table, the MODIFY acts like an ADD, and the new owentry must be inserted with zeroed counters. Otherwise, the actions eld ischanged on the existing entry and its counters and idle time elds are left un-changed.

    For DELETE requests, if no ow entry matches, no error is recorded, and noow table modication occurs. If ow entries match, and must be deleted, theneach normal entry with the OFPFF_SEND_FLOW_REMag set should generate aow removed message. Deleted emergency ow entries generate no ow removedmessages.

    MODIFY and DELETE ow mod commands have corresponding STRICTversions. Without STRICT appended, the wildcards are active and all owsthat match the description are modied or removed. If STRICT is appended,all elds, including the wildcards and priority, are strictly matched against theentry, and only an identical ow is modied or removed. For example, if a mes-sage to remove entries is sent that has all the wildcard ags set, the DELETEcommand would delete all ows from all tables, while the DELETE STRICTcommand would only delete a rule that applies to all packets at the speciedpriority.

    For non-strict MODIFY and DELETE commands that contain wildcards, amatch will occur when a ow entry exactly matches or is more specic than thedescription in the ow mod command. For example, if a DELETE commandsays to delete all ows with a destination port of 80, then a ow entry that is

    all wildcards will not be deleted. However, a DELETE command that is allwildcards will delete an entry that matches all port 80 traffic. This same inter-pretation of mixed wildcard and exact header elds also applies to individualand aggregate ows stats.

    DELETE and DELETE STRICT commands can be optionally ltered by out-put port. If the out_port eld contains a value other than OFPP_NONE, it intro-duces a constraint when matching. This constraint is that the rule must containan output action directed at that port. This eld is ignored by ADD, MODIFY,and MODIFY STRICT messages.

    Emergency ow mod messages must have timeout values set to zero. Other-wise, the switch must refuse the addition and respond with an ofp_error_msg

    with OFPET_FLOW_MOD_FAILEDtype and OFPFMFC_BAD_EMERG_TIMEOUTcode.

    4.7 Flow Removal

    Each ow entry has an idle_timeout and a hard_timeout associated with it. If no packet has matched the rule in the last idle_timeout seconds, or it has been

    13

  • 7/29/2019 Openflow Spec Latest

    14/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    hard_timeout seconds since the ow was inserted, the switch removes the entryand sends a ow removed message. In addition, the controller is able to activelyremove entries by sending a ow message with the DELETEor DELETE_STRICTcommand. Like the message used to add the entry, a removal message containsa description, which may include wild cards.

    5 Appendix A: The OpenFlow Protocol

    The heart of the OpenFlow spec is the set of structures used for OpenFlowProtocol messages.

    The structures, denes, and enumerations described below are derived fromthe le include/openflow/openflow.h , which is part of the standard Open-Flow distribution. All structures are packed with padding and 8-byte aligned,as checked by the assertion statements. All OpenFlow messages are sent inbig-endian format.

    5.1 OpenFlow Header

    Each OpenFlow message begins with the OpenFlow header:

    /* Header on all OpenFlow packets. */struct ofp_header {

    uint8_t version; /* OFP_VERSION. */uint8_t type; /* One of the OFPT_ constants. */uint16_t length; /* Length including this ofp_header. */uint32_t xid; /* Transaction id associated with this packet.

    Replies use the same id as was in the requestto facilitate pairing. */

    };OFP_ASSERT(sizeof(struct ofp_header) == 8);

    The version species the OpenFlow protocol version being used. During thecurrent draft phase of the OpenFlow Protocol, the most signicant bit will beset to indicate an experimental version and the lower bits will indicate a revisionnumber. The current version is 0x98 . The nal version for a Type 0 switchwill be 0x00. The length eld indicates the total length of the message, so noadditional framing is used to distinguish one frame from the next. The type canhave the following values:

    enum ofp_type {/* Immutable messages. */OFPT_HELLO, /* Symmetric message */

    OFPT_ERROR, /* Symmetric message */OFPT_ECHO_REQUEST, /* Symmetric message */OFPT_ECHO_REPLY, /* Symmetric message */OFPT_VENDOR, /* Symmetric message */

    /* Switch configuration messages. */OFPT_FEATURES_REQUEST, /* Controller/switch message */

    14

  • 7/29/2019 Openflow Spec Latest

    15/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    OFPT_FEATURES_REPLY, /* Controller/switch message */OFPT_GET_CONFIG_REQUEST, /* Controller/switch message */

    OFPT_GET_CONFIG_REPLY, /* Controller/switch message */OFPT_SET_CONFIG, /* Controller/switch message */

    /* Asynchronous messages. */OFPT_PACKET_IN, /* Async message */OFPT_FLOW_REMOVED, /* Async message */OFPT_PORT_STATUS, /* Async message */

    /* Controller command messages. */OFPT_PACKET_OUT, /* Controller/switch message */OFPT_FLOW_MOD, /* Controller/switch message */OFPT_PORT_MOD, /* Controller/switch message */

    /* Statistics messages. */OFPT_STATS_REQUEST, /* Controller/switch message */OFPT_STATS_REPLY, /* Controller/switch message */

    /* Barrier messages. */OFPT_BARRIER_REQUEST, /* Controller/switch message */OFPT_BARRIER_REPLY /* Controller/switch message */

    };

    5.2 Common Structures

    This section describes structures used by multiple messages.

    5.2.1 Port Structures

    Physical ports are described with the following structure:

    /* Description of a physical port */struct ofp_phy_port {

    uint16_t port_no;uint8_t hw_addr[OFP_ETH_ALEN];uint8_t name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */

    uint32_t config; /* Bitmap of OFPPC_* flags. */uint32_t state; /* Bitmap of OFPPS_* flags. */

    /* Bitmaps of OFPPF_* that describe features. All bits zeroed if* unsupported or unavailable. */

    uin t32_t cur r; /* Current features. */uint32_t advertised; /* Features being advertised by the port. */uint32_t supported; /* Features supported by the port. */uint32_t peer; /* Features advertised by peer. */

    };OFP_ASSERT(sizeof(struct ofp_phy_port) == 48);

    The port_no eld is a value the datapath associates with a physical port. Thehw_addr eld typically is the MAC address for the port; OFP_MAX_ETH_ALENis6. The name eld is a null-terminated string containing a human-readable namefor the interface. The value of OFP_MAX_PORT_NAME_LENis 16.

    15

  • 7/29/2019 Openflow Spec Latest

    16/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    The config eld describes spanning tree and administrative settings with thefollowing structure:

    /* Flags to indicate behavior of the physical port. These flags are* used in ofp_phy_port to describe the current configuration. They are* used in the ofp_port_mod message to configure the ports behavior.*/

    enum ofp_port_config {OFPPC_PORT_DOWN = 1

  • 7/29/2019 Openflow Spec Latest

    17/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    * controller must adjust OFPPC_NO_RECV, OFPPC_NO_FWD, and* OFPPC_NO_PACKET_IN appropriately to fully implement an 802.1D spanning

    * tree. */OFPPS_STP_LISTEN = 0

  • 7/29/2019 Openflow Spec Latest

    18/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    5.2.2 Flow Match Structures

    When describing a ow entry, the following structure is used:/* Fields to match against flows */struct ofp_match {

    uint32_t wildcards; /* Wildcard fields. */uin t16_t in_port; /* Input switch port . */uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */uint16_t dl_vlan; /* Input VLAN id. */uint8_t dl_vlan_pcp; /* Input VLAN priority. */uint8_t pad1[1]; /* Align to 64-bits */uin t16_t dl_ type; /* Etherne t frame type. * /uint8_t nw_proto; /* IP protocol. */uint8_t pad2[3]; /* Align to 64-bits */uint32_t nw_src; /* IP source address. */uin t32_t nw_dst; /* IP dest ination address . */

    uin t16_t tp_src; /* TCP/UDP source port. * /uint16_t tp_dst; /* TCP/UDP destination port. */};OFP_ASSERT(sizeof(struct ofp_match) == 40);

    The wildcards eld has a number of ags that may be set:

    /* Flow wildcards. */enum ofp_flow_wildcards {

    OFPFW_IN_PORT = 1

  • 7/29/2019 Openflow Spec Latest

    19/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    If no wildcards are set, then the ofp_match exactly describes a ow, over theentire OpenFlow 11-tuple. On the other extreme, if all the wildcard ags areset, then every ow will match.

    The source and destination netmasks are each specied with a 6-bit numberin the wildcard description. It is interpreted similar to the CIDR suffix, butwith the opposite meaning, since this is being used to indicate which bits in theIP address should be treated as wild. For example, a CIDR suffix of 24means to use a netmask of 255.255.255.0. However, a wildcard mask value of 24 means that the least-signicant 24-bits are wild, so it forms a netmask of 255.0.0.0.

    5.2.3 Flow Action Structures

    A number of actions may be associated with ows or packets. The currentlydened action types are:

    enum ofp_action_type {OFPAT_OUTPUT, /* Output to switch por t. */OFPAT_SET_VLAN_VID, /* Set the 802.1q VLAN id. */OFPAT_SET_VLAN_PCP, /* Set the 802.1q priority. */OFPAT_STRIP_VLAN, /* Strip the 802.1q header. */OFPAT_SET_DL_SRC, /* Ethernet source address. */OFPAT_SET_DL_DST, /* Ethernet destination address. */OFPAT_SET_NW_SRC, /* IP source address. */OFPAT_SET_NW_DST, /* IP destination address. */OFPAT_SET_NW_TOS, /* IP ToS/DSCP field (6 bits). */OFPAT_SET_TP_SRC, /* TCP/UDP source port. */OFPAT_SET_TP_DST, /* TCP/UDP destination port. */OFPAT_VENDOR = 0xffff

    };

    Output actions are described in Section 3.3, while Field-Modify actions aredescribed in Table 5. An action denition contains the action type, length, andany associated data:

    /* Action header that is common to all actions. The length includes the* header and any padding used to make the action 64-bit aligned.* NB: The length of an action *must* always be a multiple of eight. */

    struct ofp_action_header {uint16_t type; /* One of OFPAT_*. */uint16_t len; /* Length of action, including this

    header. This is the length of action,including any padding to make it64-bit aligned. */

    uint8_t pad[4];

    };OFP_ASSERT(sizeof(struct ofp_action_header) == 8);

    An action_output has the following elds:

    /* Action structure for OFPAT_OUTPUT, which sends packets out port.* When the port is the OFPP_CONTROLLER, max_len indicates the max

    19

  • 7/29/2019 Openflow Spec Latest

    20/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    * number of bytes to send. */struct ofp_action_output {

    uint16_t type; /* OFPAT_OUTPUT. */uint16_t len; /* Length is 8. */uint16_t port; /* Output port. */uint16_t max_len; /* Max length to send to controller. */

    };OFP_ASSERT(sizeof(struct ofp_action_output) == 8);

    The max_len indicates the maximum amount of data from a packet that shouldbe sent when the port is OFPP_CONTROLLER. If max_len is zero, the switch mustsend a zero-size packet_in message. The port species the physical port fromwhich packets should be sent.

    An action_vlan_vid has the following elds:

    /* Action structure for OFPAT_SET_VLAN_VID. */struct ofp_action_vlan_vid {

    uint16_t type; /* OFPAT_SET_VLAN_VID. */uint16_t len; /* Length is 8. */uint16_t vlan_vid; /* VLAN id. */uint8_t pad[2];

    };OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);

    The vlan_vid eld is 16 bits long, when an actual VLAN id is only 12 bits.The value 0xffff is used to indicate that no VLAN id was set.

    An action_vlan_pcp has the following elds:

    /* Action structure for OFPAT_SET_VLAN_PCP. */struct ofp_action_vlan_pcp {

    uint16_t type; /* OFPAT_SET_VLAN_PCP. */uint16_t len; /* Length is 8. */uint8_t vlan_pcp; /* VLAN priority. */uint8_t pad[3];

    };OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);

    The vlan_pcp eld is 8 bits long, but only the lower 3 bits have meaning.

    An action_strip_vlan takes no arguments and consists only of a genericofp_action_header . This action strips the VLAN tag if one is present.

    An action_dl_addr has the following elds:

    /* Action structure for OFPAT_SET_DL_SRC/DST. */struct ofp_action_dl_addr {

    uint16_t type; /* OFPAT_SET_DL_SRC/DST. */uint16_t len; /* Length is 16. */uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */uint8_t pad[6];

    };OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);

    20

  • 7/29/2019 Openflow Spec Latest

    21/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    The dl_addr eld is the MAC address to set.

    An action_nw_addr has the following elds:

    /* Action structure for OFPAT_SET_NW_SRC/DST. */struct ofp_action_nw_addr {

    uint16_t type; /* OFPAT_SET_TW_SRC/DST. */uint16_t len; /* Length is 8. */uint32_t nw_addr; /* IP address. */

    };OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);

    The nw_addr eld is the IP address to set.

    An action_nw_tos has the following elds:

    /* Action structure for OFPAT_SET_NW_TOS. */

    struct ofp_action_nw_tos {uint16_t type; /* OFPAT_SET_TW_SRC/DST. */uint16_t len; /* Length is 8. */uint8_t nw_tos; /* IP ToS/DSCP (6 bits). */uint8_t pad[3];

    };OFP_ASSERT(sizeof(struct ofp_action_nw_tos) == 8);

    The nw_tos eld is the 6 upper bits of the ToS eld to set, in the original bitpositions (shifted to the left by 2).

    An action_tp_port has the following elds:

    /* Action structure for OFPAT_SET_TP_SRC/DST. */struct ofp_action_tp_port {

    uint16_t type; /* OFPAT_SET_TP_SRC/DST. */uint16_t len; /* Length is 8. */uint16_t tp_port; /* TCP/UDP port. */uint8_t pad[2];

    };OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);

    The tp_port eld is the TCP/UDP/other port to set.

    An action_vendor has the following elds:

    /* Action header for OFPAT_VENDOR. The rest of the body is vendor-defined. */struct ofp_action_vendor_header {

    uint16_t type; /* OFPAT_VENDOR. */uint16_t len; /* Length is 8. */

    uint32_t vendor; /* Vendor ID, which takes the same formas in "struct ofp_vendor_header". */};OFP_ASSERT(sizeof(struct ofp_action_vendor_header) == 8);

    The vendor eld is the Vendor ID, which takes the same form as in structofp_vendor .

    21

  • 7/29/2019 Openflow Spec Latest

    22/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    5.3 Controller-to-Switch Messages

    5.3.1 HandshakeUpon SSL session establishment, the controller sends an OFPT_FEATURES_REQUESTmessage. This message does not contain a body beyond the OpenFlow header.The switch responds with an OFPT_FEATURES_REPLYmessage:

    /* Switch features. */struct ofp_switch_features {

    struct ofp_header header;uint64_t datapath_id; /* Datapath unique ID. The lower 48-bits are for

    a MAC address, while the upper 16-bits areimplementer-defined. */

    uint32_t n_buffers; /* Max packets buffered at once. */

    uint8_t n_tables; /* Number of tables supported by datapath. */uin t8_t pad[3]; /* Align to 64-bit s. */

    /* Features. */uint32_t capabilities; /* Bitmap of support "ofp_capabilities". */uint32_t actions; /* Bitmap of supported "ofp_action_type"s. */

    /* Port info.*/struct ofp_phy_port ports[0]; /* Port definitions. The number of ports

    is inferred from the length field inthe header. */

    };OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);

    The datapath_id eld uniquely identies a datapath. The lower 48 bits areintended for the switch MAC address, while the top 16 bits are up to the imple-

    menter. An example use of the top 16 bits would be a VLAN ID to distinguishmultiple virtual switch instances on a single physical switch. This eld shouldbe treated as an opaque bit string by controllers.

    The n_tables eld describes the number of tables supported by the switch,each of which can have a different set of supported wildcard bits and number of entries. When the controller and switch rst communicate, the controller willnd out how many tables the switch supports from the Features Reply. If itwishes to understand the size, types, and order in which tables are consulted,the controller sends a OFPST_TABLEstats request. A switch must return thesetables in the order the packets traverse the tables, with all exact-match tableslisted before all tables with wildcards.

    The capabilities eld uses the following ags:/* Capabilities supported by the datapath. */enum ofp_capabilities {

    OFPC_FLOW_STATS = 1

  • 7/29/2019 Openflow Spec Latest

    23/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    OFPC_STP = 1

  • 7/29/2019 Openflow Spec Latest

    24/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    5.3.3 Modify State Messages

    Modify Flow Entry Message Modications to the ow table from the con-troller are done with the OFPT_FLOW_MODmessage:

    /* Flow setup and teardown (controller -> datapath). */struct ofp_flow_mod {

    struct ofp_header header;struct ofp_match match; /* Fields to match */

    /* Flow actions. */uint16_t command; /* One of OFPFC_*. */uint16_t idle_timeout; /* Idle time before discarding (seconds). */uint16_t hard_timeout; /* Max time before discarding (seconds). */uin t16_t priority ; /* Priority level of f low entry. */uint32_t buffer_id; /* Buffered packet to apply to (or -1).

    Not meaningful for OFPFC_DELETE*. */uint16_t out_port; /* For OFPFC_DELETE* commands, require

    matching entries to include this as anoutput port. A value of OFPP_NONEindicates no restriction. */

    uint16_t flags; /* One of OFPFF_*. */uin t32_t reserved; /* Reserved for future use. */struct ofp_action_header actions[0]; /* The action length is inferred

    from the length field in theheader. */

    };OFP_ASSERT(sizeof(struct ofp_flow_mod) == 68);

    The command eld must be one of the following:

    enum ofp_flow_mod_command {OFPFC_ADD, /* New flow. */OFPFC_MODIFY, /* Modify all matching flows . */OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */OFPFC_DELETE, /* Delete all matching flows . */OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */

    };

    The differences between OFPFC_MODIFYand OFPFC_MODIFY_STRICTare explainedin Section 4.6 and differences between OFPFC_DELETEand OFPFC_DELETE_STRICTare explained in Section 4.6.

    The idle_timeout and hard_timeout elds control how quickly ows expire.

    If the idle_timeout is set and the hard_timeout is zero, the entry must ex-pire after idle_timeout seconds with no received traffic. If the idle_timeoutis zero and the hard_timeout is set, the entry must expire in hard_timeoutseconds regardless of whether or not packets are hitting the entry.

    If both idle_timeout and hard_timeout are set, the ow will timeout afteridle_timeout seconds with no traffic, or hard_timeout seconds, whichevercomes rst. If both idle_timeout and hard_timeout are zero, the entry is

    24

  • 7/29/2019 Openflow Spec Latest

    25/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    considered permanent and will never time out. It can still be removed with aflow_mod message of type OFPFC_DELETE.

    The priority eld is only relevant for ow entries with wildcard elds. The pri-ority eld indicates table priority, where higher numbers are higher priorities; theswitch must keep the highest-priority wildcard entries in the lowest-numbered(fastest) wildcard table, to ensure correctness. It is the responsibility of eachswitch implementer to ensure that exact entries always match before wildcardsentries, regardless of the table conguration.

    The buffer_id refers to a buffered packet sent by the OFPT_PACKET_INmessage.

    The out_port eld optionally lters the scope of DELETE and DELETE STRICTmessages by output port. If out_port contains a value other than OFPP_NONE,it introduces a constraint when matching. This constraint is that the rulemust contain an output action directed at that port. Other constraints suchas ofp_match structs and priorities are still used; this is purely an additional constraint. Note that to disable output port ltering, out_port must be set toOFPP_NONE, since 0 is a valid port id. This eld is ignored by ADD, MODIFY,and MODIFY STRICT messages.

    The flags eld may include the follow ags:

    enum ofp_flow_mod_flags {OFPFF_SEND_FLOW_REM = 1

  • 7/29/2019 Openflow Spec Latest

    26/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    uint16_t port_no;uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not

    configurable. This is used tosanity-check the request, so it mustbe the same as returned in anofp_phy_port struct. */

    uint32_t config; /* Bitmap of OFPPC_* flags. */uint32_t mask; /* Bitmap of OFPPC_* flags to be changed. */

    uint32_t advertise; /* Bitmap of "ofp_port_features"s. Zero allbits to prevent any action taking place. */

    uin t8_t pad[4]; /* Pad to 64-bits. */};OFP_ASSERT(sizeof(struct ofp_port_mod) == 32);

    The mask eld is used to select bits in the config eld to change. The advertiseeld has no mask; all port features change together.

    5.3.4 Read State Messages

    While the system is running, the datapath may be queried about its currentstate using the OFPT_STATS_REQUESTmessage:

    struct ofp_stats_request {struct ofp_header header;uint16_t type; /* One of the OFPST_* constants. */uin t16_t flags; /* OFPSF_REQ_* flags (none ye t def ined) . */uint8_t body[0]; /* Body of the request. */

    };OFP_ASSERT(sizeof(struct ofp_stats_request) == 12);

    The switch responds with one or more OFPT_STATS_REPLYmessages:

    struct ofp_stats_reply {struct ofp_header header;uint16_t type; /* One of the OFPST_* constants. */uint16_t flags; /* OFPSF_REPLY_* flags. */uint8_t body[0]; /* Body of the reply. */

    };OFP_ASSERT(sizeof(struct ofp_stats_reply) == 12);

    The only value dened for flags in a reply is whether more replies will followthis one - this has the value 0x0001 . To ease implementation, the switch isallowed to send replies with no additional entries. However, it must always sendanother reply following a message with the more ag set. The transaction ids(xid) of replies must always match the request that prompted them.

    In both the request and response, the type eld species the kind of infor-mation being passed and determines how the body eld is interpreted:

    enum ofp_stats_types {/* Description of this OpenFlow switch.

    * The request body is empty.

    26

  • 7/29/2019 Openflow Spec Latest

    27/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    * The reply body is struct ofp_desc_stats. */OFPST_DESC,

    /* Individual flow statistics.* The request body is struct ofp_flow_stats_request.* The reply body is an array of struct ofp_flow_stats. */

    OFPST_FLOW,

    /* Aggregate flow statistics.* The request body is struct ofp_aggregate_stats_request.* The reply body is struct ofp_aggregate_stats_reply. */

    OFPST_AGGREGATE,

    /* Flow table statistics.* The request body is empty.* The reply body is an array of struct ofp_table_stats. */

    OFPST_TABLE,

    /* Physical port statistics.* The request body is empty.* The reply body is an array of struct ofp_port_stats. */

    OFPST_PORT,

    /* Vendor extension.* The request and reply bodies begin with a 32-bit vendor ID, which takes* the same form as in "struct ofp_vendor_header". The request and reply* bodies are otherwise vendor-defined. */

    OFPST_VENDOR = 0xffff};

    Description Statistics Information about the switch manufacturer, hard-ware revision, software revision, and serial number is available from the OFPST_DESCstats request type:

    /* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated* ASCII string. */

    struct ofp_desc_stats {char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */char hw_desc[DESC_STR_LEN]; /* Hardware description. */char sw_desc[DESC_STR_LEN]; /* Software description. */char serial_num[SERIAL_NUM_LEN]; /* Serial number. */

    };OFP_ASSERT(sizeof(struct ofp_desc_stats) == 800);

    Each entry is ASCII formatted and padded on the right with 0 bytes. DESC_STR_LENis 256 and SERIAL_NUM_LENis 32 .

    Individual Flow Statistics Information about individual ows is requestedwith the OFPST_FLOWstats request type:/* Body for ofp_stats_request of type OFPST_FLOW. */struct ofp_flow_stats_request {

    struct ofp_match match; /* Fields to match. */uint8_t table_id; /* ID of table to read (from ofp_table_stats),

    0xff for all tables or 0xfe for emergency. */

    27

  • 7/29/2019 Openflow Spec Latest

    28/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    uint8_t pad; /* Align to 32 bits. */uint16_t out_port; /* Require matching entries to include this

    as an output port. A value of OFPP_NONEindicates no restriction. */};OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 44);

    The match eld contains a description of the ows that should be matched andmay contain wildcards. This elds matching behavior is described in Section4.6.

    The table_id eld indicates the index of a single table to read, or 0xff forall tables.

    The out_port eld optionally lters by output port. If out_port containsa value other than OFPP_NONE, it introduces a constraint when matching. Thisconstraint is that the rule must contain an output action directed at that port.Other constraints such as ofp_match structs are still used; this is purely an ad-ditional constraint. Note that to disable output port ltering, out_port mustbe set to OFPP_NONE, since 0 is a valid port id.

    The body of the reply consists of an array of the following:

    /* Body of reply to OFPST_FLOW request. */struct ofp_flow_stats {

    uin t16_t length; /* Length of thi s ent ry. * /uint8_t table_id; /* ID of table flow came from. */uint8_t pad;struct ofp_match match; /* Description of fields. */uint32_t duration; /* Time flow has been alive in seconds. */

    uint16_t priority; /* Priority of the entry. Only meaningfulwhen this is not an exact-match entry. */uint16_t idle_timeout; /* Number of seconds idle before expiration. */uint16_t hard_timeout; /* Number of seconds before expiration. */uint16_t pad2; /* Pad to 64 bits. */uint64_t packet_count; /* Number of packets in flow. */uint64_t byte_count; /* Number of bytes in flow. */struct ofp_action_header actions[0]; /* Actions. */

    };OFP_ASSERT(sizeof(struct ofp_flow_stats) == 72);

    The elds consist of those provided in the flow_mod that created these, plus thetable into which the entry was inserted, the packet count, and the byte count.

    Aggregate Flow Statistics Aggregate information about multiple ows is

    requested with the OFPST_AGGREGATEstats request type:/* Body for ofp_stats_request of type OFPST_AGGREGATE. */struct ofp_aggregate_stats_request {

    struct ofp_match match; /* Fields to match. */uint8_t table_id; /* ID of table to read (from ofp_table_stats)

    0xff for all tables or 0xfe for emergency. */

    28

  • 7/29/2019 Openflow Spec Latest

    29/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    uint8_t pad; /* Align to 32 bits. */uint16_t out_port; /* Require matching entries to include this

    as an output port. A value of OFPP_NONEindicates no restriction. */};OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request) == 44);

    The match eld contains a description of the ows that should be matched andmay contain wildcards. This elds matching behavior is described in Section4.6.

    The table_id eld indicates the index of a single table to read, or 0xff forall tables.

    The out_port eld optionally lters by output port. If out_port containsa value other than OFPP_NONE, it introduces a constraint when matching. Thisconstraint is that the rule must contain an output action directed at that port.Other constraints such as ofp_match structs are still used; this is purely an ad-ditional constraint. Note that to disable output port ltering, out_port mustbe set to OFPP_NONE, since 0 is a valid port id.

    The body of the reply consists of the following:

    /* Body of reply to OFPST_AGGREGATE request. */struct ofp_aggregate_stats_reply {

    uint64_t packet_count; /* Number of packets in flows. */uint64_t byte_count; /* Number of bytes in flows. */uint32_t flow_count; /* Number of flows. */uint8_t pad[4]; /* Align to 64 bits. */

    };

    OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);

    Table Statistics Information about tables is requested with the OFPST_TABLEstats request type. The request does not contain any data in the body.

    The body of the reply consists of an array of the following:

    /* Body of reply to OFPST_TABLE request. */struct ofp_table_stats {

    uint8_t table_id; /* Identifier of table. Lower numbered tablesare consulted first. */

    uint8_t pad[3]; /* Align to 32-bits. */char name[OFP_MAX_TABLE_NAME_LEN];uint32_t wildcards; /* Bitmap of OFPFW_* wildcards that are

    supported by the table. */

    uint32_t max_entries; /* Max number of entries supported. */uint32_t active_count; /* Number of active entries. */uint64_t lookup_count; /* Number of packets looked up in table. */uint64_t matched_count; /* Number of packets that hit table. */

    };OFP_ASSERT(sizeof(struct ofp_table_stats) == 64);

    29

  • 7/29/2019 Openflow Spec Latest

    30/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    The body contains a wildcards eld, which indicates the elds for which thatparticular table supports wildcarding. For example, a direct look-up hash tablewould have that eld set to zero, while a sequentially searched table would haveit set to OFPFW_ALL. The entries are returned in the order that packets traversethe tables.

    OFP_MAX_TABLE_NAME_LENis 32 .

    Port Statistics Information about physical ports is requested with the OFPST_PORTstats request type. The request does not contain any data in the body .

    The body of the reply consists of an array of the following:

    /* Body of reply to OFPST_PORT request. If a counter is unsupported, set* the field to all ones. */

    struct ofp_port_stats {uint16_t port_no;uint8_t pad[6]; /* Align to 64-bits. */uint64_t rx_packets; /* Number of received packets. */uint64_t tx_packets; /* Number of transmitted packets. */uint64_t rx_bytes; /* Number of received bytes. */uint64_t tx_bytes; /* Number of transmitted bytes. */uint64_t rx_dropped; /* Number of packets dropped by RX. */uint64_t tx_dropped; /* Number of packets dropped by TX. */uint64_t rx_errors; /* Number of receive errors. This is a super-set

    of more specific receive errors and should begreater than or equal to the sum of allrx_*_err values. */

    uint64_t tx_errors; /* Number of transmit errors. This is a super-setof more specific transmit errors and should begreater than or equal to the sum of all

    tx_*_err values (none currently defined.) */uint64_t rx_frame_err; /* Number of frame alignment errors. */uint64_t rx_over_err; /* Number of packets with RX overrun. */uint64_t rx_crc_err; /* Number of CRC errors. */uint64_t collisions; /* Number of collisions. */

    };OFP_ASSERT(sizeof(struct ofp_port_stats) == 104);

    The switch should return a value of -1 for unavailable counters.

    Vendor Statistics Vendor-specic stats messages are requested with the OFPST_VENDORstats type. The rst four bytes of the message are the vendor identier. Therest of the body is vendor-dened.

    The vendor eld is a 32-bit value that uniquely identies the vendor. If themost signicant byte is zero, the next three bytes are the vendors IEEE OUI.If vendor does not have (or wish to use) their OUI, they should contact theOpenFlow consortium to obtain one.

    30

  • 7/29/2019 Openflow Spec Latest

    31/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    5.3.5 Send Packet Message

    When the controller wishes to send a packet out through the datapath, it usesthe OFPT_PACKET_OUTmessage:

    /* Send packet (controller -> datapath). */struct ofp_packet_out {

    struct ofp_header header;uint32_t buffer_id; /* ID assigned by datapath (-1 if none). */uint16_t in_port; /* Packets input port (OFPP_NONE if none). */uint16_t actions_len; /* Size of action array in bytes. */struct ofp_action_header actions[0]; /* Actions. *//* uint8_t data[0]; */ /* Packet data. The length is inferred

    from the length field in the header.(Only meaningful if buffer_id == -1.) */

    };OFP_ASSERT(sizeof(struct ofp_packet_out) == 16);

    The buffer_id is the same given in the ofp_packet_in message. If the buffer_idis -1, then the packet data is included in the data array. If OFPP_TABLE is spec-ied as the output port of an action, the in_port in the packet_out messageis used in the ow table lookup.

    5.3.6 Barrier Message

    When the controller wants to ensure message dependencies have been met orwants to receive notications for completed operations, it may use an OFPT_BARRIER_REQUESTmessage. This message has no body. Upon receipt, the switch must nish pro-cessing all previously-received messages before executing any messages beyondthe Barrier Request. When such processing is complete, the switch must sendan OFPT_BARRIER_REPLYmessage with the xid of the original request.

    5.4 Asynchronous Messages

    5.4.1 Packet-In Message

    When packets are received by the datapath and sent to the controller, they usethe OFPT_PACKET_INmessage:

    /* Packet received on port (datapath -> controller). */struct ofp_packet_in {

    struct ofp_header header;uint32_t buffer_id; /* ID assigned by datapath. */uint16_t total_len; /* Full length of frame. */uint16_t in_port; /* Port on which frame was received. */uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */

    uint8_t pad;uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,

    so the IP header is 32-bit aligned. Theamount of data is inferred from the lengthfield in the header. Because of padding,offsetof(struct ofp_packet_in, data) ==sizeof(struct ofp_packet_in) - 2. */

    31

  • 7/29/2019 Openflow Spec Latest

    32/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    };OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);

    The buffer_id is an opaque value used by the datapath to identify a bufferedpacket. When a packet is buffered, some number of bytes from the message willbe included in the data portion of the message. If the packet is sent becauseof a send to controller action, then max_len bytes from the action_outputof the ow setup request are sent. If the packet is sent because of a ow tablemiss, then at least miss_send_len bytes from the OFPT_SET_CONFIGmessageare sent. The default miss_send_len is 128 bytes. If the packet is not buffered,the entire packet is included in the data portion, and the buffer_id is -1.

    Switches that implement buffering are expected to expose, through documen-tation, both the amount of available buffering, and the length of time beforebuffers may be reused. A switch must gracefully handle the case where a bufferedpacket_in message yields no response from the controller. A switch should pre-vent a buffer from being reused until it has been handled by the controller, orsome amount of time (indicated in documentation) has passed.

    The reason eld can be any of these values:

    /* Why is this packet being sent to the controller? */enum ofp_packet_in_reason {

    OFPR_NO_MATCH, /* No matching flow. */OFPR_ACTION /* Action explicitly output to controller. */

    };

    5.4.2 Flow Removed Message

    If the controller has requested to be notied when ows time out, the datapathdoes this with the OFPT_FLOW_REMOVEDmessage:

    /* Flow removed (datapath -> controller). */struct ofp_flow_removed {

    struct ofp_header header;struct ofp_match match; /* Description of fields. */

    uint16_t priority; /* Priority level of flow entry. */uint8_t reason; /* One of OFPRR_*. */uint8_t pad[1]; /* Align to 32-bits. */

    uint32_t duration; /* Time flow was alive in seconds. */uint16_t idle_timeout; /* Idle timeout from original flow mod. */uin t8_t pad2[6]; /* Align to 64-b its. */uint64_t packet_count;

    uint64_t byte_count;};OFP_ASSERT(sizeof(struct ofp_flow_removed) == 80);

    The match and priority elds are the same as those used in the ow setuprequest.

    32

  • 7/29/2019 Openflow Spec Latest

    33/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    The reason eld is one of the following:

    /* Why was this flow removed? */enum ofp_flow_removed_reason {

    OFPRR_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */OFPRR_HARD_TIMEOUT, /* Time exceeded hard_timeout. */OFPRR_DELETE /* Evicted by a DELETE flow mod. */

    };

    The duration eld indicates the number of seconds the ow was alive (presentin the ow table).

    The idle_timeout eld is directly copied from the ow mod that created thisentry.

    With the above three elds, one can nd both the amount of time the owwas active, as well as the amount of time the ow received traffic.

    The packet_count and byte_count indicate the number of packets and bytesthat were associated with this ow, respectively.

    5.4.3 Port Status Message

    As physical ports are added, modied, and removed from the datapath, thecontroller needs to be informed with the OFPT_PORT_STATUSmessage:

    /* A physical port has changed in the datapath */struct ofp_port_status {

    struct ofp_header header;

    uint8_t reason; /* One of OFPPR_*. */uint8_t pad[7]; /* Align to 64-bits. */struct ofp_phy_port desc;

    };OFP_ASSERT(sizeof(struct ofp_port_status) == 64);

    The status can be one of the following values:

    /* What changed about the physical port */enum ofp_port_reason {

    OFPPR_ADD, /* The port was added. */OFPPR_DELETE, /* The port was removed. */OFPPR_MODIFY /* Some attribute of the por t has changed. */

    };

    5.4.4 Error MessageThere are times that the switch needs to notify the controller of a problem. Thisis done with the OFPT_ERROR_MSGmessage:

    /* OFPT_ERROR: Error message (datapath -> controller). */struct ofp_error_msg {

    33

  • 7/29/2019 Openflow Spec Latest

    34/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    struct ofp_header header;

    uint16_t type;uint16_t code;uint8_t data[0]; /* Variable-length data. Interpreted based

    on the type and code. */};OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);

    The type value indicates the high-level type of error. The code value is inter-preted based on the type. The data is variable length and interpreted basedon the type and code ; in most cases this is the message that caused the problem.

    Error codes ending in _EPERMcorrespond to a permissions error generated byan entity between a controller and switch, such as an OpenFlow hypervisor.

    Currently dened error types are:/* Values for type in ofp_error_message. These values are immutable: they

    * will not change in future versions of the protocol (although new values may* be added). */

    enum ofp_error_type {OFPET_HELLO_FAILED, /* Hello protocol failed. */OFPET_BAD_REQUEST, /* Request was not understood. */OFPET_BAD_ACTION, /* Error in action description. */OFPET_FLOW_MOD_FAILED /* Problem modifying flow entry. */

    };

    For the OFPET_HELLO_FAILEDerror type , the following code s are currently de-ned:

    /* ofp_error_msg code values for OFPET_HELLO_FAILED. data contains an* ASCII text string that may give failure details. */

    enum ofp_hello_failed_code {OFPHFC_INCOMPATIBLE, /* No compatible version. */OFPHFC_EPERM /* Permissions error. */

    };

    The data eld contains an ASCII text string that adds detail on why the erroroccurred.

    For the OFPET_BAD_REQUESTerror type , the following code s are currently de-ned:

    /* ofp_error_msg code values for OFPET_BAD_REQUEST. data contains at least* the first 64 bytes of the failed request. */

    enum ofp_bad_request_code {OFPBRC_BAD_VERSION, /* ofp_header.version not supported. */OFPBRC_BAD_TYPE, /* ofp_header. type not supported. */OFPBRC_BAD_STAT, /* ofp_stats_request.type not supported. */OFPBRC_BAD_VENDOR, /* Vendor not supported (in ofp_vendor_header

    * or ofp_stats_request or ofp_stats_reply). */OFPBRC_BAD_SUBTYPE, /* Vendor subtype not supported. */OFPBRC_EPERM /* Permissions error. */

    };

    34

  • 7/29/2019 Openflow Spec Latest

    35/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    The data eld contains at least 64 bytes of the failed request.

    For the OFPET_BAD_ACTIONerror type , the following code s are currently de-ned:

    /* ofp_error_msg code values for OFPET_BAD_ACTION. data contains at least* the first 64 bytes of the failed request. */

    enum ofp_bad_action_code {OFPBAC_BAD_TYPE, /* Unknown action type. * /OFPBAC_BAD_LEN, /* Length problem in actions. */OFPBAC_BAD_VENDOR, /* Unknown vendor id specified. */OFPBAC_BAD_VENDOR_TYPE, /* Unknown action type for vendor id. */OFPBAC_BAD_OUT_PORT, /* Problem validating output action. */OFPBAC_BAD_ARGUMENT, /* Bad action argument. */OFPBAC_EPERM /* Permissions error. */

    };

    The data eld contains at least 64 bytes of the failed request.

    For the OFPET_FLOW_MOD_FAILEDerror type , the following code s are currentlydened:

    /* ofp_error_msg code values for OFPET_FLOW_MOD_FAILED. data contains* at least the first 64 bytes of the failed request. */

    enum ofp_flow_mod_failed_code {OFPFMFC_ALL_TABLES_FULL, /* Flow not added because of full tables. */OFPFMFC_OVERLAP, /* Attempted to add overlapping flow with

    * CHECK_OVERLAP flag set. */OFPFMFC_EPERM, /* Permissions error. */OFPFMFC_BAD_EMERG_TIMEOUT /* Flow not added because of non-zero idle/hard

    * timeout. */};

    The data eld contains at least 64 bytes of the failed request.If the error message is in response to a specic message from the controller, e.g.,OFPET_BAD_REQUEST, OFPET_BAD_ACTION, or OFPET_FLOW_MOD_FAILED, then thexid eld of the header should match that of the offending message.

    5.5 Symmetric Messages

    5.5.1 Hello

    The OFPT_HELLOmessage has no body; that is, it consists only of an OpenFlowheader. Implementations must be prepared to receive a hello message thatincludes a body, ignoring its contents, to allow for later extensions.

    5.5.2 Echo Request

    An Echo Request message consists of an OpenFlow header plus an arbitrary-length data eld. The data eld might be a message timestamp to check latency,various lengths to measure bandwidth, or zero-size to verify liveness betweenthe switch and controller.

    35

  • 7/29/2019 Openflow Spec Latest

    36/36

    DO NOT BUILD A SWITCH FROM THIS SPECIFICATION!

    5.5.3 Echo Reply

    An Echo Reply message consists of an OpenFlow header plus the unmodieddata eld of an echo request message.

    In an OpenFlow protocol implementation divided into multiple layers, the echorequest/reply logic should be implemented in the deepest practical layer. Forexample, in the OpenFlow reference implementation that includes a userspaceprocess that relays to a kernel module, echo request/reply is implemented in thekernel module. Receiving a correctly formatted echo reply then shows a greaterlikelihood of correct end-to-end functionality than if the echo request/reply wereimplemented in the userspace process, as well as providing more accurate end-to-end latency timing.

    5.5.4 Vendor

    The Vendor message is dened as follows:

    /* Vendor extension. */struct ofp_vendor_header {

    struct ofp_header header; /* Type OFPT_VENDOR. */uint32_t vendor; /* Vendor ID:

    * - MSB 0: low-order bytes are IEEE OUI.* - MSB != 0: defined by OpenFlow* consortium. */

    /* Vendor-defined arbitrary additional data. */};OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);

    The vendor eld is a 32-bit value that uniquely identies the vendor. If themost signicant byte is zero, the next three bytes are the vendors IEEE OUI.If vendor does not have (or wish to use) their OUI, they should contact theOpenFlow consortium to obtain one. The rest of the body is uninterpreted.

    If a switch does not understand a vendor extension, it must send an OFPT_ERRORmessage with a OFPBRC_BAD_VENDORerror code and OFPET_BAD_REQUESTerrortype.

    36