aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-rtps-virtual-transport.c
blob: fdd98b8c1f209f9b33ee7579b6d4d224bf5d8735 (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
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
/* packet-rtps-virtual-transport.c
 * Dissector for the Real-Time Publish-Subscribe (RTPS) Virtual Transport
 * Protocol.
 *
 * (c) 2020 Copyright, Real-Time Innovations, Inc.
 * Real-Time Innovations, Inc.
 * 232 East Java Drive
 * Sunnyvale, CA 94089
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * -----------------------------------------------------------------------------
 * RTI Connext DDS can capture RTPS-related traffic by using the Network Capture
 * Utility. The generated .pcap capture files will follow the RTPS-VT protocol,
 * which establishes a format for how information must be saved, and then
 * parsed.
 *
 * The protocol is divided into two layers: transport
 * (packet-rtps-virtual-transport.c) and advanced (packet-rtps-processed.c).
 * This file is about the transport dissector. For more information about the
 * advanced dissector, read the documentation at the beginning of
 * packet-rtps-processed.c.
 *
 * Every packet saved in the capture file follows the PCAP file format.
 * As a consequence, there are two headers: a global one (unique per file) and
 * a per-packet header. These headers have the typical content described in the
 * PCAP format: a magic number, version number, some timestamps, information
 * describing the length of the packet and the data link layer (0x000000fc, i.e.
 * custom protocol), etc. Then, we have a header that indicates Wireshark the
 * name of the protocol: "rtpsvt". The transport dissector is called when
 * Wireshark finds "rtpsvt" as the protocol name.
 *
 * After the RTPS-VT header, we have the frame type. The frame type determines
 * what kind of information has the dumped packet. RTPS-VT data comes as a
 * series of [parameter identifier, content length, content]. Depending on the
 * type of frame (RTPS or lossInfo), the dissector will expect some parameters
 * or others.
 *
 * If the frame type is RTPS, we will continue parsing transport-layer data.
 * The transport layer contains all information about the source and destination
 * of a packet. This corresponds to data typically found on Network or Transport
 * protocols. However, because RTI Connext DDS generates the capture file
 * directly at application-level, this information is added at the moment of
 * writing the capture file.
 * After the transport-layer information, we will call the advanced dissector.
 *
 * If the frame type is lossInfo, the dissector will generate a packet
 * indicating that there were missing frames (and the range of sequence
 * numbers).
 */
#include "config.h"

#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/prefs.h>
#include <epan/addr_resolv.h>
#include <epan/wmem_scopes.h>
#include <epan/conversation.h>
#include <epan/column.h>
#include <epan/dissectors/packet-tcp.h>
#include <epan/dissectors/packet-rtps.h>


#define CONTENT_KIND_RTPS                        0x01
#define CONTENT_KIND_LOSS_INFO                   0x02

#define PARAM_ID_TRANSPORT_CLASS                 0x0001
#define PARAM_ID_MONITORING_GUID                 0x0002
#define PARAM_ID_MONITORING_SN                   0x0003
#define PARAM_ID_SOURCE_IP_ADDRESS               0x0004
#define PARAM_ID_SOURCE_PORT                     0x0005
#define PARAM_ID_DESTINATION_IP_ADDRESS          0x0006
#define PARAM_ID_DESTINATION_RTPS_PORT           0x0007
#define PARAM_ID_DESTINATION_PORT                0x0008
#define PARAM_ID_DIRECTION                       0x0009
#define FIRST_PARAM_ID_RTPS  PARAM_ID_TRANSPORT_CLASS
#define LAST_PARAM_ID_RTPS   PARAM_ID_DIRECTION

/* First parameter Identifier that the "rtpsproc" protocol accepts */
#define PARAM_ID_MAIN_FRAME                      0x00C0

#define PARAM_ID_LOST_MESSAGES                   0x0001

void proto_register_rtps_virtual_transport(void);
static gint dissect_rtps_virtual_transport(
        tvbuff_t *tvb,
        packet_info *pinfo,
        proto_tree *tree,
        void *data _U_);
static gint dissect_rtps_virtual_transport_rtps_type(
        tvbuff_t *tvb,
        packet_info *pinfo,
        proto_tree *tree,
        proto_tree *tree_transport,
        gint offset,
        struct rtpsvt_data *transport_data);
static gint dissect_parameter_transport_rtps_type(
        tvbuff_t *tvb,
        proto_tree *rtpsvt_tree_general,
        proto_tree *rtpsvt_tree_identifier,
        proto_tree *rtpsvt_tree_information,
        gint offset,
        packet_info *pinfo,
        struct rtpsvt_data *transport_data);
static gint dissect_rtps_virtual_transport_loss_info_type(
        tvbuff_t *tvb,
        packet_info *pinfo,
        proto_tree *tree_transport,
        gint offset);

/* Subtree pointers */
static gint proto_rtpsvt = -1;
static gint rtpsvt_ett = -1;
static gint rtpsvt_ett_version = -1;
static gint rtpsvt_ett_identifier = -1;
static gint rtpsvt_ett_information = -1;
static gint rtpsvt_ett_information_class = -1;
static gint rtpsvt_ett_information_src_port = -1;
static gint rtpsvt_ett_information_dst_port = -1;
static gint rtpsvt_ett_information_src_addr = -1;
static gint rtpsvt_ett_information_dst_addr = -1;
static gint rtpsvt_ett_information_direction = -1;
static gint rtpsvt_ett_monitoring_sn = -1;
static gint rtpsvt_ett_frame = -1;

/* Initialize the protocol and registered fields */
static header_field_info *rtpsvt_hf = NULL;
static gint rtpsvt_hf_version = -1;
static gint rtpsvt_hf_version_major = -1;
static gint rtpsvt_hf_version_minor = -1;
static gint rtpsvt_hf_content_kind = -1;
static gint rtpsvt_hf_param_id = -1;
static gint rtpsvt_hf_param_length = -1;
static gint rtpsvt_hf_packet_identifier = -1;
static gint rtpsvt_hf_monitoring_guid = -1;
static gint rtpsvt_hf_monitoring_seqNr = -1;
static gint rtpsvt_hf_information = -1;
static gint rtpsvt_hf_class = -1;
static gint rtpsvt_hf_source_port = -1;
static gint rtpsvt_hf_source_address = -1;
static gint rtpsvt_hf_source_pid = -1;
static gint rtpsvt_hf_destination_port = -1;
static gint rtpsvt_hf_destination_rtps_port = -1;
static gint rtpsvt_hf_destination_address = -1;
static gint rtpsvt_hf_direction = -1;
static gint rtpsvt_hf_destination_pid = -1;
static gint rtpsvt_hf_missing_messages = -1;

/* expert info fields */
static expert_field ei_missing_msg = EI_INIT;

/* Vendor specific: RTI */
static const value_string ndds_transport_class_id_vals[] = {
    { NDDS_TRANSPORT_CLASSID_ANY,           "ANY" },
    { NDDS_TRANSPORT_CLASSID_UDPv4,         "UDPv4" },
    { NDDS_TRANSPORT_CLASSID_UDPv4_WAN,     "UDPv4_WAN"},
    { NDDS_TRANSPORT_CLASSID_SHMEM,         "SHMEM" },
    { NDDS_TRANSPORT_CLASSID_INTRA,         "INTRA" },
    { NDDS_TRANSPORT_CLASSID_UDPv6,         "UDPv6" },
    { NDDS_TRANSPORT_CLASSID_DTLS,          "DTLS" },
    { NDDS_TRANSPORT_CLASSID_WAN,           "WAN" },
    { NDDS_TRANSPORT_CLASSID_TCPV4_LAN,     "TCPv4_LAN" },
    { NDDS_TRANSPORT_CLASSID_TCPV4_WAN,     "TCPv4_WAN" },
    { NDDS_TRANSPORT_CLASSID_TLSV4_LAN,     "TLSv4_LAN" },
    { NDDS_TRANSPORT_CLASSID_TLSV4_WAN,     "TLSv4_WAN" },
    { NDDS_TRANSPORT_CLASSID_PCIE,          "PCIE" },
    { NDDS_TRANSPORT_CLASSID_ITP,           "ITP" },
    { 0, NULL }
};

static gint dissect_rtps_virtual_transport(
        tvbuff_t *tvb,
        packet_info *pinfo,
        proto_tree *tree,
        void *data _U_)
{
    proto_tree *rtpsvt_tree_transport;
    proto_item *rtpsvt_ti_transport;
    proto_item *rtpsvt_ti_version;
    proto_tree *rtpsvt_tree_version;
    proto_item *rtpsvt_ti_content_kind;
    struct rtpsvt_data transport_data;
    guint16 version;
    guint8 content_type;
    const gchar *content_type_label;
    gint offset = 0;
    gint output = 0;

    /* Add transport tree, used for the fields of our proto_rtpsvt */
    rtpsvt_ti_transport = proto_tree_add_item(
            tree,
            proto_rtpsvt,
            tvb,
            offset,
            -1,
            ENC_BIG_ENDIAN);
    rtpsvt_tree_transport = proto_item_add_subtree(rtpsvt_ti_transport, rtpsvt_ett);

    /* Add the version to the transport protocol */
    version = tvb_get_ntohs(tvb, offset);
    transport_data.version_major = version >> 8;
    transport_data.version_minor = version & 0xff;
    rtpsvt_ti_version = proto_tree_add_uint_format(
            rtpsvt_tree_transport,
            rtpsvt_hf_version,
            tvb,
            offset,
            2, /* 2B: sizeof(guint16) */
            version,
            "Version: %d.%d",
            transport_data.version_major,
            transport_data.version_minor);
    rtpsvt_tree_version = proto_item_add_subtree(
            rtpsvt_ti_version,
            rtpsvt_ett_version);

    proto_tree_add_item(
            rtpsvt_tree_version,
            rtpsvt_hf_version_major,
            tvb,
            offset,
            1, /* length: sizeof(guint8) */
            ENC_NA);
    proto_tree_add_item(
            rtpsvt_tree_version,
            rtpsvt_hf_version_minor,
            tvb,
            offset + 1,
            1, /* length: sizeof(guint8) */
            ENC_NA);
    offset += 2;

    /* Add the content kind. */
    content_type = tvb_get_guint8(tvb, offset);
    rtpsvt_ti_content_kind = proto_tree_add_item(
            rtpsvt_ti_transport,
            rtpsvt_hf_content_kind,
            tvb,
            offset,
            1, /* length: sizeof(guint8) */
            ENC_NA);
    if (content_type == CONTENT_KIND_RTPS) {
        content_type_label = "RTPS";
    } else {
        content_type_label = "LOST_INFO";
    }
    proto_item_append_text(rtpsvt_ti_content_kind, " (%s)", content_type_label);
    offset += 1;

    switch(content_type) {
        case CONTENT_KIND_RTPS:
            output = dissect_rtps_virtual_transport_rtps_type(
                    tvb,
                    pinfo,
                    tree,
                    rtpsvt_tree_transport,
                    offset,
                    &transport_data);
            break;

        case CONTENT_KIND_LOSS_INFO:
            output = dissect_rtps_virtual_transport_loss_info_type(
                    tvb,
                    pinfo,
                    rtpsvt_tree_transport,
                    offset);
            break;
    }
    return output;
}

static gint dissect_rtps_virtual_transport_rtps_type(
        tvbuff_t *tvb,
        packet_info *pinfo,
        proto_tree *tree,
        proto_tree *tree_transport,
        gint offset,
        struct rtpsvt_data *transport_data)
{
    proto_item *rtpsvt_ti_identifier;
    proto_tree *rtpsvt_tree_identifier;
    proto_item *rtpsvt_ti_information;
    proto_tree *rtpsvt_tree_information;
    tvbuff_t *advanced_payload;
    static dissector_handle_t advanced_handle = NULL;
    unsigned int idx = FIRST_PARAM_ID_RTPS;
    guint16 param_id;
    guint16 param_length;

    /*
     * Add the tree for the packet identifier, which will be populated in
     * dissect_parameter_transport_rtps_type.
     */
    rtpsvt_ti_identifier = proto_tree_add_item(
            tree_transport,
            rtpsvt_hf_packet_identifier,
            tvb,
            offset,
            -1,
            ENC_NA);
    rtpsvt_tree_identifier = proto_item_add_subtree(
            rtpsvt_ti_identifier,
            rtpsvt_ett_identifier);

    /*
     * Add the tree for the transport information, which will be populated in
     * dissect_parameter_transport_rtps_type.
     */
    rtpsvt_ti_information = proto_tree_add_item(
            tree_transport,
            rtpsvt_hf_information,
            tvb,
            offset,
            -1,
            ENC_NA);
    rtpsvt_tree_information = proto_item_add_subtree(
            rtpsvt_ti_information,
            rtpsvt_ett_information);

    /*
     * Each parameter has an id, a length and a value.
     */
    for (idx = FIRST_PARAM_ID_RTPS; idx <= LAST_PARAM_ID_RTPS; idx++) {
        offset = dissect_parameter_transport_rtps_type(
                tvb,
                tree_transport,
                rtpsvt_tree_identifier,
                rtpsvt_tree_information,
                offset,
                pinfo,
                transport_data);
    }

    /*
     * In the future we may have more transport parameters.
     * These parameters will have an identifier less than PARAM_ID_MAIN_FRAME
     * (which is parsed by the rtpsproc dissector).
     * If we open a "future" capture file with this dissector, we will skip all
     * of those parameters and parse only the ones we know about.
     */
    do {
        param_id = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
        offset += 2;
        param_length = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
        offset += 2;
        if (param_id == PARAM_ID_MAIN_FRAME) {
            proto_tree *rtpsvt_tree_frame;
            transport_data->rtps_length = param_length;
            rtpsvt_tree_frame = proto_tree_add_subtree_format(
                    tree_transport,
                    tvb,
                    offset,
                    0,
                    rtpsvt_ett_frame,
                    NULL,
                    "Real-Time Publish-Subscribe Wire Protocol (content)");

            proto_tree_add_uint(
                    rtpsvt_tree_frame,
                    rtpsvt_hf_param_id,
                    tvb,
                    offset,
                    2, /* 2B: sizeof(guint16) */
                    param_id);
            proto_tree_add_uint(
                    rtpsvt_tree_frame,
                    rtpsvt_hf_param_length,
                    tvb,
                    offset + 2,
                    2,
                    param_length);
            break;
        }
        offset += param_length;
    } while (tvb_reported_length_remaining(tvb, offset) > 0);

    if (param_id != PARAM_ID_MAIN_FRAME || param_length <= 0) {
        /*
         * Reject the packet if we don't have an RTPS frame.
         * The rtpsproc dissector assumes that the contents start with the
         * RTPS frame (parameter value; the length is obtained from
         * transport_data).
         */
        return 0;
    }

    advanced_payload = tvb_new_subset_length(tvb, offset, -1);
    advanced_handle = find_dissector("rtpsproc");
    call_dissector_with_data(
            advanced_handle,
            advanced_payload,
            pinfo,
            tree,
            (void *) transport_data);

    return tvb_captured_length(tvb);
}

static gint dissect_parameter_transport_rtps_type(
        tvbuff_t *tvb,
        proto_tree *rtpsvt_tree_general,
        proto_tree *rtpsvt_tree_identifier,
        proto_tree *rtpsvt_tree_information,
        gint offset,
        packet_info *pinfo,
        struct rtpsvt_data *transport_data)
{
    /*
     * We will add the parameter id and length later, as part of a subtree
     * dependent of the parameter.
     * That is why value of the parameter is now at offset + 4
     * (i.e. offset + sizeof(param_id) + sizeof(param_length))
     */
    guint16 param_id = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
    guint16 param_length = tvb_get_guint16(tvb, offset + 2, ENC_BIG_ENDIAN);
    const gint OFFSET_TO_VAL = offset + 4;
    if (param_length <=0) {
        /* Length not valid: skip parameter (id + length) */
        return OFFSET_TO_VAL;
    }

    switch(param_id) {
        case PARAM_ID_TRANSPORT_CLASS:
            {
                proto_tree *rtpsvt_tree_information_class;
                gint32 classId = tvb_get_gint32(tvb, OFFSET_TO_VAL, ENC_BIG_ENDIAN);
                const gchar *className = val_to_str(
                        classId,
                        ndds_transport_class_id_vals,
                        "%d");

                rtpsvt_tree_information_class = proto_tree_add_subtree_format(
                        rtpsvt_tree_information,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_information_class,
                        NULL,
                        "Class: %s",
                        className);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_information_class,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_information_class,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);
                offset += 2;

                /*
                 * Add transport class as item to the tree.
                 * This is useful to apply as column or filter.
                 */
                proto_tree_add_string(
                        rtpsvt_tree_information_class,
                        rtpsvt_hf_class,
                        tvb,
                        offset,
                        param_length,
                        className);
                offset += param_length;

                /* Add summary to protocol header */
                proto_item_append_text(rtpsvt_tree_general, ", %s", className);

                /* Add summary to the transport information header */
                proto_item_append_text(
                        rtpsvt_tree_information,
                        ", %s",
                        className);
            }
            break;

        case PARAM_ID_MONITORING_GUID:
            {
                proto_tree *rtpsvt_tree_monitoring_guid;
                const guint8 *guid_bytes = tvb_get_ptr(
                        tvb,
                        OFFSET_TO_VAL,
                        param_length);
                const gchar *guid_string = bytes_to_str_punct(
                        pinfo->pool,
                        guid_bytes,
                        MIN(param_length, 12),
                        0);

                rtpsvt_tree_monitoring_guid = proto_tree_add_subtree_format(
                        rtpsvt_tree_identifier,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_information_src_addr,
                        NULL,
                        "Monitoring GUID Prefix: %s",
                        guid_string);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_monitoring_guid,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_monitoring_guid,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);
                offset += 2;

                proto_tree_add_item(
                        rtpsvt_tree_monitoring_guid,
                        rtpsvt_hf_monitoring_guid,
                        tvb,
                        offset,
                        param_length,
                        ENC_NA);
                offset += param_length;

                /* Add summary to packet identifier header */
                proto_item_append_text(
                        rtpsvt_tree_identifier,
                       ", GUID: %s",
                       guid_string);
            }
            break;
        case PARAM_ID_MONITORING_SN:
            {
                proto_tree *rtpsvt_tree_seqNr;
                guint64 seqNr = tvb_get_guint64(tvb, OFFSET_TO_VAL, ENC_BIG_ENDIAN);

                rtpsvt_tree_seqNr = proto_tree_add_subtree_format(
                        rtpsvt_tree_identifier,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_monitoring_sn,
                        NULL,
                        "Monitoring Sequence Number: %" G_GUINT64_FORMAT,
                        seqNr);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_seqNr,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_seqNr,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);
                offset += 2;

                proto_tree_add_uint64(
                        rtpsvt_tree_seqNr,
                        rtpsvt_hf_monitoring_seqNr,
                        tvb,
                        offset,
                        param_length,
                        seqNr);
                offset += param_length;

                /* Add summary to packet identifier header */
                proto_item_append_text(
                        rtpsvt_tree_identifier,
                        ", SeqNum: %" G_GUINT64_FORMAT,
                        seqNr);
            }
            break;
        case PARAM_ID_SOURCE_IP_ADDRESS:
            {
                proto_tree *rtpsvt_tree_information_address;
                gint temporary_hf = rtpsvt_hf_source_address;
                const gchar *prefix = "shmem_prefix";
                const gchar *title_tree = "Source address";
                gchar addr[COL_MAX_LEN];
                ws_in6_addr addr_raw;
                const guint8 bytes_zeroed[12] = {0};
                tvb_get_ipv6(tvb, OFFSET_TO_VAL, &addr_raw);

                /* shared memory pid or address? */
                if (memcmp(&addr_raw.bytes, prefix, strlen(prefix)) == 0) {
                    temporary_hf = rtpsvt_hf_source_pid;
                    title_tree = "Source process ID";
                    guint32 pid = tvb_get_guint32(
                            tvb,
                            OFFSET_TO_VAL + (gint) (strlen(prefix)),
                            ENC_BIG_ENDIAN);
                    g_snprintf(addr, sizeof(addr), "%u", pid);
                } else if (memcmp(
                        &addr_raw.bytes,
                        bytes_zeroed,
                        sizeof(bytes_zeroed)) == 0){
                    g_snprintf(
                            addr,
                            sizeof(addr),
                            "%s",
                            tvb_ip_to_str(pinfo->pool, tvb, OFFSET_TO_VAL + sizeof(bytes_zeroed)));
                } else {
                    g_snprintf(
                            addr,
                            sizeof(addr),
                            "%s",
                            tvb_ip6_to_str(pinfo->pool, tvb, OFFSET_TO_VAL));
                }

                /* Add source to destination column field */
                if (pinfo->cinfo) {
                    col_append_str(pinfo->cinfo, COL_DEF_SRC, addr);
                }

                rtpsvt_tree_information_address = proto_tree_add_subtree_format(
                        rtpsvt_tree_information,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_information_src_addr,
                        NULL,
                        "%s: %s",
                        title_tree,
                        addr);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_information_address,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_information_address,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);
                offset += 2;

                /* Add source to the transport information tree */
                proto_tree_add_string(
                        rtpsvt_tree_information_address,
                        temporary_hf,
                        tvb,
                        offset,
                        param_length,
                        addr);
                offset += param_length;

                /* Add summary to protocol header */
                proto_item_append_text(rtpsvt_tree_general, ", Src: (%s", addr);

                /* Add summary to transport information header */
                proto_item_append_text(
                        rtpsvt_tree_information,
                        ", Src: (%s",
                        addr);
            }
            break;
        case PARAM_ID_SOURCE_PORT:
            {
                proto_tree *rtpsvt_tree_information_port;
                guint32 port = tvb_get_guint32(
                        tvb,
                        OFFSET_TO_VAL,
                        ENC_BIG_ENDIAN);

                rtpsvt_tree_information_port = proto_tree_add_subtree_format(
                        rtpsvt_tree_information,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_information_src_port,
                        NULL,
                        "Source port: %d",
                        port);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_information_port,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_information_port,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);
                offset += 2;

                proto_tree_add_uint(
                        rtpsvt_tree_information_port,
                        rtpsvt_hf_source_port,
                        tvb,
                        offset,
                        param_length,
                        port);
                offset += param_length;

                /* Add summary to protocol header */
                proto_item_append_text(rtpsvt_tree_general, ":%d)", port);

                /* Add summary to transport information header */
                proto_item_append_text(
                        rtpsvt_tree_information,
                        ":%d)",
                        port);

                /*
                 * Add the source port to pinfo.
                 * This is used by the RTPS dissector to get the domainId and
                 * participantIdx information displayed in discovery packets.
                 */
                pinfo->srcport = port;
            }
            break;
        case PARAM_ID_DESTINATION_IP_ADDRESS:
            {
                proto_tree *rtpsvt_tree_information_address;
                gint temporary_hf= rtpsvt_hf_destination_address;
                const gchar *prefix = "shmem_prefix";
                const gchar *title_tree = "Destination address";
                gchar addr[COL_MAX_LEN];
                ws_in6_addr addr_raw;
                const guint8 bytes_zeroed[12] = {0};
                tvb_get_ipv6(tvb, OFFSET_TO_VAL, &addr_raw);

                /* shared memory pid or address? */
                if (memcmp(&addr_raw.bytes, prefix, strlen(prefix)) == 0) {
                    temporary_hf = rtpsvt_hf_destination_pid;
                    title_tree = "Destination process ID";
                    guint32 pid = tvb_get_guint32(
                            tvb,
                            OFFSET_TO_VAL + (gint) (strlen(prefix)),
                            ENC_BIG_ENDIAN);
                    g_snprintf(addr, sizeof(addr), "%u", pid);
                } else if (memcmp(
                        &addr_raw.bytes,
                        bytes_zeroed,
                        sizeof(bytes_zeroed)) == 0){
                    g_snprintf(
                            addr,
                            sizeof(addr),
                            "%s",
                            tvb_ip_to_str(pinfo->pool, tvb, OFFSET_TO_VAL + sizeof(bytes_zeroed)));
                } else {
                    g_snprintf(
                            addr,
                            sizeof(addr),
                            "%s",
                            tvb_ip6_to_str(pinfo->pool, tvb, OFFSET_TO_VAL));
                }

                /* Add address to destination column field */
                if (pinfo->cinfo) {
                    col_append_str(pinfo->cinfo, COL_DEF_DST, addr);
                }

                rtpsvt_tree_information_address = proto_tree_add_subtree_format(
                        rtpsvt_tree_information,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_information_dst_addr,
                        NULL,
                        "%s: %s",
                        title_tree,
                        addr);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_information_address,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_information_address,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);
                offset += 2;

                /* Add destination to the transport information tree */
                proto_tree_add_string(
                        rtpsvt_tree_information_address,
                        temporary_hf,
                        tvb,
                        offset,
                        param_length,
                        addr);
                offset += param_length;

                /* Add summary to protocol header */
                proto_item_append_text(rtpsvt_tree_general, ", Dst: (%s", addr);

                /* Add summary to transport information header */
                proto_item_append_text(
                        rtpsvt_tree_information,
                        ", Dst: (%s",
                        addr);
            }
            break;
        case PARAM_ID_DESTINATION_RTPS_PORT:
            {
                guint32 port = tvb_get_guint32(tvb, OFFSET_TO_VAL, ENC_BIG_ENDIAN);

                proto_tree_add_uint(
                        rtpsvt_tree_information,
                        rtpsvt_hf_destination_rtps_port,
                        tvb,
                        OFFSET_TO_VAL,
                        param_length,
                        port);

                offset = OFFSET_TO_VAL + param_length;
            }
            break;
        case PARAM_ID_DESTINATION_PORT:
            {
                proto_tree *rtpsvt_tree_information_port;
                guint32 port = tvb_get_guint32(tvb, OFFSET_TO_VAL, ENC_BIG_ENDIAN);

                rtpsvt_tree_information_port = proto_tree_add_subtree_format(
                        rtpsvt_tree_information,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_information_dst_port,
                        NULL,
                        "Destination port: %d",
                        port);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_information_port,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_information_port,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);
                offset += 2;

                proto_tree_add_uint(
                        rtpsvt_tree_information_port,
                        rtpsvt_hf_destination_port,
                        tvb,
                        offset,
                        param_length,
                        port);
                offset += param_length;

                /* Add summary to protocol header */
                proto_item_append_text(rtpsvt_tree_general, ":%d)", port);

                /* Add summary to transport information header */
                proto_item_append_text(
                        rtpsvt_tree_information,
                        ":%d)",
                        port);

                /*
                 * Add the destination port to pinfo.
                 * This is used by the RTPS dissector to get the domainId and
                 * participantIdx information displayed in discovery packets.
                 */
                pinfo->destport = port;
            }
            break;
        case PARAM_ID_DIRECTION:
            {
                proto_tree *rtpsvt_tree_direction;
                guint8 value = tvb_get_guint8(tvb, OFFSET_TO_VAL);
                const gchar *direction = value ? "INBOUND" : "OUTBOUND";

                rtpsvt_tree_direction = proto_tree_add_subtree_format(
                        rtpsvt_tree_general,
                        tvb,
                        offset,
                        0,
                        rtpsvt_ett_information_src_addr,
                        NULL,
                        "Traffic Direction: %s",
                        direction);

                /* Add parameter identifier and length */
                proto_tree_add_uint(
                        rtpsvt_tree_direction,
                        rtpsvt_hf_param_id,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_id);
                offset += 2;
                proto_tree_add_uint(
                        rtpsvt_tree_direction,
                        rtpsvt_hf_param_length,
                        tvb,
                        offset,
                        2, /* length: sizeof(guint16) */
                        param_length);

                proto_tree_add_string(
                        rtpsvt_tree_direction,
                        rtpsvt_hf_direction,
                        tvb,
                        OFFSET_TO_VAL,
                        param_length,
                        direction);
                offset = OFFSET_TO_VAL + param_length;

                /* Save transport direction for the RTPS-PROC protocol */
                transport_data->direction = value;
            }
            break;
    }
    return offset;
}

static gint dissect_rtps_virtual_transport_loss_info_type(
        tvbuff_t *tvb,
        packet_info *pinfo,
        proto_tree *tree_transport,
        gint offset)
{

    guint16 param_id;

    param_id = tvb_get_guint16(tvb, offset, ENC_BIG_ENDIAN);
    offset += 2;
    offset += 2; /* parameter length */
    if (param_id == PARAM_ID_LOST_MESSAGES) {
        guint64 first_lost = tvb_get_guint64(tvb, offset, ENC_BIG_ENDIAN);
        guint64 last_lost = tvb_get_guint64(tvb, offset+8, ENC_BIG_ENDIAN);

        if (pinfo->cinfo) {
            char info[COL_MAX_INFO_LEN] = {'\0'};
            g_snprintf(
                    info,
                    sizeof(info),
                    "Missing RTPS messages [%" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT "]",
                    first_lost,
                    last_lost);
            col_append_str(pinfo->cinfo, COL_INFO, info);
        }
        expert_add_info(NULL, tree_transport, &ei_missing_msg);
    }

    return tvb_captured_length(tvb);
}

/* Register the protocol with Wireshark */
void
proto_register_rtps_virtual_transport(void)
{
    expert_module_t* expert_info;

    static hf_register_info hf[] = {
        {
            &rtpsvt_hf_version,
            {
                "Version", "rtpsvt.version",
                FT_UINT16, BASE_HEX, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_version_major,
            {
                "Major", "rtpsvt.version.major",
                FT_INT8, BASE_DEC, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_version_minor,
            {
                "Minor", "rtpsvt.version.minor",
                FT_INT8, BASE_DEC, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_content_kind,
            {
                "Content kind", "rtpsvt.content.kind",
                FT_INT8, BASE_DEC, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_param_id,
            {
                "Parameter Identifier", "rtpsvt.param.id",
                FT_UINT16, BASE_DEC, NULL, 0, 0, HFILL
            },
        },
        {
            &rtpsvt_hf_param_length,
            {
                "Parameter Length", "rtpsvt.param.length",
                FT_UINT16, BASE_DEC, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_direction,
            {
                "Traffic Direction", "rtpsvt.direction",
                FT_STRING, BASE_NONE, NULL, 0x0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_packet_identifier,
            {
                "Packet identifier", "rtpsvt.identifier",
                FT_NONE, BASE_NONE, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_monitoring_guid,
            {
                "GUID", "rtpsvt.monitoring_guid",
                FT_BYTES, BASE_NONE, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_monitoring_seqNr,
            {
                "SeqNum", "rtpsvt.seqNr",
                FT_UINT64, BASE_DEC, NULL, 0x0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_information,
            {
                "Transport Information", "rtpsvt.information",
                FT_NONE, BASE_NONE, NULL, 0x0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_source_port,
            {
                "Source Port", "rtpsvt.source_port",
                FT_UINT32, BASE_DEC, NULL, 0x0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_source_address,
            {
                "Source address", "rtpsvt.source_address",
                FT_STRING, BASE_NONE, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_source_pid,
            {
                "Source process ID", "rtpsvt.source_pid",
                FT_STRING, BASE_NONE, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_destination_port,
            {
                "Destination Port", "rtpsvt.port",
                FT_UINT32, BASE_DEC, NULL, 0x0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_destination_rtps_port,
            {
                "Destination RTPS Port", "rtpsvt.rtps_port",
                FT_UINT32, BASE_DEC, NULL, 0x0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_destination_address,
            {
                "Destination address", "rtpsvt.destination_address",
                FT_STRING, BASE_NONE, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_destination_pid,
            {
                "Destination process ID", "rtpsvt.destination_pid",
                FT_STRING, BASE_NONE, NULL, 0, 0, HFILL
            }
        },
        {
            &rtpsvt_hf_class,
            {
                "Transport class", "rtpsvt.class",
                FT_STRING, BASE_NONE, NULL, 0, 0, HFILL
            }
        },
        {
            /* Information related to the 'lost' content type */
            &rtpsvt_hf_missing_messages,
            {
                "Packets lost", "rtpsvt.missing_messages",
                FT_UINT64, BASE_DEC, NULL, 0x0, 0, HFILL
            }
        }
    };

    static gint *ett[] = {
        &rtpsvt_ett,
        &rtpsvt_ett_version,
        &rtpsvt_ett_identifier,
        &rtpsvt_ett_information,
        &rtpsvt_ett_information_class,
        &rtpsvt_ett_information_src_port,
        &rtpsvt_ett_information_dst_port,
        &rtpsvt_ett_information_src_addr,
        &rtpsvt_ett_information_dst_addr,
        &rtpsvt_ett_information_direction,
        &rtpsvt_ett_monitoring_sn,
        &rtpsvt_ett_frame
    };

    static ei_register_info ei[] = {
        {
        &ei_missing_msg,
        {
            "rtpsvt.expert.missing_messages",
            PI_PROTOCOL,
            PI_NOTE,
            "Missing RTPS Messages because of full buffer pool",
            EXPFILL
        }
    },
    };

    /* Register the protocol name and description */
    proto_rtpsvt = proto_register_protocol(
            "Real-Time Publish-Subscribe Virtual Transport",
            "RTPS-VT",
            "rtpsvt");

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

    /* Register expert information */
    expert_info = expert_register_protocol(proto_rtpsvt);
    expert_register_field_array(expert_info, ei, array_length(ei));

    register_dissector("rtpsvt", dissect_rtps_virtual_transport, proto_rtpsvt);
}

/*
 * Editor modelines  -  https://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:
 */