src/internet-stack/ipv4-interface.cc
author Pavel Boyko <boyko@iitp.ru>
Tue, 18 Aug 2009 15:07:25 +0400
changeset 5681 795c049199c5
parent 5677 81bd758dd7f4
child 6393 f7e1f9dfa08d
permissions -rw-r--r--
Includes cleanup + layer 2 link failure detection (untested)
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) 2005,2006,2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
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 "ipv4-interface.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    22
#include "loopback-net-device.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 474
diff changeset
    23
#include "ns3/ipv4-address.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    24
#include "ipv4-l3-protocol.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    25
#include "arp-l3-protocol.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    26
#include "arp-cache.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 474
diff changeset
    27
#include "ns3/net-device.h"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    28
#include "ns3/log.h"
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
    29
#include "ns3/packet.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    30
#include "ns3/node.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    31
#include "ns3/pointer.h"
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    32
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1451
diff changeset
    33
NS_LOG_COMPONENT_DEFINE ("Ipv4Interface");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
namespace ns3 {
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
2936
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    37
TypeId 
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    38
Ipv4Interface::GetTypeId (void)
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    39
{
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    40
  static TypeId tid = TypeId ("ns3::Ipv4Interface")
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    41
    .SetParent<Object> ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    42
    .AddAttribute ("ArpCache",
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    43
                   "The arp cache for this ipv4 interface",
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    44
                   PointerValue (0),
5681
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
    45
                   MakePointerAccessor (&Ipv4Interface::SetArpCache, 
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
    46
                                        &Ipv4Interface::GetArpCache),
4614
8f115595c247 bug 610: Wrong PointerChecker in attribute of Ipv4Interface
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4607
diff changeset
    47
                   MakePointerChecker<ArpCache> ())
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    48
    ;
2936
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    49
    ;
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    50
  return tid;
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    51
}
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    52
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    53
/** 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    54
 * By default, Ipv4 interface are created in the "down" state
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    55
 *  with no IP addresses.  Before becoming useable, the user must 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    56
 * invoke SetUp on them once an Ipv4 address and mask have been set.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    57
 */
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    58
Ipv4Interface::Ipv4Interface () 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    59
  : m_ifup (false),
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
    60
    m_forwarding (true),
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    61
    m_metric (1),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    62
    m_node (0), 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    63
    m_device (0),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    64
    m_cache (0)
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    65
{
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
    66
  NS_LOG_FUNCTION (this);
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    67
}
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
Ipv4Interface::~Ipv4Interface ()
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    70
{
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
    71
  NS_LOG_FUNCTION_NOARGS ();
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    72
}
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
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
    74
void
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
    75
Ipv4Interface::DoDispose (void)
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
    76
{
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
    77
  NS_LOG_FUNCTION_NOARGS ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    78
  m_node = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    79
  m_device = 0;
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
    80
  Object::DoDispose ();
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
    81
}
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
    82
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    83
void 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    84
Ipv4Interface::SetNode (Ptr<Node> node)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    85
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    86
  m_node = node;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    87
  DoSetup ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    88
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    89
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    90
void 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    91
Ipv4Interface::SetDevice (Ptr<NetDevice> device)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    92
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    93
  m_device = device;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    94
  DoSetup ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    95
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    96
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    97
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    98
Ipv4Interface::DoSetup (void)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    99
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   100
  if (m_node == 0 || m_device == 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   101
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   102
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   103
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   104
  if (!m_device->NeedsArp ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   105
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   106
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   107
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   108
  Ptr<ArpL3Protocol> arp = m_node->GetObject<ArpL3Protocol> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   109
  m_cache = arp->CreateCache (m_device, this);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   110
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   111
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   112
Ptr<NetDevice>
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   113
Ipv4Interface::GetDevice (void) const
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   114
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   115
  return m_device;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   116
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   117
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: 1504
diff changeset
   118
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: 1504
diff changeset
   119
Ipv4Interface::SetMetric (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: 1504
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 (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: 1504
diff changeset
   122
  m_metric = 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: 1504
diff changeset
   123
}
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: 1504
diff changeset
   124
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: 1504
diff changeset
   125
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: 1504
diff changeset
   126
Ipv4Interface::GetMetric (void) 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: 1504
diff changeset
   127
{
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
   128
  NS_LOG_FUNCTION_NOARGS ();
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: 1504
diff changeset
   129
  return m_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: 1504
diff changeset
   130
}
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: 1504
diff changeset
   131
5681
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   132
void
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   133
Ipv4Interface::SetArpCache (Ptr<ArpCache> a)
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   134
{
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   135
  m_cache = a;
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   136
}
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   137
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   138
Ptr<ArpCache>
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   139
Ipv4Interface::GetArpCache () const
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   140
{
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   141
  return m_cache;
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   142
}
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   143
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   144
/**
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   145
 * These are IP interface states and may be distinct from 
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   146
 * NetDevice states, such as found in real implementations
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   147
 * (where the device may be down but IP interface state is still up).
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   148
 */
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
bool 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
Ipv4Interface::IsUp (void) const
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2977
diff changeset
   152
  NS_LOG_FUNCTION_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
  return m_ifup;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
bool 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
Ipv4Interface::IsDown (void) const
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
{
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
   159
  NS_LOG_FUNCTION_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
  return !m_ifup;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
void 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
Ipv4Interface::SetUp (void)
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_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
  m_ifup = true;
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
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
void 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
Ipv4Interface::SetDown (void)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
{
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
   173
  NS_LOG_FUNCTION_NOARGS ();
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
  m_ifup = false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   177
bool 
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   178
Ipv4Interface::IsForwarding (void) const
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   179
{
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   180
  NS_LOG_FUNCTION_NOARGS ();
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   181
  return m_forwarding;
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   182
}
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   183
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   184
void 
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   185
Ipv4Interface::SetForwarding (bool val)
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   186
{
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   187
  NS_LOG_FUNCTION_NOARGS ();
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   188
  m_forwarding = val;
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   189
}
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   190
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   191
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   192
Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
{
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   194
  NS_LOG_FUNCTION (dest << *p);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   195
  if (!IsUp()) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   196
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   197
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   198
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   199
  // Check for a loopback device
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   200
  if (DynamicCast<LoopbackNetDevice> (m_device))
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   201
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   202
      // XXX additional checks needed here (such as whether multicast
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   203
      // goes to loopback)?
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   204
      m_device->Send (p, m_device->GetBroadcast (), 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   205
                      Ipv4L3Protocol::PROT_NUMBER);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   206
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   207
    } 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   208
  // is this packet aimed at a local interface ?
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   209
  for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i != m_ifaddrs.end (); ++i)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   210
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   211
      if (dest == (*i).GetLocal ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   212
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   213
          Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   214
        
4675
7defe7a99e9c fix bug preventing the sending of packets to a local IP address (bug 632)
Tom Henderson <tomh@tomh.org>
parents: 4653
diff changeset
   215
          ipv4->Receive (m_device, p, Ipv4L3Protocol::PROT_NUMBER, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   216
                         m_device->GetBroadcast (),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   217
                         m_device->GetBroadcast (),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   218
                         NetDevice::PACKET_HOST // note: linux uses PACKET_LOOPBACK here
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   219
                         );
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   220
          return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   221
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   222
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   223
  if (m_device->NeedsArp ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   224
    {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   225
      NS_LOG_LOGIC ("Needs ARP" << " " << dest);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   226
      Ptr<ArpL3Protocol> arp = m_node->GetObject<ArpL3Protocol> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   227
      Address hardwareDestination;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   228
      bool found = false;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   229
      if (dest.IsBroadcast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   230
        {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   231
          NS_LOG_LOGIC ("All-network Broadcast");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   232
          hardwareDestination = m_device->GetBroadcast ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   233
          found = true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   234
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   235
      else if (dest.IsMulticast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   236
        {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   237
          NS_LOG_LOGIC ("IsMulticast");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   238
          NS_ASSERT_MSG(m_device->IsMulticast (),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   239
            "ArpIpv4Interface::SendTo (): Sending multicast packet over "
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   240
            "non-multicast device");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   241
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   242
          hardwareDestination = m_device->GetMulticast(dest);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   243
          found = true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   244
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   245
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   246
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   247
          for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i != m_ifaddrs.end (); ++i)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   248
            {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   249
              if (dest.IsSubnetDirectedBroadcast ((*i).GetMask ()))
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   250
                {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   251
                  NS_LOG_LOGIC ("Subnetwork Broadcast");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   252
                  hardwareDestination = m_device->GetBroadcast ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   253
                  found = true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   254
                  break;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   255
                }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   256
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   257
          if (!found)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   258
            {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   259
              NS_LOG_LOGIC ("ARP Lookup");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   260
              found = arp->Lookup (p, dest, m_device, m_cache, &hardwareDestination);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   261
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   262
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   263
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   264
      if (found)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   265
        {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   266
          NS_LOG_LOGIC ("Address Resolved.  Send.");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   267
          m_device ->Send (p, hardwareDestination, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   268
                              Ipv4L3Protocol::PROT_NUMBER);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   269
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   270
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   271
  else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   272
    {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   273
      NS_LOG_LOGIC ("Doesn't need ARP");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   274
      m_device->Send (p, m_device->GetBroadcast (), 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   275
                      Ipv4L3Protocol::PROT_NUMBER);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   276
    }
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   279
uint32_t
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   280
Ipv4Interface::GetNAddresses (void) const
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   281
{
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   282
  NS_LOG_FUNCTION_NOARGS ();
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   283
  return m_ifaddrs.size();
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   284
}
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   285
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   286
bool
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   287
Ipv4Interface::AddAddress (Ipv4InterfaceAddress addr)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   288
{
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   289
  NS_LOG_FUNCTION_NOARGS ();
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   290
  m_ifaddrs.push_back (addr);
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   291
  return true;
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   292
}
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   293
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   294
Ipv4InterfaceAddress
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   295
Ipv4Interface::GetAddress (uint32_t index) const
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   296
{
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   297
  NS_LOG_FUNCTION_NOARGS ();
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   298
  if (index < m_ifaddrs.size ())
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   299
    {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   300
      uint32_t tmp = 0;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   301
      for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i!= m_ifaddrs.end (); i++)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   302
        {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   303
          if (tmp  == index)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   304
            {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   305
              return *i;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   306
            }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   307
          ++tmp;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   308
        }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   309
    }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   310
  NS_ASSERT (false);  // Assert if not found
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   311
  Ipv4InterfaceAddress addr;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   312
  return (addr);  // quiet compiler
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   313
}
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   314
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   315
Ipv4InterfaceAddress
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   316
Ipv4Interface::RemoveAddress (uint32_t index)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   317
{
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   318
  NS_LOG_FUNCTION_NOARGS ();
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   319
  if (index >= m_ifaddrs.size ())
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   320
    {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   321
      NS_ASSERT_MSG (false, "Bug in Ipv4Interface::RemoveAddress");
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   322
    }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   323
  Ipv4InterfaceAddressListI i = m_ifaddrs.begin ();
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   324
  uint32_t tmp = 0;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   325
  while (i != m_ifaddrs.end ())
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   326
    {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   327
      if (tmp  == index)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   328
        {
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   329
          Ipv4InterfaceAddress addr = *i;
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   330
          m_ifaddrs.erase (i);
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   331
          return addr;
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   332
        }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   333
       ++tmp;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   334
    }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   335
  NS_ASSERT_MSG (false, "Address " << index << " not found");
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   336
  Ipv4InterfaceAddress addr;
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   337
  return (addr);  // quiet compiler
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   338
}
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   339
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   340
}; // namespace ns3
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   341