src/internet-stack/udp-l4-protocol.cc
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Fri, 11 Jul 2008 18:39:19 +0100
changeset 3416 926ccb845111
parent 3404 b5d4a04c7b68
child 3588 ad0a36bfdb62
permissions -rw-r--r--
Rescan APIs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005 INRIA
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    21
#include "ns3/log.h"
286
57e6a2006962 convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
    22
#include "ns3/assert.h"
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "ns3/packet.h"
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    24
#include "ns3/node.h"
3363
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
    25
#include "ns3/boolean.h"
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 295
diff changeset
    26
741
38ebb2fb16f5 udp.h -> udp-l4-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 738
diff changeset
    27
#include "udp-l4-protocol.h"
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include "udp-header.h"
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include "ipv4-end-point-demux.h"
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    30
#include "ipv4-end-point.h"
733
fb1882e7d785 rename ipv4.h to ipv4-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 732
diff changeset
    31
#include "ipv4-l3-protocol.h"
3130
881cc06cd651 rename UdpSocket to UdpSocketImpl
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
    32
#include "udp-socket-impl.h"
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    34
NS_LOG_COMPONENT_DEFINE ("UdpL4Protocol");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
    35
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
namespace ns3 {
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
2501
3eaeac1dd5ed add missing NS_OBJECT_ENSURE_REGISTERED calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    38
NS_OBJECT_ENSURE_REGISTERED (UdpL4Protocol);
3eaeac1dd5ed add missing NS_OBJECT_ENSURE_REGISTERED calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2498
diff changeset
    39
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
/* see http://www.iana.org/assignments/protocol-numbers */
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    41
const uint8_t UdpL4Protocol::PROT_NUMBER = 17;
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    43
TypeId 
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    44
UdpL4Protocol::GetTypeId (void)
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    45
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    46
  static TypeId tid = TypeId ("ns3::UdpL4Protocol")
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    47
    .SetParent<Ipv4L4Protocol> ()
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    48
    .AddConstructor<UdpL4Protocol> ()
3363
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
    49
    .AddAttribute ("CalcChecksum", "If true, we calculate the checksum of outgoing packets"
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
    50
                   " and verify the checksum of incoming packets.",
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
    51
                   BooleanValue (false),
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
    52
                   MakeBooleanAccessor (&UdpL4Protocol::m_calcChecksum),
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
    53
                   MakeBooleanChecker ())
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    54
    ;
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    55
  return tid;
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    56
}
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    57
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    58
UdpL4Protocol::UdpL4Protocol ()
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    59
  : m_endPoints (new Ipv4EndPointDemux ())
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
    60
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    61
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
    62
}
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    64
UdpL4Protocol::~UdpL4Protocol ()
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
    65
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    66
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
    67
}
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    69
void 
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    70
UdpL4Protocol::SetNode (Ptr<Node> node)
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    71
{
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    72
  m_node = node;
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    73
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    74
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    75
int 
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    76
UdpL4Protocol::GetProtocolNumber (void) const
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    77
{
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    78
  return PROT_NUMBER;
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    79
}
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    80
int 
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    81
UdpL4Protocol::GetVersion (void) const
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    82
{
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    83
  return 2;
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    84
}
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    85
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    86
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    87
void
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    88
UdpL4Protocol::DoDispose (void)
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    89
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    90
  NS_LOG_FUNCTION_NOARGS ();
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    91
  if (m_endPoints != 0)
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    92
    {
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    93
      delete m_endPoints;
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    94
      m_endPoints = 0;
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    95
    }
557
927a5bb6432a convert UdpSocket and Udp to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 524
diff changeset
    96
  m_node = 0;
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 504
diff changeset
    97
  Ipv4L4Protocol::DoDispose ();
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    98
}
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    99
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 567
diff changeset
   100
Ptr<Socket>
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   101
UdpL4Protocol::CreateSocket (void)
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 348
diff changeset
   102
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   103
  NS_LOG_FUNCTION_NOARGS ();
3130
881cc06cd651 rename UdpSocket to UdpSocketImpl
Tom Henderson <tomh@tomh.org>
parents: 2983
diff changeset
   104
  Ptr<UdpSocketImpl> socket = CreateObject<UdpSocketImpl> ();
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
   105
  socket->SetNode (m_node);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
   106
  socket->SetUdp (this);
567
6fb98941c36f remove leaks and rework the Ptr class to work with a new refcount mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 557
diff changeset
   107
  return socket;
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 348
diff changeset
   108
}
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 348
diff changeset
   109
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   110
Ipv4EndPoint *
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   111
UdpL4Protocol::Allocate (void)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   113
  NS_LOG_FUNCTION_NOARGS ();
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
  return m_endPoints->Allocate ();
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   116
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   117
Ipv4EndPoint *
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   118
UdpL4Protocol::Allocate (Ipv4Address address)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   120
  NS_LOG_FUNCTION (this << address);
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   121
  return m_endPoints->Allocate (address);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   123
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   124
Ipv4EndPoint *
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   125
UdpL4Protocol::Allocate (uint16_t port)
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   126
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   127
  NS_LOG_FUNCTION (this << port);
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   128
  return m_endPoints->Allocate (port);
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   129
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   130
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   131
Ipv4EndPoint *
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   132
UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   134
  NS_LOG_FUNCTION (this << address << port);
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   135
  return m_endPoints->Allocate (address, port);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
}
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   137
Ipv4EndPoint *
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   138
UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   139
                         Ipv4Address peerAddress, uint16_t peerPort)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   141
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
  return m_endPoints->Allocate (localAddress, localPort,
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   143
                                peerAddress, peerPort);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
}
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
void 
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   147
UdpL4Protocol::DeAllocate (Ipv4EndPoint *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: 513
diff changeset
   148
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   149
  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: 513
diff changeset
   150
  m_endPoints->DeAllocate (endPoint);
e907146a191e fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
   151
}
e907146a191e fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
   152
e907146a191e fix valgrind warning: UdpSocket must manage carefully its Ipv4EndPoint to avoid double deleting it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
   153
void 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   154
UdpL4Protocol::Receive(Ptr<Packet> packet, 
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: 1504
diff changeset
   155
                       Ipv4Address const &source,
3ead2b66f2e4 Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   156
                       Ipv4Address const &destination,
3ead2b66f2e4 Fix a regression in handling of broadcast packets and UDP sockets (closes bug #51).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1504
diff changeset
   157
                       Ptr<Ipv4Interface> interface)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   159
  NS_LOG_FUNCTION (this << packet << source << destination);
3363
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   160
  UdpHeader udpHeader;
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   161
  if(m_calcChecksum)
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   162
  {
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   163
    udpHeader.EnableChecksums();
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   164
  }
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   165
3363
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   166
  udpHeader.InitializeChecksum (source, destination, PROT_NUMBER);
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   167
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   168
  packet->RemoveHeader (udpHeader);
3363
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   169
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   170
  if(!udpHeader.IsChecksumOk ())
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   171
  {
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   172
    NS_LOG_INFO("Bad checksum : dropping packet!");
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   173
    return;
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   174
  }
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   175
984
3202c053eacc Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   176
  Ipv4EndPointDemux::EndPoints endPoints =
3238
3b24ac252fba bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3130
diff changeset
   177
    m_endPoints->Lookup (destination, udpHeader.GetDestinationPort (),
3b24ac252fba bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3130
diff changeset
   178
                         source, udpHeader.GetSourcePort (), interface);
984
3202c053eacc Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   179
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
3202c053eacc Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   180
       endPoint != endPoints.end (); endPoint++)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
    {
3238
3b24ac252fba bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3130
diff changeset
   182
      (*endPoint)->ForwardUp (packet->Copy (), source, udpHeader.GetSourcePort ());
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
    }
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
}
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
void
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   187
UdpL4Protocol::Send (Ptr<Packet> packet, 
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   188
                     Ipv4Address saddr, Ipv4Address daddr, 
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   189
                     uint16_t sport, uint16_t dport)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
   191
  NS_LOG_FUNCTION (this << packet << saddr << daddr << sport << dport);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   192
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
  UdpHeader udpHeader;
3363
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   194
  if(m_calcChecksum)
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   195
  {
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   196
    udpHeader.EnableChecksums();
3404
b5d4a04c7b68 bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3363
diff changeset
   197
    udpHeader.InitializeChecksum (saddr,
b5d4a04c7b68 bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3363
diff changeset
   198
                                  daddr,
b5d4a04c7b68 bug 247: tcp checksum crashes when enabled.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3363
diff changeset
   199
                                  PROT_NUMBER);
3363
33d1ca2e4ba4 bug 236: add optional support for tcp and udp checksum.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents: 3260
diff changeset
   200
  }
3238
3b24ac252fba bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3130
diff changeset
   201
  udpHeader.SetDestinationPort (dport);
3b24ac252fba bug 195: naming inconsistency.
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3130
diff changeset
   202
  udpHeader.SetSourcePort (sport);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   204
  packet->AddHeader (udpHeader);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
   206
  Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
241
9004ab4cfe17 add Ipv4 and Udp node capabilities, rework Copy methods to include an extra Node * argument
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 240
diff changeset
   207
  if (ipv4 != 0)
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   208
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   209
      NS_LOG_LOGIC ("Sending to IP");
295
5fc7ae0d0300 remove UdpIpv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   210
      ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   211
    }
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
}
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
}; // namespace ns3
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216