src/internet-node/ipv4-l3-protocol.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 21 Apr 2008 09:04:08 -0700
changeset 2989 b7eb3929096c
parent 2983 e3a416fe9dd5
parent 2965 4b28e9740e3b
child 3124 473e59b5e141
child 3150 7350a68e5856
permissions -rw-r--r--
merge with HEAD
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"
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 555
diff changeset
    27
#include "ns3/net-device.h"
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    28
#include "ns3/uinteger.h"
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    29
#include "ns3/trace-source-accessor.h"
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    30
#include "ns3/object-vector.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
733
fb1882e7d785 rename ipv4.h to ipv4-l3-protocol.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 729
diff changeset
    32
#include "ipv4-l3-protocol.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
#include "ipv4-l4-protocol.h"
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
#include "ipv4-header.h"
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
#include "ipv4-interface.h"
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    36
#include "ipv4-loopback-interface.h"
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    37
#include "arp-ipv4-interface.h"
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
#include "ipv4-l4-demux.h"
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    40
NS_LOG_COMPONENT_DEFINE ("Ipv4L3Protocol");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
namespace ns3 {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
    44
const uint16_t Ipv4L3Protocol::PROT_NUMBER = 0x0800;
293
007bc9e735f3 remove Ipv4L3Protocol class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 287
diff changeset
    45
2249
3a1da26d61dc replace ComponentManager::Create and ClassId with InterfaceId::CreateObjest and InterfaceId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2238
diff changeset
    46
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
    47
2250
18f432098389 InterfaceId -> TypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
    48
TypeId 
2251
04963d8cca51 iid (void) -> GetTypeId (void)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
    49
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
    50
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    51
  static TypeId tid = TypeId ("ns3::Ipv4L3Protocol")
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    52
    .SetParent<Object> ()
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    53
    .AddConstructor<Ipv4L3Protocol> ()
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    54
    .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
    55
                   UintegerValue (64),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    56
                   MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    57
                   MakeUintegerChecker<uint8_t> ())
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    58
    .AddTraceSource ("Tx", "Send ipv4 packet to outgoing interface.",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    59
                   MakeTraceSourceAccessor (&Ipv4L3Protocol::m_txTrace))
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    60
    .AddTraceSource ("Rx", "Receive ipv4 packet from incoming interface.",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    61
                     MakeTraceSourceAccessor (&Ipv4L3Protocol::m_rxTrace))
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    62
    .AddTraceSource ("Drop", "Drop ipv4 packet",
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    63
                     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
    64
    .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
    65
                   ObjectVectorValue (),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    66
                   MakeObjectVectorAccessor (&Ipv4L3Protocol::m_interfaces),
2933
c7983cfa2cb3 add ObjectVector::GetItemTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    67
                   MakeObjectVectorChecker<Ipv4Interface> ())
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    68
    ;
2252
80595448707a iid -> tid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2251
diff changeset
    69
  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
    70
}
9abd038ee588 replace static const Interface iid; with static InterfaceId iid (void);
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    71
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    72
Ipv4L3Protocol::Ipv4L3Protocol()
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 983
diff changeset
    73
  : m_nInterfaces (0),
2498
e01570293b98 convert InternetNode to Attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    74
    m_identification (0)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    75
{
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
    76
  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
    77
  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
    78
  AddRoutingProtocol (m_staticRouting, 0);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    79
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    80
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
    81
Ipv4L3Protocol::~Ipv4L3Protocol ()
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    82
{
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
    83
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    84
}
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    85
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    86
void
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    87
Ipv4L3Protocol::SetNode (Ptr<Node> node)
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    88
{
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    89
  m_node = node;
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    90
  SetupLoopback ();
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    91
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
    92
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    93
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
    94
Ipv4L3Protocol::DoDispose (void)
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    95
{
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
    96
  NS_LOG_FUNCTION_NOARGS ();
496
894c8380d57b use Dispose more extensively
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 487
diff changeset
    97
  m_interfaces.clear ();
555
4d3b2a77bc92 convert Node * to Ptr<Node>
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 551
diff changeset
    98
  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
    99
  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
   100
  m_staticRouting = 0;
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 983
diff changeset
   101
  Object::DoDispose ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   104
void
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   105
Ipv4L3Protocol::SetupLoopback (void)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   106
{
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
   107
  NS_LOG_FUNCTION_NOARGS ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   108
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   109
  Ptr<Ipv4LoopbackInterface> interface = CreateObject<Ipv4LoopbackInterface> ();
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   110
  interface->SetNode (m_node);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   111
  interface->SetAddress (Ipv4Address::GetLoopback ());
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   112
  interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   113
  uint32_t index = AddIpv4Interface (interface);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   114
  AddHostRouteTo (Ipv4Address::GetLoopback (), index);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   115
  interface->SetUp ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   116
}
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   117
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   119
Ipv4L3Protocol::SetDefaultTtl (uint8_t ttl)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
{
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
   121
  NS_LOG_FUNCTION_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
  m_defaultTtl = ttl;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
    
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   127
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
   128
                      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
   129
                      uint32_t interface)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
{
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
   131
  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
   132
  m_staticRouting->AddHostRouteTo (dest, nextHop, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   134
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   136
Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
				uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
{
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
   139
  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
   140
  m_staticRouting->AddHostRouteTo (dest, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   142
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   144
Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
				   Ipv4Mask networkMask, 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
				   Ipv4Address nextHop, 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
				   uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
{
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
   149
  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
   150
  m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   152
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   154
Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
				   Ipv4Mask networkMask, 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
				   uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
{
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
   158
  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
   159
  m_staticRouting->AddNetworkRouteTo (network, networkMask, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
}
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   161
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   163
Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop, 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
				 uint32_t interface)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
{
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
   166
  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
   167
  m_staticRouting->SetDefaultRoute (nextHop, interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
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
   170
void
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   171
Ipv4L3Protocol::Lookup (
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   172
  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
   173
  Ptr<Packet> packet,
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   174
  Ipv4RoutingProtocol::RouteReplyCallback routeReply)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
{
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
   176
  NS_LOG_FUNCTION (this << &ipHeader << packet << &routeReply);
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   177
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   178
  Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply);
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   179
}
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
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
   181
void
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   182
Ipv4L3Protocol::Lookup (
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   183
  uint32_t ifIndex,
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   184
  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
   185
  Ptr<Packet> packet,
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   186
  Ipv4RoutingProtocol::RouteReplyCallback routeReply)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
{
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
   188
  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
   189
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   190
  for (Ipv4RoutingProtocolList::const_iterator rprotoIter = 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   191
         m_routingProtocols.begin ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   192
       rprotoIter != m_routingProtocols.end (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   193
       rprotoIter++)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   195
      NS_LOG_LOGIC ("Requesting route");
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   196
      if ((*rprotoIter).second->RequestRoute (ifIndex, ipHeader, packet, 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   197
                                              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
   198
        return;
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
    }
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   200
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
   201
  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
   202
      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
   203
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   204
      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
   205
//
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   206
// 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
   207
// 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
   208
// 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
   209
// 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
   210
// 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
   211
//
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   212
// 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
   213
// 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
   214
//
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   215
      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
   216
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   217
      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
   218
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   219
          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
   220
            "multicast packet");
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   221
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   222
          routeReply (true, *route, packet, ipHeader);
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   223
          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
   224
        }
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
   225
    }
1445
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   226
//
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   227
// No route found
3fba36666488 Don't flood multicasts if no route found
Craig Dowell <craigdo@ee.washington.edu>
parents: 1444
diff changeset
   228
//
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
   229
  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
   230
}
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
   231
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
   232
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
   233
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
   234
                                    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
   235
{
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
   236
  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
   237
  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
   238
    (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
   239
  m_routingProtocols.sort ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   243
Ipv4L3Protocol::GetNRoutes (void)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
{
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
   245
  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
   246
  return m_staticRouting->GetNRoutes ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
}
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
   248
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
Ipv4Route *
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   250
Ipv4L3Protocol::GetRoute (uint32_t index)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   251
{
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
   252
  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
   253
  return m_staticRouting->GetRoute (index);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
}
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
   255
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   257
Ipv4L3Protocol::RemoveRoute (uint32_t index)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
{
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
   259
  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
   260
  m_staticRouting->RemoveRoute (index);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   263
void 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   264
Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   265
                                   Ipv4Address group,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   266
                                   uint32_t inputInterface,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   267
                                   std::vector<uint32_t> outputInterfaces)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   268
{
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
   269
  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
   270
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   271
  m_staticRouting->AddMulticastRoute (origin, group, inputInterface,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   272
    outputInterfaces);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   273
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   274
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   275
void 
1444
7c81b4e2617d piles of doxygen, changes to SetDefaultMulticastRoute plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1443
diff changeset
   276
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
   277
{
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
   278
  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
   279
1444
7c81b4e2617d piles of doxygen, changes to SetDefaultMulticastRoute plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1443
diff changeset
   280
  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
   281
}
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   282
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   283
uint32_t 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   284
Ipv4L3Protocol::GetNMulticastRoutes (void) const
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   285
{
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
   286
  NS_LOG_FUNCTION_NOARGS ();
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   287
  return m_staticRouting->GetNMulticastRoutes ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   288
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   289
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   290
Ipv4MulticastRoute *
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   291
Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   292
{
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
   293
  NS_LOG_FUNCTION (this << index);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   294
  return m_staticRouting->GetMulticastRoute (index);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   295
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   296
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   297
void 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   298
Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   299
                                       Ipv4Address group,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   300
                                       uint32_t inputInterface)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   301
{
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
   302
  NS_LOG_FUNCTION (this << origin << group << inputInterface);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   303
  m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   304
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   305
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   306
void 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   307
Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   308
{
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
   309
  NS_LOG_FUNCTION (this << index);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   310
  m_staticRouting->RemoveMulticastRoute (index);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   311
}
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   314
Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   315
{
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
   316
  NS_LOG_FUNCTION (this << &device);
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   317
  Ptr<ArpIpv4Interface> interface = CreateObject<ArpIpv4Interface> ();
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   318
  interface->SetNode (m_node);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2537
diff changeset
   319
  interface->SetDevice (device);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   320
  return AddIpv4Interface (interface);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   321
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   322
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   323
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
   324
Ipv4L3Protocol::AddIpv4Interface (Ptr<Ipv4Interface>interface)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
{
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
   326
  NS_LOG_FUNCTION (this << interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   327
  uint32_t index = m_nInterfaces;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   328
  m_interfaces.push_back (interface);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
  m_nInterfaces++;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   330
  return index;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   332
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
   333
Ptr<Ipv4Interface>
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   334
Ipv4L3Protocol::GetInterface (uint32_t index) const
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
{
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
   336
  NS_LOG_FUNCTION (this << index);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
  uint32_t tmp = 0;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   338
  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
   339
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   340
      if (index == tmp) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   341
	{
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   342
	  return *i;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   343
	}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   344
      tmp++;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   345
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   346
  return 0;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   347
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   348
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   349
uint32_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   350
Ipv4L3Protocol::GetNInterfaces (void) const
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   351
{
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
   352
  NS_LOG_FUNCTION_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   353
  return m_nInterfaces;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   354
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   355
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
   356
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
   357
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
   358
{
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
   359
  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
   360
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
   361
  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
   362
  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
   363
       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
   364
       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
   365
    {
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   366
      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
   367
        {
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   368
          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
   369
        }
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
   370
    }
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
   371
2326
eec07777d1a2 Fix broadcast packet reception for locally bound sockets (bug #136)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2325
diff changeset
   372
  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
   373
                  "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
   374
  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
   375
}
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
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
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
   378
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
   379
{
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
   380
  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
   381
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
  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
   383
  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
   384
       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
   385
       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
   386
    {
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
      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
   388
        {
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
          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
   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
    }
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
   392
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
   393
  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
   394
    "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
   395
  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
   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
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   398
int32_t 
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   399
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
   400
{
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
   401
  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
   402
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   403
  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
   404
  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
   405
       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
   406
       i++, ifIndex++)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   407
    {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   408
      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
   409
        {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   410
          return ifIndex;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   411
        }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   412
    }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   413
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   414
  return -1;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   415
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents: 2602
diff changeset
   416
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
   417
Ptr<Ipv4Interface>
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   418
Ipv4L3Protocol::FindInterfaceForDevice (Ptr<const NetDevice> device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   419
{
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
   420
  NS_LOG_FUNCTION (this << &device);
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   421
  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
   422
    {
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 555
diff changeset
   423
      if ((*i)->GetDevice () == device)
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   424
        {
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   425
          return *i;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   426
        }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   427
    }
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   428
  return 0;
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
   429
}  
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   430
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   431
void 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   432
Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   433
{
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
   434
  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
   435
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   436
  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
   437
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   438
  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
   439
  Ptr<Ipv4Interface> ipv4Interface;
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   440
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   441
       i != m_interfaces.end (); 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   442
       i++)
457
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   443
    {
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
   444
      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
   445
      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
   446
        {
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   447
          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
   448
          break;
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   449
        }
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   450
      index++;
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   451
    }
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   452
  Ipv4Header ipHeader;
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   453
  packet->RemoveHeader (ipHeader);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   454
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   455
  if (!ipHeader.IsChecksumOk ()) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   456
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   457
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   458
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   459
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   460
  if (Forwarding (index, packet, ipHeader, device)) 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   461
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   462
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   463
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
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
  ForwardUp (packet, ipHeader, ipv4Interface);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   466
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   467
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
   468
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   469
void 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   470
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
   471
            Ipv4Address source, 
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   472
            Ipv4Address destination,
a468fac09924 add context information to tx and rx trace callbacks
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   473
            uint8_t protocol)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   474
{
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
   475
  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
   476
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   477
  Ipv4Header ipHeader;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   478
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   479
  ipHeader.SetSource (source);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   480
  ipHeader.SetDestination (destination);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   481
  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
   482
  ipHeader.SetPayloadSize (packet->GetSize ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   483
  ipHeader.SetTtl (m_defaultTtl);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
  ipHeader.SetMayFragment ();
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   485
  ipHeader.SetIdentification (m_identification);
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   486
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   487
  m_identification ++;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   488
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
   489
  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
   490
    {
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
   491
      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
   492
      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
   493
           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
   494
        {
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
   495
          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
   496
          Ptr<Packet> packetCopy = packet->Copy ();
1308
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   497
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   498
          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
   499
          packetCopy->AddHeader (ipHeader);
1308
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   500
          m_txTrace (packetCopy, ifaceIndex);
5c5937a4150d backout 9856d1175cbb:642d6798feaa:27dd3e15308a
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1303
diff changeset
   501
          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
   502
        }
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
   503
    }
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
   504
  else
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   505
    {
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
   506
      // 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
   507
      // 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
   508
      // 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
   509
      // 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
   510
      // 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
   511
      // 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
   512
      // 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
   513
      // 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
   514
      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
   515
              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
   516
    }
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
   517
}
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
   518
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
   519
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
   520
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
   521
                             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
   522
                             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
   523
                             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
   524
{
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
   525
  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
   526
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
   527
  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
   528
  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
   529
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   530
      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
   531
      m_dropTrace (packet);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   532
      return;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   533
    }
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   534
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   535
  NS_LOG_LOGIC ("Send via interface " << route.GetInterface ());
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   536
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
   537
  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
   538
  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
   539
  m_txTrace (packet, route.GetInterface ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   540
  if (route.IsGateway ()) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   541
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   542
      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
   543
      outInterface->Send (packet, route.GetGateway ());
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   544
    } 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   545
  else 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   546
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   547
      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
   548
      outInterface->Send (packet, ipHeader.GetDestination ());
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   549
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   550
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   551
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   552
bool
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   553
Ipv4L3Protocol::Forwarding (
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   554
  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
   555
  Ptr<Packet> packet, 
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   556
  Ipv4Header &ipHeader, 
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   557
  Ptr<NetDevice> device)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   558
{
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
   559
  NS_LOG_FUNCTION (ifIndex << packet << &ipHeader<< device);
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   560
  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
   561
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   562
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   563
       i != m_interfaces.end (); i++) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   564
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   565
      if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ())) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   566
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   567
          NS_LOG_LOGIC ("For me (destination match)");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   568
          return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   569
        }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   570
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   571
  
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   572
  for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   573
       i != m_interfaces.end (); i++) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   574
    {
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
   575
      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
   576
      if (interface->GetDevice () == device)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   577
	{
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   578
	  if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ())) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   579
	    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   580
              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
   581
	      return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   582
	    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   583
	  break;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   584
	}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   585
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   586
      
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 (ipHeader.GetDestination ().IsBroadcast ()) 
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   588
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   589
      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
   590
      return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   591
    }
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   592
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   593
  if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ())) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   594
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   595
      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
   596
      return false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   597
    }
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
   598
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   599
  if (ipHeader.GetTtl () == 1) 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   600
    {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   601
      // Should send ttl expired here
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   602
      // XXX
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   603
      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
   604
      m_dropTrace (packet);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   605
      return true;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   606
    }
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   607
  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
   608
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   609
//  
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   610
// 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
   611
// 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
   612
//        
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   613
  for (Ipv4MulticastGroupList::const_iterator i = m_multicastGroups.begin ();
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   614
       i != m_multicastGroups.end (); i++)
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   615
    {
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   616
      if ((*i).first.IsEqual (ipHeader.GetSource ()) &&
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   617
          (*i).second.IsEqual (ipHeader.GetDestination ()))
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   618
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   619
          NS_LOG_LOGIC ("For me (Joined multicast group)");
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   620
          // We forward with a packet copy, since forwarding may change
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   621
          // the packet, affecting our local delivery
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   622
          NS_LOG_LOGIC ("Forwarding (multicast).");
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   623
          Lookup (ifIndex, ipHeader, packet->Copy (),
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   624
          MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   625
          return false;
2796
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   626
        }   
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   627
    }     
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   628
  NS_LOG_LOGIC ("Not for me, forwarding.");
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   629
  Lookup (ifIndex, ipHeader, packet,
33fb53176f97 Fix multicast forwarding problem
Tom Henderson <tomh@tomh.org>
parents: 2711
diff changeset
   630
  MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   631
  
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   632
  return true;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   633
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   634
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   635
void
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1524
diff changeset
   636
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
   637
                           Ptr<Ipv4Interface> incomingInterface)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   638
{
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
   639
  NS_LOG_FUNCTION (this << p << &ip);
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   640
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2252
diff changeset
   641
  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
   642
  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
   643
  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
   644
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   645
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   646
void 
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   647
Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   648
{
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
   649
  NS_LOG_FUNCTION (this << origin << group);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   650
  m_multicastGroups.push_back(
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   651
    std::pair<Ipv4Address, Ipv4Address> (origin, group));
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   652
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   653
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   654
void
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   655
Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   656
{
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
   657
  NS_LOG_FUNCTION (this << origin << group);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   658
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   659
  for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   660
       i != m_multicastGroups.end (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   661
       i++)
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   662
    {
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   663
      if ((*i).first.IsEqual(origin) && (*i).second.IsEqual(group))
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   664
        {
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   665
          m_multicastGroups.erase (i);
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   666
          return;
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   667
        }
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   668
    }
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   669
}
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   670
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents: 1235
diff changeset
   671
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   672
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
   673
{
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
   674
  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
   675
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   676
  interface->SetAddress (address);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   677
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   678
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   679
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   680
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
   681
{
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
   682
  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
   683
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   684
  interface->SetNetworkMask (mask);
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   685
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   686
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   687
Ipv4Mask 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   688
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
   689
{
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
   690
  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
   691
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   692
  return interface->GetNetworkMask ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   693
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   694
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   695
Ipv4Address 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   696
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
   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 << 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
   699
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   700
  return interface->GetAddress ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   701
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   702
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
   703
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
   704
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
   705
{
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
   706
  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
   707
  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
   708
  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
   709
}
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
   710
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
   711
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
   712
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
   713
{
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
   714
  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
   715
  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
   716
  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
   717
}
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
   718
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   719
bool
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   720
Ipv4L3Protocol::GetIfIndexForDestination (
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   721
  Ipv4Address destination, uint32_t& ifIndex) const
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   722
{
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
   723
  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
   724
//
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   725
// 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
   726
// 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
   727
// 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
   728
//
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   729
  for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   730
       i != m_routingProtocols.end (); 
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   731
       i++)
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   732
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   733
      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
   734
      uint32_t ifIndexTmp;
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   735
1435
a70de165a25a set source IP address in udp-socket packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 1434
diff changeset
   736
      if ((*i).second->RequestIfIndex (destination, ifIndexTmp))
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   737
        {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   738
          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
   739
          ifIndex = ifIndexTmp;
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   740
          return true;
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   741
        }
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   742
    }
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
   743
//
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   744
// 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
   745
// 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
   746
// 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
   747
// 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
   748
// 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
   749
// 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
   750
// 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
   751
//
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
   752
  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
   753
    {
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   754
      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
   755
      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
   756
      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
   757
    }
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
   758
//
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
   759
// 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
   760
// 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
   761
// 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
   762
// 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
   763
//
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   764
// 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
   765
// 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
   766
// 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
   767
//
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1441
diff changeset
   768
// 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
   769
// 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
   770
// 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
   771
// 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
   772
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   773
  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
   774
  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
   775
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
   776
  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
   777
    {
a3e10db411b9 The message "Unable to determine outbound interface. No default route set"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   778
      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
   779
                    "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
   780
      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
   781
    }
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
   782
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
   783
  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
   784
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
   785
  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
   786
  return true;
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   787
}
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   788
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   789
uint16_t 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   790
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
   791
{
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
   792
  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
   793
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   794
  return interface->GetMtu ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   795
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   796
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   797
bool 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   798
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
   799
{
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
   800
  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
   801
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   802
  return interface->IsUp ();
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   803
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   804
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   805
void 
734
039fb338b6e9 Ipv4 -> Ipv4L3Protocol
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 733
diff changeset
   806
Ipv4L3Protocol::SetUp (uint32_t i)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   807
{
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
   808
  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
   809
  Ptr<Ipv4Interface> interface = GetInterface (i);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   810
  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
   811
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   812
  // 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
   813
  // 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
   814
  // Linux box)
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   815
  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
   816
      && (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
   817
    {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   818
      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
   819
                         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
   820
    }
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   821
}
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   822
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   823
void 
979
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   824
Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   825
{
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
   826
  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
   827
  Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   828
  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
   829
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   830
  // 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
   831
  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
   832
  while (modified)
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   833
    {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   834
      modified = false;
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   835
      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
   836
        {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   837
          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
   838
          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
   839
            {
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   840
              RemoveRoute (i);
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   841
              modified = true;
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   842
              break;
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   843
            }
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   844
        }
cb805f7a2e8d Add patch 49 (add/remove network route when bringing interface up/down)
Tom Henderson <tomh@tomh.org>
parents: 734
diff changeset
   845
    }
444
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   846
}
1647ca57f19d remove ipv4 interface from public API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
   847
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   848
}//namespace ns3