69417583fd8b27cef2637f1f579dd5cd421ec03c
[sliver-openvswitch.git] / switch / switch-flow.h
1 /* Copyright (C) 2008 Board of Trustees, Leland Stanford Jr. University.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21
22 #ifndef SWITCH_FLOW_H
23 #define SWITCH_FLOW_H 1
24
25 #include <time.h>
26 #include "flow.h"
27 #include "list.h"
28
29 struct ofp_match;
30
31 /* Identification data for a flow. */
32 struct sw_flow_key {
33     struct flow flow;           /* Flow data (in network byte order). */
34     uint32_t wildcards;         /* Wildcard fields (in host byte order). */
35 };
36
37 /* Maximum number of actions in a single flow entry. */
38 #define MAX_ACTIONS 16
39
40 struct sw_flow {
41     struct sw_flow_key key;
42
43     uint32_t group_id;          /* Flow group ID (for QoS). */
44     uint16_t max_idle;          /* Idle time before discarding (seconds). */
45     time_t created;             /* When the flow was created. */
46     time_t timeout;             /* When the flow expires (if idle). */
47     uint64_t packet_count;      /* Number of packets seen. */
48     uint64_t byte_count;        /* Number of bytes seen. */
49     struct list node;
50
51     /* Actions (XXX probably most flows have only a single action). */
52     unsigned int n_actions;
53     struct ofp_action *actions;
54 };
55
56 int flow_matches(const struct sw_flow_key *, const struct sw_flow_key *);
57 int flow_del_matches(const struct sw_flow_key *, const struct sw_flow_key *, 
58                      int);
59 struct sw_flow *flow_alloc(int n_actions);
60 void flow_free(struct sw_flow *);
61 void flow_deferred_free(struct sw_flow *);
62 void flow_extract_match(struct sw_flow_key* to, const struct ofp_match* from);
63 void flow_fill_match(struct ofp_match* to, const struct sw_flow_key* from);
64
65 void print_flow(const struct sw_flow_key *);
66 int flow_timeout(struct sw_flow *flow);
67 void flow_used(struct sw_flow *flow, struct buffer *buffer);
68
69 #endif /* switch-flow.h */