ofproto: Simplify thread creation API.
[sliver-openvswitch.git] / ofproto / ofproto-dpif-upcall.h
1 /* Copyright (c) 2013 Nicira, Inc.
2  *
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:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
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. */
14
15 #ifndef OFPROTO_DPIF_UPCALL_H
16 #define OFPROTO_DPIF_UPCALL_H
17
18 #define FLOW_MISS_MAX_BATCH 50
19
20 #include "dpif.h"
21 #include "flow.h"
22 #include "hmap.h"
23 #include "list.h"
24 #include "odp-util.h"
25 #include "ofpbuf.h"
26 #include "ofproto-dpif-xlate.h"
27
28 struct dpif;
29 struct dpif_backer;
30
31 /* udif is responsible for retrieving upcalls from the kernel, processing miss
32  * upcalls, and handing more complex ones up to the main ofproto-dpif
33  * module. */
34
35 struct udpif *udpif_create(struct dpif_backer *, struct dpif *);
36 void udpif_set_threads(struct udpif *, size_t n_handlers);
37 void udpif_destroy(struct udpif *);
38
39 void udpif_wait(struct udpif *);
40
41 void udpif_revalidate(struct udpif *);
42
43 void udpif_get_memory_usage(struct udpif *, struct simap *usage);
44 \f
45 /* udpif figures out how to forward packets, and does forward them, but it
46  * can't set up datapath flows on its own.  This interface passes packet
47  * forwarding data from udpif to the higher level ofproto_dpif to allow the
48  * latter to set up datapath flows. */
49
50 /* Flow miss batching.
51  *
52  * Some dpifs implement operations faster when you hand them off in a batch.
53  * To allow batching, "struct flow_miss" queues the dpif-related work needed
54  * for a given flow.  Each "struct flow_miss" corresponds to sending one or
55  * more packets, plus possibly installing the flow in the dpif. */
56 struct flow_miss {
57     struct hmap_node hmap_node;
58     struct ofproto_dpif *ofproto;
59
60     struct flow flow;
61     enum odp_key_fitness key_fitness;
62     const struct nlattr *key;
63     size_t key_len;
64     enum dpif_upcall_type upcall_type;
65     struct dpif_flow_stats stats;
66
67     struct xlate_out xout;
68 };
69
70 struct flow_miss_batch {
71     struct list list_node;
72
73     struct flow_miss miss_buf[FLOW_MISS_MAX_BATCH];
74     struct hmap misses;
75
76     unsigned int reval_seq;
77
78     /* Flow misses refer to the memory held by "struct upcall"s,
79      * so we need to keep track of the upcalls to be able to
80      * free them when done. */
81     struct list upcalls;        /* Contains "struct upcall"s. */
82 };
83
84 struct flow_miss_batch *flow_miss_batch_next(struct udpif *);
85 void flow_miss_batch_destroy(struct flow_miss_batch *);
86 \f
87 /* Drop keys are odp flow keys which have drop flows installed in the kernel.
88  * These are datapath flows which have no associated ofproto, if they did we
89  * would use facets.
90  *
91  * udpif can't install drop flows by itself.  This interfaces allows udpif to
92  * pass the drop flows up to ofproto_dpif to get it to install them. */
93 struct drop_key {
94     struct hmap_node hmap_node;
95     struct list list_node;
96     struct nlattr *key;
97     size_t key_len;
98 };
99
100 struct drop_key *drop_key_next(struct udpif *);
101 void drop_key_destroy(struct drop_key *);
102 void udpif_drop_key_clear(struct udpif *);
103
104 #endif /* ofproto-dpif-upcall.h */