]> git.proxmox.com Git - mirror_ovs.git/blame - include/openvswitch/ofp-table.h
ovs-vswitchd: Implement OFPT_TABLE_FEATURES table modification request.
[mirror_ovs.git] / include / openvswitch / ofp-table.h
CommitLineData
0d71302e
BP
1/*
2 * Copyright (c) 2008-2017 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef OPENVSWITCH_OFP_TABLE_H
18#define OPENVSWITCH_OFP_TABLE_H 1
19
20#include <limits.h>
21#include "openflow/openflow.h"
22#include "openvswitch/meta-flow.h"
23#include "openvswitch/ofp-port.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
dfc77282
BP
29struct ofputil_table_stats;
30
0d71302e
BP
31/* Abstract version of OFPTC11_TABLE_MISS_*.
32 *
33 * OpenFlow 1.0 always sends packets that miss to the next flow table, or to
34 * the controller if they miss in the last flow table.
35 *
36 * OpenFlow 1.1 and 1.2 can configure table miss behavior via a "table-mod"
37 * that specifies "send to controller", "miss", or "drop".
38 *
39 * OpenFlow 1.3 and later never sends packets that miss to the controller.
40 */
41enum ofputil_table_miss {
42 /* Protocol-specific default behavior. On OpenFlow 1.0 through 1.2
43 * connections, the packet is sent to the controller, and on OpenFlow 1.3
44 * and later connections, the packet is dropped.
45 *
46 * This is also used as a result of decoding OpenFlow 1.3+ "config" values
47 * in table-mods, to indicate that no table-miss was specified. */
48 OFPUTIL_TABLE_MISS_DEFAULT, /* Protocol default behavior. */
49
50 /* These constants have the same meanings as those in OpenFlow with the
51 * same names. */
52 OFPUTIL_TABLE_MISS_CONTROLLER, /* Send to controller. */
53 OFPUTIL_TABLE_MISS_CONTINUE, /* Go to next table. */
54 OFPUTIL_TABLE_MISS_DROP, /* Drop the packet. */
55};
56
dfc77282
BP
57const char *ofputil_table_miss_to_string(enum ofputil_table_miss);
58
0d71302e
BP
59/* Abstract version of OFPTC14_EVICTION.
60 *
61 * OpenFlow 1.0 through 1.3 don't know anything about eviction, so decoding a
62 * message for one of these protocols always yields
63 * OFPUTIL_TABLE_EVICTION_DEFAULT. */
64enum ofputil_table_eviction {
65 OFPUTIL_TABLE_EVICTION_DEFAULT, /* No value. */
66 OFPUTIL_TABLE_EVICTION_ON, /* Enable eviction. */
67 OFPUTIL_TABLE_EVICTION_OFF /* Disable eviction. */
68};
69
dfc77282
BP
70const char *ofputil_table_eviction_to_string(enum ofputil_table_eviction);
71
0d71302e
BP
72/* Abstract version of OFPTC14_VACANCY_EVENTS.
73 *
74 * OpenFlow 1.0 through 1.3 don't know anything about vacancy events, so
75 * decoding a message for one of these protocols always yields
76 * OFPUTIL_TABLE_VACANCY_DEFAULT. */
77enum ofputil_table_vacancy {
78 OFPUTIL_TABLE_VACANCY_DEFAULT, /* No value. */
79 OFPUTIL_TABLE_VACANCY_ON, /* Enable vacancy events. */
80 OFPUTIL_TABLE_VACANCY_OFF /* Disable vacancy events. */
81};
82
dfc77282
BP
83const char *ofputil_table_vacancy_to_string(enum ofputil_table_vacancy);
84
0d71302e
BP
85/* Abstract version of OFPTMPT_VACANCY.
86 *
87 * Openflow 1.4+ defines vacancy events.
88 * The fields vacancy_down and vacancy_up are the threshold for generating
89 * vacancy events that should be configured on the flow table, expressed as
90 * a percent.
91 * The vacancy field is only used when this property in included in a
92 * OFPMP_TABLE_DESC multipart reply or a OFPT_TABLE_STATUS message and
93 * represent the current vacancy of the table, expressed as a percent. In
94 * OFP_TABLE_MOD requests, this field must be set to 0 */
95struct ofputil_table_mod_prop_vacancy {
96 uint8_t vacancy_down; /* Vacancy threshold when space decreases (%). */
97 uint8_t vacancy_up; /* Vacancy threshold when space increases (%). */
98 uint8_t vacancy; /* Current vacancy (%). */
99};
100
101/* Mapping between table numbers and names. */
102struct ofputil_table_map {
103 struct namemap map;
104};
105#define OFPUTIL_TABLE_MAP_INITIALIZER(MAP) { NAMEMAP_INITIALIZER((MAP).map) }
106
107void ofputil_table_map_init(struct ofputil_table_map *);
108const char *ofputil_table_map_get_name(const struct ofputil_table_map *,
109 uint8_t);
110uint8_t ofputil_table_map_get_number(const struct ofputil_table_map *,
111 const char *name);
112void ofputil_table_map_put(struct ofputil_table_map *,
113 uint8_t, const char *name);
114void ofputil_table_map_destroy(struct ofputil_table_map *);
115
116/* Table numbers. */
117bool ofputil_table_from_string(const char *, const struct ofputil_table_map *,
118 uint8_t *tablep);
119void ofputil_format_table(uint8_t table, const struct ofputil_table_map *,
120 struct ds *);
121void ofputil_table_to_string(uint8_t, const struct ofputil_table_map *,
122 char *namebuf, size_t bufsize);
123
124/* Abstract ofp_table_mod. */
125struct ofputil_table_mod {
126 uint8_t table_id; /* ID of the table, 0xff indicates all tables. */
127
128 /* OpenFlow 1.1 and 1.2 only. For other versions, ignored on encoding,
129 * decoded to OFPUTIL_TABLE_MISS_DEFAULT. */
130 enum ofputil_table_miss miss;
131
132 /* OpenFlow 1.4+ only. For other versions, ignored on encoding, decoded to
133 * OFPUTIL_TABLE_EVICTION_DEFAULT. */
134 enum ofputil_table_eviction eviction;
135
136 /* OpenFlow 1.4+ only and optional even there; UINT32_MAX indicates
137 * absence. For other versions, ignored on encoding, decoded to
138 * UINT32_MAX.*/
139 uint32_t eviction_flags; /* OFPTMPEF14_*. */
140
141 /* OpenFlow 1.4+ only. For other versions, ignored on encoding, decoded to
142 * OFPUTIL_TABLE_VACANCY_DEFAULT. */
143 enum ofputil_table_vacancy vacancy;
144
145 /* Openflow 1.4+ only. Defines threshold values of vacancy expressed as
146 * percent, value of current vacancy is set to zero for table-mod.
147 * For other versions, ignored on encoding, all values decoded to
148 * zero. */
149 struct ofputil_table_mod_prop_vacancy table_vacancy;
150};
151
0d71302e
BP
152enum ofperr ofputil_decode_table_mod(const struct ofp_header *,
153 struct ofputil_table_mod *);
154struct ofpbuf *ofputil_encode_table_mod(const struct ofputil_table_mod *,
155 enum ofputil_protocol);
dfc77282
BP
156void ofputil_table_mod_format(struct ds *, const struct ofputil_table_mod *,
157 const struct ofputil_table_map *);
4e413ac8 158char *parse_ofp_table_mod(struct ofputil_table_mod *, const char **namep,
0d71302e
BP
159 const char *table_id, const char *flow_miss_handling,
160 const struct ofputil_table_map *,
161 uint32_t *usable_versions)
162 OVS_WARN_UNUSED_RESULT;
163
dfc77282
BP
164/* Abstract ofp14_table_desc. */
165struct ofputil_table_desc {
166 uint8_t table_id; /* ID of the table. */
167 enum ofputil_table_eviction eviction;
168 uint32_t eviction_flags; /* UINT32_MAX if not present. */
169 enum ofputil_table_vacancy vacancy;
170 struct ofputil_table_mod_prop_vacancy table_vacancy;
171};
172
173int ofputil_decode_table_desc(struct ofpbuf *,
174 struct ofputil_table_desc *,
175 enum ofp_version);
176void ofputil_append_table_desc_reply(const struct ofputil_table_desc *td,
177 struct ovs_list *replies,
178 enum ofp_version);
179void ofputil_table_desc_format(struct ds *,
180 const struct ofputil_table_desc *,
181 const struct ofputil_table_map *);
182
0d71302e
BP
183/* Abstract ofp_table_features.
184 *
185 * This is used for all versions of OpenFlow, even though ofp_table_features
186 * was only introduced in OpenFlow 1.3, because earlier versions of OpenFlow
187 * include support for a subset of ofp_table_features through OFPST_TABLE (aka
188 * OFPMP_TABLE). */
189struct ofputil_table_features {
c332ed15
BP
190 /* Only for OFPT_TABLE_FEATURES requests and only the first table_features
191 * in such a request. */
192 enum ofp15_table_features_command command;
193
194 /* The following are always present in table features requests and
195 * replies. */
196 uint8_t table_id;
0d71302e
BP
197 char name[OFP_MAX_TABLE_NAME_LEN];
198 ovs_be64 metadata_match; /* Bits of metadata table can match. */
199 ovs_be64 metadata_write; /* Bits of metadata table can write. */
200 uint32_t max_entries; /* Max number of entries supported. */
201
c332ed15
BP
202 /* True if the message included any properties. This is important for
203 * OFPT_TABLE_FEATURES requests, which change table properties only if any
204 * are included. */
205 bool any_properties;
206
0d71302e
BP
207 /* Flags.
208 *
209 * 'miss_config' is relevant for OpenFlow 1.1 and 1.2 only, because those
210 * versions include OFPTC_MISS_* flags in OFPST_TABLE. For other versions,
211 * it is decoded to OFPUTIL_TABLE_MISS_DEFAULT and ignored for encoding.
212 *
213 * 'supports_eviction' and 'supports_vacancy_events' are relevant only for
214 * OpenFlow 1.4 and later only. For OF1.4, they are boolean: 1 if
215 * supported, otherwise 0. For other versions, they are decoded as -1 and
216 * ignored for encoding.
217 *
218 * Search for "OFPTC_* Table Configuration" in the documentation for more
219 * details of how OpenFlow has changed in this area.
220 */
221 enum ofputil_table_miss miss_config; /* OF1.1 and 1.2 only. */
222 int supports_eviction; /* OF1.4+ only. */
223 int supports_vacancy_events; /* OF1.4+ only. */
224
225 /* Table features related to instructions. There are two instances:
226 *
227 * - 'miss' reports features available in the table miss flow.
228 *
229 * - 'nonmiss' reports features available in other flows. */
230 struct ofputil_table_instruction_features {
231 /* Tables that "goto-table" may jump to. */
232 unsigned long int next[BITMAP_N_LONGS(255)];
233
234 /* Bitmap of OVSINST_* for supported instructions. */
235 uint32_t instructions;
236
237 /* Table features related to actions. There are two instances:
238 *
239 * - 'write' reports features available in a "write_actions"
240 * instruction.
241 *
242 * - 'apply' reports features available in an "apply_actions"
243 * instruction. */
244 struct ofputil_table_action_features {
245 uint64_t ofpacts; /* Bitmap of supported OFPACT_*. */
246 struct mf_bitmap set_fields; /* Fields for "set-field". */
247 } write, apply;
248 } nonmiss, miss;
249
250 /* MFF_* bitmaps.
251 *
252 * For any given field the following combinations are valid:
253 *
254 * - match=0, wildcard=0, mask=0: Flows in this table cannot match on
255 * this field.
256 *
257 * - match=1, wildcard=0, mask=0: Flows in this table must match on all
258 * the bits in this field.
259 *
260 * - match=1, wildcard=1, mask=0: Flows in this table must either match
261 * on all the bits in the field or wildcard the field entirely.
262 *
263 * - match=1, wildcard=1, mask=1: Flows in this table may arbitrarily
264 * mask this field (as special cases, they may match on all the bits
265 * or wildcard it entirely).
266 *
267 * Other combinations do not make sense.
268 */
269 struct mf_bitmap match; /* Fields that may be matched. */
270 struct mf_bitmap mask; /* Subset of 'match' that may have masks. */
271 struct mf_bitmap wildcard; /* Subset of 'match' that may be wildcarded. */
272};
273
4e413ac8
BP
274int ofputil_decode_table_features(
275 struct ofpbuf *, struct ofputil_table_features *,
276 struct ofpbuf *raw_properties);
0d71302e 277
0d71302e
BP
278struct ofpbuf *ofputil_encode_table_features_request(enum ofp_version);
279
280struct ofpbuf *ofputil_encode_table_desc_request(enum ofp_version);
281
4e413ac8
BP
282void ofputil_append_table_features(
283 const struct ofputil_table_features *tf,
284 const struct ofpbuf *raw_properties,
285 struct ovs_list *msgs);
0d71302e 286
dfc77282
BP
287void ofputil_table_features_format(
288 struct ds *, const struct ofputil_table_features *features,
289 const struct ofputil_table_features *prev_features,
290 const struct ofputil_table_stats *stats,
291 const struct ofputil_table_stats *prev_stats,
9d36d7d7
BP
292 int *first_ditto, int *last_ditto);
293void ofputil_table_features_format_finish(struct ds *,
294 int first_ditto, int last_ditto);
4e413ac8
BP
295
296bool ofputil_table_features_are_superset(
297 const struct ofputil_table_features *super,
298 const struct ofputil_table_features *sub);
0d71302e
BP
299
300/* Abstract table stats.
301 *
302 * This corresponds to the OpenFlow 1.3 table statistics structure, which only
303 * includes actual statistics. In earlier versions of OpenFlow, several
304 * members describe table features, so this structure has to be paired with
305 * struct ofputil_table_features to get all information. */
306struct ofputil_table_stats {
307 uint8_t table_id; /* Identifier of table. */
308 uint32_t active_count; /* Number of active entries. */
309 uint64_t lookup_count; /* Number of packets looked up in table. */
310 uint64_t matched_count; /* Number of packets that hit table. */
311};
312
313struct ofpbuf *ofputil_encode_table_stats_reply(const struct ofp_header *rq);
314
315struct ofpbuf *ofputil_encode_table_desc_reply(const struct ofp_header *rq);
316
317void ofputil_append_table_stats_reply(struct ofpbuf *reply,
318 const struct ofputil_table_stats *,
319 const struct ofputil_table_features *);
320
321int ofputil_decode_table_stats_reply(struct ofpbuf *reply,
322 struct ofputil_table_stats *,
323 struct ofputil_table_features *);
324
325/* Abstract ofp14_table_status. */
326struct ofputil_table_status {
327 enum ofp14_table_reason reason; /* One of OFPTR_*. */
328 struct ofputil_table_desc desc; /* New table config. */
329};
330
fe2c69f4
BP
331const char *ofp_table_reason_to_string(enum ofp14_table_reason,
332 char *reasonbuf, size_t bufsize);
333
0d71302e
BP
334enum ofperr ofputil_decode_table_status(const struct ofp_header *,
335 struct ofputil_table_status *);
336struct ofpbuf *ofputil_encode_table_status(const struct ofputil_table_status *,
337 enum ofputil_protocol);
fe2c69f4
BP
338void ofputil_format_table_status(struct ds *,
339 const struct ofputil_table_status *,
340 const struct ofputil_table_map *);
0d71302e
BP
341
342#ifdef __cplusplus
343}
344#endif
345
346#endif /* ofp-table.h */