We planned to upgrade GitLab and Mattermost to the latest version this Friday morning (early). You may experience some downtime!

Commit bc642d3e authored by Paul Fiterau Brostean's avatar Paul Fiterau Brostean

Updated simulation

parent d1e764df
Pipeline #2266 skipped
model=win_server.dot
mapper=windows
\ No newline at end of file
package main;
import invlang.mapperReader.InvLangHandler;
import de.ls5.jlearn.interfaces.Automaton;
import sut.tcp.ConcretizingMapper;
import sut.tcp.HandlerLoader;
import java.io.FileNotFoundException;
import java.io.IOException;
import sut.tcp.Simulation;
import util.Action;
import util.InputAction;
import util.learnlib.Dot;
import util.OutputAction;
public class Main {
public static Simulation simulation;
public static void main(String[] args) throws Exception{
String hypFile = "hyp.dot";
String mapperFile = "freebsd";
if (args.length > 0) {
hypFile = args[0];
if (args.length > 1) {
mapperFile = args[1];
}
}
Automaton automaton = Dot.readDotFile(hypFile);
HandlerLoader loader = new HandlerLoader();
InvLangHandler handler = loader.loadMapper(mapperFile);
// String hypFile = "hyp.dot";
// String mapperFile = "freebsd";
// if (args.length > 0) {
// hypFile = args[0];
// if (args.length > 1) {
// mapperFile = args[1];
// }
// }
//
// Automaton automaton = Dot.readDotFile(hypFile);
// HandlerLoader loader = new HandlerLoader();
// InvLangHandler handler = loader.loadMapper(mapperFile);
Simulation simulation = new Simulation(automaton, new ConcretizingMapper(handler));
simulation.reset();
simulation.processSymbol(in("LISTEN"));
simulation.processSymbol(in("ACCEPT"));
int sutSeq = seq(simulation.processSymbol(in("SYN",1000,0,0)));
simulation.processSymbol(in("ACK",1001,sutSeq+1,0));
simulation.processSymbol(in("ACK+PSH",1001,sutSeq+1,1));
simulation.processSymbol(in("ACK+PSH",1002,sutSeq+1,1));
simulation.processSymbol(in("SEND"));
simulation.processSymbol(in("SEND"));
reset();
step(in("LISTEN"));
step(in("ACCEPT"));
int sutSeq = seq(step(in("SYN",1000,0,0)));
step(in("ACK",1001,sutSeq+1,0));
step(in("ACK+PSH",1001,sutSeq+1,1));
step(in("ACK+PSH",1002,sutSeq+1,1));
step(in("SEND"));
step(in("SEND"));
}
private static InputAction in(String meth, Integer...args) {
return new InputAction(meth, args);
}
private static void reset() throws FileNotFoundException, IOException {
simulation = new Simulation();
}
private static OutputAction step(InputAction input) {
OutputAction output = (OutputAction) simulation.sendInput(input);
System.out.println(simulation.sendInput(input));
return output;
}
private static int seq(Action concreteAction) {
return concreteAction.getParam(0).getValue();
}
......
......@@ -13,6 +13,7 @@ import java.net.SocketException;
import de.ls5.jlearn.interfaces.Automaton;
import invlang.mapperReader.InvLangHandler;
import sut.interfaces.SutInterface;
import sut.tcp.ConcretizingMapper;
import sut.tcp.HandlerLoader;
import sut.tcp.ModelLoader;
......@@ -141,18 +142,16 @@ public class Main implements Runnable {
System.out.println("input: " + inputString);
if (inputString.equals("reset")) {
sut.reset();
sut.sendReset();
if (verbose)
System.out.println("reset sut");
continue;
}
inputString = tomteInpToSimInp(inputString);
InputAction inputAction = new InputAction(inputString);
OutputAction outputAction = sut.processSymbol(inputAction);
OutputAction outputAction = (OutputAction)sut.sendInput(inputAction);
outputString = outputAction.getValuesAsString();
outputString = simOutToTomteOut(outputString);
if (verbose)
System.out.println("output: " + outputString);
......@@ -175,23 +174,4 @@ public class Main implements Runnable {
}
System.out.println("Closing client...");
}
private static String tomteInpToSimInp(String tomteInp) {
tomteInp = tomteInp.substring(1);
if (tomteInp.contains("_")) {
String payload = tomteInp.contains("PSH") ? "_1" : "_0"; //adding payload
tomteInp += payload;
}
return tomteInp;
}
private static String simOutToTomteOut(String simOut) {
if (simOut.contains("_")) {
simOut = simOut.substring(0, simOut.length() - 2); // removing payload
} else {
simOut = "O" + simOut;
}
return simOut;
}
}
package sut;
import util.InputAction;
import util.OutputAction;
public interface SutInterface {
public OutputAction processSymbol(InputAction methodWrapper);
public void reset();
}
......@@ -2,6 +2,8 @@ package sut;
import java.io.IOException;
import sut.interfaces.SutInterface;
public interface SutProvider {
public SutInterface newSut() throws IOException;
}
package sut.interfaces;
import java.util.List;
public interface Action {
public String getMethodName();
public List<sut.interfaces.Parameter> getParams() ;
}
package sut.interfaces;
public interface InputAction extends Action {
}
package sut.interfaces;
public interface OutputAction extends Action {
}
package sut.interfaces;
public interface Parameter {
public int getValue();
public int getParameterIndex();
}
package sut.interfaces;
public interface SutInterface {
// process input to an output
public OutputAction sendInput(InputAction inputAction);
// reset SUT
public void sendReset();
}
......@@ -40,21 +40,11 @@ public class ConcretizingMapper implements ConcretizationInterface{
// -> abssut absSeqIn, abslearner absAckIn)
public String processOutgoingResponse(FlagSet flags, String absSeq, String absAck, int payloadLength) {
OutputAction concreteOutput = concretizer.concretizeResponse(flags, absSeq, absAck, payloadLength);
return concreteOutput.getValuesAsString();
// handler.setEnum(Inputs.ABS_SEQ, "abssut", absSeq);
// handler.setEnum(Inputs.ABS_ACK, "abslearner", absAck);
// //handler.setInt(Outputs.ABS_DATA, payloadLength);
// handler.executeInverted(Mappings.INCOMING_RESPONSE);
//
// if (handler.hasResult()) {
// int concSeq = handler.getIntResult(Inputs.CONC_SEQ);
// int concAck = handler.getIntResult(Inputs.CONC_ACK);
// System.out.println(concSeq + " " + concAck);
// OutputAction output = new OutputAction(flags.toString(), new Integer [] {concSeq, concAck, payloadLength});
// return output.getValuesAsString();
// } else {
// return Outputs.UNDEF;
// }
if (concreteOutput != null)
return concreteOutput.getValuesAsString();
else {
return null;
}
}
......
......@@ -36,10 +36,11 @@ public class RandomConcretizer {
Configuration foundConfig = getFirstConfigurationMatchingAbstractions(configurations, flags, absSeq, absAck, payloadLength);
if (foundConfig == null) {
throw new BugException("Cannot concretize the input " + flags + "(" + absSeq + "," + absAck + "," + payloadLength + ")"
throw new BugException("Cannot concretize the output " + flags + "(" + absSeq + "," + absAck + "," + payloadLength + ")"
+ " for the mapper:\n" + handler.getState() +
"\nhaving checked these points of interest " + pointsOfInterest
+ "\n" + Arrays.asList(Thread.currentThread().getStackTrace()));
// return null;
} else {
updateMapperWithConcretization(flags, foundConfig.seqNum, foundConfig.ackNum, payloadLength);
OutputAction output = new OutputAction(flags.toString(), new Integer [] {foundConfig.seqNum, foundConfig.ackNum, payloadLength});
......
package sut.tcp;
import sut.SutInterface;
import util.Action;
import util.InputAction;
import util.OutputAction;
import de.ls5.jlearn.interfaces.Automaton;
import de.ls5.jlearn.interfaces.State;
import de.ls5.jlearn.interfaces.Symbol;
import de.ls5.jlearn.shared.SymbolImpl;
import exceptions.BugException;
import exceptions.DecoratedRuntimeException;
import invlang.types.FlagSet;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -21,6 +9,19 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import de.ls5.jlearn.interfaces.Automaton;
import de.ls5.jlearn.interfaces.State;
import de.ls5.jlearn.interfaces.Symbol;
import de.ls5.jlearn.shared.SymbolImpl;
import exceptions.BugException;
import exceptions.DecoratedRuntimeException;
import invlang.types.FlagSet;
import sut.interfaces.SutInterface;
import util.Action;
import util.InputAction;
import util.OutputAction;
import util.Parameter;
public class Simulation implements SutInterface{
private static boolean verbose = false;
private static String PROPERTIES_FILE = "simulation.properties";
......@@ -76,6 +77,7 @@ public class Simulation implements SutInterface{
this.model = hyp;
this.mapper = mapper;
this.trace = new ArrayList<Action>();
this.currentState = model.getStart();
if (verbose) {
try {
this.pw = new PrintWriter(new File("sim_log.txt"));
......@@ -92,8 +94,8 @@ public class Simulation implements SutInterface{
}
public OutputAction processSymbol(InputAction methodWrapper) {
try {
trace.add(methodWrapper);
try {
String requestString = null;
out("Sim received: " + methodWrapper.getValuesAsString());
......@@ -102,6 +104,9 @@ public class Simulation implements SutInterface{
if (methodWrapper.getParameters().size() > 0) {
requestString = this.mapper.processIncomingRequest(new FlagSet(methodWrapper.getMethodName()),
methodWrapper.getParam(0).getValue(), methodWrapper.getParam(1).getValue(), methodWrapper.getParam(2).getValue());
// hack needed to preserve the order of flags
int startOfParan = requestString.indexOf('(');
requestString = methodWrapper.getMethodName() + requestString.substring(startOfParan, requestString.length());
// action
} else {
requestString = methodWrapper.getMethodName();
......@@ -115,13 +120,17 @@ public class Simulation implements SutInterface{
if (outputSymbol == null) {
out("undefined input: " + requestString);
output = new OutputAction("OUNDEFINED");
output = new OutputAction("UNDEFINED");
} else {
this.currentState = currentState.getTransitionState(inputSymbol);
if (outputSymbol.toString().contains("(")) {
Packet packet = new Packet(outputSymbol.toString());
String response = this.mapper.processOutgoingResponse(packet.flags, packet.seq.toString(), packet.ack.toString(), packet.payloadLength);
output = new OutputAction("O"+response);
if (response != null) {
output = new OutputAction(""+response);
} else {
output = new OutputAction("FAIL");
}
} else {
String formattedOutput = outputSymbol.toString().replaceAll("\\(|\\)", "_");
output = new OutputAction(formattedOutput);
......@@ -144,4 +153,40 @@ public class Simulation implements SutInterface{
out("Sim reset");
}
@Override
public sut.interfaces.OutputAction sendInput(sut.interfaces.InputAction inputAction) {
//tomte input to sim input
InputAction input = tomteInpToSimInp(inputAction);
OutputAction output = this.processSymbol(input);
// sim output to tomte output without payload parameter
return simOutToTomteOut(output);
}
@Override
public void sendReset() {
this.reset();
}
private InputAction tomteInpToSimInp(sut.interfaces.InputAction tomteInp) {
String methodName = tomteInp.getMethodName();
if (methodName.startsWith("I")) {
methodName = methodName.substring(1);
}
List<sut.interfaces.Parameter> params = new ArrayList<sut.interfaces.Parameter>();
params.addAll(tomteInp.getParams());
if (params.size() > 1) {
int payload = methodName.contains("PSH")? 1: 0;
params.add(new Parameter(payload, 2));
}
return new InputAction(methodName, params);
}
private sut.interfaces.OutputAction simOutToTomteOut(OutputAction simOutput) {
List<sut.interfaces.Parameter> params = new ArrayList<>(simOutput.getParameters());
if (params.size() == 3)
params.remove(params.size()-1);
OutputAction tomteOutput = new OutputAction("O"+simOutput.getMethodName(), params);
return tomteOutput;
}
}
......@@ -28,7 +28,7 @@ public abstract class Action {
}
public Action(String methodName, Integer [] parameterValues) {
this(methodName, Collections.<Parameter>emptyList());
this(methodName, Collections.<sut.interfaces.Parameter>emptyList());
List<Parameter> params = buildParams(parameterValues);
for (Parameter param : params) {
param.setAction(this);
......@@ -46,20 +46,17 @@ public abstract class Action {
return params;
}
public Action(String methodName, List<Parameter> parameters) {
public Action(String methodName, List<sut.interfaces.Parameter> parameters) {
this.methodName = methodName;
this.parameters = new ArrayList<Parameter>();
for (Parameter parameter : parameters) {
for (sut.interfaces.Parameter parameter : parameters) {
Parameter newParam = new Parameter(parameter.getValue(), parameter.getParameterIndex());
newParam.setAction(this);
this.parameters.add(newParam);
}
}
public Action(Action action) {
this(action.getMethodName(), action.getParameters());
}
public Action(String actionString) {
String[] action = actionString.split("_");
......@@ -90,7 +87,6 @@ public abstract class Action {
}
}
}
public String toString() {
StringBuilder result = new StringBuilder(methodName);
......@@ -141,4 +137,11 @@ public abstract class Action {
}
return result;
}
public List<sut.interfaces.Parameter> getParams() {
List<sut.interfaces.Parameter> params = new ArrayList<sut.interfaces.Parameter>();
this.parameters.forEach(param -> params.add(param));
return params;
}
}
......@@ -2,16 +2,16 @@ package util;
import java.util.List;
public class InputAction extends Action {
public class InputAction extends Action implements sut.interfaces.InputAction{
public InputAction(String methodName, List<Parameter> parameters) {
public InputAction(String methodName, List<sut.interfaces.Parameter> parameters) {
super(methodName, parameters);
}
public InputAction(Action action) {
super(action);
}
// public InputAction(Action action) {
// super(action);
// }
//
public InputAction(String action) {
super(action);
}
......@@ -19,4 +19,5 @@ public class InputAction extends Action {
public InputAction(String methodName, Integer [] parameters) {
super(methodName, parameters);
}
}
......@@ -2,16 +2,12 @@ package util;
import java.util.List;
public class OutputAction extends Action {
public class OutputAction extends Action implements sut.interfaces.OutputAction{
public OutputAction(String methodName, List<Parameter> parameters) {
public OutputAction(String methodName, List<sut.interfaces.Parameter> parameters) {
super(methodName, parameters);
}
public OutputAction(Action action) {
super(action);
}
public OutputAction(String action) {
super(action);
}
......
package util;
public class Parameter {
public class Parameter implements sut.interfaces.Parameter{
private int value;
private int parameterIndex;
private Action action;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment