Modify OpenFlow commands related to ports to be more expressive.
[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_MULTI_PHY_TX )
28
29 /* Actions supported by this implementation. */
30 #define OFP_SUPPORTED_ACTIONS ( (1 << OFPAT_OUTPUT) \
31                 | (1 << OFPAT_SET_DL_VLAN) \
32                 | (1 << OFPAT_SET_DL_SRC) \
33                 | (1 << OFPAT_SET_DL_DST) \
34                 | (1 << OFPAT_SET_NW_SRC) \
35                 | (1 << OFPAT_SET_NW_DST) \
36                 | (1 << OFPAT_SET_TP_SRC) \
37                 | (1 << OFPAT_SET_TP_DST) )
38
39 struct sk_buff;
40
41 struct datapath {
42         int dp_idx;
43
44         /* Unique identifier for this datapath, incorporates the dp_idx and
45          * a hardware address */
46         uint64_t  id;
47
48         struct timer_list timer;        /* Expiration timer. */
49         struct sw_chain *chain;  /* Forwarding rules. */
50         struct task_struct *dp_task; /* Kernel thread for maintenance. */
51
52         /* Data related to the "of" device of this datapath */
53         struct net_device *netdev;
54
55         /* Configuration set from controller */
56         uint16_t flags;
57         uint16_t miss_send_len;
58
59         /* Switch ports. */
60         struct net_bridge_port *ports[OFPP_MAX];
61         struct net_bridge_port *local_port; /* OFPP_LOCAL port. */
62         struct list_head port_list; /* All ports, including local_port. */
63 };
64
65 /* Information necessary to reply to the sender of an OpenFlow message. */
66 struct sender {
67         uint32_t xid;           /* OpenFlow transaction ID of request. */
68         uint32_t pid;           /* Netlink process ID of sending socket. */
69         uint32_t seq;           /* Netlink sequence ID of request. */
70 };
71
72 struct net_bridge_port {
73         u16     port_no;
74         u32 config;             /* Some subset of OFPPC_* flags. */
75         u32 state;              /* Some subset of OFPPS_* flags. */
76         spinlock_t lock;
77         struct work_struct port_task;
78         struct datapath *dp;
79         struct net_device *dev;
80         struct list_head node; /* Element in datapath.ports. */
81 };
82
83 extern struct mutex dp_mutex;
84 extern struct notifier_block dp_device_notifier;
85
86 int dp_del_switch_port(struct net_bridge_port *);
87 int dp_output_port(struct datapath *, struct sk_buff *, int out_port,
88                    int ignore_no_fwd);
89 int dp_output_control(struct datapath *, struct sk_buff *, uint32_t, 
90                         size_t, int);
91 int dp_set_origin(struct datapath *, uint16_t, struct sk_buff *);
92 int dp_send_features_reply(struct datapath *, const struct sender *);
93 int dp_send_config_reply(struct datapath *, const struct sender *);
94 int dp_send_port_status(struct net_bridge_port *p, uint8_t status);
95 int dp_send_flow_expired(struct datapath *, struct sw_flow *,
96                          enum ofp_flow_expired_reason);
97 int dp_send_error_msg(struct datapath *, const struct sender *, 
98                         uint16_t, uint16_t, const void *, size_t);
99 int dp_update_port_flags(struct datapath *dp, const struct ofp_port_mod *opm);
100 int dp_send_echo_reply(struct datapath *, const struct sender *,
101                        const struct ofp_header *);
102 int dp_send_hello(struct datapath *, const struct sender *,
103                   const struct ofp_header *);
104
105 /* Should hold at least RCU read lock when calling */
106 struct datapath *dp_get(int dp_idx);
107
108 #endif /* datapath.h */