diff options
-rw-r--r-- | python/samba/emulate/traffic.py | 24 | ||||
-rw-r--r-- | python/samba/tests/blackbox/testdata/traffic_replay-2.expected | 17 | ||||
-rw-r--r-- | python/samba/tests/blackbox/traffic_replay.py | 2 | ||||
-rwxr-xr-x | script/traffic_replay | 7 | ||||
-rw-r--r-- | selftest/knownfail.d/traffic | 2 |
5 files changed, 45 insertions, 7 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, diff --git a/script/traffic_replay b/script/traffic_replay index b25476cae4a..a02539ffa73 100755 --- a/script/traffic_replay +++ b/script/traffic_replay @@ -88,6 +88,10 @@ def main(): help=('Wait this long for last packet to finish')) model_group.add_option('-r', '--replay-rate', type='float', default=1.0, help='Replay the traffic faster by this factor') + model_group.add_option('--conversation-persistence', type='float', + default=0.0, + help=('chance (0 to 1) that a conversation waits ' + 'when it would have died')) model_group.add_option('--traffic-summary', help=('Generate a traffic summary file and write ' 'it here (- for stdout)')) @@ -262,7 +266,8 @@ def main(): model.generate_conversation_sequences( opts.scale_traffic, opts.duration, - opts.replay_rate) + opts.replay_rate, + opts.conversation_persistence) else: conversations = [] diff --git a/selftest/knownfail.d/traffic b/selftest/knownfail.d/traffic deleted file mode 100644 index 6fd64116d51..00000000000 --- a/selftest/knownfail.d/traffic +++ /dev/null @@ -1,2 +0,0 @@ -# This is in flux, so lets fail it for a while -samba.tests.blackbox.traffic_replay.samba.tests.blackbox.traffic_replay.TrafficLearnerTests.test_summary_generation |