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 "meta-flow.h"
41 #include "multipath.h"
42 #include "netdev-vport.h"
47 #include "odp-execute.h"
50 #include "ofp-actions.h"
51 #include "ofp-parse.h"
52 #include "ofp-print.h"
53 #include "ofproto-dpif-ipfix.h"
54 #include "ofproto-dpif-mirror.h"
55 #include "ofproto-dpif-monitor.h"
56 #include "ofproto-dpif-rid.h"
57 #include "ofproto-dpif-sflow.h"
58 #include "ofproto-dpif-upcall.h"
59 #include "ofproto-dpif-xlate.h"
60 #include "poll-loop.h"
66 #include "unaligned.h"
68 #include "vlan-bitmap.h"
71 VLOG_DEFINE_THIS_MODULE(ofproto_dpif);
73 COVERAGE_DEFINE(ofproto_dpif_expired);
74 COVERAGE_DEFINE(packet_in_overflow);
76 /* Number of implemented OpenFlow tables. */
77 enum { N_TABLES = 255 };
78 enum { TBL_INTERNAL = N_TABLES - 1 }; /* Used for internal hidden rules. */
79 BUILD_ASSERT_DECL(N_TABLES >= 2 && N_TABLES <= 255);
88 * - Do include packets and bytes from datapath flows which have not
89 * recently been processed by a revalidator. */
90 struct ovs_mutex stats_mutex;
91 struct dpif_flow_stats stats OVS_GUARDED;
94 static void rule_get_stats(struct rule *, uint64_t *packets, uint64_t *bytes,
96 static struct rule_dpif *rule_dpif_cast(const struct rule *);
97 static void rule_expire(struct rule_dpif *);
104 * - Do include packets and bytes from datapath flows which have not
105 * recently been processed by a revalidator. */
106 struct ovs_mutex stats_mutex;
107 uint64_t packet_count OVS_GUARDED; /* Number of packets received. */
108 uint64_t byte_count OVS_GUARDED; /* Number of bytes received. */
109 struct bucket_counter *bucket_stats OVS_GUARDED; /* Bucket statistics. */
113 struct hmap_node hmap_node; /* In struct ofproto's "bundles" hmap. */
114 struct ofproto_dpif *ofproto; /* Owning ofproto. */
115 void *aux; /* Key supplied by ofproto's client. */
116 char *name; /* Identifier for log messages. */
119 struct list ports; /* Contains "struct ofport"s. */
120 enum port_vlan_mode vlan_mode; /* VLAN mode */
121 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
122 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
123 * NULL if all VLANs are trunked. */
124 struct lacp *lacp; /* LACP if LACP is enabled, otherwise NULL. */
125 struct bond *bond; /* Nonnull iff more than one port. */
126 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
129 bool floodable; /* True if no port has OFPUTIL_PC_NO_FLOOD set. */
132 static void bundle_remove(struct ofport *);
133 static void bundle_update(struct ofbundle *);
134 static void bundle_destroy(struct ofbundle *);
135 static void bundle_del_port(struct ofport_dpif *);
136 static void bundle_run(struct ofbundle *);
137 static void bundle_wait(struct ofbundle *);
139 static void stp_run(struct ofproto_dpif *ofproto);
140 static void stp_wait(struct ofproto_dpif *ofproto);
141 static int set_stp_port(struct ofport *,
142 const struct ofproto_port_stp_settings *);
145 struct hmap_node odp_port_node; /* In dpif_backer's "odp_to_ofport_map". */
149 struct ofbundle *bundle; /* Bundle that contains this port, if any. */
150 struct list bundle_node; /* In struct ofbundle's "ports" list. */
151 struct cfm *cfm; /* Connectivity Fault Management, if any. */
152 struct bfd *bfd; /* BFD, if any. */
153 bool may_enable; /* May be enabled in bonds. */
154 bool is_tunnel; /* This port is a tunnel. */
155 bool is_layer3; /* This is a layer 3 port. */
156 long long int carrier_seq; /* Carrier status changes. */
157 struct ofport_dpif *peer; /* Peer if patch port. */
160 struct stp_port *stp_port; /* Spanning Tree Protocol, if any. */
161 enum stp_state stp_state; /* Always STP_DISABLED if STP not in use. */
162 long long int stp_state_entered;
164 /* Queue to DSCP mapping. */
165 struct ofproto_port_queue *qdscp;
168 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
170 * This is deprecated. It is only for compatibility with broken device
171 * drivers in old versions of Linux that do not properly support VLANs when
172 * VLAN devices are not used. When broken device drivers are no longer in
173 * widespread use, we will delete these interfaces. */
174 ofp_port_t realdev_ofp_port;
178 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
180 * This is deprecated. It is only for compatibility with broken device drivers
181 * in old versions of Linux that do not properly support VLANs when VLAN
182 * devices are not used. When broken device drivers are no longer in
183 * widespread use, we will delete these interfaces. */
184 struct vlan_splinter {
185 struct hmap_node realdev_vid_node;
186 struct hmap_node vlandev_node;
187 ofp_port_t realdev_ofp_port;
188 ofp_port_t vlandev_ofp_port;
192 static void vsp_remove(struct ofport_dpif *);
193 static void vsp_add(struct ofport_dpif *, ofp_port_t realdev_ofp_port, int vid);
195 static odp_port_t ofp_port_to_odp_port(const struct ofproto_dpif *,
198 static ofp_port_t odp_port_to_ofp_port(const struct ofproto_dpif *,
201 static struct ofport_dpif *
202 ofport_dpif_cast(const struct ofport *ofport)
204 return ofport ? CONTAINER_OF(ofport, struct ofport_dpif, up) : NULL;
207 static void port_run(struct ofport_dpif *);
208 static int set_bfd(struct ofport *, const struct smap *);
209 static int set_cfm(struct ofport *, const struct cfm_settings *);
210 static void ofport_update_peer(struct ofport_dpif *);
212 struct dpif_completion {
213 struct list list_node;
214 struct ofoperation *op;
217 /* Reasons that we might need to revalidate every datapath flow, and
218 * corresponding coverage counters.
220 * A value of 0 means that there is no need to revalidate.
222 * It would be nice to have some cleaner way to integrate with coverage
223 * counters, but with only a few reasons I guess this is good enough for
225 enum revalidate_reason {
226 REV_RECONFIGURE = 1, /* Switch configuration changed. */
227 REV_STP, /* Spanning tree protocol port status change. */
228 REV_BOND, /* Bonding changed. */
229 REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/
230 REV_FLOW_TABLE, /* Flow table changed. */
231 REV_MAC_LEARNING, /* Mac learning changed. */
233 COVERAGE_DEFINE(rev_reconfigure);
234 COVERAGE_DEFINE(rev_stp);
235 COVERAGE_DEFINE(rev_bond);
236 COVERAGE_DEFINE(rev_port_toggled);
237 COVERAGE_DEFINE(rev_flow_table);
238 COVERAGE_DEFINE(rev_mac_learning);
240 /* All datapaths of a given type share a single dpif backer instance. */
247 struct ovs_rwlock odp_to_ofport_lock;
248 struct hmap odp_to_ofport_map OVS_GUARDED; /* Contains "struct ofport"s. */
250 struct simap tnl_backers; /* Set of dpif ports backing tunnels. */
252 enum revalidate_reason need_revalidate; /* Revalidate all flows. */
254 bool recv_set_enable; /* Enables or disables receiving packets. */
256 struct recirc_id_pool *rid_pool; /* Recirculation ID pool. */
258 /* True if the datapath supports variable-length
259 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions.
260 * False if the datapath supports only 8-byte (or shorter) userdata. */
261 bool variable_length_userdata;
263 /* Maximum number of MPLS label stack entries that the datapath supports
265 size_t max_mpls_depth;
268 /* All existing ofproto_backer instances, indexed by ofproto->up.type. */
269 static struct shash all_dpif_backers = SHASH_INITIALIZER(&all_dpif_backers);
271 struct ofproto_dpif {
272 struct hmap_node all_ofproto_dpifs_node; /* In 'all_ofproto_dpifs'. */
274 struct dpif_backer *backer;
276 uint64_t dump_seq; /* Last read of udpif_dump_seq(). */
278 /* Special OpenFlow rules. */
279 struct rule_dpif *miss_rule; /* Sends flow table misses to controller. */
280 struct rule_dpif *no_packet_in_rule; /* Drops flow table misses. */
281 struct rule_dpif *drop_frags_rule; /* Used in OFPC_FRAG_DROP mode. */
284 struct netflow *netflow;
285 struct dpif_sflow *sflow;
286 struct dpif_ipfix *ipfix;
287 struct hmap bundles; /* Contains "struct ofbundle"s. */
288 struct mac_learning *ml;
289 bool has_bonded_bundles;
291 struct mbridge *mbridge;
293 struct ovs_mutex stats_mutex;
294 struct netdev_stats stats OVS_GUARDED; /* To account packets generated and
295 * consumed in userspace. */
299 long long int stp_last_tick;
301 /* VLAN splinters. */
302 struct ovs_mutex vsp_mutex;
303 struct hmap realdev_vid_map OVS_GUARDED; /* (realdev,vid) -> vlandev. */
304 struct hmap vlandev_map OVS_GUARDED; /* vlandev -> (realdev,vid). */
307 struct sset ports; /* Set of standard port names. */
308 struct sset ghost_ports; /* Ports with no datapath port. */
309 struct sset port_poll_set; /* Queued names for port_poll() reply. */
310 int port_poll_errno; /* Last errno for port_poll() reply. */
311 uint64_t change_seq; /* Connectivity status changes. */
314 struct guarded_list pins; /* Contains "struct ofputil_packet_in"s. */
317 /* All existing ofproto_dpif instances, indexed by ->up.name. */
318 static struct hmap all_ofproto_dpifs = HMAP_INITIALIZER(&all_ofproto_dpifs);
320 static void ofproto_dpif_unixctl_init(void);
322 static inline struct ofproto_dpif *
323 ofproto_dpif_cast(const struct ofproto *ofproto)
325 ovs_assert(ofproto->ofproto_class == &ofproto_dpif_class);
326 return CONTAINER_OF(ofproto, struct ofproto_dpif, up);
330 ofproto_dpif_get_max_mpls_depth(const struct ofproto_dpif *ofproto)
332 return ofproto->backer->max_mpls_depth;
335 static struct ofport_dpif *get_ofp_port(const struct ofproto_dpif *ofproto,
336 ofp_port_t ofp_port);
337 static void ofproto_trace(struct ofproto_dpif *, const struct flow *,
338 const struct ofpbuf *packet,
339 const struct ofpact[], size_t ofpacts_len,
342 /* Global variables. */
343 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
345 /* Initial mappings of port to bridge mappings. */
346 static struct shash init_ofp_ports = SHASH_INITIALIZER(&init_ofp_ports);
348 /* Executes 'fm'. The caller retains ownership of 'fm' and everything in
351 ofproto_dpif_flow_mod(struct ofproto_dpif *ofproto,
352 struct ofputil_flow_mod *fm)
354 ofproto_flow_mod(&ofproto->up, fm);
357 /* Appends 'pin' to the queue of "packet ins" to be sent to the controller.
358 * Takes ownership of 'pin' and pin->packet. */
360 ofproto_dpif_send_packet_in(struct ofproto_dpif *ofproto,
361 struct ofproto_packet_in *pin)
363 if (!guarded_list_push_back(&ofproto->pins, &pin->list_node, 1024)) {
364 COVERAGE_INC(packet_in_overflow);
365 free(CONST_CAST(void *, pin->up.packet));
370 /* Factory functions. */
373 init(const struct shash *iface_hints)
375 struct shash_node *node;
377 /* Make a local copy, since we don't own 'iface_hints' elements. */
378 SHASH_FOR_EACH(node, iface_hints) {
379 const struct iface_hint *orig_hint = node->data;
380 struct iface_hint *new_hint = xmalloc(sizeof *new_hint);
382 new_hint->br_name = xstrdup(orig_hint->br_name);
383 new_hint->br_type = xstrdup(orig_hint->br_type);
384 new_hint->ofp_port = orig_hint->ofp_port;
386 shash_add(&init_ofp_ports, node->name, new_hint);
391 enumerate_types(struct sset *types)
393 dp_enumerate_types(types);
397 enumerate_names(const char *type, struct sset *names)
399 struct ofproto_dpif *ofproto;
402 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
403 if (strcmp(type, ofproto->up.type)) {
406 sset_add(names, ofproto->up.name);
413 del(const char *type, const char *name)
418 error = dpif_open(name, type, &dpif);
420 error = dpif_delete(dpif);
427 port_open_type(const char *datapath_type, const char *port_type)
429 return dpif_port_open_type(datapath_type, port_type);
432 /* Type functions. */
434 static void process_dpif_port_changes(struct dpif_backer *);
435 static void process_dpif_all_ports_changed(struct dpif_backer *);
436 static void process_dpif_port_change(struct dpif_backer *,
437 const char *devname);
438 static void process_dpif_port_error(struct dpif_backer *, int error);
440 static struct ofproto_dpif *
441 lookup_ofproto_dpif_by_port_name(const char *name)
443 struct ofproto_dpif *ofproto;
445 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
446 if (sset_contains(&ofproto->ports, name)) {
455 type_run(const char *type)
457 struct dpif_backer *backer;
459 backer = shash_find_data(&all_dpif_backers, type);
461 /* This is not necessarily a problem, since backers are only
462 * created on demand. */
466 dpif_run(backer->dpif);
468 /* If vswitchd started with other_config:flow_restore_wait set as "true",
469 * and the configuration has now changed to "false", enable receiving
470 * packets from the datapath. */
471 if (!backer->recv_set_enable && !ofproto_get_flow_restore_wait()) {
474 backer->recv_set_enable = true;
476 error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
478 VLOG_ERR("Failed to enable receiving packets in dpif.");
481 dpif_flow_flush(backer->dpif);
482 backer->need_revalidate = REV_RECONFIGURE;
485 if (backer->recv_set_enable) {
486 udpif_set_threads(backer->udpif, n_handlers, n_revalidators);
489 if (backer->need_revalidate) {
490 struct ofproto_dpif *ofproto;
491 struct simap_node *node;
492 struct simap tmp_backers;
494 /* Handle tunnel garbage collection. */
495 simap_init(&tmp_backers);
496 simap_swap(&backer->tnl_backers, &tmp_backers);
498 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
499 struct ofport_dpif *iter;
501 if (backer != ofproto->backer) {
505 HMAP_FOR_EACH (iter, up.hmap_node, &ofproto->up.ports) {
506 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
509 if (!iter->is_tunnel) {
513 dp_port = netdev_vport_get_dpif_port(iter->up.netdev,
514 namebuf, sizeof namebuf);
515 node = simap_find(&tmp_backers, dp_port);
517 simap_put(&backer->tnl_backers, dp_port, node->data);
518 simap_delete(&tmp_backers, node);
519 node = simap_find(&backer->tnl_backers, dp_port);
521 node = simap_find(&backer->tnl_backers, dp_port);
523 odp_port_t odp_port = ODPP_NONE;
525 if (!dpif_port_add(backer->dpif, iter->up.netdev,
527 simap_put(&backer->tnl_backers, dp_port,
528 odp_to_u32(odp_port));
529 node = simap_find(&backer->tnl_backers, dp_port);
534 iter->odp_port = node ? u32_to_odp(node->data) : ODPP_NONE;
535 if (tnl_port_reconfigure(iter, iter->up.netdev,
537 backer->need_revalidate = REV_RECONFIGURE;
542 SIMAP_FOR_EACH (node, &tmp_backers) {
543 dpif_port_del(backer->dpif, u32_to_odp(node->data));
545 simap_destroy(&tmp_backers);
547 switch (backer->need_revalidate) {
548 case REV_RECONFIGURE: COVERAGE_INC(rev_reconfigure); break;
549 case REV_STP: COVERAGE_INC(rev_stp); break;
550 case REV_BOND: COVERAGE_INC(rev_bond); break;
551 case REV_PORT_TOGGLED: COVERAGE_INC(rev_port_toggled); break;
552 case REV_FLOW_TABLE: COVERAGE_INC(rev_flow_table); break;
553 case REV_MAC_LEARNING: COVERAGE_INC(rev_mac_learning); break;
555 backer->need_revalidate = 0;
557 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
558 struct ofport_dpif *ofport;
559 struct ofbundle *bundle;
561 if (ofproto->backer != backer) {
565 ovs_rwlock_wrlock(&xlate_rwlock);
566 xlate_ofproto_set(ofproto, ofproto->up.name,
567 ofproto->backer->dpif, ofproto->miss_rule,
568 ofproto->no_packet_in_rule, ofproto->ml,
569 ofproto->stp, ofproto->mbridge,
570 ofproto->sflow, ofproto->ipfix,
571 ofproto->netflow, ofproto->up.frag_handling,
572 ofproto->up.forward_bpdu,
573 connmgr_has_in_band(ofproto->up.connmgr),
574 ofproto->backer->variable_length_userdata,
575 ofproto->backer->max_mpls_depth);
577 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
578 xlate_bundle_set(ofproto, bundle, bundle->name,
579 bundle->vlan_mode, bundle->vlan,
580 bundle->trunks, bundle->use_priority_tags,
581 bundle->bond, bundle->lacp,
585 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
586 int stp_port = ofport->stp_port
587 ? stp_port_no(ofport->stp_port)
589 xlate_ofport_set(ofproto, ofport->bundle, ofport,
590 ofport->up.ofp_port, ofport->odp_port,
591 ofport->up.netdev, ofport->cfm,
592 ofport->bfd, ofport->peer, stp_port,
593 ofport->qdscp, ofport->n_qdscp,
594 ofport->up.pp.config, ofport->up.pp.state,
595 ofport->is_tunnel, ofport->may_enable);
597 ovs_rwlock_unlock(&xlate_rwlock);
600 udpif_revalidate(backer->udpif);
603 process_dpif_port_changes(backer);
608 /* Check for and handle port changes in 'backer''s dpif. */
610 process_dpif_port_changes(struct dpif_backer *backer)
616 error = dpif_port_poll(backer->dpif, &devname);
622 process_dpif_all_ports_changed(backer);
626 process_dpif_port_change(backer, devname);
631 process_dpif_port_error(backer, error);
638 process_dpif_all_ports_changed(struct dpif_backer *backer)
640 struct ofproto_dpif *ofproto;
641 struct dpif_port dpif_port;
642 struct dpif_port_dump dump;
643 struct sset devnames;
646 sset_init(&devnames);
647 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
648 if (ofproto->backer == backer) {
649 struct ofport *ofport;
651 HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
652 sset_add(&devnames, netdev_get_name(ofport->netdev));
656 DPIF_PORT_FOR_EACH (&dpif_port, &dump, backer->dpif) {
657 sset_add(&devnames, dpif_port.name);
660 SSET_FOR_EACH (devname, &devnames) {
661 process_dpif_port_change(backer, devname);
663 sset_destroy(&devnames);
667 process_dpif_port_change(struct dpif_backer *backer, const char *devname)
669 struct ofproto_dpif *ofproto;
670 struct dpif_port port;
672 /* Don't report on the datapath's device. */
673 if (!strcmp(devname, dpif_base_name(backer->dpif))) {
677 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node,
678 &all_ofproto_dpifs) {
679 if (simap_contains(&ofproto->backer->tnl_backers, devname)) {
684 ofproto = lookup_ofproto_dpif_by_port_name(devname);
685 if (dpif_port_query_by_name(backer->dpif, devname, &port)) {
686 /* The port was removed. If we know the datapath,
687 * report it through poll_set(). If we don't, it may be
688 * notifying us of a removal we initiated, so ignore it.
689 * If there's a pending ENOBUFS, let it stand, since
690 * everything will be reevaluated. */
691 if (ofproto && ofproto->port_poll_errno != ENOBUFS) {
692 sset_add(&ofproto->port_poll_set, devname);
693 ofproto->port_poll_errno = 0;
695 } else if (!ofproto) {
696 /* The port was added, but we don't know with which
697 * ofproto we should associate it. Delete it. */
698 dpif_port_del(backer->dpif, port.port_no);
700 struct ofport_dpif *ofport;
702 ofport = ofport_dpif_cast(shash_find_data(
703 &ofproto->up.port_by_name, devname));
705 && ofport->odp_port != port.port_no
706 && !odp_port_to_ofport(backer, port.port_no))
708 /* 'ofport''s datapath port number has changed from
709 * 'ofport->odp_port' to 'port.port_no'. Update our internal data
710 * structures to match. */
711 ovs_rwlock_wrlock(&backer->odp_to_ofport_lock);
712 hmap_remove(&backer->odp_to_ofport_map, &ofport->odp_port_node);
713 ofport->odp_port = port.port_no;
714 hmap_insert(&backer->odp_to_ofport_map, &ofport->odp_port_node,
715 hash_odp_port(port.port_no));
716 ovs_rwlock_unlock(&backer->odp_to_ofport_lock);
717 backer->need_revalidate = REV_RECONFIGURE;
720 dpif_port_destroy(&port);
723 /* Propagate 'error' to all ofprotos based on 'backer'. */
725 process_dpif_port_error(struct dpif_backer *backer, int error)
727 struct ofproto_dpif *ofproto;
729 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
730 if (ofproto->backer == backer) {
731 sset_clear(&ofproto->port_poll_set);
732 ofproto->port_poll_errno = error;
738 type_wait(const char *type)
740 struct dpif_backer *backer;
742 backer = shash_find_data(&all_dpif_backers, type);
744 /* This is not necessarily a problem, since backers are only
745 * created on demand. */
749 dpif_wait(backer->dpif);
752 /* Basic life-cycle. */
754 static int add_internal_flows(struct ofproto_dpif *);
756 static struct ofproto *
759 struct ofproto_dpif *ofproto = xmalloc(sizeof *ofproto);
764 dealloc(struct ofproto *ofproto_)
766 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
771 close_dpif_backer(struct dpif_backer *backer)
773 ovs_assert(backer->refcount > 0);
775 if (--backer->refcount) {
779 udpif_destroy(backer->udpif);
781 simap_destroy(&backer->tnl_backers);
782 ovs_rwlock_destroy(&backer->odp_to_ofport_lock);
783 hmap_destroy(&backer->odp_to_ofport_map);
784 shash_find_and_delete(&all_dpif_backers, backer->type);
785 recirc_id_pool_destroy(backer->rid_pool);
787 dpif_close(backer->dpif);
791 /* Datapath port slated for removal from datapath. */
793 struct list list_node;
797 static bool check_variable_length_userdata(struct dpif_backer *backer);
798 static size_t check_max_mpls_depth(struct dpif_backer *backer);
801 open_dpif_backer(const char *type, struct dpif_backer **backerp)
803 struct dpif_backer *backer;
804 struct dpif_port_dump port_dump;
805 struct dpif_port port;
806 struct shash_node *node;
807 struct list garbage_list;
808 struct odp_garbage *garbage, *next;
815 backer = shash_find_data(&all_dpif_backers, type);
822 backer_name = xasprintf("ovs-%s", type);
824 /* Remove any existing datapaths, since we assume we're the only
825 * userspace controlling the datapath. */
827 dp_enumerate_names(type, &names);
828 SSET_FOR_EACH(name, &names) {
829 struct dpif *old_dpif;
831 /* Don't remove our backer if it exists. */
832 if (!strcmp(name, backer_name)) {
836 if (dpif_open(name, type, &old_dpif)) {
837 VLOG_WARN("couldn't open old datapath %s to remove it", name);
839 dpif_delete(old_dpif);
840 dpif_close(old_dpif);
843 sset_destroy(&names);
845 backer = xmalloc(sizeof *backer);
847 error = dpif_create_and_open(backer_name, type, &backer->dpif);
850 VLOG_ERR("failed to open datapath of type %s: %s", type,
851 ovs_strerror(error));
855 backer->udpif = udpif_create(backer, backer->dpif);
857 backer->type = xstrdup(type);
858 backer->refcount = 1;
859 hmap_init(&backer->odp_to_ofport_map);
860 ovs_rwlock_init(&backer->odp_to_ofport_lock);
861 backer->need_revalidate = 0;
862 simap_init(&backer->tnl_backers);
863 backer->recv_set_enable = !ofproto_get_flow_restore_wait();
866 if (backer->recv_set_enable) {
867 dpif_flow_flush(backer->dpif);
870 /* Loop through the ports already on the datapath and remove any
871 * that we don't need anymore. */
872 list_init(&garbage_list);
873 dpif_port_dump_start(&port_dump, backer->dpif);
874 while (dpif_port_dump_next(&port_dump, &port)) {
875 node = shash_find(&init_ofp_ports, port.name);
876 if (!node && strcmp(port.name, dpif_base_name(backer->dpif))) {
877 garbage = xmalloc(sizeof *garbage);
878 garbage->odp_port = port.port_no;
879 list_push_front(&garbage_list, &garbage->list_node);
882 dpif_port_dump_done(&port_dump);
884 LIST_FOR_EACH_SAFE (garbage, next, list_node, &garbage_list) {
885 dpif_port_del(backer->dpif, garbage->odp_port);
886 list_remove(&garbage->list_node);
890 shash_add(&all_dpif_backers, type, backer);
892 error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
894 VLOG_ERR("failed to listen on datapath of type %s: %s",
895 type, ovs_strerror(error));
896 close_dpif_backer(backer);
899 backer->variable_length_userdata = check_variable_length_userdata(backer);
900 backer->max_mpls_depth = check_max_mpls_depth(backer);
901 backer->rid_pool = recirc_id_pool_create();
903 if (backer->recv_set_enable) {
904 udpif_set_threads(backer->udpif, n_handlers, n_revalidators);
910 /* Tests whether 'backer''s datapath supports variable-length
911 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. We need
912 * to disable some features on older datapaths that don't support this
915 * Returns false if 'backer' definitely does not support variable-length
916 * userdata, true if it seems to support them or if at least the error we get
919 check_variable_length_userdata(struct dpif_backer *backer)
921 struct eth_header *eth;
922 struct ofpbuf actions;
923 struct dpif_execute execute;
924 struct ofpbuf packet;
928 /* Compose a userspace action that will cause an ERANGE error on older
929 * datapaths that don't support variable-length userdata.
931 * We really test for using userdata longer than 8 bytes, but older
932 * datapaths accepted these, silently truncating the userdata to 8 bytes.
933 * The same older datapaths rejected userdata shorter than 8 bytes, so we
934 * test for that instead as a proxy for longer userdata support. */
935 ofpbuf_init(&actions, 64);
936 start = nl_msg_start_nested(&actions, OVS_ACTION_ATTR_USERSPACE);
937 nl_msg_put_u32(&actions, OVS_USERSPACE_ATTR_PID,
938 dpif_port_get_pid(backer->dpif, ODPP_NONE, 0));
939 nl_msg_put_unspec_zero(&actions, OVS_USERSPACE_ATTR_USERDATA, 4);
940 nl_msg_end_nested(&actions, start);
942 /* Compose a dummy ethernet packet. */
943 ofpbuf_init(&packet, ETH_HEADER_LEN);
944 eth = ofpbuf_put_zeros(&packet, ETH_HEADER_LEN);
945 eth->eth_type = htons(0x1234);
947 /* Execute the actions. On older datapaths this fails with ERANGE, on
948 * newer datapaths it succeeds. */
949 execute.actions = ofpbuf_data(&actions);
950 execute.actions_len = ofpbuf_size(&actions);
951 execute.packet = &packet;
952 execute.md = PKT_METADATA_INITIALIZER(0);
953 execute.needs_help = false;
955 error = dpif_execute(backer->dpif, &execute);
957 ofpbuf_uninit(&packet);
958 ofpbuf_uninit(&actions);
962 /* Variable-length userdata is supported.
964 * Purge received packets to avoid processing the nonsense packet we
965 * sent to userspace, then report success. */
966 dpif_recv_purge(backer->dpif);
970 /* Variable-length userdata is not supported. */
971 VLOG_WARN("%s: datapath does not support variable-length userdata "
972 "feature (needs Linux 3.10+ or kernel module from OVS "
973 "1..11+). The NXAST_SAMPLE action will be ignored.",
974 dpif_name(backer->dpif));
978 /* Something odd happened. We're not sure whether variable-length
979 * userdata is supported. Default to "yes". */
980 VLOG_WARN("%s: variable-length userdata feature probe failed (%s)",
981 dpif_name(backer->dpif), ovs_strerror(error));
986 /* Tests the MPLS label stack depth supported by 'backer''s datapath.
988 * Returns the number of elements in a struct flow's mpls_lse field
989 * if the datapath supports at least that many entries in an
991 * Otherwise returns the number of MPLS push actions supported by
994 check_max_mpls_depth(struct dpif_backer *backer)
999 for (n = 0; n < FLOW_MAX_MPLS_LABELS; n++) {
1000 struct odputil_keybuf keybuf;
1004 memset(&flow, 0, sizeof flow);
1005 flow.dl_type = htons(ETH_TYPE_MPLS);
1006 flow_set_mpls_bos(&flow, n, 1);
1008 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
1009 odp_flow_key_from_flow(&key, &flow, 0);
1011 error = dpif_flow_put(backer->dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY,
1012 ofpbuf_data(&key), ofpbuf_size(&key), NULL, 0, NULL, 0, NULL);
1013 if (error && error != EEXIST) {
1014 if (error != EINVAL) {
1015 VLOG_WARN("%s: MPLS stack length feature probe failed (%s)",
1016 dpif_name(backer->dpif), ovs_strerror(error));
1021 error = dpif_flow_del(backer->dpif, ofpbuf_data(&key), ofpbuf_size(&key), NULL);
1023 VLOG_WARN("%s: failed to delete MPLS feature probe flow",
1024 dpif_name(backer->dpif));
1028 VLOG_INFO("%s: MPLS label stack length probed as %d",
1029 dpif_name(backer->dpif), n);
1034 construct(struct ofproto *ofproto_)
1036 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1037 struct shash_node *node, *next;
1040 error = open_dpif_backer(ofproto->up.type, &ofproto->backer);
1045 ofproto->netflow = NULL;
1046 ofproto->sflow = NULL;
1047 ofproto->ipfix = NULL;
1048 ofproto->stp = NULL;
1049 ofproto->dump_seq = 0;
1050 hmap_init(&ofproto->bundles);
1051 ofproto->ml = mac_learning_create(MAC_ENTRY_DEFAULT_IDLE_TIME);
1052 ofproto->mbridge = mbridge_create();
1053 ofproto->has_bonded_bundles = false;
1054 ofproto->lacp_enabled = false;
1055 ovs_mutex_init_adaptive(&ofproto->stats_mutex);
1056 ovs_mutex_init(&ofproto->vsp_mutex);
1058 guarded_list_init(&ofproto->pins);
1060 ofproto_dpif_unixctl_init();
1062 hmap_init(&ofproto->vlandev_map);
1063 hmap_init(&ofproto->realdev_vid_map);
1065 sset_init(&ofproto->ports);
1066 sset_init(&ofproto->ghost_ports);
1067 sset_init(&ofproto->port_poll_set);
1068 ofproto->port_poll_errno = 0;
1069 ofproto->change_seq = 0;
1071 SHASH_FOR_EACH_SAFE (node, next, &init_ofp_ports) {
1072 struct iface_hint *iface_hint = node->data;
1074 if (!strcmp(iface_hint->br_name, ofproto->up.name)) {
1075 /* Check if the datapath already has this port. */
1076 if (dpif_port_exists(ofproto->backer->dpif, node->name)) {
1077 sset_add(&ofproto->ports, node->name);
1080 free(iface_hint->br_name);
1081 free(iface_hint->br_type);
1083 shash_delete(&init_ofp_ports, node);
1087 hmap_insert(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node,
1088 hash_string(ofproto->up.name, 0));
1089 memset(&ofproto->stats, 0, sizeof ofproto->stats);
1091 ofproto_init_tables(ofproto_, N_TABLES);
1092 error = add_internal_flows(ofproto);
1093 ofproto->up.tables[TBL_INTERNAL].flags = OFTABLE_HIDDEN | OFTABLE_READONLY;
1099 add_internal_flow(struct ofproto_dpif *ofproto, int id,
1100 const struct ofpbuf *ofpacts, struct rule_dpif **rulep)
1102 struct ofputil_flow_mod fm;
1103 struct classifier *cls;
1106 match_init_catchall(&fm.match);
1108 match_set_reg(&fm.match, 0, id);
1109 fm.new_cookie = htonll(0);
1110 fm.cookie = htonll(0);
1111 fm.cookie_mask = htonll(0);
1112 fm.modify_cookie = false;
1113 fm.table_id = TBL_INTERNAL;
1114 fm.command = OFPFC_ADD;
1115 fm.idle_timeout = 0;
1116 fm.hard_timeout = 0;
1120 fm.ofpacts = ofpbuf_data(ofpacts);
1121 fm.ofpacts_len = ofpbuf_size(ofpacts);
1123 error = ofproto_flow_mod(&ofproto->up, &fm);
1125 VLOG_ERR_RL(&rl, "failed to add internal flow %d (%s)",
1126 id, ofperr_to_string(error));
1130 cls = &ofproto->up.tables[TBL_INTERNAL].cls;
1131 fat_rwlock_rdlock(&cls->rwlock);
1132 *rulep = rule_dpif_cast(rule_from_cls_rule(
1133 classifier_lookup(cls, &fm.match.flow, NULL)));
1134 ovs_assert(*rulep != NULL);
1135 fat_rwlock_unlock(&cls->rwlock);
1141 add_internal_flows(struct ofproto_dpif *ofproto)
1143 struct ofpact_controller *controller;
1144 uint64_t ofpacts_stub[128 / 8];
1145 struct ofpbuf ofpacts;
1149 ofpbuf_use_stack(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
1152 controller = ofpact_put_CONTROLLER(&ofpacts);
1153 controller->max_len = UINT16_MAX;
1154 controller->controller_id = 0;
1155 controller->reason = OFPR_NO_MATCH;
1156 ofpact_pad(&ofpacts);
1158 error = add_internal_flow(ofproto, id++, &ofpacts, &ofproto->miss_rule);
1163 ofpbuf_clear(&ofpacts);
1164 error = add_internal_flow(ofproto, id++, &ofpacts,
1165 &ofproto->no_packet_in_rule);
1170 error = add_internal_flow(ofproto, id++, &ofpacts,
1171 &ofproto->drop_frags_rule);
1176 destruct(struct ofproto *ofproto_)
1178 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1179 struct rule_dpif *rule, *next_rule;
1180 struct ofproto_packet_in *pin, *next_pin;
1181 struct oftable *table;
1184 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1185 ovs_rwlock_wrlock(&xlate_rwlock);
1186 xlate_remove_ofproto(ofproto);
1187 ovs_rwlock_unlock(&xlate_rwlock);
1189 /* Ensure that the upcall processing threads have no remaining references
1190 * to the ofproto or anything in it. */
1191 udpif_synchronize(ofproto->backer->udpif);
1193 hmap_remove(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node);
1195 OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
1196 struct cls_cursor cursor;
1198 fat_rwlock_rdlock(&table->cls.rwlock);
1199 cls_cursor_init(&cursor, &table->cls, NULL);
1200 fat_rwlock_unlock(&table->cls.rwlock);
1201 CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
1202 ofproto_rule_delete(&ofproto->up, &rule->up);
1206 guarded_list_pop_all(&ofproto->pins, &pins);
1207 LIST_FOR_EACH_SAFE (pin, next_pin, list_node, &pins) {
1208 list_remove(&pin->list_node);
1209 free(CONST_CAST(void *, pin->up.packet));
1212 guarded_list_destroy(&ofproto->pins);
1214 mbridge_unref(ofproto->mbridge);
1216 netflow_unref(ofproto->netflow);
1217 dpif_sflow_unref(ofproto->sflow);
1218 hmap_destroy(&ofproto->bundles);
1219 mac_learning_unref(ofproto->ml);
1221 hmap_destroy(&ofproto->vlandev_map);
1222 hmap_destroy(&ofproto->realdev_vid_map);
1224 sset_destroy(&ofproto->ports);
1225 sset_destroy(&ofproto->ghost_ports);
1226 sset_destroy(&ofproto->port_poll_set);
1228 ovs_mutex_destroy(&ofproto->stats_mutex);
1229 ovs_mutex_destroy(&ofproto->vsp_mutex);
1231 close_dpif_backer(ofproto->backer);
1235 run(struct ofproto *ofproto_)
1237 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1238 uint64_t new_seq, new_dump_seq;
1240 if (mbridge_need_revalidate(ofproto->mbridge)) {
1241 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1242 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
1243 mac_learning_flush(ofproto->ml);
1244 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1247 /* Do not perform any periodic activity required by 'ofproto' while
1248 * waiting for flow restore to complete. */
1249 if (!ofproto_get_flow_restore_wait()) {
1250 struct ofproto_packet_in *pin, *next_pin;
1253 guarded_list_pop_all(&ofproto->pins, &pins);
1254 LIST_FOR_EACH_SAFE (pin, next_pin, list_node, &pins) {
1255 connmgr_send_packet_in(ofproto->up.connmgr, pin);
1256 list_remove(&pin->list_node);
1257 free(CONST_CAST(void *, pin->up.packet));
1262 if (ofproto->netflow) {
1263 netflow_run(ofproto->netflow);
1265 if (ofproto->sflow) {
1266 dpif_sflow_run(ofproto->sflow);
1268 if (ofproto->ipfix) {
1269 dpif_ipfix_run(ofproto->ipfix);
1272 new_seq = seq_read(connectivity_seq_get());
1273 if (ofproto->change_seq != new_seq) {
1274 struct ofport_dpif *ofport;
1276 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1280 ofproto->change_seq = new_seq;
1282 if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) {
1283 struct ofbundle *bundle;
1285 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1291 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
1292 if (mac_learning_run(ofproto->ml)) {
1293 ofproto->backer->need_revalidate = REV_MAC_LEARNING;
1295 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1297 new_dump_seq = seq_read(udpif_dump_seq(ofproto->backer->udpif));
1298 if (ofproto->dump_seq != new_dump_seq) {
1299 struct rule *rule, *next_rule;
1301 /* We know stats are relatively fresh, so now is a good time to do some
1303 ofproto->dump_seq = new_dump_seq;
1305 /* Expire OpenFlow flows whose idle_timeout or hard_timeout
1307 ovs_mutex_lock(&ofproto_mutex);
1308 LIST_FOR_EACH_SAFE (rule, next_rule, expirable,
1309 &ofproto->up.expirable) {
1310 rule_expire(rule_dpif_cast(rule));
1312 ovs_mutex_unlock(&ofproto_mutex);
1314 /* All outstanding data in existing flows has been accounted, so it's a
1315 * good time to do bond rebalancing. */
1316 if (ofproto->has_bonded_bundles) {
1317 struct ofbundle *bundle;
1319 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1321 bond_rebalance(bundle->bond);
1331 wait(struct ofproto *ofproto_)
1333 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1335 if (ofproto_get_flow_restore_wait()) {
1339 if (ofproto->sflow) {
1340 dpif_sflow_wait(ofproto->sflow);
1342 if (ofproto->ipfix) {
1343 dpif_ipfix_wait(ofproto->ipfix);
1345 if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) {
1346 struct ofbundle *bundle;
1348 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1349 bundle_wait(bundle);
1352 if (ofproto->netflow) {
1353 netflow_wait(ofproto->netflow);
1355 ovs_rwlock_rdlock(&ofproto->ml->rwlock);
1356 mac_learning_wait(ofproto->ml);
1357 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1359 if (ofproto->backer->need_revalidate) {
1360 /* Shouldn't happen, but if it does just go around again. */
1361 VLOG_DBG_RL(&rl, "need revalidate in ofproto_wait_cb()");
1362 poll_immediate_wake();
1365 seq_wait(udpif_dump_seq(ofproto->backer->udpif), ofproto->dump_seq);
1369 type_get_memory_usage(const char *type, struct simap *usage)
1371 struct dpif_backer *backer;
1373 backer = shash_find_data(&all_dpif_backers, type);
1375 udpif_get_memory_usage(backer->udpif, usage);
1380 flush(struct ofproto *ofproto_)
1382 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1383 struct dpif_backer *backer = ofproto->backer;
1386 udpif_flush(backer->udpif);
1391 get_features(struct ofproto *ofproto_ OVS_UNUSED,
1392 bool *arp_match_ip, enum ofputil_action_bitmap *actions)
1394 *arp_match_ip = true;
1395 *actions = (OFPUTIL_A_OUTPUT |
1396 OFPUTIL_A_SET_VLAN_VID |
1397 OFPUTIL_A_SET_VLAN_PCP |
1398 OFPUTIL_A_STRIP_VLAN |
1399 OFPUTIL_A_SET_DL_SRC |
1400 OFPUTIL_A_SET_DL_DST |
1401 OFPUTIL_A_SET_NW_SRC |
1402 OFPUTIL_A_SET_NW_DST |
1403 OFPUTIL_A_SET_NW_TOS |
1404 OFPUTIL_A_SET_TP_SRC |
1405 OFPUTIL_A_SET_TP_DST |
1410 get_tables(struct ofproto *ofproto_, struct ofp12_table_stats *ots)
1412 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1413 struct dpif_dp_stats s;
1414 uint64_t n_miss, n_no_pkt_in, n_bytes, n_dropped_frags;
1418 strcpy(ots->name, "classifier");
1420 dpif_get_dp_stats(ofproto->backer->dpif, &s);
1421 rule_get_stats(&ofproto->miss_rule->up, &n_miss, &n_bytes, &used);
1422 rule_get_stats(&ofproto->no_packet_in_rule->up, &n_no_pkt_in, &n_bytes,
1424 rule_get_stats(&ofproto->drop_frags_rule->up, &n_dropped_frags, &n_bytes,
1426 n_lookup = s.n_hit + s.n_missed - n_dropped_frags;
1427 ots->lookup_count = htonll(n_lookup);
1428 ots->matched_count = htonll(n_lookup - n_miss - n_no_pkt_in);
1431 static struct ofport *
1434 struct ofport_dpif *port = xmalloc(sizeof *port);
1439 port_dealloc(struct ofport *port_)
1441 struct ofport_dpif *port = ofport_dpif_cast(port_);
1446 port_construct(struct ofport *port_)
1448 struct ofport_dpif *port = ofport_dpif_cast(port_);
1449 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1450 const struct netdev *netdev = port->up.netdev;
1451 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
1452 struct dpif_port dpif_port;
1455 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1456 port->bundle = NULL;
1459 port->may_enable = true;
1460 port->stp_port = NULL;
1461 port->stp_state = STP_DISABLED;
1462 port->is_tunnel = false;
1466 port->realdev_ofp_port = 0;
1467 port->vlandev_vid = 0;
1468 port->carrier_seq = netdev_get_carrier_resets(netdev);
1469 port->is_layer3 = netdev_vport_is_layer3(netdev);
1471 if (netdev_vport_is_patch(netdev)) {
1472 /* By bailing out here, we don't submit the port to the sFlow module
1473 * to be considered for counter polling export. This is correct
1474 * because the patch port represents an interface that sFlow considers
1475 * to be "internal" to the switch as a whole, and therefore not an
1476 * candidate for counter polling. */
1477 port->odp_port = ODPP_NONE;
1478 ofport_update_peer(port);
1482 error = dpif_port_query_by_name(ofproto->backer->dpif,
1483 netdev_vport_get_dpif_port(netdev, namebuf,
1490 port->odp_port = dpif_port.port_no;
1492 if (netdev_get_tunnel_config(netdev)) {
1493 tnl_port_add(port, port->up.netdev, port->odp_port);
1494 port->is_tunnel = true;
1496 /* Sanity-check that a mapping doesn't already exist. This
1497 * shouldn't happen for non-tunnel ports. */
1498 if (odp_port_to_ofp_port(ofproto, port->odp_port) != OFPP_NONE) {
1499 VLOG_ERR("port %s already has an OpenFlow port number",
1501 dpif_port_destroy(&dpif_port);
1505 ovs_rwlock_wrlock(&ofproto->backer->odp_to_ofport_lock);
1506 hmap_insert(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node,
1507 hash_odp_port(port->odp_port));
1508 ovs_rwlock_unlock(&ofproto->backer->odp_to_ofport_lock);
1510 dpif_port_destroy(&dpif_port);
1512 if (ofproto->sflow) {
1513 dpif_sflow_add_port(ofproto->sflow, port_, port->odp_port);
1520 port_destruct(struct ofport *port_)
1522 struct ofport_dpif *port = ofport_dpif_cast(port_);
1523 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1524 const char *devname = netdev_get_name(port->up.netdev);
1525 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
1526 const char *dp_port_name;
1528 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1529 ovs_rwlock_wrlock(&xlate_rwlock);
1530 xlate_ofport_remove(port);
1531 ovs_rwlock_unlock(&xlate_rwlock);
1533 dp_port_name = netdev_vport_get_dpif_port(port->up.netdev, namebuf,
1535 if (dpif_port_exists(ofproto->backer->dpif, dp_port_name)) {
1536 /* The underlying device is still there, so delete it. This
1537 * happens when the ofproto is being destroyed, since the caller
1538 * assumes that removal of attached ports will happen as part of
1540 if (!port->is_tunnel) {
1541 dpif_port_del(ofproto->backer->dpif, port->odp_port);
1546 port->peer->peer = NULL;
1550 if (port->odp_port != ODPP_NONE && !port->is_tunnel) {
1551 ovs_rwlock_wrlock(&ofproto->backer->odp_to_ofport_lock);
1552 hmap_remove(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node);
1553 ovs_rwlock_unlock(&ofproto->backer->odp_to_ofport_lock);
1557 sset_find_and_delete(&ofproto->ports, devname);
1558 sset_find_and_delete(&ofproto->ghost_ports, devname);
1559 bundle_remove(port_);
1560 set_cfm(port_, NULL);
1561 set_bfd(port_, NULL);
1562 if (port->stp_port) {
1563 stp_port_disable(port->stp_port);
1565 if (ofproto->sflow) {
1566 dpif_sflow_del_port(ofproto->sflow, port->odp_port);
1573 port_modified(struct ofport *port_)
1575 struct ofport_dpif *port = ofport_dpif_cast(port_);
1577 if (port->bundle && port->bundle->bond) {
1578 bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev);
1582 cfm_set_netdev(port->cfm, port->up.netdev);
1586 bfd_set_netdev(port->bfd, port->up.netdev);
1589 ofproto_dpif_monitor_port_update(port, port->bfd, port->cfm,
1590 port->up.pp.hw_addr);
1592 if (port->is_tunnel && tnl_port_reconfigure(port, port->up.netdev,
1594 ofproto_dpif_cast(port->up.ofproto)->backer->need_revalidate =
1598 ofport_update_peer(port);
1602 port_reconfigured(struct ofport *port_, enum ofputil_port_config old_config)
1604 struct ofport_dpif *port = ofport_dpif_cast(port_);
1605 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1606 enum ofputil_port_config changed = old_config ^ port->up.pp.config;
1608 if (changed & (OFPUTIL_PC_NO_RECV | OFPUTIL_PC_NO_RECV_STP |
1609 OFPUTIL_PC_NO_FWD | OFPUTIL_PC_NO_FLOOD |
1610 OFPUTIL_PC_NO_PACKET_IN)) {
1611 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1613 if (changed & OFPUTIL_PC_NO_FLOOD && port->bundle) {
1614 bundle_update(port->bundle);
1620 set_sflow(struct ofproto *ofproto_,
1621 const struct ofproto_sflow_options *sflow_options)
1623 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1624 struct dpif_sflow *ds = ofproto->sflow;
1626 if (sflow_options) {
1628 struct ofport_dpif *ofport;
1630 ds = ofproto->sflow = dpif_sflow_create();
1631 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1632 dpif_sflow_add_port(ds, &ofport->up, ofport->odp_port);
1634 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1636 dpif_sflow_set_options(ds, sflow_options);
1639 dpif_sflow_unref(ds);
1640 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1641 ofproto->sflow = NULL;
1649 struct ofproto *ofproto_,
1650 const struct ofproto_ipfix_bridge_exporter_options *bridge_exporter_options,
1651 const struct ofproto_ipfix_flow_exporter_options *flow_exporters_options,
1652 size_t n_flow_exporters_options)
1654 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1655 struct dpif_ipfix *di = ofproto->ipfix;
1656 bool has_options = bridge_exporter_options || flow_exporters_options;
1658 if (has_options && !di) {
1659 di = ofproto->ipfix = dpif_ipfix_create();
1663 /* Call set_options in any case to cleanly flush the flow
1664 * caches in the last exporters that are to be destroyed. */
1665 dpif_ipfix_set_options(
1666 di, bridge_exporter_options, flow_exporters_options,
1667 n_flow_exporters_options);
1670 dpif_ipfix_unref(di);
1671 ofproto->ipfix = NULL;
1679 set_cfm(struct ofport *ofport_, const struct cfm_settings *s)
1681 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1686 struct ofproto_dpif *ofproto;
1688 ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1689 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1690 ofport->cfm = cfm_create(ofport->up.netdev);
1693 if (cfm_configure(ofport->cfm, s)) {
1700 cfm_unref(ofport->cfm);
1703 ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm,
1704 ofport->up.pp.hw_addr);
1709 get_cfm_status(const struct ofport *ofport_,
1710 struct ofproto_cfm_status *status)
1712 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1715 status->faults = cfm_get_fault(ofport->cfm);
1716 status->flap_count = cfm_get_flap_count(ofport->cfm);
1717 status->remote_opstate = cfm_get_opup(ofport->cfm);
1718 status->health = cfm_get_health(ofport->cfm);
1719 cfm_get_remote_mpids(ofport->cfm, &status->rmps, &status->n_rmps);
1727 set_bfd(struct ofport *ofport_, const struct smap *cfg)
1729 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport_->ofproto);
1730 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1734 ofport->bfd = bfd_configure(old, netdev_get_name(ofport->up.netdev),
1735 cfg, ofport->up.netdev);
1736 if (ofport->bfd != old) {
1737 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1739 ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm,
1740 ofport->up.pp.hw_addr);
1745 get_bfd_status(struct ofport *ofport_, struct smap *smap)
1747 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1750 bfd_get_status(ofport->bfd, smap);
1757 /* Spanning Tree. */
1760 send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_)
1762 struct ofproto_dpif *ofproto = ofproto_;
1763 struct stp_port *sp = stp_get_port(ofproto->stp, port_num);
1764 struct ofport_dpif *ofport;
1766 ofport = stp_port_get_aux(sp);
1768 VLOG_WARN_RL(&rl, "%s: cannot send BPDU on unknown port %d",
1769 ofproto->up.name, port_num);
1771 struct eth_header *eth = pkt->l2;
1773 netdev_get_etheraddr(ofport->up.netdev, eth->eth_src);
1774 if (eth_addr_is_zero(eth->eth_src)) {
1775 VLOG_WARN_RL(&rl, "%s: cannot send BPDU on port %d "
1776 "with unknown MAC", ofproto->up.name, port_num);
1778 ofproto_dpif_send_packet(ofport, pkt);
1784 /* Configures STP on 'ofproto_' using the settings defined in 's'. */
1786 set_stp(struct ofproto *ofproto_, const struct ofproto_stp_settings *s)
1788 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1790 /* Only revalidate flows if the configuration changed. */
1791 if (!s != !ofproto->stp) {
1792 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1796 if (!ofproto->stp) {
1797 ofproto->stp = stp_create(ofproto_->name, s->system_id,
1798 send_bpdu_cb, ofproto);
1799 ofproto->stp_last_tick = time_msec();
1802 stp_set_bridge_id(ofproto->stp, s->system_id);
1803 stp_set_bridge_priority(ofproto->stp, s->priority);
1804 stp_set_hello_time(ofproto->stp, s->hello_time);
1805 stp_set_max_age(ofproto->stp, s->max_age);
1806 stp_set_forward_delay(ofproto->stp, s->fwd_delay);
1808 struct ofport *ofport;
1810 HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
1811 set_stp_port(ofport, NULL);
1814 stp_unref(ofproto->stp);
1815 ofproto->stp = NULL;
1822 get_stp_status(struct ofproto *ofproto_, struct ofproto_stp_status *s)
1824 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1828 s->bridge_id = stp_get_bridge_id(ofproto->stp);
1829 s->designated_root = stp_get_designated_root(ofproto->stp);
1830 s->root_path_cost = stp_get_root_path_cost(ofproto->stp);
1839 update_stp_port_state(struct ofport_dpif *ofport)
1841 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1842 enum stp_state state;
1844 /* Figure out new state. */
1845 state = ofport->stp_port ? stp_port_get_state(ofport->stp_port)
1849 if (ofport->stp_state != state) {
1850 enum ofputil_port_state of_state;
1853 VLOG_DBG_RL(&rl, "port %s: STP state changed from %s to %s",
1854 netdev_get_name(ofport->up.netdev),
1855 stp_state_name(ofport->stp_state),
1856 stp_state_name(state));
1857 if (stp_learn_in_state(ofport->stp_state)
1858 != stp_learn_in_state(state)) {
1859 /* xxx Learning action flows should also be flushed. */
1860 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
1861 mac_learning_flush(ofproto->ml);
1862 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1864 fwd_change = stp_forward_in_state(ofport->stp_state)
1865 != stp_forward_in_state(state);
1867 ofproto->backer->need_revalidate = REV_STP;
1868 ofport->stp_state = state;
1869 ofport->stp_state_entered = time_msec();
1871 if (fwd_change && ofport->bundle) {
1872 bundle_update(ofport->bundle);
1875 /* Update the STP state bits in the OpenFlow port description. */
1876 of_state = ofport->up.pp.state & ~OFPUTIL_PS_STP_MASK;
1877 of_state |= (state == STP_LISTENING ? OFPUTIL_PS_STP_LISTEN
1878 : state == STP_LEARNING ? OFPUTIL_PS_STP_LEARN
1879 : state == STP_FORWARDING ? OFPUTIL_PS_STP_FORWARD
1880 : state == STP_BLOCKING ? OFPUTIL_PS_STP_BLOCK
1882 ofproto_port_set_state(&ofport->up, of_state);
1886 /* Configures STP on 'ofport_' using the settings defined in 's'. The
1887 * caller is responsible for assigning STP port numbers and ensuring
1888 * there are no duplicates. */
1890 set_stp_port(struct ofport *ofport_,
1891 const struct ofproto_port_stp_settings *s)
1893 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1894 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1895 struct stp_port *sp = ofport->stp_port;
1897 if (!s || !s->enable) {
1899 ofport->stp_port = NULL;
1900 stp_port_disable(sp);
1901 update_stp_port_state(ofport);
1904 } else if (sp && stp_port_no(sp) != s->port_num
1905 && ofport == stp_port_get_aux(sp)) {
1906 /* The port-id changed, so disable the old one if it's not
1907 * already in use by another port. */
1908 stp_port_disable(sp);
1911 sp = ofport->stp_port = stp_get_port(ofproto->stp, s->port_num);
1912 stp_port_enable(sp);
1914 stp_port_set_aux(sp, ofport);
1915 stp_port_set_priority(sp, s->priority);
1916 stp_port_set_path_cost(sp, s->path_cost);
1918 update_stp_port_state(ofport);
1924 get_stp_port_status(struct ofport *ofport_,
1925 struct ofproto_port_stp_status *s)
1927 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1928 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1929 struct stp_port *sp = ofport->stp_port;
1931 if (!ofproto->stp || !sp) {
1937 s->port_id = stp_port_get_id(sp);
1938 s->state = stp_port_get_state(sp);
1939 s->sec_in_state = (time_msec() - ofport->stp_state_entered) / 1000;
1940 s->role = stp_port_get_role(sp);
1946 get_stp_port_stats(struct ofport *ofport_,
1947 struct ofproto_port_stp_stats *s)
1949 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1950 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1951 struct stp_port *sp = ofport->stp_port;
1953 if (!ofproto->stp || !sp) {
1959 stp_port_get_counts(sp, &s->tx_count, &s->rx_count, &s->error_count);
1965 stp_run(struct ofproto_dpif *ofproto)
1968 long long int now = time_msec();
1969 long long int elapsed = now - ofproto->stp_last_tick;
1970 struct stp_port *sp;
1973 stp_tick(ofproto->stp, MIN(INT_MAX, elapsed));
1974 ofproto->stp_last_tick = now;
1976 while (stp_get_changed_port(ofproto->stp, &sp)) {
1977 struct ofport_dpif *ofport = stp_port_get_aux(sp);
1980 update_stp_port_state(ofport);
1984 if (stp_check_and_reset_fdb_flush(ofproto->stp)) {
1985 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
1986 mac_learning_flush(ofproto->ml);
1987 ovs_rwlock_unlock(&ofproto->ml->rwlock);
1993 stp_wait(struct ofproto_dpif *ofproto)
1996 poll_timer_wait(1000);
2001 set_queues(struct ofport *ofport_, const struct ofproto_port_queue *qdscp,
2004 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2005 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2007 if (ofport->n_qdscp != n_qdscp
2008 || (n_qdscp && memcmp(ofport->qdscp, qdscp,
2009 n_qdscp * sizeof *qdscp))) {
2010 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2011 free(ofport->qdscp);
2012 ofport->qdscp = n_qdscp
2013 ? xmemdup(qdscp, n_qdscp * sizeof *qdscp)
2015 ofport->n_qdscp = n_qdscp;
2023 /* Expires all MAC learning entries associated with 'bundle' and forces its
2024 * ofproto to revalidate every flow.
2026 * Normally MAC learning entries are removed only from the ofproto associated
2027 * with 'bundle', but if 'all_ofprotos' is true, then the MAC learning entries
2028 * are removed from every ofproto. When patch ports and SLB bonds are in use
2029 * and a VM migration happens and the gratuitous ARPs are somehow lost, this
2030 * avoids a MAC_ENTRY_IDLE_TIME delay before the migrated VM can communicate
2031 * with the host from which it migrated. */
2033 bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos)
2035 struct ofproto_dpif *ofproto = bundle->ofproto;
2036 struct mac_learning *ml = ofproto->ml;
2037 struct mac_entry *mac, *next_mac;
2039 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2040 ovs_rwlock_wrlock(&ml->rwlock);
2041 LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) {
2042 if (mac->port.p == bundle) {
2044 struct ofproto_dpif *o;
2046 HMAP_FOR_EACH (o, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
2048 struct mac_entry *e;
2050 ovs_rwlock_wrlock(&o->ml->rwlock);
2051 e = mac_learning_lookup(o->ml, mac->mac, mac->vlan);
2053 mac_learning_expire(o->ml, e);
2055 ovs_rwlock_unlock(&o->ml->rwlock);
2060 mac_learning_expire(ml, mac);
2063 ovs_rwlock_unlock(&ml->rwlock);
2066 static struct ofbundle *
2067 bundle_lookup(const struct ofproto_dpif *ofproto, void *aux)
2069 struct ofbundle *bundle;
2071 HMAP_FOR_EACH_IN_BUCKET (bundle, hmap_node, hash_pointer(aux, 0),
2072 &ofproto->bundles) {
2073 if (bundle->aux == aux) {
2081 bundle_update(struct ofbundle *bundle)
2083 struct ofport_dpif *port;
2085 bundle->floodable = true;
2086 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2087 if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD
2089 || !stp_forward_in_state(port->stp_state)) {
2090 bundle->floodable = false;
2097 bundle_del_port(struct ofport_dpif *port)
2099 struct ofbundle *bundle = port->bundle;
2101 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2103 list_remove(&port->bundle_node);
2104 port->bundle = NULL;
2107 lacp_slave_unregister(bundle->lacp, port);
2110 bond_slave_unregister(bundle->bond, port);
2113 bundle_update(bundle);
2117 bundle_add_port(struct ofbundle *bundle, ofp_port_t ofp_port,
2118 struct lacp_slave_settings *lacp)
2120 struct ofport_dpif *port;
2122 port = get_ofp_port(bundle->ofproto, ofp_port);
2127 if (port->bundle != bundle) {
2128 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2130 bundle_remove(&port->up);
2133 port->bundle = bundle;
2134 list_push_back(&bundle->ports, &port->bundle_node);
2135 if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD
2137 || !stp_forward_in_state(port->stp_state)) {
2138 bundle->floodable = false;
2142 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2143 lacp_slave_register(bundle->lacp, port, lacp);
2150 bundle_destroy(struct ofbundle *bundle)
2152 struct ofproto_dpif *ofproto;
2153 struct ofport_dpif *port, *next_port;
2159 ofproto = bundle->ofproto;
2160 mbridge_unregister_bundle(ofproto->mbridge, bundle->aux);
2162 ovs_rwlock_wrlock(&xlate_rwlock);
2163 xlate_bundle_remove(bundle);
2164 ovs_rwlock_unlock(&xlate_rwlock);
2166 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
2167 bundle_del_port(port);
2170 bundle_flush_macs(bundle, true);
2171 hmap_remove(&ofproto->bundles, &bundle->hmap_node);
2173 free(bundle->trunks);
2174 lacp_unref(bundle->lacp);
2175 bond_unref(bundle->bond);
2180 bundle_set(struct ofproto *ofproto_, void *aux,
2181 const struct ofproto_bundle_settings *s)
2183 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2184 bool need_flush = false;
2185 struct ofport_dpif *port;
2186 struct ofbundle *bundle;
2187 unsigned long *trunks;
2193 bundle_destroy(bundle_lookup(ofproto, aux));
2197 ovs_assert(s->n_slaves == 1 || s->bond != NULL);
2198 ovs_assert((s->lacp != NULL) == (s->lacp_slaves != NULL));
2200 bundle = bundle_lookup(ofproto, aux);
2202 bundle = xmalloc(sizeof *bundle);
2204 bundle->ofproto = ofproto;
2205 hmap_insert(&ofproto->bundles, &bundle->hmap_node,
2206 hash_pointer(aux, 0));
2208 bundle->name = NULL;
2210 list_init(&bundle->ports);
2211 bundle->vlan_mode = PORT_VLAN_TRUNK;
2213 bundle->trunks = NULL;
2214 bundle->use_priority_tags = s->use_priority_tags;
2215 bundle->lacp = NULL;
2216 bundle->bond = NULL;
2218 bundle->floodable = true;
2219 mbridge_register_bundle(ofproto->mbridge, bundle);
2222 if (!bundle->name || strcmp(s->name, bundle->name)) {
2224 bundle->name = xstrdup(s->name);
2229 ofproto->lacp_enabled = true;
2230 if (!bundle->lacp) {
2231 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2232 bundle->lacp = lacp_create();
2234 lacp_configure(bundle->lacp, s->lacp);
2236 lacp_unref(bundle->lacp);
2237 bundle->lacp = NULL;
2240 /* Update set of ports. */
2242 for (i = 0; i < s->n_slaves; i++) {
2243 if (!bundle_add_port(bundle, s->slaves[i],
2244 s->lacp ? &s->lacp_slaves[i] : NULL)) {
2248 if (!ok || list_size(&bundle->ports) != s->n_slaves) {
2249 struct ofport_dpif *next_port;
2251 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
2252 for (i = 0; i < s->n_slaves; i++) {
2253 if (s->slaves[i] == port->up.ofp_port) {
2258 bundle_del_port(port);
2262 ovs_assert(list_size(&bundle->ports) <= s->n_slaves);
2264 if (list_is_empty(&bundle->ports)) {
2265 bundle_destroy(bundle);
2269 /* Set VLAN tagging mode */
2270 if (s->vlan_mode != bundle->vlan_mode
2271 || s->use_priority_tags != bundle->use_priority_tags) {
2272 bundle->vlan_mode = s->vlan_mode;
2273 bundle->use_priority_tags = s->use_priority_tags;
2278 vlan = (s->vlan_mode == PORT_VLAN_TRUNK ? -1
2279 : s->vlan >= 0 && s->vlan <= 4095 ? s->vlan
2281 if (vlan != bundle->vlan) {
2282 bundle->vlan = vlan;
2286 /* Get trunked VLANs. */
2287 switch (s->vlan_mode) {
2288 case PORT_VLAN_ACCESS:
2292 case PORT_VLAN_TRUNK:
2293 trunks = CONST_CAST(unsigned long *, s->trunks);
2296 case PORT_VLAN_NATIVE_UNTAGGED:
2297 case PORT_VLAN_NATIVE_TAGGED:
2298 if (vlan != 0 && (!s->trunks
2299 || !bitmap_is_set(s->trunks, vlan)
2300 || bitmap_is_set(s->trunks, 0))) {
2301 /* Force trunking the native VLAN and prohibit trunking VLAN 0. */
2303 trunks = bitmap_clone(s->trunks, 4096);
2305 trunks = bitmap_allocate1(4096);
2307 bitmap_set1(trunks, vlan);
2308 bitmap_set0(trunks, 0);
2310 trunks = CONST_CAST(unsigned long *, s->trunks);
2317 if (!vlan_bitmap_equal(trunks, bundle->trunks)) {
2318 free(bundle->trunks);
2319 if (trunks == s->trunks) {
2320 bundle->trunks = vlan_bitmap_clone(trunks);
2322 bundle->trunks = trunks;
2327 if (trunks != s->trunks) {
2332 if (!list_is_short(&bundle->ports)) {
2333 bundle->ofproto->has_bonded_bundles = true;
2335 if (bond_reconfigure(bundle->bond, s->bond)) {
2336 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2339 bundle->bond = bond_create(s->bond);
2340 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2343 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2344 bond_slave_register(bundle->bond, port, port->up.netdev);
2347 bond_unref(bundle->bond);
2348 bundle->bond = NULL;
2351 /* If we changed something that would affect MAC learning, un-learn
2352 * everything on this port and force flow revalidation. */
2354 bundle_flush_macs(bundle, false);
2361 bundle_remove(struct ofport *port_)
2363 struct ofport_dpif *port = ofport_dpif_cast(port_);
2364 struct ofbundle *bundle = port->bundle;
2367 bundle_del_port(port);
2368 if (list_is_empty(&bundle->ports)) {
2369 bundle_destroy(bundle);
2370 } else if (list_is_short(&bundle->ports)) {
2371 bond_unref(bundle->bond);
2372 bundle->bond = NULL;
2378 send_pdu_cb(void *port_, const void *pdu, size_t pdu_size)
2380 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10);
2381 struct ofport_dpif *port = port_;
2382 uint8_t ea[ETH_ADDR_LEN];
2385 error = netdev_get_etheraddr(port->up.netdev, ea);
2387 struct ofpbuf packet;
2390 ofpbuf_init(&packet, 0);
2391 packet_pdu = eth_compose(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP,
2393 memcpy(packet_pdu, pdu, pdu_size);
2395 ofproto_dpif_send_packet(port, &packet);
2396 ofpbuf_uninit(&packet);
2398 VLOG_ERR_RL(&rl, "port %s: cannot obtain Ethernet address of iface "
2399 "%s (%s)", port->bundle->name,
2400 netdev_get_name(port->up.netdev), ovs_strerror(error));
2405 bundle_send_learning_packets(struct ofbundle *bundle)
2407 struct ofproto_dpif *ofproto = bundle->ofproto;
2408 struct ofpbuf *learning_packet;
2409 int error, n_packets, n_errors;
2410 struct mac_entry *e;
2411 struct list packets;
2413 list_init(&packets);
2414 ovs_rwlock_rdlock(&ofproto->ml->rwlock);
2415 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
2416 if (e->port.p != bundle) {
2419 learning_packet = bond_compose_learning_packet(bundle->bond,
2422 /* Temporarily use l2 as a private pointer (see below). */
2423 ovs_assert(learning_packet->l2 == ofpbuf_data(learning_packet));
2424 learning_packet->l2 = port_void;
2425 list_push_back(&packets, &learning_packet->list_node);
2428 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2430 error = n_packets = n_errors = 0;
2431 LIST_FOR_EACH (learning_packet, list_node, &packets) {
2433 void *port_void = learning_packet->l2;
2436 learning_packet->l2 = ofpbuf_data(learning_packet);
2437 ret = ofproto_dpif_send_packet(port_void, learning_packet);
2444 ofpbuf_list_delete(&packets);
2447 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2448 VLOG_WARN_RL(&rl, "bond %s: %d errors sending %d gratuitous learning "
2449 "packets, last error was: %s",
2450 bundle->name, n_errors, n_packets, ovs_strerror(error));
2452 VLOG_DBG("bond %s: sent %d gratuitous learning packets",
2453 bundle->name, n_packets);
2458 bundle_run(struct ofbundle *bundle)
2461 lacp_run(bundle->lacp, send_pdu_cb);
2464 struct ofport_dpif *port;
2466 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2467 bond_slave_set_may_enable(bundle->bond, port, port->may_enable);
2470 if (bond_run(bundle->bond, lacp_status(bundle->lacp))) {
2471 bundle->ofproto->backer->need_revalidate = REV_BOND;
2474 if (bond_should_send_learning_packets(bundle->bond)) {
2475 bundle_send_learning_packets(bundle);
2481 bundle_wait(struct ofbundle *bundle)
2484 lacp_wait(bundle->lacp);
2487 bond_wait(bundle->bond);
2494 mirror_set__(struct ofproto *ofproto_, void *aux,
2495 const struct ofproto_mirror_settings *s)
2497 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2498 struct ofbundle **srcs, **dsts;
2503 mirror_destroy(ofproto->mbridge, aux);
2507 srcs = xmalloc(s->n_srcs * sizeof *srcs);
2508 dsts = xmalloc(s->n_dsts * sizeof *dsts);
2510 for (i = 0; i < s->n_srcs; i++) {
2511 srcs[i] = bundle_lookup(ofproto, s->srcs[i]);
2514 for (i = 0; i < s->n_dsts; i++) {
2515 dsts[i] = bundle_lookup(ofproto, s->dsts[i]);
2518 error = mirror_set(ofproto->mbridge, aux, s->name, srcs, s->n_srcs, dsts,
2519 s->n_dsts, s->src_vlans,
2520 bundle_lookup(ofproto, s->out_bundle), s->out_vlan);
2527 mirror_get_stats__(struct ofproto *ofproto, void *aux,
2528 uint64_t *packets, uint64_t *bytes)
2530 return mirror_get_stats(ofproto_dpif_cast(ofproto)->mbridge, aux, packets,
2535 set_flood_vlans(struct ofproto *ofproto_, unsigned long *flood_vlans)
2537 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2538 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2539 if (mac_learning_set_flood_vlans(ofproto->ml, flood_vlans)) {
2540 mac_learning_flush(ofproto->ml);
2542 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2547 is_mirror_output_bundle(const struct ofproto *ofproto_, void *aux)
2549 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2550 struct ofbundle *bundle = bundle_lookup(ofproto, aux);
2551 return bundle && mirror_bundle_out(ofproto->mbridge, bundle) != 0;
2555 forward_bpdu_changed(struct ofproto *ofproto_)
2557 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2558 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2562 set_mac_table_config(struct ofproto *ofproto_, unsigned int idle_time,
2565 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2566 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
2567 mac_learning_set_idle_time(ofproto->ml, idle_time);
2568 mac_learning_set_max_entries(ofproto->ml, max_entries);
2569 ovs_rwlock_unlock(&ofproto->ml->rwlock);
2574 static struct ofport_dpif *
2575 get_ofp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
2577 struct ofport *ofport = ofproto_get_port(&ofproto->up, ofp_port);
2578 return ofport ? ofport_dpif_cast(ofport) : NULL;
2582 ofproto_port_from_dpif_port(struct ofproto_dpif *ofproto,
2583 struct ofproto_port *ofproto_port,
2584 struct dpif_port *dpif_port)
2586 ofproto_port->name = dpif_port->name;
2587 ofproto_port->type = dpif_port->type;
2588 ofproto_port->ofp_port = odp_port_to_ofp_port(ofproto, dpif_port->port_no);
2592 ofport_update_peer(struct ofport_dpif *ofport)
2594 const struct ofproto_dpif *ofproto;
2595 struct dpif_backer *backer;
2598 if (!netdev_vport_is_patch(ofport->up.netdev)) {
2602 backer = ofproto_dpif_cast(ofport->up.ofproto)->backer;
2603 backer->need_revalidate = REV_RECONFIGURE;
2606 ofport->peer->peer = NULL;
2607 ofport->peer = NULL;
2610 peer_name = netdev_vport_patch_peer(ofport->up.netdev);
2615 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
2616 struct ofport *peer_ofport;
2617 struct ofport_dpif *peer;
2620 if (ofproto->backer != backer) {
2624 peer_ofport = shash_find_data(&ofproto->up.port_by_name, peer_name);
2629 peer = ofport_dpif_cast(peer_ofport);
2630 peer_peer = netdev_vport_patch_peer(peer->up.netdev);
2631 if (peer_peer && !strcmp(netdev_get_name(ofport->up.netdev),
2633 ofport->peer = peer;
2634 ofport->peer->peer = ofport;
2644 port_run(struct ofport_dpif *ofport)
2646 long long int carrier_seq = netdev_get_carrier_resets(ofport->up.netdev);
2647 bool carrier_changed = carrier_seq != ofport->carrier_seq;
2648 bool enable = netdev_get_carrier(ofport->up.netdev);
2649 bool cfm_enable = false;
2650 bool bfd_enable = false;
2652 ofport->carrier_seq = carrier_seq;
2655 int cfm_opup = cfm_get_opup(ofport->cfm);
2657 cfm_enable = !cfm_get_fault(ofport->cfm);
2659 if (cfm_opup >= 0) {
2660 cfm_enable = cfm_enable && cfm_opup;
2665 bfd_enable = bfd_forwarding(ofport->bfd);
2668 if (ofport->bfd || ofport->cfm) {
2669 enable = enable && (cfm_enable || bfd_enable);
2672 if (ofport->bundle) {
2673 enable = enable && lacp_slave_may_enable(ofport->bundle->lacp, ofport);
2674 if (carrier_changed) {
2675 lacp_slave_carrier_changed(ofport->bundle->lacp, ofport);
2679 if (ofport->may_enable != enable) {
2680 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2681 ofproto->backer->need_revalidate = REV_PORT_TOGGLED;
2684 ofport->may_enable = enable;
2688 port_query_by_name(const struct ofproto *ofproto_, const char *devname,
2689 struct ofproto_port *ofproto_port)
2691 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2692 struct dpif_port dpif_port;
2695 if (sset_contains(&ofproto->ghost_ports, devname)) {
2696 const char *type = netdev_get_type_from_name(devname);
2698 /* We may be called before ofproto->up.port_by_name is populated with
2699 * the appropriate ofport. For this reason, we must get the name and
2700 * type from the netdev layer directly. */
2702 const struct ofport *ofport;
2704 ofport = shash_find_data(&ofproto->up.port_by_name, devname);
2705 ofproto_port->ofp_port = ofport ? ofport->ofp_port : OFPP_NONE;
2706 ofproto_port->name = xstrdup(devname);
2707 ofproto_port->type = xstrdup(type);
2713 if (!sset_contains(&ofproto->ports, devname)) {
2716 error = dpif_port_query_by_name(ofproto->backer->dpif,
2717 devname, &dpif_port);
2719 ofproto_port_from_dpif_port(ofproto, ofproto_port, &dpif_port);
2725 port_add(struct ofproto *ofproto_, struct netdev *netdev)
2727 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2728 const char *devname = netdev_get_name(netdev);
2729 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
2730 const char *dp_port_name;
2732 if (netdev_vport_is_patch(netdev)) {
2733 sset_add(&ofproto->ghost_ports, netdev_get_name(netdev));
2737 dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
2738 if (!dpif_port_exists(ofproto->backer->dpif, dp_port_name)) {
2739 odp_port_t port_no = ODPP_NONE;
2742 error = dpif_port_add(ofproto->backer->dpif, netdev, &port_no);
2746 if (netdev_get_tunnel_config(netdev)) {
2747 simap_put(&ofproto->backer->tnl_backers,
2748 dp_port_name, odp_to_u32(port_no));
2752 if (netdev_get_tunnel_config(netdev)) {
2753 sset_add(&ofproto->ghost_ports, devname);
2755 sset_add(&ofproto->ports, devname);
2761 port_del(struct ofproto *ofproto_, ofp_port_t ofp_port)
2763 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2764 struct ofport_dpif *ofport = get_ofp_port(ofproto, ofp_port);
2771 sset_find_and_delete(&ofproto->ghost_ports,
2772 netdev_get_name(ofport->up.netdev));
2773 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2774 if (!ofport->is_tunnel && !netdev_vport_is_patch(ofport->up.netdev)) {
2775 error = dpif_port_del(ofproto->backer->dpif, ofport->odp_port);
2777 /* The caller is going to close ofport->up.netdev. If this is a
2778 * bonded port, then the bond is using that netdev, so remove it
2779 * from the bond. The client will need to reconfigure everything
2780 * after deleting ports, so then the slave will get re-added. */
2781 bundle_remove(&ofport->up);
2788 port_get_stats(const struct ofport *ofport_, struct netdev_stats *stats)
2790 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2793 error = netdev_get_stats(ofport->up.netdev, stats);
2795 if (!error && ofport_->ofp_port == OFPP_LOCAL) {
2796 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2798 ovs_mutex_lock(&ofproto->stats_mutex);
2799 /* ofproto->stats.tx_packets represents packets that we created
2800 * internally and sent to some port (e.g. packets sent with
2801 * ofproto_dpif_send_packet()). Account for them as if they had
2802 * come from OFPP_LOCAL and got forwarded. */
2804 if (stats->rx_packets != UINT64_MAX) {
2805 stats->rx_packets += ofproto->stats.tx_packets;
2808 if (stats->rx_bytes != UINT64_MAX) {
2809 stats->rx_bytes += ofproto->stats.tx_bytes;
2812 /* ofproto->stats.rx_packets represents packets that were received on
2813 * some port and we processed internally and dropped (e.g. STP).
2814 * Account for them as if they had been forwarded to OFPP_LOCAL. */
2816 if (stats->tx_packets != UINT64_MAX) {
2817 stats->tx_packets += ofproto->stats.rx_packets;
2820 if (stats->tx_bytes != UINT64_MAX) {
2821 stats->tx_bytes += ofproto->stats.rx_bytes;
2823 ovs_mutex_unlock(&ofproto->stats_mutex);
2829 struct port_dump_state {
2834 struct ofproto_port port;
2839 port_dump_start(const struct ofproto *ofproto_ OVS_UNUSED, void **statep)
2841 *statep = xzalloc(sizeof(struct port_dump_state));
2846 port_dump_next(const struct ofproto *ofproto_, void *state_,
2847 struct ofproto_port *port)
2849 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2850 struct port_dump_state *state = state_;
2851 const struct sset *sset;
2852 struct sset_node *node;
2854 if (state->has_port) {
2855 ofproto_port_destroy(&state->port);
2856 state->has_port = false;
2858 sset = state->ghost ? &ofproto->ghost_ports : &ofproto->ports;
2859 while ((node = sset_at_position(sset, &state->bucket, &state->offset))) {
2862 error = port_query_by_name(ofproto_, node->name, &state->port);
2864 *port = state->port;
2865 state->has_port = true;
2867 } else if (error != ENODEV) {
2872 if (!state->ghost) {
2873 state->ghost = true;
2876 return port_dump_next(ofproto_, state_, port);
2883 port_dump_done(const struct ofproto *ofproto_ OVS_UNUSED, void *state_)
2885 struct port_dump_state *state = state_;
2887 if (state->has_port) {
2888 ofproto_port_destroy(&state->port);
2895 port_poll(const struct ofproto *ofproto_, char **devnamep)
2897 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2899 if (ofproto->port_poll_errno) {
2900 int error = ofproto->port_poll_errno;
2901 ofproto->port_poll_errno = 0;
2905 if (sset_is_empty(&ofproto->port_poll_set)) {
2909 *devnamep = sset_pop(&ofproto->port_poll_set);
2914 port_poll_wait(const struct ofproto *ofproto_)
2916 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2917 dpif_port_poll_wait(ofproto->backer->dpif);
2921 port_is_lacp_current(const struct ofport *ofport_)
2923 const struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2924 return (ofport->bundle && ofport->bundle->lacp
2925 ? lacp_slave_is_current(ofport->bundle->lacp, ofport)
2929 /* If 'rule' is an OpenFlow rule, that has expired according to OpenFlow rules,
2930 * then delete it entirely. */
2932 rule_expire(struct rule_dpif *rule)
2933 OVS_REQUIRES(ofproto_mutex)
2935 uint16_t hard_timeout, idle_timeout;
2936 long long int now = time_msec();
2939 ovs_assert(!rule->up.pending);
2941 hard_timeout = rule->up.hard_timeout;
2942 idle_timeout = rule->up.idle_timeout;
2944 /* Has 'rule' expired? */
2946 long long int modified;
2948 ovs_mutex_lock(&rule->up.mutex);
2949 modified = rule->up.modified;
2950 ovs_mutex_unlock(&rule->up.mutex);
2952 if (now > modified + hard_timeout * 1000) {
2953 reason = OFPRR_HARD_TIMEOUT;
2957 if (reason < 0 && idle_timeout) {
2960 ovs_mutex_lock(&rule->stats_mutex);
2961 used = rule->stats.used;
2962 ovs_mutex_unlock(&rule->stats_mutex);
2964 if (now > used + idle_timeout * 1000) {
2965 reason = OFPRR_IDLE_TIMEOUT;
2970 COVERAGE_INC(ofproto_dpif_expired);
2971 ofproto_rule_expire(&rule->up, reason);
2975 /* Executes, within 'ofproto', the actions in 'rule' or 'ofpacts' on 'packet'.
2976 * 'flow' must reflect the data in 'packet'. */
2978 ofproto_dpif_execute_actions(struct ofproto_dpif *ofproto,
2979 const struct flow *flow,
2980 struct rule_dpif *rule,
2981 const struct ofpact *ofpacts, size_t ofpacts_len,
2982 struct ofpbuf *packet)
2984 struct dpif_flow_stats stats;
2985 struct xlate_out xout;
2986 struct xlate_in xin;
2988 struct dpif_execute execute;
2991 ovs_assert((rule != NULL) != (ofpacts != NULL));
2993 dpif_flow_stats_extract(flow, packet, time_msec(), &stats);
2995 rule_dpif_credit_stats(rule, &stats);
2998 xlate_in_init(&xin, ofproto, flow, rule, stats.tcp_flags, packet);
2999 xin.ofpacts = ofpacts;
3000 xin.ofpacts_len = ofpacts_len;
3001 xin.resubmit_stats = &stats;
3002 xlate_actions(&xin, &xout);
3004 in_port = flow->in_port.ofp_port;
3005 if (in_port == OFPP_NONE) {
3006 in_port = OFPP_LOCAL;
3008 execute.actions = ofpbuf_data(&xout.odp_actions);
3009 execute.actions_len = ofpbuf_size(&xout.odp_actions);
3010 execute.packet = packet;
3011 execute.md.tunnel = flow->tunnel;
3012 execute.md.skb_priority = flow->skb_priority;
3013 execute.md.pkt_mark = flow->pkt_mark;
3014 execute.md.in_port.odp_port = ofp_port_to_odp_port(ofproto, in_port);
3015 execute.needs_help = (xout.slow & SLOW_ACTION) != 0;
3017 error = dpif_execute(ofproto->backer->dpif, &execute);
3019 xlate_out_uninit(&xout);
3025 rule_dpif_credit_stats(struct rule_dpif *rule,
3026 const struct dpif_flow_stats *stats)
3028 ovs_mutex_lock(&rule->stats_mutex);
3029 rule->stats.n_packets += stats->n_packets;
3030 rule->stats.n_bytes += stats->n_bytes;
3031 rule->stats.used = MAX(rule->stats.used, stats->used);
3032 ovs_mutex_unlock(&rule->stats_mutex);
3036 rule_dpif_is_fail_open(const struct rule_dpif *rule)
3038 return is_fail_open_rule(&rule->up);
3042 rule_dpif_is_table_miss(const struct rule_dpif *rule)
3044 return rule_is_table_miss(&rule->up);
3048 rule_dpif_is_internal(const struct rule_dpif *rule)
3050 return rule_is_internal(&rule->up);
3054 rule_dpif_get_flow_cookie(const struct rule_dpif *rule)
3055 OVS_REQUIRES(rule->up.mutex)
3057 return rule->up.flow_cookie;
3061 rule_dpif_reduce_timeouts(struct rule_dpif *rule, uint16_t idle_timeout,
3062 uint16_t hard_timeout)
3064 ofproto_rule_reduce_timeouts(&rule->up, idle_timeout, hard_timeout);
3067 /* Returns 'rule''s actions. The caller owns a reference on the returned
3068 * actions and must eventually release it (with rule_actions_unref()) to avoid
3070 struct rule_actions *
3071 rule_dpif_get_actions(const struct rule_dpif *rule)
3073 return rule_get_actions(&rule->up);
3076 /* Lookup 'flow' in table 0 of 'ofproto''s classifier.
3077 * If 'wc' is non-null, sets the fields that were relevant as part of
3078 * the lookup. Returns the table_id where a match or miss occurred.
3080 * The return value will be zero unless there was a miss and
3081 * OFPTC_TABLE_MISS_CONTINUE is in effect for the sequence of tables
3082 * where misses occur. */
3084 rule_dpif_lookup(struct ofproto_dpif *ofproto, const struct flow *flow,
3085 struct flow_wildcards *wc, struct rule_dpif **rule)
3087 enum rule_dpif_lookup_verdict verdict;
3088 enum ofputil_port_config config = 0;
3089 uint8_t table_id = 0;
3091 verdict = rule_dpif_lookup_from_table(ofproto, flow, wc, true,
3095 case RULE_DPIF_LOOKUP_VERDICT_MATCH:
3097 case RULE_DPIF_LOOKUP_VERDICT_CONTROLLER: {
3098 struct ofport_dpif *port;
3100 port = get_ofp_port(ofproto, flow->in_port.ofp_port);
3102 VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16,
3103 flow->in_port.ofp_port);
3105 config = port ? port->up.pp.config : 0;
3108 case RULE_DPIF_LOOKUP_VERDICT_DROP:
3109 config = OFPUTIL_PC_NO_PACKET_IN;
3115 choose_miss_rule(config, ofproto->miss_rule,
3116 ofproto->no_packet_in_rule, rule);
3120 static struct rule_dpif *
3121 rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, uint8_t table_id,
3122 const struct flow *flow, struct flow_wildcards *wc)
3124 struct classifier *cls = &ofproto->up.tables[table_id].cls;
3125 const struct cls_rule *cls_rule;
3126 struct rule_dpif *rule;
3128 fat_rwlock_rdlock(&cls->rwlock);
3129 if (ofproto->up.frag_handling != OFPC_FRAG_NX_MATCH) {
3131 memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
3132 if (is_ip_any(flow)) {
3133 wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
3137 if (flow->nw_frag & FLOW_NW_FRAG_ANY) {
3138 if (ofproto->up.frag_handling == OFPC_FRAG_NORMAL) {
3139 /* We must pretend that transport ports are unavailable. */
3140 struct flow ofpc_normal_flow = *flow;
3141 ofpc_normal_flow.tp_src = htons(0);
3142 ofpc_normal_flow.tp_dst = htons(0);
3143 cls_rule = classifier_lookup(cls, &ofpc_normal_flow, wc);
3145 /* Must be OFPC_FRAG_DROP (we don't have OFPC_FRAG_REASM). */
3146 cls_rule = &ofproto->drop_frags_rule->up.cr;
3149 cls_rule = classifier_lookup(cls, flow, wc);
3152 cls_rule = classifier_lookup(cls, flow, wc);
3155 rule = rule_dpif_cast(rule_from_cls_rule(cls_rule));
3156 rule_dpif_ref(rule);
3157 fat_rwlock_unlock(&cls->rwlock);
3162 /* Look up 'flow' in 'ofproto''s classifier starting from table '*table_id'.
3163 * Stores the rule that was found in '*rule', or NULL if none was found.
3164 * Updates 'wc', if nonnull, to reflect the fields that were used during the
3167 * If 'honor_table_miss' is true, the first lookup occurs in '*table_id', but
3168 * if none is found then the table miss configuration for that table is
3169 * honored, which can result in additional lookups in other OpenFlow tables.
3170 * In this case the function updates '*table_id' to reflect the final OpenFlow
3171 * table that was searched.
3173 * If 'honor_table_miss' is false, then only one table lookup occurs, in
3178 * - RULE_DPIF_LOOKUP_VERDICT_MATCH if a rule (in '*rule') was found.
3180 * - RULE_DPIF_LOOKUP_VERDICT_DROP if no rule was found and a table miss
3181 * configuration specified that the packet should be dropped in this
3182 * case. (This occurs only if 'honor_table_miss' is true, because only in
3183 * this case does the table miss configuration matter.)
3185 * - RULE_DPIF_LOOKUP_VERDICT_CONTROLLER if no rule was found otherwise. */
3186 enum rule_dpif_lookup_verdict
3187 rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto,
3188 const struct flow *flow,
3189 struct flow_wildcards *wc,
3190 bool honor_table_miss,
3191 uint8_t *table_id, struct rule_dpif **rule)
3195 for (next_id = *table_id;
3196 next_id < ofproto->up.n_tables;
3197 next_id++, next_id += (next_id == TBL_INTERNAL))
3199 *table_id = next_id;
3200 *rule = rule_dpif_lookup_in_table(ofproto, *table_id, flow, wc);
3202 return RULE_DPIF_LOOKUP_VERDICT_MATCH;
3203 } else if (!honor_table_miss) {
3204 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3206 switch (table_get_config(&ofproto->up, *table_id)
3207 & OFPTC11_TABLE_MISS_MASK) {
3208 case OFPTC11_TABLE_MISS_CONTINUE:
3211 case OFPTC11_TABLE_MISS_CONTROLLER:
3212 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3214 case OFPTC11_TABLE_MISS_DROP:
3215 return RULE_DPIF_LOOKUP_VERDICT_DROP;
3220 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3223 /* Given a port configuration (specified as zero if there's no port), chooses
3224 * which of 'miss_rule' and 'no_packet_in_rule' should be used in case of a
3225 * flow table miss. */
3227 choose_miss_rule(enum ofputil_port_config config, struct rule_dpif *miss_rule,
3228 struct rule_dpif *no_packet_in_rule, struct rule_dpif **rule)
3230 *rule = config & OFPUTIL_PC_NO_PACKET_IN ? no_packet_in_rule : miss_rule;
3231 rule_dpif_ref(*rule);
3235 rule_dpif_ref(struct rule_dpif *rule)
3238 ofproto_rule_ref(&rule->up);
3243 rule_dpif_unref(struct rule_dpif *rule)
3246 ofproto_rule_unref(&rule->up);
3251 complete_operation(struct rule_dpif *rule)
3252 OVS_REQUIRES(ofproto_mutex)
3254 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
3256 ofproto->backer->need_revalidate = REV_FLOW_TABLE;
3257 ofoperation_complete(rule->up.pending, 0);
3260 static struct rule_dpif *rule_dpif_cast(const struct rule *rule)
3262 return rule ? CONTAINER_OF(rule, struct rule_dpif, up) : NULL;
3265 static struct rule *
3268 struct rule_dpif *rule = xmalloc(sizeof *rule);
3273 rule_dealloc(struct rule *rule_)
3275 struct rule_dpif *rule = rule_dpif_cast(rule_);
3280 rule_construct(struct rule *rule_)
3281 OVS_NO_THREAD_SAFETY_ANALYSIS
3283 struct rule_dpif *rule = rule_dpif_cast(rule_);
3284 ovs_mutex_init_adaptive(&rule->stats_mutex);
3285 rule->stats.n_packets = 0;
3286 rule->stats.n_bytes = 0;
3287 rule->stats.used = rule->up.modified;
3292 rule_insert(struct rule *rule_)
3293 OVS_REQUIRES(ofproto_mutex)
3295 struct rule_dpif *rule = rule_dpif_cast(rule_);
3296 complete_operation(rule);
3300 rule_delete(struct rule *rule_)
3301 OVS_REQUIRES(ofproto_mutex)
3303 struct rule_dpif *rule = rule_dpif_cast(rule_);
3304 complete_operation(rule);
3308 rule_destruct(struct rule *rule_)
3310 struct rule_dpif *rule = rule_dpif_cast(rule_);
3311 ovs_mutex_destroy(&rule->stats_mutex);
3315 rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes,
3316 long long int *used)
3318 struct rule_dpif *rule = rule_dpif_cast(rule_);
3320 ovs_mutex_lock(&rule->stats_mutex);
3321 *packets = rule->stats.n_packets;
3322 *bytes = rule->stats.n_bytes;
3323 *used = rule->stats.used;
3324 ovs_mutex_unlock(&rule->stats_mutex);
3328 rule_dpif_execute(struct rule_dpif *rule, const struct flow *flow,
3329 struct ofpbuf *packet)
3331 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
3333 ofproto_dpif_execute_actions(ofproto, flow, rule, NULL, 0, packet);
3337 rule_execute(struct rule *rule, const struct flow *flow,
3338 struct ofpbuf *packet)
3340 rule_dpif_execute(rule_dpif_cast(rule), flow, packet);
3341 ofpbuf_delete(packet);
3346 rule_modify_actions(struct rule *rule_, bool reset_counters)
3347 OVS_REQUIRES(ofproto_mutex)
3349 struct rule_dpif *rule = rule_dpif_cast(rule_);
3351 if (reset_counters) {
3352 ovs_mutex_lock(&rule->stats_mutex);
3353 rule->stats.n_packets = 0;
3354 rule->stats.n_bytes = 0;
3355 ovs_mutex_unlock(&rule->stats_mutex);
3358 complete_operation(rule);
3361 static struct group_dpif *group_dpif_cast(const struct ofgroup *group)
3363 return group ? CONTAINER_OF(group, struct group_dpif, up) : NULL;
3366 static struct ofgroup *
3369 struct group_dpif *group = xzalloc(sizeof *group);
3374 group_dealloc(struct ofgroup *group_)
3376 struct group_dpif *group = group_dpif_cast(group_);
3381 group_construct_stats(struct group_dpif *group)
3382 OVS_REQUIRES(group->stats_mutex)
3384 group->packet_count = 0;
3385 group->byte_count = 0;
3386 if (!group->bucket_stats) {
3387 group->bucket_stats = xcalloc(group->up.n_buckets,
3388 sizeof *group->bucket_stats);
3390 memset(group->bucket_stats, 0, group->up.n_buckets *
3391 sizeof *group->bucket_stats);
3396 group_construct(struct ofgroup *group_)
3398 struct group_dpif *group = group_dpif_cast(group_);
3399 const struct ofputil_bucket *bucket;
3401 /* Prevent group chaining because our locking structure makes it hard to
3402 * implement deadlock-free. (See xlate_group_resource_check().) */
3403 LIST_FOR_EACH (bucket, list_node, &group->up.buckets) {
3404 const struct ofpact *a;
3406 OFPACT_FOR_EACH (a, bucket->ofpacts, bucket->ofpacts_len) {
3407 if (a->type == OFPACT_GROUP) {
3408 return OFPERR_OFPGMFC_CHAINING_UNSUPPORTED;
3413 ovs_mutex_init_adaptive(&group->stats_mutex);
3414 ovs_mutex_lock(&group->stats_mutex);
3415 group_construct_stats(group);
3416 ovs_mutex_unlock(&group->stats_mutex);
3421 group_destruct__(struct group_dpif *group)
3422 OVS_REQUIRES(group->stats_mutex)
3424 free(group->bucket_stats);
3425 group->bucket_stats = NULL;
3429 group_destruct(struct ofgroup *group_)
3431 struct group_dpif *group = group_dpif_cast(group_);
3432 ovs_mutex_lock(&group->stats_mutex);
3433 group_destruct__(group);
3434 ovs_mutex_unlock(&group->stats_mutex);
3435 ovs_mutex_destroy(&group->stats_mutex);
3439 group_modify(struct ofgroup *group_, struct ofgroup *victim_)
3441 struct ofproto_dpif *ofproto = ofproto_dpif_cast(group_->ofproto);
3442 struct group_dpif *group = group_dpif_cast(group_);
3443 struct group_dpif *victim = group_dpif_cast(victim_);
3445 ovs_mutex_lock(&group->stats_mutex);
3446 if (victim->up.n_buckets < group->up.n_buckets) {
3447 group_destruct__(group);
3449 group_construct_stats(group);
3450 ovs_mutex_unlock(&group->stats_mutex);
3452 ofproto->backer->need_revalidate = REV_FLOW_TABLE;
3458 group_get_stats(const struct ofgroup *group_, struct ofputil_group_stats *ogs)
3460 struct group_dpif *group = group_dpif_cast(group_);
3462 ovs_mutex_lock(&group->stats_mutex);
3463 ogs->packet_count = group->packet_count;
3464 ogs->byte_count = group->byte_count;
3465 memcpy(ogs->bucket_stats, group->bucket_stats,
3466 group->up.n_buckets * sizeof *group->bucket_stats);
3467 ovs_mutex_unlock(&group->stats_mutex);
3473 group_dpif_lookup(struct ofproto_dpif *ofproto, uint32_t group_id,
3474 struct group_dpif **group)
3475 OVS_TRY_RDLOCK(true, (*group)->up.rwlock)
3477 struct ofgroup *ofgroup;
3481 found = ofproto_group_lookup(&ofproto->up, group_id, &ofgroup);
3482 *group = found ? group_dpif_cast(ofgroup) : NULL;
3488 group_dpif_release(struct group_dpif *group)
3489 OVS_RELEASES(group->up.rwlock)
3491 ofproto_group_release(&group->up);
3495 group_dpif_get_buckets(const struct group_dpif *group,
3496 const struct list **buckets)
3498 *buckets = &group->up.buckets;
3501 enum ofp11_group_type
3502 group_dpif_get_type(const struct group_dpif *group)
3504 return group->up.type;
3507 /* Sends 'packet' out 'ofport'.
3508 * May modify 'packet'.
3509 * Returns 0 if successful, otherwise a positive errno value. */
3511 ofproto_dpif_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet)
3513 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
3516 error = xlate_send_packet(ofport, packet);
3518 ovs_mutex_lock(&ofproto->stats_mutex);
3519 ofproto->stats.tx_packets++;
3520 ofproto->stats.tx_bytes += ofpbuf_size(packet);
3521 ovs_mutex_unlock(&ofproto->stats_mutex);
3526 set_frag_handling(struct ofproto *ofproto_,
3527 enum ofp_config_flags frag_handling)
3529 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3530 if (frag_handling != OFPC_FRAG_REASM) {
3531 ofproto->backer->need_revalidate = REV_RECONFIGURE;
3539 packet_out(struct ofproto *ofproto_, struct ofpbuf *packet,
3540 const struct flow *flow,
3541 const struct ofpact *ofpacts, size_t ofpacts_len)
3543 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3545 ofproto_dpif_execute_actions(ofproto, flow, NULL, ofpacts,
3546 ofpacts_len, packet);
3553 set_netflow(struct ofproto *ofproto_,
3554 const struct netflow_options *netflow_options)
3556 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3558 if (netflow_options) {
3559 if (!ofproto->netflow) {
3560 ofproto->netflow = netflow_create();
3561 ofproto->backer->need_revalidate = REV_RECONFIGURE;
3563 return netflow_set_options(ofproto->netflow, netflow_options);
3564 } else if (ofproto->netflow) {
3565 ofproto->backer->need_revalidate = REV_RECONFIGURE;
3566 netflow_unref(ofproto->netflow);
3567 ofproto->netflow = NULL;
3574 get_netflow_ids(const struct ofproto *ofproto_,
3575 uint8_t *engine_type, uint8_t *engine_id)
3577 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3579 dpif_get_netflow_ids(ofproto->backer->dpif, engine_type, engine_id);
3582 static struct ofproto_dpif *
3583 ofproto_dpif_lookup(const char *name)
3585 struct ofproto_dpif *ofproto;
3587 HMAP_FOR_EACH_WITH_HASH (ofproto, all_ofproto_dpifs_node,
3588 hash_string(name, 0), &all_ofproto_dpifs) {
3589 if (!strcmp(ofproto->up.name, name)) {
3597 ofproto_unixctl_fdb_flush(struct unixctl_conn *conn, int argc,
3598 const char *argv[], void *aux OVS_UNUSED)
3600 struct ofproto_dpif *ofproto;
3603 ofproto = ofproto_dpif_lookup(argv[1]);
3605 unixctl_command_reply_error(conn, "no such bridge");
3608 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
3609 mac_learning_flush(ofproto->ml);
3610 ovs_rwlock_unlock(&ofproto->ml->rwlock);
3612 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
3613 ovs_rwlock_wrlock(&ofproto->ml->rwlock);
3614 mac_learning_flush(ofproto->ml);
3615 ovs_rwlock_unlock(&ofproto->ml->rwlock);
3619 unixctl_command_reply(conn, "table successfully flushed");
3622 static struct ofport_dpif *
3623 ofbundle_get_a_port(const struct ofbundle *bundle)
3625 return CONTAINER_OF(list_front(&bundle->ports), struct ofport_dpif,
3630 ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
3631 const char *argv[], void *aux OVS_UNUSED)
3633 struct ds ds = DS_EMPTY_INITIALIZER;
3634 const struct ofproto_dpif *ofproto;
3635 const struct mac_entry *e;
3637 ofproto = ofproto_dpif_lookup(argv[1]);
3639 unixctl_command_reply_error(conn, "no such bridge");
3643 ds_put_cstr(&ds, " port VLAN MAC Age\n");
3644 ovs_rwlock_rdlock(&ofproto->ml->rwlock);
3645 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
3646 struct ofbundle *bundle = e->port.p;
3647 char name[OFP_MAX_PORT_NAME_LEN];
3649 ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port,
3651 ds_put_format(&ds, "%5s %4d "ETH_ADDR_FMT" %3d\n",
3652 name, e->vlan, ETH_ADDR_ARGS(e->mac),
3653 mac_entry_age(ofproto->ml, e));
3655 ovs_rwlock_unlock(&ofproto->ml->rwlock);
3656 unixctl_command_reply(conn, ds_cstr(&ds));
3661 struct xlate_out xout;
3662 struct xlate_in xin;
3664 struct flow_wildcards wc;
3669 trace_format_rule(struct ds *result, int level, const struct rule_dpif *rule)
3671 struct rule_actions *actions;
3674 ds_put_char_multiple(result, '\t', level);
3676 ds_put_cstr(result, "No match\n");
3680 ovs_mutex_lock(&rule->up.mutex);
3681 cookie = rule->up.flow_cookie;
3682 ovs_mutex_unlock(&rule->up.mutex);
3684 ds_put_format(result, "Rule: table=%"PRIu8" cookie=%#"PRIx64" ",
3685 rule ? rule->up.table_id : 0, ntohll(cookie));
3686 cls_rule_format(&rule->up.cr, result);
3687 ds_put_char(result, '\n');
3689 actions = rule_dpif_get_actions(rule);
3691 ds_put_char_multiple(result, '\t', level);
3692 ds_put_cstr(result, "OpenFlow actions=");
3693 ofpacts_format(actions->ofpacts, actions->ofpacts_len, result);
3694 ds_put_char(result, '\n');
3698 trace_format_flow(struct ds *result, int level, const char *title,
3699 struct trace_ctx *trace)
3701 ds_put_char_multiple(result, '\t', level);
3702 ds_put_format(result, "%s: ", title);
3703 if (flow_equal(&trace->xin.flow, &trace->flow)) {
3704 ds_put_cstr(result, "unchanged");
3706 flow_format(result, &trace->xin.flow);
3707 trace->flow = trace->xin.flow;
3709 ds_put_char(result, '\n');
3713 trace_format_regs(struct ds *result, int level, const char *title,
3714 struct trace_ctx *trace)
3718 ds_put_char_multiple(result, '\t', level);
3719 ds_put_format(result, "%s:", title);
3720 for (i = 0; i < FLOW_N_REGS; i++) {
3721 ds_put_format(result, " reg%"PRIuSIZE"=0x%"PRIx32, i, trace->flow.regs[i]);
3723 ds_put_char(result, '\n');
3727 trace_format_odp(struct ds *result, int level, const char *title,
3728 struct trace_ctx *trace)
3730 struct ofpbuf *odp_actions = &trace->xout.odp_actions;
3732 ds_put_char_multiple(result, '\t', level);
3733 ds_put_format(result, "%s: ", title);
3734 format_odp_actions(result, ofpbuf_data(odp_actions),
3735 ofpbuf_size(odp_actions));
3736 ds_put_char(result, '\n');
3740 trace_format_megaflow(struct ds *result, int level, const char *title,
3741 struct trace_ctx *trace)
3745 ds_put_char_multiple(result, '\t', level);
3746 ds_put_format(result, "%s: ", title);
3747 flow_wildcards_or(&trace->wc, &trace->xout.wc, &trace->wc);
3748 match_init(&match, &trace->flow, &trace->wc);
3749 match_format(&match, result, OFP_DEFAULT_PRIORITY);
3750 ds_put_char(result, '\n');
3754 trace_resubmit(struct xlate_in *xin, struct rule_dpif *rule, int recurse)
3756 struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin);
3757 struct ds *result = trace->result;
3759 ds_put_char(result, '\n');
3760 trace_format_flow(result, recurse + 1, "Resubmitted flow", trace);
3761 trace_format_regs(result, recurse + 1, "Resubmitted regs", trace);
3762 trace_format_odp(result, recurse + 1, "Resubmitted odp", trace);
3763 trace_format_megaflow(result, recurse + 1, "Resubmitted megaflow", trace);
3764 trace_format_rule(result, recurse + 1, rule);
3768 trace_report(struct xlate_in *xin, const char *s, int recurse)
3770 struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin);
3771 struct ds *result = trace->result;
3773 ds_put_char_multiple(result, '\t', recurse);
3774 ds_put_cstr(result, s);
3775 ds_put_char(result, '\n');
3778 /* Parses the 'argc' elements of 'argv', ignoring argv[0]. The following
3779 * forms are supported:
3781 * - [dpname] odp_flow [-generate | packet]
3782 * - bridge br_flow [-generate | packet]
3784 * On success, initializes '*ofprotop' and 'flow' and returns NULL. On failure
3785 * returns a nonnull malloced error message. */
3786 static char * WARN_UNUSED_RESULT
3787 parse_flow_and_packet(int argc, const char *argv[],
3788 struct ofproto_dpif **ofprotop, struct flow *flow,
3789 struct ofpbuf **packetp)
3791 const struct dpif_backer *backer = NULL;
3792 const char *error = NULL;
3794 struct simap port_names = SIMAP_INITIALIZER(&port_names);
3795 struct ofpbuf *packet;
3796 struct ofpbuf odp_key;
3797 struct ofpbuf odp_mask;
3799 ofpbuf_init(&odp_key, 0);
3800 ofpbuf_init(&odp_mask, 0);
3802 /* Handle "-generate" or a hex string as the last argument. */
3803 if (!strcmp(argv[argc - 1], "-generate")) {
3804 packet = ofpbuf_new(0);
3807 error = eth_from_hex(argv[argc - 1], &packet);
3810 } else if (argc == 4) {
3811 /* The 3-argument form must end in "-generate' or a hex string. */
3817 /* odp_flow can have its in_port specified as a name instead of port no.
3818 * We do not yet know whether a given flow is a odp_flow or a br_flow.
3819 * But, to know whether a flow is odp_flow through odp_flow_from_string(),
3820 * we need to create a simap of name to port no. */
3822 const char *dp_type;
3823 if (!strncmp(argv[1], "ovs-", 4)) {
3824 dp_type = argv[1] + 4;
3828 backer = shash_find_data(&all_dpif_backers, dp_type);
3829 } else if (argc == 2) {
3830 struct shash_node *node;
3831 if (shash_count(&all_dpif_backers) == 1) {
3832 node = shash_first(&all_dpif_backers);
3833 backer = node->data;
3836 error = "Syntax error";
3839 if (backer && backer->dpif) {
3840 struct dpif_port dpif_port;
3841 struct dpif_port_dump port_dump;
3842 DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, backer->dpif) {
3843 simap_put(&port_names, dpif_port.name,
3844 odp_to_u32(dpif_port.port_no));
3848 /* Parse the flow and determine whether a datapath or
3849 * bridge is specified. If function odp_flow_key_from_string()
3850 * returns 0, the flow is a odp_flow. If function
3851 * parse_ofp_exact_flow() returns NULL, the flow is a br_flow. */
3852 if (!odp_flow_from_string(argv[argc - 1], &port_names,
3853 &odp_key, &odp_mask)) {
3855 error = "Cannot find the datapath";
3859 if (xlate_receive(backer, NULL, ofpbuf_data(&odp_key),
3860 ofpbuf_size(&odp_key), flow,
3861 ofprotop, NULL, NULL, NULL, NULL)) {
3862 error = "Invalid datapath flow";
3866 char *err = parse_ofp_exact_flow(flow, NULL, argv[argc - 1], NULL);
3869 m_err = xasprintf("Bad flow syntax: %s", err);
3874 error = "Must specify bridge name";
3878 *ofprotop = ofproto_dpif_lookup(argv[1]);
3880 error = "Unknown bridge name";
3886 /* Generate a packet, if requested. */
3888 if (!ofpbuf_size(packet)) {
3889 flow_compose(packet, flow);
3891 struct pkt_metadata md = pkt_metadata_from_flow(flow);
3893 /* Use the metadata from the flow and the packet argument
3894 * to reconstruct the flow. */
3895 flow_extract(packet, &md, flow);
3900 if (error && !m_err) {
3901 m_err = xstrdup(error);
3904 ofpbuf_delete(packet);
3908 ofpbuf_uninit(&odp_key);
3909 ofpbuf_uninit(&odp_mask);
3910 simap_destroy(&port_names);
3915 ofproto_unixctl_trace(struct unixctl_conn *conn, int argc, const char *argv[],
3916 void *aux OVS_UNUSED)
3918 struct ofproto_dpif *ofproto;
3919 struct ofpbuf *packet;
3923 error = parse_flow_and_packet(argc, argv, &ofproto, &flow, &packet);
3928 ofproto_trace(ofproto, &flow, packet, NULL, 0, &result);
3929 unixctl_command_reply(conn, ds_cstr(&result));
3930 ds_destroy(&result);
3931 ofpbuf_delete(packet);
3933 unixctl_command_reply_error(conn, error);
3939 ofproto_unixctl_trace_actions(struct unixctl_conn *conn, int argc,
3940 const char *argv[], void *aux OVS_UNUSED)
3942 enum ofputil_protocol usable_protocols;
3943 struct ofproto_dpif *ofproto;
3944 bool enforce_consistency;
3945 struct ofpbuf ofpacts;
3946 struct ofpbuf *packet;
3951 /* Three kinds of error return values! */
3957 ofpbuf_init(&ofpacts, 0);
3959 /* Parse actions. */
3960 error = parse_ofpacts(argv[--argc], &ofpacts, &usable_protocols);
3962 unixctl_command_reply_error(conn, error);
3967 /* OpenFlow 1.1 and later suggest that the switch enforces certain forms of
3968 * consistency between the flow and the actions. With -consistent, we
3969 * enforce consistency even for a flow supported in OpenFlow 1.0. */
3970 if (!strcmp(argv[1], "-consistent")) {
3971 enforce_consistency = true;
3975 enforce_consistency = false;
3978 error = parse_flow_and_packet(argc, argv, &ofproto, &flow, &packet);
3980 unixctl_command_reply_error(conn, error);
3985 /* Do the same checks as handle_packet_out() in ofproto.c.
3987 * We pass a 'table_id' of 0 to ofproto_check_ofpacts(), which isn't
3988 * strictly correct because these actions aren't in any table, but it's OK
3989 * because it 'table_id' is used only to check goto_table instructions, but
3990 * packet-outs take a list of actions and therefore it can't include
3993 * We skip the "meter" check here because meter is an instruction, not an
3994 * action, and thus cannot appear in ofpacts. */
3995 in_port = ofp_to_u16(flow.in_port.ofp_port);
3996 if (in_port >= ofproto->up.max_ports && in_port < ofp_to_u16(OFPP_MAX)) {
3997 unixctl_command_reply_error(conn, "invalid in_port");
4000 if (enforce_consistency) {
4001 retval = ofpacts_check_consistency(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts),
4002 &flow, u16_to_ofp(ofproto->up.max_ports),
4003 0, 0, usable_protocols);
4005 retval = ofpacts_check(ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &flow,
4006 u16_to_ofp(ofproto->up.max_ports), 0, 0,
4012 ds_put_format(&result, "Bad actions: %s", ofperr_to_string(retval));
4013 unixctl_command_reply_error(conn, ds_cstr(&result));
4017 ofproto_trace(ofproto, &flow, packet,
4018 ofpbuf_data(&ofpacts), ofpbuf_size(&ofpacts), &result);
4019 unixctl_command_reply(conn, ds_cstr(&result));
4022 ds_destroy(&result);
4023 ofpbuf_delete(packet);
4024 ofpbuf_uninit(&ofpacts);
4027 /* Implements a "trace" through 'ofproto''s flow table, appending a textual
4028 * description of the results to 'ds'.
4030 * The trace follows a packet with the specified 'flow' through the flow
4031 * table. 'packet' may be nonnull to trace an actual packet, with consequent
4032 * side effects (if it is nonnull then its flow must be 'flow').
4034 * If 'ofpacts' is nonnull then its 'ofpacts_len' bytes specify the actions to
4035 * trace, otherwise the actions are determined by a flow table lookup. */
4037 ofproto_trace(struct ofproto_dpif *ofproto, const struct flow *flow,
4038 const struct ofpbuf *packet,
4039 const struct ofpact ofpacts[], size_t ofpacts_len,
4042 struct rule_dpif *rule;
4043 struct trace_ctx trace;
4045 ds_put_format(ds, "Bridge: %s\n", ofproto->up.name);
4046 ds_put_cstr(ds, "Flow: ");
4047 flow_format(ds, flow);
4048 ds_put_char(ds, '\n');
4050 flow_wildcards_init_catchall(&trace.wc);
4054 rule_dpif_lookup(ofproto, flow, &trace.wc, &rule);
4056 trace_format_rule(ds, 0, rule);
4057 if (rule == ofproto->miss_rule) {
4058 ds_put_cstr(ds, "\nNo match, flow generates \"packet in\"s.\n");
4059 } else if (rule == ofproto->no_packet_in_rule) {
4060 ds_put_cstr(ds, "\nNo match, packets dropped because "
4061 "OFPPC_NO_PACKET_IN is set on in_port.\n");
4062 } else if (rule == ofproto->drop_frags_rule) {
4063 ds_put_cstr(ds, "\nPackets dropped because they are IP fragments "
4064 "and the fragment handling mode is \"drop\".\n");
4068 if (rule || ofpacts) {
4071 xlate_in_init(&trace.xin, ofproto, flow, rule, ntohs(flow->tcp_flags),
4074 trace.xin.ofpacts = ofpacts;
4075 trace.xin.ofpacts_len = ofpacts_len;
4077 trace.xin.resubmit_hook = trace_resubmit;
4078 trace.xin.report_hook = trace_report;
4080 xlate_actions(&trace.xin, &trace.xout);
4082 ds_put_char(ds, '\n');
4083 trace_format_flow(ds, 0, "Final flow", &trace);
4084 trace_format_megaflow(ds, 0, "Megaflow", &trace);
4086 ds_put_cstr(ds, "Datapath actions: ");
4087 format_odp_actions(ds, ofpbuf_data(&trace.xout.odp_actions),
4088 ofpbuf_size(&trace.xout.odp_actions));
4090 if (trace.xout.slow) {
4091 enum slow_path_reason slow;
4093 ds_put_cstr(ds, "\nThis flow is handled by the userspace "
4094 "slow path because it:");
4096 slow = trace.xout.slow;
4098 enum slow_path_reason bit = rightmost_1bit(slow);
4100 ds_put_format(ds, "\n\t- %s.",
4101 slow_path_reason_to_explanation(bit));
4107 xlate_out_uninit(&trace.xout);
4110 rule_dpif_unref(rule);
4113 /* Store the current ofprotos in 'ofproto_shash'. Returns a sorted list
4114 * of the 'ofproto_shash' nodes. It is the responsibility of the caller
4115 * to destroy 'ofproto_shash' and free the returned value. */
4116 static const struct shash_node **
4117 get_ofprotos(struct shash *ofproto_shash)
4119 const struct ofproto_dpif *ofproto;
4121 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
4122 char *name = xasprintf("%s@%s", ofproto->up.type, ofproto->up.name);
4123 shash_add_nocopy(ofproto_shash, name, ofproto);
4126 return shash_sort(ofproto_shash);
4130 ofproto_unixctl_dpif_dump_dps(struct unixctl_conn *conn, int argc OVS_UNUSED,
4131 const char *argv[] OVS_UNUSED,
4132 void *aux OVS_UNUSED)
4134 struct ds ds = DS_EMPTY_INITIALIZER;
4135 struct shash ofproto_shash;
4136 const struct shash_node **sorted_ofprotos;
4139 shash_init(&ofproto_shash);
4140 sorted_ofprotos = get_ofprotos(&ofproto_shash);
4141 for (i = 0; i < shash_count(&ofproto_shash); i++) {
4142 const struct shash_node *node = sorted_ofprotos[i];
4143 ds_put_format(&ds, "%s\n", node->name);
4146 shash_destroy(&ofproto_shash);
4147 free(sorted_ofprotos);
4149 unixctl_command_reply(conn, ds_cstr(&ds));
4154 dpif_show_backer(const struct dpif_backer *backer, struct ds *ds)
4156 const struct shash_node **ofprotos;
4157 struct dpif_dp_stats dp_stats;
4158 struct shash ofproto_shash;
4161 dpif_get_dp_stats(backer->dpif, &dp_stats);
4163 ds_put_format(ds, "%s: hit:%"PRIu64" missed:%"PRIu64"\n",
4164 dpif_name(backer->dpif), dp_stats.n_hit, dp_stats.n_missed);
4166 shash_init(&ofproto_shash);
4167 ofprotos = get_ofprotos(&ofproto_shash);
4168 for (i = 0; i < shash_count(&ofproto_shash); i++) {
4169 struct ofproto_dpif *ofproto = ofprotos[i]->data;
4170 const struct shash_node **ports;
4173 if (ofproto->backer != backer) {
4177 ds_put_format(ds, "\t%s:\n", ofproto->up.name);
4179 ports = shash_sort(&ofproto->up.port_by_name);
4180 for (j = 0; j < shash_count(&ofproto->up.port_by_name); j++) {
4181 const struct shash_node *node = ports[j];
4182 struct ofport *ofport = node->data;
4184 odp_port_t odp_port;
4186 ds_put_format(ds, "\t\t%s %u/", netdev_get_name(ofport->netdev),
4189 odp_port = ofp_port_to_odp_port(ofproto, ofport->ofp_port);
4190 if (odp_port != ODPP_NONE) {
4191 ds_put_format(ds, "%"PRIu32":", odp_port);
4193 ds_put_cstr(ds, "none:");
4196 ds_put_format(ds, " (%s", netdev_get_type(ofport->netdev));
4199 if (!netdev_get_config(ofport->netdev, &config)) {
4200 const struct smap_node **nodes;
4203 nodes = smap_sort(&config);
4204 for (i = 0; i < smap_count(&config); i++) {
4205 const struct smap_node *node = nodes[i];
4206 ds_put_format(ds, "%c %s=%s", i ? ',' : ':',
4207 node->key, node->value);
4211 smap_destroy(&config);
4213 ds_put_char(ds, ')');
4214 ds_put_char(ds, '\n');
4218 shash_destroy(&ofproto_shash);
4223 ofproto_unixctl_dpif_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
4224 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
4226 struct ds ds = DS_EMPTY_INITIALIZER;
4227 const struct shash_node **backers;
4230 backers = shash_sort(&all_dpif_backers);
4231 for (i = 0; i < shash_count(&all_dpif_backers); i++) {
4232 dpif_show_backer(backers[i]->data, &ds);
4236 unixctl_command_reply(conn, ds_cstr(&ds));
4241 ofproto_dpif_contains_flow(const struct ofproto_dpif *ofproto,
4242 const struct nlattr *key, size_t key_len)
4244 struct ofproto_dpif *ofp;
4247 xlate_receive(ofproto->backer, NULL, key, key_len, &flow, &ofp,
4248 NULL, NULL, NULL, NULL);
4249 return ofp == ofproto;
4253 ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn,
4254 int argc OVS_UNUSED, const char *argv[],
4255 void *aux OVS_UNUSED)
4257 struct ds ds = DS_EMPTY_INITIALIZER;
4258 const struct dpif_flow_stats *stats;
4259 const struct ofproto_dpif *ofproto;
4260 struct dpif_flow_dump flow_dump;
4261 const struct nlattr *actions;
4262 const struct nlattr *mask;
4263 const struct nlattr *key;
4267 bool verbosity = false;
4268 struct dpif_port dpif_port;
4269 struct dpif_port_dump port_dump;
4270 struct hmap portno_names;
4274 ofproto = ofproto_dpif_lookup(argv[argc - 1]);
4276 unixctl_command_reply_error(conn, "no such bridge");
4280 if (argc > 2 && !strcmp(argv[1], "-m")) {
4284 hmap_init(&portno_names);
4285 DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, ofproto->backer->dpif) {
4286 odp_portno_names_set(&portno_names, dpif_port.port_no, dpif_port.name);
4290 error = dpif_flow_dump_start(&flow_dump, ofproto->backer->dpif);
4294 dpif_flow_dump_state_init(ofproto->backer->dpif, &state);
4295 while (dpif_flow_dump_next(&flow_dump, state, &key, &key_len,
4296 &mask, &mask_len, &actions, &actions_len,
4298 if (!ofproto_dpif_contains_flow(ofproto, key, key_len)) {
4302 odp_flow_format(key, key_len, mask, mask_len, &portno_names, &ds,
4304 ds_put_cstr(&ds, ", ");
4305 dpif_flow_stats_format(stats, &ds);
4306 ds_put_cstr(&ds, ", actions:");
4307 format_odp_actions(&ds, actions, actions_len);
4308 ds_put_char(&ds, '\n');
4310 dpif_flow_dump_state_uninit(ofproto->backer->dpif, state);
4311 error = dpif_flow_dump_done(&flow_dump);
4316 ds_put_format(&ds, "dpif/dump_flows failed: %s", ovs_strerror(errno));
4317 unixctl_command_reply_error(conn, ds_cstr(&ds));
4319 unixctl_command_reply(conn, ds_cstr(&ds));
4321 odp_portno_names_destroy(&portno_names);
4322 hmap_destroy(&portno_names);
4327 ofproto_dpif_unixctl_init(void)
4329 static bool registered;
4335 unixctl_command_register(
4337 "{[dp_name] odp_flow | bridge br_flow} [-generate|packet]",
4338 1, 3, ofproto_unixctl_trace, NULL);
4339 unixctl_command_register(
4340 "ofproto/trace-packet-out",
4341 "[-consistent] {[dp_name] odp_flow | bridge br_flow} [-generate|packet] actions",
4342 2, 6, ofproto_unixctl_trace_actions, NULL);
4343 unixctl_command_register("fdb/flush", "[bridge]", 0, 1,
4344 ofproto_unixctl_fdb_flush, NULL);
4345 unixctl_command_register("fdb/show", "bridge", 1, 1,
4346 ofproto_unixctl_fdb_show, NULL);
4347 unixctl_command_register("dpif/dump-dps", "", 0, 0,
4348 ofproto_unixctl_dpif_dump_dps, NULL);
4349 unixctl_command_register("dpif/show", "", 0, 0, ofproto_unixctl_dpif_show,
4351 unixctl_command_register("dpif/dump-flows", "[-m] bridge", 1, 2,
4352 ofproto_unixctl_dpif_dump_flows, NULL);
4356 /* Returns true if 'rule' is an internal rule, false otherwise. */
4358 rule_is_internal(const struct rule *rule)
4360 return rule->table_id == TBL_INTERNAL;
4363 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
4365 * This is deprecated. It is only for compatibility with broken device drivers
4366 * in old versions of Linux that do not properly support VLANs when VLAN
4367 * devices are not used. When broken device drivers are no longer in
4368 * widespread use, we will delete these interfaces. */
4371 set_realdev(struct ofport *ofport_, ofp_port_t realdev_ofp_port, int vid)
4373 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport_->ofproto);
4374 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
4376 if (realdev_ofp_port == ofport->realdev_ofp_port
4377 && vid == ofport->vlandev_vid) {
4381 ofproto->backer->need_revalidate = REV_RECONFIGURE;
4383 if (ofport->realdev_ofp_port) {
4386 if (realdev_ofp_port && ofport->bundle) {
4387 /* vlandevs are enslaved to their realdevs, so they are not allowed to
4388 * themselves be part of a bundle. */
4389 bundle_set(ofport->up.ofproto, ofport->bundle, NULL);
4392 ofport->realdev_ofp_port = realdev_ofp_port;
4393 ofport->vlandev_vid = vid;
4395 if (realdev_ofp_port) {
4396 vsp_add(ofport, realdev_ofp_port, vid);
4403 hash_realdev_vid(ofp_port_t realdev_ofp_port, int vid)
4405 return hash_2words(ofp_to_u16(realdev_ofp_port), vid);
4409 ofproto_has_vlan_splinters(const struct ofproto_dpif *ofproto)
4410 OVS_EXCLUDED(ofproto->vsp_mutex)
4412 /* hmap_is_empty is thread safe. */
4413 return !hmap_is_empty(&ofproto->realdev_vid_map);
4418 vsp_realdev_to_vlandev__(const struct ofproto_dpif *ofproto,
4419 ofp_port_t realdev_ofp_port, ovs_be16 vlan_tci)
4420 OVS_REQUIRES(ofproto->vsp_mutex)
4422 if (!hmap_is_empty(&ofproto->realdev_vid_map)) {
4423 int vid = vlan_tci_to_vid(vlan_tci);
4424 const struct vlan_splinter *vsp;
4426 HMAP_FOR_EACH_WITH_HASH (vsp, realdev_vid_node,
4427 hash_realdev_vid(realdev_ofp_port, vid),
4428 &ofproto->realdev_vid_map) {
4429 if (vsp->realdev_ofp_port == realdev_ofp_port
4430 && vsp->vid == vid) {
4431 return vsp->vlandev_ofp_port;
4435 return realdev_ofp_port;
4438 /* Returns the OFP port number of the Linux VLAN device that corresponds to
4439 * 'vlan_tci' on the network device with port number 'realdev_ofp_port' in
4440 * 'struct ofport_dpif'. For example, given 'realdev_ofp_port' of eth0 and
4441 * 'vlan_tci' 9, it would return the port number of eth0.9.
4443 * Unless VLAN splinters are enabled for port 'realdev_ofp_port', this
4444 * function just returns its 'realdev_ofp_port' argument. */
4446 vsp_realdev_to_vlandev(const struct ofproto_dpif *ofproto,
4447 ofp_port_t realdev_ofp_port, ovs_be16 vlan_tci)
4448 OVS_EXCLUDED(ofproto->vsp_mutex)
4452 /* hmap_is_empty is thread safe, see if we can return immediately. */
4453 if (hmap_is_empty(&ofproto->realdev_vid_map)) {
4454 return realdev_ofp_port;
4456 ovs_mutex_lock(&ofproto->vsp_mutex);
4457 ret = vsp_realdev_to_vlandev__(ofproto, realdev_ofp_port, vlan_tci);
4458 ovs_mutex_unlock(&ofproto->vsp_mutex);
4462 static struct vlan_splinter *
4463 vlandev_find(const struct ofproto_dpif *ofproto, ofp_port_t vlandev_ofp_port)
4465 struct vlan_splinter *vsp;
4467 HMAP_FOR_EACH_WITH_HASH (vsp, vlandev_node,
4468 hash_ofp_port(vlandev_ofp_port),
4469 &ofproto->vlandev_map) {
4470 if (vsp->vlandev_ofp_port == vlandev_ofp_port) {
4478 /* Returns the OpenFlow port number of the "real" device underlying the Linux
4479 * VLAN device with OpenFlow port number 'vlandev_ofp_port' and stores the
4480 * VLAN VID of the Linux VLAN device in '*vid'. For example, given
4481 * 'vlandev_ofp_port' of eth0.9, it would return the OpenFlow port number of
4482 * eth0 and store 9 in '*vid'.
4484 * Returns 0 and does not modify '*vid' if 'vlandev_ofp_port' is not a Linux
4485 * VLAN device. Unless VLAN splinters are enabled, this is what this function
4488 vsp_vlandev_to_realdev(const struct ofproto_dpif *ofproto,
4489 ofp_port_t vlandev_ofp_port, int *vid)
4490 OVS_REQUIRES(ofproto->vsp_mutex)
4492 if (!hmap_is_empty(&ofproto->vlandev_map)) {
4493 const struct vlan_splinter *vsp;
4495 vsp = vlandev_find(ofproto, vlandev_ofp_port);
4500 return vsp->realdev_ofp_port;
4506 /* Given 'flow', a flow representing a packet received on 'ofproto', checks
4507 * whether 'flow->in_port' represents a Linux VLAN device. If so, changes
4508 * 'flow->in_port' to the "real" device backing the VLAN device, sets
4509 * 'flow->vlan_tci' to the VLAN VID, and returns true. Otherwise (which is
4510 * always the case unless VLAN splinters are enabled), returns false without
4511 * making any changes. */
4513 vsp_adjust_flow(const struct ofproto_dpif *ofproto, struct flow *flow)
4514 OVS_EXCLUDED(ofproto->vsp_mutex)
4519 /* hmap_is_empty is thread safe. */
4520 if (hmap_is_empty(&ofproto->vlandev_map)) {
4524 ovs_mutex_lock(&ofproto->vsp_mutex);
4525 realdev = vsp_vlandev_to_realdev(ofproto, flow->in_port.ofp_port, &vid);
4526 ovs_mutex_unlock(&ofproto->vsp_mutex);
4531 /* Cause the flow to be processed as if it came in on the real device with
4532 * the VLAN device's VLAN ID. */
4533 flow->in_port.ofp_port = realdev;
4534 flow->vlan_tci = htons((vid & VLAN_VID_MASK) | VLAN_CFI);
4539 vsp_remove(struct ofport_dpif *port)
4541 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
4542 struct vlan_splinter *vsp;
4544 ovs_mutex_lock(&ofproto->vsp_mutex);
4545 vsp = vlandev_find(ofproto, port->up.ofp_port);
4547 hmap_remove(&ofproto->vlandev_map, &vsp->vlandev_node);
4548 hmap_remove(&ofproto->realdev_vid_map, &vsp->realdev_vid_node);
4551 port->realdev_ofp_port = 0;
4553 VLOG_ERR("missing vlan device record");
4555 ovs_mutex_unlock(&ofproto->vsp_mutex);
4559 vsp_add(struct ofport_dpif *port, ofp_port_t realdev_ofp_port, int vid)
4561 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
4563 ovs_mutex_lock(&ofproto->vsp_mutex);
4564 if (!vsp_vlandev_to_realdev(ofproto, port->up.ofp_port, NULL)
4565 && (vsp_realdev_to_vlandev__(ofproto, realdev_ofp_port, htons(vid))
4566 == realdev_ofp_port)) {
4567 struct vlan_splinter *vsp;
4569 vsp = xmalloc(sizeof *vsp);
4570 vsp->realdev_ofp_port = realdev_ofp_port;
4571 vsp->vlandev_ofp_port = port->up.ofp_port;
4574 port->realdev_ofp_port = realdev_ofp_port;
4576 hmap_insert(&ofproto->vlandev_map, &vsp->vlandev_node,
4577 hash_ofp_port(port->up.ofp_port));
4578 hmap_insert(&ofproto->realdev_vid_map, &vsp->realdev_vid_node,
4579 hash_realdev_vid(realdev_ofp_port, vid));
4581 VLOG_ERR("duplicate vlan device record");
4583 ovs_mutex_unlock(&ofproto->vsp_mutex);
4587 ofp_port_to_odp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
4589 const struct ofport_dpif *ofport = get_ofp_port(ofproto, ofp_port);
4590 return ofport ? ofport->odp_port : ODPP_NONE;
4593 struct ofport_dpif *
4594 odp_port_to_ofport(const struct dpif_backer *backer, odp_port_t odp_port)
4596 struct ofport_dpif *port;
4598 ovs_rwlock_rdlock(&backer->odp_to_ofport_lock);
4599 HMAP_FOR_EACH_IN_BUCKET (port, odp_port_node, hash_odp_port(odp_port),
4600 &backer->odp_to_ofport_map) {
4601 if (port->odp_port == odp_port) {
4602 ovs_rwlock_unlock(&backer->odp_to_ofport_lock);
4607 ovs_rwlock_unlock(&backer->odp_to_ofport_lock);
4612 odp_port_to_ofp_port(const struct ofproto_dpif *ofproto, odp_port_t odp_port)
4614 struct ofport_dpif *port;
4616 port = odp_port_to_ofport(ofproto->backer, odp_port);
4617 if (port && &ofproto->up == port->up.ofproto) {
4618 return port->up.ofp_port;
4625 ofproto_dpif_alloc_recirc_id(struct ofproto_dpif *ofproto)
4627 struct dpif_backer *backer = ofproto->backer;
4629 return recirc_id_alloc(backer->rid_pool);
4633 ofproto_dpif_free_recirc_id(struct ofproto_dpif *ofproto, uint32_t recirc_id)
4635 struct dpif_backer *backer = ofproto->backer;
4637 recirc_id_free(backer->rid_pool, recirc_id);
4640 const struct ofproto_class ofproto_dpif_class = {
4654 NULL, /* get_memory_usage. */
4655 type_get_memory_usage,
4674 port_is_lacp_current,
4675 NULL, /* rule_choose_table */
4684 rule_modify_actions,
4698 get_stp_port_status,
4706 is_mirror_output_bundle,
4707 forward_bpdu_changed,
4708 set_mac_table_config,
4710 NULL, /* meter_get_features */
4711 NULL, /* meter_set */
4712 NULL, /* meter_get */
4713 NULL, /* meter_del */
4714 group_alloc, /* group_alloc */
4715 group_construct, /* group_construct */
4716 group_destruct, /* group_destruct */
4717 group_dealloc, /* group_dealloc */
4718 group_modify, /* group_modify */
4719 group_get_stats, /* group_get_stats */