nsc: example files.
This adds two example files that will use the Linux
2.6.18 and 2.6.26 stacks provided by NSC.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/tcp-nsc-lfn.cc Fri Aug 29 23:11:41 2008 +0200
1.3 @@ -0,0 +1,145 @@
1.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1.5 +/*
1.6 + * This program is free software; you can redistribute it and/or modify
1.7 + * it under the terms of the GNU General Public License version 2 as
1.8 + * published by the Free Software Foundation;
1.9 + *
1.10 + * This program is distributed in the hope that it will be useful,
1.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.13 + * GNU General Public License for more details.
1.14 + *
1.15 + * You should have received a copy of the GNU General Public License
1.16 + * along with this program; if not, write to the Free Software
1.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.18 + *
1.19 + */
1.20 +
1.21 +//
1.22 +// Network topology
1.23 +//
1.24 +// 6Mb/s, 500ms
1.25 +// n0-----------------n1
1.26 +//
1.27 +// - a 'lossy' network with long delay
1.28 +// - TCP flow from n0 to n1 and from n1 to n0
1.29 +// - pcap traces generated as tcp-nsc-lfn-0-0.pcap and tcp-nsc-lfn-1-0.pcap
1.30 +// Usage (e.g.): ./waf --run 'tcp-nsc-lfn --TCP_CONGESTION=hybla --runtime=30'
1.31 +
1.32 +#include <ctype.h>
1.33 +#include <iostream>
1.34 +#include <fstream>
1.35 +#include <string>
1.36 +#include <cassert>
1.37 +
1.38 +#include "ns3/core-module.h"
1.39 +#include "ns3/common-module.h"
1.40 +#include "ns3/helper-module.h"
1.41 +#include "ns3/node-module.h"
1.42 +#include "ns3/global-route-manager.h"
1.43 +#include "ns3/simulator-module.h"
1.44 +
1.45 +using namespace ns3;
1.46 +
1.47 +NS_LOG_COMPONENT_DEFINE ("TcpNscLfn");
1.48 +
1.49 +
1.50 +int main (int argc, char *argv[])
1.51 +{
1.52 + RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
1.53 +
1.54 + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096));
1.55 + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("6Mbps"));
1.56 +
1.57 + // cubic is the default congestion algorithm in Linux 2.6.26
1.58 + std::string tcpCong = "cubic";
1.59 + // this is the default error rate of our link, that is, the the probability of a single
1.60 + // byte being 'corrupted' during transfer.
1.61 + double errRate = 0.000001;
1.62 + // how long the sender should be running, in seconds.
1.63 + unsigned int runtime = 120;
1.64 + // the name of the NSC stack library that should be used
1.65 + std::string nscStack = "liblinux2.6.26.so";
1.66 +
1.67 + CommandLine cmd;
1.68 + // Here, we define additional command line options.
1.69 + // This allows a user to override the defaults set above from the command line.
1.70 + cmd.AddValue("TCP_CONGESTION", "Linux 2.6.26 Tcp Congestion control algorithm to use", tcpCong);
1.71 + cmd.AddValue("error-rate", "Error rate to apply to link", errRate);
1.72 + cmd.AddValue("runtime", "How long the applications should send data (default 120 seconds)", runtime);
1.73 + cmd.AddValue("nscstack", "Set name of NSC stack (shared library) to use (default liblinux2.6.26.so)", nscStack);
1.74 + cmd.Parse (argc, argv);
1.75 +
1.76 + NodeContainer n;
1.77 + n.Create (2);
1.78 +
1.79 + PointToPointHelper p2p;
1.80 + // create point-to-point link with a bandwidth of 6MBit/s and a large delay (0.5 seconds)
1.81 + p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(6 * 1000 * 1000)));
1.82 + p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(500)));
1.83 +
1.84 + NetDeviceContainer p2pInterfaces = p2p.Install (n);
1.85 + // The default MTU of the p2p link would be 65535, which doesn't work
1.86 + // well with our default errRate (most packets would arrive corrupted).
1.87 + p2pInterfaces.Get(0)->SetMtu(1500);
1.88 + p2pInterfaces.Get(1)->SetMtu(1500);
1.89 +
1.90 + InternetStackHelper internet;
1.91 + // The next statement switches the nodes to 'NSC'-Mode.
1.92 + // It disables the native ns-3 TCP model and loads the NSC library.
1.93 + internet.SetNscStack (nscStack);
1.94 + internet.Install (n);
1.95 +
1.96 + if (tcpCong != "cubic") // make sure we only fail if both --nscstack and --TCP_CONGESTION are used
1.97 + {
1.98 + // This uses ns-3s attribute system to set the 'net.ipv4.tcp_congestion_control' sysctl of the
1.99 + // stack.
1.100 + // The same mechanism could be used to e.g. disable TCP timestamps:
1.101 + // Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
1.102 + Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_congestion_control", StringValue (tcpCong));
1.103 + }
1.104 + Ipv4AddressHelper ipv4;
1.105 + ipv4.SetBase ("10.0.0.0", "255.255.255.0");
1.106 + Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (p2pInterfaces);
1.107 +
1.108 + DoubleValue rate(errRate);
1.109 + RandomVariableValue u01(UniformVariable (0.0, 1.0));
1.110 + Ptr<RateErrorModel> em1 =
1.111 + CreateObject<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
1.112 + Ptr<RateErrorModel> em2 =
1.113 + CreateObject<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
1.114 +
1.115 + // This enables the specified errRate on both link endpoints.
1.116 + p2pInterfaces.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue (em1));
1.117 + p2pInterfaces.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue (em2));
1.118 +
1.119 + GlobalRouteManager::PopulateRoutingTables ();
1.120 +
1.121 + uint16_t servPort = 8080;
1.122 + PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
1.123 + ApplicationContainer sinkApp = sinkHelper.Install (n);
1.124 + sinkApp.Start (Seconds (0.0));
1.125 + // this makes sure that the receiver will run one minute longer than the sender applicaton.
1.126 + sinkApp.Stop (Seconds (runtime + 60.0));
1.127 +
1.128 + // This sets up two TCP flows, one from A -> B, one from B -> A.
1.129 + for (int i = 0, j = 1; i < 2; j--, i++)
1.130 + {
1.131 + Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (i), servPort));
1.132 + OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
1.133 + clientHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
1.134 + clientHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
1.135 + ApplicationContainer clientApp = clientHelper.Install(n.Get(j));
1.136 + clientApp.Start (Seconds (1.0 + i));
1.137 + clientApp.Stop (Seconds (runtime + 1.0 + i));
1.138 + }
1.139 +
1.140 + // This tells ns-3 to generate pcap traces.
1.141 + PointToPointHelper::EnablePcapAll ("tcp-nsc-lfn");
1.142 +
1.143 + Simulator::Stop (Seconds(900));
1.144 + Simulator::Run ();
1.145 + Simulator::Destroy ();
1.146 +
1.147 + return 0;
1.148 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/tcp-nsc-zoo.cc Fri Aug 29 23:11:41 2008 +0200
2.3 @@ -0,0 +1,131 @@
2.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2.5 +/*
2.6 + * This program is free software; you can redistribute it and/or modify
2.7 + * it under the terms of the GNU General Public License version 2 as
2.8 + * published by the Free Software Foundation;
2.9 + *
2.10 + * This program is distributed in the hope that it will be useful,
2.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.13 + * GNU General Public License for more details.
2.14 + *
2.15 + * You should have received a copy of the GNU General Public License
2.16 + * along with this program; if not, write to the Free Software
2.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2.18 + *
2.19 + */
2.20 +
2.21 +
2.22 +// Network topology
2.23 +//
2.24 +// n0 n1 n2 n3
2.25 +// | | | |
2.26 +// =================
2.27 +// LAN
2.28 +//
2.29 +// - Pcap traces are saved as tcp-nsc-zoo-$n-0.pcap, where $n represents the node number
2.30 +// - TCP flows from n0 to n1, n2, n3, from n1 to n0, n2, n3, etc.
2.31 +// Usage (e.g.): ./waf --run 'tcp-nsc-zoo --Nodes=5'
2.32 +
2.33 +#include <iostream>
2.34 +#include <string>
2.35 +
2.36 +#include "ns3/core-module.h"
2.37 +#include "ns3/helper-module.h"
2.38 +#include "ns3/node-module.h"
2.39 +#include "ns3/global-route-manager.h"
2.40 +#include "ns3/simulator-module.h"
2.41 +
2.42 +using namespace ns3;
2.43 +
2.44 +NS_LOG_COMPONENT_DEFINE ("TcpNscZoo");
2.45 +
2.46 +// Simulates a diverse network with various stacks supported by NSC.
2.47 +int main(int argc, char *argv[])
2.48 +{
2.49 + CsmaHelper csma;
2.50 + unsigned int MaxNodes = 4;
2.51 +
2.52 + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096));
2.53 + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1Mb/s"));
2.54 + CommandLine cmd;
2.55 + // this allows the user to raise the number of nodes using --Nodes=X command-line argument.
2.56 + cmd.AddValue("Nodes", "Number of nodes in the network", MaxNodes);
2.57 + cmd.Parse (argc, argv);
2.58 +
2.59 + csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(100 * 1000 * 1000)));
2.60 + csma.SetChannelAttribute ("Delay", TimeValue (MicroSeconds (200)));
2.61 +
2.62 + NodeContainer n;
2.63 + n.Create(MaxNodes);
2.64 + NetDeviceContainer ethInterfaces = csma.Install (n);
2.65 +
2.66 + InternetStackHelper internetStack;
2.67 +
2.68 + internetStack.SetNscStack ("liblinux2.6.26.so");
2.69 + // this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack.
2.70 + internetStack.Install (n.Get(0));
2.71 + internetStack.Install (n.Get(1));
2.72 + // this disables TCP SACK, wscale and timestamps on node 1 (the attributes represent sysctl-values).
2.73 + Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack", StringValue ("0"));
2.74 + Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
2.75 + Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling", StringValue ("0"));
2.76 + internetStack.Install (n.Get(2));
2.77 + // the next statement doesn't change anything for the nodes 0, 1, and 2; since they
2.78 + // already have a stack assigned.
2.79 + internetStack.SetNscStack ("liblinux2.6.18.so");
2.80 + // this switches node 3 to NSCs Linux 2.6.18 stack.
2.81 + internetStack.Install (n.Get(3));
2.82 + // and then agains disables sack/timestamps/wscale on node 3.
2.83 + Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_sack", StringValue ("0"));
2.84 + Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_timestamps", StringValue ("0"));
2.85 + Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_window_scaling", StringValue ("0"));
2.86 + // the freebsd stack is not yet built by default, so its commented out for now.
2.87 + // internetStack.SetNscStack ("libfreebsd5.so");
2.88 + for (unsigned int i =4; i < MaxNodes; i++)
2.89 + {
2.90 + internetStack.Install (n.Get(i));
2.91 + }
2.92 + Ipv4AddressHelper ipv4;
2.93 +
2.94 + ipv4.SetBase ("10.0.0.0", "255.255.255.0");
2.95 + Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (ethInterfaces);
2.96 +
2.97 + GlobalRouteManager::PopulateRoutingTables ();
2.98 +
2.99 + uint16_t servPort = 8080;
2.100 + PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
2.101 + // start a sink client on all nodes
2.102 + ApplicationContainer sinkApp = sinkHelper.Install (n);
2.103 + sinkApp.Start (Seconds (1.0));
2.104 + sinkApp.Stop (Seconds (30.0));
2.105 +
2.106 + // This tells every node on the network to start a flow to all other nodes on the network ...
2.107 + for (unsigned int i = 0 ; i < MaxNodes;i++)
2.108 + {
2.109 + for (unsigned int j = 0 ; j < MaxNodes;j++)
2.110 + {
2.111 + if (i == j)
2.112 + { // ...but we don't want a node to talk to itself.
2.113 + continue;
2.114 + }
2.115 + Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (j), servPort));
2.116 + OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
2.117 + clientHelper.SetAttribute
2.118 + ("OnTime", RandomVariableValue (ConstantVariable (1)));
2.119 + clientHelper.SetAttribute
2.120 + ("OffTime", RandomVariableValue (ConstantVariable (0)));
2.121 + ApplicationContainer clientApp = clientHelper.Install(n.Get(i));
2.122 + clientApp.Start (Seconds (j + 1.0)); /* delay startup depending on node number */
2.123 + clientApp.Stop (Seconds (j + 10.0));
2.124 + }
2.125 + }
2.126 +
2.127 + CsmaHelper::EnablePcapAll ("tcp-nsc-zoo");
2.128 +
2.129 + Simulator::Stop (Seconds(1000));
2.130 + Simulator::Run ();
2.131 + Simulator::Destroy ();
2.132 +
2.133 + return 0;
2.134 +}
3.1 --- a/examples/wscript Fri Aug 29 23:10:00 2008 +0200
3.2 +++ b/examples/wscript Fri Aug 29 23:11:41 2008 +0200
3.3 @@ -64,6 +64,14 @@
3.4 ['point-to-point', 'internet-stack'])
3.5 obj.source = 'tcp-errors.cc'
3.6
3.7 + obj = bld.create_ns3_program('tcp-nsc-lfn',
3.8 + ['point-to-point', 'internet-stack'])
3.9 + obj.source = 'tcp-nsc-lfn.cc'
3.10 +
3.11 + obj = bld.create_ns3_program('tcp-nsc-zoo',
3.12 + ['csma', 'internet-stack'])
3.13 + obj.source = 'tcp-nsc-zoo.cc'
3.14 +
3.15 obj = bld.create_ns3_program('tcp-star-server',
3.16 ['point-to-point', 'internet-stack'])
3.17 obj.source = 'tcp-star-server.cc'