ofp-util: Use our usual variable naming convention in make_ofp_error_msg().
[sliver-openvswitch.git] / ofproto / wdp.h
1 /*
2  * Copyright (c) 2010 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef WDP_H
18 #define WDP_H 1
19
20 #include "classifier.h"
21 #include "list.h"
22 #include "tag.h"
23
24 #ifdef  __cplusplus
25 extern "C" {
26 #endif
27
28 struct ofhooks;
29 struct ofpbuf;
30 struct svec;
31 struct wdp;
32 struct wdp_class;
33 union ofp_action;
34
35 struct wdp_table_stats {
36     /* Flows. */
37     unsigned int n_flows;       /* Number of flows in table. */
38     unsigned int cur_capacity;  /* Current flow table capacity. */
39     unsigned int max_capacity;  /* Maximum expansion of flow table capacity. */
40
41     /* Lookups. */
42     unsigned long long int n_hit;    /* Number of flow table matches. */
43     unsigned long long int n_missed; /* Number of flow table misses. */
44     unsigned long long int n_lost;   /* Misses dropped due to buffer limits. */
45 };
46
47 struct wdp_stats {
48     unsigned int max_ports;     /* Maximum supported number of ports. */
49 };
50
51 struct wdp_rule {
52     struct cls_rule cr;
53
54     long long int created;      /* Time created, in ms since the epoch. */
55     uint16_t idle_timeout;      /* In seconds from time of last use. */
56     uint16_t hard_timeout;      /* In seconds from time of creation. */
57     uint8_t ofp_table_id;       /* OpenFlow table_id in e.g. ofp_flow_stats.
58                                  * Supported range is at most 0...31. */
59
60     /* OpenFlow actions.
61      *
62      * 'n_actions' is the number of elements in the 'actions' array.  A single
63      * action may take up more more than one element's worth of space.
64      *
65      * A subrule has no actions (it uses the super-rule's actions). */
66     union ofp_action *actions;  /* OpenFlow actions. */
67     int n_actions;              /* Number of elements in 'actions' array. */
68
69     void *client_data;
70 };
71
72 void wdp_rule_init(struct wdp_rule *, const union ofp_action *actions,
73                      size_t n_actions);
74 void wdp_rule_uninit(struct wdp_rule *);
75 \f
76 void wdp_run(void);
77 void wdp_wait(void);
78
79 int wdp_register_provider(const struct wdp_class *);
80 int wdp_unregister_provider(const char *type);
81 void wdp_enumerate_types(struct svec *types);
82
83 int wdp_enumerate_names(const char *type, struct svec *names);
84 void wdp_parse_name(const char *datapath_name, char **name, char **type);
85
86 int wdp_open(const char *name, const char *type, struct wdp **);
87 int wdp_create(const char *name, const char *type, struct wdp **);
88 int wdp_create_and_open(const char *name, const char *type, struct wdp **);
89 void wdp_close(struct wdp *);
90
91 const char *wdp_name(const struct wdp *);
92 const char *wdp_base_name(const struct wdp *);
93 int wdp_get_all_names(const struct wdp *, struct svec *);
94
95 int wdp_delete(struct wdp *);
96
97 int wdp_get_features(const struct wdp *, struct ofpbuf **featuresp);
98 int wdp_get_wdp_stats(const struct wdp *, struct wdp_stats *);
99 int wdp_get_table_stats(const struct wdp *, struct ofpbuf *stats);
100
101 int wdp_get_drop_frags(const struct wdp *, bool *drop_frags);
102 int wdp_set_drop_frags(struct wdp *, bool drop_frags);
103
104 struct wdp_port {
105     struct netdev *netdev;
106     struct ofp_phy_port opp;    /* In *host* byte order. */
107     char *devname;              /* Network device name. */
108     bool internal;
109 };
110 void wdp_port_clear(struct wdp_port *);
111 void wdp_port_copy(struct wdp_port *, const struct wdp_port *);
112 void wdp_port_free(struct wdp_port *);
113 void wdp_port_array_free(struct wdp_port *, size_t n);
114
115 int wdp_port_add(struct wdp *, const char *devname, bool internal,
116                    uint16_t *port_no);
117 int wdp_port_del(struct wdp *, uint16_t port_no);
118 int wdp_port_query_by_number(const struct wdp *, uint16_t port_no,
119                              struct wdp_port *);
120 int wdp_port_query_by_name(const struct wdp *, const char *devname,
121                            struct wdp_port *);
122 int wdp_port_get_name(struct wdp *, uint16_t port_no, char **namep);
123 int wdp_port_list(const struct wdp *, struct wdp_port **, size_t *n_ports);
124
125 int wdp_port_set_config(struct wdp *, uint16_t port_no, uint32_t config);
126
127 typedef void wdp_port_poll_cb_func(const struct ofp_phy_port *opp,
128                                    uint8_t reason, void *aux);
129 int wdp_port_poll(struct wdp *, wdp_port_poll_cb_func *cb, void *aux);
130 int wdp_port_poll_wait(const struct wdp *);
131
132 int wdp_flow_flush(struct wdp *);
133
134 struct wdp_flow_stats {
135     unsigned long long int n_packets; /* Number of matched packets. */
136     unsigned long long int n_bytes;   /* Number of matched bytes. */
137     long long int inserted;           /* Time inserted into flow table. */
138     long long int used;               /* Time last used. */
139     uint8_t tcp_flags;                /* Bitwise-OR of TCP flags seen. */
140     uint8_t ip_tos;                   /* IP TOS for most recent packet. */
141 };
142
143 /* Finding and inspecting flows. */
144 struct wdp_rule *wdp_flow_get(struct wdp *, const flow_t *,
145                               unsigned int include);
146 struct wdp_rule *wdp_flow_match(struct wdp *, const flow_t *);
147
148 typedef int wdp_flow_cb_func(struct wdp_rule *, void *aux);
149 int wdp_flow_for_each_match(const struct wdp *, const flow_t *,
150                             unsigned int include, wdp_flow_cb_func *,
151                             void *aux);
152
153 int wdp_flow_get_stats(const struct wdp *, const struct wdp_rule *,
154                          struct wdp_flow_stats *);
155 bool wdp_flow_overlaps(const struct wdp *, const flow_t *);
156
157 /* Modifying flows. */
158 enum wdp_flow_put_flags {
159     /* At least one of these flags should be set. */
160     WDP_PUT_CREATE = 1 << 0,    /* Allow creating a new flow. */
161     WDP_PUT_MODIFY = 1 << 1,    /* Allow modifying an existing flow. */
162
163     /* Options used only for modifying existing flows. */
164     WDP_PUT_COUNTERS = 1 << 2,  /* Clear counters, TCP flags, IP TOS, used. */
165     WDP_PUT_ACTIONS = 1 << 3,   /* Update actions. */
166     WDP_PUT_INSERTED = 1 << 4,  /* Update 'inserted' to current time. */
167     WDP_PUT_TIMEOUTS = 1 << 5,  /* Update 'idle_timeout' and 'hard_timeout'. */
168     WDP_PUT_ALL = (WDP_PUT_COUNTERS | WDP_PUT_ACTIONS
169                    | WDP_PUT_INSERTED | WDP_PUT_TIMEOUTS)
170 };
171
172 struct wdp_flow_put {
173     enum wdp_flow_put_flags flags;
174
175     const flow_t *flow;
176
177     const union ofp_action *actions;
178     size_t n_actions;
179
180     unsigned short int idle_timeout;
181     unsigned short int hard_timeout;
182
183     /* OpenFlow 'table_id' to which a new flow is to be added.  Value 0xff
184      * means that the WDP implementation should select a table. */
185     uint8_t ofp_table_id;
186
187     /* If this is a new flow being created due to an OpenFlow OFPT_FLOW_MOD
188      * request, these values are copied from the ofp_header and ofp_flow_mod,
189      * respectively, in network byte order.  Otherwise they are zero.
190      *
191      * These values are provided to enable better logging.  The WDP provider
192      * may otherwise ignore them. */
193     uint64_t cookie;
194     uint32_t xid;
195 };
196
197 int wdp_flow_put(struct wdp *, struct wdp_flow_put *,
198                    struct wdp_flow_stats *old_stats,
199                    struct wdp_rule **rulep)
200     WARN_UNUSED_RESULT;
201 int wdp_flow_delete(struct wdp *, struct wdp_rule *,
202                       struct wdp_flow_stats *final_stats)
203     WARN_UNUSED_RESULT;
204
205 /* Sending packets in flows. */
206 int wdp_flow_inject(struct wdp *, struct wdp_rule *,
207                       uint16_t in_port, const struct ofpbuf *);
208 int wdp_execute(struct wdp *, uint16_t in_port,
209                   const union ofp_action[], size_t n_actions,
210                   const struct ofpbuf *);
211
212 /* ovs-vswitchd interface.
213  *
214  * This needs to be redesigned, because it only makes sense for wdp-xflow.  The
215  * ofhooks are currently the key to implementing the OFPP_NORMAL feature of
216  * ovs-vswitchd. */
217
218 int wdp_set_ofhooks(struct wdp *, const struct ofhooks *, void *aux);
219 void wdp_revalidate(struct wdp *, tag_type);
220 void wdp_revalidate_all(struct wdp *);
221
222 /* Receiving packets that miss the flow table. */
223 enum wdp_channel {
224     WDP_CHAN_MISS,              /* Packet missed in flow table. */
225     WDP_CHAN_ACTION,            /* Packet output to OFPP_CONTROLLER. */
226     WDP_CHAN_SFLOW,             /* sFlow samples. */
227     WDP_N_CHANS
228 };
229
230 struct wdp_packet {
231     struct list list;
232     enum wdp_channel channel;
233     uint32_t tun_id;
234     uint16_t in_port;
235     int send_len;
236     struct ofpbuf *payload;
237 };
238
239 struct wdp_packet *wdp_packet_clone(const struct wdp_packet *, size_t);
240 void wdp_packet_destroy(struct wdp_packet *);
241
242 int wdp_recv_get_mask(const struct wdp *, int *listen_mask);
243 int wdp_recv_set_mask(struct wdp *, int listen_mask);
244 int wdp_get_sflow_probability(const struct wdp *, uint32_t *probability);
245 int wdp_set_sflow_probability(struct wdp *, uint32_t probability);
246 int wdp_recv(struct wdp *, struct wdp_packet *);
247 int wdp_recv_purge(struct wdp *);
248 void wdp_recv_wait(struct wdp *);
249
250 void wdp_get_netflow_ids(const struct wdp *,
251                            uint8_t *engine_type, uint8_t *engine_id);
252
253 #ifdef  __cplusplus
254 }
255 #endif
256
257 #endif /* wdp.h */