src/internet/model/ipv4-interface.cc
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Fri, 11 Sep 2015 10:52:44 +0200
changeset 11666 e8634b0101f7
parent 10968 2d29fee2b7b8
child 11954 5916e41a6f07
permissions -rw-r--r--
Missing SetGroupName in two classes
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
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    33
namespace ns3 {
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    35
NS_LOG_COMPONENT_DEFINE ("Ipv4Interface");
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10410
diff changeset
    37
NS_OBJECT_ENSURE_REGISTERED (Ipv4Interface);
6393
f7e1f9dfa08d ensure objects are regsitered
Josh Pelkey <jpelkey@gatech.edu>
parents: 5681
diff changeset
    38
2936
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    39
TypeId 
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    40
Ipv4Interface::GetTypeId (void)
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    41
{
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    42
  static TypeId tid = TypeId ("ns3::Ipv4Interface")
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    43
    .SetParent<Object> ()
11666
e8634b0101f7 Missing SetGroupName in two classes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10968
diff changeset
    44
    .SetGroupName ("Internet")
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    45
    .AddAttribute ("ArpCache",
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    46
                   "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
    47
                   PointerValue (0),
5681
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
    48
                   MakePointerAccessor (&Ipv4Interface::SetArpCache, 
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
    49
                                        &Ipv4Interface::GetArpCache),
4614
8f115595c247 bug 610: Wrong PointerChecker in attribute of Ipv4Interface
Kirill V. Andreev <kirillano@yandex.ru>
parents: 4607
diff changeset
    50
                   MakePointerChecker<ArpCache> ())
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7150
diff changeset
    51
  ;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7150
diff changeset
    52
  ;
2936
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    53
  return tid;
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    54
}
d108e5f0bd3e define a TypeId for ns3::Ipv4Interface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    55
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    56
/** 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    57
 * 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
    58
 *  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
    59
 * 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
    60
 */
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2542
diff changeset
    61
Ipv4Interface::Ipv4Interface () 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    62
  : 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
    63
    m_forwarding (true),
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    64
    m_metric (1),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    65
    m_node (0), 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    66
    m_device (0),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    67
    m_cache (0)
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    68
{
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
    69
  NS_LOG_FUNCTION (this);
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    70
}
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
Ipv4Interface::~Ipv4Interface ()
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    73
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
    74
  NS_LOG_FUNCTION (this);
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
    75
}
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
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
    77
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
    78
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
    79
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
    80
  NS_LOG_FUNCTION (this);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    81
  m_node = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    82
  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
    83
  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
    84
}
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
    85
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    86
void 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    87
Ipv4Interface::SetNode (Ptr<Node> node)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    88
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
    89
  NS_LOG_FUNCTION (this << node);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    90
  m_node = node;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    91
  DoSetup ();
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
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    94
void 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    95
Ipv4Interface::SetDevice (Ptr<NetDevice> device)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    96
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
    97
  NS_LOG_FUNCTION (this << device);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    98
  m_device = device;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    99
  DoSetup ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   100
}
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
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   103
Ipv4Interface::DoSetup (void)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   104
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   105
  NS_LOG_FUNCTION (this);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   106
  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
   107
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   108
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   109
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   110
  if (!m_device->NeedsArp ())
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
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   113
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   114
  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
   115
  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
   116
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   117
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   118
Ptr<NetDevice>
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   119
Ipv4Interface::GetDevice (void) const
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   120
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   121
  NS_LOG_FUNCTION (this);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   122
  return m_device;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   123
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   124
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
   125
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
   126
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
   127
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   128
  NS_LOG_FUNCTION (this << 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
   129
  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
   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
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
   132
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
   133
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
   134
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   135
  NS_LOG_FUNCTION (this);
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
   136
  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
   137
}
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
   138
5681
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   139
void
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   140
Ipv4Interface::SetArpCache (Ptr<ArpCache> a)
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   141
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   142
  NS_LOG_FUNCTION (this << a);
5681
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   143
  m_cache = a;
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   144
}
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   145
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   146
Ptr<ArpCache>
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   147
Ipv4Interface::GetArpCache () const
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   148
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   149
  NS_LOG_FUNCTION (this);
5681
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   150
  return m_cache;
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   151
}
795c049199c5 Includes cleanup + layer 2 link failure detection (untested)
Pavel Boyko <boyko@iitp.ru>
parents: 5677
diff changeset
   152
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   153
/**
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   154
 * These are IP interface states and may be distinct from 
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   155
 * NetDevice states, such as found in real implementations
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 568
diff changeset
   156
 * (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
   157
 */
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
bool 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
Ipv4Interface::IsUp (void) const
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   161
  NS_LOG_FUNCTION (this);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
  return m_ifup;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
bool 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
Ipv4Interface::IsDown (void) const
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   168
  NS_LOG_FUNCTION (this);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
  return !m_ifup;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
void 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
Ipv4Interface::SetUp (void)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   175
  NS_LOG_FUNCTION (this);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
  m_ifup = true;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
void 
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
Ipv4Interface::SetDown (void)
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   182
  NS_LOG_FUNCTION (this);
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
  m_ifup = false;
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   186
bool 
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   187
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
   188
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   189
  NS_LOG_FUNCTION (this);
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   190
  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
   191
}
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   192
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   193
void 
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   194
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
   195
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   196
  NS_LOG_FUNCTION (this << val);
4607
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   197
  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
   198
}
0e15594f67f3 bug 63: allow enabling or disabling ip forwarding on a per-interface basis
Tom Henderson <tomh@tomh.org>
parents: 4572
diff changeset
   199
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   200
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   201
Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   203
  NS_LOG_FUNCTION (this << *p << dest);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   204
  if (!IsUp ())
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   205
    {
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
  // Check for a loopback device
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   209
  if (DynamicCast<LoopbackNetDevice> (m_device))
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   210
    {
9894
ac4e52a91d5d Doxygenate todo's
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9710
diff changeset
   211
      /// \todo additional checks needed here (such as whether multicast
ac4e52a91d5d Doxygenate todo's
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9710
diff changeset
   212
      /// goes to loopback)?
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   213
      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
   214
                      Ipv4L3Protocol::PROT_NUMBER);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   215
      return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   216
    } 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   217
  // 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
   218
  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
   219
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   220
      if (dest == (*i).GetLocal ())
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
          Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7150
diff changeset
   223
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
   224
          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
   225
                         m_device->GetBroadcast (),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   226
                         m_device->GetBroadcast (),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   227
                         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
   228
                         );
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   229
          return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   230
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   231
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   232
  if (m_device->NeedsArp ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   233
    {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   234
      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
   235
      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
   236
      Address hardwareDestination;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   237
      bool found = false;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   238
      if (dest.IsBroadcast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   239
        {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   240
          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
   241
          hardwareDestination = m_device->GetBroadcast ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   242
          found = true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   243
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   244
      else if (dest.IsMulticast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   245
        {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   246
          NS_LOG_LOGIC ("IsMulticast");
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   247
          NS_ASSERT_MSG (m_device->IsMulticast (),
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   248
                         "ArpIpv4Interface::SendTo (): Sending multicast packet over "
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   249
                         "non-multicast device");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   250
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   251
          hardwareDestination = m_device->GetMulticast (dest);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   252
          found = true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   253
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   254
      else
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
          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
   257
            {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   258
              if (dest.IsSubnetDirectedBroadcast ((*i).GetMask ()))
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   259
                {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   260
                  NS_LOG_LOGIC ("Subnetwork Broadcast");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   261
                  hardwareDestination = m_device->GetBroadcast ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   262
                  found = true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   263
                  break;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   264
                }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   265
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   266
          if (!found)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   267
            {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   268
              NS_LOG_LOGIC ("ARP Lookup");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   269
              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
   270
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   271
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   272
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   273
      if (found)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   274
        {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   275
          NS_LOG_LOGIC ("Address Resolved.  Send.");
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7150
diff changeset
   276
          m_device->Send (p, hardwareDestination,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7150
diff changeset
   277
                          Ipv4L3Protocol::PROT_NUMBER);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   278
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   279
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   280
  else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   281
    {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5619
diff changeset
   282
      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
   283
      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
   284
                      Ipv4L3Protocol::PROT_NUMBER);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   285
    }
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
}
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   288
uint32_t
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   289
Ipv4Interface::GetNAddresses (void) const
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   290
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   291
  NS_LOG_FUNCTION (this);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   292
  return m_ifaddrs.size ();
4373
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
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   295
bool
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   296
Ipv4Interface::AddAddress (Ipv4InterfaceAddress addr)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   297
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   298
  NS_LOG_FUNCTION (this << addr);
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   299
  m_ifaddrs.push_back (addr);
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   300
  return true;
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   301
}
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
Ipv4InterfaceAddress
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   304
Ipv4Interface::GetAddress (uint32_t index) const
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   305
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   306
  NS_LOG_FUNCTION (this << index);
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   307
  if (index < m_ifaddrs.size ())
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
      uint32_t tmp = 0;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   310
      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
   311
        {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   312
          if (tmp  == index)
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
              return *i;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   315
            }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   316
          ++tmp;
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
    }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   319
  NS_ASSERT (false);  // Assert if not found
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   320
  Ipv4InterfaceAddress addr;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   321
  return (addr);  // quiet compiler
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
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   324
Ipv4InterfaceAddress
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   325
Ipv4Interface::RemoveAddress (uint32_t index)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   326
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7386
diff changeset
   327
  NS_LOG_FUNCTION (this << index);
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   328
  if (index >= m_ifaddrs.size ())
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   329
    {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   330
      NS_ASSERT_MSG (false, "Bug in Ipv4Interface::RemoveAddress");
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   331
    }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   332
  Ipv4InterfaceAddressListI i = m_ifaddrs.begin ();
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   333
  uint32_t tmp = 0;
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   334
  while (i != m_ifaddrs.end ())
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   335
    {
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   336
      if (tmp  == index)
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   337
        {
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   338
          Ipv4InterfaceAddress addr = *i;
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   339
          m_ifaddrs.erase (i);
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   340
          return addr;
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   341
        }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7150
diff changeset
   342
      ++tmp;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7150
diff changeset
   343
      ++i;
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   344
    }
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   345
  NS_ASSERT_MSG (false, "Address " << index << " not found");
4563
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   346
  Ipv4InterfaceAddress addr;
55948d1baa64 fix for bug 588
Tom Henderson <tomh@tomh.org>
parents: 4472
diff changeset
   347
  return (addr);  // quiet compiler
4373
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   348
}
e493e80274bd implementation and plumbing of Ipv4InterfaceAddress class
Tom Henderson <tomh@tomh.org>
parents: 3260
diff changeset
   349
9915
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   350
Ipv4InterfaceAddress
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   351
Ipv4Interface::RemoveAddress(Ipv4Address address)
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   352
{
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   353
  NS_LOG_FUNCTION(this << address);
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   354
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   355
  if (address == address.GetLoopback())
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   356
    {
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   357
      NS_LOG_WARN ("Cannot remove loopback address.");
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   358
      return Ipv4InterfaceAddress();
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   359
    }
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   360
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   361
  for(Ipv4InterfaceAddressListI it = m_ifaddrs.begin(); it != m_ifaddrs.end(); it++)
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   362
    {
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   363
      if((*it).GetLocal() == address)
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   364
        {
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   365
          Ipv4InterfaceAddress ifAddr = *it;
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   366
          m_ifaddrs.erase(it);
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   367
          return ifAddr;
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   368
        }
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   369
    }
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   370
  return Ipv4InterfaceAddress();
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   371
}
d4c2228d3c30 Bug 760 - IP address removal can be painful
Alexander D'souza (moijes12@gmail.com)
parents: 9894
diff changeset
   372
7386
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7256
diff changeset
   373
} // namespace ns3
236
5673656dc2e7 a basic untested ipv4 implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374