examples/tcp-star-server.cc
author Florian Westphal <fw@strlen.de>
Wed, 03 Sep 2008 23:24:59 +0200
changeset 3595 693faf7f4e9b
parent 3381 3cdd9d60f7c7
child 4218 debf1a8a96d3
permissions -rw-r--r--
nsc: Fix build problem if gtk config store is disabled gtk config store pulled in libdl.so for us, so things fail to link of the config store isn't enabled. This makes nsc pull in libdl itself when its enabled.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3366
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     2
/*
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     6
 *
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    11
 *
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    15
 *
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    16
 */
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    17
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    18
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    19
// Default Network topology, 9 nodes in a star
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    20
/*
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    21
          n2 n3 n4
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    22
           \ | /
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    23
            \|/
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    24
       n1---n0---n5
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    25
            /|\
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    26
           / | \
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    27
          n8 n7 n6
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    28
*/
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    29
// - CBR Traffic goes from the star "arms" to the "hub"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    30
// - Tracing of queues and packet receptions to file
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    31
//   "tcp-star-server.tr"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    32
// - pcap traces also generated in the following files
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    33
//   "tcp-star-server-$n-$i.pcap" where n and i represent node and interface
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    34
//   numbers respectively
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    35
// Usage examples for things you might want to tweak:
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    36
//       ./waf --run="tcp-star-server"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    37
//       ./waf --run="tcp-star-server --nNodes=25"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    38
//       ./waf --run="tcp-star-server --ns3::OnOffApplication::DataRate=10000"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    39
//       ./waf --run="tcp-star-server --ns3::OnOffApplication::PacketSize=500"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    40
// See the ns-3 tutorial for more info on the command line: 
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    41
// http://www.nsnam.org/tutorials.html
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    42
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    43
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    44
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    45
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    46
#include <iostream>
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    47
#include <fstream>
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    48
#include <string>
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    49
#include <cassert>
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    50
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    51
#include "ns3/core-module.h"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    52
#include "ns3/simulator-module.h"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    53
#include "ns3/node-module.h"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    54
#include "ns3/helper-module.h"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    55
#include "ns3/global-route-manager.h"
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    56
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    57
using namespace ns3;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    58
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    59
NS_LOG_COMPONENT_DEFINE ("TcpServer");
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    60
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    61
int 
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    62
main (int argc, char *argv[])
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    63
{
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    64
  // Users may find it convenient to turn on explicit debugging
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    65
  // for selected modules; the below lines suggest how to do this
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    66
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    67
  //LogComponentEnable ("TcpServer", LOG_LEVEL_INFO);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    68
  //LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_ALL);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    69
  //LogComponentEnable ("TcpSocketImpl", LOG_LEVEL_ALL);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    70
  //LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    71
  //
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    72
  // Make the random number generators generate reproducible results.
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    73
  //
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    74
  RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    75
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    76
  // Set up some default values for the simulation.
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    77
  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (250));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    78
  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("5kb/s"));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    79
  uint32_t N = 9; //number of nodes in the star
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    80
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    81
  // Allow the user to override any of the defaults and the above
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    82
  // Config::SetDefault()s at run-time, via command-line arguments
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    83
  CommandLine cmd;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    84
  cmd.AddValue("nNodes", "Number of nodes to place in the star", N);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    85
  cmd.Parse (argc, argv);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    86
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    87
  // Here, we will create N nodes in a star.
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    88
  NS_LOG_INFO ("Create nodes.");
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    89
  NodeContainer serverNode;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    90
  NodeContainer clientNodes;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    91
  serverNode.Create(1);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    92
  clientNodes.Create(N-1);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    93
  NodeContainer allNodes = NodeContainer(serverNode, clientNodes);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    94
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    95
  // Install network stacks on the nodes
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    96
  InternetStackHelper internet;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    97
  internet.Install (allNodes);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    98
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    99
  //Collect an adjacency list of nodes for the p2p topology
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   100
  std::vector<NodeContainer> nodeAdjacencyList(N-1);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   101
  for(uint32_t i=0; i<nodeAdjacencyList.size(); ++i)
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   102
  {
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   103
    nodeAdjacencyList[i] = NodeContainer (serverNode, clientNodes.Get (i));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   104
  }
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   105
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   106
  // We create the channels first without any IP addressing information
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   107
  NS_LOG_INFO ("Create channels.");
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   108
  PointToPointHelper p2p;
3381
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3367
diff changeset
   109
  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3367
diff changeset
   110
  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
3366
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   111
  std::vector<NetDeviceContainer> deviceAdjacencyList(N-1);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   112
  for(uint32_t i=0; i<deviceAdjacencyList.size(); ++i)
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   113
  {
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   114
    deviceAdjacencyList[i] = p2p.Install (nodeAdjacencyList[i]);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   115
  }
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   116
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   117
  // Later, we add IP addresses.  
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   118
  NS_LOG_INFO ("Assign IP Addresses.");
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   119
  Ipv4AddressHelper ipv4;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   120
  std::vector<Ipv4InterfaceContainer> interfaceAdjacencyList(N-1);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   121
  for(uint32_t i=0; i<interfaceAdjacencyList.size(); ++i)
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   122
  {
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   123
    std::ostringstream subnet;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   124
    subnet<<"10.1."<<i+1<<".0";
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   125
    ipv4.SetBase (subnet.str().c_str(), "255.255.255.0");
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   126
    interfaceAdjacencyList[i] = ipv4.Assign (deviceAdjacencyList[i]);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   127
  }
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   128
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   129
  //Turn on global static routing
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   130
  GlobalRouteManager::PopulateRoutingTables ();
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   131
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   132
  // Create a packet sink on the star "hub" to receive these packets
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   133
  uint16_t port = 50000;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   134
  Address sinkLocalAddress(InetSocketAddress (Ipv4Address::GetAny (), port));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   135
  PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   136
  ApplicationContainer sinkApp = sinkHelper.Install (serverNode);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   137
  sinkApp.Start (Seconds (1.0));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   138
  sinkApp.Stop (Seconds (10.0));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   139
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   140
  // Create the OnOff applications to send TCP to the server
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   141
  OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   142
  clientHelper.SetAttribute 
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   143
      ("OnTime", RandomVariableValue (ConstantVariable (1)));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   144
  clientHelper.SetAttribute 
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   145
      ("OffTime", RandomVariableValue (ConstantVariable (0)));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   146
  //normally wouldn't need a loop here but the server IP address is different
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   147
  //on each p2p subnet
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   148
  ApplicationContainer clientApps;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   149
  for(uint32_t i=0; i<clientNodes.GetN(); ++i)
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   150
  {
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   151
    AddressValue remoteAddress
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   152
        (InetSocketAddress (interfaceAdjacencyList[i].GetAddress (0), port));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   153
    clientHelper.SetAttribute ("Remote", remoteAddress);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   154
    clientApps.Add(clientHelper.Install (clientNodes.Get(i)));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   155
  }
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   156
  clientApps.Start (Seconds (1.0));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   157
  clientApps.Stop (Seconds (10.0));
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   158
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   159
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   160
  //configure tracing
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   161
  std::ofstream ascii;
3367
8587b5520e63 Fix trace names to match documents in tcp-star-server
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3366
diff changeset
   162
  ascii.open ("tcp-star-server.tr");
8587b5520e63 Fix trace names to match documents in tcp-star-server
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3366
diff changeset
   163
  PointToPointHelper::EnablePcapAll ("tcp-star-server");
3366
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   164
  PointToPointHelper::EnableAsciiAll (ascii);
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   165
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   166
  NS_LOG_INFO ("Run Simulation.");
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   167
  Simulator::Run ();
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   168
  Simulator::Destroy ();
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   169
  NS_LOG_INFO ("Done.");
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   170
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   171
  return 0;
923e47a54fe8 Add a tcp server example
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   172
}