Esempio n. 1
0
    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)
Esempio n. 2
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)
Esempio n. 3
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)