dp-packet: Remove ofpbuf dependency.
[cascardo/ovs.git] / ofproto / ofproto-dpif-xlate.h
1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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 "meta-flow.h"
21 #include "odp-util.h"
22 #include "ofpbuf.h"
23 #include "ofproto-dpif-mirror.h"
24 #include "ofproto-dpif.h"
25 #include "ofproto.h"
26 #include "stp.h"
27
28 struct bfd;
29 struct bond;
30 struct dpif;
31 struct lacp;
32 struct dpif_ipfix;
33 struct dpif_sflow;
34 struct mac_learning;
35 struct mcast_snooping;
36 struct xlate_cache;
37
38 struct xlate_recirc {
39     uint32_t recirc_id;  /* !0 Use recirculation instead of output. */
40     uint8_t  hash_alg;   /* !0 Compute hash for recirc before. */
41     uint32_t hash_basis;  /* Compute hash for recirc before. */
42 };
43
44 struct xlate_out {
45     /* Wildcards relevant in translation.  Any fields that were used to
46      * calculate the action must be set for caching and kernel
47      * wildcarding to work.  For example, if the flow lookup involved
48      * performing the "normal" action on IPv4 and ARP packets, 'wc'
49      * would have the 'in_port' (always set), 'dl_type' (flow match),
50      * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
51      * set. */
52     struct flow_wildcards wc;
53
54     enum slow_path_reason slow; /* 0 if fast path may be used. */
55     bool fail_open;             /* Initial rule is fail open? */
56     bool has_learn;             /* Actions include NXAST_LEARN? */
57     bool has_normal;            /* Actions output to OFPP_NORMAL? */
58     bool has_fin_timeout;       /* Actions include NXAST_FIN_TIMEOUT? */
59     ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
60     mirror_mask_t mirrors;      /* Bitmap of associated mirrors. */
61
62     uint64_t odp_actions_stub[256 / 8];
63     struct ofpbuf odp_actions_buf;
64     struct ofpbuf *odp_actions;
65 };
66
67 struct xlate_in {
68     struct ofproto_dpif *ofproto;
69
70     /* Flow to which the OpenFlow actions apply.  xlate_actions() will modify
71      * this flow when actions change header fields. */
72     struct flow flow;
73
74     /* The packet corresponding to 'flow', or a null pointer if we are
75      * revalidating without a packet to refer to. */
76     const struct dp_packet *packet;
77
78     /* Should OFPP_NORMAL update the MAC learning table?  Should "learn"
79      * actions update the flow table?
80      *
81      * We want to update these tables if we are actually processing a packet,
82      * or if we are accounting for packets that the datapath has processed, but
83      * not if we are just revalidating. */
84     bool may_learn;
85
86     /* If the caller of xlate_actions() doesn't need the flow_wildcards
87      * contained in struct xlate_out.  'skip_wildcards' can be set to true
88      * disabling the expensive wildcard computation.  When true, 'wc' in struct
89      * xlate_out is undefined and should not be read. */
90     bool skip_wildcards;
91
92     /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts'
93      * are NULL, xlate_actions() will do the initial rule lookup itself. */
94     struct rule_dpif *rule;
95
96     /* The actions to translate.  If 'rule' is not NULL, these may be NULL. */
97     const struct ofpact *ofpacts;
98     size_t ofpacts_len;
99
100     /* Union of the set of TCP flags seen so far in this flow.  (Used only by
101      * NXAST_FIN_TIMEOUT.  Set to zero to avoid updating updating rules'
102      * timeouts.) */
103     uint16_t tcp_flags;
104
105     /* If nonnull, flow translation calls this function just before executing a
106      * resubmit or OFPP_TABLE action.  In addition, disables logging of traces
107      * when the recursion depth is exceeded.
108      *
109      * 'rule' is the rule being submitted into.  It will be null if the
110      * resubmit or OFPP_TABLE action didn't find a matching rule.
111      *
112      * 'recurse' is the resubmit recursion depth at time of invocation.
113      *
114      * This is normally null so the client has to set it manually after
115      * calling xlate_in_init(). */
116     void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
117                           int recurse);
118
119     /* If nonnull, flow translation calls this function to report some
120      * significant decision, e.g. to explain why OFPP_NORMAL translation
121      * dropped a packet.  'recurse' is the resubmit recursion depth at time of
122      * invocation. */
123     void (*report_hook)(struct xlate_in *, const char *s, int recurse);
124
125     /* If nonnull, flow translation credits the specified statistics to each
126      * rule reached through a resubmit or OFPP_TABLE action.
127      *
128      * This is normally null so the client has to set it manually after
129      * calling xlate_in_init(). */
130     const struct dpif_flow_stats *resubmit_stats;
131
132     /* If nonnull, flow translation populates this cache with references to all
133      * modules that are affected by translation. This 'xlate_cache' may be
134      * passed to xlate_push_stats() to perform the same function as
135      * xlate_actions() without the full cost of translation.
136      *
137      * This is normally null so the client has to set it manually after
138      * calling xlate_in_init(). */
139     struct xlate_cache *xcache;
140
141     /* Allows callers to optionally supply their own buffer for the resulting
142      * odp_actions stored in xlate_out.  If NULL, the default buffer will be
143      * used. */
144     struct ofpbuf *odp_actions;
145 };
146
147 void xlate_ofproto_set(struct ofproto_dpif *, const char *name, struct dpif *,
148                        const struct mac_learning *, struct stp *,
149                        struct rstp *, const struct mcast_snooping *,
150                        const struct mbridge *, const struct dpif_sflow *,
151                        const struct dpif_ipfix *, const struct netflow *,
152                        bool forward_bpdu,
153                        bool has_in_band, bool enable_recirc,
154                        bool variable_length_userdata,
155                        size_t mpls_label_stack_length,
156                        bool masked_set_action);
157 void xlate_remove_ofproto(struct ofproto_dpif *);
158
159 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
160                       const char *name, enum port_vlan_mode, int vlan,
161                       unsigned long *trunks, bool use_priority_tags,
162                       const struct bond *, const struct lacp *,
163                       bool floodable);
164 void xlate_bundle_remove(struct ofbundle *);
165
166 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
167                       struct ofport_dpif *, ofp_port_t, odp_port_t,
168                       const struct netdev *, const struct cfm *,
169                       const struct bfd *, struct ofport_dpif *peer,
170                       int stp_port_no,
171                       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,
175                       bool may_enable);
176 void xlate_ofport_remove(struct ofport_dpif *);
177
178 struct ofproto_dpif * xlate_lookup_ofproto(const struct dpif_backer *,
179                                            const struct flow *,
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);
185
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);
193
194 int xlate_send_packet(const struct ofport_dpif *, struct dp_packet *);
195
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 *);
200
201 void xlate_txn_start(void);
202 void xlate_txn_commit(void);
203
204 #endif /* ofproto-dpif-xlate.h */