aboutsummaryrefslogtreecommitdiffstats
path: root/tools/dissectors/epan/rfnoc/packet-rfnoc.cpp
blob: a5076c63df66ebfa564aa6b8a4b41c71e01f7e78 (plain) (blame)
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
/*
 * Dissector for UHD RFNoC (CHDR) packets
 *
 * Copyright 2019 Ettus Research, a National Instruments brand
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

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

#ifdef __cplusplus
}
#endif

#include <cstdio>
#include <iostream>

#include "../../../../host/lib/usrp/x300/x300_fw_common.h"
#include <uhdlib/rfnoc/chdr_packet_writer.hpp>

constexpr unsigned int RFNOC_PORT = X300_VITA_UDP_PORT;
static const uhd::rfnoc::chdr::chdr_packet_factory pkt_factory(uhd::rfnoc::CHDR_W_64, uhd::ENDIANNESS_LITTLE);

static int proto_rfnoc = -1;
static int hf_rfnoc_hdr = -1;
static int hf_rfnoc_hdr_vc = -1;
static int hf_rfnoc_hdr_eob = -1;
static int hf_rfnoc_hdr_eov = -1;
static int hf_rfnoc_hdr_pkttype = -1;
static int hf_rfnoc_hdr_num_mdata = -1;
static int hf_rfnoc_hdr_seqnum = -1;
static int hf_rfnoc_hdr_len = -1;
static int hf_rfnoc_hdr_dst_epid = -1;
static int hf_rfnoc_timestamp = -1;
static int hf_rfnoc_src_epid = -1;
static int hf_rfnoc_ctrl = -1;
static int hf_rfnoc_ctrl_dst_port = -1;
static int hf_rfnoc_ctrl_src_port = -1;
static int hf_rfnoc_ctrl_num_data = -1;
static int hf_rfnoc_ctrl_seqnum = -1;
static int hf_rfnoc_ctrl_is_ack = -1;
static int hf_rfnoc_ctrl_address = -1;
static int hf_rfnoc_ctrl_data0 = -1;
static int hf_rfnoc_ctrl_data = -1; // TODO: Figure out what to do here
static int hf_rfnoc_ctrl_byte_enable = -1;
static int hf_rfnoc_ctrl_opcode = -1;
static int hf_rfnoc_ctrl_status = -1;
static int hf_rfnoc_strs = -1;
static int hf_rfnoc_strs_status = -1;
static int hf_rfnoc_strs_capacity_bytes = -1;
static int hf_rfnoc_strs_capacity_pkts = -1;
static int hf_rfnoc_strs_xfer_bytes = -1;
static int hf_rfnoc_strs_xfer_pkts = -1;
static int hf_rfnoc_strs_buff_info = -1;
static int hf_rfnoc_strs_ext_status = -1;
static int hf_rfnoc_strc = -1;
static int hf_rfnoc_strc_opcode = -1;
static int hf_rfnoc_strc_data = -1;
static int hf_rfnoc_strc_num_pkts = -1;
static int hf_rfnoc_strc_num_bytes = -1;
static int hf_rfnoc_mgmt = -1;
static int hf_rfnoc_mgmt_protover = -1;
static int hf_rfnoc_mgmt_chdr_w = -1;
static int hf_rfnoc_mgmt_num_hops = -1;
static int hf_rfnoc_mgmt_hop = -1;
static int hf_rfnoc_mgmt_op = -1;
static int hf_rfnoc_mgmt_op_code = -1;
static int hf_rfnoc_mgmt_op_dest = -1;
static int hf_rfnoc_mgmt_op_device_id = -1;
static int hf_rfnoc_mgmt_op_node_type = -1;
static int hf_rfnoc_mgmt_op_node_inst = -1;
static int hf_rfnoc_mgmt_op_cfg_address = -1;
static int hf_rfnoc_mgmt_op_cfg_data = -1;

static const value_string RFNOC_PACKET_TYPES[] = {
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_MGMT, "Management" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_STRS, "Stream Status" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_STRC, "Stream Command" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_CTRL, "Control" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_DATA_NO_TS, "Data" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_DATA_WITH_TS, "Data with Timestamp" },
};

static const value_string RFNOC_PACKET_TYPES_SHORT[] = {
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_MGMT, "mgmt" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_STRS, "strs" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_STRC, "strc" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_CTRL, "ctrl" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_DATA_NO_TS, "data" },
    { uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_DATA_WITH_TS, "data" },
};

static const value_string RFNOC_CTRL_STATUS[] = {
    { uhd::rfnoc::chdr::ctrl_status_t::CMD_OKAY, "OK" },
    { uhd::rfnoc::chdr::ctrl_status_t::CMD_CMDERR, "CMDERR" },
    { uhd::rfnoc::chdr::ctrl_status_t::CMD_TSERR, "TSERR" },
    { uhd::rfnoc::chdr::ctrl_status_t::CMD_WARNING, "WARNING" },
};

static const value_string RFNOC_CTRL_OPCODES[] = {
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_SLEEP, "sleep" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_WRITE, "write" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_READ, "read" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_READ_WRITE, "r/w" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_BLOCK_WRITE, "block write" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_BLOCK_READ, "block read" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_POLL, "poll" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_USER1, "user1" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_USER2, "user2" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_USER3, "user3" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_USER4, "user4" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_USER5, "user5" },
    { uhd::rfnoc::chdr::ctrl_opcode_t::OP_USER6, "user6" },
};

static const value_string RFNOC_STRS_STATUS[] = {
    { uhd::rfnoc::chdr::strs_status_t::STRS_OKAY, "OK" },
    { uhd::rfnoc::chdr::strs_status_t::STRS_CMDERR, "CMDERR" },
    { uhd::rfnoc::chdr::strs_status_t::STRS_SEQERR, "SEQERR" },
    { uhd::rfnoc::chdr::strs_status_t::STRS_DATAERR, "DATAERR" },
    { uhd::rfnoc::chdr::strs_status_t::STRS_RTERR, "RTERR" },
};

static const value_string RFNOC_STRC_OPCODES[] = {
    { uhd::rfnoc::chdr::strc_op_code_t::STRC_INIT, "init" },
    { uhd::rfnoc::chdr::strc_op_code_t::STRC_PING, "ping" },
    { uhd::rfnoc::chdr::strc_op_code_t::STRC_RESYNC, "resync" },
};

static const value_string RFNOC_MGMT_OPCODES[] = {
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_NOP, "nop" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_ADVERTISE, "advertise" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_SEL_DEST, "select_dest" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_RETURN, "return_to_sender" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_INFO_REQ, "node_info_req" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_INFO_RESP, "node_info_resp" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_CFG_WR_REQ, "cfg_wr_req" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_CFG_RD_REQ, "cfg_rd_req" },
    { uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_CFG_RD_RESP, "cfg_rd_resp" },
};

/* the heuristic dissector is called on every packet with payload.
 * The warning printed for this should only be printed once.
 */
static int heur_warning_printed = 0;

/* Subtree handles: set by register_subtree_array */
static gint ett_rfnoc = -1;
static gint ett_rfnoc_hdr = -1;
static gint ett_rfnoc_ctrl = -1;
static gint ett_rfnoc_strs = -1;
static gint ett_rfnoc_strc = -1;
static gint ett_rfnoc_mgmt = -1;
static gint ett_rfnoc_mgmt_hop = -1;
static gint ett_rfnoc_mgmt_hop_op = -1;

/* Forward-declare the dissector functions */
static int dissect_rfnoc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);

/* The dissector itself */
static int dissect_rfnoc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
    // Here are all the variables
    proto_item *item;
    proto_tree *rfnoc_tree;
    proto_item *header_item;
    proto_tree *header_tree;
    proto_item *ctrl_item;
    proto_tree *ctrl_tree;
    proto_item *strs_item;
    proto_tree *strs_tree;
    proto_item *strc_item;
    proto_tree *strc_tree;
    proto_item *mgmt_item;
    proto_tree *mgmt_tree;
    proto_item *hop_item;
    proto_tree *hop_tree;
    proto_item *mgmt_op_item;
    proto_tree *mgmt_op_tree;
    gint len;

    guint64 hdr;
    gint flag_offset;
    guint8 *bytes;
    guint8 hdr_bits = 0;
    gboolean is_eob = 0;
    gboolean is_eov = 0;
    uint64_t timestamp;
    int chdr_len = 0;
    gboolean is_network;
    gint endianness;
    size_t offset = 0;
    /* FIXME: Assuming CHDR_W_64 */
    size_t chdr_w_bytes = 8;

    if (pinfo->match_uint == RFNOC_PORT) {
        is_network = TRUE;
        flag_offset = 0;
        endianness = ENC_LITTLE_ENDIAN;
    }

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "RFNoC");
    /* Clear out stuff in info column */
    col_clear(pinfo->cinfo, COL_INFO);

    len = tvb_reported_length(tvb);

    if (tree) {
        guint64 hdr = tvb_get_letoh64(tvb, 0);
        uhd::rfnoc::chdr::chdr_header chdr_hdr(hdr);
        chdr_len = chdr_hdr.get_length();
        len = (len < chdr_len) ? len : chdr_len;

        /* Start with a top-level item to add everything else to */
        item = proto_tree_add_item(tree, proto_rfnoc, tvb, offset, len, ENC_NA);

        if (len >= 4) {
            rfnoc_tree = proto_item_add_subtree(item, ett_rfnoc);
            proto_item_append_text(item, ", Packet type: %s, Dst EPID: %d",
                val_to_str(chdr_hdr.get_pkt_type(), RFNOC_PACKET_TYPES, "Unknown (0x%x)"), chdr_hdr.get_dst_epid()
            );
            col_add_fstr(pinfo->cinfo, COL_INFO, "%s dst_epid=%d",
                val_to_str(chdr_hdr.get_pkt_type(), RFNOC_PACKET_TYPES_SHORT, "Unknown (0x%x)"), chdr_hdr.get_dst_epid()
            );

            /* Header info. First, a top-level header tree item: */
            header_item = proto_tree_add_item(rfnoc_tree, hf_rfnoc_hdr, tvb, offset, 8, endianness);
            header_tree = proto_item_add_subtree(header_item, ett_rfnoc_hdr);
            /* Let us query hdr.type */
            proto_tree_add_string(
                header_tree, hf_rfnoc_hdr_pkttype, tvb, offset+6, 1,
                val_to_str(chdr_hdr.get_pkt_type(), RFNOC_PACKET_TYPES_SHORT, "invalid")
            );

            /* Add Dst EPID */
            proto_item_append_text(header_item, ", Dst EPID: %02x", chdr_hdr.get_dst_epid());
            proto_tree_add_uint(header_tree, hf_rfnoc_hdr_dst_epid, tvb, offset, 2, chdr_hdr.get_dst_epid());
            /* Add length */
            proto_tree_add_uint(header_tree, hf_rfnoc_hdr_len, tvb, offset+2, 2, chdr_hdr.get_length());
            /* Add sequence number */
            proto_tree_add_uint(header_tree, hf_rfnoc_hdr_seqnum, tvb, offset+4, 2, chdr_hdr.get_seq_num());

            if (chdr_hdr.get_num_mdata()) {
                /* Can't decode packets with metadata */
                return len;
            }

            /* TODO: Update offsets if there is a timestamp. Also update lengths */
            /* Add subtree based on packet type */
            uhd::rfnoc::chdr::packet_type_t pkttype = chdr_hdr.get_pkt_type();
            offset += 8;
            if (pkttype == uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_CTRL) {
                ctrl_item = proto_tree_add_item(rfnoc_tree, hf_rfnoc_ctrl, tvb, 8, chdr_len-8, endianness);
                ctrl_tree = proto_item_add_subtree(ctrl_item, ett_rfnoc_ctrl);
                auto pkt = pkt_factory.make_ctrl();
                pkt->refresh(tvb_get_ptr(tvb, 0, chdr_len));
                auto payload = pkt->get_payload();

                /* Add source EPID */
                proto_tree_add_uint(ctrl_tree, hf_rfnoc_src_epid, tvb, offset+4, 2, payload.src_epid);
                /* Add source port */
                proto_tree_add_uint(ctrl_tree, hf_rfnoc_ctrl_src_port, tvb, offset+1, 2, payload.src_port);
                /* Add dest port */
                proto_tree_add_uint(ctrl_tree, hf_rfnoc_ctrl_dst_port, tvb, offset, 2, payload.dst_port);
                /* Add num data */
                proto_tree_add_uint(ctrl_tree, hf_rfnoc_ctrl_num_data, tvb, offset+2, 1, payload.data_vtr.size());
                /* Add is_ack */
                proto_tree_add_boolean(ctrl_tree, hf_rfnoc_ctrl_is_ack, tvb, offset+3, 1, payload.is_ack);
                /* Add sequence number */
                proto_tree_add_uint(ctrl_tree, hf_rfnoc_ctrl_seqnum, tvb, offset+3, 1, payload.seq_num);
                if (payload.timestamp) {
                    proto_tree_add_uint64(ctrl_tree, hf_rfnoc_timestamp, tvb, offset+8, 8, *payload.timestamp);
                    offset += 8;
                }
                /* Add data0 */
                proto_tree_add_uint(ctrl_tree, hf_rfnoc_ctrl_data0, tvb, offset+12, 4, payload.data_vtr[0]);
                /* Add op code */
                proto_tree_add_string(
                    ctrl_tree, hf_rfnoc_ctrl_opcode, tvb, offset+11, 1,
                    val_to_str(payload.op_code, RFNOC_CTRL_OPCODES, "reserved")
                );
                /* Add address */
                proto_tree_add_uint(ctrl_tree, hf_rfnoc_ctrl_address, tvb, offset+8, 3, payload.address);
                /* Add status */
                proto_tree_add_string(
                    ctrl_tree, hf_rfnoc_ctrl_status, tvb, offset+11, 1,
                    val_to_str(payload.status, RFNOC_CTRL_STATUS, "reserved")
                );
            }

            if (pkttype == uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_STRS) {
                strs_item = proto_tree_add_item(rfnoc_tree, hf_rfnoc_strs, tvb, offset, chdr_len-8, endianness);
                strs_tree = proto_item_add_subtree(strs_item, ett_rfnoc_strs);
                auto pkt = pkt_factory.make_strs();
                pkt->refresh(tvb_get_ptr(tvb, 0, chdr_len));
                auto payload = pkt->get_payload();

                proto_tree_add_string(
                    strs_tree, hf_rfnoc_strs_status, tvb, offset+5, 1,
                    val_to_str(payload.status, RFNOC_STRS_STATUS, "invalid")
                );

                /* Add source EPID */
                proto_tree_add_uint(strs_tree, hf_rfnoc_src_epid, tvb, offset, 2, payload.src_epid);
                /* Add capacities */
                proto_tree_add_uint64(strs_tree, hf_rfnoc_strs_capacity_bytes, tvb, offset+3, 5, payload.capacity_bytes);
                proto_tree_add_uint(strs_tree, hf_rfnoc_strs_capacity_pkts, tvb, offset+8, 3, payload.capacity_pkts);
                /* Add xfer amounts */
                proto_tree_add_uint64(strs_tree, hf_rfnoc_strs_xfer_bytes, tvb, offset+16, 8, payload.xfer_count_bytes);
                proto_tree_add_uint64(strs_tree, hf_rfnoc_strs_xfer_pkts, tvb, offset+11, 5, payload.xfer_count_pkts);
            }

            if (pkttype == uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_STRC) {
                strc_item = proto_tree_add_item(rfnoc_tree, hf_rfnoc_strc, tvb, 8, chdr_len-8, endianness);
                strc_tree = proto_item_add_subtree(strc_item, ett_rfnoc_strc);
                auto pkt = pkt_factory.make_strc();
                pkt->refresh(tvb_get_ptr(tvb, 0, chdr_len));
                auto payload = pkt->get_payload();

                proto_tree_add_string(
                    strc_tree, hf_rfnoc_strc_opcode, tvb, offset+2, 1,
                    val_to_str(payload.op_code, RFNOC_STRC_OPCODES, "invalid")
                );

                /* Add source EPID */
                proto_tree_add_uint(strc_tree, hf_rfnoc_src_epid, tvb, offset, 2, payload.src_epid);
                /* Add transfer amounts */
                proto_tree_add_uint64(strc_tree, hf_rfnoc_strc_num_bytes, tvb, offset+8, 8, payload.num_bytes);
                proto_tree_add_uint64(strc_tree, hf_rfnoc_strc_num_pkts, tvb, offset+3, 5, payload.num_pkts);
            }

            if (pkttype == uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_MGMT) {
                mgmt_item = proto_tree_add_item(rfnoc_tree, hf_rfnoc_mgmt, tvb, offset, len-8, endianness);
                mgmt_tree = proto_item_add_subtree(mgmt_item, ett_rfnoc_mgmt);
                auto pkt = pkt_factory.make_mgmt();
                pkt->refresh(tvb_get_ptr(tvb, 0, chdr_len));
                auto payload = pkt->get_payload();
                /* Add source EPID */
                proto_tree_add_uint(mgmt_tree, hf_rfnoc_src_epid, tvb, offset, 2, payload.get_src_epid());
                size_t num_hops = payload.get_num_hops();
                offset += 8;

                /* FIXME: Assuming CHDR_W_64 here */
                for (size_t hop_id = 0; hop_id < num_hops; hop_id++) {
                    auto hop = payload.get_hop(hop_id);
                    size_t num_ops = hop.get_num_ops();
                    hop_item = proto_tree_add_item(mgmt_tree, hf_rfnoc_mgmt_hop, tvb, offset, num_ops*chdr_w_bytes, endianness);
                    hop_tree = proto_item_add_subtree(hop_item, ett_rfnoc_mgmt_hop);
                    for (size_t op_id = 0; op_id < num_ops; op_id++) {
                        auto op = hop.get_op(op_id);
                        auto opcode = op.get_op_code();
                        mgmt_op_item = proto_tree_add_item(hop_tree, hf_rfnoc_mgmt_op, tvb, offset, chdr_w_bytes, endianness);
                        mgmt_op_tree = proto_item_add_subtree(mgmt_op_item, ett_rfnoc_mgmt_hop_op);

                        /* Add op code */
                        proto_tree_add_string(
                            mgmt_op_tree, hf_rfnoc_mgmt_op_code, tvb, offset+1, 1,
                            val_to_str(opcode, RFNOC_MGMT_OPCODES, "invalid")
                        );

                        /* Add op payload */
                        if (opcode == uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_SEL_DEST) {
                            auto opdata = uhd::rfnoc::chdr::mgmt_op_t::sel_dest_payload(
                                op.get_op_payload());
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_dest, tvb, offset+2, 2, opdata.dest);
                        } else if (opcode == uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_INFO_RESP) {
                            auto opdata = uhd::rfnoc::chdr::mgmt_op_t::node_info_payload(
                                op.get_op_payload());
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_device_id, tvb, offset+2, 6, opdata.device_id);
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_node_type, tvb, offset+2, 6, opdata.node_type);
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_node_inst, tvb, offset+2, 6, opdata.node_inst);
                        } else if (opcode == uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_CFG_WR_REQ) {
                            auto opdata = uhd::rfnoc::chdr::mgmt_op_t::cfg_payload(
                                op.get_op_payload());
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_cfg_address, tvb, offset+2, 6, opdata.addr);
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_cfg_data, tvb, offset+2, 6, opdata.data);
                        } else if (opcode == uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_CFG_RD_REQ) {
                            auto opdata = uhd::rfnoc::chdr::mgmt_op_t::cfg_payload(
                                op.get_op_payload());
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_cfg_address, tvb, offset+2, 6, opdata.addr);
                        } else if (opcode == uhd::rfnoc::chdr::mgmt_op_t::op_code_t::MGMT_OP_CFG_RD_RESP) {
                            auto opdata = uhd::rfnoc::chdr::mgmt_op_t::cfg_payload(
                                op.get_op_payload());
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_cfg_address, tvb, offset+2, 6, opdata.addr);
                            proto_tree_add_uint(mgmt_op_tree, hf_rfnoc_mgmt_op_cfg_data, tvb, offset+2, 6, opdata.data);
                        }
                        offset += chdr_w_bytes;
                    }
                }
            }
            if (pkttype == uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_DATA_NO_TS
                || pkttype == uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_DATA_WITH_TS) {
                is_eob = chdr_hdr.get_eob();
                is_eov = chdr_hdr.get_eov();
                proto_tree_add_boolean(
                    rfnoc_tree, hf_rfnoc_hdr_eob, tvb, offset + 7, 1, is_eob);
                proto_tree_add_boolean(
                    rfnoc_tree, hf_rfnoc_hdr_eov, tvb, offset + 7, 1, is_eov);
            }
            if (pkttype == uhd::rfnoc::chdr::packet_type_t::PKT_TYPE_DATA_WITH_TS) {
                auto pkt = pkt_factory.make_generic();
                pkt->refresh(tvb_get_ptr(tvb, 0, chdr_len));
                proto_tree_add_uint64(rfnoc_tree, hf_rfnoc_timestamp, tvb, offset+8, 8, *(pkt->get_timestamp()));
            }
        }
    }
    return len;
}

extern "C"
void proto_register_rfnoc(void)
{
    static hf_register_info hf[] = {
        { &hf_rfnoc_hdr,
            { "Header", "rfnoc.hdr",
                FT_NONE, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_hdr_pkttype,
            { "Packet Type", "rfnoc.hdr.pkttype",
                FT_STRINGZ, BASE_NONE,
                NULL, 0x00,
                "Packet Type", HFILL }
        },
        { &hf_rfnoc_hdr_vc,
            { "Virtual Channel", "rfnoc.hdr.vc",
                FT_UINT8, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_hdr_eob,
            { "End Of Burst", "rfnoc.hdr.eob",
                FT_BOOLEAN, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_hdr_eov,
            { "End Of Vector", "rfnoc.hdr.eov",
                FT_BOOLEAN, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_hdr_num_mdata,
            { "Num Mdata", "rfnoc.hdr.nummdata",
                FT_UINT8, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_hdr_seqnum,
            { "Sequence Number", "rfnoc.hdr.seqnum",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_hdr_len,
            { "RFNoC Length", "rfnoc.hdr.len",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_hdr_dst_epid,
            { "Dst EPID", "rfnoc.hdr.dst_epid",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_timestamp,
            { "Timestamp", "rfnoc.timestamp",
                FT_UINT64, BASE_HEX,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl,
            { "CTRL Payload", "rfnoc.ctrl",
                FT_NONE, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_dst_port,
            { "Dst Port", "rfnoc.ctrl.dst_port",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_src_port,
            { "Src Port", "rfnoc.ctrl.src_port",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_num_data,
            { "Num Data", "rfnoc.ctrl.num_data",
                FT_UINT8, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_data0,
            { "Data0", "rfnoc.ctrl.data0",
                FT_UINT32, BASE_HEX,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_seqnum,
            { "Seq Num", "rfnoc.ctrl.seqnum",
                FT_UINT8, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_is_ack,
            { "Is ACK", "rfnoc.ctrl.is_ack",
                FT_BOOLEAN, BASE_NONE,
                NULL, 0x0,
                NULL, HFILL }
        },
        { &hf_rfnoc_src_epid,
            { "Src EPID", "rfnoc.src_epid",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_address,
            { "Address", "rfnoc.ctrl.address",
                FT_UINT32, BASE_HEX,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_opcode,
            { "Op Code", "rfnoc.ctrl.opcode",
                FT_STRINGZ, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_ctrl_status,
            { "Status", "rfnoc.ctrl.status",
                FT_STRINGZ, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strs,
            { "Stream Status", "rfnoc.strs",
                FT_NONE, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strs_status,
            { "Status", "rfnoc.strs.status",
                FT_STRINGZ, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strs_capacity_bytes,
            { "Capacity Bytes", "rfnoc.strs.capacity_bytes",
                FT_UINT64, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strs_capacity_pkts,
            { "Capacity Packets", "rfnoc.strs.capacity_pkts",
                FT_UINT32, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strs_xfer_bytes,
            { "Xfer Count Bytes", "rfnoc.strs.xfer_bytes",
                FT_UINT64, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strs_xfer_pkts,
            { "Xfer Count Packets", "rfnoc.strs.xfer_pkts",
                FT_UINT64, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strc,
            { "Stream Command", "rfnoc.strc",
                FT_NONE, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strc_opcode,
            { "Opcode", "rfnoc.strc.opcode",
                FT_STRINGZ, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strc_num_bytes,
            { "Num Bytes", "rfnoc.strc.num_bytes",
                FT_UINT64, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_strc_num_pkts,
            { "Num Packets", "rfnoc.strc.num_pkts",
                FT_UINT64, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt,
            { "Mgmt Xact", "rfnoc.mgmt",
                FT_NONE, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_protover,
            { "Protocol Version", "rfnoc.mgmt.protover",
                FT_UINT16, BASE_HEX,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_chdr_w,
            { "CHDR Width", "rfnoc.mgmt.chdr_w",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_num_hops,
            { "Num Hops", "rfnoc.mgmt.num_hops",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_hop,
            { "Hop", "rfnoc.mgmt.hop",
                FT_NONE, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op,
            { "Operation", "rfnoc.mgmt.op",
                FT_NONE, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op_code,
            { "Opcode", "rfnoc.mgmt.op.op_code",
                FT_STRINGZ, BASE_NONE,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op_dest,
            { "Destination", "rfnoc.mgmt.op.dest",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op_device_id,
            { "Device ID", "rfnoc.mgmt.op.device_id",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op_node_type,
            { "Node Type", "rfnoc.mgmt.op.node_type",
                FT_UINT8, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op_node_inst,
            { "Node Instance", "rfnoc.mgmt.op.node_inst",
                FT_UINT16, BASE_DEC,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op_cfg_address,
            { "Address", "rfnoc.mgmt.op.cfg_address",
                FT_UINT16, BASE_HEX,
                NULL, 0x00,
                NULL, HFILL }
        },
        { &hf_rfnoc_mgmt_op_cfg_data,
            { "Data", "rfnoc.mgmt.op.cfg_data",
                FT_UINT32, BASE_HEX,
                NULL, 0x00,
                NULL, HFILL }
        },

    };

    static gint *ett[] = {
        &ett_rfnoc,
        &ett_rfnoc_hdr,
        &ett_rfnoc_ctrl,
        &ett_rfnoc_strs,
        &ett_rfnoc_strc,
        &ett_rfnoc_mgmt,
        &ett_rfnoc_mgmt_hop,
        &ett_rfnoc_mgmt_hop_op,
    };

    module_t *rfnoc_module;

    proto_rfnoc = proto_register_protocol("UHD RFNoC", "RFNoC", "rfnoc");
    proto_register_field_array(proto_rfnoc, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
    rfnoc_module = prefs_register_protocol(proto_rfnoc, NULL);
}

/* Handler registration */
extern "C"
void proto_reg_handoff_rfnoc(void)
{
    static gboolean initialized = FALSE;
    static dissector_handle_t rfnoc_handle;
    static uint16_t current_port = RFNOC_PORT;

    rfnoc_handle = create_dissector_handle(dissect_rfnoc, proto_rfnoc);
    dissector_add_uint_with_preference("udp.port", current_port, rfnoc_handle);
}