Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.protocol-fuzzing</groupId>
<artifactId>protocol-state-fuzzer</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>

<name>Protocol State Fuzzer</name>
<description>A generic, modular, and extensible protocol state fuzzer for network protocol implementations.</description>
Expand Down Expand Up @@ -75,7 +75,7 @@
<jconstraints.version>0.9.9</jconstraints.version>
<junit.version>4.13.2</junit.version>
<learnlib-tooling.version>0.1.1</learnlib-tooling.version>
<learnlib.version>0.18.0</learnlib.version>
<learnlib.version>19.0.0</learnlib.version>
<log4j.version>2.26.1</log4j.version>
<ralib.version>0.1</ralib.version>
<spotbugs-annotations.version>4.10.5</spotbugs-annotations.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class WpEQSequenceGenerator<I, D, S> {

/** Stores the constructor parameter. */
protected UniversalDeterministicAutomaton<S, I, ?, ?, ?> automaton;
protected UniversalDeterministicAutomaton.RegularAutomaton<S, I, ?, ?, ?> automaton;

/** Stores the constructor parameter. */
protected Collection<? extends I> inputs;
Expand All @@ -54,7 +54,7 @@ public class WpEQSequenceGenerator<I, D, S> {
* @param inputs the inputs of the automaton
*/
public WpEQSequenceGenerator(
UniversalDeterministicAutomaton<S, I, ?, ?, ?> automaton,
UniversalDeterministicAutomaton.RegularAutomaton<S, I, ?, ?, ?> automaton,
Collection<? extends I> inputs) {

this.automaton = automaton;
Expand Down Expand Up @@ -100,7 +100,7 @@ public static <S, I> Map<S, List<PredStruct<S, I>>> computePredecessorMap(
* @return the list of global suffixes
*/
private List<Word<I>> computeGlobalSuffixes(
UniversalDeterministicAutomaton<S, I, ?, ?, ?> automaton,
UniversalDeterministicAutomaton.RegularAutomaton<S, I, ?, ?, ?> automaton,
Collection<? extends I> inputs) {

List<Word<I>> globalSuffixes = new ArrayList<>();
Expand All @@ -117,7 +117,7 @@ private List<Word<I>> computeGlobalSuffixes(
* @return the list of local suffixes
*/
private MutableMapping<S, List<Word<I>>> computeLocalSuffixSets(
UniversalDeterministicAutomaton<S, I, ?, ?, ?> automaton,
UniversalDeterministicAutomaton.RegularAutomaton<S, I, ?, ?, ?> automaton,
Collection<? extends I> inputs) {

MutableMapping<S, List<Word<I>>> localSuffixSets = automaton.createStaticStateMapping();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.protocolfuzzing.protocolstatefuzzer.components.learner.statistics;

import de.learnlib.filter.statistic.Counter;
import de.learnlib.statistic.StatisticsKey;
import io.github.protocolfuzzing.protocolstatefuzzer.statefuzzer.core.config.StateFuzzerEnabler;
import net.automatalib.alphabet.Alphabet;

Expand All @@ -9,6 +9,7 @@
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
* Tracks learning related statistics during the learning process.
Expand All @@ -21,10 +22,10 @@
public abstract class StatisticsTracker<I, ID, OD, CE> {

/** Stores the constructor parameter. */
protected Counter inputCounter;
protected List<StatisticsKey> inputStatisticsKeys;

/** Stores the constructor parameter. */
protected Counter testCounter;
protected List<StatisticsKey> testStatisticsKeys;

/** Stores the Statistics instance that is being updated. */
protected Statistics<I, ID, OD, CE> statistics;
Expand Down Expand Up @@ -59,12 +60,25 @@ protected enum State {
/**
* Creates a new instance from the given parameters.
*
* @param inputCounter counter updated on every input of membership and equivalence queries
* @param testCounter counter updated on every membership and equivalence query (also named test)
* @param inputStatisticsKey key for counter updated on every input of membership and equivalence queries
* @param testStatisticsKey key for counter updated on every membership and equivalence query (also named test)
*/
public StatisticsTracker(Counter inputCounter, Counter testCounter) {
this.inputCounter = inputCounter;
this.testCounter = testCounter;
public StatisticsTracker(StatisticsKey inputStatisticsKey, StatisticsKey testStatisticsKey) {
this.inputStatisticsKeys = List.of(inputStatisticsKey);
this.testStatisticsKeys = List.of(testStatisticsKey);
}

/**
* Creates a new instance from the given parameters.
* <p>
* This should be used when values of multiple counters should be aggregated to a single value
*
* @param inputStatisticsKeys keys for counter updated on every input of membership and equivalence queries
* @param testStatisticsKeys keys for counter updated on every membership and equivalence query (also named test)
*/
public StatisticsTracker(List<StatisticsKey> inputStatisticsKeys, List<StatisticsKey> testStatisticsKeys) {
this.inputStatisticsKeys = inputStatisticsKeys;
this.testStatisticsKeys = testStatisticsKeys;
}

/**
Expand Down Expand Up @@ -175,19 +189,34 @@ public void startLearning(StateFuzzerEnabler stateFuzzerEnabler, Alphabet<I> alp
logStateChange(State.REFINEMENT);
}

/**
* Returns the aggregated value of the counters behind the provided keys
*
* @param keys the keys to be used for the default StatisticsService
*
* @return the aggregated value
*/
protected long getCount(List<StatisticsKey> keys) {
long total = 0;
for (StatisticsKey key: keys) {
total += de.learnlib.statistic.Statistics.getService().getCount(key).orElse(0L);
}
return total;
}

/**
* Should be called every time learning produces a new hypothesis.
*
* @param hypothesis the new hypothesis that has been found
*/
public void newHypothesis(StateMachineWrapper<ID, OD> hypothesis) {
long lastHypTests = testCounter.getCount();
long lastHypTests = getCount(testStatisticsKeys);
statistics.setLastHypTests(lastHypTests);

long newLearnTests = statistics.getLearnTests() + lastHypTests - lastCETests;
statistics.setLearnTests(newLearnTests);

long lastHypInputs = inputCounter.getCount();
long lastHypInputs = getCount(inputStatisticsKeys);
statistics.setLastHypInputs(lastHypInputs);

long newLearnInputs = statistics.getLearnInputs() + lastHypInputs - lastCEInputs;
Expand All @@ -208,8 +237,8 @@ public void newHypothesis(StateMachineWrapper<ID, OD> hypothesis) {
* @param counterexample the new counterexample that has been found
*/
public void newCounterExample(CE counterexample) {
lastCETests = testCounter.getCount();
lastCEInputs = inputCounter.getCount();
lastCETests = getCount(testStatisticsKeys);
lastCEInputs = getCount(inputStatisticsKeys);

statistics.getCounterexamples().add(counterexample);

Expand Down Expand Up @@ -240,8 +269,8 @@ public void finishedLearning(StateMachineWrapper<ID, OD> learnedModel, boolean f
statistics.setStates(learnedModel.getMachineSize());
}

statistics.setAllTests(testCounter.getCount());
statistics.setAllInputs(inputCounter.getCount());
statistics.setAllTests(getCount(testStatisticsKeys));
statistics.setAllInputs(getCount(inputStatisticsKeys));
statistics.setDuration(System.currentTimeMillis() - startTime);
statistics.setFinished(finished, notFinishedReason);

Expand All @@ -259,13 +288,12 @@ public Statistics<I, ID, OD, CE> generateStatistics() {
}

/**
* Creates a new snapshot from the current values of {@link #testCounter},
* {@link #inputCounter} and current running time.
* Creates a new snapshot from the current values of the counters and current running time.
*
* @return the current statistics snapshot
*/
protected StatisticsSnapshot createSnapshot() {
return new StatisticsSnapshot(testCounter.getCount(), inputCounter.getCount(),
return new StatisticsSnapshot(getCount(testStatisticsKeys), getCount(inputStatisticsKeys),
System.currentTimeMillis() - startTime);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.protocolfuzzing.protocolstatefuzzer.components.learner.statistics;

import de.learnlib.filter.statistic.Counter;
import de.learnlib.query.DefaultQuery;
import de.learnlib.statistic.StatisticsKey;
import net.automatalib.word.Word;

/**
Expand All @@ -17,13 +17,13 @@ public class StatisticsTrackerRA<B, D, OD> extends StatisticsTracker<B, Word<D>,
/**
* Creates a new instance from the given parameters.
*
* @param inputCounter counter updated on every input of membership and
* equivalence queries
* @param testCounter counter updated on every membership and equivalence query
* (also named test)
* @param inputStatisticsKey key for counter updated on every input of membership and
* equivalence queries
* @param testStatisticsKey key for counter updated on every membership and equivalence query
* (also named test)
*/
public StatisticsTrackerRA(Counter inputCounter, Counter testCounter) {
super(inputCounter, testCounter);
public StatisticsTrackerRA(StatisticsKey inputStatisticsKey, StatisticsKey testStatisticsKey) {
super(inputStatisticsKey, testStatisticsKey);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.protocolfuzzing.protocolstatefuzzer.components.learner.statistics;

import de.learnlib.filter.statistic.Counter;
import de.learnlib.query.DefaultQuery;
import de.learnlib.statistic.StatisticsKey;
import net.automatalib.word.Word;

import java.util.List;

/**
* Standard implementation of the StatisticsTracker for specific input domain
* and counterexample type.
Expand All @@ -16,11 +18,23 @@ public class StatisticsTrackerStandard<I, OD> extends StatisticsTracker<I, Word<
/**
* Creates a new instance from the given parameters.
*
* @param inputCounter counter updated on every input of membership and equivalence queries
* @param testCounter counter updated on every membership and equivalence query (also named test)
* @param inputStatisticsKey key for counter updated on every input of membership and equivalence queries
* @param testStatisticsKey key for counter updated on every membership and equivalence query (also named test)
*/
public StatisticsTrackerStandard(StatisticsKey inputStatisticsKey, StatisticsKey testStatisticsKey) {
super(inputStatisticsKey, testStatisticsKey);
}

/**
* Creates a new instance from the given parameters.
* <p>
* This should be used when values of multiple counters should be aggregated to a single value
*
* @param inputStatisticsKeys keys for counter updated on every input of membership and equivalence queries
* @param testStatisticsKeys keys for counter updated on every membership and equivalence query (also named test)
*/
public StatisticsTrackerStandard(Counter inputCounter, Counter testCounter) {
super(inputCounter, testCounter);
public StatisticsTrackerStandard(List<StatisticsKey> inputStatisticsKeys, List<StatisticsKey> testStatisticsKeys) {
super(inputStatisticsKeys, testStatisticsKeys);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.protocolfuzzing.protocolstatefuzzer.components.sul.core;

import de.learnlib.filter.statistic.Counter;
import de.learnlib.statistic.StatisticsKey;
import de.learnlib.sul.SUL;

import java.time.Duration;
Expand Down Expand Up @@ -68,13 +68,13 @@ public interface SULWrapper<I, O, E> {
*
* @return the input counter of the underlying abstract SUL
*/
Counter getInputCounter();
StatisticsKey getInputStatisticsKey();

/**
* Returns the test counter used for counting all the tests (queries)
* directed at the underlying abstract SUL.
*
* @return the test counter of the underlying abstract SUL
*/
Counter getTestCounter();
StatisticsKey getTestStatisticsKey();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.protocolfuzzing.protocolstatefuzzer.components.sul.core;

import de.learnlib.filter.statistic.Counter;
import de.learnlib.filter.statistic.sul.CounterSUL;
import de.learnlib.statistic.StatisticsKey;
import de.learnlib.sul.SUL;
import io.github.protocolfuzzing.protocolstatefuzzer.components.sul.core.config.SULConfig;
import io.github.protocolfuzzing.protocolstatefuzzer.components.sul.core.sulwrappers.DynamicPortProvider;
Expand Down Expand Up @@ -33,10 +33,10 @@ public class SULWrapperStandard<I, O, E> implements SULWrapper<I, O, E> {
protected SUL<I, O> wrappedSUL;

/** The input counter used for the underlying abstract SUL. */
protected Counter inputCounter;
protected StatisticsKey inputStatisticsKey;

/** The test counter used for the underlying abstract SUL. */
protected Counter testCounter;
protected StatisticsKey testStatisticsKey;

/** The time limit to be set only once using {@link #setTimeLimit(Duration)}. */
protected Duration timeLimit;
Expand Down Expand Up @@ -70,8 +70,8 @@ public SULWrapper<I, O, E> wrap(AbstractSUL<I, O, E> abstractSUL) {
wrappedSUL = new SULLivenessWrapper<>(wrappedSUL, sulLivenessTracker, terminatedOutput);

wrappedSUL = new CounterSUL<>(wrappedSUL);
inputCounter = CounterSUL.class.cast(wrappedSUL).getSymbolCounter();
testCounter = CounterSUL.class.cast(wrappedSUL).getResetCounter();
inputStatisticsKey = CounterSUL.KEY_SYMBOL;
testStatisticsKey = CounterSUL.KEY_QUERY;

return this;
}
Expand Down Expand Up @@ -116,12 +116,12 @@ public SUL<I, O> getWrappedSUL() {
}

@Override
public Counter getInputCounter() {
return inputCounter;
public StatisticsKey getInputStatisticsKey() {
return inputStatisticsKey;
}

@Override
public Counter getTestCounter() {
return testCounter;
public StatisticsKey getTestStatisticsKey() {
return testStatisticsKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public StateFuzzerComposerRA(

// initialize statistics tracker
this.statisticsTracker = new StatisticsTrackerRA<B, PSymbolInstance, Boolean>(
sulWrapper.getInputCounter(), sulWrapper.getTestCounter());
sulWrapper.getInputStatisticsKey(), sulWrapper.getTestStatisticsKey());
}

/**
Expand Down
Loading
Loading