c3b62c91da912e78b86be484c3014b6b809f93e8
[sliver-openvswitch.git] / include / openflow / openflow-mgmt.h
1 /*
2  * Copyright (c) 2009 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_OPENFLOW_MGMT_H
18 #define OPENFLOW_OPENFLOW_MGMT_H 1
19
20 #include "openflow/nicira-ext.h"
21
22 enum ofmp_type {
23     OFMPT_CAPABILITY_REQUEST,
24     OFMPT_CAPABILITY_REPLY,
25     OFMPT_RESOURCES_REQUEST,
26     OFMPT_RESOURCES_UPDATE,
27     OFMPT_CONFIG_REQUEST,
28     OFMPT_CONFIG_UPDATE,
29     OFMPT_CONFIG_UPDATE_ACK,
30     OFMPT_ERROR,
31     OFMPT_EXTENDED_DATA
32 };
33
34 /* Header on all OpenFlow management packets. */
35 struct ofmp_header {
36     struct nicira_header header;
37     uint16_t type;           /* One of OFMPT_* above. */
38     uint8_t pad[2];
39 };
40 OFP_ASSERT(sizeof(struct ofmp_header) == sizeof(struct nicira_header) + 4);
41
42
43 /* Generic TLV header. */
44 struct ofmp_tlv {
45     uint16_t type;        /* Type of value (one of OFMPTLV_*). */
46     uint16_t len;         /* Length of TLV (includes this header). */
47     uint8_t data[0];      /* Value of data as defined by type and length. */
48 };
49 OFP_ASSERT(sizeof(struct ofmp_tlv) == 4);
50
51 /* Universal TLV terminator.  Used to indicate end of TLV list. */
52 struct ofmp_tlv_end {
53     uint16_t type;        /* Type is 0. */
54     uint16_t len;         /* Length is 4. */
55 };
56 OFP_ASSERT(sizeof(struct ofmp_tlv_end) == 4);
57
58
59 /* Bitmask of capability description styles. */
60 enum ofmp_capability_format {
61     OFMPCAF_SIMPLE  = 0 << 0,             /* "ovs-vswitchd.conf" style. */
62 };
63
64 /* Body of capbility request.
65  *
66  * OFMPT_CAPABILITY_REQUEST (controller -> switch) */
67 struct ofmp_capability_request {
68     struct ofmp_header header;
69     uint32_t format;                      /* One of OFMPCAF_*. */
70 };
71 OFP_ASSERT(sizeof(struct ofmp_capability_request) == 24);
72
73 /* Body of reply to capability request.  
74  *
75  * OFMPT_CAPABILITY_REPLY (switch -> controller). */
76 struct ofmp_capability_reply {
77     struct ofmp_header header;
78     uint32_t format;                      /* One of OFMPCAF_*. */
79     uint64_t mgmt_id;                     /* Management ID. */
80     uint8_t data[0];
81 };
82 OFP_ASSERT(sizeof(struct ofmp_capability_reply) == 32);
83
84
85 /* Resource TLV for datapath description. */
86 struct ofmptsr_dp {
87     uint16_t type;                        /* OFMPTSR_DP. */
88     uint16_t len;                         /* 32. */
89     uint8_t pad[4];
90     uint64_t dp_id;                       /* Datapath ID. */
91     uint8_t name[OFP_MAX_PORT_NAME_LEN];  /* Null-terminated name. */
92 };
93 OFP_ASSERT(sizeof(struct ofmptsr_dp) == 32);
94
95 /* UUIDs will be passed around as *non-terminated* strings in their
96  * canonical form (e.g., 550e8400-e29b-41d4-a716-446655440000).
97  */
98 #define OFMP_UUID_LEN 36
99
100 /* Resource TLV for XenServer UUIDs associated with this datapath. */
101 struct ofmptsr_dp_uuid {
102     uint16_t type;                        /* OFMPTSR_DP_UUID. */
103     uint16_t len;                         /* Length. */
104     uint8_t pad[4];
105     uint64_t dp_id;                       /* Datapath ID. */
106     uint8_t uuid_list[0];                 /* List of UUIDs associated with 
107                                            * this datapath. */
108 };
109 OFP_ASSERT(sizeof(struct ofmptsr_dp_uuid) == 16);
110
111 /* Resource TLV for XenServer UUID associated with this managment 
112  * instance. 
113  */
114 struct ofmptsr_mgmt_uuid {
115     uint16_t type;                        /* OFMPTSR_MGMT_UUID. */
116     uint16_t len;                         /* 52. */
117     uint8_t pad[4];
118     uint64_t mgmt_id;                     /* Management ID. */
119     uint8_t uuid[OFMP_UUID_LEN];          /* System UUID. */
120     uint8_t pad2[4];                      /* Pad for 64-bit systems. */
121 };
122 OFP_ASSERT(sizeof(struct ofmptsr_mgmt_uuid) == 56);
123
124 /* Resource TLV for details about this XenServer vif. */
125 struct ofmptsr_vif {
126     uint16_t type;                        /* OFMPTSR_VIF. */
127     uint16_t len;                         /* 136. */
128     uint8_t name[OFP_MAX_PORT_NAME_LEN];  /* Null-terminated name. */
129     uint8_t vif_uuid[OFMP_UUID_LEN];      /* VIF UUID. */
130     uint8_t vm_uuid[OFMP_UUID_LEN];       /* VM UUID. */
131     uint8_t net_uuid[OFMP_UUID_LEN];      /* Network UUID. */
132     uint64_t vif_mac;                     /* Management ID. */
133 };
134 OFP_ASSERT(sizeof(struct ofmptsr_vif) == 136);
135
136 /* TLV types for switch resource descriptions. */
137 enum ofmp_switch_resources {
138     OFMPTSR_END = 0,                      /* Terminator. */
139     OFMPTSR_DP,                           /* Datapath. */
140     OFMPTSR_DP_UUID,                      /* Xen: datapath uuid's. */
141     OFMPTSR_MGMT_UUID,                    /* Xen: management uuid. */
142     OFMPTSR_VIF,                          /* Xen: vif details. */
143 };
144
145 /* Body of resources request.
146  *
147  * OFMPT_RESOURCES_REQUEST (controller -> switch) */
148 struct ofmp_resources_request {
149     struct ofmp_header header;
150 };
151
152 /* Body of capbility update.  Sent in response to a resources request or
153  * sent asynchronously when resources change on the switch. 
154  *
155  * OFMPT_RESOURCES_UPDATE (switch -> controller) */
156 struct ofmp_resources_update {
157     struct ofmp_header header;
158     uint8_t data[0];
159 };
160 OFP_ASSERT(sizeof(struct ofmp_resources_update) == 20);
161
162
163 /* Bitmask of capability description styles. */
164 enum ofmp_config_format {
165     OFMPCOF_SIMPLE  = 0 << 0,           /* "ovs-vswitchd.conf" style. */
166 };
167
168 #define CONFIG_COOKIE_LEN 20
169
170 /* Body of configuration request.
171  *
172  * OFMPT_CONFIG_REQUEST (controller -> switch) */
173 struct ofmp_config_request {
174     struct ofmp_header header;
175     uint32_t format;                    /* One of OFMPCOF_*. */
176 };
177 OFP_ASSERT(sizeof(struct ofmp_config_request) == 24);
178
179 /* Body of configuration update.  Sent in response to a configuration 
180  * request from the controller.  May be sent asynchronously by either
181  * the controller or switch to modify configuration or notify of
182  * changes, respectively.  If sent by the controller, the switch must
183  * respond with a OFMPT_CONFIG_UPDATE_ACK.
184  *
185  * OFMPT_CONFIG_UPDATE (switch <-> controller) */
186 struct ofmp_config_update {
187     struct ofmp_header header;
188     uint32_t format;                    /* One of OFMPCOF_*. */
189     uint8_t cookie[CONFIG_COOKIE_LEN];  /* Cookie of config attempting to be
190                                          * replaced by this update. */
191     uint8_t data[0];
192 };
193 OFP_ASSERT(sizeof(struct ofmp_config_update) == 44);
194
195 /* Bitmask of configuration update ack flags. */
196 enum ofmp_config_update_ack_flags {
197     OFMPCUAF_SUCCESS = 1 << 0,          /* Config succeeded. */
198 };
199
200 /* Body of configuration update ack.  Sent in response to a configuration 
201  * udpate request.
202  *
203  * OFMPT_CONFIG_UPDATE_ACK (switch -> controller) */
204 struct ofmp_config_update_ack {
205     struct ofmp_header header;
206     uint32_t format;                    /* One of OFMPCOF_*. */
207     uint32_t flags;                     /* One of OFMPCUAF_*. */
208     uint8_t cookie[CONFIG_COOKIE_LEN];  /* Cookie of current configuration 
209                                          * being used in the switch. */
210 };
211 OFP_ASSERT(sizeof(struct ofmp_config_update_ack) == 48);
212
213 /* Values for 'type' in ofmp_error_msg. */
214 enum ofmp_error_type {
215     OFMPET_BAD_CONFIG                   /* Problem with configuration. */
216 };
217
218 /* ofmp_error_msg 'code' values for OFMPET_BAD_CONFIG.  'data' contains
219  * at least the first 64 bytes of the failed request. */
220 enum ofmp_bad_config_code {
221     OFMPBCC_BUSY,                       /* Config updating, try again. */
222     OFMPBCC_OLD_COOKIE,                 /* Config has changed. */
223 };
224
225 /* Body of error message.  May be sent by either the switch or the
226  * controller to indicate some error condition.
227  *
228  * OFMPT_ERROR (switch <-> controller) */
229 struct ofmp_error_msg {
230     struct ofmp_header header;
231
232     uint16_t type;            /* One of OFMPET_*. */
233     uint16_t code;            /* Code depending on 'type'. */
234     uint8_t data[0];          /* Variable-length data.  Interpreted based 
235                                  on the type and code. */
236 };
237 OFP_ASSERT(sizeof(struct ofmp_error_msg) == 24);
238
239 /* Bitmask of extended data message flags. */
240 enum ofmp_extended_data_flags {
241     OFMPEDF_MORE_DATA = 1 << 0,         /* More data follows. */
242 };
243
244 /* Body of extended data message.  May be sent by either the switch or the
245  * controller to send messages that are greater than 65535 bytes in
246  * length.
247  *
248  * OFMPT_EXTENDED_DATA (switch <-> controller) */
249 struct ofmp_extended_data {
250     struct ofmp_header header;
251
252     uint16_t type;            /* Type code of the encapsulated message. */
253     uint8_t flags;            /* One of OFMPEDF_*. */
254     uint8_t pad;
255     uint8_t data[0];          /* Variable-length data. */
256 };
257 OFP_ASSERT(sizeof(struct ofmp_extended_data) == 24);
258
259 #endif /* openflow/openflow-mgmt.h */