def test_ethernet_packet_parses(self): packed_message = bytes.fromhex("0180c2000003001906eab88c888e0100000501010005010000") message = EthernetPacket.parse(packed_message) self.assertEqual(message.src_mac, MacAddress.from_string("00:19:06:ea:b8:8c")) self.assertEqual(message.dst_mac, MacAddress.from_string("01:80:c2:00:00:03")) self.assertEqual(message.ethertype, 0x888e) self.assertEqual(message.data, bytes.fromhex("0100000501010005010000"))
def send_eth_to_state_machine(self, packed_message): """Send an ethernet frame to MAB State Machine""" ethernet_packet = EthernetPacket.parse(packed_message) port_id = ethernet_packet.dst_mac src_mac = ethernet_packet.src_mac self.logger.info("Sending MAC to MAB State Machine: %s", src_mac) message_id = -2 state_machine = self.get_state_machine(src_mac, port_id, message_id) event = EventMessageReceived(ethernet_packet, port_id) state_machine.event(event)
def ethernet_parse(packed_message): """Parses the ethernet header part, and payload Args: packed_message: Returns: ***Message & destination mac address. Raises: MessageParseError: the packed_message cannot be parsed.""" ethernet_packet = EthernetPacket.parse(packed_message) if ethernet_packet.ethertype != 0x888e: raise MessageParseError( "Ethernet packet with bad ethertype received: %s" % ethernet_packet) return MessageParser.one_x_parse(ethernet_packet.data, ethernet_packet.src_mac), \ ethernet_packet.dst_mac