Holger Hans Peter Freyther | 9cbdf11 | 2011-05-10 18:45:35 +0200 | [diff] [blame] | 1 | -- I count the buffer space needed for LLC PDUs in the worse case and print it |
| 2 | |
| 3 | do |
| 4 | local function init_listener() |
| 5 | -- handle the port as NS over IP |
| 6 | local udp_port_table = DissectorTable.get("udp.port") |
| 7 | local gprs_ns_dis = Dissector.get("gprs_ns") |
| 8 | udp_port_table:add(23000,gprs_ns_dis) |
| 9 | |
| 10 | -- bssgp filters |
| 11 | local bssgp_pdu_get = Field.new("bssgp.pdu_type") |
| 12 | local bssgp_delay_get = Field.new("bssgp.delay_val") |
| 13 | local llcgprs_get = Field.new("llcgprs") |
| 14 | local pdus = nil |
| 15 | |
| 16 | print("START...") |
| 17 | |
| 18 | local tap = Listener.new("ip", "udp.port == 23000 && bssgp.pdu_type == 0") |
| 19 | function tap.packet(pinfo,tvb,ip) |
| 20 | local pdu = bssgp_pdu_get() |
| 21 | local len = llcgprs_get().len |
| 22 | local delay = bssgp_delay_get() |
| 23 | |
| 24 | -- only handle bssgp, but we also want the IP frame |
| 25 | if not pdu then |
| 26 | return |
| 27 | end |
| 28 | |
| 29 | if tonumber(tostring(delay)) == 65535 then |
| 30 | pdus = { next = pdus, |
| 31 | len = len, |
| 32 | expires = -1 } |
| 33 | else |
| 34 | local off = tonumber(tostring(delay)) / 100.0 |
| 35 | pdus = { next = pdus, |
| 36 | len = len, |
| 37 | expires = pinfo.rel_ts + off } |
| 38 | end |
| 39 | local now_time = tonumber(tostring(pinfo.rel_ts)) |
| 40 | local now_size = 0 |
| 41 | local l = pdus |
| 42 | local prev = nil |
| 43 | local count = 0 |
| 44 | while l do |
| 45 | if now_time < l.expires or l.expires == -1 then |
| 46 | now_size = now_size + l.len |
| 47 | prev = l |
| 48 | l = l.next |
| 49 | count = count + 1 |
| 50 | else |
| 51 | -- delete things |
| 52 | if prev == nil then |
| 53 | pdus = nil |
| 54 | l = nil |
| 55 | else |
| 56 | prev.next = l.next |
| 57 | l = l.next |
| 58 | end |
| 59 | end |
| 60 | end |
| 61 | -- print("TOTAL: " .. now_time .. " PDU_SIZE: " .. now_size) |
| 62 | print(now_time .. " " .. now_size / 1024.0 .. " " .. count) |
| 63 | -- print("NOW: " .. tostring(pinfo.rel_ts) .. " Delay: " .. tostring(delay) .. " Length: " .. tostring(len)) |
| 64 | end |
| 65 | |
| 66 | function tap.draw() |
| 67 | -- well... this will not be called... |
| 68 | -- for ip,bssgp_histo in pairs(dumpers) do |
| 69 | -- print("IP " .. ip) |
| 70 | -- end |
| 71 | print("END") |
| 72 | end |
| 73 | |
| 74 | function tap.reset() |
| 75 | -- well... this will not be called... |
| 76 | end |
| 77 | end |
| 78 | |
| 79 | init_listener() |
| 80 | end |