2 * Copyright (c) 2009 Nicira Networks.
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.
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.
17 /* Protocol between secchan and datapath. */
19 #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
20 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
23 #include <linux/types.h>
25 #include <sys/types.h>
27 #include <linux/if_ether.h>
29 #define ODP_MAX 256 /* Maximum number of datapaths. */
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)
35 #define ODP_GET_DROP_FRAGS _IOW('O', 3, int)
36 #define ODP_SET_DROP_FRAGS _IOR('O', 4, int)
38 #define ODP_GET_LISTEN_MASK _IOW('O', 5, int)
39 #define ODP_SET_LISTEN_MASK _IOR('O', 6, int)
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)
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)
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)
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)
57 #define ODP_EXECUTE _IOR('O', 19, struct odp_execute)
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. */
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. */
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. */
78 __u16 max_miss_queue; /* Max length of ODPL_MISS queue. */
79 __u16 max_action_queue; /* Max length of ODPL_ACTION queue. */
83 #define ODPP_LOCAL ((__u16)0)
84 #define ODPP_NONE ((__u16)-1)
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)
93 /* Format of messages read from datapath fd. */
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. */
99 __u32 arg; /* Argument value specified in action. */
100 /* Followed by packet data. */
103 #define ODP_PORT_INTERNAL (1 << 0) /* This port is simulated. */
105 char devname[16]; /* IFNAMSIZ */
112 struct odp_port *ports;
116 struct odp_port_group {
118 __u16 n_ports; /* Number of ports. */
119 __u16 group; /* Group number. */
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. */
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. */
147 struct odp_flow_stats stats;
148 struct odp_flow_key key;
149 union odp_action *actions;
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. */
158 /* ODP_FLOW_PUT argument. */
159 struct odp_flow_put {
160 struct odp_flow flow;
165 struct odp_flow *flows;
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
172 #define ODP_VLAN_NONE 0xffff
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
189 struct odp_action_output {
190 __u16 type; /* ODPAT_OUTPUT. */
191 __u16 port; /* Output port. */
196 struct odp_action_output_group {
197 __u16 type; /* ODPAT_OUTPUT_GROUP. */
198 __u16 group; /* Group number. */
203 struct odp_action_controller {
204 __u16 type; /* ODPAT_OUTPUT_CONTROLLER. */
206 __u32 arg; /* Copied to struct odp_msg 'arg' member. */
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. */
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. */
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. */
232 /* Action structure for ODPAT_SET_NW_SRC/DST. */
233 struct odp_action_nw_addr {
234 __u16 type; /* ODPAT_SET_TW_SRC/DST. */
236 __be32 nw_addr; /* IP address. */
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. */
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;
264 union odp_action *actions;
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.
275 #define ODP_DL_TYPE_ETH2_CUTOFF 0x0600
277 /* Value of dl_type to indicate that the frame does not include an
280 #define ODP_DL_TYPE_NOT_ETH_TYPE 0x05ff
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.
285 #define ODP_VLAN_NONE 0xffff
287 #endif /* openvswitch/datapath-protocol.h */