1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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.h"
36 struct mcast_snooping;
40 uint32_t recirc_id; /* !0 Use recirculation instead of output. */
41 uint8_t hash_alg; /* !0 Compute hash for recirc before. */
42 uint32_t hash_basis; /* Compute hash for recirc before. */
46 /* Wildcards relevant in translation. Any fields that were used to
47 * calculate the action must be set for caching and kernel
48 * wildcarding to work. For example, if the flow lookup involved
49 * performing the "normal" action on IPv4 and ARP packets, 'wc'
50 * would have the 'in_port' (always set), 'dl_type' (flow match),
51 * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
53 struct flow_wildcards wc;
55 enum slow_path_reason slow; /* 0 if fast path may be used. */
56 bool fail_open; /* Initial rule is fail open? */
57 bool has_learn; /* Actions include NXAST_LEARN? */
58 bool has_normal; /* Actions output to OFPP_NORMAL? */
59 bool has_fin_timeout; /* Actions include NXAST_FIN_TIMEOUT? */
60 ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
61 mirror_mask_t mirrors; /* Bitmap of associated mirrors. */
63 uint64_t odp_actions_stub[256 / 8];
64 struct ofpbuf odp_actions_buf;
65 struct ofpbuf *odp_actions;
69 struct ofproto_dpif *ofproto;
71 /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
72 * this flow when actions change header fields. */
75 /* The packet corresponding to 'flow', or a null pointer if we are
76 * revalidating without a packet to refer to. */
77 const struct dp_packet *packet;
79 /* Should OFPP_NORMAL update the MAC learning table? Should "learn"
80 * actions update the flow table?
82 * We want to update these tables if we are actually processing a packet,
83 * or if we are accounting for packets that the datapath has processed, but
84 * not if we are just revalidating. */
87 /* If the caller of xlate_actions() doesn't need the flow_wildcards
88 * contained in struct xlate_out. 'skip_wildcards' can be set to true
89 * disabling the expensive wildcard computation. When true, 'wc' in struct
90 * xlate_out is undefined and should not be read. */
93 /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts'
94 * are NULL, xlate_actions() will do the initial rule lookup itself. */
95 struct rule_dpif *rule;
97 /* The actions to translate. If 'rule' is not NULL, these may be NULL. */
98 const struct ofpact *ofpacts;
101 /* Union of the set of TCP flags seen so far in this flow. (Used only by
102 * NXAST_FIN_TIMEOUT. Set to zero to avoid updating updating rules'
106 /* If nonnull, flow translation calls this function just before executing a
107 * resubmit or OFPP_TABLE action. In addition, disables logging of traces
108 * when the recursion depth is exceeded.
110 * 'rule' is the rule being submitted into. It will be null if the
111 * resubmit or OFPP_TABLE action didn't find a matching rule.
113 * 'recurse' is the resubmit recursion depth at time of invocation.
115 * This is normally null so the client has to set it manually after
116 * calling xlate_in_init(). */
117 void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
120 /* If nonnull, flow translation calls this function to report some
121 * significant decision, e.g. to explain why OFPP_NORMAL translation
122 * dropped a packet. 'recurse' is the resubmit recursion depth at time of
124 void (*report_hook)(struct xlate_in *, const char *s, int recurse);
126 /* If nonnull, flow translation credits the specified statistics to each
127 * rule reached through a resubmit or OFPP_TABLE action.
129 * This is normally null so the client has to set it manually after
130 * calling xlate_in_init(). */
131 const struct dpif_flow_stats *resubmit_stats;
133 /* If nonnull, flow translation populates this cache with references to all
134 * modules that are affected by translation. This 'xlate_cache' may be
135 * passed to xlate_push_stats() to perform the same function as
136 * xlate_actions() without the full cost of translation.
138 * This is normally null so the client has to set it manually after
139 * calling xlate_in_init(). */
140 struct xlate_cache *xcache;
142 /* Allows callers to optionally supply their own buffer for the resulting
143 * odp_actions stored in xlate_out. If NULL, the default buffer will be
145 struct ofpbuf *odp_actions;
148 void xlate_ofproto_set(struct ofproto_dpif *, const char *name, struct dpif *,
149 const struct mac_learning *, struct stp *,
150 struct rstp *, const struct mcast_snooping *,
151 const struct mbridge *, const struct dpif_sflow *,
152 const struct dpif_ipfix *, const struct netflow *,
154 bool has_in_band, bool enable_recirc,
155 bool variable_length_userdata,
156 size_t mpls_label_stack_length,
157 bool masked_set_action);
158 void xlate_remove_ofproto(struct ofproto_dpif *);
160 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
161 const char *name, enum port_vlan_mode, int vlan,
162 unsigned long *trunks, bool use_priority_tags,
163 const struct bond *, const struct lacp *,
165 void xlate_bundle_remove(struct ofbundle *);
167 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
168 struct ofport_dpif *, ofp_port_t, odp_port_t,
169 const struct netdev *, const struct cfm *, const struct bfd *,
170 const struct lldp *, struct ofport_dpif *peer,
171 int stp_port_no, const struct rstp_port *rstp_port,
172 const struct ofproto_port_queue *qdscp,
173 size_t n_qdscp, enum ofputil_port_config,
174 enum ofputil_port_state, bool is_tunnel,
176 void xlate_ofport_remove(struct ofport_dpif *);
178 struct ofproto_dpif * xlate_lookup_ofproto(const struct dpif_backer *,
180 ofp_port_t *ofp_in_port);
181 int xlate_lookup(const struct dpif_backer *, const struct flow *,
182 struct ofproto_dpif **, struct dpif_ipfix **,
183 struct dpif_sflow **, struct netflow **,
184 ofp_port_t *ofp_in_port);
186 void xlate_actions(struct xlate_in *, struct xlate_out *);
187 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *,
188 const struct flow *, ofp_port_t in_port, struct rule_dpif *,
189 uint16_t tcp_flags, const struct dp_packet *packet);
190 void xlate_out_uninit(struct xlate_out *);
191 void xlate_actions_for_side_effects(struct xlate_in *);
192 void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src);
194 int xlate_send_packet(const struct ofport_dpif *, struct dp_packet *);
196 struct xlate_cache *xlate_cache_new(void);
197 void xlate_push_stats(struct xlate_cache *, const struct dpif_flow_stats *);
198 void xlate_cache_clear(struct xlate_cache *);
199 void xlate_cache_delete(struct xlate_cache *);
201 void xlate_txn_start(void);
202 void xlate_txn_commit(void);
204 #endif /* ofproto-dpif-xlate.h */