使用facebook的atc框架.
Augmented Traffic Control(又名atc)是一种模拟网络状况的工具。由facebook开源,是一个允许开发人员控制设备与互联网连接的项目。atc可以模拟不同的网络条件,包括控制带宽,延迟,数据包丢失、数据包损坏、数据包重排序等几个因素都可以由atc来控制。atc运行在网关,可以控制连接到该网络的手机,设备的网络,atc有一个web界面,通过这个界面可以来切换不同的网络情况。atc内部使用了iptables和tc,因此只支持linux平台。
开启热点
框架搭建和启动
- 安装第三方库
pip install django==1.1.0
pip install atc_thrift atcd django-atc-api django-atc-demo-ui django-atc-profile-storage - 创建工程
django-admin startproject atcui - 编辑配置文件
ATC_UI/ATC_UI/settings.py
在INSTALLED_APPS添加如下内容:'rest_framework', 'atc_api', 'bootstrap_themes', 'django_static_jquery', 'atc_demo_ui', 'atc_profile_storage',
ALLOWED_HOSTS修改如下,‘*’允许所有ip访问。ALLOWED_HOSTS = ['*'] - 编辑文件urls.py, 修改增加如下配置:
from django.views.generic.base import RedirectView
from django.conf.urls import include
urlpatterns = [
url(r'^admin/',admin.site.urls),
url(r'^api/v1/',include('atc_api.urls')),
url(r'^atc_demo_ui/',include('atc_demo_ui.urls')),
url(r'^api/v1/profiles/',include('atc_profile_storage.urls')),
url(r'^$',RedirectView.as_view(url='/atc_demo_ui/', permanent=False)),
]

5. 切换到manage.py目录,执行更新Django数据库:python manage.py migrate
6. 设置网卡 root@raspberrypi:/home/pi/atcui/augmented-traffic-control# atcd --atcd-wan wlan0 --atcd-lan wlan1 这里必须用root执行. (我这里搭的树莓派自身wifi上网网卡是wlan0, 用来搭建ap的网卡是wlan1)
7. 运行Django,runserver 参数 指定端口。
python manage.py runserver 0.0.0.0:8000
8. 使用官方已经配好的网络配置文件
具体使用方法:
git clone https://github.com/facebookarchive/augmented-traffic-control.git
cd augmented-traffic-control
utils/restore-profiles.sh 192.168.0.1:8000
成功的话会显示:
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/2G-DevelopingRural.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/2G-DevelopingUrban.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/3G-Average.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/3G-Good.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/Cable.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/DSL.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/Edge-Average.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/Edge-Good.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/Edge-Lossy.json
Added profile /home/pi/atcui/augmented-traffic-control/utils/profiles/NoConnectivity.json
- 使用
iwconfig看好自己热点的ip地址,例如我这里是192.168.12.1,那么手机接入这个wifi后,在手机浏览器登入即可:http://192.168.12.1:8000 - 选择弱网环境
选择需要的网络环境,点击“select”,然后点击最上面的“update shaping”,也可以自定义网络。每部手机连接的网络互不影响,也就是说你设置了限速只对你自己有效,不会影响其他人。

后续启动
关机之后再次启动,需要开三个命令行窗口,分别执行指令
-
pi@raspberrypi:~/create_ap $ sudo create_ap wlan1 eth0 tester 12345678 -
pi@raspberrypi:~/atcui $ python manage.py runserver 0.0.0.0:8000 -
root@raspberrypi:/home/pi/atcui/augmented-traffic-control# atcd --atcd-wan wlan0 --atcd-lan wlan1这里必须用root执行.
启动脚本
go.sh (把go.sh加入开机启动)
#!/bin/bash
nohup sh create_ap.sh >log_ap.log &
sleep 3
nohup sh atcd.sh >log_atcd.log &
sleep 3
nohup sh start_atc.sh >log_start_atc.log &
sleep 3
create_ap.sh
#!/bin/bash
cd ~/create_ap
sudo create_ap wlan1 eth0 tester 12345678
atcd.sh
#!/bin/bash
sudo atcd --atcd-wan wlan0 --atcd-lan wlan1
start_atc.sh
#!/bin/bash
cd ~/atcui
python manage.py runserver 0.0.0.0:8000
网络参数配置表参考:


本文介绍了如何在树莓派上利用facebook的atc框架搭建APP弱网测试环境。atc是一个用于模拟网络状况的工具,支持控制带宽、延迟、数据包丢失等因素。文章详细阐述了开启热点、框架搭建与启动、后续启动流程以及如何设置开机自启动。
759

被折叠的 条评论
为什么被折叠?



