author | Raj Bhattacharjea <raj.b@gatech.edu> |
Wed, 12 Mar 2008 16:05:31 -0400 | |
changeset 2365 | 89da0ca7c55e |
parent 2364 | a78056f7a7b4 |
permissions | -rw-r--r-- |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2005 INRIA |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* All rights reserved. |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or modify |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License version 2 as |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
*/ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
#include "ipv4-end-point-demux.h" |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
#include "ipv4-end-point.h" |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
24 |
#include "ns3/log.h" |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
namespace ns3{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
|
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
28 |
NS_LOG_COMPONENT_DEFINE ("Ipv4EndPointDemux"); |
984
3202c053eacc
Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
524
diff
changeset
|
29 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
Ipv4EndPointDemux::Ipv4EndPointDemux () |
1513
d16f6fd70397
change ephemeral port range to 49152-65535 (IANA recommendation)
Tom Henderson <tomh@tomh.org>
parents:
1504
diff
changeset
|
31 |
: m_ephemeral (49152) |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
32 |
{ |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
33 |
NS_LOG_FUNCTION; |
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
34 |
} |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
36 |
Ipv4EndPointDemux::~Ipv4EndPointDemux () |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
38 |
NS_LOG_FUNCTION; |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
39 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
40 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
41 |
Ipv4EndPoint *endPoint = *i; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
42 |
delete endPoint; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
44 |
m_endPoints.clear (); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
45 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
46 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
47 |
bool |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
48 |
Ipv4EndPointDemux::LookupPortLocal (uint16_t port) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
49 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
50 |
NS_LOG_FUNCTION; |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
51 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
52 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
53 |
if ((*i)->GetLocalPort () == port) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
54 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
55 |
return true; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
56 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
57 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
58 |
return false; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
59 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
61 |
bool |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
62 |
Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
64 |
NS_LOG_FUNCTION; |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
if ((*i)->GetLocalPort () == port && |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
(*i)->GetLocalAddress () == addr) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
69 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
70 |
return true; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
71 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
72 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
return false; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
74 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
75 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
76 |
Ipv4EndPoint * |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
77 |
Ipv4EndPointDemux::Allocate (void) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
78 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
79 |
NS_LOG_FUNCTION; |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
80 |
uint16_t port = AllocateEphemeralPort (); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
81 |
if (port == 0) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
83 |
NS_LOG_WARN ("Ephemeral port allocation failed."); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
84 |
return 0; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
85 |
} |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
86 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (Ipv4Address::GetAny (), port); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
87 |
m_endPoints.push_back (endPoint); |
1524
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
88 |
NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints."); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
89 |
return endPoint; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
90 |
} |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
91 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
92 |
Ipv4EndPoint * |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
93 |
Ipv4EndPointDemux::Allocate (Ipv4Address address) |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
94 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
95 |
NS_LOG_FUNCTION; |
1828
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
96 |
NS_LOG_PARAMS (this << address); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
97 |
uint16_t port = AllocateEphemeralPort (); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
98 |
if (port == 0) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
99 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
100 |
NS_LOG_WARN ("Ephemeral port allocation failed."); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
101 |
return 0; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
102 |
} |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
103 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
104 |
m_endPoints.push_back (endPoint); |
1524
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
105 |
NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints."); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
106 |
return endPoint; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
107 |
} |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
108 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
109 |
Ipv4EndPoint * |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
110 |
Ipv4EndPointDemux::Allocate (uint16_t port) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
111 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
112 |
NS_LOG_FUNCTION; |
2326
eec07777d1a2
Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1828
diff
changeset
|
113 |
NS_LOG_PARAMS (this << port); |
eec07777d1a2
Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1828
diff
changeset
|
114 |
|
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
115 |
return Allocate (Ipv4Address::GetAny (), port); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
116 |
} |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
117 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
118 |
Ipv4EndPoint * |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
119 |
Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port) |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
120 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
121 |
NS_LOG_FUNCTION; |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
122 |
NS_LOG_PARAMS (this << address << port); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
123 |
if (LookupLocal (address, port)) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
124 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
125 |
NS_LOG_WARN ("Duplicate address/port; failing."); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
126 |
return 0; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
127 |
} |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
128 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
129 |
m_endPoints.push_back (endPoint); |
1524
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
130 |
NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints."); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
131 |
return endPoint; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
132 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
133 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
134 |
Ipv4EndPoint * |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
135 |
Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort, |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
136 |
Ipv4Address peerAddress, uint16_t peerPort) |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
137 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
138 |
NS_LOG_FUNCTION; |
1828
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
139 |
NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
140 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
141 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
142 |
if ((*i)->GetLocalPort () == localPort && |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
143 |
(*i)->GetLocalAddress () == localAddress && |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
144 |
(*i)->GetPeerPort () == peerPort && |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
145 |
(*i)->GetPeerAddress () == peerAddress) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
146 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
147 |
NS_LOG_WARN ("No way we can allocate this end-point."); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
148 |
/* no way we can allocate this end-point. */ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
149 |
return 0; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
150 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
151 |
} |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
152 |
Ipv4EndPoint *endPoint = new Ipv4EndPoint (localAddress, localPort); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
153 |
endPoint->SetPeer (peerAddress, peerPort); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
154 |
m_endPoints.push_back (endPoint); |
1524
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
155 |
|
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
156 |
NS_LOG_DEBUG ("Now have >>" << m_endPoints.size () << "<< endpoints."); |
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
157 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
158 |
return endPoint; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
159 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
160 |
|
515
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
161 |
void |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
162 |
Ipv4EndPointDemux::DeAllocate (Ipv4EndPoint *endPoint) |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
163 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
164 |
NS_LOG_FUNCTION; |
515
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
165 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
166 |
{ |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
167 |
if (*i == endPoint) |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
168 |
{ |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
169 |
delete endPoint; |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
170 |
m_endPoints.erase (i); |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
171 |
break; |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
172 |
} |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
173 |
} |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
174 |
} |
e907146a191e
fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
495
diff
changeset
|
175 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
176 |
/* |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
177 |
* If we have an exact match, we return it. |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
178 |
* Otherwise, if we find a generic match, we return it. |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
179 |
* Otherwise, we return 0. |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
180 |
*/ |
984
3202c053eacc
Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
524
diff
changeset
|
181 |
Ipv4EndPointDemux::EndPoints |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
182 |
Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport, |
1524
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
183 |
Ipv4Address saddr, uint16_t sport, |
3ead2b66f2e4
Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1523
diff
changeset
|
184 |
Ptr<Ipv4Interface> incomingInterface) |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
185 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
186 |
NS_LOG_FUNCTION; |
2363
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
187 |
EndPoints retval1; // Matches exact on local port, wildcards on others |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
188 |
EndPoints retval2; // Matches exact on local port/adder, wildcards on others |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
189 |
EndPoints retval3; // Matches all but local address |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
190 |
EndPoints retval4; // Exact match on all 4 |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
191 |
|
1828
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
192 |
//NS_LOG_PARAMS (this << daddr << dport << saddr << sport); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
193 |
NS_LOG_PARAMS_BEGIN (); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
194 |
NS_LOG_PARAM (this); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
195 |
NS_LOG_PARAM (daddr); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
196 |
NS_LOG_PARAM (dport); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
197 |
NS_LOG_PARAM (saddr); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
198 |
NS_LOG_PARAM (sport); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
199 |
NS_LOG_PARAM (incomingInterface); |
6ab68edddf45
nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents:
1524
diff
changeset
|
200 |
NS_LOG_PARAMS_END (); |
2363
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
201 |
NS_LOG_DEBUG ("Looking up endpoint for destination address " << daddr); |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
202 |
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
203 |
{ |
2363
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
204 |
Ipv4EndPoint* endP = *i; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
205 |
NS_LOG_DEBUG ("Looking at endpoint dport=" << endP->GetLocalPort () |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
206 |
<< " daddr=" << endP->GetLocalAddress () |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
207 |
<< " sport=" << endP->GetPeerPort () |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
208 |
<< " saddr=" << endP->GetPeerAddress ()); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
209 |
if (endP->GetLocalPort () != dport) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
210 |
{ |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
211 |
NS_LOG_LOGIC ("Skipping endpoint " << &endP |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
212 |
<< " because endpoint dport " |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
213 |
<< endP->GetLocalPort () |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
214 |
<< " does not match packet dport " << dport); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
215 |
continue; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
216 |
} |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
217 |
bool isBroadcast = (daddr.IsBroadcast () || |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
218 |
daddr.IsSubnetDirectedBroadcast ( |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
219 |
incomingInterface->GetNetworkMask ())); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
220 |
Ipv4Address incomingInterfaceAddr = incomingInterface->GetAddress (); |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
221 |
NS_LOG_DEBUG ("dest addr " << daddr << " broadcast? " << isBroadcast); |
2363
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
222 |
bool localAddressMatchesWildCard = |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2364
diff
changeset
|
223 |
endP->GetLocalAddress() == Ipv4Address::GetAny(); |
2363
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
224 |
bool localAddressMatchesExact = endP->GetLocalAddress () == daddr; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
225 |
|
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
226 |
if (isBroadcast) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
227 |
{ |
2364
a78056f7a7b4
Cleanup of ipv4endpointdemux and tcpl4protocol
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2363
diff
changeset
|
228 |
NS_LOG_DEBUG("Found bcast, localaddr " << endP->GetLocalAddress()); |
2363
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
229 |
} |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
230 |
|
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
231 |
if (isBroadcast && (endP->GetLocalAddress() != Ipv4Address::GetAny())) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
232 |
{ |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
233 |
localAddressMatchesExact = (endP->GetLocalAddress () == |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
234 |
incomingInterfaceAddr); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
235 |
} |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
236 |
// if no match here, keep looking |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
237 |
if (!(localAddressMatchesExact || localAddressMatchesWildCard)) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
238 |
continue; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
239 |
bool remotePeerMatchesExact = endP->GetPeerPort () == sport; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
240 |
bool remotePeerMatchesWildCard = endP->GetPeerPort() == 0; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
241 |
bool remoteAddressMatchesExact = endP->GetPeerAddress () == saddr; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
242 |
bool remoteAddressMatchesWildCard = endP->GetPeerAddress () == |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
243 |
Ipv4Address::GetAny(); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
244 |
// If remote does not match either with exact or wildcard, |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
245 |
// skip this one |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
246 |
if (!(remotePeerMatchesExact || remotePeerMatchesWildCard)) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
247 |
continue; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
248 |
if (!(remoteAddressMatchesExact || remoteAddressMatchesWildCard)) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
249 |
continue; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
250 |
|
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
251 |
// Now figure out which return list to add this one to |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
252 |
if (localAddressMatchesWildCard && |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
253 |
remotePeerMatchesWildCard && |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
254 |
remoteAddressMatchesWildCard) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
255 |
{ // Only local port matches exactly |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
256 |
retval1.push_back(endP); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
257 |
} |
2364
a78056f7a7b4
Cleanup of ipv4endpointdemux and tcpl4protocol
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2363
diff
changeset
|
258 |
if ((localAddressMatchesExact || (isBroadcast && localAddressMatchesWildCard))&& |
2363
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
259 |
remotePeerMatchesWildCard && |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
260 |
remoteAddressMatchesWildCard) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
261 |
{ // Only local port and local address matches exactly |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
262 |
retval2.push_back(endP); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
263 |
} |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
264 |
if (localAddressMatchesWildCard && |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
265 |
remotePeerMatchesExact && |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
266 |
remoteAddressMatchesExact) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
267 |
{ // All but local address |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
268 |
retval3.push_back(endP); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
269 |
} |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
270 |
if (localAddressMatchesExact && |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
271 |
remotePeerMatchesExact && |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
272 |
remoteAddressMatchesExact) |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
273 |
{ // All 4 match |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
274 |
retval4.push_back(endP); |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
275 |
} |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
276 |
} |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
277 |
|
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
278 |
// Here we find the most exact match |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
279 |
if (!retval4.empty()) return retval4; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
280 |
if (!retval3.empty()) return retval3; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
281 |
if (!retval2.empty()) return retval2; |
fec623ea779b
Fixes to tcp and to the ipv4endpointdemux to allow forking to work correctly
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
282 |
return retval1; // might be empty if no matches |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
283 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
284 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
285 |
uint16_t |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
286 |
Ipv4EndPointDemux::AllocateEphemeralPort (void) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
287 |
{ |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
984
diff
changeset
|
288 |
NS_LOG_FUNCTION; |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
289 |
uint16_t port = m_ephemeral; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
290 |
do |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
291 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
292 |
port++; |
1513
d16f6fd70397
change ephemeral port range to 49152-65535 (IANA recommendation)
Tom Henderson <tomh@tomh.org>
parents:
1504
diff
changeset
|
293 |
if (port == 65535) |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
294 |
{ |
1513
d16f6fd70397
change ephemeral port range to 49152-65535 (IANA recommendation)
Tom Henderson <tomh@tomh.org>
parents:
1504
diff
changeset
|
295 |
port = 49152; |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
296 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
297 |
if (!LookupPortLocal (port)) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
298 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
299 |
return port; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
300 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
301 |
} while (port != m_ephemeral); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
302 |
return 0; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
303 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
304 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
305 |
} //namespace ns3 |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
306 |