src/helper/ipv4-address-helper.cc
author Tom Henderson <tomh@tomh.org>
Sun, 12 Apr 2009 22:13:49 -0700
changeset 4375 db81fdcb06e7
parent 4372 d99061f1167c
child 4472 e20a31541404
permissions -rw-r--r--
Implementation cut over to use Ipv4InterfaceAddress
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2008 University of Washington
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 */
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/assert.h"
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "ns3/log.h"
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/ptr.h"
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/node.h"
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "ns3/net-device.h"
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include "ns3/ipv4.h"
2722
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
    25
#include "ns3/ipv4-address-generator.h"
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ipv4-address-helper.h"
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
NS_LOG_COMPONENT_DEFINE("Ipv4AddressHelper");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
namespace ns3 {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
Ipv4AddressHelper::Ipv4AddressHelper () 
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
    34
  NS_LOG_FUNCTION_NOARGS ();
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
// Set the default values to an illegal state.  Do this so the client is 
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
// forced to think at least briefly about what addresses get used and what
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
// is going on here.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  m_network = 0xffffffff;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
  m_mask = 0;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
  m_address = 0xffffffff;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
  m_base = 0xffffffff;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
  m_shift = 0xffffffff;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
  m_max = 0xffffffff;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
  void
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
Ipv4AddressHelper::SetBase (
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  const Ipv4Address network, 
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  const Ipv4Mask mask,
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  const Ipv4Address address)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
    55
  NS_LOG_FUNCTION_NOARGS ();
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
3179
1763f7ac8e80 bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    57
  m_network = network.Get ();
1763f7ac8e80 bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    58
  m_mask = mask.Get ();
1763f7ac8e80 bug 146: s/HostOrder//
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    59
  m_base = m_address = address.Get ();
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
// Some quick reasonableness testing.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  NS_ASSERT_MSG((m_network & ~m_mask) == 0,
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
    "Ipv4AddressHelper::SetBase(): Inconsistent network and mask");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
// Figure out how much to shift network numbers to get them aligned, and what
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
// the maximum allowed address is with respect to the current mask.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
  m_shift = NumAddressBits (m_mask);
2712
02f089bd33f0 typos in doxygen, default to 0.0.0.1, avoid broadcast address
Craig Dowell <craigdo@ee.washington.edu>
parents: 2711
diff changeset
    72
  m_max = (1 << m_shift) - 2;
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  NS_ASSERT_MSG(m_shift <= 32,
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
    "Ipv4AddressHelper::SetBase(): Unreasonable address length");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
// Shift the network down into the normalized position.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
  m_network >>= m_shift;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  NS_LOG_LOGIC ("m_network == " << m_network);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  NS_LOG_LOGIC ("m_mask == " << m_mask);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  NS_LOG_LOGIC ("m_address == " << m_address);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
  Ipv4Address
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
Ipv4AddressHelper::NewAddress (void)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
{
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
// The way this is expected to be used is that an address and network number
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
// are initialized, and then NewAddress() is called repeatedly to allocate and
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
// get new addresses on a given subnet.  The client will expect that the first
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
// address she gets back is the one she used to initialize the generator with.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
// This implies that this operation is a post-increment.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
  NS_ASSERT_MSG (m_address <= m_max,
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
    "Ipv4AddressHelper::NewAddress(): Address overflow");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  Ipv4Address addr ((m_network << m_shift) | m_address);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
  ++m_address;
2722
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   102
//
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   103
// The Ipv4AddressGenerator allows us to keep track of the addresses we have
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   104
// allocated and will assert if we accidentally generate a duplicate.  This
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   105
// avoids some really hard to debug problems.
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   106
//
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   107
  Ipv4AddressGenerator::AddAllocated (addr);
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  return addr;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  Ipv4Address
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
Ipv4AddressHelper::NewNetwork (void)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
   114
  NS_LOG_FUNCTION_NOARGS ();
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
  ++m_network;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
  m_address = m_base;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
  return Ipv4Address (m_network << m_shift);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
2748
f65f6e2629dc introduce Ipv4InterfaceContainer and make Ipv4AddressHelper::Allocate return it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2733
diff changeset
   120
Ipv4InterfaceContainer
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2748
diff changeset
   121
Ipv4AddressHelper::Assign (const NetDeviceContainer &c)
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
   123
  NS_LOG_FUNCTION_NOARGS ();
2748
f65f6e2629dc introduce Ipv4InterfaceContainer and make Ipv4AddressHelper::Allocate return it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2733
diff changeset
   124
  Ipv4InterfaceContainer retval;
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
  for (uint32_t i = 0; i < c.GetN (); ++i) {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
    Ptr<NetDevice> device = c.Get (i);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
    Ptr<Node> node = device->GetNode ();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
    NS_ASSERT_MSG (node, "Ipv4AddressHelper::Allocate(): Bad node");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
    Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
    NS_ASSERT_MSG (ipv4, "Ipv4AddressHelper::Allocate(): Bad ipv4");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 3862
diff changeset
   134
    int32_t interface = ipv4->FindInterfaceForDevice (device);
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 3862
diff changeset
   135
    if (interface == -1)
2729
da9f089742ed create an ipv4 interface if there is none.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2713
diff changeset
   136
      {
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 3862
diff changeset
   137
        interface = ipv4->AddInterface (device);
2729
da9f089742ed create an ipv4 interface if there is none.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2713
diff changeset
   138
      }
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 3862
diff changeset
   139
    NS_ASSERT_MSG (interface >= 0, "Ipv4AddressHelper::Allocate(): "
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
      "Interface index not found");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   142
    Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (NewAddress (), m_mask);
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
   143
    ipv4->AddAddress (interface, ipv4Addr);
4372
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 3862
diff changeset
   144
    ipv4->SetMetric (interface, 1);
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 3862
diff changeset
   145
    ipv4->SetUp (interface);
d99061f1167c Ipv4::ifIndex -> Ipv4::interface
Tom Henderson <tomh@tomh.org>
parents: 3862
diff changeset
   146
    retval.Add (ipv4, interface);
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
  }
2748
f65f6e2629dc introduce Ipv4InterfaceContainer and make Ipv4AddressHelper::Allocate return it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2733
diff changeset
   148
  return retval;
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
const uint32_t N_BITS = 32;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
  uint32_t
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
Ipv4AddressHelper::NumAddressBits (uint32_t maskbits) const
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
   156
  NS_LOG_FUNCTION_NOARGS ();
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
  for (uint32_t i = 0; i < N_BITS; ++i)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
    {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
      if (maskbits & 1)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
        {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
          NS_LOG_LOGIC ("NumAddressBits -> " << i);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
          return i;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
        }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
      maskbits >>= 1;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
    }
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
  NS_ASSERT_MSG(false, "Ipv4AddressHelper::NumAddressBits(): Bad Mask");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
  return 0;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
}; // namespace ns3
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
#ifdef RUN_SELF_TESTS
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
#include "ns3/test.h"
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
namespace ns3 {
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
class AddressHelperTest : public Test
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
{
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
public:
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
  AddressHelperTest ();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
  virtual bool RunTests (void);
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
};
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
static AddressHelperTest g_addressHelperTest;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
AddressHelperTest::AddressHelperTest ()
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
  : Test ("AddressHelper")
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
{
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
  bool
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
AddressHelperTest::RunTests (void)
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
{
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
  bool result = true;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  Ipv4Address network;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
  Ipv4Address address;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
// Make sure the network allocator part is working on some common network
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
// prefixes.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
  Ipv4AddressHelper h;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  h.SetBase ("1.0.0.0", "255.0.0.0");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
  network = h.NewNetwork();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("2.0.0.0"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  address = h.NewAddress();
2713
d0d5904c0fe2 fix unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2712
diff changeset
   210
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("2.0.0.1"));
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
  h.SetBase ("0.1.0.0", "255.255.0.0");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
  network = h.NewNetwork();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.2.0.0"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
  address = h.NewAddress();
2713
d0d5904c0fe2 fix unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2712
diff changeset
   216
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.2.0.1"));
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
  h.SetBase ("0.0.1.0", "255.255.255.0");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
  network = h.NewNetwork();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.2.0"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
  address = h.NewAddress();
2713
d0d5904c0fe2 fix unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 2712
diff changeset
   222
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.2.1"));
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
// Make sure the address allocator part is working.
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
//
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
  h.SetBase ("1.0.0.0", "255.0.0.0", "0.0.0.3");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.4"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
  h.SetBase ("0.1.0.0", "255.255.0.0", "0.0.0.3");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   237
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.4"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   238
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   239
  h.SetBase ("0.0.1.0", "255.255.255.0", "0.0.0.3");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   243
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.4"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
//
2722
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   246
// Make sure the reset to base behavior is working.  We're going to use some
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   247
// of the same addresses allocated above, so reset the Ipv4AddressGenerator
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   248
// to make it forget we did.
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
//
2722
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   250
  Ipv4AddressGenerator::Reset ();
f59635c9c679 address generator, address collision checker
Craig Dowell <craigdo@ee.washington.edu>
parents: 2713
diff changeset
   251
2711
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
  h.SetBase ("1.0.0.0", "255.0.0.0", "0.0.0.3");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("1.0.0.4"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
  network = h.NewNetwork();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("2.0.0.0"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("2.0.0.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
  h.SetBase ("0.1.0.0", "255.255.0.0", "0.0.0.3");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.1.0.4"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
  network = h.NewNetwork();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.2.0.0"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.2.0.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
  h.SetBase ("0.0.1.0", "255.255.255.0", "0.0.0.3");
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.1.4"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
  network = h.NewNetwork();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
  NS_TEST_ASSERT_EQUAL (network, Ipv4Address ("0.0.2.0"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   279
  address = h.NewAddress();
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
  NS_TEST_ASSERT_EQUAL (address, Ipv4Address ("0.0.2.3"));
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
  return true;
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
}
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
} // namespace ns3
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
83addb15f632 ip helper and find ip interface for device method on ipv4
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
#endif /* RUN_SELF_TEST */