Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
openflow10.h
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  *
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33 
34 /* OpenFlow: protocol between controller and datapath. */
35 
36 #ifndef _OPENFLOW_OPENFLOW10_H
37 #define _OPENFLOW_OPENFLOW10_H 1
38 
39 #include "rofl/common/openflow/openflow_common.h"
40 
41 
42 namespace rofl {
43 namespace openflow10 {
44 
45  enum ofp_version_t {
46  OFP_VERSION = 1,
47  };
48 
49  /* Version number:
50  * Non-experimental versions released: 0x01
51  * Experimental versions released: 0x81 -- 0x99
52  */
53 
54  /* The most significant bit being set in the version field indicates an
55  * experimental OpenFlow version.
56  */
57  #define OFP10_VERSION 1
58 
59 
60  /* Header on all OpenFlow packets. */
61  struct ofp_header {
62  uint8_t version; /* OFP10_VERSION. */
63  uint8_t type; /* One of the OFP10T_ constants. */
64  uint16_t length; /* Length including this ofp10_header. */
65  uint32_t xid; /* Transaction id associated with this packet.
66  Replies use the same id as was in the request
67  to facilitate pairing. */
68  };
69  OFP_ASSERT(sizeof(struct ofp_header) == 8);
70 
71 
72  /* OFPT_ERROR: Error message (datapath -> controller). */
73  struct ofp_error_msg {
74  struct ofp_header header;
75 
76  uint16_t type;
77  uint16_t code;
78  uint8_t data[0]; /* Variable-length data. Interpreted based
79  on the type and code. No padding. */
80  };
81  OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);
82 
83 
84 
85 
86 
87 
88 
89  /* Port numbering. Physical ports are numbered starting from 1. */
90  enum ofp_port_no {
91  /* Maximum number of physical switch ports. */
92  OFPP_MAX = 0xff00,
93 
94  /* Fake output "ports". */
95  OFPP_IN_PORT = 0xfff8, /* Send the packet out the input port. This
96  virtual port must be explicitly used
97  in order to send back out of the input
98  port. */
99  OFPP_TABLE = 0xfff9, /* Perform actions in flow table.
100  NB: This can only be the destination
101  port for packet-out messages. */
102  OFPP_NORMAL = 0xfffa, /* Process with normal L2/L3 switching. */
103  OFPP_FLOOD = 0xfffb, /* All physical ports except input port and
104  those disabled by STP. */
105  OFPP_ALL = 0xfffc, /* All physical ports except input port. */
106  OFPP_CONTROLLER = 0xfffd, /* Send to controller. */
107  OFPP_LOCAL = 0xfffe, /* Local OpenFlow "port". */
108  OFPP_NONE = 0xffff /* Not associated with a physical port. */
109  };
110 
111  enum ofp_buffer_t {
112  OFP_NO_BUFFER = 0xffffffff,
113  };
114 
115  enum ofp_type {
116  /* Immutable messages. */
117  OFPT_HELLO = 0, /* Symmetric message */
118  OFPT_ERROR = 1, /* Symmetric message */
119  OFPT_ECHO_REQUEST = 2, /* Symmetric message */
120  OFPT_ECHO_REPLY = 3, /* Symmetric message */
121  OFPT_VENDOR = 4, /* Symmetric message */
122 
123  /* Switch configuration messages. */
124  OFPT_FEATURES_REQUEST = 5, /* Controller/switch message */
125  OFPT_FEATURES_REPLY = 6, /* Controller/switch message */
126  OFPT_GET_CONFIG_REQUEST = 7, /* Controller/switch message */
127  OFPT_GET_CONFIG_REPLY = 8, /* Controller/switch message */
128  OFPT_SET_CONFIG = 9, /* Controller/switch message */
129 
130  /* Asynchronous messages. */
131  OFPT_PACKET_IN = 10, /* Async message */
132  OFPT_FLOW_REMOVED = 11, /* Async message */
133  OFPT_PORT_STATUS = 12, /* Async message */
134 
135  /* Controller command messages. */
136  OFPT_PACKET_OUT = 13, /* Controller/switch message */
137  OFPT_FLOW_MOD = 14, /* Controller/switch message */
138  OFPT_PORT_MOD = 15, /* Controller/switch message */
139 
140  /* Statistics messages (up to and including OF1.2) */
141  OFPT_STATS_REQUEST = 16, /* Controller/switch message */
142  OFPT_STATS_REPLY = 17, /* Controller/switch message */
143 
144  /* Barrier messages. */
145  OFPT_BARRIER_REQUEST = 18, /* Controller/switch message */
146  OFPT_BARRIER_REPLY = 19, /* Controller/switch message */
147 
148  /* Queue Configuration messages. */
149  OFPT_QUEUE_GET_CONFIG_REQUEST = 20, /* Controller/switch message */
150  OFPT_QUEUE_GET_CONFIG_REPLY = 21, /* Controller/switch message */
151  };
152 
153 
154 
155 
156  /* OFPT_HELLO. This message has an empty body, but implementations must
157  * ignore any data included in the body, to allow for future extensions. */
158  struct ofp_hello {
159  struct ofp_header header;
160  };
161 
162  #define OFP_DEFAULT_MISS_SEND_LEN 128
163 
164  enum ofp_config_flags {
165  /* Handling of IP fragments. */
166  OFPC_FRAG_NORMAL = 0, /* No special handling for fragments. */
167  OFPC_FRAG_DROP = 1, /* Drop fragments. */
168  OFPC_FRAG_REASM = 2, /* Reassemble (only if OFPC_IP_REASM set). */
169  OFPC_FRAG_MASK = 3
170  };
171 
172  /* Switch configuration. */
174  struct ofp_header header;
175  uint16_t flags; /* OFPC_* flags. */
176  uint16_t miss_send_len; /* Max bytes of new flow that datapath should
177  send to the controller. */
178  };
179  OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
180 
181  /* Capabilities supported by the datapath. */
182  enum ofp_capabilities {
183  OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
184  OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
185  OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
186  OFPC_STP = 1 << 3, /* 802.1d spanning tree. */
187  OFPC_RESERVED = 1 << 4, /* Reserved, must be zero. */
188  OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
189  OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
190  OFPC_ARP_MATCH_IP = 1 << 7 /* Match IP addresses in ARP pkts. */
191  };
192 
193  /* Flags to indicate behavior of the physical port. These flags are
194  * used in ofp_phy_port to describe the current configuration. They are
195  * used in the ofp_port_mod message to configure the port's behavior.
196  */
197  enum ofp_port_config {
198  OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
199 
200  OFPPC_NO_STP = 1 << 1, /* Disable 802.1D spanning tree on port. */
201  OFPPC_NO_RECV = 1 << 2, /* Drop all packets except 802.1D spanning
202  tree packets. */
203  OFPPC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
204  OFPPC_NO_FLOOD = 1 << 4, /* Do not include this port when flooding. */
205  OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
206  OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
207  };
208 
209  /* Current state of the physical port. These are not configurable from
210  * the controller.
211  */
212  enum ofp_port_state {
213  OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
214 
215  /* The OFPPS_STP_* bits have no effect on switch operation. The
216  * controller must adjust OFPPC_NO_RECV, OFPPC_NO_FWD, and
217  * OFPPC_NO_PACKET_IN appropriately to fully implement an 802.1D spanning
218  * tree. */
219  OFPPS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
220  OFPPS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
221  OFPPS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
222  OFPPS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
223  OFPPS_STP_MASK = 3 << 8 /* Bit mask for OFPPS_STP_* values. */
224  };
225 
226  /* Features of physical ports available in a datapath. */
227  enum ofp_port_features {
228  OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
229  OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
230  OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
231  OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
232  OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
233  OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
234  OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
235  OFPPF_COPPER = 1 << 7, /* Copper medium. */
236  OFPPF_FIBER = 1 << 8, /* Fiber medium. */
237  OFPPF_AUTONEG = 1 << 9, /* Auto-negotiation. */
238  OFPPF_PAUSE = 1 << 10, /* Pause. */
239  OFPPF_PAUSE_ASYM = 1 << 11 /* Asymmetric pause. */
240  };
241 
242  /* Description of a physical port */
243  struct ofp_port {
244  uint16_t port_no;
245  uint8_t hw_addr[OFP_ETH_ALEN];
246  char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
247 
248  uint32_t config; /* Bitmap of OFPPC_* flags. */
249  uint32_t state; /* Bitmap of OFPPS_* flags. */
250 
251  /* Bitmaps of OFPPF_* that describe features. All bits zeroed if
252  * unsupported or unavailable. */
253  uint32_t curr; /* Current features. */
254  uint32_t advertised; /* Features being advertised by the port. */
255  uint32_t supported; /* Features supported by the port. */
256  uint32_t peer; /* Features advertised by peer. */
257  };
258  OFP_ASSERT(sizeof(struct ofp_port) == 48);
259 
260  /* Switch features. */
262  struct ofp_header header;
263  uint64_t datapath_id; /* Datapath unique ID. The lower 48-bits are for
264  a MAC address, while the upper 16-bits are
265  implementer-defined. */
266 
267  uint32_t n_buffers; /* Max packets buffered at once. */
268 
269  uint8_t n_tables; /* Number of tables supported by datapath. */
270  uint8_t pad[3]; /* Align to 64-bits. */
271 
272  /* Features. */
273  uint32_t capabilities; /* Bitmap of support "ofp_capabilities". */
274  uint32_t actions; /* Bitmap of supported "ofp_action_type"s. */
275 
276  /* Port info.*/
277  struct ofp_port ports[0]; /* Port definitions. The number of ports
278  is inferred from the length field in
279  the header. */
280  };
281  OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
282 
283  /* What changed about the physical port */
284  enum ofp_port_reason {
285  OFPPR_ADD, /* The port was added. */
286  OFPPR_DELETE, /* The port was removed. */
287  OFPPR_MODIFY /* Some attribute of the port has changed. */
288  };
289 
290  /* A physical port has changed in the datapath */
292  struct ofp_header header;
293  uint8_t reason; /* One of OFPPR_*. */
294  uint8_t pad[7]; /* Align to 64-bits. */
295  struct ofp_port desc;
296  };
297  OFP_ASSERT(sizeof(struct ofp_port_status) == 64);
298 
299  /* Modify behavior of the physical port */
300  struct ofp_port_mod {
301  struct ofp_header header;
302  uint16_t port_no;
303  uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
304  configurable. This is used to
305  sanity-check the request, so it must
306  be the same as returned in an
307  ofp_phy_port struct. */
308 
309  uint32_t config; /* Bitmap of OFPPC_* flags. */
310  uint32_t mask; /* Bitmap of OFPPC_* flags to be changed. */
311 
312  uint32_t advertise; /* Bitmap of "ofp_port_features"s. Zero all
313  bits to prevent any action taking place. */
314  uint8_t pad[4]; /* Pad to 64-bits. */
315  };
316  OFP_ASSERT(sizeof(struct ofp_port_mod) == 32);
317 
318  /* Why is this packet being sent to the controller? */
319  enum ofp_packet_in_reason {
320  OFPR_NO_MATCH, /* No matching flow. */
321  OFPR_ACTION /* Action explicitly output to controller. */
322  };
323 
324  /* Packet received on port (datapath -> controller). */
325  struct ofp_packet_in {
326  struct ofp_header header;
327  uint32_t buffer_id; /* ID assigned by datapath. */
328  uint16_t total_len; /* Full length of frame. */
329  uint16_t in_port; /* Port on which frame was received. */
330  uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
331  uint8_t pad;
332  uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,
333  so the IP header is 32-bit aligned. The
334  amount of data is inferred from the length
335  field in the header. Because of padding,
336  offsetof(struct ofp_packet_in, data) ==
337  sizeof(struct ofp_packet_in) - 2. */
338  };
339  OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
340 
341  static int const OFP_PACKET_IN_STATIC_HDR_LEN = sizeof(struct ofp_packet_in) - 2; /* 18bytes */
342 
343  OFP_ASSERT(OFP_PACKET_IN_STATIC_HDR_LEN == 18);
344 
345  enum ofp_action_type {
346  OFPAT_OUTPUT, /* Output to switch port. */
347  OFPAT_SET_VLAN_VID, /* Set the 802.1q VLAN id. */
348  OFPAT_SET_VLAN_PCP, /* Set the 802.1q priority. */
349  OFPAT_STRIP_VLAN, /* Strip the 802.1q header. */
350  OFPAT_SET_DL_SRC, /* Ethernet source address. */
351  OFPAT_SET_DL_DST, /* Ethernet destination address. */
352  OFPAT_SET_NW_SRC, /* IP source address. */
353  OFPAT_SET_NW_DST, /* IP destination address. */
354  OFPAT_SET_NW_TOS, /* IP ToS (DSCP field, 6 bits). */
355  OFPAT_SET_TP_SRC, /* TCP/UDP source port. */
356  OFPAT_SET_TP_DST, /* TCP/UDP destination port. */
357  OFPAT_ENQUEUE, /* Output to queue. */
358  OFPAT_VENDOR = 0xffff
359  };
360 
361 
362 
363  /* Action header that is common to all actions. The length includes the
364  * header and any padding used to make the action 64-bit aligned.
365  * NB: The length of an action *must* always be a multiple of eight. */
367  uint16_t type; /* One of OFPAT_*. */
368  uint16_t len; /* Length of action, including this
369  header. This is the length of action,
370  including any padding to make it
371  64-bit aligned. */
372  uint8_t pad[4];
373  };
374  OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
375 
376 
377  /* Action structure for OFPAT_OUTPUT, which sends packets out 'port'.
378  * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
379  * number of bytes to send. A 'max_len' of zero means no bytes of the
380  * packet should be sent.*/
382  uint16_t type; /* OFPAT_OUTPUT. */
383  uint16_t len; /* Length is 8. */
384  uint16_t port; /* Output port. */
385  uint16_t max_len; /* Max length to send to controller. */
386  };
387  OFP_ASSERT(sizeof(struct ofp_action_output) == 8);
388 
389  /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
390  * special conditions. All ones is used to match that no VLAN id was
391  * set. */
392  static int const OFP_VLAN_NONE = 0xffff;
393 
394  enum ofp_vlan_id {
395  OFPVID_ANY = 0xfffe, /* Indicate that a VLAN id is set but don't care
396  about it's value. Note: only valid when specifying
397  the VLAN id in a match */
398  OFPVID_NONE = 0xffff, /* No VLAN id was set. */
399  };
400 
401  /* Action structure for OFPAT_SET_VLAN_VID. */
403  uint16_t type; /* OFPAT_SET_VLAN_VID. */
404  uint16_t len; /* Length is 8. */
405  uint16_t vlan_vid; /* VLAN id. */
406  uint8_t pad[2];
407  };
408  OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);
409 
410  /* Action structure for OFPAT_SET_VLAN_PCP. */
412  uint16_t type; /* OFPAT_SET_VLAN_PCP. */
413  uint16_t len; /* Length is 8. */
414  uint8_t vlan_pcp; /* VLAN priority. */
415  uint8_t pad[3];
416  };
417  OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);
418 
419  /* Action structure for OFPAT_SET_DL_SRC/DST. */
421  uint16_t type; /* OFPAT_SET_DL_SRC/DST. */
422  uint16_t len; /* Length is 16. */
423  uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */
424  uint8_t pad[6];
425  };
426  OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
427 
428  /* Action structure for OFPAT_SET_NW_SRC/DST. */
430  uint16_t type; /* OFPAT_SET_TW_SRC/DST. */
431  uint16_t len; /* Length is 8. */
432  uint32_t nw_addr; /* IP address. */
433  };
434  OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);
435 
436  /* Action structure for OFPAT_SET_TP_SRC/DST. */
438  uint16_t type; /* OFPAT_SET_TP_SRC/DST. */
439  uint16_t len; /* Length is 8. */
440  uint16_t tp_port; /* TCP/UDP port. */
441  uint8_t pad[2];
442  };
443  OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);
444 
445  /* Action structure for OFPAT_SET_NW_TOS. */
447  uint16_t type; /* OFPAT_SET_TW_SRC/DST. */
448  uint16_t len; /* Length is 8. */
449  uint8_t nw_tos; /* IP ToS (DSCP field, 6 bits). */
450  uint8_t pad[3];
451  };
452  OFP_ASSERT(sizeof(struct ofp_action_nw_tos) == 8);
453 
454  /* Action header for OFPAT_VENDOR. The rest of the body is vendor-defined. */
456  uint16_t type; /* OFPAT_VENDOR. */
457  uint16_t len; /* Length is a multiple of 8. */
458  uint32_t vendor; /* Vendor ID, which takes the same form
459  as in "struct ofp_vendor_header". */
460  uint8_t data[0];
461  };
462  OFP_ASSERT(sizeof(struct ofp_action_vendor_header) == 8);
463 
464 
465 
466 
467 
468 
469 
470 
471 
472 
473 
474 
475  /* Send packet (controller -> datapath). */
476  struct ofp_packet_out {
477  struct ofp_header header;
478  uint32_t buffer_id; /* ID assigned by datapath (-1 if none). */
479  uint16_t in_port; /* Packet's input port (OFPP_NONE if none). */
480  uint16_t actions_len; /* Size of action array in bytes. */
481  struct ofp_action_header actions[0]; /* Actions. */
482  /* uint8_t data[0]; */ /* Packet data. The length is inferred
483  from the length field in the header.
484  (Only meaningful if buffer_id == -1.) */
485  };
486  OFP_ASSERT(sizeof(struct ofp_packet_out) == 16);
487 
488  enum ofp_flow_mod_command {
489  OFPFC_ADD, /* New flow. */
490  OFPFC_MODIFY, /* Modify all matching flows. */
491  OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */
492  OFPFC_DELETE, /* Delete all matching flows. */
493  OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */
494  };
495 
496  enum flow_mod_header_len {
497  OFP_FLOW_MOD_STATIC_HDR_LEN = 72,
498  };
499 
500  /* Flow wildcards. */
501  enum ofp_flow_wildcards {
502  OFPFW_IN_PORT = 1 << 0, /* Switch input port. */
503  OFPFW_DL_VLAN = 1 << 1, /* VLAN id. */
504  OFPFW_DL_SRC = 1 << 2, /* Ethernet source address. */
505  OFPFW_DL_DST = 1 << 3, /* Ethernet destination address. */
506  OFPFW_DL_TYPE = 1 << 4, /* Ethernet frame type. */
507  OFPFW_NW_PROTO = 1 << 5, /* IP protocol. */
508  OFPFW_TP_SRC = 1 << 6, /* TCP/UDP source port. */
509  OFPFW_TP_DST = 1 << 7, /* TCP/UDP destination port. */
510 
511  /* IP source address wildcard bit count. 0 is exact match, 1 ignores the
512  * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
513  * the entire field. This is the *opposite* of the usual convention where
514  * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded. */
515  OFPFW_NW_SRC_SHIFT = 8,
516  OFPFW_NW_SRC_BITS = 6,
517  OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT,
518  OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT,
519 
520  /* IP destination address wildcard bit count. Same format as source. */
521  OFPFW_NW_DST_SHIFT = 14,
522  OFPFW_NW_DST_BITS = 6,
523  OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT,
524  OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT,
525 
526  OFPFW_DL_VLAN_PCP = 1 << 20, /* VLAN priority. */
527  OFPFW_NW_TOS = 1 << 21, /* IP ToS (DSCP field, 6 bits). */
528 
529  /* Wildcard all fields. */
530  OFPFW_ALL = ((1 << 22) - 1)
531  };
532 
533  /* The wildcards for ICMP type and code fields use the transport source
534  * and destination port fields, respectively. */
535  #define OFPFW_ICMP_TYPE OFPFW_TP_SRC
536  #define OFPFW_ICMP_CODE OFPFW_TP_DST
537 
538  /* Values below this cutoff are 802.3 packets and the two bytes
539  * following MAC addresses are used as a frame length. Otherwise, the
540  * two bytes are used as the Ethernet type.
541  */
542  #define OFP_DL_TYPE_ETH2_CUTOFF 0x0600
543 
544  /* Value of dl_type to indicate that the frame does not include an
545  * Ethernet type.
546  */
547  #define OFP_DL_TYPE_NOT_ETH_TYPE 0x05ff
548 
549 
550  /* Fields to match against flows */
551  struct ofp_match {
552  uint32_t wildcards; /* Wildcard fields. */
553  uint16_t in_port; /* Input switch port. */
554  uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
555  uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
556  uint16_t dl_vlan; /* Input VLAN id. */
557  uint8_t dl_vlan_pcp; /* Input VLAN priority. */
558  uint8_t pad1[1]; /* Align to 64-bits */
559  uint16_t dl_type; /* Ethernet frame type. */
560  uint8_t nw_tos; /* IP ToS (actually DSCP field, 6 bits). */
561  uint8_t nw_proto; /* IP protocol or lower 8 bits of
562  * ARP opcode. */
563  uint8_t pad2[2]; /* Align to 64-bits */
564  uint32_t nw_src; /* IP source address. */
565  uint32_t nw_dst; /* IP destination address. */
566  uint16_t tp_src; /* TCP/UDP source port. */
567  uint16_t tp_dst; /* TCP/UDP destination port. */
568  };
569  OFP_ASSERT(sizeof(struct ofp_match) == 40);
570 
571  static int const OFP_MATCH_STATIC_LEN = sizeof(struct ofp_match);
572 
573  /* The match fields for ICMP type and code use the transport source and
574  * destination port fields, respectively. */
575  #define icmp_type tp_src
576  #define icmp_code tp_dst
577 
578  /* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
579  * is permanent. */
580  #define OFP_FLOW_PERMANENT 0
581 
582  /* By default, choose a priority in the middle. */
583  #define OFP_DEFAULT_PRIORITY 0x8000
584 
585  enum ofp_flow_mod_flags {
586  OFPFF_SEND_FLOW_REM = 1 << 0, /* Send flow removed message when flow
587  * expires or is deleted. */
588  OFPFF_CHECK_OVERLAP = 1 << 1, /* Check for overlapping entries first. */
589  OFPFF_EMERG = 1 << 2 /* Remark this is for emergency. */
590  };
591 
592  /* Flow setup and teardown (controller -> datapath). */
593  struct ofp_flow_mod {
594  struct ofp_header header;
595  struct ofp_match match; /* Fields to match */
596  uint64_t cookie; /* Opaque controller-issued identifier. */
597 
598  /* Flow actions. */
599  uint16_t command; /* One of OFPFC_*. */
600  uint16_t idle_timeout; /* Idle time before discarding (seconds). */
601  uint16_t hard_timeout; /* Max time before discarding (seconds). */
602  uint16_t priority; /* Priority level of flow entry. */
603  uint32_t buffer_id; /* Buffered packet to apply to (or -1).
604  Not meaningful for OFPFC_DELETE*. */
605  uint16_t out_port; /* For OFPFC_DELETE* commands, require
606  matching entries to include this as an
607  output port. A value of OFPP_NONE
608  indicates no restriction. */
609  uint16_t flags; /* One of OFPFF_*. */
610  struct ofp_action_header actions[0]; /* The action length is inferred
611  from the length field in the
612  header. */
613  };
614  OFP_ASSERT(sizeof(struct ofp_flow_mod) == 72);
615 
616  /* Why was this flow removed? */
617  enum ofp_flow_removed_reason {
618  OFPRR_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */
619  OFPRR_HARD_TIMEOUT, /* Time exceeded hard_timeout. */
620  OFPRR_DELETE /* Evicted by a DELETE flow mod. */
621  };
622 
623  /* Flow removed (datapath -> controller). */
625  struct ofp_header header;
626  struct ofp_match match; /* Description of fields. */
627  uint64_t cookie; /* Opaque controller-issued identifier. */
628 
629  uint16_t priority; /* Priority level of flow entry. */
630  uint8_t reason; /* One of OFPRR_*. */
631  uint8_t pad[1]; /* Align to 32-bits. */
632 
633  uint32_t duration_sec; /* Time flow was alive in seconds. */
634  uint32_t duration_nsec; /* Time flow was alive in nanoseconds beyond
635  duration_sec. */
636  uint16_t idle_timeout; /* Idle timeout from original flow mod. */
637  uint8_t pad2[2]; /* Align to 64-bits. */
638  uint64_t packet_count;
639  uint64_t byte_count;
640  };
641  OFP_ASSERT(sizeof(struct ofp_flow_removed) == 88);
642 
643  /* Values for 'type' in ofp_error_message. These values are immutable: they
644  * will not change in future versions of the protocol (although new values may
645  * be added). */
646  enum ofp_error_type {
647  OFPET_HELLO_FAILED, /* Hello protocol failed. */
648  OFPET_BAD_REQUEST, /* Request was not understood. */
649  OFPET_BAD_ACTION, /* Error in action description. */
650  OFPET_FLOW_MOD_FAILED, /* Problem modifying flow entry. */
651  OFPET_PORT_MOD_FAILED, /* Port mod request failed. */
652  OFPET_QUEUE_OP_FAILED /* Queue operation failed. */
653  };
654 
655  /* ofp_error_msg 'code' values for OFPET_HELLO_FAILED. 'data' contains an
656  * ASCII text string that may give failure details. */
657  enum ofp_hello_failed_code {
658  OFPHFC_INCOMPATIBLE, /* No compatible version. */
659  OFPHFC_EPERM /* Permissions error. */
660  };
661 
662  /* ofp_error_msg 'code' values for OFPET_BAD_REQUEST. 'data' contains at least
663  * the first 64 bytes of the failed request. */
664  enum ofp_bad_request_code {
665  OFPBRC_BAD_VERSION, /* ofp_header.version not supported. */
666  OFPBRC_BAD_TYPE, /* ofp_header.type not supported. */
667  OFPBRC_BAD_STAT, /* ofp_stats_request.type not supported. */
668  OFPBRC_BAD_VENDOR, /* Vendor not supported (in ofp_vendor_header
669  * or ofp_stats_request or ofp_stats_reply). */
670  OFPBRC_BAD_SUBTYPE, /* Vendor subtype not supported. */
671  OFPBRC_EPERM, /* Permissions error. */
672  OFPBRC_BAD_LEN, /* Wrong request length for type. */
673  OFPBRC_BUFFER_EMPTY, /* Specified buffer has already been used. */
674  OFPBRC_BUFFER_UNKNOWN /* Specified buffer does not exist. */
675  };
676 
677  /* ofp_error_msg 'code' values for OFPET_BAD_ACTION. 'data' contains at least
678  * the first 64 bytes of the failed request. */
679  enum ofp_bad_action_code {
680  OFPBAC_BAD_TYPE, /* Unknown action type. */
681  OFPBAC_BAD_LEN, /* Length problem in actions. */
682  OFPBAC_BAD_VENDOR, /* Unknown vendor id specified. */
683  OFPBAC_BAD_VENDOR_TYPE, /* Unknown action type for vendor id. */
684  OFPBAC_BAD_OUT_PORT, /* Problem validating output action. */
685  OFPBAC_BAD_ARGUMENT, /* Bad action argument. */
686  OFPBAC_EPERM, /* Permissions error. */
687  OFPBAC_TOO_MANY, /* Can't handle this many actions. */
688  OFPBAC_BAD_QUEUE /* Problem validating output queue. */
689  };
690 
691  /* ofp_error_msg 'code' values for OFPET_FLOW_MOD_FAILED. 'data' contains
692  * at least the first 64 bytes of the failed request. */
693  enum ofp_flow_mod_failed_code {
694  OFPFMFC_ALL_TABLES_FULL, /* Flow not added because of full tables. */
695  OFPFMFC_OVERLAP, /* Attempted to add overlapping flow with
696  * CHECK_OVERLAP flag set. */
697  OFPFMFC_EPERM, /* Permissions error. */
698  OFPFMFC_BAD_EMERG_TIMEOUT, /* Flow not added because of non-zero idle/hard
699  * timeout. */
700  OFPFMFC_BAD_COMMAND, /* Unknown command. */
701  OFPFMFC_UNSUPPORTED /* Unsupported action list - cannot process in
702  * the order specified. */
703  };
704 
705  /* ofp_error_msg 'code' values for OFPET_PORT_MOD_FAILED. 'data' contains
706  * at least the first 64 bytes of the failed request. */
707  enum ofp_port_mod_failed_code {
708  OFPPMFC_BAD_PORT, /* Specified port does not exist. */
709  OFPPMFC_BAD_HW_ADDR, /* Specified hardware address is wrong. */
710  };
711 
712  /* ofp_error msg 'code' values for OFPET_QUEUE_OP_FAILED. 'data' contains
713  * at least the first 64 bytes of the failed request */
714  enum ofp_queue_op_failed_code {
715  OFPQOFC_BAD_PORT, /* Invalid port (or port does not exist). */
716  OFPQOFC_BAD_QUEUE, /* Queue does not exist. */
717  OFPQOFC_EPERM /* Permissions error. */
718  };
719 
720 
721  enum ofp_stats_types {
722  /* Description of this OpenFlow switch.
723  * The request body is empty.
724  * The reply body is struct ofp_desc_stats. */
725  OFPST_DESC,
726 
727  /* Individual flow statistics.
728  * The request body is struct ofp_flow_stats_request.
729  * The reply body is an array of struct ofp_flow_stats. */
730  OFPST_FLOW,
731 
732  /* Aggregate flow statistics.
733  * The request body is struct ofp_aggregate_stats_request.
734  * The reply body is struct ofp_aggregate_stats_reply. */
735  OFPST_AGGREGATE,
736 
737  /* Flow table statistics.
738  * The request body is empty.
739  * The reply body is an array of struct ofp_table_stats. */
740  OFPST_TABLE,
741 
742  /* Physical port statistics.
743  * The request body is struct ofp_port_stats_request.
744  * The reply body is an array of struct ofp_port_stats. */
745  OFPST_PORT,
746 
747  /* Queue statistics for a port
748  * The request body defines the port
749  * The reply body is an array of struct ofp_queue_stats */
750  OFPST_QUEUE,
751 
752  /* Vendor extension.
753  * The request and reply bodies begin with a 32-bit vendor ID, which takes
754  * the same form as in "struct ofp_vendor_header". The request and reply
755  * bodies are otherwise vendor-defined. */
756  OFPST_VENDOR = 0xffff
757  };
758 
760  struct ofp_header header;
761  uint16_t type; /* One of the OFPST_* constants. */
762  uint16_t flags; /* OFPSF_REQ_* flags (none yet defined). */
763  uint8_t body[0]; /* Body of the request. */
764  };
765  OFP_ASSERT(sizeof(struct ofp_stats_request) == 12);
766 
767  enum ofp_stats_reply_flags {
768  OFPSF_REPLY_MORE = 1 << 0 /* More replies to follow. */
769  };
770 
772  struct ofp_header header;
773  uint16_t type; /* One of the OFPST_* constants. */
774  uint16_t flags; /* OFPSF_REPLY_* flags. */
775  uint8_t body[0]; /* Body of the reply. */
776  };
777  OFP_ASSERT(sizeof(struct ofp_stats_reply) == 12);
778 
779  #define DESC_STR_LEN 256
780  #define SERIAL_NUM_LEN 32
781  /* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated
782  * ASCII string. */
783  struct ofp_desc_stats {
784  char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
785  char hw_desc[DESC_STR_LEN]; /* Hardware description. */
786  char sw_desc[DESC_STR_LEN]; /* Software description. */
787  char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
788  char dp_desc[DESC_STR_LEN]; /* Human readable description of datapath. */
789  };
790  OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1056);
791 
792  /* Body for ofp_stats_request of type OFPST_FLOW. */
794  struct ofp_match match; /* Fields to match. */
795  uint8_t table_id; /* ID of table to read (from ofp_table_stats),
796  0xff for all tables or 0xfe for emergency. */
797  uint8_t pad; /* Align to 32 bits. */
798  uint16_t out_port; /* Require matching entries to include this
799  as an output port. A value of OFPP_NONE
800  indicates no restriction. */
801  };
802  OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 44);
803 
804  /* Body of reply to OFPST_FLOW request. */
805  struct ofp_flow_stats {
806  uint16_t length; /* Length of this entry. */
807  uint8_t table_id; /* ID of table flow came from. */
808  uint8_t pad;
809  struct ofp_match match; /* Description of fields. */
810  uint32_t duration_sec; /* Time flow has been alive in seconds. */
811  uint32_t duration_nsec; /* Time flow has been alive in nanoseconds beyond
812  duration_sec. */
813  uint16_t priority; /* Priority of the entry. Only meaningful
814  when this is not an exact-match entry. */
815  uint16_t idle_timeout; /* Number of seconds idle before expiration. */
816  uint16_t hard_timeout; /* Number of seconds before expiration. */
817  uint8_t pad2[6]; /* Align to 64-bits. */
818  uint64_t cookie; /* Opaque controller-issued identifier. */
819  uint64_t packet_count; /* Number of packets in flow. */
820  uint64_t byte_count; /* Number of bytes in flow. */
821  struct ofp_action_header actions[0]; /* Actions. */
822  };
823  OFP_ASSERT(sizeof(struct ofp_flow_stats) == 88);
824 
825  /* Body for ofp_stats_request of type OFPST_AGGREGATE. */
827  struct ofp_match match; /* Fields to match. */
828  uint8_t table_id; /* ID of table to read (from ofp_table_stats)
829  0xff for all tables or 0xfe for emergency. */
830  uint8_t pad; /* Align to 32 bits. */
831  uint16_t out_port; /* Require matching entries to include this
832  as an output port. A value of OFPP_NONE
833  indicates no restriction. */
834  };
835  OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request) == 44);
836 
837  /* Body of reply to OFPST_AGGREGATE request. */
839  uint64_t packet_count; /* Number of packets in flows. */
840  uint64_t byte_count; /* Number of bytes in flows. */
841  uint32_t flow_count; /* Number of flows. */
842  uint8_t pad[4]; /* Align to 64 bits. */
843  };
844  OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
845 
846  /* Body of reply to OFPST_TABLE request. */
848  uint8_t table_id; /* Identifier of table. Lower numbered tables
849  are consulted first. */
850  uint8_t pad[3]; /* Align to 32-bits. */
851  char name[OFP_MAX_TABLE_NAME_LEN];
852  uint32_t wildcards; /* Bitmap of OFPFW_* wildcards that are
853  supported by the table. */
854  uint32_t max_entries; /* Max number of entries supported. */
855  uint32_t active_count; /* Number of active entries. */
856  uint64_t lookup_count; /* Number of packets looked up in table. */
857  uint64_t matched_count; /* Number of packets that hit table. */
858  };
859  OFP_ASSERT(sizeof(struct ofp_table_stats) == 64);
860 
861  /* Body for ofp_stats_request of type OFPST_PORT. */
863  uint16_t port_no; /* OFPST_PORT message must request statistics
864  * either for a single port (specified in
865  * port_no) or for all ports (if port_no ==
866  * OFPP_NONE). */
867  uint8_t pad[6];
868  };
869  OFP_ASSERT(sizeof(struct ofp_port_stats_request) == 8);
870 
871  /* Body of reply to OFPST_PORT request. If a counter is unsupported, set
872  * the field to all ones. */
873  struct ofp_port_stats {
874  uint16_t port_no;
875  uint8_t pad[6]; /* Align to 64-bits. */
876  uint64_t rx_packets; /* Number of received packets. */
877  uint64_t tx_packets; /* Number of transmitted packets. */
878  uint64_t rx_bytes; /* Number of received bytes. */
879  uint64_t tx_bytes; /* Number of transmitted bytes. */
880  uint64_t rx_dropped; /* Number of packets dropped by RX. */
881  uint64_t tx_dropped; /* Number of packets dropped by TX. */
882  uint64_t rx_errors; /* Number of receive errors. This is a super-set
883  of more specific receive errors and should be
884  greater than or equal to the sum of all
885  rx_*_err values. */
886  uint64_t tx_errors; /* Number of transmit errors. This is a super-set
887  of more specific transmit errors and should be
888  greater than or equal to the sum of all
889  tx_*_err values (none currently defined.) */
890  uint64_t rx_frame_err; /* Number of frame alignment errors. */
891  uint64_t rx_over_err; /* Number of packets with RX overrun. */
892  uint64_t rx_crc_err; /* Number of CRC errors. */
893  uint64_t collisions; /* Number of collisions. */
894  };
895  OFP_ASSERT(sizeof(struct ofp_port_stats) == 104);
896 
897  /* Body for ofp_stats_request/reply of type OFPST_EXPERIMENTER. */
899  uint32_t vendor;
900  /* Experimenter ID which takes the same form
901  as in struct ofp_vendor_header. */
902  };
903  OFP_ASSERT(sizeof(struct ofp_vendor_stats_header) == 4);
904 
905  /* Vendor extension. */
907  struct ofp_header header; /* Type OFPT_VENDOR. */
908  uint32_t vendor; /* Vendor ID:
909  * - MSB 0: low-order bytes are IEEE OUI.
910  * - MSB != 0: defined by OpenFlow
911  * consortium. */
912  /* Vendor-defined arbitrary additional data. */
913  uint8_t body[0];
914  };
915  OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);
916 
917  /* All ones is used to indicate all queues in a port (for stats retrieval). */
918  #define OFPQ_ALL 0xffffffff
919 
920  /* Min rate > 1000 means not configured. */
921  #define OFPQ_MIN_RATE_UNCFG 0xffff
922 
923  enum ofp_queue_properties {
924  OFPQT_NONE = 0, /* No property defined for queue (default). */
925  OFPQT_MIN_RATE, /* Minimum datarate guaranteed. */
926  /* Other types should be added here
927  * (i.e. max rate, precedence, etc). */
928  };
929 
930  /* Common description for a queue. */
932  uint16_t property; /* One of OFPQT_. */
933  uint16_t len; /* Length of property, including this header. */
934  uint8_t pad[4]; /* 64-bit alignemnt. */
935  };
936  OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
937 
938  /* Min-Rate queue property description. */
940  struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MIN, len: 16. */
941  uint16_t rate; /* In 1/10 of a percent; >1000 -> disabled. */
942  uint8_t pad[6]; /* 64-bit alignment */
943  };
944  OFP_ASSERT(sizeof(struct ofp_queue_prop_min_rate) == 16);
945 
946  /* Full description for a queue. */
948  uint32_t queue_id; /* id for the specific queue. */
949  uint16_t len; /* Length in bytes of this queue desc. */
950  uint8_t pad[2]; /* 64-bit alignment. */
951  struct ofp_queue_prop_header properties[0]; /* List of properties. */
952  };
953  OFP_ASSERT(sizeof(struct ofp_packet_queue) == 8);
954 
955  /* Query for port queue configuration. */
957  struct ofp_header header;
958  uint16_t port; /* Port to be queried. Should refer
959  to a valid physical port (i.e. < OFPP_MAX) */
960  uint8_t pad[2]; /* 32-bit alignment. */
961  };
962  OFP_ASSERT(sizeof(struct ofp_queue_get_config_request) == 12);
963 
964  /* Queue configuration for a given port. */
966  struct ofp_header header;
967  uint16_t port;
968  uint8_t pad[6];
969  struct ofp_packet_queue queues[0]; /* List of configured queues. */
970  };
971  OFP_ASSERT(sizeof(struct ofp_queue_get_config_reply) == 16);
972 
973  /* OFPAT_ENQUEUE action struct: send packets to given queue on port. */
975  uint16_t type; /* OFPAT_ENQUEUE. */
976  uint16_t len; /* Len is 16. */
977  uint16_t port; /* Port that queue belongs. Should
978  refer to a valid physical port
979  (i.e. < OFPP_MAX) or OFPP_IN_PORT. */
980  uint8_t pad[6]; /* Pad for 64-bit alignment. */
981  uint32_t queue_id; /* Where to enqueue the packets. */
982  };
983  OFP_ASSERT(sizeof(struct ofp_action_enqueue) == 16);
984 
986  uint16_t port_no; /* All ports if OFPT_ALL. */
987  uint8_t pad[2]; /* Align to 32-bits. */
988  uint32_t queue_id; /* All queues if OFPQ_ALL. */
989  };
990  OFP_ASSERT(sizeof(struct ofp_queue_stats_request) == 8);
991 
993  uint16_t port_no;
994  uint8_t pad[2]; /* Align to 32-bits. */
995  uint32_t queue_id; /* Queue i.d */
996  uint64_t tx_bytes; /* Number of transmitted bytes. */
997  uint64_t tx_packets; /* Number of transmitted packets. */
998  uint64_t tx_errors; /* Number of packets dropped due to overrun. */
999  };
1000  OFP_ASSERT(sizeof(struct ofp_queue_stats) == 32);
1001 
1002  /* Table numbering. Tables can use any number up to OFPT_MAX. */
1003  enum ofp_table {
1004  /* Last usable table number. */
1005  OFPTT_MAX = 0xfe,
1006  /* Fake tables. */
1007  OFPTT_ALL = 0xff
1008  /* Wildcard table used for table config,
1009  flow stats and flow deletes. */
1010  };
1011 
1012 
1013 }; // end of namespace openflow10
1014 }; // end of namespace rofl
1015 
1016 #endif /* _OPENFLOW_OPENFLOW10_H */
Definition: openflow10.h:862
Definition: openflow10.h:420
Definition: openflow10.h:873
Definition: openflow10.h:455
Definition: openflow10.h:429
Definition: openflow10.h:847
Definition: openflow10.h:974
Definition: openflow10.h:261
Definition: openflow10.h:593
Definition: openflow10.h:437
Definition: openflow10.h:300
Definition: openflow10.h:243
Definition: openflow10.h:551
Definition: openflow10.h:793
Definition: openflow10.h:624
Definition: openflow10.h:402
Definition: openflow10.h:381
Definition: openflow10.h:158
Definition: openflow10.h:73
Definition: openflow10.h:291
Definition: openflow10.h:931
Definition: openflow10.h:805
Definition: openflow10.h:985
Definition: openflow10.h:906
Definition: openflow10.h:325
Definition: openflow10.h:366
Definition: openflow10.h:61
Definition: openflow10.h:898
Definition: openflow10.h:783
Definition: openflow10.h:939
Definition: openflow10.h:947
Definition: openflow10.h:446
Definition: openflow10.h:476
Definition: openflow10.h:411
Definition: openflow10.h:992
Definition: openflow10.h:771
Definition: openflow10.h:759
Definition: openflow10.h:173