tutorial/tutorial-star.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 07 Apr 2008 10:41:21 -0700
changeset 2888 872dc8466352
parent 2887 9a637e6daee0
child 2965 4b28e9740e3b
child 2996 a83b94e277d4
permissions -rw-r--r--
Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    17
#include <fstream>
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    19
#include "ns3/core-module.h"
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    20
#include "ns3/node-module.h"
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    21
#include "ns3/helper-module.h"
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    22
#include "ns3/simulator-module.h"
1848
5dfaf1619279 move in topo
Craig Dowell <craigdo@ee.washington.edu>
parents: 1843
diff changeset
    23
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    24
NS_LOG_COMPONENT_DEFINE ("StarRoutingSimulation");
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
using namespace ns3;
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
// Network topology
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
//
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
//                  n3    n2
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
//                   |   /
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
//                    | /
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
//              n4 --- n0 --- n1
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
//                    /  |
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
//                   /    |
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
//                  n5    n6
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
int 
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
main (int argc, char *argv[])
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
{
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    41
  LogComponentEnable ("StarRoutingSimulation", LOG_LEVEL_INFO);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    43
  NS_LOG_INFO ("Star Topology with Routing Simulation");
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    45
  NodeContainer n;
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    46
  n.Create (7);
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    47
  NodeContainer n01 = NodeContainer (n.Get (0), n.Get (1));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    48
  NodeContainer n02 = NodeContainer (n.Get (0), n.Get (2));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    49
  NodeContainer n03 = NodeContainer (n.Get (0), n.Get (3));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    50
  NodeContainer n04 = NodeContainer (n.Get (0), n.Get (4));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    51
  NodeContainer n05 = NodeContainer (n.Get (0), n.Get (5));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    52
  NodeContainer n06 = NodeContainer (n.Get (0), n.Get (6));
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    54
  InternetStackHelper internet;
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    55
  internet.Install (n);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    57
  PointToPointHelper p2p;
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    58
  p2p.SetChannelParameter ("BitRate", DataRate (38400));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    59
  p2p.SetChannelParameter ("Delay", MilliSeconds (20));
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    61
  NetDeviceContainer d01 = p2p.Install (n01);
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    62
  NetDeviceContainer d02 = p2p.Install (n02);
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    63
  NetDeviceContainer d03 = p2p.Install (n03);
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    64
  NetDeviceContainer d04 = p2p.Install (n04);
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    65
  NetDeviceContainer d05 = p2p.Install (n05);
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    66
  NetDeviceContainer d06 = p2p.Install (n06);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    68
  Ipv4AddressHelper ipv4;
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    69
  ipv4.SetBase ("10.1.1.0", "255.255.255.252");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    70
  Ipv4InterfaceContainer i01 = ipv4.Assign (d01);
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    71
  ipv4.SetBase ("10.1.2.0", "255.255.255.252");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    72
  Ipv4InterfaceContainer i02 = ipv4.Assign (d02);
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    73
  ipv4.SetBase ("10.1.3.0", "255.255.255.252");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    74
  Ipv4InterfaceContainer i03 = ipv4.Assign (d03);
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    75
  ipv4.SetBase ("10.1.4.0", "255.255.255.252");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    76
  Ipv4InterfaceContainer i04 = ipv4.Assign (d04);
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    77
  ipv4.SetBase ("10.1.5.0", "255.255.255.252");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    78
  Ipv4InterfaceContainer i05 = ipv4.Assign (d05);
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    79
  ipv4.SetBase ("10.1.6.0", "255.255.255.252");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    80
  Ipv4InterfaceContainer i06 = ipv4.Assign (d06);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  uint16_t port = 7;
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    84
  UdpEchoServerHelper server;
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    85
  server.SetPort (port);
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    86
  ApplicationContainer apps = server.Install (n.Get (1));
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    87
  apps.Start (Seconds (1.0));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    88
  apps.Stop (Seconds (10.0));
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    90
  UdpEchoClientHelper client;
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    91
  client.SetRemote (i01.GetAddress (1), port);
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    92
  client.SetAppAttribute ("MaxPackets", Uinteger (1));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    93
  client.SetAppAttribute ("Interval", Seconds (1.0));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    94
  client.SetAppAttribute ("PacketSize", Uinteger (1024));
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2817
diff changeset
    95
  apps = client.Install (n.Get (0));
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    96
  apps.Start (Seconds (2.0));
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    97
  apps.Stop (Seconds (10.0));
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
2817
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    99
  std::ofstream ascii;
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
   100
  ascii.open ("tutorial.tr");
edb3d28c7f9a port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
   101
  PointToPointHelper::EnableAscii (ascii);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  Simulator::Run ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  Simulator::Destroy ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
}