1 #!/usr/bin/env python2.5
14 os
.environ
["PATH"] += ":../switzerland/client/"
16 from switzerland
.common
import util
17 from switzerland
.common
import local_ip
18 from switzerland
.client
import Alice
19 from switzerland
.client
.AliceConfig
import AliceConfig
20 from switzerland
.client
.AliceLink
import LocalAliceLink
21 from switzerland
.server
import Switzerland
22 from switzerland
.server
.SwitzerlandConfig
import SwitzerlandConfig
25 class PcapPlayback(unittest
.TestCase
):
27 Inherit from this class to create tests by playing back PCAP logs.
31 self
.port
= random
.randint(17000,18000)
32 self
.server
= Switzerland
.SwitzerlandMasterServer(SwitzerlandConfig(port
=self
.port
, keep_threads
=True, keep_reconciliators
=True, seriousness
=seriousness_threshold
, allow_fake_ips
=True))
33 util
.ThreadLauncher(self
.server
.accept_connections
).start()
38 def pcap_playback(self
, filename1
, ip_in_pcap1
, filename2
, ip_in_pcap2
, skew_pcap2
, playback_offset
=0, keep_archives
=False, force_public_ip1
=False, force_public_ip2
=False):
39 ip
= local_ip
.get_local_ip()
40 localhost
= "127.0.0.1"
42 print "Can't run system tests without a non-localhost interface!!"
45 # We turn the packet filter off, because it would require extra waiting
46 # mechanisms for the new-members messages to arrive in time for the
47 # filtering mechanism. NTP is off because we don't need it. Cleaning has
48 # to be off because the timestamps in the pcaps are antique.
49 if not force_public_ip1
:
50 public_ip1
= ip_in_pcap1
52 public_ip1
= force_public_ip1
54 client1
= Alice
.Alice(linkobj
=LocalAliceLink
,\
55 config
=AliceConfig(host
="localhost", port
=self
.port
, use_ntp
=False,\
56 do_cleaning
=False, seriousness
=seriousness_threshold
,\
57 filter_packets
=False, keep_archives
=keep_archives
,\
58 force_public_ip
=public_ip1
, pcap_playback
=filename1
,\
59 force_private_ip
=ip_in_pcap1
, logfile
=None, pcap_logdir
=None))
61 if not force_public_ip2
:
62 public_ip2
= ip_in_pcap2
64 public_ip2
= force_public_ip2
66 client2
= Alice
.Alice(\
67 config
=AliceConfig(host
=ip
, port
=self
.port
, use_ntp
=False,\
68 do_cleaning
=False, seriousness
=seriousness_threshold
, skew
=skew_pcap2
,\
69 filter_packets
=False, keep_archives
=keep_archives
,\
70 force_public_ip
=public_ip2
, pcap_playback
=filename2
,\
71 force_private_ip
=ip_in_pcap2
, logfile
=None, \
74 # if we have a negative playback_offset, switch the order of events
75 if playback_offset
< 0.0:
77 client1
, client2
= client2
, client1
78 client2
.listener
.start()
80 time
.sleep(playback_offset
)
81 client1
.listener
.start()
83 client1
.listener
.done
.wait()
84 client2
.listener
.done
.wait()
86 seriousness_threshold
= 0
90 pos
= sys
.argv
.index("-s")
92 # unittest does things with argv, so lets get there first :)
93 global seriousness_threshold
94 seriousness_threshold
= int(sys
.argv
[pos
+1])
95 print "Setting Debug Seriousness to", seriousness_threshold
96 del sys
.argv
[pos
:pos
+2] # deletes 2 args