87 auto GetLocalIP = [=](
const uint16_t sport)-> std::pair<std::string, uint16_t> {
88 std::pair<std::string, uint16_t> localIP;
89 int sock = socket(AF_INET, SOCK_DGRAM, 0);
92 std::cout <<
"Error number 1: " << errno << std::endl;
93 std::cout <<
"Error message: " << strerror(errno) << std::endl;
98 std::memset(&loopback, 0,
sizeof(loopback));
99 loopback.sin_family = AF_INET;
100 loopback.sin_addr.s_addr = INADDR_LOOPBACK;
101 loopback.sin_port = htons(9);
102 err = connect(sock,
reinterpret_cast<sockaddr*
>(&loopback),
sizeof(loopback));
105 std::cout <<
"Error number 2: " << errno << std::endl;
106 std::cout <<
"Error message: " << strerror(errno) << std::endl;
109 socklen_t addrlen =
sizeof(loopback);
110 err = getsockname(sock,
reinterpret_cast<struct sockaddr*
> (&loopback), &addrlen);
113 std::cout <<
"Error number 3: " << errno << std::endl;
114 std::cout <<
"Error message: " << strerror(errno) << std::endl;
120 localIP = std::pair<std::string, uint16_t>(std::string(buffer), sport);
123 std::cout <<
"Error number 4: " << errno << std::endl;
124 std::cout <<
"Error message: " << strerror(errno) << std::endl;
145 std::pair<std::string, uint16_t> serverTM;
150 longitudinal_highway_param,
152 lateral_highway_param,
153 perc_difference_from_limit,
158 serverTM = GetLocalIP(port);
161 episode_proxy.
Lock()->AddTrafficManagerRunning(serverTM);
165 std::cout <<
"NEW@: Registered TM at "
166 << serverTM.first <<
":"
167 << serverTM.second <<
" ..... SUCCESS."
172 _tm_map.insert(std::make_pair(port, tm_ptr));
182 if(episode_proxy.
Lock()->IsTrafficManagerRunning(port)) {
185 std::pair<std::string, uint16_t> serverTM =
186 episode_proxy.
Lock()->GetTrafficManagerRunning(port);
196 if(tm_ptr !=
nullptr) {
200 std::cout <<
"OLD@: Registered TM at "
201 << serverTM.first <<
":"
202 << serverTM.second <<
" ..... TRY "
209 _tm_map.insert(std::make_pair(port, tm_ptr));
223 std::cout <<
"OLD@: Registered TM at "
224 << serverTM.first <<
":"
225 << serverTM.second <<
" ..... FAILED "