1.1 --- a/Makefile Sun Apr 05 16:27:42 2009 +0200
1.2 +++ b/Makefile Sun Apr 05 21:44:11 2009 +0200
1.3 @@ -11,7 +11,12 @@
1.4 pstoedit -pta -f "emf:-OO" $^ $@
1.5
1.6 MAIN_SOURCE=tutorial.tex
1.7 -DIA_SOURCES=simulation-workflow.dia
1.8 +DIA_SOURCES=\
1.9 +simulation-workflow.dia \
1.10 +architecture.dia \
1.11 +scenario.dia \
1.12 +topology-basics \
1.13 +device-channel
1.14 PDF_SOURCES=test-random-variable.pdf
1.15 PNG_SOURCES=ns-3-doxygen.png
1.16
2.1 Binary file architecture.dia has changed
3.1 Binary file device-channel.dia has changed
4.1 Binary file topology-basics.dia has changed
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tutorial-helper.cc Sun Apr 05 21:44:11 2009 +0200
5.3 @@ -0,0 +1,87 @@
5.4 +#include <iostream>
5.5 +#include <fstream>
5.6 +#include "ns3/simulator-module.h"
5.7 +#include "ns3/node-module.h"
5.8 +#include "ns3/core-module.h"
5.9 +#include "ns3/helper-module.h"
5.10 +#include "ns3/global-route-manager.h"
5.11 +#include "ns3/contrib-module.h"
5.12 +
5.13 +using namespace ns3;
5.14 +
5.15 +int main (int argc, char *argv[])
5.16 +{
5.17 + CommandLine cmd;
5.18 + cmd.Parse (argc, argv);
5.19 +
5.20 + NodeContainer csmaNodes;
5.21 + csmaNodes.Create (2);
5.22 + NodeContainer wifiNodes;
5.23 + wifiNodes.Add (csmaNodes.Get (1));
5.24 + wifiNodes.Create (3);
5.25 +
5.26 + NetDeviceContainer csmaDevices;
5.27 + CsmaHelper csma;
5.28 + csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
5.29 + csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
5.30 + csmaDevices = csma.Install (csmaNodes);
5.31 +
5.32 + NetDeviceContainer wifiDevices;
5.33 + YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
5.34 + YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
5.35 + wifiPhy.SetChannel (wifiChannel.Create ());
5.36 + WifiHelper wifi = WifiHelper::Default ();
5.37 + wifiDevices = wifi.Install (wifiPhy, wifiNodes);
5.38 +
5.39 + MobilityHelper mobility;
5.40 + mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator",
5.41 + "X", StringValue ("100.0"),
5.42 + "Y", StringValue ("100.0"),
5.43 + "Rho", StringValue ("Uniform:0:30"));
5.44 + mobility.SetMobilityModel ("ns3::StaticMobilityModel");
5.45 + mobility.Install (wifiNodes);
5.46 +
5.47 + Ipv4InterfaceContainer csmaInterfaces;
5.48 + Ipv4InterfaceContainer wifiInterfaces;
5.49 + InternetStackHelper internet;
5.50 + internet.Install (NodeContainer::GetGlobal ());
5.51 + Ipv4AddressHelper ipv4;
5.52 + ipv4.SetBase ("10.1.1.0", "255.255.255.0");
5.53 + csmaInterfaces = ipv4.Assign (csmaDevices);
5.54 + ipv4.SetBase ("10.1.2.0", "255.255.255.0");
5.55 + wifiInterfaces = ipv4.Assign (wifiDevices);
5.56 +
5.57 + GlobalRouteManager::PopulateRoutingTables ();
5.58 +
5.59 + ApplicationContainer apps;
5.60 + OnOffHelper onoff ("ns3::UdpSocketFactory",
5.61 + InetSocketAddress ("10.1.2.2", 1025));
5.62 + onoff.SetAttribute ("OnTime", StringValue ("Constant:1.0"));
5.63 + onoff.SetAttribute ("OffTime", StringValue ("Constant:0.0"));
5.64 + apps = onoff.Install (csmaNodes.Get (0));
5.65 + apps.Start (Seconds (1.0));
5.66 + apps.Stop (Seconds (4.0));
5.67 +
5.68 + PacketSinkHelper sink ("ns3::UdpSocketFactory",
5.69 + InetSocketAddress ("10.1.2.2", 1025));
5.70 + apps = sink.Install (wifiNodes.Get (1));
5.71 + apps.Start (Seconds (0.0));
5.72 + apps.Stop (Seconds (4.0));
5.73 +
5.74 + std::ofstream ascii;
5.75 + ascii.open ("wns3-helper.tr");
5.76 + CsmaHelper::EnableAsciiAll (ascii);
5.77 + CsmaHelper::EnablePcapAll ("wns3-helper");
5.78 + YansWifiPhyHelper::EnablePcapAll ("wsn3-helper");
5.79 +
5.80 + GtkConfigStore config;
5.81 + config.Configure ();
5.82 +
5.83 + Simulator::Stop (Seconds (4.5));
5.84 +
5.85 + Simulator::Run ();
5.86 + Simulator::Destroy ();
5.87 +
5.88 +
5.89 + return 0;
5.90 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tutorial-lowlevel.cc Sun Apr 05 21:44:11 2009 +0200
6.3 @@ -0,0 +1,213 @@
6.4 +#include <iostream>
6.5 +#include <fstream>
6.6 +#include "ns3/simulator-module.h"
6.7 +#include "ns3/node-module.h"
6.8 +#include "ns3/core-module.h"
6.9 +#include "ns3/csma-module.h"
6.10 +#include "ns3/wifi-module.h"
6.11 +#include "ns3/internet-stack-module.h"
6.12 +#include "ns3/onoff-module.h"
6.13 +#include "ns3/packet-sink-module.h"
6.14 +#include "ns3/mobility-module.h"
6.15 +#include "ns3/global-route-manager.h"
6.16 +#include "ns3/contrib-module.h"
6.17 +#include "ns3/common-module.h"
6.18 +
6.19 +using namespace ns3;
6.20 +
6.21 +static Ptr<CsmaNetDevice>
6.22 +AddCsma (Ptr<Node> node, Ptr<CsmaChannel> channel)
6.23 +{
6.24 + Ptr<CsmaNetDevice> dev = CreateObject<CsmaNetDevice> ();
6.25 + dev->SetAddress (Mac48Address::Allocate ());
6.26 + node->AddDevice (dev);
6.27 + Ptr<Queue> queue = CreateObject<DropTailQueue> ();
6.28 + dev->SetQueue (queue);
6.29 + dev->Attach (channel);
6.30 + return dev;
6.31 +}
6.32 +
6.33 +static Ptr<WifiNetDevice>
6.34 +AddWifi (Ptr<Node> node, Ptr<YansWifiChannel> channel)
6.35 +{
6.36 + Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
6.37 +
6.38 + Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
6.39 + Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
6.40 + phy->SetErrorRateModel (error);
6.41 + phy->SetChannel (channel);
6.42 + phy->SetMobility (node);
6.43 + phy->SetDevice (device);
6.44 +
6.45 + Ptr<WifiRemoteStationManager> manager = CreateObject<ArfWifiManager> ();
6.46 + Ptr<WifiMac> mac = CreateObject<AdhocWifiMac> ();
6.47 + mac->SetAddress (Mac48Address::Allocate ());
6.48 +
6.49 + device->SetMac (mac);
6.50 + device->SetPhy (phy);
6.51 + device->SetRemoteStationManager (manager);
6.52 + node->AddDevice (device);
6.53 +
6.54 + return device;
6.55 +}
6.56 +
6.57 +static Ptr<PositionAllocator>
6.58 +GetPositionAllocator (void)
6.59 +{
6.60 + static Ptr<PositionAllocator> allocator = 0;
6.61 + if (allocator == 0)
6.62 + {
6.63 + allocator = CreateObject<RandomDiscPositionAllocator> ();
6.64 + allocator->SetAttribute ("X", StringValue ("100.0"));
6.65 + allocator->SetAttribute ("Y", StringValue ("100.0"));
6.66 + allocator->SetAttribute ("Rho", StringValue ("Uniform:0:30"));
6.67 + }
6.68 + return allocator;
6.69 +}
6.70 +
6.71 +static void
6.72 +AddMobility (Ptr<Node> node)
6.73 +{
6.74 + Ptr<StaticMobilityModel> mobility = CreateObject<StaticMobilityModel> ();
6.75 + mobility->SetPosition (GetPositionAllocator ()->GetNext ());
6.76 + node->AggregateObject (mobility);
6.77 +}
6.78 +
6.79 +static void
6.80 +AddIpv4Interface (Ptr<NetDevice> device,
6.81 + const char * ip,
6.82 + const char * mask)
6.83 +{
6.84 + Ptr<Node> node = device->GetNode ();
6.85 + Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
6.86 + int32_t ifIndex = ipv4->AddInterface (device);
6.87 + ipv4->SetAddress (ifIndex, Ipv4Address (ip));
6.88 + ipv4->SetNetworkMask (ifIndex, Ipv4Mask (mask));
6.89 + ipv4->SetMetric (ifIndex, 1);
6.90 + ipv4->SetUp (ifIndex);
6.91 +}
6.92 +
6.93 +static Ptr<Application>
6.94 +AddUdpSource (Ptr<Node> node,
6.95 + const char *ip, uint16_t port)
6.96 +{
6.97 + Ptr<OnOffApplication> application = CreateObject<OnOffApplication> ();
6.98 + application->SetAttribute ("Protocol", StringValue ("ns3::UdpSocketFactory"));
6.99 + application->SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address (ip), port)));
6.100 + application->SetAttribute ("OnTime", StringValue ("Constant:1.0"));
6.101 + application->SetAttribute ("OffTime", StringValue ("Constant:0.0"));
6.102 + node->AddApplication (application);
6.103 + return application;
6.104 +}
6.105 +
6.106 +static Ptr<Application>
6.107 +AddUdpSink (Ptr<Node> node, const char *ip, uint16_t port)
6.108 +{
6.109 + Ptr<PacketSink> sink = CreateObject<PacketSink> ();
6.110 + sink->SetAttribute ("Protocol", StringValue ("ns3::UdpSocketFactory"));
6.111 + sink->SetAttribute ("Local", AddressValue (InetSocketAddress (Ipv4Address (ip), port)));
6.112 + node->AddApplication (sink);
6.113 + return sink;
6.114 +}
6.115 +
6.116 +static void PcapPhyRxEvent (Ptr<PcapWriter> writer,
6.117 + Ptr<const Packet> packet, double snr, WifiMode mode,
6.118 + enum WifiPreamble preamble)
6.119 +{
6.120 + writer->WritePacket (packet);
6.121 +}
6.122 +static void PcapPhyTxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet,
6.123 + WifiMode mode, WifiPreamble preamble,
6.124 + uint8_t txLevel)
6.125 +{
6.126 + writer->WritePacket (packet);
6.127 +}
6.128 +
6.129 +
6.130 +static void
6.131 +WifiEnablePcap (Ptr<WifiNetDevice> wifi, const char *filename)
6.132 +{
6.133 + uint32_t nodeId = wifi->GetNode ()->GetId ();
6.134 + uint32_t deviceId = wifi->GetIfIndex ();
6.135 + std::ostringstream oss;
6.136 + oss << filename << "-" << nodeId << "-" << deviceId << ".pcap";
6.137 + Ptr<PcapWriter> pcap = ::ns3::Create<PcapWriter> ();
6.138 + pcap->Open (oss.str ());
6.139 + pcap->WriteWifiHeader ();
6.140 + oss.str ("");
6.141 + oss << "/NodeList/" << nodeId << "/DeviceList/" << deviceId
6.142 + << "/$ns3::WifiNetDevice/Phy/State/Tx";
6.143 + Config::ConnectWithoutContext (oss.str (),
6.144 + MakeBoundCallback (&PcapPhyTxEvent, pcap));
6.145 + oss.str ("");
6.146 + oss << "/NodeList/" << nodeId << "/DeviceList/" << deviceId
6.147 + << "/$ns3::WifiNetDevice/Phy/State/RxOk";
6.148 + Config::ConnectWithoutContext (oss.str (),
6.149 + MakeBoundCallback (&PcapPhyRxEvent, pcap));
6.150 +}
6.151 +
6.152 +int main (int argc, char *argv[])
6.153 +{
6.154 + Ptr<Node> node0 = CreateObject<Node> ();
6.155 + Ptr<Node> node1 = CreateObject<Node> ();
6.156 + Ptr<Node> node2 = CreateObject<Node> ();
6.157 + Ptr<Node> node3 = CreateObject<Node> ();
6.158 + Ptr<Node> node4 = CreateObject<Node> ();
6.159 +
6.160 + Ptr<CsmaChannel> csmaChannel = CreateObject<CsmaChannel> ();
6.161 + csmaChannel->SetAttribute ("DataRate", StringValue ("5Mbps"));
6.162 + csmaChannel->SetAttribute ("Delay", StringValue ("2ms"));
6.163 + Ptr<CsmaNetDevice> csmaDev0 = AddCsma (node0, csmaChannel);
6.164 + Ptr<CsmaNetDevice> csmaDev1 = AddCsma (node1, csmaChannel);
6.165 +
6.166 + Ptr<YansWifiChannel> wifiChannel = CreateObject<YansWifiChannel> ();
6.167 + wifiChannel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
6.168 + Ptr<PropagationLossModel> loss = CreateObject<LogDistancePropagationLossModel> ();
6.169 + wifiChannel->SetPropagationLossModel (loss);
6.170 +
6.171 + Ptr<WifiNetDevice> wifiDev0 = AddWifi (node1, wifiChannel);
6.172 + Ptr<WifiNetDevice> wifiDev1 = AddWifi (node2, wifiChannel);
6.173 + Ptr<WifiNetDevice> wifiDev2 = AddWifi (node3, wifiChannel);
6.174 + Ptr<WifiNetDevice> wifiDev3 = AddWifi (node4, wifiChannel);
6.175 +
6.176 + AddMobility (node1);
6.177 + AddMobility (node2);
6.178 + AddMobility (node3);
6.179 + AddMobility (node4);
6.180 +
6.181 + AddInternetStack (node0);
6.182 + AddInternetStack (node1);
6.183 + AddInternetStack (node2);
6.184 + AddInternetStack (node3);
6.185 + AddInternetStack (node4);
6.186 +
6.187 + AddIpv4Interface (csmaDev0, "10.1.1.1", "255.255.255.0");
6.188 + AddIpv4Interface (csmaDev1, "10.1.1.2", "255.255.255.0");
6.189 + AddIpv4Interface (wifiDev0, "10.1.2.1", "255.255.255.0");
6.190 + AddIpv4Interface (wifiDev1, "10.1.2.2", "255.255.255.0");
6.191 + AddIpv4Interface (wifiDev2, "10.1.2.3", "255.255.255.0");
6.192 + AddIpv4Interface (wifiDev3, "10.1.2.4", "255.255.255.0");
6.193 +
6.194 + GlobalRouteManager::PopulateRoutingTables ();
6.195 +
6.196 + Ptr<Application> app;
6.197 + app = AddUdpSource (node0, "10.1.2.2", 1025);
6.198 + app->Start (Seconds (1.0));
6.199 + app->Stop (Seconds (4.0));
6.200 + app = AddUdpSink (node2, "10.1.2.2", 1025);
6.201 + app->Start (Seconds (0.0));
6.202 + app->Stop (Seconds (4.0));
6.203 +
6.204 + WifiEnablePcap (wifiDev2, "wns3-lowlevel");
6.205 +
6.206 + GtkConfigStore config;
6.207 + config.Configure ();
6.208 +
6.209 + Simulator::Stop (Seconds (4.5));
6.210 +
6.211 + Simulator::Run ();
6.212 + Simulator::Destroy ();
6.213 +
6.214 +
6.215 + return 0;
6.216 +}
7.1 --- a/tutorial.tex Sun Apr 05 16:27:42 2009 +0200
7.2 +++ b/tutorial.tex Sun Apr 05 21:44:11 2009 +0200
7.3 @@ -47,33 +47,12 @@
7.4 \end{itemize}
7.5 \end{frame}
7.6
7.7 -\part{The goals of ns-3}
7.8 -
7.9 -\begin{frame}
7.10 -\partpage
7.11 -\end{frame}
7.12 -
7.13 -\begin{frame}{}
7.14 -
7.15 -Need to explain experimentation, simulation, overall workflow.
7.16 -Try to explain what ns-3 is trying to achieve, and where it
7.17 -wants to be relative to other solutions
7.18 -
7.19 -\end{frame}
7.20 -
7.21 -
7.22 \part{Overview of ns-3 features}
7.23
7.24 \begin{frame}
7.25 \partpage
7.26 \end{frame}
7.27
7.28 -\begin{frame}{A typical simulation workflow}
7.29 -
7.30 -\includegraphics[width=10cm]{simulation-workflow}
7.31 -
7.32 -\end{frame}
7.33 -
7.34 \section{Introductory Software Overview}
7.35
7.36 \begin{frame}{The basics}
7.37 @@ -87,6 +66,8 @@
7.38 \end{itemize}
7.39 \end{frame}
7.40
7.41 +\subsection{The Development Environment}
7.42 +
7.43 \begin{frame}{The waf build system}
7.44 Waf is a Python-based framework for
7.45 configuring, compiling and installing
7.46 @@ -188,11 +169,7 @@
7.47
7.48 \end{frame}
7.49
7.50 -\section{Introductory Architecture}
7.51 -
7.52 -\begin{frame}{}
7.53 -
7.54 -\end{frame}
7.55 +\subsection{This is an event-driven simulator}
7.56
7.57 \begin{frame}{Simulation basics}
7.58
7.59 @@ -230,38 +207,92 @@
7.60 \end{block}
7.61 \end{frame}
7.62
7.63 -\begin{frame}[fragile]{Random variables}
7.64 +\section{An illustrated feature tour}
7.65
7.66 -Currently implemented distributions:
7.67 +\begin{frame}{The Testcase}
7.68 +\begin{columns}
7.69 +\begin{column}{0.5\textwidth}
7.70 +\includegraphics[width=6cm]{scenario}
7.71 +\end{column}
7.72 +\begin{column}{0.5\textwidth}
7.73 \begin{itemize}
7.74 -\item Uniform: values uniformly distributed in an interval
7.75 -\item Constant: value is always the same (not really random)
7.76 -\item Sequential: return a sequential list of predefined values
7.77 -\item Exponential: exponential distribution (poisson process)
7.78 -\item Normal (gaussian)
7.79 -\item Log-normal
7.80 -\item pareto, weibull, triangular,
7.81 -\item ...
7.82 +\item One csma link
7.83 +\item One wifi infrastructure network
7.84 +\item Two ip subnetworks
7.85 +\item One udp traffic generator
7.86 +\item One udp traffic receiver
7.87 +\item Global god ip routing
7.88 \end{itemize}
7.89 -\begin{columns}
7.90 -\begin{column}{0.75\textwidth}
7.91 -\begin{block}{}
7.92 -\begin{verbatim}
7.93 -import pylab
7.94 -import ns3
7.95 -rng = ns3.NormalVariable(10.0, 5.0)
7.96 -x = [rng.GetValue() for t in range(100000)]
7.97 -pylab.hist(x,100)
7.98 -pylab.show()
7.99 -\end{verbatim}
7.100 -\end{block}
7.101 -\end{column}
7.102 -\begin{column}{0.25\textwidth}
7.103 -\includegraphics[width=3cm]{test-random-variable}
7.104 \end{column}
7.105 \end{columns}
7.106 +\end{frame}
7.107 +
7.108 +\begin{frame}{A typical simulation structure}
7.109 +
7.110 +\includegraphics[width=12cm]{simulation-workflow}
7.111
7.112 \end{frame}
7.113
7.114 +\begin{frame}{Where is everything located ?}
7.115 +
7.116 +\includegraphics[width=12cm]{architecture}
7.117 +\end{frame}
7.118 +
7.119 +\begin{frame}{So, what does the source code look like ?}
7.120 +
7.121 +Let's open \code{tutorial-helper.cc}
7.122 +
7.123 +\end{frame}
7.124 +
7.125 +\begin{frame}[fragile]{Topology construction}
7.126 +
7.127 +\begin{block}{}
7.128 +\begin{verbatim}
7.129 +NodeContainer csmaNodes;
7.130 +csmaNodes.Create (2);
7.131 +...
7.132 +NetDeviceContainer csmaDevices;
7.133 +CsmaHelper csma;
7.134 +csma.SetChannelAttribute ("DataRate",
7.135 + StringValue ("5Mbps"));
7.136 +csma.SetChannelAttribute ("Delay",
7.137 + StringValue ("2ms"));
7.138 +csmaDevices = csma.Install (csmaNodes);
7.139 +\end{verbatim}
7.140 +\end{block}
7.141 +
7.142 +\end{frame}
7.143 +
7.144 +\begin{frame}{The basic model}
7.145 +
7.146 +\includegraphics[width=10cm]{topology-basics}
7.147 +
7.148 +\end{frame}
7.149 +
7.150 +\begin{frame}{The fundamental objects}
7.151 +
7.152 +\begin{itemize}
7.153 +\item Node: the motherboard of a computer with RAM, CPU, and, IO interfaces
7.154 +\item Application: a packet generator and consumer which can run on a Node and
7.155 +talk to a set of network \emph{stacks}
7.156 +\item NetDevice: a network card which can be plugged in an IO interface of a Node
7.157 +\item Channel: a physical connector between a set of NetDevice objects
7.158 +\end{itemize}
7.159 +
7.160 +\end{frame}
7.161 +
7.162 +\begin{frame}{Important remarks}
7.163 +
7.164 +\begin{itemize}
7.165 +\item NetDevices are strongly bound to Channels
7.166 +of a matching type:
7.167 +\begin{block}{}
7.168 +\includegraphics[width=10cm]{device-channel}
7.169 +\end{block}
7.170 +\item Nodes are architected for multiple interfaces
7.171 +\end{itemize}
7.172 +\end{frame}
7.173 +
7.174 +
7.175
7.176 \end{document}
8.1 --- a/wns3-example.cc Sun Apr 05 16:27:42 2009 +0200
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,186 +0,0 @@
8.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
8.5 -/*
8.6 - * This program is free software; you can redistribute it and/or modify
8.7 - * it under the terms of the GNU General Public License version 2 as
8.8 - * published by the Free Software Foundation;
8.9 - *
8.10 - * This program is distributed in the hope that it will be useful,
8.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.13 - * GNU General Public License for more details.
8.14 - *
8.15 - * You should have received a copy of the GNU General Public License
8.16 - * along with this program; if not, write to the Free Software
8.17 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8.18 - */
8.19 -
8.20 -//
8.21 -// Default network topology includes some number of AP nodes specified by
8.22 -// the variable nWifis (defaults to two). Off of each AP node, there are some
8.23 -// number of STA nodes specified by the variable nStas (defaults to two).
8.24 -// Each AP talks to its associated STA nodes. There are bridge net devices
8.25 -// on each AP node that bridge the whole thing into one network.
8.26 -//
8.27 -// +-----+ +-----+ +-----+ +-----+
8.28 -// | STA | | STA | | STA | | STA |
8.29 -// +-----+ +-----+ +-----+ +-----+
8.30 -// 192.168.0.2 192.168.0.3 192.168.1.2 192.168.1.3
8.31 -// -------- -------- -------- --------
8.32 -// WIFI STA WIFI STA WIFI STA WIFI STA
8.33 -// -------- -------- -------- --------
8.34 -// ((*)) ((*)) | ((*)) ((*))
8.35 -// |
8.36 -// ((*)) | ((*))
8.37 -// 192.168.0.1 192.168.1.1
8.38 -// ------- -------
8.39 -// WIFI AP CSMA ========= CSMA WIFI AP
8.40 -// ------- ---- ---- -------
8.41 -// 10.0.0.1 10.0.0.2
8.42 -// ############## ##############
8.43 -// ROUTER ROUTER
8.44 -// ############## ##############
8.45 -// +---------+ +---------+
8.46 -// | AP Node | | AP Node |
8.47 -// +---------+ +---------+
8.48 -//
8.49 -
8.50 -#include "ns3/core-module.h"
8.51 -#include "ns3/simulator-module.h"
8.52 -#include "ns3/mobility-module.h"
8.53 -#include "ns3/helper-module.h"
8.54 -#include "ns3/wifi-module.h"
8.55 -#include "ns3/node-module.h"
8.56 -#include "ns3/global-route-manager.h"
8.57 -#include <vector>
8.58 -#include <stdint.h>
8.59 -#include <sstream>
8.60 -#include <fstream>
8.61 -
8.62 -using namespace ns3;
8.63 -
8.64 -int main (int argc, char *argv[])
8.65 -{
8.66 - uint32_t nWifis = 2;
8.67 - uint32_t nStas = 2;
8.68 -
8.69 - RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
8.70 -
8.71 - CommandLine cmd;
8.72 - cmd.AddValue ("nWifis", "Number of wifi networks", nWifis);
8.73 - cmd.AddValue ("nStas", "Number of stations per wifi network", nStas);
8.74 - cmd.Parse (argc, argv);
8.75 -
8.76 - NodeContainer backboneNodes;
8.77 - NetDeviceContainer backboneDevices;
8.78 - Ipv4InterfaceContainer backboneInterfaces;
8.79 - std::vector<NodeContainer> staNodes;
8.80 - std::vector<NetDeviceContainer> staDevices;
8.81 - std::vector<NetDeviceContainer> apDevices;
8.82 - std::vector<Ipv4InterfaceContainer> staInterfaces;
8.83 - std::vector<Ipv4InterfaceContainer> apInterfaces;
8.84 -
8.85 - InternetStackHelper stack;
8.86 - CsmaHelper csma;
8.87 - Ipv4AddressHelper ip;
8.88 - ip.SetBase ("192.168.0.0", "255.255.255.0");
8.89 - Ipv4AddressHelper ipBackbone;
8.90 - ipBackbone.SetBase ("10.0.0.0", "255.255.255.0");
8.91 -
8.92 - backboneNodes.Create (nWifis);
8.93 - stack.Install (backboneNodes);
8.94 -
8.95 - backboneDevices = csma.Install (backboneNodes);
8.96 - ipBackbone.Assign (backboneDevices);
8.97 -
8.98 - double wifiX = 0.0;
8.99 - for (uint32_t i = 0; i < nWifis; ++i)
8.100 - {
8.101 - // calculate ssid for wifi subnetwork
8.102 - std::ostringstream oss;
8.103 - oss << "wifi-default-" << i;
8.104 - Ssid ssid = Ssid (oss.str ());
8.105 -
8.106 - NodeContainer sta;
8.107 - NetDeviceContainer staDev;
8.108 - NetDeviceContainer apDev;
8.109 - Ipv4InterfaceContainer staInterface;
8.110 - Ipv4InterfaceContainer apInterface;
8.111 - MobilityHelper mobility;
8.112 - WifiHelper wifi = WifiHelper::Default ();
8.113 - YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
8.114 - YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
8.115 - wifiPhy.SetChannel (wifiChannel.Create ());
8.116 -
8.117 - sta.Create (nStas);
8.118 - mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
8.119 - "MinX", DoubleValue (wifiX),
8.120 - "MinY", DoubleValue (0.0),
8.121 - "DeltaX", DoubleValue (5.0),
8.122 - "DeltaY", DoubleValue (5.0),
8.123 - "GridWidth", UintegerValue (1),
8.124 - "LayoutType", StringValue ("RowFirst"));
8.125 -
8.126 -
8.127 - // setup the AP.
8.128 - mobility.SetMobilityModel ("ns3::StaticMobilityModel");
8.129 - mobility.Install (backboneNodes.Get (i));
8.130 - wifi.SetMac ("ns3::NqapWifiMac",
8.131 - "Ssid", SsidValue (ssid),
8.132 - "BeaconGeneration", BooleanValue (true),
8.133 - "BeaconInterval", TimeValue (Seconds (2.5)));
8.134 - apDev = wifi.Install (wifiPhy, backboneNodes.Get (i));
8.135 -
8.136 - // assign AP IP address
8.137 - apInterface = ip.Assign (apDev);
8.138 -
8.139 - // setup the STAs
8.140 - stack.Install (sta);
8.141 - mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
8.142 - "Mode", StringValue ("Time"),
8.143 - "Time", StringValue ("2s"),
8.144 - "Speed", StringValue ("Constant:1.0"),
8.145 - "Bounds", RectangleValue (Rectangle (wifiX, wifiX+5.0,0.0, (nStas+1)*5.0)));
8.146 - mobility.Install (sta);
8.147 - wifi.SetMac ("ns3::NqstaWifiMac",
8.148 - "Ssid", SsidValue (ssid),
8.149 - "ActiveProbing", BooleanValue (false));
8.150 - staDev = wifi.Install (wifiPhy, sta);
8.151 - staInterface = ip.Assign (staDev);
8.152 -
8.153 - // save everything in containers.
8.154 - staNodes.push_back (sta);
8.155 - apDevices.push_back (apDev);
8.156 - apInterfaces.push_back (apInterface);
8.157 - staDevices.push_back (staDev);
8.158 - staInterfaces.push_back (staInterface);
8.159 -
8.160 - wifiX += 20.0;
8.161 - ip.NewNetwork ();
8.162 - }
8.163 -
8.164 - GlobalRouteManager::PopulateRoutingTables ();
8.165 -
8.166 - Address dest;
8.167 - std::string protocol;
8.168 - dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025);
8.169 - protocol = "ns3::UdpSocketFactory";
8.170 -
8.171 - OnOffHelper onoff = OnOffHelper (protocol, dest);
8.172 - onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
8.173 - onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
8.174 - ApplicationContainer apps = onoff.Install (staNodes[0].Get (0));
8.175 - apps.Start (Seconds (0.5));
8.176 - apps.Stop (Seconds (3.0));
8.177 -
8.178 - YansWifiPhyHelper::EnablePcap ("wns3-example", staNodes[1].Get (1));
8.179 - YansWifiPhyHelper::EnablePcap ("wns3-example", staNodes[0].Get (0));
8.180 - std::ofstream os;
8.181 - os.open ("wns3-example.mob");
8.182 - MobilityHelper::EnableAsciiAll (os);
8.183 -
8.184 - Simulator::Stop (Seconds (100.0));
8.185 - Simulator::Run ();
8.186 - Simulator::Destroy ();
8.187 -}
8.188 -
8.189 -
9.1 --- a/wns3-helper.cc Sun Apr 05 16:27:42 2009 +0200
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,87 +0,0 @@
9.4 -#include <iostream>
9.5 -#include <fstream>
9.6 -#include "ns3/simulator-module.h"
9.7 -#include "ns3/node-module.h"
9.8 -#include "ns3/core-module.h"
9.9 -#include "ns3/helper-module.h"
9.10 -#include "ns3/global-route-manager.h"
9.11 -#include "ns3/contrib-module.h"
9.12 -
9.13 -using namespace ns3;
9.14 -
9.15 -int main (int argc, char *argv[])
9.16 -{
9.17 - CommandLine cmd;
9.18 - cmd.Parse (argc, argv);
9.19 -
9.20 - NodeContainer csmaNodes;
9.21 - csmaNodes.Create (2);
9.22 - NodeContainer wifiNodes;
9.23 - wifiNodes.Add (csmaNodes.Get (1));
9.24 - wifiNodes.Create (3);
9.25 -
9.26 - NetDeviceContainer csmaDevices;
9.27 - CsmaHelper csma;
9.28 - csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
9.29 - csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
9.30 - csmaDevices = csma.Install (csmaNodes);
9.31 -
9.32 - NetDeviceContainer wifiDevices;
9.33 - YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
9.34 - YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
9.35 - wifiPhy.SetChannel (wifiChannel.Create ());
9.36 - WifiHelper wifi = WifiHelper::Default ();
9.37 - wifiDevices = wifi.Install (wifiPhy, wifiNodes);
9.38 -
9.39 - MobilityHelper mobility;
9.40 - mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator",
9.41 - "X", StringValue ("100.0"),
9.42 - "Y", StringValue ("100.0"),
9.43 - "Rho", StringValue ("Uniform:0:30"));
9.44 - mobility.SetMobilityModel ("ns3::StaticMobilityModel");
9.45 - mobility.Install (wifiNodes);
9.46 -
9.47 - Ipv4InterfaceContainer csmaInterfaces;
9.48 - Ipv4InterfaceContainer wifiInterfaces;
9.49 - InternetStackHelper internet;
9.50 - internet.Install (NodeContainer::GetGlobal ());
9.51 - Ipv4AddressHelper ipv4;
9.52 - ipv4.SetBase ("10.1.1.0", "255.255.255.0");
9.53 - csmaInterfaces = ipv4.Assign (csmaDevices);
9.54 - ipv4.SetBase ("10.1.2.0", "255.255.255.0");
9.55 - wifiInterfaces = ipv4.Assign (wifiDevices);
9.56 -
9.57 - GlobalRouteManager::PopulateRoutingTables ();
9.58 -
9.59 - ApplicationContainer apps;
9.60 - OnOffHelper onoff ("ns3::UdpSocketFactory",
9.61 - InetSocketAddress ("10.1.2.2", 1025));
9.62 - onoff.SetAttribute ("OnTime", StringValue ("Constant:1.0"));
9.63 - onoff.SetAttribute ("OffTime", StringValue ("Constant:0.0"));
9.64 - apps = onoff.Install (csmaNodes.Get (0));
9.65 - apps.Start (Seconds (1.0));
9.66 - apps.Stop (Seconds (4.0));
9.67 -
9.68 - PacketSinkHelper sink ("ns3::UdpSocketFactory",
9.69 - InetSocketAddress ("10.1.2.2", 1025));
9.70 - apps = sink.Install (wifiNodes.Get (1));
9.71 - apps.Start (Seconds (0.0));
9.72 - apps.Stop (Seconds (4.0));
9.73 -
9.74 - std::ofstream ascii;
9.75 - ascii.open ("wns3-helper.tr");
9.76 - CsmaHelper::EnableAsciiAll (ascii);
9.77 - CsmaHelper::EnablePcapAll ("wns3-helper");
9.78 - YansWifiPhyHelper::EnablePcapAll ("wsn3-helper");
9.79 -
9.80 - GtkConfigStore config;
9.81 - config.Configure ();
9.82 -
9.83 - Simulator::Stop (Seconds (4.5));
9.84 -
9.85 - Simulator::Run ();
9.86 - Simulator::Destroy ();
9.87 -
9.88 -
9.89 - return 0;
9.90 -}
10.1 --- a/wns3-lowlevel.cc Sun Apr 05 16:27:42 2009 +0200
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,213 +0,0 @@
10.4 -#include <iostream>
10.5 -#include <fstream>
10.6 -#include "ns3/simulator-module.h"
10.7 -#include "ns3/node-module.h"
10.8 -#include "ns3/core-module.h"
10.9 -#include "ns3/csma-module.h"
10.10 -#include "ns3/wifi-module.h"
10.11 -#include "ns3/internet-stack-module.h"
10.12 -#include "ns3/onoff-module.h"
10.13 -#include "ns3/packet-sink-module.h"
10.14 -#include "ns3/mobility-module.h"
10.15 -#include "ns3/global-route-manager.h"
10.16 -#include "ns3/contrib-module.h"
10.17 -#include "ns3/common-module.h"
10.18 -
10.19 -using namespace ns3;
10.20 -
10.21 -static Ptr<CsmaNetDevice>
10.22 -AddCsma (Ptr<Node> node, Ptr<CsmaChannel> channel)
10.23 -{
10.24 - Ptr<CsmaNetDevice> dev = CreateObject<CsmaNetDevice> ();
10.25 - dev->SetAddress (Mac48Address::Allocate ());
10.26 - node->AddDevice (dev);
10.27 - Ptr<Queue> queue = CreateObject<DropTailQueue> ();
10.28 - dev->SetQueue (queue);
10.29 - dev->Attach (channel);
10.30 - return dev;
10.31 -}
10.32 -
10.33 -static Ptr<WifiNetDevice>
10.34 -AddWifi (Ptr<Node> node, Ptr<YansWifiChannel> channel)
10.35 -{
10.36 - Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
10.37 -
10.38 - Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
10.39 - Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
10.40 - phy->SetErrorRateModel (error);
10.41 - phy->SetChannel (channel);
10.42 - phy->SetMobility (node);
10.43 - phy->SetDevice (device);
10.44 -
10.45 - Ptr<WifiRemoteStationManager> manager = CreateObject<ArfWifiManager> ();
10.46 - Ptr<WifiMac> mac = CreateObject<AdhocWifiMac> ();
10.47 - mac->SetAddress (Mac48Address::Allocate ());
10.48 -
10.49 - device->SetMac (mac);
10.50 - device->SetPhy (phy);
10.51 - device->SetRemoteStationManager (manager);
10.52 - node->AddDevice (device);
10.53 -
10.54 - return device;
10.55 -}
10.56 -
10.57 -static Ptr<PositionAllocator>
10.58 -GetPositionAllocator (void)
10.59 -{
10.60 - static Ptr<PositionAllocator> allocator = 0;
10.61 - if (allocator == 0)
10.62 - {
10.63 - allocator = CreateObject<RandomDiscPositionAllocator> ();
10.64 - allocator->SetAttribute ("X", StringValue ("100.0"));
10.65 - allocator->SetAttribute ("Y", StringValue ("100.0"));
10.66 - allocator->SetAttribute ("Rho", StringValue ("Uniform:0:30"));
10.67 - }
10.68 - return allocator;
10.69 -}
10.70 -
10.71 -static void
10.72 -AddMobility (Ptr<Node> node)
10.73 -{
10.74 - Ptr<StaticMobilityModel> mobility = CreateObject<StaticMobilityModel> ();
10.75 - mobility->SetPosition (GetPositionAllocator ()->GetNext ());
10.76 - node->AggregateObject (mobility);
10.77 -}
10.78 -
10.79 -static void
10.80 -AddIpv4Interface (Ptr<NetDevice> device,
10.81 - const char * ip,
10.82 - const char * mask)
10.83 -{
10.84 - Ptr<Node> node = device->GetNode ();
10.85 - Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
10.86 - int32_t ifIndex = ipv4->AddInterface (device);
10.87 - ipv4->SetAddress (ifIndex, Ipv4Address (ip));
10.88 - ipv4->SetNetworkMask (ifIndex, Ipv4Mask (mask));
10.89 - ipv4->SetMetric (ifIndex, 1);
10.90 - ipv4->SetUp (ifIndex);
10.91 -}
10.92 -
10.93 -static Ptr<Application>
10.94 -AddUdpSource (Ptr<Node> node,
10.95 - const char *ip, uint16_t port)
10.96 -{
10.97 - Ptr<OnOffApplication> application = CreateObject<OnOffApplication> ();
10.98 - application->SetAttribute ("Protocol", StringValue ("ns3::UdpSocketFactory"));
10.99 - application->SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address (ip), port)));
10.100 - application->SetAttribute ("OnTime", StringValue ("Constant:1.0"));
10.101 - application->SetAttribute ("OffTime", StringValue ("Constant:0.0"));
10.102 - node->AddApplication (application);
10.103 - return application;
10.104 -}
10.105 -
10.106 -static Ptr<Application>
10.107 -AddUdpSink (Ptr<Node> node, const char *ip, uint16_t port)
10.108 -{
10.109 - Ptr<PacketSink> sink = CreateObject<PacketSink> ();
10.110 - sink->SetAttribute ("Protocol", StringValue ("ns3::UdpSocketFactory"));
10.111 - sink->SetAttribute ("Local", AddressValue (InetSocketAddress (Ipv4Address (ip), port)));
10.112 - node->AddApplication (sink);
10.113 - return sink;
10.114 -}
10.115 -
10.116 -static void PcapPhyRxEvent (Ptr<PcapWriter> writer,
10.117 - Ptr<const Packet> packet, double snr, WifiMode mode,
10.118 - enum WifiPreamble preamble)
10.119 -{
10.120 - writer->WritePacket (packet);
10.121 -}
10.122 -static void PcapPhyTxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet,
10.123 - WifiMode mode, WifiPreamble preamble,
10.124 - uint8_t txLevel)
10.125 -{
10.126 - writer->WritePacket (packet);
10.127 -}
10.128 -
10.129 -
10.130 -static void
10.131 -WifiEnablePcap (Ptr<WifiNetDevice> wifi, const char *filename)
10.132 -{
10.133 - uint32_t nodeId = wifi->GetNode ()->GetId ();
10.134 - uint32_t deviceId = wifi->GetIfIndex ();
10.135 - std::ostringstream oss;
10.136 - oss << filename << "-" << nodeId << "-" << deviceId << ".pcap";
10.137 - Ptr<PcapWriter> pcap = ::ns3::Create<PcapWriter> ();
10.138 - pcap->Open (oss.str ());
10.139 - pcap->WriteWifiHeader ();
10.140 - oss.str ("");
10.141 - oss << "/NodeList/" << nodeId << "/DeviceList/" << deviceId
10.142 - << "/$ns3::WifiNetDevice/Phy/State/Tx";
10.143 - Config::ConnectWithoutContext (oss.str (),
10.144 - MakeBoundCallback (&PcapPhyTxEvent, pcap));
10.145 - oss.str ("");
10.146 - oss << "/NodeList/" << nodeId << "/DeviceList/" << deviceId
10.147 - << "/$ns3::WifiNetDevice/Phy/State/RxOk";
10.148 - Config::ConnectWithoutContext (oss.str (),
10.149 - MakeBoundCallback (&PcapPhyRxEvent, pcap));
10.150 -}
10.151 -
10.152 -int main (int argc, char *argv[])
10.153 -{
10.154 - Ptr<Node> node0 = CreateObject<Node> ();
10.155 - Ptr<Node> node1 = CreateObject<Node> ();
10.156 - Ptr<Node> node2 = CreateObject<Node> ();
10.157 - Ptr<Node> node3 = CreateObject<Node> ();
10.158 - Ptr<Node> node4 = CreateObject<Node> ();
10.159 -
10.160 - Ptr<CsmaChannel> csmaChannel = CreateObject<CsmaChannel> ();
10.161 - csmaChannel->SetAttribute ("DataRate", StringValue ("5Mbps"));
10.162 - csmaChannel->SetAttribute ("Delay", StringValue ("2ms"));
10.163 - Ptr<CsmaNetDevice> csmaDev0 = AddCsma (node0, csmaChannel);
10.164 - Ptr<CsmaNetDevice> csmaDev1 = AddCsma (node1, csmaChannel);
10.165 -
10.166 - Ptr<YansWifiChannel> wifiChannel = CreateObject<YansWifiChannel> ();
10.167 - wifiChannel->SetPropagationDelayModel (CreateObject<ConstantSpeedPropagationDelayModel> ());
10.168 - Ptr<PropagationLossModel> loss = CreateObject<LogDistancePropagationLossModel> ();
10.169 - wifiChannel->SetPropagationLossModel (loss);
10.170 -
10.171 - Ptr<WifiNetDevice> wifiDev0 = AddWifi (node1, wifiChannel);
10.172 - Ptr<WifiNetDevice> wifiDev1 = AddWifi (node2, wifiChannel);
10.173 - Ptr<WifiNetDevice> wifiDev2 = AddWifi (node3, wifiChannel);
10.174 - Ptr<WifiNetDevice> wifiDev3 = AddWifi (node4, wifiChannel);
10.175 -
10.176 - AddMobility (node1);
10.177 - AddMobility (node2);
10.178 - AddMobility (node3);
10.179 - AddMobility (node4);
10.180 -
10.181 - AddInternetStack (node0);
10.182 - AddInternetStack (node1);
10.183 - AddInternetStack (node2);
10.184 - AddInternetStack (node3);
10.185 - AddInternetStack (node4);
10.186 -
10.187 - AddIpv4Interface (csmaDev0, "10.1.1.1", "255.255.255.0");
10.188 - AddIpv4Interface (csmaDev1, "10.1.1.2", "255.255.255.0");
10.189 - AddIpv4Interface (wifiDev0, "10.1.2.1", "255.255.255.0");
10.190 - AddIpv4Interface (wifiDev1, "10.1.2.2", "255.255.255.0");
10.191 - AddIpv4Interface (wifiDev2, "10.1.2.3", "255.255.255.0");
10.192 - AddIpv4Interface (wifiDev3, "10.1.2.4", "255.255.255.0");
10.193 -
10.194 - GlobalRouteManager::PopulateRoutingTables ();
10.195 -
10.196 - Ptr<Application> app;
10.197 - app = AddUdpSource (node0, "10.1.2.2", 1025);
10.198 - app->Start (Seconds (1.0));
10.199 - app->Stop (Seconds (4.0));
10.200 - app = AddUdpSink (node2, "10.1.2.2", 1025);
10.201 - app->Start (Seconds (0.0));
10.202 - app->Stop (Seconds (4.0));
10.203 -
10.204 - WifiEnablePcap (wifiDev2, "wns3-lowlevel");
10.205 -
10.206 - GtkConfigStore config;
10.207 - config.Configure ();
10.208 -
10.209 - Simulator::Stop (Seconds (4.5));
10.210 -
10.211 - Simulator::Run ();
10.212 - Simulator::Destroy ();
10.213 -
10.214 -
10.215 - return 0;
10.216 -}