1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013 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
19 #include "meta-flow.h"
22 #include "ofproto-dpif-mirror.h"
23 #include "ofproto-dpif.h"
34 struct mcast_snooping;
38 uint32_t recirc_id; /* !0 Use recirculation instead of output. */
39 uint8_t hash_alg; /* !0 Compute hash for recirc before. */
40 uint32_t hash_basis; /* Compute hash for recirc before. */
44 /* Wildcards relevant in translation. Any fields that were used to
45 * calculate the action must be set for caching and kernel
46 * wildcarding to work. For example, if the flow lookup involved
47 * performing the "normal" action on IPv4 and ARP packets, 'wc'
48 * would have the 'in_port' (always set), 'dl_type' (flow match),
49 * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
51 struct flow_wildcards wc;
53 enum slow_path_reason slow; /* 0 if fast path may be used. */
54 bool fail_open; /* Initial rule is fail open? */
55 bool has_learn; /* Actions include NXAST_LEARN? */
56 bool has_normal; /* Actions output to OFPP_NORMAL? */
57 bool has_fin_timeout; /* Actions include NXAST_FIN_TIMEOUT? */
58 ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
59 mirror_mask_t mirrors; /* Bitmap of associated mirrors. */
61 uint64_t odp_actions_stub[256 / 8];
62 struct ofpbuf odp_actions;
66 struct ofproto_dpif *ofproto;
68 /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
69 * this flow when actions change header fields. */
72 /* The packet corresponding to 'flow', or a null pointer if we are
73 * revalidating without a packet to refer to. */
74 const struct ofpbuf *packet;
76 /* Should OFPP_NORMAL update the MAC learning table? Should "learn"
77 * actions update the flow table?
79 * We want to update these tables if we are actually processing a packet,
80 * or if we are accounting for packets that the datapath has processed, but
81 * not if we are just revalidating. */
84 /* If the caller of xlate_actions() doesn't need the flow_wildcards
85 * contained in struct xlate_out. 'skip_wildcards' can be set to true
86 * disabling the expensive wildcard computation. When true, 'wc' in struct
87 * xlate_out is undefined and should not be read. */
90 /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts'
91 * are NULL, xlate_actions() will do the initial rule lookup itself. */
92 struct rule_dpif *rule;
94 /* The actions to translate. If 'rule' is not NULL, these may be NULL. */
95 const struct ofpact *ofpacts;
98 /* Union of the set of TCP flags seen so far in this flow. (Used only by
99 * NXAST_FIN_TIMEOUT. Set to zero to avoid updating updating rules'
103 /* If nonnull, flow translation calls this function just before executing a
104 * resubmit or OFPP_TABLE action. In addition, disables logging of traces
105 * when the recursion depth is exceeded.
107 * 'rule' is the rule being submitted into. It will be null if the
108 * resubmit or OFPP_TABLE action didn't find a matching rule.
110 * 'recurse' is the resubmit recursion depth at time of invocation.
112 * This is normally null so the client has to set it manually after
113 * calling xlate_in_init(). */
114 void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
117 /* If nonnull, flow translation calls this function to report some
118 * significant decision, e.g. to explain why OFPP_NORMAL translation
119 * dropped a packet. 'recurse' is the resubmit recursion depth at time of
121 void (*report_hook)(struct xlate_in *, const char *s, int recurse);
123 /* If nonnull, flow translation credits the specified statistics to each
124 * rule reached through a resubmit or OFPP_TABLE action.
126 * This is normally null so the client has to set it manually after
127 * calling xlate_in_init(). */
128 const struct dpif_flow_stats *resubmit_stats;
130 /* If nonnull, flow translation populates this cache with references to all
131 * modules that are affected by translation. This 'xlate_cache' may be
132 * passed to xlate_push_stats() to perform the same function as
133 * xlate_actions() without the full cost of translation.
135 * This is normally null so the client has to set it manually after
136 * calling xlate_in_init(). */
137 struct xlate_cache *xcache;
140 void xlate_ofproto_set(struct ofproto_dpif *, const char *name,
141 struct dpif *, struct rule_dpif *miss_rule,
142 struct rule_dpif *no_packet_in_rule,
143 const struct mac_learning *, struct stp *,
144 const struct mcast_snooping *,
145 const struct mbridge *, const struct dpif_sflow *,
146 const struct dpif_ipfix *, const struct netflow *,
147 enum ofp_config_flags, bool forward_bpdu,
148 bool has_in_band, bool enable_recirc,
149 bool variable_length_userdata,
150 size_t mpls_label_stack_length);
151 void xlate_remove_ofproto(struct ofproto_dpif *);
153 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
154 const char *name, enum port_vlan_mode, int vlan,
155 unsigned long *trunks, bool use_priority_tags,
156 const struct bond *, const struct lacp *,
158 void xlate_bundle_remove(struct ofbundle *);
160 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
161 struct ofport_dpif *, ofp_port_t, odp_port_t,
162 const struct netdev *, const struct cfm *,
163 const struct bfd *, struct ofport_dpif *peer,
164 int stp_port_no, const struct ofproto_port_queue *qdscp,
165 size_t n_qdscp, enum ofputil_port_config,
166 enum ofputil_port_state, bool is_tunnel,
168 void xlate_ofport_remove(struct ofport_dpif *);
170 int xlate_receive(const struct dpif_backer *, struct ofpbuf *packet,
171 const struct nlattr *key, size_t key_len,
172 struct flow *, struct ofproto_dpif **, struct dpif_ipfix **,
173 struct dpif_sflow **, struct netflow **,
174 odp_port_t *odp_in_port);
176 void xlate_actions(struct xlate_in *, struct xlate_out *);
177 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *,
178 const struct flow *, struct rule_dpif *,
179 uint16_t tcp_flags, const struct ofpbuf *packet);
180 void xlate_out_uninit(struct xlate_out *);
181 void xlate_actions_for_side_effects(struct xlate_in *);
182 void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src);
184 int xlate_send_packet(const struct ofport_dpif *, struct ofpbuf *);
186 struct xlate_cache *xlate_cache_new(void);
187 void xlate_push_stats(struct xlate_cache *, bool may_learn,
188 const struct dpif_flow_stats *);
189 void xlate_cache_clear(struct xlate_cache *);
190 void xlate_cache_delete(struct xlate_cache *);
192 void xlate_txn_start(void);
193 void xlate_txn_commit(void);
195 #endif /* ofproto-dpif-xlate.h */