ofp-util: Work on decoding OF1.1 flow_mods.
[openvswitch] / include / openflow / openflow-1.1.h
1 /* Copyright (c) 2008, 2011, 2012 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 /*
35  * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
36  *
37  * Licensed under the Apache License, Version 2.0 (the "License");
38  * you may not use this file except in compliance with the License.
39  * You may obtain a copy of the License at:
40  *
41  *     http://www.apache.org/licenses/LICENSE-2.0
42  *
43  * Unless required by applicable law or agreed to in writing, software
44  * distributed under the License is distributed on an "AS IS" BASIS,
45  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46  * See the License for the specific language governing permissions and
47  * limitations under the License.
48  */
49
50 /* OpenFlow: protocol between controller and datapath. */
51
52 #ifndef OPENFLOW_11_H
53 #define OPENFLOW_11_H 1
54
55 #include "openflow/openflow-common.h"
56
57 /* OpenFlow 1.1 uses 32-bit port numbers.  Open vSwitch, for now, uses OpenFlow
58  * 1.0 port numbers internally.  We map them to OpenFlow 1.0 as follows:
59  *
60  * OF1.1                    <=>  OF1.0
61  * -----------------------       ---------------
62  * 0x00000000...0x0000feff  <=>  0x0000...0xfeff  "physical" ports
63  * 0x0000ff00...0xfffffeff  <=>  not supported
64  * 0xffffff00...0xffffffff  <=>  0xff00...0xffff  "reserved" OFPP_* ports
65  *
66  * OFPP11_OFFSET is the value that must be added or subtracted to convert
67  * an OpenFlow 1.0 reserved port number to or from, respectively, the
68  * corresponding OpenFlow 1.1 reserved port number.
69  */
70 #define OFPP11_MAX    0xffffff00
71 #define OFPP11_OFFSET (OFPP11_MAX - OFPP_MAX)
72
73 /* OpenFlow 1.1 port config flags are just the common flags. */
74 #define OFPPC11_ALL \
75     (OFPPC_PORT_DOWN | OFPPC_NO_RECV | OFPPC_NO_FWD | OFPPC_NO_PACKET_IN)
76
77 /* OpenFlow 1.1 specific current state of the physical port.  These are not
78  * configurable from the controller.
79  */
80 enum ofp11_port_state {
81     OFPPS11_BLOCKED      = 1 << 1,  /* Port is blocked */
82     OFPPS11_LIVE         = 1 << 2,  /* Live for Fast Failover Group. */
83 #define OFPPS11_ALL (OFPPS_LINK_DOWN | OFPPS11_BLOCKED | OFPPS11_LIVE)
84 };
85
86 /* OpenFlow 1.1 specific features of ports available in a datapath. */
87 enum ofp11_port_features {
88     OFPPF11_40GB_FD    = 1 << 7,  /* 40 Gb full-duplex rate support. */
89     OFPPF11_100GB_FD   = 1 << 8,  /* 100 Gb full-duplex rate support. */
90     OFPPF11_1TB_FD     = 1 << 9,  /* 1 Tb full-duplex rate support. */
91     OFPPF11_OTHER      = 1 << 10, /* Other rate, not in the list. */
92
93     OFPPF11_COPPER     = 1 << 11, /* Copper medium. */
94     OFPPF11_FIBER      = 1 << 12, /* Fiber medium. */
95     OFPPF11_AUTONEG    = 1 << 13, /* Auto-negotiation. */
96     OFPPF11_PAUSE      = 1 << 14, /* Pause. */
97     OFPPF11_PAUSE_ASYM = 1 << 15  /* Asymmetric pause. */
98 #define OFPPF11_ALL ((1 << 16) - 1)
99 };
100
101 /* Description of a port */
102 struct ofp11_port {
103     ovs_be32 port_no;
104     uint8_t pad[4];
105     uint8_t hw_addr[OFP_ETH_ALEN];
106     uint8_t pad2[2];                  /* Align to 64 bits. */
107     char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
108
109     ovs_be32 config;        /* Bitmap of OFPPC_* flags. */
110     ovs_be32 state;         /* Bitmap of OFPPS_* and OFPPS11_* flags. */
111
112     /* Bitmaps of OFPPF_* and OFPPF11_* that describe features.  All bits
113      * zeroed if unsupported or unavailable. */
114     ovs_be32 curr;          /* Current features. */
115     ovs_be32 advertised;    /* Features being advertised by the port. */
116     ovs_be32 supported;     /* Features supported by the port. */
117     ovs_be32 peer;          /* Features advertised by peer. */
118
119     ovs_be32 curr_speed;    /* Current port bitrate in kbps. */
120     ovs_be32 max_speed;     /* Max port bitrate in kbps */
121 };
122
123 /* Modify behavior of the physical port */
124 struct ofp11_port_mod {
125     ovs_be32 port_no;
126     uint8_t pad[4];
127     uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
128                                       configurable.  This is used to
129                                       sanity-check the request, so it must
130                                       be the same as returned in an
131                                       ofp11_port struct. */
132     uint8_t pad2[2];        /* Pad to 64 bits. */
133     ovs_be32 config;        /* Bitmap of OFPPC_* flags. */
134     ovs_be32 mask;          /* Bitmap of OFPPC_* flags to be changed. */
135
136     ovs_be32 advertise;     /* Bitmap of OFPPF_* and OFPPF11_*.  Zero all bits
137                                to prevent any action taking place. */
138     uint8_t pad3[4];        /* Pad to 64 bits. */
139 };
140 OFP_ASSERT(sizeof(struct ofp11_port_mod) == 32);
141
142 /* Group setup and teardown (controller -> datapath). */
143 struct ofp11_group_mod {
144     ovs_be16 command;             /* One of OFPGC_*. */
145     uint8_t type;                 /* One of OFPGT_*. */
146     uint8_t pad;                  /* Pad to 64 bits. */
147     ovs_be32 group_id;            /* Group identifier. */
148     /* struct ofp11_bucket buckets[0]; The bucket length is inferred from the
149                                        length field in the header. */
150 };
151 OFP_ASSERT(sizeof(struct ofp11_group_mod) == 8);
152
153 /* Query for port queue configuration. */
154 struct ofp11_queue_get_config_request {
155     ovs_be32 port;
156     /* Port to be queried. Should refer
157        to a valid physical port (i.e. < OFPP_MAX) */
158     uint8_t pad[4];
159 };
160 OFP_ASSERT(sizeof(struct ofp11_queue_get_config_request) == 8);
161
162 /* Group commands */
163 enum ofp11_group_mod_command {
164     OFPGC11_ADD,          /* New group. */
165     OFPGC11_MODIFY,       /* Modify all matching groups. */
166     OFPGC11_DELETE,       /* Delete all matching groups. */
167 };
168
169 /* OpenFlow 1.1 specific capabilities supported by the datapath (struct
170  * ofp_switch_features, member capabilities). */
171 enum ofp11_capabilities {
172     OFPC11_GROUP_STATS    = 1 << 3,  /* Group statistics. */
173 };
174
175 enum ofp11_action_type {
176     OFPAT11_OUTPUT,           /* Output to switch port. */
177     OFPAT11_SET_VLAN_VID,     /* Set the 802.1q VLAN id. */
178     OFPAT11_SET_VLAN_PCP,     /* Set the 802.1q priority. */
179     OFPAT11_SET_DL_SRC,       /* Ethernet source address. */
180     OFPAT11_SET_DL_DST,       /* Ethernet destination address. */
181     OFPAT11_SET_NW_SRC,       /* IP source address. */
182     OFPAT11_SET_NW_DST,       /* IP destination address. */
183     OFPAT11_SET_NW_TOS,       /* IP ToS (DSCP field, 6 bits). */
184     OFPAT11_SET_NW_ECN,       /* IP ECN (2 bits). */
185     OFPAT11_SET_TP_SRC,       /* TCP/UDP/SCTP source port. */
186     OFPAT11_SET_TP_DST,       /* TCP/UDP/SCTP destination port. */
187     OFPAT11_COPY_TTL_OUT,     /* Copy TTL "outwards" -- from next-to-outermost
188                                  to outermost */
189     OFPAT11_COPY_TTL_IN,      /* Copy TTL "inwards" -- from outermost to
190                                next-to-outermost */
191     OFPAT11_SET_MPLS_LABEL,   /* MPLS label */
192     OFPAT11_SET_MPLS_TC,      /* MPLS TC */
193     OFPAT11_SET_MPLS_TTL,     /* MPLS TTL */
194     OFPAT11_DEC_MPLS_TTL,     /* Decrement MPLS TTL */
195
196     OFPAT11_PUSH_VLAN,        /* Push a new VLAN tag */
197     OFPAT11_POP_VLAN,         /* Pop the outer VLAN tag */
198     OFPAT11_PUSH_MPLS,        /* Push a new MPLS tag */
199     OFPAT11_POP_MPLS,         /* Pop the outer MPLS tag */
200     OFPAT11_SET_QUEUE,        /* Set queue id when outputting to a port */
201     OFPAT11_GROUP,            /* Apply group. */
202     OFPAT11_SET_NW_TTL,       /* IP TTL. */
203     OFPAT11_DEC_NW_TTL,       /* Decrement IP TTL. */
204     OFPAT11_EXPERIMENTER = 0xffff
205 };
206
207 #define OFPMT11_STANDARD_LENGTH 88
208
209 struct ofp11_match_header {
210     ovs_be16 type;             /* One of OFPMT_* */
211     ovs_be16 length;           /* Length of match */
212 };
213 OFP_ASSERT(sizeof(struct ofp11_match_header) == 4);
214
215 /* Fields to match against flows */
216 struct ofp11_match {
217     struct ofp11_match_header omh;
218     ovs_be32 in_port;          /* Input switch port. */
219     ovs_be32 wildcards;        /* Wildcard fields. */
220     uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
221     uint8_t dl_src_mask[OFP_ETH_ALEN]; /* Ethernet source address mask.  */
222     uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
223     uint8_t dl_dst_mask[OFP_ETH_ALEN]; /* Ethernet destination address mask. */
224     ovs_be16 dl_vlan;          /* Input VLAN id. */
225     uint8_t dl_vlan_pcp;       /* Input VLAN priority. */
226     uint8_t pad1[1];           /* Align to 32-bits */
227     ovs_be16 dl_type;          /* Ethernet frame type. */
228     uint8_t nw_tos;            /* IP ToS (actually DSCP field, 6 bits). */
229     uint8_t nw_proto;          /* IP protocol or lower 8 bits of ARP opcode. */
230     ovs_be32 nw_src;           /* IP source address. */
231     ovs_be32 nw_src_mask;      /* IP source address mask. */
232     ovs_be32 nw_dst;           /* IP destination address. */
233     ovs_be32 nw_dst_mask;      /* IP destination address mask. */
234     ovs_be16 tp_src;           /* TCP/UDP/SCTP source port. */
235     ovs_be16 tp_dst;           /* TCP/UDP/SCTP destination port. */
236     ovs_be32 mpls_label;       /* MPLS label. */
237     uint8_t mpls_tc;           /* MPLS TC. */
238     uint8_t pad2[3];           /* Align to 64-bits */
239     ovs_be64 metadata;         /* Metadata passed between tables. */
240     ovs_be64 metadata_mask;    /* Mask for metadata. */
241 };
242 OFP_ASSERT(sizeof(struct ofp11_match) == OFPMT11_STANDARD_LENGTH);
243
244 /* Flow wildcards. */
245 enum ofp11_flow_wildcards {
246     OFPFW11_IN_PORT     = 1 << 0,  /* Switch input port. */
247     OFPFW11_DL_VLAN     = 1 << 1,  /* VLAN id. */
248     OFPFW11_DL_VLAN_PCP = 1 << 2,  /* VLAN priority. */
249     OFPFW11_DL_TYPE     = 1 << 3,  /* Ethernet frame type. */
250     OFPFW11_NW_TOS      = 1 << 4,  /* IP ToS (DSCP field, 6 bits). */
251     OFPFW11_NW_PROTO    = 1 << 5,  /* IP protocol. */
252     OFPFW11_TP_SRC      = 1 << 6,  /* TCP/UDP/SCTP source port. */
253     OFPFW11_TP_DST      = 1 << 7,  /* TCP/UDP/SCTP destination port. */
254     OFPFW11_MPLS_LABEL  = 1 << 8,  /* MPLS label. */
255     OFPFW11_MPLS_TC     = 1 << 9,  /* MPLS TC. */
256
257     /* Wildcard all fields. */
258     OFPFW11_ALL           = ((1 << 10) - 1)
259 };
260
261 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
262  * special conditions.
263  */
264 enum ofp11_vlan_id {
265     OFPVID11_ANY = 0xfffe,  /* Indicate that a VLAN id is set but don't care
266                                about it's value. Note: only valid when
267                                specifying the VLAN id in a match */
268     OFPVID11_NONE = 0xffff, /* No VLAN id was set. */
269 };
270
271 enum ofp11_instruction_type {
272     OFPIT11_GOTO_TABLE = 1,        /* Setup the next table in the lookup
273                                       pipeline */
274     OFPIT11_WRITE_METADATA = 2,    /* Setup the metadata field for use later
275                                       in pipeline */
276     OFPIT11_WRITE_ACTIONS = 3,     /* Write the action(s) onto the datapath
277                                       action set */
278     OFPIT11_APPLY_ACTIONS = 4,     /* Applies the action(s) immediately */
279     OFPIT11_CLEAR_ACTIONS = 5,     /* Clears all actions from the datapath
280                                       action set */
281     OFPIT11_EXPERIMENTER = 0xFFFF  /* Experimenter instruction */
282 };
283
284 #define OFP11_INSTRUCTION_ALIGN 8
285
286 /* Generic ofp_instruction structure. */
287 struct ofp11_instruction {
288     ovs_be16 type;              /* Instruction type */
289     ovs_be16 len;               /* Length of this struct in bytes. */
290     uint8_t pad[4];             /* Align to 64-bits */
291 };
292 OFP_ASSERT(sizeof(struct ofp11_instruction) == 8);
293
294 /* Instruction structure for OFPIT_GOTO_TABLE */
295 struct ofp11_instruction_goto_table {
296     ovs_be16 type;                 /* OFPIT_GOTO_TABLE */
297     ovs_be16 len;                  /* Length of this struct in bytes. */
298     uint8_t table_id;              /* Set next table in the lookup pipeline */
299     uint8_t pad[3];                /* Pad to 64 bits. */
300 };
301 OFP_ASSERT(sizeof(struct ofp11_instruction_goto_table) == 8);
302
303 /* Instruction structure for OFPIT_WRITE_METADATA */
304 struct ofp11_instruction_write_metadata {
305     ovs_be16 type;              /* OFPIT_WRITE_METADATA */
306     ovs_be16 len;               /* Length of this struct in bytes. */
307     uint8_t pad[4];             /* Align to 64-bits */
308     ovs_be64 metadata;          /* Metadata value to write */
309     ovs_be64 metadata_mask;     /* Metadata write bitmask */
310 };
311 OFP_ASSERT(sizeof(struct ofp11_instruction_write_metadata) == 24);
312
313 /* Instruction structure for OFPIT_WRITE/APPLY/CLEAR_ACTIONS */
314 struct ofp11_instruction_actions {
315     ovs_be16 type;              /* One of OFPIT_*_ACTIONS */
316     ovs_be16 len;               /* Length of this struct in bytes. */
317     uint8_t pad[4];             /* Align to 64-bits */
318     /* struct ofp_action_header actions[0];  Actions associated with
319                                              OFPIT_WRITE_ACTIONS and
320                                              OFPIT_APPLY_ACTIONS */
321 };
322 OFP_ASSERT(sizeof(struct ofp11_instruction_actions) == 8);
323
324 /* Instruction structure for experimental instructions */
325 struct ofp11_instruction_experimenter {
326     ovs_be16 type;              /* OFPIT11_EXPERIMENTER */
327     ovs_be16 len;               /* Length of this struct in bytes */
328     ovs_be32 experimenter;      /* Experimenter ID which takes the same form
329                                    as in struct ofp_vendor_header. */
330     /* Experimenter-defined arbitrary additional data. */
331 };
332 OFP_ASSERT(sizeof(struct ofp11_instruction_experimenter) == 8);
333
334 /* Action structure for OFPAT_OUTPUT, which sends packets out 'port'.
335    * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
336    * number of bytes to send. A 'max_len' of zero means no bytes of the
337    * packet should be sent.*/
338 struct ofp11_action_output {
339     ovs_be16 type;                    /* OFPAT11_OUTPUT. */
340     ovs_be16 len;                     /* Length is 16. */
341     ovs_be32 port;                    /* Output port. */
342     ovs_be16 max_len;                 /* Max length to send to controller. */
343     uint8_t pad[6];                   /* Pad to 64 bits. */
344 };
345 OFP_ASSERT(sizeof(struct ofp11_action_output) == 16);
346
347 /* Action structure for OFPAT_GROUP. */
348 struct ofp11_action_group {
349     ovs_be16 type;                    /* OFPAT11_GROUP. */
350     ovs_be16 len;                     /* Length is 8. */
351     ovs_be32 group_id;                /* Group identifier. */
352 };
353 OFP_ASSERT(sizeof(struct ofp11_action_group) == 8);
354
355 /* OFPAT_SET_QUEUE action struct: send packets to given queue on port. */
356 struct ofp11_action_set_queue {
357     ovs_be16 type;                    /* OFPAT11_SET_QUEUE. */
358     ovs_be16 len;                     /* Len is 8. */
359     ovs_be32 queue_id;                /* Queue id for the packets. */
360 };
361 OFP_ASSERT(sizeof(struct ofp11_action_set_queue) == 8);
362
363 /* Action structure for OFPAT11_SET_MPLS_LABEL. */
364 struct ofp11_action_mpls_label {
365     ovs_be16 type;                    /* OFPAT11_SET_MPLS_LABEL. */
366     ovs_be16 len;                     /* Length is 8. */
367     ovs_be32 mpls_label;              /* MPLS label */
368 };
369 OFP_ASSERT(sizeof(struct ofp11_action_mpls_label) == 8);
370
371 /* Action structure for OFPAT11_SET_MPLS_TC. */
372 struct ofp11_action_mpls_tc {
373     ovs_be16 type;                    /* OFPAT11_SET_MPLS_TC. */
374     ovs_be16 len;                     /* Length is 8. */
375     uint8_t mpls_tc;                  /* MPLS TC */
376     uint8_t pad[3];
377 };
378 OFP_ASSERT(sizeof(struct ofp11_action_mpls_tc) == 8);
379
380 /* Action structure for OFPAT11_SET_MPLS_TTL. */
381 struct ofp11_action_mpls_ttl {
382     ovs_be16 type;                    /* OFPAT11_SET_MPLS_TTL. */
383     ovs_be16 len;                     /* Length is 8. */
384     uint8_t mpls_ttl;                 /* MPLS TTL */
385     uint8_t pad[3];
386 };
387 OFP_ASSERT(sizeof(struct ofp11_action_mpls_ttl) == 8);
388
389 /* Action structure for OFPAT11_SET_NW_ECN. */
390 struct ofp11_action_nw_ecn {
391     ovs_be16 type;                    /* OFPAT11_SET_TW_SRC/DST. */
392     ovs_be16 len;                     /* Length is 8. */
393     uint8_t nw_ecn;                   /* IP ECN (2 bits). */
394     uint8_t pad[3];
395 };
396 OFP_ASSERT(sizeof(struct ofp11_action_nw_ecn) == 8);
397
398 /* Action structure for OFPAT11_SET_NW_TTL. */
399 struct ofp11_action_nw_ttl {
400     ovs_be16 type;                    /* OFPAT11_SET_NW_TTL. */
401     ovs_be16 len;                     /* Length is 8. */
402     uint8_t nw_ttl;                   /* IP TTL */
403     uint8_t pad[3];
404 };
405 OFP_ASSERT(sizeof(struct ofp11_action_nw_ttl) == 8);
406
407 /* Action structure for OFPAT11_PUSH_VLAN/MPLS. */
408 struct ofp11_action_push {
409     ovs_be16 type;                    /* OFPAT11_PUSH_VLAN/MPLS. */
410     ovs_be16 len;                     /* Length is 8. */
411     ovs_be16 ethertype;               /* Ethertype */
412     uint8_t pad[2];
413 };
414 OFP_ASSERT(sizeof(struct ofp11_action_push) == 8);
415
416 /* Action structure for OFPAT11_POP_MPLS. */
417 struct ofp11_action_pop_mpls {
418     ovs_be16 type;                    /* OFPAT11_POP_MPLS. */
419     ovs_be16 len;                     /* Length is 8. */
420     ovs_be16 ethertype;               /* Ethertype */
421     uint8_t pad[2];
422 };
423 OFP_ASSERT(sizeof(struct ofp11_action_pop_mpls) == 8);
424
425 /* Configure/Modify behavior of a flow table */
426 struct ofp11_table_mod {
427     uint8_t table_id;       /* ID of the table, 0xFF indicates all tables */
428     uint8_t pad[3];         /* Pad to 32 bits */
429     ovs_be32 config;        /* Bitmap of OFPTC_* flags */
430 };
431 OFP_ASSERT(sizeof(struct ofp11_table_mod) == 8);
432
433 /* Flags to indicate behavior of the flow table for unmatched packets.
434    These flags are used in ofp_table_stats messages to describe the current
435    configuration and in ofp_table_mod messages to configure table behavior.  */
436 enum ofp11_table_config {
437     OFPTC11_TABLE_MISS_CONTROLLER = 0,    /* Send to controller. */
438     OFPTC11_TABLE_MISS_CONTINUE = 1 << 0, /* Continue to the next table in the
439                                              pipeline (OpenFlow 1.0
440                                              behavior). */
441     OFPTC11_TABLE_MISS_DROP = 1 << 1,     /* Drop the packet. */
442     OFPTC11_TABLE_MISS_MASK = 3
443 };
444
445 /* Flow setup and teardown (controller -> datapath). */
446 struct ofp11_flow_mod {
447     ovs_be64 cookie;             /* Opaque controller-issued identifier. */
448     ovs_be64 cookie_mask;        /* Mask used to restrict the cookie bits
449                                     that must match when the command is
450                                     OFPFC_MODIFY* or OFPFC_DELETE*. A value
451                                     of 0 indicates no restriction. */
452     /* Flow actions. */
453     uint8_t table_id;            /* ID of the table to put the flow in */
454     uint8_t command;             /* One of OFPFC_*. */
455     ovs_be16 idle_timeout;       /* Idle time before discarding (seconds). */
456     ovs_be16 hard_timeout;       /* Max time before discarding (seconds). */
457     ovs_be16 priority;           /* Priority level of flow entry. */
458     ovs_be32 buffer_id;          /* Buffered packet to apply to (or -1).
459                                     Not meaningful for OFPFC_DELETE*. */
460     ovs_be32 out_port;           /* For OFPFC_DELETE* commands, require
461                                     matching entries to include this as an
462                                     output port. A value of OFPP_ANY
463                                     indicates no restriction. */
464     ovs_be32 out_group;          /* For OFPFC_DELETE* commands, require
465                                     matching entries to include this as an
466                                     output group. A value of OFPG11_ANY
467                                     indicates no restriction. */
468     ovs_be16 flags;              /* One of OFPFF_*. */
469     uint8_t pad[2];
470     /* Followed by an ofp11_match structure. */
471     /* Followed by an instruction set. */
472 };
473 OFP_ASSERT(sizeof(struct ofp11_flow_mod) == 40);
474
475 /* Group types. Values in the range [128, 255] are reserved for experimental
476  * use. */
477 enum ofp11_group_type {
478     OFPGT11_ALL,      /* All (multicast/broadcast) group. */
479     OFPGT11_SELECT,   /* Select group. */
480     OFPGT11_INDIRECT, /* Indirect group. */
481     OFPGT11_FF        /* Fast failover group. */
482 };
483
484 /* Group numbering. Groups can use any number up to OFPG_MAX. */
485 enum ofp11_group {
486     /* Last usable group number. */
487     OFPG11_MAX        = 0xffffff00,
488
489     /* Fake groups. */
490     OFPG11_ALL        = 0xfffffffc,  /* Represents all groups for group delete
491                                         commands. */
492     OFPG11_ANY        = 0xffffffff   /* Wildcard group used only for flow stats
493                                         requests. Selects all flows regardless
494                                         of group (including flows with no
495                                         group). */
496 };
497
498 /* Bucket for use in groups. */
499 struct ofp11_bucket {
500     ovs_be16 len;                    /* Length the bucket in bytes, including
501                                         this header and any padding to make it
502                                         64-bit aligned. */
503     ovs_be16 weight;                 /* Relative weight of bucket. Only
504                                         defined for select groups. */
505     ovs_be32 watch_port;             /* Port whose state affects whether this
506                                         bucket is live. Only required for fast
507                                         failover groups. */
508     ovs_be32 watch_group;            /* Group whose state affects whether this
509                                         bucket is live. Only required for fast
510                                         failover groups. */
511     uint8_t pad[4];
512     /* struct ofp_action_header actions[0]; The action length is inferred
513                                             from the length field in the
514                                             header. */
515 };
516 OFP_ASSERT(sizeof(struct ofp11_bucket) == 16);
517
518 /* Queue configuration for a given port. */
519 struct ofp11_queue_get_config_reply {
520     ovs_be32 port;
521     uint8_t pad[4];
522     /* struct ofp_packet_queue queues[0];  List of configured queues. */
523 };
524 OFP_ASSERT(sizeof(struct ofp11_queue_get_config_reply) == 8);
525
526 struct ofp11_stats_msg {
527     struct ofp_header header;
528     ovs_be16 type;              /* One of the OFPST_* constants. */
529     ovs_be16 flags;             /* OFPSF_REQ_* flags (none yet defined). */
530     uint8_t pad[4];
531     /* Followed by the body of the request. */
532 };
533 OFP_ASSERT(sizeof(struct ofp11_stats_msg) == 16);
534
535 /* Vendor extension stats message. */
536 struct ofp11_vendor_stats_msg {
537     struct ofp11_stats_msg osm; /* Type OFPST_VENDOR. */
538     ovs_be32 vendor;            /* Vendor ID:
539                                  * - MSB 0: low-order bytes are IEEE OUI.
540                                  * - MSB != 0: defined by OpenFlow
541                                  *   consortium. */
542     /* Followed by vendor-defined arbitrary additional data. */
543 };
544 OFP_ASSERT(sizeof(struct ofp11_vendor_stats_msg) == 20);
545
546 /* Stats request of type OFPST_FLOW. */
547 struct ofp11_flow_stats_request {
548     uint8_t table_id;         /* ID of table to read (from ofp_table_stats),
549                                  0xff for all tables. */
550     uint8_t pad[3];           /* Align to 64 bits. */
551     ovs_be32 out_port;        /* Require matching entries to include this
552                                  as an output port. A value of OFPP_ANY
553                                  indicates no restriction. */
554     ovs_be32 out_group;       /* Require matching entries to include this
555                                  as an output group. A value of OFPG11_ANY
556                                  indicates no restriction. */
557     uint8_t pad2[4];          /* Align to 64 bits. */
558     ovs_be64 cookie;          /* Require matching entries to contain this
559                                  cookie value */
560     ovs_be64 cookie_mask;     /* Mask used to restrict the cookie bits that
561                                  must match. A value of 0 indicates
562                                  no restriction. */
563     /* Followed by an ofp11_match structure. */
564 };
565 OFP_ASSERT(sizeof(struct ofp11_flow_stats_request) == 32);
566
567 /* Body of reply to OFPST_FLOW request. */
568 struct ofp11_flow_stats {
569     ovs_be16 length;           /* Length of this entry. */
570     uint8_t table_id;          /* ID of table flow came from. */
571     uint8_t pad;
572     ovs_be32 duration_sec;     /* Time flow has been alive in seconds. */
573     ovs_be32 duration_nsec;    /* Time flow has been alive in nanoseconds beyond
574                                   duration_sec. */
575     ovs_be16 priority;         /* Priority of the entry. Only meaningful
576                                   when this is not an exact-match entry. */
577     ovs_be16 idle_timeout;     /* Number of seconds idle before expiration. */
578     ovs_be16 hard_timeout;     /* Number of seconds before expiration. */
579     uint8_t pad2[6];           /* Align to 64-bits. */
580     ovs_be64 cookie;           /* Opaque controller-issued identifier. */
581     ovs_be64 packet_count;     /* Number of packets in flow. */
582     ovs_be64 byte_count;       /* Number of bytes in flow. */
583     /* Open Flow version specific match */
584     /* struct ofp11_instruction instructions[0];  Instruction set. */
585 };
586 OFP_ASSERT(sizeof(struct ofp11_flow_stats) == 48);
587
588 /* Body for ofp_stats_request of type OFPST_AGGREGATE. */
589 /* Identical to ofp11_flow_stats_request */
590
591 /* Body of reply to OFPST_TABLE request. */
592 struct ofp11_table_stats {
593     uint8_t table_id;        /* Identifier of table. Lower numbered tables
594                                 are consulted first. */
595     uint8_t pad[7];          /* Align to 64-bits. */
596     char name[OFP_MAX_TABLE_NAME_LEN];
597     ovs_be32 wildcards;      /* Bitmap of OFPFMF_* wildcards that are
598                                 supported by the table. */
599     ovs_be32 match;          /* Bitmap of OFPFMF_* that indicate the fields
600                                 the table can match on. */
601     ovs_be32 instructions;   /* Bitmap of OFPIT_* values supported. */
602     ovs_be32 write_actions;  /* Bitmap of OFPAT_* that are supported
603                                 by the table with OFPIT_WRITE_ACTIONS.  */
604     ovs_be32 apply_actions;  /* Bitmap of OFPAT_* that are supported
605                                 by the table with OFPIT_APPLY_ACTIONS. */
606     ovs_be32 config;         /* Bitmap of OFPTC_* values */
607     ovs_be32 max_entries;    /* Max number of entries supported. */
608     ovs_be32 active_count;   /* Number of active entries. */
609     ovs_be64 lookup_count;   /* Number of packets looked up in table. */
610     ovs_be64 matched_count;  /* Number of packets that hit table. */
611 };
612 OFP_ASSERT(sizeof(struct ofp11_table_stats) == 88);
613
614 /* Body for ofp_stats_request of type OFPST_PORT. */
615 struct ofp11_port_stats_request {
616     ovs_be32 port_no;        /* OFPST_PORT message must request statistics
617                               * either for a single port (specified in
618                               * port_no) or for all ports (if port_no ==
619                               * OFPP_ANY). */
620     uint8_t pad[4];
621 };
622 OFP_ASSERT(sizeof(struct ofp11_port_stats_request) == 8);
623
624 /* Body of reply to OFPST_PORT request. If a counter is unsupported, set
625  * the field to all ones. */
626 struct ofp11_port_stats {
627     ovs_be32 port_no;
628     uint8_t pad[4];           /* Align to 64-bits. */
629     ovs_be64 rx_packets;      /* Number of received packets. */
630     ovs_be64 tx_packets;      /* Number of transmitted packets. */
631     ovs_be64 rx_bytes;        /* Number of received bytes. */
632     ovs_be64 tx_bytes;        /* Number of transmitted bytes. */
633     ovs_be64 rx_dropped;      /* Number of packets dropped by RX. */
634     ovs_be64 tx_dropped;      /* Number of packets dropped by TX. */
635     ovs_be64 rx_errors;       /* Number of receive errors.  This is a
636                                  super-set of receive errors and should be
637                                  great than or equal to the sum of all
638                                  rx_*_err values. */
639     ovs_be64 tx_errors;       /* Number of transmit errors.  This is a
640                                  super-set of transmit errors. */
641     ovs_be64 rx_frame_err;    /* Number of frame alignment errors. */
642     ovs_be64 rx_over_err;     /* Number of packets with RX overrun. */
643     ovs_be64 rx_crc_err;      /* Number of CRC errors. */
644     ovs_be64 collisions;      /* Number of collisions. */
645 };
646 OFP_ASSERT(sizeof(struct ofp11_port_stats) == 104);
647
648 struct ofp11_queue_stats_request {
649     ovs_be32 port_no;         /* All ports if OFPP_ANY. */
650     ovs_be32 queue_id;        /* All queues if OFPQ_ALL. */
651 };
652 OFP_ASSERT(sizeof(struct ofp11_queue_stats_request) == 8);
653
654 struct ofp11_queue_stats {
655     ovs_be32 port_no;
656     ovs_be32 queue_id;         /* Queue id. */
657     ovs_be64 tx_bytes;         /* Number of transmitted bytes. */
658     ovs_be64 tx_packets;       /* Number of transmitted packets. */
659     ovs_be64 tx_errors;        /* # of packets dropped due to overrun. */
660 };
661 OFP_ASSERT(sizeof(struct ofp11_queue_stats) == 32);
662
663 struct ofp11_group_stats_request {
664     ovs_be32 group_id;         /* All groups if OFPG_ALL. */
665     uint8_t pad[4];            /* Align to 64 bits. */
666 };
667 OFP_ASSERT(sizeof(struct ofp11_group_stats_request) == 8);
668
669 /* Body of reply to OFPST11_GROUP request */
670 struct ofp11_group_stats {
671     ovs_be16 length;           /* Length of this entry. */
672     uint8_t pad[2];            /* Align to 64 bits. */
673     ovs_be32 group_id;         /* Group identifier. */
674     ovs_be32 ref_count;        /* Number of flows or groups that
675                                   directly forward to this group. */
676     uint8_t pad2[4];           /* Align to 64 bits. */
677     ovs_be64 packet_count;     /* Number of packets processed by group. */
678     ovs_be64 byte_count;       /* Number of bytes processed by group. */
679     /* struct ofp11_bucket_counter bucket_stats[0]; */
680
681 };
682 OFP_ASSERT(sizeof(struct ofp11_group_stats) == 32);
683
684 /* Used in group stats replies. */
685 struct ofp11_bucket_counter {
686     ovs_be64 packet_count;   /* Number of packets processed by bucket. */
687     ovs_be64 byte_count;     /* Number of bytes processed by bucket. */
688 };
689 OFP_ASSERT(sizeof(struct ofp11_bucket_counter) == 16);
690
691 /* Body of reply to OFPST11_GROUP_DESC request. */
692 struct ofp11_group_desc_stats {
693     ovs_be16 length;            /* Length of this entry. */
694     uint8_t type;               /* One of OFPGT_*. */
695     uint8_t pad;                /* Pad to 64 bits. */
696     ovs_be32 group_id;          /* Group identifier. */
697     /* struct ofp11_bucket buckets[0]; */
698 };
699 OFP_ASSERT(sizeof(struct ofp11_group_desc_stats) == 8);
700
701 /* Send packet (controller -> datapath). */
702 struct ofp11_packet_out {
703     ovs_be32 buffer_id;       /* ID assigned by datapath (-1 if none). */
704     ovs_be32 in_port;         /* Packet's input port or OFPP_CONTROLLER. */
705     ovs_be16 actions_len;     /* Size of action array in bytes. */
706     uint8_t pad[6];
707     /* struct ofp_action_header actions[0];  Action list. */
708     /* uint8_t data[0]; */    /* Packet data. The length is inferred
709                                  from the length field in the header.
710                                  (Only meaningful if buffer_id == -1.) */
711 };
712 OFP_ASSERT(sizeof(struct ofp11_packet_out) == 16);
713
714 /* Packet received on port (datapath -> controller). */
715 struct ofp11_packet_in {
716     ovs_be32 buffer_id;     /* ID assigned by datapath. */
717     ovs_be32 in_port;       /* Port on which frame was received. */
718     ovs_be32 in_phy_port;   /* Physical Port on which frame was received. */
719     ovs_be16 total_len;     /* Full length of frame. */
720     uint8_t reason;         /* Reason packet is being sent (one of OFPR_*) */
721     uint8_t table_id;       /* ID of the table that was looked up */
722     uint8_t data[0];        /* Ethernet frame, halfway through 32-bit word,
723                                so the IP header is 32-bit aligned. The
724                                amount of data is inferred from the length
725                                field in the header. Because of padding,
726                                offsetof(struct ofp_packet_in, data) ==
727                                sizeof(struct ofp_packet_in) - 2. */
728 };
729 OFP_ASSERT(sizeof(struct ofp11_packet_in) == 16);
730
731 /* Flow removed (datapath -> controller). */
732 struct ofp11_flow_removed {
733     ovs_be64 cookie;          /* Opaque controller-issued identifier. */
734
735     ovs_be16 priority;        /* Priority level of flow entry. */
736     uint8_t reason;           /* One of OFPRR_*. */
737     uint8_t table_id;         /* ID of the table */
738
739     ovs_be32 duration_sec;    /* Time flow was alive in seconds. */
740     ovs_be32 duration_nsec;   /* Time flow was alive in nanoseconds beyond
741                                  duration_sec. */
742     ovs_be16 idle_timeout;    /* Idle timeout from original flow mod. */
743     uint8_t pad2[2];          /* Align to 64-bits. */
744     ovs_be64 packet_count;
745     ovs_be64 byte_count;
746     /* Followed by an ofp11_match structure. */
747 };
748 OFP_ASSERT(sizeof(struct ofp11_flow_removed) == 40);
749
750 #endif /* openflow/openflow-1.1.h */