2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <sys/types.h>
21 #include <netinet/in.h>
26 #include "classifier.h"
28 #include "meta-flow.h"
48 /* Needed for the lock annotations. */
49 extern struct ovs_mutex ofproto_mutex;
51 struct ofproto_controller_info {
53 enum ofp12_controller_role role;
56 const char *values[4];
61 struct ofproto_sflow_options {
63 uint32_t sampling_rate;
64 uint32_t polling_interval;
71 struct ofproto_ipfix_bridge_exporter_options {
73 uint32_t sampling_rate;
74 uint32_t obs_domain_id; /* Bridge-wide Observation Domain ID. */
75 uint32_t obs_point_id; /* Bridge-wide Observation Point ID. */
76 uint32_t cache_active_timeout;
77 uint32_t cache_max_flows;
80 struct ofproto_ipfix_flow_exporter_options {
81 uint32_t collector_set_id;
83 uint32_t cache_active_timeout;
84 uint32_t cache_max_flows;
87 struct ofproto_stp_settings {
88 stp_identifier system_id;
95 struct ofproto_stp_status {
96 bool enabled; /* If false, ignore other members. */
97 stp_identifier bridge_id;
98 stp_identifier designated_root;
102 struct ofproto_port_stp_settings {
104 uint8_t port_num; /* In the range 1-255, inclusive. */
109 struct ofproto_port_stp_status {
110 bool enabled; /* If false, ignore other members. */
112 enum stp_state state;
113 unsigned int sec_in_state;
117 struct ofproto_port_stp_stats {
118 bool enabled; /* If false, ignore other members. */
119 int tx_count; /* Number of BPDUs transmitted. */
120 int rx_count; /* Number of valid BPDUs received. */
121 int error_count; /* Number of bad BPDUs received. */
124 struct ofproto_port_queue {
125 uint32_t queue; /* Queue ID. */
126 uint8_t dscp; /* DSCP bits (e.g. [0, 63]). */
129 struct ofproto_mcast_snooping_settings {
130 bool flood_unreg; /* If true, flood unregistered packets to all
131 all ports. If false, send only to ports
132 connected to multicast routers. */
133 unsigned int idle_time; /* Entry is removed after the idle time
135 unsigned int max_entries; /* Size of the multicast snooping table. */
138 /* How the switch should act if the controller cannot be contacted. */
139 enum ofproto_fail_mode {
140 OFPROTO_FAIL_SECURE, /* Preserve flow table. */
141 OFPROTO_FAIL_STANDALONE /* Act as a standalone switch. */
145 OFPROTO_IN_BAND, /* In-band connection to controller. */
146 OFPROTO_OUT_OF_BAND /* Out-of-band connection to controller. */
149 struct ofproto_controller {
150 char *target; /* e.g. "tcp:127.0.0.1" */
151 int max_backoff; /* Maximum reconnection backoff, in seconds. */
152 int probe_interval; /* Max idle time before probing, in seconds. */
153 enum ofproto_band band; /* In-band or out-of-band? */
154 bool enable_async_msgs; /* Initially enable asynchronous messages? */
156 /* OpenFlow packet-in rate-limiting. */
157 int rate_limit; /* Max packet-in rate in packets per second. */
158 int burst_limit; /* Limit on accumulating packet credits. */
160 uint8_t dscp; /* DSCP value for controller connection. */
163 void ofproto_enumerate_types(struct sset *types);
164 const char *ofproto_normalize_type(const char *);
166 int ofproto_enumerate_names(const char *type, struct sset *names);
167 void ofproto_parse_name(const char *name, char **dp_name, char **dp_type);
169 /* An interface hint element, which is used by ofproto_init() to
170 * describe the caller's understanding of the startup state. */
172 char *br_name; /* Name of owning bridge. */
173 char *br_type; /* Type of owning bridge. */
174 ofp_port_t ofp_port; /* OpenFlow port number. */
177 void ofproto_init(const struct shash *iface_hints);
179 int ofproto_type_run(const char *datapath_type);
180 void ofproto_type_wait(const char *datapath_type);
182 int ofproto_create(const char *datapath, const char *datapath_type,
183 struct ofproto **ofprotop);
184 void ofproto_destroy(struct ofproto *);
185 int ofproto_delete(const char *name, const char *type);
187 int ofproto_run(struct ofproto *);
188 void ofproto_wait(struct ofproto *);
189 bool ofproto_is_alive(const struct ofproto *);
191 void ofproto_get_memory_usage(const struct ofproto *, struct simap *);
192 void ofproto_type_get_memory_usage(const char *datapath_type, struct simap *);
194 /* A port within an OpenFlow switch.
196 * 'name' and 'type' are suitable for passing to netdev_open(). */
197 struct ofproto_port {
198 char *name; /* Network device name, e.g. "eth0". */
199 char *type; /* Network device type, e.g. "system". */
200 ofp_port_t ofp_port; /* OpenFlow port number. */
202 void ofproto_port_clone(struct ofproto_port *, const struct ofproto_port *);
203 void ofproto_port_destroy(struct ofproto_port *);
205 struct ofproto_port_dump {
206 const struct ofproto *ofproto;
210 void ofproto_port_dump_start(struct ofproto_port_dump *,
211 const struct ofproto *);
212 bool ofproto_port_dump_next(struct ofproto_port_dump *, struct ofproto_port *);
213 int ofproto_port_dump_done(struct ofproto_port_dump *);
215 /* Iterates through each OFPROTO_PORT in OFPROTO, using DUMP as state.
217 * Arguments all have pointer type.
219 * If you break out of the loop, then you need to free the dump structure by
220 * hand using ofproto_port_dump_done(). */
221 #define OFPROTO_PORT_FOR_EACH(OFPROTO_PORT, DUMP, OFPROTO) \
222 for (ofproto_port_dump_start(DUMP, OFPROTO); \
223 (ofproto_port_dump_next(DUMP, OFPROTO_PORT) \
225 : (ofproto_port_dump_done(DUMP), false)); \
228 #define OFPROTO_FLOW_LIMIT_DEFAULT 200000
229 #define OFPROTO_MAX_IDLE_DEFAULT 1500
231 const char *ofproto_port_open_type(const char *datapath_type,
232 const char *port_type);
233 int ofproto_port_add(struct ofproto *, struct netdev *, ofp_port_t *ofp_portp);
234 int ofproto_port_del(struct ofproto *, ofp_port_t ofp_port);
235 int ofproto_port_get_stats(const struct ofport *, struct netdev_stats *stats);
237 int ofproto_port_query_by_name(const struct ofproto *, const char *devname,
238 struct ofproto_port *);
240 /* Top-level configuration. */
241 uint64_t ofproto_get_datapath_id(const struct ofproto *);
242 void ofproto_set_datapath_id(struct ofproto *, uint64_t datapath_id);
243 void ofproto_set_controllers(struct ofproto *,
244 const struct ofproto_controller *, size_t n,
245 uint32_t allowed_versions);
246 void ofproto_set_fail_mode(struct ofproto *, enum ofproto_fail_mode fail_mode);
247 void ofproto_reconnect_controllers(struct ofproto *);
248 void ofproto_set_extra_in_band_remotes(struct ofproto *,
249 const struct sockaddr_in *, size_t n);
250 void ofproto_set_in_band_queue(struct ofproto *, int queue_id);
251 void ofproto_set_flow_limit(unsigned limit);
252 void ofproto_set_max_idle(unsigned max_idle);
253 void ofproto_set_forward_bpdu(struct ofproto *, bool forward_bpdu);
254 void ofproto_set_mac_table_config(struct ofproto *, unsigned idle_time,
256 int ofproto_set_mcast_snooping(struct ofproto *ofproto,
257 const struct ofproto_mcast_snooping_settings *s);
258 int ofproto_port_set_mcast_snooping(struct ofproto *ofproto, void *aux,
260 void ofproto_set_threads(int n_handlers, int n_revalidators);
261 void ofproto_set_dp_desc(struct ofproto *, const char *dp_desc);
262 int ofproto_set_snoops(struct ofproto *, const struct sset *snoops);
263 int ofproto_set_netflow(struct ofproto *,
264 const struct netflow_options *nf_options);
265 int ofproto_set_sflow(struct ofproto *, const struct ofproto_sflow_options *);
266 int ofproto_set_ipfix(struct ofproto *,
267 const struct ofproto_ipfix_bridge_exporter_options *,
268 const struct ofproto_ipfix_flow_exporter_options *,
270 void ofproto_set_flow_restore_wait(bool flow_restore_wait_db);
271 bool ofproto_get_flow_restore_wait(void);
272 int ofproto_set_stp(struct ofproto *, const struct ofproto_stp_settings *);
273 int ofproto_get_stp_status(struct ofproto *, struct ofproto_stp_status *);
275 /* Configuration of ports. */
276 void ofproto_port_unregister(struct ofproto *, ofp_port_t ofp_port);
278 void ofproto_port_clear_cfm(struct ofproto *, ofp_port_t ofp_port);
279 void ofproto_port_set_cfm(struct ofproto *, ofp_port_t ofp_port,
280 const struct cfm_settings *);
281 void ofproto_port_set_bfd(struct ofproto *, ofp_port_t ofp_port,
282 const struct smap *cfg);
283 bool ofproto_port_bfd_status_changed(struct ofproto *, ofp_port_t ofp_port);
284 int ofproto_port_get_bfd_status(struct ofproto *, ofp_port_t ofp_port,
286 int ofproto_port_is_lacp_current(struct ofproto *, ofp_port_t ofp_port);
287 int ofproto_port_set_stp(struct ofproto *, ofp_port_t ofp_port,
288 const struct ofproto_port_stp_settings *);
289 int ofproto_port_get_stp_status(struct ofproto *, ofp_port_t ofp_port,
290 struct ofproto_port_stp_status *);
291 int ofproto_port_get_stp_stats(struct ofproto *, ofp_port_t ofp_port,
292 struct ofproto_port_stp_stats *);
293 int ofproto_port_set_queues(struct ofproto *, ofp_port_t ofp_port,
294 const struct ofproto_port_queue *,
297 /* The behaviour of the port regarding VLAN handling */
298 enum port_vlan_mode {
299 /* This port is an access port. 'vlan' is the VLAN ID. 'trunks' is
303 /* This port is a trunk. 'trunks' is the set of trunks. 'vlan' is
307 /* Untagged incoming packets are part of 'vlan', as are incoming packets
308 * tagged with 'vlan'. Outgoing packets tagged with 'vlan' stay tagged.
309 * Other VLANs in 'trunks' are trunked. */
310 PORT_VLAN_NATIVE_TAGGED,
312 /* Untagged incoming packets are part of 'vlan', as are incoming packets
313 * tagged with 'vlan'. Outgoing packets tagged with 'vlan' are untagged.
314 * Other VLANs in 'trunks' are trunked. */
315 PORT_VLAN_NATIVE_UNTAGGED
318 /* Configuration of bundles. */
319 struct ofproto_bundle_settings {
320 char *name; /* For use in log messages. */
322 ofp_port_t *slaves; /* OpenFlow port numbers for slaves. */
325 enum port_vlan_mode vlan_mode; /* Selects mode for vlan and trunks */
326 int vlan; /* VLAN VID, except for PORT_VLAN_TRUNK. */
327 unsigned long *trunks; /* vlan_bitmap, except for PORT_VLAN_ACCESS. */
328 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
330 struct bond_settings *bond; /* Must be nonnull iff if n_slaves > 1. */
332 struct lacp_settings *lacp; /* Nonnull to enable LACP. */
333 struct lacp_slave_settings *lacp_slaves; /* Array of n_slaves elements. */
335 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
337 * This is deprecated. It is only for compatibility with broken device
338 * drivers in old versions of Linux that do not properly support VLANs when
339 * VLAN devices are not used. When broken device drivers are no longer in
340 * widespread use, we will delete these interfaces. */
341 ofp_port_t realdev_ofp_port;/* OpenFlow port number of real device. */
344 int ofproto_bundle_register(struct ofproto *, void *aux,
345 const struct ofproto_bundle_settings *);
346 int ofproto_bundle_unregister(struct ofproto *, void *aux);
348 /* Configuration of mirrors. */
349 struct ofproto_mirror_settings {
350 /* Name for log messages. */
353 /* Bundles that select packets for mirroring upon ingress. */
354 void **srcs; /* A set of registered ofbundle handles. */
357 /* Bundles that select packets for mirroring upon egress. */
358 void **dsts; /* A set of registered ofbundle handles. */
361 /* VLANs of packets to select for mirroring. */
362 unsigned long *src_vlans; /* vlan_bitmap, NULL selects all VLANs. */
364 /* Output (mutually exclusive). */
365 void *out_bundle; /* A registered ofbundle handle or NULL. */
366 uint16_t out_vlan; /* Output VLAN, only if out_bundle is NULL. */
369 int ofproto_mirror_register(struct ofproto *, void *aux,
370 const struct ofproto_mirror_settings *);
371 int ofproto_mirror_unregister(struct ofproto *, void *aux);
372 int ofproto_mirror_get_stats(struct ofproto *, void *aux,
373 uint64_t *packets, uint64_t *bytes);
375 int ofproto_set_flood_vlans(struct ofproto *, unsigned long *flood_vlans);
376 bool ofproto_is_mirror_output_bundle(const struct ofproto *, void *aux);
378 /* Configuration of OpenFlow tables. */
379 struct ofproto_table_settings {
380 char *name; /* Name exported via OpenFlow or NULL. */
381 unsigned int max_flows; /* Maximum number of flows or UINT_MAX. */
383 /* These members determine the handling of an attempt to add a flow that
384 * would cause the table to have more than 'max_flows' flows.
386 * If 'groups' is NULL, overflows will be rejected with an error.
388 * If 'groups' is nonnull, an overflow will cause a flow to be removed.
389 * The flow to be removed is chosen to give fairness among groups
390 * distinguished by different values for the subfields within 'groups'. */
391 struct mf_subfield *groups;
395 * Fields for which prefix trie lookup is maintained.
397 unsigned int n_prefix_fields;
398 enum mf_field_id prefix_fields[CLS_MAX_TRIES];
401 extern const enum mf_field_id default_prefix_fields[2];
402 BUILD_ASSERT_DECL(ARRAY_SIZE(default_prefix_fields) <= CLS_MAX_TRIES);
404 int ofproto_get_n_tables(const struct ofproto *);
405 uint8_t ofproto_get_n_visible_tables(const struct ofproto *);
406 void ofproto_configure_table(struct ofproto *, int table_id,
407 const struct ofproto_table_settings *);
409 /* Configuration querying. */
410 bool ofproto_has_snoops(const struct ofproto *);
411 void ofproto_get_snoops(const struct ofproto *, struct sset *);
412 void ofproto_get_all_flows(struct ofproto *p, struct ds *);
413 void ofproto_get_netflow_ids(const struct ofproto *,
414 uint8_t *engine_type, uint8_t *engine_id);
416 void ofproto_get_ofproto_controller_info(const struct ofproto *, struct shash *);
417 void ofproto_free_ofproto_controller_info(struct shash *);
419 bool ofproto_port_cfm_status_changed(struct ofproto *, ofp_port_t ofp_port);
421 int ofproto_port_get_cfm_status(const struct ofproto *,
423 struct cfm_status *);
425 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
427 * This is deprecated. It is only for compatibility with broken device drivers
428 * in old versions of Linux that do not properly support VLANs when VLAN
429 * devices are not used. When broken device drivers are no longer in
430 * widespread use, we will delete these interfaces. */
432 void ofproto_get_vlan_usage(struct ofproto *, unsigned long int *vlan_bitmap);
433 bool ofproto_has_vlan_usage_changed(const struct ofproto *);
434 int ofproto_port_set_realdev(struct ofproto *, ofp_port_t vlandev_ofp_port,
435 ofp_port_t realdev_ofp_port, int vid);
437 /* Table configuration */
439 enum ofproto_table_config {
440 /* Send to controller. */
441 OFPROTO_TABLE_MISS_CONTROLLER = OFPTC11_TABLE_MISS_CONTROLLER,
443 /* Continue to the next table in the pipeline (OpenFlow 1.0 behavior). */
444 OFPROTO_TABLE_MISS_CONTINUE = OFPTC11_TABLE_MISS_CONTINUE,
446 /* Drop the packet. */
447 OFPROTO_TABLE_MISS_DROP = OFPTC11_TABLE_MISS_DROP,
449 /* The default miss behaviour for the OpenFlow version of the controller a
450 * packet_in message would be sent to.. For pre-OF1.3 controllers, send
451 * packet_in to controller. For OF1.3+ controllers, drop. */
452 OFPROTO_TABLE_MISS_DEFAULT = 3,
455 enum ofproto_table_config ofproto_table_get_config(const struct ofproto *,
462 #endif /* ofproto.h */