def test_ipv4_time(self): """Test the timestamp setting facility.""" import time file = PcapConnector("loopping.out") packet = file.readpkt() ip = packet.data self.assertEqual(packet.timestamp, ip.timestamp, "lower and upper layer timestamps are different but should not be")
def test_ipv4_time(self): """Test the timestamp setting facility.""" import time file = PcapConnector("loopping.out") packet = file.readpkt() ip = packet.data self.assertEqual( packet.timestamp, ip.timestamp, "lower and upper layer timestamps are different but should not be")
def test_pcap_read(self): """This test reads from a pre-stored pcap file generated with tcpdump and ping on the loopback interface.""" file = PcapConnector("etherping.out") ether = file.readpkt() assert (ether != None) self.assertEqual(ether.dst, "\x00\x10\xdb\x3a\x3a\x77", "dst not equal %s" % ether.src) self.assertEqual(ether.src, "\x00\x0d\x93\x44\xfa\x62", "src not equal %s" % ether.dst) self.assertEqual(ether.type, 0x800, "type not equal %d" % ether.type)
def test_pcap_read(self): """This test reads from a pre-stored pcap file generated with tcpdump and ping on the loopback interface.""" file = PcapConnector("etherping.out") ether = file.readpkt() assert (ether != None) self.assertEqual(ether.dst, "\x00\x10\xdb\x3a\x3a\x77", "dst not equal %s" % ether.src) self.assertEqual(ether.src, "\x00\x0d\x93\x44\xfa\x62", "src not equal %s" % ether.dst) self.assertEqual(ether.type, 0x800, "type not equal %d" % ether.type)
def test_map(self): # We're going to replace the higher layer protocol with the NULL # protocol. (Actually we're replacing it with Folger's Crystals.) """This test reads from a pre-stored pcap file generated with tcpdump and ping on an ethernet interface and tests the __str__ method to make sure the correct values are printed.""" file = PcapConnector("etherping.out") packet = file.readpkt() self.assertEqual(type(packet.data), ipv4) file.close # Replace the mapping of IPv4 ethernet_map.map[ethernet_map.ETHERTYPE_IP] = null file = PcapConnector("etherping.out") packet = file.readpkt() self.assertEqual(type(packet.data), null) file.close
def test_map(self): # We're going to replace the higher layer protocol with the NULL # protocol. (Actually we're replacing it with Folger's Crystals.) """This test reads from a pre-stored pcap file generated with tcpdump and ping on an ethernet interface and tests the __str__ method to make sure the correct values are printed.""" file = PcapConnector("etherping.out") packet = file.readpkt() self.assertEqual(type(packet.data), ipv4) file.close # Replace the mapping of IPv4 ethernet_map.map[ethernet_map.ETHERTYPE_IP] = null file = PcapConnector("etherping.out") packet = file.readpkt() self.assertEqual(type(packet.data), null) file.close
def test_ipv4_compare(self): """Test the underlying __compare__ functionality of the packet. Two packets constructed from the same bytes should be equal and two that are not should not be equal.""" file = PcapConnector("loopping.out") packet = file.readpkt() ip1 = packet.data ip2 = ipv4(packet.data.bytes) assert (ip1 != None) assert (ip2 != None) self.assertEqual(ip1, ip2, "packets should be equal but are not") ip1.dst = 0xffffffffL self.assertNotEqual(ip1, ip2, "packets compare equal but should not")
def test_ipv4_compare(self): """Test the underlying __compare__ functionality of the packet. Two packets constructed from the same bytes should be equal and two that are not should not be equal.""" file = PcapConnector("loopping.out") packet = file.readpkt() ip1 = packet.data ip2 = ipv4(packet.data.bytes) assert (ip1 != None) assert (ip2 != None) self.assertEqual(ip1, ip2, "packets should be equal but are not") ip1.dst = 0xffffffffL self.assertNotEqual(ip1, ip2, "packets compare equal but should not")
def test_sctp_read(self): """Read a packet from a pcap file.""" file = PcapConnector("sctp.pcap") packet = file.readpkt() sctp = packet.data.data assert (sctp != None) expected = "<SCTP common header class: sport: 16384, dport: 2944, " \ "tag: 93962, checksum: 1840257154>" got = sctp.println() self.assertEqual(expected, got, \ "strings are not equal \nexpected %s \ngot %s " % \ (expected, got))
def test_sctp_read(self): """Read a packet from a pcap file.""" file = PcapConnector("sctp.pcap") packet = file.readpkt() sctp = packet.data.data assert (sctp != None) expected = "<SCTP common header class: sport: 16384, dport: 2944, " \ "tag: 93962, checksum: 1840257154>" got = sctp.println() self.assertEqual(expected, got, \ "strings are not equal \nexpected %s \ngot %s " % \ (expected, got))
def test_dhcpv4_decode(self): """This test reads from a pre-stored pcap file.""" file = PcapConnector("dhcp_minimal.pcap") packet = file.readpkt() chain = packet.chain() #print chain ether = chain.packets[0] assert (ether != None) ip = chain.packets[1] assert (ip != None) udp = chain.packets[2] assert (udp != None) dhcp = chain.packets[3] assert (dhcp != None) self.assertEqual(dhcp.op, 1, "op not equal") self.assertEqual(dhcp.xid, 0xffff0001, "xid not equal") self.assertEqual(dhcp.secs, 42848, "secs not equal") self.assertEqual(dhcp.flags, 0x8000, "flags not equal") mac = ether_atob("52:54:00:12:34:56") #print ether_btoa(dhcp.chaddr) self.assertEqual(dhcp.chaddr[:dhcp.hlen], mac, "mac not equal") self.assertEqual( len(dhcp.options), 6, "wrong option field count %d should be %d" % (len(dhcp.options), 6)) # Not a tlv field self.assertEqual(dhcp.options[0], pcs.packets.dhcpv4_options.DHCP_OPTIONS_COOKIE, "invalid cookie value") # TLV fields self.assertEqual(dhcp.options[1].value, 1460, "invalid maximum message size value") self.assertEqual(dhcp.options[2].value, "FreeBSD:i386:6.3-RELEASE", \ "invalid vendor class") self.assertEqual(dhcp.options[3].value, pcs.packets.dhcpv4_options.DHCPDISCOVER, "invalud dhcp message type") # Not a tlv field self.assertEqual(dhcp.options[4], pcs.packets.dhcpv4_options.DHO_END, "invalid end value")
def test_dhcpv4_decode(self): """This test reads from a pre-stored pcap file.""" file = PcapConnector("dhcp_minimal.pcap") packet = file.readpkt() chain = packet.chain() #print chain ether = chain.packets[0] assert (ether != None) ip = chain.packets[1] assert (ip != None) udp = chain.packets[2] assert (udp != None) dhcp = chain.packets[3] assert (dhcp != None) self.assertEqual(dhcp.op, 1, "op not equal") self.assertEqual(dhcp.xid, 0xffff0001, "xid not equal") self.assertEqual(dhcp.secs, 42848, "secs not equal") self.assertEqual(dhcp.flags, 0x8000, "flags not equal") mac = ether_atob("52:54:00:12:34:56") #print ether_btoa(dhcp.chaddr) self.assertEqual(dhcp.chaddr[:dhcp.hlen], mac, "mac not equal") self.assertEqual(len(dhcp.options), 6, "wrong option field count %d should be %d" % (len(dhcp.options), 6)) # Not a tlv field self.assertEqual(dhcp.options[0], pcs.packets.dhcpv4_options.DHCP_OPTIONS_COOKIE, "invalid cookie value") # TLV fields self.assertEqual(dhcp.options[1].value, 1460, "invalid maximum message size value") self.assertEqual(dhcp.options[2].value, "FreeBSD:i386:6.3-RELEASE", \ "invalid vendor class") self.assertEqual(dhcp.options[3].value, pcs.packets.dhcpv4_options.DHCPDISCOVER, "invalud dhcp message type") # Not a tlv field self.assertEqual(dhcp.options[4], pcs.packets.dhcpv4_options.DHO_END, "invalid end value")