Network simulations with
Keefer Rourke
2020.11.24 - Guelph Coding Community
What we’re going to cover
Computer Networks 101
The OSI network model
Layer | Purpose | Sample Protocols |
Application | Useful user-facing stuff! | HTTP |
Presentation | Translating data for use in applications | SSL/TLS |
Session | Connection management | Sockets, proxies |
Transport | Message segmentation/desegmentation | TCP, UDP |
Network | Routing data between networks | IP, BGP |
Data Link | Establishing topology | 802.1 x MAC, ARP |
Physical | Physical connections and signals | 802.1x PHY |
Types of networks
Types of routing
Type | What | Picture |
unicast | One-to-one (selective) transmission between nodes. | |
broadcast | One-to-all (non-selective) transmission between nodes. | |
multicast | One-to-many (selective) transmission between nodes. | |
anycast | One-to-one (of many) transmission between nodes. | |
Wireless ad hoc networks
Mobile ad hoc networks (MANETs)
Physical properties of MANETs
Simulation programming for beginners
Specifying a simulation
ns-3 programming
Some things to keep in mind:
Aside: Modern C++ programming
Aside: Modern C++ programming
Getting started with ns-3
Step 1: Get it.
Getting started with ns-3
Step 1: Get it.
bake.py:
Getting started with ns-3
Step 1: Get it.
By git:
*ns-3 encourages you to write your scripts directly in their source distributions… More on this later.
Getting started with ns-3
Step 1: Get it.
By tarball:
$ wget https://www.nsnam.org/release/ns-allinone-3.32.tar.bz2
$ tar xjvf ns-allinone-3.32.tar.bz2
$ cd ns-allinone-3.32
$ python3 ./build.py --enable-examples
Getting started with ns-3
Step 2: Understand some weirdnesses
# typical c/c++ project
# structure
my_project/
├── build/
├── src/
├── include/
├── dep-1/
├── dep-2/
└── CMakeLists.txt
# ns-3 project structure
ns-allinone-3.32/
└── ns-3.32/
├── scratch/
│ ├── your-src/
│ └── scratch-simulator.cc
├── …
├── wscript
└── waf
It is misleading and unhelpful to call ns-3 simulations “scripts”.
… but we’re going to do that anyway.
Getting started with ns-3
Step 2: Understand some weirdnesses
# typical c/c++ project
# structure
my_project/
├── build/
├── src/
├── include/
├── dep-1/
├── dep-2/
└── CMakeLists.txt
# ns-3 project structure
ns-allinone-3.32/
└── ns-3.32/
├── scratch/
│ ├── your-src/
│ └── scratch-simulator.cc
├── …
├── wscript
└── waf
Getting started with ns-3
Step 3: Build and run your first “script”
$ pwd
/home/user/project/ns-allinone-3.32/ns-3.32/
$ ./waf --run examples/tutorial/first
Waf: Entering directory `/home/user/project/ns-allinone-3.32/ns-3.32/build'
Waf: Leaving directory `/home/user/ns-allinone-3.32/ns-3.32/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (1.369s)
At time +2s client sent 1024 bytes to 10.1.1.2 port 9
At time +2.00369s server received 1024 bytes from 10.1.1.1 port 49153
Getting started with ns-3
Step 3: Build and run your first “script”
$ ./waf --run does-not-exist 2>&1 | tr ',' '\n'
So you want to write a simulation?
Aside: COM Programming in ns-3
The Component Object Model is:
* except that ns-3 COM doesn’t...
Aside: COM Programming in ns-3
Key ideas:
Aside: COM Programming in ns-3
Suppose you want to change the packet queue size of particular node in a network to see if there would be a performance impact...
// Set up code. Let’s make a node with a Wifi device and packet queue.
using namespace ns3;
Ptr<Node> n = CreateObject<Node>();
Ptr<WifiNetDevice> net0 = CreateObject<WifiNetDevice>();
n->AddDevice (net0);
Ptr<Queue<Packet>> q = CreateObject<DropTailQueue<Packet>>();
net0->AddQueue(q);
Aside: COM Programming in ns-3
Suppose you want to change the packet queue size of particular node in a network to see if there would be a performance impact...
// Retrieve the queue and set the attribute.
PointerValue ptr;
net0->GetAttribute("TxQueue", ptr);
Ptr<Queue<Packet>> txQueue = ptr.Get<Queue<Packet>>();
txQueue->SetAttribute("MaxSize",
QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, 80));
Aside: COM Programming in ns-3
Suppose you want to change the packet queue size of particular node in a network to see if there would be a performance impact...
// Retrieve the queue and set the attribute.
PointerValue ptr;
net0->GetAttribute("TxQueue", ptr);
Ptr<Queue<Packet>> txQueue = ptr.Get<Queue<Packet>>();
txQueue->SetAttribute("MaxSize", StringValue("80p"));
Aside: COM Programming in ns-3
Suppose you want to change the packet queue size of particular node in a network to see if there would be a performance impact…
This is made possible by the runtime type-system, so you can save yourself some typing.
// Just set the attribute directly...?
Config::Set("/NodeList/0/DeviceList/0/TxQueue/MaxSize", StringValue("80p")
// Even for all instances?
Config::Set("ns3::QueueBase::MaxSize", StringValue("80p")
Aside: COM Programming in ns-3
Suppose you want to mess with something on a particular instance of a broader interface...
// Retrieve the queue and perform a safe downcast.
PointerValue ptr;
net0->GetAttribute("TxQueue", ptr);
Ptr<Queue<Packet>> txQueue = ptr.Get<Queue<Packet>>();
Ptr<DropTailQueue<Packet>> dtq = txQueue->GetObject<DropTailQueue<Packet>>();
NS_ASSERT(dtq != 0);
Aside: COM Programming in ns-3
ns-3 models and classes
ns-3 has extensive class reference docs here:
Broadly speaking, every part of the OSI Network Model is represented somehow.
Generally there are “helpers” which make it is bit easier to set up networks with a collection of nodes.
ns-3 models and classes
Nodes and NodeContainers
ns-3 models and classes
Helper classes
Understanding simulation results
Animation and visualization
Two animation interfaces:
Packet captures
Your first simulation
Recipe for a simulation
using namespace ns3;
int main(int argc, char* argv[]) {
// Get options.
CommandLine cmd;
…
cmd.Parse(argc, argv);
// Set up nodes.
NodeContainer nodes;
...
// Add the animation interface.
AnimationInterface animation("anim-trace-file.xml");
// Run the simulation.
Simulator::Stop(Seconds(10));
Simulator::Run();
Simulator::Destroy();
return EX_OK;
}
Demo time.
Simulating MANETs
Simulating MANETs
Mobility
Model is concerned with:
Some available models:
For the most part we are only interested in RandomWaypoint and RandomWalk2d.
Mobility models
Some interesting examples.
Random waypoint
Jitter�(RandomWalk2D default)
Walk over area�(RandomWalk2D)
Travellers between partitions on 3x3 grid
Mobility models
Underlying implementation supports 3D movement, but the visualization tools do not appear to.
Routing
Various routing algorithms have been designed for use in MANETs and other distributed networks
Recipe for ad hoc network simulations
using namespace ns3;
int main(int argc, char* argv[]) {
…
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetPcapDataLinkType(YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
auto wifiChannel = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType("ns3::AdhocWifiMac");
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211b);
…
return EX_OK;
}
Demo time.
Pro tips
Limitations and aggravations
Buyer beware
Wide open-field
Simulation studies vary greatly
Questions?