2 * Copyright (c) 2010 Nicira Networks.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "classifier.h"
33 struct wdp_table_stats {
35 unsigned int n_flows; /* Number of flows in table. */
36 unsigned int cur_capacity; /* Current flow table capacity. */
37 unsigned int max_capacity; /* Maximum expansion of flow table capacity. */
40 unsigned long long int n_hit; /* Number of flow table matches. */
41 unsigned long long int n_missed; /* Number of flow table misses. */
42 unsigned long long int n_lost; /* Misses dropped due to buffer limits. */
46 struct wdp_table_stats exact;
47 struct wdp_table_stats wild;
50 unsigned int n_ports; /* Current number of ports. */
51 unsigned int max_ports; /* Maximum supported number of ports. */
54 unsigned long long int n_frags; /* Number of dropped IP fragments. */
57 unsigned int max_miss_queue; /* Max length of WDP_CHAN_MISS queue. */
58 unsigned int max_action_queue; /* Max length of WDP_CHAN_ACTION queue. */
59 unsigned int max_sflow_queue; /* Max length of WDP_CHAN_SFLOW queue. */
65 union ofp_action *actions; /* OpenFlow actions. */
66 int n_actions; /* Number of elements in 'actions' array. */
67 long long int created; /* Time created, in ms since the epoch. */
68 uint16_t idle_timeout; /* In seconds from time of last use. */
69 uint16_t hard_timeout; /* In seconds from time of creation. */
74 void wdp_rule_init(struct wdp_rule *, const union ofp_action *actions,
76 void wdp_rule_uninit(struct wdp_rule *);
81 int wdp_register_provider(const struct wdp_class *);
82 int wdp_unregister_provider(const char *type);
83 void wdp_enumerate_types(struct svec *types);
85 int wdp_enumerate_names(const char *type, struct svec *names);
86 void wdp_parse_name(const char *datapath_name, char **name, char **type);
88 void wdp_run_expiration(struct wdp *);
89 void wdp_run_revalidation(struct wdp *, bool revalidate_all);
91 int wdp_open(const char *name, const char *type, struct wdp **);
92 int wdp_create(const char *name, const char *type, struct wdp **);
93 int wdp_create_and_open(const char *name, const char *type, struct wdp **);
94 void wdp_close(struct wdp *);
96 const char *wdp_name(const struct wdp *);
97 const char *wdp_base_name(const struct wdp *);
98 int wdp_get_all_names(const struct wdp *, struct svec *);
100 int wdp_delete(struct wdp *);
102 int wdp_get_features(const struct wdp *, struct ofpbuf **featuresp);
103 int wdp_get_wdp_stats(const struct wdp *, struct wdp_stats *);
105 int wdp_get_drop_frags(const struct wdp *, bool *drop_frags);
106 int wdp_set_drop_frags(struct wdp *, bool drop_frags);
109 struct netdev *netdev;
110 struct ofp_phy_port opp; /* In *host* byte order. */
111 char *devname; /* Network device name. */
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);
119 int wdp_port_add(struct wdp *, const char *devname, bool internal,
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,
124 int wdp_port_query_by_name(const struct wdp *, const char *devname,
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);
129 int wdp_port_set_config(struct wdp *, uint16_t port_no, uint32_t config);
131 int wdp_port_poll(const struct wdp *, char **devnamep);
132 void wdp_port_poll_wait(const struct wdp *);
134 int wdp_flow_flush(struct wdp *);
136 struct wdp_flow_stats {
137 unsigned long long int n_packets; /* Number of matched packets. */
138 unsigned long long int n_bytes; /* Number of matched bytes. */
139 long long int inserted; /* Time inserted into flow table. */
140 long long int used; /* Time last used. */
141 uint8_t tcp_flags; /* Bitwise-OR of TCP flags seen. */
142 uint8_t ip_tos; /* IP TOS for most recent packet. */
145 /* Finding and inspecting flows. */
146 struct wdp_rule *wdp_flow_get(struct wdp *, const flow_t *);
147 struct wdp_rule *wdp_flow_match(struct wdp *, const flow_t *);
149 typedef void wdp_flow_cb_func(struct wdp_rule *, void *aux);
150 void wdp_flow_for_each_match(const struct wdp *, const flow_t *,
151 int include, wdp_flow_cb_func *, void *aux);
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 *);
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. */
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)
172 struct wdp_flow_put {
173 enum wdp_flow_put_flags flags;
177 const union ofp_action *actions;
180 unsigned short int idle_timeout;
181 unsigned short int hard_timeout;
184 int wdp_flow_put(struct wdp *, struct wdp_flow_put *,
185 struct wdp_flow_stats *old_stats,
186 struct wdp_rule **rulep);
187 int wdp_flow_delete(struct wdp *, struct wdp_rule *,
188 struct wdp_flow_stats *final_stats);
190 /* Sending packets in flows. */
191 int wdp_flow_inject(struct wdp *, struct wdp_rule *,
192 uint16_t in_port, const struct ofpbuf *);
193 int wdp_execute(struct wdp *, uint16_t in_port,
194 const union ofp_action[], size_t n_actions,
195 const struct ofpbuf *);
197 /* Receiving packets that miss the flow table. */
199 WDP_CHAN_MISS, /* Packet missed in flow table. */
200 WDP_CHAN_ACTION, /* Packet output to OFPP_CONTROLLER. */
201 WDP_CHAN_SFLOW, /* sFlow samples. */
207 enum wdp_channel channel;
210 struct ofpbuf *payload;
213 void wdp_packet_destroy(struct wdp_packet *);
215 int wdp_recv_get_mask(const struct wdp *, int *listen_mask);
216 int wdp_recv_set_mask(struct wdp *, int listen_mask);
217 int wdp_get_sflow_probability(const struct wdp *, uint32_t *probability);
218 int wdp_set_sflow_probability(struct wdp *, uint32_t probability);
219 int wdp_recv(struct wdp *, struct wdp_packet *);
220 int wdp_recv_purge(struct wdp *);
221 void wdp_recv_wait(struct wdp *);
223 void wdp_get_netflow_ids(const struct wdp *,
224 uint8_t *engine_type, uint8_t *engine_id);