wdp: Get rid of most members of struct wdp_stats.
[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
23 #ifdef  __cplusplus
24 extern "C" {
25 #endif
26
27 enum {
28     TABLEID_HASH = 0,
29     TABLEID_CLASSIFIER = 1
30 };
31
32 struct ofpbuf;
33 struct svec;
34 struct wdp;
35 struct wdp_class;
36 union ofp_action;
37
38 struct wdp_table_stats {
39     /* Flows. */
40     unsigned int n_flows;       /* Number of flows in table. */
41     unsigned int cur_capacity;  /* Current flow table capacity. */
42     unsigned int max_capacity;  /* Maximum expansion of flow table capacity. */
43
44     /* Lookups. */
45     unsigned long long int n_hit;    /* Number of flow table matches. */
46     unsigned long long int n_missed; /* Number of flow table misses. */
47     unsigned long long int n_lost;   /* Misses dropped due to buffer limits. */
48 };
49
50 struct wdp_stats {
51     unsigned int max_ports;     /* Maximum supported number of ports. */
52 };
53
54 struct wdp_rule {
55     struct cls_rule cr;
56
57     long long int created;      /* Time created, in ms since the epoch. */
58     uint16_t idle_timeout;      /* In seconds from time of last use. */
59     uint16_t hard_timeout;      /* In seconds from time of creation. */
60
61     /* OpenFlow actions.
62      *
63      * 'n_actions' is the number of elements in the 'actions' array.  A single
64      * action may take up more more than one element's worth of space.
65      *
66      * A subrule has no actions (it uses the super-rule's actions). */
67     union ofp_action *actions;  /* OpenFlow actions. */
68     int n_actions;              /* Number of elements in 'actions' array. */
69
70     void *client_data;
71 };
72
73 void wdp_rule_init(struct wdp_rule *, const union ofp_action *actions,
74                      size_t n_actions);
75 void wdp_rule_uninit(struct wdp_rule *);
76 \f
77 void wdp_run(void);
78 void wdp_wait(void);
79
80 int wdp_register_provider(const struct wdp_class *);
81 int wdp_unregister_provider(const char *type);
82 void wdp_enumerate_types(struct svec *types);
83
84 int wdp_enumerate_names(const char *type, struct svec *names);
85 void wdp_parse_name(const char *datapath_name, char **name, char **type);
86
87 void wdp_run_expiration(struct wdp *);
88 void wdp_run_revalidation(struct wdp *, bool revalidate_all);
89
90 int wdp_open(const char *name, const char *type, struct wdp **);
91 int wdp_create(const char *name, const char *type, struct wdp **);
92 int wdp_create_and_open(const char *name, const char *type, struct wdp **);
93 void wdp_close(struct wdp *);
94
95 const char *wdp_name(const struct wdp *);
96 const char *wdp_base_name(const struct wdp *);
97 int wdp_get_all_names(const struct wdp *, struct svec *);
98
99 int wdp_delete(struct wdp *);
100
101 int wdp_get_features(const struct wdp *, struct ofpbuf **featuresp);
102 int wdp_get_wdp_stats(const struct wdp *, struct wdp_stats *);
103 int wdp_get_table_stats(const struct wdp *, struct ofpbuf *stats);
104
105 int wdp_get_drop_frags(const struct wdp *, bool *drop_frags);
106 int wdp_set_drop_frags(struct wdp *, bool drop_frags);
107
108 struct wdp_port {
109     struct netdev *netdev;
110     struct ofp_phy_port opp;    /* In *host* byte order. */
111     char *devname;              /* Network device name. */
112     bool internal;
113 };
114 void wdp_port_clear(struct wdp_port *);
115 void wdp_port_copy(struct wdp_port *, const struct wdp_port *);
116 void wdp_port_free(struct wdp_port *);
117 void wdp_port_array_free(struct wdp_port *, size_t n);
118
119 int wdp_port_add(struct wdp *, const char *devname, bool internal,
120                    uint16_t *port_no);
121 int wdp_port_del(struct wdp *, uint16_t port_no);
122 int wdp_port_query_by_number(const struct wdp *, uint16_t port_no,
123                              struct wdp_port *);
124 int wdp_port_query_by_name(const struct wdp *, const char *devname,
125                            struct wdp_port *);
126 int wdp_port_get_name(struct wdp *, uint16_t port_no, char **namep);
127 int wdp_port_list(const struct wdp *, struct wdp_port **, size_t *n_ports);
128
129 int wdp_port_set_config(struct wdp *, uint16_t port_no, uint32_t config);
130
131 typedef void wdp_port_poll_cb_func(const struct ofp_phy_port *opp,
132                                    uint8_t reason, void *aux);
133 int wdp_port_poll(struct wdp *, wdp_port_poll_cb_func *cb, void *aux);
134 int wdp_port_poll_wait(const struct wdp *);
135
136 int wdp_flow_flush(struct wdp *);
137
138 struct wdp_flow_stats {
139     unsigned long long int n_packets; /* Number of matched packets. */
140     unsigned long long int n_bytes;   /* Number of matched bytes. */
141     long long int inserted;           /* Time inserted into flow table. */
142     long long int used;               /* Time last used. */
143     uint8_t tcp_flags;                /* Bitwise-OR of TCP flags seen. */
144     uint8_t ip_tos;                   /* IP TOS for most recent packet. */
145 };
146
147 /* Finding and inspecting flows. */
148 struct wdp_rule *wdp_flow_get(struct wdp *, const flow_t *);
149 struct wdp_rule *wdp_flow_match(struct wdp *, const flow_t *);
150
151 typedef void wdp_flow_cb_func(struct wdp_rule *, void *aux);
152 void wdp_flow_for_each_match(const struct wdp *, const flow_t *,
153                                int include, wdp_flow_cb_func *, void *aux);
154
155 int wdp_flow_get_stats(const struct wdp *, const struct wdp_rule *,
156                          struct wdp_flow_stats *);
157 bool wdp_flow_overlaps(const struct wdp *, const flow_t *);
158
159 /* Modifying flows. */
160 enum wdp_flow_put_flags {
161     /* At least one of these flags should be set. */
162     WDP_PUT_CREATE = 1 << 0,    /* Allow creating a new flow. */
163     WDP_PUT_MODIFY = 1 << 1,    /* Allow modifying an existing flow. */
164
165     /* Options used only for modifying existing flows. */
166     WDP_PUT_COUNTERS = 1 << 2,  /* Clear counters, TCP flags, IP TOS, used. */
167     WDP_PUT_ACTIONS = 1 << 3,   /* Update actions. */
168     WDP_PUT_INSERTED = 1 << 4,  /* Update 'inserted' to current time. */
169     WDP_PUT_TIMEOUTS = 1 << 5,  /* Update 'idle_timeout' and 'hard_timeout'. */
170     WDP_PUT_ALL = (WDP_PUT_COUNTERS | WDP_PUT_ACTIONS
171                    | WDP_PUT_INSERTED | WDP_PUT_TIMEOUTS)
172 };
173
174 struct wdp_flow_put {
175     enum wdp_flow_put_flags flags;
176
177     const flow_t *flow;
178
179     const union ofp_action *actions;
180     size_t n_actions;
181
182     unsigned short int idle_timeout;
183     unsigned short int hard_timeout;
184 };
185
186 int wdp_flow_put(struct wdp *, struct wdp_flow_put *,
187                    struct wdp_flow_stats *old_stats,
188                    struct wdp_rule **rulep);
189 int wdp_flow_delete(struct wdp *, struct wdp_rule *,
190                       struct wdp_flow_stats *final_stats);
191
192 /* Sending packets in flows. */
193 int wdp_flow_inject(struct wdp *, struct wdp_rule *,
194                       uint16_t in_port, const struct ofpbuf *);
195 int wdp_execute(struct wdp *, uint16_t in_port,
196                   const union ofp_action[], size_t n_actions,
197                   const struct ofpbuf *);
198
199 /* Receiving packets that miss the flow table. */
200 enum wdp_channel {
201     WDP_CHAN_MISS,              /* Packet missed in flow table. */
202     WDP_CHAN_ACTION,            /* Packet output to OFPP_CONTROLLER. */
203     WDP_CHAN_SFLOW,             /* sFlow samples. */
204     WDP_N_CHANS
205 };
206
207 struct wdp_packet {
208     struct list list;
209     enum wdp_channel channel;
210     uint32_t tun_id;
211     uint16_t in_port;
212     int send_len;
213     struct ofpbuf *payload;
214 };
215
216 struct wdp_packet *wdp_packet_clone(const struct wdp_packet *, size_t);
217 void wdp_packet_destroy(struct wdp_packet *);
218
219 int wdp_recv_get_mask(const struct wdp *, int *listen_mask);
220 int wdp_recv_set_mask(struct wdp *, int listen_mask);
221 int wdp_get_sflow_probability(const struct wdp *, uint32_t *probability);
222 int wdp_set_sflow_probability(struct wdp *, uint32_t probability);
223 int wdp_recv(struct wdp *, struct wdp_packet *);
224 int wdp_recv_purge(struct wdp *);
225 void wdp_recv_wait(struct wdp *);
226
227 void wdp_get_netflow_ids(const struct wdp *,
228                            uint8_t *engine_type, uint8_t *engine_id);
229
230 #ifdef  __cplusplus
231 }
232 #endif
233
234 #endif /* wdp.h */