1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License. */
16 #include "ofproto-dpif-upcall.h"
24 #include "dynamic-string.h"
26 #include "fail-open.h"
27 #include "guarded-list.h"
33 #include "ofproto-dpif-ipfix.h"
34 #include "ofproto-dpif-sflow.h"
36 #include "poll-loop.h"
39 #define MAX_QUEUE_LENGTH 512
41 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_upcall);
43 COVERAGE_DEFINE(drop_queue_overflow);
44 COVERAGE_DEFINE(upcall_queue_overflow);
45 COVERAGE_DEFINE(fmb_queue_overflow);
46 COVERAGE_DEFINE(fmb_queue_revalidated);
48 /* A thread that processes each upcall handed to it by the dispatcher thread,
49 * forwards the upcall's packet, and then queues it to the main ofproto_dpif
50 * to possibly set up a kernel flow as a cache. */
52 struct udpif *udpif; /* Parent udpif. */
53 pthread_t thread; /* Thread ID. */
55 struct ovs_mutex mutex; /* Mutex guarding the following. */
57 /* Atomic queue of unprocessed upcalls. */
58 struct list upcalls OVS_GUARDED;
59 size_t n_upcalls OVS_GUARDED;
61 bool need_signal; /* Only changed by the dispatcher. */
63 pthread_cond_t wake_cond; /* Wakes 'thread' while holding
67 /* An upcall handler for ofproto_dpif.
69 * udpif is implemented as a "dispatcher" thread that reads upcalls from the
70 * kernel. It processes each upcall just enough to figure out its next
71 * destination. For a "miss" upcall (MISS_UPCALL), this is one of several
72 * "handler" threads (see struct handler). Other upcalls are queued to the
73 * main ofproto_dpif. */
75 struct dpif *dpif; /* Datapath handle. */
76 struct dpif_backer *backer; /* Opaque dpif_backer pointer. */
78 uint32_t secret; /* Random seed for upcall hash. */
80 pthread_t dispatcher; /* Dispatcher thread ID. */
82 struct handler *handlers; /* Upcall handlers. */
85 /* Queues to pass up to ofproto-dpif. */
86 struct guarded_list drop_keys; /* "struct drop key"s. */
87 struct guarded_list fmbs; /* "struct flow_miss_batch"es. */
89 /* Number of times udpif_revalidate() has been called. */
90 atomic_uint reval_seq;
94 struct latch exit_latch; /* Tells child threads to exit. */
98 BAD_UPCALL, /* Some kind of bug somewhere. */
99 MISS_UPCALL, /* A flow miss. */
100 SFLOW_UPCALL, /* sFlow sample. */
101 FLOW_SAMPLE_UPCALL, /* Per-flow sampling. */
102 IPFIX_UPCALL /* Per-bridge sampling. */
106 struct list list_node; /* For queuing upcalls. */
107 struct flow_miss *flow_miss; /* This upcall's flow_miss. */
109 /* Raw upcall plus data for keeping track of the memory backing it. */
110 struct dpif_upcall dpif_upcall; /* As returned by dpif_recv() */
111 struct ofpbuf upcall_buf; /* Owns some data in 'dpif_upcall'. */
112 uint64_t upcall_stub[512 / 8]; /* Buffer to reduce need for malloc(). */
115 static void upcall_destroy(struct upcall *);
117 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
119 static void recv_upcalls(struct udpif *);
120 static void handle_upcalls(struct udpif *, struct list *upcalls);
121 static void miss_destroy(struct flow_miss *);
122 static void *udpif_dispatcher(void *);
123 static void *udpif_upcall_handler(void *);
126 udpif_create(struct dpif_backer *backer, struct dpif *dpif)
128 struct udpif *udpif = xzalloc(sizeof *udpif);
131 udpif->backer = backer;
132 udpif->secret = random_uint32();
133 udpif->wait_seq = seq_create();
134 latch_init(&udpif->exit_latch);
135 guarded_list_init(&udpif->drop_keys);
136 guarded_list_init(&udpif->fmbs);
137 atomic_init(&udpif->reval_seq, 0);
143 udpif_destroy(struct udpif *udpif)
145 struct flow_miss_batch *fmb;
146 struct drop_key *drop_key;
148 udpif_recv_set(udpif, 0, false);
150 while ((drop_key = drop_key_next(udpif))) {
151 drop_key_destroy(drop_key);
154 while ((fmb = flow_miss_batch_next(udpif))) {
155 flow_miss_batch_destroy(fmb);
158 guarded_list_destroy(&udpif->drop_keys);
159 guarded_list_destroy(&udpif->fmbs);
160 latch_destroy(&udpif->exit_latch);
161 seq_destroy(udpif->wait_seq);
165 /* Tells 'udpif' to begin or stop handling flow misses depending on the value
166 * of 'enable'. 'n_handlers' is the number of upcall_handler threads to
167 * create. Passing 'n_handlers' as zero is equivalent to passing 'enable' as
170 udpif_recv_set(struct udpif *udpif, size_t n_handlers, bool enable)
172 n_handlers = enable ? n_handlers : 0;
174 /* Stop the old threads (if any). */
175 if (udpif->handlers && udpif->n_handlers != n_handlers) {
178 latch_set(&udpif->exit_latch);
180 /* Wake the handlers so they can exit. */
181 for (i = 0; i < udpif->n_handlers; i++) {
182 struct handler *handler = &udpif->handlers[i];
184 ovs_mutex_lock(&handler->mutex);
185 xpthread_cond_signal(&handler->wake_cond);
186 ovs_mutex_unlock(&handler->mutex);
189 xpthread_join(udpif->dispatcher, NULL);
190 for (i = 0; i < udpif->n_handlers; i++) {
191 struct handler *handler = &udpif->handlers[i];
192 struct upcall *miss, *next;
194 xpthread_join(handler->thread, NULL);
196 ovs_mutex_lock(&handler->mutex);
197 LIST_FOR_EACH_SAFE (miss, next, list_node, &handler->upcalls) {
198 list_remove(&miss->list_node);
199 upcall_destroy(miss);
201 ovs_mutex_unlock(&handler->mutex);
202 ovs_mutex_destroy(&handler->mutex);
204 xpthread_cond_destroy(&handler->wake_cond);
206 latch_poll(&udpif->exit_latch);
208 free(udpif->handlers);
209 udpif->handlers = NULL;
210 udpif->n_handlers = 0;
213 /* Start new threads (if necessary). */
214 if (!udpif->handlers && n_handlers) {
217 udpif->n_handlers = n_handlers;
218 udpif->handlers = xzalloc(udpif->n_handlers * sizeof *udpif->handlers);
219 for (i = 0; i < udpif->n_handlers; i++) {
220 struct handler *handler = &udpif->handlers[i];
222 handler->udpif = udpif;
223 list_init(&handler->upcalls);
224 handler->need_signal = false;
225 xpthread_cond_init(&handler->wake_cond, NULL);
226 ovs_mutex_init(&handler->mutex);
227 xpthread_create(&handler->thread, NULL, udpif_upcall_handler,
230 xpthread_create(&udpif->dispatcher, NULL, udpif_dispatcher, udpif);
235 udpif_wait(struct udpif *udpif)
237 uint64_t seq = seq_read(udpif->wait_seq);
238 if (!guarded_list_is_empty(&udpif->drop_keys) ||
239 !guarded_list_is_empty(&udpif->fmbs)) {
240 poll_immediate_wake();
242 seq_wait(udpif->wait_seq, seq);
246 /* Notifies 'udpif' that something changed which may render previous
247 * xlate_actions() results invalid. */
249 udpif_revalidate(struct udpif *udpif)
251 struct flow_miss_batch *fmb, *next_fmb;
255 /* Since we remove each miss on revalidation, their statistics won't be
256 * accounted to the appropriate 'facet's in the upper layer. In most
257 * cases, this is alright because we've already pushed the stats to the
258 * relevant rules. However, NetFlow requires absolute packet counts on
259 * 'facet's which could now be incorrect. */
260 atomic_add(&udpif->reval_seq, 1, &junk);
262 guarded_list_pop_all(&udpif->fmbs, &fmbs);
263 LIST_FOR_EACH_SAFE (fmb, next_fmb, list_node, &fmbs) {
264 list_remove(&fmb->list_node);
265 flow_miss_batch_destroy(fmb);
268 udpif_drop_key_clear(udpif);
271 /* Destroys and deallocates 'upcall'. */
273 upcall_destroy(struct upcall *upcall)
276 ofpbuf_uninit(&upcall->upcall_buf);
281 /* Retrieves the next batch of processed flow misses for 'udpif' to install.
282 * The caller is responsible for destroying it with flow_miss_batch_destroy().
284 struct flow_miss_batch *
285 flow_miss_batch_next(struct udpif *udpif)
289 for (i = 0; i < 50; i++) {
290 struct flow_miss_batch *next;
291 unsigned int reval_seq;
292 struct list *next_node;
294 next_node = guarded_list_pop_front(&udpif->fmbs);
299 next = CONTAINER_OF(next_node, struct flow_miss_batch, list_node);
300 atomic_read(&udpif->reval_seq, &reval_seq);
301 if (next->reval_seq == reval_seq) {
305 flow_miss_batch_destroy(next);
311 /* Destroys and deallocates 'fmb'. */
313 flow_miss_batch_destroy(struct flow_miss_batch *fmb)
315 struct flow_miss *miss, *next;
316 struct upcall *upcall, *next_upcall;
322 HMAP_FOR_EACH_SAFE (miss, next, hmap_node, &fmb->misses) {
323 hmap_remove(&fmb->misses, &miss->hmap_node);
327 LIST_FOR_EACH_SAFE (upcall, next_upcall, list_node, &fmb->upcalls) {
328 list_remove(&upcall->list_node);
329 upcall_destroy(upcall);
332 hmap_destroy(&fmb->misses);
336 /* Retrieves the next drop key which ofproto-dpif needs to process. The caller
337 * is responsible for destroying it with drop_key_destroy(). */
339 drop_key_next(struct udpif *udpif)
341 struct list *next = guarded_list_pop_front(&udpif->drop_keys);
342 return next ? CONTAINER_OF(next, struct drop_key, list_node) : NULL;
345 /* Destroys and deallocates 'drop_key'. */
347 drop_key_destroy(struct drop_key *drop_key)
355 /* Clears all drop keys waiting to be processed by drop_key_next(). */
357 udpif_drop_key_clear(struct udpif *udpif)
359 struct drop_key *drop_key, *next;
362 guarded_list_pop_all(&udpif->drop_keys, &list);
363 LIST_FOR_EACH_SAFE (drop_key, next, list_node, &list) {
364 list_remove(&drop_key->list_node);
365 drop_key_destroy(drop_key);
369 /* The dispatcher thread is responsible for receiving upcalls from the kernel,
370 * assigning them to a upcall_handler thread. */
372 udpif_dispatcher(void *arg)
374 struct udpif *udpif = arg;
376 set_subprogram_name("dispatcher");
377 while (!latch_is_set(&udpif->exit_latch)) {
379 dpif_recv_wait(udpif->dpif);
380 latch_wait(&udpif->exit_latch);
387 /* The miss handler thread is responsible for processing miss upcalls retrieved
388 * by the dispatcher thread. Once finished it passes the processed miss
389 * upcalls to ofproto-dpif where they're installed in the datapath. */
391 udpif_upcall_handler(void *arg)
393 struct handler *handler = arg;
395 set_subprogram_name("upcall_%u", ovsthread_id_self());
397 struct list misses = LIST_INITIALIZER(&misses);
400 ovs_mutex_lock(&handler->mutex);
402 if (latch_is_set(&handler->udpif->exit_latch)) {
403 ovs_mutex_unlock(&handler->mutex);
407 if (!handler->n_upcalls) {
408 ovs_mutex_cond_wait(&handler->wake_cond, &handler->mutex);
411 for (i = 0; i < FLOW_MISS_MAX_BATCH; i++) {
412 if (handler->n_upcalls) {
413 handler->n_upcalls--;
414 list_push_back(&misses, list_pop_front(&handler->upcalls));
419 ovs_mutex_unlock(&handler->mutex);
421 handle_upcalls(handler->udpif, &misses);
428 miss_destroy(struct flow_miss *miss)
430 xlate_out_uninit(&miss->xout);
433 static enum upcall_type
434 classify_upcall(const struct upcall *upcall)
436 const struct dpif_upcall *dpif_upcall = &upcall->dpif_upcall;
437 union user_action_cookie cookie;
440 /* First look at the upcall type. */
441 switch (dpif_upcall->type) {
448 case DPIF_N_UC_TYPES:
450 VLOG_WARN_RL(&rl, "upcall has unexpected type %"PRIu32,
455 /* "action" upcalls need a closer look. */
456 if (!dpif_upcall->userdata) {
457 VLOG_WARN_RL(&rl, "action upcall missing cookie");
460 userdata_len = nl_attr_get_size(dpif_upcall->userdata);
461 if (userdata_len < sizeof cookie.type
462 || userdata_len > sizeof cookie) {
463 VLOG_WARN_RL(&rl, "action upcall cookie has unexpected size %"PRIuSIZE,
467 memset(&cookie, 0, sizeof cookie);
468 memcpy(&cookie, nl_attr_get(dpif_upcall->userdata), userdata_len);
469 if (userdata_len == sizeof cookie.sflow
470 && cookie.type == USER_ACTION_COOKIE_SFLOW) {
472 } else if (userdata_len == sizeof cookie.slow_path
473 && cookie.type == USER_ACTION_COOKIE_SLOW_PATH) {
475 } else if (userdata_len == sizeof cookie.flow_sample
476 && cookie.type == USER_ACTION_COOKIE_FLOW_SAMPLE) {
477 return FLOW_SAMPLE_UPCALL;
478 } else if (userdata_len == sizeof cookie.ipfix
479 && cookie.type == USER_ACTION_COOKIE_IPFIX) {
482 VLOG_WARN_RL(&rl, "invalid user cookie of type %"PRIu16
483 " and size %"PRIuSIZE, cookie.type, userdata_len);
489 recv_upcalls(struct udpif *udpif)
494 uint32_t hash = udpif->secret;
495 struct handler *handler;
496 struct upcall *upcall;
497 size_t n_bytes, left;
501 upcall = xmalloc(sizeof *upcall);
502 ofpbuf_use_stub(&upcall->upcall_buf, upcall->upcall_stub,
503 sizeof upcall->upcall_stub);
504 error = dpif_recv(udpif->dpif, &upcall->dpif_upcall,
505 &upcall->upcall_buf);
507 upcall_destroy(upcall);
512 NL_ATTR_FOR_EACH (nla, left, upcall->dpif_upcall.key,
513 upcall->dpif_upcall.key_len) {
514 enum ovs_key_attr type = nl_attr_type(nla);
515 if (type == OVS_KEY_ATTR_IN_PORT
516 || type == OVS_KEY_ATTR_TCP
517 || type == OVS_KEY_ATTR_UDP) {
518 if (nl_attr_get_size(nla) == 4) {
519 hash = mhash_add(hash, nl_attr_get_u32(nla));
523 "Netlink attribute with incorrect size.");
527 hash = mhash_finish(hash, n_bytes);
529 handler = &udpif->handlers[hash % udpif->n_handlers];
531 ovs_mutex_lock(&handler->mutex);
532 if (handler->n_upcalls < MAX_QUEUE_LENGTH) {
533 list_push_back(&handler->upcalls, &upcall->list_node);
534 if (handler->n_upcalls == 0) {
535 handler->need_signal = true;
537 handler->n_upcalls++;
538 if (handler->need_signal &&
539 handler->n_upcalls >= FLOW_MISS_MAX_BATCH) {
540 handler->need_signal = false;
541 xpthread_cond_signal(&handler->wake_cond);
543 ovs_mutex_unlock(&handler->mutex);
544 if (!VLOG_DROP_DBG(&rl)) {
545 struct ds ds = DS_EMPTY_INITIALIZER;
547 odp_flow_key_format(upcall->dpif_upcall.key,
548 upcall->dpif_upcall.key_len,
550 VLOG_DBG("dispatcher: enqueue (%s)", ds_cstr(&ds));
554 ovs_mutex_unlock(&handler->mutex);
555 COVERAGE_INC(upcall_queue_overflow);
556 upcall_destroy(upcall);
560 for (n = 0; n < udpif->n_handlers; ++n) {
561 struct handler *handler = &udpif->handlers[n];
563 if (handler->need_signal) {
564 handler->need_signal = false;
565 ovs_mutex_lock(&handler->mutex);
566 xpthread_cond_signal(&handler->wake_cond);
567 ovs_mutex_unlock(&handler->mutex);
572 static struct flow_miss *
573 flow_miss_find(struct hmap *todo, const struct ofproto_dpif *ofproto,
574 const struct flow *flow, uint32_t hash)
576 struct flow_miss *miss;
578 HMAP_FOR_EACH_WITH_HASH (miss, hmap_node, hash, todo) {
579 if (miss->ofproto == ofproto && flow_equal(&miss->flow, flow)) {
588 handle_upcalls(struct udpif *udpif, struct list *upcalls)
590 struct dpif_op *opsp[FLOW_MISS_MAX_BATCH];
591 struct dpif_op ops[FLOW_MISS_MAX_BATCH];
592 struct upcall *upcall, *next;
593 struct flow_miss_batch *fmb;
594 size_t n_misses, n_ops, i;
595 struct flow_miss *miss;
596 unsigned int reval_seq;
597 enum upcall_type type;
600 /* Extract the flow from each upcall. Construct in fmb->misses a hash
601 * table that maps each unique flow to a 'struct flow_miss'.
603 * Most commonly there is a single packet per flow_miss, but there are
604 * several reasons why there might be more than one, e.g.:
606 * - The dpif packet interface does not support TSO (or UFO, etc.), so a
607 * large packet sent to userspace is split into a sequence of smaller
610 * - A stream of quickly arriving packets in an established "slow-pathed"
613 * - Rarely, a stream of quickly arriving packets in a flow not yet
614 * established. (This is rare because most protocols do not send
615 * multiple back-to-back packets before receiving a reply from the
616 * other end of the connection, which gives OVS a chance to set up a
619 fmb = xmalloc(sizeof *fmb);
620 atomic_read(&udpif->reval_seq, &fmb->reval_seq);
621 hmap_init(&fmb->misses);
622 list_init(&fmb->upcalls);
624 LIST_FOR_EACH_SAFE (upcall, next, list_node, upcalls) {
625 struct dpif_upcall *dupcall = &upcall->dpif_upcall;
626 struct ofpbuf *packet = dupcall->packet;
627 struct flow_miss *miss = &fmb->miss_buf[n_misses];
628 struct flow_miss *existing_miss;
629 struct ofproto_dpif *ofproto;
630 struct dpif_sflow *sflow;
631 struct dpif_ipfix *ipfix;
632 odp_port_t odp_in_port;
636 error = xlate_receive(udpif->backer, packet, dupcall->key,
637 dupcall->key_len, &flow, &miss->key_fitness,
638 &ofproto, &odp_in_port);
640 if (error == ENODEV) {
641 struct drop_key *drop_key;
643 /* Received packet on datapath port for which we couldn't
644 * associate an ofproto. This can happen if a port is removed
645 * while traffic is being received. Print a rate-limited
646 * message in case it happens frequently. Install a drop flow
647 * so that future packets of the flow are inexpensively dropped
649 VLOG_INFO_RL(&rl, "received packet on unassociated datapath "
650 "port %"PRIu32, odp_in_port);
652 drop_key = xmalloc(sizeof *drop_key);
653 drop_key->key = xmemdup(dupcall->key, dupcall->key_len);
654 drop_key->key_len = dupcall->key_len;
656 if (guarded_list_push_back(&udpif->drop_keys,
657 &drop_key->list_node,
659 seq_change(udpif->wait_seq);
661 COVERAGE_INC(drop_queue_overflow);
662 drop_key_destroy(drop_key);
665 list_remove(&upcall->list_node);
666 upcall_destroy(upcall);
670 type = classify_upcall(upcall);
671 if (type == MISS_UPCALL) {
674 flow_extract(packet, flow.skb_priority, flow.pkt_mark,
675 &flow.tunnel, &flow.in_port, &miss->flow);
677 hash = flow_hash(&miss->flow, 0);
678 existing_miss = flow_miss_find(&fmb->misses, ofproto, &miss->flow,
680 if (!existing_miss) {
681 hmap_insert(&fmb->misses, &miss->hmap_node, hash);
682 miss->ofproto = ofproto;
683 miss->key = dupcall->key;
684 miss->key_len = dupcall->key_len;
685 miss->upcall_type = dupcall->type;
686 miss->stats.n_packets = 0;
687 miss->stats.n_bytes = 0;
688 miss->stats.used = time_msec();
689 miss->stats.tcp_flags = 0;
693 miss = existing_miss;
695 miss->stats.tcp_flags |= packet_get_tcp_flags(packet, &miss->flow);
696 miss->stats.n_bytes += packet->size;
697 miss->stats.n_packets++;
699 upcall->flow_miss = miss;
705 sflow = xlate_get_sflow(ofproto);
707 union user_action_cookie cookie;
709 memset(&cookie, 0, sizeof cookie);
710 memcpy(&cookie, nl_attr_get(dupcall->userdata),
711 sizeof cookie.sflow);
712 dpif_sflow_received(sflow, dupcall->packet, &flow, odp_in_port,
714 dpif_sflow_unref(sflow);
718 ipfix = xlate_get_ipfix(ofproto);
720 dpif_ipfix_bridge_sample(ipfix, dupcall->packet, &flow);
721 dpif_ipfix_unref(ipfix);
724 case FLOW_SAMPLE_UPCALL:
725 ipfix = xlate_get_ipfix(ofproto);
727 union user_action_cookie cookie;
729 memset(&cookie, 0, sizeof cookie);
730 memcpy(&cookie, nl_attr_get(dupcall->userdata),
731 sizeof cookie.flow_sample);
733 /* The flow reflects exactly the contents of the packet.
734 * Sample the packet using it. */
735 dpif_ipfix_flow_sample(ipfix, dupcall->packet, &flow,
736 cookie.flow_sample.collector_set_id,
737 cookie.flow_sample.probability,
738 cookie.flow_sample.obs_domain_id,
739 cookie.flow_sample.obs_point_id);
740 dpif_ipfix_unref(ipfix);
749 list_remove(&upcall->list_node);
750 upcall_destroy(upcall);
753 /* Initialize each 'struct flow_miss's ->xout.
755 * We do this per-flow_miss rather than per-packet because, most commonly,
756 * all the packets in a flow can use the same translation.
758 * We can't do this in the previous loop because we need the TCP flags for
759 * all the packets in each miss. */
761 HMAP_FOR_EACH (miss, hmap_node, &fmb->misses) {
764 xlate_in_init(&xin, miss->ofproto, &miss->flow, NULL,
765 miss->stats.tcp_flags, NULL);
766 xin.may_learn = true;
767 xin.resubmit_stats = &miss->stats;
768 xlate_actions(&xin, &miss->xout);
769 fail_open = fail_open || miss->xout.fail_open;
772 /* Now handle the packets individually in order of arrival. In the common
773 * case each packet of a miss can share the same actions, but slow-pathed
774 * packets need to be translated individually:
776 * - For SLOW_CFM, SLOW_LACP, SLOW_STP, and SLOW_BFD, translation is what
777 * processes received packets for these protocols.
779 * - For SLOW_CONTROLLER, translation sends the packet to the OpenFlow
782 * The loop fills 'ops' with an array of operations to execute in the
785 LIST_FOR_EACH (upcall, list_node, upcalls) {
786 struct flow_miss *miss = upcall->flow_miss;
787 struct ofpbuf *packet = upcall->dpif_upcall.packet;
789 if (miss->xout.slow) {
792 xlate_in_init(&xin, miss->ofproto, &miss->flow, NULL, 0, packet);
793 xlate_actions_for_side_effects(&xin);
796 if (miss->xout.odp_actions.size) {
799 if (miss->flow.in_port.ofp_port
800 != vsp_realdev_to_vlandev(miss->ofproto,
801 miss->flow.in_port.ofp_port,
802 miss->flow.vlan_tci)) {
803 /* This packet was received on a VLAN splinter port. We
804 * added a VLAN to the packet to make the packet resemble
805 * the flow, but the actions were composed assuming that
806 * the packet contained no VLAN. So, we must remove the
807 * VLAN header from the packet before trying to execute the
809 eth_pop_vlan(packet);
813 op->type = DPIF_OP_EXECUTE;
814 op->u.execute.key = miss->key;
815 op->u.execute.key_len = miss->key_len;
816 op->u.execute.packet = packet;
817 op->u.execute.actions = miss->xout.odp_actions.data;
818 op->u.execute.actions_len = miss->xout.odp_actions.size;
819 op->u.execute.needs_help = (miss->xout.slow & SLOW_ACTION) != 0;
824 for (i = 0; i < n_ops; i++) {
827 dpif_operate(udpif->dpif, opsp, n_ops);
829 /* Special case for fail-open mode.
831 * If we are in fail-open mode, but we are connected to a controller too,
832 * then we should send the packet up to the controller in the hope that it
833 * will try to set up a flow and thereby allow us to exit fail-open.
835 * See the top-level comment in fail-open.c for more information. */
837 LIST_FOR_EACH (upcall, list_node, upcalls) {
838 struct flow_miss *miss = upcall->flow_miss;
839 struct ofpbuf *packet = upcall->dpif_upcall.packet;
840 struct ofproto_packet_in *pin;
842 pin = xmalloc(sizeof *pin);
843 pin->up.packet = xmemdup(packet->data, packet->size);
844 pin->up.packet_len = packet->size;
845 pin->up.reason = OFPR_NO_MATCH;
846 pin->up.table_id = 0;
847 pin->up.cookie = OVS_BE64_MAX;
848 flow_get_metadata(&miss->flow, &pin->up.fmd);
849 pin->send_len = 0; /* Not used for flow table misses. */
850 pin->generated_by_table_miss = false;
851 ofproto_dpif_send_packet_in(miss->ofproto, pin);
855 list_move(&fmb->upcalls, upcalls);
857 atomic_read(&udpif->reval_seq, &reval_seq);
858 if (reval_seq != fmb->reval_seq) {
859 COVERAGE_INC(fmb_queue_revalidated);
860 flow_miss_batch_destroy(fmb);
861 } else if (!guarded_list_push_back(&udpif->fmbs, &fmb->list_node,
863 COVERAGE_INC(fmb_queue_overflow);
864 flow_miss_batch_destroy(fmb);
866 seq_change(udpif->wait_seq);