packet-openflow_v1.c: Rename "Padding" fields & filter-names to be consistent with...
[metze/wireshark/wip.git] / epan / dissectors / packet-openflow_v1.c
1 /* packet-openflow_v1.c
2  * Routines for OpenFlow dissection
3  * Copyright 2013, Anders Broman <anders.broman@ericsson.com>
4  * Copyright 2013, Zoltan Lajos Kis <zoltan.lajos.kis@ericsson.com>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  *
24  * Ref https://www.opennetworking.org/sdn-resources/onf-specifications/openflow
25  */
26
27 #include "config.h"
28
29 #include <glib.h>
30
31 #include <epan/packet.h>
32 #include <epan/expert.h>
33
34 void proto_register_openflow_v1(void);
35 void proto_reg_handoff_openflow_v1(void);
36
37 static dissector_handle_t eth_withoutfcs_handle;
38
39 /* Initialize the protocol and registered fields */
40 static int proto_openflow_v1 = -1;
41 static int hf_openflow_version = -1;
42 static int hf_openflow_1_0_type = -1;
43 static int hf_openflow_length = -1;
44 static int hf_openflow_xid = -1;
45
46 static int hf_openflow_datapath_id = -1;
47 static int hf_openflow_datapath_mac = -1;
48 static int hf_openflow_datapath_impl = -1;
49 static int hf_openflow_n_buffers = -1;
50 static int hf_openflow_n_tables = -1;
51 /* static int hf_openflow_auxiliary_id = -1; */
52 static int hf_openflow_capabilities = -1;
53 static int hf_openflow_actions = -1;
54 /* static int hf_openflow_reserved32 = -1; */
55 static int hf_openflow_cap_flow_stats = -1;
56 static int hf_openflow_table_stats = -1;
57 static int hf_openflow_port_stats = -1;
58 static int hf_openflow_group_stats = -1;
59 static int hf_openflow_ip_reasm = -1;
60 static int hf_openflow_queue_stats = -1;
61 static int hf_openflow_port_blocked = -1;
62
63 static int hf_openflow_output = -1; /* Output to switch port. */
64 static int hf_openflow_set_vlan_vid = -1; /* Set the 802.1q VLAN id. */
65 static int hf_openflow_set_vlan_pcp = -1; /* Set the 802.1q priority. */
66 static int hf_openflow_strip_vlan = -1; /* Strip the 802.1q header. */
67 static int hf_openflow_set_dl_src = -1; /* Ethernet source address. */
68 static int hf_openflow_set_dl_dst = -1; /* Ethernet destination address. */
69 static int hf_openflow_set_nw_src = -1; /* IP source address. */
70 static int hf_openflow_set_nw_dst = -1; /* IP destination address. */
71 static int hf_openflow_set_nw_tos = -1; /* IP ToS (DSCP field, 6 bits). */
72 static int hf_openflow_set_tp_src = -1; /* TCP/UDP source port. */
73 static int hf_openflow_set_tp_dst = -1; /* TCP/UDP destination port. */
74 static int hf_openflow_enqueue = -1; /* Output to queue. */
75
76 static int hf_openflow_port_no = -1;
77 static int hf_openflow_hw_addr = -1;
78 static int hf_openflow_port_name = -1;
79
80
81 static int hf_openflow_port_config = -1;
82 static int hf_openflow_port_state = -1;
83 static int hf_openflow_port_curr = -1;
84 static int hf_openflow_port_advertised = -1;
85 static int hf_openflow_port_supported = -1;
86 static int hf_openflow_port_peer = -1;
87
88 static int hf_openflow_port_down = -1;    /* Port is administratively down. */
89 static int hf_openflow_no_stp = -1;       /* Disable 802.1D spanning tree on port. */
90 static int hf_openflow_no_recv = -1;      /* Drop all packets except 802.1D spanning tree packets. */
91 static int hf_openflow_no_recv_stp = -1;  /* Drop received 802.1D STP packets. */
92 static int hf_openflow_no_flood = -1;     /* Do not include this port when flooding. */
93 static int hf_openflow_no_fwd = -1;       /* Drop packets forwarded to port. */
94 static int hf_openflow_no_packet_in = -1; /* Do not send packet-in msgs for port. */
95
96 static int hf_openflow_link_down = -1;    /* No physical link present. */
97
98 static int hf_openflow_10mb_hd = -1;      /* 10 Mb half-duplex rate support. */
99 static int hf_openflow_10mb_fd = -1;      /* 10 Mb full-duplex rate support. */
100 static int hf_openflow_100mb_hd = -1;     /* 100 Mb half-duplex rate support. */
101 static int hf_openflow_100mb_fd = -1;     /* 100 Mb full-duplex rate support. */
102 static int hf_openflow_1gb_hd = -1;       /* 1 Gb half-duplex rate support. */
103 static int hf_openflow_1gb_fd = -1;       /* 1 Gb full-duplex rate support. */
104 static int hf_openflow_10gb_fd = -1;      /* 10 Gb full-duplex rate support. */
105 static int hf_openflow_copper = -1;       /* Copper medium. */
106 static int hf_openflow_fiber = -1;        /* Fiber medium. */
107 static int hf_openflow_autoneg = -1;      /* Auto-negotiation. */
108 static int hf_openflow_pause = -1;        /* Pause. */
109 static int hf_openflow_pause_asym = -1;   /* Asymmetric pause. */
110
111 static int hf_openflow_config_flags = -1;
112 static int hf_openflow_miss_send_len = -1;
113
114 static int hf_openflow_buffer_id = -1;
115 static int hf_openflow_total_len = -1;
116 static int hf_openflow_in_port = -1;
117 static int hf_openflow_reason = -1;
118 static int hf_openflow_pkt_in_pad = -1;
119 /* static int hf_openflow_table_id = -1; */
120 static int hf_openflow_cookie = -1;
121 /* static int hf_openflow_cookie_mask = -1; */
122 static int hf_openflow_features_reply_pad = -1;
123 static int hf_openflow_actions_len = -1;
124 static int hf_openflow_action_type = -1;
125 static int hf_openflow_action_len = -1;
126 static int hf_openflow_output_port = -1;
127 static int hf_openflow_max_len = -1;
128 static int hf_openflow_wildcards = -1;
129 static int hf_openflow_command = -1;
130 static int hf_openflow_eth_src = -1;
131 static int hf_openflow_eth_dst = -1;
132 static int hf_openflow_dl_vlan = -1;
133 static int hf_openflow_dl_vlan_pcp = -1;
134 static int hf_openflow_ofp_match_pad = -1;
135 static int hf_openflow_idle_timeout = -1;
136 static int hf_openflow_hard_timeout = -1;
137 static int hf_openflow_priority = -1;
138 static int hf_openflow_out_port = -1;
139 /* static int hf_openflow_out_group = -1; */
140 static int hf_openflow_flags = -1;
141
142 /* Initialize the subtree pointers */
143 static gint ett_openflow = -1;
144 static gint ett_openflow_path_id = -1;
145 static gint ett_openflow_cap = -1;
146 static gint ett_openflow_act = -1;
147 static gint ett_openflow_port = -1;
148 static gint ett_openflow_port_cnf = -1;
149 static gint ett_openflow_port_state = -1;
150 static gint ett_openflow_port_cf = -1;
151
152 static expert_field ei_openflow_undecoded_data = EI_INIT;
153 static expert_field ei_openflow_action_type = EI_INIT;
154 static expert_field ei_openflow_1_0_type = EI_INIT;
155
156 static const value_string openflow_version_values[] = {
157     { 0x01, "1.0" },
158     { 0, NULL }
159 };
160
161
162 /* Immutable messages. */
163 #define OFPT_1_0_HELLO                     0 /* Symmetric message */
164 #define OFPT_1_0_ERROR                     1 /* Symmetric message */
165 #define OFPT_1_0_ECHO_REQUEST              2 /* Symmetric message */
166 #define OFPT_1_0_ECHO_REPLY                3 /* Symmetric message */
167 #define OFPT_1_0_VENDOR                    4 /* Symmetric message */
168 /* Switch configuration messages. */
169 #define OFPT_1_0_FEATURES_REQUEST          5 /* Controller/switch message */
170 #define OFPT_1_0_FEATURES_REPLY            6 /* Controller/switch message */
171 #define OFPT_1_0_GET_CONFIG_REQUEST        7 /* Controller/switch message */
172 #define OFPT_1_0_GET_CONFIG_REPLY          8 /* Controller/switch message */
173 #define OFPT_1_0_SET_CONFIG                9 /* Controller/switch message */
174 /* Asynchronous messages. */
175 #define OFPT_1_0_PACKET_IN                10 /* Async message */
176 #define OFPT_1_0_FLOW_REMOVED             11 /* Async message */
177 #define OFPT_1_0_PORT_STATUS              12 /* Async message */
178 /* Controller command messages. */
179 #define OFPT_1_0_PACKET_OUT               13 /* Controller/switch message */
180 #define OFPT_1_0_FLOW_MOD                 14 /* Controller/switch message */
181 #define OFPT_1_0_PORT_MOD                 15 /* Controller/switch message */
182 /* Statistics messages. */
183 #define OFPT_1_0_STATS_REQUEST            16 /* Controller/switch message */
184 #define OFPT_1_0_STATS_REPLY              17 /* Controller/switch message */
185 /* Barrier messages. */
186 #define OFPT_1_0_BARRIER_REQUEST          18 /* Controller/switch message */
187 #define OFPT_1_0_BARRIER_REPLY            19 /* Controller/switch message */
188 /* Queue Configuration messages. */
189 #define OFPT_1_0_QUEUE_GET_CONFIG_REQUEST 20 /* Controller/switch message */
190 #define OFPT_1_0_QUEUE_GET_CONFIG_REPLY   21 /* Controller/switch message */
191
192
193 static const value_string openflow_1_0_type_values[] = {
194 /* Immutable messages. */
195
196 /* Immutable messages. */
197     { 0, "OFPT_HELLO" },              /* Symmetric message */
198     { 1, "OFPT_ERROR" },              /* Symmetric message */
199     { 2, "OFPT_ECHO_REQUEST" },       /* Symmetric message */
200     { 3, "OFPT_ECHO_REPLY" },         /* Symmetric message */
201     { 4, "OFPT_VENDOR" },             /* Symmetric message */
202 /* Switch configuration messages. */
203     { 5, "OFPT_FEATURES_REQUEST" },   /* Controller/switch message */
204     { 6, "OFPT_FEATURES_REPLY" },     /* Controller/switch message */
205     { 7, "OFPT_GET_CONFIG_REQUEST" }, /* Controller/switch message */
206     { 8, "OFPT_GET_CONFIG_REPLY" },   /* Controller/switch message */
207     { 9, "OFPT_SET_CONFIG" },         /* Controller/switch message */
208 /* Asynchronous messages. */
209     { 10, "OFPT_PACKET_IN" },                /* Async message */
210     { 11, "OFPT_FLOW_REMOVED" },             /* Async message */
211     { 12, "OFPT_PORT_STATUS" },              /* Async message */
212 /* Controller command messages. */
213     { 13, "OFPT_PACKET_OUT" },               /* Controller/switch message */
214     { 14, "OFPT_FLOW_MOD" },                 /* Controller/switch message */
215     { 15, "OFPT_PORT_MOD" },                 /* Controller/switch message */
216 /* Statistics messages. */
217     { 16, "OFPT_STATS_REQUEST" },            /* Controller/switch message */
218     { 17, "OFPT_STATS_REPLY" },              /* Controller/switch message */
219 /* Barrier messages. */
220     { 18, "OFPT_BARRIER_REQUEST" },          /* Controller/switch message */
221     { 19, "OFPT_BARRIER_REPLY" },            /* Controller/switch message */
222 /* Queue Configuration messages. */
223     { 20, "OFPT_QUEUE_GET_CONFIG_REQUEST" }, /* Controller/switch message */
224     { 21, "OFPT_QUEUE_GET_CONFIG_REPLY" },   /* Controller/switch message */
225     { 0, NULL }
226 };
227
228
229 #define OFPC_FLOW_STATS   1<<0  /* Flow statistics. */
230 #define OFPC_TABLE_STATS  1<<1  /* Table statistics. */
231 #define OFPC_PORT_STATS   1<<2  /* Port statistics. */
232 #define OFPC_GROUP_STATS  1<<3  /* Group statistics. */
233 #define OFPC_IP_REASM     1<<5  /* Can reassemble IP fragments. */
234 #define OFPC_QUEUE_STATS  1<<6  /* Queue statistics. */
235 #define OFPC_PORT_BLOCKED 1<<8  /* Switch will block looping ports. */
236
237 #define OFPAT_OUTPUT_MASK       1<<0  /* Output to switch port. */
238 #define OFPAT_SET_VLAN_VID_MASK 1<<1  /* Set the 802.1q VLAN id. */
239 #define OFPAT_SET_VLAN_PCP_MASK 1<<2  /* Set the 802.1q priority. */
240 #define OFPAT_STRIP_VLAN_MASK   1<<3  /* Strip the 802.1q header. */
241 #define OFPAT_SET_DL_SRC_MASK   1<<4  /* Ethernet source address. */
242 #define OFPAT_SET_DL_DST_MASK   1<<5  /* Ethernet destination address. */
243 #define OFPAT_SET_NW_SRC_MASK   1<<6  /* IP source address. */
244 #define OFPAT_SET_NW_DST_MASK   1<<7  /* IP destination address. */
245 #define OFPAT_SET_NW_TOS_MASK   1<<8  /* IP ToS (DSCP field, 6 bits). */
246 #define OFPAT_SET_TP_SRC_MASK   1<<9  /* TCP/UDP source port. */
247 #define OFPAT_SET_TP_DST_MASK   1<<10 /* TCP/UDP destination port. */
248 #define OFPAT_ENQUEUE_MASK      1<<11 /* Output to queue. */
249
250 #define OFPPC_PORT_DOWN    1<<0 /* Port is administratively down. */
251 #define OFPPC_NO_STP       1<<1 /* Disable 802.1D spanning tree on port. */
252 #define OFPPC_NO_RECV      1<<2 /* Drop all packets except 802.1D spanning tree packets. */
253 #define OFPPC_NO_RECV_STP  1<<3 /* Drop received 802.1D STP packets. */
254 #define OFPPC_NO_FLOOD     1<<4 /* Do not include this port when flooding. */
255 #define OFPPC_NO_FWD       1<<5 /* Drop packets forwarded to port. */
256 #define OFPPC_NO_PACKET_IN 1<<6 /* Do not send packet-in msgs for port. */
257
258 #define OFP_MAX_PORT_NAME_LEN 16
259
260 #define OFPPS_LINK_DOWN    1<<0 /* No physical link present. */
261 #define OFPPS_STP_LISTEN   0<<8 /* Not learning or relaying frames. */
262 #define OFPPS_STP_LEARN    1<<8 /* Learning but not relaying frames. */
263 #define OFPPS_STP_FORWARD  2<<8 /* Learning and relaying frames. */
264 #define OFPPS_STP_BLOCK    3<<8 /* Not part of spanning tree. */
265 #define OFPPS_STP_MASK     3<<8 /* Bit mask for OFPPS_STP_* values. */
266
267
268 #define OFPPF_10MB_HD      1<<0 /* 10 Mb half-duplex rate support. */
269 #define OFPPF_10MB_FD      1<<1 /* 10 Mb full-duplex rate support. */
270 #define OFPPF_100MB_HD     1<<2 /* 100 Mb half-duplex rate support. */
271 #define OFPPF_100MB_FD     1<<3 /* 100 Mb full-duplex rate support. */
272 #define OFPPF_1GB_HD       1<<4 /* 1 Gb half-duplex rate support. */
273 #define OFPPF_1GB_FD       1<<5 /* 1 Gb full-duplex rate support. */
274 #define OFPPF_10GB_FD      1<<6 /* 10 Gb full-duplex rate support. */
275 #define OFPPF_COPPER       1<<7 /* Copper medium. */
276 #define OFPPF_FIBER        1<<8 /* Fiber medium. */
277 #define OFPPF_AUTONEG      1<<9 /* Auto-negotiation. */
278 #define OFPPF_PAUSE        1<<10 /* Pause. */
279 #define OFPPF_PAUSE_ASYM   1<<11 /* Asymmetric pause. */
280
281
282 #define OFPAT_OUTPUT         0 /* Output to switch port. */
283 #define OFPAT_SET_VLAN_VID   1 /* Set the 802.1q VLAN id. */
284 #define OFPAT_SET_VLAN_PCP   2 /* Set the 802.1q priority. */
285 #define OFPAT_STRIP_VLAN     3 /* Strip the 802.1q header. */
286 #define OFPAT_SET_DL_SRC     4 /* Ethernet source address. */
287 #define OFPAT_SET_DL_DST     5 /* Ethernet destination address. */
288 #define OFPAT_SET_NW_SRC     6 /* IP source address. */
289 #define OFPAT_SET_NW_DST     7 /* IP destination address. */
290 #define OFPAT_SET_TP_SRC     8 /* TCP/UDP source port. */
291 #define OFPAT_SET_TP_DST     9 /* TCP/UDP destination port. */
292 #define OFPAT_VENDOR         0xffff
293
294 static int
295 dissect_openflow_ofp_match_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
296 {
297
298     /* uint32_t wildcards; Wildcard fields. */
299     proto_tree_add_item(tree, hf_openflow_wildcards, tvb, offset, 4, ENC_BIG_ENDIAN);
300     offset+=4;
301     /* uint16_t in_port; Input switch port. */
302     proto_tree_add_item(tree, hf_openflow_in_port, tvb, offset, 2, ENC_BIG_ENDIAN);
303     offset+=2;
304
305     /* uint8_t dl_src[OFP_ETH_ALEN];  Ethernet source address. */
306     proto_tree_add_item(tree, hf_openflow_eth_src, tvb, offset, 6, ENC_NA);
307     offset+=6;
308     /* uint8_t dl_dst[OFP_ETH_ALEN]; Ethernet destination address. */
309     proto_tree_add_item(tree, hf_openflow_eth_dst, tvb, offset, 6, ENC_NA);
310     offset+=6;
311     /* uint16_t dl_vlan; Input VLAN id. */
312     proto_tree_add_item(tree, hf_openflow_dl_vlan, tvb, offset, 2, ENC_BIG_ENDIAN);
313     offset+=2;
314     /* uint8_t dl_vlan_pcp; Input VLAN priority. */
315     proto_tree_add_item(tree, hf_openflow_dl_vlan_pcp, tvb, offset, 1, ENC_BIG_ENDIAN);
316     offset++;
317     /* uint8_t pad1[1]; Align to 64-bits */
318     proto_tree_add_item(tree, hf_openflow_ofp_match_pad, tvb, offset, 1, ENC_NA);
319     offset++;
320     /* uint16_t dl_type; Ethernet frame type. */
321     /* uint8_t nw_tos; IP ToS (actually DSCP field, 6 bits). */
322     /* uint8_t nw_proto; IP protocol or lower 8 bits of
323      * ARP opcode.
324      */
325     /* uint8_t pad2[2]; Align to 64-bits */
326     /* uint32_t nw_src; IP source address. */
327     /* uint32_t nw_dst; IP destination address. */
328     /* uint16_t tp_src; TCP/UDP source port. */
329     /* uint16_t tp_dst; TCP/UDP destination port. */
330     proto_tree_add_expert(tree, pinfo, &ei_openflow_undecoded_data, tvb, offset, 18);
331     offset +=18;
332
333     return offset;
334 }
335
336
337 static const value_string openflow_action_values[] = {
338     { OFPAT_OUTPUT,          "Output to switch port" },
339     { OFPAT_SET_VLAN_VID,    "Set the 802.1q VLAN id" },
340     { OFPAT_SET_VLAN_PCP,    "Set the 802.1q priority" },
341     { OFPAT_STRIP_VLAN,      "Strip the 802.1q header" },
342     { OFPAT_SET_DL_SRC,      "Ethernet source address" },
343     { OFPAT_SET_DL_DST,      "Ethernet destination address" },
344     { OFPAT_SET_NW_SRC,      "IP source address" },
345     { OFPAT_SET_NW_DST,      "IP destination address" },
346     { OFPAT_SET_TP_SRC,      "TCP/UDP source port" },
347     { OFPAT_SET_TP_DST,      "TCP/UDP destination port" },
348     { OFPAT_VENDOR,          "Vendor specific action"},
349     { 0, NULL }
350 };
351
352 static int
353 dissect_openflow_action_header(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset)
354 {
355     guint16 action_type, action_len;
356     proto_item* ti;
357
358     /* uint16_t type;  One of OFPAT_*. */
359     action_type = tvb_get_ntohs(tvb, offset);
360     ti = proto_tree_add_item(tree, hf_openflow_action_type, tvb, offset, 2, ENC_BIG_ENDIAN);
361     offset+=2;
362     /* Length of action, including this
363      * header. This is the length of action,
364      * including any padding to make it
365      * 64-bit aligned.
366      */
367     action_len = tvb_get_ntohs(tvb, offset);
368     proto_tree_add_item(tree, hf_openflow_action_len, tvb, offset, 2, ENC_BIG_ENDIAN);
369     offset+=2;
370
371     switch(action_type){
372     case OFPAT_OUTPUT:
373         /* uint16_t port;  Output port. */
374         proto_tree_add_item(tree, hf_openflow_output_port, tvb, offset, 2, ENC_BIG_ENDIAN);
375         offset+=2;
376         /* uint16_t max_len;  Max length to send to controller. */
377         proto_tree_add_item(tree, hf_openflow_max_len, tvb, offset, 2, ENC_BIG_ENDIAN);
378         offset+=2;
379         break;
380     default:
381         expert_add_info(pinfo, ti, &ei_openflow_action_type);
382         offset+=(action_len-4);
383         break;
384     }
385
386     return offset;
387 }
388 static void
389 dissect_openflow_phy_port(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset)
390 {
391     proto_item *ti;
392     proto_tree *port_cnf_tree, *port_state_tree, *port_cf_tree;
393
394     proto_tree_add_item(tree, hf_openflow_port_no, tvb, offset, 2, ENC_BIG_ENDIAN);
395     offset+=2;
396     proto_tree_add_item(tree, hf_openflow_hw_addr, tvb, offset, 6, ENC_NA);
397     offset+=6;
398     proto_tree_add_item(tree, hf_openflow_port_name, tvb, offset, OFP_MAX_PORT_NAME_LEN, ENC_ASCII|ENC_NA);
399     offset+=OFP_MAX_PORT_NAME_LEN;
400
401     /* Bitmap of OFPPC_* flags. */
402     ti = proto_tree_add_item(tree, hf_openflow_port_config, tvb, offset, 4, ENC_BIG_ENDIAN);
403     port_cnf_tree = proto_item_add_subtree(ti, ett_openflow_port_cnf);
404
405     /* Port is administratively down. */
406     proto_tree_add_item(port_cnf_tree, hf_openflow_port_down, tvb, offset, 4, ENC_BIG_ENDIAN);
407     /* Disable 802.1D spanning tree on port. */
408     proto_tree_add_item(port_cnf_tree, hf_openflow_no_stp, tvb, offset, 4, ENC_BIG_ENDIAN);
409     /* Drop all packets except 802.1D spanning tree packets. */
410     proto_tree_add_item(port_cnf_tree, hf_openflow_no_recv, tvb, offset, 4, ENC_BIG_ENDIAN);
411     /* Drop received 802.1D STP packets. */
412     proto_tree_add_item(port_cnf_tree, hf_openflow_no_recv_stp, tvb, offset, 4, ENC_BIG_ENDIAN);
413     /* Do not include this port when flooding. */
414     proto_tree_add_item(port_cnf_tree, hf_openflow_no_flood, tvb, offset, 4, ENC_BIG_ENDIAN);
415      /* Drop packets forwarded to port. */
416     proto_tree_add_item(port_cnf_tree, hf_openflow_no_fwd, tvb, offset, 4, ENC_BIG_ENDIAN);
417     /* Do not send packet-in msgs for port. */
418     proto_tree_add_item(port_cnf_tree, hf_openflow_no_packet_in, tvb, offset, 4, ENC_BIG_ENDIAN);
419     offset+=4;
420
421     /* Bitmap of OFPPS_* flags. */
422     ti = proto_tree_add_item(tree, hf_openflow_port_state, tvb, offset, 4, ENC_BIG_ENDIAN);
423     port_state_tree = proto_item_add_subtree(ti, ett_openflow_port_state);
424
425     /* No physical link present. */
426     proto_tree_add_item(port_state_tree, hf_openflow_link_down, tvb, offset, 4, ENC_BIG_ENDIAN);
427
428     offset+=4;
429
430     /* Current features. */
431     ti = proto_tree_add_item(tree, hf_openflow_port_curr, tvb, offset, 4, ENC_BIG_ENDIAN);
432     port_cf_tree = proto_item_add_subtree(ti, ett_openflow_port_cf);
433     /* 10 Mb half-duplex rate support. */
434     proto_tree_add_item(port_cf_tree, hf_openflow_10mb_hd, tvb, offset, 4, ENC_BIG_ENDIAN);
435     /* 10 Mb full-duplex rate support. */
436     proto_tree_add_item(port_cf_tree, hf_openflow_10mb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
437     /* 100 Mb half-duplex rate support. */
438     proto_tree_add_item(port_cf_tree, hf_openflow_100mb_hd, tvb, offset, 4, ENC_BIG_ENDIAN);
439     /* 100 Mb full-duplex rate support. */
440     proto_tree_add_item(port_cf_tree, hf_openflow_100mb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
441     /* 1 Gb half-duplex rate support. */
442     proto_tree_add_item(port_cf_tree, hf_openflow_1gb_hd, tvb, offset, 4, ENC_BIG_ENDIAN);
443     /* 1 Gb full-duplex rate support. */
444     proto_tree_add_item(port_cf_tree, hf_openflow_1gb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
445     /* 10 Gb full-duplex rate support. */
446     proto_tree_add_item(port_cf_tree, hf_openflow_10gb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
447     /* Copper medium. */
448     proto_tree_add_item(port_cf_tree, hf_openflow_copper, tvb, offset, 4, ENC_BIG_ENDIAN);
449     /* Fiber medium. */
450     proto_tree_add_item(port_cf_tree, hf_openflow_fiber, tvb, offset, 4, ENC_BIG_ENDIAN);
451     /* Auto-negotiation. */
452     proto_tree_add_item(port_cf_tree, hf_openflow_autoneg, tvb, offset, 4, ENC_BIG_ENDIAN);
453     /* Pause. */
454     proto_tree_add_item(port_cf_tree, hf_openflow_pause, tvb, offset, 4, ENC_BIG_ENDIAN);
455     /* Asymmetric pause. */
456     proto_tree_add_item(port_cf_tree, hf_openflow_pause_asym, tvb, offset, 4, ENC_BIG_ENDIAN);
457     offset+=4;
458
459     /* Features being advertised by the port. */
460     proto_tree_add_item(tree, hf_openflow_port_advertised, tvb, offset, 4, ENC_BIG_ENDIAN);
461     offset+=4;
462
463     /* Features supported by the port. */
464     proto_tree_add_item(tree, hf_openflow_port_supported, tvb, offset, 4, ENC_BIG_ENDIAN);
465     offset+=4;
466     /* Features advertised by peer. */
467     proto_tree_add_item(tree, hf_openflow_port_peer, tvb, offset, 4, ENC_BIG_ENDIAN);
468
469
470 }
471
472 #if 0
473 /*
474  * Switch features.
475  */
476
477 struct ofp_switch_features {
478     struct ofp_header   header;
479     uint64_t            datapath_id;  /* Datapath unique ID. The lower 48-bits are for
480                                          a MAC address, while the upper 16-bits are
481                                          implementer-defined. */
482     uint32_t            n_buffers;    /* Max packets buffered at once. */
483     uint8_t             n_tables;     /* Number of tables supported by datapath. */
484     uint8_t             pad[3];       /* Align to 64-bits. */
485     /* Features. */
486     uint32_t            capabilities; /* Bitmap of support "ofp_capabilities". */
487     uint32_t            actions;      /* Bitmap of supported "ofp_action_type"s. */
488     /* Port info.*/
489     struct ofp_phy_port ports[0];     /* Port definitions. The number of ports
490                                          is inferred from the length field in
491                                          the header. */
492 #endif
493
494 static void
495 dissect_openflow_features_reply_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint16 length)
496 {
497     proto_item *ti;
498     proto_tree *path_id_tree, *cap_tree, *act_tree;
499
500     guint16 length_remaining;
501
502     ti = proto_tree_add_item(tree, hf_openflow_datapath_id, tvb, offset, 8, ENC_BIG_ENDIAN);
503     path_id_tree = proto_item_add_subtree(ti, ett_openflow_path_id);
504     proto_tree_add_item(path_id_tree, hf_openflow_datapath_mac, tvb, offset, 6, ENC_NA);
505     offset+=6;
506     proto_tree_add_item(path_id_tree, hf_openflow_datapath_impl, tvb, offset, 2, ENC_BIG_ENDIAN);
507     offset+=2;
508
509     proto_tree_add_item(tree, hf_openflow_n_buffers, tvb, offset, 4, ENC_BIG_ENDIAN);
510     offset+=4;
511
512     proto_tree_add_item(tree, hf_openflow_n_tables, tvb, offset, 1, ENC_BIG_ENDIAN);
513     offset++;
514
515     proto_tree_add_item(tree, hf_openflow_features_reply_pad, tvb, offset, 3, ENC_NA);
516     offset+=3;
517
518     ti = proto_tree_add_item(tree, hf_openflow_capabilities, tvb, offset, 4, ENC_BIG_ENDIAN);
519     cap_tree = proto_item_add_subtree(ti, ett_openflow_cap);
520
521     /* Dissect flags */
522     proto_tree_add_item(cap_tree, hf_openflow_cap_flow_stats, tvb, offset, 4, ENC_BIG_ENDIAN);
523     proto_tree_add_item(cap_tree, hf_openflow_table_stats,    tvb, offset, 4, ENC_BIG_ENDIAN);
524     proto_tree_add_item(cap_tree, hf_openflow_port_stats,     tvb, offset, 4, ENC_BIG_ENDIAN);
525     proto_tree_add_item(cap_tree, hf_openflow_group_stats,    tvb, offset, 4, ENC_BIG_ENDIAN);
526     proto_tree_add_item(cap_tree, hf_openflow_ip_reasm,       tvb, offset, 4, ENC_BIG_ENDIAN);
527     proto_tree_add_item(cap_tree, hf_openflow_queue_stats,    tvb, offset, 4, ENC_BIG_ENDIAN);
528     proto_tree_add_item(cap_tree, hf_openflow_port_blocked,   tvb, offset, 4, ENC_BIG_ENDIAN);
529     offset+=4;
530
531     ti = proto_tree_add_item(tree, hf_openflow_actions, tvb, offset, 4, ENC_BIG_ENDIAN);
532     act_tree = proto_item_add_subtree(ti, ett_openflow_act);
533     /* Dissect flags */
534     proto_tree_add_item(act_tree, hf_openflow_output, tvb, offset, 4, ENC_BIG_ENDIAN);
535     proto_tree_add_item(act_tree, hf_openflow_set_vlan_vid, tvb, offset, 4, ENC_BIG_ENDIAN);
536     proto_tree_add_item(act_tree, hf_openflow_set_vlan_pcp, tvb, offset, 4, ENC_BIG_ENDIAN);
537     proto_tree_add_item(act_tree, hf_openflow_strip_vlan, tvb, offset, 4, ENC_BIG_ENDIAN);
538     proto_tree_add_item(act_tree, hf_openflow_set_dl_src, tvb, offset, 4, ENC_BIG_ENDIAN);
539     proto_tree_add_item(act_tree, hf_openflow_set_dl_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
540     proto_tree_add_item(act_tree, hf_openflow_set_nw_src, tvb, offset, 4, ENC_BIG_ENDIAN);
541     proto_tree_add_item(act_tree, hf_openflow_set_nw_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
542     proto_tree_add_item(act_tree, hf_openflow_set_nw_tos, tvb, offset, 4, ENC_BIG_ENDIAN);
543     proto_tree_add_item(act_tree, hf_openflow_set_tp_src, tvb, offset, 4, ENC_BIG_ENDIAN);
544     proto_tree_add_item(act_tree, hf_openflow_set_tp_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
545     proto_tree_add_item(act_tree, hf_openflow_enqueue, tvb, offset, 4, ENC_BIG_ENDIAN);
546     offset+=4;
547
548     length_remaining = length-32;
549     if(length_remaining > 0){
550         guint16 num_ports = length_remaining/48;
551         int i;
552         if ((length_remaining&0x003f) != 0){
553             /* protocol_error */
554         }
555         for(i=0; i<num_ports ;i++){
556             proto_tree *port_tree;
557
558             port_tree = proto_tree_add_subtree_format(tree, tvb, offset, 48, ett_openflow_port, NULL, "Port data %u",i+1);
559             dissect_openflow_phy_port(tvb, pinfo, port_tree, offset);
560             offset+=48;
561         }
562     }
563
564 }
565
566
567 static void
568 dissect_openflow_switch_config(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, guint16 length _U_)
569 {
570
571     /* ofp_config_flags */
572     proto_tree_add_item(tree, hf_openflow_config_flags, tvb, offset, 2, ENC_BIG_ENDIAN);
573     offset+=2;
574     /* miss_send_len */
575     proto_tree_add_item(tree, hf_openflow_miss_send_len, tvb, offset, 2, ENC_BIG_ENDIAN);
576     /*offset+=2;*/
577
578 }
579
580 #define OFPR_NO_MATCH       0        /* No matching flow (table-miss flow entry). */
581 #define OFPR_ACTION         1        /* Action explicitly output to controller. */
582 #define OFPR_INVALID_TTL    2        /* Packet has invalid TTL */
583
584 static const value_string openflow_reason_values[] = {
585     { OFPR_NO_MATCH,    "No matching flow (table-miss flow entry)" },
586     { OFPR_ACTION,      "Action explicitly output to controller" },
587     { OFPR_INVALID_TTL, "Packet has invalid TTL" },
588     { 0, NULL }
589 };
590
591 static void
592 dissect_openflow_pkt_in(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, guint16 length)
593 {
594     tvbuff_t *next_tvb;
595
596     /* uint32_t buffer_id;  ID assigned by datapath. */
597     proto_tree_add_item(tree, hf_openflow_buffer_id, tvb, offset, 4, ENC_BIG_ENDIAN);
598     offset+=4;
599     /* uint16_t total_len;  Full length of frame. */
600     proto_tree_add_item(tree, hf_openflow_total_len, tvb, offset, 2, ENC_BIG_ENDIAN);
601     offset+=2;
602
603     /* uint16_t in_port;  Port on which frame was received. */
604     proto_tree_add_item(tree, hf_openflow_in_port, tvb, offset, 2, ENC_BIG_ENDIAN);
605     offset+=2;
606
607     /* uint8_t reason; Reason packet is being sent (one of OFPR_*) */
608     proto_tree_add_item(tree, hf_openflow_reason, tvb, offset, 1, ENC_BIG_ENDIAN);
609     offset++;
610
611     proto_tree_add_item(tree, hf_openflow_pkt_in_pad, tvb, offset, 1, ENC_NA);
612     offset+=1;
613
614     next_tvb = tvb_new_subset_length(tvb, offset, length-offset);
615     call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree);
616
617 }
618
619 static void
620 dissect_openflow_pkt_out(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, guint16 length _U_)
621 {
622     tvbuff_t *next_tvb;
623     gint32 buffer_id;
624
625     /* uint32_t buffer_id;  ID assigned by datapath. */
626     buffer_id = tvb_get_ntohl(tvb, offset);
627     proto_tree_add_item(tree, hf_openflow_buffer_id, tvb, offset, 4, ENC_BIG_ENDIAN);
628     offset+=4;
629
630     /* uint32_t in_port; Packet's input port or OFPP_CONTROLLER. */
631     proto_tree_add_item(tree, hf_openflow_in_port, tvb, offset, 2, ENC_BIG_ENDIAN);
632     offset+=2;
633
634     /* uint16_t actions_len;  Size of action array in bytes. */
635     proto_tree_add_item(tree, hf_openflow_actions_len, tvb, offset, 2, ENC_BIG_ENDIAN);
636     offset+=2;
637
638     /* struct ofp_action_header actions[0];  Action list. */
639     offset = dissect_openflow_action_header(tvb, pinfo, tree, offset);
640     /* Packet data. The length is inferred
641        from the length field in the header.
642        (Only meaningful if buffer_id == -1.)
643      */
644     if(buffer_id == -1){
645         next_tvb = tvb_new_subset_length(tvb, offset, length-offset);
646         call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree);
647     }
648 }
649
650 #define OFPFC_ADD             0 /* New flow. */
651 #define OFPFC_MODIFY          1 /* Modify all matching flows. */
652 #define OFPFC_MODIFY_STRICT   2 /* Modify entry strictly matching wildcards */
653 #define OFPFC_DELETE          3 /* Delete all matching flows. */
654 #define OFPFC_DELETE_STRICT   4 /* Strictly match wildcards and priority. */
655
656 static const value_string openflow_command_values[] = {
657     { OFPFC_ADD,            "New flow" },
658     { OFPFC_MODIFY,         "Modify all matching flows" },
659     { OFPFC_MODIFY_STRICT,  "Modify entry strictly matching wildcards" },
660     { OFPFC_DELETE,         "Delete all matching flows" },
661     { OFPFC_DELETE_STRICT,  "Strictly match wildcards and priority" },
662     { 0, NULL }
663 };
664
665 static void
666 dissect_openflow_flow_mod(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint16 length _U_)
667 {
668
669     /* struct ofp_match match;  Fields to match */
670     offset = dissect_openflow_ofp_match_v1(tvb, pinfo, tree, offset);
671
672     /* uint64_t cookie; Opaque controller-issued identifier. */
673     proto_tree_add_item(tree, hf_openflow_cookie, tvb, offset, 8, ENC_BIG_ENDIAN);
674     offset+=8;
675
676     /* uint16_t command;  One of OFPFC_*. */
677     proto_tree_add_item(tree, hf_openflow_command, tvb, offset, 2, ENC_BIG_ENDIAN);
678     offset+=2;
679
680     /* uint16_t idle_timeout;  Idle time before discarding (seconds). */
681     proto_tree_add_item(tree, hf_openflow_idle_timeout, tvb, offset, 2, ENC_BIG_ENDIAN);
682     offset+=2;
683     /* uint16_t hard_timeout; Max time before discarding (seconds). */
684     proto_tree_add_item(tree, hf_openflow_hard_timeout, tvb, offset, 2, ENC_BIG_ENDIAN);
685     offset+=2;
686     /* uint16_t priority; Priority level of flow entry. */
687     proto_tree_add_item(tree, hf_openflow_priority, tvb, offset, 2, ENC_BIG_ENDIAN);
688     offset+=2;
689     /* uint32_t buffer_id;  Buffered packet to apply to, or OFP_NO_BUFFER.
690        Not meaningful for OFPFC_DELETE*.
691      */
692     proto_tree_add_item(tree, hf_openflow_buffer_id, tvb, offset, 4, ENC_BIG_ENDIAN);
693     offset+=4;
694     /* uint32_t out_port; For OFPFC_DELETE* commands, require
695        matching entries to include this as an output port. A value of OFPP_ANY
696        indicates no restriction.
697        */
698     proto_tree_add_item(tree, hf_openflow_out_port, tvb, offset, 2, ENC_BIG_ENDIAN);
699     offset+=2;
700
701     /* uint16_t flags; One of OFPFF_*. */
702     proto_tree_add_item(tree, hf_openflow_flags, tvb, offset, 2, ENC_BIG_ENDIAN);
703     /*offset+=2;*/
704 }
705
706 static int
707 dissect_openflow_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
708 {
709     proto_item *ti, *type_item;
710     proto_tree *openflow_tree;
711     guint offset = 0;
712     guint8 type;
713     guint16 length;
714
715     type    = tvb_get_guint8(tvb, 1);
716
717     col_append_fstr(pinfo->cinfo, COL_INFO, "Type: %s",
718                   val_to_str_const(type, openflow_1_0_type_values, "Unknown message type"));
719
720     /* Stop the Ethernet frame from overwriting the columns */
721     if((type == OFPT_1_0_PACKET_IN) || (type == OFPT_1_0_PACKET_OUT)){
722         col_set_writable(pinfo->cinfo, FALSE);
723     }
724
725     /* Create display subtree for the protocol */
726     ti = proto_tree_add_item(tree, proto_openflow_v1, tvb, 0, -1, ENC_NA);
727     openflow_tree = proto_item_add_subtree(ti, ett_openflow);
728
729     /* A.1 OpenFlow Header. */
730     /* OFP_VERSION. */
731     proto_tree_add_item(openflow_tree, hf_openflow_version, tvb, offset, 1, ENC_BIG_ENDIAN);
732     offset++;
733
734     /* One of the OFPT_ constants. */
735     type_item = proto_tree_add_item(openflow_tree, hf_openflow_1_0_type, tvb, offset, 1, ENC_BIG_ENDIAN);
736     offset++;
737
738     /* Length including this ofp_header. */
739     length = tvb_get_ntohs(tvb, offset);
740     proto_tree_add_item(openflow_tree, hf_openflow_length, tvb, offset, 2, ENC_BIG_ENDIAN);
741     offset+=2;
742
743     /* Transaction id associated with this packet. Replies use the same id as was in the request
744      * to facilitate pairing.
745      */
746     proto_tree_add_item(openflow_tree, hf_openflow_xid, tvb, offset, 4, ENC_BIG_ENDIAN);
747     offset+=4;
748
749     switch(type){
750     case OFPT_1_0_HELLO: /* 0 */
751         /* 5.5.1 Hello
752          * The OFPT_HELLO message has no body;
753          */
754         break;
755     case OFPT_1_0_FEATURES_REQUEST: /* 5 */
756         /* 5.3.1 Handshake
757          * Upon TLS session establishment, the controller sends an OFPT_FEATURES_REQUEST
758          * message. This message does not contain a body beyond the OpenFlow header.
759          */
760         break;
761     case OFPT_1_0_FEATURES_REPLY: /* 6 */
762         dissect_openflow_features_reply_v1(tvb, pinfo, openflow_tree, offset, length);
763         break;
764     case OFPT_1_0_GET_CONFIG_REQUEST: /* 7 */
765         /* A.3.2 There is no body for OFPT_GET_CONFIG_REQUEST beyond the OpenFlow header. */
766         break;
767     case OFPT_1_0_GET_CONFIG_REPLY: /* 8 */
768         /* Fall trough */
769     case OFPT_1_0_SET_CONFIG: /* 9 */
770         dissect_openflow_switch_config(tvb, pinfo, openflow_tree, offset, length);
771         break;
772     case OFPT_1_0_PACKET_IN: /* 10 */
773         dissect_openflow_pkt_in(tvb, pinfo, openflow_tree, offset, length);
774         break;
775     case OFPT_1_0_PACKET_OUT: /* 13 */
776         dissect_openflow_pkt_out(tvb, pinfo, openflow_tree, offset, length);
777         break;
778     case OFPT_1_0_FLOW_MOD: /* 14 */
779         dissect_openflow_flow_mod(tvb, pinfo, openflow_tree, offset, length);
780         break;
781     default:
782         if(length>8){
783             expert_add_info(pinfo, type_item, &ei_openflow_1_0_type);
784         }
785         break;
786     }
787
788     return tvb_reported_length(tvb);
789
790 }
791
792
793 /*
794  * Register the protocol with Wireshark.
795  */
796 void
797 proto_register_openflow_v1(void)
798 {
799     static hf_register_info hf[] = {
800         { &hf_openflow_version,
801             { "Version", "openflow.version",
802                FT_UINT8, BASE_HEX, VALS(openflow_version_values), 0x7f,
803                NULL, HFILL }
804         },
805         { &hf_openflow_1_0_type,
806             { "Type", "openflow_1_0.type",
807                FT_UINT8, BASE_DEC, VALS(openflow_1_0_type_values), 0x0,
808                NULL, HFILL }
809         },
810         { &hf_openflow_xid,
811             { "Transaction ID", "openflow.xid",
812                FT_UINT32, BASE_DEC, NULL, 0x0,
813                NULL, HFILL }
814         },
815         { &hf_openflow_length,
816             { "Length", "openflow.length",
817                FT_UINT16, BASE_DEC, NULL, 0x0,
818                NULL, HFILL }
819         },
820         { &hf_openflow_datapath_id,
821             { "Datapath unique ID", "openflow.datapath_id",
822                FT_UINT64, BASE_HEX, NULL, 0x0,
823                NULL, HFILL }
824         },
825         { &hf_openflow_datapath_mac,
826             { "MAC addr", "openflow.datapath_mac",
827                FT_ETHER, BASE_NONE, NULL, 0x0,
828                NULL, HFILL }
829         },
830         { &hf_openflow_datapath_impl,
831             { "Implementers part", "openflow.datapath_imp",
832                FT_UINT16, BASE_HEX, NULL, 0x0,
833                NULL, HFILL }
834         },
835         { &hf_openflow_n_buffers,
836             { "n_buffers", "openflow.n_buffers",
837                FT_UINT32, BASE_DEC, NULL, 0x0,
838                NULL, HFILL }
839         },
840         { &hf_openflow_n_tables,
841             { "n_tables", "openflow.n_tables",
842                FT_UINT8, BASE_DEC, NULL, 0x0,
843                NULL, HFILL }
844         },
845 #if 0
846         { &hf_openflow_auxiliary_id,
847             { "auxiliary_id", "openflow.auxiliary_id",
848                FT_UINT8, BASE_DEC, NULL, 0x0,
849                NULL, HFILL }
850         },
851 #endif
852         { &hf_openflow_capabilities,
853             { "capabilities", "openflow.capabilities",
854                FT_UINT32, BASE_HEX, NULL, 0x0,
855                NULL, HFILL }
856         },
857         { &hf_openflow_actions,
858             { "actions", "openflow.actions",
859                FT_UINT32, BASE_HEX, NULL, 0x0,
860                NULL, HFILL }
861         },
862 #if 0
863         { &hf_openflow_reserved32,
864             { "Reserved", "openflow.reserved32",
865                FT_UINT32, BASE_DEC, NULL, 0x0,
866                NULL, HFILL }
867         },
868 #endif
869         { &hf_openflow_cap_flow_stats,
870             { "Flow statistics", "openflow.flow_stats",
871                FT_BOOLEAN, 32, NULL, OFPC_FLOW_STATS,
872                NULL, HFILL }
873         },
874         { &hf_openflow_table_stats,
875             { "Table statistics", "openflow.table_stats",
876                FT_BOOLEAN, 32, NULL, OFPC_TABLE_STATS,
877                NULL, HFILL }
878         },
879         { &hf_openflow_port_stats,
880             { "Port statistics", "openflow.port_stats",
881                FT_BOOLEAN, 32, NULL,  OFPC_PORT_STATS,
882                NULL, HFILL }
883         },
884         { &hf_openflow_group_stats,
885             { "Group statistics", "openflow.group_stats",
886                FT_BOOLEAN, 32, NULL, OFPC_GROUP_STATS,
887                NULL, HFILL }
888         },
889         { &hf_openflow_ip_reasm,
890             { "Can reassemble IP fragments", "openflow.ip_reasm",
891                FT_BOOLEAN, 32, NULL, OFPC_IP_REASM,
892                NULL, HFILL }
893         },
894         { &hf_openflow_queue_stats,
895             { "Queue statistics", "openflow.queue_stats",
896                FT_BOOLEAN, 32, NULL, OFPC_QUEUE_STATS,
897                NULL, HFILL }
898         },
899         { &hf_openflow_port_blocked,
900             { "Switch will block looping ports", "openflow.port_blocked",
901                FT_BOOLEAN, 32, NULL, OFPC_PORT_BLOCKED,
902                NULL, HFILL }
903         },
904         { &hf_openflow_output,
905             { "Output to switch port", "openflow.output",
906                FT_BOOLEAN, 32, NULL, OFPAT_OUTPUT_MASK,
907                NULL, HFILL }
908         },
909         { &hf_openflow_set_vlan_vid,
910             { "Set the 802.1q VLAN id", "openflow.set_vlan_vid",
911                FT_BOOLEAN, 32, NULL, OFPAT_SET_VLAN_VID_MASK,
912                NULL, HFILL }
913         },
914         { &hf_openflow_set_vlan_pcp,
915             { "Set the 802.1q priority", "openflow.set_vlan_pcp",
916                FT_BOOLEAN, 32, NULL, OFPAT_SET_VLAN_PCP_MASK,
917                NULL, HFILL }
918         },
919         { &hf_openflow_strip_vlan,
920             { "Strip the 802.1q header", "openflow.strip_vlan",
921                FT_BOOLEAN, 32, NULL, OFPAT_STRIP_VLAN_MASK,
922                NULL, HFILL }
923         },
924         { &hf_openflow_set_dl_src,
925             { "Ethernet source address", "openflow.set_dl_src",
926                FT_BOOLEAN, 32, NULL, OFPAT_SET_DL_SRC_MASK,
927                NULL, HFILL }
928         },
929         { &hf_openflow_set_dl_dst,
930             { "Ethernet destination address", "openflow.set_dl_ds",
931                FT_BOOLEAN, 32, NULL, OFPAT_SET_DL_DST_MASK,
932                NULL, HFILL }
933         },
934         { &hf_openflow_set_nw_src,
935             { "IP source address", "openflow.set_nw_src",
936                FT_BOOLEAN, 32, NULL, OFPAT_SET_NW_SRC_MASK,
937                NULL, HFILL }
938         },
939         { &hf_openflow_set_nw_dst,
940             { "IP destination address", "openflow.set_nw_ds",
941                FT_BOOLEAN, 32, NULL, OFPAT_SET_NW_DST_MASK,
942                NULL, HFILL }
943         },
944         { &hf_openflow_set_nw_tos,
945             { "IP ToS (DSCP field, 6 bits)", "openflow.set_nw_tos",
946                FT_BOOLEAN, 32, NULL, OFPAT_SET_NW_TOS_MASK,
947                NULL, HFILL }
948         },
949         { &hf_openflow_set_tp_src,
950             { "TCP/UDP source port", "openflow.set_tp_src",
951                FT_BOOLEAN, 32, NULL, OFPAT_SET_TP_SRC_MASK,
952                NULL, HFILL }
953         },
954         { &hf_openflow_set_tp_dst,
955             { "TCP/UDP destination port", "openflow.set_tp_dst",
956                FT_BOOLEAN, 32, NULL, OFPAT_SET_TP_DST_MASK,
957                NULL, HFILL }
958         },
959         { &hf_openflow_enqueue,
960             { "Output to queue", "openflow.enqueue",
961                FT_BOOLEAN, 32, NULL, OFPAT_ENQUEUE_MASK,
962                NULL, HFILL }
963         },
964         { &hf_openflow_port_no,
965             { "Port number", "openflow.port_no",
966                FT_UINT16, BASE_DEC, NULL, 0x0,
967                NULL, HFILL }
968         },
969         { &hf_openflow_hw_addr,
970             { "HW Address", "openflow.hw_add",
971                FT_ETHER, BASE_NONE, NULL, 0x0,
972                NULL, HFILL }
973         },
974         { &hf_openflow_port_name,
975             { "Name", "openflow.hw_add",
976                FT_STRING, BASE_NONE, NULL, 0x0,
977                NULL, HFILL }
978         },
979         { &hf_openflow_port_config,
980             { "Config flags", "openflow.port_config",
981                FT_UINT32, BASE_HEX, NULL, 0x0,
982                NULL, HFILL }
983         },
984         { &hf_openflow_port_state,
985             { "State flags", "openflow.port_state",
986                FT_UINT32, BASE_HEX, NULL, 0x0,
987                NULL, HFILL }
988         },
989         { &hf_openflow_port_curr,
990             { "Current features", "openflow.port_curr",
991                FT_UINT32, BASE_HEX, NULL, 0x0,
992                NULL, HFILL }
993         },
994         { &hf_openflow_port_advertised,
995             { "Advertised features", "openflow.port_advertised",
996                FT_UINT32, BASE_HEX, NULL, 0x0,
997                NULL, HFILL }
998         },
999         { &hf_openflow_port_supported,
1000             { "Features supported", "openflow.port_supported",
1001                FT_UINT32, BASE_HEX, NULL, 0x0,
1002                NULL, HFILL }
1003         },
1004         { &hf_openflow_port_peer,
1005             { "Features advertised by peer", "openflow.port_peer",
1006                FT_UINT32, BASE_HEX, NULL, 0x0,
1007                NULL, HFILL }
1008         },
1009         { &hf_openflow_port_down,
1010             { "Port is administratively down", "openflow.port_down",
1011                FT_BOOLEAN, 32, NULL, OFPPC_PORT_DOWN,
1012                NULL, HFILL }
1013         },
1014         { &hf_openflow_no_stp,
1015             { "Disable 802.1D spanning tree on port", "openflow.no_stp",
1016                FT_BOOLEAN, 32, NULL, OFPPC_NO_STP,
1017                NULL, HFILL }
1018         },
1019         { &hf_openflow_no_recv,
1020             { "Drop all packets except 802.1D spanning tree packets", "openflow.no_recv",
1021                FT_BOOLEAN, 32, NULL, OFPPC_NO_RECV,
1022                NULL, HFILL }
1023         },
1024         { &hf_openflow_no_recv_stp,
1025             { "Drop received 802.1D STP packets", "openflow.no_recv",
1026                FT_BOOLEAN, 32, NULL, OFPPC_NO_RECV_STP,
1027                NULL, HFILL }
1028         },
1029         { &hf_openflow_no_flood,
1030             { "Do not include this port when flooding", "openflow.no_flood",
1031                FT_BOOLEAN, 32, NULL, OFPPC_NO_FLOOD,
1032                NULL, HFILL }
1033         },
1034         { &hf_openflow_no_fwd,
1035             { "Drop packets forwarded to port", "openflow.no_fwd",
1036                FT_BOOLEAN, 32, NULL, OFPPC_NO_FWD,
1037                NULL, HFILL }
1038         },
1039         { &hf_openflow_no_packet_in,
1040             { "Do not send packet-in msgs for port", "openflow.no_packet_in",
1041                FT_BOOLEAN, 32, NULL, OFPPC_NO_PACKET_IN,
1042                NULL, HFILL }
1043         },
1044         { &hf_openflow_link_down,
1045             { "No physical link present", "openflow.link_down",
1046                FT_BOOLEAN, 32, NULL, OFPPS_LINK_DOWN,
1047                NULL, HFILL }
1048         },
1049         { &hf_openflow_10mb_hd,
1050             { "10 Mb half-duplex rate support", "openflow.10mb_hd",
1051                FT_BOOLEAN, 32, NULL, OFPPF_10MB_HD,
1052                NULL, HFILL }
1053         },
1054         { &hf_openflow_10mb_fd,
1055             { "10 Mb full-duplex rate support", "openflow.10mb_fd",
1056                FT_BOOLEAN, 32, NULL, OFPPF_10MB_FD,
1057                NULL, HFILL }
1058         },
1059         { &hf_openflow_100mb_hd,
1060             { "100 Mb half-duplex rate support", "openflow.100mb_hd",
1061                FT_BOOLEAN, 32, NULL, OFPPF_100MB_HD,
1062                NULL, HFILL }
1063         },
1064         { &hf_openflow_100mb_fd,
1065             { "100 Mb full-duplex rate support", "openflow.100mb_0fd",
1066                FT_BOOLEAN, 32, NULL, OFPPF_100MB_FD,
1067                NULL, HFILL }
1068         },
1069         { &hf_openflow_1gb_hd,
1070             { "1 Gb half-duplex rate support", "openflow.1gb_hd",
1071                FT_BOOLEAN, 32, NULL, OFPPF_1GB_HD,
1072                NULL, HFILL }
1073         },
1074         { &hf_openflow_1gb_fd,
1075             { "1 Gb full-duplex rate support", "openflow.1gb_fd",
1076                FT_BOOLEAN, 32, NULL, OFPPF_1GB_FD,
1077                NULL, HFILL }
1078         },
1079         { &hf_openflow_10gb_fd,
1080             { "10 Gb full-duplex rate support", "openflow.10gb_fd",
1081                FT_BOOLEAN, 32, NULL, OFPPF_10GB_FD,
1082                NULL, HFILL }
1083         },
1084         { &hf_openflow_copper,
1085             { "Copper medium", "openflow.copper",
1086                FT_BOOLEAN, 32, NULL, OFPPF_COPPER,
1087                NULL, HFILL }
1088         },
1089         { &hf_openflow_fiber,
1090             { "Fiber medium", "openflow.fiber",
1091                FT_BOOLEAN, 32, NULL, OFPPF_FIBER,
1092                NULL, HFILL }
1093         },
1094         { &hf_openflow_autoneg,
1095             { "Auto-negotiation", "openflow.autoneg",
1096                FT_BOOLEAN, 32, NULL, OFPPF_AUTONEG,
1097                NULL, HFILL }
1098         },
1099         { &hf_openflow_pause,
1100             { "Pause", "openflow.pause",
1101                FT_BOOLEAN, 32, NULL, OFPPF_PAUSE,
1102                NULL, HFILL }
1103         },
1104         { &hf_openflow_pause_asym,
1105             { "Asymmetric pause", "openflow.pause_asym",
1106                FT_BOOLEAN, 32, NULL, OFPPF_PAUSE_ASYM,
1107                NULL, HFILL }
1108         },
1109         { &hf_openflow_config_flags,
1110             { "Config flags", "openflow.config_flags",
1111                FT_UINT16, BASE_HEX, NULL, 0x0,
1112                NULL, HFILL }
1113         },
1114         { &hf_openflow_miss_send_len,
1115             { "Max bytes of packet", "openflow.miss_send_len",
1116                FT_UINT16, BASE_HEX, NULL, 0x0,
1117                NULL, HFILL }
1118         },
1119         { &hf_openflow_buffer_id,
1120             { "Buffer Id", "openflow.buffer_id",
1121                FT_UINT32, BASE_HEX, NULL, 0x0,
1122                NULL, HFILL }
1123         },
1124         { &hf_openflow_total_len,
1125             { "Total length", "openflow.total_len",
1126                FT_UINT16, BASE_DEC, NULL, 0x0,
1127                NULL, HFILL }
1128         },
1129         { &hf_openflow_in_port,
1130             { "In port", "openflow.in_port",
1131                FT_UINT16, BASE_DEC, NULL, 0x0,
1132                NULL, HFILL }
1133         },
1134         { &hf_openflow_reason,
1135             { "Reason", "openflow.reason",
1136                FT_UINT8, BASE_DEC, VALS(openflow_reason_values), 0x0,
1137                NULL, HFILL }
1138         },
1139
1140         { &hf_openflow_pkt_in_pad,
1141             { "Pad", "openflow.pkt_in.pad",
1142                FT_BYTES, BASE_NONE, NULL, 0x0,
1143                NULL, HFILL }
1144         },
1145 #if 0
1146         { &hf_openflow_table_id,
1147             { "Table Id", "openflow.table_id",
1148                FT_UINT8, BASE_DEC, NULL, 0x0,
1149                NULL, HFILL }
1150         },
1151 #endif
1152         { &hf_openflow_cookie,
1153             { "Cookie", "openflow.cookie",
1154                FT_UINT64, BASE_HEX, NULL, 0x0,
1155                NULL, HFILL }
1156         },
1157 #if 0
1158         { &hf_openflow_cookie_mask,
1159             { "Cookie mask", "openflow.cookie",
1160                FT_UINT64, BASE_HEX, NULL, 0x0,
1161                NULL, HFILL }
1162         },
1163 #endif
1164         { &hf_openflow_features_reply_pad,
1165             { "Pad", "openflow.features_reply.pad",
1166                FT_BYTES, BASE_NONE, NULL, 0x0,
1167                NULL, HFILL }
1168         },
1169         { &hf_openflow_actions_len,
1170             { "Actions length", "openflow.actions_len",
1171                FT_UINT16, BASE_DEC, NULL, 0x0,
1172                NULL, HFILL }
1173         },
1174         { &hf_openflow_action_type,
1175             { "Actions type", "openflow.action_typ",
1176                FT_UINT16, BASE_DEC, VALS(openflow_action_values), 0x0,
1177                NULL, HFILL }
1178         },
1179         { &hf_openflow_action_len,
1180             { "Action length", "openflow.action_len",
1181                FT_UINT16, BASE_DEC, NULL, 0x0,
1182                NULL, HFILL }
1183         },
1184         { &hf_openflow_output_port,
1185             { "Output port", "openflow.output_port",
1186                FT_UINT16, BASE_DEC, NULL, 0x0,
1187                NULL, HFILL }
1188         },
1189         { &hf_openflow_max_len,
1190             { "Max length", "openflow.max_len",
1191                FT_UINT16, BASE_DEC, NULL, 0x0,
1192                NULL, HFILL }
1193         },
1194         { &hf_openflow_wildcards,
1195             { "Wildcards", "openflow.wildcards",
1196                FT_UINT32, BASE_DEC, NULL, 0x0,
1197                NULL, HFILL }
1198         },
1199         { &hf_openflow_command,
1200             { "Command", "openflow.command",
1201                FT_UINT16, BASE_DEC, VALS(openflow_command_values), 0x0,
1202                NULL, HFILL }
1203         },
1204         { &hf_openflow_eth_src,
1205             { "Ethernet source address", "openflow.eth_src",
1206                FT_ETHER, BASE_NONE, NULL, 0x0,
1207                NULL, HFILL }
1208         },
1209         { &hf_openflow_eth_dst,
1210             { "Ethernet destination address", "openflow.eth_src",
1211                FT_ETHER, BASE_NONE, NULL, 0x0,
1212                NULL, HFILL }
1213         },
1214         { &hf_openflow_dl_vlan,
1215             { "Input VLAN id", "openflow.dl_vlan",
1216                FT_UINT16, BASE_DEC, NULL, 0x0,
1217                NULL, HFILL }
1218         },
1219         { &hf_openflow_dl_vlan_pcp,
1220             { "Input VLAN priority", "openflow.dl_vlan_pcp",
1221                FT_UINT8, BASE_DEC, NULL, 0x0,
1222                NULL, HFILL }
1223         },
1224         { &hf_openflow_ofp_match_pad,
1225             { "Pad", "openflow.ofp_match.pad",
1226               FT_BYTES, BASE_NONE, NULL, 0x0,
1227                NULL, HFILL }
1228         },
1229         { &hf_openflow_idle_timeout,
1230             { "Idle time-out", "openflow.idle_timeout",
1231                FT_UINT16, BASE_DEC, NULL, 0x0,
1232                NULL, HFILL }
1233         },
1234         { &hf_openflow_hard_timeout,
1235             { "hard time-out", "openflow.hard_timeout",
1236                FT_UINT16, BASE_DEC, NULL, 0x0,
1237                NULL, HFILL }
1238         },
1239         { &hf_openflow_priority,
1240             { "Priority", "openflow.priority",
1241                FT_UINT16, BASE_DEC, NULL, 0x0,
1242                NULL, HFILL }
1243         },
1244         { &hf_openflow_out_port,
1245             { "Out port", "openflow.out_port",
1246                FT_UINT32, BASE_DEC, NULL, 0x0,
1247                NULL, HFILL }
1248         },
1249 #if 0
1250         { &hf_openflow_out_group,
1251             { "Out group", "openflow.out_group",
1252                FT_UINT32, BASE_DEC, NULL, 0x0,
1253                NULL, HFILL }
1254         },
1255 #endif
1256         { &hf_openflow_flags,
1257             { "Flags", "openflow.flags",
1258                FT_UINT16, BASE_DEC, NULL, 0x0,
1259                NULL, HFILL }
1260         },
1261     };
1262
1263     static gint *ett[] = {
1264         &ett_openflow,
1265         &ett_openflow_path_id,
1266         &ett_openflow_cap,
1267         &ett_openflow_act,
1268         &ett_openflow_port,
1269         &ett_openflow_port_cnf,
1270         &ett_openflow_port_state,
1271         &ett_openflow_port_cf
1272     };
1273
1274     static ei_register_info ei[] = {
1275         { &ei_openflow_undecoded_data, { "openflow.undecoded_data", PI_UNDECODED, PI_WARN, "Data not dissected yet", EXPFILL }},
1276         { &ei_openflow_action_type, { "openflow.action_typ.undecoded", PI_UNDECODED, PI_WARN, "Action not dissected yet", EXPFILL }},
1277         { &ei_openflow_1_0_type, { "openflow_1_0.type.undecoded", PI_UNDECODED, PI_WARN, "Message data not dissected yet", EXPFILL }},
1278     };
1279
1280     expert_module_t* expert_openflow_v1;
1281
1282     /* Register the protocol name and description */
1283     proto_openflow_v1 = proto_register_protocol("OpenFlow 1.0",
1284             "openflow_v1", "openflow_v1");
1285
1286     new_register_dissector("openflow_v1", dissect_openflow_v1, proto_openflow_v1);
1287
1288     eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
1289
1290     /* Required function calls to register the header fields and subtrees */
1291     proto_register_field_array(proto_openflow_v1, hf, array_length(hf));
1292     proto_register_subtree_array(ett, array_length(ett));
1293     expert_openflow_v1 = expert_register_protocol(proto_openflow_v1);
1294     expert_register_field_array(expert_openflow_v1, ei, array_length(ei));
1295 }
1296
1297 /*
1298  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
1299  *
1300  * Local variables:
1301  * c-basic-offset: 4
1302  * tab-width: 8
1303  * indent-tabs-mode: nil
1304  * End:
1305  *
1306  * vi: set shiftwidth=4 tabstop=8 expandtab:
1307  * :indentSize=4:tabSize=8:noTabs=true:
1308  */