xlate: Skip recirculation for output and set actions
[cascardo/ovs.git] / ofproto / ofproto-dpif-xlate.h
1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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_XLATE_H
16 #define OFPROTO_DPIF_XLATE_H 1
17
18 #include "dp-packet.h"
19 #include "flow.h"
20 #include "openvswitch/meta-flow.h"
21 #include "odp-util.h"
22 #include "openvswitch/ofpbuf.h"
23 #include "ofproto-dpif-mirror.h"
24 #include "ofproto-dpif-rid.h"
25 #include "ofproto-dpif.h"
26 #include "ofproto.h"
27 #include "stp.h"
28 #include "ovs-lldp.h"
29
30 struct bfd;
31 struct bond;
32 struct dpif;
33 struct lacp;
34 struct dpif_ipfix;
35 struct dpif_sflow;
36 struct mac_learning;
37 struct mcast_snooping;
38 struct xlate_cache;
39
40 struct xlate_out {
41     enum slow_path_reason slow; /* 0 if fast path may be used. */
42
43     struct recirc_refs recircs; /* Recirc action IDs on which references are
44                                  * held. */
45 };
46
47 struct xlate_in {
48     struct ofproto_dpif *ofproto;
49
50     /* Flow to which the OpenFlow actions apply.  xlate_actions() will modify
51      * this flow when actions change header fields. */
52     struct flow flow;
53
54     /* The packet corresponding to 'flow', or a null pointer if we are
55      * revalidating without a packet to refer to. */
56     const struct dp_packet *packet;
57
58     /* Should OFPP_NORMAL update the MAC learning table?  Should "learn"
59      * actions update the flow table?
60      *
61      * We want to update these tables if we are actually processing a packet,
62      * or if we are accounting for packets that the datapath has processed, but
63      * not if we are just revalidating. */
64     bool may_learn;
65
66     /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts'
67      * are NULL, xlate_actions() will do the initial rule lookup itself. */
68     struct rule_dpif *rule;
69
70     /* The actions to translate.  If 'rule' is not NULL, these may be NULL. */
71     const struct ofpact *ofpacts;
72     size_t ofpacts_len;
73
74     /* Union of the set of TCP flags seen so far in this flow.  (Used only by
75      * NXAST_FIN_TIMEOUT.  Set to zero to avoid updating updating rules'
76      * timeouts.) */
77     uint16_t tcp_flags;
78
79     /* If nonnull, flow translation calls this function just before executing a
80      * resubmit or OFPP_TABLE action.  In addition, disables logging of traces
81      * when the recursion depth is exceeded.
82      *
83      * 'rule' is the rule being submitted into.  It will be null if the
84      * resubmit or OFPP_TABLE action didn't find a matching rule.
85      *
86      * 'indentation' is the resubmit recursion depth at time of invocation,
87      * suitable for indenting the output.
88      *
89      * This is normally null so the client has to set it manually after
90      * calling xlate_in_init(). */
91     void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
92                           int indentation);
93
94     /* If nonnull, flow translation calls this function to report some
95      * significant decision, e.g. to explain why OFPP_NORMAL translation
96      * dropped a packet.  'indentation' is the resubmit recursion depth at time
97      * of invocation, suitable for indenting the output. */
98     void (*report_hook)(struct xlate_in *, int indentation,
99                         const char *format, va_list args);
100
101     /* If nonnull, flow translation credits the specified statistics to each
102      * rule reached through a resubmit or OFPP_TABLE action.
103      *
104      * This is normally null so the client has to set it manually after
105      * calling xlate_in_init(). */
106     const struct dpif_flow_stats *resubmit_stats;
107
108     /* Counters carried over from a pre-existing translation of a related flow.
109      * This can occur due to, e.g., the translation of an ARP packet that was
110      * generated as the result of outputting to a tunnel port.  In that case,
111      * the original flow going to the tunnel is the related flow.  Since the
112      * two flows are different, they should not use the same xlate_ctx
113      * structure.  However, we still need limit the maximum recursion across
114      * the entire translation.
115      *
116      * These fields are normally set to zero, so the client has to set them
117      * manually after calling xlate_in_init().  In that case, they should be
118      * copied from the same-named fields in the related flow's xlate_ctx.
119      *
120      * These fields are really implementation details; the client doesn't care
121      * about what they mean.  See the corresponding fields in xlate_ctx for
122      * real documentation. */
123     int indentation;
124     int depth;
125     int resubmits;
126
127     /* If nonnull, flow translation populates this cache with references to all
128      * modules that are affected by translation. This 'xlate_cache' may be
129      * passed to xlate_push_stats() to perform the same function as
130      * xlate_actions() without the full cost of translation.
131      *
132      * This is normally null so the client has to set it manually after
133      * calling xlate_in_init(). */
134     struct xlate_cache *xcache;
135
136     /* If nonnull, flow translation puts the resulting datapath actions in this
137      * buffer.  If null, flow translation will not produce datapath actions. */
138     struct ofpbuf *odp_actions;
139
140     /* If nonnull, flow translation populates this with wildcards relevant in
141      * translation.  Any fields that were used to calculate the action are set,
142      * to allow caching and kernel wildcarding to work.  For example, if the
143      * flow lookup involved performing the "normal" action on IPv4 and ARP
144      * packets, 'wc' would have the 'in_port' (always set), 'dl_type' (flow
145      * match), 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
146      * set. */
147     struct flow_wildcards *wc;
148
149     /* The frozen state to be resumed, as returned by xlate_lookup(). */
150     const struct frozen_state *frozen_state;
151 };
152
153 void xlate_ofproto_set(struct ofproto_dpif *, const char *name, struct dpif *,
154                        const struct mac_learning *, struct stp *,
155                        struct rstp *, const struct mcast_snooping *,
156                        const struct mbridge *, const struct dpif_sflow *,
157                        const struct dpif_ipfix *, const struct netflow *,
158                        bool forward_bpdu, bool has_in_band,
159                        const struct dpif_backer_support *support);
160 void xlate_remove_ofproto(struct ofproto_dpif *);
161
162 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
163                       const char *name, enum port_vlan_mode, int vlan,
164                       unsigned long *trunks, bool use_priority_tags,
165                       const struct bond *, const struct lacp *,
166                       bool floodable);
167 void xlate_bundle_remove(struct ofbundle *);
168
169 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
170                       struct ofport_dpif *, ofp_port_t, odp_port_t,
171                       const struct netdev *, const struct cfm *, const struct bfd *,
172                       const struct lldp *, struct ofport_dpif *peer,
173                       int stp_port_no, const struct rstp_port *rstp_port,
174                       const struct ofproto_port_queue *qdscp,
175                       size_t n_qdscp, enum ofputil_port_config,
176                       enum ofputil_port_state, bool is_tunnel,
177                       bool may_enable);
178 void xlate_ofport_remove(struct ofport_dpif *);
179
180 struct ofproto_dpif * xlate_lookup_ofproto(const struct dpif_backer *,
181                                            const struct flow *,
182                                            ofp_port_t *ofp_in_port);
183 int xlate_lookup(const struct dpif_backer *, const struct flow *,
184                  struct ofproto_dpif **, struct dpif_ipfix **,
185                  struct dpif_sflow **, struct netflow **,
186                  ofp_port_t *ofp_in_port);
187
188 enum xlate_error {
189     XLATE_OK = 0,
190     XLATE_BRIDGE_NOT_FOUND,
191     XLATE_RECURSION_TOO_DEEP,
192     XLATE_TOO_MANY_RESUBMITS,
193     XLATE_STACK_TOO_DEEP,
194     XLATE_NO_RECIRCULATION_CONTEXT,
195     XLATE_RECIRCULATION_CONFLICT,
196     XLATE_TOO_MANY_MPLS_LABELS,
197 };
198
199 const char *xlate_strerror(enum xlate_error error);
200
201 enum xlate_error xlate_actions(struct xlate_in *, struct xlate_out *);
202
203 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *,
204                    const struct flow *, ofp_port_t in_port, struct rule_dpif *,
205                    uint16_t tcp_flags, const struct dp_packet *packet,
206                    struct flow_wildcards *, struct ofpbuf *odp_actions);
207 void xlate_out_uninit(struct xlate_out *);
208 void xlate_actions_for_side_effects(struct xlate_in *);
209
210 enum ofperr xlate_resume(struct ofproto_dpif *,
211                          const struct ofputil_packet_in_private *,
212                          struct ofpbuf *odp_actions, enum slow_path_reason *);
213
214 int xlate_send_packet(const struct ofport_dpif *, struct dp_packet *);
215
216 struct xlate_cache *xlate_cache_new(void);
217 void xlate_push_stats(struct xlate_cache *, const struct dpif_flow_stats *);
218 void xlate_cache_clear(struct xlate_cache *);
219 void xlate_cache_delete(struct xlate_cache *);
220
221 void xlate_txn_start(void);
222 void xlate_txn_commit(void);
223
224 #endif /* ofproto-dpif-xlate.h */