tutorial/testipv4.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 17 Mar 2008 05:22:29 +0100
changeset 2637 ac94e4889027
parent 1838 25d76cec436b
child 2810 92e2b4ffae4a
permissions -rw-r--r--
move attribute code to ObjectBase.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1835
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include "ns3/log.h"
1838
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    18
#include "ipv4-address-generator.h"
1835
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
NS_LOG_COMPONENT_DEFINE ("TestIpv4");
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
using namespace ns3;
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
int 
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
main (int argc, char *argv[])
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
{
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
  LogComponentEnable ("TestIpv4", LOG_LEVEL_ALL);
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
  NS_LOG_INFO ("Test Ipv4");
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
  Ipv4Mask mask1 ("255.0.0.0");
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
  for (uint32_t i = 0; i < 10; ++i)
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
    {
1838
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    35
      Ipv4Address network = Ipv4AddressGenerator::AllocateNetwork (mask1);
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    36
      Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask1, 
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    37
        network);
1835
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
      NS_LOG_INFO ("address = " << address);
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
    }
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  Ipv4Mask mask2 ("255.255.0.0");
1838
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    42
  Ipv4AddressGenerator::SeedNetwork (mask2, "192.168.0.0");
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    43
  Ipv4AddressGenerator::SeedAddress (mask2, "0.0.0.3");
1835
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
1838
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    45
  Ipv4Address network1 = Ipv4AddressGenerator::AllocateNetwork (mask2);
1835
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
  for (uint32_t i = 0; i < 10; ++i)
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
    {
1838
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    48
      Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask2, 
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    49
        network1);
1835
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
      NS_LOG_INFO ("address = " << address);
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
    }
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  Ipv4Mask mask3 ("255.255.255.0");
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  for (uint32_t i = 0; i < 10; ++i)
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
    {
1838
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    57
      Ipv4Address network = Ipv4AddressGenerator::AllocateNetwork (mask3);
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    58
      Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask3, 
25d76cec436b more descriptive name
Craig Dowell <craigdo@ee.washington.edu>
parents: 1837
diff changeset
    59
        network);
1835
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
      NS_LOG_INFO ("address = " << address);
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
    }
ccd0fc4d9bf8 prototype address and network allocation
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
}