View | Details | Raw Unified | Return to bug 2762
Collapse All | Expand All

(-)a/CHANGES.html (+5 lines)
 Lines 130-135    Link Here 
130
    <b>Previously, a socket bound to an unicast address received also subnet-directed broadcast packets. 
130
    <b>Previously, a socket bound to an unicast address received also subnet-directed broadcast packets. 
131
    This is not anymore possible</b>.
131
    This is not anymore possible</b>.
132
</li>
132
</li>
133
<li>You can now Bind as many socket as you want to an address/port, provided that they are bound to different NetDevices.
134
    Moreover, BindToNetDevice does not anymore call Bind. In other terms, Bind and BindToNetDevice can be called
135
    in any order.
136
    However, it is suggested to use BindToNetDevice <i>before</i> Bind in order to avoid conflicts.
137
</li>
133
</ul>
138
</ul>
134
<h2>Changes to build system:</h2>
139
<h2>Changes to build system:</h2>
135
<ul>
140
<ul>
(-)a/src/internet/model/ipv4-end-point-demux.cc (-18 / +24 lines)
 Lines 60-72    Link Here 
60
}
60
}
61
61
62
bool
62
bool
63
Ipv4EndPointDemux::LookupLocal (Ipv4Address addr, uint16_t port)
63
Ipv4EndPointDemux::LookupLocal (Ptr<NetDevice> boundNetDevice, Ipv4Address addr, uint16_t port)
64
{
64
{
65
  NS_LOG_FUNCTION (this << addr << port);
65
  NS_LOG_FUNCTION (this << addr << port);
66
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
66
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
67
    {
67
    {
68
      if ((*i)->GetLocalPort () == port &&
68
      if ((*i)->GetLocalPort () == port &&
69
          (*i)->GetLocalAddress () == addr) 
69
          (*i)->GetLocalAddress () == addr &&
70
          (*i)->GetBoundNetDevice () == boundNetDevice)
70
        {
71
        {
71
          return true;
72
          return true;
72
        }
73
        }
 Lines 107-126    Link Here 
107
}
108
}
108
109
109
Ipv4EndPoint *
110
Ipv4EndPoint *
110
Ipv4EndPointDemux::Allocate (uint16_t port)
111
Ipv4EndPointDemux::Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port)
111
{
112
{
112
  NS_LOG_FUNCTION (this <<  port);
113
  NS_LOG_FUNCTION (this <<  port << boundNetDevice);
113
114
114
  return Allocate (Ipv4Address::GetAny (), port);
115
  return Allocate (boundNetDevice, Ipv4Address::GetAny (), port);
115
}
116
}
116
117
117
Ipv4EndPoint *
118
Ipv4EndPoint *
118
Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
119
Ipv4EndPointDemux::Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port)
119
{
120
{
120
  NS_LOG_FUNCTION (this << address << port);
121
  NS_LOG_FUNCTION (this << address << port << boundNetDevice);
121
  if (LookupLocal (address, port)) 
122
  if (LookupLocal (boundNetDevice, address, port) || LookupLocal (0, address, port))
122
    {
123
    {
123
      NS_LOG_WARN ("Duplicate address/port; failing.");
124
      NS_LOG_WARN ("Duplicated endpoint.");
124
      return 0;
125
      return 0;
125
    }
126
    }
126
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
127
  Ipv4EndPoint *endPoint = new Ipv4EndPoint (address, port);
 Lines 130-148    Link Here 
130
}
131
}
131
132
132
Ipv4EndPoint *
133
Ipv4EndPoint *
133
Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort,
134
Ipv4EndPointDemux::Allocate (Ptr<NetDevice> boundNetDevice,
135
                             Ipv4Address localAddress, uint16_t localPort,
134
                             Ipv4Address peerAddress, uint16_t peerPort)
136
                             Ipv4Address peerAddress, uint16_t peerPort)
135
{
137
{
136
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
138
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort << boundNetDevice);
137
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
139
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
138
    {
140
    {
139
      if ((*i)->GetLocalPort () == localPort &&
141
      if ((*i)->GetLocalPort () == localPort &&
140
          (*i)->GetLocalAddress () == localAddress &&
142
          (*i)->GetLocalAddress () == localAddress &&
141
          (*i)->GetPeerPort () == peerPort &&
143
          (*i)->GetPeerPort () == peerPort &&
142
          (*i)->GetPeerAddress () == peerAddress) 
144
          (*i)->GetPeerAddress () == peerAddress &&
145
          ((*i)->GetBoundNetDevice () == boundNetDevice || (*i)->GetBoundNetDevice () == 0))
143
        {
146
        {
144
          NS_LOG_WARN ("No way we can allocate this end-point.");
147
          NS_LOG_WARN ("Duplicated endpoint.");
145
          /* no way we can allocate this end-point. */
146
          return 0;
148
          return 0;
147
        }
149
        }
148
    }
150
    }
 Lines 323-332    Link Here 
323
    }
325
    }
324
326
325
  // Here we find the most exact match
327
  // Here we find the most exact match
326
  if (!retval4.empty ()) return retval4;
328
  EndPoints retval;
327
  if (!retval3.empty ()) return retval3;
329
  if (!retval4.empty ()) retval = retval4;
328
  if (!retval2.empty ()) return retval2;
330
  else if (!retval3.empty ()) retval = retval3;
329
  return retval1;  // might be empty if no matches
331
  else if (!retval2.empty ()) retval = retval2;
332
  else retval = retval1;
333
334
  NS_ABORT_MSG_IF (retval.size () > 1, "Too many endpoints - perhaps you created too many sockets without binding them to different NetDevices.");
335
  return retval;  // might be empty if no matches
330
}
336
}
331
337
332
Ipv4EndPoint *
338
Ipv4EndPoint *
(-)a/src/internet/model/ipv4-end-point-demux.h (-7 / +10 lines)
 Lines 72-82    Link Here 
72
72
73
  /**
73
  /**
74
   * \brief Lookup for address and port.
74
   * \brief Lookup for address and port.
75
   * \param boundNetDevice Bound NetDevice (if any)
75
   * \param addr address to test
76
   * \param addr address to test
76
   * \param port port to test
77
   * \param port port to test
77
   * \return true if there is a match in EndPoints, false otherwise
78
   * \return true if there is a match in EndPoints, false otherwise
78
   */
79
   */
79
  bool LookupLocal (Ipv4Address addr, uint16_t port);
80
  bool LookupLocal (Ptr<NetDevice> boundNetDevice, Ipv4Address addr, uint16_t port);
80
81
81
  /**
82
  /**
82
   * \brief lookup for a match with all the parameters.
83
   * \brief lookup for a match with all the parameters.
 Lines 130-160    Link Here 
130
131
131
  /**
132
  /**
132
   * \brief Allocate a Ipv4EndPoint.
133
   * \brief Allocate a Ipv4EndPoint.
134
   * \param boundNetDevice Bound NetDevice (if any)
133
   * \param port local port
135
   * \param port local port
134
   * \return an Ipv4EndPoint instance
136
   * \return an Ipv4EndPoint instance
135
   */
137
   */
136
  Ipv4EndPoint *Allocate (uint16_t port);
138
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port);
137
139
138
  /**
140
  /**
139
   * \brief Allocate a Ipv4EndPoint.
141
   * \brief Allocate a Ipv4EndPoint.
142
   * \param boundNetDevice Bound NetDevice (if any)
140
   * \param address local address
143
   * \param address local address
141
   * \param port local port
144
   * \param port local port
142
   * \return an Ipv4EndPoint instance
145
   * \return an Ipv4EndPoint instance
143
   */
146
   */
144
  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
147
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
145
148
146
  /**
149
  /**
147
   * \brief Allocate a Ipv4EndPoint.
150
   * \brief Allocate a Ipv4EndPoint.
151
   * \param boundNetDevice Bound NetDevice (if any)
148
   * \param localAddress local address
152
   * \param localAddress local address
149
   * \param localPort local port
153
   * \param localPort local port
150
   * \param peerAddress peer address
154
   * \param peerAddress peer address
151
   * \param peerPort peer port
155
   * \param peerPort peer port
152
   * \return an Ipv4EndPoint instance
156
   * \return an Ipv4EndPoint instance
153
   */
157
   */
154
  Ipv4EndPoint *Allocate (Ipv4Address localAddress, 
158
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice,
155
                          uint16_t localPort,
159
                          Ipv4Address localAddress, uint16_t localPort,
156
                          Ipv4Address peerAddress, 
160
                          Ipv4Address peerAddress, uint16_t peerPort);
157
                          uint16_t peerPort);
158
161
159
  /**
162
  /**
160
   * \brief Remove a end point.
163
   * \brief Remove a end point.
(-)a/src/internet/model/ipv6-end-point-demux.cc (-35 / +32 lines)
 Lines 58-70    Link Here 
58
  return false;
58
  return false;
59
}
59
}
60
60
61
bool Ipv6EndPointDemux::LookupLocal (Ipv6Address addr, uint16_t port)
61
bool Ipv6EndPointDemux::LookupLocal (Ptr<NetDevice> boundNetDevice, Ipv6Address addr, uint16_t port)
62
{
62
{
63
  NS_LOG_FUNCTION (this << addr << port);
63
  NS_LOG_FUNCTION (this << addr << port);
64
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
64
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
65
    {
65
    {
66
      if ((*i)->GetLocalPort () == port
66
      if ((*i)->GetLocalPort () == port &&
67
          && (*i)->GetLocalAddress () == addr)
67
          (*i)->GetLocalAddress () == addr &&
68
          (*i)->GetBoundNetDevice () == boundNetDevice)
68
        {
69
        {
69
          return true;
70
          return true;
70
        }
71
        }
 Lines 74-80    Link Here 
74
75
75
Ipv6EndPoint* Ipv6EndPointDemux::Allocate ()
76
Ipv6EndPoint* Ipv6EndPointDemux::Allocate ()
76
{
77
{
77
  NS_LOG_FUNCTION_NOARGS ();
78
  NS_LOG_FUNCTION (this);
78
  uint16_t port = AllocateEphemeralPort ();
79
  uint16_t port = AllocateEphemeralPort ();
79
  if (port == 0)
80
  if (port == 0)
80
    {
81
    {
 Lines 102-120    Link Here 
102
  return endPoint;
103
  return endPoint;
103
}
104
}
104
105
105
Ipv6EndPoint* Ipv6EndPointDemux::Allocate (uint16_t port)
106
Ipv6EndPoint* Ipv6EndPointDemux::Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port)
106
{
107
{
107
  NS_LOG_FUNCTION (this <<  port);
108
  NS_LOG_FUNCTION (this << boundNetDevice << port);
108
109
109
  return Allocate (Ipv6Address::GetAny (), port);
110
  return Allocate (boundNetDevice, Ipv6Address::GetAny (), port);
110
}
111
}
111
112
112
Ipv6EndPoint* Ipv6EndPointDemux::Allocate (Ipv6Address address, uint16_t port)
113
Ipv6EndPoint* Ipv6EndPointDemux::Allocate (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port)
113
{
114
{
114
  NS_LOG_FUNCTION (this << address << port);
115
  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
115
  if (LookupLocal (address, port))
116
  if (LookupLocal (boundNetDevice, address, port) || LookupLocal (0, address, port))
116
    {
117
    {
117
      NS_LOG_WARN ("Duplicate address/port; failing.");
118
      NS_LOG_WARN ("Duplicated endpoint.");
118
      return 0;
119
      return 0;
119
    }
120
    }
120
  Ipv6EndPoint *endPoint = new Ipv6EndPoint (address, port);
121
  Ipv6EndPoint *endPoint = new Ipv6EndPoint (address, port);
 Lines 123-141    Link Here 
123
  return endPoint;
124
  return endPoint;
124
}
125
}
125
126
126
Ipv6EndPoint* Ipv6EndPointDemux::Allocate (Ipv6Address localAddress, uint16_t localPort,
127
Ipv6EndPoint* Ipv6EndPointDemux::Allocate (Ptr<NetDevice> boundNetDevice,
128
                                           Ipv6Address localAddress, uint16_t localPort,
127
                                           Ipv6Address peerAddress, uint16_t peerPort)
129
                                           Ipv6Address peerAddress, uint16_t peerPort)
128
{
130
{
129
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
131
  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
130
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
132
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
131
    {
133
    {
132
      if ((*i)->GetLocalPort () == localPort
134
      if ((*i)->GetLocalPort () == localPort &&
133
          && (*i)->GetLocalAddress () == localAddress
135
          (*i)->GetLocalAddress () == localAddress &&
134
          && (*i)->GetPeerPort () == peerPort
136
          (*i)->GetPeerPort () == peerPort &&
135
          && (*i)->GetPeerAddress () == peerAddress)
137
          (*i)->GetPeerAddress () == peerAddress &&
138
          ((*i)->GetBoundNetDevice () == boundNetDevice || (*i)->GetBoundNetDevice () == 0))
136
        {
139
        {
137
          NS_LOG_WARN ("No way we can allocate this end-point.");
140
          NS_LOG_WARN ("Duplicated endpoint.");
138
          /* no way we can allocate this end-point. */
139
          return 0;
141
          return 0;
140
        }
142
        }
141
    }
143
    }
 Lines 150-156    Link Here 
150
152
151
void Ipv6EndPointDemux::DeAllocate (Ipv6EndPoint *endPoint)
153
void Ipv6EndPointDemux::DeAllocate (Ipv6EndPoint *endPoint)
152
{
154
{
153
  NS_LOG_FUNCTION_NOARGS ();
155
  NS_LOG_FUNCTION (this);
154
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
156
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
155
    {
157
    {
156
      if (*i == endPoint)
158
      if (*i == endPoint)
 Lines 275-294    Link Here 
275
        }
277
        }
276
    }
278
    }
277
279
278
  /* Here we find the most exact match */
280
  // Here we find the most exact match
279
  if (!retval4.empty ())
281
  EndPoints retval;
280
    {
282
  if (!retval4.empty ()) retval = retval4;
281
      return retval4;
283
  else if (!retval3.empty ()) retval = retval3;
282
    }
284
  else if (!retval2.empty ()) retval = retval2;
283
  if (!retval3.empty ())
285
  else retval = retval1;
284
    {
286
285
      return retval3;
287
  NS_ABORT_MSG_IF (retval.size () > 1, "Too many endpoints - perhaps you created too many sockets without binding them to different NetDevices.");
286
    }
288
  return retval;  // might be empty if no matches
287
  if (!retval2.empty ())
288
    {
289
      return retval2;
290
    }
291
  return retval1;  /* might be empty if no matches */
292
}
289
}
293
290
294
Ipv6EndPoint* Ipv6EndPointDemux::SimpleLookup (Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport)
291
Ipv6EndPoint* Ipv6EndPointDemux::SimpleLookup (Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport)
 Lines 333-339    Link Here 
333
330
334
uint16_t Ipv6EndPointDemux::AllocateEphemeralPort ()
331
uint16_t Ipv6EndPointDemux::AllocateEphemeralPort ()
335
{
332
{
336
  NS_LOG_FUNCTION_NOARGS ();
333
  NS_LOG_FUNCTION (this);
337
  uint16_t port = m_ephemeral;
334
  uint16_t port = m_ephemeral;
338
  int count = m_portLast - m_portFirst;
335
  int count = m_portLast - m_portFirst;
339
  do
336
  do
(-)a/src/internet/model/ipv6-end-point-demux.h (-4 / +10 lines)
 Lines 60-70    Link Here 
60
60
61
  /**
61
  /**
62
   * \brief Lookup for address and port.
62
   * \brief Lookup for address and port.
63
   * \param boundNetDevice Bound NetDevice (if any)
63
   * \param addr address to test
64
   * \param addr address to test
64
   * \param port port to test
65
   * \param port port to test
65
   * \return true if there is a match in EndPoints, false otherwise
66
   * \return true if there is a match in EndPoints, false otherwise
66
   */
67
   */
67
  bool LookupLocal (Ipv6Address addr, uint16_t port);
68
  bool LookupLocal (Ptr<NetDevice> boundNetDevice, Ipv6Address addr, uint16_t port);
68
69
69
  /**
70
  /**
70
   * \brief lookup for a match with all the parameters.
71
   * \brief lookup for a match with all the parameters.
 Lines 111-138    Link Here 
111
112
112
  /**
113
  /**
113
   * \brief Allocate a Ipv6EndPoint.
114
   * \brief Allocate a Ipv6EndPoint.
115
   * \param boundNetDevice Bound NetDevice (if any)
114
   * \param port local port
116
   * \param port local port
115
   * \return an Ipv6EndPoint instance
117
   * \return an Ipv6EndPoint instance
116
   */
118
   */
117
  Ipv6EndPoint * Allocate (uint16_t port);
119
  Ipv6EndPoint * Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port);
118
120
119
  /**
121
  /**
120
   * \brief Allocate a Ipv6EndPoint.
122
   * \brief Allocate a Ipv6EndPoint.
123
   * \param boundNetDevice Bound NetDevice (if any)
121
   * \param address local address
124
   * \param address local address
122
   * \param port local port
125
   * \param port local port
123
   * \return an Ipv6EndPoint instance
126
   * \return an Ipv6EndPoint instance
124
   */
127
   */
125
  Ipv6EndPoint * Allocate (Ipv6Address address, uint16_t port);
128
  Ipv6EndPoint * Allocate (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
126
129
127
  /**
130
  /**
128
   * \brief Allocate a Ipv6EndPoint.
131
   * \brief Allocate a Ipv6EndPoint.
132
   * \param boundNetDevice Bound NetDevice (if any)
129
   * \param localAddress local address
133
   * \param localAddress local address
130
   * \param localPort local port
134
   * \param localPort local port
131
   * \param peerAddress peer address
135
   * \param peerAddress peer address
132
   * \param peerPort peer port
136
   * \param peerPort peer port
133
   * \return an Ipv6EndPoint instance
137
   * \return an Ipv6EndPoint instance
134
   */
138
   */
135
  Ipv6EndPoint * Allocate (Ipv6Address localAddress, uint16_t localPort, Ipv6Address peerAddress, uint16_t peerPort);
139
  Ipv6EndPoint * Allocate (Ptr<NetDevice> boundNetDevice,
140
                           Ipv6Address localAddress, uint16_t localPort,
141
                           Ipv6Address peerAddress, uint16_t peerPort);
136
142
137
  /**
143
  /**
138
   * \brief Remove a end point.
144
   * \brief Remove a end point.
(-)a/src/internet/model/tcp-l4-protocol.cc (-20 / +24 lines)
 Lines 205-211    Link Here 
205
Ipv4EndPoint *
205
Ipv4EndPoint *
206
TcpL4Protocol::Allocate (void)
206
TcpL4Protocol::Allocate (void)
207
{
207
{
208
  NS_LOG_FUNCTION_NOARGS ();
208
  NS_LOG_FUNCTION (this);
209
  return m_endPoints->Allocate ();
209
  return m_endPoints->Allocate ();
210
}
210
}
211
211
 Lines 217-241    Link Here 
217
}
217
}
218
218
219
Ipv4EndPoint *
219
Ipv4EndPoint *
220
TcpL4Protocol::Allocate (uint16_t port)
220
TcpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port)
221
{
221
{
222
  NS_LOG_FUNCTION (this << port);
222
  NS_LOG_FUNCTION (this << boundNetDevice << port);
223
  return m_endPoints->Allocate (port);
223
  return m_endPoints->Allocate (boundNetDevice, port);
224
}
224
}
225
225
226
Ipv4EndPoint *
226
Ipv4EndPoint *
227
TcpL4Protocol::Allocate (Ipv4Address address, uint16_t port)
227
TcpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port)
228
{
228
{
229
  NS_LOG_FUNCTION (this << address << port);
229
  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
230
  return m_endPoints->Allocate (address, port);
230
  return m_endPoints->Allocate (boundNetDevice, address, port);
231
}
231
}
232
232
233
Ipv4EndPoint *
233
Ipv4EndPoint *
234
TcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
234
TcpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice,
235
                         Ipv4Address localAddress, uint16_t localPort,
235
                         Ipv4Address peerAddress, uint16_t peerPort)
236
                         Ipv4Address peerAddress, uint16_t peerPort)
236
{
237
{
237
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
238
  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
238
  return m_endPoints->Allocate (localAddress, localPort,
239
  return m_endPoints->Allocate (boundNetDevice,
240
                                localAddress, localPort,
239
                                peerAddress, peerPort);
241
                                peerAddress, peerPort);
240
}
242
}
241
243
 Lines 249-255    Link Here 
249
Ipv6EndPoint *
251
Ipv6EndPoint *
250
TcpL4Protocol::Allocate6 (void)
252
TcpL4Protocol::Allocate6 (void)
251
{
253
{
252
  NS_LOG_FUNCTION_NOARGS ();
254
  NS_LOG_FUNCTION (this);
253
  return m_endPoints6->Allocate ();
255
  return m_endPoints6->Allocate ();
254
}
256
}
255
257
 Lines 261-285    Link Here 
261
}
263
}
262
264
263
Ipv6EndPoint *
265
Ipv6EndPoint *
264
TcpL4Protocol::Allocate6 (uint16_t port)
266
TcpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port)
265
{
267
{
266
  NS_LOG_FUNCTION (this << port);
268
  NS_LOG_FUNCTION (this << boundNetDevice << port);
267
  return m_endPoints6->Allocate (port);
269
  return m_endPoints6->Allocate (boundNetDevice, port);
268
}
270
}
269
271
270
Ipv6EndPoint *
272
Ipv6EndPoint *
271
TcpL4Protocol::Allocate6 (Ipv6Address address, uint16_t port)
273
TcpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port)
272
{
274
{
273
  NS_LOG_FUNCTION (this << address << port);
275
  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
274
  return m_endPoints6->Allocate (address, port);
276
  return m_endPoints6->Allocate (boundNetDevice, address, port);
275
}
277
}
276
278
277
Ipv6EndPoint *
279
Ipv6EndPoint *
278
TcpL4Protocol::Allocate6 (Ipv6Address localAddress, uint16_t localPort,
280
TcpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice,
281
                          Ipv6Address localAddress, uint16_t localPort,
279
                          Ipv6Address peerAddress, uint16_t peerPort)
282
                          Ipv6Address peerAddress, uint16_t peerPort)
280
{
283
{
281
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
284
  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
282
  return m_endPoints6->Allocate (localAddress, localPort,
285
  return m_endPoints6->Allocate (boundNetDevice,
286
                                 localAddress, localPort,
283
                                 peerAddress, peerPort);
287
                                 peerAddress, peerPort);
284
}
288
}
285
289
(-)a/src/internet/model/tcp-l4-protocol.h (-6 / +14 lines)
 Lines 128-153    Link Here 
128
  Ipv4EndPoint *Allocate (Ipv4Address address);
128
  Ipv4EndPoint *Allocate (Ipv4Address address);
129
  /**
129
  /**
130
   * \brief Allocate an IPv4 Endpoint
130
   * \brief Allocate an IPv4 Endpoint
131
   * \param boundNetDevice Bound NetDevice (if any)
131
   * \param port port to use
132
   * \param port port to use
132
   * \return the Endpoint
133
   * \return the Endpoint
133
   */
134
   */
134
  Ipv4EndPoint *Allocate (uint16_t port);
135
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port);
135
  /**
136
  /**
136
   * \brief Allocate an IPv4 Endpoint
137
   * \brief Allocate an IPv4 Endpoint
138
   * \param boundNetDevice Bound NetDevice (if any)
137
   * \param address address to use
139
   * \param address address to use
138
   * \param port port to use
140
   * \param port port to use
139
   * \return the Endpoint
141
   * \return the Endpoint
140
   */
142
   */
141
  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
143
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
142
  /**
144
  /**
143
   * \brief Allocate an IPv4 Endpoint
145
   * \brief Allocate an IPv4 Endpoint
146
   * \param boundNetDevice Bound NetDevice (if any)
144
   * \param localAddress local address to use
147
   * \param localAddress local address to use
145
   * \param localPort local port to use
148
   * \param localPort local port to use
146
   * \param peerAddress remote address to use
149
   * \param peerAddress remote address to use
147
   * \param peerPort remote port to use
150
   * \param peerPort remote port to use
148
   * \return the Endpoint
151
   * \return the Endpoint
149
   */
152
   */
150
  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
153
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice,
154
                          Ipv4Address localAddress, uint16_t localPort,
151
                          Ipv4Address peerAddress, uint16_t peerPort);
155
                          Ipv4Address peerAddress, uint16_t peerPort);
152
  /**
156
  /**
153
   * \brief Allocate an IPv6 Endpoint
157
   * \brief Allocate an IPv6 Endpoint
 Lines 162-187    Link Here 
162
  Ipv6EndPoint *Allocate6 (Ipv6Address address);
166
  Ipv6EndPoint *Allocate6 (Ipv6Address address);
163
  /**
167
  /**
164
   * \brief Allocate an IPv6 Endpoint
168
   * \brief Allocate an IPv6 Endpoint
169
   * \param boundNetDevice Bound NetDevice (if any)
165
   * \param port port to use
170
   * \param port port to use
166
   * \return the Endpoint
171
   * \return the Endpoint
167
   */
172
   */
168
  Ipv6EndPoint *Allocate6 (uint16_t port);
173
  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port);
169
  /**
174
  /**
170
   * \brief Allocate an IPv6 Endpoint
175
   * \brief Allocate an IPv6 Endpoint
176
   * \param boundNetDevice Bound NetDevice (if any)
171
   * \param address address to use
177
   * \param address address to use
172
   * \param port port to use
178
   * \param port port to use
173
   * \return the Endpoint
179
   * \return the Endpoint
174
   */
180
   */
175
  Ipv6EndPoint *Allocate6 (Ipv6Address address, uint16_t port);
181
  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
176
  /**
182
  /**
177
   * \brief Allocate an IPv6 Endpoint
183
   * \brief Allocate an IPv6 Endpoint
184
   * \param boundNetDevice Bound NetDevice (if any)
178
   * \param localAddress local address to use
185
   * \param localAddress local address to use
179
   * \param localPort local port to use
186
   * \param localPort local port to use
180
   * \param peerAddress remote address to use
187
   * \param peerAddress remote address to use
181
   * \param peerPort remote port to use
188
   * \param peerPort remote port to use
182
   * \return the Endpoint
189
   * \return the Endpoint
183
   */
190
   */
184
  Ipv6EndPoint *Allocate6 (Ipv6Address localAddress, uint16_t localPort,
191
  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice,
192
                           Ipv6Address localAddress, uint16_t localPort,
185
                           Ipv6Address peerAddress, uint16_t peerPort);
193
                           Ipv6Address peerAddress, uint16_t peerPort);
186
194
187
  /**
195
  /**
(-)a/src/internet/model/tcp-socket-base.cc (-23 / +13 lines)
 Lines 579-585    Link Here 
579
        }
579
        }
580
      else if (ipv4 == Ipv4Address::GetAny () && port != 0)
580
      else if (ipv4 == Ipv4Address::GetAny () && port != 0)
581
        {
581
        {
582
          m_endPoint = m_tcp->Allocate (port);
582
          m_endPoint = m_tcp->Allocate (GetBoundNetDevice (), port);
583
        }
583
        }
584
      else if (ipv4 != Ipv4Address::GetAny () && port == 0)
584
      else if (ipv4 != Ipv4Address::GetAny () && port == 0)
585
        {
585
        {
 Lines 587-593    Link Here 
587
        }
587
        }
588
      else if (ipv4 != Ipv4Address::GetAny () && port != 0)
588
      else if (ipv4 != Ipv4Address::GetAny () && port != 0)
589
        {
589
        {
590
          m_endPoint = m_tcp->Allocate (ipv4, port);
590
          m_endPoint = m_tcp->Allocate (GetBoundNetDevice (), ipv4, port);
591
        }
591
        }
592
      if (0 == m_endPoint)
592
      if (0 == m_endPoint)
593
        {
593
        {
 Lines 606-612    Link Here 
606
        }
606
        }
607
      else if (ipv6 == Ipv6Address::GetAny () && port != 0)
607
      else if (ipv6 == Ipv6Address::GetAny () && port != 0)
608
        {
608
        {
609
          m_endPoint6 = m_tcp->Allocate6 (port);
609
          m_endPoint6 = m_tcp->Allocate6 (GetBoundNetDevice (), port);
610
        }
610
        }
611
      else if (ipv6 != Ipv6Address::GetAny () && port == 0)
611
      else if (ipv6 != Ipv6Address::GetAny () && port == 0)
612
        {
612
        {
 Lines 614-620    Link Here 
614
        }
614
        }
615
      else if (ipv6 != Ipv6Address::GetAny () && port != 0)
615
      else if (ipv6 != Ipv6Address::GetAny () && port != 0)
616
        {
616
        {
617
          m_endPoint6 = m_tcp->Allocate6 (ipv6, port);
617
          m_endPoint6 = m_tcp->Allocate6 (GetBoundNetDevice (), ipv6, port);
618
        }
618
        }
619
      if (0 == m_endPoint6)
619
      if (0 == m_endPoint6)
620
        {
620
        {
 Lines 991-1017    Link Here 
991
{
991
{
992
  NS_LOG_FUNCTION (netdevice);
992
  NS_LOG_FUNCTION (netdevice);
993
  Socket::BindToNetDevice (netdevice); // Includes sanity check
993
  Socket::BindToNetDevice (netdevice); // Includes sanity check
994
  if (m_endPoint == 0)
994
  if (m_endPoint != 0)
995
    {
995
    {
996
      if (Bind () == -1)
996
      m_endPoint->BindToNetDevice (netdevice);
997
        {
998
          NS_ASSERT (m_endPoint == 0);
999
          return;
1000
        }
1001
      NS_ASSERT (m_endPoint != 0);
1002
    }
997
    }
1003
  m_endPoint->BindToNetDevice (netdevice);
998
1004
999
  if (m_endPoint6 != 0)
1005
  if (m_endPoint6 == 0)
1006
    {
1000
    {
1007
      if (Bind6 () == -1)
1001
      m_endPoint6->BindToNetDevice (netdevice);
1008
        {
1009
          NS_ASSERT (m_endPoint6 == 0);
1010
          return;
1011
        }
1012
      NS_ASSERT (m_endPoint6 != 0);
1013
    }
1002
    }
1014
  m_endPoint6->BindToNetDevice (netdevice);
1015
1003
1016
  return;
1004
  return;
1017
}
1005
}
 Lines 2577-2583    Link Here 
2577
  // Get port and address from peer (connecting host)
2565
  // Get port and address from peer (connecting host)
2578
  if (InetSocketAddress::IsMatchingType (toAddress))
2566
  if (InetSocketAddress::IsMatchingType (toAddress))
2579
    {
2567
    {
2580
      m_endPoint = m_tcp->Allocate (InetSocketAddress::ConvertFrom (toAddress).GetIpv4 (),
2568
      m_endPoint = m_tcp->Allocate (GetBoundNetDevice (),
2569
                                    InetSocketAddress::ConvertFrom (toAddress).GetIpv4 (),
2581
                                    InetSocketAddress::ConvertFrom (toAddress).GetPort (),
2570
                                    InetSocketAddress::ConvertFrom (toAddress).GetPort (),
2582
                                    InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
2571
                                    InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
2583
                                    InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
2572
                                    InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
 Lines 2585-2591    Link Here 
2585
    }
2574
    }
2586
  else if (Inet6SocketAddress::IsMatchingType (toAddress))
2575
  else if (Inet6SocketAddress::IsMatchingType (toAddress))
2587
    {
2576
    {
2588
      m_endPoint6 = m_tcp->Allocate6 (Inet6SocketAddress::ConvertFrom (toAddress).GetIpv6 (),
2577
      m_endPoint6 = m_tcp->Allocate6 (GetBoundNetDevice (),
2578
                                      Inet6SocketAddress::ConvertFrom (toAddress).GetIpv6 (),
2589
                                      Inet6SocketAddress::ConvertFrom (toAddress).GetPort (),
2579
                                      Inet6SocketAddress::ConvertFrom (toAddress).GetPort (),
2590
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
2580
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
2591
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
2581
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
(-)a/src/internet/model/udp-l4-protocol.cc (-22 / +26 lines)
 Lines 173-179    Link Here 
173
Ipv4EndPoint *
173
Ipv4EndPoint *
174
UdpL4Protocol::Allocate (void)
174
UdpL4Protocol::Allocate (void)
175
{
175
{
176
  NS_LOG_FUNCTION_NOARGS ();
176
  NS_LOG_FUNCTION (this);
177
  return m_endPoints->Allocate ();
177
  return m_endPoints->Allocate ();
178
}
178
}
179
179
 Lines 185-208    Link Here 
185
}
185
}
186
186
187
Ipv4EndPoint *
187
Ipv4EndPoint *
188
UdpL4Protocol::Allocate (uint16_t port)
188
UdpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port)
189
{
189
{
190
  NS_LOG_FUNCTION (this << port);
190
  NS_LOG_FUNCTION (this << boundNetDevice << port);
191
  return m_endPoints->Allocate (port);
191
  return m_endPoints->Allocate (boundNetDevice, port);
192
}
192
}
193
193
194
Ipv4EndPoint *
194
Ipv4EndPoint *
195
UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port)
195
UdpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port)
196
{
196
{
197
  NS_LOG_FUNCTION (this << address << port);
197
  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
198
  return m_endPoints->Allocate (address, port);
198
  return m_endPoints->Allocate (boundNetDevice, address, port);
199
}
199
}
200
Ipv4EndPoint *
200
Ipv4EndPoint *
201
UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
201
UdpL4Protocol::Allocate (Ptr<NetDevice> boundNetDevice,
202
                         Ipv4Address localAddress, uint16_t localPort,
202
                         Ipv4Address peerAddress, uint16_t peerPort)
203
                         Ipv4Address peerAddress, uint16_t peerPort)
203
{
204
{
204
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
205
  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
205
  return m_endPoints->Allocate (localAddress, localPort,
206
  return m_endPoints->Allocate (boundNetDevice,
207
                                localAddress, localPort,
206
                                peerAddress, peerPort);
208
                                peerAddress, peerPort);
207
}
209
}
208
210
 Lines 216-222    Link Here 
216
Ipv6EndPoint *
218
Ipv6EndPoint *
217
UdpL4Protocol::Allocate6 (void)
219
UdpL4Protocol::Allocate6 (void)
218
{
220
{
219
  NS_LOG_FUNCTION_NOARGS ();
221
  NS_LOG_FUNCTION (this);
220
  return m_endPoints6->Allocate ();
222
  return m_endPoints6->Allocate ();
221
}
223
}
222
224
 Lines 228-252    Link Here 
228
}
230
}
229
231
230
Ipv6EndPoint *
232
Ipv6EndPoint *
231
UdpL4Protocol::Allocate6 (uint16_t port)
233
UdpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port)
232
{
234
{
233
  NS_LOG_FUNCTION (this << port);
235
  NS_LOG_FUNCTION (this << boundNetDevice << port);
234
  return m_endPoints6->Allocate (port);
236
  return m_endPoints6->Allocate (boundNetDevice, port);
235
}
237
}
236
238
237
Ipv6EndPoint *
239
Ipv6EndPoint *
238
UdpL4Protocol::Allocate6 (Ipv6Address address, uint16_t port)
240
UdpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port)
239
{
241
{
240
  NS_LOG_FUNCTION (this << address << port);
242
  NS_LOG_FUNCTION (this << boundNetDevice << address << port);
241
  return m_endPoints6->Allocate (address, port);
243
  return m_endPoints6->Allocate (boundNetDevice, address, port);
242
}
244
}
243
Ipv6EndPoint *
245
Ipv6EndPoint *
244
UdpL4Protocol::Allocate6 (Ipv6Address localAddress, uint16_t localPort,
246
UdpL4Protocol::Allocate6 (Ptr<NetDevice> boundNetDevice,
245
                         Ipv6Address peerAddress, uint16_t peerPort)
247
                          Ipv6Address localAddress, uint16_t localPort,
248
                          Ipv6Address peerAddress, uint16_t peerPort)
246
{
249
{
247
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
250
  NS_LOG_FUNCTION (this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
248
  return m_endPoints6->Allocate (localAddress, localPort,
251
  return m_endPoints6->Allocate (boundNetDevice,
249
                                peerAddress, peerPort);
252
                                 localAddress, localPort,
253
                                 peerAddress, peerPort);
250
}
254
}
251
255
252
void 
256
void 
(-)a/src/internet/model/udp-l4-protocol.h (-6 / +15 lines)
 Lines 36-41    Link Here 
36
class Ipv6EndPointDemux;
36
class Ipv6EndPointDemux;
37
class Ipv6EndPoint;
37
class Ipv6EndPoint;
38
class UdpSocketImpl;
38
class UdpSocketImpl;
39
class NetDevice;
39
40
40
/**
41
/**
41
 * \ingroup internet
42
 * \ingroup internet
 Lines 96-121    Link Here 
96
  Ipv4EndPoint *Allocate (Ipv4Address address);
97
  Ipv4EndPoint *Allocate (Ipv4Address address);
97
  /**
98
  /**
98
   * \brief Allocate an IPv4 Endpoint
99
   * \brief Allocate an IPv4 Endpoint
100
   * \param boundNetDevice Bound NetDevice (if any)
99
   * \param port port to use
101
   * \param port port to use
100
   * \return the Endpoint
102
   * \return the Endpoint
101
   */
103
   */
102
  Ipv4EndPoint *Allocate (uint16_t port);
104
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port);
103
  /**
105
  /**
104
   * \brief Allocate an IPv4 Endpoint
106
   * \brief Allocate an IPv4 Endpoint
107
   * \param boundNetDevice Bound NetDevice (if any)
105
   * \param address address to use
108
   * \param address address to use
106
   * \param port port to use
109
   * \param port port to use
107
   * \return the Endpoint
110
   * \return the Endpoint
108
   */
111
   */
109
  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
112
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
110
  /**
113
  /**
111
   * \brief Allocate an IPv4 Endpoint
114
   * \brief Allocate an IPv4 Endpoint
115
   * \param boundNetDevice Bound NetDevice (if any)
112
   * \param localAddress local address to use
116
   * \param localAddress local address to use
113
   * \param localPort local port to use
117
   * \param localPort local port to use
114
   * \param peerAddress remote address to use
118
   * \param peerAddress remote address to use
115
   * \param peerPort remote port to use
119
   * \param peerPort remote port to use
116
   * \return the Endpoint
120
   * \return the Endpoint
117
   */
121
   */
118
  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
122
  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice,
123
                          Ipv4Address localAddress, uint16_t localPort,
119
                          Ipv4Address peerAddress, uint16_t peerPort);
124
                          Ipv4Address peerAddress, uint16_t peerPort);
120
125
121
  /**
126
  /**
 Lines 131-156    Link Here 
131
  Ipv6EndPoint *Allocate6 (Ipv6Address address);
136
  Ipv6EndPoint *Allocate6 (Ipv6Address address);
132
  /**
137
  /**
133
   * \brief Allocate an IPv6 Endpoint
138
   * \brief Allocate an IPv6 Endpoint
139
   * \param boundNetDevice Bound NetDevice (if any)
134
   * \param port port to use
140
   * \param port port to use
135
   * \return the Endpoint
141
   * \return the Endpoint
136
   */
142
   */
137
  Ipv6EndPoint *Allocate6 (uint16_t port);
143
  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port);
138
  /**
144
  /**
139
   * \brief Allocate an IPv6 Endpoint
145
   * \brief Allocate an IPv6 Endpoint
146
   * \param boundNetDevice Bound NetDevice (if any)
140
   * \param address address to use
147
   * \param address address to use
141
   * \param port port to use
148
   * \param port port to use
142
   * \return the Endpoint
149
   * \return the Endpoint
143
   */
150
   */
144
  Ipv6EndPoint *Allocate6 (Ipv6Address address, uint16_t port);
151
  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
145
  /**
152
  /**
146
   * \brief Allocate an IPv6 Endpoint
153
   * \brief Allocate an IPv6 Endpoint
154
   * \param boundNetDevice Bound NetDevice (if any)
147
   * \param localAddress local address to use
155
   * \param localAddress local address to use
148
   * \param localPort local port to use
156
   * \param localPort local port to use
149
   * \param peerAddress remote address to use
157
   * \param peerAddress remote address to use
150
   * \param peerPort remote port to use
158
   * \param peerPort remote port to use
151
   * \return the Endpoint
159
   * \return the Endpoint
152
   */
160
   */
153
  Ipv6EndPoint *Allocate6 (Ipv6Address localAddress, uint16_t localPort,
161
  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice,
162
                           Ipv6Address localAddress, uint16_t localPort,
154
                           Ipv6Address peerAddress, uint16_t peerPort);
163
                           Ipv6Address peerAddress, uint16_t peerPort);
155
164
156
  /**
165
  /**
(-)a/src/internet/model/udp-socket-impl.cc (-32 / +67 lines)
 Lines 233-238    Link Here 
233
{
233
{
234
  NS_LOG_FUNCTION_NOARGS ();
234
  NS_LOG_FUNCTION_NOARGS ();
235
  m_endPoint = m_udp->Allocate ();
235
  m_endPoint = m_udp->Allocate ();
236
  if (m_boundnetdevice)
237
    {
238
      m_endPoint->BindToNetDevice (m_boundnetdevice);
239
    }
236
  return FinishBind ();
240
  return FinishBind ();
237
}
241
}
238
242
 Lines 241-246    Link Here 
241
{
245
{
242
  NS_LOG_FUNCTION_NOARGS ();
246
  NS_LOG_FUNCTION_NOARGS ();
243
  m_endPoint6 = m_udp->Allocate6 ();
247
  m_endPoint6 = m_udp->Allocate6 ();
248
  if (m_boundnetdevice)
249
    {
250
      m_endPoint6->BindToNetDevice (m_boundnetdevice);
251
    }
244
  return FinishBind ();
252
  return FinishBind ();
245
}
253
}
246
254
 Lines 251-257    Link Here 
251
259
252
  if (InetSocketAddress::IsMatchingType (address))
260
  if (InetSocketAddress::IsMatchingType (address))
253
    {
261
    {
254
      NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated (maybe you used BindToNetDevice before Bind).");
262
      NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated.");
255
263
256
      InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
264
      InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
257
      Ipv4Address ipv4 = transport.GetIpv4 ();
265
      Ipv4Address ipv4 = transport.GetIpv4 ();
 Lines 263-269    Link Here 
263
        }
271
        }
264
      else if (ipv4 == Ipv4Address::GetAny () && port != 0)
272
      else if (ipv4 == Ipv4Address::GetAny () && port != 0)
265
        {
273
        {
266
          m_endPoint = m_udp->Allocate (port);
274
          m_endPoint = m_udp->Allocate (GetBoundNetDevice (), port);
267
        }
275
        }
268
      else if (ipv4 != Ipv4Address::GetAny () && port == 0)
276
      else if (ipv4 != Ipv4Address::GetAny () && port == 0)
269
        {
277
        {
 Lines 271-287    Link Here 
271
        }
279
        }
272
      else if (ipv4 != Ipv4Address::GetAny () && port != 0)
280
      else if (ipv4 != Ipv4Address::GetAny () && port != 0)
273
        {
281
        {
274
          m_endPoint = m_udp->Allocate (ipv4, port);
282
          m_endPoint = m_udp->Allocate (GetBoundNetDevice (), ipv4, port);
275
        }
283
        }
276
      if (0 == m_endPoint)
284
      if (0 == m_endPoint)
277
        {
285
        {
278
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
286
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
279
          return -1;
287
          return -1;
280
        }
288
        }
289
      if (m_boundnetdevice)
290
        {
291
          m_endPoint->BindToNetDevice (m_boundnetdevice);
292
        }
293
281
    }
294
    }
282
  else if (Inet6SocketAddress::IsMatchingType (address))
295
  else if (Inet6SocketAddress::IsMatchingType (address))
283
    {
296
    {
284
      NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated (maybe you used BindToNetDevice before Bind).");
297
      NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated.");
285
298
286
      Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address);
299
      Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address);
287
      Ipv6Address ipv6 = transport.GetIpv6 ();
300
      Ipv6Address ipv6 = transport.GetIpv6 ();
 Lines 292-298    Link Here 
292
        }
305
        }
293
      else if (ipv6 == Ipv6Address::GetAny () && port != 0)
306
      else if (ipv6 == Ipv6Address::GetAny () && port != 0)
294
        {
307
        {
295
          m_endPoint6 = m_udp->Allocate6 (port);
308
          m_endPoint6 = m_udp->Allocate6 (GetBoundNetDevice (), port);
296
        }
309
        }
297
      else if (ipv6 != Ipv6Address::GetAny () && port == 0)
310
      else if (ipv6 != Ipv6Address::GetAny () && port == 0)
298
        {
311
        {
 Lines 300-318    Link Here 
300
        }
313
        }
301
      else if (ipv6 != Ipv6Address::GetAny () && port != 0)
314
      else if (ipv6 != Ipv6Address::GetAny () && port != 0)
302
        {
315
        {
303
          m_endPoint6 = m_udp->Allocate6 (ipv6, port);
316
          m_endPoint6 = m_udp->Allocate6 (GetBoundNetDevice (), ipv6, port);
304
        }
317
        }
305
      if (0 == m_endPoint6)
318
      if (0 == m_endPoint6)
306
        {
319
        {
307
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
320
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
308
          return -1;
321
          return -1;
309
        }
322
        }
323
      if (m_boundnetdevice)
324
        {
325
          m_endPoint6->BindToNetDevice (m_boundnetdevice);
326
        }
327
310
      if (ipv6.IsMulticast ())
328
      if (ipv6.IsMulticast ())
311
        {
329
        {
312
          Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> ();
330
          Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> ();
313
          if (ipv6l3)
331
          if (ipv6l3)
314
            {
332
            {
315
              ipv6l3->AddMulticastAddress (ipv6);
333
              if (m_boundnetdevice == 0)
334
                {
335
                  ipv6l3->AddMulticastAddress (ipv6);
336
                }
337
              else
338
                {
339
                  uint32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
340
                  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index);
341
                }
316
            }
342
            }
317
        }
343
        }
318
    }
344
    }
 Lines 928-964    Link Here 
928
{
954
{
929
  NS_LOG_FUNCTION (netdevice);
955
  NS_LOG_FUNCTION (netdevice);
930
956
957
  Ptr<NetDevice> oldBoundNetDevice = m_boundnetdevice;
958
931
  Socket::BindToNetDevice (netdevice); // Includes sanity check
959
  Socket::BindToNetDevice (netdevice); // Includes sanity check
932
  if (m_endPoint == 0)
960
  if (m_endPoint != 0)
933
    {
961
    {
934
      if (Bind () == -1)
962
      m_endPoint->BindToNetDevice (netdevice);
935
        {
936
          NS_ASSERT (m_endPoint == 0);
937
          return;
938
        }
939
      NS_ASSERT (m_endPoint != 0);
940
    }
963
    }
941
  m_endPoint->BindToNetDevice (netdevice);
942
964
943
  if (m_endPoint6 == 0)
965
  if (m_endPoint6 != 0)
944
    {
966
    {
945
      if (Bind6 () == -1)
967
      m_endPoint6->BindToNetDevice (netdevice);
968
969
      // The following is to fix the multicast distribution inside the node
970
      // and to upgrade it to the actual bound NetDevice.
971
      if (m_endPoint6->GetLocalAddress ().IsMulticast ())
946
        {
972
        {
947
          NS_ASSERT (m_endPoint6 == 0);
973
          Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> ();
948
          return;
974
          if (ipv6l3)
949
        }
975
            {
950
      NS_ASSERT (m_endPoint6 != 0);
976
              // Cleanup old one
951
    }
977
              if (oldBoundNetDevice)
952
  m_endPoint6->BindToNetDevice (netdevice);
978
                {
953
979
                  uint32_t index = ipv6l3->GetInterfaceForDevice (oldBoundNetDevice);
954
  if (m_endPoint6->GetLocalAddress ().IsMulticast ())
980
                  ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress (), index);
955
    {
981
                }
956
      Ptr<Ipv6L3Protocol> ipv6l3 = m_node->GetObject <Ipv6L3Protocol> ();
982
              else
957
      if (ipv6l3)
983
                {
958
        {
984
                  ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress ());
959
          uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice);
985
                }
960
          ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress ());
986
              // add new one
961
          ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index);
987
              if (netdevice)
988
                {
989
                  uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice);
990
                  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index);
991
                }
992
              else
993
                {
994
                  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress ());
995
                }
996
            }
962
        }
997
        }
963
    }
998
    }
964
999
(-)a/src/network/model/socket.h (-5 / +2 lines)
 Lines 616-631    Link Here 
616
   * is also possible to bind to mismatching device and address, even if
616
   * is also possible to bind to mismatching device and address, even if
617
   * the socket can not receive any packets as a result.
617
   * the socket can not receive any packets as a result.
618
   *
618
   *
619
   * \warning BindToNetDevice should be used \a after Bind. Otherwise
619
   * \param netdevice Pointer to NetDevice of desired interface
620
   * it will perform a Bind itself.
621
   *
622
   * \param netdevice Pointer to Netdevice of desired interface
623
   * \returns nothing
620
   * \returns nothing
624
   */
621
   */
625
  virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
622
  virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
626
623
627
  /**
624
  /**
628
   * \brief Returns socket's bound netdevice, if any.
625
   * \brief Returns socket's bound NetDevice, if any.
629
   *
626
   *
630
   * This method corresponds to using getsockopt() SO_BINDTODEVICE
627
   * This method corresponds to using getsockopt() SO_BINDTODEVICE
631
   * of real network or BSD sockets.
628
   * of real network or BSD sockets.

Return to bug 2762