src/internet-stack/udp-l4-protocol.h
author Craig Dowell <craigdo@ee.washington.edu>
Wed, 17 Feb 2010 21:50:11 -0800
changeset 5994 ced6c14c957e
parent 4740 34acfd7ad508
child 6273 8d70de29d514
permissions -rw-r--r--
branch merge
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,2006,2007 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
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    21
#ifndef UDP_L4_PROTOCOL_H
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    22
#define UDP_L4_PROTOCOL_H
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <stdint.h>
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "ns3/packet.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 515
diff changeset
    27
#include "ns3/ipv4-address.h"
557
927a5bb6432a convert UdpSocket and Udp to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 524
diff changeset
    28
#include "ns3/ptr.h"
295
5fc7ae0d0300 remove UdpIpv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
    29
#include "ipv4-l4-protocol.h"
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
namespace ns3 {
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
    33
class Node;
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    34
class Socket;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
    35
class Ipv4Route;
4740
34acfd7ad508 export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
    36
class Ipv4EndPointDemux;
34acfd7ad508 export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
    37
class Ipv4EndPoint;
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    38
/**
3691
372f4475dc47 Doxygen for internet-stack
Tom Henderson <tomh@tomh.org>
parents: 3588
diff changeset
    39
 * \ingroup udp
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    40
 * \brief Implementation of the UDP protocol
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    41
 */
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    42
class UdpL4Protocol : public Ipv4L4Protocol {
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
public:
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    44
  static TypeId GetTypeId (void);
295
5fc7ae0d0300 remove UdpIpv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
    45
  static const uint8_t PROT_NUMBER;
2595
b504951bcca8 fix doxygen errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    46
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    47
  UdpL4Protocol ();
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
    48
  virtual ~UdpL4Protocol ();
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    50
  void SetNode (Ptr<Node> node);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    51
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    52
  virtual int GetProtocolNumber (void) const;
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1867
diff changeset
    53
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    54
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    55
   * \return A smart Socket pointer to a UdpSocket, allocated by this instance
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    56
   * of the UDP protocol
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    57
   */
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 557
diff changeset
    58
  Ptr<Socket> CreateSocket (void);
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    59
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 453
diff changeset
    60
  Ipv4EndPoint *Allocate (void);
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2595
diff changeset
    61
  Ipv4EndPoint *Allocate (Ipv4Address address);
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 453
diff changeset
    62
  Ipv4EndPoint *Allocate (uint16_t port);
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2595
diff changeset
    63
  Ipv4EndPoint *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: 453
diff changeset
    64
  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
2608
408589d1dfff merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2595
diff changeset
    65
                          Ipv4Address peerAddress, uint16_t peerPort);
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
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
    67
  void 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: 513
diff changeset
    68
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
    69
  // called by UdpSocket.
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    70
  /**
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    71
   * \brief Send a packet via UDP
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    72
   * \param packet The packet to send
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    73
   * \param saddr The source Ipv4Address
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    74
   * \param daddr The destination Ipv4Address
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    75
   * \param sport The source port number
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    76
   * \param dport The destination port number
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    77
   */
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
    78
  void Send (Ptr<Packet> packet,
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
    79
             Ipv4Address saddr, Ipv4Address daddr, 
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 238
diff changeset
    80
             uint16_t sport, uint16_t dport);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
    81
  void Send (Ptr<Packet> packet,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
    82
             Ipv4Address saddr, Ipv4Address daddr, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
    83
             uint16_t sport, uint16_t dport, Ptr<Ipv4Route> route);
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    84
  /**
1795
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
    85
   * \brief Receive a packet up the protocol stack
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    86
   * \param p The Packet to dump the contents into
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    87
   * \param source The source's Ipv4Address
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    88
   * \param destination The destinations Ipv4Address
1795
820cc1254290 get rid of doxygen warnings
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
    89
   * \param interface the interface from which the packet is coming.
632
1e419ebb4012 Internet-node module dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 607
diff changeset
    90
   */
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
  // inherited from Ipv4L4Protocol
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
    92
  virtual enum Ipv4L4Protocol::RxStatus Receive(Ptr<Packet> p, 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
    93
                                                Ipv4Address const &source,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
    94
                                                Ipv4Address const &destination,
3997
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    95
                                                Ptr<Ipv4Interface> interface);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
    96
3997
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    97
  /**
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    98
   * \brief Receive an ICMP packet
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    99
   * \param icmpSource The IP address of the source of the packet.
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   100
   * \param icmpTtl The time to live from the IP header
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   101
   * \param icmpType The type of the message from the ICMP header
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   102
   * \param icmpCode The message code from the ICMP header
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   103
   * \param icmpInfo 32-bit integer carrying informational value of varying semantics.
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   104
   * \param payloadSource The IP source addresss from the IP header of the packet
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   105
   * \param payloadDestination The IP destination address from the IP header of the packet
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   106
   * \param payload Payload of the ICMP packet
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   107
   */
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
   108
  virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
   109
                            uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
   110
                            Ipv4Address payloadSource,Ipv4Address payloadDestination,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
   111
                            const uint8_t payload[8]);
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 504
diff changeset
   112
protected:
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 504
diff changeset
   113
  virtual void DoDispose (void);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
   114
  /*
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
   115
   * This function will notify other components connected to the node that a new stack member is now connected
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
   116
   * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
   117
   */
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 3997
diff changeset
   118
  virtual void NotifyNewAggregate ();
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 504
diff changeset
   119
private:
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 632
diff changeset
   120
  Ptr<Node> m_node;
495
a839408950b9 rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 453
diff changeset
   121
  Ipv4EndPointDemux *m_endPoints;
238
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
};
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
}; // namespace ns3
2f09fd9cf32e add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
742
b73f8e30c75e Udp -> UdpL4Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 741
diff changeset
   126
#endif /* UDP_L4_PROTOCOL_H */