src/internet/model/ipv4-end-point-demux.cc
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Wed, 20 Nov 2013 20:15:02 +0100
changeset 10440 1e48ff9185f1
parent 10411 f5916669dbe7
child 10652 dc18deba4502
permissions -rw-r--r--
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Mileti? <rivanvx@gmail.com>
parents: 7256
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
495
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
 *
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * 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
     6
 * 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
     7
 * 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
     8
 *
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * 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
    13
 *
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * 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
    15
 * 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
    16
 * 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
    17
 *
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * 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
    19
 */
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
#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
    22
#include "ipv4-end-point.h"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 984
diff changeset
    23
#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
    24
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    25
namespace ns3 {
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
10411
f5916669dbe7 [doxygen] Suppress "warning: Member NS_LOG_COMPONENT_DEFINE is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9710
diff changeset
    27
NS_LOG_COMPONENT_DEFINE ("Ipv4EndPointDemux")
f5916669dbe7 [doxygen] Suppress "warning: Member NS_LOG_COMPONENT_DEFINE is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9710
diff changeset
    28
  ;
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 ()
7441
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7386
diff changeset
    31
  : m_ephemeral (49152), m_portLast (65535), m_portFirst (49152)
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 984
diff changeset
    32
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
    33
  NS_LOG_FUNCTION (this);
1504
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
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
    38
  NS_LOG_FUNCTION (this);
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
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
    50
  NS_LOG_FUNCTION (this << port);
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
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
    64
  NS_LOG_FUNCTION (this << addr << port);
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
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
    79
  NS_LOG_FUNCTION (this);
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
    }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
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 *
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
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
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
    95
  NS_LOG_FUNCTION (this << address);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
  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
    97
  if (port == 0) 
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 984
diff changeset
    99
      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
   100
      return 0;
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
    }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   102
  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
   103
  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
   104
  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
   105
  return endPoint;
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 984
diff changeset
   107
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
Ipv4EndPoint *
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
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
   110
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   111
  NS_LOG_FUNCTION (this <<  port);
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1828
diff changeset
   112
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   113
  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
   114
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 984
diff changeset
   115
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
Ipv4EndPoint *
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   117
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
   118
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   119
  NS_LOG_FUNCTION (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
   120
  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
   121
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 984
diff changeset
   122
      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
   123
      return 0;
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
    }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   125
  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
   126
  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
   127
  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
   128
  return endPoint;
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
}
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
Ipv4EndPoint *
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort,
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   133
                             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
   134
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2975
diff changeset
   135
  NS_LOG_FUNCTION (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
   136
  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
   137
    {
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
      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
   139
          (*i)->GetLocalAddress () == localAddress &&
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
          (*i)->GetPeerPort () == peerPort &&
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
          (*i)->GetPeerAddress () == peerAddress) 
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 984
diff changeset
   143
          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
   144
          /* 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
   145
          return 0;
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
        }
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
    }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   148
  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
   149
  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
   150
  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
   151
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
   152
  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
   153
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
  return endPoint;
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
}
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
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
   157
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
   158
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
   159
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
   160
  NS_LOG_FUNCTION (this << endPoint);
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
  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
   162
    {
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
      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
   164
        {
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
          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
   166
          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
   167
          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
   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
    }
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
}
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
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
/*
3577
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   173
 * return list of all available Endpoints
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   174
 */
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   175
Ipv4EndPointDemux::EndPoints
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   176
Ipv4EndPointDemux::GetAllEndPoints (void)
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   177
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
   178
  NS_LOG_FUNCTION (this);
3577
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   179
  EndPoints ret;
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   180
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   181
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   182
    {
3577
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   183
      Ipv4EndPoint* endP = *i;
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   184
      ret.push_back (endP);
3577
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   185
    }
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   186
  return ret;
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   187
}
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   188
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   189
4631eaaf84c4 ipv4-end-point-demux: add method to fetch list of all endpoints
Florian Westphal <fw@strlen.de>
parents: 3260
diff changeset
   190
/*
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
 * 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
   192
 * 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
   193
 * 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
   194
 */
984
3202c053eacc Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 524
diff changeset
   195
Ipv4EndPointDemux::EndPoints
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
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
   197
                           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
   198
                           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
   199
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
   200
  NS_LOG_FUNCTION (this << daddr << dport << saddr << sport << incomingInterface);
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
   201
  
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   202
  EndPoints retval1; // Matches exact on local port, wildcards on others
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   203
  EndPoints retval2; // Matches exact on local port/adder, wildcards on others
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   204
  EndPoints retval3; // Matches all but local address
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   205
  EndPoints retval4; // Exact match on all 4
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   206
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   207
  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
   208
  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
   209
    {
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   210
      Ipv4EndPoint* endP = *i;
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   211
      NS_LOG_DEBUG ("Looking at endpoint dport=" << endP->GetLocalPort ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   212
                                                 << " daddr=" << endP->GetLocalAddress ()
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   213
                                                 << " sport=" << endP->GetPeerPort ()
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   214
                                                 << " saddr=" << endP->GetPeerAddress ());
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   215
      if (endP->GetLocalPort () != dport) 
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
        {
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   217
          NS_LOG_LOGIC ("Skipping endpoint " << &endP
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   218
                                             << " because endpoint dport "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   219
                                             << endP->GetLocalPort ()
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   220
                                             << " does not match packet dport " << dport);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
          continue;
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
        }
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   223
      if (endP->GetBoundNetDevice ())
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   224
        {
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   225
          if (endP->GetBoundNetDevice () != incomingInterface->GetDevice ())
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   226
            {
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   227
              NS_LOG_LOGIC ("Skipping endpoint " << &endP
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   228
                                                 << " because endpoint is bound to specific device and"
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   229
                                                 << endP->GetBoundNetDevice ()
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   230
                                                 << " does not match packet device " << incomingInterface->GetDevice ());
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   231
              continue;
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   232
            }
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 4571
diff changeset
   233
        }
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   234
      bool subnetDirected = false;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   235
      Ipv4Address incomingInterfaceAddr = daddr;  // may be a broadcast
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   236
      for (uint32_t i = 0; i < incomingInterface->GetNAddresses (); i++)
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   237
        {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   238
          Ipv4InterfaceAddress addr = incomingInterface->GetAddress (i);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   239
          if (addr.GetLocal ().CombineMask (addr.GetMask ()) == daddr.CombineMask (addr.GetMask ()) &&
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   240
              daddr.IsSubnetDirectedBroadcast (addr.GetMask ()))
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   241
            {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   242
              subnetDirected = true;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   243
              incomingInterfaceAddr = addr.GetLocal ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   244
            }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   245
        }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   246
      bool isBroadcast = (daddr.IsBroadcast () || subnetDirected == true);
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   247
      NS_LOG_DEBUG ("dest addr " << daddr << " broadcast? " << isBroadcast);
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   248
      bool localAddressMatchesWildCard = 
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   249
        endP->GetLocalAddress () == Ipv4Address::GetAny ();
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   250
      bool localAddressMatchesExact = endP->GetLocalAddress () == daddr;
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
   251
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1828
diff changeset
   252
      if (isBroadcast)
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1828
diff changeset
   253
        {
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   254
          NS_LOG_DEBUG ("Found bcast, localaddr " << endP->GetLocalAddress ());
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   255
        }
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   256
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   257
      if (isBroadcast && (endP->GetLocalAddress () != Ipv4Address::GetAny ()))
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   258
        {
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   259
          localAddressMatchesExact = (endP->GetLocalAddress () ==
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   260
                                      incomingInterfaceAddr);
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1828
diff changeset
   261
        }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   262
      // if no match here, keep looking
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   263
      if (!(localAddressMatchesExact || localAddressMatchesWildCard))
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   264
        continue; 
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   265
      bool remotePeerMatchesExact = endP->GetPeerPort () == sport;
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   266
      bool remotePeerMatchesWildCard = endP->GetPeerPort () == 0;
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   267
      bool remoteAddressMatchesExact = endP->GetPeerAddress () == saddr;
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   268
      bool remoteAddressMatchesWildCard = endP->GetPeerAddress () ==
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   269
        Ipv4Address::GetAny ();
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   270
      // If remote does not match either with exact or wildcard,
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   271
      // skip this one
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   272
      if (!(remotePeerMatchesExact || remotePeerMatchesWildCard))
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   273
        continue;
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   274
      if (!(remoteAddressMatchesExact || remoteAddressMatchesWildCard))
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   275
        continue;
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   276
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   277
      // Now figure out which return list to add this one to
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   278
      if (localAddressMatchesWildCard &&
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   279
          remotePeerMatchesWildCard &&
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   280
          remoteAddressMatchesWildCard)
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   281
        { // Only local port matches exactly
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   282
          retval1.push_back (endP);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
        }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   284
      if ((localAddressMatchesExact || (isBroadcast && localAddressMatchesWildCard))&&
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   285
          remotePeerMatchesWildCard &&
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   286
          remoteAddressMatchesWildCard)
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   287
        { // Only local port and local address matches exactly
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   288
          retval2.push_back (endP);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
        }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   290
      if (localAddressMatchesWildCard &&
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   291
          remotePeerMatchesExact &&
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   292
          remoteAddressMatchesExact)
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   293
        { // All but local address
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   294
          retval3.push_back (endP);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
        }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   296
      if (localAddressMatchesExact &&
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   297
          remotePeerMatchesExact &&
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   298
          remoteAddressMatchesExact)
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   299
        { // All 4 match
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   300
          retval4.push_back (endP);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
        }
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   302
    }
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   303
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   304
  // Here we find the most exact match
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   305
  if (!retval4.empty ()) return retval4;
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   306
  if (!retval3.empty ()) return retval3;
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   307
  if (!retval2.empty ()) return retval2;
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2326
diff changeset
   308
  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
   309
}
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   311
Ipv4EndPoint *
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   312
Ipv4EndPointDemux::SimpleLookup (Ipv4Address daddr, 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   313
                                 uint16_t dport, 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   314
                                 Ipv4Address saddr, 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   315
                                 uint16_t sport)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   316
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
   317
  NS_LOG_FUNCTION (this << daddr << dport << saddr << sport);
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
   318
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   319
  // this code is a copy/paste version of an old BSD ip stack lookup
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   320
  // function.
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   321
  uint32_t genericity = 3;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   322
  Ipv4EndPoint *generic = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   323
  for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++) 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   324
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   325
      if ((*i)->GetLocalPort () != dport) 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   326
        {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   327
          continue;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   328
        }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   329
      if ((*i)->GetLocalAddress () == daddr &&
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   330
          (*i)->GetPeerPort () == sport &&
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   331
          (*i)->GetPeerAddress () == saddr) 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   332
        {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   333
          /* this is an exact match. */
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   334
          return *i;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   335
        }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   336
      uint32_t tmp = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   337
      if ((*i)->GetLocalAddress () == Ipv4Address::GetAny ()) 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   338
        {
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   339
          tmp++;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   340
        }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   341
      if ((*i)->GetPeerAddress () == Ipv4Address::GetAny ()) 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   342
        {
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   343
          tmp++;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   344
        }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   345
      if (tmp < genericity) 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   346
        {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   347
          generic = (*i);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   348
          genericity = tmp;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   349
        }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   350
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   351
  return generic;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3577
diff changeset
   352
}
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   353
uint16_t
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   354
Ipv4EndPointDemux::AllocateEphemeralPort (void)
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
{
7442
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   356
  // Similar to counting up logic in netinet/in_pcb.c
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 7442
diff changeset
   357
  NS_LOG_FUNCTION (this);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   358
  uint16_t port = m_ephemeral;
7442
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   359
  int count = m_portLast - m_portFirst;
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   360
  do 
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   361
    {
7442
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   362
      if (count-- < 0)
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   363
        {
7442
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   364
          return 0;
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   365
        }
7442
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   366
      ++port;
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   367
      if (port < m_portFirst || port > m_portLast)
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   368
        {
7442
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   369
          port = m_portFirst;
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   370
        }
7442
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   371
    } while (LookupPortLocal (port));
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   372
  m_ephemeral = port;
7fbcc8eb8679 Bug 1163: Part 2
John Abraham <john.abraham@gatech.edu>
parents: 7441
diff changeset
   373
  return port;
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374
}
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   375
7386
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Mileti? <rivanvx@gmail.com>
parents: 7385
diff changeset
   376
} // namespace ns3
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   377