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