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"
23 #include "dynamic-string.h"
25 #include "fail-open.h"
26 #include "guarded-list.h"
32 #include "ofproto-dpif-ipfix.h"
33 #include "ofproto-dpif-sflow.h"
34 #include "ofproto-dpif.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 size_t n_new_upcalls; /* Only changed by the dispatcher. */
62 bool need_signal; /* Only changed by the dispatcher. */
64 pthread_cond_t wake_cond; /* Wakes 'thread' while holding
68 /* An upcall handler for ofproto_dpif.
70 * udpif is implemented as a "dispatcher" thread that reads upcalls from the
71 * kernel. It processes each upcall just enough to figure out its next
72 * destination. For a "miss" upcall (MISS_UPCALL), this is one of several
73 * "handler" threads (see struct handler). Other upcalls are queued to the
74 * main ofproto_dpif. */
76 struct dpif *dpif; /* Datapath handle. */
77 struct dpif_backer *backer; /* Opaque dpif_backer pointer. */
79 uint32_t secret; /* Random seed for upcall hash. */
81 pthread_t dispatcher; /* Dispatcher thread ID. */
83 struct handler *handlers; /* Upcall handlers. */
86 /* Queues to pass up to ofproto-dpif. */
87 struct guarded_list drop_keys; /* "struct drop key"s. */
88 struct guarded_list fmbs; /* "struct flow_miss_batch"es. */
90 /* Number of times udpif_revalidate() has been called. */
91 atomic_uint reval_seq;
95 struct latch exit_latch; /* Tells child threads to exit. */
99 BAD_UPCALL, /* Some kind of bug somewhere. */
100 MISS_UPCALL, /* A flow miss. */
101 SFLOW_UPCALL, /* sFlow sample. */
102 FLOW_SAMPLE_UPCALL, /* Per-flow sampling. */
103 IPFIX_UPCALL /* Per-bridge sampling. */
107 struct list list_node; /* For queuing upcalls. */
108 struct flow_miss *flow_miss; /* This upcall's flow_miss. */
110 /* Raw upcall plus data for keeping track of the memory backing it. */
111 struct dpif_upcall dpif_upcall; /* As returned by dpif_recv() */
112 struct ofpbuf upcall_buf; /* Owns some data in 'dpif_upcall'. */
113 uint64_t upcall_stub[512 / 8]; /* Buffer to reduce need for malloc(). */
116 static void upcall_destroy(struct upcall *);
118 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
120 static void recv_upcalls(struct udpif *);
121 static void handle_upcalls(struct udpif *, struct list *upcalls);
122 static void miss_destroy(struct flow_miss *);
123 static void *udpif_dispatcher(void *);
124 static void *udpif_upcall_handler(void *);
127 udpif_create(struct dpif_backer *backer, struct dpif *dpif)
129 struct udpif *udpif = xzalloc(sizeof *udpif);
132 udpif->backer = backer;
133 udpif->secret = random_uint32();
134 udpif->wait_seq = seq_create();
135 latch_init(&udpif->exit_latch);
136 guarded_list_init(&udpif->drop_keys);
137 guarded_list_init(&udpif->fmbs);
138 atomic_init(&udpif->reval_seq, 0);
144 udpif_destroy(struct udpif *udpif)
146 struct flow_miss_batch *fmb;
147 struct drop_key *drop_key;
149 udpif_recv_set(udpif, 0, false);
151 while ((drop_key = drop_key_next(udpif))) {
152 drop_key_destroy(drop_key);
155 while ((fmb = flow_miss_batch_next(udpif))) {
156 flow_miss_batch_destroy(fmb);
159 guarded_list_destroy(&udpif->drop_keys);
160 guarded_list_destroy(&udpif->fmbs);
161 latch_destroy(&udpif->exit_latch);
162 seq_destroy(udpif->wait_seq);
166 /* Tells 'udpif' to begin or stop handling flow misses depending on the value
167 * of 'enable'. 'n_handlers' is the number of upcall_handler threads to
168 * create. Passing 'n_handlers' as zero is equivalent to passing 'enable' as
171 udpif_recv_set(struct udpif *udpif, size_t n_handlers, bool enable)
173 n_handlers = enable ? n_handlers : 0;
174 n_handlers = MIN(n_handlers, 64);
176 /* Stop the old threads (if any). */
177 if (udpif->handlers && udpif->n_handlers != n_handlers) {
180 latch_set(&udpif->exit_latch);
182 /* Wake the handlers so they can exit. */
183 for (i = 0; i < udpif->n_handlers; i++) {
184 struct handler *handler = &udpif->handlers[i];
186 ovs_mutex_lock(&handler->mutex);
187 xpthread_cond_signal(&handler->wake_cond);
188 ovs_mutex_unlock(&handler->mutex);
191 xpthread_join(udpif->dispatcher, NULL);
192 for (i = 0; i < udpif->n_handlers; i++) {
193 struct handler *handler = &udpif->handlers[i];
194 struct upcall *miss, *next;
196 xpthread_join(handler->thread, NULL);
198 ovs_mutex_lock(&handler->mutex);
199 LIST_FOR_EACH_SAFE (miss, next, list_node, &handler->upcalls) {
200 list_remove(&miss->list_node);
201 upcall_destroy(miss);
203 ovs_mutex_unlock(&handler->mutex);
204 ovs_mutex_destroy(&handler->mutex);
206 xpthread_cond_destroy(&handler->wake_cond);
208 latch_poll(&udpif->exit_latch);
210 free(udpif->handlers);
211 udpif->handlers = NULL;
212 udpif->n_handlers = 0;
215 /* Start new threads (if necessary). */
216 if (!udpif->handlers && n_handlers) {
219 udpif->n_handlers = n_handlers;
220 udpif->handlers = xzalloc(udpif->n_handlers * sizeof *udpif->handlers);
221 for (i = 0; i < udpif->n_handlers; i++) {
222 struct handler *handler = &udpif->handlers[i];
224 handler->udpif = udpif;
225 list_init(&handler->upcalls);
226 handler->need_signal = false;
227 xpthread_cond_init(&handler->wake_cond, NULL);
228 ovs_mutex_init(&handler->mutex);
229 xpthread_create(&handler->thread, NULL, udpif_upcall_handler,
232 xpthread_create(&udpif->dispatcher, NULL, udpif_dispatcher, udpif);
237 udpif_wait(struct udpif *udpif)
239 uint64_t seq = seq_read(udpif->wait_seq);
240 if (!guarded_list_is_empty(&udpif->drop_keys) ||
241 !guarded_list_is_empty(&udpif->fmbs)) {
242 poll_immediate_wake();
244 seq_wait(udpif->wait_seq, seq);
248 /* Notifies 'udpif' that something changed which may render previous
249 * xlate_actions() results invalid. */
251 udpif_revalidate(struct udpif *udpif)
253 struct flow_miss_batch *fmb, *next_fmb;
257 /* Since we remove each miss on revalidation, their statistics won't be
258 * accounted to the appropriate 'facet's in the upper layer. In most
259 * cases, this is alright because we've already pushed the stats to the
260 * relevant rules. However, NetFlow requires absolute packet counts on
261 * 'facet's which could now be incorrect. */
262 atomic_add(&udpif->reval_seq, 1, &junk);
264 guarded_list_pop_all(&udpif->fmbs, &fmbs);
265 LIST_FOR_EACH_SAFE (fmb, next_fmb, list_node, &fmbs) {
266 list_remove(&fmb->list_node);
267 flow_miss_batch_destroy(fmb);
270 udpif_drop_key_clear(udpif);
273 /* Destroys and deallocates 'upcall'. */
275 upcall_destroy(struct upcall *upcall)
278 ofpbuf_uninit(&upcall->upcall_buf);
283 /* Retrieves the next batch of processed flow misses for 'udpif' to install.
284 * The caller is responsible for destroying it with flow_miss_batch_destroy().
286 struct flow_miss_batch *
287 flow_miss_batch_next(struct udpif *udpif)
291 for (i = 0; i < 50; i++) {
292 struct flow_miss_batch *next;
293 unsigned int reval_seq;
294 struct list *next_node;
296 next_node = guarded_list_pop_front(&udpif->fmbs);
301 next = CONTAINER_OF(next_node, struct flow_miss_batch, list_node);
302 atomic_read(&udpif->reval_seq, &reval_seq);
303 if (next->reval_seq == reval_seq) {
307 flow_miss_batch_destroy(next);
313 /* Destroys and deallocates 'fmb'. */
315 flow_miss_batch_destroy(struct flow_miss_batch *fmb)
317 struct flow_miss *miss, *next;
318 struct upcall *upcall, *next_upcall;
324 HMAP_FOR_EACH_SAFE (miss, next, hmap_node, &fmb->misses) {
325 hmap_remove(&fmb->misses, &miss->hmap_node);
329 LIST_FOR_EACH_SAFE (upcall, next_upcall, list_node, &fmb->upcalls) {
330 list_remove(&upcall->list_node);
331 upcall_destroy(upcall);
334 hmap_destroy(&fmb->misses);
338 /* Retrieves the next drop key which ofproto-dpif needs to process. The caller
339 * is responsible for destroying it with drop_key_destroy(). */
341 drop_key_next(struct udpif *udpif)
343 struct list *next = guarded_list_pop_front(&udpif->drop_keys);
344 return next ? CONTAINER_OF(next, struct drop_key, list_node) : NULL;
347 /* Destroys and deallocates 'drop_key'. */
349 drop_key_destroy(struct drop_key *drop_key)
357 /* Clears all drop keys waiting to be processed by drop_key_next(). */
359 udpif_drop_key_clear(struct udpif *udpif)
361 struct drop_key *drop_key, *next;
364 guarded_list_pop_all(&udpif->drop_keys, &list);
365 LIST_FOR_EACH_SAFE (drop_key, next, list_node, &list) {
366 list_remove(&drop_key->list_node);
367 drop_key_destroy(drop_key);
371 /* The dispatcher thread is responsible for receiving upcalls from the kernel,
372 * assigning them to a upcall_handler thread. */
374 udpif_dispatcher(void *arg)
376 struct udpif *udpif = arg;
378 set_subprogram_name("dispatcher");
379 while (!latch_is_set(&udpif->exit_latch)) {
381 dpif_recv_wait(udpif->dpif);
382 latch_wait(&udpif->exit_latch);
389 /* The miss handler thread is responsible for processing miss upcalls retrieved
390 * by the dispatcher thread. Once finished it passes the processed miss
391 * upcalls to ofproto-dpif where they're installed in the datapath. */
393 udpif_upcall_handler(void *arg)
395 struct handler *handler = arg;
397 set_subprogram_name("upcall_handler");
399 struct list misses = LIST_INITIALIZER(&misses);
402 ovs_mutex_lock(&handler->mutex);
404 if (latch_is_set(&handler->udpif->exit_latch)) {
405 ovs_mutex_unlock(&handler->mutex);
409 if (!handler->n_upcalls) {
410 ovs_mutex_cond_wait(&handler->wake_cond, &handler->mutex);
413 for (i = 0; i < FLOW_MISS_MAX_BATCH; i++) {
414 if (handler->n_upcalls) {
415 handler->n_upcalls--;
416 list_push_back(&misses, list_pop_front(&handler->upcalls));
421 ovs_mutex_unlock(&handler->mutex);
423 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 %zu",
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 %zu", cookie.type, userdata_len);
489 recv_upcalls(struct udpif *udpif)
491 size_t n_udpif_new_upcalls = 0;
495 uint32_t hash = udpif->secret;
496 struct handler *handler;
497 struct upcall *upcall;
498 size_t n_bytes, left;
502 upcall = xmalloc(sizeof *upcall);
503 ofpbuf_use_stub(&upcall->upcall_buf, upcall->upcall_stub,
504 sizeof upcall->upcall_stub);
505 error = dpif_recv(udpif->dpif, &upcall->dpif_upcall,
506 &upcall->upcall_buf);
508 upcall_destroy(upcall);
513 NL_ATTR_FOR_EACH (nla, left, upcall->dpif_upcall.key,
514 upcall->dpif_upcall.key_len) {
515 enum ovs_key_attr type = nl_attr_type(nla);
516 if (type == OVS_KEY_ATTR_IN_PORT
517 || type == OVS_KEY_ATTR_TCP
518 || type == OVS_KEY_ATTR_UDP) {
519 if (nl_attr_get_size(nla) == 4) {
520 hash = mhash_add(hash, nl_attr_get_u32(nla));
524 "Netlink attribute with incorrect size.");
528 hash = mhash_finish(hash, n_bytes);
530 handler = &udpif->handlers[hash % udpif->n_handlers];
532 ovs_mutex_lock(&handler->mutex);
533 if (handler->n_upcalls < MAX_QUEUE_LENGTH) {
534 list_push_back(&handler->upcalls, &upcall->list_node);
535 if (handler->n_upcalls == 0) {
536 handler->need_signal = true;
538 handler->n_upcalls++;
539 if (handler->need_signal &&
540 handler->n_upcalls >= FLOW_MISS_MAX_BATCH) {
541 handler->need_signal = false;
542 xpthread_cond_signal(&handler->wake_cond);
544 ovs_mutex_unlock(&handler->mutex);
545 if (!VLOG_DROP_DBG(&rl)) {
546 struct ds ds = DS_EMPTY_INITIALIZER;
548 odp_flow_key_format(upcall->dpif_upcall.key,
549 upcall->dpif_upcall.key_len,
551 VLOG_DBG("dispatcher: enqueue (%s)", ds_cstr(&ds));
555 ovs_mutex_unlock(&handler->mutex);
556 COVERAGE_INC(upcall_queue_overflow);
557 upcall_destroy(upcall);
561 for (n = 0; n < udpif->n_handlers; ++n) {
562 struct handler *handler = &udpif->handlers[n];
564 if (handler->need_signal) {
565 handler->need_signal = false;
566 ovs_mutex_lock(&handler->mutex);
567 xpthread_cond_signal(&handler->wake_cond);
568 ovs_mutex_unlock(&handler->mutex);
571 if (n_udpif_new_upcalls) {
572 seq_change(udpif->wait_seq);
576 static struct flow_miss *
577 flow_miss_find(struct hmap *todo, const struct ofproto_dpif *ofproto,
578 const struct flow *flow, uint32_t hash)
580 struct flow_miss *miss;
582 HMAP_FOR_EACH_WITH_HASH (miss, hmap_node, hash, todo) {
583 if (miss->ofproto == ofproto && flow_equal(&miss->flow, flow)) {
592 handle_upcalls(struct udpif *udpif, struct list *upcalls)
594 struct dpif_op *opsp[FLOW_MISS_MAX_BATCH];
595 struct dpif_op ops[FLOW_MISS_MAX_BATCH];
596 struct upcall *upcall, *next;
597 struct flow_miss_batch *fmb;
598 size_t n_misses, n_ops, i;
599 struct flow_miss *miss;
600 unsigned int reval_seq;
601 enum upcall_type type;
604 /* Extract the flow from each upcall. Construct in fmb->misses a hash
605 * table that maps each unique flow to a 'struct flow_miss'.
607 * Most commonly there is a single packet per flow_miss, but there are
608 * several reasons why there might be more than one, e.g.:
610 * - The dpif packet interface does not support TSO (or UFO, etc.), so a
611 * large packet sent to userspace is split into a sequence of smaller
614 * - A stream of quickly arriving packets in an established "slow-pathed"
617 * - Rarely, a stream of quickly arriving packets in a flow not yet
618 * established. (This is rare because most protocols do not send
619 * multiple back-to-back packets before receiving a reply from the
620 * other end of the connection, which gives OVS a chance to set up a
623 fmb = xmalloc(sizeof *fmb);
624 atomic_read(&udpif->reval_seq, &fmb->reval_seq);
625 hmap_init(&fmb->misses);
626 list_init(&fmb->upcalls);
628 LIST_FOR_EACH_SAFE (upcall, next, list_node, upcalls) {
629 struct dpif_upcall *dupcall = &upcall->dpif_upcall;
630 struct ofpbuf *packet = dupcall->packet;
631 struct flow_miss *miss = &fmb->miss_buf[n_misses];
632 struct flow_miss *existing_miss;
633 struct ofproto_dpif *ofproto;
634 struct dpif_sflow *sflow;
635 struct dpif_ipfix *ipfix;
636 odp_port_t odp_in_port;
640 error = xlate_receive(udpif->backer, packet, dupcall->key,
641 dupcall->key_len, &flow, &miss->key_fitness,
642 &ofproto, &odp_in_port);
644 if (error == ENODEV) {
645 struct drop_key *drop_key;
647 /* Received packet on datapath port for which we couldn't
648 * associate an ofproto. This can happen if a port is removed
649 * while traffic is being received. Print a rate-limited
650 * message in case it happens frequently. Install a drop flow
651 * so that future packets of the flow are inexpensively dropped
653 VLOG_INFO_RL(&rl, "received packet on unassociated datapath "
654 "port %"PRIu32, odp_in_port);
656 drop_key = xmalloc(sizeof *drop_key);
657 drop_key->key = xmemdup(dupcall->key, dupcall->key_len);
658 drop_key->key_len = dupcall->key_len;
660 if (guarded_list_push_back(&udpif->drop_keys,
661 &drop_key->list_node,
663 seq_change(udpif->wait_seq);
665 COVERAGE_INC(drop_queue_overflow);
666 drop_key_destroy(drop_key);
669 list_remove(&upcall->list_node);
670 upcall_destroy(upcall);
674 type = classify_upcall(upcall);
675 if (type == MISS_UPCALL) {
678 flow_extract(packet, flow.skb_priority, flow.pkt_mark,
679 &flow.tunnel, &flow.in_port, &miss->flow);
681 hash = flow_hash(&miss->flow, 0);
682 existing_miss = flow_miss_find(&fmb->misses, ofproto, &miss->flow,
684 if (!existing_miss) {
685 hmap_insert(&fmb->misses, &miss->hmap_node, hash);
686 miss->ofproto = ofproto;
687 miss->key = dupcall->key;
688 miss->key_len = dupcall->key_len;
689 miss->upcall_type = dupcall->type;
690 miss->stats.n_packets = 0;
691 miss->stats.n_bytes = 0;
692 miss->stats.used = time_msec();
693 miss->stats.tcp_flags = 0;
697 miss = existing_miss;
699 miss->stats.tcp_flags |= packet_get_tcp_flags(packet, &miss->flow);
700 miss->stats.n_bytes += packet->size;
701 miss->stats.n_packets++;
703 upcall->flow_miss = miss;
709 sflow = xlate_get_sflow(ofproto);
711 union user_action_cookie cookie;
713 memset(&cookie, 0, sizeof cookie);
714 memcpy(&cookie, nl_attr_get(dupcall->userdata),
715 sizeof cookie.sflow);
716 dpif_sflow_received(sflow, dupcall->packet, &flow, odp_in_port,
718 dpif_sflow_unref(sflow);
722 ipfix = xlate_get_ipfix(ofproto);
724 dpif_ipfix_bridge_sample(ipfix, dupcall->packet, &flow);
725 dpif_ipfix_unref(ipfix);
728 case FLOW_SAMPLE_UPCALL:
729 ipfix = xlate_get_ipfix(ofproto);
731 union user_action_cookie cookie;
733 memset(&cookie, 0, sizeof cookie);
734 memcpy(&cookie, nl_attr_get(dupcall->userdata),
735 sizeof cookie.flow_sample);
737 /* The flow reflects exactly the contents of the packet.
738 * Sample the packet using it. */
739 dpif_ipfix_flow_sample(ipfix, dupcall->packet, &flow,
740 cookie.flow_sample.collector_set_id,
741 cookie.flow_sample.probability,
742 cookie.flow_sample.obs_domain_id,
743 cookie.flow_sample.obs_point_id);
744 dpif_ipfix_unref(ipfix);
753 list_remove(&upcall->list_node);
754 upcall_destroy(upcall);
757 /* Initialize each 'struct flow_miss's ->xout.
759 * We do this per-flow_miss rather than per-packet because, most commonly,
760 * all the packets in a flow can use the same translation.
762 * We can't do this in the previous loop because we need the TCP flags for
763 * all the packets in each miss. */
765 HMAP_FOR_EACH (miss, hmap_node, &fmb->misses) {
766 struct flow_wildcards wc;
767 struct rule_dpif *rule;
770 flow_wildcards_init_catchall(&wc);
771 rule_dpif_lookup(miss->ofproto, &miss->flow, &wc, &rule);
772 if (rule_dpif_fail_open(rule)) {
775 rule_dpif_credit_stats(rule, &miss->stats);
776 xlate_in_init(&xin, miss->ofproto, &miss->flow, rule,
777 miss->stats.tcp_flags, NULL);
778 xin.may_learn = true;
779 xin.resubmit_stats = &miss->stats;
780 xlate_actions(&xin, &miss->xout);
781 flow_wildcards_or(&miss->xout.wc, &miss->xout.wc, &wc);
782 rule_dpif_unref(rule);
785 /* Now handle the packets individually in order of arrival. In the common
786 * case each packet of a miss can share the same actions, but slow-pathed
787 * packets need to be translated individually:
789 * - For SLOW_CFM, SLOW_LACP, SLOW_STP, and SLOW_BFD, translation is what
790 * processes received packets for these protocols.
792 * - For SLOW_CONTROLLER, translation sends the packet to the OpenFlow
795 * The loop fills 'ops' with an array of operations to execute in the
798 LIST_FOR_EACH (upcall, list_node, upcalls) {
799 struct flow_miss *miss = upcall->flow_miss;
800 struct ofpbuf *packet = upcall->dpif_upcall.packet;
802 if (miss->xout.slow) {
803 struct rule_dpif *rule;
806 rule_dpif_lookup(miss->ofproto, &miss->flow, NULL, &rule);
807 xlate_in_init(&xin, miss->ofproto, &miss->flow, rule, 0, packet);
808 xlate_actions_for_side_effects(&xin);
809 rule_dpif_unref(rule);
812 if (miss->xout.odp_actions.size) {
815 if (miss->flow.in_port.ofp_port
816 != vsp_realdev_to_vlandev(miss->ofproto,
817 miss->flow.in_port.ofp_port,
818 miss->flow.vlan_tci)) {
819 /* This packet was received on a VLAN splinter port. We
820 * added a VLAN to the packet to make the packet resemble
821 * the flow, but the actions were composed assuming that
822 * the packet contained no VLAN. So, we must remove the
823 * VLAN header from the packet before trying to execute the
825 eth_pop_vlan(packet);
829 op->type = DPIF_OP_EXECUTE;
830 op->u.execute.key = miss->key;
831 op->u.execute.key_len = miss->key_len;
832 op->u.execute.packet = packet;
833 op->u.execute.actions = miss->xout.odp_actions.data;
834 op->u.execute.actions_len = miss->xout.odp_actions.size;
839 for (i = 0; i < n_ops; i++) {
842 dpif_operate(udpif->dpif, opsp, n_ops);
844 /* Special case for fail-open mode.
846 * If we are in fail-open mode, but we are connected to a controller too,
847 * then we should send the packet up to the controller in the hope that it
848 * will try to set up a flow and thereby allow us to exit fail-open.
850 * See the top-level comment in fail-open.c for more information. */
852 LIST_FOR_EACH (upcall, list_node, upcalls) {
853 struct flow_miss *miss = upcall->flow_miss;
854 struct ofpbuf *packet = upcall->dpif_upcall.packet;
855 struct ofputil_packet_in *pin;
857 pin = xmalloc(sizeof *pin);
858 pin->packet = xmemdup(packet->data, packet->size);
859 pin->packet_len = packet->size;
860 pin->reason = OFPR_NO_MATCH;
861 pin->controller_id = 0;
864 pin->send_len = 0; /* Not used for flow table misses. */
865 flow_get_metadata(&miss->flow, &pin->fmd);
866 ofproto_dpif_send_packet_in(miss->ofproto, pin);
870 list_move(&fmb->upcalls, upcalls);
872 atomic_read(&udpif->reval_seq, &reval_seq);
873 if (reval_seq != fmb->reval_seq) {
874 COVERAGE_INC(fmb_queue_revalidated);
875 flow_miss_batch_destroy(fmb);
876 } else if (!guarded_list_push_back(&udpif->fmbs, &fmb->list_node,
878 COVERAGE_INC(fmb_queue_overflow);
879 flow_miss_batch_destroy(fmb);
881 seq_change(udpif->wait_seq);