ofproto-dpif-xlate: Hide 'struct xlate_ctx'.
[cascardo/ovs.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 OFPROT_DPIF_XLATE_H
16 #define OFPROT_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.h"
23 #include "tag.h"
24
25 /* Maximum depth of flow table recursion (due to resubmit actions) in a
26  * flow translation. */
27 #define MAX_RESUBMIT_RECURSION 64
28
29 struct xlate_out {
30     /* Wildcards relevant in translation.  Any fields that were used to
31      * calculate the action must be set for caching and kernel
32      * wildcarding to work.  For example, if the flow lookup involved
33      * performing the "normal" action on IPv4 and ARP packets, 'wc'
34      * would have the 'in_port' (always set), 'dl_type' (flow match),
35      * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
36      * set. */
37     struct flow_wildcards wc;
38
39     tag_type tags;              /* Tags associated with actions. */
40     enum slow_path_reason slow; /* 0 if fast path may be used. */
41     bool has_learn;             /* Actions include NXAST_LEARN? */
42     bool has_normal;            /* Actions output to OFPP_NORMAL? */
43     bool has_fin_timeout;       /* Actions include NXAST_FIN_TIMEOUT? */
44     uint16_t nf_output_iface;   /* Output interface index for NetFlow. */
45     mirror_mask_t mirrors;      /* Bitmap of associated mirrors. */
46
47     uint64_t odp_actions_stub[256 / 8];
48     struct ofpbuf odp_actions;
49 };
50
51 struct xlate_in {
52     struct ofproto_dpif *ofproto;
53
54     /* Flow to which the OpenFlow actions apply.  xlate_actions() will modify
55      * this flow when actions change header fields. */
56     struct flow flow;
57
58     /* The packet corresponding to 'flow', or a null pointer if we are
59      * revalidating without a packet to refer to. */
60     const struct ofpbuf *packet;
61
62     /* Should OFPP_NORMAL update the MAC learning table?  Should "learn"
63      * actions update the flow table?
64      *
65      * We want to update these tables if we are actually processing a packet,
66      * or if we are accounting for packets that the datapath has processed, but
67      * not if we are just revalidating. */
68     bool may_learn;
69
70     /* The rule initiating translation or NULL. */
71     struct rule_dpif *rule;
72
73     /* The actions to translate.  If 'rule' is not NULL, these may be NULL. */
74     const struct ofpact *ofpacts;
75     size_t ofpacts_len;
76
77     /* Union of the set of TCP flags seen so far in this flow.  (Used only by
78      * NXAST_FIN_TIMEOUT.  Set to zero to avoid updating updating rules'
79      * timeouts.) */
80     uint8_t tcp_flags;
81
82     /* If nonnull, flow translation calls this function just before executing a
83      * resubmit or OFPP_TABLE action.  In addition, disables logging of traces
84      * when the recursion depth is exceeded.
85      *
86      * 'rule' is the rule being submitted into.  It will be null if the
87      * resubmit or OFPP_TABLE action didn't find a matching rule.
88      *
89      * 'recurse' is the resubmit recursion depth at time of invocation.
90      *
91      * This is normally null so the client has to set it manually after
92      * calling xlate_in_init(). */
93     void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
94                           int recurse);
95
96     /* If nonnull, flow translation calls this function to report some
97      * significant decision, e.g. to explain why OFPP_NORMAL translation
98      * dropped a packet.  'recurse' is the resubmit recursion depth at time of
99      * invocation. */
100     void (*report_hook)(struct xlate_in *, const char *s, int recurse);
101
102     /* If nonnull, flow translation credits the specified statistics to each
103      * rule reached through a resubmit or OFPP_TABLE action.
104      *
105      * This is normally null so the client has to set it manually after
106      * calling xlate_in_init(). */
107     const struct dpif_flow_stats *resubmit_stats;
108 };
109
110 void xlate_actions(struct xlate_in *, struct xlate_out *);
111 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *,
112                    const struct flow *, struct rule_dpif *,
113                    uint8_t tcp_flags, const struct ofpbuf *packet);
114 void xlate_out_uninit(struct xlate_out *);
115 void xlate_actions_for_side_effects(struct xlate_in *);
116 void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src);
117
118 #endif /* ofproto-dpif-xlate.h */