changeset 1251:974d2217d08c

flow - bugfixes
author Devel 1
date Wed, 01 Jul 2020 14:30:20 +0200
parents 0aaec16bfed7
children aa5ba90755dd
files stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerUtils.java stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java stress-tester/src/main/java/com/passus/st/scanner/SequenceConverter.java stress-tester/src/main/resources/flow_analyzer.py
diffstat 4 files changed, 30 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerUtils.java	Wed Jul 01 13:59:15 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerUtils.java	Wed Jul 01 14:30:20 2020 +0200
@@ -21,7 +21,7 @@
         }
     }
 
-    static final class SeqWithFolds {
+    static final class SequenceWithFolds {
 
         public ArrayList<String> sequence;
         public float prob;
@@ -31,14 +31,26 @@
     static final class AnalyzerResult {
 
         public String[] ignoredUrls;
-        public SeqWithFolds[] sequences;
-        
-        public ArrayList<ArrayList<String>> getSequences() {
+        public SequenceWithFolds[] sequences;
+
+        public ArrayList<ArrayList<String>> getSequences(boolean fold) {
+            return fold ? getSequencesFold() : getSequencesNoFold();
+        }
+
+        public ArrayList<ArrayList<String>> getSequencesNoFold() {
             ArrayList<ArrayList<String>> result = new ArrayList<>(sequences.length);
-            for (SeqWithFolds sequence : sequences) {
+            for (SequenceWithFolds sequence : sequences) {
                 result.add(sequence.sequence);
             }
             return result;
         }
+
+        public ArrayList<ArrayList<String>> getSequencesFold() {
+            ArrayList<ArrayList<String>> result = new ArrayList<>();
+            for (SequenceWithFolds sequence : sequences) {
+                result.addAll(sequence.unfolded);
+            }
+            return result;
+        }
     }
 }
--- a/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java	Wed Jul 01 13:59:15 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java	Wed Jul 01 14:30:20 2020 +0200
@@ -157,7 +157,7 @@
                 Matcher m = pattern.matcher(fname);
                 if (m.matches()) {
                     FlowAnalyzerUtils.AnalyzerResult result = FlowAnalyzerUtils.readResult(new File(dir, fname), gson);
-                    metric.addSequences(m.group(1), result.getSequences());
+                    metric.addSequences(m.group(1), result.getSequencesNoFold());
                 }
             }
 
--- a/stress-tester/src/main/java/com/passus/st/scanner/SequenceConverter.java	Wed Jul 01 13:59:15 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/scanner/SequenceConverter.java	Wed Jul 01 14:30:20 2020 +0200
@@ -126,19 +126,10 @@
                 return;
             }
             File output = new File(clArgs[1]);
-            if (!output.isFile()) {
-                System.err.println("Not a file: " + output.getAbsolutePath());
-                return;
-            }
 
             boolean fold = cl.hasOption('f');
-            ArrayList<ArrayList<String>> sequences;
             FlowAnalyzerUtils.AnalyzerResult result = FlowAnalyzerUtils.readResult(input, new Gson());
-            if (fold) {
-                sequences = result.sequences[1].unfolded;
-            } else {
-                sequences = result.getSequences();
-            }
+            ArrayList<ArrayList<String>> sequences = result.getSequences(fold);
 
             SequenceConverter converter = new SequenceConverter();
             converter.writeSequenceFilterConf(sequences, Arrays.asList(result.ignoredUrls), output);
--- a/stress-tester/src/main/resources/flow_analyzer.py	Wed Jul 01 13:59:15 2020 +0200
+++ b/stress-tester/src/main/resources/flow_analyzer.py	Wed Jul 01 14:30:20 2020 +0200
@@ -702,14 +702,18 @@
     analyzer.prep_sequences(dropDuplicates=True)
 
     for length in range(args.lmin, args.lmax + 1):
+        res = analyzer.analyze(targetLength=length, foldLoops=args.fold)
+        seqs_prob = [(s, prob) for s, prob in res if prob >= args.pmin]
+        stats = {
+            'seqCount': len(res),
+            'seqCountP': len(seqs_prob)
+        }
+
         if args.fold:
-            suffix = 'f'
-            res = analyzer.analyze(targetLength=length, foldLoops=True)
-            seqs_prob = [(s, prob) for s, prob in analyzer.analyzed if prob >= args.pmin]
-
+            seqs_ids = [(s, prob) for s, prob in analyzer.analyzed if prob >= args.pmin]
             unfolded = []
             num_unfolded = 0
-            for (s, prob) in seqs_prob:
+            for (s, prob) in seqs_ids:
                 seq_mapped = analyzer.seq_id_to_path(s)
                 si = [int(x) for x in s]
                 unfolded_ids = analyzer.get_unfolded(si)
@@ -721,30 +725,20 @@
                 })
                 num_unfolded += len(unfolded_ids)
 
-            stats = {
-                'seqCount': len(res),
-                'seqCountP': len(seqs_prob),
-                'unfoldedCount': num_unfolded
-            }
+            stats['unfoldedCount'] = num_unfolded
             unfolded = unfolded[:args.maxSeq]
             out = {
                 'ignoredUrls': args.c,
                 'sequences': unfolded
             }
         else:
-            suffix = ''
-            res = analyzer.analyze_markov(targetLength=length)
-            seqs_prob = [(s, prob) for s, prob in res if prob >= args.pmin]
-            stats = {
-                'seqCount': len(res),
-                'seqCountP': len(seqs_prob)
-            }
             seqs_prob = seqs_prob[:args.maxSeq]
             out = {
                 'ignoredUrls': args.c,
                 'sequences': [{'sequence': seq, 'prob': prob} for seq, prob in seqs_prob]
             }
 
+        suffix = 'f' if args.fold else ''
         # for metrics and generator
         with open("seq_L{}{}_out.json".format(length, suffix), "w") as f:
             json.dump(out, f)