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