Add support for exporting flow information in NetFlow v5 format.
[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 ofp_action_header;
12 struct datapath;
13
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. */
23 };
24
25 /* Position within an iteration of a sw_table.
26  *
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];
31 };
32
33 /* A single table of flows.
34  *
35  * All functions, except destroy, must be called holding the
36  * rcu_read_lock.  destroy must be fully serialized.
37  */
38 struct sw_table {
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;
44
45         /* Searches 'table' for a flow matching 'key', which must not have any
46          * wildcard fields.  Returns the flow if successful, a null pointer
47          * otherwise. */
48         struct sw_flow *(*lookup)(struct sw_table *table,
49                         const struct sw_flow_key *key);
50
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
54          * the table accepts.
55          *
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);
59
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);
66
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 datapath *dp, struct sw_table *table, 
73                         const struct sw_flow_key *key, 
74                         uint16_t out_port, uint16_t priority, int strict);
75
76         /* Performs timeout processing on all the flow entries in 'table'.
77          * Returns the number of flow entries deleted through expiration. */
78         int (*timeout)(struct datapath *dp, struct sw_table *table);
79
80         /* Destroys 'table', which must not have any users. */
81         void (*destroy)(struct sw_table *table);
82
83         /* Iterates through the flow entries in 'table', passing each one
84          * matches 'key' and output port 'out_port' to 'callback'.  The 
85          * callback function should return 0 to continue iteration or a 
86          * nonzero error code to stop.  The iterator function returns either 
87          * 0 if the table iteration completed or the value returned by the 
88          * callback function otherwise.
89          *
90          * The iteration starts at 'position', which may be initialized to
91          * all-zero-bits to iterate from the beginning of the table.  If the
92          * iteration terminates due to an error from the callback function,
93          * 'position' is updated to a value that can be passed back to the
94          * iterator function to continue iteration later from the same position
95          * that caused the error (assuming that that flow entry has not been
96          * deleted in the meantime). */
97         int (*iterate)(struct sw_table *table,
98                        const struct sw_flow_key *key, uint16_t out_port,
99                        struct sw_table_position *position,
100                        int (*callback)(struct sw_flow *flow, void *private),
101                        void *private);
102
103         /* Dumps statistics for 'table' into 'stats'. */
104         void (*stats)(struct sw_table *table, struct sw_table_stats *stats);
105 };
106
107 struct sw_table *table_hash_create(unsigned int polynomial,
108                 unsigned int n_buckets);
109 struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
110                 unsigned int poly1, unsigned int buckets1);
111 struct sw_table *table_linear_create(unsigned int max_flows);
112
113 #endif /* table.h */