|
|
| 120 |
NS_LOG_FUNCTION (this << address << port); |
120 |
NS_LOG_FUNCTION (this << address << port); |
| 121 |
if (LookupLocal (address, port)) |
121 |
if (LookupLocal (address, port)) |
| 122 |
{ |
122 |
{ |
| 123 |
NS_LOG_WARN ("Duplicate address/port; failing."); |
123 |
NS_LOG_WARN ("Duplicated endpoint - I hope you will use BindToNetDevice later."); |
| 124 |
return 0; |
|
|
| 125 |
} |
124 |
} |
| 126 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port); |
125 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port); |
| 127 |
m_endPoints.push_back (endPoint); |
126 |
m_endPoints.push_back (endPoint); |
|
|
| 141 |
(*i)->GetPeerPort () == peerPort && |
140 |
(*i)->GetPeerPort () == peerPort && |
| 142 |
(*i)->GetPeerAddress () == peerAddress) |
141 |
(*i)->GetPeerAddress () == peerAddress) |
| 143 |
{ |
142 |
{ |
| 144 |
NS_LOG_WARN ("No way we can allocate this end-point."); |
143 |
NS_LOG_WARN ("Duplicated endpoint - I hope you will use BindToNetDevice later."); |
| 145 |
/* no way we can allocate this end-point. */ |
|
|
| 146 |
return 0; |
| 147 |
} |
144 |
} |
| 148 |
} |
145 |
} |
| 149 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (localAddress, localPort); |
146 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (localAddress, localPort); |
|
|
| 204 |
EndPoints retval2; // Matches exact on local port/adder, wildcards on others |
201 |
EndPoints retval2; // Matches exact on local port/adder, wildcards on others |
| 205 |
EndPoints retval3; // Matches all but local address |
202 |
EndPoints retval3; // Matches all but local address |
| 206 |
EndPoints retval4; // Exact match on all 4 |
203 |
EndPoints retval4; // Exact match on all 4 |
|
|
204 |
EndPoints retvalBound1; // Matches exact on local port, wildcards on others |
| 205 |
EndPoints retvalBound2; // Matches exact on local port/adder, wildcards on others |
| 206 |
EndPoints retvalBound3; // Matches all but local address |
| 207 |
EndPoints retvalBound4; // Exact match on all 4 |
| 207 |
|
208 |
|
| 208 |
NS_LOG_DEBUG ("Looking up endpoint for destination address " << daddr << ":" << dport); |
209 |
NS_LOG_DEBUG ("Looking up endpoint for destination address " << daddr << ":" << dport); |
| 209 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
210 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
|
|
| 303 |
if (localAddressMatchesExact && remoteAddressMatchesExact && remotePortMatchesExact) |
304 |
if (localAddressMatchesExact && remoteAddressMatchesExact && remotePortMatchesExact) |
| 304 |
{ // All 4 match - this is the case of an open TCP connection, for example. |
305 |
{ // All 4 match - this is the case of an open TCP connection, for example. |
| 305 |
NS_LOG_LOGIC ("Found an endpoint for case 4, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
306 |
NS_LOG_LOGIC ("Found an endpoint for case 4, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
| 306 |
retval4.push_back (endP); |
307 |
if (endP->GetBoundNetDevice ()) |
|
|
308 |
{ |
| 309 |
retvalBound4.push_back (endP); |
| 310 |
} |
| 311 |
else |
| 312 |
{ |
| 313 |
retval4.push_back (endP); |
| 314 |
} |
| 307 |
} |
315 |
} |
| 308 |
if (localAddressMatchesWildCard && remoteAddressMatchesExact && remotePortMatchesExact) |
316 |
if (localAddressMatchesWildCard && remoteAddressMatchesExact && remotePortMatchesExact) |
| 309 |
{ // All but local address - no idea what this case could be. |
317 |
{ // All but local address - no idea what this case could be. |
| 310 |
NS_LOG_LOGIC ("Found an endpoint for case 3, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
318 |
NS_LOG_LOGIC ("Found an endpoint for case 3, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
| 311 |
retval3.push_back (endP); |
319 |
if (endP->GetBoundNetDevice ()) |
|
|
320 |
{ |
| 321 |
retvalBound3.push_back (endP); |
| 322 |
} |
| 323 |
else |
| 324 |
{ |
| 325 |
retval3.push_back (endP); |
| 326 |
} |
| 312 |
} |
327 |
} |
| 313 |
if (localAddressMatchesExact && remoteAddressMatchesWildCard && remotePortMatchesWildCard) |
328 |
if (localAddressMatchesExact && remoteAddressMatchesWildCard && remotePortMatchesWildCard) |
| 314 |
{ // Only local port and local address matches exactly - Not yet opened connection |
329 |
{ // Only local port and local address matches exactly - Not yet opened connection |
| 315 |
NS_LOG_LOGIC ("Found an endpoint for case 2, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
330 |
NS_LOG_LOGIC ("Found an endpoint for case 2, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
| 316 |
retval2.push_back (endP); |
331 |
if (endP->GetBoundNetDevice ()) |
|
|
332 |
{ |
| 333 |
retvalBound2.push_back (endP); |
| 334 |
} |
| 335 |
else |
| 336 |
{ |
| 337 |
retval2.push_back (endP); |
| 338 |
} |
| 317 |
} |
339 |
} |
| 318 |
if (localAddressMatchesWildCard && remoteAddressMatchesWildCard && remotePortMatchesWildCard) |
340 |
if (localAddressMatchesWildCard && remoteAddressMatchesWildCard && remotePortMatchesWildCard) |
| 319 |
{ // Only local port matches exactly - Endpoint open to "any" connection |
341 |
{ // Only local port matches exactly - Endpoint open to "any" connection |
| 320 |
NS_LOG_LOGIC ("Found an endpoint for case 1, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
342 |
NS_LOG_LOGIC ("Found an endpoint for case 1, adding " << endP->GetLocalAddress () << ":" << endP->GetLocalPort ()); |
| 321 |
retval1.push_back (endP); |
343 |
if (endP->GetBoundNetDevice ()) |
|
|
344 |
{ |
| 345 |
retvalBound1.push_back (endP); |
| 346 |
} |
| 347 |
else |
| 348 |
{ |
| 349 |
retval1.push_back (endP); |
| 350 |
} |
| 322 |
} |
351 |
} |
| 323 |
} |
352 |
} |
| 324 |
|
353 |
|
| 325 |
// Here we find the most exact match |
354 |
// Here we find the most exact match, but we could still have one ambiguity |
| 326 |
if (!retval4.empty ()) return retval4; |
355 |
// I.e., one EndPoint not bound to any NetDevice and one bound. |
| 327 |
if (!retval3.empty ()) return retval3; |
356 |
// We always go for the bound one. |
| 328 |
if (!retval2.empty ()) return retval2; |
357 |
|
| 329 |
return retval1; // might be empty if no matches |
358 |
EndPoints retval; |
|
|
359 |
if (!retvalBound4.empty ()) retval = retvalBound4; |
| 360 |
else if (!retval4.empty ()) retval = retval4; |
| 361 |
else if (!retvalBound3.empty ()) retval = retvalBound3; |
| 362 |
else if (!retval3.empty ()) retval = retval3; |
| 363 |
else if (!retvalBound2.empty ()) retval = retvalBound2; |
| 364 |
else if (!retval2.empty ()) retval = retval2; |
| 365 |
else if (!retvalBound1.empty ()) retval = retvalBound1; |
| 366 |
else retval = retval1; |
| 367 |
|
| 368 |
if (retval.size () > 1) |
| 369 |
{ |
| 370 |
NS_ABORT_MSG ("Too many endpoints - perhaps you created too many sockets without binding them to different NetDevices."); |
| 371 |
} |
| 372 |
return retval; // might be empty if no matches |
| 330 |
} |
373 |
} |
| 331 |
|
374 |
|
| 332 |
Ipv4EndPoint * |
375 |
Ipv4EndPoint * |