aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-openflow.c
blob: 46b5523d583799d9b43f6e7c0eafa255ea3bc83d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
/* packet-openflow.c
 * Routines for OpenFlow dissection
 * Copyright 2013, Anders Broman <anders.broman@ericsson.com>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Ref https://www.opennetworking.org/sdn-resources/onf-specifications/openflow 
 */

#include "config.h"

#include <glib.h>

#include <epan/packet.h>
#include <epan/prefs.h>

void proto_reg_handoff_openflow(void);

static int g_openflow_port = 0;

/* Initialize the protocol and registered fields */
static int proto_openflow = -1;
static int hf_openflow_version = -1;
static int hf_openflow_type = -1;
static int hf_openflow_length = -1;
static int hf_openflow_xid = -1;

static int hf_openflow_datapath_id = -1;
static int hf_openflow_datapath_mac = -1;
static int hf_openflow_datapath_impl = -1;
static int hf_openflow_n_buffers = -1;
static int hf_openflow_n_tables = -1;
static int hf_openflow_pad3 = -1;
static int hf_openflow_capabilities = -1;
static int hf_openflow_actions = -1;
static int hf_openflow_reserved32 = -1;
static int hf_openflow_cap_flow_stats = -1;
static int hf_openflow_table_stats = -1;
static int hf_openflow_port_stats = -1;
static int hf_openflow_group_stats = -1;
static int hf_openflow_ip_reasm = -1; 
static int hf_openflow_queue_stats = -1;
static int hf_openflow_port_blocked = -1;

static int hf_openflow_output = -1; /* Output to switch port. */
static int hf_openflow_set_vlan_vid = -1; /* Set the 802.1q VLAN id. */
static int hf_openflow_set_vlan_pcp = -1; /* Set the 802.1q priority. */
static int hf_openflow_strip_vlan = -1; /* Strip the 802.1q header. */
static int hf_openflow_set_dl_src = -1; /* Ethernet source address. */
static int hf_openflow_set_dl_dst = -1; /* Ethernet destination address. */
static int hf_openflow_set_nw_src = -1; /* IP source address. */
static int hf_openflow_set_nw_dst = -1; /* IP destination address. */
static int hf_openflow_set_nw_tos = -1; /* IP ToS (DSCP field, 6 bits). */
static int hf_openflow_set_tp_src = -1; /* TCP/UDP source port. */
static int hf_openflow_set_tp_dst = -1; /* TCP/UDP destination port. */
static int hf_openflow_enqueue = -1; /* Output to queue. */

static int hf_openflow_port_no = -1;
static int hf_openflow_hw_addr = -1;
static int hf_openflow_port_name = -1;


static int hf_openflow_port_config = -1;
static int hf_openflow_port_state = -1;
static int hf_openflow_port_curr = -1;
static int hf_openflow_port_advertised = -1;
static int hf_openflow_port_supported = -1;
static int hf_openflow_port_peer = -1;

static int hf_openflow_port_down = -1;    /* Port is administratively down. */
static int hf_openflow_no_stp = -1;       /* Disable 802.1D spanning tree on port. */
static int hf_openflow_no_recv = -1;      /* Drop all packets except 802.1D spanning tree packets. */
static int hf_openflow_no_recv_stp = -1;  /* Drop received 802.1D STP packets. */
static int hf_openflow_no_flood = -1;     /* Do not include this port when flooding. */
static int hf_openflow_no_fwd = -1;       /* Drop packets forwarded to port. */
static int hf_openflow_no_packet_in = -1; /* Do not send packet-in msgs for port. */

static int hf_openflow_link_down = -1;    /* No physical link present. */

static int hf_openflow_10mb_hd = -1;      /* 10 Mb half-duplex rate support. */
static int hf_openflow_10mb_fd = -1;      /* 10 Mb full-duplex rate support. */
static int hf_openflow_100mb_hd = -1;     /* 100 Mb half-duplex rate support. */
static int hf_openflow_100mb_fd = -1;     /* 100 Mb full-duplex rate support. */
static int hf_openflow_1gb_hd = -1;       /* 1 Gb half-duplex rate support. */
static int hf_openflow_1gb_fd = -1;       /* 1 Gb full-duplex rate support. */
static int hf_openflow_10gb_fd = -1;      /* 10 Gb full-duplex rate support. */
static int hf_openflow_copper = -1;       /* Copper medium. */
static int hf_openflow_fiber = -1;        /* Fiber medium. */
static int hf_openflow_autoneg = -1;      /* Auto-negotiation. */
static int hf_openflow_pause = -1;        /* Pause. */
static int hf_openflow_pause_asym = -1;   /* Asymmetric pause. */

static int hf_openflow_config_flags = -1;
static int hf_openflow_miss_send_len = -1;

/* Initialize the subtree pointers */
static gint ett_openflow = -1;
static gint ett_openflow_path_id = -1;
static gint ett_openflow_cap = -1;
static gint ett_openflow_act = -1;
static gint ett_openflow_port = -1;
static gint ett_openflow_port_cnf = -1;
static gint ett_openflow_port_state = -1;
static gint ett_port_cf = -1;


static const value_string openflow_version_values[] = {
    { 0x01, "1.0" },
    { 0x02, "1.1" },
    { 0x03, "1.2" },
    { 0x04, "1.3" },
    { 0, NULL }
};

/* Immutable messages. */
#define OFPT_HELLO                     0 /* Symmetric message */
#define OFPT_ERROR                     1 /* Symmetric message */
#define OFPT_ECHO_REQUEST              2 /* Symmetric message */
#define OFPT_ECHO_REPLY                3 /* Symmetric message */
#define OFPT_EXPERIMENTER              4 /* Symmetric message */
/* Switch configuration messages. */
#define OFPT_FEATURES_REQUEST          5 /* Controller/switch message */
#define OFPT_FEATURES_REPLY            6 /* Controller/switch message */
#define OFPT_GET_CONFIG_REQUEST        7 /* Controller/switch message */
#define OFPT_GET_CONFIG_REPLY          8 /* Controller/switch message */
#define OFPT_SET_CONFIG                9 /* Controller/switch message */
/* Asynchronous messages. */
#define OFPT_PACKET_IN                10 /* Async message */
#define OFPT_FLOW_REMOVED             11 /* Async message */
#define OFPT_PORT_STATUS              12 /* Async message */
/* Controller command messages. */
#define OFPT_PACKET_OUT               13 /* Controller/switch message */
#define OFPT_FLOW_MOD                 14 /* Controller/switch message */
#define OFPT_GROUP_MOD                15 /* Controller/switch message */
#define OFPT_PORT_MOD                 16 /* Controller/switch message */
#define OFPT_TABLE_MOD                17 /* Controller/switch message */
/* Multipart messages. */
#define OFPT_MULTIPART_REQUEST        18 /* Controller/switch message */
#define OFPT_MULTIPART_REPLY          19 /* Controller/switch message */
/* Barrier messages. */
#define OFPT_BARRIER_REQUEST          20 /* Controller/switch message */
#define OFPT_BARRIER_REPLY            21 /* Controller/switch message */
/* Queue Configuration messages. */
#define OFPT_QUEUE_GET_CONFIG_REQUEST 22 /* Controller/switch message */
#define OFPT_QUEUE_GET_CONFIG_REPLY   23 /* Controller/switch message */
/* Controller role change request messages. */
#define OFPT_ROLE_REQUEST             24 /* Controller/switch message */
#define OFPT_ROLE_REPLY               25 /* Controller/switch message */
/* Asynchronous message configuration. */
#define OFPT_GET_ASYNC_REQUEST        26 /* Controller/switch message */
#define OFPT_GET_ASYNC_REPLY          27 /* Controller/switch message */
#define OFPT_SET_ASYNC                28 /* Controller/switch message */
/* Meters and rate limiters configuration messages. */
#define OFPT_METER_MOD                29 /* Controller/switch message */

static const value_string openflow_type_values[] = {
/* Immutable messages. */
    { 0, "OFPT_HELLO" },              /* Symmetric message */
    { 1, "OFPT_ERROR" },              /* Symmetric message */
    { 2, "OFPT_ECHO_REQUEST" },       /* Symmetric message */
    { 3, "OFPT_ECHO_REPLY" },         /* Symmetric message */
    { 4, "OFPT_EXPERIMENTER" },       /* Symmetric message */
/* Switch configuration messages. */
    { 5, "OFPT_FEATURES_REQUEST" },   /* Controller/switch message */
    { 6, "OFPT_FEATURES_REPLY" },     /* Controller/switch message */
    { 7, "OFPT_GET_CONFIG_REQUEST" }, /* Controller/switch message */
    { 8, "OFPT_GET_CONFIG_REPLY" },   /* Controller/switch message */
    { 9, "OFPT_SET_CONFIG" },         /* Controller/switch message */
/* Asynchronous messages. */
    { 10, "OFPT_PACKET_IN" },                /* Async message */
    { 11, "OFPT_FLOW_REMOVED" },             /* Async message */
    { 12, "OFPT_PORT_STATUS" },              /* Async message */
/* Controller command messages. */
    { 13, "OFPT_PACKET_OUT" },               /* Controller/switch message */
    { 14, "OFPT_FLOW_MOD" },                 /* Controller/switch message */
    { 15, "OFPT_GROUP_MOD" },                /* Controller/switch message */
    { 16, "OFPT_PORT_MOD" },                 /* Controller/switch message */
    { 17, "OFPT_TABLE_MOD" },                /* Controller/switch message */
/* Multipart messages. */
    { 18, "OFPT_MULTIPART_REQUEST" },        /* Controller/switch message */
    { 19, "OFPT_MULTIPART_REPLY" },          /* Controller/switch message */
/* Barrier messages. */
    { 20, "OFPT_BARRIER_REQUEST" },          /* Controller/switch message */
    { 21, "OFPT_BARRIER_REPLY" },            /* Controller/switch message */
/* Queue Configuration messages. */
    { 22, "OFPT_QUEUE_GET_CONFIG_REQUEST" }, /* Controller/switch message */
    { 23, "OFPT_QUEUE_GET_CONFIG_REPLY" },   /* Controller/switch message */
/* Controller role change request messages. */
    { 24, "OFPT_ROLE_REQUEST" },             /* Controller/switch message */
    { 25, "OFPT_ROLE_REPLY" },               /* Controller/switch message */
/* Asynchronous message configuration. */
    { 26, "OFPT_GET_ASYNC_REQUEST" },        /* Controller/switch message */
    { 27, "OFPT_GET_ASYNC_REPLY" },          /* Controller/switch message */
    { 28, "OFPT_SET_ASYNC" },                /* Controller/switch message */
/* Meters and rate limiters configuration messages. */
    { 29, "OFPT_METER_MOD" },                /* Controller/switch message */
    { 0, NULL }
};

#define OFPC_FLOW_STATS   1<<0  /* Flow statistics. */
#define OFPC_TABLE_STATS  1<<1  /* Table statistics. */
#define OFPC_PORT_STATS   1<<2  /* Port statistics. */
#define OFPC_GROUP_STATS  1<<3  /* Group statistics. */
#define OFPC_IP_REASM     1<<5  /* Can reassemble IP fragments. */
#define OFPC_QUEUE_STATS  1<<6  /* Queue statistics. */
#define OFPC_PORT_BLOCKED 1<<8  /* Switch will block looping ports. */

#define OFPAT_OUTPUT_MASK       1<<0  /* Output to switch port. */
#define OFPAT_SET_VLAN_VID_MASK 1<<1  /* Set the 802.1q VLAN id. */
#define OFPAT_SET_VLAN_PCP_MASK 1<<2  /* Set the 802.1q priority. */
#define OFPAT_STRIP_VLAN_MASK   1<<3  /* Strip the 802.1q header. */
#define OFPAT_SET_DL_SRC_MASK   1<<4  /* Ethernet source address. */
#define OFPAT_SET_DL_DST_MASK   1<<5  /* Ethernet destination address. */
#define OFPAT_SET_NW_SRC_MASK   1<<6  /* IP source address. */
#define OFPAT_SET_NW_DST_MASK   1<<7  /* IP destination address. */
#define OFPAT_SET_NW_TOS_MASK   1<<8  /* IP ToS (DSCP field, 6 bits). */
#define OFPAT_SET_TP_SRC_MASK   1<<9  /* TCP/UDP source port. */
#define OFPAT_SET_TP_DST_MASK   1<<10 /* TCP/UDP destination port. */
#define OFPAT_ENQUEUE_MASK      1<<11 /* Output to queue. */

#define OFPPC_PORT_DOWN    1<<0 /* Port is administratively down. */
#define OFPPC_NO_STP       1<<1 /* Disable 802.1D spanning tree on port. */
#define OFPPC_NO_RECV      1<<2 /* Drop all packets except 802.1D spanning tree packets. */
#define OFPPC_NO_RECV_STP  1<<3 /* Drop received 802.1D STP packets. */
#define OFPPC_NO_FLOOD     1<<4 /* Do not include this port when flooding. */
#define OFPPC_NO_FWD       1<<5 /* Drop packets forwarded to port. */
#define OFPPC_NO_PACKET_IN 1<<6 /* Do not send packet-in msgs for port. */

#define OFP_MAX_PORT_NAME_LEN 16

#define OFPPS_LINK_DOWN    1<<0 /* No physical link present. */
#define OFPPS_STP_LISTEN   0<<8 /* Not learning or relaying frames. */
#define OFPPS_STP_LEARN    1<<8 /* Learning but not relaying frames. */
#define OFPPS_STP_FORWARD  2<<8 /* Learning and relaying frames. */
#define OFPPS_STP_BLOCK    3<<8 /* Not part of spanning tree. */
#define OFPPS_STP_MASK     3<<8 /* Bit mask for OFPPS_STP_* values. */


#define OFPPF_10MB_HD      1<<0 /* 10 Mb half-duplex rate support. */
#define OFPPF_10MB_FD      1<<1 /* 10 Mb full-duplex rate support. */
#define OFPPF_100MB_HD     1<<2 /* 100 Mb half-duplex rate support. */
#define OFPPF_100MB_FD     1<<3 /* 100 Mb full-duplex rate support. */
#define OFPPF_1GB_HD       1<<4 /* 1 Gb half-duplex rate support. */
#define OFPPF_1GB_FD       1<<5 /* 1 Gb full-duplex rate support. */
#define OFPPF_10GB_FD      1<<6 /* 10 Gb full-duplex rate support. */
#define OFPPF_COPPER       1<<7 /* Copper medium. */
#define OFPPF_FIBER        1<<8 /* Fiber medium. */
#define OFPPF_AUTONEG      1<<9 /* Auto-negotiation. */
#define OFPPF_PAUSE        1<<10 /* Pause. */
#define OFPPF_PAUSE_ASYM   1<<11 /* Asymmetric pause. */

static void
dissect_openflow_phy_port(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset)
{
    proto_item *ti;
    proto_tree *port_cnf_tree, *port_state_tree, *port_cf_tree;

    proto_tree_add_item(tree, hf_openflow_port_no, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset+=2;
    proto_tree_add_item(tree, hf_openflow_hw_addr, tvb, offset, 6, ENC_NA);
    offset+=6;
    proto_tree_add_item(tree, hf_openflow_port_name, tvb, offset, OFP_MAX_PORT_NAME_LEN, ENC_ASCII|ENC_NA);
    offset+=OFP_MAX_PORT_NAME_LEN;

    /* Bitmap of OFPPC_* flags. */
    ti = proto_tree_add_item(tree, hf_openflow_port_config, tvb, offset, 4, ENC_BIG_ENDIAN);
    port_cnf_tree = proto_item_add_subtree(ti, ett_openflow_port_cnf);

    /* Port is administratively down. */
    proto_tree_add_item(port_cnf_tree, hf_openflow_port_down, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Disable 802.1D spanning tree on port. */
    proto_tree_add_item(port_cnf_tree, hf_openflow_no_stp, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Drop all packets except 802.1D spanning tree packets. */
    proto_tree_add_item(port_cnf_tree, hf_openflow_no_recv, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Drop received 802.1D STP packets. */
    proto_tree_add_item(port_cnf_tree, hf_openflow_no_recv_stp, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Do not include this port when flooding. */
    proto_tree_add_item(port_cnf_tree, hf_openflow_no_flood, tvb, offset, 4, ENC_BIG_ENDIAN);
     /* Drop packets forwarded to port. */
    proto_tree_add_item(port_cnf_tree, hf_openflow_no_fwd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Do not send packet-in msgs for port. */
    proto_tree_add_item(port_cnf_tree, hf_openflow_no_packet_in, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;

    /* Bitmap of OFPPS_* flags. */
    ti = proto_tree_add_item(tree, hf_openflow_port_state, tvb, offset, 4, ENC_BIG_ENDIAN);
    port_state_tree = proto_item_add_subtree(ti, ett_openflow_port_state);

    /* No physical link present. */
    proto_tree_add_item(port_state_tree, hf_openflow_link_down, tvb, offset, 4, ENC_BIG_ENDIAN);

    offset+=4;

    /* Current features. */
    ti = proto_tree_add_item(tree, hf_openflow_port_curr, tvb, offset, 4, ENC_BIG_ENDIAN);
    port_cf_tree = proto_item_add_subtree(ti, ett_port_cf);
    /* 10 Mb half-duplex rate support. */
    proto_tree_add_item(port_cf_tree, hf_openflow_10mb_hd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* 10 Mb full-duplex rate support. */
    proto_tree_add_item(port_cf_tree, hf_openflow_10mb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* 100 Mb half-duplex rate support. */
    proto_tree_add_item(port_cf_tree, hf_openflow_100mb_hd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* 100 Mb full-duplex rate support. */
    proto_tree_add_item(port_cf_tree, hf_openflow_100mb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* 1 Gb half-duplex rate support. */
    proto_tree_add_item(port_cf_tree, hf_openflow_1gb_hd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* 1 Gb full-duplex rate support. */
    proto_tree_add_item(port_cf_tree, hf_openflow_1gb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* 10 Gb full-duplex rate support. */
    proto_tree_add_item(port_cf_tree, hf_openflow_10gb_fd, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Copper medium. */
    proto_tree_add_item(port_cf_tree, hf_openflow_copper, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Fiber medium. */
    proto_tree_add_item(port_cf_tree, hf_openflow_fiber, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Auto-negotiation. */
    proto_tree_add_item(port_cf_tree, hf_openflow_autoneg, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Pause. */
    proto_tree_add_item(port_cf_tree, hf_openflow_pause, tvb, offset, 4, ENC_BIG_ENDIAN);
    /* Asymmetric pause. */
    proto_tree_add_item(port_cf_tree, hf_openflow_pause_asym, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;

    /* Features being advertised by the port. */
    proto_tree_add_item(tree, hf_openflow_port_advertised, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;

    /* Features supported by the port. */
    proto_tree_add_item(tree, hf_openflow_port_supported, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;
    /* Features advertised by peer. */
    proto_tree_add_item(tree, hf_openflow_port_peer, tvb, offset, 4, ENC_BIG_ENDIAN);


}
/* 
 * Switch features. 
 *
   struct ofp_switch_features {
   struct ofp_header header;
   uint64_t datapath_id; * Datapath unique ID. The lower 48-bits are for
                           a MAC address, while the upper 16-bits are
                           implementer-defined. *
   uint32_t n_buffers;   * Max packets buffered at once. *
   uint8_t n_tables;     * Number of tables supported by datapath. *
   uint8_t pad[3];       * Align to 64-bits. *
* Features. *
   uint32_t capabilities;  * Bitmap of support "ofp_capabilities".   *
   uptill 1.1
       uint32_t actions;       * Bitmap of supported "ofp_action_type"s. *
   from 1.2
       uint32_t reserved;
* Port info.*
  struct ofp_phy_port ports[0]; * Port definitions. The number of ports
                                  is inferred from the length field in
                                  the header.
  };
*/
static void
dissect_openflow_features_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint8 version, guint16 length)
{
    proto_item *ti;
    proto_tree *path_id_tree, *cap_tree, *act_tree;

    guint16 length_remaining;
    
    ti = proto_tree_add_item(tree, hf_openflow_datapath_id, tvb, offset, 8, ENC_BIG_ENDIAN);
    path_id_tree = proto_item_add_subtree(ti, ett_openflow_path_id);
    proto_tree_add_item(path_id_tree, hf_openflow_datapath_mac, tvb, offset, 6, ENC_NA);
    offset+=6;
    proto_tree_add_item(path_id_tree, hf_openflow_datapath_impl, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset+=2;

    proto_tree_add_item(tree, hf_openflow_n_buffers, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;

    proto_tree_add_item(tree, hf_openflow_n_tables, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset++;

    if(version<3){
        proto_tree_add_item(tree, hf_openflow_pad3, tvb, offset, 3, ENC_BIG_ENDIAN);
        offset+=3;
    }else{
    }

    ti = proto_tree_add_item(tree, hf_openflow_capabilities, tvb, offset, 4, ENC_BIG_ENDIAN);
    cap_tree = proto_item_add_subtree(ti, ett_openflow_cap);

    /* Dissect flags */
    proto_tree_add_item(cap_tree, hf_openflow_cap_flow_stats, tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(cap_tree, hf_openflow_table_stats,    tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(cap_tree, hf_openflow_port_stats,     tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(cap_tree, hf_openflow_group_stats,    tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(cap_tree, hf_openflow_ip_reasm,       tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(cap_tree, hf_openflow_queue_stats,    tvb, offset, 4, ENC_BIG_ENDIAN);
    proto_tree_add_item(cap_tree, hf_openflow_port_blocked,   tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;

    if(version<2){
        ti = proto_tree_add_item(tree, hf_openflow_actions, tvb, offset, 4, ENC_BIG_ENDIAN);
        act_tree = proto_item_add_subtree(ti, ett_openflow_act);
        /* Dissect flags */
        proto_tree_add_item(act_tree, hf_openflow_output, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_vlan_vid, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_vlan_pcp, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_strip_vlan, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_dl_src, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_dl_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_nw_src, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_nw_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_nw_tos, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_tp_src, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_set_tp_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
        proto_tree_add_item(act_tree, hf_openflow_enqueue, tvb, offset, 4, ENC_BIG_ENDIAN);
    }else{
        proto_tree_add_item(tree, hf_openflow_reserved32, tvb, offset, 4, ENC_BIG_ENDIAN);
    }
    offset+=4;
    
    length_remaining = length-32;
    if(length_remaining > 0){
        guint16 num_ports = length_remaining/48;
        int i;
        if ((length_remaining&0x003f) != 0){
            /* protocol_error */
        }
        for(i=0; i<num_ports ;i++){
            proto_tree *port_tree;

            ti = proto_tree_add_text(tree, tvb, offset, 48, "Port data %u",i+1);
            port_tree = proto_item_add_subtree(ti, ett_openflow_port);
            dissect_openflow_phy_port(tvb, pinfo, port_tree, offset);
            offset+=48;
        }
    }

}

static void
dissect_openflow_switch_config(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, guint8 version _U_, guint16 length _U_)
{

    proto_tree_add_item(tree, hf_openflow_config_flags, tvb, offset, 2, ENC_BIG_ENDIAN);
    /* ofp_config_flags */
    offset+=2;
    /* miss_send_len */
    proto_tree_add_item(tree, hf_openflow_miss_send_len, tvb, offset, 2, ENC_BIG_ENDIAN);
    /*offset+=2;*/

}
/* Code to actually dissect the packets */
static int
dissect_openflow(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
    proto_item *ti;
    proto_tree *openflow_tree;
    guint offset = 0;
    guint8 type, version;
    guint16 length;


    version = tvb_get_guint8(tvb, 0);
    type    = tvb_get_guint8(tvb, 1);
    /* Set the Protocol column to the constant string of openflow */
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "OpenFlow");
    col_clear(pinfo->cinfo,COL_INFO);

    if((version&0x80)==0x80){
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "OpenFlow experimental version");
        proto_tree_add_text(tree, tvb, offset, -1, "Experimental versions not dissected");
    }else{
        version = version & 0x7f;
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "OpenFlow");
        col_append_fstr(pinfo->cinfo, COL_INFO, "Type: %s",
                  val_to_str_const(type, openflow_type_values, "Unknown Messagetype"));
    }

    /* Create display subtree for the protocol */
    ti = proto_tree_add_item(tree, proto_openflow, tvb, 0, -1, ENC_NA);
    openflow_tree = proto_item_add_subtree(ti, ett_openflow);

    /* A.1 OpenFlow Header. */
    /* OFP_VERSION. */
    proto_tree_add_item(openflow_tree, hf_openflow_version, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset++;

    /* One of the OFPT_ constants. */
    proto_tree_add_item(openflow_tree, hf_openflow_type, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset++;

    /* Length including this ofp_header. */
    length = tvb_get_ntohs(tvb, offset);
    proto_tree_add_item(openflow_tree, hf_openflow_length, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset+=2;

    /* Transaction id associated with this packet. Replies use the same id as was in the request
     * to facilitate pairing. 
     */
    proto_tree_add_item(openflow_tree, hf_openflow_xid, tvb, offset, 4, ENC_BIG_ENDIAN);
    offset+=4;

    switch(type){
    case OFPT_HELLO: /* 0 */
        /* 5.5.1 Hello
         * The OFPT_HELLO message has no body;
         */
        break;
    case OFPT_FEATURES_REQUEST: /* 5 */
        /* 5.3.1 Handshake
         * Upon TLS session establishment, the controller sends an OFPT_FEATURES_REQUEST
         * message. This message does not contain a body beyond the OpenFlow header.
         */
        break;
    case OFPT_FEATURES_REPLY: /* 6 */
        dissect_openflow_features_reply(tvb, pinfo, openflow_tree, offset, version, length);
        break;
    case OFPT_GET_CONFIG_REQUEST: /* 7 */
        /* A.3.2 There is no body for OFPT_GET_CONFIG_REQUEST beyond the OpenFlow header. */
        break;
    case OFPT_GET_CONFIG_REPLY: /* 8 */
        /* Fall trough */
    case OFPT_SET_CONFIG: /* 9 */
        dissect_openflow_switch_config(tvb, pinfo, openflow_tree, offset, version, length);
        break;
    default:
        if(length>8){
            proto_tree_add_text(tree, tvb, offset, -1, "Message data not dissected yet");
        }
        break;
    }

    return tvb_length(tvb);
}

/* Register the protocol with Wireshark.
 *
 * This format is require because a script is used to build the C function that
 * calls all the protocol registration.
 */
void
proto_register_openflow(void)
{
    module_t *openflow_module;

    static hf_register_info hf[] = {
        { &hf_openflow_version,
            { "Version", "openflow.version",
               FT_UINT8, BASE_HEX, VALS(openflow_version_values), 0x7f,
               NULL, HFILL }
        },
        { &hf_openflow_type,
            { "Type", "openflow.type",
               FT_UINT8, BASE_DEC, VALS(openflow_type_values), 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_xid,
            { "Transaction ID", "openflow.xid",
               FT_UINT32, BASE_DEC, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_length,
            { "Length", "openflow.length",
               FT_UINT16, BASE_DEC, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_datapath_id,
            { "Datapath unique ID", "openflow.datapath_id",
               FT_UINT64, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_datapath_mac,
            { "MAC addr", "openflow.datapath_mac",
               FT_ETHER, BASE_NONE, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_datapath_impl,
            { "Implementers part", "openflow.datapath_imp",
               FT_UINT16, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_n_buffers,
            { "n_buffers", "openflow.n_buffers",
               FT_UINT32, BASE_DEC, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_n_tables,
            { "n_tables", "openflow.n_tables",
               FT_UINT8, BASE_DEC, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_pad3,
            { "Padding", "openflow.pad3",
               FT_UINT24, BASE_DEC, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_capabilities,
            { "capabilities", "openflow.capabilities",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_actions,
            { "actions", "openflow.actions",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_reserved32,
            { "Reserved", "openflow.reserved32",
               FT_UINT32, BASE_DEC, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_cap_flow_stats,
            { "Flow statistics", "openflow.flow_stats",
               FT_BOOLEAN, 32, NULL, OFPC_FLOW_STATS,
               NULL, HFILL }
        },
        { &hf_openflow_table_stats,
            { "Table statistics", "openflow.table_stats",
               FT_BOOLEAN, 32, NULL, OFPC_TABLE_STATS,
               NULL, HFILL }
        },
        { &hf_openflow_port_stats,
            { "Port statistics", "openflow.port_stats",
               FT_BOOLEAN, 32, NULL,  OFPC_PORT_STATS,
               NULL, HFILL }
        },
        { &hf_openflow_group_stats,
            { "Group statistics", "openflow.group_stats",
               FT_BOOLEAN, 32, NULL, OFPC_GROUP_STATS,
               NULL, HFILL }
        },
        { &hf_openflow_ip_reasm,
            { "Can reassemble IP fragments", "openflow.ip_reasm",
               FT_BOOLEAN, 32, NULL, OFPC_IP_REASM,
               NULL, HFILL }
        },
        { &hf_openflow_queue_stats,
            { "Queue statistics", "openflow.queue_stats",
               FT_BOOLEAN, 32, NULL, OFPC_QUEUE_STATS,
               NULL, HFILL }
        },
        { &hf_openflow_port_blocked,
            { "Switch will block looping ports", "openflow.port_blocked",
               FT_BOOLEAN, 32, NULL, OFPC_PORT_BLOCKED,
               NULL, HFILL }
        },
        { &hf_openflow_output,
            { "Output to switch port", "openflow.output",
               FT_BOOLEAN, 32, NULL, OFPAT_OUTPUT_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_vlan_vid,
            { "Set the 802.1q VLAN id", "openflow.set_vlan_vid",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_VLAN_VID_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_vlan_pcp,
            { "Set the 802.1q priority", "openflow.set_vlan_pcp",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_VLAN_PCP_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_strip_vlan,
            { "Strip the 802.1q header", "openflow.strip_vlan",
               FT_BOOLEAN, 32, NULL, OFPAT_STRIP_VLAN_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_dl_src,
            { "Ethernet source address", "openflow.set_dl_src",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_DL_SRC_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_dl_dst,
            { "Ethernet destination address", "openflow.set_dl_ds",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_DL_DST_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_nw_src,
            { "IP source address", "openflow.set_nw_src",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_NW_SRC_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_nw_dst,
            { "IP destination address", "openflow.set_nw_ds",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_NW_DST_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_nw_tos,
            { "IP ToS (DSCP field, 6 bits)", "openflow.set_nw_tos",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_NW_TOS_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_tp_src,
            { "TCP/UDP source port", "openflow.set_tp_src",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_TP_SRC_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_set_tp_dst,
            { "TCP/UDP destination port", "openflow.set_tp_dst",
               FT_BOOLEAN, 32, NULL, OFPAT_SET_TP_DST_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_enqueue,
            { "Output to queue", "openflow.enqueue",
               FT_BOOLEAN, 32, NULL, OFPAT_ENQUEUE_MASK,
               NULL, HFILL }
        },
        { &hf_openflow_port_no,
            { "Port number", "openflow.port_no",
               FT_UINT16, BASE_DEC, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_hw_addr,
            { "HW Address", "openflow.hw_add",
               FT_ETHER, BASE_NONE, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_name,
            { "Name", "openflow.hw_add",
               FT_STRING, BASE_NONE, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_config,
            { "Config flags", "openflow.port_config",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_state,
            { "State flags", "openflow.port_state",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_curr,
            { "Current features", "openflow.port_curr",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_advertised,
            { "Advertised features", "openflow.port_advertised",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_supported,
            { "Features supported", "openflow.port_supported",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_peer,
            { "Features advertised by peer", "openflow.port_peer",
               FT_UINT32, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_port_down,
            { "Port is administratively down", "openflow.port_down",
               FT_BOOLEAN, 32, NULL, OFPPC_PORT_DOWN,
               NULL, HFILL }
        },
        { &hf_openflow_no_stp,
            { "Disable 802.1D spanning tree on port", "openflow.no_stp",
               FT_BOOLEAN, 32, NULL, OFPPC_NO_STP,
               NULL, HFILL }
        },
        { &hf_openflow_no_recv,
            { "Drop all packets except 802.1D spanning tree packets", "openflow.no_recv",
               FT_BOOLEAN, 32, NULL, OFPPC_NO_RECV,
               NULL, HFILL }
        },
        { &hf_openflow_no_recv_stp,
            { "Drop received 802.1D STP packets", "openflow.no_recv",
               FT_BOOLEAN, 32, NULL, OFPPC_NO_RECV_STP,
               NULL, HFILL }
        },
        { &hf_openflow_no_flood,
            { "Do not include this port when flooding", "openflow.no_flood",
               FT_BOOLEAN, 32, NULL, OFPPC_NO_FLOOD,
               NULL, HFILL }
        },
        { &hf_openflow_no_fwd,
            { "Drop packets forwarded to port", "openflow.no_fwd",
               FT_BOOLEAN, 32, NULL, OFPPC_NO_FWD,
               NULL, HFILL }
        },
        { &hf_openflow_no_packet_in,
            { "Do not send packet-in msgs for port", "openflow.no_packet_in",
               FT_BOOLEAN, 32, NULL, OFPPC_NO_PACKET_IN,
               NULL, HFILL }
        },
        { &hf_openflow_link_down,
            { "No physical link present", "openflow.link_down",
               FT_BOOLEAN, 32, NULL, OFPPS_LINK_DOWN,
               NULL, HFILL }
        },
        { &hf_openflow_10mb_hd,
            { "10 Mb half-duplex rate support", "openflow.10mb_hd",
               FT_BOOLEAN, 32, NULL, OFPPF_10MB_HD,
               NULL, HFILL }
        },
        { &hf_openflow_10mb_fd,
            { "10 Mb full-duplex rate support", "openflow.10mb_fd",
               FT_BOOLEAN, 32, NULL, OFPPF_10MB_FD,
               NULL, HFILL }
        },
        { &hf_openflow_100mb_hd,
            { "100 Mb half-duplex rate support", "openflow.100mb_hd",
               FT_BOOLEAN, 32, NULL, OFPPF_100MB_HD,
               NULL, HFILL }
        },
        { &hf_openflow_100mb_fd,
            { "100 Mb full-duplex rate support", "openflow.100mb_0fd",
               FT_BOOLEAN, 32, NULL, OFPPF_100MB_FD,
               NULL, HFILL }
        },
        { &hf_openflow_1gb_hd,
            { "1 Gb half-duplex rate support", "openflow.1gb_hd",
               FT_BOOLEAN, 32, NULL, OFPPF_1GB_HD,
               NULL, HFILL }
        },
        { &hf_openflow_1gb_fd,
            { "1 Gb full-duplex rate support", "openflow.1gb_fd",
               FT_BOOLEAN, 32, NULL, OFPPF_1GB_FD,
               NULL, HFILL }
        },
        { &hf_openflow_10gb_fd,
            { "10 Gb full-duplex rate support", "openflow.10gb_fd",
               FT_BOOLEAN, 32, NULL, OFPPF_10GB_FD,
               NULL, HFILL }
        },
        { &hf_openflow_copper,
            { "Copper medium", "openflow.copper",
               FT_BOOLEAN, 32, NULL, OFPPF_COPPER,
               NULL, HFILL }
        },
        { &hf_openflow_fiber,
            { "Fiber medium", "openflow.fiber",
               FT_BOOLEAN, 32, NULL, OFPPF_FIBER,
               NULL, HFILL }
        },
        { &hf_openflow_autoneg,
            { "Auto-negotiation", "openflow.autoneg",
               FT_BOOLEAN, 32, NULL, OFPPF_AUTONEG,
               NULL, HFILL }
        },
        { &hf_openflow_pause,
            { "Pause", "openflow.pause",
               FT_BOOLEAN, 32, NULL, OFPPF_PAUSE,
               NULL, HFILL }
        },
        { &hf_openflow_pause_asym,
            { "Asymmetric pause", "openflow.pause_asym",
               FT_BOOLEAN, 32, NULL, OFPPF_PAUSE_ASYM,
               NULL, HFILL }
        },
        { &hf_openflow_config_flags,
            { "Config flags", "openflow.config_flags",
               FT_UINT16, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
        { &hf_openflow_miss_send_len,
            { "Max bytes of packet", "openflow.miss_send_len",
               FT_UINT16, BASE_HEX, NULL, 0x0,
               NULL, HFILL }
        },
    };

    static gint *ett[] = {
        &ett_openflow,
        &ett_openflow_path_id,
        &ett_openflow_cap,
        &ett_openflow_act,
        &ett_openflow_port,
        &ett_openflow_port_cnf,
        &ett_openflow_port_state,
        &ett_port_cf
    };

    /* Register the protocol name and description */
    proto_openflow = proto_register_protocol("OpenFlow",
            "openflow", "openflow");

    /* Required function calls to register the header fields and subtrees */
    proto_register_field_array(proto_openflow, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    openflow_module = prefs_register_protocol(proto_openflow, proto_reg_handoff_openflow);

    /* Register port preference */
    prefs_register_uint_preference(openflow_module, "tcp.port", "openflow TCP Port",
            " openflow TCP port if other than the default",
            10, &g_openflow_port);
}

void
proto_reg_handoff_openflow(void)
{
    static gboolean initialized = FALSE;
    static dissector_handle_t openflow_handle;
    static int currentPort;

    if (!initialized) {
        openflow_handle = new_create_dissector_handle(dissect_openflow, proto_openflow);
        initialized = TRUE;

    } else {
        dissector_delete_uint("tcp.port", currentPort, openflow_handle);
    }

    currentPort = g_openflow_port;

    dissector_add_uint("tcp.port", currentPort, openflow_handle);
}


/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */