1# Introduction 2 3This is a wireless medium simulation tool for Linux, based on the netlink API 4implemented in the `mac80211_hwsim` kernel driver. Unlike the default in-kernel 5forwarding mode of `mac80211_hwsim`, wmediumd allows simulating frame loss and 6delay. 7 8This version is forked from an earlier version, hosted here: 9 10 https://github.com/cozybit/wmediumd 11 12# Prerequisites 13 14First, you need a recent Linux kernel with the `mac80211_hwsim` module 15available. If you do not have this module, you may be able to build it using 16the [backports project](https://backports.wiki.kernel.org/index.php/Main_Page). 17 18Wmediumd requires libnl3.0. 19 20# Building 21``` 22cd wmediumd && make 23``` 24 25# Using Wmediumd 26 27Starting wmediumd with an appropriate config file is enough to make frames 28pass through wmediumd: 29``` 30sudo modprobe mac80211_hwsim radios=2 31sudo ./wmediumd/wmediumd -c tests/2node.cfg & 32# run some hwsim test 33``` 34However, please see the next section on some potential pitfalls. 35 36A complete example using network namespaces is given at the end of 37this document. 38 39# Configuration 40 41Wmediumd supports multiple ways of configuring the wireless medium. 42 43## Perfect medium 44 45With this configuration, all traffic flows between the configured interfaces, identified by their mac address: 46 47``` 48ifaces : 49{ 50 ids = [ 51 "02:00:00:00:00:00", 52 "02:00:00:00:01:00", 53 "02:00:00:00:02:00", 54 "02:00:00:00:03:00" 55 ]; 56}; 57``` 58 59## Per-link loss probability model 60 61You can simulate a slightly more realistic channel by assigning fixed error 62probabilities to each link. 63 64``` 65ifaces : 66{ 67 ids = [ 68 "02:00:00:00:00:00", 69 "02:00:00:00:01:00", 70 "02:00:00:00:02:00", 71 "02:00:00:00:03:00" 72 ]; 73}; 74 75model: 76{ 77 type = "prob"; 78 79 default_prob = 1.0; 80 links = ( 81 (0, 2, 0.000000), 82 (2, 3, 0.000000) 83 ); 84}; 85``` 86 87The above configuration would assign 0% loss probability (perfect medium) to 88all frames flowing between nodes 0 and 2, and 100% loss probability to all 89other links. Unless both directions of a link are configured, the loss 90probability will be symmetric. 91 92This is a very simplistic model that does not take into account that losses 93depend on transmission rates and signal-to-noise ratio. For that, keep reading. 94 95## Per-link signal-to-noise ratio (SNR) model 96 97You can model different signal-to-noise ratios for each link by including a 98list of link tuples in the form of (sta1, sta2, snr). 99 100``` 101ifaces : 102{ 103 ids = [ 104 "02:00:00:00:00:00", 105 "02:00:00:00:01:00", 106 "02:00:00:00:02:00", 107 "02:00:00:00:03:00" 108 ]; 109 110 links = ( 111 (0, 1, 0), 112 (0, 2, 0), 113 (2, 0, 10), 114 (0, 3, 0), 115 (1, 2, 30), 116 (1, 3, 10), 117 (2, 3, 20) 118 ); 119}; 120``` 121The snr will affect the maximum data rates that are successfully transmitted 122over the link. 123 124If only one direction of a link is configured, then the link will be 125symmetric. For asymmetric links, configure both directions, as in the 126above example where the path between 0 and 2 is usable in only one 127direction. 128 129The packet loss error probabilities are derived from this snr. See function 130`get_error_prob_from_snr()`. Or you can provide a packet-error-rate table like 131the one in `tests/signal_table_ieee80211ax` 132 133## Path loss model 134 135The path loss model derives signal-to-noise and probabilities from the 136coordinates of each node. This is an example configuration file for it. 137 138``` 139ifaces : {...}; 140model : 141{ 142 type = "path_loss"; 143 positions = ( 144 (-50.0, 0.0), 145 ( 0.0, 40.0), 146 ( 0.0, -70.0), 147 ( 50.0, 0.0) 148 ); 149 directions = ( 150 ( 0.0, 0.0), 151 ( 0.0, 10.0), 152 ( 0.0, 10.0), 153 ( 0.0, 0.0) 154 ); 155 tx_powers = (15.0, 15.0, 15.0, 15.0); 156 157 model_name = "log_distance"; 158 path_loss_exp = 3.5; 159 xg = 0.0; 160}; 161``` 162 163## Gotchas 164 165### Allowable MAC addresses 166 167The kernel only allows wmediumd to work on the second available hardware 168address, which has bit 6 set in the most significant octet 169(i.e. 42:00:00:xx:xx:xx, not 02:00:00:xx:xx:xx). Set this appropriately 170using 'ip link set address'. 171 172This issue was fixed in commit cd37a90b2a417e5882414e19954eeed174aa4d29 173in Linux, released in kernel 4.1.0. 174 175### Rates 176 177wmediumd's rate table is currently hardcoded to 802.11a OFDM rates. 178Therefore, either operate wmediumd networks in 5 GHz channels, or supply 179a rateset for the BSS with no CCK rates. 180 181### Send-to-self 182 183By default, traffic between local devices in Linux will not go over 184the wire / wireless medium. This is true of vanilla hwsim as well. 185In order to make this happen, you need to either run the hwsim interfaces 186in separate network namespaces, or you need to set up routing rules with 187the hwsim devices at a higher priority than local forwarding. 188 189`tests/test-001.sh` contains an example of the latter setup. 190 191# Example session 192 193The following sequence of commands establishes a two-node mesh using network 194namespaces. 195``` 196sudo modprobe -r mac80211_hwsim 197sudo modprobe mac80211_hwsim 198sudo ./wmediumd/wmediumd -c ./tests/2node.cfg 199 200# in window 2 201sudo lxc-unshare -s NETWORK bash 202ps | grep bash # note pid 203 204# in window 1 205sudo iw phy phy2 set netns $pid 206 207sudo ip link set wlan1 down 208sudo iw dev wlan1 set type mp 209sudo ip link set addr 42:00:00:00:00:00 dev wlan1 210sudo ip link set wlan1 up 211sudo ip addr add 10.10.10.1/24 dev wlan1 212sudo iw dev wlan1 set channel 149 213sudo iw dev wlan1 mesh join meshabc 214 215# in window 2 216ip link set lo 217 218sudo ip link set wlan2 down 219sudo iw dev wlan2 set type mp 220sudo ip link set addr 42:00:00:00:01:00 dev wlan2 221sudo ip link set wlan2 up 222sudo ip addr add 10.10.10.2/24 dev wlan2 223sudo iw dev wlan2 set channel 149 224sudo iw dev wlan2 mesh join meshabc 225 226iperf -u -s -i 10 -B 10.10.10.2 227 228# in window 1 229iperf -u -c 10.10.10.2 -b 100M -i 10 -t 120 230``` 231