Implement 802.1D Spanning Tree Protocol.
[sliver-openvswitch.git] / datapath / datapath.h
1 /* Interface exported by OpenFlow module. */
2
3 #ifndef DATAPATH_H
4 #define DATAPATH_H 1
5
6 #include <linux/mutex.h>
7 #include <linux/netlink.h>
8 #include <linux/netdevice.h>
9 #include <linux/workqueue.h>
10 #include <linux/skbuff.h>
11 #include "openflow.h"
12 #include "flow.h"
13
14
15 #define NL_FLOWS_PER_MESSAGE 100
16
17 #ifdef NDEBUG
18 #define dprintk(x...)
19 #else
20 #define dprintk(x...) printk(x)
21 #endif
22
23 /* Capabilities supported by this implementation. */
24 #define OFP_SUPPORTED_CAPABILITIES ( OFPC_FLOW_STATS \
25                 | OFPC_TABLE_STATS \
26                 | OFPC_PORT_STATS \
27                 | OFPC_STP \
28                 | OFPC_MULTI_PHY_TX )
29
30 /* Actions supported by this implementation. */
31 #define OFP_SUPPORTED_ACTIONS ( (1 << OFPAT_OUTPUT) \
32                 | (1 << OFPAT_SET_DL_VLAN) \
33                 | (1 << OFPAT_SET_DL_SRC) \
34                 | (1 << OFPAT_SET_DL_DST) \
35                 | (1 << OFPAT_SET_NW_SRC) \
36                 | (1 << OFPAT_SET_NW_DST) \
37                 | (1 << OFPAT_SET_TP_SRC) \
38                 | (1 << OFPAT_SET_TP_DST) )
39
40 struct sk_buff;
41
42 struct datapath {
43         int dp_idx;
44
45         /* Unique identifier for this datapath, incorporates the dp_idx and
46          * a hardware address */
47         uint64_t  id;
48
49         struct timer_list timer;        /* Expiration timer. */
50         struct sw_chain *chain;  /* Forwarding rules. */
51         struct task_struct *dp_task; /* Kernel thread for maintenance. */
52
53         /* Data related to the "of" device of this datapath */
54         struct net_device *netdev;
55
56         /* Configuration set from controller */
57         uint16_t flags;
58         uint16_t miss_send_len;
59
60         /* Switch ports. */
61         struct net_bridge_port *ports[OFPP_MAX];
62         struct net_bridge_port *local_port; /* OFPP_LOCAL port. */
63         struct list_head port_list; /* All ports, including local_port. */
64 };
65
66 /* Information necessary to reply to the sender of an OpenFlow message. */
67 struct sender {
68         uint32_t xid;           /* OpenFlow transaction ID of request. */
69         uint32_t pid;           /* Netlink process ID of sending socket. */
70         uint32_t seq;           /* Netlink sequence ID of request. */
71 };
72
73 #define PORT_STATUS_BITS (OFPPFL_PORT_DOWN | OFPPFL_LINK_DOWN)
74 #define PORT_FLAG_BITS (~PORT_STATUS_BITS)
75
76 struct net_bridge_port {
77         u16     port_no;
78         u32 flags;              /* Some subset of PORT_FLAG_BITS. */
79         u32 status;             /* Some subset of PORT_STATUS_BITS. */
80         spinlock_t lock;
81         struct work_struct port_task;
82         struct datapath *dp;
83         struct net_device *dev;
84         struct list_head node; /* Element in datapath.ports. */
85 };
86
87 extern struct mutex dp_mutex;
88
89 int dp_output_port(struct datapath *, struct sk_buff *, int out_port,
90                    int ignore_no_fwd);
91 int dp_output_control(struct datapath *, struct sk_buff *, uint32_t, 
92                         size_t, int);
93 int dp_set_origin(struct datapath *, uint16_t, struct sk_buff *);
94 int dp_send_features_reply(struct datapath *, const struct sender *);
95 int dp_send_config_reply(struct datapath *, const struct sender *);
96 int dp_send_flow_expired(struct datapath *, struct sw_flow *,
97                          enum ofp_flow_expired_reason);
98 int dp_send_error_msg(struct datapath *, const struct sender *, 
99                         uint16_t, uint16_t, const uint8_t *, size_t);
100 int dp_update_port_flags(struct datapath *dp, const struct ofp_port_mod *opm);
101 int dp_send_echo_reply(struct datapath *, const struct sender *,
102                        const struct ofp_header *);
103
104 /* Should hold at least RCU read lock when calling */
105 struct datapath *dp_get(int dp_idx);
106
107 #endif /* datapath.h */