dissect-wireshark: recognize CanBePrefix, HopLimit, Parameters

refs #4517

Change-Id: I9ea61a070286bbc460ff7f64fb66092a891dcadb
diff --git a/tests/dissect-wireshark/README.md b/tests/dissect-wireshark/README.md
index df3a906..7933e6d 100644
--- a/tests/dissect-wireshark/README.md
+++ b/tests/dissect-wireshark/README.md
@@ -140,3 +140,16 @@
 - the dissection results include Fragment (Interest/Data), Sequence (number), FragIndex (number),
   FragCount (number), Nack (various reasons), NextHopFaceId, IncomingFaceId, CachingPolicy, and
   unknown fields
+
+### 11. NDN Packet Format v0.3
+
+Trace file: `packet03.pcap`
+
+Trace summary: Hand-crafted packets in NDN Packet Format v0.3
+(`xxd -p -r < packet03.hex > packet03.pcap`).
+All packets are valid and do not contain unrecognized TLV elements.
+
+Expected results of the dissection:
+- Packet 1 is recognized as "Interest" type, and has "CanBePrefix: Yes", "MustBeFresh: Yes",
+  "HopLimit: 214", and "Parameters" field.
+- Packet 3 is recognized as "Data" type.
diff --git a/tests/dissect-wireshark/packet03.hex b/tests/dissect-wireshark/packet03.hex
new file mode 100644
index 0000000..da0d7e4
--- /dev/null
+++ b/tests/dissect-wireshark/packet03.hex
@@ -0,0 +1,52 @@
+A1B2C3D4
+00020004
+00000000
+00000000
+00010000
+00000001
+
+00000000
+00000000
+00000039
+00000039
+
+01005E0017AA
+000000000000
+8624
+
+0529
+0703080149
+2100
+1200
+1E0B 1F09 1E023E15 0703080148
+0A044ACB1E4C
+0C0276A1
+2201D6
+2304C0C1C2C3
+
+00000000
+00000000
+00000050
+00000050
+
+01005E0017AA
+000000000000
+8624
+
+0540
+0738 020141 070142 080143 FC0144 FD01000145 FDFFFF0145 0120EE357C5791DCAA4494D9B301047B875D8833CAA76DADA3E95837BBC3EAF7B300
+0A044ACB1E4C
+
+00000000
+00000000
+00000039
+00000039
+
+01005E0017AA
+000000000000
+8624
+
+0629
+0700
+16031B0100
+1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76
diff --git a/tests/dissect-wireshark/packet03.pcap b/tests/dissect-wireshark/packet03.pcap
new file mode 100644
index 0000000..35f6161
--- /dev/null
+++ b/tests/dissect-wireshark/packet03.pcap
Binary files differ
diff --git a/tools/dissect-wireshark/ndn.lua b/tools/dissect-wireshark/ndn.lua
index 13b8a8c..f3463e2 100755
--- a/tools/dissect-wireshark/ndn.lua
+++ b/tools/dissect-wireshark/ndn.lua
@@ -159,51 +159,38 @@
 -----------------------------------------------------
 
 local NDN_DICT = {
-   -- Interest or Data packets
-   [5]  = {name = "Interest"                     , summary = true},
-   [6]  = {name = "Data"                         , summary = true},
-
-   -- Name field
+   -- Name and NameComponent
    [7]  = {name = "Name"                         , field = ProtoField.string("ndn.name", "Name")                                   , value = getUriFromName},
    [1]  = {name = "ImplicitSha256DigestComponent", field = ProtoField.string("ndn.implicitsha256", "ImplicitSha256DigestComponent"), value = getUriFromNameComponent},
-   [8]  = {name = "NameComponent"                , field = ProtoField.string("ndn.namecomponent", "NameComponent")                 , value = getUriFromNameComponent},
+   [8]  = {name = "GenericNameComponent"         , field = ProtoField.string("ndn.namecomponent", "NameComponent")                 , value = getUriFromNameComponent},
 
-   -- Sub-fields of Interest packet
-   [9]  = {name = "Selectors"                    , summary = true},
+   -- Interest and its sub-elements in Packet Format v0.3
+   [5]  = {name = "Interest"                     , summary = true},
+   [33] = {name = "CanBePrefix"                  , field = ProtoField.string("ndn.canbeprefix", "CanBePrefix")                     , value = getTrue},
+   [18] = {name = "MustBeFresh"                  , field = ProtoField.string("ndn.mustbefresh", "MustBeFresh")                     , value = getTrue},
+   -- [30] = {name = "ForwardingHint"               , summary = true},
+   -- ForwardingHint and LinkPreference have the same TLV-TYPE number, so we can't recognize both for now (see #4185).
+   [31] = {name = "LinkDelegation"               , summary = true},
+   [30] = {name = "LinkPreference"               , field = ProtoField.uint32("ndn.link_preference", "LinkPreference", base.DEC)    , value = getNonNegativeInteger},
    [10] = {name = "Nonce"                        , field = ProtoField.uint32("ndn.nonce", "Nonce", base.HEX)                       , value = getNonce},
    [12] = {name = "InterestLifetime"             , field = ProtoField.uint32("ndn.interestlifetime", "InterestLifetime", base.DEC) , value = getNonNegativeInteger},
+   [34] = {name = "HopLimit"                     , field = ProtoField.uint32("ndn.hoplimit", "HopLimit", base.DEC)                 , value = getNonNegativeInteger},
+   [35] = {name = "Parameters"                   , field = ProtoField.string("ndn.parameters", "Parameters")},
 
-   -- Sub-fields of Interest/Selector field
-   [13] = {name = "MinSuffixComponents"          , field = ProtoField.uint32("ndn.minsuffix", "MinSuffixComponents")               , value = getNonNegativeInteger},
-   [14] = {name = "MaxSuffixComponents"          , field = ProtoField.uint32("ndn.maxsuffix", "MaxSuffixComponents")               , value = getNonNegativeInteger},
-   [15] = {name = "PublisherPublicKeyLocator"    , summary = true},
-   [16] = {name = "Exclude"                      , field = ProtoField.string("ndn.exclude", "Exclude")                             , value = getUriFromExclude},
-   [17] = {name = "ChildSelector"                , field = ProtoField.uint32("ndn.childselector", "ChildSelector", base.DEC)       , value = getNonNegativeInteger},
-   [18] = {name = "MustBeFresh"                  , field = ProtoField.string("ndn.mustbefresh", "MustBeFresh")                     , value = getTrue},
-   [19] = {name = "Any"                          , field = ProtoField.string("ndn.any", "Any")                                     , value = getTrue},
-
-   -- Sub-fields of Data packet
+   -- Data and its sub-elements in Packet Format v0.3
+   [6]  = {name = "Data"                         , summary = true},
    [20] = {name = "MetaInfo"                     , summary = true},
-   [21] = {name = "Content"                      , field = ProtoField.string("ndn.content", "Content")},
-   [22] = {name = "SignatureInfo"                , summary = true},
-   [23] = {name = "SignatureValue"               , field = ProtoField.bytes("ndn.signaturevalue", "SignatureValue")},
-
-   -- Sub-fields of Data/MetaInfo field
    [24] = {name = "ContentType"                  , field = ProtoField.uint32("ndn.contenttype", "Content Type", base.DEC)          , value = getNonNegativeInteger},
    [25] = {name = "FreshnessPeriod"              , field = ProtoField.uint32("ndn.freshnessperiod", "FreshnessPeriod", base.DEC)   , value = getNonNegativeInteger},
    [26] = {name = "FinalBlockId"                 , field = ProtoField.string("ndn.finalblockid", "FinalBlockId")                   , value = getUriFromNameComponent},
-
-   -- Sub-fields of Data/Signature field
+   [21] = {name = "Content"                      , field = ProtoField.string("ndn.content", "Content")},
+   [22] = {name = "SignatureInfo"                , summary = true},
    [27] = {name = "SignatureType"                , field = ProtoField.uint32("ndn.signaturetype", "SignatureType", base.DEC)       , value = getNonNegativeInteger},
    [28] = {name = "KeyLocator"                   , summary = true},
    [29] = {name = "KeyDigest"                    , field = ProtoField.bytes("ndn.keydigest", "KeyDigest")},
+   [23] = {name = "SignatureValue"               , field = ProtoField.bytes("ndn.signaturevalue", "SignatureValue")},
 
-   -- Other fields
-   [30] = {name = "LinkPreference"               , field = ProtoField.uint32("ndn.link_preference", "LinkPreference", base.DEC)    , value = getNonNegativeInteger},
-   [31] = {name = "LinkDelegation"               , summary = true},
-   [32] = {name = "SelectedDelegation"           , field = ProtoField.uint32("ndn.selected_delegation", "SelectedDelegation", base.DEC), value = getNonNegativeInteger},
-
-   -- NDNLPv2 Packet field
+   -- NDNLPv2 headers
    [80] = {name = "Fragment"                     },
    [81] = {name = "Sequence"                     , field = ProtoField.uint32("ndn.sequence", "Sequence", base.DEC), value = getNonNegativeInteger},
    [82] = {name = "FragIndex"                    , field = ProtoField.uint32("ndn.fragindex", "FragIndex", base.DEC), value = getNonNegativeInteger},
@@ -215,6 +202,16 @@
    [817] = {name = "IncomingFaceId"              , field = ProtoField.uint32("ndn.incoming_faceid", "IncomingFaceId", base.DEC), value = getNonNegativeInteger},
    [820] = {name = "CachePolicy"                 , summary = true},
    [821] = {name = "CachePolicyType"             , field = ProtoField.string("ndn.cachepolicy_type", "CachePolicyType"), value = getCachePolicyDetail},
+
+   -- Deprecated elements
+   [9]  = {name = "Selectors"                    , summary = true},
+   [13] = {name = "MinSuffixComponents"          , field = ProtoField.uint32("ndn.minsuffix", "MinSuffixComponents")               , value = getNonNegativeInteger},
+   [14] = {name = "MaxSuffixComponents"          , field = ProtoField.uint32("ndn.maxsuffix", "MaxSuffixComponents")               , value = getNonNegativeInteger},
+   [15] = {name = "PublisherPublicKeyLocator"    , summary = true},
+   [16] = {name = "Exclude"                      , field = ProtoField.string("ndn.exclude", "Exclude")                             , value = getUriFromExclude},
+   [17] = {name = "ChildSelector"                , field = ProtoField.uint32("ndn.childselector", "ChildSelector", base.DEC)       , value = getNonNegativeInteger},
+   [19] = {name = "Any"                          , field = ProtoField.string("ndn.any", "Any")                                     , value = getTrue},
+   [32] = {name = "SelectedDelegation"           , field = ProtoField.uint32("ndn.selected_delegation", "SelectedDelegation", base.DEC), value = getNonNegativeInteger},
 }
 
 -- -- Add protofields in NDN protocol
@@ -508,5 +505,4 @@
 local ethernetDissectorTable = DissectorTable.get("ethertype")
 ethernetDissectorTable:add(0x8624, ndn)
 
-io.stderr:write("ndn.lua is successfully loaded\n")
-
+io.stderr:write("NDN dissector successfully loaded\n")