Linux - WAN Network Simulator

WAN Network

 

Why do do you need a WAN network simulator?

Applications usually work well on the Local Area Network (LAN) where there’s plenty of bandwidth and very little latency or packet loss. Although, when you run them over a Wide Area Network (WAN) with long delays and limited bandwidth, they can crawl or even halt.

A WAN simulator simulates a long distance link so you can test applications in your lab, or even in your own office, to see how they’ll perform for users across a city, region or on the other side of the world.

 

Linux WAN Simulator (WANsim) Project

This project is mainly run by a bash script that shows a menu upon login, allowing you to to select bandwidth, latency and packet loss and then sets those settings for the WAN, which is simulated by a Linux layer-2 bridge. The script is designed to be run in place of a normal user account login shell, so a command line interface isn't available.

The script uses Linux Quality of Service (QoS) tc commands in the background to dynamically change the characteristics of the traffic flow. So, when the changes are set via the menu, the changes take place in real time. This allows you to also dynamically test your applications, simulating various network conditions, such as link fail-overs, network device outages and so forth.

To use this WANsim, you need to send traffic across the layer-2 bridge so the QoS settings will take affect while traveling through the WAN interface. The LAN and WAN interfaces don't have IP addresses. This design allows the WANsim to be transparent on the network and seem like a continuous cable from a routing perspective.

 

Installation Prerequisites

The following items are needed to successfully build your own WANsim:

  • Physical computer or virtual machine
  • Any Linux distribution - the smaller the better
  • SSH server - for remote access
  • brutils package - Linux bridging package
  • Three physical or virtual network interfaces
    • Management - to access your WANsim (will have an IP address)
    • LAN interface - attached to your "fast, local" network
    • WAN interface - attached to your "slow, long-distance" network

 

Setup and Configuration

The following steps will guide you through creating your very own WANsim. 

1. Install your Linux operating system and assign an IP address to your management interface. There are many tutorials about Linux installations and network configuration out on the big, wide Internet. Google is your friend! 

2. Access your new Linux system using SSH using an account with root privileges (sudo). This is required to compete the configuration. There are lots of tutorials for using sudo and configuring SSH, so again... Google is still your friend! 

3. Create a layer-2 bridge between two interfaces so that the traffic simulation is transparent to the endpoint systems. See my Linux - Create a Linux Bridge Hub page for instructions about how to create a Linux bridge. Once the bridge is created, the results should be similar to the following:

    user@wansim# brctl show
    bridge name     bridge id           STP enabled     interfaces
    wanbr1          8000.0250011126e2   yes             eth1 eth2

4. Create a user that will only be used to run the WANsim script. Then assign the user a password

    user@wansim:/# adduser wansimuser
    user@wansim:/# passwd wansimuser
 
5. Download the WAN Emulator script - wansim-config-v2.sh from my GitHub page here.

6. Copy the wansim-config-v2.sh file to a directory in the wansimuser home directory.    

    user@wansim:/home/wansimuser# mkdir scripts
    user@wansim:/home/wansimuser# cd scripts/
    user@wanem:/home/wanemuser/scripts/# mv ./Downloads/wansim-config-v2.sh /home/wansimuser/scripts/wansim-config-v2.sh

7. Change the permissions so that only wansimuser can execute it.

    user@wansim:/home/wasimuser/scripts/# chmod 700 wansim-config.sh

8. Using a text editor, change the shell parameter for wansimuser in the /etc/password file to the name of the WANsim script. This tells the system to run the script as the user's "shell" instead of a command line interface.
 
    user@wansim:/home/wanemuser/scripts/# nano /etc/password

    OLD - wansimuser:x:502:502::/home/wansimuser:/bin/bash
    NEW - wansimuser:x:502:502::/home/wansimuser:/home/wansimuser/scripts/wansim-config-v2.sh

9. Add the user to the wheel administrator's group. This allows the wansimuser to change QoS settings on a network interface.

    user@wanem:/home/wansimuser/scripts/# usermod -a -G wheel wansimuser

10. Test by logging in using a second SSH session with the newly created wansimuser username and password. The script will run in place of an interactive shell.

          >>>> WANSIM CONFIGURATION MENU <<<< 
    Please choose from the following options:

    1. Typical WAN      BW: 500 kbps  DLY: ~100ms  LOSS: 0.5%
    2. LFN WAN (T1)     BW: 1.5 mbps  DLY: ~10ms   LOSS: 1%
    3. Satellite WAN    BW: 2 mbps    DLY: ~500ms  LOSS: 2%
    4. Typical LAN      BW: 100 mbps  DLY: < ~5ms  LOSS: 0%

    S. Show Correct Settings
    C. Custom Bandwidth and Latency - Choose your own!
    D. Defaults  - Revert All WAN Networks to Original Settings
    Q. Quit menu and close console window

    Enter choice [1,2,3,4,s,c,d,q]
 

11. Choose the simulation option for your testing. Enjoy using passing network traffic across your new WANsim!

 

NOTE:

Remember that this WANsim is a layer-2 bridge (basically a 2-port network switch), so both the LAN and WAN interfaces will be on the same network layer-3 subnet. This creates the possibility for network loops, so be careful which ports you connect your WANsim to. For more information see Geek University's What is a network bridge? page.