Ticket #21: test_gre.py

File test_gre.py, 1.3 kB (added by zer0@droids-corp.org, 2 years ago)

Some tests for GRE

Line 
1 # Test the GRE protocol (after applying the patch)
2 # It displays GRE packets in scapy and generate a
3 # pcap file that can be opened by wireshark
4 #
5 # To launch this test : launche scapy, then
6 # >>> execfile("test_gre.py")
7
8 plist=[]
9
10 # correct packets
11 plist.append(Ether()/IP()/GRE()/"tototiti")
12 plist.append(Ether()/IP()/GRE(chksum_present=1)/"tototiti")
13 plist.append(Ether()/IP()/GRE(key_present=1,chksum_present=1,key=0x1337beef)/"tototiti")
14 plist.append(Ether()/IP()/GRE(seqnum_present=1, seqence_number=123456789)/"tototiti")
15 plist.append(Ether()/IP()/GRE(routing_present=1)/GRErouting(address_family=1, SRE_len=4, routing_info="abcd")/GRErouting()/"tototiti")
16
17 # test str <-> packet conversion
18 for p in plist:
19     print "-----------------------------------"
20     Ether(str(p)).show()
21
22 # malformed packets
23 plist.append(Ether()/IP()/GRE(chksum_present=1, chksum=0xcafe)/"BAD CHECKSUM")
24 plist.append(Ether()/IP()/GRE(routing_present=1)/GRErouting(address_family=1, SRE_len=4, routing_info="abcd")/"BAD GRE routing info")
25
26 # Because of ConditionalField, we cannot generate the
27 # following packets... is there an issue ?
28 plist.append(Ether()/IP()/GRE(seqnum_present=0, seqence_number=123456789)/"pouet")
29 plist.append(Ether()/IP()/GRE(chksum_present=0, chksum=0xcafe)/"coin")
30
31 wrpcap("scapy_gre.pcap", PacketList(plist))