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