def test_send_icmp(self):

        icmp_cont = dpkt.icmp.ICMP.Echo()
        icmp_cont.data = 'icmp echo'
        icmp_cont.seq = random.randint(0, 65535)
        icmp_cont.id = random.randint(0, 65535)

        icmp_packet = dpkt.icmp.ICMP()
        icmp_packet.type = dpkt.icmp.ICMP_ECHO
        icmp_packet.data = icmp_cont

        self.analyze_packets("h2", lambda: self.send_ip4_packet("h1", "192.168.0.2", dpkt.ip.IP_PROTO_ICMP, str(icmp_packet)))
        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        self.assertReceivedPacket(packet, "Received sent icmp packet", "h2")
    def test_tcp(self):
        # start netcat server
        self.execCmd("h2", "nc -l 12345 &")
        pid = self.net.get("h2").lastPid

        # send packets
        self.analyze_packets("h1", lambda: self.execCmd("h1", "echo 'TEST' | nc 192.168.0.2 12345"))

        # stop netcat server
        self.execCmd("h2", "kill " + str(pid))

        # analyze packets
        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        packet.tcp_dst_port = 12345
        self.assertReceivedPacket(packet, "TCP Packet Received")
Пример #3
0
    def test_send_icmp(self):

        icmp_cont = dpkt.icmp.ICMP.Echo()
        icmp_cont.data = 'icmp echo'
        icmp_cont.seq = random.randint(0, 65535)
        icmp_cont.id = random.randint(0, 65535)

        icmp_packet = dpkt.icmp.ICMP()
        icmp_packet.type = dpkt.icmp.ICMP_ECHO
        icmp_packet.data = icmp_cont

        self.analyze_packets(
            "h2", lambda: self.send_ip4_packet(
                "h1", "192.168.0.2", dpkt.ip.IP_PROTO_ICMP, str(icmp_packet)))
        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        self.assertReceivedPacket(packet, "Received sent icmp packet", "h2")
Пример #4
0
 def test_received_ip_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     packet.ip_src = "192.168.0.1"
     packet.ip_dst = "192.168.0.2"
     self.assertReceivedPacket(packet, "Received ip packet")
     packet1 = Packet()
     packet1.ip_src = "192.168.0.254"
     packet1.ip_dst = "192.168.0.2"
     self.assertNotReceivedPacket(packet1,
                                  "Not received packet from unknown ip.")
Пример #5
0
 def test_received_eth_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     packet.eth_src = "cc:cc:cc:cc:cc:01"
     packet.eth_dst = "cc:cc:cc:cc:cc:02"
     self.assertReceivedPacket(packet, "Received eth packet")
     packet1 = Packet()
     packet1.eth_src = "aa:aa:aa:aa:aa:aa"
     packet1.eth_dst = "cc:cc:cc:cc:cc:02"
     self.assertNotReceivedPacket(packet1,
                                  "Not received packet from switch.")
Пример #6
0
    def test_tcp(self):
        # start netcat server
        self.execCmd("h2", "nc -l 12345 &")
        pid = self.net.get("h2").lastPid

        # send packets
        self.analyze_packets(
            ["h1", "h2"],
            lambda: self.execCmd("h1", "echo 'TEST' | nc 192.168.0.2 12345"))

        # stop netcat server
        self.execCmd("h2", "kill " + str(pid))

        packet = Packet()
        packet.ip_src = "192.168.0.1"
        packet.ip_dst = "192.168.0.2"
        packet.tcp_dst_port = 12345
        self.assertReceivedPacket(packet, "TCP Packet Received on h1", "h1")
        self.assertReceivedPacket(packet, "TCP Packet Received on h2", "h2")
    def test_timestamps(self):
        self.analyze_packets(["h1", "h3"], lambda: self.net.pingAll())
        packet_1_to_2 = Packet()
        packet_1_to_2.ip_src = "192.168.0.1"
        packet_1_to_2.ip_dst = "192.168.0.2"

        packet_3_to_4 = Packet()
        packet_3_to_4.ip_src = "192.168.0.3"
        packet_3_to_4.ip_dst = "192.168.0.4"
        time_1_to_2 = self.get_all_packets(packet_1_to_2, "h1")[0].time_stamp
        time_3_to_4 = self.get_all_packets(packet_3_to_4, "h3")[0].time_stamp
        self.assertTrue(
            time_3_to_4 > time_1_to_2,
            "Timestamp ordering ok. Ping from h1 to h2 is sent first.")
 def test_received_ip_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     packet.ip_src = "192.168.0.1"
     packet.ip_dst = "192.168.0.2"
     self.assertReceivedPacket(packet, "Received ip packet")
     packet1 = Packet()
     packet1.ip_src = "192.168.0.254"
     packet1.ip_dst = "192.168.0.2"
     self.assertNotReceivedPacket(packet1, "Not received packet from unknown ip.")
 def test_received_eth_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     packet.eth_src = "cc:cc:cc:cc:cc:01"
     packet.eth_dst = "cc:cc:cc:cc:cc:02"
     self.assertReceivedPacket(packet, "Received eth packet")
     packet1 = Packet()
     packet1.eth_src = "aa:aa:aa:aa:aa:aa"
     packet1.eth_dst = "cc:cc:cc:cc:cc:02"
     self.assertNotReceivedPacket(packet1, "Not received packet from switch.")
    def test_timestamps(self):
        self.analyze_packets(["h1", "h3"], lambda: self.net.pingAll())
        packet_1_to_2 = Packet()
        packet_1_to_2.ip_src = "192.168.0.1"
        packet_1_to_2.ip_dst = "192.168.0.2"

        packet_3_to_4 = Packet()
        packet_3_to_4.ip_src = "192.168.0.3"
        packet_3_to_4.ip_dst = "192.168.0.4"
        time_1_to_2 = self.get_all_packets(packet_1_to_2, "h1")[0].time_stamp
        time_3_to_4 = self.get_all_packets(packet_3_to_4, "h3")[0].time_stamp
        self.assertTrue(time_3_to_4 > time_1_to_2, "Timestamp ordering ok. Ping from h1 to h2 is sent first.")
Пример #11
0
 def test_ip_v6(self):
     self.analyze_packets(["h1", "h2"], lambda: self.net.pingAll())
     packet = Packet()
     packet.ip_version = 6
     packet.ip_dst = "ff02::16"
     self.assertReceivedPacket(packet, "Received IPv6-Packet", "h2")
Пример #12
0
    def test_received_eth_packet(self):
        host1, host2 = self.net.get("h1", "h2")
        self.analyze_packets(["h1", "h2"], lambda: self.net.ping(
            (host1, host2)))

        # Analyze packets on h1
        packet = Packet()
        packet.eth_src = "cc:cc:cc:cc:cc:01"
        packet.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertReceivedPacket(packet, "Received eth packet", "h1")
        packet1 = Packet()
        packet1.eth_src = "aa:aa:aa:aa:aa:aa"
        packet1.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertNotReceivedPacket(packet1,
                                     "Not received packet from switch.", "h1")

        # Analyze packets on h2
        packet3 = Packet()
        packet3.eth_src = "cc:cc:cc:cc:cc:01"
        packet3.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertReceivedPacket(packet3, "Received eth packet", "h2")
        packet4 = Packet()
        packet4.eth_src = "aa:aa:aa:aa:aa:aa"
        packet4.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertNotReceivedPacket(packet4,
                                     "Not received packet from switch.", "h2")
 def test_ip_v6(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     packet.ip_version = 6
     packet.ip_dst = "ff02::16"
     self.assertReceivedPacket(packet, "Received IPv6-Packet")
Пример #14
0
 def test_received_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     all_packets = self.get_all_packets(packet)
     self.assertTrue(len(all_packets) > 0, "all_packets returns packet.")
Пример #15
0
 def test_empty_ref_packet(self):
     self.analyze_packets("h1", lambda: self.net.pingAll())
     packet = Packet()
     self.assertReceivedPacket(
         packet, "Received packet. Used empty reference packet")
    def test_received_eth_packet(self):
        host1, host2 = self.net.get("h1", "h2")
        self.analyze_packets(["h1","h2"], lambda: self.net.ping((host1, host2)))

        # Analyze packets on h1
        packet = Packet()
        packet.eth_src = "cc:cc:cc:cc:cc:01"
        packet.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertReceivedPacket(packet, "Received eth packet", "h1")
        packet1 = Packet()
        packet1.eth_src = "aa:aa:aa:aa:aa:aa"
        packet1.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertNotReceivedPacket(packet1, "Not received packet from switch.", "h1")

        # Analyze packets on h2
        packet3 = Packet()
        packet3.eth_src = "cc:cc:cc:cc:cc:01"
        packet3.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertReceivedPacket(packet3, "Received eth packet", "h2")
        packet4 = Packet()
        packet4.eth_src = "aa:aa:aa:aa:aa:aa"
        packet4.eth_dst = "cc:cc:cc:cc:cc:02"
        self.assertNotReceivedPacket(packet4, "Not received packet from switch.", "h2")