ofproto-dpif-upcall: Increase upcall stub size.
[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_recv_set(struct udpif *, size_t n_workers, bool enable);
37 void udpif_destroy(struct udpif *);
38
39 void udpif_run(struct udpif *);
40 void udpif_wait(struct udpif *);
41
42 void udpif_revalidate(struct udpif *);
43 \f
44 /* udpif can handle some upcalls on its own.  Others need the main ofproto_dpif
45  * code to handle them.  This interface passes upcalls not handled by udpif up
46  * to the ofproto_dpif main thread. */
47
48 /* Type of an upcall. */
49 enum upcall_type {
50     /* Handled internally by udpif code.  Not returned by upcall_next().*/
51     BAD_UPCALL,                 /* Some kind of bug somewhere. */
52     MISS_UPCALL,                /* A flow miss.  */
53
54     /* Require main thread's involvement.  May be returned by upcall_next(). */
55     SFLOW_UPCALL,               /* sFlow sample. */
56     FLOW_SAMPLE_UPCALL,         /* Per-flow sampling. */
57     IPFIX_UPCALL                /* Per-bridge sampling. */
58 };
59
60 /* An upcall. */
61 struct upcall {
62     struct list list_node;          /* For queuing upcalls. */
63
64     enum upcall_type type;          /* Classification. */
65
66     /* Raw upcall plus data for keeping track of the memory backing it. */
67     struct dpif_upcall dpif_upcall; /* As returned by dpif_recv() */
68     struct ofpbuf upcall_buf;       /* Owns some data in 'dpif_upcall'. */
69     uint64_t upcall_stub[512 / 8];  /* Buffer to reduce need for malloc(). */
70 };
71
72 struct upcall *upcall_next(struct udpif *);
73 void upcall_destroy(struct upcall *);
74 \f
75 /* udpif figures out how to forward packets, and does forward them, but it
76  * can't set up datapath flows on its own.  This interface passes packet
77  * forwarding data from udpif to the higher level ofproto_dpif to allow the
78  * latter to set up datapath flows. */
79
80 /* Flow miss batching.
81  *
82  * Some dpifs implement operations faster when you hand them off in a batch.
83  * To allow batching, "struct flow_miss" queues the dpif-related work needed
84  * for a given flow.  Each "struct flow_miss" corresponds to sending one or
85  * more packets, plus possibly installing the flow in the dpif. */
86 struct flow_miss {
87     struct hmap_node hmap_node;
88     struct ofproto_dpif *ofproto;
89
90     struct flow flow;
91     enum odp_key_fitness key_fitness;
92     const struct nlattr *key;
93     size_t key_len;
94     struct list packets;
95     enum dpif_upcall_type upcall_type;
96     struct dpif_flow_stats stats;
97
98     struct xlate_out xout;
99
100     struct list upcalls;
101 };
102
103 struct flow_miss_batch {
104     struct list list_node;
105
106     struct flow_miss miss_buf[FLOW_MISS_MAX_BATCH];
107     struct hmap misses;
108 };
109
110 struct flow_miss_batch *flow_miss_batch_next(struct udpif *);
111 void flow_miss_batch_destroy(struct flow_miss_batch *);
112 \f
113 /* Drop keys are odp flow keys which have drop flows installed in the kernel.
114  * These are datapath flows which have no associated ofproto, if they did we
115  * would use facets.
116  *
117  * udpif can't install drop flows by itself.  This interfaces allows udpif to
118  * pass the drop flows up to ofproto_dpif to get it to install them. */
119 struct drop_key {
120     struct hmap_node hmap_node;
121     struct list list_node;
122     struct nlattr *key;
123     size_t key_len;
124 };
125
126 struct drop_key *drop_key_next(struct udpif *);
127 void drop_key_destroy(struct drop_key *);
128 void udpif_drop_key_clear(struct udpif *);
129
130 #endif /* ofproto-dpif-upcall.h */