Fix typos in comments.
[sliver-openvswitch.git] / include / openflow / nicira-ext.h
1 /*
2  * Copyright (c) 2008, 2009, 2010 Nicira Networks
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OPENFLOW_NICIRA_EXT_H
18 #define OPENFLOW_NICIRA_EXT_H 1
19
20 #include "openflow/openflow.h"
21 #include "openvswitch/types.h"
22
23 #define NICIRA_OUI_STR "002320"
24
25 /* The following vendor extensions, proposed by Nicira Networks, are not yet
26  * standardized, so they are not included in openflow.h.  Some of them may be
27  * suitable for standardization; others we never expect to standardize. */
28
29 #define NX_VENDOR_ID 0x00002320
30 \f
31 /* Nicira vendor-specific error messages extension.
32  *
33  * OpenFlow 1.0 has a set of predefined error types (OFPET_*) and codes (which
34  * are specific to each type).  It does not have any provision for
35  * vendor-specific error codes, and it does not even provide "generic" error
36  * codes that can apply to problems not anticipated by the OpenFlow
37  * specification authors.
38  *
39  * This extension attempts to address the problem by adding a generic "error
40  * vendor extension".  The extension works as follows: use NXET_VENDOR as type
41  * and NXVC_VENDOR_CODE as code, followed by struct nx_vendor_error with
42  * vendor-specific details, followed by at least 64 bytes of the failed
43  * request.
44  *
45  * It would be better to have a type-specific vendor extension, e.g. so that
46  * OFPET_BAD_ACTION could be used with vendor-specific code values.  But
47  * OFPET_BAD_ACTION and most other standardized types already specify that
48  * their 'data' values are (the start of) the OpenFlow message being replied
49  * to, so there is no room to insert a vendor ID.
50  *
51  * Currently this extension is only implemented by Open vSwitch, but it seems
52  * like a reasonable candidate for future standardization.
53  */
54
55 /* This is a random number to avoid accidental collision with any other
56  * vendor's extension. */
57 #define NXET_VENDOR 0xb0c2
58
59 /* ofp_error msg 'code' values for NXET_VENDOR. */
60 enum nx_vendor_code {
61     NXVC_VENDOR_ERROR           /* 'data' contains struct nx_vendor_error. */
62 };
63
64 /* 'data' for 'type' == NXET_VENDOR, 'code' == NXVC_VENDOR_ERROR. */
65 struct nx_vendor_error {
66     ovs_be32 vendor;            /* Vendor ID as in struct ofp_vendor_header. */
67     ovs_be16 type;              /* Vendor-defined type. */
68     ovs_be16 code;              /* Vendor-defined subtype. */
69     /* Followed by at least the first 64 bytes of the failed request. */
70 };
71 \f
72 /* Nicira vendor requests and replies. */
73
74 enum nicira_type {
75     /* Switch status request.  The request body is an ASCII string that
76      * specifies a prefix of the key names to include in the output; if it is
77      * the null string, then all key-value pairs are included. */
78     NXT_STATUS_REQUEST,
79
80     /* Switch status reply.  The reply body is an ASCII string of key-value
81      * pairs in the form "key=value\n". */
82     NXT_STATUS_REPLY,
83
84     /* No longer used. */
85     NXT_ACT_SET_CONFIG__OBSOLETE,
86     NXT_ACT_GET_CONFIG__OBSOLETE,
87     NXT_COMMAND_REQUEST__OBSOLETE,
88     NXT_COMMAND_REPLY__OBSOLETE,
89     NXT_FLOW_END_CONFIG__OBSOLETE,
90     NXT_FLOW_END__OBSOLETE,
91     NXT_MGMT__OBSOLETE,
92
93     /* Use the high 32 bits of the cookie field as the tunnel ID in the flow
94      * match. */
95     NXT_TUN_ID_FROM_COOKIE,
96
97     /* Controller role support.  The request body is struct nx_role_request.
98      * The reply echos the request. */
99     NXT_ROLE_REQUEST,
100     NXT_ROLE_REPLY
101 };
102
103 struct nicira_header {
104     struct ofp_header header;
105     uint32_t vendor;            /* NX_VENDOR_ID. */
106     uint32_t subtype;           /* One of NXT_* above. */
107 };
108 OFP_ASSERT(sizeof(struct nicira_header) == 16);
109
110 struct nxt_tun_id_cookie {
111     struct ofp_header header;
112     uint32_t vendor;            /* NX_VENDOR_ID. */
113     uint32_t subtype;           /* NXT_TUN_ID_FROM_COOKIE */
114     uint8_t set;                /* Nonzero to enable, zero to disable. */
115     uint8_t pad[7];
116 };
117 OFP_ASSERT(sizeof(struct nxt_tun_id_cookie) == 24);
118
119 /* Configures the "role" of the sending controller.  The default role is:
120  *
121  *    - Other (NX_ROLE_OTHER), which allows the controller access to all
122  *      OpenFlow features.
123  *
124  * The other possible roles are a related pair:
125  *
126  *    - Master (NX_ROLE_MASTER) is equivalent to Other, except that there may
127  *      be at most one Master controller at a time: when a controller
128  *      configures itself as Master, any existing Master is demoted to the
129  *      Slave role.
130  *
131  *    - Slave (NX_ROLE_SLAVE) allows the controller read-only access to
132  *      OpenFlow features.  In particular attempts to modify the flow table
133  *      will be rejected with an OFPBRC_EPERM error.
134  *
135  *      Slave controllers also do not receive asynchronous messages
136  *      (OFPT_PACKET_IN, OFPT_FLOW_REMOVED, OFPT_PORT_STATUS).
137  */
138 struct nx_role_request {
139     struct nicira_header nxh;
140     uint32_t role;              /* One of NX_ROLE_*. */
141 };
142
143 enum nx_role {
144     NX_ROLE_OTHER,              /* Default role, full access. */
145     NX_ROLE_MASTER,             /* Full access, at most one. */
146     NX_ROLE_SLAVE               /* Read-only access. */
147 };
148 \f
149 /* Nicira vendor flow actions. */
150
151 enum nx_action_subtype {
152     NXAST_SNAT__OBSOLETE,           /* No longer used. */
153
154     /* Searches the flow table again, using a flow that is slightly modified
155      * from the original lookup:
156      *
157      *    - The 'in_port' member of struct nx_action_resubmit is used as the
158      *      flow's in_port.
159      *
160      *    - If NXAST_RESUBMIT is preceded by actions that affect the flow
161      *      (e.g. OFPAT_SET_VLAN_VID), then the flow is updated with the new
162      *      values.
163      *
164      * Following the lookup, the original in_port is restored.
165      *
166      * If the modified flow matched in the flow table, then the corresponding
167      * actions are executed.  Afterward, actions following NXAST_RESUBMIT in
168      * the original set of actions, if any, are executed; any changes made to
169      * the packet (e.g. changes to VLAN) by secondary actions persist when
170      * those actions are executed, although the original in_port is restored.
171      *
172      * NXAST_RESUBMIT may be used any number of times within a set of actions.
173      *
174      * NXAST_RESUBMIT may nest to an implementation-defined depth.  Beyond this
175      * implementation-defined depth, further NXAST_RESUBMIT actions are simply
176      * ignored.  (Open vSwitch 1.0.1 and earlier did not support recursion.)
177      */
178     NXAST_RESUBMIT,
179
180     /* Set encapsulating tunnel ID. */
181     NXAST_SET_TUNNEL,
182
183     /* Stops processing further actions, if the packet being processed is an
184      * Ethernet+IPv4 ARP packet for which the source Ethernet address inside
185      * the ARP packet differs from the source Ethernet address in the Ethernet
186      * header.
187      *
188      * This is useful because OpenFlow does not provide a way to match on the
189      * Ethernet addresses inside ARP packets, so there is no other way to drop
190      * spoofed ARPs other than sending every ARP packet to a controller. */
191     NXAST_DROP_SPOOFED_ARP,
192
193     /* Set the queue that should be used when packets are output.  This
194      * is similar to the OpenFlow OFPAT_ENQUEUE action, but does not
195      * take the output port as an argument.  This allows the queue
196      * to be defined before the port is known. */
197     NXAST_SET_QUEUE,
198
199     /* Restore the queue to the value it was before any NXAST_SET_QUEUE
200      * actions were used. */
201     NXAST_POP_QUEUE
202 };
203
204 /* Action structure for NXAST_RESUBMIT. */
205 struct nx_action_resubmit {
206     uint16_t type;                  /* OFPAT_VENDOR. */
207     uint16_t len;                   /* Length is 16. */
208     uint32_t vendor;                /* NX_VENDOR_ID. */
209     uint16_t subtype;               /* NXAST_RESUBMIT. */
210     uint16_t in_port;               /* New in_port for checking flow table. */
211     uint8_t pad[4];
212 };
213 OFP_ASSERT(sizeof(struct nx_action_resubmit) == 16);
214
215 /* Action structure for NXAST_SET_TUNNEL. */
216 struct nx_action_set_tunnel {
217     uint16_t type;                  /* OFPAT_VENDOR. */
218     uint16_t len;                   /* Length is 16. */
219     uint32_t vendor;                /* NX_VENDOR_ID. */
220     uint16_t subtype;               /* NXAST_SET_TUNNEL. */
221     uint8_t pad[2];
222     uint32_t tun_id;                /* Tunnel ID. */
223 };
224 OFP_ASSERT(sizeof(struct nx_action_set_tunnel) == 16);
225
226 /* Action structure for NXAST_SET_QUEUE. */
227 struct nx_action_set_queue {
228     uint16_t type;                  /* OFPAT_VENDOR. */
229     uint16_t len;                   /* Length is 16. */
230     uint32_t vendor;                /* NX_VENDOR_ID. */
231     uint16_t subtype;               /* NXAST_SET_QUEUE. */
232     uint8_t pad[2];
233     uint32_t queue_id;              /* Where to enqueue packets. */
234 };
235 OFP_ASSERT(sizeof(struct nx_action_set_queue) == 16);
236
237 /* Header for Nicira-defined actions. */
238 struct nx_action_header {
239     uint16_t type;                  /* OFPAT_VENDOR. */
240     uint16_t len;                   /* Length is 16. */
241     uint32_t vendor;                /* NX_VENDOR_ID. */
242     uint16_t subtype;               /* NXAST_*. */
243     uint8_t pad[6];
244 };
245 OFP_ASSERT(sizeof(struct nx_action_header) == 16);
246
247 /* Wildcard for tunnel ID. */
248 #define NXFW_TUN_ID  (1 << 25)
249
250 #define NXFW_ALL NXFW_TUN_ID
251 #define OVSFW_ALL (OFPFW_ALL | NXFW_ALL)
252
253 #endif /* openflow/nicira-ext.h */