From 6455255ee6fa5e1dade5a5ce6d9d74c3bdf889b3 Mon Sep 17 00:00:00 2001 From: charlie Date: Mon, 25 Jan 2016 17:14:42 +0100 Subject: [PATCH] fully working adapter and time logging for the learner --- a4/tcp/adapter/listener.py | 21 ++++++++++- .../learnedModel.full.TTT.wm.2692sec.dot | 36 +++++++++++++++++++ a4/tcp/results/learnedModel.full.TTT.wm.dot | 26 ++++++++++++++ a4/tcp/run.sh | 8 ++++- a4/tcp/tester/learner/Main.java | 8 +++-- 5 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 a4/tcp/results/learnedModel.full.TTT.wm.2692sec.dot create mode 100644 a4/tcp/results/learnedModel.full.TTT.wm.dot diff --git a/a4/tcp/adapter/listener.py b/a4/tcp/adapter/listener.py index 121442e..a7ff786 100644 --- a/a4/tcp/adapter/listener.py +++ b/a4/tcp/adapter/listener.py @@ -22,6 +22,7 @@ if __name__ == "__main__": data = '' has_error=False did_syn=False + con_closed=False while True: print 'waiting for data' done = False @@ -33,17 +34,23 @@ if __name__ == "__main__": data += d if d == '\n': done = True + if data == '': + print 'invalid data received!' + break print 'received: {}'.format(data) if data == 'RES': print 'resetting the SUT...' - sender.sendReset() + #sender.sendReset() sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=0) data = '' has_error = False did_syn = False + con_closed = False continue elif has_error: response = 'ERR' + elif con_closed: + response = 'Closed' elif data == 'SYN' and not did_syn: seqnr = 100 print 'S: {}'.format(seqnr) @@ -73,12 +80,18 @@ if __name__ == "__main__": seqnr += 1 print 'RP: {}'.format(seqnr) response = sender.sendInput("RP", seqnr, 0) + if response[0] == 'T': + response = 'Reset' elif data == 'FIN': response = 'Timeout' if sender.lastSeqReceived != None: seqnr += 1 print 'F: {}'.format(seqnr) response = sender.sendInput("FA", seqnr, sender.lastSeqReceived + 1) + if response[0] == 'A': + con_closed = True + else: + response = 'Timeout' else: print 'INVALID INPUT!: {}'.format(repr(data)) break @@ -86,6 +99,11 @@ if __name__ == "__main__": if response == 'Timeout': data = 'ERR' has_error = True + elif response == 'Reset': + data = 'Reset' + did_syn = False + elif response == 'Closed': + data = 'Closed' elif response[0] == 'A': data = 'ACK' elif response[0] == 'PA': @@ -96,6 +114,7 @@ if __name__ == "__main__": data = 'SYN-ACK' else: data = 'ERR' + has_error = True print 'RESPONSE: '+data conn.send('{}\n'.format(data)) diff --git a/a4/tcp/results/learnedModel.full.TTT.wm.2692sec.dot b/a4/tcp/results/learnedModel.full.TTT.wm.2692sec.dot new file mode 100644 index 0000000..5db1c7b --- /dev/null +++ b/a4/tcp/results/learnedModel.full.TTT.wm.2692sec.dot @@ -0,0 +1,36 @@ +digraph g { +__start0 [label="" shape="none"]; + + s0 [shape="circle" label="s0"]; + s1 [shape="circle" label="s1"]; + s2 [shape="circle" label="s2"]; + s3 [shape="circle" label="s3"]; + s4 [shape="circle" label="s4"]; + s0 -> s1 [label="SYN / SYN-ACK"]; + s0 -> s3 [label="ACK / ERR"]; + s0 -> s3 [label="DAT / ERR"]; + s0 -> s3 [label="RST / ERR"]; + s0 -> s3 [label="FIN / ERR"]; + s1 -> s3 [label="SYN / ERR"]; + s1 -> s3 [label="ACK / ERR"]; + s1 -> s4 [label="DAT / ACK"]; + s1 -> s0 [label="RST / Reset"]; + s1 -> s2 [label="FIN / ACK"]; + s2 -> s2 [label="SYN / Closed"]; + s2 -> s2 [label="ACK / Closed"]; + s2 -> s2 [label="DAT / Closed"]; + s2 -> s2 [label="RST / Closed"]; + s2 -> s2 [label="FIN / Closed"]; + s3 -> s3 [label="SYN / ERR"]; + s3 -> s3 [label="ACK / ERR"]; + s3 -> s3 [label="DAT / ERR"]; + s3 -> s3 [label="RST / ERR"]; + s3 -> s3 [label="FIN / ERR"]; + s4 -> s3 [label="SYN / ERR"]; + s4 -> s3 [label="ACK / ERR"]; + s4 -> s4 [label="DAT / DATA"]; + s4 -> s0 [label="RST / Reset"]; + s4 -> s2 [label="FIN / ACK"]; + +__start0 -> s0; +} diff --git a/a4/tcp/results/learnedModel.full.TTT.wm.dot b/a4/tcp/results/learnedModel.full.TTT.wm.dot new file mode 100644 index 0000000..b4c1e2b --- /dev/null +++ b/a4/tcp/results/learnedModel.full.TTT.wm.dot @@ -0,0 +1,26 @@ +digraph g { +__start0 [label="" shape="none"]; + + s0 [shape="circle" label="s0"]; + s1 [shape="circle" label="s1"]; + s2 [shape="circle" label="s2"]; + s3 [shape="circle" label="s3"]; + s0 -> s1 [label="SYN / SYN-ACK"]; + s0 -> s2 [label="ACK / ERR"]; + s0 -> s2 [label="DAT / ERR"]; + s0 -> s2 [label="RST / ERR"]; + s1 -> s2 [label="SYN / ERR"]; + s1 -> s2 [label="ACK / ERR"]; + s1 -> s3 [label="DAT / ACK"]; + s1 -> s0 [label="RST / Reset"]; + s2 -> s2 [label="SYN / ERR"]; + s2 -> s2 [label="ACK / ERR"]; + s2 -> s2 [label="DAT / ERR"]; + s2 -> s2 [label="RST / ERR"]; + s3 -> s2 [label="SYN / ERR"]; + s3 -> s2 [label="ACK / ERR"]; + s3 -> s3 [label="DAT / DATA"]; + s3 -> s0 [label="RST / Reset"]; + +__start0 -> s0; +} diff --git a/a4/tcp/run.sh b/a4/tcp/run.sh index cbda43f..c19167c 100755 --- a/a4/tcp/run.sh +++ b/a4/tcp/run.sh @@ -1,3 +1,9 @@ #!/bin/bash -x + +# parametrs for learner +# aphabetSize {small, partial, full} - selects subset input alphabet. this affects model size +# learningMethod {LStar, TTT, RS, KV} +# equaviance orace {rand, wm, wpm} + #java -cp ":lib/automata-parent.jar:lib/learnlib-parent.jar" learner.Main small -java -cp ":lib/automata-parent.jar:lib/learnlib-parent.jar" learner.Main partial TTT wm +java -cp ":lib/automata-parent.jar:lib/learnlib-parent.jar" learner.Main full TTT wm diff --git a/a4/tcp/tester/learner/Main.java b/a4/tcp/tester/learner/Main.java index fa9c649..a3b167a 100644 --- a/a4/tcp/tester/learner/Main.java +++ b/a4/tcp/tester/learner/Main.java @@ -91,8 +91,11 @@ public class Main { private static String stateCountStr; private static String methodStr; private static String testStr; + private static long startTime; public static void main(String [] args) throws IOException { + startTime = System.currentTimeMillis(); + if (args.length != 3) { System.out.println("error: missing commandline arguments!"); return; @@ -326,9 +329,10 @@ public class Main { * @throws IOException */ public static void produceOutput(String fileName, MealyMachine model, Alphabet alphabet, boolean verboseError) throws FileNotFoundException, IOException { - GraphDOT.write(model, alphabet, new PrintWriter(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + ".dot")); + long time = (System.currentTimeMillis()-startTime)/1000L; + GraphDOT.write(model, alphabet, new PrintWriter(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + "." + time + "sec" + ".dot")); try { - DOT.runDOT(new File(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + ".dot"), "pdf", new File(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + ".pdf")); + DOT.runDOT(new File(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + "." + time + "sec" + ".dot"), "pdf", new File(fileName + "." + stateCountStr + "." + methodStr + "." + testStr + "." + time + "sec" + ".pdf")); } catch (Exception e) { if (verboseError) { System.err.println("Warning: Install graphviz to convert dot-files to PDF"); -- 2.20.1