ofproto-dpif: Hide rule_dpif_miss_rule().
[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 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-mirror.h"
23 #include "ofproto-dpif.h"
24
25 struct bfd;
26 struct bond;
27 struct dpif;
28 struct lacp;
29 struct dpif_ipfix;
30 struct dpif_sflow;
31 struct mac_learning;
32
33 struct xlate_out {
34     /* Wildcards relevant in translation.  Any fields that were used to
35      * calculate the action must be set for caching and kernel
36      * wildcarding to work.  For example, if the flow lookup involved
37      * performing the "normal" action on IPv4 and ARP packets, 'wc'
38      * would have the 'in_port' (always set), 'dl_type' (flow match),
39      * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
40      * set. */
41     struct flow_wildcards wc;
42
43     enum slow_path_reason slow; /* 0 if fast path may be used. */
44     bool has_learn;             /* Actions include NXAST_LEARN? */
45     bool has_normal;            /* Actions output to OFPP_NORMAL? */
46     bool has_fin_timeout;       /* Actions include NXAST_FIN_TIMEOUT? */
47     ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
48     mirror_mask_t mirrors;      /* Bitmap of associated mirrors. */
49
50     uint64_t odp_actions_stub[256 / 8];
51     struct ofpbuf odp_actions;
52 };
53
54 struct xlate_in {
55     struct ofproto_dpif *ofproto;
56
57     /* Flow to which the OpenFlow actions apply.  xlate_actions() will modify
58      * this flow when actions change header fields. */
59     struct flow flow;
60
61     /* The packet corresponding to 'flow', or a null pointer if we are
62      * revalidating without a packet to refer to. */
63     const struct ofpbuf *packet;
64
65     /* Should OFPP_NORMAL update the MAC learning table?  Should "learn"
66      * actions update the flow table?
67      *
68      * We want to update these tables if we are actually processing a packet,
69      * or if we are accounting for packets that the datapath has processed, but
70      * not if we are just revalidating. */
71     bool may_learn;
72
73     /* The rule initiating translation or NULL. */
74     struct rule_dpif *rule;
75
76     /* The actions to translate.  If 'rule' is not NULL, these may be NULL. */
77     const struct ofpact *ofpacts;
78     size_t ofpacts_len;
79
80     /* Union of the set of TCP flags seen so far in this flow.  (Used only by
81      * NXAST_FIN_TIMEOUT.  Set to zero to avoid updating updating rules'
82      * timeouts.) */
83     uint8_t tcp_flags;
84
85     /* If nonnull, flow translation calls this function just before executing a
86      * resubmit or OFPP_TABLE action.  In addition, disables logging of traces
87      * when the recursion depth is exceeded.
88      *
89      * 'rule' is the rule being submitted into.  It will be null if the
90      * resubmit or OFPP_TABLE action didn't find a matching rule.
91      *
92      * 'recurse' is the resubmit recursion depth at time of invocation.
93      *
94      * This is normally null so the client has to set it manually after
95      * calling xlate_in_init(). */
96     void (*resubmit_hook)(struct xlate_in *, struct rule_dpif *rule,
97                           int recurse);
98
99     /* If nonnull, flow translation calls this function to report some
100      * significant decision, e.g. to explain why OFPP_NORMAL translation
101      * dropped a packet.  'recurse' is the resubmit recursion depth at time of
102      * invocation. */
103     void (*report_hook)(struct xlate_in *, const char *s, int recurse);
104
105     /* If nonnull, flow translation credits the specified statistics to each
106      * rule reached through a resubmit or OFPP_TABLE action.
107      *
108      * This is normally null so the client has to set it manually after
109      * calling xlate_in_init(). */
110     const struct dpif_flow_stats *resubmit_stats;
111 };
112
113 void xlate_ofproto_set(struct ofproto_dpif *, const char *name,
114                        struct dpif *, struct rule_dpif *miss_rule,
115                        struct rule_dpif *no_packet_in_rule,
116                        const struct mac_learning *, struct stp *,
117                        const struct mbridge *, const struct dpif_sflow *,
118                        const struct dpif_ipfix *, enum ofp_config_flags,
119                        bool forward_bpdu, bool has_in_band, bool has_netflow);
120
121 void xlate_remove_ofproto(struct ofproto_dpif *);
122
123 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
124                       const char *name, enum port_vlan_mode, int vlan,
125                       unsigned long *trunks, bool use_priority_tags,
126                       const struct bond *, const struct lacp *,
127                       bool floodable);
128 void xlate_bundle_remove(struct ofbundle *);
129
130 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
131                       struct ofport_dpif *, ofp_port_t, odp_port_t,
132                       const struct netdev *, const struct cfm *,
133                       const struct bfd *, struct ofport_dpif *peer,
134                       int stp_port_no, const struct ofproto_port_queue *qdscp,
135                       size_t n_qdscp, enum ofputil_port_config, bool is_tunnel,
136                       bool may_enable);
137 void xlate_ofport_remove(struct ofport_dpif *);
138
139 int xlate_receive(const struct dpif_backer *, struct ofpbuf *packet,
140                   const struct nlattr *key, size_t key_len,
141                   struct flow *, enum odp_key_fitness *,
142                   struct ofproto_dpif **, odp_port_t *odp_in_port);
143
144 void xlate_actions(struct xlate_in *, struct xlate_out *);
145 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *,
146                    const struct flow *, struct rule_dpif *,
147                    uint8_t tcp_flags, const struct ofpbuf *packet);
148 void xlate_out_uninit(struct xlate_out *);
149 void xlate_actions_for_side_effects(struct xlate_in *);
150 void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src);
151 #endif /* ofproto-dpif-xlate.h */