summaryrefslogtreecommitdiffstats
path: root/openbsc/contrib/gprs/gprs-bssgp-histogram.lua
blob: d1a2049a6bf1293ac55e18dff4320b354ac839f3 (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
-- Simple LUA script to print the size of BSSGP messages over their type...

do
	local ip_bucket = {}

	local function init_listener()
		-- handle the port as NS over IP
		local udp_port_table = DissectorTable.get("udp.port")
		local gprs_ns_dis = Dissector.get("gprs_ns")
		udp_port_table:add(23000,gprs_ns_dis)

		-- bssgp filters
		local bssgp_pdu_get = Field.new("bssgp.pdu_type")
		local udp_length_get = Field.new("udp.length")

		local tap = Listener.new("ip", "udp.port == 23000")
		function tap.packet(pinfo,tvb,ip)
			local pdu = bssgp_pdu_get()
			local len = udp_length_get()

			-- only handle bssgp, but we also want the IP frame
			if not pdu then
				return
			end

			pdu = tostring(pdu)
			if tonumber(pdu) == 0 or tonumber(pdu) == 1 then
				return
			end

			local ip_src = tostring(ip.ip_src)
			local bssgp_histo = ip_bucket[ip_src]
			if not bssgp_histo then
				bssgp_histo = {}
				ip_bucket[ip_src] = bssgp_histo
			end

			local key = pdu
			local bucket = bssgp_histo[key]
			if not bucket then
				bucket = {}
				bssgp_histo[key] = bucket
			end

			table.insert(bucket, tostring(len))
			print("IP: " .. ip_src .. " PDU: " .. pdu .. " Length: " .. tostring(len))
		end

		function tap.draw()
			-- well... this will not be called...
--			for ip,bssgp_histo in pairs(dumpers) do
--				print("IP " .. ip)
--			end
		end

		function tap.reset()
			-- well... this will not be called...
		end
	end

	init_listener()
end