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