summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2018-10-23 11:58:52 +1300
committerDouglas Bagnall <dbagnall@samba.org>2019-01-08 23:55:34 +0100
commit524777e681b1fecf5686843f10ae01637285a891 (patch)
tree28f4579a468ad8e4a4750fb52dd7e0aedd261093 /python
parentbda7f35a5e1418a3e9d4f582f72d2bbe9cb10f44 (diff)
downloadsamba-524777e681b1fecf5686843f10ae01637285a891.tar.gz
traffic: add option to reanimate dying conversations
The traffic model is generated from a window in time, which makes conversations appear to start and stop unnaturally at the window boundaries. When the window is short compared to the traffic replay time and the true expected conversation length, this has a significant distorting effect, leading to more conversations than would be expected to generate a given number of packets. To offset this slightly we add the --conversation-persistence option which tries to convert apparent death into a longish wait. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r--python/samba/emulate/traffic.py24
-rw-r--r--python/samba/tests/blackbox/testdata/traffic_replay-2.expected17
-rw-r--r--python/samba/tests/blackbox/traffic_replay.py2
3 files changed, 39 insertions, 4 deletions
diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py
index 448cacfda41..76c39efba56 100644
--- a/python/samba/emulate/traffic.py
+++ b/python/samba/emulate/traffic.py
@@ -1226,7 +1226,8 @@ class TrafficModel(object):
def construct_conversation_sequence(self, timestamp=0.0,
hard_stop=None,
replay_speed=1,
- ignore_before=0):
+ ignore_before=0,
+ persistence=0):
"""Construct an individual conversation packet sequence from the
model.
"""
@@ -1238,7 +1239,15 @@ class TrafficModel(object):
while True:
p = random.choice(self.ngrams.get(key, (NON_PACKET,)))
if p == NON_PACKET:
- break
+ if timestamp < ignore_before:
+ break
+ if random.random() > persistence:
+ print("ending after %s (persistence %.1f)" % (key, persistence),
+ file=sys.stderr)
+ break
+
+ p = 'wait:%d' % random.randrange(5, 12)
+ print("trying %s instead of end" % p, file=sys.stderr)
if p in self.query_details:
extra = random.choice(self.query_details[p])
@@ -1260,10 +1269,16 @@ class TrafficModel(object):
c.append((timestamp, protocol, opcode, extra))
key = key[1:] + (p,)
+ if key[-2][:5] == 'wait:' and key[-1][:5] == 'wait:':
+ # two waits in a row can only be caused by "persistence"
+ # tricks, and will not result in any packets being found.
+ # Instead we pretend this is a fresh start.
+ key = (NON_PACKET,) * (self.n - 1)
return c
- def generate_conversation_sequences(self, scale, duration, replay_speed=1):
+ def generate_conversation_sequences(self, scale, duration, replay_speed=1,
+ persistence=0):
"""Generate a list of conversation descriptions from the model."""
# We run the simulation for ten times as long as our desired
@@ -1280,7 +1295,8 @@ class TrafficModel(object):
c = self.construct_conversation_sequence(start,
hard_stop=duration,
replay_speed=replay_speed,
- ignore_before=0)
+ ignore_before=0,
+ persistence=persistence)
# will these "packets" generate actual traffic?
# some (e.g. ldap unbind) will not generate anything
# if the previous packets are not there, and if the
diff --git a/python/samba/tests/blackbox/testdata/traffic_replay-2.expected b/python/samba/tests/blackbox/testdata/traffic_replay-2.expected
new file mode 100644
index 00000000000..7850a255043
--- /dev/null
+++ b/python/samba/tests/blackbox/testdata/traffic_replay-2.expected
@@ -0,0 +1,17 @@
+0.011388 06 2 1 ldap 3 searchRequest 2 DC,DC cn
+0.221447 06 2 1 ldap 2 unbindRequest
+0.460878 06 3 1 ldap 3 searchRequest 2 DC,DC cn
+0.581933 11 4 1 cldap 3 searchRequest Netlogon
+0.596977 11 4 1 cldap 3 searchRequest Netlogon
+0.611184 11 4 1 cldap 3 searchRequest Netlogon
+0.666808 06 3 1 ldap 2 unbindRequest
+0.692730 11 5 1 cldap 3 searchRequest Netlogon
+0.692879 11 5 1 cldap 3 searchRequest Netlogon
+0.692946 11 5 1 cldap 3 searchRequest Netlogon
+0.744297 06 4 1 rpc_netlogon 29 NetrLogonGetDomainInfo
+0.768994 06 4 1 kerberos
+0.772476 06 4 1 ldap 3 searchRequest 2 DC,DC cn
+0.827760 06 5 1 rpc_netlogon 29 NetrLogonGetDomainInfo
+0.828419 06 5 1 kerberos
+0.862850 06 5 1 ldap 3 searchRequest subschemaSubentry,dsServiceName,namingContexts,defaultNamingContext,schemaNamingContext,configurationNamingContext,rootDomainNamingContext,supportedControl,supportedLDAPVersion,supportedLDAPPolicies,supportedSASLMechanisms,dnsHostName,ldapServiceName,serverName,supportedCapabilities
+0.865384 06 6 1 ldap 3 searchRequest subschemaSubentry,dsServiceName,namingContexts,defaultNamingContext,schemaNamingContext,configurationNamingContext,rootDomainNamingContext,supportedControl,supportedLDAPVersion,supportedLDAPPolicies,supportedSASLMechanisms,dnsHostName,ldapServiceName,serverName,supportedCapabilities
diff --git a/python/samba/tests/blackbox/traffic_replay.py b/python/samba/tests/blackbox/traffic_replay.py
index 4e9783ec515..8370939d243 100644
--- a/python/samba/tests/blackbox/traffic_replay.py
+++ b/python/samba/tests/blackbox/traffic_replay.py
@@ -70,6 +70,8 @@ class TrafficLearnerTests(BlackboxTestCase):
for i, opts in enumerate((["--random-seed=3"],
["--random-seed=4"],
+ ["--random-seed=3",
+ "--conversation-persistence=0.5"],
)):
with temp_file(self.tempdir) as output:
command = ([SCRIPT, MODEL,