Let the GUI handle the new dump format.

This commit is contained in:
Guus Sliepen 2012-09-27 22:12:15 +02:00
parent 2e09986a1f
commit aee86011ff

View file

@ -23,6 +23,7 @@ import wx
import sys import sys
import os import os
import platform import platform
import time
from wx.lib.mixins.listctrl import ColumnSorterMixin from wx.lib.mixins.listctrl import ColumnSorterMixin
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
@ -52,34 +53,32 @@ CONTROL = 18
class Node: class Node:
def parse(self, args): def parse(self, args):
self.name = args[0] self.name = args[0]
self.address = args[2] self.address = args[1]
if args[3] != 'port': self.port = args[3]
args.insert(3, 'port') self.cipher = int(args[4])
args.insert(4, '') self.digest = int(args[5])
self.port = args[4] self.maclength = int(args[6])
self.cipher = int(args[6]) self.compression = int(args[7])
self.digest = int(args[8]) self.options = int(args[8], 0x10)
self.maclength = int(args[10]) self.status = int(args[9], 0x10)
self.compression = int(args[12]) self.nexthop = args[10]
self.options = int(args[14], 0x10) self.via = args[11]
self.status = int(args[16], 0x10) self.distance = int(args[12])
self.nexthop = args[18] self.pmtu = int(args[13])
self.via = args[20] self.minmtu = int(args[14])
self.distance = int(args[22]) self.maxmtu = int(args[15])
self.pmtu = int(args[24]) self.last_state_change = float(args[16])
self.minmtu = int(args[26])
self.maxmtu = int(args[28][:-1])
self.subnets = {} self.subnets = {}
class Edge: class Edge:
def parse(self, args): def parse(self, args):
self.fr = args[0] self.fr = args[0]
self.to = args[2] self.to = args[1]
self.address = args[4] self.address = args[2]
self.port = args[6] self.port = args[4]
self.options = int(args[8], 16) self.options = int(args[5], 16)
self.weight = int(args[10]) self.weight = int(args[6])
class Subnet: class Subnet:
def parse(self, args): def parse(self, args):
@ -95,19 +94,16 @@ class Subnet:
self.address = address self.address = address
self.prefixlen = '48' self.prefixlen = '48'
self.owner = args[2] self.owner = args[1]
class Connection: class Connection:
def parse(self, args): def parse(self, args):
self.name = args[0] self.name = args[0]
self.address = args[2] self.address = args[1]
if args[3] != 'port': self.port = args[3]
args.insert(3, 'port') self.options = int(args[4], 0x10)
args.insert(4, '') self.socket = int(args[5])
self.port = args[4] self.status = int(args[6], 0x10)
self.options = int(args[6], 0x10)
self.socket = int(args[8])
self.status = int(args[10], 0x10)
self.weight = 123 self.weight = 123
class VPN: class VPN:
@ -154,34 +150,34 @@ class VPN:
if resp[0] != '18': if resp[0] != '18':
break break
if resp[1] == '3': if resp[1] == '3':
if len(resp) < 3: if len(resp) < 19:
continue continue
node = self.nodes.get(resp[2]) or Node() node = self.nodes.get(resp[2]) or Node()
node.parse(resp[2:]) node.parse(resp[2:])
node.visited = True node.visited = True
self.nodes[resp[2]] = node self.nodes[resp[2]] = node
elif resp[1] == '4': elif resp[1] == '4':
if len(resp) < 5: if len(resp) < 9:
continue continue
edge = self.nodes.get((resp[2], resp[4])) or Edge() edge = self.nodes.get((resp[2], resp[3])) or Edge()
edge.parse(resp[2:]) edge.parse(resp[2:])
edge.visited = True edge.visited = True
self.edges[(resp[2], resp[4])] = edge self.edges[(resp[2], resp[3])] = edge
elif resp[1] == '5': elif resp[1] == '5':
if len(resp) < 5: if len(resp) < 4:
continue continue
subnet = self.subnets.get((resp[2], resp[4])) or Subnet() subnet = self.subnets.get((resp[2], resp[3])) or Subnet()
subnet.parse(resp[2:]) subnet.parse(resp[2:])
subnet.visited = True subnet.visited = True
self.subnets[(resp[2], resp[4])] = subnet self.subnets[(resp[2], resp[3])] = subnet
self.nodes[subnet.owner].subnets[resp[2]] = subnet self.nodes[subnet.owner].subnets[resp[2]] = subnet
elif resp[1] == '6': elif resp[1] == '6':
if len(resp) < 5: if len(resp) < 9:
break break
connection = self.connections.get((resp[2], resp[4])) or Connection() connection = self.connections.get((resp[2], resp[3], resp[5])) or Connection()
connection.parse(resp[2:]) connection.parse(resp[2:])
connection.visited = True connection.visited = True
self.connections[(resp[2], resp[4])] = connection self.connections[(resp[2], resp[3], resp[5])] = connection
else: else:
break break
@ -401,6 +397,7 @@ class NodesPage(wx.Panel):
self.list.InsertColumn(12, 'PMTU') self.list.InsertColumn(12, 'PMTU')
self.list.InsertColumn(13, 'Min MTU') self.list.InsertColumn(13, 'Min MTU')
self.list.InsertColumn(14, 'Max MTU') self.list.InsertColumn(14, 'Max MTU')
self.list.InsertColumn(15, 'Since')
hbox = wx.BoxSizer(wx.HORIZONTAL) hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.list, 1, wx.EXPAND) hbox.Add(self.list, 1, wx.EXPAND)
@ -422,14 +419,19 @@ class NodesPage(wx.Panel):
self.list.SetStringItem(i, 4, str(node.digest)) self.list.SetStringItem(i, 4, str(node.digest))
self.list.SetStringItem(i, 5, str(node.maclength)) self.list.SetStringItem(i, 5, str(node.maclength))
self.list.SetStringItem(i, 6, str(node.compression)) self.list.SetStringItem(i, 6, str(node.compression))
self.list.SetStringItem(i, 7, str(node.options)) self.list.SetStringItem(i, 7, format(node.options, "x"))
self.list.SetStringItem(i, 8, str(node.status)) self.list.SetStringItem(i, 8, format(node.status, "04x"))
self.list.SetStringItem(i, 9, node.nexthop) self.list.SetStringItem(i, 9, node.nexthop)
self.list.SetStringItem(i, 10, node.via) self.list.SetStringItem(i, 10, node.via)
self.list.SetStringItem(i, 11, str(node.distance)) self.list.SetStringItem(i, 11, str(node.distance))
self.list.SetStringItem(i, 12, str(node.pmtu)) self.list.SetStringItem(i, 12, str(node.pmtu))
self.list.SetStringItem(i, 13, str(node.minmtu)) self.list.SetStringItem(i, 13, str(node.minmtu))
self.list.SetStringItem(i, 14, str(node.maxmtu)) self.list.SetStringItem(i, 14, str(node.maxmtu))
if node.last_state_change:
since = time.strftime("%Y-%m-%d %H:%M", time.localtime(node.last_state_change))
else:
since = "never"
self.list.SetStringItem(i, 15, since)
self.list.itemDataMap[i] = (node.name, node.address, node.port, node.cipher, node.digest, node.maclength, node.compression, node.options, node.status, node.nexthop, node.via, node.distance, node.pmtu, node.minmtu, node.maxmtu) self.list.itemDataMap[i] = (node.name, node.address, node.port, node.cipher, node.digest, node.maclength, node.compression, node.options, node.status, node.nexthop, node.via, node.distance, node.pmtu, node.minmtu, node.maxmtu)
self.list.SetItemData(i, i) self.list.SetItemData(i, i)
i += 1 i += 1
@ -465,7 +467,7 @@ class EdgesPage(wx.Panel):
self.list.SetStringItem(i, 1, edge.to) self.list.SetStringItem(i, 1, edge.to)
self.list.SetStringItem(i, 2, edge.address) self.list.SetStringItem(i, 2, edge.address)
self.list.SetStringItem(i, 3, edge.port) self.list.SetStringItem(i, 3, edge.port)
self.list.SetStringItem(i, 4, str(edge.options)) self.list.SetStringItem(i, 4, format(edge.options, "x"))
self.list.SetStringItem(i, 5, str(edge.weight)) self.list.SetStringItem(i, 5, str(edge.weight))
self.list.itemDataMap[i] = (edge.fr, edge.to, edge.address, edge.port, edge.options, edge.weight) self.list.itemDataMap[i] = (edge.fr, edge.to, edge.address, edge.port, edge.options, edge.weight)
i += 1 i += 1