src/internet/model/ipv4-l4-protocol.h
author Tom Henderson <tomh@tomh.org>
Sun, 22 May 2011 23:18:47 -0700
changeset 7256 b04ba6772f8c
parent 7176 9f2663992e99
child 7385 10beb0e53130
permissions -rw-r--r--
rerun check-style.py at default level to enforce space after function name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
// published by the Free Software Foundation;
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
// GNU General Public License for more details.
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
// Author: George F. Riley<riley@ece.gatech.edu>
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
// NS3 - Layer 4 Protocol base class
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
// George F. Riley, Georgia Tech, Spring 2007
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#ifndef IPV4_L4_PROTOCOL_H
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#define IPV4_L4_PROTOCOL_H
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
498
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 496
diff changeset
    27
#include "ns3/object.h"
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6445
diff changeset
    28
#include "ns3/callback.h"
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    29
#include "ns3/ipv4-header.h"
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
namespace ns3 {
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
class Packet;
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
class Ipv4Address;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    35
class Ipv4Interface;
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6445
diff changeset
    36
class Ipv4Route;
407
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    37
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    38
/**
3266
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    39
 * \brief L4 Protocol abstract base class 
407
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    40
 *
3266
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    41
 * This is an abstract base class for layer four protocols which use IPv4 as
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    42
 * the network layer.
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    43
 */
498
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 496
diff changeset
    44
class Ipv4L4Protocol : public Object
5d5fe14d5751 make capabilities and sockets refcounted
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 496
diff changeset
    45
{
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
public:
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    47
  enum RxStatus {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    48
    RX_OK,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    49
    RX_CSUM_FAILED,
5380
3a8177ed2dda Fix for bug 615
Josh Pelkey <jpelkey@gatech.edu>
parents: 3997
diff changeset
    50
    RX_ENDPOINT_CLOSED,
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    51
    RX_ENDPOINT_UNREACH
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    52
  };
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    53
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    54
  static TypeId GetTypeId (void);
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    55
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
  virtual ~Ipv4L4Protocol ();
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
407
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    58
  /**
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    59
   * \returns the protocol number of this protocol.
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    60
   */
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1866
diff changeset
    61
  virtual int GetProtocolNumber (void) const = 0;
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
  /**
407
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    64
   * \param p packet to forward up
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 5380
diff changeset
    65
   * \param header IPv4 Header information
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: 1341
diff changeset
    66
   * \param incomingInterface the Ipv4Interface on which the packet arrived
407
d249fd346a7c doxygen for Ipv4L4Protocol class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    67
   * 
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
   * Called from lower-level layers to send the packet up
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
   * in the stack. 
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
   */
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
    71
  virtual enum RxStatus Receive (Ptr<Packet> p,
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
    72
                                 Ipv4Header const &header,
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
    73
                                 Ptr<Ipv4Interface> incomingInterface) = 0;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    74
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    75
  /**
3997
a66553c56a8f make a pass through doxygen fixing errors
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    76
   * \param icmpSource the source address of the icmp message
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    77
   * \param icmpTtl the ttl of the icmp message
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    78
   * \param icmpType the 'type' field of the icmp message
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    79
   * \param icmpCode the 'code' field of the icmp message
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    80
   * \param icmpInfo extra information dependent on the icmp message
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    81
   *        generated by Icmpv4L4Protocol
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    82
   * \param payloadSource the source address of the packet which triggered
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    83
   *        the icmp message
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    84
   * \param payloadDestination the destination address of the packet which
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    85
   *        triggered the icmp message.
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    86
   * \param payload the first 8 bytes of the udp header of the packet
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    87
   *        which triggered the icmp message.
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    88
   */
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    89
  virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    90
                            uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    91
                            Ipv4Address payloadSource, Ipv4Address payloadDestination,
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3588
diff changeset
    92
                            const uint8_t payload[8]);
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6445
diff changeset
    93
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6445
diff changeset
    94
  typedef Callback<void,Ptr<Packet>, Ipv4Address, Ipv4Address, uint8_t, Ptr<Ipv4Route> > DownTargetCallback;
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    95
  /**
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    96
   * This method allows a caller to set the current down target callback
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    97
   * set for this L4 protocol
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    98
   *
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    99
   * \param cb current Callback for the L4 protocol
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   100
   */
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6445
diff changeset
   101
  virtual void SetDownTarget (DownTargetCallback cb) = 0;
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   102
  /**
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   103
   * This method allows a caller to get the current down target callback
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   104
   * set for this L4 protocol, for
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   105
   *
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   106
   * \return current Callback for the L4 protocol
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   107
   */
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6445
diff changeset
   108
  virtual DownTargetCallback GetDownTarget (void) const = 0;
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
};
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
} // Namespace ns3
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
#endif