-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraverse_TCP_states.cpp
More file actions
29 lines (28 loc) · 2.06 KB
/
traverse_TCP_states.cpp
File metadata and controls
29 lines (28 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <string>
#include <vector>
#include <unordered_map>
std::unordered_map<std::string,std::vector<std::pair<std::string,std::string>>> routing = {{"CLOSED",{{"APP_PASSIVE_OPEN","LISTEN"},{"APP_ACTIVE_OPEN","SYN_SENT"}}},
{"LISTEN",{{"RCV_SYN","SYN_RCVD"},{"APP_SEND","SYN_SENT"},{"APP_CLOSE","CLOSED"}}},
{"SYN_RCVD",{{"APP_CLOSE","FIN_WAIT_1"},{"RCV_ACK","ESTABLISHED"}}},
{"SYN_SENT",{{"RCV_SYN","SYN_RCVD"},{"RCV_SYN_ACK","ESTABLISHED"},{"APP_CLOSE","CLOSED"}}},
{"ESTABLISHED",{{"APP_CLOSE","FIN_WAIT_1"},{"RCV_FIN","CLOSE_WAIT"}}},
{"FIN_WAIT_1",{{"RCV_FIN","CLOSING"},{"RCV_FIN_ACK","TIME_WAIT"},{"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"}}}};
std::string traverse_TCP_states(const std::vector<std::string> &events){
std::string state = "CLOSED";
for (auto ha:events){
std::string temp = state;
for (auto a:routing[state]){
if(a.first==ha)
state=a.second;
}
if(state==temp){
return "ERROR";
}
}
return state;
}