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"
36 uint32_t recirc_id; /* !0 Use recirculation instead of output. */
37 uint8_t hash_alg; /* !0 Compute hash for recirc before. */
38 uint32_t hash_bias; /* Compute hash for recirc before. */
42 /* Wildcards relevant in translation. Any fields that were used to
43 * calculate the action must be set for caching and kernel
44 * wildcarding to work. For example, if the flow lookup involved
45 * performing the "normal" action on IPv4 and ARP packets, 'wc'
46 * would have the 'in_port' (always set), 'dl_type' (flow match),
47 * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
49 struct flow_wildcards wc;
51 enum slow_path_reason slow; /* 0 if fast path may be used. */
52 bool fail_open; /* Initial rule is fail open? */
53 bool has_learn; /* Actions include NXAST_LEARN? */
54 bool has_normal; /* Actions output to OFPP_NORMAL? */
55 bool has_fin_timeout; /* Actions include NXAST_FIN_TIMEOUT? */
56 ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
57 mirror_mask_t mirrors; /* Bitmap of associated mirrors. */
59 bool use_recirc; /* Should generate recirc? */
60 struct xlate_recirc recirc; /* Information used for generating
61 * recirculation actions */
62 uint64_t odp_actions_stub[256 / 8];
63 struct ofpbuf odp_actions;
67 struct ofproto_dpif *ofproto;
69 /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
70 * this flow when actions change header fields. */
73 /* The packet corresponding to 'flow', or a null pointer if we are
74 * revalidating without a packet to refer to. */
75 const struct ofpbuf *packet;
77 /* Should OFPP_NORMAL update the MAC learning table? Should "learn"
78 * actions update the flow table?
80 * We want to update these tables if we are actually processing a packet,
81 * or if we are accounting for packets that the datapath has processed, but
82 * not if we are just revalidating. */
85 /* If the caller of xlate_actions() doesn't need the flow_wildcards
86 * contained in struct xlate_out. 'skip_wildcards' can be set to true
87 * disabling the expensive wildcard computation. When true, 'wc' in struct
88 * xlate_out is undefined and should not be read. */
91 /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts'
92 * are NULL, xlate_actions() will do the initial rule lookup itself. */
93 struct rule_dpif *rule;
95 /* The actions to translate. If 'rule' is not NULL, these may be NULL. */
96 const struct ofpact *ofpacts;
99 /* Union of the set of TCP flags seen so far in this flow. (Used only by
100 * NXAST_FIN_TIMEOUT. Set to zero to avoid updating updating rules'
104 /* If nonnull, flow translation calls this function just before executing a
105 * resubmit or OFPP_TABLE action. In addition, disables logging of traces
106 * when the recursion depth is exceeded.
108 * 'rule' is the rule being submitted into. It will be null if the
109 * resubmit or OFPP_TABLE action didn't find a matching rule.
111 * 'recurse' is the resubmit recursion depth at time of invocation.
113 * This is normally null so the client has to set it manually after
114 * calling xlate_in_init(). */
115 void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
118 /* If nonnull, flow translation calls this function to report some
119 * significant decision, e.g. to explain why OFPP_NORMAL translation
120 * dropped a packet. 'recurse' is the resubmit recursion depth at time of
122 void (*report_hook)(struct xlate_in *, const char *s, int recurse);
124 /* If nonnull, flow translation credits the specified statistics to each
125 * rule reached through a resubmit or OFPP_TABLE action.
127 * This is normally null so the client has to set it manually after
128 * calling xlate_in_init(). */
129 const struct dpif_flow_stats *resubmit_stats;
132 extern struct ovs_rwlock xlate_rwlock;
134 void xlate_ofproto_set(struct ofproto_dpif *, const char *name,
135 struct dpif *, struct rule_dpif *miss_rule,
136 struct rule_dpif *no_packet_in_rule,
137 const struct mac_learning *, struct stp *,
138 const struct mbridge *, const struct dpif_sflow *,
139 const struct dpif_ipfix *, const struct netflow *,
140 enum ofp_config_flags, bool forward_bpdu,
141 bool has_in_band, bool enable_recirc,
142 bool variable_length_userdata,
143 size_t mpls_label_stack_length)
144 OVS_REQ_WRLOCK(xlate_rwlock);
145 void xlate_remove_ofproto(struct ofproto_dpif *) OVS_REQ_WRLOCK(xlate_rwlock);
147 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
148 const char *name, enum port_vlan_mode, int vlan,
149 unsigned long *trunks, bool use_priority_tags,
150 const struct bond *, const struct lacp *,
151 bool floodable) OVS_REQ_WRLOCK(xlate_rwlock);
152 void xlate_bundle_remove(struct ofbundle *) OVS_REQ_WRLOCK(xlate_rwlock);
154 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
155 struct ofport_dpif *, ofp_port_t, odp_port_t,
156 const struct netdev *, const struct cfm *,
157 const struct bfd *, struct ofport_dpif *peer,
158 int stp_port_no, const struct ofproto_port_queue *qdscp,
159 size_t n_qdscp, enum ofputil_port_config,
160 enum ofputil_port_state, bool is_tunnel,
161 bool may_enable) OVS_REQ_WRLOCK(xlate_rwlock);
162 void xlate_ofport_remove(struct ofport_dpif *) OVS_REQ_WRLOCK(xlate_rwlock);
164 int xlate_receive(const struct dpif_backer *, struct ofpbuf *packet,
165 const struct nlattr *key, size_t key_len,
166 struct flow *, struct ofproto_dpif **, struct dpif_ipfix **,
167 struct dpif_sflow **, struct netflow **,
168 odp_port_t *odp_in_port)
169 OVS_EXCLUDED(xlate_rwlock);
171 void xlate_actions(struct xlate_in *, struct xlate_out *)
172 OVS_EXCLUDED(xlate_rwlock);
173 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *,
174 const struct flow *, struct rule_dpif *,
175 uint16_t tcp_flags, const struct ofpbuf *packet);
176 void xlate_out_uninit(struct xlate_out *);
177 void xlate_actions_for_side_effects(struct xlate_in *);
178 void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src);
180 int xlate_send_packet(const struct ofport_dpif *, struct ofpbuf *);
182 #endif /* ofproto-dpif-xlate.h */