Make dumping large numbers of flows possible.
[sliver-openvswitch.git] / datapath / table.h
1 /* Individual switching tables.  Generally grouped together in a chain (see
2  * chain.h). */
3
4 #ifndef TABLE_H
5 #define TABLE_H 1
6
7 struct sw_flow;
8 struct sw_flow_key;
9 struct datapath;
10
11 /* Table statistics. */
12 struct sw_table_stats {
13         const char *name;       /* Human-readable name. */
14         unsigned long int n_flows; /* Number of active flows. */
15         unsigned long int max_flows; /* Flow capacity. */
16 };
17
18 /* Position within an iteration of a sw_table.
19  *
20  * The contents are private to the table implementation, except that a position
21  * initialized to all-zero-bits represents the start of a table. */
22 struct sw_table_position {
23         unsigned long private[4];
24 };
25
26 /* A single table of flows.
27  *
28  * All functions, except destroy, must be called holding the
29  * rcu_read_lock.  destroy must be fully serialized.
30  */
31 struct sw_table {
32         /* Searches 'table' for a flow matching 'key', which must not have any
33          * wildcard fields.  Returns the flow if successful, a null pointer
34          * otherwise. */
35         struct sw_flow *(*lookup)(struct sw_table *table,
36                         const struct sw_flow_key *key);
37
38         /* Inserts 'flow' into 'table', replacing any duplicate flow.  Returns
39          * 0 if successful or a negative error.  Error can be due to an
40          * over-capacity table or because the flow is not one of the kind that
41          * the table accepts.
42          *
43          * If successful, 'flow' becomes owned by 'table', otherwise it is
44          * retained by the caller. */
45         int (*insert)(struct sw_table *table, struct sw_flow *flow);
46
47         /* Deletes from 'table' any and all flows that match 'key' from
48          * 'table'.  If 'strict' set, wildcards must match.  Returns the 
49          * number of flows that were deleted. */
50         int (*delete)(struct sw_table *table, const struct sw_flow_key *key, 
51                         int strict);
52
53         /* Performs timeout processing on all the flow entries in 'table'.
54          * Returns the number of flow entries deleted through expiration. */
55         int (*timeout)(struct datapath *dp, struct sw_table *table);
56
57         /* Destroys 'table', which must not have any users. */
58         void (*destroy)(struct sw_table *table);
59
60         /* Iterates through the flow entries in 'table', passing each one
61          * matches 'key' to 'callback'.  The callback function should return 0
62          * to continue iteration or a nonzero error code to stop.  The iterator
63          * function returns either 0 if the table iteration completed or the
64          * value returned by the callback function otherwise.
65          *
66          * The iteration starts at 'position', which may be initialized to
67          * all-zero-bits to iterate from the beginning of the table.  If the
68          * iteration terminates due to an error from the callback function,
69          * 'position' is updated to a value that can be passed back to the
70          * iterator function to resume iteration later with the following
71          * flow. */
72         int (*iterate)(struct sw_table *table,
73                        const struct sw_flow_key *key,
74                        struct sw_table_position *position,
75                        int (*callback)(struct sw_flow *flow, void *private),
76                        void *private);
77
78         /* Dumps statistics for 'table' into 'stats'. */
79         void (*stats)(struct sw_table *table, struct sw_table_stats *stats);
80 };
81
82 struct sw_table *table_hash_create(unsigned int polynomial,
83                 unsigned int n_buckets);
84 struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
85                 unsigned int poly1, unsigned int buckets1);
86 struct sw_table *table_linear_create(unsigned int max_flows);
87
88 #endif /* table.h */