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.
19 #include "ofproto/ofproto-dpif.h"
20 #include "ofproto/ofproto-provider.h"
27 #include "byte-order.h"
28 #include "connectivity.h"
33 #include "dynamic-string.h"
34 #include "fail-open.h"
35 #include "guarded-list.h"
39 #include "mac-learning.h"
40 #include "mcast-snooping.h"
41 #include "meta-flow.h"
42 #include "multipath.h"
43 #include "netdev-vport.h"
48 #include "odp-execute.h"
51 #include "ofp-actions.h"
52 #include "ofp-parse.h"
53 #include "ofp-print.h"
54 #include "ofproto-dpif-ipfix.h"
55 #include "ofproto-dpif-mirror.h"
56 #include "ofproto-dpif-monitor.h"
57 #include "ofproto-dpif-rid.h"
58 #include "ofproto-dpif-sflow.h"
59 #include "ofproto-dpif-upcall.h"
60 #include "ofproto-dpif-xlate.h"
61 #include "poll-loop.h"
67 #include "unaligned.h"
69 #include "vlan-bitmap.h"
72 VLOG_DEFINE_THIS_MODULE(ofproto_dpif);
74 COVERAGE_DEFINE(ofproto_dpif_expired);
75 COVERAGE_DEFINE(packet_in_overflow);
84 * - Do include packets and bytes from datapath flows which have not
85 * recently been processed by a revalidator. */
86 struct ovs_mutex stats_mutex;
87 struct dpif_flow_stats stats OVS_GUARDED;
89 /* If non-zero then the recirculation id that has
90 * been allocated for use with this rule.
91 * The recirculation id and associated internal flow should
92 * be freed when the rule is freed */
96 /* RULE_CAST() depends on this. */
97 BUILD_ASSERT_DECL(offsetof(struct rule_dpif, up) == 0);
99 static void rule_get_stats(struct rule *, uint64_t *packets, uint64_t *bytes,
100 long long int *used);
101 static struct rule_dpif *rule_dpif_cast(const struct rule *);
102 static void rule_expire(struct rule_dpif *);
109 * - Do include packets and bytes from datapath flows which have not
110 * recently been processed by a revalidator. */
111 struct ovs_mutex stats_mutex;
112 uint64_t packet_count OVS_GUARDED; /* Number of packets received. */
113 uint64_t byte_count OVS_GUARDED; /* Number of bytes received. */
117 struct hmap_node hmap_node; /* In struct ofproto's "bundles" hmap. */
118 struct ofproto_dpif *ofproto; /* Owning ofproto. */
119 void *aux; /* Key supplied by ofproto's client. */
120 char *name; /* Identifier for log messages. */
123 struct list ports; /* Contains "struct ofport"s. */
124 enum port_vlan_mode vlan_mode; /* VLAN mode */
125 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
126 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
127 * NULL if all VLANs are trunked. */
128 struct lacp *lacp; /* LACP if LACP is enabled, otherwise NULL. */
129 struct bond *bond; /* Nonnull iff more than one port. */
130 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
133 bool floodable; /* True if no port has OFPUTIL_PC_NO_FLOOD set. */
136 static void bundle_remove(struct ofport *);
137 static void bundle_update(struct ofbundle *);
138 static void bundle_destroy(struct ofbundle *);
139 static void bundle_del_port(struct ofport_dpif *);
140 static void bundle_run(struct ofbundle *);
141 static void bundle_wait(struct ofbundle *);
143 static void stp_run(struct ofproto_dpif *ofproto);
144 static void stp_wait(struct ofproto_dpif *ofproto);
145 static int set_stp_port(struct ofport *,
146 const struct ofproto_port_stp_settings *);
148 static void rstp_run(struct ofproto_dpif *ofproto);
149 static void set_rstp_port(struct ofport *,
150 const struct ofproto_port_rstp_settings *);
153 struct hmap_node odp_port_node; /* In dpif_backer's "odp_to_ofport_map". */
157 struct ofbundle *bundle; /* Bundle that contains this port, if any. */
158 struct list bundle_node; /* In struct ofbundle's "ports" list. */
159 struct cfm *cfm; /* Connectivity Fault Management, if any. */
160 struct bfd *bfd; /* BFD, if any. */
161 bool may_enable; /* May be enabled in bonds. */
162 bool is_tunnel; /* This port is a tunnel. */
163 bool is_layer3; /* This is a layer 3 port. */
164 long long int carrier_seq; /* Carrier status changes. */
165 struct ofport_dpif *peer; /* Peer if patch port. */
168 struct stp_port *stp_port; /* Spanning Tree Protocol, if any. */
169 enum stp_state stp_state; /* Always STP_DISABLED if STP not in use. */
170 long long int stp_state_entered;
172 /* Rapid Spanning Tree. */
173 struct rstp_port *rstp_port; /* Rapid Spanning Tree Protocol, if any. */
174 enum rstp_state rstp_state; /* Always RSTP_DISABLED if RSTP not in use. */
176 /* Queue to DSCP mapping. */
177 struct ofproto_port_queue *qdscp;
180 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
182 * This is deprecated. It is only for compatibility with broken device
183 * drivers in old versions of Linux that do not properly support VLANs when
184 * VLAN devices are not used. When broken device drivers are no longer in
185 * widespread use, we will delete these interfaces. */
186 ofp_port_t realdev_ofp_port;
190 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
192 * This is deprecated. It is only for compatibility with broken device drivers
193 * in old versions of Linux that do not properly support VLANs when VLAN
194 * devices are not used. When broken device drivers are no longer in
195 * widespread use, we will delete these interfaces. */
196 struct vlan_splinter {
197 struct hmap_node realdev_vid_node;
198 struct hmap_node vlandev_node;
199 ofp_port_t realdev_ofp_port;
200 ofp_port_t vlandev_ofp_port;
204 static void vsp_remove(struct ofport_dpif *);
205 static void vsp_add(struct ofport_dpif *, ofp_port_t realdev_ofp_port, int vid);
207 static odp_port_t ofp_port_to_odp_port(const struct ofproto_dpif *,
210 static ofp_port_t odp_port_to_ofp_port(const struct ofproto_dpif *,
213 static struct ofport_dpif *
214 ofport_dpif_cast(const struct ofport *ofport)
216 return ofport ? CONTAINER_OF(ofport, struct ofport_dpif, up) : NULL;
219 static void port_run(struct ofport_dpif *);
220 static int set_bfd(struct ofport *, const struct smap *);
221 static int set_cfm(struct ofport *, const struct cfm_settings *);
222 static void ofport_update_peer(struct ofport_dpif *);
224 /* Reasons that we might need to revalidate every datapath flow, and
225 * corresponding coverage counters.
227 * A value of 0 means that there is no need to revalidate.
229 * It would be nice to have some cleaner way to integrate with coverage
230 * counters, but with only a few reasons I guess this is good enough for
232 enum revalidate_reason {
233 REV_RECONFIGURE = 1, /* Switch configuration changed. */
234 REV_STP, /* Spanning tree protocol port status change. */
235 REV_RSTP, /* RSTP port status change. */
236 REV_BOND, /* Bonding changed. */
237 REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/
238 REV_FLOW_TABLE, /* Flow table changed. */
239 REV_MAC_LEARNING, /* Mac learning changed. */
240 REV_MCAST_SNOOPING, /* Multicast snooping changed. */
242 COVERAGE_DEFINE(rev_reconfigure);
243 COVERAGE_DEFINE(rev_stp);
244 COVERAGE_DEFINE(rev_rstp);
245 COVERAGE_DEFINE(rev_bond);
246 COVERAGE_DEFINE(rev_port_toggled);
247 COVERAGE_DEFINE(rev_flow_table);
248 COVERAGE_DEFINE(rev_mac_learning);
249 COVERAGE_DEFINE(rev_mcast_snooping);
251 /* All datapaths of a given type share a single dpif backer instance. */
258 struct ovs_rwlock odp_to_ofport_lock;
259 struct hmap odp_to_ofport_map OVS_GUARDED; /* Contains "struct ofport"s. */
261 struct simap tnl_backers; /* Set of dpif ports backing tunnels. */
263 enum revalidate_reason need_revalidate; /* Revalidate all flows. */
265 bool recv_set_enable; /* Enables or disables receiving packets. */
268 struct recirc_id_pool *rid_pool; /* Recirculation ID pool. */
269 bool enable_recirc; /* True if the datapath supports recirculation */
271 /* True if the datapath supports variable-length
272 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions.
273 * False if the datapath supports only 8-byte (or shorter) userdata. */
274 bool variable_length_userdata;
276 /* Maximum number of MPLS label stack entries that the datapath supports
278 size_t max_mpls_depth;
281 /* All existing ofproto_backer instances, indexed by ofproto->up.type. */
282 static struct shash all_dpif_backers = SHASH_INITIALIZER(&all_dpif_backers);
284 struct ofproto_dpif {
285 struct hmap_node all_ofproto_dpifs_node; /* In 'all_ofproto_dpifs'. */
287 struct dpif_backer *backer;
289 uint64_t dump_seq; /* Last read of udpif_dump_seq(). */
291 /* Special OpenFlow rules. */
292 struct rule_dpif *miss_rule; /* Sends flow table misses to controller. */
293 struct rule_dpif *no_packet_in_rule; /* Drops flow table misses. */
294 struct rule_dpif *drop_frags_rule; /* Used in OFPC_FRAG_DROP mode. */
297 struct netflow *netflow;
298 struct dpif_sflow *sflow;
299 struct dpif_ipfix *ipfix;
300 struct hmap bundles; /* Contains "struct ofbundle"s. */
301 struct mac_learning *ml;
302 struct mcast_snooping *ms;
303 bool has_bonded_bundles;
305 struct mbridge *mbridge;
307 struct ovs_mutex stats_mutex;
308 struct netdev_stats stats OVS_GUARDED; /* To account packets generated and
309 * consumed in userspace. */
313 long long int stp_last_tick;
315 /* Rapid Spanning Tree. */
317 long long int rstp_last_tick;
319 /* VLAN splinters. */
320 struct ovs_mutex vsp_mutex;
321 struct hmap realdev_vid_map OVS_GUARDED; /* (realdev,vid) -> vlandev. */
322 struct hmap vlandev_map OVS_GUARDED; /* vlandev -> (realdev,vid). */
325 struct sset ports; /* Set of standard port names. */
326 struct sset ghost_ports; /* Ports with no datapath port. */
327 struct sset port_poll_set; /* Queued names for port_poll() reply. */
328 int port_poll_errno; /* Last errno for port_poll() reply. */
329 uint64_t change_seq; /* Connectivity status changes. */
332 struct guarded_list pins; /* Contains "struct ofputil_packet_in"s. */
333 struct seq *pins_seq; /* For notifying 'pins' reception. */
337 /* All existing ofproto_dpif instances, indexed by ->up.name. */
338 static struct hmap all_ofproto_dpifs = HMAP_INITIALIZER(&all_ofproto_dpifs);
340 static void ofproto_dpif_unixctl_init(void);
342 static inline struct ofproto_dpif *
343 ofproto_dpif_cast(const struct ofproto *ofproto)
345 ovs_assert(ofproto->ofproto_class == &ofproto_dpif_class);
346 return CONTAINER_OF(ofproto, struct ofproto_dpif, up);
350 ofproto_dpif_get_max_mpls_depth(const struct ofproto_dpif *ofproto)
352 return ofproto->backer->max_mpls_depth;
356 ofproto_dpif_get_enable_recirc(const struct ofproto_dpif *ofproto)
358 return ofproto->backer->enable_recirc;
361 static struct ofport_dpif *get_ofp_port(const struct ofproto_dpif *ofproto,
362 ofp_port_t ofp_port);
363 static void ofproto_trace(struct ofproto_dpif *, struct flow *,
364 const struct ofpbuf *packet,
365 const struct ofpact[], size_t ofpacts_len,
368 /* Global variables. */
369 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
371 /* Initial mappings of port to bridge mappings. */
372 static struct shash init_ofp_ports = SHASH_INITIALIZER(&init_ofp_ports);
374 /* Executes 'fm'. The caller retains ownership of 'fm' and everything in
377 ofproto_dpif_flow_mod(struct ofproto_dpif *ofproto,
378 struct ofputil_flow_mod *fm)
380 ofproto_flow_mod(&ofproto->up, fm);
383 /* Appends 'pin' to the queue of "packet ins" to be sent to the controller.
384 * Takes ownership of 'pin' and pin->packet. */
386 ofproto_dpif_send_packet_in(struct ofproto_dpif *ofproto,
387 struct ofproto_packet_in *pin)
389 if (!guarded_list_push_back(&ofproto->pins, &pin->list_node, 1024)) {
390 COVERAGE_INC(packet_in_overflow);
391 free(CONST_CAST(void *, pin->up.packet));
395 /* Wakes up main thread for packet-in I/O. */
396 seq_change(ofproto->pins_seq);
399 /* The default "table-miss" behaviour for OpenFlow1.3+ is to drop the
400 * packet rather than to send the packet to the controller.
402 * This function returns false to indicate that a packet_in message
403 * for a "table-miss" should be sent to at least one controller.
404 * False otherwise. */
406 ofproto_dpif_wants_packet_in_on_miss(struct ofproto_dpif *ofproto)
408 return connmgr_wants_packet_in_on_miss(ofproto->up.connmgr);
411 /* Factory functions. */
414 init(const struct shash *iface_hints)
416 struct shash_node *node;
418 /* Make a local copy, since we don't own 'iface_hints' elements. */
419 SHASH_FOR_EACH(node, iface_hints) {
420 const struct iface_hint *orig_hint = node->data;
421 struct iface_hint *new_hint = xmalloc(sizeof *new_hint);
423 new_hint->br_name = xstrdup(orig_hint->br_name);
424 new_hint->br_type = xstrdup(orig_hint->br_type);
425 new_hint->ofp_port = orig_hint->ofp_port;
427 shash_add(&init_ofp_ports, node->name, new_hint);
432 enumerate_types(struct sset *types)
434 dp_enumerate_types(types);
438 enumerate_names(const char *type, struct sset *names)
440 struct ofproto_dpif *ofproto;
443 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
444 if (strcmp(type, ofproto->up.type)) {
447 sset_add(names, ofproto->up.name);
454 del(const char *type, const char *name)
459 error = dpif_open(name, type, &dpif);
461 error = dpif_delete(dpif);
468 port_open_type(const char *datapath_type, const char *port_type)
470 return dpif_port_open_type(datapath_type, port_type);
473 /* Type functions. */
475 static void process_dpif_port_changes(struct dpif_backer *);
476 static void process_dpif_all_ports_changed(struct dpif_backer *);
477 static void process_dpif_port_change(struct dpif_backer *,
478 const char *devname);
479 static void process_dpif_port_error(struct dpif_backer *, int error);
481 static struct ofproto_dpif *
482 lookup_ofproto_dpif_by_port_name(const char *name)
484 struct ofproto_dpif *ofproto;
486 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
487 if (sset_contains(&ofproto->ports, name)) {
496 type_run(const char *type)
498 struct dpif_backer *backer;
500 backer = shash_find_data(&all_dpif_backers, type);
502 /* This is not necessarily a problem, since backers are only
503 * created on demand. */
507 dpif_run(backer->dpif);
508 udpif_run(backer->udpif);
510 /* If vswitchd started with other_config:flow_restore_wait set as "true",
511 * and the configuration has now changed to "false", enable receiving
512 * packets from the datapath. */
513 if (!backer->recv_set_enable && !ofproto_get_flow_restore_wait()) {
516 backer->recv_set_enable = true;
518 error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
520 VLOG_ERR("Failed to enable receiving packets in dpif.");
523 dpif_flow_flush(backer->dpif);
524 backer->need_revalidate = REV_RECONFIGURE;
527 if (backer->recv_set_enable) {
528 udpif_set_threads(backer->udpif, n_handlers, n_revalidators);
531 if (backer->need_revalidate) {
532 struct ofproto_dpif *ofproto;
533 struct simap_node *node;
534 struct simap tmp_backers;
536 /* Handle tunnel garbage collection. */
537 simap_init(&tmp_backers);
538 simap_swap(&backer->tnl_backers, &tmp_backers);
540 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
541 struct ofport_dpif *iter;
543 if (backer != ofproto->backer) {
547 HMAP_FOR_EACH (iter, up.hmap_node, &ofproto->up.ports) {
548 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
551 if (!iter->is_tunnel) {
555 dp_port = netdev_vport_get_dpif_port(iter->up.netdev,
556 namebuf, sizeof namebuf);
557 node = simap_find(&tmp_backers, dp_port);
559 simap_put(&backer->tnl_backers, dp_port, node->data);
560 simap_delete(&tmp_backers, node);
561 node = simap_find(&backer->tnl_backers, dp_port);
563 node = simap_find(&backer->tnl_backers, dp_port);
565 odp_port_t odp_port = ODPP_NONE;
567 if (!dpif_port_add(backer->dpif, iter->up.netdev,
569 simap_put(&backer->tnl_backers, dp_port,
570 odp_to_u32(odp_port));
571 node = simap_find(&backer->tnl_backers, dp_port);
576 iter->odp_port = node ? u32_to_odp(node->data) : ODPP_NONE;
577 if (tnl_port_reconfigure(iter, iter->up.netdev,
579 backer->need_revalidate = REV_RECONFIGURE;
584 SIMAP_FOR_EACH (node, &tmp_backers) {
585 dpif_port_del(backer->dpif, u32_to_odp(node->data));
587 simap_destroy(&tmp_backers);
589 switch (backer->need_revalidate) {
590 case REV_RECONFIGURE: COVERAGE_INC(rev_reconfigure); break;
591 case REV_STP: COVERAGE_INC(rev_stp); break;
592 case REV_RSTP: COVERAGE_INC(rev_rstp); break;
593 case REV_BOND: COVERAGE_INC(rev_bond); break;
594 case REV_PORT_TOGGLED: COVERAGE_INC(rev_port_toggled); break;
595 case REV_FLOW_TABLE: COVERAGE_INC(rev_flow_table); break;
596 case REV_MAC_LEARNING: COVERAGE_INC(rev_mac_learning); break;
597 case REV_MCAST_SNOOPING: COVERAGE_INC(rev_mcast_snooping); break;
599 backer->need_revalidate = 0;
601 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
602 struct ofport_dpif *ofport;
603 struct ofbundle *bundle;
605 if (ofproto->backer != backer) {
610 xlate_ofproto_set(ofproto, ofproto->up.name,
611 ofproto->backer->dpif, ofproto->miss_rule,
612 ofproto->no_packet_in_rule, ofproto->ml,
613 ofproto->stp, ofproto->rstp, ofproto->ms,
614 ofproto->mbridge, ofproto->sflow, ofproto->ipfix,
615 ofproto->netflow, ofproto->up.frag_handling,
616 ofproto->up.forward_bpdu,
617 connmgr_has_in_band(ofproto->up.connmgr),
618 ofproto->backer->enable_recirc,
619 ofproto->backer->variable_length_userdata,
620 ofproto->backer->max_mpls_depth);
622 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
623 xlate_bundle_set(ofproto, bundle, bundle->name,
624 bundle->vlan_mode, bundle->vlan,
625 bundle->trunks, bundle->use_priority_tags,
626 bundle->bond, bundle->lacp,
630 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
631 int stp_port = ofport->stp_port
632 ? stp_port_no(ofport->stp_port)
634 int rstp_port = ofport->rstp_port
635 ? rstp_port_number(ofport->rstp_port)
637 xlate_ofport_set(ofproto, ofport->bundle, ofport,
638 ofport->up.ofp_port, ofport->odp_port,
639 ofport->up.netdev, ofport->cfm,
640 ofport->bfd, ofport->peer, stp_port,
641 rstp_port, ofport->qdscp, ofport->n_qdscp,
642 ofport->up.pp.config, ofport->up.pp.state,
643 ofport->is_tunnel, ofport->may_enable);
648 udpif_revalidate(backer->udpif);
651 process_dpif_port_changes(backer);
656 /* Check for and handle port changes in 'backer''s dpif. */
658 process_dpif_port_changes(struct dpif_backer *backer)
664 error = dpif_port_poll(backer->dpif, &devname);
670 process_dpif_all_ports_changed(backer);
674 process_dpif_port_change(backer, devname);
679 process_dpif_port_error(backer, error);
686 process_dpif_all_ports_changed(struct dpif_backer *backer)
688 struct ofproto_dpif *ofproto;
689 struct dpif_port dpif_port;
690 struct dpif_port_dump dump;
691 struct sset devnames;
694 sset_init(&devnames);
695 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
696 if (ofproto->backer == backer) {
697 struct ofport *ofport;
699 HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
700 sset_add(&devnames, netdev_get_name(ofport->netdev));
704 DPIF_PORT_FOR_EACH (&dpif_port, &dump, backer->dpif) {
705 sset_add(&devnames, dpif_port.name);
708 SSET_FOR_EACH (devname, &devnames) {
709 process_dpif_port_change(backer, devname);
711 sset_destroy(&devnames);
715 process_dpif_port_change(struct dpif_backer *backer, const char *devname)
717 struct ofproto_dpif *ofproto;
718 struct dpif_port port;
720 /* Don't report on the datapath's device. */
721 if (!strcmp(devname, dpif_base_name(backer->dpif))) {
725 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node,
726 &all_ofproto_dpifs) {
727 if (simap_contains(&ofproto->backer->tnl_backers, devname)) {
732 ofproto = lookup_ofproto_dpif_by_port_name(devname);
733 if (dpif_port_query_by_name(backer->dpif, devname, &port)) {
734 /* The port was removed. If we know the datapath,
735 * report it through poll_set(). If we don't, it may be
736 * notifying us of a removal we initiated, so ignore it.
737 * If there's a pending ENOBUFS, let it stand, since
738 * everything will be reevaluated. */
739 if (ofproto && ofproto->port_poll_errno != ENOBUFS) {
740 sset_add(&ofproto->port_poll_set, devname);
741 ofproto->port_poll_errno = 0;
743 } else if (!ofproto) {
744 /* The port was added, but we don't know with which
745 * ofproto we should associate it. Delete it. */
746 dpif_port_del(backer->dpif, port.port_no);
748 struct ofport_dpif *ofport;
750 ofport = ofport_dpif_cast(shash_find_data(
751 &ofproto->up.port_by_name, devname));
753 && ofport->odp_port != port.port_no
754 && !odp_port_to_ofport(backer, port.port_no))
756 /* 'ofport''s datapath port number has changed from
757 * 'ofport->odp_port' to 'port.port_no'. Update our internal data
758 * structures to match. */
759 ovs_rwlock_wrlock(&backer->odp_to_ofport_lock);
760 hmap_remove(&backer->odp_to_ofport_map, &ofport->odp_port_node);
761 ofport->odp_port = port.port_no;
762 hmap_insert(&backer->odp_to_ofport_map, &ofport->odp_port_node,
763 hash_odp_port(port.port_no));
764 ovs_rwlock_unlock(&backer->odp_to_ofport_lock);
765 backer->need_revalidate = REV_RECONFIGURE;
768 dpif_port_destroy(&port);
771 /* Propagate 'error' to all ofprotos based on 'backer'. */
773 process_dpif_port_error(struct dpif_backer *backer, int error)
775 struct ofproto_dpif *ofproto;
777 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
778 if (ofproto->backer == backer) {
779 sset_clear(&ofproto->port_poll_set);
780 ofproto->port_poll_errno = error;
786 type_wait(const char *type)
788 struct dpif_backer *backer;
790 backer = shash_find_data(&all_dpif_backers, type);
792 /* This is not necessarily a problem, since backers are only
793 * created on demand. */
797 dpif_wait(backer->dpif);
800 /* Basic life-cycle. */
802 static int add_internal_flows(struct ofproto_dpif *);
804 static struct ofproto *
807 struct ofproto_dpif *ofproto = xmalloc(sizeof *ofproto);
812 dealloc(struct ofproto *ofproto_)
814 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
819 close_dpif_backer(struct dpif_backer *backer)
821 ovs_assert(backer->refcount > 0);
823 if (--backer->refcount) {
827 udpif_destroy(backer->udpif);
829 simap_destroy(&backer->tnl_backers);
830 ovs_rwlock_destroy(&backer->odp_to_ofport_lock);
831 hmap_destroy(&backer->odp_to_ofport_map);
832 shash_find_and_delete(&all_dpif_backers, backer->type);
833 recirc_id_pool_destroy(backer->rid_pool);
835 dpif_close(backer->dpif);
839 /* Datapath port slated for removal from datapath. */
841 struct list list_node;
845 static bool check_variable_length_userdata(struct dpif_backer *backer);
846 static size_t check_max_mpls_depth(struct dpif_backer *backer);
847 static bool check_recirc(struct dpif_backer *backer);
850 open_dpif_backer(const char *type, struct dpif_backer **backerp)
852 struct dpif_backer *backer;
853 struct dpif_port_dump port_dump;
854 struct dpif_port port;
855 struct shash_node *node;
856 struct list garbage_list;
857 struct odp_garbage *garbage, *next;
864 backer = shash_find_data(&all_dpif_backers, type);
871 backer_name = xasprintf("ovs-%s", type);
873 /* Remove any existing datapaths, since we assume we're the only
874 * userspace controlling the datapath. */
876 dp_enumerate_names(type, &names);
877 SSET_FOR_EACH(name, &names) {
878 struct dpif *old_dpif;
880 /* Don't remove our backer if it exists. */
881 if (!strcmp(name, backer_name)) {
885 if (dpif_open(name, type, &old_dpif)) {
886 VLOG_WARN("couldn't open old datapath %s to remove it", name);
888 dpif_delete(old_dpif);
889 dpif_close(old_dpif);
892 sset_destroy(&names);
894 backer = xmalloc(sizeof *backer);
896 error = dpif_create_and_open(backer_name, type, &backer->dpif);
899 VLOG_ERR("failed to open datapath of type %s: %s", type,
900 ovs_strerror(error));
904 backer->udpif = udpif_create(backer, backer->dpif);
906 backer->type = xstrdup(type);
907 backer->refcount = 1;
908 hmap_init(&backer->odp_to_ofport_map);
909 ovs_rwlock_init(&backer->odp_to_ofport_lock);
910 backer->need_revalidate = 0;
911 simap_init(&backer->tnl_backers);
912 backer->recv_set_enable = !ofproto_get_flow_restore_wait();
915 if (backer->recv_set_enable) {
916 dpif_flow_flush(backer->dpif);
919 /* Loop through the ports already on the datapath and remove any
920 * that we don't need anymore. */
921 list_init(&garbage_list);
922 dpif_port_dump_start(&port_dump, backer->dpif);
923 while (dpif_port_dump_next(&port_dump, &port)) {
924 node = shash_find(&init_ofp_ports, port.name);
925 if (!node && strcmp(port.name, dpif_base_name(backer->dpif))) {
926 garbage = xmalloc(sizeof *garbage);
927 garbage->odp_port = port.port_no;
928 list_push_front(&garbage_list, &garbage->list_node);
931 dpif_port_dump_done(&port_dump);
933 LIST_FOR_EACH_SAFE (garbage, next, list_node, &garbage_list) {
934 dpif_port_del(backer->dpif, garbage->odp_port);
935 list_remove(&garbage->list_node);
939 shash_add(&all_dpif_backers, type, backer);
941 backer->enable_recirc = check_recirc(backer);
942 backer->variable_length_userdata = check_variable_length_userdata(backer);
943 backer->max_mpls_depth = check_max_mpls_depth(backer);
944 backer->rid_pool = recirc_id_pool_create();
946 error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
948 VLOG_ERR("failed to listen on datapath of type %s: %s",
949 type, ovs_strerror(error));
950 close_dpif_backer(backer);
954 if (backer->recv_set_enable) {
955 udpif_set_threads(backer->udpif, n_handlers, n_revalidators);
961 /* Tests whether 'backer''s datapath supports recirculation. Only newer
962 * datapaths support OVS_KEY_ATTR_RECIRC_ID in keys. We need to disable some
963 * features on older datapaths that don't support this feature.
965 * Returns false if 'backer' definitely does not support recirculation, true if
966 * it seems to support recirculation or if at least the error we get is
969 check_recirc(struct dpif_backer *backer)
972 struct odputil_keybuf keybuf;
975 bool enable_recirc = false;
977 memset(&flow, 0, sizeof flow);
981 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
982 odp_flow_key_from_flow(&key, &flow, NULL, 0, true);
984 error = dpif_flow_put(backer->dpif, DPIF_FP_CREATE,
985 ofpbuf_data(&key), ofpbuf_size(&key), NULL, 0, NULL,
987 if (error && error != EEXIST) {
988 if (error != EINVAL) {
989 VLOG_WARN("%s: Reciculation flow probe failed (%s)",
990 dpif_name(backer->dpif), ovs_strerror(error));
995 error = dpif_flow_del(backer->dpif, ofpbuf_data(&key), ofpbuf_size(&key),
998 VLOG_WARN("%s: failed to delete recirculation feature probe flow",
999 dpif_name(backer->dpif));
1002 enable_recirc = true;
1005 if (enable_recirc) {
1006 VLOG_INFO("%s: Datapath supports recirculation",
1007 dpif_name(backer->dpif));
1009 VLOG_INFO("%s: Datapath does not support recirculation",
1010 dpif_name(backer->dpif));
1013 return enable_recirc;
1016 /* Tests whether 'backer''s datapath supports variable-length
1017 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. We need
1018 * to disable some features on older datapaths that don't support this
1021 * Returns false if 'backer' definitely does not support variable-length
1022 * userdata, true if it seems to support them or if at least the error we get
1025 check_variable_length_userdata(struct dpif_backer *backer)
1027 struct eth_header *eth;
1028 struct ofpbuf actions;
1029 struct dpif_execute execute;
1030 struct ofpbuf packet;
1034 /* Compose a userspace action that will cause an ERANGE error on older
1035 * datapaths that don't support variable-length userdata.
1037 * We really test for using userdata longer than 8 bytes, but older
1038 * datapaths accepted these, silently truncating the userdata to 8 bytes.
1039 * The same older datapaths rejected userdata shorter than 8 bytes, so we
1040 * test for that instead as a proxy for longer userdata support. */
1041 ofpbuf_init(&actions, 64);
1042 start = nl_msg_start_nested(&actions, OVS_ACTION_ATTR_USERSPACE);
1043 nl_msg_put_u32(&actions, OVS_USERSPACE_ATTR_PID,
1044 dpif_port_get_pid(backer->dpif, ODPP_NONE, 0));
1045 nl_msg_put_unspec_zero(&actions, OVS_USERSPACE_ATTR_USERDATA, 4);
1046 nl_msg_end_nested(&actions, start);
1048 /* Compose a dummy ethernet packet. */
1049 ofpbuf_init(&packet, ETH_HEADER_LEN);
1050 eth = ofpbuf_put_zeros(&packet, ETH_HEADER_LEN);
1051 eth->eth_type = htons(0x1234);
1053 /* Execute the actions. On older datapaths this fails with ERANGE, on
1054 * newer datapaths it succeeds. */
1055 execute.actions = ofpbuf_data(&actions);
1056 execute.actions_len = ofpbuf_size(&actions);
1057 execute.packet = &packet;
1058 execute.md = PKT_METADATA_INITIALIZER(0);
1059 execute.needs_help = false;
1061 error = dpif_execute(backer->dpif, &execute);
1063 ofpbuf_uninit(&packet);
1064 ofpbuf_uninit(&actions);
1071 /* Variable-length userdata is not supported. */
1072 VLOG_WARN("%s: datapath does not support variable-length userdata "
1073 "feature (needs Linux 3.10+ or kernel module from OVS "
1074 "1..11+). The NXAST_SAMPLE action will be ignored.",
1075 dpif_name(backer->dpif));
1079 /* Something odd happened. We're not sure whether variable-length
1080 * userdata is supported. Default to "yes". */
1081 VLOG_WARN("%s: variable-length userdata feature probe failed (%s)",
1082 dpif_name(backer->dpif), ovs_strerror(error));
1087 /* Tests the MPLS label stack depth supported by 'backer''s datapath.
1089 * Returns the number of elements in a struct flow's mpls_lse field
1090 * if the datapath supports at least that many entries in an
1092 * Otherwise returns the number of MPLS push actions supported by
1095 check_max_mpls_depth(struct dpif_backer *backer)
1100 for (n = 0; n < FLOW_MAX_MPLS_LABELS; n++) {
1101 struct odputil_keybuf keybuf;
1105 memset(&flow, 0, sizeof flow);
1106 flow.dl_type = htons(ETH_TYPE_MPLS);
1107 flow_set_mpls_bos(&flow, n, 1);
1109 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
1110 odp_flow_key_from_flow(&key, &flow, NULL, 0, false);
1112 error = dpif_flow_put(backer->dpif, DPIF_FP_CREATE,
1113 ofpbuf_data(&key), ofpbuf_size(&key), NULL, 0, NULL, 0, NULL);
1114 if (error && error != EEXIST) {
1115 if (error != EINVAL) {
1116 VLOG_WARN("%s: MPLS stack length feature probe failed (%s)",
1117 dpif_name(backer->dpif), ovs_strerror(error));
1122 error = dpif_flow_del(backer->dpif, ofpbuf_data(&key), ofpbuf_size(&key), NULL);
1124 VLOG_WARN("%s: failed to delete MPLS feature probe flow",
1125 dpif_name(backer->dpif));
1129 VLOG_INFO("%s: MPLS label stack length probed as %d",
1130 dpif_name(backer->dpif), n);
1135 construct(struct ofproto *ofproto_)
1137 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1138 struct shash_node *node, *next;
1141 error = open_dpif_backer(ofproto->up.type, &ofproto->backer);
1146 ofproto->netflow = NULL;
1147 ofproto->sflow = NULL;
1148 ofproto->ipfix = NULL;
1149 ofproto->stp = NULL;
1150 ofproto->rstp = NULL;
1151 ofproto->dump_seq = 0;
1152 hmap_init(&ofproto->bundles);
1153 ofproto->ml = mac_learning_create(MAC_ENTRY_DEFAULT_IDLE_TIME);
1155 ofproto->mbridge = mbridge_create();
1156 ofproto->has_bonded_bundles = false;
1157 ofproto->lacp_enabled = false;
1158 ovs_mutex_init_adaptive(&ofproto->stats_mutex);
1159 ovs_mutex_init(&ofproto->vsp_mutex);
1161 guarded_list_init(&ofproto->pins);
1163 ofproto_dpif_unixctl_init();
1165 hmap_init(&ofproto->vlandev_map);
1166 hmap_init(&ofproto->realdev_vid_map);
1168 sset_init(&ofproto->ports);
1169 sset_init(&ofproto->ghost_ports);
1170 sset_init(&ofproto->port_poll_set);
1171 ofproto->port_poll_errno = 0;
1172 ofproto->change_seq = 0;
1173 ofproto->pins_seq = seq_create();
1174 ofproto->pins_seqno = seq_read(ofproto->pins_seq);
1177 SHASH_FOR_EACH_SAFE (node, next, &init_ofp_ports) {
1178 struct iface_hint *iface_hint = node->data;
1180 if (!strcmp(iface_hint->br_name, ofproto->up.name)) {
1181 /* Check if the datapath already has this port. */
1182 if (dpif_port_exists(ofproto->backer->dpif, node->name)) {
1183 sset_add(&ofproto->ports, node->name);
1186 free(iface_hint->br_name);
1187 free(iface_hint->br_type);
1189 shash_delete(&init_ofp_ports, node);
1193 hmap_insert(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node,
1194 hash_string(ofproto->up.name, 0));
1195 memset(&ofproto->stats, 0, sizeof ofproto->stats);
1197 ofproto_init_tables(ofproto_, N_TABLES);
1198 error = add_internal_flows(ofproto);
1200 ofproto->up.tables[TBL_INTERNAL].flags = OFTABLE_HIDDEN | OFTABLE_READONLY;
1206 add_internal_miss_flow(struct ofproto_dpif *ofproto, int id,
1207 const struct ofpbuf *ofpacts, struct rule_dpif **rulep)
1213 match_init_catchall(&match);
1214 match_set_reg(&match, 0, id);
1216 error = ofproto_dpif_add_internal_flow(ofproto, &match, 0, 0, ofpacts,
1218 *rulep = error ? NULL : rule_dpif_cast(rule);
1224 add_internal_flows(struct ofproto_dpif *ofproto)
1226 struct ofpact_controller *controller;
1227 uint64_t ofpacts_stub[128 / 8];
1228 struct ofpbuf ofpacts;
1229 struct rule *unused_rulep OVS_UNUSED;
1230 struct ofpact_resubmit *resubmit;
1235 ofpbuf_use_stack(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
1238 controller = ofpact_put_CONTROLLER(&ofpacts);
1239 controller->max_len = UINT16_MAX;
1240 controller->controller_id = 0;
1241 controller->reason = OFPR_NO_MATCH;
1242 ofpact_pad(&ofpacts);
1244 error = add_internal_miss_flow(ofproto, id++, &ofpacts,
1245 &ofproto->miss_rule);
1250 ofpbuf_clear(&ofpacts);
1251 error = add_internal_miss_flow(ofproto, id++, &ofpacts,
1252 &ofproto->no_packet_in_rule);
1257 error = add_internal_miss_flow(ofproto, id++, &ofpacts,
1258 &ofproto->drop_frags_rule);
1263 /* Continue non-recirculation rule lookups from table 0.
1265 * (priority=2), recirc=0, actions=resubmit(, 0)
1267 resubmit = ofpact_put_RESUBMIT(&ofpacts);
1268 resubmit->in_port = OFPP_IN_PORT;
1269 resubmit->table_id = 0;
1271 match_init_catchall(&match);
1272 match_set_recirc_id(&match, 0);
1274 error = ofproto_dpif_add_internal_flow(ofproto, &match, 2, 0, &ofpacts,
1280 /* Drop any run away recirc rule lookups. Recirc_id has to be
1281 * non-zero when reaching this rule.
1283 * (priority=1), *, actions=drop
1285 ofpbuf_clear(&ofpacts);
1286 match_init_catchall(&match);
1287 error = ofproto_dpif_add_internal_flow(ofproto, &match, 1, 0, &ofpacts,
1294 destruct(struct ofproto *ofproto_)
1296 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1297 struct ofproto_packet_in *pin, *next_pin;
1298 struct rule_dpif *rule;
1299 struct oftable *table;
1302 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1304 xlate_remove_ofproto(ofproto);
1307 /* Ensure that the upcall processing threads have no remaining references
1308 * to the ofproto or anything in it. */
1309 udpif_synchronize(ofproto->backer->udpif);
1311 hmap_remove(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node);
1313 OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
1314 CLS_FOR_EACH_SAFE (rule, up.cr, &table->cls) {
1315 ofproto_rule_delete(&ofproto->up, &rule->up);
1319 guarded_list_pop_all(&ofproto->pins, &pins);
1320 LIST_FOR_EACH_SAFE (pin, next_pin, list_node, &pins) {
1321 list_remove(&pin->list_node);
1322 free(CONST_CAST(void *, pin->up.packet));
1325 guarded_list_destroy(&ofproto->pins);
1327 mbridge_unref(ofproto->mbridge);
1329 netflow_unref(ofproto->netflow);
1330 dpif_sflow_unref(ofproto->sflow);
1331 dpif_ipfix_unref(ofproto->ipfix);
1332 hmap_destroy(&ofproto->bundles);
1333 mac_learning_unref(ofproto->ml);
1334 mcast_snooping_unref(ofproto->ms);
1336 hmap_destroy(&ofproto->vlandev_map);
1337 hmap_destroy(&ofproto->realdev_vid_map);
1339 sset_destroy(&ofproto->ports);
1340 sset_destroy(&ofproto->ghost_ports);
1341 sset_destroy(&ofproto->port_poll_set);
1343 ovs_mutex_destroy(&ofproto->stats_mutex);
1344 ovs_mutex_destroy(&ofproto->vsp_mutex);
1346 seq_destroy(ofproto->pins_seq);
1348 close_dpif_backer(ofproto->backer);
1352 run(struct ofproto *ofproto_)
1354 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1355 uint64_t new_seq, new_dump_seq;
1357 if (mbridge_need_revalidate(ofproto->mbridge)) {
1358 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1359 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
1360 mac_learning_flush(ofproto->ml);
1361 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1362 mcast_snooping_mdb_flush(ofproto->ms);
1365 /* Always updates the ofproto->pins_seqno to avoid frequent wakeup during
1366 * flow restore. Even though nothing is processed during flow restore,
1367 * all queued 'pins' will be handled immediately when flow restore
1369 ofproto->pins_seqno = seq_read(ofproto->pins_seq);
1371 /* Do not perform any periodic activity required by 'ofproto' while
1372 * waiting for flow restore to complete. */
1373 if (!ofproto_get_flow_restore_wait()) {
1374 struct ofproto_packet_in *pin, *next_pin;
1377 guarded_list_pop_all(&ofproto->pins, &pins);
1378 LIST_FOR_EACH_SAFE (pin, next_pin, list_node, &pins) {
1379 connmgr_send_packet_in(ofproto->up.connmgr, pin);
1380 list_remove(&pin->list_node);
1381 free(CONST_CAST(void *, pin->up.packet));
1386 if (ofproto->netflow) {
1387 netflow_run(ofproto->netflow);
1389 if (ofproto->sflow) {
1390 dpif_sflow_run(ofproto->sflow);
1392 if (ofproto->ipfix) {
1393 dpif_ipfix_run(ofproto->ipfix);
1396 new_seq = seq_read(connectivity_seq_get());
1397 if (ofproto->change_seq != new_seq) {
1398 struct ofport_dpif *ofport;
1400 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1404 ofproto->change_seq = new_seq;
1406 if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) {
1407 struct ofbundle *bundle;
1409 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1416 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
1417 if (mac_learning_run(ofproto->ml)) {
1418 ofproto->backer->need_revalidate = REV_MAC_LEARNING;
1420 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1422 if (mcast_snooping_run(ofproto->ms)) {
1423 ofproto->backer->need_revalidate = REV_MCAST_SNOOPING;
1426 new_dump_seq = seq_read(udpif_dump_seq(ofproto->backer->udpif));
1427 if (ofproto->dump_seq != new_dump_seq) {
1428 struct rule *rule, *next_rule;
1430 /* We know stats are relatively fresh, so now is a good time to do some
1432 ofproto->dump_seq = new_dump_seq;
1434 /* Expire OpenFlow flows whose idle_timeout or hard_timeout
1436 ovs_mutex_lock(&ofproto_mutex);
1437 LIST_FOR_EACH_SAFE (rule, next_rule, expirable,
1438 &ofproto->up.expirable) {
1439 rule_expire(rule_dpif_cast(rule));
1441 ovs_mutex_unlock(&ofproto_mutex);
1443 /* All outstanding data in existing flows has been accounted, so it's a
1444 * good time to do bond rebalancing. */
1445 if (ofproto->has_bonded_bundles) {
1446 struct ofbundle *bundle;
1448 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1450 bond_rebalance(bundle->bond);
1460 wait(struct ofproto *ofproto_)
1462 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1464 if (ofproto_get_flow_restore_wait()) {
1468 if (ofproto->sflow) {
1469 dpif_sflow_wait(ofproto->sflow);
1471 if (ofproto->ipfix) {
1472 dpif_ipfix_wait(ofproto->ipfix);
1474 if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) {
1475 struct ofbundle *bundle;
1477 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1478 bundle_wait(bundle);
1481 if (ofproto->netflow) {
1482 netflow_wait(ofproto->netflow);
1484 ovs_rwlock_rdlock(&ofproto->ml->rwlock);
1485 mac_learning_wait(ofproto->ml);
1486 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1487 mcast_snooping_wait(ofproto->ms);
1489 if (ofproto->backer->need_revalidate) {
1490 /* Shouldn't happen, but if it does just go around again. */
1491 VLOG_DBG_RL(&rl, "need revalidate in ofproto_wait_cb()");
1492 poll_immediate_wake();
1495 seq_wait(udpif_dump_seq(ofproto->backer->udpif), ofproto->dump_seq);
1496 seq_wait(ofproto->pins_seq, ofproto->pins_seqno);
1500 type_get_memory_usage(const char *type, struct simap *usage)
1502 struct dpif_backer *backer;
1504 backer = shash_find_data(&all_dpif_backers, type);
1506 udpif_get_memory_usage(backer->udpif, usage);
1511 flush(struct ofproto *ofproto_)
1513 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1514 struct dpif_backer *backer = ofproto->backer;
1517 udpif_flush(backer->udpif);
1522 query_tables(struct ofproto *ofproto,
1523 struct ofputil_table_features *features,
1524 struct ofputil_table_stats *stats)
1526 strcpy(features->name, "classifier");
1531 for (i = 0; i < ofproto->n_tables; i++) {
1532 unsigned long missed, matched;
1534 atomic_read_relaxed(&ofproto->tables[i].n_matched, &matched);
1535 atomic_read_relaxed(&ofproto->tables[i].n_missed, &missed);
1537 stats[i].matched_count = matched;
1538 stats[i].lookup_count = matched + missed;
1543 static struct ofport *
1546 struct ofport_dpif *port = xmalloc(sizeof *port);
1551 port_dealloc(struct ofport *port_)
1553 struct ofport_dpif *port = ofport_dpif_cast(port_);
1558 port_construct(struct ofport *port_)
1560 struct ofport_dpif *port = ofport_dpif_cast(port_);
1561 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1562 const struct netdev *netdev = port->up.netdev;
1563 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
1564 struct dpif_port dpif_port;
1567 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1568 port->bundle = NULL;
1571 port->may_enable = true;
1572 port->stp_port = NULL;
1573 port->stp_state = STP_DISABLED;
1574 port->rstp_port = NULL;
1575 port->rstp_state = RSTP_DISABLED;
1576 port->is_tunnel = false;
1580 port->realdev_ofp_port = 0;
1581 port->vlandev_vid = 0;
1582 port->carrier_seq = netdev_get_carrier_resets(netdev);
1583 port->is_layer3 = netdev_vport_is_layer3(netdev);
1585 if (netdev_vport_is_patch(netdev)) {
1586 /* By bailing out here, we don't submit the port to the sFlow module
1587 * to be considered for counter polling export. This is correct
1588 * because the patch port represents an interface that sFlow considers
1589 * to be "internal" to the switch as a whole, and therefore not an
1590 * candidate for counter polling. */
1591 port->odp_port = ODPP_NONE;
1592 ofport_update_peer(port);
1596 error = dpif_port_query_by_name(ofproto->backer->dpif,
1597 netdev_vport_get_dpif_port(netdev, namebuf,
1604 port->odp_port = dpif_port.port_no;
1606 if (netdev_get_tunnel_config(netdev)) {
1607 tnl_port_add(port, port->up.netdev, port->odp_port);
1608 port->is_tunnel = true;
1609 if (ofproto->ipfix) {
1610 dpif_ipfix_add_tunnel_port(ofproto->ipfix, port_, port->odp_port);
1613 /* Sanity-check that a mapping doesn't already exist. This
1614 * shouldn't happen for non-tunnel ports. */
1615 if (odp_port_to_ofp_port(ofproto, port->odp_port) != OFPP_NONE) {
1616 VLOG_ERR("port %s already has an OpenFlow port number",
1618 dpif_port_destroy(&dpif_port);
1622 ovs_rwlock_wrlock(&ofproto->backer->odp_to_ofport_lock);
1623 hmap_insert(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node,
1624 hash_odp_port(port->odp_port));
1625 ovs_rwlock_unlock(&ofproto->backer->odp_to_ofport_lock);
1627 dpif_port_destroy(&dpif_port);
1629 if (ofproto->sflow) {
1630 dpif_sflow_add_port(ofproto->sflow, port_, port->odp_port);
1637 port_destruct(struct ofport *port_)
1639 struct ofport_dpif *port = ofport_dpif_cast(port_);
1640 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1641 const char *devname = netdev_get_name(port->up.netdev);
1642 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
1643 const char *dp_port_name;
1645 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1647 xlate_ofport_remove(port);
1650 dp_port_name = netdev_vport_get_dpif_port(port->up.netdev, namebuf,
1652 if (dpif_port_exists(ofproto->backer->dpif, dp_port_name)) {
1653 /* The underlying device is still there, so delete it. This
1654 * happens when the ofproto is being destroyed, since the caller
1655 * assumes that removal of attached ports will happen as part of
1657 if (!port->is_tunnel) {
1658 dpif_port_del(ofproto->backer->dpif, port->odp_port);
1663 port->peer->peer = NULL;
1667 if (port->odp_port != ODPP_NONE && !port->is_tunnel) {
1668 ovs_rwlock_wrlock(&ofproto->backer->odp_to_ofport_lock);
1669 hmap_remove(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node);
1670 ovs_rwlock_unlock(&ofproto->backer->odp_to_ofport_lock);
1673 if (port->is_tunnel && ofproto->ipfix) {
1674 dpif_ipfix_del_tunnel_port(ofproto->ipfix, port->odp_port);
1678 sset_find_and_delete(&ofproto->ports, devname);
1679 sset_find_and_delete(&ofproto->ghost_ports, devname);
1680 bundle_remove(port_);
1681 set_cfm(port_, NULL);
1682 set_bfd(port_, NULL);
1683 if (port->stp_port) {
1684 stp_port_disable(port->stp_port);
1686 if (port->rstp_port) {
1687 rstp_delete_port(port->rstp_port);
1689 if (ofproto->sflow) {
1690 dpif_sflow_del_port(ofproto->sflow, port->odp_port);
1697 port_modified(struct ofport *port_)
1699 struct ofport_dpif *port = ofport_dpif_cast(port_);
1701 if (port->bundle && port->bundle->bond) {
1702 bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev);
1706 cfm_set_netdev(port->cfm, port->up.netdev);
1710 bfd_set_netdev(port->bfd, port->up.netdev);
1713 ofproto_dpif_monitor_port_update(port, port->bfd, port->cfm,
1714 port->up.pp.hw_addr);
1716 if (port->is_tunnel && tnl_port_reconfigure(port, port->up.netdev,
1718 ofproto_dpif_cast(port->up.ofproto)->backer->need_revalidate =
1722 ofport_update_peer(port);
1726 port_reconfigured(struct ofport *port_, enum ofputil_port_config old_config)
1728 struct ofport_dpif *port = ofport_dpif_cast(port_);
1729 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1730 enum ofputil_port_config changed = old_config ^ port->up.pp.config;
1732 if (changed & (OFPUTIL_PC_NO_RECV | OFPUTIL_PC_NO_RECV_STP |
1733 OFPUTIL_PC_NO_FWD | OFPUTIL_PC_NO_FLOOD |
1734 OFPUTIL_PC_NO_PACKET_IN)) {
1735 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1737 if (changed & OFPUTIL_PC_NO_FLOOD && port->bundle) {
1738 bundle_update(port->bundle);
1744 set_sflow(struct ofproto *ofproto_,
1745 const struct ofproto_sflow_options *sflow_options)
1747 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1748 struct dpif_sflow *ds = ofproto->sflow;
1750 if (sflow_options) {
1752 struct ofport_dpif *ofport;
1754 ds = ofproto->sflow = dpif_sflow_create();
1755 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1756 dpif_sflow_add_port(ds, &ofport->up, ofport->odp_port);
1758 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1760 dpif_sflow_set_options(ds, sflow_options);
1763 dpif_sflow_unref(ds);
1764 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1765 ofproto->sflow = NULL;
1773 struct ofproto *ofproto_,
1774 const struct ofproto_ipfix_bridge_exporter_options *bridge_exporter_options,
1775 const struct ofproto_ipfix_flow_exporter_options *flow_exporters_options,
1776 size_t n_flow_exporters_options)
1778 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1779 struct dpif_ipfix *di = ofproto->ipfix;
1780 bool has_options = bridge_exporter_options || flow_exporters_options;
1781 bool new_di = false;
1783 if (has_options && !di) {
1784 di = ofproto->ipfix = dpif_ipfix_create();
1789 /* Call set_options in any case to cleanly flush the flow
1790 * caches in the last exporters that are to be destroyed. */
1791 dpif_ipfix_set_options(
1792 di, bridge_exporter_options, flow_exporters_options,
1793 n_flow_exporters_options);
1795 /* Add tunnel ports only when a new ipfix created */
1796 if (new_di == true) {
1797 struct ofport_dpif *ofport;
1798 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1799 if (ofport->is_tunnel == true) {
1800 dpif_ipfix_add_tunnel_port(di, &ofport->up, ofport->odp_port);
1806 dpif_ipfix_unref(di);
1807 ofproto->ipfix = NULL;
1815 set_cfm(struct ofport *ofport_, const struct cfm_settings *s)
1817 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1822 struct ofproto_dpif *ofproto;
1824 ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1825 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1826 ofport->cfm = cfm_create(ofport->up.netdev);
1829 if (cfm_configure(ofport->cfm, s)) {
1836 cfm_unref(ofport->cfm);
1839 ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm,
1840 ofport->up.pp.hw_addr);
1845 cfm_status_changed(struct ofport *ofport_)
1847 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1849 return ofport->cfm ? cfm_check_status_change(ofport->cfm) : true;
1853 get_cfm_status(const struct ofport *ofport_,
1854 struct cfm_status *status)
1856 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1860 cfm_get_status(ofport->cfm, status);
1869 set_bfd(struct ofport *ofport_, const struct smap *cfg)
1871 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport_->ofproto);
1872 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1876 ofport->bfd = bfd_configure(old, netdev_get_name(ofport->up.netdev),
1877 cfg, ofport->up.netdev);
1878 if (ofport->bfd != old) {
1879 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1881 ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm,
1882 ofport->up.pp.hw_addr);
1887 bfd_status_changed(struct ofport *ofport_)
1889 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1891 return ofport->bfd ? bfd_check_status_change(ofport->bfd) : true;
1895 get_bfd_status(struct ofport *ofport_, struct smap *smap)
1897 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1901 bfd_get_status(ofport->bfd, smap);
1909 /* Spanning Tree. */
1912 rstp_send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_)
1914 struct ofproto_dpif *ofproto = ofproto_;
1915 struct rstp_port *rp = rstp_get_port(ofproto->rstp, port_num);
1916 struct ofport_dpif *ofport;
1918 ofport = rstp_port_get_aux(rp);
1920 VLOG_WARN_RL(&rl, "%s: cannot send BPDU on unknown RSTP port %d",
1921 ofproto->up.name, port_num);
1923 struct eth_header *eth = ofpbuf_l2(pkt);
1925 netdev_get_etheraddr(ofport->up.netdev, eth->eth_src);
1926 if (eth_addr_is_zero(eth->eth_src)) {
1927 VLOG_WARN_RL(&rl, "%s port %d: cannot send BPDU on RSTP port %d "
1928 "with unknown MAC", ofproto->up.name,
1929 ofp_to_u16(ofport->up.ofp_port), port_num);
1931 ofproto_dpif_send_packet(ofport, pkt);
1938 send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_)
1940 struct ofproto_dpif *ofproto = ofproto_;
1941 struct stp_port *sp = stp_get_port(ofproto->stp, port_num);
1942 struct ofport_dpif *ofport;
1944 ofport = stp_port_get_aux(sp);
1946 VLOG_WARN_RL(&rl, "%s: cannot send BPDU on unknown port %d",
1947 ofproto->up.name, port_num);
1949 struct eth_header *eth = ofpbuf_l2(pkt);
1951 netdev_get_etheraddr(ofport->up.netdev, eth->eth_src);
1952 if (eth_addr_is_zero(eth->eth_src)) {
1953 VLOG_WARN_RL(&rl, "%s: cannot send BPDU on port %d "
1954 "with unknown MAC", ofproto->up.name, port_num);
1956 ofproto_dpif_send_packet(ofport, pkt);
1962 /* Configure RSTP on 'ofproto_' using the settings defined in 's'. */
1964 set_rstp(struct ofproto *ofproto_, const struct ofproto_rstp_settings *s)
1966 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1968 /* Only revalidate flows if the configuration changed. */
1969 if (!s != !ofproto->rstp) {
1970 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1974 if (!ofproto->rstp) {
1975 ofproto->rstp = rstp_create(ofproto_->name, s->address,
1976 rstp_send_bpdu_cb, ofproto);
1977 ofproto->rstp_last_tick = time_msec();
1979 rstp_set_bridge_address(ofproto->rstp, s->address);
1980 rstp_set_bridge_priority(ofproto->rstp, s->priority);
1981 rstp_set_bridge_ageing_time(ofproto->rstp, s->ageing_time);
1982 rstp_set_bridge_force_protocol_version(ofproto->rstp,
1983 s->force_protocol_version);
1984 rstp_set_bridge_max_age(ofproto->rstp, s->bridge_max_age);
1985 rstp_set_bridge_forward_delay(ofproto->rstp, s->bridge_forward_delay);
1986 rstp_set_bridge_transmit_hold_count(ofproto->rstp,
1987 s->transmit_hold_count);
1989 struct ofport *ofport;
1990 HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
1991 set_rstp_port(ofport, NULL);
1993 rstp_unref(ofproto->rstp);
1994 ofproto->rstp = NULL;
1999 get_rstp_status(struct ofproto *ofproto_, struct ofproto_rstp_status *s)
2001 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2003 if (ofproto->rstp) {
2005 s->root_id = rstp_get_root_id(ofproto->rstp);
2006 s->bridge_id = rstp_get_bridge_id(ofproto->rstp);
2007 s->designated_id = rstp_get_designated_id(ofproto->rstp);
2008 s->root_path_cost = rstp_get_root_path_cost(ofproto->rstp);
2009 s->designated_port_id = rstp_get_designated_port_id(ofproto->rstp);
2010 s->bridge_port_id = rstp_get_bridge_port_id(ofproto->rstp);
2017 update_rstp_port_state(struct ofport_dpif *ofport)
2019 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2020 enum rstp_state state;
2022 /* Figure out new state. */
2023 state = ofport->rstp_port ? rstp_port_get_state(ofport->rstp_port)
2027 if (ofport->rstp_state != state) {
2028 enum ofputil_port_state of_state;
2031 VLOG_DBG("port %s: RSTP state changed from %s to %s",
2032 netdev_get_name(ofport->up.netdev),
2033 rstp_state_name(ofport->rstp_state),
2034 rstp_state_name(state));
2035 if (rstp_learn_in_state(ofport->rstp_state)
2036 != rstp_learn_in_state(state)) {
2037 /* xxx Learning action flows should also be flushed. */
2038 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2039 mac_learning_flush(ofproto->ml);
2040 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2042 fwd_change = rstp_forward_in_state(ofport->rstp_state)
2043 != rstp_forward_in_state(state);
2045 ofproto->backer->need_revalidate = REV_RSTP;
2046 ofport->rstp_state = state;
2048 if (fwd_change && ofport->bundle) {
2049 bundle_update(ofport->bundle);
2052 /* Update the RSTP state bits in the OpenFlow port description. */
2053 of_state = ofport->up.pp.state & ~OFPUTIL_PS_STP_MASK;
2054 of_state |= (state == RSTP_LEARNING ? OFPUTIL_PS_STP_LEARN
2055 : state == RSTP_FORWARDING ? OFPUTIL_PS_STP_FORWARD
2056 : state == RSTP_DISCARDING ? OFPUTIL_PS_STP_LISTEN
2058 ofproto_port_set_state(&ofport->up, of_state);
2063 rstp_run(struct ofproto_dpif *ofproto)
2065 if (ofproto->rstp) {
2066 long long int now = time_msec();
2067 long long int elapsed = now - ofproto->rstp_last_tick;
2068 struct rstp_port *rp;
2069 /* Every second, decrease the values of the timers. */
2070 if (elapsed >= 1000) {
2071 rstp_tick_timers(ofproto->rstp);
2072 ofproto->rstp_last_tick = now;
2074 while (rstp_get_changed_port(ofproto->rstp, &rp)) {
2075 struct ofport_dpif *ofport = rstp_port_get_aux(rp);
2077 update_rstp_port_state(ofport);
2080 /* FIXME: This check should be done on-event (i.e., when setting
2081 * p->fdb_flush) and not periodically.
2083 if (rstp_check_and_reset_fdb_flush(ofproto->rstp)) {
2084 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2085 /* FIXME: RSTP should be able to flush the entries pertaining to a
2086 * single port, not the whole table.
2088 mac_learning_flush(ofproto->ml);
2089 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2094 /* Configures STP on 'ofproto_' using the settings defined in 's'. */
2096 set_stp(struct ofproto *ofproto_, const struct ofproto_stp_settings *s)
2098 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2100 /* Only revalidate flows if the configuration changed. */
2101 if (!s != !ofproto->stp) {
2102 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2106 if (!ofproto->stp) {
2107 ofproto->stp = stp_create(ofproto_->name, s->system_id,
2108 send_bpdu_cb, ofproto);
2109 ofproto->stp_last_tick = time_msec();
2112 stp_set_bridge_id(ofproto->stp, s->system_id);
2113 stp_set_bridge_priority(ofproto->stp, s->priority);
2114 stp_set_hello_time(ofproto->stp, s->hello_time);
2115 stp_set_max_age(ofproto->stp, s->max_age);
2116 stp_set_forward_delay(ofproto->stp, s->fwd_delay);
2118 struct ofport *ofport;
2120 HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
2121 set_stp_port(ofport, NULL);
2124 stp_unref(ofproto->stp);
2125 ofproto->stp = NULL;
2132 get_stp_status(struct ofproto *ofproto_, struct ofproto_stp_status *s)
2134 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2138 s->bridge_id = stp_get_bridge_id(ofproto->stp);
2139 s->designated_root = stp_get_designated_root(ofproto->stp);
2140 s->root_path_cost = stp_get_root_path_cost(ofproto->stp);
2149 update_stp_port_state(struct ofport_dpif *ofport)
2151 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2152 enum stp_state state;
2154 /* Figure out new state. */
2155 state = ofport->stp_port ? stp_port_get_state(ofport->stp_port)
2159 if (ofport->stp_state != state) {
2160 enum ofputil_port_state of_state;
2163 VLOG_DBG("port %s: STP state changed from %s to %s",
2164 netdev_get_name(ofport->up.netdev),
2165 stp_state_name(ofport->stp_state),
2166 stp_state_name(state));
2167 if (stp_learn_in_state(ofport->stp_state)
2168 != stp_learn_in_state(state)) {
2169 /* xxx Learning action flows should also be flushed. */
2170 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2171 mac_learning_flush(ofproto->ml);
2172 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2173 mcast_snooping_mdb_flush(ofproto->ms);
2175 fwd_change = stp_forward_in_state(ofport->stp_state)
2176 != stp_forward_in_state(state);
2178 ofproto->backer->need_revalidate = REV_STP;
2179 ofport->stp_state = state;
2180 ofport->stp_state_entered = time_msec();
2182 if (fwd_change && ofport->bundle) {
2183 bundle_update(ofport->bundle);
2186 /* Update the STP state bits in the OpenFlow port description. */
2187 of_state = ofport->up.pp.state & ~OFPUTIL_PS_STP_MASK;
2188 of_state |= (state == STP_LISTENING ? OFPUTIL_PS_STP_LISTEN
2189 : state == STP_LEARNING ? OFPUTIL_PS_STP_LEARN
2190 : state == STP_FORWARDING ? OFPUTIL_PS_STP_FORWARD
2191 : state == STP_BLOCKING ? OFPUTIL_PS_STP_BLOCK
2193 ofproto_port_set_state(&ofport->up, of_state);
2197 /* Configures STP on 'ofport_' using the settings defined in 's'. The
2198 * caller is responsible for assigning STP port numbers and ensuring
2199 * there are no duplicates. */
2201 set_stp_port(struct ofport *ofport_,
2202 const struct ofproto_port_stp_settings *s)
2204 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2205 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2206 struct stp_port *sp = ofport->stp_port;
2208 if (!s || !s->enable) {
2210 ofport->stp_port = NULL;
2211 stp_port_disable(sp);
2212 update_stp_port_state(ofport);
2215 } else if (sp && stp_port_no(sp) != s->port_num
2216 && ofport == stp_port_get_aux(sp)) {
2217 /* The port-id changed, so disable the old one if it's not
2218 * already in use by another port. */
2219 stp_port_disable(sp);
2222 sp = ofport->stp_port = stp_get_port(ofproto->stp, s->port_num);
2224 /* Set name before enabling the port so that debugging messages can print
2226 stp_port_set_name(sp, netdev_get_name(ofport->up.netdev));
2227 stp_port_enable(sp);
2229 stp_port_set_aux(sp, ofport);
2230 stp_port_set_priority(sp, s->priority);
2231 stp_port_set_path_cost(sp, s->path_cost);
2233 update_stp_port_state(ofport);
2239 get_stp_port_status(struct ofport *ofport_,
2240 struct ofproto_port_stp_status *s)
2242 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2243 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2244 struct stp_port *sp = ofport->stp_port;
2246 if (!ofproto->stp || !sp) {
2252 s->port_id = stp_port_get_id(sp);
2253 s->state = stp_port_get_state(sp);
2254 s->sec_in_state = (time_msec() - ofport->stp_state_entered) / 1000;
2255 s->role = stp_port_get_role(sp);
2261 get_stp_port_stats(struct ofport *ofport_,
2262 struct ofproto_port_stp_stats *s)
2264 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2265 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2266 struct stp_port *sp = ofport->stp_port;
2268 if (!ofproto->stp || !sp) {
2274 stp_port_get_counts(sp, &s->tx_count, &s->rx_count, &s->error_count);
2280 stp_run(struct ofproto_dpif *ofproto)
2283 long long int now = time_msec();
2284 long long int elapsed = now - ofproto->stp_last_tick;
2285 struct stp_port *sp;
2288 stp_tick(ofproto->stp, MIN(INT_MAX, elapsed));
2289 ofproto->stp_last_tick = now;
2291 while (stp_get_changed_port(ofproto->stp, &sp)) {
2292 struct ofport_dpif *ofport = stp_port_get_aux(sp);
2295 update_stp_port_state(ofport);
2299 if (stp_check_and_reset_fdb_flush(ofproto->stp)) {
2300 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2301 mac_learning_flush(ofproto->ml);
2302 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2303 mcast_snooping_mdb_flush(ofproto->ms);
2309 stp_wait(struct ofproto_dpif *ofproto)
2312 poll_timer_wait(1000);
2316 /* Configures RSTP on 'ofport_' using the settings defined in 's'. The
2317 * caller is responsible for assigning RSTP port numbers and ensuring
2318 * there are no duplicates. */
2320 set_rstp_port(struct ofport *ofport_,
2321 const struct ofproto_port_rstp_settings *s)
2323 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2324 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2325 struct rstp_port *rp = ofport->rstp_port;
2328 if (!s || !s->enable) {
2330 ofport->rstp_port = NULL;
2331 rstp_delete_port(rp);
2332 update_rstp_port_state(ofport);
2335 } else if (rp && rstp_port_number(rp) != s->port_num
2336 && ofport == rstp_port_get_aux(rp)) {
2337 /* The port-id changed, so disable the old one if it's not
2338 * already in use by another port. */
2339 if (s->port_num != 0) {
2341 stp_port = ofport->stp_port ? stp_port_no(ofport->stp_port) : -1;
2342 xlate_ofport_set(ofproto, ofport->bundle, ofport,
2343 ofport->up.ofp_port, ofport->odp_port,
2344 ofport->up.netdev, ofport->cfm,
2345 ofport->bfd, ofport->peer, stp_port,
2347 ofport->qdscp, ofport->n_qdscp,
2348 ofport->up.pp.config, ofport->up.pp.state,
2349 ofport->is_tunnel, ofport->may_enable);
2353 rstp_port_set_aux(rp, ofport);
2354 rstp_port_set_priority(rp, s->priority);
2355 rstp_port_set_port_number(rp, s->port_num);
2356 rstp_port_set_path_cost(rp, s->path_cost);
2357 rstp_port_set_admin_edge(rp, s->admin_edge_port);
2358 rstp_port_set_auto_edge(rp, s->auto_edge);
2359 rstp_port_set_mcheck(rp, s->mcheck);
2361 update_rstp_port_state(ofport);
2365 rp = ofport->rstp_port = rstp_get_port(ofproto->rstp, s->port_num);
2366 /* Enable RSTP on port */
2368 rp = ofport->rstp_port = rstp_add_port(ofproto->rstp);
2371 rstp_port_set_aux(rp, ofport);
2372 rstp_port_set_priority(rp, s->priority);
2373 rstp_port_set_port_number(rp, s->port_num);
2374 rstp_port_set_path_cost(rp, s->path_cost);
2375 rstp_port_set_admin_edge(rp, s->admin_edge_port);
2376 rstp_port_set_auto_edge(rp, s->auto_edge);
2377 rstp_port_set_mcheck(rp, s->mcheck);
2379 update_rstp_port_state(ofport);
2383 get_rstp_port_status(struct ofport *ofport_,
2384 struct ofproto_port_rstp_status *s)
2386 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2387 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2388 struct rstp_port *rp = ofport->rstp_port;
2390 if (!ofproto->rstp || !rp) {
2396 s->port_id = rstp_port_get_id(rp);
2397 s->state = rstp_port_get_state(rp);
2398 s->role = rstp_port_get_role(rp);
2399 rstp_port_get_counts(rp, &s->tx_count, &s->rx_count,
2400 &s->error_count, &s->uptime);
2405 set_queues(struct ofport *ofport_, const struct ofproto_port_queue *qdscp,
2408 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2409 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2411 if (ofport->n_qdscp != n_qdscp
2412 || (n_qdscp && memcmp(ofport->qdscp, qdscp,
2413 n_qdscp * sizeof *qdscp))) {
2414 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2415 free(ofport->qdscp);
2416 ofport->qdscp = n_qdscp
2417 ? xmemdup(qdscp, n_qdscp * sizeof *qdscp)
2419 ofport->n_qdscp = n_qdscp;
2427 /* Expires all MAC learning entries associated with 'bundle' and forces its
2428 * ofproto to revalidate every flow.
2430 * Normally MAC learning entries are removed only from the ofproto associated
2431 * with 'bundle', but if 'all_ofprotos' is true, then the MAC learning entries
2432 * are removed from every ofproto. When patch ports and SLB bonds are in use
2433 * and a VM migration happens and the gratuitous ARPs are somehow lost, this
2434 * avoids a MAC_ENTRY_IDLE_TIME delay before the migrated VM can communicate
2435 * with the host from which it migrated. */
2437 bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos)
2439 struct ofproto_dpif *ofproto = bundle->ofproto;
2440 struct mac_learning *ml = ofproto->ml;
2441 struct mac_entry *mac, *next_mac;
2443 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2444 ovs_rwlock_wrlock(&ml->rwlock);
2445 LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) {
2446 if (mac->port.p == bundle) {
2448 struct ofproto_dpif *o;
2450 HMAP_FOR_EACH (o, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
2452 struct mac_entry *e;
2454 ovs_rwlock_wrlock(&o->ml->rwlock);
2455 e = mac_learning_lookup(o->ml, mac->mac, mac->vlan);
2457 mac_learning_expire(o->ml, e);
2459 ovs_rwlock_unlock(&o->ml->rwlock);
2464 mac_learning_expire(ml, mac);
2467 ovs_rwlock_unlock(&ml->rwlock);
2470 static struct ofbundle *
2471 bundle_lookup(const struct ofproto_dpif *ofproto, void *aux)
2473 struct ofbundle *bundle;
2475 HMAP_FOR_EACH_IN_BUCKET (bundle, hmap_node, hash_pointer(aux, 0),
2476 &ofproto->bundles) {
2477 if (bundle->aux == aux) {
2485 bundle_update(struct ofbundle *bundle)
2487 struct ofport_dpif *port;
2489 bundle->floodable = true;
2490 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2491 if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD
2493 || !stp_forward_in_state(port->stp_state)) {
2494 bundle->floodable = false;
2501 bundle_del_port(struct ofport_dpif *port)
2503 struct ofbundle *bundle = port->bundle;
2505 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2507 list_remove(&port->bundle_node);
2508 port->bundle = NULL;
2511 lacp_slave_unregister(bundle->lacp, port);
2514 bond_slave_unregister(bundle->bond, port);
2517 bundle_update(bundle);
2521 bundle_add_port(struct ofbundle *bundle, ofp_port_t ofp_port,
2522 struct lacp_slave_settings *lacp)
2524 struct ofport_dpif *port;
2526 port = get_ofp_port(bundle->ofproto, ofp_port);
2531 if (port->bundle != bundle) {
2532 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2534 bundle_remove(&port->up);
2537 port->bundle = bundle;
2538 list_push_back(&bundle->ports, &port->bundle_node);
2539 if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD
2541 || !stp_forward_in_state(port->stp_state)) {
2542 bundle->floodable = false;
2546 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2547 lacp_slave_register(bundle->lacp, port, lacp);
2554 bundle_destroy(struct ofbundle *bundle)
2556 struct ofproto_dpif *ofproto;
2557 struct ofport_dpif *port, *next_port;
2563 ofproto = bundle->ofproto;
2564 mbridge_unregister_bundle(ofproto->mbridge, bundle->aux);
2567 xlate_bundle_remove(bundle);
2570 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
2571 bundle_del_port(port);
2574 bundle_flush_macs(bundle, true);
2575 hmap_remove(&ofproto->bundles, &bundle->hmap_node);
2577 free(bundle->trunks);
2578 lacp_unref(bundle->lacp);
2579 bond_unref(bundle->bond);
2584 bundle_set(struct ofproto *ofproto_, void *aux,
2585 const struct ofproto_bundle_settings *s)
2587 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2588 bool need_flush = false;
2589 struct ofport_dpif *port;
2590 struct ofbundle *bundle;
2591 unsigned long *trunks;
2597 bundle_destroy(bundle_lookup(ofproto, aux));
2601 ovs_assert(s->n_slaves == 1 || s->bond != NULL);
2602 ovs_assert((s->lacp != NULL) == (s->lacp_slaves != NULL));
2604 bundle = bundle_lookup(ofproto, aux);
2606 bundle = xmalloc(sizeof *bundle);
2608 bundle->ofproto = ofproto;
2609 hmap_insert(&ofproto->bundles, &bundle->hmap_node,
2610 hash_pointer(aux, 0));
2612 bundle->name = NULL;
2614 list_init(&bundle->ports);
2615 bundle->vlan_mode = PORT_VLAN_TRUNK;
2617 bundle->trunks = NULL;
2618 bundle->use_priority_tags = s->use_priority_tags;
2619 bundle->lacp = NULL;
2620 bundle->bond = NULL;
2622 bundle->floodable = true;
2623 mbridge_register_bundle(ofproto->mbridge, bundle);
2626 if (!bundle->name || strcmp(s->name, bundle->name)) {
2628 bundle->name = xstrdup(s->name);
2633 ofproto->lacp_enabled = true;
2634 if (!bundle->lacp) {
2635 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2636 bundle->lacp = lacp_create();
2638 lacp_configure(bundle->lacp, s->lacp);
2640 lacp_unref(bundle->lacp);
2641 bundle->lacp = NULL;
2644 /* Update set of ports. */
2646 for (i = 0; i < s->n_slaves; i++) {
2647 if (!bundle_add_port(bundle, s->slaves[i],
2648 s->lacp ? &s->lacp_slaves[i] : NULL)) {
2652 if (!ok || list_size(&bundle->ports) != s->n_slaves) {
2653 struct ofport_dpif *next_port;
2655 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
2656 for (i = 0; i < s->n_slaves; i++) {
2657 if (s->slaves[i] == port->up.ofp_port) {
2662 bundle_del_port(port);
2666 ovs_assert(list_size(&bundle->ports) <= s->n_slaves);
2668 if (list_is_empty(&bundle->ports)) {
2669 bundle_destroy(bundle);
2673 /* Set VLAN tagging mode */
2674 if (s->vlan_mode != bundle->vlan_mode
2675 || s->use_priority_tags != bundle->use_priority_tags) {
2676 bundle->vlan_mode = s->vlan_mode;
2677 bundle->use_priority_tags = s->use_priority_tags;
2682 vlan = (s->vlan_mode == PORT_VLAN_TRUNK ? -1
2683 : s->vlan >= 0 && s->vlan <= 4095 ? s->vlan
2685 if (vlan != bundle->vlan) {
2686 bundle->vlan = vlan;
2690 /* Get trunked VLANs. */
2691 switch (s->vlan_mode) {
2692 case PORT_VLAN_ACCESS:
2696 case PORT_VLAN_TRUNK:
2697 trunks = CONST_CAST(unsigned long *, s->trunks);
2700 case PORT_VLAN_NATIVE_UNTAGGED:
2701 case PORT_VLAN_NATIVE_TAGGED:
2702 if (vlan != 0 && (!s->trunks
2703 || !bitmap_is_set(s->trunks, vlan)
2704 || bitmap_is_set(s->trunks, 0))) {
2705 /* Force trunking the native VLAN and prohibit trunking VLAN 0. */
2707 trunks = bitmap_clone(s->trunks, 4096);
2709 trunks = bitmap_allocate1(4096);
2711 bitmap_set1(trunks, vlan);
2712 bitmap_set0(trunks, 0);
2714 trunks = CONST_CAST(unsigned long *, s->trunks);
2721 if (!vlan_bitmap_equal(trunks, bundle->trunks)) {
2722 free(bundle->trunks);
2723 if (trunks == s->trunks) {
2724 bundle->trunks = vlan_bitmap_clone(trunks);
2726 bundle->trunks = trunks;
2731 if (trunks != s->trunks) {
2736 if (!list_is_short(&bundle->ports)) {
2737 bundle->ofproto->has_bonded_bundles = true;
2739 if (bond_reconfigure(bundle->bond, s->bond)) {
2740 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2743 bundle->bond = bond_create(s->bond, ofproto);
2744 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2747 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2748 bond_slave_register(bundle->bond, port,
2749 port->up.ofp_port, port->up.netdev);
2752 bond_unref(bundle->bond);
2753 bundle->bond = NULL;
2756 /* If we changed something that would affect MAC learning, un-learn
2757 * everything on this port and force flow revalidation. */
2759 bundle_flush_macs(bundle, false);
2766 bundle_remove(struct ofport *port_)
2768 struct ofport_dpif *port = ofport_dpif_cast(port_);
2769 struct ofbundle *bundle = port->bundle;
2772 bundle_del_port(port);
2773 if (list_is_empty(&bundle->ports)) {
2774 bundle_destroy(bundle);
2775 } else if (list_is_short(&bundle->ports)) {
2776 bond_unref(bundle->bond);
2777 bundle->bond = NULL;
2783 send_pdu_cb(void *port_, const void *pdu, size_t pdu_size)
2785 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10);
2786 struct ofport_dpif *port = port_;
2787 uint8_t ea[ETH_ADDR_LEN];
2790 error = netdev_get_etheraddr(port->up.netdev, ea);
2792 struct ofpbuf packet;
2795 ofpbuf_init(&packet, 0);
2796 packet_pdu = eth_compose(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP,
2798 memcpy(packet_pdu, pdu, pdu_size);
2800 ofproto_dpif_send_packet(port, &packet);
2801 ofpbuf_uninit(&packet);
2803 VLOG_ERR_RL(&rl, "port %s: cannot obtain Ethernet address of iface "
2804 "%s (%s)", port->bundle->name,
2805 netdev_get_name(port->up.netdev), ovs_strerror(error));
2810 bundle_send_learning_packets(struct ofbundle *bundle)
2812 struct ofproto_dpif *ofproto = bundle->ofproto;
2813 struct ofpbuf *learning_packet;
2814 int error, n_packets, n_errors;
2815 struct mac_entry *e;
2816 struct list packets;
2818 list_init(&packets);
2819 ovs_rwlock_rdlock(&ofproto->ml->rwlock);
2820 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
2821 if (e->port.p != bundle) {
2824 learning_packet = bond_compose_learning_packet(bundle->bond,
2827 /* Temporarily use 'frame' as a private pointer (see below). */
2828 ovs_assert(learning_packet->frame == ofpbuf_data(learning_packet));
2829 learning_packet->frame = port_void;
2830 list_push_back(&packets, &learning_packet->list_node);
2833 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2835 error = n_packets = n_errors = 0;
2836 LIST_FOR_EACH (learning_packet, list_node, &packets) {
2838 void *port_void = learning_packet->frame;
2840 /* Restore 'frame'. */
2841 learning_packet->frame = ofpbuf_data(learning_packet);
2842 ret = ofproto_dpif_send_packet(port_void, learning_packet);
2849 ofpbuf_list_delete(&packets);
2852 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2853 VLOG_WARN_RL(&rl, "bond %s: %d errors sending %d gratuitous learning "
2854 "packets, last error was: %s",
2855 bundle->name, n_errors, n_packets, ovs_strerror(error));
2857 VLOG_DBG("bond %s: sent %d gratuitous learning packets",
2858 bundle->name, n_packets);
2863 bundle_run(struct ofbundle *bundle)
2866 lacp_run(bundle->lacp, send_pdu_cb);
2869 struct ofport_dpif *port;
2871 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2872 bond_slave_set_may_enable(bundle->bond, port, port->may_enable);
2875 if (bond_run(bundle->bond, lacp_status(bundle->lacp))) {
2876 bundle->ofproto->backer->need_revalidate = REV_BOND;
2879 if (bond_should_send_learning_packets(bundle->bond)) {
2880 bundle_send_learning_packets(bundle);
2886 bundle_wait(struct ofbundle *bundle)
2889 lacp_wait(bundle->lacp);
2892 bond_wait(bundle->bond);
2899 mirror_set__(struct ofproto *ofproto_, void *aux,
2900 const struct ofproto_mirror_settings *s)
2902 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2903 struct ofbundle **srcs, **dsts;
2908 mirror_destroy(ofproto->mbridge, aux);
2912 srcs = xmalloc(s->n_srcs * sizeof *srcs);
2913 dsts = xmalloc(s->n_dsts * sizeof *dsts);
2915 for (i = 0; i < s->n_srcs; i++) {
2916 srcs[i] = bundle_lookup(ofproto, s->srcs[i]);
2919 for (i = 0; i < s->n_dsts; i++) {
2920 dsts[i] = bundle_lookup(ofproto, s->dsts[i]);
2923 error = mirror_set(ofproto->mbridge, aux, s->name, srcs, s->n_srcs, dsts,
2924 s->n_dsts, s->src_vlans,
2925 bundle_lookup(ofproto, s->out_bundle), s->out_vlan);
2932 mirror_get_stats__(struct ofproto *ofproto, void *aux,
2933 uint64_t *packets, uint64_t *bytes)
2935 return mirror_get_stats(ofproto_dpif_cast(ofproto)->mbridge, aux, packets,
2940 set_flood_vlans(struct ofproto *ofproto_, unsigned long *flood_vlans)
2942 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2943 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2944 if (mac_learning_set_flood_vlans(ofproto->ml, flood_vlans)) {
2945 mac_learning_flush(ofproto->ml);
2947 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2952 is_mirror_output_bundle(const struct ofproto *ofproto_, void *aux)
2954 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2955 struct ofbundle *bundle = bundle_lookup(ofproto, aux);
2956 return bundle && mirror_bundle_out(ofproto->mbridge, bundle) != 0;
2960 forward_bpdu_changed(struct ofproto *ofproto_)
2962 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2963 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2967 set_mac_table_config(struct ofproto *ofproto_, unsigned int idle_time,
2970 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2971 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2972 mac_learning_set_idle_time(ofproto->ml, idle_time);
2973 mac_learning_set_max_entries(ofproto->ml, max_entries);
2974 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2977 /* Configures multicast snooping on 'ofport' using the settings
2978 * defined in 's'. */
2980 set_mcast_snooping(struct ofproto *ofproto_,
2981 const struct ofproto_mcast_snooping_settings *s)
2983 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2985 /* Only revalidate flows if the configuration changed. */
2986 if (!s != !ofproto->ms) {
2987 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2992 ofproto->ms = mcast_snooping_create();
2995 ovs_rwlock_wrlock(&ofproto->ms->rwlock);
2996 mcast_snooping_set_idle_time(ofproto->ms, s->idle_time);
2997 mcast_snooping_set_max_entries(ofproto->ms, s->max_entries);
2998 if (mcast_snooping_set_flood_unreg(ofproto->ms, s->flood_unreg)) {
2999 ofproto->backer->need_revalidate = REV_RECONFIGURE;
3001 ovs_rwlock_unlock(&ofproto->ms->rwlock);
3003 mcast_snooping_unref(ofproto->ms);
3010 /* Configures multicast snooping port's flood setting on 'ofproto'. */
3012 set_mcast_snooping_port(struct ofproto *ofproto_, void *aux, bool flood)
3014 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3015 struct ofbundle *bundle = bundle_lookup(ofproto, aux);
3018 ovs_rwlock_wrlock(&ofproto->ms->rwlock);
3019 mcast_snooping_set_port_flood(ofproto->ms, bundle->vlan, bundle,
3021 ovs_rwlock_unlock(&ofproto->ms->rwlock);
3029 static struct ofport_dpif *
3030 get_ofp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
3032 struct ofport *ofport = ofproto_get_port(&ofproto->up, ofp_port);
3033 return ofport ? ofport_dpif_cast(ofport) : NULL;
3037 ofproto_port_from_dpif_port(struct ofproto_dpif *ofproto,
3038 struct ofproto_port *ofproto_port,
3039 struct dpif_port *dpif_port)
3041 ofproto_port->name = dpif_port->name;
3042 ofproto_port->type = dpif_port->type;
3043 ofproto_port->ofp_port = odp_port_to_ofp_port(ofproto, dpif_port->port_no);
3047 ofport_update_peer(struct ofport_dpif *ofport)
3049 const struct ofproto_dpif *ofproto;
3050 struct dpif_backer *backer;
3053 if (!netdev_vport_is_patch(ofport->up.netdev)) {
3057 backer = ofproto_dpif_cast(ofport->up.ofproto)->backer;
3058 backer->need_revalidate = REV_RECONFIGURE;
3061 ofport->peer->peer = NULL;
3062 ofport->peer = NULL;
3065 peer_name = netdev_vport_patch_peer(ofport->up.netdev);
3070 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
3071 struct ofport *peer_ofport;
3072 struct ofport_dpif *peer;
3075 if (ofproto->backer != backer) {
3079 peer_ofport = shash_find_data(&ofproto->up.port_by_name, peer_name);
3084 peer = ofport_dpif_cast(peer_ofport);
3085 peer_peer = netdev_vport_patch_peer(peer->up.netdev);
3086 if (peer_peer && !strcmp(netdev_get_name(ofport->up.netdev),
3088 ofport->peer = peer;
3089 ofport->peer->peer = ofport;
3099 port_run(struct ofport_dpif *ofport)
3101 long long int carrier_seq = netdev_get_carrier_resets(ofport->up.netdev);
3102 bool carrier_changed = carrier_seq != ofport->carrier_seq;
3103 bool enable = netdev_get_carrier(ofport->up.netdev);
3104 bool cfm_enable = false;
3105 bool bfd_enable = false;
3107 ofport->carrier_seq = carrier_seq;
3110 int cfm_opup = cfm_get_opup(ofport->cfm);
3112 cfm_enable = !cfm_get_fault(ofport->cfm);
3114 if (cfm_opup >= 0) {
3115 cfm_enable = cfm_enable && cfm_opup;
3120 bfd_enable = bfd_forwarding(ofport->bfd);
3123 if (ofport->bfd || ofport->cfm) {
3124 enable = enable && (cfm_enable || bfd_enable);
3127 if (ofport->bundle) {
3128 enable = enable && lacp_slave_may_enable(ofport->bundle->lacp, ofport);
3129 if (carrier_changed) {
3130 lacp_slave_carrier_changed(ofport->bundle->lacp, ofport);
3134 if (ofport->may_enable != enable) {
3135 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
3136 ofproto->backer->need_revalidate = REV_PORT_TOGGLED;
3139 ofport->may_enable = enable;
3141 if (ofport->rstp_port) {
3142 if (rstp_port_get_mac_operational(ofport->rstp_port) != enable) {
3143 rstp_port_set_mac_operational(ofport->rstp_port, enable);
3149 port_query_by_name(const struct ofproto *ofproto_, const char *devname,
3150 struct ofproto_port *ofproto_port)
3152 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3153 struct dpif_port dpif_port;
3156 if (sset_contains(&ofproto->ghost_ports, devname)) {
3157 const char *type = netdev_get_type_from_name(devname);
3159 /* We may be called before ofproto->up.port_by_name is populated with
3160 * the appropriate ofport. For this reason, we must get the name and
3161 * type from the netdev layer directly. */
3163 const struct ofport *ofport;
3165 ofport = shash_find_data(&ofproto->up.port_by_name, devname);
3166 ofproto_port->ofp_port = ofport ? ofport->ofp_port : OFPP_NONE;
3167 ofproto_port->name = xstrdup(devname);
3168 ofproto_port->type = xstrdup(type);
3174 if (!sset_contains(&ofproto->ports, devname)) {
3177 error = dpif_port_query_by_name(ofproto->backer->dpif,
3178 devname, &dpif_port);
3180 ofproto_port_from_dpif_port(ofproto, ofproto_port, &dpif_port);
3186 port_add(struct ofproto *ofproto_, struct netdev *netdev)
3188 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3189 const char *devname = netdev_get_name(netdev);
3190 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
3191 const char *dp_port_name;
3193 if (netdev_vport_is_patch(netdev)) {
3194 sset_add(&ofproto->ghost_ports, netdev_get_name(netdev));
3198 dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
3199 if (!dpif_port_exists(ofproto->backer->dpif, dp_port_name)) {
3200 odp_port_t port_no = ODPP_NONE;
3203 error = dpif_port_add(ofproto->backer->dpif, netdev, &port_no);
3207 if (netdev_get_tunnel_config(netdev)) {
3208 simap_put(&ofproto->backer->tnl_backers,
3209 dp_port_name, odp_to_u32(port_no));
3213 if (netdev_get_tunnel_config(netdev)) {
3214 sset_add(&ofproto->ghost_ports, devname);
3216 sset_add(&ofproto->ports, devname);
3222 port_del(struct ofproto *ofproto_, ofp_port_t ofp_port)
3224 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3225 struct ofport_dpif *ofport = get_ofp_port(ofproto, ofp_port);
3232 sset_find_and_delete(&ofproto->ghost_ports,
3233 netdev_get_name(ofport->up.netdev));
3234 ofproto->backer->need_revalidate = REV_RECONFIGURE;
3235 if (!ofport->is_tunnel && !netdev_vport_is_patch(ofport->up.netdev)) {
3236 error = dpif_port_del(ofproto->backer->dpif, ofport->odp_port);
3238 /* The caller is going to close ofport->up.netdev. If this is a
3239 * bonded port, then the bond is using that netdev, so remove it
3240 * from the bond. The client will need to reconfigure everything
3241 * after deleting ports, so then the slave will get re-added. */
3242 bundle_remove(&ofport->up);
3249 port_get_stats(const struct ofport *ofport_, struct netdev_stats *stats)
3251 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
3254 error = netdev_get_stats(ofport->up.netdev, stats);
3256 if (!error && ofport_->ofp_port == OFPP_LOCAL) {
3257 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
3259 ovs_mutex_lock(&ofproto->stats_mutex);
3260 /* ofproto->stats.tx_packets represents packets that we created
3261 * internally and sent to some port (e.g. packets sent with
3262 * ofproto_dpif_send_packet()). Account for them as if they had
3263 * come from OFPP_LOCAL and got forwarded. */
3265 if (stats->rx_packets != UINT64_MAX) {
3266 stats->rx_packets += ofproto->stats.tx_packets;
3269 if (stats->rx_bytes != UINT64_MAX) {
3270 stats->rx_bytes += ofproto->stats.tx_bytes;
3273 /* ofproto->stats.rx_packets represents packets that were received on
3274 * some port and we processed internally and dropped (e.g. STP).
3275 * Account for them as if they had been forwarded to OFPP_LOCAL. */
3277 if (stats->tx_packets != UINT64_MAX) {
3278 stats->tx_packets += ofproto->stats.rx_packets;
3281 if (stats->tx_bytes != UINT64_MAX) {
3282 stats->tx_bytes += ofproto->stats.rx_bytes;
3284 ovs_mutex_unlock(&ofproto->stats_mutex);
3290 struct port_dump_state {
3295 struct ofproto_port port;
3300 port_dump_start(const struct ofproto *ofproto_ OVS_UNUSED, void **statep)
3302 *statep = xzalloc(sizeof(struct port_dump_state));
3307 port_dump_next(const struct ofproto *ofproto_, void *state_,
3308 struct ofproto_port *port)
3310 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3311 struct port_dump_state *state = state_;
3312 const struct sset *sset;
3313 struct sset_node *node;
3315 if (state->has_port) {
3316 ofproto_port_destroy(&state->port);
3317 state->has_port = false;
3319 sset = state->ghost ? &ofproto->ghost_ports : &ofproto->ports;
3320 while ((node = sset_at_position(sset, &state->bucket, &state->offset))) {
3323 error = port_query_by_name(ofproto_, node->name, &state->port);
3325 *port = state->port;
3326 state->has_port = true;
3328 } else if (error != ENODEV) {
3333 if (!state->ghost) {
3334 state->ghost = true;
3337 return port_dump_next(ofproto_, state_, port);
3344 port_dump_done(const struct ofproto *ofproto_ OVS_UNUSED, void *state_)
3346 struct port_dump_state *state = state_;
3348 if (state->has_port) {
3349 ofproto_port_destroy(&state->port);
3356 port_poll(const struct ofproto *ofproto_, char **devnamep)
3358 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3360 if (ofproto->port_poll_errno) {
3361 int error = ofproto->port_poll_errno;
3362 ofproto->port_poll_errno = 0;
3366 if (sset_is_empty(&ofproto->port_poll_set)) {
3370 *devnamep = sset_pop(&ofproto->port_poll_set);
3375 port_poll_wait(const struct ofproto *ofproto_)
3377 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3378 dpif_port_poll_wait(ofproto->backer->dpif);
3382 port_is_lacp_current(const struct ofport *ofport_)
3384 const struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
3385 return (ofport->bundle && ofport->bundle->lacp
3386 ? lacp_slave_is_current(ofport->bundle->lacp, ofport)
3390 /* If 'rule' is an OpenFlow rule, that has expired according to OpenFlow rules,
3391 * then delete it entirely. */
3393 rule_expire(struct rule_dpif *rule)
3394 OVS_REQUIRES(ofproto_mutex)
3396 uint16_t hard_timeout, idle_timeout;
3397 long long int now = time_msec();
3400 hard_timeout = rule->up.hard_timeout;
3401 idle_timeout = rule->up.idle_timeout;
3403 /* Has 'rule' expired? */
3405 long long int modified;
3407 ovs_mutex_lock(&rule->up.mutex);
3408 modified = rule->up.modified;
3409 ovs_mutex_unlock(&rule->up.mutex);
3411 if (now > modified + hard_timeout * 1000) {
3412 reason = OFPRR_HARD_TIMEOUT;
3416 if (reason < 0 && idle_timeout) {
3419 ovs_mutex_lock(&rule->stats_mutex);
3420 used = rule->stats.used;
3421 ovs_mutex_unlock(&rule->stats_mutex);
3423 if (now > used + idle_timeout * 1000) {
3424 reason = OFPRR_IDLE_TIMEOUT;
3429 COVERAGE_INC(ofproto_dpif_expired);
3430 ofproto_rule_expire(&rule->up, reason);
3434 /* Executes, within 'ofproto', the actions in 'rule' or 'ofpacts' on 'packet'.
3435 * 'flow' must reflect the data in 'packet'. */
3437 ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto,
3438 const struct flow *flow,
3439 struct rule_dpif *rule,
3440 const struct ofpact *ofpacts, size_t ofpacts_len,
3441 struct ofpbuf *packet)
3443 struct dpif_flow_stats stats;
3444 struct xlate_out xout;
3445 struct xlate_in xin;
3447 struct dpif_execute execute;
3450 ovs_assert((rule != NULL) != (ofpacts != NULL));
3452 dpif_flow_stats_extract(flow, packet, time_msec(), &stats);
3455 rule_dpif_credit_stats(rule, &stats);
3458 xlate_in_init(&xin, ofproto, flow, flow->in_port.ofp_port, rule,
3459 stats.tcp_flags, packet);
3460 xin.ofpacts = ofpacts;
3461 xin.ofpacts_len = ofpacts_len;
3462 xin.resubmit_stats = &stats;
3463 xlate_actions(&xin, &xout);
3465 execute.actions = ofpbuf_data(xout.odp_actions);
3466 execute.actions_len = ofpbuf_size(xout.odp_actions);
3467 execute.packet = packet;
3468 execute.md = pkt_metadata_from_flow(flow);
3469 execute.needs_help = (xout.slow & SLOW_ACTION) != 0;
3471 /* Fix up in_port. */
3472 in_port = flow->in_port.ofp_port;
3473 if (in_port == OFPP_NONE) {
3474 in_port = OFPP_LOCAL;
3476 execute.md.in_port.odp_port = ofp_port_to_odp_port(ofproto, in_port);
3478 error = dpif_execute(ofproto->backer->dpif, &execute);
3480 xlate_out_uninit(&xout);
3486 rule_dpif_credit_stats(struct rule_dpif *rule,
3487 const struct dpif_flow_stats *stats)
3489 ovs_mutex_lock(&rule->stats_mutex);
3490 rule->stats.n_packets += stats->n_packets;
3491 rule->stats.n_bytes += stats->n_bytes;
3492 rule->stats.used = MAX(rule->stats.used, stats->used);
3493 ovs_mutex_unlock(&rule->stats_mutex);
3497 rule_dpif_get_flow_cookie(const struct rule_dpif *rule)
3498 OVS_REQUIRES(rule->up.mutex)
3500 return rule->up.flow_cookie;
3504 rule_dpif_reduce_timeouts(struct rule_dpif *rule, uint16_t idle_timeout,
3505 uint16_t hard_timeout)
3507 ofproto_rule_reduce_timeouts(&rule->up, idle_timeout, hard_timeout);
3510 /* Returns 'rule''s actions. The caller owns a reference on the returned
3511 * actions and must eventually release it (with rule_actions_unref()) to avoid
3513 const struct rule_actions *
3514 rule_dpif_get_actions(const struct rule_dpif *rule)
3516 return rule_get_actions(&rule->up);
3519 /* Sets 'rule''s recirculation id. */
3521 rule_dpif_set_recirc_id(struct rule_dpif *rule, uint32_t id)
3522 OVS_REQUIRES(rule->up.mutex)
3524 ovs_assert(!rule->recirc_id);
3525 rule->recirc_id = id;
3528 /* Returns 'rule''s recirculation id. */
3530 rule_dpif_get_recirc_id(struct rule_dpif *rule)
3531 OVS_REQUIRES(rule->up.mutex)
3533 if (!rule->recirc_id) {
3534 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
3536 rule_dpif_set_recirc_id(rule, ofproto_dpif_alloc_recirc_id(ofproto));
3538 return rule->recirc_id;
3541 /* Sets 'rule''s recirculation id. */
3543 rule_set_recirc_id(struct rule *rule_, uint32_t id)
3545 struct rule_dpif *rule = rule_dpif_cast(rule_);
3547 ovs_mutex_lock(&rule->up.mutex);
3548 rule_dpif_set_recirc_id(rule, id);
3549 ovs_mutex_unlock(&rule->up.mutex);
3552 /* Lookup 'flow' in table 0 of 'ofproto''s classifier.
3553 * If 'wc' is non-null, sets the fields that were relevant as part of
3554 * the lookup. Returns the table_id where a match or miss occurred.
3556 * The return value will be zero unless there was a miss and
3557 * OFPTC11_TABLE_MISS_CONTINUE is in effect for the sequence of tables
3558 * where misses occur.
3560 * The rule is returned in '*rule', which is valid at least until the next
3561 * RCU quiescent period. If the '*rule' needs to stay around longer,
3562 * a non-zero 'take_ref' must be passed in to cause a reference to be taken
3563 * on it before this returns. */
3565 rule_dpif_lookup(struct ofproto_dpif *ofproto, struct flow *flow,
3566 struct flow_wildcards *wc, struct rule_dpif **rule,
3567 bool take_ref, const struct dpif_flow_stats *stats)
3569 enum rule_dpif_lookup_verdict verdict;
3570 enum ofputil_port_config config = 0;
3573 if (ofproto_dpif_get_enable_recirc(ofproto)) {
3574 /* Always exactly match recirc_id since datapath supports
3577 wc->masks.recirc_id = UINT32_MAX;
3580 /* Start looking up from internal table for post recirculation flows
3581 * or packets. We can also simply send all, including normal flows
3582 * or packets to the internal table. They will not match any post
3583 * recirculation rules except the 'catch all' rule that resubmit
3586 * As an optimization, we send normal flows and packets to table 0
3587 * directly, saving one table lookup. */
3588 table_id = flow->recirc_id ? TBL_INTERNAL : 0;
3593 verdict = rule_dpif_lookup_from_table(ofproto, flow, wc, true,
3594 &table_id, rule, take_ref, stats);
3597 case RULE_DPIF_LOOKUP_VERDICT_MATCH:
3599 case RULE_DPIF_LOOKUP_VERDICT_CONTROLLER: {
3600 struct ofport_dpif *port;
3602 port = get_ofp_port(ofproto, flow->in_port.ofp_port);
3604 VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16,
3605 flow->in_port.ofp_port);
3607 config = port ? port->up.pp.config : 0;
3610 case RULE_DPIF_LOOKUP_VERDICT_DROP:
3611 config = OFPUTIL_PC_NO_PACKET_IN;
3613 case RULE_DPIF_LOOKUP_VERDICT_DEFAULT:
3614 if (!connmgr_wants_packet_in_on_miss(ofproto->up.connmgr)) {
3615 config = OFPUTIL_PC_NO_PACKET_IN;
3622 choose_miss_rule(config, ofproto->miss_rule,
3623 ofproto->no_packet_in_rule, rule, take_ref);
3627 /* The returned rule is valid at least until the next RCU quiescent period.
3628 * If the '*rule' needs to stay around longer, a non-zero 'take_ref' must be
3629 * passed in to cause a reference to be taken on it before this returns. */
3630 static struct rule_dpif *
3631 rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, uint8_t table_id,
3632 const struct flow *flow, struct flow_wildcards *wc,
3635 struct classifier *cls = &ofproto->up.tables[table_id].cls;
3636 const struct cls_rule *cls_rule;
3637 struct rule_dpif *rule;
3638 struct flow ofpc_normal_flow;
3640 if (ofproto->up.frag_handling != OFPC_FRAG_NX_MATCH) {
3641 /* We always unwildcard dl_type and nw_frag (for IP), so they
3642 * need not be unwildcarded here. */
3644 if (flow->nw_frag & FLOW_NW_FRAG_ANY) {
3645 if (ofproto->up.frag_handling == OFPC_FRAG_NORMAL) {
3646 /* We must pretend that transport ports are unavailable. */
3647 ofpc_normal_flow = *flow;
3648 ofpc_normal_flow.tp_src = htons(0);
3649 ofpc_normal_flow.tp_dst = htons(0);
3650 flow = &ofpc_normal_flow;
3652 /* Must be OFPC_FRAG_DROP (we don't have OFPC_FRAG_REASM).
3653 * Use the drop_frags_rule (which cannot disappear). */
3654 cls_rule = &ofproto->drop_frags_rule->up.cr;
3655 rule = rule_dpif_cast(rule_from_cls_rule(cls_rule));
3657 rule_dpif_ref(rule);
3665 cls_rule = classifier_lookup(cls, flow, wc);
3667 rule = rule_dpif_cast(rule_from_cls_rule(cls_rule));
3669 /* Try again if the rule was released before we get the reference. */
3670 } while (rule && take_ref && !rule_dpif_try_ref(rule));
3675 /* Look up 'flow' in 'ofproto''s classifier starting from table '*table_id'.
3676 * Stores the rule that was found in '*rule', or NULL if none was found.
3677 * Updates 'wc', if nonnull, to reflect the fields that were used during the
3680 * If 'honor_table_miss' is true, the first lookup occurs in '*table_id', but
3681 * if none is found then the table miss configuration for that table is
3682 * honored, which can result in additional lookups in other OpenFlow tables.
3683 * In this case the function updates '*table_id' to reflect the final OpenFlow
3684 * table that was searched.
3686 * If 'honor_table_miss' is false, then only one table lookup occurs, in
3691 * - RULE_DPIF_LOOKUP_VERDICT_MATCH if a rule (in '*rule') was found.
3693 * - RULE_OFPTC_TABLE_MISS_CONTROLLER if no rule was found and either:
3694 * + 'honor_table_miss' is false
3695 * + a table miss configuration specified that the packet should be
3696 * sent to the controller in this case.
3698 * - RULE_DPIF_LOOKUP_VERDICT_DROP if no rule was found, 'honor_table_miss'
3699 * is true and a table miss configuration specified that the packet
3700 * should be dropped in this case.
3702 * - RULE_DPIF_LOOKUP_VERDICT_DEFAULT if no rule was found,
3703 * 'honor_table_miss' is true and a table miss configuration has
3704 * not been specified in this case.
3706 * The rule is returned in '*rule', which is valid at least until the next
3707 * RCU quiescent period. If the '*rule' needs to stay around longer,
3708 * a non-zero 'take_ref' must be passed in to cause a reference to be taken
3709 * on it before this returns. */
3710 enum rule_dpif_lookup_verdict
3711 rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto,
3712 const struct flow *flow,
3713 struct flow_wildcards *wc,
3714 bool honor_table_miss,
3715 uint8_t *table_id, struct rule_dpif **rule,
3716 bool take_ref, const struct dpif_flow_stats *stats)
3720 for (next_id = *table_id;
3721 next_id < ofproto->up.n_tables;
3722 next_id++, next_id += (next_id == TBL_INTERNAL))
3724 *table_id = next_id;
3725 *rule = rule_dpif_lookup_in_table(ofproto, *table_id, flow, wc,
3728 struct oftable *tbl = &ofproto->up.tables[next_id];
3731 atomic_add_relaxed(*rule ? &tbl->n_matched : &tbl->n_missed,
3732 stats->n_packets, &orig);
3735 return RULE_DPIF_LOOKUP_VERDICT_MATCH;
3736 } else if (!honor_table_miss) {
3737 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3739 switch (ofproto_table_get_miss_config(&ofproto->up, *table_id)) {
3740 case OFPUTIL_TABLE_MISS_CONTINUE:
3743 case OFPUTIL_TABLE_MISS_CONTROLLER:
3744 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3746 case OFPUTIL_TABLE_MISS_DROP:
3747 return RULE_DPIF_LOOKUP_VERDICT_DROP;
3749 case OFPUTIL_TABLE_MISS_DEFAULT:
3750 return RULE_DPIF_LOOKUP_VERDICT_DEFAULT;
3755 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3758 /* Given a port configuration (specified as zero if there's no port), chooses
3759 * which of 'miss_rule' and 'no_packet_in_rule' should be used in case of a
3762 * The rule is returned in '*rule', which is valid at least until the next
3763 * RCU quiescent period. If the '*rule' needs to stay around longer,
3764 * a reference must be taken on it (rule_dpif_ref()).
3767 choose_miss_rule(enum ofputil_port_config config, struct rule_dpif *miss_rule,
3768 struct rule_dpif *no_packet_in_rule, struct rule_dpif **rule,
3771 *rule = config & OFPUTIL_PC_NO_PACKET_IN ? no_packet_in_rule : miss_rule;
3773 rule_dpif_ref(*rule);
3778 complete_operation(struct rule_dpif *rule)
3779 OVS_REQUIRES(ofproto_mutex)
3781 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
3783 ofproto->backer->need_revalidate = REV_FLOW_TABLE;
3786 static struct rule_dpif *rule_dpif_cast(const struct rule *rule)
3788 return rule ? CONTAINER_OF(rule, struct rule_dpif, up) : NULL;
3791 static struct rule *
3794 struct rule_dpif *rule = xmalloc(sizeof *rule);
3799 rule_dealloc(struct rule *rule_)
3801 struct rule_dpif *rule = rule_dpif_cast(rule_);
3806 rule_construct(struct rule *rule_)
3807 OVS_NO_THREAD_SAFETY_ANALYSIS
3809 struct rule_dpif *rule = rule_dpif_cast(rule_);
3810 ovs_mutex_init_adaptive(&rule->stats_mutex);
3811 rule->stats.n_packets = 0;
3812 rule->stats.n_bytes = 0;
3813 rule->stats.used = rule->up.modified;
3814 rule->recirc_id = 0;
3820 rule_insert(struct rule *rule_)
3821 OVS_REQUIRES(ofproto_mutex)
3823 struct rule_dpif *rule = rule_dpif_cast(rule_);
3824 complete_operation(rule);
3829 rule_delete(struct rule *rule_)
3830 OVS_REQUIRES(ofproto_mutex)
3832 struct rule_dpif *rule = rule_dpif_cast(rule_);
3833 complete_operation(rule);
3837 rule_destruct(struct rule *rule_)
3839 struct rule_dpif *rule = rule_dpif_cast(rule_);
3841 ovs_mutex_destroy(&rule->stats_mutex);
3842 if (rule->recirc_id) {
3843 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
3845 ofproto_dpif_free_recirc_id(ofproto, rule->recirc_id);
3850 rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes,
3851 long long int *used)
3853 struct rule_dpif *rule = rule_dpif_cast(rule_);
3855 ovs_mutex_lock(&rule->stats_mutex);
3856 *packets = rule->stats.n_packets;
3857 *bytes = rule->stats.n_bytes;
3858 *used = rule->stats.used;
3859 ovs_mutex_unlock(&rule->stats_mutex);
3863 rule_dpif_execute(struct rule_dpif *rule, const struct flow *flow,
3864 struct ofpbuf *packet)
3866 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
3868 ofproto_dpif_execute_actions(ofproto, flow, rule, NULL, 0, packet);
3872 rule_execute(struct rule *rule, const struct flow *flow,
3873 struct ofpbuf *packet)
3875 rule_dpif_execute(rule_dpif_cast(rule), flow, packet);
3876 ofpbuf_delete(packet);
3881 rule_modify_actions(struct rule *rule_, bool reset_counters)
3882 OVS_REQUIRES(ofproto_mutex)
3884 struct rule_dpif *rule = rule_dpif_cast(rule_);
3886 if (reset_counters) {
3887 ovs_mutex_lock(&rule->stats_mutex);
3888 rule->stats.n_packets = 0;
3889 rule->stats.n_bytes = 0;
3890 ovs_mutex_unlock(&rule->stats_mutex);
3893 complete_operation(rule);
3896 static struct group_dpif *group_dpif_cast(const struct ofgroup *group)
3898 return group ? CONTAINER_OF(group, struct group_dpif, up) : NULL;
3901 static struct ofgroup *
3904 struct group_dpif *group = xzalloc(sizeof *group);
3909 group_dealloc(struct ofgroup *group_)
3911 struct group_dpif *group = group_dpif_cast(group_);
3916 group_construct_stats(struct group_dpif *group)
3917 OVS_REQUIRES(group->stats_mutex)
3919 struct ofputil_bucket *bucket;
3920 const struct list *buckets;
3922 group->packet_count = 0;
3923 group->byte_count = 0;
3925 group_dpif_get_buckets(group, &buckets);
3926 LIST_FOR_EACH (bucket, list_node, buckets) {
3927 bucket->stats.packet_count = 0;
3928 bucket->stats.byte_count = 0;
3933 group_dpif_credit_stats(struct group_dpif *group,
3934 struct ofputil_bucket *bucket,
3935 const struct dpif_flow_stats *stats)
3937 ovs_mutex_lock(&group->stats_mutex);
3938 group->packet_count += stats->n_packets;
3939 group->byte_count += stats->n_bytes;
3941 bucket->stats.packet_count += stats->n_packets;
3942 bucket->stats.byte_count += stats->n_bytes;
3943 } else { /* Credit to all buckets */
3944 const struct list *buckets;
3946 group_dpif_get_buckets(group, &buckets);
3947 LIST_FOR_EACH (bucket, list_node, buckets) {
3948 bucket->stats.packet_count += stats->n_packets;
3949 bucket->stats.byte_count += stats->n_bytes;
3952 ovs_mutex_unlock(&group->stats_mutex);
3956 group_construct(struct ofgroup *group_)
3958 struct group_dpif *group = group_dpif_cast(group_);
3959 const struct ofputil_bucket *bucket;
3961 /* Prevent group chaining because our locking structure makes it hard to
3962 * implement deadlock-free. (See xlate_group_resource_check().) */
3963 LIST_FOR_EACH (bucket, list_node, &group->up.buckets) {
3964 const struct ofpact *a;
3966 OFPACT_FOR_EACH (a, bucket->ofpacts, bucket->ofpacts_len) {
3967 if (a->type == OFPACT_GROUP) {
3968 return OFPERR_OFPGMFC_CHAINING_UNSUPPORTED;
3973 ovs_mutex_init_adaptive(&group->stats_mutex);
3974 ovs_mutex_lock(&group->stats_mutex);
3975 group_construct_stats(group);
3976 ovs_mutex_unlock(&group->stats_mutex);
3981 group_destruct(struct ofgroup *group_)
3983 struct group_dpif *group = group_dpif_cast(group_);
3984 ovs_mutex_destroy(&group->stats_mutex);
3988 group_modify(struct ofgroup *group_)
3990 struct ofproto_dpif *ofproto = ofproto_dpif_cast(group_->ofproto);
3992 ofproto->backer->need_revalidate = REV_FLOW_TABLE;
3998 group_get_stats(const struct ofgroup *group_, struct ofputil_group_stats *ogs)
4000 struct group_dpif *group = group_dpif_cast(group_);
4001 struct ofputil_bucket *bucket;
4002 const struct list *buckets;
4003 struct bucket_counter *bucket_stats;
4005 ovs_mutex_lock(&group->stats_mutex);
4006 ogs->packet_count = group->packet_count;
4007 ogs->byte_count = group->byte_count;
4009 group_dpif_get_buckets(group, &buckets);
4010 bucket_stats = ogs->bucket_stats;
4011 LIST_FOR_EACH (bucket, list_node, buckets) {
4012 bucket_stats->packet_count = bucket->stats.packet_count;
4013 bucket_stats->byte_count = bucket->stats.byte_count;
4016 ovs_mutex_unlock(&group->stats_mutex);
4021 /* If the group exists, this function increments the groups's reference count.
4023 * Make sure to call group_dpif_unref() after no longer needing to maintain
4024 * a reference to the group. */
4026 group_dpif_lookup(struct ofproto_dpif *ofproto, uint32_t group_id,
4027 struct group_dpif **group)
4029 struct ofgroup *ofgroup;
4032 found = ofproto_group_lookup(&ofproto->up, group_id, &ofgroup);
4033 *group = found ? group_dpif_cast(ofgroup) : NULL;
4039 group_dpif_get_buckets(const struct group_dpif *group,
4040 const struct list **buckets)
4042 *buckets = &group->up.buckets;
4045 enum ofp11_group_type
4046 group_dpif_get_type(const struct group_dpif *group)
4048 return group->up.type;
4051 /* Sends 'packet' out 'ofport'.
4052 * May modify 'packet'.
4053 * Returns 0 if successful, otherwise a positive errno value. */
4055 ofproto_dpif_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet)
4057 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
4060 error = xlate_send_packet(ofport, packet);
4062 ovs_mutex_lock(&ofproto->stats_mutex);
4063 ofproto->stats.tx_packets++;
4064 ofproto->stats.tx_bytes += ofpbuf_size(packet);
4065 ovs_mutex_unlock(&ofproto->stats_mutex);
4070 set_frag_handling(struct ofproto *ofproto_,
4071 enum ofp_config_flags frag_handling)
4073 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4074 if (frag_handling != OFPC_FRAG_REASM) {
4075 ofproto->backer->need_revalidate = REV_RECONFIGURE;
4083 packet_out(struct ofproto *ofproto_, struct ofpbuf *packet,
4084 const struct flow *flow,
4085 const struct ofpact *ofpacts, size_t ofpacts_len)
4087 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4089 ofproto_dpif_execute_actions(ofproto, flow, NULL, ofpacts,
4090 ofpacts_len, packet);
4097 set_netflow(struct ofproto *ofproto_,
4098 const struct netflow_options *netflow_options)
4100 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4102 if (netflow_options) {
4103 if (!ofproto->netflow) {
4104 ofproto->netflow = netflow_create();
4105 ofproto->backer->need_revalidate = REV_RECONFIGURE;
4107 return netflow_set_options(ofproto->netflow, netflow_options);
4108 } else if (ofproto->netflow) {
4109 ofproto->backer->need_revalidate = REV_RECONFIGURE;
4110 netflow_unref(ofproto->netflow);
4111 ofproto->netflow = NULL;
4118 get_netflow_ids(const struct ofproto *ofproto_,
4119 uint8_t *engine_type, uint8_t *engine_id)
4121 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4123 dpif_get_netflow_ids(ofproto->backer->dpif, engine_type, engine_id);
4126 static struct ofproto_dpif *
4127 ofproto_dpif_lookup(const char *name)
4129 struct ofproto_dpif *ofproto;
4131 HMAP_FOR_EACH_WITH_HASH (ofproto, all_ofproto_dpifs_node,
4132 hash_string(name, 0), &all_ofproto_dpifs) {
4133 if (!strcmp(ofproto->up.name, name)) {
4141 ofproto_unixctl_fdb_flush(struct unixctl_conn *conn, int argc,
4142 const char *argv[], void *aux OVS_UNUSED)
4144 struct ofproto_dpif *ofproto;
4147 ofproto = ofproto_dpif_lookup(argv[1]);
4149 unixctl_command_reply_error(conn, "no such bridge");
4152 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
4153 mac_learning_flush(ofproto->ml);
4154 ovs_rwlock_unlock(&ofproto->ml->rwlock);
4156 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
4157 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
4158 mac_learning_flush(ofproto->ml);
4159 ovs_rwlock_unlock(&ofproto->ml->rwlock);
4163 unixctl_command_reply(conn, "table successfully flushed");
4167 ofproto_unixctl_mcast_snooping_flush(struct unixctl_conn *conn, int argc,
4168 const char *argv[], void *aux OVS_UNUSED)
4170 struct ofproto_dpif *ofproto;
4173 ofproto = ofproto_dpif_lookup(argv[1]);
4175 unixctl_command_reply_error(conn, "no such bridge");
4179 if (!mcast_snooping_enabled(ofproto->ms)) {
4180 unixctl_command_reply_error(conn, "multicast snooping is disabled");
4183 mcast_snooping_mdb_flush(ofproto->ms);
4185 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
4186 if (!mcast_snooping_enabled(ofproto->ms)) {
4189 mcast_snooping_mdb_flush(ofproto->ms);
4193 unixctl_command_reply(conn, "table successfully flushed");
4196 static struct ofport_dpif *
4197 ofbundle_get_a_port(const struct ofbundle *bundle)
4199 return CONTAINER_OF(list_front(&bundle->ports), struct ofport_dpif,
4204 ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
4205 const char *argv[], void *aux OVS_UNUSED)
4207 struct ds ds = DS_EMPTY_INITIALIZER;
4208 const struct ofproto_dpif *ofproto;
4209 const struct mac_entry *e;
4211 ofproto = ofproto_dpif_lookup(argv[1]);
4213 unixctl_command_reply_error(conn, "no such bridge");
4217 ds_put_cstr(&ds, " port VLAN MAC Age\n");
4218 ovs_rwlock_rdlock(&ofproto->ml->rwlock);
4219 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
4220 struct ofbundle *bundle = e->port.p;
4221 char name[OFP_MAX_PORT_NAME_LEN];
4223 ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port,
4225 ds_put_format(&ds, "%5s %4d "ETH_ADDR_FMT" %3d\n",
4226 name, e->vlan, ETH_ADDR_ARGS(e->mac),
4227 mac_entry_age(ofproto->ml, e));
4229 ovs_rwlock_unlock(&ofproto->ml->rwlock);
4230 unixctl_command_reply(conn, ds_cstr(&ds));
4235 ofproto_unixctl_mcast_snooping_show(struct unixctl_conn *conn,
4236 int argc OVS_UNUSED,
4238 void *aux OVS_UNUSED)
4240 struct ds ds = DS_EMPTY_INITIALIZER;
4241 const struct ofproto_dpif *ofproto;
4242 const struct ofbundle *bundle;
4243 const struct mcast_group *grp;
4244 struct mcast_group_bundle *b;
4245 struct mcast_mrouter_bundle *mrouter;
4247 ofproto = ofproto_dpif_lookup(argv[1]);
4249 unixctl_command_reply_error(conn, "no such bridge");
4253 if (!mcast_snooping_enabled(ofproto->ms)) {
4254 unixctl_command_reply_error(conn, "multicast snooping is disabled");
4258 ds_put_cstr(&ds, " port VLAN GROUP Age\n");
4259 ovs_rwlock_rdlock(&ofproto->ms->rwlock);
4260 LIST_FOR_EACH (grp, group_node, &ofproto->ms->group_lru) {
4261 LIST_FOR_EACH(b, bundle_node, &grp->bundle_lru) {
4262 char name[OFP_MAX_PORT_NAME_LEN];
4265 ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port,
4267 ds_put_format(&ds, "%5s %4d "IP_FMT" %3d\n",
4268 name, grp->vlan, IP_ARGS(grp->ip4),
4269 mcast_bundle_age(ofproto->ms, b));
4273 /* ports connected to multicast routers */
4274 LIST_FOR_EACH(mrouter, mrouter_node, &ofproto->ms->mrouter_lru) {
4275 char name[OFP_MAX_PORT_NAME_LEN];
4277 bundle = mrouter->port;
4278 ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port,
4280 ds_put_format(&ds, "%5s %4d querier %3d\n",
4281 name, mrouter->vlan,
4282 mcast_mrouter_age(ofproto->ms, mrouter));
4284 ovs_rwlock_unlock(&ofproto->ms->rwlock);
4285 unixctl_command_reply(conn, ds_cstr(&ds));
4290 struct xlate_out xout;
4291 struct xlate_in xin;
4292 const struct flow *key;
4294 struct flow_wildcards wc;
4299 trace_format_rule(struct ds *result, int level, const struct rule_dpif *rule)
4301 const struct rule_actions *actions;
4304 ds_put_char_multiple(result, '\t', level);
4306 ds_put_cstr(result, "No match\n");
4310 ovs_mutex_lock(&rule->up.mutex);
4311 cookie = rule->up.flow_cookie;
4312 ovs_mutex_unlock(&rule->up.mutex);
4314 ds_put_format(result, "Rule: table=%"PRIu8" cookie=%#"PRIx64" ",
4315 rule ? rule->up.table_id : 0, ntohll(cookie));
4316 cls_rule_format(&rule->up.cr, result);
4317 ds_put_char(result, '\n');
4319 actions = rule_dpif_get_actions(rule);
4321 ds_put_char_multiple(result, '\t', level);
4322 ds_put_cstr(result, "OpenFlow actions=");
4323 ofpacts_format(actions->ofpacts, actions->ofpacts_len, result);
4324 ds_put_char(result, '\n');
4328 trace_format_flow(struct ds *result, int level, const char *title,
4329 struct trace_ctx *trace)
4331 ds_put_char_multiple(result, '\t', level);
4332 ds_put_format(result, "%s: ", title);
4333 /* Do not report unchanged flows for resubmits. */
4334 if ((level > 0 && flow_equal(&trace->xin.flow, &trace->flow))
4335 || (level == 0 && flow_equal(&trace->xin.flow, trace->key))) {
4336 ds_put_cstr(result, "unchanged");
4338 flow_format(result, &trace->xin.flow);
4339 trace->flow = trace->xin.flow;
4341 ds_put_char(result, '\n');
4345 trace_format_regs(struct ds *result, int level, const char *title,
4346 struct trace_ctx *trace)
4350 ds_put_char_multiple(result, '\t', level);
4351 ds_put_format(result, "%s:", title);
4352 for (i = 0; i < FLOW_N_REGS; i++) {
4353 ds_put_format(result, " reg%"PRIuSIZE"=0x%"PRIx32, i, trace->flow.regs[i]);
4355 ds_put_char(result, '\n');
4359 trace_format_odp(struct ds *result, int level, const char *title,
4360 struct trace_ctx *trace)
4362 struct ofpbuf *odp_actions = trace->xout.odp_actions;
4364 ds_put_char_multiple(result, '\t', level);
4365 ds_put_format(result, "%s: ", title);
4366 format_odp_actions(result, ofpbuf_data(odp_actions),
4367 ofpbuf_size(odp_actions));
4368 ds_put_char(result, '\n');
4372 trace_format_megaflow(struct ds *result, int level, const char *title,
4373 struct trace_ctx *trace)
4377 ds_put_char_multiple(result, '\t', level);
4378 ds_put_format(result, "%s: ", title);
4379 flow_wildcards_or(&trace->wc, &trace->xout.wc, &trace->wc);
4380 match_init(&match, trace->key, &trace->wc);
4381 match_format(&match, result, OFP_DEFAULT_PRIORITY);
4382 ds_put_char(result, '\n');
4386 trace_resubmit(struct xlate_in *xin, struct rule_dpif *rule, int recurse)
4388 struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin);
4389 struct ds *result = trace->result;
4391 ds_put_char(result, '\n');
4392 trace_format_flow(result, recurse + 1, "Resubmitted flow", trace);
4393 trace_format_regs(result, recurse + 1, "Resubmitted regs", trace);
4394 trace_format_odp(result, recurse + 1, "Resubmitted odp", trace);
4395 trace_format_megaflow(result, recurse + 1, "Resubmitted megaflow", trace);
4396 trace_format_rule(result, recurse + 1, rule);
4400 trace_report(struct xlate_in *xin, const char *s, int recurse)
4402 struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin);
4403 struct ds *result = trace->result;
4405 ds_put_char_multiple(result, '\t', recurse);
4406 ds_put_cstr(result, s);
4407 ds_put_char(result, '\n');
4410 /* Parses the 'argc' elements of 'argv', ignoring argv[0]. The following
4411 * forms are supported:
4413 * - [dpname] odp_flow [-generate | packet]
4414 * - bridge br_flow [-generate | packet]
4416 * On success, initializes '*ofprotop' and 'flow' and returns NULL. On failure
4417 * returns a nonnull malloced error message. */
4418 static char * WARN_UNUSED_RESULT
4419 parse_flow_and_packet(int argc, const char *argv[],
4420 struct ofproto_dpif **ofprotop, struct flow *flow,
4421 struct ofpbuf **packetp)
4423 const struct dpif_backer *backer = NULL;
4424 const char *error = NULL;
4426 struct simap port_names = SIMAP_INITIALIZER(&port_names);
4427 struct ofpbuf *packet;
4428 struct ofpbuf odp_key;
4429 struct ofpbuf odp_mask;
4431 ofpbuf_init(&odp_key, 0);
4432 ofpbuf_init(&odp_mask, 0);
4434 /* Handle "-generate" or a hex string as the last argument. */
4435 if (!strcmp(argv[argc - 1], "-generate")) {
4436 packet = ofpbuf_new(0);
4439 error = eth_from_hex(argv[argc - 1], &packet);
4442 } else if (argc == 4) {
4443 /* The 3-argument form must end in "-generate' or a hex string. */
4449 /* odp_flow can have its in_port specified as a name instead of port no.
4450 * We do not yet know whether a given flow is a odp_flow or a br_flow.
4451 * But, to know whether a flow is odp_flow through odp_flow_from_string(),
4452 * we need to create a simap of name to port no. */
4454 const char *dp_type;
4455 if (!strncmp(argv[1], "ovs-", 4)) {
4456 dp_type = argv[1] + 4;
4460 backer = shash_find_data(&all_dpif_backers, dp_type);
4461 } else if (argc == 2) {
4462 struct shash_node *node;
4463 if (shash_count(&all_dpif_backers) == 1) {
4464 node = shash_first(&all_dpif_backers);
4465 backer = node->data;
4468 error = "Syntax error";
4471 if (backer && backer->dpif) {
4472 struct dpif_port dpif_port;
4473 struct dpif_port_dump port_dump;
4474 DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, backer->dpif) {
4475 simap_put(&port_names, dpif_port.name,
4476 odp_to_u32(dpif_port.port_no));
4480 /* Parse the flow and determine whether a datapath or
4481 * bridge is specified. If function odp_flow_key_from_string()
4482 * returns 0, the flow is a odp_flow. If function
4483 * parse_ofp_exact_flow() returns NULL, the flow is a br_flow. */
4484 if (!odp_flow_from_string(argv[argc - 1], &port_names,
4485 &odp_key, &odp_mask)) {
4487 error = "Cannot find the datapath";
4491 if (odp_flow_key_to_flow(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key),
4492 flow) == ODP_FIT_ERROR) {
4493 error = "Failed to parse flow key";
4497 *ofprotop = xlate_lookup_ofproto(backer, flow,
4498 &flow->in_port.ofp_port);
4499 if (*ofprotop == NULL) {
4500 error = "Invalid datapath flow";
4504 vsp_adjust_flow(*ofprotop, flow, NULL);
4507 char *err = parse_ofp_exact_flow(flow, NULL, argv[argc - 1], NULL);
4510 m_err = xasprintf("Bad flow syntax: %s", err);
4515 error = "Must specify bridge name";
4519 *ofprotop = ofproto_dpif_lookup(argv[1]);
4521 error = "Unknown bridge name";
4527 /* Generate a packet, if requested. */
4529 if (!ofpbuf_size(packet)) {
4530 flow_compose(packet, flow);
4532 struct pkt_metadata md = pkt_metadata_from_flow(flow);
4534 /* Use the metadata from the flow and the packet argument
4535 * to reconstruct the flow. */
4536 flow_extract(packet, &md, flow);
4541 if (error && !m_err) {
4542 m_err = xstrdup(error);
4545 ofpbuf_delete(packet);
4549 ofpbuf_uninit(&odp_key);
4550 ofpbuf_uninit(&odp_mask);
4551 simap_destroy(&port_names);
4556 ofproto_unixctl_trace(struct unixctl_conn *conn, int argc, const char *argv[],
4557 void *aux OVS_UNUSED)
4559 struct ofproto_dpif *ofproto;
4560 struct ofpbuf *packet;
4564 error = parse_flow_and_packet(argc, argv, &ofproto, &flow, &packet);
4569 ofproto_trace(ofproto, &flow, packet, NULL, 0, &result);
4570 unixctl_command_reply(conn, ds_cstr(&result));
4571 ds_destroy(&result);
4572 ofpbuf_delete(packet);
4574 unixctl_command_reply_error(conn, error);
4580 ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc,
4581 const char *argv[], void *aux OVS_UNUSED)
4583 enum ofputil_protocol usable_protocols;
4584 struct ofproto_dpif *ofproto;
4585 bool enforce_consistency;
4586 struct ofpbuf ofpacts;
4587 struct ofpbuf *packet;
4592 /* Three kinds of error return values! */
4598 ofpbuf_init(&ofpacts, 0);
4600 /* Parse actions. */
4601 error = ofpacts_parse_actions(argv[--argc], &ofpacts, &usable_protocols);
4603 unixctl_command_reply_error(conn, error);
4608 /* OpenFlow 1.1 and later suggest that the switch enforces certain forms of
4609 * consistency between the flow and the actions. With -consistent, we
4610 * enforce consistency even for a flow supported in OpenFlow 1.0. */
4611 if (!strcmp(argv[1], "-consistent")) {
4612 enforce_consistency = true;
4616 enforce_consistency = false;
4619 error = parse_flow_and_packet(argc, argv, &ofproto, &flow, &packet);
4621 unixctl_command_reply_error(conn, error);
4626 /* Do the same checks as handle_packet_out() in ofproto.c.
4628 * We pass a 'table_id' of 0 to ofproto_check_ofpacts(), which isn't
4629 * strictly correct because these actions aren't in any table, but it's OK
4630 * because it 'table_id' is used only to check goto_table instructions, but
4631 * packet-outs take a list of actions and therefore it can't include
4634 * We skip the "meter" check here because meter is an instruction, not an
4635 * action, and thus cannot appear in ofpacts. */
4636 in_port = ofp_to_u16(flow.in_port.ofp_port);
4637 if (in_port >= ofproto->up.max_ports && in_port < ofp_to_u16(OFPP_MAX)) {
4638 unixctl_command_reply_error(conn, "invalid in_port");
4641 if (enforce_consistency) {
4642 retval = ofpacts_check_consistency(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts),
4643 &flow, u16_to_ofp(ofproto->up.max_ports),
4644 0, 0, usable_protocols);
4646 retval = ofpacts_check(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &flow,
4647 u16_to_ofp(ofproto->up.max_ports), 0, 0,
4653 ds_put_format(&result, "Bad actions: %s", ofperr_to_string(retval));
4654 unixctl_command_reply_error(conn, ds_cstr(&result));
4658 ofproto_trace(ofproto, &flow, packet,
4659 ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &result);
4660 unixctl_command_reply(conn, ds_cstr(&result));
4663 ds_destroy(&result);
4664 ofpbuf_delete(packet);
4665 ofpbuf_uninit(&ofpacts);
4668 /* Implements a "trace" through 'ofproto''s flow table, appending a textual
4669 * description of the results to 'ds'.
4671 * The trace follows a packet with the specified 'flow' through the flow
4672 * table. 'packet' may be nonnull to trace an actual packet, with consequent
4673 * side effects (if it is nonnull then its flow must be 'flow').
4675 * If 'ofpacts' is nonnull then its 'ofpacts_len' bytes specify the actions to
4676 * trace, otherwise the actions are determined by a flow table lookup. */
4678 ofproto_trace(struct ofproto_dpif *ofproto, struct flow *flow,
4679 const struct ofpbuf *packet,
4680 const struct ofpact ofpacts[], size_t ofpacts_len,
4683 struct rule_dpif *rule;
4684 struct trace_ctx trace;
4686 ds_put_format(ds, "Bridge: %s\n", ofproto->up.name);
4687 ds_put_cstr(ds, "Flow: ");
4688 flow_format(ds, flow);
4689 ds_put_char(ds, '\n');
4691 flow_wildcards_init_catchall(&trace.wc);
4695 rule_dpif_lookup(ofproto, flow, &trace.wc, &rule, false, NULL);
4697 trace_format_rule(ds, 0, rule);
4698 if (rule == ofproto->miss_rule) {
4699 ds_put_cstr(ds, "\nNo match, flow generates \"packet in\"s.\n");
4700 } else if (rule == ofproto->no_packet_in_rule) {
4701 ds_put_cstr(ds, "\nNo match, packets dropped because "
4702 "OFPPC_NO_PACKET_IN is set on in_port.\n");
4703 } else if (rule == ofproto->drop_frags_rule) {
4704 ds_put_cstr(ds, "\nPackets dropped because they are IP fragments "
4705 "and the fragment handling mode is \"drop\".\n");
4709 if (rule || ofpacts) {
4711 trace.key = flow; /* Original flow key, used for megaflow. */
4712 trace.flow = *flow; /* May be modified by actions. */
4713 xlate_in_init(&trace.xin, ofproto, flow, flow->in_port.ofp_port, rule,
4714 ntohs(flow->tcp_flags), packet);
4716 trace.xin.ofpacts = ofpacts;
4717 trace.xin.ofpacts_len = ofpacts_len;
4719 trace.xin.resubmit_hook = trace_resubmit;
4720 trace.xin.report_hook = trace_report;
4722 xlate_actions(&trace.xin, &trace.xout);
4724 ds_put_char(ds, '\n');
4725 trace_format_flow(ds, 0, "Final flow", &trace);
4726 trace_format_megaflow(ds, 0, "Megaflow", &trace);
4728 ds_put_cstr(ds, "Datapath actions: ");
4729 format_odp_actions(ds, ofpbuf_data(trace.xout.odp_actions),
4730 ofpbuf_size(trace.xout.odp_actions));
4732 if (trace.xout.slow) {
4733 enum slow_path_reason slow;
4735 ds_put_cstr(ds, "\nThis flow is handled by the userspace "
4736 "slow path because it:");
4738 slow = trace.xout.slow;
4740 enum slow_path_reason bit = rightmost_1bit(slow);
4742 ds_put_format(ds, "\n\t- %s.",
4743 slow_path_reason_to_explanation(bit));
4749 xlate_out_uninit(&trace.xout);
4753 /* Store the current ofprotos in 'ofproto_shash'. Returns a sorted list
4754 * of the 'ofproto_shash' nodes. It is the responsibility of the caller
4755 * to destroy 'ofproto_shash' and free the returned value. */
4756 static const struct shash_node **
4757 get_ofprotos(struct shash *ofproto_shash)
4759 const struct ofproto_dpif *ofproto;
4761 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
4762 char *name = xasprintf("%s@%s", ofproto->up.type, ofproto->up.name);
4763 shash_add_nocopy(ofproto_shash, name, ofproto);
4766 return shash_sort(ofproto_shash);
4770 ofproto_unixctl_dpif_dump_dps(struct unixctl_conn *conn, int argc OVS_UNUSED,
4771 const char *argv[] OVS_UNUSED,
4772 void *aux OVS_UNUSED)
4774 struct ds ds = DS_EMPTY_INITIALIZER;
4775 struct shash ofproto_shash;
4776 const struct shash_node **sorted_ofprotos;
4779 shash_init(&ofproto_shash);
4780 sorted_ofprotos = get_ofprotos(&ofproto_shash);
4781 for (i = 0; i < shash_count(&ofproto_shash); i++) {
4782 const struct shash_node *node = sorted_ofprotos[i];
4783 ds_put_format(&ds, "%s\n", node->name);
4786 shash_destroy(&ofproto_shash);
4787 free(sorted_ofprotos);
4789 unixctl_command_reply(conn, ds_cstr(&ds));
4794 dpif_show_backer(const struct dpif_backer *backer, struct ds *ds)
4796 const struct shash_node **ofprotos;
4797 struct dpif_dp_stats dp_stats;
4798 struct shash ofproto_shash;
4801 dpif_get_dp_stats(backer->dpif, &dp_stats);
4803 ds_put_format(ds, "%s: hit:%"PRIu64" missed:%"PRIu64"\n",
4804 dpif_name(backer->dpif), dp_stats.n_hit, dp_stats.n_missed);
4806 shash_init(&ofproto_shash);
4807 ofprotos = get_ofprotos(&ofproto_shash);
4808 for (i = 0; i < shash_count(&ofproto_shash); i++) {
4809 struct ofproto_dpif *ofproto = ofprotos[i]->data;
4810 const struct shash_node **ports;
4813 if (ofproto->backer != backer) {
4817 ds_put_format(ds, "\t%s:\n", ofproto->up.name);
4819 ports = shash_sort(&ofproto->up.port_by_name);
4820 for (j = 0; j < shash_count(&ofproto->up.port_by_name); j++) {
4821 const struct shash_node *node = ports[j];
4822 struct ofport *ofport = node->data;
4824 odp_port_t odp_port;
4826 ds_put_format(ds, "\t\t%s %u/", netdev_get_name(ofport->netdev),
4829 odp_port = ofp_port_to_odp_port(ofproto, ofport->ofp_port);
4830 if (odp_port != ODPP_NONE) {
4831 ds_put_format(ds, "%"PRIu32":", odp_port);
4833 ds_put_cstr(ds, "none:");
4836 ds_put_format(ds, " (%s", netdev_get_type(ofport->netdev));
4839 if (!netdev_get_config(ofport->netdev, &config)) {
4840 const struct smap_node **nodes;
4843 nodes = smap_sort(&config);
4844 for (i = 0; i < smap_count(&config); i++) {
4845 const struct smap_node *node = nodes[i];
4846 ds_put_format(ds, "%c %s=%s", i ? ',' : ':',
4847 node->key, node->value);
4851 smap_destroy(&config);
4853 ds_put_char(ds, ')');
4854 ds_put_char(ds, '\n');
4858 shash_destroy(&ofproto_shash);
4863 ofproto_unixctl_dpif_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
4864 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
4866 struct ds ds = DS_EMPTY_INITIALIZER;
4867 const struct shash_node **backers;
4870 backers = shash_sort(&all_dpif_backers);
4871 for (i = 0; i < shash_count(&all_dpif_backers); i++) {
4872 dpif_show_backer(backers[i]->data, &ds);
4876 unixctl_command_reply(conn, ds_cstr(&ds));
4881 ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn,
4882 int argc OVS_UNUSED, const char *argv[],
4883 void *aux OVS_UNUSED)
4885 const struct ofproto_dpif *ofproto;
4887 struct ds ds = DS_EMPTY_INITIALIZER;
4888 bool verbosity = false;
4890 struct dpif_port dpif_port;
4891 struct dpif_port_dump port_dump;
4892 struct hmap portno_names;
4894 struct dpif_flow_dump *flow_dump;
4895 struct dpif_flow_dump_thread *flow_dump_thread;
4899 ofproto = ofproto_dpif_lookup(argv[argc - 1]);
4901 unixctl_command_reply_error(conn, "no such bridge");
4905 if (argc > 2 && !strcmp(argv[1], "-m")) {
4909 hmap_init(&portno_names);
4910 DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, ofproto->backer->dpif) {
4911 odp_portno_names_set(&portno_names, dpif_port.port_no, dpif_port.name);
4915 flow_dump = dpif_flow_dump_create(ofproto->backer->dpif);
4916 flow_dump_thread = dpif_flow_dump_thread_create(flow_dump);
4917 while (dpif_flow_dump_next(flow_dump_thread, &f, 1)) {
4920 if (odp_flow_key_to_flow(f.key, f.key_len, &flow) == ODP_FIT_ERROR
4921 || xlate_lookup_ofproto(ofproto->backer, &flow, NULL) != ofproto) {
4925 odp_flow_format(f.key, f.key_len, f.mask, f.mask_len,
4926 &portno_names, &ds, verbosity);
4927 ds_put_cstr(&ds, ", ");
4928 dpif_flow_stats_format(&f.stats, &ds);
4929 ds_put_cstr(&ds, ", actions:");
4930 format_odp_actions(&ds, f.actions, f.actions_len);
4931 ds_put_char(&ds, '\n');
4933 dpif_flow_dump_thread_destroy(flow_dump_thread);
4934 error = dpif_flow_dump_destroy(flow_dump);
4938 ds_put_format(&ds, "dpif/dump_flows failed: %s", ovs_strerror(errno));
4939 unixctl_command_reply_error(conn, ds_cstr(&ds));
4941 unixctl_command_reply(conn, ds_cstr(&ds));
4943 odp_portno_names_destroy(&portno_names);
4944 hmap_destroy(&portno_names);
4949 ofproto_dpif_unixctl_init(void)
4951 static bool registered;
4957 unixctl_command_register(
4959 "{[dp_name] odp_flow | bridge br_flow} [-generate|packet]",
4960 1, 3, ofproto_unixctl_trace, NULL);
4961 unixctl_command_register(
4962 "ofproto/trace-packet-out",
4963 "[-consistent] {[dp_name] odp_flow | bridge br_flow} [-generate|packet] actions",
4964 2, 6, ofproto_unixctl_trace_actions, NULL);
4965 unixctl_command_register("fdb/flush", "[bridge]", 0, 1,
4966 ofproto_unixctl_fdb_flush, NULL);
4967 unixctl_command_register("fdb/show", "bridge", 1, 1,
4968 ofproto_unixctl_fdb_show, NULL);
4969 unixctl_command_register("mdb/flush", "[bridge]", 0, 1,
4970 ofproto_unixctl_mcast_snooping_flush, NULL);
4971 unixctl_command_register("mdb/show", "bridge", 1, 1,
4972 ofproto_unixctl_mcast_snooping_show, NULL);
4973 unixctl_command_register("dpif/dump-dps", "", 0, 0,
4974 ofproto_unixctl_dpif_dump_dps, NULL);
4975 unixctl_command_register("dpif/show", "", 0, 0, ofproto_unixctl_dpif_show,
4977 unixctl_command_register("dpif/dump-flows", "[-m] bridge", 1, 2,
4978 ofproto_unixctl_dpif_dump_flows, NULL);
4981 /* Returns true if 'table' is the table used for internal rules,
4982 * false otherwise. */
4984 table_is_internal(uint8_t table_id)
4986 return table_id == TBL_INTERNAL;
4989 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
4991 * This is deprecated. It is only for compatibility with broken device drivers
4992 * in old versions of Linux that do not properly support VLANs when VLAN
4993 * devices are not used. When broken device drivers are no longer in
4994 * widespread use, we will delete these interfaces. */
4997 set_realdev(struct ofport *ofport_, ofp_port_t realdev_ofp_port, int vid)
4999 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport_->ofproto);
5000 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
5002 if (realdev_ofp_port == ofport->realdev_ofp_port
5003 && vid == ofport->vlandev_vid) {
5007 ofproto->backer->need_revalidate = REV_RECONFIGURE;
5009 if (ofport->realdev_ofp_port) {
5012 if (realdev_ofp_port && ofport->bundle) {
5013 /* vlandevs are enslaved to their realdevs, so they are not allowed to
5014 * themselves be part of a bundle. */
5015 bundle_set(ofport_->ofproto, ofport->bundle, NULL);
5018 ofport->realdev_ofp_port = realdev_ofp_port;
5019 ofport->vlandev_vid = vid;
5021 if (realdev_ofp_port) {
5022 vsp_add(ofport, realdev_ofp_port, vid);
5029 hash_realdev_vid(ofp_port_t realdev_ofp_port, int vid)
5031 return hash_2words(ofp_to_u16(realdev_ofp_port), vid);
5035 ofproto_has_vlan_splinters(const struct ofproto_dpif *ofproto)
5036 OVS_EXCLUDED(ofproto->vsp_mutex)
5038 /* hmap_is_empty is thread safe. */
5039 return !hmap_is_empty(&ofproto->realdev_vid_map);
5044 vsp_realdev_to_vlandev__(const struct ofproto_dpif *ofproto,
5045 ofp_port_t realdev_ofp_port, ovs_be16 vlan_tci)
5046 OVS_REQUIRES(ofproto->vsp_mutex)
5048 if (!hmap_is_empty(&ofproto->realdev_vid_map)) {
5049 int vid = vlan_tci_to_vid(vlan_tci);
5050 const struct vlan_splinter *vsp;
5052 HMAP_FOR_EACH_WITH_HASH (vsp, realdev_vid_node,
5053 hash_realdev_vid(realdev_ofp_port, vid),
5054 &ofproto->realdev_vid_map) {
5055 if (vsp->realdev_ofp_port == realdev_ofp_port
5056 && vsp->vid == vid) {
5057 return vsp->vlandev_ofp_port;
5061 return realdev_ofp_port;
5064 /* Returns the OFP port number of the Linux VLAN device that corresponds to
5065 * 'vlan_tci' on the network device with port number 'realdev_ofp_port' in
5066 * 'struct ofport_dpif'. For example, given 'realdev_ofp_port' of eth0 and
5067 * 'vlan_tci' 9, it would return the port number of eth0.9.
5069 * Unless VLAN splinters are enabled for port 'realdev_ofp_port', this
5070 * function just returns its 'realdev_ofp_port' argument. */
5072 vsp_realdev_to_vlandev(const struct ofproto_dpif *ofproto,
5073 ofp_port_t realdev_ofp_port, ovs_be16 vlan_tci)
5074 OVS_EXCLUDED(ofproto->vsp_mutex)
5078 /* hmap_is_empty is thread safe, see if we can return immediately. */
5079 if (hmap_is_empty(&ofproto->realdev_vid_map)) {
5080 return realdev_ofp_port;
5082 ovs_mutex_lock(&ofproto->vsp_mutex);
5083 ret = vsp_realdev_to_vlandev__(ofproto, realdev_ofp_port, vlan_tci);
5084 ovs_mutex_unlock(&ofproto->vsp_mutex);
5088 static struct vlan_splinter *
5089 vlandev_find(const struct ofproto_dpif *ofproto, ofp_port_t vlandev_ofp_port)
5091 struct vlan_splinter *vsp;
5093 HMAP_FOR_EACH_WITH_HASH (vsp, vlandev_node,
5094 hash_ofp_port(vlandev_ofp_port),
5095 &ofproto->vlandev_map) {
5096 if (vsp->vlandev_ofp_port == vlandev_ofp_port) {
5104 /* Returns the OpenFlow port number of the "real" device underlying the Linux
5105 * VLAN device with OpenFlow port number 'vlandev_ofp_port' and stores the
5106 * VLAN VID of the Linux VLAN device in '*vid'. For example, given
5107 * 'vlandev_ofp_port' of eth0.9, it would return the OpenFlow port number of
5108 * eth0 and store 9 in '*vid'.
5110 * Returns 0 and does not modify '*vid' if 'vlandev_ofp_port' is not a Linux
5111 * VLAN device. Unless VLAN splinters are enabled, this is what this function
5114 vsp_vlandev_to_realdev(const struct ofproto_dpif *ofproto,
5115 ofp_port_t vlandev_ofp_port, int *vid)
5116 OVS_REQUIRES(ofproto->vsp_mutex)
5118 if (!hmap_is_empty(&ofproto->vlandev_map)) {
5119 const struct vlan_splinter *vsp;
5121 vsp = vlandev_find(ofproto, vlandev_ofp_port);
5126 return vsp->realdev_ofp_port;
5132 /* Given 'flow', a flow representing a packet received on 'ofproto', checks
5133 * whether 'flow->in_port' represents a Linux VLAN device. If so, changes
5134 * 'flow->in_port' to the "real" device backing the VLAN device, sets
5135 * 'flow->vlan_tci' to the VLAN VID, and returns true. Optionally pushes the
5136 * appropriate VLAN on 'packet' if provided. Otherwise (which is always the
5137 * case unless VLAN splinters are enabled), returns false without making any
5140 vsp_adjust_flow(const struct ofproto_dpif *ofproto, struct flow *flow,
5141 struct ofpbuf *packet)
5142 OVS_EXCLUDED(ofproto->vsp_mutex)
5147 /* hmap_is_empty is thread safe. */
5148 if (hmap_is_empty(&ofproto->vlandev_map)) {
5152 ovs_mutex_lock(&ofproto->vsp_mutex);
5153 realdev = vsp_vlandev_to_realdev(ofproto, flow->in_port.ofp_port, &vid);
5154 ovs_mutex_unlock(&ofproto->vsp_mutex);
5159 /* Cause the flow to be processed as if it came in on the real device with
5160 * the VLAN device's VLAN ID. */
5161 flow->in_port.ofp_port = realdev;
5162 flow->vlan_tci = htons((vid & VLAN_VID_MASK) | VLAN_CFI);
5165 /* Make the packet resemble the flow, so that it gets sent to an
5166 * OpenFlow controller properly, so that it looks correct for sFlow,
5167 * and so that flow_extract() will get the correct vlan_tci if it is
5168 * called on 'packet'. */
5169 eth_push_vlan(packet, htons(ETH_TYPE_VLAN), flow->vlan_tci);
5176 vsp_remove(struct ofport_dpif *port)
5178 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
5179 struct vlan_splinter *vsp;
5181 ovs_mutex_lock(&ofproto->vsp_mutex);
5182 vsp = vlandev_find(ofproto, port->up.ofp_port);
5184 hmap_remove(&ofproto->vlandev_map, &vsp->vlandev_node);
5185 hmap_remove(&ofproto->realdev_vid_map, &vsp->realdev_vid_node);
5188 port->realdev_ofp_port = 0;
5190 VLOG_ERR("missing vlan device record");
5192 ovs_mutex_unlock(&ofproto->vsp_mutex);
5196 vsp_add(struct ofport_dpif *port, ofp_port_t realdev_ofp_port, int vid)
5198 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
5200 ovs_mutex_lock(&ofproto->vsp_mutex);
5201 if (!vsp_vlandev_to_realdev(ofproto, port->up.ofp_port, NULL)
5202 && (vsp_realdev_to_vlandev__(ofproto, realdev_ofp_port, htons(vid))
5203 == realdev_ofp_port)) {
5204 struct vlan_splinter *vsp;
5206 vsp = xmalloc(sizeof *vsp);
5207 vsp->realdev_ofp_port = realdev_ofp_port;
5208 vsp->vlandev_ofp_port = port->up.ofp_port;
5211 port->realdev_ofp_port = realdev_ofp_port;
5213 hmap_insert(&ofproto->vlandev_map, &vsp->vlandev_node,
5214 hash_ofp_port(port->up.ofp_port));
5215 hmap_insert(&ofproto->realdev_vid_map, &vsp->realdev_vid_node,
5216 hash_realdev_vid(realdev_ofp_port, vid));
5218 VLOG_ERR("duplicate vlan device record");
5220 ovs_mutex_unlock(&ofproto->vsp_mutex);
5224 ofp_port_to_odp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
5226 const struct ofport_dpif *ofport = get_ofp_port(ofproto, ofp_port);
5227 return ofport ? ofport->odp_port : ODPP_NONE;
5230 struct ofport_dpif *
5231 odp_port_to_ofport(const struct dpif_backer *backer, odp_port_t odp_port)
5233 struct ofport_dpif *port;
5235 ovs_rwlock_rdlock(&backer->odp_to_ofport_lock);
5236 HMAP_FOR_EACH_IN_BUCKET (port, odp_port_node, hash_odp_port(odp_port),
5237 &backer->odp_to_ofport_map) {
5238 if (port->odp_port == odp_port) {
5239 ovs_rwlock_unlock(&backer->odp_to_ofport_lock);
5244 ovs_rwlock_unlock(&backer->odp_to_ofport_lock);
5249 odp_port_to_ofp_port(const struct ofproto_dpif *ofproto, odp_port_t odp_port)
5251 struct ofport_dpif *port;
5253 port = odp_port_to_ofport(ofproto->backer, odp_port);
5254 if (port && &ofproto->up == port->up.ofproto) {
5255 return port->up.ofp_port;
5262 ofproto_dpif_alloc_recirc_id(struct ofproto_dpif *ofproto)
5264 struct dpif_backer *backer = ofproto->backer;
5266 return recirc_id_alloc(backer->rid_pool);
5270 ofproto_dpif_free_recirc_id(struct ofproto_dpif *ofproto, uint32_t recirc_id)
5272 struct dpif_backer *backer = ofproto->backer;
5274 recirc_id_free(backer->rid_pool, recirc_id);
5278 ofproto_dpif_add_internal_flow(struct ofproto_dpif *ofproto,
5279 const struct match *match, int priority,
5280 uint16_t idle_timeout,
5281 const struct ofpbuf *ofpacts,
5282 struct rule **rulep)
5284 struct ofputil_flow_mod fm;
5285 struct rule_dpif *rule;
5289 fm.priority = priority;
5290 fm.new_cookie = htonll(0);
5291 fm.cookie = htonll(0);
5292 fm.cookie_mask = htonll(0);
5293 fm.modify_cookie = false;
5294 fm.table_id = TBL_INTERNAL;
5295 fm.command = OFPFC_ADD;
5296 fm.idle_timeout = idle_timeout;
5297 fm.hard_timeout = 0;
5300 fm.flags = OFPUTIL_FF_HIDDEN_FIELDS | OFPUTIL_FF_NO_READONLY;
5301 fm.ofpacts = ofpbuf_data(ofpacts);
5302 fm.ofpacts_len = ofpbuf_size(ofpacts);
5304 error = ofproto_flow_mod(&ofproto->up, &fm);
5306 VLOG_ERR_RL(&rl, "failed to add internal flow (%s)",
5307 ofperr_to_string(error));
5312 rule = rule_dpif_lookup_in_table(ofproto, TBL_INTERNAL, &fm.match.flow,
5313 &fm.match.wc, false);
5323 ofproto_dpif_delete_internal_flow(struct ofproto_dpif *ofproto,
5324 struct match *match, int priority)
5326 struct ofputil_flow_mod fm;
5330 fm.priority = priority;
5331 fm.new_cookie = htonll(0);
5332 fm.cookie = htonll(0);
5333 fm.cookie_mask = htonll(0);
5334 fm.modify_cookie = false;
5335 fm.table_id = TBL_INTERNAL;
5336 fm.flags = OFPUTIL_FF_HIDDEN_FIELDS | OFPUTIL_FF_NO_READONLY;
5337 fm.command = OFPFC_DELETE_STRICT;
5339 error = ofproto_flow_mod(&ofproto->up, &fm);
5341 VLOG_ERR_RL(&rl, "failed to delete internal flow (%s)",
5342 ofperr_to_string(error));
5349 const struct ofproto_class ofproto_dpif_class = {
5363 NULL, /* get_memory_usage. */
5364 type_get_memory_usage,
5382 port_is_lacp_current,
5383 NULL, /* rule_choose_table */
5392 NULL, /* rule_premodify_actions */
5393 rule_modify_actions,
5409 get_stp_port_status,
5414 get_rstp_port_status,
5421 is_mirror_output_bundle,
5422 forward_bpdu_changed,
5423 set_mac_table_config,
5425 set_mcast_snooping_port,
5427 NULL, /* meter_get_features */
5428 NULL, /* meter_set */
5429 NULL, /* meter_get */
5430 NULL, /* meter_del */
5431 group_alloc, /* group_alloc */
5432 group_construct, /* group_construct */
5433 group_destruct, /* group_destruct */
5434 group_dealloc, /* group_dealloc */
5435 group_modify, /* group_modify */
5436 group_get_stats, /* group_get_stats */