2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "ofproto/ofproto-dpif.h"
20 #include "ofproto/ofproto-provider.h"
27 #include "byte-order.h"
28 #include "connectivity.h"
33 #include "dynamic-string.h"
34 #include "fail-open.h"
35 #include "guarded-list.h"
39 #include "mac-learning.h"
40 #include "mcast-snooping.h"
41 #include "meta-flow.h"
42 #include "multipath.h"
43 #include "netdev-vport.h"
48 #include "odp-execute.h"
51 #include "ofp-actions.h"
52 #include "ofp-parse.h"
53 #include "ofp-print.h"
54 #include "ofproto-dpif-ipfix.h"
55 #include "ofproto-dpif-mirror.h"
56 #include "ofproto-dpif-monitor.h"
57 #include "ofproto-dpif-rid.h"
58 #include "ofproto-dpif-sflow.h"
59 #include "ofproto-dpif-upcall.h"
60 #include "ofproto-dpif-xlate.h"
61 #include "poll-loop.h"
67 #include "unaligned.h"
69 #include "vlan-bitmap.h"
72 VLOG_DEFINE_THIS_MODULE(ofproto_dpif
);
74 COVERAGE_DEFINE(ofproto_dpif_expired
);
75 COVERAGE_DEFINE(packet_in_overflow
);
84 * - Do include packets and bytes from datapath flows which have not
85 * recently been processed by a revalidator. */
86 struct ovs_mutex stats_mutex
;
87 struct dpif_flow_stats stats OVS_GUARDED
;
89 /* If non-zero then the recirculation id that has
90 * been allocated for use with this rule.
91 * The recirculation id and associated internal flow should
92 * be freed when the rule is freed */
96 /* RULE_CAST() depends on this. */
97 BUILD_ASSERT_DECL(offsetof(struct rule_dpif
, up
) == 0);
99 static void rule_get_stats(struct rule
*, uint64_t *packets
, uint64_t *bytes
,
100 long long int *used
);
101 static struct rule_dpif
*rule_dpif_cast(const struct rule
*);
102 static void rule_expire(struct rule_dpif
*);
109 * - Do include packets and bytes from datapath flows which have not
110 * recently been processed by a revalidator. */
111 struct ovs_mutex stats_mutex
;
112 uint64_t packet_count OVS_GUARDED
; /* Number of packets received. */
113 uint64_t byte_count OVS_GUARDED
; /* Number of bytes received. */
117 struct hmap_node hmap_node
; /* In struct ofproto's "bundles" hmap. */
118 struct ofproto_dpif
*ofproto
; /* Owning ofproto. */
119 void *aux
; /* Key supplied by ofproto's client. */
120 char *name
; /* Identifier for log messages. */
123 struct list ports
; /* Contains "struct ofport"s. */
124 enum port_vlan_mode vlan_mode
; /* VLAN mode */
125 int vlan
; /* -1=trunk port, else a 12-bit VLAN ID. */
126 unsigned long *trunks
; /* Bitmap of trunked VLANs, if 'vlan' == -1.
127 * NULL if all VLANs are trunked. */
128 struct lacp
*lacp
; /* LACP if LACP is enabled, otherwise NULL. */
129 struct bond
*bond
; /* Nonnull iff more than one port. */
130 bool use_priority_tags
; /* Use 802.1p tag for frames in VLAN 0? */
133 bool floodable
; /* True if no port has OFPUTIL_PC_NO_FLOOD set. */
136 static void bundle_remove(struct ofport
*);
137 static void bundle_update(struct ofbundle
*);
138 static void bundle_destroy(struct ofbundle
*);
139 static void bundle_del_port(struct ofport_dpif
*);
140 static void bundle_run(struct ofbundle
*);
141 static void bundle_wait(struct ofbundle
*);
143 static void stp_run(struct ofproto_dpif
*ofproto
);
144 static void stp_wait(struct ofproto_dpif
*ofproto
);
145 static int set_stp_port(struct ofport
*,
146 const struct ofproto_port_stp_settings
*);
149 struct hmap_node odp_port_node
; /* In dpif_backer's "odp_to_ofport_map". */
153 struct ofbundle
*bundle
; /* Bundle that contains this port, if any. */
154 struct list bundle_node
; /* In struct ofbundle's "ports" list. */
155 struct cfm
*cfm
; /* Connectivity Fault Management, if any. */
156 struct bfd
*bfd
; /* BFD, if any. */
157 bool may_enable
; /* May be enabled in bonds. */
158 bool is_tunnel
; /* This port is a tunnel. */
159 bool is_layer3
; /* This is a layer 3 port. */
160 long long int carrier_seq
; /* Carrier status changes. */
161 struct ofport_dpif
*peer
; /* Peer if patch port. */
164 struct stp_port
*stp_port
; /* Spanning Tree Protocol, if any. */
165 enum stp_state stp_state
; /* Always STP_DISABLED if STP not in use. */
166 long long int stp_state_entered
;
168 /* Queue to DSCP mapping. */
169 struct ofproto_port_queue
*qdscp
;
172 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
174 * This is deprecated. It is only for compatibility with broken device
175 * drivers in old versions of Linux that do not properly support VLANs when
176 * VLAN devices are not used. When broken device drivers are no longer in
177 * widespread use, we will delete these interfaces. */
178 ofp_port_t realdev_ofp_port
;
182 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
184 * This is deprecated. It is only for compatibility with broken device drivers
185 * in old versions of Linux that do not properly support VLANs when VLAN
186 * devices are not used. When broken device drivers are no longer in
187 * widespread use, we will delete these interfaces. */
188 struct vlan_splinter
{
189 struct hmap_node realdev_vid_node
;
190 struct hmap_node vlandev_node
;
191 ofp_port_t realdev_ofp_port
;
192 ofp_port_t vlandev_ofp_port
;
196 static void vsp_remove(struct ofport_dpif
*);
197 static void vsp_add(struct ofport_dpif
*, ofp_port_t realdev_ofp_port
, int vid
);
199 static odp_port_t
ofp_port_to_odp_port(const struct ofproto_dpif
*,
202 static ofp_port_t
odp_port_to_ofp_port(const struct ofproto_dpif
*,
205 static struct ofport_dpif
*
206 ofport_dpif_cast(const struct ofport
*ofport
)
208 return ofport
? CONTAINER_OF(ofport
, struct ofport_dpif
, up
) : NULL
;
211 static void port_run(struct ofport_dpif
*);
212 static int set_bfd(struct ofport
*, const struct smap
*);
213 static int set_cfm(struct ofport
*, const struct cfm_settings
*);
214 static void ofport_update_peer(struct ofport_dpif
*);
216 /* Reasons that we might need to revalidate every datapath flow, and
217 * corresponding coverage counters.
219 * A value of 0 means that there is no need to revalidate.
221 * It would be nice to have some cleaner way to integrate with coverage
222 * counters, but with only a few reasons I guess this is good enough for
224 enum revalidate_reason
{
225 REV_RECONFIGURE
= 1, /* Switch configuration changed. */
226 REV_STP
, /* Spanning tree protocol port status change. */
227 REV_BOND
, /* Bonding changed. */
228 REV_PORT_TOGGLED
, /* Port enabled or disabled by CFM, LACP, ...*/
229 REV_FLOW_TABLE
, /* Flow table changed. */
230 REV_MAC_LEARNING
, /* Mac learning changed. */
231 REV_MCAST_SNOOPING
, /* Multicast snooping 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
);
239 COVERAGE_DEFINE(rev_mcast_snooping
);
241 /* All datapaths of a given type share a single dpif backer instance. */
248 struct ovs_rwlock odp_to_ofport_lock
;
249 struct hmap odp_to_ofport_map OVS_GUARDED
; /* Contains "struct ofport"s. */
251 struct simap tnl_backers
; /* Set of dpif ports backing tunnels. */
253 enum revalidate_reason need_revalidate
; /* Revalidate all flows. */
255 bool recv_set_enable
; /* Enables or disables receiving packets. */
258 struct recirc_id_pool
*rid_pool
; /* Recirculation ID pool. */
259 bool enable_recirc
; /* True if the datapath supports recirculation */
261 /* True if the datapath supports variable-length
262 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions.
263 * False if the datapath supports only 8-byte (or shorter) userdata. */
264 bool variable_length_userdata
;
266 /* Maximum number of MPLS label stack entries that the datapath supports
268 size_t max_mpls_depth
;
271 /* All existing ofproto_backer instances, indexed by ofproto->up.type. */
272 static struct shash all_dpif_backers
= SHASH_INITIALIZER(&all_dpif_backers
);
274 struct ofproto_dpif
{
275 struct hmap_node all_ofproto_dpifs_node
; /* In 'all_ofproto_dpifs'. */
277 struct dpif_backer
*backer
;
279 uint64_t dump_seq
; /* Last read of udpif_dump_seq(). */
281 /* Special OpenFlow rules. */
282 struct rule_dpif
*miss_rule
; /* Sends flow table misses to controller. */
283 struct rule_dpif
*no_packet_in_rule
; /* Drops flow table misses. */
284 struct rule_dpif
*drop_frags_rule
; /* Used in OFPC_FRAG_DROP mode. */
287 struct netflow
*netflow
;
288 struct dpif_sflow
*sflow
;
289 struct dpif_ipfix
*ipfix
;
290 struct hmap bundles
; /* Contains "struct ofbundle"s. */
291 struct mac_learning
*ml
;
292 struct mcast_snooping
*ms
;
293 bool has_bonded_bundles
;
295 struct mbridge
*mbridge
;
297 struct ovs_mutex stats_mutex
;
298 struct netdev_stats stats OVS_GUARDED
; /* To account packets generated and
299 * consumed in userspace. */
303 long long int stp_last_tick
;
305 /* VLAN splinters. */
306 struct ovs_mutex vsp_mutex
;
307 struct hmap realdev_vid_map OVS_GUARDED
; /* (realdev,vid) -> vlandev. */
308 struct hmap vlandev_map OVS_GUARDED
; /* vlandev -> (realdev,vid). */
311 struct sset ports
; /* Set of standard port names. */
312 struct sset ghost_ports
; /* Ports with no datapath port. */
313 struct sset port_poll_set
; /* Queued names for port_poll() reply. */
314 int port_poll_errno
; /* Last errno for port_poll() reply. */
315 uint64_t change_seq
; /* Connectivity status changes. */
318 struct guarded_list pins
; /* Contains "struct ofputil_packet_in"s. */
319 struct seq
*pins_seq
; /* For notifying 'pins' reception. */
323 /* All existing ofproto_dpif instances, indexed by ->up.name. */
324 static struct hmap all_ofproto_dpifs
= HMAP_INITIALIZER(&all_ofproto_dpifs
);
326 static void ofproto_dpif_unixctl_init(void);
328 static inline struct ofproto_dpif
*
329 ofproto_dpif_cast(const struct ofproto
*ofproto
)
331 ovs_assert(ofproto
->ofproto_class
== &ofproto_dpif_class
);
332 return CONTAINER_OF(ofproto
, struct ofproto_dpif
, up
);
336 ofproto_dpif_get_max_mpls_depth(const struct ofproto_dpif
*ofproto
)
338 return ofproto
->backer
->max_mpls_depth
;
342 ofproto_dpif_get_enable_recirc(const struct ofproto_dpif
*ofproto
)
344 return ofproto
->backer
->enable_recirc
;
347 static struct ofport_dpif
*get_ofp_port(const struct ofproto_dpif
*ofproto
,
348 ofp_port_t ofp_port
);
349 static void ofproto_trace(struct ofproto_dpif
*, struct flow
*,
350 const struct ofpbuf
*packet
,
351 const struct ofpact
[], size_t ofpacts_len
,
354 /* Global variables. */
355 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
357 /* Initial mappings of port to bridge mappings. */
358 static struct shash init_ofp_ports
= SHASH_INITIALIZER(&init_ofp_ports
);
360 /* Executes 'fm'. The caller retains ownership of 'fm' and everything in
363 ofproto_dpif_flow_mod(struct ofproto_dpif
*ofproto
,
364 struct ofputil_flow_mod
*fm
)
366 ofproto_flow_mod(&ofproto
->up
, fm
);
369 /* Appends 'pin' to the queue of "packet ins" to be sent to the controller.
370 * Takes ownership of 'pin' and pin->packet. */
372 ofproto_dpif_send_packet_in(struct ofproto_dpif
*ofproto
,
373 struct ofproto_packet_in
*pin
)
375 if (!guarded_list_push_back(&ofproto
->pins
, &pin
->list_node
, 1024)) {
376 COVERAGE_INC(packet_in_overflow
);
377 free(CONST_CAST(void *, pin
->up
.packet
));
381 /* Wakes up main thread for packet-in I/O. */
382 seq_change(ofproto
->pins_seq
);
385 /* The default "table-miss" behaviour for OpenFlow1.3+ is to drop the
386 * packet rather than to send the packet to the controller.
388 * This function returns false to indicate that a packet_in message
389 * for a "table-miss" should be sent to at least one controller.
390 * False otherwise. */
392 ofproto_dpif_wants_packet_in_on_miss(struct ofproto_dpif
*ofproto
)
394 return connmgr_wants_packet_in_on_miss(ofproto
->up
.connmgr
);
397 /* Factory functions. */
400 init(const struct shash
*iface_hints
)
402 struct shash_node
*node
;
404 /* Make a local copy, since we don't own 'iface_hints' elements. */
405 SHASH_FOR_EACH(node
, iface_hints
) {
406 const struct iface_hint
*orig_hint
= node
->data
;
407 struct iface_hint
*new_hint
= xmalloc(sizeof *new_hint
);
409 new_hint
->br_name
= xstrdup(orig_hint
->br_name
);
410 new_hint
->br_type
= xstrdup(orig_hint
->br_type
);
411 new_hint
->ofp_port
= orig_hint
->ofp_port
;
413 shash_add(&init_ofp_ports
, node
->name
, new_hint
);
418 enumerate_types(struct sset
*types
)
420 dp_enumerate_types(types
);
424 enumerate_names(const char *type
, struct sset
*names
)
426 struct ofproto_dpif
*ofproto
;
429 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
430 if (strcmp(type
, ofproto
->up
.type
)) {
433 sset_add(names
, ofproto
->up
.name
);
440 del(const char *type
, const char *name
)
445 error
= dpif_open(name
, type
, &dpif
);
447 error
= dpif_delete(dpif
);
454 port_open_type(const char *datapath_type
, const char *port_type
)
456 return dpif_port_open_type(datapath_type
, port_type
);
459 /* Type functions. */
461 static void process_dpif_port_changes(struct dpif_backer
*);
462 static void process_dpif_all_ports_changed(struct dpif_backer
*);
463 static void process_dpif_port_change(struct dpif_backer
*,
464 const char *devname
);
465 static void process_dpif_port_error(struct dpif_backer
*, int error
);
467 static struct ofproto_dpif
*
468 lookup_ofproto_dpif_by_port_name(const char *name
)
470 struct ofproto_dpif
*ofproto
;
472 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
473 if (sset_contains(&ofproto
->ports
, name
)) {
482 type_run(const char *type
)
484 struct dpif_backer
*backer
;
486 backer
= shash_find_data(&all_dpif_backers
, type
);
488 /* This is not necessarily a problem, since backers are only
489 * created on demand. */
493 dpif_run(backer
->dpif
);
494 udpif_run(backer
->udpif
);
496 /* If vswitchd started with other_config:flow_restore_wait set as "true",
497 * and the configuration has now changed to "false", enable receiving
498 * packets from the datapath. */
499 if (!backer
->recv_set_enable
&& !ofproto_get_flow_restore_wait()) {
502 backer
->recv_set_enable
= true;
504 error
= dpif_recv_set(backer
->dpif
, backer
->recv_set_enable
);
506 VLOG_ERR("Failed to enable receiving packets in dpif.");
509 dpif_flow_flush(backer
->dpif
);
510 backer
->need_revalidate
= REV_RECONFIGURE
;
513 if (backer
->recv_set_enable
) {
514 udpif_set_threads(backer
->udpif
, n_handlers
, n_revalidators
);
517 if (backer
->need_revalidate
) {
518 struct ofproto_dpif
*ofproto
;
519 struct simap_node
*node
;
520 struct simap tmp_backers
;
522 /* Handle tunnel garbage collection. */
523 simap_init(&tmp_backers
);
524 simap_swap(&backer
->tnl_backers
, &tmp_backers
);
526 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
527 struct ofport_dpif
*iter
;
529 if (backer
!= ofproto
->backer
) {
533 HMAP_FOR_EACH (iter
, up
.hmap_node
, &ofproto
->up
.ports
) {
534 char namebuf
[NETDEV_VPORT_NAME_BUFSIZE
];
537 if (!iter
->is_tunnel
) {
541 dp_port
= netdev_vport_get_dpif_port(iter
->up
.netdev
,
542 namebuf
, sizeof namebuf
);
543 node
= simap_find(&tmp_backers
, dp_port
);
545 simap_put(&backer
->tnl_backers
, dp_port
, node
->data
);
546 simap_delete(&tmp_backers
, node
);
547 node
= simap_find(&backer
->tnl_backers
, dp_port
);
549 node
= simap_find(&backer
->tnl_backers
, dp_port
);
551 odp_port_t odp_port
= ODPP_NONE
;
553 if (!dpif_port_add(backer
->dpif
, iter
->up
.netdev
,
555 simap_put(&backer
->tnl_backers
, dp_port
,
556 odp_to_u32(odp_port
));
557 node
= simap_find(&backer
->tnl_backers
, dp_port
);
562 iter
->odp_port
= node
? u32_to_odp(node
->data
) : ODPP_NONE
;
563 if (tnl_port_reconfigure(iter
, iter
->up
.netdev
,
565 backer
->need_revalidate
= REV_RECONFIGURE
;
570 SIMAP_FOR_EACH (node
, &tmp_backers
) {
571 dpif_port_del(backer
->dpif
, u32_to_odp(node
->data
));
573 simap_destroy(&tmp_backers
);
575 switch (backer
->need_revalidate
) {
576 case REV_RECONFIGURE
: COVERAGE_INC(rev_reconfigure
); break;
577 case REV_STP
: COVERAGE_INC(rev_stp
); break;
578 case REV_BOND
: COVERAGE_INC(rev_bond
); break;
579 case REV_PORT_TOGGLED
: COVERAGE_INC(rev_port_toggled
); break;
580 case REV_FLOW_TABLE
: COVERAGE_INC(rev_flow_table
); break;
581 case REV_MAC_LEARNING
: COVERAGE_INC(rev_mac_learning
); break;
582 case REV_MCAST_SNOOPING
: COVERAGE_INC(rev_mcast_snooping
); break;
584 backer
->need_revalidate
= 0;
586 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
587 struct ofport_dpif
*ofport
;
588 struct ofbundle
*bundle
;
590 if (ofproto
->backer
!= backer
) {
595 xlate_ofproto_set(ofproto
, ofproto
->up
.name
,
596 ofproto
->backer
->dpif
, ofproto
->miss_rule
,
597 ofproto
->no_packet_in_rule
, ofproto
->ml
,
598 ofproto
->stp
, ofproto
->ms
, ofproto
->mbridge
,
599 ofproto
->sflow
, ofproto
->ipfix
,
600 ofproto
->netflow
, ofproto
->up
.frag_handling
,
601 ofproto
->up
.forward_bpdu
,
602 connmgr_has_in_band(ofproto
->up
.connmgr
),
603 ofproto
->backer
->enable_recirc
,
604 ofproto
->backer
->variable_length_userdata
,
605 ofproto
->backer
->max_mpls_depth
);
607 HMAP_FOR_EACH (bundle
, hmap_node
, &ofproto
->bundles
) {
608 xlate_bundle_set(ofproto
, bundle
, bundle
->name
,
609 bundle
->vlan_mode
, bundle
->vlan
,
610 bundle
->trunks
, bundle
->use_priority_tags
,
611 bundle
->bond
, bundle
->lacp
,
615 HMAP_FOR_EACH (ofport
, up
.hmap_node
, &ofproto
->up
.ports
) {
616 int stp_port
= ofport
->stp_port
617 ? stp_port_no(ofport
->stp_port
)
619 xlate_ofport_set(ofproto
, ofport
->bundle
, ofport
,
620 ofport
->up
.ofp_port
, ofport
->odp_port
,
621 ofport
->up
.netdev
, ofport
->cfm
,
622 ofport
->bfd
, ofport
->peer
, stp_port
,
623 ofport
->qdscp
, ofport
->n_qdscp
,
624 ofport
->up
.pp
.config
, ofport
->up
.pp
.state
,
625 ofport
->is_tunnel
, ofport
->may_enable
);
630 udpif_revalidate(backer
->udpif
);
633 process_dpif_port_changes(backer
);
638 /* Check for and handle port changes in 'backer''s dpif. */
640 process_dpif_port_changes(struct dpif_backer
*backer
)
646 error
= dpif_port_poll(backer
->dpif
, &devname
);
652 process_dpif_all_ports_changed(backer
);
656 process_dpif_port_change(backer
, devname
);
661 process_dpif_port_error(backer
, error
);
668 process_dpif_all_ports_changed(struct dpif_backer
*backer
)
670 struct ofproto_dpif
*ofproto
;
671 struct dpif_port dpif_port
;
672 struct dpif_port_dump dump
;
673 struct sset devnames
;
676 sset_init(&devnames
);
677 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
678 if (ofproto
->backer
== backer
) {
679 struct ofport
*ofport
;
681 HMAP_FOR_EACH (ofport
, hmap_node
, &ofproto
->up
.ports
) {
682 sset_add(&devnames
, netdev_get_name(ofport
->netdev
));
686 DPIF_PORT_FOR_EACH (&dpif_port
, &dump
, backer
->dpif
) {
687 sset_add(&devnames
, dpif_port
.name
);
690 SSET_FOR_EACH (devname
, &devnames
) {
691 process_dpif_port_change(backer
, devname
);
693 sset_destroy(&devnames
);
697 process_dpif_port_change(struct dpif_backer
*backer
, const char *devname
)
699 struct ofproto_dpif
*ofproto
;
700 struct dpif_port port
;
702 /* Don't report on the datapath's device. */
703 if (!strcmp(devname
, dpif_base_name(backer
->dpif
))) {
707 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
,
708 &all_ofproto_dpifs
) {
709 if (simap_contains(&ofproto
->backer
->tnl_backers
, devname
)) {
714 ofproto
= lookup_ofproto_dpif_by_port_name(devname
);
715 if (dpif_port_query_by_name(backer
->dpif
, devname
, &port
)) {
716 /* The port was removed. If we know the datapath,
717 * report it through poll_set(). If we don't, it may be
718 * notifying us of a removal we initiated, so ignore it.
719 * If there's a pending ENOBUFS, let it stand, since
720 * everything will be reevaluated. */
721 if (ofproto
&& ofproto
->port_poll_errno
!= ENOBUFS
) {
722 sset_add(&ofproto
->port_poll_set
, devname
);
723 ofproto
->port_poll_errno
= 0;
725 } else if (!ofproto
) {
726 /* The port was added, but we don't know with which
727 * ofproto we should associate it. Delete it. */
728 dpif_port_del(backer
->dpif
, port
.port_no
);
730 struct ofport_dpif
*ofport
;
732 ofport
= ofport_dpif_cast(shash_find_data(
733 &ofproto
->up
.port_by_name
, devname
));
735 && ofport
->odp_port
!= port
.port_no
736 && !odp_port_to_ofport(backer
, port
.port_no
))
738 /* 'ofport''s datapath port number has changed from
739 * 'ofport->odp_port' to 'port.port_no'. Update our internal data
740 * structures to match. */
741 ovs_rwlock_wrlock(&backer
->odp_to_ofport_lock
);
742 hmap_remove(&backer
->odp_to_ofport_map
, &ofport
->odp_port_node
);
743 ofport
->odp_port
= port
.port_no
;
744 hmap_insert(&backer
->odp_to_ofport_map
, &ofport
->odp_port_node
,
745 hash_odp_port(port
.port_no
));
746 ovs_rwlock_unlock(&backer
->odp_to_ofport_lock
);
747 backer
->need_revalidate
= REV_RECONFIGURE
;
750 dpif_port_destroy(&port
);
753 /* Propagate 'error' to all ofprotos based on 'backer'. */
755 process_dpif_port_error(struct dpif_backer
*backer
, int error
)
757 struct ofproto_dpif
*ofproto
;
759 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
760 if (ofproto
->backer
== backer
) {
761 sset_clear(&ofproto
->port_poll_set
);
762 ofproto
->port_poll_errno
= error
;
768 type_wait(const char *type
)
770 struct dpif_backer
*backer
;
772 backer
= shash_find_data(&all_dpif_backers
, type
);
774 /* This is not necessarily a problem, since backers are only
775 * created on demand. */
779 dpif_wait(backer
->dpif
);
782 /* Basic life-cycle. */
784 static int add_internal_flows(struct ofproto_dpif
*);
786 static struct ofproto
*
789 struct ofproto_dpif
*ofproto
= xmalloc(sizeof *ofproto
);
794 dealloc(struct ofproto
*ofproto_
)
796 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
801 close_dpif_backer(struct dpif_backer
*backer
)
803 ovs_assert(backer
->refcount
> 0);
805 if (--backer
->refcount
) {
809 udpif_destroy(backer
->udpif
);
811 simap_destroy(&backer
->tnl_backers
);
812 ovs_rwlock_destroy(&backer
->odp_to_ofport_lock
);
813 hmap_destroy(&backer
->odp_to_ofport_map
);
814 shash_find_and_delete(&all_dpif_backers
, backer
->type
);
815 recirc_id_pool_destroy(backer
->rid_pool
);
817 dpif_close(backer
->dpif
);
821 /* Datapath port slated for removal from datapath. */
823 struct list list_node
;
827 static bool check_variable_length_userdata(struct dpif_backer
*backer
);
828 static size_t check_max_mpls_depth(struct dpif_backer
*backer
);
829 static bool check_recirc(struct dpif_backer
*backer
);
832 open_dpif_backer(const char *type
, struct dpif_backer
**backerp
)
834 struct dpif_backer
*backer
;
835 struct dpif_port_dump port_dump
;
836 struct dpif_port port
;
837 struct shash_node
*node
;
838 struct list garbage_list
;
839 struct odp_garbage
*garbage
, *next
;
846 backer
= shash_find_data(&all_dpif_backers
, type
);
853 backer_name
= xasprintf("ovs-%s", type
);
855 /* Remove any existing datapaths, since we assume we're the only
856 * userspace controlling the datapath. */
858 dp_enumerate_names(type
, &names
);
859 SSET_FOR_EACH(name
, &names
) {
860 struct dpif
*old_dpif
;
862 /* Don't remove our backer if it exists. */
863 if (!strcmp(name
, backer_name
)) {
867 if (dpif_open(name
, type
, &old_dpif
)) {
868 VLOG_WARN("couldn't open old datapath %s to remove it", name
);
870 dpif_delete(old_dpif
);
871 dpif_close(old_dpif
);
874 sset_destroy(&names
);
876 backer
= xmalloc(sizeof *backer
);
878 error
= dpif_create_and_open(backer_name
, type
, &backer
->dpif
);
881 VLOG_ERR("failed to open datapath of type %s: %s", type
,
882 ovs_strerror(error
));
886 backer
->udpif
= udpif_create(backer
, backer
->dpif
);
888 backer
->type
= xstrdup(type
);
889 backer
->refcount
= 1;
890 hmap_init(&backer
->odp_to_ofport_map
);
891 ovs_rwlock_init(&backer
->odp_to_ofport_lock
);
892 backer
->need_revalidate
= 0;
893 simap_init(&backer
->tnl_backers
);
894 backer
->recv_set_enable
= !ofproto_get_flow_restore_wait();
897 if (backer
->recv_set_enable
) {
898 dpif_flow_flush(backer
->dpif
);
901 /* Loop through the ports already on the datapath and remove any
902 * that we don't need anymore. */
903 list_init(&garbage_list
);
904 dpif_port_dump_start(&port_dump
, backer
->dpif
);
905 while (dpif_port_dump_next(&port_dump
, &port
)) {
906 node
= shash_find(&init_ofp_ports
, port
.name
);
907 if (!node
&& strcmp(port
.name
, dpif_base_name(backer
->dpif
))) {
908 garbage
= xmalloc(sizeof *garbage
);
909 garbage
->odp_port
= port
.port_no
;
910 list_push_front(&garbage_list
, &garbage
->list_node
);
913 dpif_port_dump_done(&port_dump
);
915 LIST_FOR_EACH_SAFE (garbage
, next
, list_node
, &garbage_list
) {
916 dpif_port_del(backer
->dpif
, garbage
->odp_port
);
917 list_remove(&garbage
->list_node
);
921 shash_add(&all_dpif_backers
, type
, backer
);
923 error
= dpif_recv_set(backer
->dpif
, backer
->recv_set_enable
);
925 VLOG_ERR("failed to listen on datapath of type %s: %s",
926 type
, ovs_strerror(error
));
927 close_dpif_backer(backer
);
930 backer
->enable_recirc
= check_recirc(backer
);
931 backer
->variable_length_userdata
= check_variable_length_userdata(backer
);
932 backer
->max_mpls_depth
= check_max_mpls_depth(backer
);
933 backer
->rid_pool
= recirc_id_pool_create();
935 if (backer
->recv_set_enable
) {
936 udpif_set_threads(backer
->udpif
, n_handlers
, n_revalidators
);
942 /* Tests whether 'backer''s datapath supports recirculation. Only newer
943 * datapaths support OVS_KEY_ATTR_RECIRC_ID in keys. We need to disable some
944 * features on older datapaths that don't support this feature.
946 * Returns false if 'backer' definitely does not support recirculation, true if
947 * it seems to support recirculation or if at least the error we get is
950 check_recirc(struct dpif_backer
*backer
)
953 struct odputil_keybuf keybuf
;
956 bool enable_recirc
= false;
958 memset(&flow
, 0, sizeof flow
);
962 ofpbuf_use_stack(&key
, &keybuf
, sizeof keybuf
);
963 odp_flow_key_from_flow(&key
, &flow
, NULL
, 0, true);
965 error
= dpif_flow_put(backer
->dpif
, DPIF_FP_CREATE
,
966 ofpbuf_data(&key
), ofpbuf_size(&key
), NULL
, 0, NULL
,
968 if (error
&& error
!= EEXIST
) {
969 if (error
!= EINVAL
) {
970 VLOG_WARN("%s: Reciculation flow probe failed (%s)",
971 dpif_name(backer
->dpif
), ovs_strerror(error
));
976 error
= dpif_flow_del(backer
->dpif
, ofpbuf_data(&key
), ofpbuf_size(&key
),
979 VLOG_WARN("%s: failed to delete recirculation feature probe flow",
980 dpif_name(backer
->dpif
));
983 enable_recirc
= true;
987 VLOG_INFO("%s: Datapath supports recirculation",
988 dpif_name(backer
->dpif
));
990 VLOG_INFO("%s: Datapath does not support recirculation",
991 dpif_name(backer
->dpif
));
994 return enable_recirc
;
997 /* Tests whether 'backer''s datapath supports variable-length
998 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. We need
999 * to disable some features on older datapaths that don't support this
1002 * Returns false if 'backer' definitely does not support variable-length
1003 * userdata, true if it seems to support them or if at least the error we get
1006 check_variable_length_userdata(struct dpif_backer
*backer
)
1008 struct eth_header
*eth
;
1009 struct ofpbuf actions
;
1010 struct dpif_execute execute
;
1011 struct ofpbuf packet
;
1015 /* Compose a userspace action that will cause an ERANGE error on older
1016 * datapaths that don't support variable-length userdata.
1018 * We really test for using userdata longer than 8 bytes, but older
1019 * datapaths accepted these, silently truncating the userdata to 8 bytes.
1020 * The same older datapaths rejected userdata shorter than 8 bytes, so we
1021 * test for that instead as a proxy for longer userdata support. */
1022 ofpbuf_init(&actions
, 64);
1023 start
= nl_msg_start_nested(&actions
, OVS_ACTION_ATTR_USERSPACE
);
1024 nl_msg_put_u32(&actions
, OVS_USERSPACE_ATTR_PID
,
1025 dpif_port_get_pid(backer
->dpif
, ODPP_NONE
, 0));
1026 nl_msg_put_unspec_zero(&actions
, OVS_USERSPACE_ATTR_USERDATA
, 4);
1027 nl_msg_end_nested(&actions
, start
);
1029 /* Compose a dummy ethernet packet. */
1030 ofpbuf_init(&packet
, ETH_HEADER_LEN
);
1031 eth
= ofpbuf_put_zeros(&packet
, ETH_HEADER_LEN
);
1032 eth
->eth_type
= htons(0x1234);
1034 /* Execute the actions. On older datapaths this fails with ERANGE, on
1035 * newer datapaths it succeeds. */
1036 execute
.actions
= ofpbuf_data(&actions
);
1037 execute
.actions_len
= ofpbuf_size(&actions
);
1038 execute
.packet
= &packet
;
1039 execute
.md
= PKT_METADATA_INITIALIZER(0);
1040 execute
.needs_help
= false;
1042 error
= dpif_execute(backer
->dpif
, &execute
);
1044 ofpbuf_uninit(&packet
);
1045 ofpbuf_uninit(&actions
);
1049 /* Variable-length userdata is supported.
1051 * Purge received packets to avoid processing the nonsense packet we
1052 * sent to userspace, then report success. */
1053 dpif_recv_purge(backer
->dpif
);
1057 /* Variable-length userdata is not supported. */
1058 VLOG_WARN("%s: datapath does not support variable-length userdata "
1059 "feature (needs Linux 3.10+ or kernel module from OVS "
1060 "1..11+). The NXAST_SAMPLE action will be ignored.",
1061 dpif_name(backer
->dpif
));
1065 /* Something odd happened. We're not sure whether variable-length
1066 * userdata is supported. Default to "yes". */
1067 VLOG_WARN("%s: variable-length userdata feature probe failed (%s)",
1068 dpif_name(backer
->dpif
), ovs_strerror(error
));
1073 /* Tests the MPLS label stack depth supported by 'backer''s datapath.
1075 * Returns the number of elements in a struct flow's mpls_lse field
1076 * if the datapath supports at least that many entries in an
1078 * Otherwise returns the number of MPLS push actions supported by
1081 check_max_mpls_depth(struct dpif_backer
*backer
)
1086 for (n
= 0; n
< FLOW_MAX_MPLS_LABELS
; n
++) {
1087 struct odputil_keybuf keybuf
;
1091 memset(&flow
, 0, sizeof flow
);
1092 flow
.dl_type
= htons(ETH_TYPE_MPLS
);
1093 flow_set_mpls_bos(&flow
, n
, 1);
1095 ofpbuf_use_stack(&key
, &keybuf
, sizeof keybuf
);
1096 odp_flow_key_from_flow(&key
, &flow
, NULL
, 0, false);
1098 error
= dpif_flow_put(backer
->dpif
, DPIF_FP_CREATE
,
1099 ofpbuf_data(&key
), ofpbuf_size(&key
), NULL
, 0, NULL
, 0, NULL
);
1100 if (error
&& error
!= EEXIST
) {
1101 if (error
!= EINVAL
) {
1102 VLOG_WARN("%s: MPLS stack length feature probe failed (%s)",
1103 dpif_name(backer
->dpif
), ovs_strerror(error
));
1108 error
= dpif_flow_del(backer
->dpif
, ofpbuf_data(&key
), ofpbuf_size(&key
), NULL
);
1110 VLOG_WARN("%s: failed to delete MPLS feature probe flow",
1111 dpif_name(backer
->dpif
));
1115 VLOG_INFO("%s: MPLS label stack length probed as %d",
1116 dpif_name(backer
->dpif
), n
);
1121 construct(struct ofproto
*ofproto_
)
1123 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1124 struct shash_node
*node
, *next
;
1127 error
= open_dpif_backer(ofproto
->up
.type
, &ofproto
->backer
);
1132 ofproto
->netflow
= NULL
;
1133 ofproto
->sflow
= NULL
;
1134 ofproto
->ipfix
= NULL
;
1135 ofproto
->stp
= NULL
;
1136 ofproto
->dump_seq
= 0;
1137 hmap_init(&ofproto
->bundles
);
1138 ofproto
->ml
= mac_learning_create(MAC_ENTRY_DEFAULT_IDLE_TIME
);
1140 ofproto
->mbridge
= mbridge_create();
1141 ofproto
->has_bonded_bundles
= false;
1142 ofproto
->lacp_enabled
= false;
1143 ovs_mutex_init_adaptive(&ofproto
->stats_mutex
);
1144 ovs_mutex_init(&ofproto
->vsp_mutex
);
1146 guarded_list_init(&ofproto
->pins
);
1148 ofproto_dpif_unixctl_init();
1150 hmap_init(&ofproto
->vlandev_map
);
1151 hmap_init(&ofproto
->realdev_vid_map
);
1153 sset_init(&ofproto
->ports
);
1154 sset_init(&ofproto
->ghost_ports
);
1155 sset_init(&ofproto
->port_poll_set
);
1156 ofproto
->port_poll_errno
= 0;
1157 ofproto
->change_seq
= 0;
1158 ofproto
->pins_seq
= seq_create();
1159 ofproto
->pins_seqno
= seq_read(ofproto
->pins_seq
);
1162 SHASH_FOR_EACH_SAFE (node
, next
, &init_ofp_ports
) {
1163 struct iface_hint
*iface_hint
= node
->data
;
1165 if (!strcmp(iface_hint
->br_name
, ofproto
->up
.name
)) {
1166 /* Check if the datapath already has this port. */
1167 if (dpif_port_exists(ofproto
->backer
->dpif
, node
->name
)) {
1168 sset_add(&ofproto
->ports
, node
->name
);
1171 free(iface_hint
->br_name
);
1172 free(iface_hint
->br_type
);
1174 shash_delete(&init_ofp_ports
, node
);
1178 hmap_insert(&all_ofproto_dpifs
, &ofproto
->all_ofproto_dpifs_node
,
1179 hash_string(ofproto
->up
.name
, 0));
1180 memset(&ofproto
->stats
, 0, sizeof ofproto
->stats
);
1182 ofproto_init_tables(ofproto_
, N_TABLES
);
1183 error
= add_internal_flows(ofproto
);
1185 ofproto
->up
.tables
[TBL_INTERNAL
].flags
= OFTABLE_HIDDEN
| OFTABLE_READONLY
;
1191 add_internal_miss_flow(struct ofproto_dpif
*ofproto
, int id
,
1192 const struct ofpbuf
*ofpacts
, struct rule_dpif
**rulep
)
1198 match_init_catchall(&match
);
1199 match_set_reg(&match
, 0, id
);
1201 error
= ofproto_dpif_add_internal_flow(ofproto
, &match
, 0, 0, ofpacts
,
1203 *rulep
= error
? NULL
: rule_dpif_cast(rule
);
1209 add_internal_flows(struct ofproto_dpif
*ofproto
)
1211 struct ofpact_controller
*controller
;
1212 uint64_t ofpacts_stub
[128 / 8];
1213 struct ofpbuf ofpacts
;
1214 struct rule
*unused_rulep OVS_UNUSED
;
1215 struct ofpact_resubmit
*resubmit
;
1220 ofpbuf_use_stack(&ofpacts
, ofpacts_stub
, sizeof ofpacts_stub
);
1223 controller
= ofpact_put_CONTROLLER(&ofpacts
);
1224 controller
->max_len
= UINT16_MAX
;
1225 controller
->controller_id
= 0;
1226 controller
->reason
= OFPR_NO_MATCH
;
1227 ofpact_pad(&ofpacts
);
1229 error
= add_internal_miss_flow(ofproto
, id
++, &ofpacts
,
1230 &ofproto
->miss_rule
);
1235 ofpbuf_clear(&ofpacts
);
1236 error
= add_internal_miss_flow(ofproto
, id
++, &ofpacts
,
1237 &ofproto
->no_packet_in_rule
);
1242 error
= add_internal_miss_flow(ofproto
, id
++, &ofpacts
,
1243 &ofproto
->drop_frags_rule
);
1248 /* Continue non-recirculation rule lookups from table 0.
1250 * (priority=2), recirc=0, actions=resubmit(, 0)
1252 resubmit
= ofpact_put_RESUBMIT(&ofpacts
);
1253 resubmit
->ofpact
.compat
= 0;
1254 resubmit
->in_port
= OFPP_IN_PORT
;
1255 resubmit
->table_id
= 0;
1257 match_init_catchall(&match
);
1258 match_set_recirc_id(&match
, 0);
1260 error
= ofproto_dpif_add_internal_flow(ofproto
, &match
, 2, 0, &ofpacts
,
1266 /* Drop any run away recirc rule lookups. Recirc_id has to be
1267 * non-zero when reaching this rule.
1269 * (priority=1), *, actions=drop
1271 ofpbuf_clear(&ofpacts
);
1272 match_init_catchall(&match
);
1273 error
= ofproto_dpif_add_internal_flow(ofproto
, &match
, 1, 0, &ofpacts
,
1280 destruct(struct ofproto
*ofproto_
)
1282 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1283 struct ofproto_packet_in
*pin
, *next_pin
;
1284 struct rule_dpif
*rule
;
1285 struct oftable
*table
;
1288 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1290 xlate_remove_ofproto(ofproto
);
1293 /* Ensure that the upcall processing threads have no remaining references
1294 * to the ofproto or anything in it. */
1295 udpif_synchronize(ofproto
->backer
->udpif
);
1297 hmap_remove(&all_ofproto_dpifs
, &ofproto
->all_ofproto_dpifs_node
);
1299 OFPROTO_FOR_EACH_TABLE (table
, &ofproto
->up
) {
1300 CLS_FOR_EACH_SAFE (rule
, up
.cr
, &table
->cls
) {
1301 ofproto_rule_delete(&ofproto
->up
, &rule
->up
);
1305 guarded_list_pop_all(&ofproto
->pins
, &pins
);
1306 LIST_FOR_EACH_SAFE (pin
, next_pin
, list_node
, &pins
) {
1307 list_remove(&pin
->list_node
);
1308 free(CONST_CAST(void *, pin
->up
.packet
));
1311 guarded_list_destroy(&ofproto
->pins
);
1313 mbridge_unref(ofproto
->mbridge
);
1315 netflow_unref(ofproto
->netflow
);
1316 dpif_sflow_unref(ofproto
->sflow
);
1317 hmap_destroy(&ofproto
->bundles
);
1318 mac_learning_unref(ofproto
->ml
);
1319 mcast_snooping_unref(ofproto
->ms
);
1321 hmap_destroy(&ofproto
->vlandev_map
);
1322 hmap_destroy(&ofproto
->realdev_vid_map
);
1324 sset_destroy(&ofproto
->ports
);
1325 sset_destroy(&ofproto
->ghost_ports
);
1326 sset_destroy(&ofproto
->port_poll_set
);
1328 ovs_mutex_destroy(&ofproto
->stats_mutex
);
1329 ovs_mutex_destroy(&ofproto
->vsp_mutex
);
1331 seq_destroy(ofproto
->pins_seq
);
1333 close_dpif_backer(ofproto
->backer
);
1337 run(struct ofproto
*ofproto_
)
1339 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1340 uint64_t new_seq
, new_dump_seq
;
1342 if (mbridge_need_revalidate(ofproto
->mbridge
)) {
1343 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1344 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
1345 mac_learning_flush(ofproto
->ml
);
1346 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
1347 mcast_snooping_mdb_flush(ofproto
->ms
);
1350 /* Always updates the ofproto->pins_seqno to avoid frequent wakeup during
1351 * flow restore. Even though nothing is processed during flow restore,
1352 * all queued 'pins' will be handled immediately when flow restore
1354 ofproto
->pins_seqno
= seq_read(ofproto
->pins_seq
);
1356 /* Do not perform any periodic activity required by 'ofproto' while
1357 * waiting for flow restore to complete. */
1358 if (!ofproto_get_flow_restore_wait()) {
1359 struct ofproto_packet_in
*pin
, *next_pin
;
1362 guarded_list_pop_all(&ofproto
->pins
, &pins
);
1363 LIST_FOR_EACH_SAFE (pin
, next_pin
, list_node
, &pins
) {
1364 connmgr_send_packet_in(ofproto
->up
.connmgr
, pin
);
1365 list_remove(&pin
->list_node
);
1366 free(CONST_CAST(void *, pin
->up
.packet
));
1371 if (ofproto
->netflow
) {
1372 netflow_run(ofproto
->netflow
);
1374 if (ofproto
->sflow
) {
1375 dpif_sflow_run(ofproto
->sflow
);
1377 if (ofproto
->ipfix
) {
1378 dpif_ipfix_run(ofproto
->ipfix
);
1381 new_seq
= seq_read(connectivity_seq_get());
1382 if (ofproto
->change_seq
!= new_seq
) {
1383 struct ofport_dpif
*ofport
;
1385 HMAP_FOR_EACH (ofport
, up
.hmap_node
, &ofproto
->up
.ports
) {
1389 ofproto
->change_seq
= new_seq
;
1391 if (ofproto
->lacp_enabled
|| ofproto
->has_bonded_bundles
) {
1392 struct ofbundle
*bundle
;
1394 HMAP_FOR_EACH (bundle
, hmap_node
, &ofproto
->bundles
) {
1400 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
1401 if (mac_learning_run(ofproto
->ml
)) {
1402 ofproto
->backer
->need_revalidate
= REV_MAC_LEARNING
;
1404 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
1406 if (mcast_snooping_run(ofproto
->ms
)) {
1407 ofproto
->backer
->need_revalidate
= REV_MCAST_SNOOPING
;
1410 new_dump_seq
= seq_read(udpif_dump_seq(ofproto
->backer
->udpif
));
1411 if (ofproto
->dump_seq
!= new_dump_seq
) {
1412 struct rule
*rule
, *next_rule
;
1414 /* We know stats are relatively fresh, so now is a good time to do some
1416 ofproto
->dump_seq
= new_dump_seq
;
1418 /* Expire OpenFlow flows whose idle_timeout or hard_timeout
1420 ovs_mutex_lock(&ofproto_mutex
);
1421 LIST_FOR_EACH_SAFE (rule
, next_rule
, expirable
,
1422 &ofproto
->up
.expirable
) {
1423 rule_expire(rule_dpif_cast(rule
));
1425 ovs_mutex_unlock(&ofproto_mutex
);
1427 /* All outstanding data in existing flows has been accounted, so it's a
1428 * good time to do bond rebalancing. */
1429 if (ofproto
->has_bonded_bundles
) {
1430 struct ofbundle
*bundle
;
1432 HMAP_FOR_EACH (bundle
, hmap_node
, &ofproto
->bundles
) {
1434 bond_rebalance(bundle
->bond
);
1444 wait(struct ofproto
*ofproto_
)
1446 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1448 if (ofproto_get_flow_restore_wait()) {
1452 if (ofproto
->sflow
) {
1453 dpif_sflow_wait(ofproto
->sflow
);
1455 if (ofproto
->ipfix
) {
1456 dpif_ipfix_wait(ofproto
->ipfix
);
1458 if (ofproto
->lacp_enabled
|| ofproto
->has_bonded_bundles
) {
1459 struct ofbundle
*bundle
;
1461 HMAP_FOR_EACH (bundle
, hmap_node
, &ofproto
->bundles
) {
1462 bundle_wait(bundle
);
1465 if (ofproto
->netflow
) {
1466 netflow_wait(ofproto
->netflow
);
1468 ovs_rwlock_rdlock(&ofproto
->ml
->rwlock
);
1469 mac_learning_wait(ofproto
->ml
);
1470 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
1471 mcast_snooping_wait(ofproto
->ms
);
1473 if (ofproto
->backer
->need_revalidate
) {
1474 /* Shouldn't happen, but if it does just go around again. */
1475 VLOG_DBG_RL(&rl
, "need revalidate in ofproto_wait_cb()");
1476 poll_immediate_wake();
1479 seq_wait(udpif_dump_seq(ofproto
->backer
->udpif
), ofproto
->dump_seq
);
1480 seq_wait(ofproto
->pins_seq
, ofproto
->pins_seqno
);
1484 type_get_memory_usage(const char *type
, struct simap
*usage
)
1486 struct dpif_backer
*backer
;
1488 backer
= shash_find_data(&all_dpif_backers
, type
);
1490 udpif_get_memory_usage(backer
->udpif
, usage
);
1495 flush(struct ofproto
*ofproto_
)
1497 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1498 struct dpif_backer
*backer
= ofproto
->backer
;
1501 udpif_flush(backer
->udpif
);
1506 get_features(struct ofproto
*ofproto_ OVS_UNUSED
,
1507 bool *arp_match_ip
, enum ofputil_action_bitmap
*actions
)
1509 *arp_match_ip
= true;
1510 *actions
= (OFPUTIL_A_OUTPUT
|
1511 OFPUTIL_A_SET_VLAN_VID
|
1512 OFPUTIL_A_SET_VLAN_PCP
|
1513 OFPUTIL_A_STRIP_VLAN
|
1514 OFPUTIL_A_SET_DL_SRC
|
1515 OFPUTIL_A_SET_DL_DST
|
1516 OFPUTIL_A_SET_NW_SRC
|
1517 OFPUTIL_A_SET_NW_DST
|
1518 OFPUTIL_A_SET_NW_TOS
|
1519 OFPUTIL_A_SET_TP_SRC
|
1520 OFPUTIL_A_SET_TP_DST
|
1525 get_tables(struct ofproto
*ofproto
, struct ofp12_table_stats
*ots
)
1529 strcpy(ots
->name
, "classifier");
1531 for (i
= 0; i
< ofproto
->n_tables
; i
++) {
1532 unsigned long missed
, matched
;
1534 atomic_read(&ofproto
->tables
[i
].n_matched
, &matched
);
1535 ots
[i
].matched_count
= htonll(matched
);
1536 atomic_read(&ofproto
->tables
[i
].n_missed
, &missed
);
1537 ots
[i
].lookup_count
= htonll(matched
+ missed
);
1541 static struct ofport
*
1544 struct ofport_dpif
*port
= xmalloc(sizeof *port
);
1549 port_dealloc(struct ofport
*port_
)
1551 struct ofport_dpif
*port
= ofport_dpif_cast(port_
);
1556 port_construct(struct ofport
*port_
)
1558 struct ofport_dpif
*port
= ofport_dpif_cast(port_
);
1559 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(port
->up
.ofproto
);
1560 const struct netdev
*netdev
= port
->up
.netdev
;
1561 char namebuf
[NETDEV_VPORT_NAME_BUFSIZE
];
1562 struct dpif_port dpif_port
;
1565 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1566 port
->bundle
= NULL
;
1569 port
->may_enable
= true;
1570 port
->stp_port
= NULL
;
1571 port
->stp_state
= STP_DISABLED
;
1572 port
->is_tunnel
= false;
1576 port
->realdev_ofp_port
= 0;
1577 port
->vlandev_vid
= 0;
1578 port
->carrier_seq
= netdev_get_carrier_resets(netdev
);
1579 port
->is_layer3
= netdev_vport_is_layer3(netdev
);
1581 if (netdev_vport_is_patch(netdev
)) {
1582 /* By bailing out here, we don't submit the port to the sFlow module
1583 * to be considered for counter polling export. This is correct
1584 * because the patch port represents an interface that sFlow considers
1585 * to be "internal" to the switch as a whole, and therefore not an
1586 * candidate for counter polling. */
1587 port
->odp_port
= ODPP_NONE
;
1588 ofport_update_peer(port
);
1592 error
= dpif_port_query_by_name(ofproto
->backer
->dpif
,
1593 netdev_vport_get_dpif_port(netdev
, namebuf
,
1600 port
->odp_port
= dpif_port
.port_no
;
1602 if (netdev_get_tunnel_config(netdev
)) {
1603 tnl_port_add(port
, port
->up
.netdev
, port
->odp_port
);
1604 port
->is_tunnel
= true;
1606 /* Sanity-check that a mapping doesn't already exist. This
1607 * shouldn't happen for non-tunnel ports. */
1608 if (odp_port_to_ofp_port(ofproto
, port
->odp_port
) != OFPP_NONE
) {
1609 VLOG_ERR("port %s already has an OpenFlow port number",
1611 dpif_port_destroy(&dpif_port
);
1615 ovs_rwlock_wrlock(&ofproto
->backer
->odp_to_ofport_lock
);
1616 hmap_insert(&ofproto
->backer
->odp_to_ofport_map
, &port
->odp_port_node
,
1617 hash_odp_port(port
->odp_port
));
1618 ovs_rwlock_unlock(&ofproto
->backer
->odp_to_ofport_lock
);
1620 dpif_port_destroy(&dpif_port
);
1622 if (ofproto
->sflow
) {
1623 dpif_sflow_add_port(ofproto
->sflow
, port_
, port
->odp_port
);
1630 port_destruct(struct ofport
*port_
)
1632 struct ofport_dpif
*port
= ofport_dpif_cast(port_
);
1633 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(port
->up
.ofproto
);
1634 const char *devname
= netdev_get_name(port
->up
.netdev
);
1635 char namebuf
[NETDEV_VPORT_NAME_BUFSIZE
];
1636 const char *dp_port_name
;
1638 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1640 xlate_ofport_remove(port
);
1643 dp_port_name
= netdev_vport_get_dpif_port(port
->up
.netdev
, namebuf
,
1645 if (dpif_port_exists(ofproto
->backer
->dpif
, dp_port_name
)) {
1646 /* The underlying device is still there, so delete it. This
1647 * happens when the ofproto is being destroyed, since the caller
1648 * assumes that removal of attached ports will happen as part of
1650 if (!port
->is_tunnel
) {
1651 dpif_port_del(ofproto
->backer
->dpif
, port
->odp_port
);
1656 port
->peer
->peer
= NULL
;
1660 if (port
->odp_port
!= ODPP_NONE
&& !port
->is_tunnel
) {
1661 ovs_rwlock_wrlock(&ofproto
->backer
->odp_to_ofport_lock
);
1662 hmap_remove(&ofproto
->backer
->odp_to_ofport_map
, &port
->odp_port_node
);
1663 ovs_rwlock_unlock(&ofproto
->backer
->odp_to_ofport_lock
);
1667 sset_find_and_delete(&ofproto
->ports
, devname
);
1668 sset_find_and_delete(&ofproto
->ghost_ports
, devname
);
1669 bundle_remove(port_
);
1670 set_cfm(port_
, NULL
);
1671 set_bfd(port_
, NULL
);
1672 if (port
->stp_port
) {
1673 stp_port_disable(port
->stp_port
);
1675 if (ofproto
->sflow
) {
1676 dpif_sflow_del_port(ofproto
->sflow
, port
->odp_port
);
1683 port_modified(struct ofport
*port_
)
1685 struct ofport_dpif
*port
= ofport_dpif_cast(port_
);
1687 if (port
->bundle
&& port
->bundle
->bond
) {
1688 bond_slave_set_netdev(port
->bundle
->bond
, port
, port
->up
.netdev
);
1692 cfm_set_netdev(port
->cfm
, port
->up
.netdev
);
1696 bfd_set_netdev(port
->bfd
, port
->up
.netdev
);
1699 ofproto_dpif_monitor_port_update(port
, port
->bfd
, port
->cfm
,
1700 port
->up
.pp
.hw_addr
);
1702 if (port
->is_tunnel
&& tnl_port_reconfigure(port
, port
->up
.netdev
,
1704 ofproto_dpif_cast(port
->up
.ofproto
)->backer
->need_revalidate
=
1708 ofport_update_peer(port
);
1712 port_reconfigured(struct ofport
*port_
, enum ofputil_port_config old_config
)
1714 struct ofport_dpif
*port
= ofport_dpif_cast(port_
);
1715 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(port
->up
.ofproto
);
1716 enum ofputil_port_config changed
= old_config
^ port
->up
.pp
.config
;
1718 if (changed
& (OFPUTIL_PC_NO_RECV
| OFPUTIL_PC_NO_RECV_STP
|
1719 OFPUTIL_PC_NO_FWD
| OFPUTIL_PC_NO_FLOOD
|
1720 OFPUTIL_PC_NO_PACKET_IN
)) {
1721 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1723 if (changed
& OFPUTIL_PC_NO_FLOOD
&& port
->bundle
) {
1724 bundle_update(port
->bundle
);
1730 set_sflow(struct ofproto
*ofproto_
,
1731 const struct ofproto_sflow_options
*sflow_options
)
1733 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1734 struct dpif_sflow
*ds
= ofproto
->sflow
;
1736 if (sflow_options
) {
1738 struct ofport_dpif
*ofport
;
1740 ds
= ofproto
->sflow
= dpif_sflow_create();
1741 HMAP_FOR_EACH (ofport
, up
.hmap_node
, &ofproto
->up
.ports
) {
1742 dpif_sflow_add_port(ds
, &ofport
->up
, ofport
->odp_port
);
1744 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1746 dpif_sflow_set_options(ds
, sflow_options
);
1749 dpif_sflow_unref(ds
);
1750 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1751 ofproto
->sflow
= NULL
;
1759 struct ofproto
*ofproto_
,
1760 const struct ofproto_ipfix_bridge_exporter_options
*bridge_exporter_options
,
1761 const struct ofproto_ipfix_flow_exporter_options
*flow_exporters_options
,
1762 size_t n_flow_exporters_options
)
1764 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1765 struct dpif_ipfix
*di
= ofproto
->ipfix
;
1766 bool has_options
= bridge_exporter_options
|| flow_exporters_options
;
1768 if (has_options
&& !di
) {
1769 di
= ofproto
->ipfix
= dpif_ipfix_create();
1773 /* Call set_options in any case to cleanly flush the flow
1774 * caches in the last exporters that are to be destroyed. */
1775 dpif_ipfix_set_options(
1776 di
, bridge_exporter_options
, flow_exporters_options
,
1777 n_flow_exporters_options
);
1780 dpif_ipfix_unref(di
);
1781 ofproto
->ipfix
= NULL
;
1789 set_cfm(struct ofport
*ofport_
, const struct cfm_settings
*s
)
1791 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
1796 struct ofproto_dpif
*ofproto
;
1798 ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
1799 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1800 ofport
->cfm
= cfm_create(ofport
->up
.netdev
);
1803 if (cfm_configure(ofport
->cfm
, s
)) {
1810 cfm_unref(ofport
->cfm
);
1813 ofproto_dpif_monitor_port_update(ofport
, ofport
->bfd
, ofport
->cfm
,
1814 ofport
->up
.pp
.hw_addr
);
1819 cfm_status_changed(struct ofport
*ofport_
)
1821 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
1823 return ofport
->cfm
? cfm_check_status_change(ofport
->cfm
) : true;
1827 get_cfm_status(const struct ofport
*ofport_
,
1828 struct cfm_status
*status
)
1830 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
1834 cfm_get_status(ofport
->cfm
, status
);
1843 set_bfd(struct ofport
*ofport_
, const struct smap
*cfg
)
1845 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport_
->ofproto
);
1846 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
1850 ofport
->bfd
= bfd_configure(old
, netdev_get_name(ofport
->up
.netdev
),
1851 cfg
, ofport
->up
.netdev
);
1852 if (ofport
->bfd
!= old
) {
1853 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1855 ofproto_dpif_monitor_port_update(ofport
, ofport
->bfd
, ofport
->cfm
,
1856 ofport
->up
.pp
.hw_addr
);
1861 bfd_status_changed(struct ofport
*ofport_
)
1863 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
1865 return ofport
->bfd
? bfd_check_status_change(ofport
->bfd
) : true;
1869 get_bfd_status(struct ofport
*ofport_
, struct smap
*smap
)
1871 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
1875 bfd_get_status(ofport
->bfd
, smap
);
1883 /* Spanning Tree. */
1886 send_bpdu_cb(struct ofpbuf
*pkt
, int port_num
, void *ofproto_
)
1888 struct ofproto_dpif
*ofproto
= ofproto_
;
1889 struct stp_port
*sp
= stp_get_port(ofproto
->stp
, port_num
);
1890 struct ofport_dpif
*ofport
;
1892 ofport
= stp_port_get_aux(sp
);
1894 VLOG_WARN_RL(&rl
, "%s: cannot send BPDU on unknown port %d",
1895 ofproto
->up
.name
, port_num
);
1897 struct eth_header
*eth
= ofpbuf_l2(pkt
);
1899 netdev_get_etheraddr(ofport
->up
.netdev
, eth
->eth_src
);
1900 if (eth_addr_is_zero(eth
->eth_src
)) {
1901 VLOG_WARN_RL(&rl
, "%s: cannot send BPDU on port %d "
1902 "with unknown MAC", ofproto
->up
.name
, port_num
);
1904 ofproto_dpif_send_packet(ofport
, pkt
);
1910 /* Configures STP on 'ofproto_' using the settings defined in 's'. */
1912 set_stp(struct ofproto
*ofproto_
, const struct ofproto_stp_settings
*s
)
1914 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1916 /* Only revalidate flows if the configuration changed. */
1917 if (!s
!= !ofproto
->stp
) {
1918 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
1922 if (!ofproto
->stp
) {
1923 ofproto
->stp
= stp_create(ofproto_
->name
, s
->system_id
,
1924 send_bpdu_cb
, ofproto
);
1925 ofproto
->stp_last_tick
= time_msec();
1928 stp_set_bridge_id(ofproto
->stp
, s
->system_id
);
1929 stp_set_bridge_priority(ofproto
->stp
, s
->priority
);
1930 stp_set_hello_time(ofproto
->stp
, s
->hello_time
);
1931 stp_set_max_age(ofproto
->stp
, s
->max_age
);
1932 stp_set_forward_delay(ofproto
->stp
, s
->fwd_delay
);
1934 struct ofport
*ofport
;
1936 HMAP_FOR_EACH (ofport
, hmap_node
, &ofproto
->up
.ports
) {
1937 set_stp_port(ofport
, NULL
);
1940 stp_unref(ofproto
->stp
);
1941 ofproto
->stp
= NULL
;
1948 get_stp_status(struct ofproto
*ofproto_
, struct ofproto_stp_status
*s
)
1950 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
1954 s
->bridge_id
= stp_get_bridge_id(ofproto
->stp
);
1955 s
->designated_root
= stp_get_designated_root(ofproto
->stp
);
1956 s
->root_path_cost
= stp_get_root_path_cost(ofproto
->stp
);
1965 update_stp_port_state(struct ofport_dpif
*ofport
)
1967 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
1968 enum stp_state state
;
1970 /* Figure out new state. */
1971 state
= ofport
->stp_port
? stp_port_get_state(ofport
->stp_port
)
1975 if (ofport
->stp_state
!= state
) {
1976 enum ofputil_port_state of_state
;
1979 VLOG_DBG_RL(&rl
, "port %s: STP state changed from %s to %s",
1980 netdev_get_name(ofport
->up
.netdev
),
1981 stp_state_name(ofport
->stp_state
),
1982 stp_state_name(state
));
1983 if (stp_learn_in_state(ofport
->stp_state
)
1984 != stp_learn_in_state(state
)) {
1985 /* xxx Learning action flows should also be flushed. */
1986 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
1987 mac_learning_flush(ofproto
->ml
);
1988 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
1989 mcast_snooping_mdb_flush(ofproto
->ms
);
1991 fwd_change
= stp_forward_in_state(ofport
->stp_state
)
1992 != stp_forward_in_state(state
);
1994 ofproto
->backer
->need_revalidate
= REV_STP
;
1995 ofport
->stp_state
= state
;
1996 ofport
->stp_state_entered
= time_msec();
1998 if (fwd_change
&& ofport
->bundle
) {
1999 bundle_update(ofport
->bundle
);
2002 /* Update the STP state bits in the OpenFlow port description. */
2003 of_state
= ofport
->up
.pp
.state
& ~OFPUTIL_PS_STP_MASK
;
2004 of_state
|= (state
== STP_LISTENING
? OFPUTIL_PS_STP_LISTEN
2005 : state
== STP_LEARNING
? OFPUTIL_PS_STP_LEARN
2006 : state
== STP_FORWARDING
? OFPUTIL_PS_STP_FORWARD
2007 : state
== STP_BLOCKING
? OFPUTIL_PS_STP_BLOCK
2009 ofproto_port_set_state(&ofport
->up
, of_state
);
2013 /* Configures STP on 'ofport_' using the settings defined in 's'. The
2014 * caller is responsible for assigning STP port numbers and ensuring
2015 * there are no duplicates. */
2017 set_stp_port(struct ofport
*ofport_
,
2018 const struct ofproto_port_stp_settings
*s
)
2020 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
2021 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
2022 struct stp_port
*sp
= ofport
->stp_port
;
2024 if (!s
|| !s
->enable
) {
2026 ofport
->stp_port
= NULL
;
2027 stp_port_disable(sp
);
2028 update_stp_port_state(ofport
);
2031 } else if (sp
&& stp_port_no(sp
) != s
->port_num
2032 && ofport
== stp_port_get_aux(sp
)) {
2033 /* The port-id changed, so disable the old one if it's not
2034 * already in use by another port. */
2035 stp_port_disable(sp
);
2038 sp
= ofport
->stp_port
= stp_get_port(ofproto
->stp
, s
->port_num
);
2039 stp_port_enable(sp
);
2041 stp_port_set_name(sp
, netdev_get_name(ofport
->up
.netdev
));
2042 stp_port_set_aux(sp
, ofport
);
2043 stp_port_set_priority(sp
, s
->priority
);
2044 stp_port_set_path_cost(sp
, s
->path_cost
);
2046 update_stp_port_state(ofport
);
2052 get_stp_port_status(struct ofport
*ofport_
,
2053 struct ofproto_port_stp_status
*s
)
2055 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
2056 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
2057 struct stp_port
*sp
= ofport
->stp_port
;
2059 if (!ofproto
->stp
|| !sp
) {
2065 s
->port_id
= stp_port_get_id(sp
);
2066 s
->state
= stp_port_get_state(sp
);
2067 s
->sec_in_state
= (time_msec() - ofport
->stp_state_entered
) / 1000;
2068 s
->role
= stp_port_get_role(sp
);
2074 get_stp_port_stats(struct ofport
*ofport_
,
2075 struct ofproto_port_stp_stats
*s
)
2077 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
2078 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
2079 struct stp_port
*sp
= ofport
->stp_port
;
2081 if (!ofproto
->stp
|| !sp
) {
2087 stp_port_get_counts(sp
, &s
->tx_count
, &s
->rx_count
, &s
->error_count
);
2093 stp_run(struct ofproto_dpif
*ofproto
)
2096 long long int now
= time_msec();
2097 long long int elapsed
= now
- ofproto
->stp_last_tick
;
2098 struct stp_port
*sp
;
2101 stp_tick(ofproto
->stp
, MIN(INT_MAX
, elapsed
));
2102 ofproto
->stp_last_tick
= now
;
2104 while (stp_get_changed_port(ofproto
->stp
, &sp
)) {
2105 struct ofport_dpif
*ofport
= stp_port_get_aux(sp
);
2108 update_stp_port_state(ofport
);
2112 if (stp_check_and_reset_fdb_flush(ofproto
->stp
)) {
2113 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
2114 mac_learning_flush(ofproto
->ml
);
2115 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
2116 mcast_snooping_mdb_flush(ofproto
->ms
);
2122 stp_wait(struct ofproto_dpif
*ofproto
)
2125 poll_timer_wait(1000);
2130 set_queues(struct ofport
*ofport_
, const struct ofproto_port_queue
*qdscp
,
2133 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
2134 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
2136 if (ofport
->n_qdscp
!= n_qdscp
2137 || (n_qdscp
&& memcmp(ofport
->qdscp
, qdscp
,
2138 n_qdscp
* sizeof *qdscp
))) {
2139 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2140 free(ofport
->qdscp
);
2141 ofport
->qdscp
= n_qdscp
2142 ? xmemdup(qdscp
, n_qdscp
* sizeof *qdscp
)
2144 ofport
->n_qdscp
= n_qdscp
;
2152 /* Expires all MAC learning entries associated with 'bundle' and forces its
2153 * ofproto to revalidate every flow.
2155 * Normally MAC learning entries are removed only from the ofproto associated
2156 * with 'bundle', but if 'all_ofprotos' is true, then the MAC learning entries
2157 * are removed from every ofproto. When patch ports and SLB bonds are in use
2158 * and a VM migration happens and the gratuitous ARPs are somehow lost, this
2159 * avoids a MAC_ENTRY_IDLE_TIME delay before the migrated VM can communicate
2160 * with the host from which it migrated. */
2162 bundle_flush_macs(struct ofbundle
*bundle
, bool all_ofprotos
)
2164 struct ofproto_dpif
*ofproto
= bundle
->ofproto
;
2165 struct mac_learning
*ml
= ofproto
->ml
;
2166 struct mac_entry
*mac
, *next_mac
;
2168 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2169 ovs_rwlock_wrlock(&ml
->rwlock
);
2170 LIST_FOR_EACH_SAFE (mac
, next_mac
, lru_node
, &ml
->lrus
) {
2171 if (mac
->port
.p
== bundle
) {
2173 struct ofproto_dpif
*o
;
2175 HMAP_FOR_EACH (o
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
2177 struct mac_entry
*e
;
2179 ovs_rwlock_wrlock(&o
->ml
->rwlock
);
2180 e
= mac_learning_lookup(o
->ml
, mac
->mac
, mac
->vlan
);
2182 mac_learning_expire(o
->ml
, e
);
2184 ovs_rwlock_unlock(&o
->ml
->rwlock
);
2189 mac_learning_expire(ml
, mac
);
2192 ovs_rwlock_unlock(&ml
->rwlock
);
2195 static struct ofbundle
*
2196 bundle_lookup(const struct ofproto_dpif
*ofproto
, void *aux
)
2198 struct ofbundle
*bundle
;
2200 HMAP_FOR_EACH_IN_BUCKET (bundle
, hmap_node
, hash_pointer(aux
, 0),
2201 &ofproto
->bundles
) {
2202 if (bundle
->aux
== aux
) {
2210 bundle_update(struct ofbundle
*bundle
)
2212 struct ofport_dpif
*port
;
2214 bundle
->floodable
= true;
2215 LIST_FOR_EACH (port
, bundle_node
, &bundle
->ports
) {
2216 if (port
->up
.pp
.config
& OFPUTIL_PC_NO_FLOOD
2218 || !stp_forward_in_state(port
->stp_state
)) {
2219 bundle
->floodable
= false;
2226 bundle_del_port(struct ofport_dpif
*port
)
2228 struct ofbundle
*bundle
= port
->bundle
;
2230 bundle
->ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2232 list_remove(&port
->bundle_node
);
2233 port
->bundle
= NULL
;
2236 lacp_slave_unregister(bundle
->lacp
, port
);
2239 bond_slave_unregister(bundle
->bond
, port
);
2242 bundle_update(bundle
);
2246 bundle_add_port(struct ofbundle
*bundle
, ofp_port_t ofp_port
,
2247 struct lacp_slave_settings
*lacp
)
2249 struct ofport_dpif
*port
;
2251 port
= get_ofp_port(bundle
->ofproto
, ofp_port
);
2256 if (port
->bundle
!= bundle
) {
2257 bundle
->ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2259 bundle_remove(&port
->up
);
2262 port
->bundle
= bundle
;
2263 list_push_back(&bundle
->ports
, &port
->bundle_node
);
2264 if (port
->up
.pp
.config
& OFPUTIL_PC_NO_FLOOD
2266 || !stp_forward_in_state(port
->stp_state
)) {
2267 bundle
->floodable
= false;
2271 bundle
->ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2272 lacp_slave_register(bundle
->lacp
, port
, lacp
);
2279 bundle_destroy(struct ofbundle
*bundle
)
2281 struct ofproto_dpif
*ofproto
;
2282 struct ofport_dpif
*port
, *next_port
;
2288 ofproto
= bundle
->ofproto
;
2289 mbridge_unregister_bundle(ofproto
->mbridge
, bundle
->aux
);
2292 xlate_bundle_remove(bundle
);
2295 LIST_FOR_EACH_SAFE (port
, next_port
, bundle_node
, &bundle
->ports
) {
2296 bundle_del_port(port
);
2299 bundle_flush_macs(bundle
, true);
2300 hmap_remove(&ofproto
->bundles
, &bundle
->hmap_node
);
2302 free(bundle
->trunks
);
2303 lacp_unref(bundle
->lacp
);
2304 bond_unref(bundle
->bond
);
2309 bundle_set(struct ofproto
*ofproto_
, void *aux
,
2310 const struct ofproto_bundle_settings
*s
)
2312 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2313 bool need_flush
= false;
2314 struct ofport_dpif
*port
;
2315 struct ofbundle
*bundle
;
2316 unsigned long *trunks
;
2322 bundle_destroy(bundle_lookup(ofproto
, aux
));
2326 ovs_assert(s
->n_slaves
== 1 || s
->bond
!= NULL
);
2327 ovs_assert((s
->lacp
!= NULL
) == (s
->lacp_slaves
!= NULL
));
2329 bundle
= bundle_lookup(ofproto
, aux
);
2331 bundle
= xmalloc(sizeof *bundle
);
2333 bundle
->ofproto
= ofproto
;
2334 hmap_insert(&ofproto
->bundles
, &bundle
->hmap_node
,
2335 hash_pointer(aux
, 0));
2337 bundle
->name
= NULL
;
2339 list_init(&bundle
->ports
);
2340 bundle
->vlan_mode
= PORT_VLAN_TRUNK
;
2342 bundle
->trunks
= NULL
;
2343 bundle
->use_priority_tags
= s
->use_priority_tags
;
2344 bundle
->lacp
= NULL
;
2345 bundle
->bond
= NULL
;
2347 bundle
->floodable
= true;
2348 mbridge_register_bundle(ofproto
->mbridge
, bundle
);
2351 if (!bundle
->name
|| strcmp(s
->name
, bundle
->name
)) {
2353 bundle
->name
= xstrdup(s
->name
);
2358 ofproto
->lacp_enabled
= true;
2359 if (!bundle
->lacp
) {
2360 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2361 bundle
->lacp
= lacp_create();
2363 lacp_configure(bundle
->lacp
, s
->lacp
);
2365 lacp_unref(bundle
->lacp
);
2366 bundle
->lacp
= NULL
;
2369 /* Update set of ports. */
2371 for (i
= 0; i
< s
->n_slaves
; i
++) {
2372 if (!bundle_add_port(bundle
, s
->slaves
[i
],
2373 s
->lacp
? &s
->lacp_slaves
[i
] : NULL
)) {
2377 if (!ok
|| list_size(&bundle
->ports
) != s
->n_slaves
) {
2378 struct ofport_dpif
*next_port
;
2380 LIST_FOR_EACH_SAFE (port
, next_port
, bundle_node
, &bundle
->ports
) {
2381 for (i
= 0; i
< s
->n_slaves
; i
++) {
2382 if (s
->slaves
[i
] == port
->up
.ofp_port
) {
2387 bundle_del_port(port
);
2391 ovs_assert(list_size(&bundle
->ports
) <= s
->n_slaves
);
2393 if (list_is_empty(&bundle
->ports
)) {
2394 bundle_destroy(bundle
);
2398 /* Set VLAN tagging mode */
2399 if (s
->vlan_mode
!= bundle
->vlan_mode
2400 || s
->use_priority_tags
!= bundle
->use_priority_tags
) {
2401 bundle
->vlan_mode
= s
->vlan_mode
;
2402 bundle
->use_priority_tags
= s
->use_priority_tags
;
2407 vlan
= (s
->vlan_mode
== PORT_VLAN_TRUNK
? -1
2408 : s
->vlan
>= 0 && s
->vlan
<= 4095 ? s
->vlan
2410 if (vlan
!= bundle
->vlan
) {
2411 bundle
->vlan
= vlan
;
2415 /* Get trunked VLANs. */
2416 switch (s
->vlan_mode
) {
2417 case PORT_VLAN_ACCESS
:
2421 case PORT_VLAN_TRUNK
:
2422 trunks
= CONST_CAST(unsigned long *, s
->trunks
);
2425 case PORT_VLAN_NATIVE_UNTAGGED
:
2426 case PORT_VLAN_NATIVE_TAGGED
:
2427 if (vlan
!= 0 && (!s
->trunks
2428 || !bitmap_is_set(s
->trunks
, vlan
)
2429 || bitmap_is_set(s
->trunks
, 0))) {
2430 /* Force trunking the native VLAN and prohibit trunking VLAN 0. */
2432 trunks
= bitmap_clone(s
->trunks
, 4096);
2434 trunks
= bitmap_allocate1(4096);
2436 bitmap_set1(trunks
, vlan
);
2437 bitmap_set0(trunks
, 0);
2439 trunks
= CONST_CAST(unsigned long *, s
->trunks
);
2446 if (!vlan_bitmap_equal(trunks
, bundle
->trunks
)) {
2447 free(bundle
->trunks
);
2448 if (trunks
== s
->trunks
) {
2449 bundle
->trunks
= vlan_bitmap_clone(trunks
);
2451 bundle
->trunks
= trunks
;
2456 if (trunks
!= s
->trunks
) {
2461 if (!list_is_short(&bundle
->ports
)) {
2462 bundle
->ofproto
->has_bonded_bundles
= true;
2464 if (bond_reconfigure(bundle
->bond
, s
->bond
)) {
2465 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2468 bundle
->bond
= bond_create(s
->bond
, ofproto
);
2469 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2472 LIST_FOR_EACH (port
, bundle_node
, &bundle
->ports
) {
2473 bond_slave_register(bundle
->bond
, port
,
2474 port
->up
.ofp_port
, port
->up
.netdev
);
2477 bond_unref(bundle
->bond
);
2478 bundle
->bond
= NULL
;
2481 /* If we changed something that would affect MAC learning, un-learn
2482 * everything on this port and force flow revalidation. */
2484 bundle_flush_macs(bundle
, false);
2491 bundle_remove(struct ofport
*port_
)
2493 struct ofport_dpif
*port
= ofport_dpif_cast(port_
);
2494 struct ofbundle
*bundle
= port
->bundle
;
2497 bundle_del_port(port
);
2498 if (list_is_empty(&bundle
->ports
)) {
2499 bundle_destroy(bundle
);
2500 } else if (list_is_short(&bundle
->ports
)) {
2501 bond_unref(bundle
->bond
);
2502 bundle
->bond
= NULL
;
2508 send_pdu_cb(void *port_
, const void *pdu
, size_t pdu_size
)
2510 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 10);
2511 struct ofport_dpif
*port
= port_
;
2512 uint8_t ea
[ETH_ADDR_LEN
];
2515 error
= netdev_get_etheraddr(port
->up
.netdev
, ea
);
2517 struct ofpbuf packet
;
2520 ofpbuf_init(&packet
, 0);
2521 packet_pdu
= eth_compose(&packet
, eth_addr_lacp
, ea
, ETH_TYPE_LACP
,
2523 memcpy(packet_pdu
, pdu
, pdu_size
);
2525 ofproto_dpif_send_packet(port
, &packet
);
2526 ofpbuf_uninit(&packet
);
2528 VLOG_ERR_RL(&rl
, "port %s: cannot obtain Ethernet address of iface "
2529 "%s (%s)", port
->bundle
->name
,
2530 netdev_get_name(port
->up
.netdev
), ovs_strerror(error
));
2535 bundle_send_learning_packets(struct ofbundle
*bundle
)
2537 struct ofproto_dpif
*ofproto
= bundle
->ofproto
;
2538 struct ofpbuf
*learning_packet
;
2539 int error
, n_packets
, n_errors
;
2540 struct mac_entry
*e
;
2541 struct list packets
;
2543 list_init(&packets
);
2544 ovs_rwlock_rdlock(&ofproto
->ml
->rwlock
);
2545 LIST_FOR_EACH (e
, lru_node
, &ofproto
->ml
->lrus
) {
2546 if (e
->port
.p
!= bundle
) {
2549 learning_packet
= bond_compose_learning_packet(bundle
->bond
,
2552 /* Temporarily use 'frame' as a private pointer (see below). */
2553 ovs_assert(learning_packet
->frame
== ofpbuf_data(learning_packet
));
2554 learning_packet
->frame
= port_void
;
2555 list_push_back(&packets
, &learning_packet
->list_node
);
2558 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
2560 error
= n_packets
= n_errors
= 0;
2561 LIST_FOR_EACH (learning_packet
, list_node
, &packets
) {
2563 void *port_void
= learning_packet
->frame
;
2565 /* Restore 'frame'. */
2566 learning_packet
->frame
= ofpbuf_data(learning_packet
);
2567 ret
= ofproto_dpif_send_packet(port_void
, learning_packet
);
2574 ofpbuf_list_delete(&packets
);
2577 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
2578 VLOG_WARN_RL(&rl
, "bond %s: %d errors sending %d gratuitous learning "
2579 "packets, last error was: %s",
2580 bundle
->name
, n_errors
, n_packets
, ovs_strerror(error
));
2582 VLOG_DBG("bond %s: sent %d gratuitous learning packets",
2583 bundle
->name
, n_packets
);
2588 bundle_run(struct ofbundle
*bundle
)
2591 lacp_run(bundle
->lacp
, send_pdu_cb
);
2594 struct ofport_dpif
*port
;
2596 LIST_FOR_EACH (port
, bundle_node
, &bundle
->ports
) {
2597 bond_slave_set_may_enable(bundle
->bond
, port
, port
->may_enable
);
2600 if (bond_run(bundle
->bond
, lacp_status(bundle
->lacp
))) {
2601 bundle
->ofproto
->backer
->need_revalidate
= REV_BOND
;
2604 if (bond_should_send_learning_packets(bundle
->bond
)) {
2605 bundle_send_learning_packets(bundle
);
2611 bundle_wait(struct ofbundle
*bundle
)
2614 lacp_wait(bundle
->lacp
);
2617 bond_wait(bundle
->bond
);
2624 mirror_set__(struct ofproto
*ofproto_
, void *aux
,
2625 const struct ofproto_mirror_settings
*s
)
2627 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2628 struct ofbundle
**srcs
, **dsts
;
2633 mirror_destroy(ofproto
->mbridge
, aux
);
2637 srcs
= xmalloc(s
->n_srcs
* sizeof *srcs
);
2638 dsts
= xmalloc(s
->n_dsts
* sizeof *dsts
);
2640 for (i
= 0; i
< s
->n_srcs
; i
++) {
2641 srcs
[i
] = bundle_lookup(ofproto
, s
->srcs
[i
]);
2644 for (i
= 0; i
< s
->n_dsts
; i
++) {
2645 dsts
[i
] = bundle_lookup(ofproto
, s
->dsts
[i
]);
2648 error
= mirror_set(ofproto
->mbridge
, aux
, s
->name
, srcs
, s
->n_srcs
, dsts
,
2649 s
->n_dsts
, s
->src_vlans
,
2650 bundle_lookup(ofproto
, s
->out_bundle
), s
->out_vlan
);
2657 mirror_get_stats__(struct ofproto
*ofproto
, void *aux
,
2658 uint64_t *packets
, uint64_t *bytes
)
2660 return mirror_get_stats(ofproto_dpif_cast(ofproto
)->mbridge
, aux
, packets
,
2665 set_flood_vlans(struct ofproto
*ofproto_
, unsigned long *flood_vlans
)
2667 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2668 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
2669 if (mac_learning_set_flood_vlans(ofproto
->ml
, flood_vlans
)) {
2670 mac_learning_flush(ofproto
->ml
);
2672 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
2677 is_mirror_output_bundle(const struct ofproto
*ofproto_
, void *aux
)
2679 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2680 struct ofbundle
*bundle
= bundle_lookup(ofproto
, aux
);
2681 return bundle
&& mirror_bundle_out(ofproto
->mbridge
, bundle
) != 0;
2685 forward_bpdu_changed(struct ofproto
*ofproto_
)
2687 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2688 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2692 set_mac_table_config(struct ofproto
*ofproto_
, unsigned int idle_time
,
2695 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2696 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
2697 mac_learning_set_idle_time(ofproto
->ml
, idle_time
);
2698 mac_learning_set_max_entries(ofproto
->ml
, max_entries
);
2699 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
2702 /* Configures multicast snooping on 'ofport' using the settings
2703 * defined in 's'. */
2705 set_mcast_snooping(struct ofproto
*ofproto_
,
2706 const struct ofproto_mcast_snooping_settings
*s
)
2708 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2710 /* Only revalidate flows if the configuration changed. */
2711 if (!s
!= !ofproto
->ms
) {
2712 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2717 ofproto
->ms
= mcast_snooping_create();
2720 ovs_rwlock_wrlock(&ofproto
->ms
->rwlock
);
2721 mcast_snooping_set_idle_time(ofproto
->ms
, s
->idle_time
);
2722 mcast_snooping_set_max_entries(ofproto
->ms
, s
->max_entries
);
2723 if (mcast_snooping_set_flood_unreg(ofproto
->ms
, s
->flood_unreg
)) {
2724 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2726 ovs_rwlock_unlock(&ofproto
->ms
->rwlock
);
2728 mcast_snooping_unref(ofproto
->ms
);
2735 /* Configures multicast snooping port's flood setting on 'ofproto'. */
2737 set_mcast_snooping_port(struct ofproto
*ofproto_
, void *aux
, bool flood
)
2739 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2740 struct ofbundle
*bundle
= bundle_lookup(ofproto
, aux
);
2743 ovs_rwlock_wrlock(&ofproto
->ms
->rwlock
);
2744 mcast_snooping_set_port_flood(ofproto
->ms
, bundle
->vlan
, bundle
,
2746 ovs_rwlock_unlock(&ofproto
->ms
->rwlock
);
2754 static struct ofport_dpif
*
2755 get_ofp_port(const struct ofproto_dpif
*ofproto
, ofp_port_t ofp_port
)
2757 struct ofport
*ofport
= ofproto_get_port(&ofproto
->up
, ofp_port
);
2758 return ofport
? ofport_dpif_cast(ofport
) : NULL
;
2762 ofproto_port_from_dpif_port(struct ofproto_dpif
*ofproto
,
2763 struct ofproto_port
*ofproto_port
,
2764 struct dpif_port
*dpif_port
)
2766 ofproto_port
->name
= dpif_port
->name
;
2767 ofproto_port
->type
= dpif_port
->type
;
2768 ofproto_port
->ofp_port
= odp_port_to_ofp_port(ofproto
, dpif_port
->port_no
);
2772 ofport_update_peer(struct ofport_dpif
*ofport
)
2774 const struct ofproto_dpif
*ofproto
;
2775 struct dpif_backer
*backer
;
2778 if (!netdev_vport_is_patch(ofport
->up
.netdev
)) {
2782 backer
= ofproto_dpif_cast(ofport
->up
.ofproto
)->backer
;
2783 backer
->need_revalidate
= REV_RECONFIGURE
;
2786 ofport
->peer
->peer
= NULL
;
2787 ofport
->peer
= NULL
;
2790 peer_name
= netdev_vport_patch_peer(ofport
->up
.netdev
);
2795 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
2796 struct ofport
*peer_ofport
;
2797 struct ofport_dpif
*peer
;
2800 if (ofproto
->backer
!= backer
) {
2804 peer_ofport
= shash_find_data(&ofproto
->up
.port_by_name
, peer_name
);
2809 peer
= ofport_dpif_cast(peer_ofport
);
2810 peer_peer
= netdev_vport_patch_peer(peer
->up
.netdev
);
2811 if (peer_peer
&& !strcmp(netdev_get_name(ofport
->up
.netdev
),
2813 ofport
->peer
= peer
;
2814 ofport
->peer
->peer
= ofport
;
2824 port_run(struct ofport_dpif
*ofport
)
2826 long long int carrier_seq
= netdev_get_carrier_resets(ofport
->up
.netdev
);
2827 bool carrier_changed
= carrier_seq
!= ofport
->carrier_seq
;
2828 bool enable
= netdev_get_carrier(ofport
->up
.netdev
);
2829 bool cfm_enable
= false;
2830 bool bfd_enable
= false;
2832 ofport
->carrier_seq
= carrier_seq
;
2835 int cfm_opup
= cfm_get_opup(ofport
->cfm
);
2837 cfm_enable
= !cfm_get_fault(ofport
->cfm
);
2839 if (cfm_opup
>= 0) {
2840 cfm_enable
= cfm_enable
&& cfm_opup
;
2845 bfd_enable
= bfd_forwarding(ofport
->bfd
);
2848 if (ofport
->bfd
|| ofport
->cfm
) {
2849 enable
= enable
&& (cfm_enable
|| bfd_enable
);
2852 if (ofport
->bundle
) {
2853 enable
= enable
&& lacp_slave_may_enable(ofport
->bundle
->lacp
, ofport
);
2854 if (carrier_changed
) {
2855 lacp_slave_carrier_changed(ofport
->bundle
->lacp
, ofport
);
2859 if (ofport
->may_enable
!= enable
) {
2860 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
2861 ofproto
->backer
->need_revalidate
= REV_PORT_TOGGLED
;
2864 ofport
->may_enable
= enable
;
2868 port_query_by_name(const struct ofproto
*ofproto_
, const char *devname
,
2869 struct ofproto_port
*ofproto_port
)
2871 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2872 struct dpif_port dpif_port
;
2875 if (sset_contains(&ofproto
->ghost_ports
, devname
)) {
2876 const char *type
= netdev_get_type_from_name(devname
);
2878 /* We may be called before ofproto->up.port_by_name is populated with
2879 * the appropriate ofport. For this reason, we must get the name and
2880 * type from the netdev layer directly. */
2882 const struct ofport
*ofport
;
2884 ofport
= shash_find_data(&ofproto
->up
.port_by_name
, devname
);
2885 ofproto_port
->ofp_port
= ofport
? ofport
->ofp_port
: OFPP_NONE
;
2886 ofproto_port
->name
= xstrdup(devname
);
2887 ofproto_port
->type
= xstrdup(type
);
2893 if (!sset_contains(&ofproto
->ports
, devname
)) {
2896 error
= dpif_port_query_by_name(ofproto
->backer
->dpif
,
2897 devname
, &dpif_port
);
2899 ofproto_port_from_dpif_port(ofproto
, ofproto_port
, &dpif_port
);
2905 port_add(struct ofproto
*ofproto_
, struct netdev
*netdev
)
2907 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2908 const char *devname
= netdev_get_name(netdev
);
2909 char namebuf
[NETDEV_VPORT_NAME_BUFSIZE
];
2910 const char *dp_port_name
;
2912 if (netdev_vport_is_patch(netdev
)) {
2913 sset_add(&ofproto
->ghost_ports
, netdev_get_name(netdev
));
2917 dp_port_name
= netdev_vport_get_dpif_port(netdev
, namebuf
, sizeof namebuf
);
2918 if (!dpif_port_exists(ofproto
->backer
->dpif
, dp_port_name
)) {
2919 odp_port_t port_no
= ODPP_NONE
;
2922 error
= dpif_port_add(ofproto
->backer
->dpif
, netdev
, &port_no
);
2926 if (netdev_get_tunnel_config(netdev
)) {
2927 simap_put(&ofproto
->backer
->tnl_backers
,
2928 dp_port_name
, odp_to_u32(port_no
));
2932 if (netdev_get_tunnel_config(netdev
)) {
2933 sset_add(&ofproto
->ghost_ports
, devname
);
2935 sset_add(&ofproto
->ports
, devname
);
2941 port_del(struct ofproto
*ofproto_
, ofp_port_t ofp_port
)
2943 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
2944 struct ofport_dpif
*ofport
= get_ofp_port(ofproto
, ofp_port
);
2951 sset_find_and_delete(&ofproto
->ghost_ports
,
2952 netdev_get_name(ofport
->up
.netdev
));
2953 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
2954 if (!ofport
->is_tunnel
&& !netdev_vport_is_patch(ofport
->up
.netdev
)) {
2955 error
= dpif_port_del(ofproto
->backer
->dpif
, ofport
->odp_port
);
2957 /* The caller is going to close ofport->up.netdev. If this is a
2958 * bonded port, then the bond is using that netdev, so remove it
2959 * from the bond. The client will need to reconfigure everything
2960 * after deleting ports, so then the slave will get re-added. */
2961 bundle_remove(&ofport
->up
);
2968 port_get_stats(const struct ofport
*ofport_
, struct netdev_stats
*stats
)
2970 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
2973 error
= netdev_get_stats(ofport
->up
.netdev
, stats
);
2975 if (!error
&& ofport_
->ofp_port
== OFPP_LOCAL
) {
2976 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
2978 ovs_mutex_lock(&ofproto
->stats_mutex
);
2979 /* ofproto->stats.tx_packets represents packets that we created
2980 * internally and sent to some port (e.g. packets sent with
2981 * ofproto_dpif_send_packet()). Account for them as if they had
2982 * come from OFPP_LOCAL and got forwarded. */
2984 if (stats
->rx_packets
!= UINT64_MAX
) {
2985 stats
->rx_packets
+= ofproto
->stats
.tx_packets
;
2988 if (stats
->rx_bytes
!= UINT64_MAX
) {
2989 stats
->rx_bytes
+= ofproto
->stats
.tx_bytes
;
2992 /* ofproto->stats.rx_packets represents packets that were received on
2993 * some port and we processed internally and dropped (e.g. STP).
2994 * Account for them as if they had been forwarded to OFPP_LOCAL. */
2996 if (stats
->tx_packets
!= UINT64_MAX
) {
2997 stats
->tx_packets
+= ofproto
->stats
.rx_packets
;
3000 if (stats
->tx_bytes
!= UINT64_MAX
) {
3001 stats
->tx_bytes
+= ofproto
->stats
.rx_bytes
;
3003 ovs_mutex_unlock(&ofproto
->stats_mutex
);
3009 struct port_dump_state
{
3014 struct ofproto_port port
;
3019 port_dump_start(const struct ofproto
*ofproto_ OVS_UNUSED
, void **statep
)
3021 *statep
= xzalloc(sizeof(struct port_dump_state
));
3026 port_dump_next(const struct ofproto
*ofproto_
, void *state_
,
3027 struct ofproto_port
*port
)
3029 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
3030 struct port_dump_state
*state
= state_
;
3031 const struct sset
*sset
;
3032 struct sset_node
*node
;
3034 if (state
->has_port
) {
3035 ofproto_port_destroy(&state
->port
);
3036 state
->has_port
= false;
3038 sset
= state
->ghost
? &ofproto
->ghost_ports
: &ofproto
->ports
;
3039 while ((node
= sset_at_position(sset
, &state
->bucket
, &state
->offset
))) {
3042 error
= port_query_by_name(ofproto_
, node
->name
, &state
->port
);
3044 *port
= state
->port
;
3045 state
->has_port
= true;
3047 } else if (error
!= ENODEV
) {
3052 if (!state
->ghost
) {
3053 state
->ghost
= true;
3056 return port_dump_next(ofproto_
, state_
, port
);
3063 port_dump_done(const struct ofproto
*ofproto_ OVS_UNUSED
, void *state_
)
3065 struct port_dump_state
*state
= state_
;
3067 if (state
->has_port
) {
3068 ofproto_port_destroy(&state
->port
);
3075 port_poll(const struct ofproto
*ofproto_
, char **devnamep
)
3077 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
3079 if (ofproto
->port_poll_errno
) {
3080 int error
= ofproto
->port_poll_errno
;
3081 ofproto
->port_poll_errno
= 0;
3085 if (sset_is_empty(&ofproto
->port_poll_set
)) {
3089 *devnamep
= sset_pop(&ofproto
->port_poll_set
);
3094 port_poll_wait(const struct ofproto
*ofproto_
)
3096 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
3097 dpif_port_poll_wait(ofproto
->backer
->dpif
);
3101 port_is_lacp_current(const struct ofport
*ofport_
)
3103 const struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
3104 return (ofport
->bundle
&& ofport
->bundle
->lacp
3105 ? lacp_slave_is_current(ofport
->bundle
->lacp
, ofport
)
3109 /* If 'rule' is an OpenFlow rule, that has expired according to OpenFlow rules,
3110 * then delete it entirely. */
3112 rule_expire(struct rule_dpif
*rule
)
3113 OVS_REQUIRES(ofproto_mutex
)
3115 uint16_t hard_timeout
, idle_timeout
;
3116 long long int now
= time_msec();
3119 hard_timeout
= rule
->up
.hard_timeout
;
3120 idle_timeout
= rule
->up
.idle_timeout
;
3122 /* Has 'rule' expired? */
3124 long long int modified
;
3126 ovs_mutex_lock(&rule
->up
.mutex
);
3127 modified
= rule
->up
.modified
;
3128 ovs_mutex_unlock(&rule
->up
.mutex
);
3130 if (now
> modified
+ hard_timeout
* 1000) {
3131 reason
= OFPRR_HARD_TIMEOUT
;
3135 if (reason
< 0 && idle_timeout
) {
3138 ovs_mutex_lock(&rule
->stats_mutex
);
3139 used
= rule
->stats
.used
;
3140 ovs_mutex_unlock(&rule
->stats_mutex
);
3142 if (now
> used
+ idle_timeout
* 1000) {
3143 reason
= OFPRR_IDLE_TIMEOUT
;
3148 COVERAGE_INC(ofproto_dpif_expired
);
3149 ofproto_rule_expire(&rule
->up
, reason
);
3153 /* Executes, within 'ofproto', the actions in 'rule' or 'ofpacts' on 'packet'.
3154 * 'flow' must reflect the data in 'packet'. */
3156 ofproto_dpif_execute_actions(struct ofproto_dpif
*ofproto
,
3157 const struct flow
*flow
,
3158 struct rule_dpif
*rule
,
3159 const struct ofpact
*ofpacts
, size_t ofpacts_len
,
3160 struct ofpbuf
*packet
)
3162 struct dpif_flow_stats stats
;
3163 struct xlate_out xout
;
3164 struct xlate_in xin
;
3166 struct dpif_execute execute
;
3169 ovs_assert((rule
!= NULL
) != (ofpacts
!= NULL
));
3171 dpif_flow_stats_extract(flow
, packet
, time_msec(), &stats
);
3174 rule_dpif_credit_stats(rule
, &stats
);
3177 xlate_in_init(&xin
, ofproto
, flow
, rule
, stats
.tcp_flags
, packet
);
3178 xin
.ofpacts
= ofpacts
;
3179 xin
.ofpacts_len
= ofpacts_len
;
3180 xin
.resubmit_stats
= &stats
;
3181 xlate_actions(&xin
, &xout
);
3183 execute
.actions
= ofpbuf_data(&xout
.odp_actions
);
3184 execute
.actions_len
= ofpbuf_size(&xout
.odp_actions
);
3185 execute
.packet
= packet
;
3186 execute
.md
= pkt_metadata_from_flow(flow
);
3187 execute
.needs_help
= (xout
.slow
& SLOW_ACTION
) != 0;
3189 /* Fix up in_port. */
3190 in_port
= flow
->in_port
.ofp_port
;
3191 if (in_port
== OFPP_NONE
) {
3192 in_port
= OFPP_LOCAL
;
3194 execute
.md
.in_port
.odp_port
= ofp_port_to_odp_port(ofproto
, in_port
);
3196 error
= dpif_execute(ofproto
->backer
->dpif
, &execute
);
3198 xlate_out_uninit(&xout
);
3204 rule_dpif_credit_stats(struct rule_dpif
*rule
,
3205 const struct dpif_flow_stats
*stats
)
3207 ovs_mutex_lock(&rule
->stats_mutex
);
3208 rule
->stats
.n_packets
+= stats
->n_packets
;
3209 rule
->stats
.n_bytes
+= stats
->n_bytes
;
3210 rule
->stats
.used
= MAX(rule
->stats
.used
, stats
->used
);
3211 ovs_mutex_unlock(&rule
->stats_mutex
);
3215 rule_dpif_get_flow_cookie(const struct rule_dpif
*rule
)
3216 OVS_REQUIRES(rule
->up
.mutex
)
3218 return rule
->up
.flow_cookie
;
3222 rule_dpif_reduce_timeouts(struct rule_dpif
*rule
, uint16_t idle_timeout
,
3223 uint16_t hard_timeout
)
3225 ofproto_rule_reduce_timeouts(&rule
->up
, idle_timeout
, hard_timeout
);
3228 /* Returns 'rule''s actions. The caller owns a reference on the returned
3229 * actions and must eventually release it (with rule_actions_unref()) to avoid
3231 const struct rule_actions
*
3232 rule_dpif_get_actions(const struct rule_dpif
*rule
)
3234 return rule_get_actions(&rule
->up
);
3237 /* Sets 'rule''s recirculation id. */
3239 rule_dpif_set_recirc_id(struct rule_dpif
*rule
, uint32_t id
)
3240 OVS_REQUIRES(rule
->up
.mutex
)
3242 ovs_assert(!rule
->recirc_id
);
3243 rule
->recirc_id
= id
;
3246 /* Returns 'rule''s recirculation id. */
3248 rule_dpif_get_recirc_id(struct rule_dpif
*rule
)
3249 OVS_REQUIRES(rule
->up
.mutex
)
3251 if (!rule
->recirc_id
) {
3252 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(rule
->up
.ofproto
);
3254 rule_dpif_set_recirc_id(rule
, ofproto_dpif_alloc_recirc_id(ofproto
));
3256 return rule
->recirc_id
;
3259 /* Sets 'rule''s recirculation id. */
3261 rule_set_recirc_id(struct rule
*rule_
, uint32_t id
)
3263 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3265 ovs_mutex_lock(&rule
->up
.mutex
);
3266 rule_dpif_set_recirc_id(rule
, id
);
3267 ovs_mutex_unlock(&rule
->up
.mutex
);
3270 /* Lookup 'flow' in table 0 of 'ofproto''s classifier.
3271 * If 'wc' is non-null, sets the fields that were relevant as part of
3272 * the lookup. Returns the table_id where a match or miss occurred.
3274 * The return value will be zero unless there was a miss and
3275 * OFPTC11_TABLE_MISS_CONTINUE is in effect for the sequence of tables
3276 * where misses occur.
3278 * The rule is returned in '*rule', which is valid at least until the next
3279 * RCU quiescent period. If the '*rule' needs to stay around longer,
3280 * a non-zero 'take_ref' must be passed in to cause a reference to be taken
3281 * on it before this returns. */
3283 rule_dpif_lookup(struct ofproto_dpif
*ofproto
, struct flow
*flow
,
3284 struct flow_wildcards
*wc
, struct rule_dpif
**rule
,
3285 bool take_ref
, const struct dpif_flow_stats
*stats
)
3287 enum rule_dpif_lookup_verdict verdict
;
3288 enum ofputil_port_config config
= 0;
3291 if (ofproto_dpif_get_enable_recirc(ofproto
)) {
3292 /* Always exactly match recirc_id since datapath supports
3295 wc
->masks
.recirc_id
= UINT32_MAX
;
3298 /* Start looking up from internal table for post recirculation flows
3299 * or packets. We can also simply send all, including normal flows
3300 * or packets to the internal table. They will not match any post
3301 * recirculation rules except the 'catch all' rule that resubmit
3304 * As an optimization, we send normal flows and packets to table 0
3305 * directly, saving one table lookup. */
3306 table_id
= flow
->recirc_id
? TBL_INTERNAL
: 0;
3311 verdict
= rule_dpif_lookup_from_table(ofproto
, flow
, wc
, true,
3312 &table_id
, rule
, take_ref
, stats
);
3315 case RULE_DPIF_LOOKUP_VERDICT_MATCH
:
3317 case RULE_DPIF_LOOKUP_VERDICT_CONTROLLER
: {
3318 struct ofport_dpif
*port
;
3320 port
= get_ofp_port(ofproto
, flow
->in_port
.ofp_port
);
3322 VLOG_WARN_RL(&rl
, "packet-in on unknown OpenFlow port %"PRIu16
,
3323 flow
->in_port
.ofp_port
);
3325 config
= port
? port
->up
.pp
.config
: 0;
3328 case RULE_DPIF_LOOKUP_VERDICT_DROP
:
3329 config
= OFPUTIL_PC_NO_PACKET_IN
;
3331 case RULE_DPIF_LOOKUP_VERDICT_DEFAULT
:
3332 if (!connmgr_wants_packet_in_on_miss(ofproto
->up
.connmgr
)) {
3333 config
= OFPUTIL_PC_NO_PACKET_IN
;
3340 choose_miss_rule(config
, ofproto
->miss_rule
,
3341 ofproto
->no_packet_in_rule
, rule
, take_ref
);
3345 /* The returned rule is valid at least until the next RCU quiescent period.
3346 * If the '*rule' needs to stay around longer, a non-zero 'take_ref' must be
3347 * passed in to cause a reference to be taken on it before this returns. */
3348 static struct rule_dpif
*
3349 rule_dpif_lookup_in_table(struct ofproto_dpif
*ofproto
, uint8_t table_id
,
3350 const struct flow
*flow
, struct flow_wildcards
*wc
,
3353 struct classifier
*cls
= &ofproto
->up
.tables
[table_id
].cls
;
3354 const struct cls_rule
*cls_rule
;
3355 struct rule_dpif
*rule
;
3356 struct flow ofpc_normal_flow
;
3358 if (ofproto
->up
.frag_handling
!= OFPC_FRAG_NX_MATCH
) {
3359 /* We always unwildcard dl_type and nw_frag (for IP), so they
3360 * need not be unwildcarded here. */
3362 if (flow
->nw_frag
& FLOW_NW_FRAG_ANY
) {
3363 if (ofproto
->up
.frag_handling
== OFPC_FRAG_NORMAL
) {
3364 /* We must pretend that transport ports are unavailable. */
3365 ofpc_normal_flow
= *flow
;
3366 ofpc_normal_flow
.tp_src
= htons(0);
3367 ofpc_normal_flow
.tp_dst
= htons(0);
3368 flow
= &ofpc_normal_flow
;
3370 /* Must be OFPC_FRAG_DROP (we don't have OFPC_FRAG_REASM).
3371 * Use the drop_frags_rule (which cannot disappear). */
3372 cls_rule
= &ofproto
->drop_frags_rule
->up
.cr
;
3373 rule
= rule_dpif_cast(rule_from_cls_rule(cls_rule
));
3375 rule_dpif_ref(rule
);
3383 cls_rule
= classifier_lookup(cls
, flow
, wc
);
3385 rule
= rule_dpif_cast(rule_from_cls_rule(cls_rule
));
3387 /* Try again if the rule was released before we get the reference. */
3388 } while (rule
&& take_ref
&& !rule_dpif_try_ref(rule
));
3393 /* Look up 'flow' in 'ofproto''s classifier starting from table '*table_id'.
3394 * Stores the rule that was found in '*rule', or NULL if none was found.
3395 * Updates 'wc', if nonnull, to reflect the fields that were used during the
3398 * If 'honor_table_miss' is true, the first lookup occurs in '*table_id', but
3399 * if none is found then the table miss configuration for that table is
3400 * honored, which can result in additional lookups in other OpenFlow tables.
3401 * In this case the function updates '*table_id' to reflect the final OpenFlow
3402 * table that was searched.
3404 * If 'honor_table_miss' is false, then only one table lookup occurs, in
3409 * - RULE_DPIF_LOOKUP_VERDICT_MATCH if a rule (in '*rule') was found.
3411 * - RULE_OFPTC_TABLE_MISS_CONTROLLER if no rule was found and either:
3412 * + 'honor_table_miss' is false
3413 * + a table miss configuration specified that the packet should be
3414 * sent to the controller in this case.
3416 * - RULE_DPIF_LOOKUP_VERDICT_DROP if no rule was found, 'honor_table_miss'
3417 * is true and a table miss configuration specified that the packet
3418 * should be dropped in this case.
3420 * - RULE_DPIF_LOOKUP_VERDICT_DEFAULT if no rule was found,
3421 * 'honor_table_miss' is true and a table miss configuration has
3422 * not been specified in this case.
3424 * The rule is returned in '*rule', which is valid at least until the next
3425 * RCU quiescent period. If the '*rule' needs to stay around longer,
3426 * a non-zero 'take_ref' must be passed in to cause a reference to be taken
3427 * on it before this returns. */
3428 enum rule_dpif_lookup_verdict
3429 rule_dpif_lookup_from_table(struct ofproto_dpif
*ofproto
,
3430 const struct flow
*flow
,
3431 struct flow_wildcards
*wc
,
3432 bool honor_table_miss
,
3433 uint8_t *table_id
, struct rule_dpif
**rule
,
3434 bool take_ref
, const struct dpif_flow_stats
*stats
)
3438 for (next_id
= *table_id
;
3439 next_id
< ofproto
->up
.n_tables
;
3440 next_id
++, next_id
+= (next_id
== TBL_INTERNAL
))
3442 *table_id
= next_id
;
3443 *rule
= rule_dpif_lookup_in_table(ofproto
, *table_id
, flow
, wc
,
3446 struct oftable
*tbl
= &ofproto
->up
.tables
[next_id
];
3447 atomic_ulong
*stat
= *rule
? &tbl
->n_matched
: &tbl
->n_missed
;
3449 atomic_add(stat
, stats
->n_packets
, &orig
);
3452 return RULE_DPIF_LOOKUP_VERDICT_MATCH
;
3453 } else if (!honor_table_miss
) {
3454 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER
;
3456 switch (ofproto_table_get_config(&ofproto
->up
, *table_id
)) {
3457 case OFPROTO_TABLE_MISS_CONTINUE
:
3460 case OFPROTO_TABLE_MISS_CONTROLLER
:
3461 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER
;
3463 case OFPROTO_TABLE_MISS_DROP
:
3464 return RULE_DPIF_LOOKUP_VERDICT_DROP
;
3466 case OFPROTO_TABLE_MISS_DEFAULT
:
3467 return RULE_DPIF_LOOKUP_VERDICT_DEFAULT
;
3472 return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER
;
3475 /* Given a port configuration (specified as zero if there's no port), chooses
3476 * which of 'miss_rule' and 'no_packet_in_rule' should be used in case of a
3479 * The rule is returned in '*rule', which is valid at least until the next
3480 * RCU quiescent period. If the '*rule' needs to stay around longer,
3481 * a reference must be taken on it (rule_dpif_ref()).
3484 choose_miss_rule(enum ofputil_port_config config
, struct rule_dpif
*miss_rule
,
3485 struct rule_dpif
*no_packet_in_rule
, struct rule_dpif
**rule
,
3488 *rule
= config
& OFPUTIL_PC_NO_PACKET_IN
? no_packet_in_rule
: miss_rule
;
3490 rule_dpif_ref(*rule
);
3495 complete_operation(struct rule_dpif
*rule
)
3496 OVS_REQUIRES(ofproto_mutex
)
3498 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(rule
->up
.ofproto
);
3500 ofproto
->backer
->need_revalidate
= REV_FLOW_TABLE
;
3503 static struct rule_dpif
*rule_dpif_cast(const struct rule
*rule
)
3505 return rule
? CONTAINER_OF(rule
, struct rule_dpif
, up
) : NULL
;
3508 static struct rule
*
3511 struct rule_dpif
*rule
= xmalloc(sizeof *rule
);
3516 rule_dealloc(struct rule
*rule_
)
3518 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3523 rule_construct(struct rule
*rule_
)
3524 OVS_NO_THREAD_SAFETY_ANALYSIS
3526 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3527 ovs_mutex_init_adaptive(&rule
->stats_mutex
);
3528 rule
->stats
.n_packets
= 0;
3529 rule
->stats
.n_bytes
= 0;
3530 rule
->stats
.used
= rule
->up
.modified
;
3531 rule
->recirc_id
= 0;
3537 rule_insert(struct rule
*rule_
)
3538 OVS_REQUIRES(ofproto_mutex
)
3540 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3541 complete_operation(rule
);
3546 rule_delete(struct rule
*rule_
)
3547 OVS_REQUIRES(ofproto_mutex
)
3549 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3550 complete_operation(rule
);
3554 rule_destruct(struct rule
*rule_
)
3556 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3558 ovs_mutex_destroy(&rule
->stats_mutex
);
3559 if (rule
->recirc_id
) {
3560 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(rule
->up
.ofproto
);
3562 ofproto_dpif_free_recirc_id(ofproto
, rule
->recirc_id
);
3567 rule_get_stats(struct rule
*rule_
, uint64_t *packets
, uint64_t *bytes
,
3568 long long int *used
)
3570 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3572 ovs_mutex_lock(&rule
->stats_mutex
);
3573 *packets
= rule
->stats
.n_packets
;
3574 *bytes
= rule
->stats
.n_bytes
;
3575 *used
= rule
->stats
.used
;
3576 ovs_mutex_unlock(&rule
->stats_mutex
);
3580 rule_dpif_execute(struct rule_dpif
*rule
, const struct flow
*flow
,
3581 struct ofpbuf
*packet
)
3583 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(rule
->up
.ofproto
);
3585 ofproto_dpif_execute_actions(ofproto
, flow
, rule
, NULL
, 0, packet
);
3589 rule_execute(struct rule
*rule
, const struct flow
*flow
,
3590 struct ofpbuf
*packet
)
3592 rule_dpif_execute(rule_dpif_cast(rule
), flow
, packet
);
3593 ofpbuf_delete(packet
);
3598 rule_modify_actions(struct rule
*rule_
, bool reset_counters
)
3599 OVS_REQUIRES(ofproto_mutex
)
3601 struct rule_dpif
*rule
= rule_dpif_cast(rule_
);
3603 if (reset_counters
) {
3604 ovs_mutex_lock(&rule
->stats_mutex
);
3605 rule
->stats
.n_packets
= 0;
3606 rule
->stats
.n_bytes
= 0;
3607 ovs_mutex_unlock(&rule
->stats_mutex
);
3610 complete_operation(rule
);
3613 static struct group_dpif
*group_dpif_cast(const struct ofgroup
*group
)
3615 return group
? CONTAINER_OF(group
, struct group_dpif
, up
) : NULL
;
3618 static struct ofgroup
*
3621 struct group_dpif
*group
= xzalloc(sizeof *group
);
3626 group_dealloc(struct ofgroup
*group_
)
3628 struct group_dpif
*group
= group_dpif_cast(group_
);
3633 group_construct_stats(struct group_dpif
*group
)
3634 OVS_REQUIRES(group
->stats_mutex
)
3636 struct ofputil_bucket
*bucket
;
3637 const struct list
*buckets
;
3639 group
->packet_count
= 0;
3640 group
->byte_count
= 0;
3642 group_dpif_get_buckets(group
, &buckets
);
3643 LIST_FOR_EACH (bucket
, list_node
, buckets
) {
3644 bucket
->stats
.packet_count
= 0;
3645 bucket
->stats
.byte_count
= 0;
3650 group_dpif_credit_stats(struct group_dpif
*group
,
3651 struct ofputil_bucket
*bucket
,
3652 const struct dpif_flow_stats
*stats
)
3654 ovs_mutex_lock(&group
->stats_mutex
);
3655 group
->packet_count
+= stats
->n_packets
;
3656 group
->byte_count
+= stats
->n_bytes
;
3658 bucket
->stats
.packet_count
+= stats
->n_packets
;
3659 bucket
->stats
.byte_count
+= stats
->n_bytes
;
3660 } else { /* Credit to all buckets */
3661 const struct list
*buckets
;
3663 group_dpif_get_buckets(group
, &buckets
);
3664 LIST_FOR_EACH (bucket
, list_node
, buckets
) {
3665 bucket
->stats
.packet_count
+= stats
->n_packets
;
3666 bucket
->stats
.byte_count
+= stats
->n_bytes
;
3669 ovs_mutex_unlock(&group
->stats_mutex
);
3673 group_construct(struct ofgroup
*group_
)
3675 struct group_dpif
*group
= group_dpif_cast(group_
);
3676 const struct ofputil_bucket
*bucket
;
3678 /* Prevent group chaining because our locking structure makes it hard to
3679 * implement deadlock-free. (See xlate_group_resource_check().) */
3680 LIST_FOR_EACH (bucket
, list_node
, &group
->up
.buckets
) {
3681 const struct ofpact
*a
;
3683 OFPACT_FOR_EACH (a
, bucket
->ofpacts
, bucket
->ofpacts_len
) {
3684 if (a
->type
== OFPACT_GROUP
) {
3685 return OFPERR_OFPGMFC_CHAINING_UNSUPPORTED
;
3690 ovs_mutex_init_adaptive(&group
->stats_mutex
);
3691 ovs_mutex_lock(&group
->stats_mutex
);
3692 group_construct_stats(group
);
3693 ovs_mutex_unlock(&group
->stats_mutex
);
3698 group_destruct(struct ofgroup
*group_
)
3700 struct group_dpif
*group
= group_dpif_cast(group_
);
3701 ovs_mutex_destroy(&group
->stats_mutex
);
3705 group_modify(struct ofgroup
*group_
)
3707 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(group_
->ofproto
);
3709 ofproto
->backer
->need_revalidate
= REV_FLOW_TABLE
;
3715 group_get_stats(const struct ofgroup
*group_
, struct ofputil_group_stats
*ogs
)
3717 struct group_dpif
*group
= group_dpif_cast(group_
);
3718 struct ofputil_bucket
*bucket
;
3719 const struct list
*buckets
;
3720 struct bucket_counter
*bucket_stats
;
3722 ovs_mutex_lock(&group
->stats_mutex
);
3723 ogs
->packet_count
= group
->packet_count
;
3724 ogs
->byte_count
= group
->byte_count
;
3726 group_dpif_get_buckets(group
, &buckets
);
3727 bucket_stats
= ogs
->bucket_stats
;
3728 LIST_FOR_EACH (bucket
, list_node
, buckets
) {
3729 bucket_stats
->packet_count
= bucket
->stats
.packet_count
;
3730 bucket_stats
->byte_count
= bucket
->stats
.byte_count
;
3733 ovs_mutex_unlock(&group
->stats_mutex
);
3738 /* If the group exists, this function increments the groups's reference count.
3740 * Make sure to call group_dpif_unref() after no longer needing to maintain
3741 * a reference to the group. */
3743 group_dpif_lookup(struct ofproto_dpif
*ofproto
, uint32_t group_id
,
3744 struct group_dpif
**group
)
3746 struct ofgroup
*ofgroup
;
3749 found
= ofproto_group_lookup(&ofproto
->up
, group_id
, &ofgroup
);
3750 *group
= found
? group_dpif_cast(ofgroup
) : NULL
;
3756 group_dpif_get_buckets(const struct group_dpif
*group
,
3757 const struct list
**buckets
)
3759 *buckets
= &group
->up
.buckets
;
3762 enum ofp11_group_type
3763 group_dpif_get_type(const struct group_dpif
*group
)
3765 return group
->up
.type
;
3768 /* Sends 'packet' out 'ofport'.
3769 * May modify 'packet'.
3770 * Returns 0 if successful, otherwise a positive errno value. */
3772 ofproto_dpif_send_packet(const struct ofport_dpif
*ofport
, struct ofpbuf
*packet
)
3774 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport
->up
.ofproto
);
3777 error
= xlate_send_packet(ofport
, packet
);
3779 ovs_mutex_lock(&ofproto
->stats_mutex
);
3780 ofproto
->stats
.tx_packets
++;
3781 ofproto
->stats
.tx_bytes
+= ofpbuf_size(packet
);
3782 ovs_mutex_unlock(&ofproto
->stats_mutex
);
3787 set_frag_handling(struct ofproto
*ofproto_
,
3788 enum ofp_config_flags frag_handling
)
3790 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
3791 if (frag_handling
!= OFPC_FRAG_REASM
) {
3792 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
3800 packet_out(struct ofproto
*ofproto_
, struct ofpbuf
*packet
,
3801 const struct flow
*flow
,
3802 const struct ofpact
*ofpacts
, size_t ofpacts_len
)
3804 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
3806 ofproto_dpif_execute_actions(ofproto
, flow
, NULL
, ofpacts
,
3807 ofpacts_len
, packet
);
3814 set_netflow(struct ofproto
*ofproto_
,
3815 const struct netflow_options
*netflow_options
)
3817 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
3819 if (netflow_options
) {
3820 if (!ofproto
->netflow
) {
3821 ofproto
->netflow
= netflow_create();
3822 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
3824 return netflow_set_options(ofproto
->netflow
, netflow_options
);
3825 } else if (ofproto
->netflow
) {
3826 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
3827 netflow_unref(ofproto
->netflow
);
3828 ofproto
->netflow
= NULL
;
3835 get_netflow_ids(const struct ofproto
*ofproto_
,
3836 uint8_t *engine_type
, uint8_t *engine_id
)
3838 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofproto_
);
3840 dpif_get_netflow_ids(ofproto
->backer
->dpif
, engine_type
, engine_id
);
3843 static struct ofproto_dpif
*
3844 ofproto_dpif_lookup(const char *name
)
3846 struct ofproto_dpif
*ofproto
;
3848 HMAP_FOR_EACH_WITH_HASH (ofproto
, all_ofproto_dpifs_node
,
3849 hash_string(name
, 0), &all_ofproto_dpifs
) {
3850 if (!strcmp(ofproto
->up
.name
, name
)) {
3858 ofproto_unixctl_fdb_flush(struct unixctl_conn
*conn
, int argc
,
3859 const char *argv
[], void *aux OVS_UNUSED
)
3861 struct ofproto_dpif
*ofproto
;
3864 ofproto
= ofproto_dpif_lookup(argv
[1]);
3866 unixctl_command_reply_error(conn
, "no such bridge");
3869 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
3870 mac_learning_flush(ofproto
->ml
);
3871 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
3873 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
3874 ovs_rwlock_wrlock(&ofproto
->ml
->rwlock
);
3875 mac_learning_flush(ofproto
->ml
);
3876 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
3880 unixctl_command_reply(conn
, "table successfully flushed");
3884 ofproto_unixctl_mcast_snooping_flush(struct unixctl_conn
*conn
, int argc
,
3885 const char *argv
[], void *aux OVS_UNUSED
)
3887 struct ofproto_dpif
*ofproto
;
3890 ofproto
= ofproto_dpif_lookup(argv
[1]);
3892 unixctl_command_reply_error(conn
, "no such bridge");
3896 if (!mcast_snooping_enabled(ofproto
->ms
)) {
3897 unixctl_command_reply_error(conn
, "multicast snooping is disabled");
3900 mcast_snooping_mdb_flush(ofproto
->ms
);
3902 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
3903 if (!mcast_snooping_enabled(ofproto
->ms
)) {
3906 mcast_snooping_mdb_flush(ofproto
->ms
);
3910 unixctl_command_reply(conn
, "table successfully flushed");
3913 static struct ofport_dpif
*
3914 ofbundle_get_a_port(const struct ofbundle
*bundle
)
3916 return CONTAINER_OF(list_front(&bundle
->ports
), struct ofport_dpif
,
3921 ofproto_unixctl_fdb_show(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
3922 const char *argv
[], void *aux OVS_UNUSED
)
3924 struct ds ds
= DS_EMPTY_INITIALIZER
;
3925 const struct ofproto_dpif
*ofproto
;
3926 const struct mac_entry
*e
;
3928 ofproto
= ofproto_dpif_lookup(argv
[1]);
3930 unixctl_command_reply_error(conn
, "no such bridge");
3934 ds_put_cstr(&ds
, " port VLAN MAC Age\n");
3935 ovs_rwlock_rdlock(&ofproto
->ml
->rwlock
);
3936 LIST_FOR_EACH (e
, lru_node
, &ofproto
->ml
->lrus
) {
3937 struct ofbundle
*bundle
= e
->port
.p
;
3938 char name
[OFP_MAX_PORT_NAME_LEN
];
3940 ofputil_port_to_string(ofbundle_get_a_port(bundle
)->up
.ofp_port
,
3942 ds_put_format(&ds
, "%5s %4d "ETH_ADDR_FMT
" %3d\n",
3943 name
, e
->vlan
, ETH_ADDR_ARGS(e
->mac
),
3944 mac_entry_age(ofproto
->ml
, e
));
3946 ovs_rwlock_unlock(&ofproto
->ml
->rwlock
);
3947 unixctl_command_reply(conn
, ds_cstr(&ds
));
3952 ofproto_unixctl_mcast_snooping_show(struct unixctl_conn
*conn
,
3953 int argc OVS_UNUSED
,
3955 void *aux OVS_UNUSED
)
3957 struct ds ds
= DS_EMPTY_INITIALIZER
;
3958 const struct ofproto_dpif
*ofproto
;
3959 const struct ofbundle
*bundle
;
3960 const struct mcast_group
*grp
;
3961 struct mcast_group_bundle
*b
;
3962 struct mcast_mrouter_bundle
*mrouter
;
3964 ofproto
= ofproto_dpif_lookup(argv
[1]);
3966 unixctl_command_reply_error(conn
, "no such bridge");
3970 if (!mcast_snooping_enabled(ofproto
->ms
)) {
3971 unixctl_command_reply_error(conn
, "multicast snooping is disabled");
3975 ds_put_cstr(&ds
, " port VLAN GROUP Age\n");
3976 ovs_rwlock_rdlock(&ofproto
->ms
->rwlock
);
3977 LIST_FOR_EACH (grp
, group_node
, &ofproto
->ms
->group_lru
) {
3978 LIST_FOR_EACH(b
, bundle_node
, &grp
->bundle_lru
) {
3979 char name
[OFP_MAX_PORT_NAME_LEN
];
3982 ofputil_port_to_string(ofbundle_get_a_port(bundle
)->up
.ofp_port
,
3984 ds_put_format(&ds
, "%5s %4d "IP_FMT
" %3d\n",
3985 name
, grp
->vlan
, IP_ARGS(grp
->ip4
),
3986 mcast_bundle_age(ofproto
->ms
, b
));
3990 /* ports connected to multicast routers */
3991 LIST_FOR_EACH(mrouter
, mrouter_node
, &ofproto
->ms
->mrouter_lru
) {
3992 char name
[OFP_MAX_PORT_NAME_LEN
];
3994 bundle
= mrouter
->port
;
3995 ofputil_port_to_string(ofbundle_get_a_port(bundle
)->up
.ofp_port
,
3997 ds_put_format(&ds
, "%5s %4d querier %3d\n",
3998 name
, mrouter
->vlan
,
3999 mcast_mrouter_age(ofproto
->ms
, mrouter
));
4001 ovs_rwlock_unlock(&ofproto
->ms
->rwlock
);
4002 unixctl_command_reply(conn
, ds_cstr(&ds
));
4007 struct xlate_out xout
;
4008 struct xlate_in xin
;
4009 const struct flow
*key
;
4011 struct flow_wildcards wc
;
4016 trace_format_rule(struct ds
*result
, int level
, const struct rule_dpif
*rule
)
4018 const struct rule_actions
*actions
;
4021 ds_put_char_multiple(result
, '\t', level
);
4023 ds_put_cstr(result
, "No match\n");
4027 ovs_mutex_lock(&rule
->up
.mutex
);
4028 cookie
= rule
->up
.flow_cookie
;
4029 ovs_mutex_unlock(&rule
->up
.mutex
);
4031 ds_put_format(result
, "Rule: table=%"PRIu8
" cookie=%#"PRIx64
" ",
4032 rule
? rule
->up
.table_id
: 0, ntohll(cookie
));
4033 cls_rule_format(&rule
->up
.cr
, result
);
4034 ds_put_char(result
, '\n');
4036 actions
= rule_dpif_get_actions(rule
);
4038 ds_put_char_multiple(result
, '\t', level
);
4039 ds_put_cstr(result
, "OpenFlow actions=");
4040 ofpacts_format(actions
->ofpacts
, actions
->ofpacts_len
, result
);
4041 ds_put_char(result
, '\n');
4045 trace_format_flow(struct ds
*result
, int level
, const char *title
,
4046 struct trace_ctx
*trace
)
4048 ds_put_char_multiple(result
, '\t', level
);
4049 ds_put_format(result
, "%s: ", title
);
4050 /* Do not report unchanged flows for resubmits. */
4051 if ((level
> 0 && flow_equal(&trace
->xin
.flow
, &trace
->flow
))
4052 || (level
== 0 && flow_equal(&trace
->xin
.flow
, trace
->key
))) {
4053 ds_put_cstr(result
, "unchanged");
4055 flow_format(result
, &trace
->xin
.flow
);
4056 trace
->flow
= trace
->xin
.flow
;
4058 ds_put_char(result
, '\n');
4062 trace_format_regs(struct ds
*result
, int level
, const char *title
,
4063 struct trace_ctx
*trace
)
4067 ds_put_char_multiple(result
, '\t', level
);
4068 ds_put_format(result
, "%s:", title
);
4069 for (i
= 0; i
< FLOW_N_REGS
; i
++) {
4070 ds_put_format(result
, " reg%"PRIuSIZE
"=0x%"PRIx32
, i
, trace
->flow
.regs
[i
]);
4072 ds_put_char(result
, '\n');
4076 trace_format_odp(struct ds
*result
, int level
, const char *title
,
4077 struct trace_ctx
*trace
)
4079 struct ofpbuf
*odp_actions
= &trace
->xout
.odp_actions
;
4081 ds_put_char_multiple(result
, '\t', level
);
4082 ds_put_format(result
, "%s: ", title
);
4083 format_odp_actions(result
, ofpbuf_data(odp_actions
),
4084 ofpbuf_size(odp_actions
));
4085 ds_put_char(result
, '\n');
4089 trace_format_megaflow(struct ds
*result
, int level
, const char *title
,
4090 struct trace_ctx
*trace
)
4094 ds_put_char_multiple(result
, '\t', level
);
4095 ds_put_format(result
, "%s: ", title
);
4096 flow_wildcards_or(&trace
->wc
, &trace
->xout
.wc
, &trace
->wc
);
4097 match_init(&match
, trace
->key
, &trace
->wc
);
4098 match_format(&match
, result
, OFP_DEFAULT_PRIORITY
);
4099 ds_put_char(result
, '\n');
4103 trace_resubmit(struct xlate_in
*xin
, struct rule_dpif
*rule
, int recurse
)
4105 struct trace_ctx
*trace
= CONTAINER_OF(xin
, struct trace_ctx
, xin
);
4106 struct ds
*result
= trace
->result
;
4108 ds_put_char(result
, '\n');
4109 trace_format_flow(result
, recurse
+ 1, "Resubmitted flow", trace
);
4110 trace_format_regs(result
, recurse
+ 1, "Resubmitted regs", trace
);
4111 trace_format_odp(result
, recurse
+ 1, "Resubmitted odp", trace
);
4112 trace_format_megaflow(result
, recurse
+ 1, "Resubmitted megaflow", trace
);
4113 trace_format_rule(result
, recurse
+ 1, rule
);
4117 trace_report(struct xlate_in
*xin
, const char *s
, int recurse
)
4119 struct trace_ctx
*trace
= CONTAINER_OF(xin
, struct trace_ctx
, xin
);
4120 struct ds
*result
= trace
->result
;
4122 ds_put_char_multiple(result
, '\t', recurse
);
4123 ds_put_cstr(result
, s
);
4124 ds_put_char(result
, '\n');
4127 /* Parses the 'argc' elements of 'argv', ignoring argv[0]. The following
4128 * forms are supported:
4130 * - [dpname] odp_flow [-generate | packet]
4131 * - bridge br_flow [-generate | packet]
4133 * On success, initializes '*ofprotop' and 'flow' and returns NULL. On failure
4134 * returns a nonnull malloced error message. */
4135 static char * WARN_UNUSED_RESULT
4136 parse_flow_and_packet(int argc
, const char *argv
[],
4137 struct ofproto_dpif
**ofprotop
, struct flow
*flow
,
4138 struct ofpbuf
**packetp
)
4140 const struct dpif_backer
*backer
= NULL
;
4141 const char *error
= NULL
;
4143 struct simap port_names
= SIMAP_INITIALIZER(&port_names
);
4144 struct ofpbuf
*packet
;
4145 struct ofpbuf odp_key
;
4146 struct ofpbuf odp_mask
;
4148 ofpbuf_init(&odp_key
, 0);
4149 ofpbuf_init(&odp_mask
, 0);
4151 /* Handle "-generate" or a hex string as the last argument. */
4152 if (!strcmp(argv
[argc
- 1], "-generate")) {
4153 packet
= ofpbuf_new(0);
4156 error
= eth_from_hex(argv
[argc
- 1], &packet
);
4159 } else if (argc
== 4) {
4160 /* The 3-argument form must end in "-generate' or a hex string. */
4166 /* odp_flow can have its in_port specified as a name instead of port no.
4167 * We do not yet know whether a given flow is a odp_flow or a br_flow.
4168 * But, to know whether a flow is odp_flow through odp_flow_from_string(),
4169 * we need to create a simap of name to port no. */
4171 const char *dp_type
;
4172 if (!strncmp(argv
[1], "ovs-", 4)) {
4173 dp_type
= argv
[1] + 4;
4177 backer
= shash_find_data(&all_dpif_backers
, dp_type
);
4178 } else if (argc
== 2) {
4179 struct shash_node
*node
;
4180 if (shash_count(&all_dpif_backers
) == 1) {
4181 node
= shash_first(&all_dpif_backers
);
4182 backer
= node
->data
;
4185 error
= "Syntax error";
4188 if (backer
&& backer
->dpif
) {
4189 struct dpif_port dpif_port
;
4190 struct dpif_port_dump port_dump
;
4191 DPIF_PORT_FOR_EACH (&dpif_port
, &port_dump
, backer
->dpif
) {
4192 simap_put(&port_names
, dpif_port
.name
,
4193 odp_to_u32(dpif_port
.port_no
));
4197 /* Parse the flow and determine whether a datapath or
4198 * bridge is specified. If function odp_flow_key_from_string()
4199 * returns 0, the flow is a odp_flow. If function
4200 * parse_ofp_exact_flow() returns NULL, the flow is a br_flow. */
4201 if (!odp_flow_from_string(argv
[argc
- 1], &port_names
,
4202 &odp_key
, &odp_mask
)) {
4204 error
= "Cannot find the datapath";
4208 if (xlate_receive(backer
, NULL
, ofpbuf_data(&odp_key
),
4209 ofpbuf_size(&odp_key
), flow
,
4210 ofprotop
, NULL
, NULL
, NULL
, NULL
)) {
4211 error
= "Invalid datapath flow";
4215 char *err
= parse_ofp_exact_flow(flow
, NULL
, argv
[argc
- 1], NULL
);
4218 m_err
= xasprintf("Bad flow syntax: %s", err
);
4223 error
= "Must specify bridge name";
4227 *ofprotop
= ofproto_dpif_lookup(argv
[1]);
4229 error
= "Unknown bridge name";
4235 /* Generate a packet, if requested. */
4237 if (!ofpbuf_size(packet
)) {
4238 flow_compose(packet
, flow
);
4240 struct pkt_metadata md
= pkt_metadata_from_flow(flow
);
4242 /* Use the metadata from the flow and the packet argument
4243 * to reconstruct the flow. */
4244 flow_extract(packet
, &md
, flow
);
4249 if (error
&& !m_err
) {
4250 m_err
= xstrdup(error
);
4253 ofpbuf_delete(packet
);
4257 ofpbuf_uninit(&odp_key
);
4258 ofpbuf_uninit(&odp_mask
);
4259 simap_destroy(&port_names
);
4264 ofproto_unixctl_trace(struct unixctl_conn
*conn
, int argc
, const char *argv
[],
4265 void *aux OVS_UNUSED
)
4267 struct ofproto_dpif
*ofproto
;
4268 struct ofpbuf
*packet
;
4272 error
= parse_flow_and_packet(argc
, argv
, &ofproto
, &flow
, &packet
);
4277 ofproto_trace(ofproto
, &flow
, packet
, NULL
, 0, &result
);
4278 unixctl_command_reply(conn
, ds_cstr(&result
));
4279 ds_destroy(&result
);
4280 ofpbuf_delete(packet
);
4282 unixctl_command_reply_error(conn
, error
);
4288 ofproto_unixctl_trace_actions(struct unixctl_conn
*conn
, int argc
,
4289 const char *argv
[], void *aux OVS_UNUSED
)
4291 enum ofputil_protocol usable_protocols
;
4292 struct ofproto_dpif
*ofproto
;
4293 bool enforce_consistency
;
4294 struct ofpbuf ofpacts
;
4295 struct ofpbuf
*packet
;
4300 /* Three kinds of error return values! */
4306 ofpbuf_init(&ofpacts
, 0);
4308 /* Parse actions. */
4309 error
= parse_ofpacts(argv
[--argc
], &ofpacts
, &usable_protocols
);
4311 unixctl_command_reply_error(conn
, error
);
4316 /* OpenFlow 1.1 and later suggest that the switch enforces certain forms of
4317 * consistency between the flow and the actions. With -consistent, we
4318 * enforce consistency even for a flow supported in OpenFlow 1.0. */
4319 if (!strcmp(argv
[1], "-consistent")) {
4320 enforce_consistency
= true;
4324 enforce_consistency
= false;
4327 error
= parse_flow_and_packet(argc
, argv
, &ofproto
, &flow
, &packet
);
4329 unixctl_command_reply_error(conn
, error
);
4334 /* Do the same checks as handle_packet_out() in ofproto.c.
4336 * We pass a 'table_id' of 0 to ofproto_check_ofpacts(), which isn't
4337 * strictly correct because these actions aren't in any table, but it's OK
4338 * because it 'table_id' is used only to check goto_table instructions, but
4339 * packet-outs take a list of actions and therefore it can't include
4342 * We skip the "meter" check here because meter is an instruction, not an
4343 * action, and thus cannot appear in ofpacts. */
4344 in_port
= ofp_to_u16(flow
.in_port
.ofp_port
);
4345 if (in_port
>= ofproto
->up
.max_ports
&& in_port
< ofp_to_u16(OFPP_MAX
)) {
4346 unixctl_command_reply_error(conn
, "invalid in_port");
4349 if (enforce_consistency
) {
4350 retval
= ofpacts_check_consistency(ofpbuf_data(&ofpacts
), ofpbuf_size(&ofpacts
),
4351 &flow
, u16_to_ofp(ofproto
->up
.max_ports
),
4352 0, 0, usable_protocols
);
4354 retval
= ofpacts_check(ofpbuf_data(&ofpacts
), ofpbuf_size(&ofpacts
), &flow
,
4355 u16_to_ofp(ofproto
->up
.max_ports
), 0, 0,
4361 ds_put_format(&result
, "Bad actions: %s", ofperr_to_string(retval
));
4362 unixctl_command_reply_error(conn
, ds_cstr(&result
));
4366 ofproto_trace(ofproto
, &flow
, packet
,
4367 ofpbuf_data(&ofpacts
), ofpbuf_size(&ofpacts
), &result
);
4368 unixctl_command_reply(conn
, ds_cstr(&result
));
4371 ds_destroy(&result
);
4372 ofpbuf_delete(packet
);
4373 ofpbuf_uninit(&ofpacts
);
4376 /* Implements a "trace" through 'ofproto''s flow table, appending a textual
4377 * description of the results to 'ds'.
4379 * The trace follows a packet with the specified 'flow' through the flow
4380 * table. 'packet' may be nonnull to trace an actual packet, with consequent
4381 * side effects (if it is nonnull then its flow must be 'flow').
4383 * If 'ofpacts' is nonnull then its 'ofpacts_len' bytes specify the actions to
4384 * trace, otherwise the actions are determined by a flow table lookup. */
4386 ofproto_trace(struct ofproto_dpif
*ofproto
, struct flow
*flow
,
4387 const struct ofpbuf
*packet
,
4388 const struct ofpact ofpacts
[], size_t ofpacts_len
,
4391 struct rule_dpif
*rule
;
4392 struct trace_ctx trace
;
4394 ds_put_format(ds
, "Bridge: %s\n", ofproto
->up
.name
);
4395 ds_put_cstr(ds
, "Flow: ");
4396 flow_format(ds
, flow
);
4397 ds_put_char(ds
, '\n');
4399 flow_wildcards_init_catchall(&trace
.wc
);
4403 rule_dpif_lookup(ofproto
, flow
, &trace
.wc
, &rule
, false, NULL
);
4405 trace_format_rule(ds
, 0, rule
);
4406 if (rule
== ofproto
->miss_rule
) {
4407 ds_put_cstr(ds
, "\nNo match, flow generates \"packet in\"s.\n");
4408 } else if (rule
== ofproto
->no_packet_in_rule
) {
4409 ds_put_cstr(ds
, "\nNo match, packets dropped because "
4410 "OFPPC_NO_PACKET_IN is set on in_port.\n");
4411 } else if (rule
== ofproto
->drop_frags_rule
) {
4412 ds_put_cstr(ds
, "\nPackets dropped because they are IP fragments "
4413 "and the fragment handling mode is \"drop\".\n");
4417 if (rule
|| ofpacts
) {
4419 trace
.key
= flow
; /* Original flow key, used for megaflow. */
4420 trace
.flow
= *flow
; /* May be modified by actions. */
4421 xlate_in_init(&trace
.xin
, ofproto
, flow
, rule
, ntohs(flow
->tcp_flags
),
4424 trace
.xin
.ofpacts
= ofpacts
;
4425 trace
.xin
.ofpacts_len
= ofpacts_len
;
4427 trace
.xin
.resubmit_hook
= trace_resubmit
;
4428 trace
.xin
.report_hook
= trace_report
;
4430 xlate_actions(&trace
.xin
, &trace
.xout
);
4432 ds_put_char(ds
, '\n');
4433 trace_format_flow(ds
, 0, "Final flow", &trace
);
4434 trace_format_megaflow(ds
, 0, "Megaflow", &trace
);
4436 ds_put_cstr(ds
, "Datapath actions: ");
4437 format_odp_actions(ds
, ofpbuf_data(&trace
.xout
.odp_actions
),
4438 ofpbuf_size(&trace
.xout
.odp_actions
));
4440 if (trace
.xout
.slow
) {
4441 enum slow_path_reason slow
;
4443 ds_put_cstr(ds
, "\nThis flow is handled by the userspace "
4444 "slow path because it:");
4446 slow
= trace
.xout
.slow
;
4448 enum slow_path_reason bit
= rightmost_1bit(slow
);
4450 ds_put_format(ds
, "\n\t- %s.",
4451 slow_path_reason_to_explanation(bit
));
4457 xlate_out_uninit(&trace
.xout
);
4461 /* Store the current ofprotos in 'ofproto_shash'. Returns a sorted list
4462 * of the 'ofproto_shash' nodes. It is the responsibility of the caller
4463 * to destroy 'ofproto_shash' and free the returned value. */
4464 static const struct shash_node
**
4465 get_ofprotos(struct shash
*ofproto_shash
)
4467 const struct ofproto_dpif
*ofproto
;
4469 HMAP_FOR_EACH (ofproto
, all_ofproto_dpifs_node
, &all_ofproto_dpifs
) {
4470 char *name
= xasprintf("%s@%s", ofproto
->up
.type
, ofproto
->up
.name
);
4471 shash_add_nocopy(ofproto_shash
, name
, ofproto
);
4474 return shash_sort(ofproto_shash
);
4478 ofproto_unixctl_dpif_dump_dps(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
4479 const char *argv
[] OVS_UNUSED
,
4480 void *aux OVS_UNUSED
)
4482 struct ds ds
= DS_EMPTY_INITIALIZER
;
4483 struct shash ofproto_shash
;
4484 const struct shash_node
**sorted_ofprotos
;
4487 shash_init(&ofproto_shash
);
4488 sorted_ofprotos
= get_ofprotos(&ofproto_shash
);
4489 for (i
= 0; i
< shash_count(&ofproto_shash
); i
++) {
4490 const struct shash_node
*node
= sorted_ofprotos
[i
];
4491 ds_put_format(&ds
, "%s\n", node
->name
);
4494 shash_destroy(&ofproto_shash
);
4495 free(sorted_ofprotos
);
4497 unixctl_command_reply(conn
, ds_cstr(&ds
));
4502 dpif_show_backer(const struct dpif_backer
*backer
, struct ds
*ds
)
4504 const struct shash_node
**ofprotos
;
4505 struct dpif_dp_stats dp_stats
;
4506 struct shash ofproto_shash
;
4509 dpif_get_dp_stats(backer
->dpif
, &dp_stats
);
4511 ds_put_format(ds
, "%s: hit:%"PRIu64
" missed:%"PRIu64
"\n",
4512 dpif_name(backer
->dpif
), dp_stats
.n_hit
, dp_stats
.n_missed
);
4514 shash_init(&ofproto_shash
);
4515 ofprotos
= get_ofprotos(&ofproto_shash
);
4516 for (i
= 0; i
< shash_count(&ofproto_shash
); i
++) {
4517 struct ofproto_dpif
*ofproto
= ofprotos
[i
]->data
;
4518 const struct shash_node
**ports
;
4521 if (ofproto
->backer
!= backer
) {
4525 ds_put_format(ds
, "\t%s:\n", ofproto
->up
.name
);
4527 ports
= shash_sort(&ofproto
->up
.port_by_name
);
4528 for (j
= 0; j
< shash_count(&ofproto
->up
.port_by_name
); j
++) {
4529 const struct shash_node
*node
= ports
[j
];
4530 struct ofport
*ofport
= node
->data
;
4532 odp_port_t odp_port
;
4534 ds_put_format(ds
, "\t\t%s %u/", netdev_get_name(ofport
->netdev
),
4537 odp_port
= ofp_port_to_odp_port(ofproto
, ofport
->ofp_port
);
4538 if (odp_port
!= ODPP_NONE
) {
4539 ds_put_format(ds
, "%"PRIu32
":", odp_port
);
4541 ds_put_cstr(ds
, "none:");
4544 ds_put_format(ds
, " (%s", netdev_get_type(ofport
->netdev
));
4547 if (!netdev_get_config(ofport
->netdev
, &config
)) {
4548 const struct smap_node
**nodes
;
4551 nodes
= smap_sort(&config
);
4552 for (i
= 0; i
< smap_count(&config
); i
++) {
4553 const struct smap_node
*node
= nodes
[i
];
4554 ds_put_format(ds
, "%c %s=%s", i
? ',' : ':',
4555 node
->key
, node
->value
);
4559 smap_destroy(&config
);
4561 ds_put_char(ds
, ')');
4562 ds_put_char(ds
, '\n');
4566 shash_destroy(&ofproto_shash
);
4571 ofproto_unixctl_dpif_show(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
4572 const char *argv
[] OVS_UNUSED
, void *aux OVS_UNUSED
)
4574 struct ds ds
= DS_EMPTY_INITIALIZER
;
4575 const struct shash_node
**backers
;
4578 backers
= shash_sort(&all_dpif_backers
);
4579 for (i
= 0; i
< shash_count(&all_dpif_backers
); i
++) {
4580 dpif_show_backer(backers
[i
]->data
, &ds
);
4584 unixctl_command_reply(conn
, ds_cstr(&ds
));
4589 ofproto_dpif_contains_flow(const struct ofproto_dpif
*ofproto
,
4590 const struct nlattr
*key
, size_t key_len
)
4592 struct ofproto_dpif
*ofp
;
4595 xlate_receive(ofproto
->backer
, NULL
, key
, key_len
, &flow
, &ofp
,
4596 NULL
, NULL
, NULL
, NULL
);
4597 return ofp
== ofproto
;
4601 ofproto_unixctl_dpif_dump_flows(struct unixctl_conn
*conn
,
4602 int argc OVS_UNUSED
, const char *argv
[],
4603 void *aux OVS_UNUSED
)
4605 const struct ofproto_dpif
*ofproto
;
4607 struct ds ds
= DS_EMPTY_INITIALIZER
;
4608 bool verbosity
= false;
4610 struct dpif_port dpif_port
;
4611 struct dpif_port_dump port_dump
;
4612 struct hmap portno_names
;
4614 struct dpif_flow_dump
*flow_dump
;
4615 struct dpif_flow_dump_thread
*flow_dump_thread
;
4619 ofproto
= ofproto_dpif_lookup(argv
[argc
- 1]);
4621 unixctl_command_reply_error(conn
, "no such bridge");
4625 if (argc
> 2 && !strcmp(argv
[1], "-m")) {
4629 hmap_init(&portno_names
);
4630 DPIF_PORT_FOR_EACH (&dpif_port
, &port_dump
, ofproto
->backer
->dpif
) {
4631 odp_portno_names_set(&portno_names
, dpif_port
.port_no
, dpif_port
.name
);
4635 flow_dump
= dpif_flow_dump_create(ofproto
->backer
->dpif
);
4636 flow_dump_thread
= dpif_flow_dump_thread_create(flow_dump
);
4637 while (dpif_flow_dump_next(flow_dump_thread
, &f
, 1)) {
4638 if (!ofproto_dpif_contains_flow(ofproto
, f
.key
, f
.key_len
)) {
4642 odp_flow_format(f
.key
, f
.key_len
, f
.mask
, f
.mask_len
,
4643 &portno_names
, &ds
, verbosity
);
4644 ds_put_cstr(&ds
, ", ");
4645 dpif_flow_stats_format(&f
.stats
, &ds
);
4646 ds_put_cstr(&ds
, ", actions:");
4647 format_odp_actions(&ds
, f
.actions
, f
.actions_len
);
4648 ds_put_char(&ds
, '\n');
4650 dpif_flow_dump_thread_destroy(flow_dump_thread
);
4651 error
= dpif_flow_dump_destroy(flow_dump
);
4655 ds_put_format(&ds
, "dpif/dump_flows failed: %s", ovs_strerror(errno
));
4656 unixctl_command_reply_error(conn
, ds_cstr(&ds
));
4658 unixctl_command_reply(conn
, ds_cstr(&ds
));
4660 odp_portno_names_destroy(&portno_names
);
4661 hmap_destroy(&portno_names
);
4666 ofproto_dpif_unixctl_init(void)
4668 static bool registered
;
4674 unixctl_command_register(
4676 "{[dp_name] odp_flow | bridge br_flow} [-generate|packet]",
4677 1, 3, ofproto_unixctl_trace
, NULL
);
4678 unixctl_command_register(
4679 "ofproto/trace-packet-out",
4680 "[-consistent] {[dp_name] odp_flow | bridge br_flow} [-generate|packet] actions",
4681 2, 6, ofproto_unixctl_trace_actions
, NULL
);
4682 unixctl_command_register("fdb/flush", "[bridge]", 0, 1,
4683 ofproto_unixctl_fdb_flush
, NULL
);
4684 unixctl_command_register("fdb/show", "bridge", 1, 1,
4685 ofproto_unixctl_fdb_show
, NULL
);
4686 unixctl_command_register("mdb/flush", "[bridge]", 0, 1,
4687 ofproto_unixctl_mcast_snooping_flush
, NULL
);
4688 unixctl_command_register("mdb/show", "bridge", 1, 1,
4689 ofproto_unixctl_mcast_snooping_show
, NULL
);
4690 unixctl_command_register("dpif/dump-dps", "", 0, 0,
4691 ofproto_unixctl_dpif_dump_dps
, NULL
);
4692 unixctl_command_register("dpif/show", "", 0, 0, ofproto_unixctl_dpif_show
,
4694 unixctl_command_register("dpif/dump-flows", "[-m] bridge", 1, 2,
4695 ofproto_unixctl_dpif_dump_flows
, NULL
);
4698 /* Returns true if 'table' is the table used for internal rules,
4699 * false otherwise. */
4701 table_is_internal(uint8_t table_id
)
4703 return table_id
== TBL_INTERNAL
;
4706 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
4708 * This is deprecated. It is only for compatibility with broken device drivers
4709 * in old versions of Linux that do not properly support VLANs when VLAN
4710 * devices are not used. When broken device drivers are no longer in
4711 * widespread use, we will delete these interfaces. */
4714 set_realdev(struct ofport
*ofport_
, ofp_port_t realdev_ofp_port
, int vid
)
4716 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(ofport_
->ofproto
);
4717 struct ofport_dpif
*ofport
= ofport_dpif_cast(ofport_
);
4719 if (realdev_ofp_port
== ofport
->realdev_ofp_port
4720 && vid
== ofport
->vlandev_vid
) {
4724 ofproto
->backer
->need_revalidate
= REV_RECONFIGURE
;
4726 if (ofport
->realdev_ofp_port
) {
4729 if (realdev_ofp_port
&& ofport
->bundle
) {
4730 /* vlandevs are enslaved to their realdevs, so they are not allowed to
4731 * themselves be part of a bundle. */
4732 bundle_set(ofport_
->ofproto
, ofport
->bundle
, NULL
);
4735 ofport
->realdev_ofp_port
= realdev_ofp_port
;
4736 ofport
->vlandev_vid
= vid
;
4738 if (realdev_ofp_port
) {
4739 vsp_add(ofport
, realdev_ofp_port
, vid
);
4746 hash_realdev_vid(ofp_port_t realdev_ofp_port
, int vid
)
4748 return hash_2words(ofp_to_u16(realdev_ofp_port
), vid
);
4752 ofproto_has_vlan_splinters(const struct ofproto_dpif
*ofproto
)
4753 OVS_EXCLUDED(ofproto
->vsp_mutex
)
4755 /* hmap_is_empty is thread safe. */
4756 return !hmap_is_empty(&ofproto
->realdev_vid_map
);
4761 vsp_realdev_to_vlandev__(const struct ofproto_dpif
*ofproto
,
4762 ofp_port_t realdev_ofp_port
, ovs_be16 vlan_tci
)
4763 OVS_REQUIRES(ofproto
->vsp_mutex
)
4765 if (!hmap_is_empty(&ofproto
->realdev_vid_map
)) {
4766 int vid
= vlan_tci_to_vid(vlan_tci
);
4767 const struct vlan_splinter
*vsp
;
4769 HMAP_FOR_EACH_WITH_HASH (vsp
, realdev_vid_node
,
4770 hash_realdev_vid(realdev_ofp_port
, vid
),
4771 &ofproto
->realdev_vid_map
) {
4772 if (vsp
->realdev_ofp_port
== realdev_ofp_port
4773 && vsp
->vid
== vid
) {
4774 return vsp
->vlandev_ofp_port
;
4778 return realdev_ofp_port
;
4781 /* Returns the OFP port number of the Linux VLAN device that corresponds to
4782 * 'vlan_tci' on the network device with port number 'realdev_ofp_port' in
4783 * 'struct ofport_dpif'. For example, given 'realdev_ofp_port' of eth0 and
4784 * 'vlan_tci' 9, it would return the port number of eth0.9.
4786 * Unless VLAN splinters are enabled for port 'realdev_ofp_port', this
4787 * function just returns its 'realdev_ofp_port' argument. */
4789 vsp_realdev_to_vlandev(const struct ofproto_dpif
*ofproto
,
4790 ofp_port_t realdev_ofp_port
, ovs_be16 vlan_tci
)
4791 OVS_EXCLUDED(ofproto
->vsp_mutex
)
4795 /* hmap_is_empty is thread safe, see if we can return immediately. */
4796 if (hmap_is_empty(&ofproto
->realdev_vid_map
)) {
4797 return realdev_ofp_port
;
4799 ovs_mutex_lock(&ofproto
->vsp_mutex
);
4800 ret
= vsp_realdev_to_vlandev__(ofproto
, realdev_ofp_port
, vlan_tci
);
4801 ovs_mutex_unlock(&ofproto
->vsp_mutex
);
4805 static struct vlan_splinter
*
4806 vlandev_find(const struct ofproto_dpif
*ofproto
, ofp_port_t vlandev_ofp_port
)
4808 struct vlan_splinter
*vsp
;
4810 HMAP_FOR_EACH_WITH_HASH (vsp
, vlandev_node
,
4811 hash_ofp_port(vlandev_ofp_port
),
4812 &ofproto
->vlandev_map
) {
4813 if (vsp
->vlandev_ofp_port
== vlandev_ofp_port
) {
4821 /* Returns the OpenFlow port number of the "real" device underlying the Linux
4822 * VLAN device with OpenFlow port number 'vlandev_ofp_port' and stores the
4823 * VLAN VID of the Linux VLAN device in '*vid'. For example, given
4824 * 'vlandev_ofp_port' of eth0.9, it would return the OpenFlow port number of
4825 * eth0 and store 9 in '*vid'.
4827 * Returns 0 and does not modify '*vid' if 'vlandev_ofp_port' is not a Linux
4828 * VLAN device. Unless VLAN splinters are enabled, this is what this function
4831 vsp_vlandev_to_realdev(const struct ofproto_dpif
*ofproto
,
4832 ofp_port_t vlandev_ofp_port
, int *vid
)
4833 OVS_REQUIRES(ofproto
->vsp_mutex
)
4835 if (!hmap_is_empty(&ofproto
->vlandev_map
)) {
4836 const struct vlan_splinter
*vsp
;
4838 vsp
= vlandev_find(ofproto
, vlandev_ofp_port
);
4843 return vsp
->realdev_ofp_port
;
4849 /* Given 'flow', a flow representing a packet received on 'ofproto', checks
4850 * whether 'flow->in_port' represents a Linux VLAN device. If so, changes
4851 * 'flow->in_port' to the "real" device backing the VLAN device, sets
4852 * 'flow->vlan_tci' to the VLAN VID, and returns true. Otherwise (which is
4853 * always the case unless VLAN splinters are enabled), returns false without
4854 * making any changes. */
4856 vsp_adjust_flow(const struct ofproto_dpif
*ofproto
, struct flow
*flow
)
4857 OVS_EXCLUDED(ofproto
->vsp_mutex
)
4862 /* hmap_is_empty is thread safe. */
4863 if (hmap_is_empty(&ofproto
->vlandev_map
)) {
4867 ovs_mutex_lock(&ofproto
->vsp_mutex
);
4868 realdev
= vsp_vlandev_to_realdev(ofproto
, flow
->in_port
.ofp_port
, &vid
);
4869 ovs_mutex_unlock(&ofproto
->vsp_mutex
);
4874 /* Cause the flow to be processed as if it came in on the real device with
4875 * the VLAN device's VLAN ID. */
4876 flow
->in_port
.ofp_port
= realdev
;
4877 flow
->vlan_tci
= htons((vid
& VLAN_VID_MASK
) | VLAN_CFI
);
4882 vsp_remove(struct ofport_dpif
*port
)
4884 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(port
->up
.ofproto
);
4885 struct vlan_splinter
*vsp
;
4887 ovs_mutex_lock(&ofproto
->vsp_mutex
);
4888 vsp
= vlandev_find(ofproto
, port
->up
.ofp_port
);
4890 hmap_remove(&ofproto
->vlandev_map
, &vsp
->vlandev_node
);
4891 hmap_remove(&ofproto
->realdev_vid_map
, &vsp
->realdev_vid_node
);
4894 port
->realdev_ofp_port
= 0;
4896 VLOG_ERR("missing vlan device record");
4898 ovs_mutex_unlock(&ofproto
->vsp_mutex
);
4902 vsp_add(struct ofport_dpif
*port
, ofp_port_t realdev_ofp_port
, int vid
)
4904 struct ofproto_dpif
*ofproto
= ofproto_dpif_cast(port
->up
.ofproto
);
4906 ovs_mutex_lock(&ofproto
->vsp_mutex
);
4907 if (!vsp_vlandev_to_realdev(ofproto
, port
->up
.ofp_port
, NULL
)
4908 && (vsp_realdev_to_vlandev__(ofproto
, realdev_ofp_port
, htons(vid
))
4909 == realdev_ofp_port
)) {
4910 struct vlan_splinter
*vsp
;
4912 vsp
= xmalloc(sizeof *vsp
);
4913 vsp
->realdev_ofp_port
= realdev_ofp_port
;
4914 vsp
->vlandev_ofp_port
= port
->up
.ofp_port
;
4917 port
->realdev_ofp_port
= realdev_ofp_port
;
4919 hmap_insert(&ofproto
->vlandev_map
, &vsp
->vlandev_node
,
4920 hash_ofp_port(port
->up
.ofp_port
));
4921 hmap_insert(&ofproto
->realdev_vid_map
, &vsp
->realdev_vid_node
,
4922 hash_realdev_vid(realdev_ofp_port
, vid
));
4924 VLOG_ERR("duplicate vlan device record");
4926 ovs_mutex_unlock(&ofproto
->vsp_mutex
);
4930 ofp_port_to_odp_port(const struct ofproto_dpif
*ofproto
, ofp_port_t ofp_port
)
4932 const struct ofport_dpif
*ofport
= get_ofp_port(ofproto
, ofp_port
);
4933 return ofport
? ofport
->odp_port
: ODPP_NONE
;
4936 struct ofport_dpif
*
4937 odp_port_to_ofport(const struct dpif_backer
*backer
, odp_port_t odp_port
)
4939 struct ofport_dpif
*port
;
4941 ovs_rwlock_rdlock(&backer
->odp_to_ofport_lock
);
4942 HMAP_FOR_EACH_IN_BUCKET (port
, odp_port_node
, hash_odp_port(odp_port
),
4943 &backer
->odp_to_ofport_map
) {
4944 if (port
->odp_port
== odp_port
) {
4945 ovs_rwlock_unlock(&backer
->odp_to_ofport_lock
);
4950 ovs_rwlock_unlock(&backer
->odp_to_ofport_lock
);
4955 odp_port_to_ofp_port(const struct ofproto_dpif
*ofproto
, odp_port_t odp_port
)
4957 struct ofport_dpif
*port
;
4959 port
= odp_port_to_ofport(ofproto
->backer
, odp_port
);
4960 if (port
&& &ofproto
->up
== port
->up
.ofproto
) {
4961 return port
->up
.ofp_port
;
4968 ofproto_dpif_alloc_recirc_id(struct ofproto_dpif
*ofproto
)
4970 struct dpif_backer
*backer
= ofproto
->backer
;
4972 return recirc_id_alloc(backer
->rid_pool
);
4976 ofproto_dpif_free_recirc_id(struct ofproto_dpif
*ofproto
, uint32_t recirc_id
)
4978 struct dpif_backer
*backer
= ofproto
->backer
;
4980 recirc_id_free(backer
->rid_pool
, recirc_id
);
4984 ofproto_dpif_add_internal_flow(struct ofproto_dpif
*ofproto
,
4985 const struct match
*match
, int priority
,
4986 uint16_t idle_timeout
,
4987 const struct ofpbuf
*ofpacts
,
4988 struct rule
**rulep
)
4990 struct ofputil_flow_mod fm
;
4991 struct rule_dpif
*rule
;
4995 fm
.priority
= priority
;
4996 fm
.new_cookie
= htonll(0);
4997 fm
.cookie
= htonll(0);
4998 fm
.cookie_mask
= htonll(0);
4999 fm
.modify_cookie
= false;
5000 fm
.table_id
= TBL_INTERNAL
;
5001 fm
.command
= OFPFC_ADD
;
5002 fm
.idle_timeout
= idle_timeout
;
5003 fm
.hard_timeout
= 0;
5006 fm
.flags
= OFPUTIL_FF_HIDDEN_FIELDS
| OFPUTIL_FF_NO_READONLY
;
5007 fm
.ofpacts
= ofpbuf_data(ofpacts
);
5008 fm
.ofpacts_len
= ofpbuf_size(ofpacts
);
5010 error
= ofproto_flow_mod(&ofproto
->up
, &fm
);
5012 VLOG_ERR_RL(&rl
, "failed to add internal flow (%s)",
5013 ofperr_to_string(error
));
5018 rule
= rule_dpif_lookup_in_table(ofproto
, TBL_INTERNAL
, &fm
.match
.flow
,
5019 &fm
.match
.wc
, false);
5029 ofproto_dpif_delete_internal_flow(struct ofproto_dpif
*ofproto
,
5030 struct match
*match
, int priority
)
5032 struct ofputil_flow_mod fm
;
5036 fm
.priority
= priority
;
5037 fm
.new_cookie
= htonll(0);
5038 fm
.cookie
= htonll(0);
5039 fm
.cookie_mask
= htonll(0);
5040 fm
.modify_cookie
= false;
5041 fm
.table_id
= TBL_INTERNAL
;
5042 fm
.flags
= OFPUTIL_FF_HIDDEN_FIELDS
| OFPUTIL_FF_NO_READONLY
;
5043 fm
.command
= OFPFC_DELETE_STRICT
;
5045 error
= ofproto_flow_mod(&ofproto
->up
, &fm
);
5047 VLOG_ERR_RL(&rl
, "failed to delete internal flow (%s)",
5048 ofperr_to_string(error
));
5055 const struct ofproto_class ofproto_dpif_class
= {
5069 NULL
, /* get_memory_usage. */
5070 type_get_memory_usage
,
5089 port_is_lacp_current
,
5090 NULL
, /* rule_choose_table */
5099 NULL
, /* rule_premodify_actions */
5100 rule_modify_actions
,
5116 get_stp_port_status
,
5124 is_mirror_output_bundle
,
5125 forward_bpdu_changed
,
5126 set_mac_table_config
,
5128 set_mcast_snooping_port
,
5130 NULL
, /* meter_get_features */
5131 NULL
, /* meter_set */
5132 NULL
, /* meter_get */
5133 NULL
, /* meter_del */
5134 group_alloc
, /* group_alloc */
5135 group_construct
, /* group_construct */
5136 group_destruct
, /* group_destruct */
5137 group_dealloc
, /* group_dealloc */
5138 group_modify
, /* group_modify */
5139 group_get_stats
, /* group_get_stats */