Mercurial > stress-tester
changeset 1230:1006020f834f
flow - in progress
author | Devel 1 |
---|---|
date | Fri, 26 Jun 2020 12:55:28 +0200 |
parents | 38535d18ed51 |
children | caea6899e63a |
files | stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerCommand.java stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java stress-tester/src/main/resources/flow_analyzer.py |
diffstat | 3 files changed, 49 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerCommand.java Fri Jun 26 08:32:57 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerCommand.java Fri Jun 26 12:55:28 2020 +0200 @@ -23,6 +23,7 @@ public static final float DEFAULT_PMIN = 0.005f; public static final int DEFAULT_LMIN = 3; public static final int DEFAULT_LMAX = 7; + public static final int DEFAULT_MAX_SEQ = 10; public static final boolean DEFAULT_FOLD = false; String pythonCmd = DEFAULT_PYTHON_CMD; @@ -31,6 +32,7 @@ float pmin = DEFAULT_PMIN; int lmin = DEFAULT_LMIN; int lmax = DEFAULT_LMAX; + int maxSeq = DEFAULT_MAX_SEQ; boolean fold = DEFAULT_FOLD; List<String> cleanRules; @@ -42,7 +44,8 @@ List<String> commandLine = new ArrayList<>(); commandLine.addAll(Arrays.asList( pythonCmd, scriptPath, dataPath, "-pmin", Float.toString(pmin), - "-lmin", Integer.toString(lmin), "-lmax", Integer.toString(lmax) + "-lmin", Integer.toString(lmin), "-lmax", Integer.toString(lmax), + "-maxSeq", Integer.toString(maxSeq) )); if (fold) { commandLine.add("--fold");
--- a/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java Fri Jun 26 08:32:57 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java Fri Jun 26 12:55:28 2020 +0200 @@ -71,6 +71,7 @@ command.pmin = config.getFloat("pmin", FlowAnalyzerCommand.DEFAULT_PMIN); command.lmin = config.getInteger("lmin", FlowAnalyzerCommand.DEFAULT_LMIN); command.lmax = config.getInteger("lmax", FlowAnalyzerCommand.DEFAULT_LMAX); + command.maxSeq = config.getInteger("maxSeq", FlowAnalyzerCommand.DEFAULT_MAX_SEQ); command.fold = config.getBoolean("fold", FlowAnalyzerCommand.DEFAULT_FOLD); command.cleanRules = config.getList("cleanRules"); } @@ -245,7 +246,8 @@ tupleDef("fold", BOOLEAN_DEF).setRequired(false), tupleDef("pmin", FLOAT_GREATER_EQUAL_ZERO_DEF).setRequired(false), tupleDef("lmin", INT_GREATER_THAN_ZERO_DEF).setRequired(false), - tupleDef("lmax", INT_GREATER_THAN_ZERO_DEF).setRequired(false) + tupleDef("lmax", INT_GREATER_THAN_ZERO_DEF).setRequired(false), + tupleDef("maxSeq", INT_GREATER_THAN_ZERO_DEF).setRequired(false) ); } }
--- a/stress-tester/src/main/resources/flow_analyzer.py Fri Jun 26 08:32:57 2020 +0200 +++ b/stress-tester/src/main/resources/flow_analyzer.py Fri Jun 26 12:55:28 2020 +0200 @@ -617,10 +617,10 @@ def find_sub_list(haystack, needle): - results=[] - sll=len(needle) - for ind in (i for i,e in enumerate(haystack) if e == needle[0]): - if haystack[ind:ind + sll]==needle: + results = [] + sll = len(needle) + for ind in (i for i, e in enumerate(haystack) if e == needle[0]): + if haystack[ind: ind + sll] == needle: results.append(ind) return results @@ -644,9 +644,20 @@ def expand(seqs, folds): - print("seqs\n", json.dumps(seqs)) - print("folds\n", json.dumps(folds)) - return [] + # print('{\n"seqs" :', json.dumps(seqs), ",") + # print('"folds": ', json.dumps(folds), "\n}\n") + results = [] + for seq in seqs: + results.append(seq) + # print("processing ", seq) + for repl, needle, x, y in folds: + locs = find_sub_list(seq, needle) + if len(locs) > 0: + newseq = seq.copy() + replace_sublist(newseq, needle, repl, locs[0]) + results.append(newseq) + # print(seq, needle, locs, repl, ' => ', newseq) + return results if __name__ == "__main__": @@ -658,6 +669,7 @@ parser.add_argument('-pmin', type=float, default=0.005) parser.add_argument('-lmin', type=int, default=3) parser.add_argument('-lmax', type=int, default=7) + parser.add_argument('-maxSeq', type=int, default=100) parser.add_argument('--fold', action='store_true') args = parser.parse_args() @@ -682,16 +694,32 @@ if args.fold: suffix = '_fold' res = analyzer.analyze_markov_fold(targetLength=length, foldLoops=True) - seqs = [(s, prob) for s, prob in res if prob >= args.pmin] - folds = analyzer.markovLoopsMapped - out = expand(seqs, folds) + seqs_prob = [(s, prob) for s, prob in res if prob >= args.pmin] + seqs_only = [s for s, prob in res if prob >= args.pmin] + seqs = expand(seqs_only, analyzer.markovLoopsMapped) + stats = { + 'seqCount': len(res), + 'seqCountP': len(seqs_only), + 'loopCount': len(analyzer.markovLoopsMapped), + 'expandedCount': len(seqs) + } + seqs_prob = seqs_prob[:args.maxSeq] + seqs_only = seqs_only[:args.maxSeq] else: suffix = '' res = analyzer.analyze_markov(targetLength=length) - seqs = [(s, prob) for s, prob in res if prob >= args.pmin] - out = [s for s, prob in res if prob >= args.pmin] + seqs_prob = [(s, prob) for s, prob in res if prob >= args.pmin] + seqs = [s for s, prob in res if prob >= args.pmin] + stats = { + 'seqCount': len(res), + 'seqCountP': len(seqs) + } + seqs = seqs[:args.maxSeq] + seqs_prob = seqs_prob[:args.maxSeq] + with open("seq_L{}{}_stats.json".format(length, suffix), "w") as f: + json.dump(stats, f) with open("seq_L{}{}_prob.json".format(length, suffix), "w") as f: + json.dump(seqs_prob, f) + with open("seq_L{}{}.json".format(length, suffix), "w") as f: json.dump(seqs, f) - with open("seq_L{}{}.json".format(length, suffix), "w") as f: - json.dump(out, f)