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"
25 #include "dynamic-string.h"
26 #include "fail-open.h"
27 #include "guarded-list.h"
32 #include "ofproto-dpif-ipfix.h"
33 #include "ofproto-dpif-sflow.h"
35 #include "poll-loop.h"
40 #define MAX_QUEUE_LENGTH 512
42 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_upcall);
44 COVERAGE_DEFINE(drop_queue_overflow);
45 COVERAGE_DEFINE(upcall_queue_overflow);
46 COVERAGE_DEFINE(fmb_queue_overflow);
47 COVERAGE_DEFINE(fmb_queue_revalidated);
49 /* A thread that processes each upcall handed to it by the dispatcher thread,
50 * forwards the upcall's packet, and then queues it to the main ofproto_dpif
51 * to possibly set up a kernel flow as a cache. */
53 struct udpif *udpif; /* Parent udpif. */
54 pthread_t thread; /* Thread ID. */
55 char *name; /* Thread name. */
57 struct ovs_mutex mutex; /* Mutex guarding the following. */
59 /* Atomic queue of unprocessed upcalls. */
60 struct list upcalls OVS_GUARDED;
61 size_t n_upcalls OVS_GUARDED;
63 bool need_signal; /* Only changed by the dispatcher. */
65 pthread_cond_t wake_cond; /* Wakes 'thread' while holding
69 /* An upcall handler for ofproto_dpif.
71 * udpif is implemented as a "dispatcher" thread that reads upcalls from the
72 * kernel. It processes each upcall just enough to figure out its next
73 * destination. For a "miss" upcall (MISS_UPCALL), this is one of several
74 * "handler" threads (see struct handler). Other upcalls are queued to the
75 * main ofproto_dpif. */
77 struct list list_node; /* In all_udpifs list. */
79 struct dpif *dpif; /* Datapath handle. */
80 struct dpif_backer *backer; /* Opaque dpif_backer pointer. */
82 uint32_t secret; /* Random seed for upcall hash. */
84 pthread_t dispatcher; /* Dispatcher thread ID. */
86 struct handler *handlers; /* Upcall handlers. */
89 /* Queues to pass up to ofproto-dpif. */
90 struct guarded_list drop_keys; /* "struct drop key"s. */
91 struct guarded_list fmbs; /* "struct flow_miss_batch"es. */
94 struct seq *reval_seq;
96 struct latch exit_latch; /* Tells child threads to exit. */
100 BAD_UPCALL, /* Some kind of bug somewhere. */
101 MISS_UPCALL, /* A flow miss. */
102 SFLOW_UPCALL, /* sFlow sample. */
103 FLOW_SAMPLE_UPCALL, /* Per-flow sampling. */
104 IPFIX_UPCALL /* Per-bridge sampling. */
108 struct list list_node; /* For queuing upcalls. */
109 struct flow_miss *flow_miss; /* This upcall's flow_miss. */
111 /* Raw upcall plus data for keeping track of the memory backing it. */
112 struct dpif_upcall dpif_upcall; /* As returned by dpif_recv() */
113 struct ofpbuf upcall_buf; /* Owns some data in 'dpif_upcall'. */
114 uint64_t upcall_stub[512 / 8]; /* Buffer to reduce need for malloc(). */
117 static void upcall_destroy(struct upcall *);
119 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
120 static struct list all_udpifs = LIST_INITIALIZER(&all_udpifs);
122 static void recv_upcalls(struct udpif *);
123 static void handle_upcalls(struct udpif *, struct list *upcalls);
124 static void miss_destroy(struct flow_miss *);
125 static void *udpif_dispatcher(void *);
126 static void *udpif_upcall_handler(void *);
127 static void upcall_unixctl_show(struct unixctl_conn *conn, int argc,
128 const char *argv[], void *aux);
131 udpif_create(struct dpif_backer *backer, struct dpif *dpif)
133 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
134 struct udpif *udpif = xzalloc(sizeof *udpif);
136 if (ovsthread_once_start(&once)) {
137 unixctl_command_register("upcall/show", "", 0, 0, upcall_unixctl_show,
139 ovsthread_once_done(&once);
143 udpif->backer = backer;
144 udpif->secret = random_uint32();
145 udpif->wait_seq = seq_create();
146 udpif->reval_seq = seq_create();
147 latch_init(&udpif->exit_latch);
148 guarded_list_init(&udpif->drop_keys);
149 guarded_list_init(&udpif->fmbs);
150 list_push_back(&all_udpifs, &udpif->list_node);
156 udpif_destroy(struct udpif *udpif)
158 struct flow_miss_batch *fmb;
159 struct drop_key *drop_key;
161 udpif_set_threads(udpif, 0);
162 list_remove(&udpif->list_node);
164 while ((drop_key = drop_key_next(udpif))) {
165 drop_key_destroy(drop_key);
168 while ((fmb = flow_miss_batch_next(udpif))) {
169 flow_miss_batch_destroy(fmb);
172 guarded_list_destroy(&udpif->drop_keys);
173 guarded_list_destroy(&udpif->fmbs);
174 latch_destroy(&udpif->exit_latch);
175 seq_destroy(udpif->wait_seq);
176 seq_destroy(udpif->reval_seq);
180 /* Tells 'udpif' how many threads it should use to handle upcalls. Disables
181 * all threads if 'n_handlers' is zero. 'udpif''s datapath handle must have
182 * packet reception enabled before starting threads. */
184 udpif_set_threads(struct udpif *udpif, size_t n_handlers)
186 /* Stop the old threads (if any). */
187 if (udpif->handlers && udpif->n_handlers != n_handlers) {
190 latch_set(&udpif->exit_latch);
192 /* Wake the handlers so they can exit. */
193 for (i = 0; i < udpif->n_handlers; i++) {
194 struct handler *handler = &udpif->handlers[i];
196 ovs_mutex_lock(&handler->mutex);
197 xpthread_cond_signal(&handler->wake_cond);
198 ovs_mutex_unlock(&handler->mutex);
201 xpthread_join(udpif->dispatcher, NULL);
202 for (i = 0; i < udpif->n_handlers; i++) {
203 struct handler *handler = &udpif->handlers[i];
204 struct upcall *miss, *next;
206 xpthread_join(handler->thread, NULL);
208 ovs_mutex_lock(&handler->mutex);
209 LIST_FOR_EACH_SAFE (miss, next, list_node, &handler->upcalls) {
210 list_remove(&miss->list_node);
211 upcall_destroy(miss);
213 ovs_mutex_unlock(&handler->mutex);
214 ovs_mutex_destroy(&handler->mutex);
216 xpthread_cond_destroy(&handler->wake_cond);
219 latch_poll(&udpif->exit_latch);
221 free(udpif->handlers);
222 udpif->handlers = NULL;
223 udpif->n_handlers = 0;
226 /* Start new threads (if necessary). */
227 if (!udpif->handlers && n_handlers) {
230 udpif->n_handlers = n_handlers;
231 udpif->handlers = xzalloc(udpif->n_handlers * sizeof *udpif->handlers);
232 for (i = 0; i < udpif->n_handlers; i++) {
233 struct handler *handler = &udpif->handlers[i];
235 handler->udpif = udpif;
236 list_init(&handler->upcalls);
237 handler->need_signal = false;
238 xpthread_cond_init(&handler->wake_cond, NULL);
239 ovs_mutex_init(&handler->mutex);
240 xpthread_create(&handler->thread, NULL, udpif_upcall_handler,
243 xpthread_create(&udpif->dispatcher, NULL, udpif_dispatcher, udpif);
248 udpif_wait(struct udpif *udpif)
250 uint64_t seq = seq_read(udpif->wait_seq);
251 if (!guarded_list_is_empty(&udpif->drop_keys) ||
252 !guarded_list_is_empty(&udpif->fmbs)) {
253 poll_immediate_wake();
255 seq_wait(udpif->wait_seq, seq);
259 /* Notifies 'udpif' that something changed which may render previous
260 * xlate_actions() results invalid. */
262 udpif_revalidate(struct udpif *udpif)
264 struct flow_miss_batch *fmb, *next_fmb;
267 /* Since we remove each miss on revalidation, their statistics won't be
268 * accounted to the appropriate 'facet's in the upper layer. In most
269 * cases, this is alright because we've already pushed the stats to the
271 seq_change(udpif->reval_seq);
273 guarded_list_pop_all(&udpif->fmbs, &fmbs);
274 LIST_FOR_EACH_SAFE (fmb, next_fmb, list_node, &fmbs) {
275 list_remove(&fmb->list_node);
276 flow_miss_batch_destroy(fmb);
279 udpif_drop_key_clear(udpif);
283 udpif_get_memory_usage(struct udpif *udpif, struct simap *usage)
287 simap_increase(usage, "dispatchers", 1);
288 simap_increase(usage, "flow_dumpers", 1);
290 simap_increase(usage, "handlers", udpif->n_handlers);
291 for (i = 0; i < udpif->n_handlers; i++) {
292 struct handler *handler = &udpif->handlers[i];
293 ovs_mutex_lock(&handler->mutex);
294 simap_increase(usage, "handler upcalls", handler->n_upcalls);
295 ovs_mutex_unlock(&handler->mutex);
299 /* Destroys and deallocates 'upcall'. */
301 upcall_destroy(struct upcall *upcall)
304 ofpbuf_uninit(&upcall->upcall_buf);
309 /* Retrieves the next batch of processed flow misses for 'udpif' to install.
310 * The caller is responsible for destroying it with flow_miss_batch_destroy().
312 struct flow_miss_batch *
313 flow_miss_batch_next(struct udpif *udpif)
317 for (i = 0; i < 50; i++) {
318 struct flow_miss_batch *next;
319 struct list *next_node;
321 next_node = guarded_list_pop_front(&udpif->fmbs);
326 next = CONTAINER_OF(next_node, struct flow_miss_batch, list_node);
327 if (next->reval_seq == seq_read(udpif->reval_seq)) {
331 flow_miss_batch_destroy(next);
337 /* Destroys and deallocates 'fmb'. */
339 flow_miss_batch_destroy(struct flow_miss_batch *fmb)
341 struct flow_miss *miss, *next;
342 struct upcall *upcall, *next_upcall;
348 HMAP_FOR_EACH_SAFE (miss, next, hmap_node, &fmb->misses) {
349 hmap_remove(&fmb->misses, &miss->hmap_node);
353 LIST_FOR_EACH_SAFE (upcall, next_upcall, list_node, &fmb->upcalls) {
354 list_remove(&upcall->list_node);
355 upcall_destroy(upcall);
358 hmap_destroy(&fmb->misses);
362 /* Retrieves the next drop key which ofproto-dpif needs to process. The caller
363 * is responsible for destroying it with drop_key_destroy(). */
365 drop_key_next(struct udpif *udpif)
367 struct list *next = guarded_list_pop_front(&udpif->drop_keys);
368 return next ? CONTAINER_OF(next, struct drop_key, list_node) : NULL;
371 /* Destroys and deallocates 'drop_key'. */
373 drop_key_destroy(struct drop_key *drop_key)
381 /* Clears all drop keys waiting to be processed by drop_key_next(). */
383 udpif_drop_key_clear(struct udpif *udpif)
385 struct drop_key *drop_key, *next;
388 guarded_list_pop_all(&udpif->drop_keys, &list);
389 LIST_FOR_EACH_SAFE (drop_key, next, list_node, &list) {
390 list_remove(&drop_key->list_node);
391 drop_key_destroy(drop_key);
395 /* The dispatcher thread is responsible for receiving upcalls from the kernel,
396 * assigning them to a upcall_handler thread. */
398 udpif_dispatcher(void *arg)
400 struct udpif *udpif = arg;
402 set_subprogram_name("dispatcher");
403 while (!latch_is_set(&udpif->exit_latch)) {
405 dpif_recv_wait(udpif->dpif);
406 latch_wait(&udpif->exit_latch);
413 /* The miss handler thread is responsible for processing miss upcalls retrieved
414 * by the dispatcher thread. Once finished it passes the processed miss
415 * upcalls to ofproto-dpif where they're installed in the datapath. */
417 udpif_upcall_handler(void *arg)
419 struct handler *handler = arg;
421 handler->name = xasprintf("handler_%u", ovsthread_id_self());
422 set_subprogram_name("%s", handler->name);
425 struct list misses = LIST_INITIALIZER(&misses);
428 ovs_mutex_lock(&handler->mutex);
430 if (latch_is_set(&handler->udpif->exit_latch)) {
431 ovs_mutex_unlock(&handler->mutex);
435 if (!handler->n_upcalls) {
436 ovs_mutex_cond_wait(&handler->wake_cond, &handler->mutex);
439 for (i = 0; i < FLOW_MISS_MAX_BATCH; i++) {
440 if (handler->n_upcalls) {
441 handler->n_upcalls--;
442 list_push_back(&misses, list_pop_front(&handler->upcalls));
447 ovs_mutex_unlock(&handler->mutex);
449 handle_upcalls(handler->udpif, &misses);
456 miss_destroy(struct flow_miss *miss)
458 xlate_out_uninit(&miss->xout);
461 static enum upcall_type
462 classify_upcall(const struct upcall *upcall)
464 const struct dpif_upcall *dpif_upcall = &upcall->dpif_upcall;
465 union user_action_cookie cookie;
468 /* First look at the upcall type. */
469 switch (dpif_upcall->type) {
476 case DPIF_N_UC_TYPES:
478 VLOG_WARN_RL(&rl, "upcall has unexpected type %"PRIu32,
483 /* "action" upcalls need a closer look. */
484 if (!dpif_upcall->userdata) {
485 VLOG_WARN_RL(&rl, "action upcall missing cookie");
488 userdata_len = nl_attr_get_size(dpif_upcall->userdata);
489 if (userdata_len < sizeof cookie.type
490 || userdata_len > sizeof cookie) {
491 VLOG_WARN_RL(&rl, "action upcall cookie has unexpected size %"PRIuSIZE,
495 memset(&cookie, 0, sizeof cookie);
496 memcpy(&cookie, nl_attr_get(dpif_upcall->userdata), userdata_len);
497 if (userdata_len == sizeof cookie.sflow
498 && cookie.type == USER_ACTION_COOKIE_SFLOW) {
500 } else if (userdata_len == sizeof cookie.slow_path
501 && cookie.type == USER_ACTION_COOKIE_SLOW_PATH) {
503 } else if (userdata_len == sizeof cookie.flow_sample
504 && cookie.type == USER_ACTION_COOKIE_FLOW_SAMPLE) {
505 return FLOW_SAMPLE_UPCALL;
506 } else if (userdata_len == sizeof cookie.ipfix
507 && cookie.type == USER_ACTION_COOKIE_IPFIX) {
510 VLOG_WARN_RL(&rl, "invalid user cookie of type %"PRIu16
511 " and size %"PRIuSIZE, cookie.type, userdata_len);
517 recv_upcalls(struct udpif *udpif)
522 uint32_t hash = udpif->secret;
523 struct handler *handler;
524 struct upcall *upcall;
525 size_t n_bytes, left;
529 upcall = xmalloc(sizeof *upcall);
530 ofpbuf_use_stub(&upcall->upcall_buf, upcall->upcall_stub,
531 sizeof upcall->upcall_stub);
532 error = dpif_recv(udpif->dpif, &upcall->dpif_upcall,
533 &upcall->upcall_buf);
535 upcall_destroy(upcall);
540 NL_ATTR_FOR_EACH (nla, left, upcall->dpif_upcall.key,
541 upcall->dpif_upcall.key_len) {
542 enum ovs_key_attr type = nl_attr_type(nla);
543 if (type == OVS_KEY_ATTR_IN_PORT
544 || type == OVS_KEY_ATTR_TCP
545 || type == OVS_KEY_ATTR_UDP) {
546 if (nl_attr_get_size(nla) == 4) {
547 hash = mhash_add(hash, nl_attr_get_u32(nla));
551 "Netlink attribute with incorrect size.");
555 hash = mhash_finish(hash, n_bytes);
557 handler = &udpif->handlers[hash % udpif->n_handlers];
559 ovs_mutex_lock(&handler->mutex);
560 if (handler->n_upcalls < MAX_QUEUE_LENGTH) {
561 list_push_back(&handler->upcalls, &upcall->list_node);
562 if (handler->n_upcalls == 0) {
563 handler->need_signal = true;
565 handler->n_upcalls++;
566 if (handler->need_signal &&
567 handler->n_upcalls >= FLOW_MISS_MAX_BATCH) {
568 handler->need_signal = false;
569 xpthread_cond_signal(&handler->wake_cond);
571 ovs_mutex_unlock(&handler->mutex);
572 if (!VLOG_DROP_DBG(&rl)) {
573 struct ds ds = DS_EMPTY_INITIALIZER;
575 odp_flow_key_format(upcall->dpif_upcall.key,
576 upcall->dpif_upcall.key_len,
578 VLOG_DBG("dispatcher: enqueue (%s)", ds_cstr(&ds));
582 ovs_mutex_unlock(&handler->mutex);
583 COVERAGE_INC(upcall_queue_overflow);
584 upcall_destroy(upcall);
588 for (n = 0; n < udpif->n_handlers; ++n) {
589 struct handler *handler = &udpif->handlers[n];
591 if (handler->need_signal) {
592 handler->need_signal = false;
593 ovs_mutex_lock(&handler->mutex);
594 xpthread_cond_signal(&handler->wake_cond);
595 ovs_mutex_unlock(&handler->mutex);
600 static struct flow_miss *
601 flow_miss_find(struct hmap *todo, const struct ofproto_dpif *ofproto,
602 const struct flow *flow, uint32_t hash)
604 struct flow_miss *miss;
606 HMAP_FOR_EACH_WITH_HASH (miss, hmap_node, hash, todo) {
607 if (miss->ofproto == ofproto && flow_equal(&miss->flow, flow)) {
616 handle_upcalls(struct udpif *udpif, struct list *upcalls)
618 struct dpif_op *opsp[FLOW_MISS_MAX_BATCH];
619 struct dpif_op ops[FLOW_MISS_MAX_BATCH];
620 struct upcall *upcall, *next;
621 struct flow_miss_batch *fmb;
622 size_t n_misses, n_ops, i;
623 struct flow_miss *miss;
624 enum upcall_type type;
627 /* Extract the flow from each upcall. Construct in fmb->misses a hash
628 * table that maps each unique flow to a 'struct flow_miss'.
630 * Most commonly there is a single packet per flow_miss, but there are
631 * several reasons why there might be more than one, e.g.:
633 * - The dpif packet interface does not support TSO (or UFO, etc.), so a
634 * large packet sent to userspace is split into a sequence of smaller
637 * - A stream of quickly arriving packets in an established "slow-pathed"
640 * - Rarely, a stream of quickly arriving packets in a flow not yet
641 * established. (This is rare because most protocols do not send
642 * multiple back-to-back packets before receiving a reply from the
643 * other end of the connection, which gives OVS a chance to set up a
646 fmb = xmalloc(sizeof *fmb);
647 fmb->reval_seq = seq_read(udpif->reval_seq);
648 hmap_init(&fmb->misses);
649 list_init(&fmb->upcalls);
651 LIST_FOR_EACH_SAFE (upcall, next, list_node, upcalls) {
652 struct dpif_upcall *dupcall = &upcall->dpif_upcall;
653 struct ofpbuf *packet = dupcall->packet;
654 struct flow_miss *miss = &fmb->miss_buf[n_misses];
655 struct flow_miss *existing_miss;
656 struct ofproto_dpif *ofproto;
657 struct dpif_sflow *sflow;
658 struct dpif_ipfix *ipfix;
659 odp_port_t odp_in_port;
663 error = xlate_receive(udpif->backer, packet, dupcall->key,
664 dupcall->key_len, &flow, &miss->key_fitness,
665 &ofproto, &ipfix, &sflow, NULL, &odp_in_port);
667 if (error == ENODEV) {
668 struct drop_key *drop_key;
670 /* Received packet on datapath port for which we couldn't
671 * associate an ofproto. This can happen if a port is removed
672 * while traffic is being received. Print a rate-limited
673 * message in case it happens frequently. Install a drop flow
674 * so that future packets of the flow are inexpensively dropped
676 VLOG_INFO_RL(&rl, "received packet on unassociated datapath "
677 "port %"PRIu32, odp_in_port);
679 drop_key = xmalloc(sizeof *drop_key);
680 drop_key->key = xmemdup(dupcall->key, dupcall->key_len);
681 drop_key->key_len = dupcall->key_len;
683 if (guarded_list_push_back(&udpif->drop_keys,
684 &drop_key->list_node,
686 seq_change(udpif->wait_seq);
688 COVERAGE_INC(drop_queue_overflow);
689 drop_key_destroy(drop_key);
692 list_remove(&upcall->list_node);
693 upcall_destroy(upcall);
697 type = classify_upcall(upcall);
698 if (type == MISS_UPCALL) {
701 flow_extract(packet, flow.skb_priority, flow.pkt_mark,
702 &flow.tunnel, &flow.in_port, &miss->flow);
704 hash = flow_hash(&miss->flow, 0);
705 existing_miss = flow_miss_find(&fmb->misses, ofproto, &miss->flow,
707 if (!existing_miss) {
708 hmap_insert(&fmb->misses, &miss->hmap_node, hash);
709 miss->ofproto = ofproto;
710 miss->key = dupcall->key;
711 miss->key_len = dupcall->key_len;
712 miss->upcall_type = dupcall->type;
713 miss->stats.n_packets = 0;
714 miss->stats.n_bytes = 0;
715 miss->stats.used = time_msec();
716 miss->stats.tcp_flags = 0;
720 miss = existing_miss;
722 miss->stats.tcp_flags |= packet_get_tcp_flags(packet, &miss->flow);
723 miss->stats.n_bytes += packet->size;
724 miss->stats.n_packets++;
726 upcall->flow_miss = miss;
733 union user_action_cookie cookie;
735 memset(&cookie, 0, sizeof cookie);
736 memcpy(&cookie, nl_attr_get(dupcall->userdata),
737 sizeof cookie.sflow);
738 dpif_sflow_received(sflow, dupcall->packet, &flow, odp_in_port,
744 dpif_ipfix_bridge_sample(ipfix, dupcall->packet, &flow);
747 case FLOW_SAMPLE_UPCALL:
749 union user_action_cookie cookie;
751 memset(&cookie, 0, sizeof cookie);
752 memcpy(&cookie, nl_attr_get(dupcall->userdata),
753 sizeof cookie.flow_sample);
755 /* The flow reflects exactly the contents of the packet.
756 * Sample the packet using it. */
757 dpif_ipfix_flow_sample(ipfix, dupcall->packet, &flow,
758 cookie.flow_sample.collector_set_id,
759 cookie.flow_sample.probability,
760 cookie.flow_sample.obs_domain_id,
761 cookie.flow_sample.obs_point_id);
770 dpif_ipfix_unref(ipfix);
771 dpif_sflow_unref(sflow);
773 list_remove(&upcall->list_node);
774 upcall_destroy(upcall);
777 /* Initialize each 'struct flow_miss's ->xout.
779 * We do this per-flow_miss rather than per-packet because, most commonly,
780 * all the packets in a flow can use the same translation.
782 * We can't do this in the previous loop because we need the TCP flags for
783 * all the packets in each miss. */
785 HMAP_FOR_EACH (miss, hmap_node, &fmb->misses) {
788 xlate_in_init(&xin, miss->ofproto, &miss->flow, NULL,
789 miss->stats.tcp_flags, NULL);
790 xin.may_learn = true;
791 xin.resubmit_stats = &miss->stats;
792 xlate_actions(&xin, &miss->xout);
793 fail_open = fail_open || miss->xout.fail_open;
796 /* Now handle the packets individually in order of arrival. In the common
797 * case each packet of a miss can share the same actions, but slow-pathed
798 * packets need to be translated individually:
800 * - For SLOW_CFM, SLOW_LACP, SLOW_STP, and SLOW_BFD, translation is what
801 * processes received packets for these protocols.
803 * - For SLOW_CONTROLLER, translation sends the packet to the OpenFlow
806 * The loop fills 'ops' with an array of operations to execute in the
809 LIST_FOR_EACH (upcall, list_node, upcalls) {
810 struct flow_miss *miss = upcall->flow_miss;
811 struct ofpbuf *packet = upcall->dpif_upcall.packet;
813 if (miss->xout.slow) {
816 xlate_in_init(&xin, miss->ofproto, &miss->flow, NULL, 0, packet);
817 xlate_actions_for_side_effects(&xin);
820 if (miss->xout.odp_actions.size) {
823 if (miss->flow.in_port.ofp_port
824 != vsp_realdev_to_vlandev(miss->ofproto,
825 miss->flow.in_port.ofp_port,
826 miss->flow.vlan_tci)) {
827 /* This packet was received on a VLAN splinter port. We
828 * added a VLAN to the packet to make the packet resemble
829 * the flow, but the actions were composed assuming that
830 * the packet contained no VLAN. So, we must remove the
831 * VLAN header from the packet before trying to execute the
833 eth_pop_vlan(packet);
837 op->type = DPIF_OP_EXECUTE;
838 op->u.execute.key = miss->key;
839 op->u.execute.key_len = miss->key_len;
840 op->u.execute.packet = packet;
841 op->u.execute.actions = miss->xout.odp_actions.data;
842 op->u.execute.actions_len = miss->xout.odp_actions.size;
843 op->u.execute.needs_help = (miss->xout.slow & SLOW_ACTION) != 0;
848 for (i = 0; i < n_ops; i++) {
851 dpif_operate(udpif->dpif, opsp, n_ops);
853 /* Special case for fail-open mode.
855 * If we are in fail-open mode, but we are connected to a controller too,
856 * then we should send the packet up to the controller in the hope that it
857 * will try to set up a flow and thereby allow us to exit fail-open.
859 * See the top-level comment in fail-open.c for more information. */
861 LIST_FOR_EACH (upcall, list_node, upcalls) {
862 struct flow_miss *miss = upcall->flow_miss;
863 struct ofpbuf *packet = upcall->dpif_upcall.packet;
864 struct ofproto_packet_in *pin;
866 pin = xmalloc(sizeof *pin);
867 pin->up.packet = xmemdup(packet->data, packet->size);
868 pin->up.packet_len = packet->size;
869 pin->up.reason = OFPR_NO_MATCH;
870 pin->up.table_id = 0;
871 pin->up.cookie = OVS_BE64_MAX;
872 flow_get_metadata(&miss->flow, &pin->up.fmd);
873 pin->send_len = 0; /* Not used for flow table misses. */
874 pin->generated_by_table_miss = false;
875 ofproto_dpif_send_packet_in(miss->ofproto, pin);
879 list_move(&fmb->upcalls, upcalls);
881 if (fmb->reval_seq != seq_read(udpif->reval_seq)) {
882 COVERAGE_INC(fmb_queue_revalidated);
883 flow_miss_batch_destroy(fmb);
884 } else if (!guarded_list_push_back(&udpif->fmbs, &fmb->list_node,
886 COVERAGE_INC(fmb_queue_overflow);
887 flow_miss_batch_destroy(fmb);
889 seq_change(udpif->wait_seq);
894 upcall_unixctl_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
895 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
897 struct ds ds = DS_EMPTY_INITIALIZER;
900 LIST_FOR_EACH (udpif, list_node, &all_udpifs) {
903 ds_put_format(&ds, "%s:\n", dpif_name(udpif->dpif));
904 for (i = 0; i < udpif->n_handlers; i++) {
905 struct handler *handler = &udpif->handlers[i];
907 ovs_mutex_lock(&handler->mutex);
908 ds_put_format(&ds, "\t%s: (upcall queue %"PRIuSIZE")\n",
909 handler->name, handler->n_upcalls);
910 ovs_mutex_unlock(&handler->mutex);
914 unixctl_command_reply(conn, ds_cstr(&ds));