src/internet-stack/ipv4-l3-protocol.cc
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Wed, 16 Jul 2008 16:17:21 +0100
changeset 3461 b38ddf78470a
parent 3448 0bd851bb1225
child 3548 e5ab96db540e
permissions -rw-r--r--
Remove some useless code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
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"
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
    34
#include "arp-l3-protocol.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
733
fb1882e7d785 rename ipv4.h to ipv4-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    36
#include "ipv4-l3-protocol.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
#include "ipv4-l4-protocol.h"
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
#include "ipv4-interface.h"
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    39
#include "ipv4-loopback-interface.h"
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    40
#include "arp-ipv4-interface.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
#include "ipv4-l4-demux.h"
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
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    49
NS_OBJECT_ENSURE_REGISTERED (Ipv4L3Protocol);
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    50
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
    51
TypeId 
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    52
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
    53
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    54
  static TypeId tid = TypeId ("ns3::Ipv4L3Protocol")
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    55
    .SetParent<Object> ()
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    56
    .AddConstructor<Ipv4L3Protocol> ()
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    57
    .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
    58
                   UintegerValue (64),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    59
                   MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    60
                   MakeUintegerChecker<uint8_t> ())
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
    61
    .AddAttribute ("CalcChecksum", "If true, we calculate the checksum of outgoing packets"
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
    62
                   " and verify the checksum of incoming packets.",
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
    63
                   BooleanValue (false),
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
    64
                   MakeBooleanAccessor (&Ipv4L3Protocol::m_calcChecksum),
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
    65
                   MakeBooleanChecker ())
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    66
    .AddTraceSource ("Tx", "Send ipv4 packet to outgoing interface.",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    67
                   MakeTraceSourceAccessor (&Ipv4L3Protocol::m_txTrace))
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    68
    .AddTraceSource ("Rx", "Receive ipv4 packet from incoming interface.",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    69
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_rxTrace))
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    70
    .AddTraceSource ("Drop", "Drop ipv4 packet",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    71
                     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
    72
    .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
    73
                   ObjectVectorValue (),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    74
                   MakeObjectVectorAccessor (&Ipv4L3Protocol::m_interfaces),
2933
c7983cfa2cb3 add ObjectVector::GetItemTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    75
                   MakeObjectVectorChecker<Ipv4Interface> ())
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    76
    ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    77
  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
    78
}
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    79
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    80
Ipv4L3Protocol::Ipv4L3Protocol()
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 983
diff changeset
    81
  : m_nInterfaces (0),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    82
    m_identification (0)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    83
{
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
    84
  NS_LOG_FUNCTION_NOARGS ();
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1870
diff changeset
    85
  m_staticRouting = CreateObject<Ipv4StaticRouting> ();
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
    86
  AddRoutingProtocol (m_staticRouting, 0);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    87
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    88
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
    89
Ipv4L3Protocol::~Ipv4L3Protocol ()
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    90
{
3150
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
    91
  NS_LOG_FUNCTION (this);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    92
}
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    93
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    94
void
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    95
Ipv4L3Protocol::SetNode (Ptr<Node> node)
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    96
{
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    97
  m_node = node;
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    98
  SetupLoopback ();
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    99
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   100
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   101
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   102
Ipv4L3Protocol::DoDispose (void)
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   103
{
3150
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   104
  NS_LOG_FUNCTION (this);
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   105
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); ++i)
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   106
    {
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   107
      Ptr<Ipv4Interface> interface = *i;
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   108
      interface->Dispose ();
7350a68e5856 more logging. Make sure we do dispose attached Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2989
diff changeset
   109
    }
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
   110
  m_interfaces.clear ();
555
4d3b2a77bc92 convert Node * to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 551
diff changeset
   111
  m_node = 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
   112
  m_staticRouting->Dispose ();
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
   113
  m_staticRouting = 0;
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 983
diff changeset
   114
  Object::DoDispose ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   117
void
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   118
Ipv4L3Protocol::SetupLoopback (void)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   119
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2977
diff changeset
   120
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   121
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   122
  Ptr<Ipv4LoopbackInterface> interface = CreateObject<Ipv4LoopbackInterface> ();
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   123
  interface->SetNode (m_node);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   124
  interface->SetAddress (Ipv4Address::GetLoopback ());
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   125
  interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   126
  uint32_t index = AddIpv4Interface (interface);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   127
  AddHostRouteTo (Ipv4Address::GetLoopback (), index);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   128
  interface->SetUp ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   129
}
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   130
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   132
Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2977
diff changeset
   134
  NS_LOG_FUNCTION_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
  m_defaultTtl = ttl;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
    
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   140
Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, 
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
   141
                      Ipv4Address nextHop, 
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 293
diff changeset
   142
                      uint32_t interface)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
{
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
   144
  NS_LOG_FUNCTION (this << dest << nextHop << interface);
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
   145
  m_staticRouting->AddHostRouteTo (dest, nextHop, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   147
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   149
Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
				uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
{
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
   152
  NS_LOG_FUNCTION (this << dest << interface);
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
   153
  m_staticRouting->AddHostRouteTo (dest, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   155
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   157
Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
				   Ipv4Mask networkMask, 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
				   Ipv4Address nextHop, 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
				   uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
{
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
   162
  NS_LOG_FUNCTION (this << network << networkMask << nextHop << interface);
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
   163
  m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   165
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   167
Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
				   Ipv4Mask networkMask, 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
				   uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
{
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
   171
  NS_LOG_FUNCTION (this << network << networkMask << interface);
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
   172
  m_staticRouting->AddNetworkRouteTo (network, networkMask, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   174
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   176
Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
				 uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
{
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
   179
  NS_LOG_FUNCTION (this << nextHop << interface);
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
   180
  m_staticRouting->SetDefaultRoute (nextHop, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
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
   183
void
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   184
Ipv4L3Protocol::Lookup (
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   185
  Ipv4Header const &ipHeader,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   186
  Ptr<Packet> packet,
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   187
  Ipv4RoutingProtocol::RouteReplyCallback routeReply)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
{
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
   189
  NS_LOG_FUNCTION (this << &ipHeader << packet << &routeReply);
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   190
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   191
  Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply);
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   192
}
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
   193
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
   194
void
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   195
Ipv4L3Protocol::Lookup (
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   196
  uint32_t ifIndex,
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   197
  Ipv4Header const &ipHeader,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   198
  Ptr<Packet> packet,
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   199
  Ipv4RoutingProtocol::RouteReplyCallback routeReply)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
{
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
   201
  NS_LOG_FUNCTION (this << ifIndex << &ipHeader << packet << &routeReply);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   202
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   203
  for (Ipv4RoutingProtocolList::const_iterator rprotoIter = 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   204
         m_routingProtocols.begin ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   205
       rprotoIter != m_routingProtocols.end (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   206
       rprotoIter++)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   208
      NS_LOG_LOGIC ("Requesting route");
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   209
      if ((*rprotoIter).second->RequestRoute (ifIndex, ipHeader, packet, 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   210
                                              routeReply))
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
   211
        return;
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
    }
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   213
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
   214
  if (ipHeader.GetDestination ().IsMulticast () && 
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
   215
      ifIndex == Ipv4RoutingProtocol::IF_INDEX_ANY)
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
   216
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   217
      NS_LOG_LOGIC ("Multicast destination with local source");
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
   218
//
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   219
// We have a multicast packet originating from the current node and were not
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   220
// able to send it using the usual RequestRoute process.  Since the usual
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   221
// process includes trying to use a default multicast route, this means that
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   222
// there was no specific route out of the node found, and there was no default
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   223
// multicast route set.
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
   224
//
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   225
// The fallback position is to look for a default unicast route and use that
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   226
// to get the packet off the node if we have one.
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   227
//
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   228
      Ipv4Route *route = m_staticRouting->GetDefaultRoute ();
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
   229
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   230
      if (route)
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
   231
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   232
          NS_LOG_LOGIC ("Local source. Using unicast default route for "
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   233
            "multicast packet");
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   234
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   235
          routeReply (true, *route, packet, ipHeader);
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   236
          return;
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
   237
        }
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
   238
    }
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   239
//
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   240
// No route found
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   241
//
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
   242
  routeReply (false, Ipv4Route (), packet, 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
   243
}
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
   244
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
   245
void
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
   246
Ipv4L3Protocol::AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
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
   247
                                    int priority)
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
   248
{
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
   249
  NS_LOG_FUNCTION (this << &routingProtocol << priority);
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
   250
  m_routingProtocols.push_back
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
   251
    (std::pair<int, Ptr<Ipv4RoutingProtocol> > (-priority, routingProtocol));
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
   252
  m_routingProtocols.sort ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   256
Ipv4L3Protocol::GetNRoutes (void)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
{
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
   258
  NS_LOG_FUNCTION_NOARGS ();
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
   259
  return m_staticRouting->GetNRoutes ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
}
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
   261
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
Ipv4Route *
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   263
Ipv4L3Protocol::GetRoute (uint32_t index)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
{
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
   265
  NS_LOG_FUNCTION_NOARGS ();
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
   266
  return m_staticRouting->GetRoute (index);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
}
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
   268
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   270
Ipv4L3Protocol::RemoveRoute (uint32_t index)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
{
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
   272
  NS_LOG_FUNCTION (this << index);
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
   273
  m_staticRouting->RemoveRoute (index);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   275
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   276
void 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   277
Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   278
                                   Ipv4Address group,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   279
                                   uint32_t inputInterface,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   280
                                   std::vector<uint32_t> outputInterfaces)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   281
{
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
   282
  NS_LOG_FUNCTION (this << origin << group << inputInterface << &outputInterfaces);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   283
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   284
  m_staticRouting->AddMulticastRoute (origin, group, inputInterface,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   285
    outputInterfaces);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   286
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   287
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   288
void 
1444
7c81b4e2617d piles of doxygen, changes to SetDefaultMulticastRoute plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1443
diff changeset
   289
Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface)
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   290
{
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
   291
  NS_LOG_FUNCTION (this << outputInterface);
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   292
1444
7c81b4e2617d piles of doxygen, changes to SetDefaultMulticastRoute plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1443
diff changeset
   293
  m_staticRouting->SetDefaultMulticastRoute (outputInterface);
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   294
}
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   295
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   296
uint32_t 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   297
Ipv4L3Protocol::GetNMulticastRoutes (void) const
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   298
{
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
   299
  NS_LOG_FUNCTION_NOARGS ();
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   300
  return m_staticRouting->GetNMulticastRoutes ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   301
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   302
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   303
Ipv4MulticastRoute *
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   304
Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   305
{
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
   306
  NS_LOG_FUNCTION (this << index);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   307
  return m_staticRouting->GetMulticastRoute (index);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   308
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   309
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   310
void 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   311
Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   312
                                       Ipv4Address group,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   313
                                       uint32_t inputInterface)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   314
{
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
   315
  NS_LOG_FUNCTION (this << origin << group << inputInterface);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   316
  m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   317
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   318
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   319
void 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   320
Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   321
{
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
   322
  NS_LOG_FUNCTION (this << index);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   323
  m_staticRouting->RemoveMulticastRoute (index);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   324
}
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   327
Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   328
{
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
   329
  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
   330
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
   331
  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
   332
  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
   333
                                 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
   334
  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
   335
                                 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
   336
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   337
  Ptr<ArpIpv4Interface> interface = CreateObject<ArpIpv4Interface> ();
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   338
  interface->SetNode (m_node);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   339
  interface->SetDevice (device);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   340
  return AddIpv4Interface (interface);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   341
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   342
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   343
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
   344
Ipv4L3Protocol::AddIpv4Interface (Ptr<Ipv4Interface>interface)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   345
{
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
   346
  NS_LOG_FUNCTION (this << interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   347
  uint32_t index = m_nInterfaces;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   348
  m_interfaces.push_back (interface);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   349
  m_nInterfaces++;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   350
  return index;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   351
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   352
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
   353
Ptr<Ipv4Interface>
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   354
Ipv4L3Protocol::GetInterface (uint32_t index) const
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
{
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
   356
  NS_LOG_FUNCTION (this << index);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   357
  uint32_t tmp = 0;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   358
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   359
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   360
      if (index == tmp) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   361
	{
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   362
	  return *i;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   363
	}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   364
      tmp++;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   365
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   366
  return 0;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   367
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   368
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   370
Ipv4L3Protocol::GetNInterfaces (void) const
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   371
{
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
   372
  NS_LOG_FUNCTION_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
  return m_nInterfaces;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   375
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
   376
uint32_t 
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
   377
Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const
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
   378
{
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
   379
  NS_LOG_FUNCTION (this << addr);
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
   380
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
   381
  uint32_t ifIndex = 0;
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
   382
  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
   383
       i != m_interfaces.end (); 
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
   384
       i++, ifIndex++)
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
   385
    {
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
   386
      if ((*i)->GetAddress () == addr)
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
   387
        {
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
   388
          return ifIndex;
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
   389
        }
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
   390
    }
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
   391
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2325
diff changeset
   392
  NS_FATAL_ERROR ("Ipv4L3Protocol::FindInterfaceForAddr (): "
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2325
diff changeset
   393
                  "Interface not found for IP address " << addr);
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
   394
  return 0;
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
   395
}
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
   396
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
   397
uint32_t 
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
   398
Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const
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
   399
{
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
   400
  NS_LOG_FUNCTION (this << addr << mask);
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
   401
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
   402
  uint32_t ifIndex = 0;
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
   403
  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
   404
       i != m_interfaces.end (); 
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
   405
       i++, ifIndex++)
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
   406
    {
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
   407
      if ((*i)->GetAddress ().CombineMask (mask) == addr.CombineMask (mask))
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
   408
        {
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
   409
          return ifIndex;
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
   410
        }
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
   411
    }
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
   412
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
   413
  NS_ASSERT_MSG(false, "Ipv4L3Protocol::FindInterfaceForAddr (): "
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
   414
    "Interface not found for masked IP address");
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
   415
  return 0;
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
   416
}
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
   417
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   418
int32_t 
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   419
Ipv4L3Protocol::FindInterfaceIndexForDevice (Ptr<NetDevice> device) const
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   420
{
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
   421
  NS_LOG_FUNCTION (this << device);
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   422
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   423
  uint32_t ifIndex = 0;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   424
  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
   425
       i != m_interfaces.end (); 
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   426
       i++, ifIndex++)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   427
    {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   428
      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
   429
        {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   430
          return ifIndex;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   431
        }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   432
    }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   433
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   434
  return -1;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   435
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   436
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
   437
Ptr<Ipv4Interface>
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   438
Ipv4L3Protocol::FindInterfaceForDevice (Ptr<const NetDevice> device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   439
{
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
   440
  NS_LOG_FUNCTION (this << &device);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   441
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   442
    {
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 555
diff changeset
   443
      if ((*i)->GetDevice () == device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   444
        {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   445
          return *i;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   446
        }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   447
    }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   448
  return 0;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   449
}  
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   450
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   451
void 
3448
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
   452
Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from,
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
   453
                         const Address &to, NetDevice::PacketType packetType)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   454
{
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
   455
  NS_LOG_FUNCTION (this << &device << packet << protocol <<  from);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   456
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   457
  NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ());
1443
580ed7a4dd1e Move MakeMulticastAddress to NetDevice
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   458
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   459
  uint32_t index = 0;
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
   460
  Ptr<Ipv4Interface> ipv4Interface;
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   461
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   462
       i != m_interfaces.end (); 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   463
       i++)
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   464
    {
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
   465
      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
   466
      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
   467
        {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   468
          m_rxTrace (packet, index);
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   469
          break;
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   470
        }
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   471
      index++;
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   472
    }
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   473
  Ipv4Header ipHeader;
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   474
  if (m_calcChecksum)
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   475
    {
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   476
      ipHeader.EnableChecksum ();
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   477
    }
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   478
  packet->RemoveHeader (ipHeader);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   479
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   480
  if (!ipHeader.IsChecksumOk ()) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   481
    {
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   482
      m_dropTrace (packet);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   483
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   485
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   486
  if (Forwarding (index, packet, ipHeader, device)) 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   487
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   488
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   489
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   490
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
   491
  ForwardUp (packet, ipHeader, ipv4Interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   492
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   493
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
   494
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   495
void 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   496
Ipv4L3Protocol::Send (Ptr<Packet> packet, 
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   497
            Ipv4Address source, 
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   498
            Ipv4Address destination,
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   499
            uint8_t protocol)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   500
{
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
   501
  NS_LOG_FUNCTION (this << packet << source << destination << protocol);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   502
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   503
  Ipv4Header ipHeader;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   504
3235
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   505
  if (m_calcChecksum)
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   506
    {
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   507
      ipHeader.EnableChecksum ();
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   508
    }
c2f34dac1b9e add support for attribtues to bug 34
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3216
diff changeset
   509
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   510
  ipHeader.SetSource (source);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   511
  ipHeader.SetDestination (destination);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   512
  ipHeader.SetProtocol (protocol);
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   513
  ipHeader.SetPayloadSize (packet->GetSize ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   514
  ipHeader.SetTtl (m_defaultTtl);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   515
  ipHeader.SetMayFragment ();
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   516
  ipHeader.SetIdentification (m_identification);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   517
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   518
  m_identification ++;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   519
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   520
  // Set TTL to 1 if it is a broadcast packet of any type.  Otherwise,
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   521
  // possibly override the default TTL if the packet is tagged
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   522
  SocketIpTtlTag tag;
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3124
diff changeset
   523
  bool found = packet->FindFirstMatchingTag (tag);
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   524
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   525
  if (destination.IsBroadcast ()) 
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   526
    {
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   527
      ipHeader.SetTtl (1);
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   528
    }
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   529
  else if (found)
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   530
    {
3138
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3124
diff changeset
   531
      ipHeader.SetTtl (tag.GetTtl ());
44711f06705e merge with ns-3-dev
Tom Henderson <tomh@tomh.org>
parents: 3124
diff changeset
   532
      // XXX remove tag here?  
3124
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   533
    }
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   534
  else
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   535
    {
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   536
      uint32_t ifaceIndex = 0;
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   537
      for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   538
           ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   539
        {
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   540
          Ptr<Ipv4Interface> outInterface = *ifaceIter;
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   541
          if (destination.IsSubnetDirectedBroadcast (
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   542
                outInterface->GetNetworkMask ()))
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   543
          {
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   544
            ipHeader.SetTtl (1);
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   545
          }
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   546
        }
473e59b5e141 Implement IPTTL socket option for UDP
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   547
    }
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
   548
  if (destination.IsBroadcast ())
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
    {
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
   550
      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
   551
      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
   552
           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
   553
        {
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
   554
          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
   555
          Ptr<Packet> packetCopy = packet->Copy ();
1308
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   556
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   557
          NS_ASSERT (packetCopy->GetSize () <= outInterface->GetMtu ());
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   558
          packetCopy->AddHeader (ipHeader);
1308
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   559
          m_txTrace (packetCopy, ifaceIndex);
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   560
          outInterface->Send (packetCopy, destination);
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
   561
        }
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
   562
    }
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
   563
  else
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   564
    {
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
   565
      // XXX Note here that in most ipv4 stacks in the world,
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
   566
      // the route calculation for an outgoing packet is not
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
   567
      // done in the ip layer. It is done within the application
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
   568
      // socket when the first packet is sent to avoid this
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
   569
      // costly lookup on a per-packet basis.
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
   570
      // That would require us to get the route from the packet,
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
   571
      // most likely with a packet tag. The higher layers do not
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
   572
      // do this yet for us.
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
   573
      Lookup (ipHeader, packet,
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
   574
              MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
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
   575
    }
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
   576
}
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
   577
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
   578
void
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
   579
Ipv4L3Protocol::SendRealOut (bool found,
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
   580
                             Ipv4Route const &route,
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   581
                             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
   582
                             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
   583
{
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
   584
  NS_LOG_FUNCTION (this << found << &route << packet << &ipHeader);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   585
2325
084b07dceafb Add the IPv4 header before deciding whether to drop packets. Closes bug #135.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2324
diff changeset
   586
  packet->AddHeader (ipHeader);
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
   587
  if (!found)
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
   588
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   589
      NS_LOG_WARN ("No route to host.  Drop.");
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
   590
      m_dropTrace (packet);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   591
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   592
    }
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   593
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   594
  NS_LOG_LOGIC ("Send via interface " << route.GetInterface ());
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   595
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
   596
  Ptr<Ipv4Interface> outInterface = GetInterface (route.GetInterface ());
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   597
  NS_ASSERT (packet->GetSize () <= outInterface->GetMtu ());
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   598
  m_txTrace (packet, route.GetInterface ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   599
  if (route.IsGateway ()) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   600
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   601
      NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   602
      outInterface->Send (packet, route.GetGateway ());
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   603
    } 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   604
  else 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   605
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   606
      NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
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
   607
      outInterface->Send (packet, ipHeader.GetDestination ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   608
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   609
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   610
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   611
bool
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   612
Ipv4L3Protocol::Forwarding (
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   613
  uint32_t ifIndex, 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   614
  Ptr<Packet> packet, 
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   615
  Ipv4Header &ipHeader, 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   616
  Ptr<NetDevice> device)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   617
{
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
   618
  NS_LOG_FUNCTION (ifIndex << packet << &ipHeader<< device);
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   619
  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   620
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   621
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   622
       i != m_interfaces.end (); i++) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   623
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   624
      if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   625
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   626
          NS_LOG_LOGIC ("For me (destination match)");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   627
          return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   628
        }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   629
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   630
  
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   631
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   632
       i != m_interfaces.end (); i++) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   633
    {
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
   634
      Ptr<Ipv4Interface> interface = *i;
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 555
diff changeset
   635
      if (interface->GetDevice () == device)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   636
	{
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   637
	  if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   638
	    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   639
              NS_LOG_LOGIC ("For me (interface broadcast address)");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   640
	      return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   641
	    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   642
	  break;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   643
	}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   644
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   645
      
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
   646
  if (ipHeader.GetDestination ().IsBroadcast ()) 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   647
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   648
      NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   649
      return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   650
    }
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   651
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   652
  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ())) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   653
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   654
      NS_LOG_LOGIC ("For me (Ipv4Addr any address)");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   655
      return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   656
    }
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   657
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   658
  if (ipHeader.GetTtl () == 1) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   659
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   660
      // Should send ttl expired here
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   661
      // XXX
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   662
      NS_LOG_LOGIC ("Not for me (TTL expired).  Drop");
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
   663
      m_dropTrace (packet);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   664
      return true;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   665
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   666
  ipHeader.SetTtl (ipHeader.GetTtl () - 1);
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
   667
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   668
//  
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   669
// If this is a to a multicast address and this node is a member of the 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   670
// indicated group we need to return false so the multicast is forwarded up.
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   671
//        
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   672
  for (Ipv4MulticastGroupList::const_iterator i = m_multicastGroups.begin ();
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   673
       i != m_multicastGroups.end (); i++)
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   674
    {
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   675
      if ((*i).first.IsEqual (ipHeader.GetSource ()) &&
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   676
          (*i).second.IsEqual (ipHeader.GetDestination ()))
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   677
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   678
          NS_LOG_LOGIC ("For me (Joined multicast group)");
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   679
          // We forward with a packet copy, since forwarding may change
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   680
          // the packet, affecting our local delivery
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   681
          NS_LOG_LOGIC ("Forwarding (multicast).");
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   682
          Lookup (ifIndex, ipHeader, packet->Copy (),
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   683
          MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   684
          return false;
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   685
        }   
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   686
    }     
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   687
  NS_LOG_LOGIC ("Not for me, forwarding.");
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   688
  Lookup (ifIndex, ipHeader, packet,
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   689
  MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   690
  
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   691
  return true;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   692
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   693
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   694
void
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   695
Ipv4L3Protocol::ForwardUp (Ptr<Packet> p, Ipv4Header const&ip,
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
   696
                           Ptr<Ipv4Interface> incomingInterface)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   697
{
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
   698
  NS_LOG_FUNCTION (this << p << &ip);
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   699
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   700
  Ptr<Ipv4L4Demux> demux = m_node->GetObject<Ipv4L4Demux> ();
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 555
diff changeset
   701
  Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
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
   702
  protocol->Receive (p, ip.GetSource (), ip.GetDestination (), incomingInterface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   703
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   704
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   705
void 
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   706
Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   707
{
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
   708
  NS_LOG_FUNCTION (this << origin << group);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   709
  m_multicastGroups.push_back(
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   710
    std::pair<Ipv4Address, Ipv4Address> (origin, group));
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   711
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   712
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   713
void
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   714
Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   715
{
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
   716
  NS_LOG_FUNCTION (this << origin << group);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   717
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   718
  for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   719
       i != m_multicastGroups.end (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   720
       i++)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   721
    {
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   722
      if ((*i).first.IsEqual(origin) && (*i).second.IsEqual(group))
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   723
        {
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   724
          m_multicastGroups.erase (i);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   725
          return;
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   726
        }
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   727
    }
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   728
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   729
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   730
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   731
Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   732
{
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
   733
  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
   734
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   735
  interface->SetAddress (address);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   736
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   737
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   738
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   739
Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   740
{
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
   741
  NS_LOG_FUNCTION (this << i << mask);
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
   742
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   743
  interface->SetNetworkMask (mask);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   744
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   745
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   746
Ipv4Mask 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   747
Ipv4L3Protocol::GetNetworkMask (uint32_t i) const
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   748
{
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
   749
  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
   750
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   751
  return interface->GetNetworkMask ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   752
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   753
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   754
Ipv4Address 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   755
Ipv4L3Protocol::GetAddress (uint32_t i) const
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   756
{
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
   757
  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
   758
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   759
  return interface->GetAddress ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   760
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   761
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
   762
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
   763
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
   764
{
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
   765
  NS_LOG_FUNCTION (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
   766
  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
   767
  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
   768
}
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
   769
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
   770
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
   771
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
   772
{
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
   773
  NS_LOG_FUNCTION (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
   774
  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
   775
  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
   776
}
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
   777
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   778
bool
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   779
Ipv4L3Protocol::GetIfIndexForDestination (
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   780
  Ipv4Address destination, uint32_t& ifIndex) const
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   781
{
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
   782
  NS_LOG_FUNCTION (this << destination << &ifIndex);
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   783
//
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   784
// The first thing we do in trying to determine a source address is to 
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   785
// consult the routing protocols.  These will also check for a default route
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   786
// if one has been set.
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   787
//
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   788
  for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   789
       i != m_routingProtocols.end (); 
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   790
       i++)
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   791
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   792
      NS_LOG_LOGIC ("Requesting Source Address");
1435
a70de165a25a set source IP address in udp-socket packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 1434
diff changeset
   793
      uint32_t ifIndexTmp;
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   794
1435
a70de165a25a set source IP address in udp-socket packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 1434
diff changeset
   795
      if ((*i).second->RequestIfIndex (destination, ifIndexTmp))
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   796
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   797
          NS_LOG_LOGIC ("Found ifIndex " << ifIndexTmp);
1435
a70de165a25a set source IP address in udp-socket packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 1434
diff changeset
   798
          ifIndex = ifIndexTmp;
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   799
          return true;
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   800
        }
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   801
    }
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
   802
//
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   803
// If there's no routing table entry telling us what *single* interface will 
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   804
// be used to send a packet to this destination, we'll have to just pick one.  
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
   805
// If there's only one interface on this node, a good answer isn't very hard
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
   806
// to come up with.  Before jumping to any conclusions, remember that the 
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
   807
// zeroth interface is the loopback interface, so what we actually want is
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
   808
// a situation where there are exactly two interfaces on the node, in which
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   809
// case interface one is the "single" interface connected to the outside world.
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
   810
//
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
   811
  if (GetNInterfaces () == 2)
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
   812
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   813
      NS_LOG_LOGIC ("One Interface.  Using interface 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
   814
      ifIndex = 1;
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
   815
      return true;
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
   816
    }
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
   817
//
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
   818
// If we fall through to here, we have a node with multiple interfaces and
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   819
// no routes to guide us in determining what interface to choose.  Either
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   820
// no default route was found (for unicast or multicast), or in the case of a
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   821
// multicast, the default route contained multiple outbound interfaces.
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   822
//
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   823
// The fallback position is to just get the unicast default route and use 
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   824
// the outgoing interface specified there.  We don't want to leave the source
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   825
// address unset, so we just assert here.
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   826
//
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   827
// N.B. that in the case of a multicast with a route containing multiple
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   828
// outgoing interfaces, the source address of packets from that node will be
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   829
// set to the IP address of the interface set in the default unicast route.
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   830
// Also, in the case of a broadcast, the same will be true.
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   831
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   832
  NS_LOG_LOGIC ("Using default unicast route");
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
   833
  Ipv4Route *route = m_staticRouting->GetDefaultRoute ();
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
   834
2324
a3e10db411b9 The message "Unable to determine outbound interface. No default route set"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   835
  if (route == NULL)
a3e10db411b9 The message "Unable to determine outbound interface. No default route set"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   836
    {
a3e10db411b9 The message "Unable to determine outbound interface. No default route set"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   837
      NS_LOG_LOGIC ("Ipv4L3Protocol::GetIfIndexForDestination (): "
a3e10db411b9 The message "Unable to determine outbound interface. No default route set"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   838
                    "Unable to determine outbound interface.  No default route set");
a3e10db411b9 The message "Unable to determine outbound interface. No default route set"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   839
      return false;
a3e10db411b9 The message "Unable to determine outbound interface. No default route set"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   840
    }
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
   841
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
   842
  ifIndex = route->GetInterface ();
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
   843
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   844
  NS_LOG_LOGIC ("Default route specifies interface " << ifIndex);
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
   845
  return true;
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   846
}
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   847
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   848
uint16_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   849
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
   850
{
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
   851
  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
   852
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   853
  return interface->GetMtu ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   854
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   855
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   856
bool 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   857
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
   858
{
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
   859
  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
   860
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   861
  return interface->IsUp ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   862
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   863
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   864
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   865
Ipv4L3Protocol::SetUp (uint32_t i)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   866
{
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
   867
  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
   868
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   869
  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
   870
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   871
  // If interface address and network mask have been set, add a route
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   872
  // to the network of the interface (like e.g. ifconfig does on a
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   873
  // Linux box)
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   874
  if ((interface->GetAddress ()) != (Ipv4Address ())
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   875
      && (interface->GetNetworkMask ()) != (Ipv4Mask ()))
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   876
    {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   877
      AddNetworkRouteTo (interface->GetAddress ().CombineMask (interface->GetNetworkMask ()),
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   878
                         interface->GetNetworkMask (), i);
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   879
    }
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   880
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   881
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   882
void 
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   883
Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   884
{
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
   885
  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
   886
  Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   887
  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
   888
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   889
  // Remove all routes that are going through this interface
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   890
  bool modified = true;
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   891
  while (modified)
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   892
    {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   893
      modified = false;
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   894
      for (uint32_t i = 0; i < GetNRoutes (); i++)
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   895
        {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   896
          Ipv4Route *route = GetRoute (i);
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   897
          if (route->GetInterface () == ifaceIndex)
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   898
            {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   899
              RemoveRoute (i);
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   900
              modified = true;
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   901
              break;
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   902
            }
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   903
        }
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   904
    }
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   905
}
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   906
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   907
}//namespace ns3