facebook atc弱网环境搭建和踩坑总结

facebook atc介绍html

Augmented Traffic Control(又名atc)是一种模拟网络情况的工具。由facebook开源,是一个容许开发人员控制设备与互联网链接的项目。atc能够模拟不一样的网络条件,包括控制带宽,延迟,数据包丢失、数据包损坏、数据包重排序等几个因素均可以由atc来控制。atc运行在网关,能够控制链接到该网络的手机,设备的网络,atc有一个web界面,经过这个界面能够来切换不一样的网络状况。atc内部使用了iptables和tc,所以只支持linux平台。python

 

下面介绍facebook atc在 ubuntu 18.04(使用vmware 安装的虚拟机)系统下facebook atc 的安装和使用。jquery

准备环境:linux

一、用vmware装个ubuntu
二、准备一个无线网卡,建议选择一个linux免驱的无线网卡,否则在开启热点的时候会提示失败。git

 

ubuntu设置wifi热点功能

ubuntu须要利用hostapd和dhcp开启ap热点,首先安装hostapd和dhcpgithub

sudo apt-get install hostapd isc-dhcp-server

 

而后编辑/etc/hostapd/hostapd.conf文件,内容以下图:web

 

  • ssid 为wifi名称
  • wpa_passphrase 为wifi密码

 

接着启动hostapd服务数据库

sudo hostapd /etc/hostapd/hostapd.conf 

 

若是没报错并搜到热点证实启动ap热点成功,若是有报错能够用如下命令解决:django

sudo nmcli radio wifi off sudo rfkill unblock wlan

 

若是提示hostapd进程已存在,则须要先杀掉进程bootstrap

sudo killall hostapd

 

配置dhcp

编辑文件/etc/dhcp/dhcpd.conf, 内容以下图:

 

  • subnet为子网范围,netmask为子网掩码
  • range为可分配的IP地址范围
  • option router 为配置的网关
  • option domain-name-servers 为配置的dns,我用的8.8.8.8,即谷歌的dns服务器

 

设置无线网卡接口地址

sudo ifconfig wlx00026fb9727b 192.168.179.1 netmask 255.255.255.0

 

启动dhcp-server服务

sudo dhcpd wlx00026fb9727b -pf /var/run/dhcp-server/dhcpd.pid

 

如有提示pid或leases文件错误,就按照提示就去建立文件并赋予权限

sudo touch /var/lib/dhcp/dhcpd.leases chmod a+x /var/lib/dhcp/dhcpd.leases

 

若开启dhcp服务没有提示报错,则表明开启成功,此时wifi应该能够连上,可是还不能够上网。

 

设置IP转发

sudo bash -c "echo 1 >/proc/sys/net/ipv4/ip_forward"

 

设置NAT转发

sudo iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE

 

由于设置步骤较多,能够写成2个脚本,ap-start.sh, ap-stop.sh。一切顺利的话,此时wifi应该能够连上了

 

配置facebook atc 

首先安装python2.7和pip,和django

sudo apt-get install python sudo apt-get install python-pip sudo apt-get install django

 

安装atc的组件

pip install atc_thrift atcd django-atc-api django-atc-demo-ui django-atc-profile-storage

 

建立atc工程

django-admin startproject atcui cd atcui

 

配置setting.py 的 INSTALLED_APPS

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.py

from django.views.generic.base import RedirectView from django.conf.urls import include urlpatterns = [ ... # Django ATC API
url(r'^api/v1/', include('atc_api.urls')), # Django ATC Demo UI
url(r'^atc_demo_ui/', include('atc_demo_ui.urls')), # Django ATC profile storage
url(r'^api/v1/profiles/', include('atc_profile_storage.urls')), url(r'^$', RedirectView.as_view(url='/atc_demo_ui/', permanent=False)), ]

 

更新数据库

python manage.py migrate

 

启动atc

sudo atcd --atcd-wan ens33 --atcd-lan wlx00026fb9727b

 

不过启动atc的时候我遇到了https://github.com/facebook/augmented-traffic-control/issues/302 这里所说的问题,加上里面说的参数就解决了

--atcd-dont-drop-packets

 

启动atc web

python manage.py runserver 0.0.0.0:8000

 

导入facebook默认的几个配置文件

utils/restore-profiles.sh localhost:8000

 

这时用手机连上wifi热点,访问 http://192.168.179.1:8000

此时能够看到下图

 

使用方法为

turn on select update shaping

 

而后就大功告成了,能够试着切换不一样的模拟网络试试效果。

 

 

 参考文章:

 https://www.cnblogs.com/coderzh/p/AugmentedTrafficControl.html

 https://blog.csdn.net/itfootball/article/details/46763731

相关文章
相关标签/搜索