ofp-util: Support for OpenFlow 1.3 meters.
[sliver-openvswitch.git] / include / openflow / openflow-1.3.h
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2 * Junior University
3 * Copyright (c) 2011, 2012 Open Networking Foundation
4 *
5 * We are making the OpenFlow specification and associated documentation
6 * (Software) available for public use and benefit with the expectation
7 * that others will use, modify and enhance the Software and contribute
8 * those enhancements back to the community. However, since we would
9 * like to make the Software available for broadest use, with as few
10 * restrictions as possible permission is hereby granted, free of
11 * charge, to any person obtaining a copy of this Software to deal in
12 * the Software under the copyrights without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 *
30 * The name and trademarks of copyright holder(s) may NOT be used in
31 * advertising or publicity pertaining to the Software or any
32 * derivatives without specific, written prior permission.
33 */
34
35 /* OpenFlow: protocol between controller and datapath. */
36
37 #ifndef OPENFLOW_13_H
38 #define OPENFLOW_13_H 1
39
40 #include "openflow/openflow-1.2.h"
41
42 /*
43  * OpenFlow 1.3 modifies the syntax of the following message types:
44  *
45  * OFPT_FEATURES_REPLY     = 6    (opf13_switch_features)
46  *                                 - new field: auxiliary_id
47  *                                 - removed: ofp_ports at the end
48  *
49  * OFPT_PACKET_IN          = 10   (ofp13_packet_in) new field: cookie
50  *
51  * OpenFlow 1.3 adds following new message types:
52  *
53  * * Asynchronous message configuration. *
54  * OFPT13_GET_ASYNC_REQUEST  = 26   (void)
55  * OFPT13_GET_ASYNC_REPLY    = 27   (ofp13_async_config)
56  * OFPT13_SET_ASYNC          = 28   (ofp13_async_config)
57  *
58  * * Meters and rate limiters configuration messages. *
59  * OFPT13_METER_MOD          = 29   (ofp13_meter_mod)
60  *
61  * OpenFlow 1.3 modifies the syntax of the following statistics message types
62  * (now called multipart message types):
63  *
64  * OFPMP13_FLOW_REPLY = 1 (struct ofp13_flow_stats[])
65  * OFPMP13_TABLE_REPLY = 3 (struct ofp13_table_stats[])
66  * OFPMP13_PORT_REPLY = 4 (struct ofp13_port_stats[])
67  * OFPMP13_QUEUE_REPLY = 5, (struct ofp13_queue_stats[])
68  * OFPMP13_GROUP_REPLY = 6, (struct ofp13_group_stats[])
69  *
70  * OpenFlow 1.3 adds the following multipart message types
71  *
72  * Meter statistics:
73  * OFPMP13_METER_REQUEST = 9, (struct ofp13_meter_multipart_request)
74  * OFPMP13_METER_REPLY = 9, (struct ofp13_meter_stats[])
75  *
76  * Meter configuration:
77  * OFPMP13_METER_CONFIG_REQUEST = 10, (struct ofp13_meter_multipart_request)
78  * OFPMP13_METER_CONFIG_REPLY = 10, (struct ofp13_meter_config[])
79  *
80  * Meter features:
81  * OFPMP13_METER_FEATURES_REQUEST = 11 (void)
82  * OFPMP13_METER_FEATURES_REPLY = 11 (struct ofp13_meter_features)
83  *
84  * Table features:
85  * OFPMP13_TABLE_FEATURES_REQUEST = 12, (struct ofp13_table_features[])
86  * OFPMP13_TABLE_FEATURES_REPLY = 12, (struct ofp13_table_features[])
87  *
88  */
89
90 enum ofp13_instruction_type {
91     OFPIT13_METER = 6           /* Apply meter (rate limiter) */
92 };
93
94 #define OFPIT13_ALL (OFPIT11_GOTO_TABLE | OFPIT11_WRITE_METADATA |      \
95                      OFPIT11_WRITE_ACTIONS | OFPIT11_APPLY_ACTIONS |    \
96                      OFPIT11_CLEAR_ACTIONS | OFPIT13_METER)
97
98 /* Instruction structure for OFPIT_METER */
99 struct ofp13_instruction_meter {
100     ovs_be16 type;              /* OFPIT13_METER */
101     ovs_be16 len;               /* Length is 8. */
102     ovs_be32 meter_id;          /* Meter instance. */
103 };
104 OFP_ASSERT(sizeof(struct ofp13_instruction_meter) == 8);
105
106 enum ofp13_action_type {
107     OFPAT13_PUSH_PBB = 26,     /* Push a new PBB service tag (I-TAG) */
108     OFPAT13_POP_PBB  = 27      /* Pop the outer PBB service tag (I-TAG) */
109 };
110
111 /* enum ofp_config_flags value OFPC_INVALID_TTL_TO_CONTROLLER
112  * is deprecated in OpenFlow 1.3 */
113
114 /* Flags to configure the table. Reserved for future use. */
115 enum ofp13_table_config {
116     OFPTC13_DEPRECATED_MASK = 3  /* Deprecated bits */
117 };
118
119 /* OpenFlow 1.3 specific flags
120  * (struct ofp12_flow_mod, member flags). */
121 enum ofp13_flow_mod_flags {
122     OFPFF13_NO_PKT_COUNTS = 1 << 3, /* Don't keep track of packet count. */
123     OFPFF13_NO_BYT_COUNTS = 1 << 4  /* Don't keep track of byte count. */
124 };
125
126 /* Common header for all meter bands */
127 struct ofp13_meter_band_header {
128     ovs_be16 type;       /* One of OFPMBT_*. */
129     ovs_be16 len;        /* Length in bytes of this band. */
130     ovs_be32 rate;       /* Rate for this band. */
131     ovs_be32 burst_size; /* Size of bursts. */
132 };
133 OFP_ASSERT(sizeof(struct ofp13_meter_band_header) == 12);
134
135 /* Meter configuration. OFPT_METER_MOD. */
136 struct ofp13_meter_mod {
137     ovs_be16          command;      /* One of OFPMC_*. */
138     ovs_be16          flags;        /* Set of OFPMF_*. */
139     ovs_be32          meter_id;     /* Meter instance. */
140     /* struct ofp13_meter_band_header bands[0];  The bands length is inferred
141                                                  from the length field in the
142                                                  header. */
143 };
144 OFP_ASSERT(sizeof(struct ofp13_meter_mod) == 8);
145
146 /* Meter numbering. Flow meters can use any number up to OFPM_MAX. */
147 enum ofp13_meter {
148     /* Last usable meter. */
149     OFPM13_MAX        = 0xffff0000,
150     /* Virtual meters. */
151     OFPM13_SLOWPATH   = 0xfffffffd, /* Meter for slow datapath. */
152     OFPM13_CONTROLLER = 0xfffffffe, /* Meter for controller connection. */
153     OFPM13_ALL        = 0xffffffff, /* Represents all meters for stat requests
154                                      commands. */
155 };
156
157 /* Meter commands */
158 enum ofp13_meter_mod_command {
159     OFPMC13_ADD,           /* New meter. */
160     OFPMC13_MODIFY,        /* Modify specified meter. */
161     OFPMC13_DELETE         /* Delete specified meter. */
162 };
163
164 /* Meter configuration flags */
165 enum ofp13_meter_flags {
166     OFPMF13_KBPS    = 1 << 0,   /* Rate value in kb/s (kilo-bit per second). */
167     OFPMF13_PKTPS   = 1 << 1,   /* Rate value in packet/sec. */
168     OFPMF13_BURST   = 1 << 2,   /* Do burst size. */
169     OFPMF13_STATS   = 1 << 3    /* Collect statistics. */
170 };
171
172 /* Meter band types */
173 enum ofp13_meter_band_type {
174     OFPMBT13_DROP         = 1,     /* Drop packet. */
175     OFPMBT13_DSCP_REMARK  = 2,     /* Remark DSCP in the IP header. */
176     OFPMBT13_EXPERIMENTER = 0xFFFF /* Experimenter meter band. */
177 };
178
179 /* OFPMBT_DROP band - drop packets */
180 struct ofp13_meter_band_drop {
181     ovs_be16    type;        /* OFPMBT_DROP. */
182     ovs_be16    len;         /* Length in bytes of this band. */
183     ovs_be32    rate;        /* Rate for dropping packets. */
184     ovs_be32    burst_size;  /* Size of bursts. */
185     uint8_t     pad[4];
186 };
187 OFP_ASSERT(sizeof(struct ofp13_meter_band_drop) == 16);
188
189 /* OFPMBT_DSCP_REMARK band - Remark DSCP in the IP header */
190 struct ofp13_meter_band_dscp_remark {
191     ovs_be16    type;        /* OFPMBT_DSCP_REMARK. */
192     ovs_be16    len;         /* Length in bytes of this band. */
193     ovs_be32    rate;        /* Rate for remarking packets. */
194     ovs_be32    burst_size;  /* Size of bursts. */
195     uint8_t     prec_level;  /* Number of drop precedence level to add. */
196     uint8_t     pad[3];
197 };
198 OFP_ASSERT(sizeof(struct ofp13_meter_band_dscp_remark) == 16);
199
200 /* OFPMBT_EXPERIMENTER band - Write actions in action set */
201 struct ofp13_meter_band_experimenter {
202     ovs_be16    type;        /* OFPMBT_EXPERIMENTER. */
203     ovs_be16    len;         /* Length in bytes of this band. */
204     ovs_be32    rate;        /* Rate for dropping packets. */
205     ovs_be32    burst_size;  /* Size of bursts. */
206     ovs_be32    experimenter; /* Experimenter ID which takes the same form as
207                                  in struct ofp_experimenter_header. */
208 };
209 OFP_ASSERT(sizeof(struct ofp13_meter_band_experimenter) == 16);
210
211 /* OF 1.3 adds MORE flag also for requests */
212 enum ofp13_multipart_request_flags {
213     OFPMPF13_REQ_MORE = 1 << 0 /* More requests to follow. */
214 };
215
216 /* OF 1.3 splits table features off the ofp_table_stats */
217 /* Body of reply to OFPMP13_TABLE request. */
218 struct ofp13_table_stats {
219     uint8_t  table_id;      /* Identifier of table. Lower numbered tables are
220                                consulted first. */
221     uint8_t  pad[3];        /* Align to 32-bits. */
222     ovs_be32 active_count;  /* Number of active entries. */
223     ovs_be64 lookup_count;  /* Number of packets looked up in table. */
224     ovs_be64 matched_count; /* Number of packets that hit table. */
225 };
226 OFP_ASSERT(sizeof(struct ofp13_table_stats) == 24);
227
228 /* Common header for all Table Feature Properties */
229 struct ofp13_table_feature_prop_header {
230     ovs_be16    type;   /* One of OFPTFPT_*. */
231     ovs_be16    length; /* Length in bytes of this property. */
232 };
233 OFP_ASSERT(sizeof(struct ofp13_table_feature_prop_header) == 4);
234
235 /* Body for ofp_multipart_request of type OFPMP_TABLE_FEATURES./
236  * Body of reply to OFPMP_TABLE_FEATURES request. */
237 struct ofp13_table_features {
238     ovs_be16 length;          /* Length is padded to 64 bits. */
239     uint8_t table_id;         /* Identifier of table. Lower numbered tables
240                                  are consulted first. */
241     uint8_t pad[5];           /* Align to 64-bits. */
242     char name[OFP_MAX_TABLE_NAME_LEN];
243     ovs_be64 metadata_match;  /* Bits of metadata table can match. */
244     ovs_be64 metadata_write;  /* Bits of metadata table can write. */
245     ovs_be32 config;          /* Bitmap of OFPTC_* values */
246     ovs_be32 max_entries;     /* Max number of entries supported. */
247
248     /* Table Feature Property list */
249     /* struct ofp13_table_feature_prop_header properties[0]; */
250 };
251 OFP_ASSERT(sizeof(struct ofp13_table_features) == 64);
252
253 /* Table Feature property types.
254  * Low order bit cleared indicates a property for a regular Flow Entry.
255  * Low order bit set indicates a property for the Table-Miss Flow Entry. */
256 enum ofp13_table_feature_prop_type {
257     OFPTFPT13_INSTRUCTIONS         = 0, /* Instructions property. */
258     OFPTFPT13_INSTRUCTIONS_MISS    = 1, /* Instructions for table-miss. */
259     OFPTFPT13_NEXT_TABLES          = 2, /* Next Table property. */
260     OFPTFPT13_NEXT_TABLES_MISS     = 3, /* Next Table for table-miss. */
261     OFPTFPT13_WRITE_ACTIONS        = 4, /* Write Actions property. */
262     OFPTFPT13_WRITE_ACTIONS_MISS   = 5, /* Write Actions for table-miss. */
263     OFPTFPT13_APPLY_ACTIONS        = 6, /* Apply Actions property. */
264     OFPTFPT13_APPLY_ACTIONS_MISS   = 7, /* Apply Actions for table-miss. */
265     OFPTFPT13_MATCH                = 8, /* Match property. */
266     OFPTFPT13_WILDCARDS            = 10, /* Wildcards property. */
267     OFPTFPT13_WRITE_SETFIELD       = 12, /* Write Set-Field property. */
268     OFPTFPT13_WRITE_SETFIELD_MISS  = 13, /* Write Set-Field for table-miss. */
269     OFPTFPT13_APPLY_SETFIELD       = 14, /* Apply Set-Field property. */
270     OFPTFPT13_APPLY_SETFIELD_MISS  = 15, /* Apply Set-Field for table-miss. */
271     OFPTFPT13_EXPERIMENTER         = 0xFFFE, /* Experimenter property. */
272     OFPTFPT13_EXPERIMENTER_MISS    = 0xFFFF, /* Experimenter for table-miss. */
273 };
274
275 /* Instructions property */
276 struct ofp13_table_feature_prop_instructions {
277     ovs_be16    type;    /* One of OFPTFPT13_INSTRUCTIONS,
278                             OFPTFPT13_INSTRUCTIONS_MISS. */
279     ovs_be16    length;  /* Length in bytes of this property. */
280     /* Followed by:
281      *   - Exactly (length - 4) bytes containing the instruction ids, then
282      *   - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
283      *     bytes of all-zero bytes */
284     /* struct ofp11_instruction instruction_ids[0];  List of instructions
285                                                      without any data */
286 };
287 OFP_ASSERT(sizeof(struct ofp13_table_feature_prop_instructions) == 4);
288
289 /* Next Tables property */
290 struct ofp13_table_feature_prop_next_tables {
291     ovs_be16    type;   /* One of OFPTFPT13_NEXT_TABLES,
292                            OFPTFPT13_NEXT_TABLES_MISS. */
293     ovs_be16    length; /* Length in bytes of this property. */
294     /* Followed by:
295      *   - Exactly (length - 4) bytes containing the table_ids, then
296      *   - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
297      *     bytes of all-zero bytes */
298     /* uint8_t     next_table_ids[0]; */
299 };
300 OFP_ASSERT(sizeof(struct ofp13_table_feature_prop_next_tables) == 4);
301
302 /* Actions property */
303 struct ofp13_table_feature_prop_actions {
304     ovs_be16    type;   /* One of OFPTFPT13_WRITE_ACTIONS,
305                            OFPTFPT13_WRITE_ACTIONS_MISS,
306                            OFPTFPT13_APPLY_ACTIONS,
307                            OFPTFPT13_APPLY_ACTIONS_MISS. */
308     ovs_be16    length; /* Length in bytes of this property. */
309     /* Followed by:
310      *   - Exactly (length - 4) bytes containing the action_ids, then
311      *   - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
312      *     bytes of all-zero bytes */
313     /* struct ofp_action_header action_ids[0];     List of actions
314                                                    without any data */
315 };
316 OFP_ASSERT(sizeof(struct ofp13_table_feature_prop_actions) == 4);
317
318
319 /* Match, Wildcard or Set-Field property */
320 struct ofp13_table_feature_prop_oxm {
321     ovs_be16    type;   /* One of OFPTFPT13_MATCH, OFPTFPT13_WILDCARDS,
322                            OFPTFPT13_WRITE_SETFIELD,
323                            OFPTFPT13_WRITE_SETFIELD_MISS,
324                            OFPTFPT13_APPLY_SETFIELD,
325                            OFPTFPT13_APPLY_SETFIELD_MISS. */
326     ovs_be16    length; /* Length in bytes of this property. */
327     /* Followed by:
328      *   - Exactly (length - 4) bytes containing the oxm_ids, then
329      *   - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
330      *     bytes of all-zero bytes */
331     /* ovs_be32    oxm_ids[0];     Array of OXM headers */
332 };
333 OFP_ASSERT(sizeof(struct ofp13_table_feature_prop_oxm) == 4);
334
335 /* Experimenter table feature property */
336 struct ofp13_table_feature_prop_experimenter {
337     ovs_be16    type;     /* One of OFPTFPT13_EXPERIMENTER,
338                              OFPTFPT13_EXPERIMENTER_MISS. */
339     ovs_be16    length;   /* Length in bytes of this property. */
340     ovs_be32    experimenter; /* Experimenter ID which takes the same form
341                                  as in struct ofp_experimenter_header. */
342     ovs_be32    exp_type;     /* Experimenter defined. */
343     /* Followed by:
344      *   - Exactly (length - 12) bytes containing the experimenter data, then
345      *   - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
346      *     bytes of all-zero bytes */
347     /* ovs_be32    experimenter_data[0]; */
348 };
349 OFP_ASSERT(sizeof(struct ofp13_table_feature_prop_experimenter) == 12);
350
351 /* Body of reply to OFPMP13_PORT request. If a counter is unsupported, set
352  * the field to all ones. */
353 struct ofp13_port_stats {
354     struct ofp11_port_stats ps;
355     ovs_be32 duration_sec;    /* Time port has been alive in seconds. */
356     ovs_be32 duration_nsec;   /* Time port has been alive in nanoseconds
357                                  beyond duration_sec. */
358 };
359 OFP_ASSERT(sizeof(struct ofp13_port_stats) == 112);
360
361 /* Body of reply to OFPMP13_QUEUE request */
362 struct ofp13_queue_stats {
363     struct ofp11_queue_stats qs;
364     ovs_be32 duration_sec;    /* Time queue has been alive in seconds. */
365     ovs_be32 duration_nsec;   /* Time queue has been alive in nanoseconds
366                                  beyond duration_sec. */
367 };
368 OFP_ASSERT(sizeof(struct ofp13_queue_stats) == 40);
369
370 /* Body of reply to OFPMP13_GROUP request */
371 struct ofp13_group_stats {
372     struct ofp11_group_stats gs;
373     ovs_be32 duration_sec;    /* NEW: Time group has been alive in seconds. */
374     ovs_be32 duration_nsec;   /* NEW: Time group has been alive in nanoseconds
375                                  beyond duration_sec. */
376     /* struct ofp11_bucket_counter bucket_stats[0]; */
377 };
378 OFP_ASSERT(sizeof(struct ofp13_group_stats) == 40);
379
380 /* Body of OFPMP13_METER and OFPMP13_METER_CONFIG requests. */
381 struct ofp13_meter_multipart_request {
382     ovs_be32 meter_id;  /* Meter instance, or OFPM_ALL. */
383     uint8_t pad[4];     /* Align to 64 bits. */
384 };
385 OFP_ASSERT(sizeof(struct ofp13_meter_multipart_request) == 8);
386
387 /* Statistics for each meter band */
388 struct ofp13_meter_band_stats {
389     ovs_be64    packet_band_count;      /* Number of packets in band. */
390     ovs_be64    byte_band_count;        /* Number of bytes in band. */
391 };
392 OFP_ASSERT(sizeof(struct ofp13_meter_band_stats) == 16);
393
394 /* Body of reply to OFPMP13_METER request. Meter statistics. */
395 struct ofp13_meter_stats {
396     ovs_be32  meter_id;          /* Meter instance. */
397     ovs_be16  len;               /* Length in bytes of this stats. */
398     uint8_t   pad[6];
399     ovs_be32  flow_count;        /* Number of flows bound to meter. */
400     ovs_be64  packet_in_count;   /* Number of packets in input. */
401     ovs_be64  byte_in_count;     /* Number of bytes in input. */
402     ovs_be32  duration_sec;      /* Time meter has been alive in seconds. */
403     ovs_be32  duration_nsec;     /* Time meter has been alive in nanoseconds
404                                     beyond duration_sec. */
405     struct ofp13_meter_band_stats band_stats[0];  /* The band_stats length is
406                                              inferred from the length field. */
407 };
408 OFP_ASSERT(sizeof(struct ofp13_meter_stats) == 40);
409
410 /* Body of reply to OFPMP13_METER_CONFIG request. Meter configuration. */
411 struct ofp13_meter_config {
412     ovs_be16          length;       /* Length of this entry. */
413     ovs_be16          flags;        /* Set of OFPMC_* that apply. */
414     ovs_be32          meter_id;     /* Meter instance. */
415     /* struct ofp13_meter_band_header bands[0];   The bands length is inferred
416                                                from the length field. */
417 };
418 OFP_ASSERT(sizeof(struct ofp13_meter_config) == 8);
419
420 /* Body of reply to OFPMP13_METER_FEATURES request. Meter features. */
421 struct ofp13_meter_features {
422     ovs_be32   max_meter;     /* Maximum number of meters. */
423     ovs_be32   band_types;    /* Bitmaps of OFPMBT13_* values supported. */
424     ovs_be32   capabilities;  /* Bitmaps of "ofp13_meter_flags". */
425     uint8_t    max_bands;     /* Maximum bands per meters */
426     uint8_t    max_color;     /* Maximum color value */
427     uint8_t    pad[2];
428 };
429 OFP_ASSERT(sizeof(struct ofp13_meter_features) == 16);
430
431 /* Asynchronous message configuration. */
432 /* The body of this is the same as nx_async_config */
433 /* OFPT_GET_ASYNC_REPLY or OFPT_SET_ASYNC. */
434 struct ofp13_async_config {
435     ovs_be32 packet_in_mask[2];   /* Bitmasks of OFPR_* values. */
436     ovs_be32 port_status_mask[2]; /* Bitmasks of OFPPR_* values. */
437     ovs_be32 flow_removed_mask[2];/* Bitmasks of OFPRR_* values. */
438 };
439 OFP_ASSERT(sizeof(struct ofp13_async_config) == 24);
440
441
442 /* Packet received on port (datapath -> controller). */
443 struct ofp13_packet_in {
444     struct ofp12_packet_in pi;
445     ovs_be64 cookie;          /* Cookie of the flow entry that was looked up */
446     /* Followed by:
447      *   - Match
448      *   - Exactly 2 all-zero padding bytes, then
449      *   - An Ethernet frame whose length is inferred from header.length.
450      * The padding bytes preceding the Ethernet frame ensure that the IP
451      * header (if any) following the Ethernet header is 32-bit aligned.
452      */
453     /* struct ofp12_match match; */
454     /* uint8_t pad[2];         Align to 64 bit + 16 bit */
455     /* uint8_t data[0];        Ethernet frame */
456 };
457 OFP_ASSERT(sizeof(struct ofp13_packet_in) == 16);
458
459
460 #endif /* openflow/openflow-1.3.h */