src/internet-node/udp-l4-protocol.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 27 Feb 2008 22:19:39 +0100
changeset 2503 e667dc0f350e
parent 2326 eec07777d1a2
parent 2501 3eaeac1dd5ed
child 2592 3ebf97150166
permissions -rw-r--r--
merge with HEAD
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
 * All rights reserved.
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * 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
     7
 * 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
     8
 * published by the Free Software Foundation;
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * 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
    11
 * 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
    12
 * 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
    13
 * GNU General Public License for more details.
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    22
#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
    23
#include "ns3/assert.h"
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include "ns3/packet.h"
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    25
#include "ns3/node.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"
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 348
diff changeset
    32
#include "udp-socket.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
{
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    46
  static TypeId tid = TypeId ("UdpL4Protocol")
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> ()
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    49
    .AddAttribute ("Node", "The node which contains this protocol.",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    50
                   TypeId::ATTR_GET | TypeId::ATTR_CONSTRUCT,
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    51
                   Ptr<Node> (0),
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    52
                   MakePtrAccessor (&UdpL4Protocol::m_node),
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    53
                   MakePtrChecker<Node> ())
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
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    61
  NS_LOG_FUNCTION;
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
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    66
  NS_LOG_FUNCTION;
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
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    69
int 
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    70
UdpL4Protocol::GetProtocolNumber (void) const
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    71
{
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    72
  return PROT_NUMBER;
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    73
}
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    74
int 
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    75
UdpL4Protocol::GetVersion (void) const
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    76
{
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    77
  return 2;
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    78
}
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
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    81
void
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    82
UdpL4Protocol::DoDispose (void)
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    83
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    84
  NS_LOG_FUNCTION;
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    85
  if (m_endPoints != 0)
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    86
    {
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    87
      delete m_endPoints;
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    88
      m_endPoints = 0;
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 495
diff changeset
    89
    }
557
927a5bb6432a convert UdpSocket and Udp to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 524
diff changeset
    90
  m_node = 0;
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 504
diff changeset
    91
  Ipv4L4Protocol::DoDispose ();
496
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
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 567
diff changeset
    94
Ptr<Socket>
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    95
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
    96
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    97
  NS_LOG_FUNCTION;
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1870
diff changeset
    98
  Ptr<Socket> socket = CreateObject<UdpSocket> (m_node, 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
    99
  return socket;
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 348
diff changeset
   100
}
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 348
diff changeset
   101
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   102
Ipv4EndPoint *
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   103
UdpL4Protocol::Allocate (void)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   105
  NS_LOG_FUNCTION;
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
  return m_endPoints->Allocate ();
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   108
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   109
Ipv4EndPoint *
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   110
UdpL4Protocol::Allocate (Ipv4Address address, Ipv4Address localInterface)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   112
  NS_LOG_FUNCTION;
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
   113
  NS_LOG_PARAMS (this << address);
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   114
  return m_endPoints->Allocate (address, localInterface);
238
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 *
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   118
UdpL4Protocol::Allocate (uint16_t port)
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   119
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   120
  NS_LOG_FUNCTION;
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
   121
  NS_LOG_PARAMS (this << port);
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   122
  return m_endPoints->Allocate (port);
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   123
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   124
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   125
Ipv4EndPoint *
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   126
UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port, Ipv4Address localInterface)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   128
  NS_LOG_FUNCTION;
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
   129
  NS_LOG_PARAMS (this << address << port);
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   130
  return m_endPoints->Allocate (address, port, localInterface);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
}
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   132
Ipv4EndPoint *
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   133
UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   134
                         Ipv4Address peerAddress, uint16_t peerPort,
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   135
                         Ipv4Address localInterface)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   137
  NS_LOG_FUNCTION; 
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
   138
  NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
  return m_endPoints->Allocate (localAddress, localPort,
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   140
                                peerAddress, peerPort, localInterface);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
}
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
void 
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   144
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
   145
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   146
  NS_LOG_FUNCTION; 
1828
6ab68edddf45 nicer logging of parameters (bug 79 patch from Gustavo)
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
   147
  NS_LOG_PARAMS (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
   148
  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
   149
}
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
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
void 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   152
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
   153
                       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
   154
                       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
   155
                       Ptr<Ipv4Interface> interface)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   157
  NS_LOG_FUNCTION; 
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828 1866
diff changeset
   158
  NS_LOG_PARAMS (this << packet << source << destination);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   159
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
  UdpHeader udpHeader;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   161
  packet->RemoveHeader (udpHeader);
984
3202c053eacc Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   162
  Ipv4EndPointDemux::EndPoints endPoints =
3202c053eacc Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   163
    m_endPoints->Lookup (destination, udpHeader.GetDestination (),
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
   164
                         source, udpHeader.GetSource (), interface);
984
3202c053eacc Allow UDP sockets to receive broadcast (bug #51)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 746
diff changeset
   165
  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
   166
       endPoint != endPoints.end (); endPoint++)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
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
      (*endPoint)->ForwardUp (packet->Copy (), source, udpHeader.GetSource ());
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
    }
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
}
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
void
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   173
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
   174
                     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
   175
                     uint16_t sport, uint16_t dport)
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
{
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   177
  NS_LOG_FUNCTION; 
1870
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1828 1866
diff changeset
   178
  NS_LOG_PARAMS (this << packet << saddr << daddr << sport << dport);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1176
diff changeset
   179
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
  UdpHeader udpHeader;
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
  udpHeader.SetDestination (dport);
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
  udpHeader.SetSource (sport);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   183
  udpHeader.SetPayloadSize (packet->GetSize ());
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
  udpHeader.InitializeChecksum (saddr,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   185
                                daddr,
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   186
                                PROT_NUMBER);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   188
  packet->AddHeader (udpHeader);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
   190
  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
   191
  if (ipv4 != 0)
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
   192
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   193
      NS_LOG_LOGIC ("Sending to IP");
295
5fc7ae0d0300 remove UdpIpv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 286
diff changeset
   194
      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
   195
    }
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
}
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
}; // namespace ns3
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200