def test_icmp(self): errors = 0 # ICMP packet packet = MACPacket(ping_request) packet.decode_remove_header() # print(packet) packet = IPPacket(packet) packet.decode() # print(packet) packet = ICMPPacket(packet) packet.decode() # print(packet) errors += verify_packet(packet, ping_request_infos) packet.encode() packet.decode() # print(packet) errors += verify_packet(packet, ping_request_infos) self.assertEqual(errors, 0)
def test_ip(self): errors = 0 # UDP packet packet = MACPacket(udp) packet.decode_remove_header() # print(packet) packet = IPPacket(packet) # check decoding errors += not packet.check_checksum() packet.decode() # print(packet) errors += verify_packet(packet, {}) # check encoding packet.encode() packet.insert_checksum() errors += not packet.check_checksum() packet.decode() # print(packet) errors += verify_packet(packet, {}) self.assertEqual(errors, 0)
def test_mac(self): errors = 0 packet = MACPacket(arp_request) packet.decode_remove_header() # print(packet) errors += verify_packet(packet, arp_request_infos) packet.encode_header() packet.decode_remove_header() # print(packet) errors += verify_packet(packet, arp_request_infos) # print(packet) packet = MACPacket(arp_reply) packet.decode_remove_header() errors += verify_packet(packet, arp_reply_infos) packet.encode_header() packet.decode_remove_header() # print(packet) errors += verify_packet(packet, arp_reply_infos) self.assertEqual(errors, 0)
def test_arp(self): errors = 0 # ARP request packet = MACPacket(arp_request) packet.decode_remove_header() packet = ARPPacket(packet) # check decoding packet.decode() # print(packet) errors += verify_packet(packet, arp_request_infos) # check encoding packet.encode() packet.decode() # print(packet) errors += verify_packet(packet, arp_request_infos) # ARP Reply packet = MACPacket(arp_reply) packet.decode_remove_header() packet = ARPPacket(packet) # check decoding packet.decode() # print(packet) errors += verify_packet(packet, arp_reply_infos) # check encoding packet.encode() packet.decode() # print(packet) errors += verify_packet(packet, arp_reply_infos) self.assertEqual(errors, 0)
def test_udp(self): errors = 0 # UDP packet packet = MACPacket(udp) packet.decode_remove_header() # print(packet) packet = IPPacket(packet) packet.decode() # print(packet) packet = UDPPacket(packet) packet.decode() # print(packet) if packet.length != (len(packet)+udp_header.length): errors += 1 errors += verify_packet(packet, udp_infos) packet.encode() packet.decode() # print(packet) if packet.length != (len(packet)+udp_header.length): errors += 1 errors += verify_packet(packet, udp_infos) self.assertEqual(errors, 0)