From bcd451be345263ce9d6ecd3c3c4c4fb7a1bf23b7 Mon Sep 17 00:00:00 2001 From: charlie Date: Sun, 20 Dec 2015 23:22:13 +0100 Subject: [PATCH] working python adapter for gast. --- a3/code/Gast/confSM.icl | 4 ++-- a3/code/Makefile | 1 + a3/code/adapter/listener.py | 43 +++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/a3/code/Gast/confSM.icl b/a3/code/Gast/confSM.icl index 93a648d..65946e4 100644 --- a/a3/code/Gast/confSM.icl +++ b/a3/code/Gast/confSM.icl @@ -212,10 +212,10 @@ findFileName [_:r] name = findFileName r name doTest :: (TestState s i o) (IUTstep .t i o) .t (.t->.t) -> (.t,TestState s i o) | gEq{|*|} s & gEq{|*|} o & genShow{|*|} s & genShow{|*|} i & genShow{|*|} o -doTest ts=:{input,curState,spec,incons} step t reset +doTest ts=:{input,curState,spec,incons,stop} step t reset | isEmpty ts.curState = (t, errorFound ts) - | ts.nStep >= ts.maxLen || ts.nRej >= ts.maxLen + | ts.nStep >= ts.maxLen || ts.nRej >= ts.maxLen || stop curState = doTest (resetState ts) step (reset t) reset | ts.nPath >= ts.maxPath | ts.nRej == 0 && ts.nTrun == 0 diff --git a/a3/code/Makefile b/a3/code/Makefile index f7a24b0..25326c0 100644 --- a/a3/code/Makefile +++ b/a3/code/Makefile @@ -1,5 +1,6 @@ CLMFLAGS:=\ -I $(CURDIR)/Gast\ + -I $(CURDIR)/Generics\ -IL ../lib/MersenneTwister\ -IL ../lib/StdLib\ -IL ../lib/TCPIP diff --git a/a3/code/adapter/listener.py b/a3/code/adapter/listener.py index 897ec4b..f0a7382 100644 --- a/a3/code/adapter/listener.py +++ b/a3/code/adapter/listener.py @@ -32,27 +32,40 @@ if __name__ == "__main__": data = conn.recv(int(data)) print "INPUT: "+data - if data == 'SYN': + if data == 'SUT-RESET': + print 'resetting the SUT...' + sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=0) + data = '' + continue + elif data == 'SYN': seqnr = 100 print 'S: {}'.format(seqnr) response = sender.sendInput('S', seqnr, seqnr) elif data == 'ACK': - seqnr += 1 - print 'A: {}'.format(seqnr) - response = sender.sendInput('A', seqnr, sender.lastSeqReceived + 1) + response = 'Timeout' + if sender.lastSeqReceived != None: + seqnr += 1 + print 'A: {}'.format(seqnr) + response = sender.sendInput('A', seqnr, sender.lastSeqReceived + 1) elif data == 'DATA': - seqnr += 1 - print 'DAT: {} sending: a'.format(seqnr) - response = sender.sendInput('PA', seqnr, sender.lastSeqReceived + 1, 'a') + response = 'Timeout' + if sender.lastSeqReceived != None: + seqnr += 1 + print 'DAT: {} sending: a'.format(seqnr) + response = sender.sendInput('PA', seqnr, sender.lastSeqReceived + 1, 'a') elif data == 'RST': - seqnr += 1 - print 'RP: {}'.format(seqnr) - response = sender.sendInput("RP", seqnr, 0) - sender.sendReset() + response = 'Timeout' + if sender.lastSeqReceived != None: + seqnr += 1 + print 'RP: {}'.format(seqnr) + response = sender.sendInput("RP", seqnr, 0) + sender.sendReset() elif data == 'FIN': - seqnr += 1 - print 'F: {}'.format(seqnr) - response = sender.sendInput("FA", seqnr, sender.lastSeqReceived + 1) + response = 'Timeout' + if sender.lastSeqReceived != None: + seqnr += 1 + print 'F: {}'.format(seqnr) + response = sender.sendInput("FA", seqnr, sender.lastSeqReceived + 1) else: print 'INVALID INPUT!' break @@ -61,6 +74,8 @@ if __name__ == "__main__": data = 'TO' elif response[0] == 'A': data = 'ACK' + elif response[0] == 'PA': + data = 'DATA' elif response[0] == 'R': data = 'RST' elif response[0] == 'SA': -- 2.20.1