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