Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class TCP
- Public Shared Function TraverseStates(ByVal r As String()) As String
- Dim dict = ParseStates()
- Dim currentState = "CLOSED"
- For Each el As String In r
- If Not dict.ContainsKey(currentState)Then Return "ERROR"
- Dim currentDict = dict(currentState)
- If Not currentDict.ContainsKey(el) Then Return "ERROR"
- currentState = currentDict(el)
- Next
- Return currentState
- End Function
- ' init state event new_state
- Public Shared Function ParseStates() As Dictionary(Of String, Dictionary(Of String, String))
- Dim parsedStates = states.Split(Environment.NewLine).
- Select(Function(s) ParseStateLine(s)).
- ToList()
- Dim results = New Dictionary(Of String, Dictionary(Of String, String))
- For Each line As Tuple(Of String, String, String) In parsedStates
- If Not results.ContainsKey(line.Item1) Then results.Add(line.Item1, New Dictionary(Of String, String))
- Dim subdict = results(line.Item1)
- subdict(line.Item2) = line.Item3
- Next
- Return results
- End Function
- Public Shared Function ParseStateLine(line As String) As Tuple(Of String, String, String)
- Dim parts = line.Split(":")
- Dim initialState = parts(0).Trim()
- parts = parts(1).Split("->")
- Dim [event] = parts(0).Trim()
- Dim resultingState = parts(1).Trim()
- Return New Tuple(Of String, String, String)(initialState, [event], resultingState)
- End Function
- Class State
- Public InitialState As String
- Public EventName As String
- Public NewState As String
- End Class
- Dim Shared states As String = "CLOSED: APP_PASSIVE_OPEN -> LISTEN
- CLOSED: APP_ACTIVE_OPEN -> SYN_SENT
- LISTEN: RCV_SYN -> SYN_RCVD
- LISTEN: APP_SEND -> SYN_SENT
- LISTEN: APP_CLOSE -> CLOSED
- SYN_RCVD: APP_CLOSE -> FIN_WAIT_1
- SYN_RCVD: RCV_ACK -> ESTABLISHED
- SYN_SENT: RCV_SYN -> SYN_RCVD
- SYN_SENT: RCV_SYN_ACK -> ESTABLISHED
- SYN_SENT: APP_CLOSE -> CLOSED
- ESTABLISHED: APP_CLOSE -> FIN_WAIT_1
- ESTABLISHED: RCV_FIN -> CLOSE_WAIT
- FIN_WAIT_1: RCV_FIN -> CLOSING
- FIN_WAIT_1: RCV_FIN_ACK -> TIME_WAIT
- FIN_WAIT_1: RCV_ACK -> FIN_WAIT_2
- CLOSING: RCV_ACK -> TIME_WAIT
- FIN_WAIT_2: RCV_FIN -> TIME_WAIT
- TIME_WAIT: APP_TIMEOUT -> CLOSED
- CLOSE_WAIT: APP_CLOSE -> LAST_ACK
- LAST_ACK: RCV_ACK -> CLOSED"
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement