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