1 /* Individual switching tables. Generally grouped together in a chain (see
7 #include <linux/types.h>
11 struct ofp_action_header;
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_lookup; /* Number of packets looked up. */
22 unsigned long int n_matched; /* Number of packets that have hit. */
25 /* Position within an iteration of a sw_table.
27 * The contents are private to the table implementation, except that a position
28 * initialized to all-zero-bits represents the start of a table. */
29 struct sw_table_position {
30 unsigned long private[4];
33 /* A single table of flows.
35 * All functions, except destroy, must be called holding the
36 * rcu_read_lock. destroy must be fully serialized.
39 /* The number of packets that have been looked up and matched,
40 * respecitvely. To make these 100% accurate, they should be atomic.
41 * However, we're primarily concerned about speed. */
42 unsigned long long n_lookup;
43 unsigned long long n_matched;
45 /* Searches 'table' for a flow matching 'key', which must not have any
46 * wildcard fields. Returns the flow if successful, a null pointer
48 struct sw_flow *(*lookup)(struct sw_table *table,
49 const struct sw_flow_key *key);
51 /* Inserts 'flow' into 'table', replacing any duplicate flow. Returns
52 * 0 if successful or a negative error. Error can be due to an
53 * over-capacity table or because the flow is not one of the kind that
56 * If successful, 'flow' becomes owned by 'table', otherwise it is
57 * retained by the caller. */
58 int (*insert)(struct sw_table *table, struct sw_flow *flow);
60 /* Modifies the actions in 'table' that match 'key'. If 'strict'
61 * set, wildcards and priority must match. Returns the number of flows
62 * that were modified. */
63 int (*modify)(struct sw_table *table, const struct sw_flow_key *key,
64 uint16_t priority, int strict,
65 const struct ofp_action_header *actions, size_t actions_len);
67 /* Deletes from 'table' any and all flows that match 'key' from
68 * 'table'. If 'out_port' is not OFPP_NONE, then matching entries
69 * must have that port as an argument for an output action. If
70 * 'strict' is set, wildcards and priority must match. Returns the
71 * number of flows that were deleted. */
72 int (*delete)(struct sw_table *table, const struct sw_flow_key *key,
73 uint16_t out_port, uint16_t priority, int strict);
75 /* Performs timeout processing on all the flow entries in 'table'.
76 * Returns the number of flow entries deleted through expiration. */
77 int (*timeout)(struct datapath *dp, struct sw_table *table);
79 /* Destroys 'table', which must not have any users. */
80 void (*destroy)(struct sw_table *table);
82 /* Iterates through the flow entries in 'table', passing each one
83 * matches 'key' and output port 'out_port' to 'callback'. The
84 * callback function should return 0 to continue iteration or a
85 * nonzero error code to stop. The iterator function returns either
86 * 0 if the table iteration completed or the value returned by the
87 * callback function otherwise.
89 * The iteration starts at 'position', which may be initialized to
90 * all-zero-bits to iterate from the beginning of the table. If the
91 * iteration terminates due to an error from the callback function,
92 * 'position' is updated to a value that can be passed back to the
93 * iterator function to continue iteration later from the same position
94 * that caused the error (assuming that that flow entry has not been
95 * deleted in the meantime). */
96 int (*iterate)(struct sw_table *table,
97 const struct sw_flow_key *key, uint16_t out_port,
98 struct sw_table_position *position,
99 int (*callback)(struct sw_flow *flow, void *private),
102 /* Dumps statistics for 'table' into 'stats'. */
103 void (*stats)(struct sw_table *table, struct sw_table_stats *stats);
106 struct sw_table *table_hash_create(unsigned int polynomial,
107 unsigned int n_buckets);
108 struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
109 unsigned int poly1, unsigned int buckets1);
110 struct sw_table *table_linear_create(unsigned int max_flows);