Example #1
0
 def addDevice(self,device):
     """Fügt ein EthernetDevice zu diesem Router hinzu."""
     self.model.devs.append([device.ipaddr, device.subnetmask, device])
     self.connectors.append(device)
     # Route für dieses Netz hinzufügen
     myip = routing.binaryIP(device.ipaddr)
     mymask = routing.binaryIP(device.subnetmask)
     mynet = myip & mymask
     self.model.routes.append(routing.Route(routing.binaryIP2String(mynet), device.subnetmask, None, 10, len(self.connectors)-1))
Example #2
0
    def __init__(self, x, y, devlist):
        super(Router, self).__init__(x, y, model = NodeModel())
        self.fillcolor = "#3333ff"
        # Routen
        self.model.routes = []
        # Konfigurationsdaten der Ethernet-Devices
        self.model.devs = []
        # ARP Queue beinhaltet alle Pakete, die auf ein MAC warten
        self.model.arpqueue = []
        # ARP Cache
        self.model.arpcache = {}

        # Some statistics: Number of packets for this host
        self.model.inboundpackets = 0
        self.model.forwardedpackets = 0
        
        for dev in devlist:
            self.model.devs.append([dev[0], dev[1], dev[2]])
            dev[2].node = self
            self.connectors.append(dev[2])
            # Lokale Netze werden automatisch in Routingtabelle geschrieben
            myip = routing.binaryIP(dev[0])
            mymask = routing.binaryIP(dev[1])
            mynet = myip & mymask
            self.model.routes.append(routing.Route(routing.binaryIP2String(mynet), dev[1], None, 10, len(self.connectors)-1))

        # Kontext-Menü für Hosts
        self.contextmenu = m = wx.Menu()
        self.contextMenuHandler = self.onContextMenu
        m.AppendCheckItem(10001, "Online")
        m.Append(10002, "&ARP-Request senden")
        m.Append(10003, "&IP-Paket senden")
        m.Append(10004, "&Routingtabelle")
        m.Append(10005, "ARP &Cache")
        m.Append(10006, "&Statistik löschen")

        # Binde die beiden Kontextmenüeinträge an Methoden
        self.bindCommand(10001, self.onOnlineStateCommand)
        self.bindCommand(10002, self.onSendPacketCommand)
        self.bindCommand(10003, self.onSendIPPacketCommand)
        self.bindCommand(10004, self.onEditRoutingTableCommand)
        self.bindCommand(10005, self.onViewARPCacheCommand)
        self.bindCommand(10006, self.onClearStatsCommand)
Example #3
0
 def isValidRoute(self, row):
     """Überprüft, ob Zeile row eine gültige Route darstellt, und liefert
        entsprechend True oder False."""
     
     try:            
         for i in range(2):
             val = routing.binaryIP(self.GetCellValue(row, i))
             gw = self.GetCellValue(3,i)
         if gw != '' and not routing.isValidIP(gw):
             raise ValueError
         metric = int(self.GetCellValue(row, 3))
         device = int(self.GetCellValue(row, 4))
         return True
     except ValueError:
         return False