def status(self): raw = self.getter() r = OrderedDict([('raw', repr(raw))]) if raw: frame = Frame(raw) r['Frame'] = OrderedDict([ ('Dst MAC', '{:02x}'.format(mac_from_bytes(frame.dst))), ('Src MAC', '{:02x}'.format(mac_from_bytes(frame.src))), ('EtherType', Frame.EtherType[frame.ethertype]), ]) if frame.ethertype == Frame.EtherType.IPv4: packet = Packet(frame.payload) r['IPv4'] = OrderedDict([ ('Protocol', Packet.Protocol[packet.protocol]), ('Src IP', ip_to_str(packet.src)), ('Dst IP', ip_to_str(packet.dst)), ('Payload', repr(packet.payload)), ]) elif frame.ethertype == Frame.EtherType.ARP: arp = ARP(frame.payload) r['ARP'] = OrderedDict([ ('Oper', ARP.Oper[arp.oper]), ('Src IP', ip_to_str(arp.src_ip)), ('Src MAC', '{:02x}'.format(mac_from_bytes(arp.src_mac))), ('Dst IP', ip_to_str(arp.dst_ip)), ('Dst MAC', '{:02x}'.format(mac_from_bytes(arp.dst_mac))), ]) return r
def status(self): r = OrderedDict() for addr, entry in self.route_table.items(): addr = '{:02x}'.format(mac_from_bytes(addr)) ports = map(lambda p: self.ports.index(p), entry.ports) time = entry.time r[addr] = '{} {}'.format(ports, time) return r
def run(self): while True: raw = self.delimiter.recv() frame = Frame(raw) if self.for_me(frame.dst): try: handler = self.handlers[frame.ethertype] except KeyError: mint.report('no handler for {}'.format( Frame.EtherType[frame.ethertype])) else: handler(frame.payload) else: msg = '{:02x} dropped frame from {:02x} to {:02x}: {}' mint.report( msg.format(mac_from_bytes(self.mac), mac_from_bytes(frame.src), mac_from_bytes(frame.dst), repr(frame.payload)))
def run(self): while True: raw = self.delimiter.recv() frame = Frame(raw) if self.for_me(frame.dst): try: handler = self.handlers[frame.ethertype] except KeyError: mint.report('no handler for {}'.format( Frame.EtherType[frame.ethertype] )) else: handler(frame.payload) else: msg = '{:02x} dropped frame from {:02x} to {:02x}: {}' mint.report(msg.format( mac_from_bytes(self.mac), mac_from_bytes(frame.src), mac_from_bytes(frame.dst), repr(frame.payload) ))
def register(self, addr, port): mint.report('register host with address {:02x} on port-{}', mac_from_bytes(addr), self.ports.index(port)) if addr == '\x00': return self.route_table[addr] = bunch(ports=[port], time=mint.now())
def mac(self): return mac_from_bytes(self.framer.mac)