1 /* Individual switching tables. Generally grouped together in a chain (see
7 #include <linux/types.h>
14 /* Table statistics. */
15 struct sw_table_stats {
16 const char *name; /* Human-readable name. */
17 uint32_t wildcards; /* Bitmap of OFPFW_* wildcards that are
18 supported by the table. */
19 unsigned int n_flows; /* Number of active flows. */
20 unsigned int max_flows; /* Flow capacity. */
21 unsigned long int n_matched; /* Number of packets that have hit. */
24 /* Position within an iteration of a sw_table.
26 * The contents are private to the table implementation, except that a position
27 * initialized to all-zero-bits represents the start of a table. */
28 struct sw_table_position {
29 unsigned long private[4];
32 /* A single table of flows.
34 * All functions, except destroy, must be called holding the
35 * rcu_read_lock. destroy must be fully serialized.
38 /* Keep track of the number of packets that matched this table. To
39 * make this 100% accurate, it should be atomic. However, we're
40 * primarily concerned about speed. */
41 unsigned long int n_matched;
43 /* Searches 'table' for a flow matching 'key', which must not have any
44 * wildcard fields. Returns the flow if successful, a null pointer
46 struct sw_flow *(*lookup)(struct sw_table *table,
47 const struct sw_flow_key *key);
49 /* Inserts 'flow' into 'table', replacing any duplicate flow. Returns
50 * 0 if successful or a negative error. Error can be due to an
51 * over-capacity table or because the flow is not one of the kind that
54 * If successful, 'flow' becomes owned by 'table', otherwise it is
55 * retained by the caller. */
56 int (*insert)(struct sw_table *table, struct sw_flow *flow);
58 /* Modifies the actions in 'table' that match 'key'. If 'strict'
59 * set, wildcards and priority must match. Returns the number of flows
60 * that were modified. */
61 int (*modify)(struct sw_table *table, const struct sw_flow_key *key,
62 uint16_t priority, int strict,
63 const struct ofp_action *actions, int n_actions);
65 /* Deletes from 'table' any and all flows that match 'key' from
66 * 'table'. If 'strict' set, wildcards and priority must match.
67 * Returns the number of flows that were deleted. */
68 int (*delete)(struct sw_table *table, const struct sw_flow_key *key,
69 uint16_t priority, int strict);
71 /* Performs timeout processing on all the flow entries in 'table'.
72 * Returns the number of flow entries deleted through expiration. */
73 int (*timeout)(struct datapath *dp, struct sw_table *table);
75 /* Destroys 'table', which must not have any users. */
76 void (*destroy)(struct sw_table *table);
78 /* Iterates through the flow entries in 'table', passing each one
79 * matches 'key' to 'callback'. The callback function should return 0
80 * to continue iteration or a nonzero error code to stop. The iterator
81 * function returns either 0 if the table iteration completed or the
82 * value returned by the callback function otherwise.
84 * The iteration starts at 'position', which may be initialized to
85 * all-zero-bits to iterate from the beginning of the table. If the
86 * iteration terminates due to an error from the callback function,
87 * 'position' is updated to a value that can be passed back to the
88 * iterator function to continue iteration later from the same position
89 * that caused the error (assuming that that flow entry has not been
90 * deleted in the meantime). */
91 int (*iterate)(struct sw_table *table,
92 const struct sw_flow_key *key,
93 struct sw_table_position *position,
94 int (*callback)(struct sw_flow *flow, void *private),
97 /* Dumps statistics for 'table' into 'stats'. */
98 void (*stats)(struct sw_table *table, struct sw_table_stats *stats);
101 struct sw_table *table_hash_create(unsigned int polynomial,
102 unsigned int n_buckets);
103 struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
104 unsigned int poly1, unsigned int buckets1);
105 struct sw_table *table_linear_create(unsigned int max_flows);