Implement userspace switch.
[sliver-openvswitch.git] / switch / datapath.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 /* Interface exported by OpenFlow module. */
23
24 #ifndef DATAPATH_H
25 #define DATAPATH_H 1
26
27 #include <time.h>
28 #include "openflow.h"
29 #include "switch-flow.h"
30 #include "buffer.h"
31 #include "list.h"
32
33 #define NL_FLOWS_PER_MESSAGE 100
34
35 /* Capabilities supported by this implementation. */
36 #define OFP_SUPPORTED_CAPABILITIES (OFPC_MULTI_PHY_TX)
37
38 /* Actions supported by this implementation. */
39 #define OFP_SUPPORTED_ACTIONS ( (1 << OFPAT_OUTPUT)         \
40                                 | (1 << OFPAT_SET_DL_VLAN)  \
41                                 | (1 << OFPAT_SET_DL_SRC)   \
42                                 | (1 << OFPAT_SET_DL_DST)   \
43                                 | (1 << OFPAT_SET_NW_SRC)   \
44                                 | (1 << OFPAT_SET_NW_DST)   \
45                                 | (1 << OFPAT_SET_TP_SRC)   \
46                                 | (1 << OFPAT_SET_TP_DST) )
47
48 struct sw_port {
49     uint32_t flags;
50     struct datapath *dp;
51     struct netdev *netdev;
52     struct list node; /* Element in datapath.ports. */
53 };
54
55 struct datapath {
56     struct controller_connection *cc;
57
58     time_t last_timeout;
59
60     /* Unique identifier for this datapath */
61     uint64_t  id;
62
63     struct sw_chain *chain;  /* Forwarding rules. */
64
65     /* Flags from the control hello message */
66     uint16_t hello_flags;
67
68     /* Maximum number of bytes that should be sent for flow misses */
69     uint16_t miss_send_len;
70
71     /* Switch ports. */
72     struct sw_port ports[OFPP_MAX];
73     struct list port_list; /* List of ports, for flooding. */
74 };
75
76 int dp_new(struct datapath **, uint64_t dpid, struct controller_connection *);
77 int dp_add_port(struct datapath *, const char *netdev);
78 void dp_run(struct datapath *);
79 void dp_wait(struct datapath *);
80
81 void dp_output_port(struct datapath *, struct buffer *,
82                     int in_port, int out_port);
83 void dp_output_control(struct datapath *, struct buffer *, int in_port,
84                        uint32_t buffer_id, size_t max_len, int reason);
85 void dp_send_hello(struct datapath *);
86 void dp_send_flow_expired(struct datapath *, struct sw_flow *);
87 void dp_update_port_flags(struct datapath *dp, const struct ofp_phy_port *opp);
88
89 #endif /* datapath.h */