src/internet/model/ipv4-l3-protocol.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Thu, 14 Nov 2013 16:58:28 -0800
changeset 10410 4d4eb8097fa3
parent 9915 d4c2228d3c30
child 10440 1e48ff9185f1
permissions -rw-r--r--
doxygen] Suppress "warning: Member NS_OBJECT_ENSURE_REGISTERED is not documented"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7366
diff changeset
     1
// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
//
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
//
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
// published by the Free Software Foundation;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
//
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
// GNU General Public License for more details.
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
//
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
//
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
// Author: George F. Riley<riley@ece.gatech.edu>
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
//
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "ns3/packet.h"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    22
#include "ns3/log.h"
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 293
diff changeset
    23
#include "ns3/callback.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 514
diff changeset
    24
#include "ns3/ipv4-address.h"
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 514
diff changeset
    25
#include "ns3/ipv4-route.h"
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    26
#include "ns3/node.h"
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
    27
#include "ns3/socket.h"
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 555
diff changeset
    28
#include "ns3/net-device.h"
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    29
#include "ns3/uinteger.h"
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    30
#include "ns3/trace-source-accessor.h"
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    31
#include "ns3/object-vector.h"
3216
b36bb98d766e bug 207: ipv4-header.h needed in src/node module.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3172
diff changeset
    32
#include "ns3/ipv4-header.h"
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
    33
#include "ns3/boolean.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
    34
#include "ns3/ipv4-routing-table-entry.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
    35
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
    36
#include "loopback-net-device.h"
3172
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
    37
#include "arp-l3-protocol.h"
733
fb1882e7d785 rename ipv4.h to ipv4-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    38
#include "ipv4-l3-protocol.h"
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
    39
#include "icmpv4-l4-protocol.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
#include "ipv4-interface.h"
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
    41
#include "ipv4-raw-socket-impl.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    43
NS_LOG_COMPONENT_DEFINE ("Ipv4L3Protocol");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
namespace ns3 {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
    47
const uint16_t Ipv4L3Protocol::PROT_NUMBER = 0x0800;
293
007bc9e735f3 remove Ipv4L3Protocol class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 287
diff changeset
    48
10410
4d4eb8097fa3 doxygen] Suppress "warning: Member NS_OBJECT_ENSURE_REGISTERED is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9915
diff changeset
    49
NS_OBJECT_ENSURE_REGISTERED (Ipv4L3Protocol)
4d4eb8097fa3 doxygen] Suppress "warning: Member NS_OBJECT_ENSURE_REGISTERED is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9915
diff changeset
    50
  ;
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    51
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
    52
TypeId 
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    53
Ipv4L3Protocol::GetTypeId (void)
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    54
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    55
  static TypeId tid = TypeId ("ns3::Ipv4L3Protocol")
4377
2a05a47dba22 Remove class Ipv4Impl
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    56
    .SetParent<Ipv4> ()
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    57
    .AddConstructor<Ipv4L3Protocol> ()
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
    58
    .AddAttribute ("DefaultTos", "The TOS value set by default on all outgoing packets generated on this node.",
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
    59
                   UintegerValue (0),
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
    60
                   MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTos),
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
    61
                   MakeUintegerChecker<uint8_t> ())
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    62
    .AddAttribute ("DefaultTtl", "The TTL value set by default on all outgoing packets generated on this node.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
    63
                   UintegerValue (64),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    64
                   MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    65
                   MakeUintegerChecker<uint8_t> ())
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
    66
    .AddAttribute ("FragmentExpirationTimeout",
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
    67
                   "When this timeout expires, the fragments will be cleared from the buffer.",
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
    68
                   TimeValue (Seconds (30)),
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
    69
                   MakeTimeAccessor (&Ipv4L3Protocol::m_fragmentExpirationTimeout),
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
    70
                   MakeTimeChecker ())
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    71
    .AddTraceSource ("Tx", "Send ipv4 packet to outgoing interface.",
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
    72
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_txTrace))
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    73
    .AddTraceSource ("Rx", "Receive ipv4 packet from incoming interface.",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    74
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_rxTrace))
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    75
    .AddTraceSource ("Drop", "Drop ipv4 packet",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    76
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_dropTrace))
2537
c937f3317a1f be consistant in how lists of objects are named.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2503
diff changeset
    77
    .AddAttribute ("InterfaceList", "The set of Ipv4 interfaces associated to this Ipv4 stack.",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
    78
                   ObjectVectorValue (),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    79
                   MakeObjectVectorAccessor (&Ipv4L3Protocol::m_interfaces),
2933
c7983cfa2cb3 add ObjectVector::GetItemTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    80
                   MakeObjectVectorChecker<Ipv4Interface> ())
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
    81
5374
825478d4cf10 Tom's update to Gustavo's patch for bug 676.
Craig Dowell <craigdo@ee.washington.edu>
parents: 5211
diff changeset
    82
    .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission",
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
    83
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_sendOutgoingTrace))
5374
825478d4cf10 Tom's update to Gustavo's patch for bug 676.
Craig Dowell <craigdo@ee.washington.edu>
parents: 5211
diff changeset
    84
    .AddTraceSource ("UnicastForward", "A unicast IPv4 packet was received by this node and is being forwarded to another node",
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
    85
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_unicastForwardTrace))
5374
825478d4cf10 Tom's update to Gustavo's patch for bug 676.
Craig Dowell <craigdo@ee.washington.edu>
parents: 5211
diff changeset
    86
    .AddTraceSource ("LocalDeliver", "An IPv4 packet was received by/for this node, and it is being forward up the stack",
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
    87
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_localDeliverTrace))
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
    88
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
    89
  ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    90
  return tid;
2232
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    91
}
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    92
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    93
Ipv4L3Protocol::Ipv4L3Protocol()
5487
9485bee6b7eb Ipv4L3Protocol::GetInterface optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5380
diff changeset
    94
  : m_identification (0)
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
    95
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    96
{
6558
4528811088d9 get rid of annoying logging for getters and of the _NOARGS log calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6536
diff changeset
    97
  NS_LOG_FUNCTION (this);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    98
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    99
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   100
Ipv4L3Protocol::~Ipv4L3Protocol ()
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   101
{
3150
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   102
  NS_LOG_FUNCTION (this);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   103
}
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   104
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   105
void
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   106
Ipv4L3Protocol::Insert (Ptr<IpL4Protocol> protocol)
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   107
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   108
  NS_LOG_FUNCTION (this << protocol);
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   109
  m_protocols.push_back (protocol);
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   110
}
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   111
Ptr<IpL4Protocol>
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   112
Ipv4L3Protocol::GetProtocol (int protocolNumber) const
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   113
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   114
  NS_LOG_FUNCTION (this << protocolNumber);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   115
  for (L4List_t::const_iterator i = m_protocols.begin (); i != m_protocols.end (); ++i)
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   116
    {
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   117
      if ((*i)->GetProtocolNumber () == protocolNumber)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   118
        {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   119
          return *i;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   120
        }
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   121
    }
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   122
  return 0;
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   123
}
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   124
void
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   125
Ipv4L3Protocol::Remove (Ptr<IpL4Protocol> protocol)
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   126
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   127
  NS_LOG_FUNCTION (this << protocol);
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   128
  m_protocols.remove (protocol);
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   129
}
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   130
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   131
void
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   132
Ipv4L3Protocol::SetNode (Ptr<Node> node)
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   133
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   134
  NS_LOG_FUNCTION (this << node);
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   135
  m_node = node;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   136
  // Add a LoopbackNetDevice if needed, and an Ipv4Interface on top of it
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   137
  SetupLoopback ();
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   138
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   139
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   140
Ptr<Socket> 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   141
Ipv4L3Protocol::CreateRawSocket (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   142
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   143
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   144
  Ptr<Ipv4RawSocketImpl> socket = CreateObject<Ipv4RawSocketImpl> ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   145
  socket->SetNode (m_node);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   146
  m_sockets.push_back (socket);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   147
  return socket;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   148
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   149
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   150
Ipv4L3Protocol::DeleteRawSocket (Ptr<Socket> socket)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   151
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   152
  NS_LOG_FUNCTION (this << socket);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   153
  for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   154
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   155
      if ((*i) == socket)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   156
        {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   157
          m_sockets.erase (i);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   158
          return;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   159
        }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   160
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   161
  return;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   162
}
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   163
/*
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   164
 * This method is called by AddAgregate and completes the aggregation
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   165
 * by setting the node in the ipv4 stack
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   166
 */
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   167
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   168
Ipv4L3Protocol::NotifyNewAggregate ()
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   169
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   170
  NS_LOG_FUNCTION (this);
4669
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   171
  if (m_node == 0)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   172
    {
4669
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   173
      Ptr<Node>node = this->GetObject<Node>();
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   174
      // verify that it's a valid node and that
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   175
      // the node has not been set before
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   176
      if (node != 0)
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   177
        {
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   178
          this->SetNode (node);
8aaa5e83939e avoid excessive calls to GetObject during topology construction
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4616
diff changeset
   179
        }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   180
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   181
  Object::NotifyNewAggregate ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   182
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   183
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   184
void 
4481
9250a25ee683 Doxygen cleanup
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   185
Ipv4L3Protocol::SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   186
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   187
  NS_LOG_FUNCTION (this << routingProtocol);
4481
9250a25ee683 Doxygen cleanup
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   188
  m_routingProtocol = routingProtocol;
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   189
  m_routingProtocol->SetIpv4 (this);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   190
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   191
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   192
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   193
Ptr<Ipv4RoutingProtocol> 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   194
Ipv4L3Protocol::GetRoutingProtocol (void) const
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   195
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   196
  NS_LOG_FUNCTION (this);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   197
  return m_routingProtocol;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   198
}
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   199
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   200
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   201
Ipv4L3Protocol::DoDispose (void)
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   202
{
3150
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   203
  NS_LOG_FUNCTION (this);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   204
  for (L4List_t::iterator i = m_protocols.begin (); i != m_protocols.end (); ++i)
3588
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   205
    {
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   206
      *i = 0;
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   207
    }
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   208
  m_protocols.clear ();
ad0a36bfdb62 bug 282: remove Ipv4L4Demux
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3548
diff changeset
   209
4283
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 4210
diff changeset
   210
  for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); ++i)
3150
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   211
    {
4283
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 4210
diff changeset
   212
      *i = 0;
3150
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   213
    }
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   214
  m_interfaces.clear ();
5916
8f94a0ca3964 Bug 790: Fix memory leak in routing-aodv-regression
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 5856
diff changeset
   215
  m_sockets.clear ();
555
4d3b2a77bc92 convert Node * to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 551
diff changeset
   216
  m_node = 0;
4616
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4607
diff changeset
   217
  m_routingProtocol = 0;
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   218
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   219
  for (MapFragments_t::iterator it = m_fragments.begin (); it != m_fragments.end (); it++)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   220
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   221
      it->second = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   222
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   223
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   224
  for (MapFragmentsTimers_t::iterator it = m_fragmentsTimers.begin (); it != m_fragmentsTimers.end (); it++)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   225
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   226
      if (it->second.IsRunning ())
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   227
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   228
          it->second.Cancel ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   229
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   230
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   231
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   232
  m_fragments.clear ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   233
  m_fragmentsTimers.clear ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   234
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 983
diff changeset
   235
  Object::DoDispose ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   238
void
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   239
Ipv4L3Protocol::SetupLoopback (void)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   240
{
6558
4528811088d9 get rid of annoying logging for getters and of the _NOARGS log calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6536
diff changeset
   241
  NS_LOG_FUNCTION (this);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   242
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   243
  Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   244
  Ptr<LoopbackNetDevice> device = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   245
  // First check whether an existing LoopbackNetDevice exists on the node
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   246
  for (uint32_t i = 0; i < m_node->GetNDevices (); i++)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   247
    {
7741
2eec1176940e Bug 1367 - [LLVM] error: added parentheses
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
   248
      if ((device = DynamicCast<LoopbackNetDevice> (m_node->GetDevice (i))))
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   249
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   250
          break;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   251
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   252
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   253
  if (device == 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   254
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   255
      device = CreateObject<LoopbackNetDevice> (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   256
      m_node->AddDevice (device);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   257
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   258
  interface->SetDevice (device);
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   259
  interface->SetNode (m_node);
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   260
  Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress (Ipv4Address::GetLoopback (), Ipv4Mask::GetLoopback ());
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   261
  interface->AddAddress (ifaceAddr);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   262
  uint32_t index = AddIpv4Interface (interface);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   263
  Ptr<Node> node = GetObject<Node> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   264
  node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, this), 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   265
                                 Ipv4L3Protocol::PROT_NUMBER, device);
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   266
  interface->SetUp ();
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   267
  if (m_routingProtocol != 0)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   268
    {
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   269
      m_routingProtocol->NotifyInterfaceUp (index);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   270
    }
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   271
}
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   272
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   274
Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   276
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
  m_defaultTtl = ttl;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   279
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   281
Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   282
{
8960
beab5f474e09 Fix logging in Ipv4L3Protocol::AddInterface and Ipv4L3Protocol::Receive.
Vedran Miletić <rivanvx@gmail.com>
parents: 7758
diff changeset
   283
  NS_LOG_FUNCTION (this << device);
3172
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
   284
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
   285
  Ptr<Node> node = GetObject<Node> ();
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
   286
  node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, this), 
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
   287
                                 Ipv4L3Protocol::PROT_NUMBER, device);
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
   288
  node->RegisterProtocolHandler (MakeCallback (&ArpL3Protocol::Receive, PeekPointer (GetObject<ArpL3Protocol> ())),
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
   289
                                 ArpL3Protocol::PROT_NUMBER, device);
e661e08c3211 Don't register IPv4 protocol handler for all interfaces, only for IPv4-enabled interfaces.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3153
diff changeset
   290
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   291
  Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   292
  interface->SetNode (m_node);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   293
  interface->SetDevice (device);
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
   294
  interface->SetForwarding (m_ipForward);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   295
  return AddIpv4Interface (interface);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   296
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   297
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   298
uint32_t 
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
   299
Ipv4L3Protocol::AddIpv4Interface (Ptr<Ipv4Interface>interface)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2977
diff changeset
   301
  NS_LOG_FUNCTION (this << interface);
5487
9485bee6b7eb Ipv4L3Protocol::GetInterface optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5380
diff changeset
   302
  uint32_t index = m_interfaces.size ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
  m_interfaces.push_back (interface);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
  return index;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   306
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
   307
Ptr<Ipv4Interface>
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   308
Ipv4L3Protocol::GetInterface (uint32_t index) const
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   310
  NS_LOG_FUNCTION (this << index);
5487
9485bee6b7eb Ipv4L3Protocol::GetInterface optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5380
diff changeset
   311
  if (index < m_interfaces.size ())
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
    {
5487
9485bee6b7eb Ipv4L3Protocol::GetInterface optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5380
diff changeset
   313
      return m_interfaces[index];
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
  return 0;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   317
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   319
Ipv4L3Protocol::GetNInterfaces (void) const
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   320
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   321
  NS_LOG_FUNCTION (this);
5487
9485bee6b7eb Ipv4L3Protocol::GetInterface optimization
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5380
diff changeset
   322
  return m_interfaces.size ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   323
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   325
int32_t 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   326
Ipv4L3Protocol::GetInterfaceForAddress (
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   327
  Ipv4Address address) const
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   328
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   329
  NS_LOG_FUNCTION (this << address);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   330
  int32_t interface = 0;
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   331
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   332
       i != m_interfaces.end (); 
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 4284
diff changeset
   333
       i++, interface++)
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   334
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   335
      for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   336
        {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   337
          if ((*i)->GetAddress (j).GetLocal () == address)
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   338
            {
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   339
              return interface;
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   340
            }
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   341
        }
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   342
    }
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   343
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   344
  return -1;
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   345
}
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   346
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   347
int32_t 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   348
Ipv4L3Protocol::GetInterfaceForPrefix (
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   349
  Ipv4Address address, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   350
  Ipv4Mask mask) const
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   351
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   352
  NS_LOG_FUNCTION (this << address << mask);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   353
  int32_t interface = 0;
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   354
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   355
       i != m_interfaces.end (); 
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 4284
diff changeset
   356
       i++, interface++)
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   357
    {
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   358
      for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   359
        {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   360
          if ((*i)->GetAddress (j).GetLocal ().CombineMask (mask) == address.CombineMask (mask))
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   361
            {
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   362
              return interface;
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4373
diff changeset
   363
            }
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   364
        }
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   365
    }
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   366
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   367
  return -1;
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   368
}
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   369
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   370
int32_t 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   371
Ipv4L3Protocol::GetInterfaceForDevice (
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   372
  Ptr<const NetDevice> device) const
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   373
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   374
  NS_LOG_FUNCTION (this << device);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   375
  int32_t interface = 0;
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   376
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   377
       i != m_interfaces.end (); 
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 4284
diff changeset
   378
       i++, interface++)
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   379
    {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   380
      if ((*i)->GetDevice () == device)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   381
        {
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 4284
diff changeset
   382
          return interface;
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   383
        }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   384
    }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   385
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   386
  return -1;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   387
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   388
5760
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   389
bool
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   390
Ipv4L3Protocol::IsDestinationAddress (Ipv4Address address, uint32_t iif) const
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   391
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   392
  NS_LOG_FUNCTION (this << address << iif);
5760
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   393
  // First check the incoming interface for a unicast address match
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   394
  for (uint32_t i = 0; i < GetNAddresses (iif); i++)
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   395
    {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   396
      Ipv4InterfaceAddress iaddr = GetAddress (iif, i);
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   397
      if (address == iaddr.GetLocal ())
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   398
        {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   399
          NS_LOG_LOGIC ("For me (destination " << address << " match)");
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   400
          return true;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   401
        }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   402
      if (address == iaddr.GetBroadcast ())
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   403
        {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   404
          NS_LOG_LOGIC ("For me (interface broadcast address)");
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   405
          return true;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   406
        }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   407
    }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   408
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   409
  if (address.IsMulticast ())
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   410
    {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   411
#ifdef NOTYET
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   412
      if (MulticastCheckGroup (iif, address ))
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   413
#endif
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   414
      if (true)
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   415
        {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   416
          NS_LOG_LOGIC ("For me (Ipv4Addr multicast address");
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   417
          return true;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   418
        }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   419
    }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   420
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   421
  if (address.IsBroadcast ())
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   422
    {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   423
      NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)");
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   424
      return true;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   425
    }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   426
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   427
  if (GetWeakEsModel ())  // Check other interfaces
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   428
    { 
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   429
      for (uint32_t j = 0; j < GetNInterfaces (); j++)
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   430
        {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   431
          if (j == uint32_t (iif)) continue;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   432
          for (uint32_t i = 0; i < GetNAddresses (j); i++)
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   433
            {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   434
              Ipv4InterfaceAddress iaddr = GetAddress (j, i);
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   435
              if (address == iaddr.GetLocal ())
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   436
                {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   437
                  NS_LOG_LOGIC ("For me (destination " << address << " match) on another interface");
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   438
                  return true;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   439
                }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   440
              //  This is a small corner case:  match another interface's broadcast address
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   441
              if (address == iaddr.GetBroadcast ())
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   442
                {
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   443
                  NS_LOG_LOGIC ("For me (interface broadcast address on another interface)");
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   444
                  return true;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   445
                }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   446
            }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   447
        }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   448
    }
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   449
  return false;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   450
}
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
   451
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   452
void 
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   453
Ipv4L3Protocol::Receive ( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   454
                          const Address &to, NetDevice::PacketType packetType)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   455
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   456
  NS_LOG_FUNCTION (this << device << p << protocol << from << to << packetType);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   457
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   458
  NS_LOG_LOGIC ("Packet from " << from << " received on node " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   459
                m_node->GetId ());
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   460
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   461
  uint32_t interface = 0;
3548
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3461
diff changeset
   462
  Ptr<Packet> packet = p->Copy ();
e5ab96db540e bug 273: constify packet pointers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3461
diff changeset
   463
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
   464
  Ptr<Ipv4Interface> ipv4Interface;
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   465
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   466
       i != m_interfaces.end (); 
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   467
       i++, interface++)
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   468
    {
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
   469
      ipv4Interface = *i;
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
   470
      if (ipv4Interface->GetDevice () == device)
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   471
        {
3958
7658bcc28d8d Drop packets in Ipv4L3Protocol::Receive if interface is down
Tom Henderson <tomh@tomh.org>
parents: 3956
diff changeset
   472
          if (ipv4Interface->IsUp ())
7658bcc28d8d Drop packets in Ipv4L3Protocol::Receive if interface is down
Tom Henderson <tomh@tomh.org>
parents: 3956
diff changeset
   473
            {
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   474
              m_rxTrace (packet, m_node->GetObject<Ipv4> (), interface);
3958
7658bcc28d8d Drop packets in Ipv4L3Protocol::Receive if interface is down
Tom Henderson <tomh@tomh.org>
parents: 3956
diff changeset
   475
              break;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   476
            }
3958
7658bcc28d8d Drop packets in Ipv4L3Protocol::Receive if interface is down
Tom Henderson <tomh@tomh.org>
parents: 3956
diff changeset
   477
          else
7658bcc28d8d Drop packets in Ipv4L3Protocol::Receive if interface is down
Tom Henderson <tomh@tomh.org>
parents: 3956
diff changeset
   478
            {
6030
7b67e0413b57 linearize mixins and make internet stack helper work correctly
Craig Dowell <craigdo@ee.washington.edu>
parents: 6015
diff changeset
   479
              NS_LOG_LOGIC ("Dropping received packet -- interface is down");
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   480
              Ipv4Header ipHeader;
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   481
              packet->RemoveHeader (ipHeader);
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   482
              m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv4> (), interface);
3958
7658bcc28d8d Drop packets in Ipv4L3Protocol::Receive if interface is down
Tom Henderson <tomh@tomh.org>
parents: 3956
diff changeset
   483
              return;
7658bcc28d8d Drop packets in Ipv4L3Protocol::Receive if interface is down
Tom Henderson <tomh@tomh.org>
parents: 3956
diff changeset
   484
            }
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   485
        }
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   486
    }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   487
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   488
  Ipv4Header ipHeader;
4558
31e9053749bb bug 491: It is painful to enable all checksums
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4502
diff changeset
   489
  if (Node::ChecksumEnabled ())
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   490
    {
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   491
      ipHeader.EnableChecksum ();
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   492
    }
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   493
  packet->RemoveHeader (ipHeader);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   494
5977
288416b082a4 [bug 806] Remove CSMA padding from IP datagrams
Bill Roome <wdr@bell-labs.com>
parents: 5916
diff changeset
   495
  // Trim any residual frame padding from underlying devices
288416b082a4 [bug 806] Remove CSMA padding from IP datagrams
Bill Roome <wdr@bell-labs.com>
parents: 5916
diff changeset
   496
  if (ipHeader.GetPayloadSize () < packet->GetSize ())
288416b082a4 [bug 806] Remove CSMA padding from IP datagrams
Bill Roome <wdr@bell-labs.com>
parents: 5916
diff changeset
   497
    {
288416b082a4 [bug 806] Remove CSMA padding from IP datagrams
Bill Roome <wdr@bell-labs.com>
parents: 5916
diff changeset
   498
      packet->RemoveAtEnd (packet->GetSize () - ipHeader.GetPayloadSize ());
288416b082a4 [bug 806] Remove CSMA padding from IP datagrams
Bill Roome <wdr@bell-labs.com>
parents: 5916
diff changeset
   499
    }
288416b082a4 [bug 806] Remove CSMA padding from IP datagrams
Bill Roome <wdr@bell-labs.com>
parents: 5916
diff changeset
   500
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   501
  if (!ipHeader.IsChecksumOk ()) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   502
    {
6030
7b67e0413b57 linearize mixins and make internet stack helper work correctly
Craig Dowell <craigdo@ee.washington.edu>
parents: 6015
diff changeset
   503
      NS_LOG_LOGIC ("Dropping received packet -- checksum not ok");
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   504
      m_dropTrace (ipHeader, packet, DROP_BAD_CHECKSUM, m_node->GetObject<Ipv4> (), interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   505
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   506
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   507
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   508
  for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   509
    {
5529
58b1b656d536 Default TTL of IPv4 broadcast datagrams changed from 1 to 64
Pavel Boyko <boyko@iitp.ru>
parents: 5487
diff changeset
   510
      NS_LOG_LOGIC ("Forwarding to raw socket"); 
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   511
      Ptr<Ipv4RawSocketImpl> socket = *i;
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   512
      socket->ForwardUp (packet, ipHeader, ipv4Interface);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   513
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   514
5984
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   515
  NS_ASSERT_MSG (m_routingProtocol != 0, "Need a routing protocol object to process packets");
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   516
  if (!m_routingProtocol->RouteInput (packet, ipHeader, device,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   517
                                      MakeCallback (&Ipv4L3Protocol::IpForward, this),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   518
                                      MakeCallback (&Ipv4L3Protocol::IpMulticastForward, this),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   519
                                      MakeCallback (&Ipv4L3Protocol::LocalDeliver, this),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   520
                                      MakeCallback (&Ipv4L3Protocol::RouteInputError, this)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   521
                                      ))
6300
bd1da3a75496 bug 861: Log drop traces for forwarding failures into IPv4 and IPv6 ascii traces
Tom Henderson <tomh@tomh.org>
parents: 6232
diff changeset
   522
    {
bd1da3a75496 bug 861: Log drop traces for forwarding failures into IPv4 and IPv6 ascii traces
Tom Henderson <tomh@tomh.org>
parents: 6232
diff changeset
   523
      NS_LOG_WARN ("No route found for forwarding packet.  Drop.");
bd1da3a75496 bug 861: Log drop traces for forwarding failures into IPv4 and IPv6 ascii traces
Tom Henderson <tomh@tomh.org>
parents: 6232
diff changeset
   524
      m_dropTrace (ipHeader, packet, DROP_NO_ROUTE, m_node->GetObject<Ipv4> (), interface);
bd1da3a75496 bug 861: Log drop traces for forwarding failures into IPv4 and IPv6 ascii traces
Tom Henderson <tomh@tomh.org>
parents: 6232
diff changeset
   525
    }
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   526
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   527
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   528
Ptr<Icmpv4L4Protocol> 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   529
Ipv4L3Protocol::GetIcmp (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   530
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   531
  NS_LOG_FUNCTION (this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   532
  Ptr<IpL4Protocol> prot = GetProtocol (Icmpv4L4Protocol::GetStaticProtocolNumber ());
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   533
  if (prot != 0)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   534
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   535
      return prot->GetObject<Icmpv4L4Protocol> ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   536
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   537
  else
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   538
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   539
      return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   540
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   541
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   542
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   543
bool
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   544
Ipv4L3Protocol::IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   545
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   546
  NS_LOG_FUNCTION (this << ad << interfaceMask);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   547
  return !ad.IsMulticast () && !ad.IsSubnetDirectedBroadcast (interfaceMask);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   548
}
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   549
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   550
void 
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6558
diff changeset
   551
Ipv4L3Protocol::SendWithHeader (Ptr<Packet> packet, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   552
                                Ipv4Header ipHeader,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   553
                                Ptr<Ipv4Route> route)
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6300
diff changeset
   554
{
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6300
diff changeset
   555
  NS_LOG_FUNCTION (this << packet << ipHeader << route);
9110
9ae62bcda73e Checksum for Ipv4RawSocket
Daniel L. <nikkipui@gmail.com>
parents: 8960
diff changeset
   556
  if (Node::ChecksumEnabled ())
9ae62bcda73e Checksum for Ipv4RawSocket
Daniel L. <nikkipui@gmail.com>
parents: 8960
diff changeset
   557
    {
9ae62bcda73e Checksum for Ipv4RawSocket
Daniel L. <nikkipui@gmail.com>
parents: 8960
diff changeset
   558
      ipHeader.EnableChecksum ();
9ae62bcda73e Checksum for Ipv4RawSocket
Daniel L. <nikkipui@gmail.com>
parents: 8960
diff changeset
   559
    }
6336
464e8093700d update Bug 932 (Support IP_HDRINCL option for Ipv4RawSocket) again: regarding w/ Tom's comments.
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6334
diff changeset
   560
  SendRealOut (route, packet, ipHeader);
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6300
diff changeset
   561
}
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6300
diff changeset
   562
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6300
diff changeset
   563
void 
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6300
diff changeset
   564
Ipv4L3Protocol::Send (Ptr<Packet> packet, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   565
                      Ipv4Address source,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   566
                      Ipv4Address destination,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   567
                      uint8_t protocol,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   568
                      Ptr<Ipv4Route> route)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   569
{
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   570
  NS_LOG_FUNCTION (this << packet << source << destination << uint32_t (protocol) << route);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   571
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   572
  Ipv4Header ipHeader;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   573
  bool mayFragment = true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   574
  uint8_t ttl = m_defaultTtl;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   575
  SocketIpTtlTag tag;
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4481
diff changeset
   576
  bool found = packet->RemovePacketTag (tag);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   577
  if (found)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   578
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   579
      ttl = tag.GetTtl ();
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   580
    }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   581
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   582
  uint8_t tos = m_defaultTos;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   583
  SocketIpTosTag ipTosTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   584
  found = packet->RemovePacketTag (ipTosTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   585
  if (found)
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   586
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   587
      tos = ipTosTag.GetTos ();
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   588
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   589
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   590
  // Handle a few cases:
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   591
  // 1) packet is destined to limited broadcast address
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   592
  // 2) packet is destined to a subnet-directed broadcast address
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   593
  // 3) packet is not broadcast, and is passed in with a route entry
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   594
  // 4) packet is not broadcast, and is passed in with a route entry but route->GetGateway is not set (e.g., on-demand)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   595
  // 5) packet is not broadcast, and route is NULL (e.g., a raw socket call, or ICMP)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   596
6181
05727a89b220 bug 857 - Link-Local Multicast handle in Ipv4 Output processing
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6047
diff changeset
   597
  // 1) packet is destined to limited broadcast address or link-local multicast address
05727a89b220 bug 857 - Link-Local Multicast handle in Ipv4 Output processing
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6047
diff changeset
   598
  if (destination.IsBroadcast () || destination.IsLocalMulticast ())
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   599
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   600
      NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 1:  limited broadcast");
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   601
      ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   602
      uint32_t ifaceIndex = 0;
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   603
      for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   604
           ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   605
        {
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
   606
          Ptr<Ipv4Interface> outInterface = *ifaceIter;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   607
          Ptr<Packet> packetCopy = packet->Copy ();
1308
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   608
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   609
          NS_ASSERT (packetCopy->GetSize () <= outInterface->GetDevice ()->GetMtu ());
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   610
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   611
          m_sendOutgoingTrace (ipHeader, packetCopy, ifaceIndex);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   612
          packetCopy->AddHeader (ipHeader);
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   613
          m_txTrace (packetCopy, m_node->GetObject<Ipv4> (), ifaceIndex);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   614
          outInterface->Send (packetCopy, destination);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   615
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   616
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   617
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   618
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   619
  // 2) check: packet is destined to a subnet-directed broadcast address
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   620
  uint32_t ifaceIndex = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   621
  for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   622
       ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   623
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   624
      Ptr<Ipv4Interface> outInterface = *ifaceIter;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   625
      for (uint32_t j = 0; j < GetNAddresses (ifaceIndex); j++)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   626
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   627
          Ipv4InterfaceAddress ifAddr = GetAddress (ifaceIndex, j);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   628
          NS_LOG_LOGIC ("Testing address " << ifAddr.GetLocal () << " with mask " << ifAddr.GetMask ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   629
          if (destination.IsSubnetDirectedBroadcast (ifAddr.GetMask ()) && 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   630
              destination.CombineMask (ifAddr.GetMask ()) == ifAddr.GetLocal ().CombineMask (ifAddr.GetMask ())   )
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   631
            {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   632
              NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 2:  subnet directed bcast to " << ifAddr.GetLocal ());
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   633
              ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   634
              Ptr<Packet> packetCopy = packet->Copy ();
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   635
              m_sendOutgoingTrace (ipHeader, packetCopy, ifaceIndex);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   636
              packetCopy->AddHeader (ipHeader);
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   637
              m_txTrace (packetCopy, m_node->GetObject<Ipv4> (), ifaceIndex);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   638
              outInterface->Send (packetCopy, destination);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   639
              return;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   640
            }
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   641
        }
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   642
    }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   643
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   644
  // 3) packet is not broadcast, and is passed in with a route entry
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   645
  //    with a valid Ipv4Address as the gateway
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   646
  if (route && route->GetGateway () != Ipv4Address ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   647
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   648
      NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 3:  passed in with route");
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   649
      ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   650
      int32_t interface = GetInterfaceForDevice (route->GetOutputDevice ());
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   651
      m_sendOutgoingTrace (ipHeader, packet, interface);
6182
9e060dd421fa bug 868 - invalid packet size after Ipv4L3Protocol::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6181
diff changeset
   652
      SendRealOut (route, packet->Copy (), ipHeader);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   653
      return; 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   654
    } 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   655
  // 4) packet is not broadcast, and is passed in with a route entry but route->GetGateway is not set (e.g., on-demand)
6232
cdf770714461 (bug 867) Minor bug in Ipv4L3Protocol::Send()
Danqi Wang <beyondwdq@gmail.com>
parents: 6182
diff changeset
   656
  if (route && route->GetGateway () == Ipv4Address ())
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   657
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   658
      // This could arise because the synchronous RouteOutput() call
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   659
      // returned to the transport protocol with a source address but
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   660
      // there was no next hop available yet (since a route may need
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   661
      // to be queried).
6466
a5e7a5b2c2a6 improve a few logging statements
Tom Henderson <tomh@tomh.org>
parents: 6442
diff changeset
   662
      NS_FATAL_ERROR ("Ipv4L3Protocol::Send case 4: This case not yet implemented");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   663
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   664
  // 5) packet is not broadcast, and route is NULL (e.g., a raw socket call)
6466
a5e7a5b2c2a6 improve a few logging statements
Tom Henderson <tomh@tomh.org>
parents: 6442
diff changeset
   665
  NS_LOG_LOGIC ("Ipv4L3Protocol::Send case 5:  passed in with no route " << destination);
4567
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4565
diff changeset
   666
  Socket::SocketErrno errno_; 
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5850
diff changeset
   667
  Ptr<NetDevice> oif (0); // unused for now
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   668
  ipHeader = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tos, mayFragment);
5984
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   669
  Ptr<Ipv4Route> newRoute;
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   670
  if (m_routingProtocol != 0)
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   671
    {
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   672
      newRoute = m_routingProtocol->RouteOutput (packet, ipHeader, oif, errno_);
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   673
    }
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   674
  else
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   675
    {
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   676
      NS_LOG_ERROR ("Ipv4L3Protocol::Send: m_routingProtocol == 0");
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5977
diff changeset
   677
    }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   678
  if (newRoute)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   679
    {
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   680
      int32_t interface = GetInterfaceForDevice (newRoute->GetOutputDevice ());
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   681
      m_sendOutgoingTrace (ipHeader, packet, interface);
6182
9e060dd421fa bug 868 - invalid packet size after Ipv4L3Protocol::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6181
diff changeset
   682
      SendRealOut (newRoute, packet->Copy (), ipHeader);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   683
    }
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   684
  else
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   685
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   686
      NS_LOG_WARN ("No route to host.  Drop.");
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   687
      m_dropTrace (ipHeader, packet, DROP_NO_ROUTE, m_node->GetObject<Ipv4> (), 0);
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   688
    }
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   689
}
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   690
9894
ac4e52a91d5d Doxygenate todo's
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9813
diff changeset
   691
/// \todo when should we set ip_id?   check whether we are incrementing
ac4e52a91d5d Doxygenate todo's
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9813
diff changeset
   692
/// m_identification on packets that may later be dropped in this stack
ac4e52a91d5d Doxygenate todo's
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9813
diff changeset
   693
/// and whether that deviates from Linux
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   694
Ipv4Header
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   695
Ipv4L3Protocol::BuildHeader (
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   696
  Ipv4Address source,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   697
  Ipv4Address destination,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   698
  uint8_t protocol,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   699
  uint16_t payloadSize,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   700
  uint8_t ttl,
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   701
  uint8_t tos,
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   702
  bool mayFragment)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   703
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   704
  NS_LOG_FUNCTION (this << source << destination << (uint16_t)protocol << payloadSize << (uint16_t)ttl << (uint16_t)tos << mayFragment);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   705
  Ipv4Header ipHeader;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   706
  ipHeader.SetSource (source);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   707
  ipHeader.SetDestination (destination);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   708
  ipHeader.SetProtocol (protocol);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   709
  ipHeader.SetPayloadSize (payloadSize);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   710
  ipHeader.SetTtl (ttl);
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9110
diff changeset
   711
  ipHeader.SetTos (tos);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   712
  if (mayFragment == true)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   713
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   714
      ipHeader.SetMayFragment ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   715
      ipHeader.SetIdentification (m_identification);
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   716
      m_identification++;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   717
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   718
  else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   719
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   720
      ipHeader.SetDontFragment ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   721
      // TBD:  set to zero here; will cause traces to change
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   722
      ipHeader.SetIdentification (m_identification);
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   723
      m_identification++;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   724
    }
4558
31e9053749bb bug 491: It is painful to enable all checksums
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4502
diff changeset
   725
  if (Node::ChecksumEnabled ())
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   726
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   727
      ipHeader.EnableChecksum ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   728
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   729
  return ipHeader;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   730
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   731
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   732
void
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   733
Ipv4L3Protocol::SendRealOut (Ptr<Ipv4Route> route,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   734
                             Ptr<Packet> packet,
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   735
                             Ipv4Header const &ipHeader)
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   736
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   737
  NS_LOG_FUNCTION (this << route << packet << &ipHeader);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   738
  if (route == 0)
983
47c42bd66fb7 Support dynamic routing and multiple routing protocols; static routing table is refactored as a "routing protocol".
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 979
diff changeset
   739
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   740
      NS_LOG_WARN ("No route to host.  Drop.");
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   741
      m_dropTrace (ipHeader, packet, DROP_NO_ROUTE, m_node->GetObject<Ipv4> (), 0);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   742
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   743
    }
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   744
  packet->AddHeader (ipHeader);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   745
  Ptr<NetDevice> outDev = route->GetOutputDevice ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   746
  int32_t interface = GetInterfaceForDevice (outDev);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   747
  NS_ASSERT (interface >= 0);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   748
  Ptr<Ipv4Interface> outInterface = GetInterface (interface);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   749
  NS_LOG_LOGIC ("Send via NetDevice ifIndex " << outDev->GetIfIndex () << " ipv4InterfaceIndex " << interface);
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   750
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   751
  if (!route->GetGateway ().IsEqual (Ipv4Address ("0.0.0.0")))
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   752
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   753
      if (outInterface->IsUp ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   754
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   755
          NS_LOG_LOGIC ("Send to gateway " << route->GetGateway ());
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   756
          if ( packet->GetSize () > outInterface->GetDevice ()->GetMtu () )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   757
            {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   758
              std::list<Ptr<Packet> > listFragments;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   759
              DoFragmentation (packet, outInterface->GetDevice ()->GetMtu (), listFragments);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   760
              for ( std::list<Ptr<Packet> >::iterator it = listFragments.begin (); it != listFragments.end (); it++ )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   761
                {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   762
                  m_txTrace (*it, m_node->GetObject<Ipv4> (), interface);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   763
                  outInterface->Send (*it, route->GetGateway ());
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   764
                }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   765
            }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   766
          else
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   767
            {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   768
              m_txTrace (packet, m_node->GetObject<Ipv4> (), interface);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   769
              outInterface->Send (packet, route->GetGateway ());
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   770
            }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   771
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   772
      else
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   773
        {
6030
7b67e0413b57 linearize mixins and make internet stack helper work correctly
Craig Dowell <craigdo@ee.washington.edu>
parents: 6015
diff changeset
   774
          NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << route->GetGateway ());
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   775
          Ipv4Header ipHeader;
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   776
          packet->RemoveHeader (ipHeader);
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   777
          m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv4> (), interface);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   778
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   779
    } 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   780
  else 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   781
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   782
      if (outInterface->IsUp ())
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   783
        {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   784
          NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   785
          if ( packet->GetSize () > outInterface->GetDevice ()->GetMtu () )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   786
            {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   787
              std::list<Ptr<Packet> > listFragments;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   788
              DoFragmentation (packet, outInterface->GetDevice ()->GetMtu (), listFragments);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   789
              for ( std::list<Ptr<Packet> >::iterator it = listFragments.begin (); it != listFragments.end (); it++ )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   790
                {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   791
                  NS_LOG_LOGIC ("Sending fragment " << **it );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   792
                  m_txTrace (*it, m_node->GetObject<Ipv4> (), interface);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   793
                  outInterface->Send (*it, ipHeader.GetDestination ());
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   794
                }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   795
            }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   796
          else
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   797
            {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   798
              m_txTrace (packet, m_node->GetObject<Ipv4> (), interface);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   799
              outInterface->Send (packet, ipHeader.GetDestination ());
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   800
            }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   801
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   802
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   803
        {
6030
7b67e0413b57 linearize mixins and make internet stack helper work correctly
Craig Dowell <craigdo@ee.washington.edu>
parents: 6015
diff changeset
   804
          NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << ipHeader.GetDestination ());
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   805
          Ipv4Header ipHeader;
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   806
          packet->RemoveHeader (ipHeader);
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   807
          m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv4> (), interface);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   808
        }
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   809
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   810
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   811
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   812
// This function analogous to Linux ip_mr_forward()
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   813
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   814
Ipv4L3Protocol::IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, Ptr<const Packet> p, const Ipv4Header &header)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   815
{
6558
4528811088d9 get rid of annoying logging for getters and of the _NOARGS log calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6536
diff changeset
   816
  NS_LOG_FUNCTION (this << mrtentry << p << header);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   817
  NS_LOG_LOGIC ("Multicast forwarding logic for node: " << m_node->GetId ());
7161
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   818
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   819
  std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
7161
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   820
  std::map<uint32_t, uint32_t>::iterator mapIter;
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   821
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   822
  for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   823
    {
7161
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   824
      uint32_t interfaceId = mapIter->first;
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   825
      //uint32_t outputTtl = mapIter->second;  // Unused for now
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   826
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   827
      Ptr<Packet> packet = p->Copy ();
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   828
      Ipv4Header h = header;
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   829
      h.SetTtl (header.GetTtl () - 1);
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   830
      if (h.GetTtl () == 0)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   831
        {
7161
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   832
          NS_LOG_WARN ("TTL exceeded.  Drop.");
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   833
          m_dropTrace (header, packet, DROP_TTL_EXPIRED, m_node->GetObject<Ipv4> (), interfaceId);
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   834
          return;
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   835
        }
7161
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   836
      NS_LOG_LOGIC ("Forward multicast via interface " << interfaceId);
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   837
      Ptr<Ipv4Route> rtentry = Create<Ipv4Route> ();
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   838
      rtentry->SetSource (h.GetSource ());
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   839
      rtentry->SetDestination (h.GetDestination ());
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   840
      rtentry->SetGateway (Ipv4Address::GetAny ());
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   841
      rtentry->SetOutputDevice (GetNetDevice (interfaceId));
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   842
      SendRealOut (rtentry, packet, h);
7cc4506fb853 bug 1047: Multicast routes on nodes with >16 interfaces
Ken Renard <kenneth.renard@arl.army.mil>
parents: 6834
diff changeset
   843
      continue;
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   844
    }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   845
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   846
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   847
// This function analogous to Linux ip_forward()
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   848
void
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   849
Ipv4L3Protocol::IpForward (Ptr<Ipv4Route> rtentry, Ptr<const Packet> p, const Ipv4Header &header)
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   850
{
6558
4528811088d9 get rid of annoying logging for getters and of the _NOARGS log calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6536
diff changeset
   851
  NS_LOG_FUNCTION (this << rtentry << p << header);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   852
  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   853
  // Forwarding
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   854
  Ipv4Header ipHeader = header;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   855
  Ptr<Packet> packet = p->Copy ();
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   856
  int32_t interface = GetInterfaceForDevice (rtentry->GetOutputDevice ());
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   857
  ipHeader.SetTtl (ipHeader.GetTtl () - 1);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   858
  if (ipHeader.GetTtl () == 0)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   859
    {
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4567
diff changeset
   860
      // Do not reply to ICMP or to multicast/broadcast IP address 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4567
diff changeset
   861
      if (ipHeader.GetProtocol () != Icmpv4L4Protocol::PROT_NUMBER && 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   862
          ipHeader.GetDestination ().IsBroadcast () == false &&
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   863
          ipHeader.GetDestination ().IsMulticast () == false)
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   864
        {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   865
          Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   866
          icmp->SendTimeExceededTtl (ipHeader, packet);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   867
        }
3956
0339a8ad5983 Bug 400: allow /32 addresses to be used on IPv4 interfaces
Tom Henderson <tomh@tomh.org>
parents: 3877
diff changeset
   868
      NS_LOG_WARN ("TTL exceeded.  Drop.");
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
   869
      m_dropTrace (header, packet, DROP_TTL_EXPIRED, m_node->GetObject<Ipv4> (), interface);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   870
      return;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   871
    }
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   872
  m_unicastForwardTrace (ipHeader, packet, interface);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   873
  SendRealOut (rtentry, packet, ipHeader);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   874
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   875
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   876
void
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   877
Ipv4L3Protocol::LocalDeliver (Ptr<const Packet> packet, Ipv4Header const&ip, uint32_t iif)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   878
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   879
  NS_LOG_FUNCTION (this << packet << &ip << iif);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   880
  Ptr<Packet> p = packet->Copy (); // need to pass a non-const packet up
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   881
  Ipv4Header ipHeader = ip;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   882
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   883
  if ( !ipHeader.IsLastFragment () || ipHeader.GetFragmentOffset () != 0 )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   884
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   885
      NS_LOG_LOGIC ("Received a fragment, processing " << *p );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   886
      bool isPacketComplete;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   887
      isPacketComplete = ProcessFragment (p, ipHeader, iif);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   888
      if ( isPacketComplete == false)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   889
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   890
          return;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   891
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   892
      NS_LOG_LOGIC ("Got last fragment, Packet is complete " << *p );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
   893
    }
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   894
5204
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   895
  m_localDeliverTrace (ip, packet, iif);
cb3087d8f330 Ipv4L3Protocol::Drop trace source enhanced, and add new SendOutgoing, UnicastForward, and LocalDeliver trace sources, for the FlowMonitor.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4669
diff changeset
   896
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   897
  Ptr<IpL4Protocol> protocol = GetProtocol (ip.GetProtocol ());
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   898
  if (protocol != 0)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   899
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   900
      // we need to make a copy in the unlikely event we hit the
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   901
      // RX_ENDPOINT_UNREACH codepath
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   902
      Ptr<Packet> copy = p->Copy ();
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   903
      enum IpL4Protocol::RxStatus status = 
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   904
        protocol->Receive (p, ip, GetInterface (iif));
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   905
      switch (status) {
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   906
        case IpL4Protocol::RX_OK:
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   907
        // fall through
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   908
        case IpL4Protocol::RX_ENDPOINT_CLOSED:
5380
3a8177ed2dda Fix for bug 615
Josh Pelkey <jpelkey@gatech.edu>
parents: 5374
diff changeset
   909
        // fall through
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   910
        case IpL4Protocol::RX_CSUM_FAILED:
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   911
          break;
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7625
diff changeset
   912
        case IpL4Protocol::RX_ENDPOINT_UNREACH:
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   913
          if (ip.GetDestination ().IsBroadcast () == true ||
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   914
              ip.GetDestination ().IsMulticast () == true)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   915
            {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   916
              break; // Do not reply to broadcast or multicast
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   917
            }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   918
          // Another case to suppress ICMP is a subnet-directed broadcast
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   919
          bool subnetDirected = false;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   920
          for (uint32_t i = 0; i < GetNAddresses (iif); i++)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   921
            {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   922
              Ipv4InterfaceAddress addr = GetAddress (iif, i);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   923
              if (addr.GetLocal ().CombineMask (addr.GetMask ()) == ip.GetDestination ().CombineMask (addr.GetMask ()) &&
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   924
                  ip.GetDestination ().IsSubnetDirectedBroadcast (addr.GetMask ()))
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   925
                {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   926
                  subnetDirected = true;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   927
                }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   928
            }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   929
          if (subnetDirected == false)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   930
            {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   931
              GetIcmp ()->SendDestUnreachPort (ip, copy);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   932
            }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
   933
        }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3744
diff changeset
   934
    }
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   935
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   936
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   937
bool
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   938
Ipv4L3Protocol::AddAddress (uint32_t i, Ipv4InterfaceAddress address)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   939
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2977
diff changeset
   940
  NS_LOG_FUNCTION (this << i << address);
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
   941
  Ptr<Ipv4Interface> interface = GetInterface (i);
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   942
  bool retVal = interface->AddAddress (address);
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   943
  if (m_routingProtocol != 0)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   944
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   945
      m_routingProtocol->NotifyAddAddress (i, address);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
   946
    }
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   947
  return retVal;
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   948
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   949
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   950
Ipv4InterfaceAddress 
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   951
Ipv4L3Protocol::GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   952
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   953
  NS_LOG_FUNCTION (this << interfaceIndex << addressIndex);
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   954
  Ptr<Ipv4Interface> interface = GetInterface (interfaceIndex);
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   955
  return interface->GetAddress (addressIndex);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   956
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   957
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
   958
uint32_t 
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   959
Ipv4L3Protocol::GetNAddresses (uint32_t interface) const
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   960
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
   961
  NS_LOG_FUNCTION (this << interface);
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   962
  Ptr<Ipv4Interface> iface = GetInterface (interface);
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   963
  return iface->GetNAddresses ();
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   964
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   965
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   966
bool
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   967
Ipv4L3Protocol::RemoveAddress (uint32_t i, uint32_t addressIndex)
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   968
{
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   969
  NS_LOG_FUNCTION (this << i << addressIndex);
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   970
  Ptr<Ipv4Interface> interface = GetInterface (i);
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   971
  Ipv4InterfaceAddress address = interface->RemoveAddress (addressIndex);
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   972
  if (address != Ipv4InterfaceAddress ())
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   973
    {
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   974
      if (m_routingProtocol != 0)
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   975
        {
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   976
          m_routingProtocol->NotifyRemoveAddress (i, address);
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   977
        }
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   978
      return true;
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   979
    }
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   980
  return false;
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   981
}
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4561
diff changeset
   982
9915
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   983
bool
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   984
Ipv4L3Protocol::RemoveAddress (uint32_t i, Ipv4Address address)
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   985
{
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   986
  NS_LOG_FUNCTION (this << i << address);
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   987
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   988
  if (address == Ipv4Address::GetLoopback())
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   989
    {
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   990
      NS_LOG_WARN ("Cannot remove loopback address.");
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   991
      return false;
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   992
    }
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   993
  Ptr<Ipv4Interface> interface = GetInterface (i);
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   994
  Ipv4InterfaceAddress ifAddr = interface->RemoveAddress (address);
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   995
  if (ifAddr != Ipv4InterfaceAddress ())
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   996
    {
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   997
      if (m_routingProtocol != 0)
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   998
        {
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   999
          m_routingProtocol->NotifyRemoveAddress (i, ifAddr);
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
  1000
        }
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
  1001
      return true;
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
  1002
    }
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
  1003
  return false;
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
  1004
}
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
  1005
5850
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1006
Ipv4Address 
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1007
Ipv4L3Protocol::SelectSourceAddress (Ptr<const NetDevice> device,
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
  1008
                                     Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
5850
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1009
{
6558
4528811088d9 get rid of annoying logging for getters and of the _NOARGS log calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6536
diff changeset
  1010
  NS_LOG_FUNCTION (this << device << dst << scope);
5850
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1011
  Ipv4Address addr ("0.0.0.0");
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1012
  Ipv4InterfaceAddress iaddr; 
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1013
  bool found = false;
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1014
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1015
  if (device != 0)
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1016
    {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1017
      int32_t i = GetInterfaceForDevice (device);
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1018
      NS_ASSERT_MSG (i >= 0, "No device found on node");
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1019
      for (uint32_t j = 0; j < GetNAddresses (i); j++)
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1020
        {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1021
          iaddr = GetAddress (i, j);
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1022
          if (iaddr.IsSecondary ()) continue;
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1023
          if (iaddr.GetScope () > scope) continue; 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
  1024
          if (dst.CombineMask (iaddr.GetMask ())  == iaddr.GetLocal ().CombineMask (iaddr.GetMask ()) )
5850
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1025
            {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1026
              return iaddr.GetLocal ();
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1027
            }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1028
          if (!found)
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1029
            {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1030
              addr = iaddr.GetLocal ();
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1031
              found = true;
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1032
            }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1033
        }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1034
    }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1035
  if (found)
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1036
    {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1037
      return addr;
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1038
    }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1039
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1040
  // Iterate among all interfaces
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1041
  for (uint32_t i = 0; i < GetNInterfaces (); i++)
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1042
    {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1043
      for (uint32_t j = 0; j < GetNAddresses (i); j++)
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1044
        {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1045
          iaddr = GetAddress (i, j);
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1046
          if (iaddr.IsSecondary ()) continue;
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1047
          if (iaddr.GetScope () != Ipv4InterfaceAddress::LINK 
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1048
              && iaddr.GetScope () <= scope) 
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1049
            {
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1050
              return iaddr.GetLocal ();
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1051
            }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1052
        }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1053
    }
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1054
  NS_LOG_WARN ("Could not find source address for " << dst << " and scope " 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
  1055
                                                    << scope << ", returning 0");
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
  1056
  return addr;
5850
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1057
}
1a6375ac5431 Fix bug 606: Arp depends on IP routing system
Tom Henderson <tomh@tomh.org>
parents: 5760
diff changeset
  1058
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1059
void 
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1060
Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric)
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1061
{
6558
4528811088d9 get rid of annoying logging for getters and of the _NOARGS log calls.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6536
diff changeset
  1062
  NS_LOG_FUNCTION (this << i << metric);
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1063
  Ptr<Ipv4Interface> interface = GetInterface (i);
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1064
  interface->SetMetric (metric);
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1065
}
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1066
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1067
uint16_t
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1068
Ipv4L3Protocol::GetMetric (uint32_t i) const
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1069
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1070
  NS_LOG_FUNCTION (this << i);
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1071
  Ptr<Ipv4Interface> interface = GetInterface (i);
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1072
  return interface->GetMetric ();
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1073
}
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1524
diff changeset
  1074
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1075
uint16_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
  1076
Ipv4L3Protocol::GetMtu (uint32_t i) const
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1077
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1078
  NS_LOG_FUNCTION (this << i);
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
  1079
  Ptr<Ipv4Interface> interface = GetInterface (i);
4572
e5dcdf2868df Remove Ipv4Interface::GetMtu ()
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
  1080
  return interface->GetDevice ()->GetMtu ();
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1081
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
  1082
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1083
bool 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
  1084
Ipv4L3Protocol::IsUp (uint32_t i) const
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1085
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1086
  NS_LOG_FUNCTION (this << i);
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
  1087
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1088
  return interface->IsUp ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1089
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
  1090
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1091
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
  1092
Ipv4L3Protocol::SetUp (uint32_t i)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1093
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2977
diff changeset
  1094
  NS_LOG_FUNCTION (this << i);
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
  1095
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1096
  interface->SetUp ();
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
  1097
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
  1098
  if (m_routingProtocol != 0)
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
  1099
    {
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
  1100
      m_routingProtocol->NotifyInterfaceUp (i);
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
  1101
    }
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1102
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
  1103
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1104
void 
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
  1105
Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1106
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2977
diff changeset
  1107
  NS_LOG_FUNCTION (this << ifaceIndex);
1341
f685d4bf320f use the Object::GetTraceResolver tracing support rather than the old adhoc tracing code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1333
diff changeset
  1108
  Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1109
  interface->SetDown ();
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
  1110
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
  1111
  if (m_routingProtocol != 0)
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
  1112
    {
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4558
diff changeset
  1113
      m_routingProtocol->NotifyInterfaceDown (ifaceIndex);
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
  1114
    }
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1115
}
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
  1116
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1117
bool 
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1118
Ipv4L3Protocol::IsForwarding (uint32_t i) const
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1119
{
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1120
  NS_LOG_FUNCTION (this << i);
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1121
  Ptr<Ipv4Interface> interface = GetInterface (i);
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1122
  NS_LOG_LOGIC ("Forwarding state: " << interface->IsForwarding ());
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1123
  return interface->IsForwarding ();
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1124
}
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1125
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1126
void 
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1127
Ipv4L3Protocol::SetForwarding (uint32_t i, bool val)
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1128
{
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1129
  NS_LOG_FUNCTION (this << i);
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1130
  Ptr<Ipv4Interface> interface = GetInterface (i);
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1131
  interface->SetForwarding (val);
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1132
}
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1133
4377
2a05a47dba22 Remove class Ipv4Impl
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
  1134
Ptr<NetDevice>
2a05a47dba22 Remove class Ipv4Impl
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
  1135
Ipv4L3Protocol::GetNetDevice (uint32_t i)
2a05a47dba22 Remove class Ipv4Impl
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
  1136
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1137
  NS_LOG_FUNCTION (this << i);
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7161
diff changeset
  1138
  return GetInterface (i)->GetDevice ();
4377
2a05a47dba22 Remove class Ipv4Impl
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
  1139
}
2a05a47dba22 Remove class Ipv4Impl
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
  1140
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1141
void 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1142
Ipv4L3Protocol::SetIpForward (bool forward) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1143
{
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1144
  NS_LOG_FUNCTION (this << forward);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1145
  m_ipForward = forward;
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1146
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1147
    {
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1148
      (*i)->SetForwarding (forward);
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1149
    }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1150
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1151
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1152
bool 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1153
Ipv4L3Protocol::GetIpForward (void) const
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1154
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1155
  NS_LOG_FUNCTION (this);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1156
  return m_ipForward;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4379
diff changeset
  1157
}
4377
2a05a47dba22 Remove class Ipv4Impl
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
  1158
5760
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1159
void 
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1160
Ipv4L3Protocol::SetWeakEsModel (bool model)
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1161
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1162
  NS_LOG_FUNCTION (this << model);
5760
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1163
  m_weakEsModel = model;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1164
}
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1165
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1166
bool 
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1167
Ipv4L3Protocol::GetWeakEsModel (void) const
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1168
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1169
  NS_LOG_FUNCTION (this);
5760
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1170
  return m_weakEsModel;
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1171
}
4f08a0837018 Add new method for determining whether Ipv4 dest address is mine; add attribute to control RFC1122 behavior
Tom Henderson <tomh@tomh.org>
parents: 5738
diff changeset
  1172
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1173
void
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1174
Ipv4L3Protocol::RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno)
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1175
{
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1176
  NS_LOG_FUNCTION (this << p << ipHeader << sockErrno);
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1177
  NS_LOG_LOGIC ("Route input failure-- dropping packet to " << ipHeader << " with errno " << sockErrno); 
6015
e9e4575cb6f3 clean up internet stack helper tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5916
diff changeset
  1178
  m_dropTrace (ipHeader, p, DROP_ROUTE_ERROR, m_node->GetObject<Ipv4> (), 0);
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1179
}
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4603
diff changeset
  1180
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1181
void
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1182
Ipv4L3Protocol::DoFragmentation (Ptr<Packet> packet, uint32_t outIfaceMtu, std::list<Ptr<Packet> >& listFragments)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1183
{
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1184
  // BEWARE: here we do assume that the header options are not present.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1185
  // a much more complex handling is necessary in case there are options.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1186
  // If (when) IPv4 option headers will be implemented, the following code shall be changed.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1187
  // Of course also the reassemby code shall be changed as well.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1188
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1189
  NS_LOG_FUNCTION (this << *packet << outIfaceMtu << &listFragments);
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1190
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1191
  Ptr<Packet> p = packet->Copy ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1192
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1193
  Ipv4Header ipv4Header;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1194
  p->RemoveHeader (ipv4Header);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1195
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1196
  NS_ASSERT_MSG( (ipv4Header.GetSerializedSize() == 5*4),
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1197
                 "IPv4 fragmentation implementation only works without option headers." );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1198
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1199
  uint16_t offset = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1200
  bool moreFragment = true;
7625
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1201
  uint16_t originalOffset = 0;
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1202
  bool alreadyFragmented = false;
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1203
  uint32_t currentFragmentablePartSize = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1204
7625
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1205
  if (!ipv4Header.IsLastFragment())
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1206
    {
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1207
      alreadyFragmented = true;
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1208
      originalOffset = ipv4Header.GetFragmentOffset();
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1209
    }
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1210
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1211
  // IPv4 fragments are all 8 bytes aligned but the last.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1212
  // The IP payload size is:
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1213
  // floor( ( outIfaceMtu - ipv4Header.GetSerializedSize() ) /8 ) *8
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1214
  uint32_t fragmentSize = (outIfaceMtu - ipv4Header.GetSerializedSize () ) & ~uint32_t (0x7);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1215
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1216
  NS_LOG_LOGIC ("Fragmenting - Target Size: " << fragmentSize );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1217
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1218
  do
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1219
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1220
      Ipv4Header fragmentHeader = ipv4Header;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1221
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1222
      if (p->GetSize () > offset + fragmentSize )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1223
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1224
          moreFragment = true;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1225
          currentFragmentablePartSize = fragmentSize;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1226
          fragmentHeader.SetMoreFragments ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1227
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1228
      else
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1229
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1230
          moreFragment = false;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1231
          currentFragmentablePartSize = p->GetSize () - offset;
7625
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1232
          if (alreadyFragmented)
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1233
            {
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1234
              fragmentHeader.SetMoreFragments ();
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1235
            }
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1236
          else
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1237
            {
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1238
              fragmentHeader.SetLastFragment ();
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1239
            }
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1240
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1241
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1242
      NS_LOG_LOGIC ("Fragment creation - " << offset << ", " << currentFragmentablePartSize  );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1243
      Ptr<Packet> fragment = p->CreateFragment (offset, currentFragmentablePartSize);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1244
      NS_LOG_LOGIC ("Fragment created - " << offset << ", " << fragment->GetSize ()  );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1245
7625
17e4957e0cce IPv4 packets double fragmentation was broken. Fixed.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7562
diff changeset
  1246
      fragmentHeader.SetFragmentOffset (offset+originalOffset);
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1247
      fragmentHeader.SetPayloadSize (currentFragmentablePartSize);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1248
7562
be2b2c3c480c Bug 1281 Checksum not calculated when doing IP fragmentation
John Abraham <john.abraham@gatech.edu>
parents: 7386
diff changeset
  1249
      if (Node::ChecksumEnabled ())
be2b2c3c480c Bug 1281 Checksum not calculated when doing IP fragmentation
John Abraham <john.abraham@gatech.edu>
parents: 7386
diff changeset
  1250
        {
be2b2c3c480c Bug 1281 Checksum not calculated when doing IP fragmentation
John Abraham <john.abraham@gatech.edu>
parents: 7386
diff changeset
  1251
          fragmentHeader.EnableChecksum ();
be2b2c3c480c Bug 1281 Checksum not calculated when doing IP fragmentation
John Abraham <john.abraham@gatech.edu>
parents: 7386
diff changeset
  1252
        }
be2b2c3c480c Bug 1281 Checksum not calculated when doing IP fragmentation
John Abraham <john.abraham@gatech.edu>
parents: 7386
diff changeset
  1253
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1254
      NS_LOG_LOGIC ("Fragment check - " << fragmentHeader.GetFragmentOffset ()  );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1255
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1256
      NS_LOG_LOGIC ("New fragment Header " << fragmentHeader);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1257
      fragment->AddHeader (fragmentHeader);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1258
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1259
      std::ostringstream oss;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1260
      fragment->Print (oss);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1261
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1262
      NS_LOG_LOGIC ("New fragment " << *fragment);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1263
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1264
      listFragments.push_back (fragment);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1265
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1266
      offset += currentFragmentablePartSize;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1267
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1268
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1269
  while (moreFragment);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1270
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1271
  return;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1272
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1273
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1274
bool
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1275
Ipv4L3Protocol::ProcessFragment (Ptr<Packet>& packet, Ipv4Header& ipHeader, uint32_t iif)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1276
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1277
  NS_LOG_FUNCTION (this << packet << ipHeader << iif);
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1278
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1279
  uint64_t addressCombination = uint64_t (ipHeader.GetSource ().Get ()) << 32 & uint64_t (ipHeader.GetDestination ().Get ());
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1280
  uint32_t idProto = uint32_t (ipHeader.GetIdentification ()) << 16 & uint32_t (ipHeader.GetProtocol ());
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1281
  std::pair<uint64_t, uint32_t> key;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1282
  bool ret = false;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1283
  Ptr<Packet> p = packet->Copy ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1284
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1285
  key.first = addressCombination;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1286
  key.second = idProto;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1287
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1288
  Ptr<Fragments> fragments;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1289
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1290
  MapFragments_t::iterator it = m_fragments.find (key);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1291
  if (it == m_fragments.end ())
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1292
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1293
      fragments = Create<Fragments> ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1294
      m_fragments.insert (std::make_pair (key, fragments));
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1295
      m_fragmentsTimers[key] = Simulator::Schedule (m_fragmentExpirationTimeout,
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1296
                                                    &Ipv4L3Protocol::HandleFragmentsTimeout, this,
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1297
                                                    key, ipHeader, iif);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1298
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1299
  else
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1300
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1301
      fragments = it->second;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1302
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1303
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1304
  NS_LOG_LOGIC ("Adding fragment - Size: " << packet->GetSize ( ) << " - Offset: " << (ipHeader.GetFragmentOffset ()) );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1305
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1306
  fragments->AddFragment (p, ipHeader.GetFragmentOffset (), !ipHeader.IsLastFragment () );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1307
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1308
  if ( fragments->IsEntire () )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1309
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1310
      packet = fragments->GetPacket ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1311
      fragments = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1312
      m_fragments.erase (key);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1313
      if (m_fragmentsTimers[key].IsRunning ())
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1314
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1315
          NS_LOG_LOGIC ("Stopping WaitFragmentsTimer at " << Simulator::Now ().GetSeconds () << " due to complete packet");
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1316
          m_fragmentsTimers[key].Cancel ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1317
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1318
      m_fragmentsTimers.erase (key);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1319
      ret = true;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1320
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1321
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1322
  return ret;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1323
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1324
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1325
Ipv4L3Protocol::Fragments::Fragments ()
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1326
  : m_moreFragment (0)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1327
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1328
  NS_LOG_FUNCTION (this);
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1329
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1330
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1331
Ipv4L3Protocol::Fragments::~Fragments ()
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1332
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1333
  NS_LOG_FUNCTION (this);
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1334
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1335
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1336
void
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1337
Ipv4L3Protocol::Fragments::AddFragment (Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFragment)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1338
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1339
  NS_LOG_FUNCTION (this << fragment << fragmentOffset << moreFragment);
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1340
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1341
  std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1342
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1343
  for (it = m_fragments.begin (); it != m_fragments.end (); it++)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1344
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1345
      if (it->second > fragmentOffset)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1346
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1347
          break;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1348
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1349
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1350
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1351
  if (it == m_fragments.end ())
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1352
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1353
      m_moreFragment = moreFragment;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1354
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1355
9813
16f65595bdf8 imported patch make_pair.patch
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9710
diff changeset
  1356
  m_fragments.insert (it, std::pair<Ptr<Packet>, uint16_t> (fragment, fragmentOffset));
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1357
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1358
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1359
bool
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1360
Ipv4L3Protocol::Fragments::IsEntire () const
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1361
{
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1362
  NS_LOG_FUNCTION (this);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1363
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1364
  bool ret = !m_moreFragment && m_fragments.size () > 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1365
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1366
  if (ret)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1367
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1368
      uint16_t lastEndOffset = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1369
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1370
      for (std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it = m_fragments.begin (); it != m_fragments.end (); it++)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1371
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1372
          // overlapping fragments do exist
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1373
          NS_LOG_LOGIC ("Checking overlaps " << lastEndOffset << " - " << it->second );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1374
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1375
          if (lastEndOffset < it->second)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1376
            {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1377
              ret = false;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1378
              break;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1379
            }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1380
          // fragments might overlap in strange ways
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1381
          uint16_t fragmentEnd = it->first->GetSize () + it->second;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1382
          lastEndOffset = std::max ( lastEndOffset, fragmentEnd );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1383
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1384
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1385
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1386
  return ret;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1387
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1388
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1389
Ptr<Packet>
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1390
Ipv4L3Protocol::Fragments::GetPacket () const
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1391
{
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1392
  NS_LOG_FUNCTION (this);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1393
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1394
  std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it = m_fragments.begin ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1395
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1396
  Ptr<Packet> p = Create<Packet> ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1397
  uint16_t lastEndOffset = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1398
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1399
  for ( it = m_fragments.begin (); it != m_fragments.end (); it++)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1400
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1401
      if ( lastEndOffset > it->second )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1402
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1403
          // The fragments are overlapping.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1404
          // We do not overwrite the "old" with the "new" because we do not know when each arrived.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1405
          // This is different from what Linux does.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1406
          // It is not possible to emulate a fragmentation attack.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1407
          uint32_t newStart = lastEndOffset - it->second;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1408
          if ( it->first->GetSize () > newStart )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1409
            {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1410
              uint32_t newSize = it->first->GetSize () - newStart;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1411
              Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1412
              p->AddAtEnd (tempFragment);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1413
            }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1414
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1415
      else
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1416
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1417
          NS_LOG_LOGIC ("Adding: " << *(it->first) );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1418
          p->AddAtEnd (it->first);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1419
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1420
      lastEndOffset = p->GetSize ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1421
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1422
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1423
  return p;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1424
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1425
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1426
Ptr<Packet>
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1427
Ipv4L3Protocol::Fragments::GetPartialPacket () const
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1428
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1429
  NS_LOG_FUNCTION (this);
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1430
  
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1431
  std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it = m_fragments.begin ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1432
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1433
  Ptr<Packet> p = Create<Packet> ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1434
  uint16_t lastEndOffset = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1435
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1436
  if ( m_fragments.begin ()->second > 0 )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1437
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1438
      return p;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1439
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1440
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1441
  for ( it = m_fragments.begin (); it != m_fragments.end (); it++)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1442
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1443
      if ( lastEndOffset > it->second )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1444
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1445
          uint32_t newStart = lastEndOffset - it->second;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1446
          uint32_t newSize = it->first->GetSize () - newStart;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1447
          Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1448
          p->AddAtEnd (tempFragment);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1449
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1450
      else if ( lastEndOffset == it->second )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1451
        {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1452
          NS_LOG_LOGIC ("Adding: " << *(it->first) );
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1453
          p->AddAtEnd (it->first);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1454
        }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1455
      lastEndOffset = p->GetSize ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1456
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1457
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1458
  return p;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1459
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1460
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1461
void
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1462
Ipv4L3Protocol::HandleFragmentsTimeout (std::pair<uint64_t, uint32_t> key, Ipv4Header & ipHeader, uint32_t iif)
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1463
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9145
diff changeset
  1464
  NS_LOG_FUNCTION (this << &key << &ipHeader << iif);
7366
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1465
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1466
  MapFragments_t::iterator it = m_fragments.find (key);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1467
  Ptr<Packet> packet = it->second->GetPartialPacket ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1468
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1469
  // if we have at least 8 bytes, we can send an ICMP.
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1470
  if ( packet->GetSize () > 8 )
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1471
    {
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1472
      Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1473
      icmp->SendTimeExceededTtl (ipHeader, packet);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1474
    }
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1475
  m_dropTrace (ipHeader, packet, DROP_FRAGMENT_TIMEOUT, m_node->GetObject<Ipv4> (), iif);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1476
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1477
  // clear the buffers
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1478
  it->second = 0;
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1479
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1480
  m_fragments.erase (key);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1481
  m_fragmentsTimers.erase (key);
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1482
}
838079534ff9 Support to IPv4 fragmentation
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7256
diff changeset
  1483
7386
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7385
diff changeset
  1484
} // namespace ns3