Import from old repository commit 61ef2b42a9c4ba8e1600f15bb0236765edc2ad45.
[cascardo/ovs.git] / include / openvswitch / datapath-protocol.h
1 /*
2  * Copyright (c) 2009 Nicira Networks.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 /* Protocol between secchan and datapath. */
18
19 #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
20 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
21
22 #ifdef __KERNEL__
23 #include <linux/types.h>
24 #else
25 #include <sys/types.h>
26 #endif
27 #include <linux/if_ether.h>
28
29 #define ODP_MAX 256             /* Maximum number of datapaths. */
30
31 #define ODP_DP_CREATE           _IO('O', 0)
32 #define ODP_DP_DESTROY          _IO('O', 1)
33 #define ODP_DP_STATS            _IOW('O', 2, struct odp_stats)
34
35 #define ODP_GET_DROP_FRAGS      _IOW('O', 3, int)
36 #define ODP_SET_DROP_FRAGS      _IOR('O', 4, int)
37
38 #define ODP_GET_LISTEN_MASK     _IOW('O', 5, int)
39 #define ODP_SET_LISTEN_MASK     _IOR('O', 6, int)
40
41 #define ODP_PORT_ADD            _IOR('O', 7, struct odp_port)
42 #define ODP_PORT_DEL            _IOR('O', 8, int)
43 #define ODP_PORT_QUERY          _IOWR('O', 9, struct odp_port)
44 #define ODP_PORT_LIST           _IOWR('O', 10, struct odp_portvec)
45
46 #define ODP_PORT_GROUP_SET      _IOR('O', 11, struct odp_port_group)
47 #define ODP_PORT_GROUP_GET      _IOWR('O', 12, struct odp_port_group)
48
49 #define ODP_FLOW_GET            _IOWR('O', 13, struct odp_flow)
50 #define ODP_FLOW_GET_MULTIPLE   _IOWR('O', 14, struct odp_flowvec)
51 #define ODP_FLOW_LIST           _IOWR('O', 15, struct odp_flowvec)
52
53 #define ODP_FLOW_FLUSH          _IO('O', 16)
54 #define ODP_FLOW_PUT            _IOWR('O', 17, struct odp_flow)
55 #define ODP_FLOW_DEL            _IOWR('O', 18, struct odp_flow)
56
57 #define ODP_EXECUTE             _IOR('O', 19, struct odp_execute)
58
59 struct odp_stats {
60     /* Flows. */
61     __u32 n_flows;              /* Number of flows in flow table. */
62     __u32 cur_capacity;         /* Current flow table capacity. */
63     __u32 max_capacity;         /* Maximum expansion of flow table capacity. */
64
65     /* Ports. */
66     __u32 n_ports;              /* Current number of ports. */
67     __u32 max_ports;            /* Maximum supported number of ports. */
68     __u16 max_groups;           /* Maximum number of port groups. */
69     __u16 reserved;
70
71     /* Lookups. */
72     __u64 n_frags;               /* Number of dropped IP fragments. */
73     __u64 n_hit;                 /* Number of flow table matches. */
74     __u64 n_missed;              /* Number of flow table misses. */
75     __u64 n_lost;                /* Number of misses not sent to userspace. */
76
77     /* Queues. */
78     __u16 max_miss_queue;       /* Max length of ODPL_MISS queue. */
79     __u16 max_action_queue;     /* Max length of ODPL_ACTION queue. */
80 };
81
82 /* Logical ports. */
83 #define ODPP_LOCAL      ((__u16)0)
84 #define ODPP_NONE       ((__u16)-1)
85
86 /* Listening channels. */
87 #define _ODPL_MISS_NR   0       /* Packet missed in flow table. */
88 #define ODPL_MISS       (1 << _ODPL_MISS_NR)
89 #define _ODPL_ACTION_NR 1       /* Packet output to ODPP_CONTROLLER. */
90 #define ODPL_ACTION     (1 << _ODPL_ACTION_NR)
91 #define ODPL_ALL        (ODPL_MISS | ODPL_ACTION)
92
93 /* Format of messages read from datapath fd. */
94 struct odp_msg {
95     __u32 type;                 /* _ODPL_MISS_NR or _ODPL_ACTION_NR. */
96     __u32 length;               /* Message length, including header. */
97     __u16 port;                 /* Port on which frame was received. */
98     __u16 reserved;
99     __u32 arg;                  /* Argument value specified in action. */
100     /* Followed by packet data. */
101 };
102
103 #define ODP_PORT_INTERNAL (1 << 0) /* This port is simulated. */
104 struct odp_port {
105     char devname[16];           /* IFNAMSIZ */
106     __u16 port;
107     __u16 flags;
108     __u32 reserved2;
109 };
110
111 struct odp_portvec {
112     struct odp_port *ports;
113     int n_ports;
114 };
115
116 struct odp_port_group {
117     __u16 *ports;
118     __u16 n_ports;                /* Number of ports. */
119     __u16 group;                  /* Group number. */
120 };
121
122 struct odp_flow_stats {
123     __u64 n_packets;            /* Number of matched packets. */
124     __u64 n_bytes;              /* Number of matched bytes. */
125     __u64 used_sec;             /* Time last used. */
126     __u32 used_nsec;
127     __u8 tcp_flags;
128     __u8 ip_tos;
129     __u16 reserved;
130 };
131
132 struct odp_flow_key {
133         __be32 nw_src;               /* IP source address. */
134         __be32 nw_dst;               /* IP destination address. */
135         __u16  in_port;              /* Input switch port. */
136         __be16 dl_vlan;              /* Input VLAN. */
137         __be16 dl_type;              /* Ethernet frame type. */
138         __be16 tp_src;               /* TCP/UDP source port. */
139         __be16 tp_dst;               /* TCP/UDP destination port. */
140         __u8   dl_src[ETH_ALEN];     /* Ethernet source address. */
141         __u8   dl_dst[ETH_ALEN];     /* Ethernet destination address. */
142         __u8   nw_proto;             /* IP protocol. */
143         __u8   reserved;             /* Pad to 64 bits. */
144 };
145
146 struct odp_flow {
147     struct odp_flow_stats stats;
148     struct odp_flow_key key;
149     union odp_action *actions;
150     __u32 n_actions;
151 };
152
153 /* Flags for ODP_FLOW_PUT. */
154 #define ODPPF_CREATE        (1 << 0) /* Allow creating a new flow. */
155 #define ODPPF_MODIFY        (1 << 1) /* Allow modifying an existing flow. */
156 #define ODPPF_ZERO_STATS    (1 << 2) /* Zero the stats of an existing flow. */
157
158 /* ODP_FLOW_PUT argument. */
159 struct odp_flow_put {
160     struct odp_flow flow;
161     __u32 flags;
162 };
163
164 struct odp_flowvec {
165     struct odp_flow *flows;
166     int n_flows;
167 };
168
169 /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
170  * special conditions.  All ones is used to match that no VLAN id was
171  * set. */
172 #define ODP_VLAN_NONE      0xffff
173
174 /* Action types. */
175 #define ODPAT_OUTPUT            0    /* Output to switch port. */
176 #define ODPAT_OUTPUT_GROUP      1    /* Output to all ports in group. */
177 #define ODPAT_CONTROLLER        2    /* Send copy to controller. */
178 #define ODPAT_SET_VLAN_VID      3    /* Set the 802.1q VLAN id. */
179 #define ODPAT_SET_VLAN_PCP      4    /* Set the 802.1q priority. */
180 #define ODPAT_STRIP_VLAN        5    /* Strip the 802.1q header. */
181 #define ODPAT_SET_DL_SRC        6    /* Ethernet source address. */
182 #define ODPAT_SET_DL_DST        7    /* Ethernet destination address. */
183 #define ODPAT_SET_NW_SRC        8    /* IP source address. */
184 #define ODPAT_SET_NW_DST        9    /* IP destination address. */
185 #define ODPAT_SET_TP_SRC        10   /* TCP/UDP source port. */
186 #define ODPAT_SET_TP_DST        11   /* TCP/UDP destination port. */
187 #define ODPAT_N_ACTIONS         12
188
189 struct odp_action_output {
190     __u16 type;                  /* ODPAT_OUTPUT. */
191     __u16 port;                  /* Output port. */
192     __u16 reserved1;
193     __u16 reserved2;
194 };
195
196 struct odp_action_output_group {
197     __u16 type;                 /* ODPAT_OUTPUT_GROUP. */
198     __u16 group;                /* Group number. */
199     __u16 reserved1;
200     __u16 reserved2;
201 };
202
203 struct odp_action_controller {
204     __u16 type;                 /* ODPAT_OUTPUT_CONTROLLER. */
205     __u16 reserved;
206     __u32 arg;                  /* Copied to struct odp_msg 'arg' member. */
207 };
208
209 /* Action structure for ODPAT_SET_VLAN_VID. */
210 struct odp_action_vlan_vid {
211     __u16 type;                  /* ODPAT_SET_VLAN_VID. */
212     __be16 vlan_vid;             /* VLAN id. */
213     __u16 reserved1;
214     __u16 reserved2;
215 };
216
217 /* Action structure for ODPAT_SET_VLAN_PCP. */
218 struct odp_action_vlan_pcp {
219     __u16 type;                  /* ODPAT_SET_VLAN_PCP. */
220     __u8 vlan_pcp;               /* VLAN priority. */
221     __u8 reserved1;
222     __u16 reserved2;
223     __u16 reserved3;
224 };
225
226 /* Action structure for ODPAT_SET_DL_SRC/DST. */
227 struct odp_action_dl_addr {
228     __u16 type;                  /* ODPAT_SET_DL_SRC/DST. */
229     __u8 dl_addr[ETH_ALEN];      /* Ethernet address. */
230 };
231
232 /* Action structure for ODPAT_SET_NW_SRC/DST. */
233 struct odp_action_nw_addr {
234     __u16 type;                 /* ODPAT_SET_TW_SRC/DST. */
235     __u16 reserved;
236     __be32 nw_addr;             /* IP address. */
237 };
238
239 /* Action structure for ODPAT_SET_TP_SRC/DST. */
240 struct odp_action_tp_port {
241     __u16 type;                  /* ODPAT_SET_TP_SRC/DST. */
242     __be16 tp_port;              /* TCP/UDP port. */
243     __u16 reserved1;
244     __u16 reserved2;
245 };
246
247 union odp_action {
248     __u16 type;
249     struct odp_action_output output;
250     struct odp_action_output_group output_group;
251     struct odp_action_controller controller;
252     struct odp_action_vlan_vid vlan_vid;
253     struct odp_action_vlan_pcp vlan_pcp;
254     struct odp_action_dl_addr dl_addr;
255     struct odp_action_nw_addr nw_addr;
256     struct odp_action_tp_port tp_port;
257 };
258
259 struct odp_execute {
260     __u16 in_port;
261     __u16 reserved1;
262     __u32 reserved2;
263
264     union odp_action *actions;
265     __u32 n_actions;
266
267     const void *data;
268     __u32 length;
269 };
270
271 /* Values below this cutoff are 802.3 packets and the two bytes
272  * following MAC addresses are used as a frame length.  Otherwise, the
273  * two bytes are used as the Ethernet type.
274  */
275 #define ODP_DL_TYPE_ETH2_CUTOFF   0x0600
276
277 /* Value of dl_type to indicate that the frame does not include an
278  * Ethernet type.
279  */
280 #define ODP_DL_TYPE_NOT_ETH_TYPE  0x05ff
281
282 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
283  * special conditions.  All ones indicates that no VLAN id was set.
284  */
285 #define ODP_VLAN_NONE      0xffff
286
287 #endif /* openvswitch/datapath-protocol.h */