1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 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. */
15 #ifndef OFPROTO_DPIF_XLATE_H
16 #define OFPROTO_DPIF_XLATE_H 1
18 #include "dp-packet.h"
20 #include "meta-flow.h"
23 #include "ofproto-dpif-mirror.h"
24 #include "ofproto-dpif-rid.h"
25 #include "ofproto-dpif.h"
37 struct mcast_snooping;
41 enum slow_path_reason slow; /* 0 if fast path may be used. */
42 bool fail_open; /* Initial rule is fail open? */
44 /* Recirculation IDs on which references are held. */
47 uint32_t recirc[2]; /* When n_recircs == 1 or 2 */
48 uint32_t *recircs; /* When 'n_recircs' > 2 */
52 /* Helpers to abstract the recirculation union away. */
54 xlate_out_add_recirc(struct xlate_out *xout, uint32_t id)
56 if (OVS_LIKELY(xout->n_recircs < ARRAY_SIZE(xout->recirc))) {
57 xout->recirc[xout->n_recircs++] = id;
59 if (xout->n_recircs == ARRAY_SIZE(xout->recirc)) {
60 uint32_t *recircs = xmalloc(sizeof xout->recirc + sizeof id);
62 memcpy(recircs, xout->recirc, sizeof xout->recirc);
63 xout->recircs = recircs;
65 xout->recircs = xrealloc(xout->recircs,
66 (xout->n_recircs + 1) * sizeof id);
68 xout->recircs[xout->n_recircs++] = id;
72 static inline const uint32_t *
73 xlate_out_get_recircs(const struct xlate_out *xout)
75 if (OVS_LIKELY(xout->n_recircs <= ARRAY_SIZE(xout->recirc))) {
83 xlate_out_take_recircs(struct xlate_out *xout)
85 if (OVS_UNLIKELY(xout->n_recircs > ARRAY_SIZE(xout->recirc))) {
92 xlate_out_free_recircs(struct xlate_out *xout)
94 if (OVS_LIKELY(xout->n_recircs <= ARRAY_SIZE(xout->recirc))) {
95 for (int i = 0; i < xout->n_recircs; i++) {
96 recirc_free_id(xout->recirc[i]);
99 for (int i = 0; i < xout->n_recircs; i++) {
100 recirc_free_id(xout->recircs[i]);
107 struct ofproto_dpif *ofproto;
109 /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
110 * this flow when actions change header fields. */
113 /* The packet corresponding to 'flow', or a null pointer if we are
114 * revalidating without a packet to refer to. */
115 const struct dp_packet *packet;
117 /* Should OFPP_NORMAL update the MAC learning table? Should "learn"
118 * actions update the flow table?
120 * We want to update these tables if we are actually processing a packet,
121 * or if we are accounting for packets that the datapath has processed, but
122 * not if we are just revalidating. */
125 /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts'
126 * are NULL, xlate_actions() will do the initial rule lookup itself. */
127 struct rule_dpif *rule;
129 /* The actions to translate. If 'rule' is not NULL, these may be NULL. */
130 const struct ofpact *ofpacts;
133 /* Union of the set of TCP flags seen so far in this flow. (Used only by
134 * NXAST_FIN_TIMEOUT. Set to zero to avoid updating updating rules'
138 /* If nonnull, flow translation calls this function just before executing a
139 * resubmit or OFPP_TABLE action. In addition, disables logging of traces
140 * when the recursion depth is exceeded.
142 * 'rule' is the rule being submitted into. It will be null if the
143 * resubmit or OFPP_TABLE action didn't find a matching rule.
145 * 'recurse' is the resubmit recursion depth at time of invocation.
147 * This is normally null so the client has to set it manually after
148 * calling xlate_in_init(). */
149 void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
152 /* If nonnull, flow translation calls this function to report some
153 * significant decision, e.g. to explain why OFPP_NORMAL translation
154 * dropped a packet. 'recurse' is the resubmit recursion depth at time of
156 void (*report_hook)(struct xlate_in *, int recurse,
157 const char *format, va_list args);
159 /* If nonnull, flow translation credits the specified statistics to each
160 * rule reached through a resubmit or OFPP_TABLE action.
162 * This is normally null so the client has to set it manually after
163 * calling xlate_in_init(). */
164 const struct dpif_flow_stats *resubmit_stats;
166 /* If nonnull, flow translation populates this cache with references to all
167 * modules that are affected by translation. This 'xlate_cache' may be
168 * passed to xlate_push_stats() to perform the same function as
169 * xlate_actions() without the full cost of translation.
171 * This is normally null so the client has to set it manually after
172 * calling xlate_in_init(). */
173 struct xlate_cache *xcache;
175 /* If nonnull, flow translation puts the resulting datapath actions in this
176 * buffer. If null, flow translation will not produce datapath actions. */
177 struct ofpbuf *odp_actions;
179 /* If nonnull, flow translation populates this with wildcards relevant in
180 * translation. Any fields that were used to calculate the action are set,
181 * to allow caching and kernel wildcarding to work. For example, if the
182 * flow lookup involved performing the "normal" action on IPv4 and ARP
183 * packets, 'wc' would have the 'in_port' (always set), 'dl_type' (flow
184 * match), 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
186 struct flow_wildcards *wc;
188 /* The recirculation context related to this translation, as returned by
190 const struct recirc_id_node *recirc;
193 void xlate_ofproto_set(struct ofproto_dpif *, const char *name, struct dpif *,
194 const struct mac_learning *, struct stp *,
195 struct rstp *, const struct mcast_snooping *,
196 const struct mbridge *, const struct dpif_sflow *,
197 const struct dpif_ipfix *, const struct netflow *,
198 bool forward_bpdu, bool has_in_band,
199 const struct dpif_backer_support *support);
200 void xlate_remove_ofproto(struct ofproto_dpif *);
202 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
203 const char *name, enum port_vlan_mode, int vlan,
204 unsigned long *trunks, bool use_priority_tags,
205 const struct bond *, const struct lacp *,
207 void xlate_bundle_remove(struct ofbundle *);
209 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
210 struct ofport_dpif *, ofp_port_t, odp_port_t,
211 const struct netdev *, const struct cfm *, const struct bfd *,
212 const struct lldp *, struct ofport_dpif *peer,
213 int stp_port_no, const struct rstp_port *rstp_port,
214 const struct ofproto_port_queue *qdscp,
215 size_t n_qdscp, enum ofputil_port_config,
216 enum ofputil_port_state, bool is_tunnel,
218 void xlate_ofport_remove(struct ofport_dpif *);
220 struct ofproto_dpif * xlate_lookup_ofproto(const struct dpif_backer *,
222 ofp_port_t *ofp_in_port);
223 int xlate_lookup(const struct dpif_backer *, const struct flow *,
224 struct ofproto_dpif **, struct dpif_ipfix **,
225 struct dpif_sflow **, struct netflow **,
226 ofp_port_t *ofp_in_port);
228 void xlate_actions(struct xlate_in *, struct xlate_out *);
229 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *,
230 const struct flow *, ofp_port_t in_port, struct rule_dpif *,
231 uint16_t tcp_flags, const struct dp_packet *packet,
232 struct flow_wildcards *, struct ofpbuf *odp_actions);
233 void xlate_out_uninit(struct xlate_out *);
234 void xlate_actions_for_side_effects(struct xlate_in *);
236 int xlate_send_packet(const struct ofport_dpif *, struct dp_packet *);
238 struct xlate_cache *xlate_cache_new(void);
239 void xlate_push_stats(struct xlate_cache *, const struct dpif_flow_stats *);
240 void xlate_cache_clear(struct xlate_cache *);
241 void xlate_cache_delete(struct xlate_cache *);
243 void xlate_txn_start(void);
244 void xlate_txn_commit(void);
246 #endif /* ofproto-dpif-xlate.h */