1 /* Individual switching tables. Generally grouped together in a chain (see
7 #include <linux/types.h>
13 /* Table statistics. */
14 struct sw_table_stats {
15 const char *name; /* Human-readable name. */
16 unsigned long int n_flows; /* Number of active flows. */
17 unsigned long int max_flows; /* Flow capacity. */
20 /* Position within an iteration of a sw_table.
22 * The contents are private to the table implementation, except that a position
23 * initialized to all-zero-bits represents the start of a table. */
24 struct sw_table_position {
25 unsigned long private[4];
28 /* A single table of flows.
30 * All functions, except destroy, must be called holding the
31 * rcu_read_lock. destroy must be fully serialized.
34 /* Searches 'table' for a flow matching 'key', which must not have any
35 * wildcard fields. Returns the flow if successful, a null pointer
37 struct sw_flow *(*lookup)(struct sw_table *table,
38 const struct sw_flow_key *key);
40 /* Inserts 'flow' into 'table', replacing any duplicate flow. Returns
41 * 0 if successful or a negative error. Error can be due to an
42 * over-capacity table or because the flow is not one of the kind that
45 * If successful, 'flow' becomes owned by 'table', otherwise it is
46 * retained by the caller. */
47 int (*insert)(struct sw_table *table, struct sw_flow *flow);
49 /* Deletes from 'table' any and all flows that match 'key' from
50 * 'table'. If 'strict' set, wildcards and priority must match.
51 * Returns the number of flows that were deleted. */
52 int (*delete)(struct sw_table *table, const struct sw_flow_key *key,
53 uint16_t priority, int strict);
55 /* Performs timeout processing on all the flow entries in 'table'.
56 * Returns the number of flow entries deleted through expiration. */
57 int (*timeout)(struct datapath *dp, struct sw_table *table);
59 /* Destroys 'table', which must not have any users. */
60 void (*destroy)(struct sw_table *table);
62 /* Iterates through the flow entries in 'table', passing each one
63 * matches 'key' to 'callback'. The callback function should return 0
64 * to continue iteration or a nonzero error code to stop. The iterator
65 * function returns either 0 if the table iteration completed or the
66 * value returned by the callback function otherwise.
68 * The iteration starts at 'position', which may be initialized to
69 * all-zero-bits to iterate from the beginning of the table. If the
70 * iteration terminates due to an error from the callback function,
71 * 'position' is updated to a value that can be passed back to the
72 * iterator function to continue iteration later from the same position
73 * that caused the error (assuming that that flow entry has not been
74 * deleted in the meantime). */
75 int (*iterate)(struct sw_table *table,
76 const struct sw_flow_key *key,
77 struct sw_table_position *position,
78 int (*callback)(struct sw_flow *flow, void *private),
81 /* Dumps statistics for 'table' into 'stats'. */
82 void (*stats)(struct sw_table *table, struct sw_table_stats *stats);
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);