1 /* Copyright (C) 2008 Board of Trustees, Leland Stanford Jr. University.
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 /* Individual switching tables. Generally grouped together in a chain (see
32 /* Iterator through the flows stored in a table. */
34 struct sw_flow *flow; /* Current flow, for use by client. */
38 /* Table statistics. */
39 struct sw_table_stats {
40 const char *name; /* Human-readable name. */
41 unsigned long int n_flows; /* Number of active flows. */
42 unsigned long int max_flows; /* Flow capacity. */
45 /* A single table of flows. */
47 /* Searches 'table' for a flow matching 'key', which must not have any
48 * wildcard fields. Returns the flow if successful, a null pointer
50 struct sw_flow *(*lookup)(struct sw_table *table,
51 const struct sw_flow_key *key);
53 /* Inserts 'flow' into 'table', replacing any duplicate flow. Returns
54 * 0 if successful or a negative error. Error can be due to an
55 * over-capacity table or because the flow is not one of the kind that
58 * If successful, 'flow' becomes owned by 'table', otherwise it is
59 * retained by the caller. */
60 int (*insert)(struct sw_table *table, struct sw_flow *flow);
62 /* Deletes from 'table' any and all flows that match 'key' from
63 * 'table'. If 'strict' set, wildcards must match. Returns the
64 * number of flows that were deleted. */
65 int (*delete)(struct sw_table *table, const struct sw_flow_key *key,
68 /* Performs timeout processing on all the flow entries in 'table'.
69 * Returns the number of flow entries deleted through expiration. */
70 int (*timeout)(struct datapath *dp, struct sw_table *table);
72 /* Destroys 'table', which must not have any users. */
73 void (*destroy)(struct sw_table *table);
75 int (*iterator)(struct sw_table *, struct swt_iterator *);
76 void (*iterator_next)(struct swt_iterator *);
77 void (*iterator_destroy)(struct swt_iterator *);
79 /* Dumps statistics for 'table' into 'stats'. */
80 void (*stats)(struct sw_table *table, struct sw_table_stats *stats);
83 struct sw_table *table_mac_create(unsigned int n_buckets,
84 unsigned int max_flows);
85 struct sw_table *table_hash_create(unsigned int polynomial,
86 unsigned int n_buckets);
87 struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
88 unsigned int poly1, unsigned int buckets1);
89 struct sw_table *table_linear_create(unsigned int max_flows);