blob: 724861b7efef0fd9cf975b49298793811624e146 [file] [log] [blame]
Junxiao Shie65c6d72016-07-24 21:53:19 +00001-- Copyright (c) 2015-2016, Regents of the University of California.
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -07002--
3-- This file is part of ndn-tools (Named Data Networking Essential Tools).
4-- See AUTHORS.md for complete list of ndn-tools authors and contributors.
5--
6-- ndn-tools is free software: you can redistribute it and/or modify it under the terms
7-- of the GNU General Public License as published by the Free Software Foundation,
8-- either version 3 of the License, or (at your option) any later version.
9--
10-- ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11-- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12-- PURPOSE. See the GNU General Public License for more details.
13--
14-- You should have received a copy of the GNU General Public License along with
15-- ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
16--
17-- @author Qi Zhao <https://www.linkedin.com/pub/qi-zhao/73/835/9a3>
18-- @author Seunghyun Yoo <http://relue2718.com/>
19-- @author Seungbae Kim <https://sites.google.com/site/sbkimcv/>
Alexander Afanasyev357c2052015-08-10 21:26:52 -070020-- @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Zipeng Wang574eeb02016-10-05 21:46:02 -070021-- @author Zipeng Wang
22-- @author Qianshan Yu
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -070023
24-- inspect.lua (https://github.com/kikito/inspect.lua) can be used for debugging.
25-- See more at http://stackoverflow.com/q/15175859/2150331
26-- local inspect = require('inspect')
27
28-- NDN protocol
Alexander Afanasyev357c2052015-08-10 21:26:52 -070029ndn = Proto("ndn", "Named Data Networking (NDN)")
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -070030
Zipeng Wang574eeb02016-10-05 21:46:02 -070031-- TODO with NDNLPv2 processing:
32-- * mark field "unknown" when the field is recognized but the relevant feature is disabled
33-- * colorize "unknown field"
34-- * for a field that appears out-of-order, display "out-of-order field " in red
35
Alexander Afanasyev357c2052015-08-10 21:26:52 -070036-----------------------------------------------------
37-----------------------------------------------------
38-- Field formatting helpers
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -070039
Alexander Afanasyev357c2052015-08-10 21:26:52 -070040-- Borrowed from http://lua-users.org/wiki/StringRecipes
41function escapeString(str)
42 if (str) then
43 str = string.gsub(str, "\n", "\r\n")
44 str = string.gsub(str, "([^%w %-%_%.%~])",
45 function (c) return string.format ("%%%02X", string.byte(c)) end)
46 str = string.gsub(str, " ", "+")
47 end
48 return str
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -070049end
50
Alexander Afanasyev357c2052015-08-10 21:26:52 -070051function getUriFromNameComponent(block)
52 -- @todo Implement proper proper URL escaping
53 return block.tvb(block.offset + block.typeLen + block.lengthLen, block.length):string()
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -070054end
55
Alexander Afanasyev357c2052015-08-10 21:26:52 -070056function getUriFromName(nameBlock)
57 if (nameBlock.elements == nil) then
58 return ""
59 else
60 components = {}
61 for i, block in pairs(nameBlock.elements) do
62 table.insert(components, getUriFromNameComponent(block))
63 end
64
65 return "/" .. table.concat(components, "/")
66 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -070067end
68
Zipeng Wang574eeb02016-10-05 21:46:02 -070069function getNackReasonDetail(b)
70 local code = getNonNegativeInteger(b)
71 if (code == 0) then return "None"
72 elseif (code == 50) then return "Congestion"
73 elseif (code == 100) then return "Duplicate"
74 elseif (code == 150) then return "NoRoute"
75 else return "Unknown"
76 end
77end
78
79function getCachePolicyDetail(b)
80 local code = getNonNegativeInteger(b)
81 if (code == 1) then return "NoCache"
82 else return "Unknown"
83 end
84end
85
Alexander Afanasyev357c2052015-08-10 21:26:52 -070086function getNonNegativeInteger(b)
87 if (b.length == 1) then
88 return b.tvb(b.offset + b.typeLen + b.lengthLen, 1):uint()
89 elseif (b.length == 2) then
90 return b.tvb(b.offset + b.typeLen + b.lengthLen, 2):uint()
91 elseif (b.length == 4) then
92 return b.tvb(b.offset + b.typeLen + b.lengthLen, 4):uint()
93 -- Something strange with uint64, not supporting it for now
94 -- elseif (b.length == 8) then
95 -- return b.tvb(b.offset + b.typeLen + b.lengthLen, 8):uint64()
96 else
97 return 0xFFFFFFFF;
98 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -070099end
100
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700101function getUriFromExclude(block)
102 -- @todo
103 return ""
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700104end
105
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700106function getTrue(block)
107 return "Yes"
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700108end
109
Zipeng Wang574eeb02016-10-05 21:46:02 -0700110local AppPrivateBlock1 = 100
111local AppPrivateBlock2 = 800
112local AppPrivateBlock3 = 1000
113
114function canIgnoreTlvType(t)
115 if (t < AppPrivateBlock2 or t >= AppPrivateBlock3) then
116 return false
117 else
118 local mod = math.fmod(t, 2)
119 if (mod == 1) then
120 return true
121 else
122 return false
123 end
124 end
125end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700126
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700127function getGenericBlockInfo(block)
128 local name = ""
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700129
Zipeng Wang574eeb02016-10-05 21:46:02 -0700130 -- TODO: Properly format informational message based type value reservations
131 -- (http://named-data.net/doc/ndn-tlv/types.html#type-value-reservations)
132 if (block.type <= AppPrivateBlock1) then
133 name = "Unrecognized from the reserved range " .. 0 .. "-" .. AppPrivateBlock1 .. ""
134 elseif (AppPrivateBlock1 < block.type and block.type < AppPrivateBlock2) then
135 name = "Unrecognized from the reserved range " .. (AppPrivateBlock1 + 1) .. "-" .. (AppPrivateBlock2 - 1) .. ""
136 elseif (AppPrivateBlock2 <= block.type and block.type <= AppPrivateBlock3) then
137 if (canIgnoreTlvType(block.type)) then
138 name = "Unknown field (ignored)"
139 else
140 name = "Unknown field"
141 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700142 else
Zipeng Wang574eeb02016-10-05 21:46:02 -0700143 name = "RESERVED_3"
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700144 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700145
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700146 return name .. ", Type: " .. block.type .. ", Length: " .. block.length
147end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700148
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700149-----------------------------------------------------
150-----------------------------------------------------
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700151
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700152local NDN_DICT = {
153 -- Interest or Data packets
154 [5] = {name = "Interest" , summary = true},
155 [6] = {name = "Data" , summary = true},
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700156
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700157 -- Name field
158 [7] = {name = "Name" , field = ProtoField.string("ndn.name", "Name") , value = getUriFromName},
159 [1] = {name = "ImplicitSha256DigestComponent", field = ProtoField.string("ndn.implicitsha256", "ImplicitSha256DigestComponent"), value = getUriFromNameComponent},
160 [8] = {name = "NameComponent" , field = ProtoField.string("ndn.namecomponent", "NameComponent") , value = getUriFromNameComponent},
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700161
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700162 -- Sub-fields of Interest packet
163 [9] = {name = "Selectors" , summary = true},
164 [10] = {name = "Nonce" , field = ProtoField.bytes("ndn.nonce", "Nonce")},
165 [12] = {name = "InterestLifetime" , field = ProtoField.uint32("ndn.interestlifetime", "InterestLifetime", base.DEC) , value = getNonNegativeInteger},
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700166
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700167 -- Sub-fields of Interest/Selector field
168 [13] = {name = "MinSuffixComponents" , field = ProtoField.uint32("ndn.minsuffix", "MinSuffixComponents") , value = getNonNegativeInteger},
169 [14] = {name = "MaxSuffixComponents" , field = ProtoField.uint32("ndn.maxsuffix", "MaxSuffixComponents") , value = getNonNegativeInteger},
170 [15] = {name = "PublisherPublicKeyLocator" , summary = true},
171 [16] = {name = "Exclude" , field = ProtoField.string("ndn.exclude", "Exclude") , value = getUriFromExclude},
172 [17] = {name = "ChildSelector" , field = ProtoField.uint32("ndn.childselector", "ChildSelector", base.DEC) , value = getNonNegativeInteger},
173 [18] = {name = "MustBeFresh" , field = ProtoField.string("ndn.mustbefresh", "MustBeFresh") , value = getTrue},
174 [19] = {name = "Any" , field = ProtoField.string("ndn.any", "Any") , value = getTrue},
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700175
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700176 -- Sub-fields of Data packet
177 [20] = {name = "MetaInfo" , summary = true},
178 [21] = {name = "Content" , field = ProtoField.string("ndn.content", "Content")},
179 [22] = {name = "SignatureInfo" , summary = true},
180 [23] = {name = "SignatureValue" , field = ProtoField.bytes("ndn.signaturevalue", "SignatureValue")},
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700181
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700182 -- Sub-fields of Data/MetaInfo field
183 [24] = {name = "ContentType" , field = ProtoField.uint32("ndn.contenttype", "Content Type", base.DEC) , value = getNonNegativeInteger},
184 [25] = {name = "FreshnessPeriod" , field = ProtoField.uint32("ndn.freshnessperiod", "FreshnessPeriod", base.DEC) , value = getNonNegativeInteger},
185 [26] = {name = "FinalBlockId" , field = ProtoField.string("ndn.finalblockid", "FinalBlockId") , value = getUriFromNameComponent},
186
187 -- Sub-fields of Data/Signature field
188 [27] = {name = "SignatureType" , field = ProtoField.uint32("ndn.signaturetype", "SignatureType", base.DEC) , value = getNonNegativeInteger},
189 [28] = {name = "KeyLocator" , summary = true},
190 [29] = {name = "KeyDigest" , field = ProtoField.bytes("ndn.keydigest", "KeyDigest")},
191
192 -- Other fields
193 [30] = {name = "LinkPreference" , field = ProtoField.uint32("ndn.link_preference", "LinkPreference", base.DEC) , value = getNonNegativeInteger},
194 [31] = {name = "LinkDelegation" , summary = true},
195 [32] = {name = "SelectedDelegation" , field = ProtoField.uint32("ndn.selected_delegation", "SelectedDelegation", base.DEC), value = getNonNegativeInteger},
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700196
Zipeng Wang574eeb02016-10-05 21:46:02 -0700197 -- NDNLPv2 Packet field
198 [80] = {name = "Fragment" },
199 [81] = {name = "Sequence" , field = ProtoField.uint32("ndn.sequence", "Sequence", base.DEC), value = getNonNegativeInteger},
200 [82] = {name = "FragIndex" , field = ProtoField.uint32("ndn.fragindex", "FragIndex", base.DEC), value = getNonNegativeInteger},
201 [83] = {name = "FragCount" , field = ProtoField.uint32("ndn.fragcount", "FragCount", base.DEC), value = getNonNegativeInteger},
202 [100] = {name = "LpPacket" , summary = true},
203 [800] = {name = "Nack" , summary = true},
204 [801] = {name = "NackReason" , field = ProtoField.string("ndn.nack_reason", "NackReason"), value = getNackReasonDetail},
205 [816] = {name = "NextHopFaceId" , field = ProtoField.uint32("ndn.nexthop_faceid", "NextHopFaceId", base.DEC), value = getNonNegativeInteger},
206 [817] = {name = "IncomingFaceId" , field = ProtoField.uint32("ndn.incoming_faceid", "IncomingFaceId", base.DEC), value = getNonNegativeInteger},
207 [820] = {name = "CachePolicy" , summary = true},
208 [821] = {name = "CachePolicyType" , field = ProtoField.string("ndn.cachepolicy_type", "CachePolicyType"), value = getCachePolicyDetail},
209}
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700210
211-- -- Add protofields in NDN protocol
212ndn.fields = {
213}
214for key, value in pairs(NDN_DICT) do
215 table.insert(ndn.fields, value.field)
216end
217
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700218-----------------------------------------------------
219-----------------------------------------------------
220
221-- block
222-- .tvb
223-- .offset
224-- .type
225-- .typeLen
226-- .length
227-- .lengthLen
228-- .size = .typeLen + .lengthLen + .length
229
230function addInfo(block, root) -- may be add additional context later
231 local info = NDN_DICT[block.type]
232
233 if (info == nil) then
234 info = {}
235 info.value = getGenericBlockInfo
Zipeng Wang574eeb02016-10-05 21:46:02 -0700236 -- color
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700237 end
238
239 local treeInfo
240 if (info.value == nil) then
241
242 if (info.field ~= nil) then
243 treeInfo = root:add(info.field, block.tvb(block.offset, block.size))
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700244 else
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700245 treeInfo = root:add(block.tvb(block.offset, block.size), info.name)
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700246 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700247
248 treeInfo:append_text(", Type: " .. block.type .. ", Length: " .. block.length)
249 else
250 block.value = info.value(block)
251
252 if (info.field ~= nil) then
253 treeInfo = root:add(info.field, block.tvb(block.offset, block.size), block.value)
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700254 else
Zipeng Wang574eeb02016-10-05 21:46:02 -0700255 treeInfo = root:add(block.tvb(block.offset, block.size), block.value)
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700256 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700257 end
258 block.root = treeInfo
259 return block.root
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700260end
261
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700262function addSummary(block)
263 if (block.elements == nil) then
264 return
265 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700266
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700267 local info = NDN_DICT[block.type]
268 if (info == nil or info.summary == nil) then
269 return
270 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700271
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700272 local summary = {}
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700273
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700274 for k, subblock in pairs(block.elements) do
275 if (subblock.value ~= nil) then
276 local info = NDN_DICT[subblock.type]
277 if (info ~= nil) then
278 table.insert(summary, info.name .. ": " .. subblock.value)
279 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700280 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700281 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700282
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700283 if (#summary > 0) then
284 block.summary = table.concat(summary, ", ")
285 if (block.value == nil) then
286 block.value = block.summary
287 end
288 block.root:append_text(", " .. block.summary)
289 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700290end
291
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700292-----------------------------------------------------
293-----------------------------------------------------
294
295function readVarNumber(tvb, offset)
Junxiao Shie65c6d72016-07-24 21:53:19 +0000296 if offset >= tvb:len() then
297 return 0, 0
298 end
299
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700300 local firstOctet = tvb(offset, 1):uint()
301 if (firstOctet < 253) then
302 return firstOctet, 1
Junxiao Shie65c6d72016-07-24 21:53:19 +0000303 elseif (firstOctet == 253) and (offset + 3 < tvb:len()) then
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700304 return tvb(offset + 1, 2):uint(), 3
Junxiao Shie65c6d72016-07-24 21:53:19 +0000305 elseif (firstOctet == 254) and (offset + 5 < tvb:len()) then
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700306 return tvb(offset + 1, 4):uint(), 5
Junxiao Shie65c6d72016-07-24 21:53:19 +0000307 elseif (firstOctet == 255) and (offset + 9 < tvb:len()) then
308 return tvb(offset + 1, 8):uint64(), 9
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700309 end
Junxiao Shie65c6d72016-07-24 21:53:19 +0000310
311 return 0, 0
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700312end
313
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700314function getBlock(tvb, offset)
315 local block = {}
316 block.tvb = tvb
317 block.offset = offset
318
319 block.type, block.typeLen = readVarNumber(block.tvb, block.offset)
Junxiao Shie65c6d72016-07-24 21:53:19 +0000320 if block.typeLen == 0 then
321 return nil
322 end
323
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700324 block.length, block.lengthLen = readVarNumber(block.tvb, block.offset + block.typeLen)
Junxiao Shie65c6d72016-07-24 21:53:19 +0000325 if block.lengthLen == 0 then
326 return nil
327 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700328
329 block.size = block.typeLen + block.lengthLen + block.length
330
331 return block
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700332end
333
Alexander Afanasyev7f43c532015-08-12 15:28:51 -0700334function canBeValidNdnPacket(block)
Zipeng Wang574eeb02016-10-05 21:46:02 -0700335 if ((block.type == 5 or block.type == 6 or block.type == 100) and block.length <= 8800) then
Alexander Afanasyev7f43c532015-08-12 15:28:51 -0700336 return true
337 else
338 return false
339 end
340end
341
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700342function findNdnPacket(tvb)
343 offset = 0
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700344
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700345 while offset + 2 < tvb:len() do
346 local block = getBlock(tvb, offset)
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700347
Junxiao Shie65c6d72016-07-24 21:53:19 +0000348 if (block ~= nil) and canBeValidNdnPacket(block) then
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700349 return block
350 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700351
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700352 offset = offset + 1
353 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700354
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700355 return nil
356end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700357
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700358function getSubBlocks(block)
359 local valueLeft = block.length
360 local subBlocks = {}
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700361
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700362 while valueLeft > 0 do
Junxiao Shie65c6d72016-07-24 21:53:19 +0000363 local offset = block.offset + block.typeLen + block.lengthLen + (block.length - valueLeft)
364 local child = getBlock(block.tvb, offset)
365 if child == nil then
366 return nil
367 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700368
369 valueLeft = valueLeft - child.size
370 table.insert(subBlocks, child)
371 end
372
373 if (valueLeft == 0) then
374 return subBlocks
375 else
376 return nil
377 end
378end
379
380-----------------------------------------------------
381-----------------------------------------------------
382
383-- NDN protocol dissector function
384function ndn.dissector(tvb, pInfo, root) -- Tvb, Pinfo, TreeItem
385
386 if (tvb:len() ~= tvb:reported_len()) then
387 return 0 -- ignore partially captured packets
388 -- this can/may be re-enabled only for unfragmented UDP packets
389 end
390
391 local ok, block = pcall(findNdnPacket, tvb)
392 if (not ok) then
393 return 0
394 end
395
396 if (block == nil or block.offset == nil) then
397 -- no valid NDN packets found
398 return 0
399 end
400
401 local nBytesLeft = tvb:len() - block.offset
402 -- print (pInfo.number .. ":: Found block: " .. block.type .. " of length " .. block.size .. " bytesLeft: " .. nBytesLeft)
403
404 while (block.size <= nBytesLeft) do
405 -- Create TreeItems
406 block.tree = root:add(ndn, tvb(block.offset, block.size))
407
408 local queue = {block}
409 while (#queue > 0) do
410 local block = queue[1]
411 table.remove(queue, 1)
412
413 block.elements = getSubBlocks(block)
414 local subtree = addInfo(block, block.tree)
415
416 if (block.elements ~= nil) then
417 for i, subBlock in pairs(block.elements) do
418 subBlock.tree = subtree
419 table.insert(queue, subBlock)
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700420 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700421 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700422 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700423
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700424 -- Make summaries
425 local queue = {block}
426 while (#queue > 0) do
427 local block = queue[1]
428 if (block.visited ~= nil or block.elements == nil) then
429 -- try to make summary
430 table.remove(queue, 1)
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700431
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700432 addSummary(block)
433 else
434 for i, subBlock in pairs(block.elements) do
435 table.insert(queue, 1, subBlock)
436 end
437 block.visited = true
438 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700439 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700440
441 local info = NDN_DICT[block.type]
442 if (info ~= nil) then
Zipeng Wang574eeb02016-10-05 21:46:02 -0700443 if (block.summary ~= nil) then
444 block.tree:append_text(", " .. NDN_DICT[block.type].name .. ", " .. block.summary)
445 else
446 block.tree:append_text(", " .. NDN_DICT[block.type].name)
447 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700448 end
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700449
450 nBytesLeft = nBytesLeft - block.size
451
452 if (nBytesLeft > 0) then
453 ok, block = pcall(getBlock, tvb, tvb:len() - nBytesLeft)
Zipeng Wang574eeb02016-10-05 21:46:02 -0700454 if (not ok or block == nil or not canBeValidNdnPacket(block)) then
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700455 break
456 end
457 end
Zipeng Wang574eeb02016-10-05 21:46:02 -0700458 end -- while(block.size <= nBytesLeft)
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700459
460 pInfo.cols.protocol = tostring(pInfo.cols.protocol) .. " (" .. ndn.name .. ")"
461
Alexander Afanasyev7f43c532015-08-12 15:28:51 -0700462 if (nBytesLeft > 0 and block ~= nil and block.size ~= nil and block.size > nBytesLeft) then
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700463 pInfo.desegment_offset = tvb:len() - nBytesLeft
464
465 -- Originally, I set desegment_len to the exact lenght, but it mysteriously didn't work for TCP
466 -- pInfo.desegment_len = block.size -- this will not work to desegment TCP streams
467 pInfo.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
468 end
Alexander Afanasyev6fbb7b42015-08-10 11:53:49 -0700469end
470
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700471local udpDissectorTable = DissectorTable.get("udp.port")
472udpDissectorTable:add("6363", ndn)
473udpDissectorTable:add("56363", ndn)
474
475local tcpDissectorTable = DissectorTable.get("tcp.port")
476tcpDissectorTable:add("6363", ndn)
477
478local websocketDissectorTable = DissectorTable.get("ws.port")
479-- websocketDissectorTable:add("9696", ndn)
480websocketDissectorTable:add("1-65535", ndn)
481
Alexander Afanasyev7f43c532015-08-12 15:28:51 -0700482local ethernetDissectorTable = DissectorTable.get("ethertype")
483ethernetDissectorTable:add(0x8624, ndn)
484
Alexander Afanasyev357c2052015-08-10 21:26:52 -0700485io.stderr:write("ndn.lua is successfully loaded\n")