Abstract everything that uses ofp_phy_port, add OF1.1 support.
[sliver-openvswitch.git] / include / openflow / openflow-1.0.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /* OpenFlow: protocol between controller and datapath. */
18
19 #ifndef OPENFLOW_OPENFLOW10_H
20 #define OPENFLOW_OPENFLOW10_H 1
21
22 #include "openflow/openflow-common.h"
23
24 /* Port numbering.  Physical ports are numbered starting from 1. */
25 enum ofp_port {
26     /* Maximum number of physical switch ports. */
27     OFPP_MAX = 0xff00,
28
29     /* Fake output "ports". */
30     OFPP_IN_PORT    = 0xfff8,  /* Send the packet out the input port.  This
31                                   virtual port must be explicitly used
32                                   in order to send back out of the input
33                                   port. */
34     OFPP_TABLE      = 0xfff9,  /* Perform actions in flow table.
35                                   NB: This can only be the destination
36                                   port for packet-out messages. */
37     OFPP_NORMAL     = 0xfffa,  /* Process with normal L2/L3 switching. */
38     OFPP_FLOOD      = 0xfffb,  /* All physical ports except input port and
39                                   those disabled by STP. */
40     OFPP_ALL        = 0xfffc,  /* All physical ports except input port. */
41     OFPP_CONTROLLER = 0xfffd,  /* Send to controller. */
42     OFPP_LOCAL      = 0xfffe,  /* Local openflow "port". */
43     OFPP_NONE       = 0xffff   /* Not associated with a physical port. */
44 };
45
46 /* OpenFlow 1.0 specific message types, in addition to the common message
47  * types. */
48 enum ofp10_type {
49     /* Controller command messages. */
50     OFPT10_PACKET_OUT = 13,     /* Controller/switch message */
51     OFPT10_FLOW_MOD,            /* Controller/switch message */
52     OFPT10_PORT_MOD,            /* Controller/switch message */
53
54     /* Statistics messages. */
55     OFPT10_STATS_REQUEST,       /* Controller/switch message */
56     OFPT10_STATS_REPLY,         /* Controller/switch message */
57
58     /* Barrier messages. */
59     OFPT10_BARRIER_REQUEST,     /* Controller/switch message */
60     OFPT10_BARRIER_REPLY,       /* Controller/switch message */
61
62     /* Queue Configuration messages. */
63     OFPT10_QUEUE_GET_CONFIG_REQUEST,  /* Controller/switch message */
64     OFPT10_QUEUE_GET_CONFIG_REPLY     /* Controller/switch message */
65 };
66
67 /* OFPT_HELLO.  This message has an empty body, but implementations must
68  * ignore any data included in the body, to allow for future extensions. */
69 struct ofp_hello {
70     struct ofp_header header;
71 };
72
73 #define OFP_DEFAULT_MISS_SEND_LEN   128
74
75 enum ofp_config_flags {
76     /* Handling of IP fragments. */
77     OFPC_FRAG_NORMAL   = 0,  /* No special handling for fragments. */
78     OFPC_FRAG_DROP     = 1,  /* Drop fragments. */
79     OFPC_FRAG_REASM    = 2,  /* Reassemble (only if OFPC_IP_REASM set). */
80     OFPC_FRAG_NX_MATCH = 3,  /* Make first fragments available for matching. */
81     OFPC_FRAG_MASK     = 3,
82
83     /* TTL processing - applicable for IP and MPLS packets. */
84     OFPC_INVALID_TTL_TO_CONTROLLER = 1 << 2, /* Send packets with invalid TTL
85                                                 to the controller. */
86 };
87
88 /* Switch configuration. */
89 struct ofp_switch_config {
90     struct ofp_header header;
91     ovs_be16 flags;             /* OFPC_* flags. */
92     ovs_be16 miss_send_len;     /* Max bytes of new flow that datapath should
93                                    send to the controller. */
94 };
95 OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
96
97 /* OpenFlow 1.0 specific capabilities supported by the datapath (struct
98  * ofp_switch_features, member capabilities). */
99 enum ofp10_capabilities {
100     OFPC10_STP            = 1 << 3,  /* 802.1d spanning tree. */
101     OFPC10_RESERVED       = 1 << 4,  /* Reserved, must not be set. */
102 };
103
104 /* OpenFlow 1.0 specific flags to indicate behavior of the physical port.
105  * These flags are used in ofp10_phy_port to describe the current
106  * configuration.  They are used in the ofp10_port_mod message to configure the
107  * port's behavior.
108  */
109 enum ofp10_port_config {
110     OFPPC10_NO_STP       = 1 << 1, /* Disable 802.1D spanning tree on port. */
111     OFPPC10_NO_RECV_STP  = 1 << 3, /* Drop received 802.1D STP packets. */
112     OFPPC10_NO_FLOOD     = 1 << 4, /* Do not include port when flooding. */
113 #define OFPPC10_ALL (OFPPC_PORT_DOWN | OFPPC10_NO_STP | OFPPC_NO_RECV | \
114                      OFPPC10_NO_RECV_STP | OFPPC10_NO_FLOOD | OFPPC_NO_FWD | \
115                      OFPPC_NO_PACKET_IN)
116 };
117
118 /* OpenFlow 1.0 specific current state of the physical port.  These are not
119  * configurable from the controller.
120  */
121 enum ofp10_port_state {
122     /* The OFPPS10_STP_* bits have no effect on switch operation.  The
123      * controller must adjust OFPPC_NO_RECV, OFPPC_NO_FWD, and
124      * OFPPC_NO_PACKET_IN appropriately to fully implement an 802.1D spanning
125      * tree. */
126     OFPPS10_STP_LISTEN  = 0 << 8, /* Not learning or relaying frames. */
127     OFPPS10_STP_LEARN   = 1 << 8, /* Learning but not relaying frames. */
128     OFPPS10_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
129     OFPPS10_STP_BLOCK   = 3 << 8, /* Not part of spanning tree. */
130     OFPPS10_STP_MASK    = 3 << 8  /* Bit mask for OFPPS10_STP_* values. */
131
132 #define OFPPS10_ALL (OFPPS_LINK_DOWN | OFPPS10_STP_MASK)
133 };
134
135 /* OpenFlow 1.0 specific features of physical ports available in a datapath. */
136 enum ofp10_port_features {
137     OFPPF10_COPPER     = 1 << 7,  /* Copper medium. */
138     OFPPF10_FIBER      = 1 << 8,  /* Fiber medium. */
139     OFPPF10_AUTONEG    = 1 << 9,  /* Auto-negotiation. */
140     OFPPF10_PAUSE      = 1 << 10, /* Pause. */
141     OFPPF10_PAUSE_ASYM = 1 << 11  /* Asymmetric pause. */
142 };
143
144 /* Description of a physical port */
145 struct ofp10_phy_port {
146     ovs_be16 port_no;
147     uint8_t hw_addr[OFP_ETH_ALEN];
148     char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
149
150     ovs_be32 config;        /* Bitmap of OFPPC_* and OFPPC10_* flags. */
151     ovs_be32 state;         /* Bitmap of OFPPS_* and OFPPS10_* flags. */
152
153     /* Bitmaps of OFPPF_* and OFPPF10_* that describe features.  All bits
154      * zeroed if unsupported or unavailable. */
155     ovs_be32 curr;          /* Current features. */
156     ovs_be32 advertised;    /* Features being advertised by the port. */
157     ovs_be32 supported;     /* Features supported by the port. */
158     ovs_be32 peer;          /* Features advertised by peer. */
159 };
160 OFP_ASSERT(sizeof(struct ofp10_phy_port) == 48);
161
162 /* Modify behavior of the physical port */
163 struct ofp10_port_mod {
164     struct ofp_header header;
165     ovs_be16 port_no;
166     uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
167                                       configurable.  This is used to
168                                       sanity-check the request, so it must
169                                       be the same as returned in an
170                                       ofp10_phy_port struct. */
171
172     ovs_be32 config;        /* Bitmap of OFPPC_* flags. */
173     ovs_be32 mask;          /* Bitmap of OFPPC_* flags to be changed. */
174
175     ovs_be32 advertise;     /* Bitmap of "ofp_port_features"s.  Zero all
176                                bits to prevent any action taking place. */
177     uint8_t pad[4];         /* Pad to 64-bits. */
178 };
179 OFP_ASSERT(sizeof(struct ofp10_port_mod) == 32);
180
181 /* Why is this packet being sent to the controller? */
182 enum ofp_packet_in_reason {
183     OFPR_NO_MATCH,          /* No matching flow. */
184     OFPR_ACTION,            /* Action explicitly output to controller. */
185     OFPR_INVALID_TTL        /* Packet has invalid TTL. */,
186     OFPR_N_REASONS
187 };
188
189 /* Packet received on port (datapath -> controller). */
190 struct ofp_packet_in {
191     struct ofp_header header;
192     ovs_be32 buffer_id;     /* ID assigned by datapath. */
193     ovs_be16 total_len;     /* Full length of frame. */
194     ovs_be16 in_port;       /* Port on which frame was received. */
195     uint8_t reason;         /* Reason packet is being sent (one of OFPR_*) */
196     uint8_t pad;
197     uint8_t data[0];        /* Ethernet frame, halfway through 32-bit word,
198                                so the IP header is 32-bit aligned.  The
199                                amount of data is inferred from the length
200                                field in the header.  Because of padding,
201                                offsetof(struct ofp_packet_in, data) ==
202                                sizeof(struct ofp_packet_in) - 2. */
203 };
204 OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
205
206 enum ofp10_action_type {
207     OFPAT10_OUTPUT,             /* Output to switch port. */
208     OFPAT10_SET_VLAN_VID,       /* Set the 802.1q VLAN id. */
209     OFPAT10_SET_VLAN_PCP,       /* Set the 802.1q priority. */
210     OFPAT10_STRIP_VLAN,         /* Strip the 802.1q header. */
211     OFPAT10_SET_DL_SRC,         /* Ethernet source address. */
212     OFPAT10_SET_DL_DST,         /* Ethernet destination address. */
213     OFPAT10_SET_NW_SRC,         /* IP source address. */
214     OFPAT10_SET_NW_DST,         /* IP destination address. */
215     OFPAT10_SET_NW_TOS,         /* IP ToS (DSCP field, 6 bits). */
216     OFPAT10_SET_TP_SRC,         /* TCP/UDP source port. */
217     OFPAT10_SET_TP_DST,         /* TCP/UDP destination port. */
218     OFPAT10_ENQUEUE,            /* Output to queue. */
219     OFPAT10_VENDOR = 0xffff
220 };
221
222 /* Action structure for OFPAT10_OUTPUT, which sends packets out 'port'.
223  * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
224  * number of bytes to send.  A 'max_len' of zero means no bytes of the
225  * packet should be sent. */
226 struct ofp_action_output {
227     ovs_be16 type;                  /* OFPAT10_OUTPUT. */
228     ovs_be16 len;                   /* Length is 8. */
229     ovs_be16 port;                  /* Output port. */
230     ovs_be16 max_len;               /* Max length to send to controller. */
231 };
232 OFP_ASSERT(sizeof(struct ofp_action_output) == 8);
233
234 /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
235  * special conditions.  All ones is used to match that no VLAN id was
236  * set. */
237 #define OFP_VLAN_NONE      0xffff
238
239 /* Action structure for OFPAT10_SET_VLAN_VID. */
240 struct ofp_action_vlan_vid {
241     ovs_be16 type;                  /* OFPAT10_SET_VLAN_VID. */
242     ovs_be16 len;                   /* Length is 8. */
243     ovs_be16 vlan_vid;              /* VLAN id. */
244     uint8_t pad[2];
245 };
246 OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);
247
248 /* Action structure for OFPAT10_SET_VLAN_PCP. */
249 struct ofp_action_vlan_pcp {
250     ovs_be16 type;                  /* OFPAT10_SET_VLAN_PCP. */
251     ovs_be16 len;                   /* Length is 8. */
252     uint8_t vlan_pcp;               /* VLAN priority. */
253     uint8_t pad[3];
254 };
255 OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);
256
257 /* Action structure for OFPAT10_SET_DL_SRC/DST. */
258 struct ofp_action_dl_addr {
259     ovs_be16 type;                  /* OFPAT10_SET_DL_SRC/DST. */
260     ovs_be16 len;                   /* Length is 16. */
261     uint8_t dl_addr[OFP_ETH_ALEN];  /* Ethernet address. */
262     uint8_t pad[6];
263 };
264 OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
265
266 /* Action structure for OFPAT10_SET_NW_SRC/DST. */
267 struct ofp_action_nw_addr {
268     ovs_be16 type;                  /* OFPAT10_SET_TW_SRC/DST. */
269     ovs_be16 len;                   /* Length is 8. */
270     ovs_be32 nw_addr;               /* IP address. */
271 };
272 OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);
273
274 /* Action structure for OFPAT10_SET_NW_TOS. */
275 struct ofp_action_nw_tos {
276     ovs_be16 type;                  /* OFPAT10_SET_TW_TOS. */
277     ovs_be16 len;                   /* Length is 8. */
278     uint8_t nw_tos;                 /* IP TOS (DSCP field, 6 bits). */
279     uint8_t pad[3];
280 };
281 OFP_ASSERT(sizeof(struct ofp_action_nw_tos) == 8);
282
283 /* Action structure for OFPAT10_SET_TP_SRC/DST. */
284 struct ofp_action_tp_port {
285     ovs_be16 type;                  /* OFPAT10_SET_TP_SRC/DST. */
286     ovs_be16 len;                   /* Length is 8. */
287     ovs_be16 tp_port;               /* TCP/UDP port. */
288     uint8_t pad[2];
289 };
290 OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);
291
292 /* Action header for OFPAT10_VENDOR. The rest of the body is vendor-defined. */
293 struct ofp_action_vendor_header {
294     ovs_be16 type;                  /* OFPAT10_VENDOR. */
295     ovs_be16 len;                   /* Length is a multiple of 8. */
296     ovs_be32 vendor;                /* Vendor ID, which takes the same form
297                                        as in "struct ofp_vendor_header". */
298 };
299 OFP_ASSERT(sizeof(struct ofp_action_vendor_header) == 8);
300
301 /* Action header that is common to all actions.  The length includes the
302  * header and any padding used to make the action 64-bit aligned.
303  * NB: The length of an action *must* always be a multiple of eight. */
304 struct ofp_action_header {
305     ovs_be16 type;                  /* One of OFPAT10_*. */
306     ovs_be16 len;                   /* Length of action, including this
307                                        header.  This is the length of action,
308                                        including any padding to make it
309                                        64-bit aligned. */
310     uint8_t pad[4];
311 };
312 OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
313
314 /* OFPAT10_ENQUEUE action struct: send packets to given queue on port. */
315 struct ofp_action_enqueue {
316     ovs_be16 type;            /* OFPAT10_ENQUEUE. */
317     ovs_be16 len;             /* Len is 16. */
318     ovs_be16 port;            /* Port that queue belongs. Should
319                                  refer to a valid physical port
320                                  (i.e. < OFPP_MAX) or OFPP_IN_PORT. */
321     uint8_t pad[6];           /* Pad for 64-bit alignment. */
322     ovs_be32 queue_id;        /* Where to enqueue the packets. */
323 };
324 OFP_ASSERT(sizeof(struct ofp_action_enqueue) == 16);
325
326 union ofp_action {
327     ovs_be16 type;
328     struct ofp_action_header header;
329     struct ofp_action_vendor_header vendor;
330     struct ofp_action_output output;
331     struct ofp_action_vlan_vid vlan_vid;
332     struct ofp_action_vlan_pcp vlan_pcp;
333     struct ofp_action_nw_addr nw_addr;
334     struct ofp_action_nw_tos nw_tos;
335     struct ofp_action_tp_port tp_port;
336 };
337 OFP_ASSERT(sizeof(union ofp_action) == 8);
338
339 /* Send packet (controller -> datapath). */
340 struct ofp_packet_out {
341     struct ofp_header header;
342     ovs_be32 buffer_id;           /* ID assigned by datapath or UINT32_MAX. */
343     ovs_be16 in_port;             /* Packet's input port (OFPP_NONE if none). */
344     ovs_be16 actions_len;         /* Size of action array in bytes. */
345     /* Followed by:
346      *   - Exactly 'actions_len' bytes (possibly 0 bytes, and always a multiple
347      *     of 8) containing actions.
348      *   - If 'buffer_id' == UINT32_MAX, packet data to fill out the remainder
349      *     of the message length.
350      */
351 };
352 OFP_ASSERT(sizeof(struct ofp_packet_out) == 16);
353
354 enum ofp_flow_mod_command {
355     OFPFC_ADD,              /* New flow. */
356     OFPFC_MODIFY,           /* Modify all matching flows. */
357     OFPFC_MODIFY_STRICT,    /* Modify entry strictly matching wildcards */
358     OFPFC_DELETE,           /* Delete all matching flows. */
359     OFPFC_DELETE_STRICT     /* Strictly match wildcards and priority. */
360 };
361
362 /* Flow wildcards. */
363 enum ofp_flow_wildcards {
364     OFPFW_IN_PORT    = 1 << 0,  /* Switch input port. */
365     OFPFW_DL_VLAN    = 1 << 1,  /* VLAN vid. */
366     OFPFW_DL_SRC     = 1 << 2,  /* Ethernet source address. */
367     OFPFW_DL_DST     = 1 << 3,  /* Ethernet destination address. */
368     OFPFW_DL_TYPE    = 1 << 4,  /* Ethernet frame type. */
369     OFPFW_NW_PROTO   = 1 << 5,  /* IP protocol. */
370     OFPFW_TP_SRC     = 1 << 6,  /* TCP/UDP source port. */
371     OFPFW_TP_DST     = 1 << 7,  /* TCP/UDP destination port. */
372
373     /* IP source address wildcard bit count.  0 is exact match, 1 ignores the
374      * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
375      * the entire field.  This is the *opposite* of the usual convention where
376      * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded. */
377     OFPFW_NW_SRC_SHIFT = 8,
378     OFPFW_NW_SRC_BITS = 6,
379     OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT,
380     OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT,
381
382     /* IP destination address wildcard bit count.  Same format as source. */
383     OFPFW_NW_DST_SHIFT = 14,
384     OFPFW_NW_DST_BITS = 6,
385     OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT,
386     OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT,
387
388     OFPFW_DL_VLAN_PCP = 1 << 20, /* VLAN priority. */
389     OFPFW_NW_TOS = 1 << 21, /* IP ToS (DSCP field, 6 bits). */
390
391     /* Wildcard all fields. */
392     OFPFW_ALL = ((1 << 22) - 1)
393 };
394
395 /* The wildcards for ICMP type and code fields use the transport source
396  * and destination port fields, respectively. */
397 #define OFPFW_ICMP_TYPE OFPFW_TP_SRC
398 #define OFPFW_ICMP_CODE OFPFW_TP_DST
399
400 /* Values below this cutoff are 802.3 packets and the two bytes
401  * following MAC addresses are used as a frame length.  Otherwise, the
402  * two bytes are used as the Ethernet type.
403  */
404 #define OFP_DL_TYPE_ETH2_CUTOFF   0x0600
405
406 /* Value of dl_type to indicate that the frame does not include an
407  * Ethernet type.
408  */
409 #define OFP_DL_TYPE_NOT_ETH_TYPE  0x05ff
410
411 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
412  * special conditions.  All ones indicates that no VLAN id was set.
413  */
414 #define OFP_VLAN_NONE      0xffff
415
416 /* Fields to match against flows */
417 struct ofp_match {
418     ovs_be32 wildcards;        /* Wildcard fields. */
419     ovs_be16 in_port;          /* Input switch port. */
420     uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
421     uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
422     ovs_be16 dl_vlan;          /* Input VLAN. */
423     uint8_t dl_vlan_pcp;       /* Input VLAN priority. */
424     uint8_t pad1[1];           /* Align to 64-bits. */
425     ovs_be16 dl_type;          /* Ethernet frame type. */
426     uint8_t nw_tos;            /* IP ToS (DSCP field, 6 bits). */
427     uint8_t nw_proto;          /* IP protocol or lower 8 bits of
428                                   ARP opcode. */
429     uint8_t pad2[2];           /* Align to 64-bits. */
430     ovs_be32 nw_src;           /* IP source address. */
431     ovs_be32 nw_dst;           /* IP destination address. */
432     ovs_be16 tp_src;           /* TCP/UDP source port. */
433     ovs_be16 tp_dst;           /* TCP/UDP destination port. */
434 };
435 OFP_ASSERT(sizeof(struct ofp_match) == 40);
436
437 /* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
438  * is permanent. */
439 #define OFP_FLOW_PERMANENT 0
440
441 /* By default, choose a priority in the middle. */
442 #define OFP_DEFAULT_PRIORITY 0x8000
443
444 enum ofp_flow_mod_flags {
445     OFPFF_SEND_FLOW_REM = 1 << 0,  /* Send flow removed message when flow
446                                     * expires or is deleted. */
447     OFPFF_CHECK_OVERLAP = 1 << 1,  /* Check for overlapping entries first. */
448     OFPFF_EMERG         = 1 << 2   /* Ramark this is for emergency. */
449 };
450
451 /* Flow setup and teardown (controller -> datapath). */
452 struct ofp_flow_mod {
453     struct ofp_header header;
454     struct ofp_match match;      /* Fields to match */
455     ovs_be64 cookie;             /* Opaque controller-issued identifier. */
456
457     /* Flow actions. */
458     ovs_be16 command;             /* One of OFPFC_*. */
459     ovs_be16 idle_timeout;        /* Idle time before discarding (seconds). */
460     ovs_be16 hard_timeout;        /* Max time before discarding (seconds). */
461     ovs_be16 priority;            /* Priority level of flow entry. */
462     ovs_be32 buffer_id;           /* Buffered packet to apply to (or -1).
463                                      Not meaningful for OFPFC_DELETE*. */
464     ovs_be16 out_port;            /* For OFPFC_DELETE* commands, require
465                                      matching entries to include this as an
466                                      output port.  A value of OFPP_NONE
467                                      indicates no restriction. */
468     ovs_be16 flags;               /* One of OFPFF_*. */
469     struct ofp_action_header actions[0]; /* The action length is inferred
470                                             from the length field in the
471                                             header. */
472 };
473 OFP_ASSERT(sizeof(struct ofp_flow_mod) == 72);
474
475 /* Why was this flow removed? */
476 enum ofp_flow_removed_reason {
477     OFPRR_IDLE_TIMEOUT,         /* Flow idle time exceeded idle_timeout. */
478     OFPRR_HARD_TIMEOUT,         /* Time exceeded hard_timeout. */
479     OFPRR_DELETE                /* Evicted by a DELETE flow mod. */
480 };
481
482 /* Flow removed (datapath -> controller). */
483 struct ofp_flow_removed {
484     struct ofp_header header;
485     struct ofp_match match;   /* Description of fields. */
486     ovs_be64 cookie;          /* Opaque controller-issued identifier. */
487
488     ovs_be16 priority;        /* Priority level of flow entry. */
489     uint8_t reason;           /* One of OFPRR_*. */
490     uint8_t pad[1];           /* Align to 32-bits. */
491
492     ovs_be32 duration_sec;    /* Time flow was alive in seconds. */
493     ovs_be32 duration_nsec;   /* Time flow was alive in nanoseconds beyond
494                                  duration_sec. */
495     ovs_be16 idle_timeout;    /* Idle timeout from original flow mod. */
496     uint8_t pad2[2];          /* Align to 64-bits. */
497     ovs_be64 packet_count;
498     ovs_be64 byte_count;
499 };
500 OFP_ASSERT(sizeof(struct ofp_flow_removed) == 88);
501
502 /* OFPT_ERROR: Error message (datapath -> controller). */
503 struct ofp_error_msg {
504     struct ofp_header header;
505
506     ovs_be16 type;
507     ovs_be16 code;
508     uint8_t data[0];          /* Variable-length data.  Interpreted based
509                                  on the type and code. */
510 };
511 OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);
512
513 enum ofp_stats_types {
514     /* Description of this OpenFlow switch.
515      * The request is struct ofp_stats_msg.
516      * The reply is struct ofp_desc_stats. */
517     OFPST_DESC,
518
519     /* Individual flow statistics.
520      * The request is struct ofp_flow_stats_request.
521      * The reply body is an array of struct ofp_flow_stats. */
522     OFPST_FLOW,
523
524     /* Aggregate flow statistics.
525      * The request is struct ofp_flow_stats_request.
526      * The reply is struct ofp_aggregate_stats_reply. */
527     OFPST_AGGREGATE,
528
529     /* Flow table statistics.
530      * The request is struct ofp_stats_msg.
531      * The reply body is an array of struct ofp_table_stats. */
532     OFPST_TABLE,
533
534     /* Physical port statistics.
535      * The request is struct ofp_port_stats_request.
536      * The reply body is an array of struct ofp_port_stats. */
537     OFPST_PORT,
538
539     /* Queue statistics for a port.
540      * The request body is struct ofp_queue_stats_request.
541      * The reply body is an array of struct ofp_queue_stats. */
542     OFPST_QUEUE,
543
544     /* Vendor extension.
545      * The request and reply begin with "struct ofp_vendor_stats". */
546     OFPST_VENDOR = 0xffff
547 };
548
549 /* Statistics request or reply message. */
550 struct ofp_stats_msg {
551     struct ofp_header header;
552     ovs_be16 type;              /* One of the OFPST_* constants. */
553     ovs_be16 flags;             /* Requests: always 0.
554                                  * Replies: 0 or OFPSF_REPLY_MORE. */
555 };
556 OFP_ASSERT(sizeof(struct ofp_stats_msg) == 12);
557
558 enum ofp_stats_reply_flags {
559     OFPSF_REPLY_MORE  = 1 << 0  /* More replies to follow. */
560 };
561
562 #define DESC_STR_LEN   256
563 #define SERIAL_NUM_LEN 32
564 /* Reply to OFPST_DESC request.  Each entry is a NULL-terminated ASCII
565  * string. */
566 struct ofp_desc_stats {
567     struct ofp_stats_msg osm;
568     char mfr_desc[DESC_STR_LEN];       /* Manufacturer description. */
569     char hw_desc[DESC_STR_LEN];        /* Hardware description. */
570     char sw_desc[DESC_STR_LEN];        /* Software description. */
571     char serial_num[SERIAL_NUM_LEN];   /* Serial number. */
572     char dp_desc[DESC_STR_LEN];        /* Human readable description of
573                                           the datapath. */
574 };
575 OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1068);
576
577 /* Stats request of type OFPST_AGGREGATE or OFPST_FLOW. */
578 struct ofp_flow_stats_request {
579     struct ofp_stats_msg osm;
580     struct ofp_match match;   /* Fields to match. */
581     uint8_t table_id;         /* ID of table to read (from ofp_table_stats)
582                                  or 0xff for all tables. */
583     uint8_t pad;              /* Align to 32 bits. */
584     ovs_be16 out_port;        /* Require matching entries to include this
585                                  as an output port.  A value of OFPP_NONE
586                                  indicates no restriction. */
587 };
588 OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 56);
589
590 /* Body of reply to OFPST_FLOW request. */
591 struct ofp_flow_stats {
592     ovs_be16 length;          /* Length of this entry. */
593     uint8_t table_id;         /* ID of table flow came from. */
594     uint8_t pad;
595     struct ofp_match match;   /* Description of fields. */
596     ovs_be32 duration_sec;    /* Time flow has been alive in seconds. */
597     ovs_be32 duration_nsec;   /* Time flow has been alive in nanoseconds
598                                  beyond duration_sec. */
599     ovs_be16 priority;        /* Priority of the entry. Only meaningful
600                                  when this is not an exact-match entry. */
601     ovs_be16 idle_timeout;    /* Number of seconds idle before expiration. */
602     ovs_be16 hard_timeout;    /* Number of seconds before expiration. */
603     uint8_t pad2[6];          /* Align to 64 bits. */
604     ovs_32aligned_be64 cookie;       /* Opaque controller-issued identifier. */
605     ovs_32aligned_be64 packet_count; /* Number of packets in flow. */
606     ovs_32aligned_be64 byte_count;   /* Number of bytes in flow. */
607     struct ofp_action_header actions[0]; /* Actions. */
608 };
609 OFP_ASSERT(sizeof(struct ofp_flow_stats) == 88);
610
611 /* Reply to OFPST_AGGREGATE request. */
612 struct ofp_aggregate_stats_reply {
613     struct ofp_stats_msg osm;
614     ovs_32aligned_be64 packet_count; /* Number of packets in flows. */
615     ovs_32aligned_be64 byte_count;   /* Number of bytes in flows. */
616     ovs_be32 flow_count;      /* Number of flows. */
617     uint8_t pad[4];           /* Align to 64 bits. */
618 };
619 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 36);
620
621 /* Body of reply to OFPST_TABLE request. */
622 struct ofp_table_stats {
623     uint8_t table_id;        /* Identifier of table.  Lower numbered tables
624                                 are consulted first. */
625     uint8_t pad[3];          /* Align to 32-bits. */
626     char name[OFP_MAX_TABLE_NAME_LEN];
627     ovs_be32 wildcards;      /* Bitmap of OFPFW_* wildcards that are
628                                 supported by the table. */
629     ovs_be32 max_entries;    /* Max number of entries supported. */
630     ovs_be32 active_count;   /* Number of active entries. */
631     ovs_32aligned_be64 lookup_count;  /* # of packets looked up in table. */
632     ovs_32aligned_be64 matched_count; /* Number of packets that hit table. */
633 };
634 OFP_ASSERT(sizeof(struct ofp_table_stats) == 64);
635
636 /* Stats request of type OFPST_PORT. */
637 struct ofp_port_stats_request {
638     struct ofp_stats_msg osm;
639     ovs_be16 port_no;        /* OFPST_PORT message may request statistics
640                                 for a single port (specified with port_no)
641                                 or for all ports (port_no == OFPP_NONE). */
642     uint8_t pad[6];
643 };
644 OFP_ASSERT(sizeof(struct ofp_port_stats_request) == 20);
645
646 /* Body of reply to OFPST_PORT request. If a counter is unsupported, set
647  * the field to all ones. */
648 struct ofp_port_stats {
649     ovs_be16 port_no;
650     uint8_t pad[6];          /* Align to 64-bits. */
651     ovs_32aligned_be64 rx_packets;     /* Number of received packets. */
652     ovs_32aligned_be64 tx_packets;     /* Number of transmitted packets. */
653     ovs_32aligned_be64 rx_bytes;       /* Number of received bytes. */
654     ovs_32aligned_be64 tx_bytes;       /* Number of transmitted bytes. */
655     ovs_32aligned_be64 rx_dropped;     /* Number of packets dropped by RX. */
656     ovs_32aligned_be64 tx_dropped;     /* Number of packets dropped by TX. */
657     ovs_32aligned_be64 rx_errors; /* Number of receive errors.  This is a
658                                      super-set of receive errors and should be
659                                      great than or equal to the sum of all
660                                      rx_*_err values. */
661     ovs_32aligned_be64 tx_errors; /* Number of transmit errors.  This is a
662                                      super-set of transmit errors. */
663     ovs_32aligned_be64 rx_frame_err; /* Number of frame alignment errors. */
664     ovs_32aligned_be64 rx_over_err;  /* Number of packets with RX overrun. */
665     ovs_32aligned_be64 rx_crc_err;   /* Number of CRC errors. */
666     ovs_32aligned_be64 collisions;   /* Number of collisions. */
667 };
668 OFP_ASSERT(sizeof(struct ofp_port_stats) == 104);
669
670 /* All ones is used to indicate all queues in a port (for stats retrieval). */
671 #define OFPQ_ALL      0xffffffff
672
673 /* Body for stats request of type OFPST_QUEUE. */
674 struct ofp_queue_stats_request {
675     struct ofp_stats_msg osm;
676     ovs_be16 port_no;        /* All ports if OFPP_ALL. */
677     uint8_t pad[2];          /* Align to 32-bits. */
678     ovs_be32 queue_id;       /* All queues if OFPQ_ALL. */
679 };
680 OFP_ASSERT(sizeof(struct ofp_queue_stats_request) == 20);
681
682 /* Body for stats reply of type OFPST_QUEUE consists of an array of this
683  * structure type. */
684 struct ofp_queue_stats {
685     ovs_be16 port_no;
686     uint8_t pad[2];          /* Align to 32-bits. */
687     ovs_be32 queue_id;       /* Queue id. */
688     ovs_32aligned_be64 tx_bytes;   /* Number of transmitted bytes. */
689     ovs_32aligned_be64 tx_packets; /* Number of transmitted packets. */
690     ovs_32aligned_be64 tx_errors;  /* # of packets dropped due to overrun. */
691 };
692 OFP_ASSERT(sizeof(struct ofp_queue_stats) == 32);
693
694 /* Vendor extension stats message. */
695 struct ofp_vendor_stats_msg {
696     struct ofp_stats_msg osm;   /* Type OFPST_VENDOR. */
697     ovs_be32 vendor;            /* Vendor ID:
698                                  * - MSB 0: low-order bytes are IEEE OUI.
699                                  * - MSB != 0: defined by OpenFlow
700                                  *   consortium. */
701     /* Followed by vendor-defined arbitrary additional data. */
702 };
703 OFP_ASSERT(sizeof(struct ofp_vendor_stats_msg) == 16);
704
705 /* Vendor extension. */
706 struct ofp_vendor_header {
707     struct ofp_header header;   /* Type OFPT_VENDOR. */
708     ovs_be32 vendor;            /* Vendor ID:
709                                  * - MSB 0: low-order bytes are IEEE OUI.
710                                  * - MSB != 0: defined by OpenFlow
711                                  *   consortium. */
712     /* Vendor-defined arbitrary additional data. */
713 };
714 OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);
715
716 #endif /* openflow/openflow-1.0.h */