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