14 /* connection settings */
19 :: State = Listen | ReceivedSYN | Established | Waiting | Closed
21 /* input (received from client) */
22 :: Input = InSYN | InACK | InRST | InFIN | InUserData
24 instance toString Input where
25 toString InSYN = "SYN"
26 toString InACK = "ACK"
27 toString InRST = "RST"
28 toString InFIN = "FIN"
29 toString InUserData = "DATA <some data here>"
31 /* output (sent to client) */
32 :: Output = OutSYN | OutACK | OutFIN
34 toOutput :: String -> [Output]
35 toOutput "SYN-ACK" = [OutSYN, OutACK]
38 /* state transitions */
39 stateTrans :: State Input -> [Trans Output State]
40 stateTrans Listen InSYN = [Pt [OutSYN, OutACK] ReceivedSYN]
41 stateTrans Listen _ = [Pt [] Listen]
43 stateTrans ReceivedSYN InRST = [Pt [] Listen]
44 stateTrans ReceivedSYN InACK = [Pt [] Established]
45 stateTrans ReceivedSYN _ = [Pt [] ReceivedSYN]
47 stateTrans Established InACK = [Pt [OutACK] Established]
48 stateTrans Established InUserData = [Pt [OutACK] Waiting]
49 stateTrans Established InFIN = [Pt [OutACK] Closed]
50 stateTrans Established _ = [Pt [] Established]
52 stateTrans Waiting InACK = [Pt [] Established]
53 stateTrans Waiting _ = [Pt [] Waiting]
56 :: *SutState :== (StringSChannel, StringRChannel, *World)
58 /* adapter for SUT communication */
59 adapter :: *SutState Input -> ([Output], *SutState)
60 adapter (s, r, world) i
61 # (s, world) = send (toString i) s world
62 # (cmd, r, world) = receive r world
63 = (toOutput cmd, (s, r, world))
66 reset :: *SutState -> *SutState
68 # (s, world) = send "SUT-RESET" s world
73 # (console, world) = stdio world
74 /* setup connection with adapter */
75 # (Just adr, world) = lookupIPAddress hostIP world
76 # (to, mcon, world) = connectTCP_MT Nothing (adr, hostPort) world
78 # console = console <<< "ERROR: can't connect to SUT!\n"
79 # (_, world) = fclose console world
83 # (_, file, world) = fopen "testOut.txt" FWriteText world
85 # st = (toStringSChannel con.sChannel, toStringRChannel con.rChannel, world)
86 # ((_, _, world), console, file) = testConfSM [] stateTrans Listen adapter st reset console file
87 /* close connection */
89 # (_, world) = fclose file world
90 # (_, world) = fclose console world