diff --git a/examples/tcp-star-server.cc b/examples/tcp-star-server.cc new file mode 100644 index 000000000..54d5a23e6 --- /dev/null +++ b/examples/tcp-star-server.cc @@ -0,0 +1,172 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +// Default Network topology, 9 nodes in a star +/* + n2 n3 n4 + \ | / + \|/ + n1---n0---n5 + /|\ + / | \ + n8 n7 n6 +*/ +// - CBR Traffic goes from the star "arms" to the "hub" +// - Tracing of queues and packet receptions to file +// "tcp-star-server.tr" +// - pcap traces also generated in the following files +// "tcp-star-server-$n-$i.pcap" where n and i represent node and interface +// numbers respectively +// Usage examples for things you might want to tweak: +// ./waf --run="tcp-star-server" +// ./waf --run="tcp-star-server --nNodes=25" +// ./waf --run="tcp-star-server --ns3::OnOffApplication::DataRate=10000" +// ./waf --run="tcp-star-server --ns3::OnOffApplication::PacketSize=500" +// See the ns-3 tutorial for more info on the command line: +// http://www.nsnam.org/tutorials.html + + + + +#include +#include +#include +#include + +#include "ns3/core-module.h" +#include "ns3/simulator-module.h" +#include "ns3/node-module.h" +#include "ns3/helper-module.h" +#include "ns3/global-route-manager.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("TcpServer"); + +int +main (int argc, char *argv[]) +{ + // Users may find it convenient to turn on explicit debugging + // for selected modules; the below lines suggest how to do this + + //LogComponentEnable ("TcpServer", LOG_LEVEL_INFO); + //LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_ALL); + //LogComponentEnable ("TcpSocketImpl", LOG_LEVEL_ALL); + //LogComponentEnable ("PacketSink", LOG_LEVEL_ALL); + // + // Make the random number generators generate reproducible results. + // + RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); + + // Set up some default values for the simulation. + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (250)); + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("5kb/s")); + uint32_t N = 9; //number of nodes in the star + + // Allow the user to override any of the defaults and the above + // Config::SetDefault()s at run-time, via command-line arguments + CommandLine cmd; + cmd.AddValue("nNodes", "Number of nodes to place in the star", N); + cmd.Parse (argc, argv); + + // Here, we will create N nodes in a star. + NS_LOG_INFO ("Create nodes."); + NodeContainer serverNode; + NodeContainer clientNodes; + serverNode.Create(1); + clientNodes.Create(N-1); + NodeContainer allNodes = NodeContainer(serverNode, clientNodes); + + // Install network stacks on the nodes + InternetStackHelper internet; + internet.Install (allNodes); + + //Collect an adjacency list of nodes for the p2p topology + std::vector nodeAdjacencyList(N-1); + for(uint32_t i=0; i deviceAdjacencyList(N-1); + for(uint32_t i=0; i interfaceAdjacencyList(N-1); + for(uint32_t i=0; i