Augmented Traffic Control: A tool to simulate network conditions
Full documentation for the project is available at http://facebook.github.io/augmented-traffic-control/.
Augmented Traffic Control (ATC) is a tool to simulate network conditions. It allows controlling the connection that a device has to the internet. Developers can use
ATCto test their application across varying network conditions, easily emulating high speed, mobile, and even severely impaired networks. Aspects of the connection that can be controlled include:
In order to be able to shape the network traffic, ATC must be running on a device that routes the traffic and sees the real IP address of the device, like your network gateway for instance. This also allows any devices that route through
ATCto be able to shape their traffic. Traffic can be shaped/unshaped using a web interface allowing any devices with a web browser to use
ATCwithout the need for a client application.
atcdexposes a Thrift interface to interact with it. *
django-atc-api: A Django app based on Django Rest Framework that provides a RESTful interface to
django-atc-demo-ui: A Django app that provides a simple Web UI to use
atcfrom a mobile phone. *
django-atc-profile-storage: A Django app that can be used to save shaping profiles, making it easier to re-use them later without manually re-entering those settings.
ATCin sub-components, it make it easier to hack on it or build on top of it. While
django-atc-demo-uiis shipped as part of
ATC's main repository to allow people to be able to use
ATCout of the box, by providing a REST API to
atcd, it makes it relatively easy to interact with
atcdvia the command line and opens the path for the community to be able to build creative command line tools, web UI or mobile apps that interact with
Most requirements are handled automatically by pip, the packaging system used by ATC, and each
ATCpackage may have different requirements and the README.md files of the respective packages should be checked for more details. Anyhow, some requirements apply to the overall codebase:
The fact that
ATCis splitted in multiple packages allows for multiple deployment scenarii. However, deploying all the packages on the same host is the simplest and most likely fitting most use cases.
To get more details on how to install/configure each packages, please refer to the packages' respective READMEs.
The easiest way to install
ATCis by using
bash pip install atc_thrift atcd django-atc-api django-atc-demo-ui django-atc-profile-storage
Now that we have all the packages installed, we need to create a new Django project in which we will use our Django app.
django-admin startproject atcui cd atcui
Now that we have our django project, we need to configure it to use our apps and we need to tell it how to route to our apps.
atcui/settings.pyand enable the
ATCapps by adding to
INSTALLED_APPS = ( ... # Django ATC API 'rest_framework', 'atc_api', # Django ATC Demo UI 'bootstrap_themes', 'django_static_jquery', 'atc_demo_ui', # Django ATC Profile Storage 'atc_profile_storage', )
atcui/urls.pyand enable routing to the
ATCapps by adding the routes to
urlpatterns: ``` python ... ... from django.views.generic.base import RedirectView from django.conf.urls import include
urlpatterns = [ ... # Django ATC API url(r'^api/v1/', include('atcapi.urls')), # Django ATC Demo UI url(r'^atcdemoui/', include('atcdemoui.urls')), # Django ATC profile storage url(r'^api/v1/profiles/', include('atcprofilestorage.urls')), url(r'^$', RedirectView.asview(url='/atcdemoui/', permanent=False)), ] ```
Finally, let's update the Django DB:
bash python manage.py migrate
All require packages should now be installed and configured. We now need to run the daemon and the UI interface. While we will run
ATCstraight from the command line in this example, you can refer to example sysvinit and upstart scripts.
atcdmodifies network related settings and as such needs to run in privileged mode:
eth0is your interface to connect to the internet and
eth1, your interface to connect to your lan, this should just work. If your setting is slightly different, use the command line arguments
--atcd-lanto adapt to your configuration.
The UI on the other hand is a standard Django Web app and can be run as a normal user. Make sure you are in the directory that was created when you ran
django-admin startproject atcuiand run:
python manage.py runserver 0.0.0.0:8000
You should now be able to access the web UI at http://localhost:8000
ATC source code is available under the atc directory, it is currently composed of:
The chef directory contains 2 chef cookbooks:
atcdis the daemon that runs on the router that does the shaping. Interaction with the daemon is done using thrift. The interface definition can be found in atc_thrift.thrift.
atc_thriftdefines the thrift interface to communicate with the
django-atc-apiis a django app that provide a REST API to the
atcddaemon. Web applications, command line tools can use the API in order to shape/unshape traffic.
django-atc-demo-uiis a simple Web UI to enable/disable traffic shaping. The UI is mostly written in React
django-atc-profile-storageallows saving profiles to DB. A typical use case will be to save a list of predefined/often used shaping settings that you want to be able to accessing in just a few clicks/taps.
To make ATC development easier, we use Virtual Box and Vagrant to provision and run a VM that will run the ATC daemon and the ATC UI from your git checkout.
Interacting with ATC will only shape the traffic within the VM and not on the host.
Note: vagrant is an easy way to set up a test environment, but virtualization will produce different results than a setup on bare-metal. We recommend using vagrant only for testing/development and using bare-metal for setups which require realistic shaping settings.
You will need to install VirtualBox, Vagrant and a couple of plugins:
Once in the repo, go to the
chef/atcdirectory and run:
vagrant up trusty
This will take some time before it completes, once the VM is provision, SSH into it:
vagrant ssh trusty
You should now be able to access ATC at: http://localhost:8080/
Once you've got ATC up and running, you can run the script
utils/restore-profiles.shto setup the set of default profiles.
The script needs to be passed a
hostname:portwith the location of your ATC instance:
After doing this, you should see the 10 sample profiles listed below in your ATC instance:
2G - Developing Rural
2G - Developing Urban
3G - Average
3G - Good
Edge - Average
Edge - Good
Edge - Lossy
Naturally, you cannot improve your natural network speed by selecting a faster profile than your service. For example, selecting the
Cableprofile will not make your network faster if your natural connection speed resembles DSL more closely.
Hacking on ATC is done from the host and tested in the VM. In order to reflect the changes, you will need to start the services manually.
atcuihave their python libraries installed in a python virtualenv so you will need to activate the environment in order to be able to run the services.
The virtualenv is installed in /usr/local/atc/venv/bin/activate .
atcddaemon is running under the root user privileges, all operations below needs to be done as root.
To run the daemon manually, first make sure it is not running in the background:
service atcd stop
And run the daemon:
Once you are happy with your changes and you want to test them, you will need to kill the daemon and restart it in order to apply the changes.
This is a django project and, when running the django built-in HTTP server, will detect code changes and reload automatically.
To run the HTTP REST API and UI:
cd /var/django && python manage.py runserver 0.0.0.0:8000