Ns3 Part4 Wireless
Ns3 Part4 Wireless
Ns3 Part4 Wireless
th
ns-3 Tutorial (Part IV) Wireless & Tracing System and Visualizing Results
JCSSE 2011's tutorials and workshops Wednesday, 11 May 2011, 9:00 - 16:00
Time Table
09:00 - 10:15 ns-3 Introduction & Installation 10:15 - 10.30 Break 10:30 - 12:00 Hands-On: Point-to-point and CSMA (Ethernet) 12:00 - 13:00 Lunch 13:00 - 14:15 Hands-On: Wireless & Tracing System and Visualizing Results 14:15 - 14:30 Break 14:30 - 15:30 Demonstation: ns-3 protocol stack modification 15:30 - 16:00 Q&A
Outline
Wireless modules overview Tracing with Trace Helpers Creating custom tracers Visualizing and analyzing results Walk-through examples Hands-on exercise
Tracing Overview
ns-3 provides a set of pre-congured trace sources Users provide trace sinks and attach to the trace source Multiple trace sources can connect to a trace sink
High-level
Use a helper to hook a predefined trace source to an existing trace sink (e.g., ascii, pcap) Hook an existing trace source to a custom trace sink Add a new trace source and connect it to a special trace sink
Mid-level
Low-level
Trace Helpers
Task: model the network topology below in ns-3 and capture ECHO packets transmitted from N7 to N4
N2 N0 N5 N3 N4 N1
10.1.1.0/24
N6
N7
10
Dissecting third.cc
main (int argc, char *argv[]) { bool verbose = true; uint32_t nCsma = 3; uint32_t nWifi = 3; CommandLine cmd; cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); cmd.Parse (argc,argv);
11
Dissecting third.cc
NodeContainer wifiStaNodes; wifiStaNodes.Create (nWifi); NodeContainer wifiApNode = p2pNodes.Get (0); YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); phy.SetChannel (channel.Create ()); WifiHelper wifi = WifiHelper::Default (); wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
12
Dissecting third.cc
13
Dissecting third.cc
All wireless nodes must be associated with mobility MobilityHelper provides a lot of help
(MinX, MinY)
MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", DeltaY "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), 4 "DeltaX", DoubleValue (5.0), "DeltaY", DoubleValue (10.0), "GridWidth", UintegerValue (3), "LayoutType", StringValue ("RowFirst"));
DeltaX
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50))); mobility.Install (wifiStaNodes);
14
Create a copy of third.cc into the scratch dir and rename it to pm-ex1.cc
$ cp examples/tutorials/third.cc scratch/pm-ex1.cc
pointToPoint.EnablePcapAll ("pm-ex1"); phy.EnablePcap ("pm-ex1", apDevices.Get (0)); csma.EnablePcap ("pm-ex1", csmaDevices.Get (0), true);
15
16
17
18
19
Task: Using the previous topology, replace ECHO traffic with CBR (Constant Bit Rate) traffic
N2 N0 N3 N4
10.1.1.0/24
N1
N5
N6
N7
20
21
22
Connect a custom trace sink to PacketSink's Rx trace source Compute average throughput from first and last packets' timestamps total bytes received
23
In ns-3 Doxygen, look for ns3::PacketSink (either via Class List or List of Trace Sources)
24
We now know that PacketSink object already comes with a trace source, called Rx We need to write a callback function to serve as a trace sink
PacketSink Object Trace Source
Callback Signature
$ find examples/ -name "*.cc" -exec grep -H PacketSink/Rx {} \; examples/csma/csma-ping.cc: Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", examples/csma/csma-packet-socket.cc: Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx", examples/csma/csma-raw-ip-socket.cc: Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", : :
static void SinkRx (Ptr<const Packet> p, const Address &ad) { //std::cout << *p << std::endl; }
26
Callback Signature
Either way, we now know that our callback's signature should be:
void Callback(Ptr<const Packet>, const Address &)
27
28
29
30
Modify the source so that OnOff application is installed on all WiFi stations
31
Try running the script with various values specified for nWifi argument suppress stderr
messages
32
Create a shell-script, named run-all.sh, that runs the simulation with different values for nWifi
#!/bin/bash for ((i=2; i<=14; i += 2)); do waf --run "pm-ex4 --nWifi=$i" done
33
34
Change x-axis to load, Polish the plot: turn on grid, turn off legend
#!/usr/bin/gnuplot set terminal png set output 'graph.png' set xrange [0:] set yrange [0:] set xlabel 'Load (kb/s)' set ylabel 'Average Throughput (kb/s)' set grid plot 'results.dat' using ($4*512):8 with lines notitle
35
36
37
Hands-on Exercise
38