###### tags: `Simulation - WIFI`
# Mininet-WIFI introduction
# Resources
## Github
https://github.com/intrig-unicamp/mininet-wifi
### Pre-configured Virtual Machine
For your convenience, we provide pre-built VM images including Mininet-WiFi and other useful software. The VM images are in .ova format and should be usable with any modern x64 virtualization system.
[[3.4GB Size\] - Lubuntu 20.04 x64](https://drive.google.com/file/d/1R8n4thPwV2krFa6WNP0Eh05ZHZEdhw4W/view?usp=sharing) - Mininet-WiFi (*password: wifi*)
[[6.7GB Size\] - Lubuntu 20.04 x64](https://drive.google.com/file/d/1oozRqFO2KjjxW0Ob47d6Re4i6ay1wdwg/view?usp=sharing) - Mininet-WiFi with P4 (*password: wifi*)
### Note
Mininet-WiFi should work fine in any Ubuntu distribution from 14.04, but in some cases (only if you have problems when start it) you have to stop *Network Manager* with either `sudo systemctl stop network-manager` or `sudo service network-manager stop`.
## Online Doc
https://mininet-wifi.github.io/
## Book
https://github.com/ramonfontes/mn-wifi-ebook/
## The User Manual
https://usermanual.wiki/Pdf/mininetwifidraftmanual.297704656.pdf
# Mininet Inro
https://www.brianlinkletter.com/2013/11/mininet-test-drive/
To create a network topology with four virtual machines connected to a switch, enter the command:
```
$ sudo mn --topo=single,4
```
### Mininet commands
- *help*: lists the mininet commands
- *dump*: lists information about the nodes, switches, and controllers in the simulated network.
- *nodes*: lists the names of the network elements in the simulated network
- *net*: shows how network elements are connected to each other in the simulated network.
### Run commands on hosts
"h1" is the host name.
```
mininet> h1 pwd
/home/mininet
```
```
mininet> h1 ls
install-mininet-vm.sh
mininet
of-dissector
oflops
oftest
openflow
pox
mininet>
```
### Interacting with hosts
```
mininet> xterm h1
```
```
mininet> xterm h2 h3 h4
```
### h1 ping h2 on the Wireshark
On the Wireshark, the packets are only in h1 and h2 interfaces. (Or use the interface: any.)
On the Wireshark, don't monitor switches(s1 s2 s3 ...). It will crash.
### Simulating a large network
```
$ sudo mn --topo tree,depth=3,fanout=4
```
### Mininet and routing
A good example of this functionality is provided by the [RouteFlow project](https://sites.google.com/site/routeflow/).
### Mininet tutorials
The [Mininet web site](http://mininet.org/) offers some very good tutorials to help new users understand how to use Mininet. For more details about using Mininet and about OpenFlow controllers, please see the [Mininet walkthrough](http://mininet.org/walkthrough/) tutorial and the [Openflow tutorial](http://archive.openflow.org/wk/index.php/OpenFlow_Tutorial).
### Conclusion
As a simulator for Software Defined Networking, Mininet seems to work well. However, Mininet — as it is provided by the Mininet project without modification — will not simulate a “traditional” IP network composed of hosts, switches, and routers.
# Mininet-WIFI Intro
https://www.brianlinkletter.com/2016/04/mininet-wifi-software-defined-network-emulator-supports-wifi-networks/
You will have to install additional tools and follow a complex procedure to [enable monitoring of WiFi traffic on the *ap1-wlan0* interface](https://wiki.wireshark.org/CaptureSetup/WLAN#Linux)
An easier method is available: look for the *hwsim0* interface on an access point, enable it, and monitor traffic on it. The *hwsim0* interface replays communications
Mininet-WiFi : has graph
Mininet : has no graph
### STOP Tutorial
Stop Mininet-Wifi and clean up the system with the following commands:
```
mininet-wifi> exit
wifi:~$ sudo mn -c
```
### Tutorial #1: 1 AP, 2 STAs
To view wireless control traffic we must first start Wireshark:
```
wifi:~$ sudo wireshark &
```
Then, start Mininet-WiFi with the default network scenario using the command below:
```
wifi:~$ sudo mn --wifi
```
Next, enable the *hwsim0* interface. The *hwsim0* interface is the software interface created by Mininet-WiFi that copies all wireless traffic to all the virtual wireless interfaces in the network scenario. It is the easiest way to monitor the wireless packets in Mininet-WiFi.
```
mininet-wifi> sh ifconfig hwsim0 up
```
Now, in Wireshark, refresh the interfaces and then start capturing packets on the *hwsim0* interface.
Next, tun a *ping* command:
```
mininet-wifi> sta1 ping sta2
```
**Note: No packets on lo(loopback), in other words: no packets to OpenFlow-enabled switches**
### Tutorial #2: Multiple access points
In this tutorial, we will create a linear topology with three access points, where one station is connected to each access point.
```
wifi:~$ sudo mn --wifi --topo linear,3
```
For example, we can run the *net* command to see the connections between nodes:
```
mininet-wifi> net
sta1 sta1-wlan0:None
sta2 sta2-wlan0:None
sta3 sta3-wlan0:None
ap1 lo: ap1-eth1:ap2-eth1
ap2 lo: ap2-eth1:ap1-eth1 ap2-eth2:ap3-eth1
ap3 lo: ap3-eth1:ap2-eth2
c0
```
To check which access points are “visible” to each station, use the *iw scan* command:
```
mininet-wifi> sta1 iw dev sta1-wlan0 scan | grep ssid
SSID: ssid_ap1
SSID: ssid_ap2
SSID: ssid_ap3
```
Verify the access point to which each station is currently connected ...
```
mininet-wifi> sta1 iw dev sta1-wlan0 link
Connected to 02:00:00:00:03:00 (on sta1-wlan0)
SSID: ssid_ap1
freq: 2412
RX: 1853238 bytes (33672 packets)
TX: 7871 bytes (174 packets)
signal: -30 dBm
tx bitrate: 54.0 MBit/s
bss flags: short-slot-time
dtim period: 2
beacon int: 100
mininet-wifi>
```
==A simple mobility scenario==
Manually switch the *sta1* association from *ap1* to *ap2* ...
```
mininet-wifi> sta1 iw dev sta1-wlan0 disconnect
mininet-wifi> sta1 iw dev sta1-wlan0 connect ssid_ap2
```
We see that *sta1* is now associated with *ap2*.
```
mininet-wifi> sta1 iw dev sta1-wlan0 link
Connected to 02:00:00:00:04:00 (on sta1-wlan0)
SSID: ssid_ap2
freq: 2412
RX: 112 bytes (4 packets)
TX: 103 bytes (2 packets)
signal: -30 dBm
tx bitrate: 1.0 MBit/s
bss flags: short-slot-time
dtim period: 2
beacon int: 100
mininet-wifi>
```
sta3 ping sta1
```
> xterm sta3
> ping 10.0.0.1
```
dump flow
```
mininet-wifi> dpctl dump-flows
```
sta1 connect to ap1
```
mininet-wifi> sta1 iw dev sta1-wlan0 disconnect
mininet-wifi> sta1 iw dev sta1-wlan0 connect ssid_ap1
```
sta3 ping sta1 failed
```
ping is stopped.
```
delete flow
```
mininet-wifi> dpctl del-flows
```
ping is back!!
We will need to us a more advanced remote controller, such as OpenDaylight, to enable station mobility ...
### Tutorial #3: Python API and scripts
Mininet provides a Python API.
Mininet-WiFi extends this API.
```
sta2 = net.addStation('sta2', mac='00:00:00:00:00:02', **sta2_args)
ap1 = net.addAccessPoint('ap1', ssid='ssid-ap1', channel='1', position='15,30,0')
```
Add an access point and specify the wireless encryption method, SSID, wireless mode, channel, position, and radio range:
```
net.addAccessPoint( 'ap1', passwd='123456789a', encrypt='wpa2', ssid= 'ap1-ssid', mode= 'g', channel= '1', position='30,30,0', range=30 )
```
Add a wireless association between a station and an access point and specifiy link properties of maximum bandwidth, error rate, and delay:
```
net.addLink( ap1, sta1, bw='11Mbps', loss='0.1%', delay='15ms' )
```
For example, use the following method to use the *strongest signal first* when determining connections between station and access points:
```
net.associationControl( 'ssf' )
```
#### Classic Mininet API
The Mininet WiFi Python API still supports the standard Mininet node types — switches, hosts, and controllers. For example:
Add a host. Note that the station discussed above is a type of host nodem with a wireless interface instead of an Ehternet interface.
```
net.addHost( 'h1' )
```
Add a switch. Note that the access point discussed above is a type of switch that has one wireless interface (*wlan0*) and any number of Ethernet interfaces (up to the maximum supported by your installed version of Open vSwitch).
```
net.addSwitch( 's1' )
```
Add an Ethernet link between two nodes. Note that if you use *addLink* to connect two access points together (and are using the default Infrastructure mode), Mininet-WiFi creates an Ethernet link between them.
```
net.addLink( s1, h1 )
```
Add a controller:
```
net.addController( 'c0' )
```
#### Working with Mininet-WiFi during runtime
Mininet-WiFi python scripts may be run from the command line by running the script directly, or by calling it as part of a Python command. The only difference is how the path is stated. For example:
```
wifi:~/scripts $ sudo ./position-test.py
```
or,
```
wifi:~$ sudo python position-test.py
```
#### Mininet-WiFi CLI: Distance
```
mininet-wifi> distance ap1 sta2
The distance between ap1 and sta2 is 41.23 meters
```
#### Mininet-WiFi Python runtime interpreter
```
mininet-wifi> py ap1.range
```
#### Changing the network during runtime
![](https://raw.githubusercontent.com/mininet-wifi/mininet-wifi.github.io/master/assets/img/arch.png)