PTF
PTF is a Python based dataplane test framework. It is based on unittest, which is included in the standard Python distribution.
Longer Start
需要先安装的东西:
Python 2.7
Scapy
pypcap (optional - VLAN tests will fail without this)
tcpdump (optional - Scapy will complain if it's missing)
请先安装scapy-vxlan
安装pypcap = 安装flex:the fast lexical analyser + 安装libpcap-1.7.4
Ubuntu安装Tcpdump
We recommend that you install your extension of Scapy, which you can obtain here. It adds support for additional header types: VXLAN, ERSPAN, GENEVE, MPLS and NVGRE.
注意:在执行命令的时候,应注意权限问题(sudo root)。
Install PTF
先fork下来目录:
git clone git@github.com:Wasdns/ptf.git
cd ptf
sudo python setup.py install
如何写ptf程序?
Take a look at the example directory. This is not a working example as it is (the switch is not included), but it will show you how to write tests. This directory contains the following:
run_client.sh: a wrapper around ptf
switch_sai_thrift: empty directory, this is where the Python bindings to program the switch's control plane would be copied
mytests/sai_base_test.py: a wrapper Python class around PTF's BaseTest class. It is the base class for all the tests we added to mytests/switch.py
mytests/switch.py: some example tests
可以在example目录下找到答案。
在安装p4factory的前提下,跑个样例
请先安装p4factory。
First, you need to create the required veths: 先打开虚拟接口
cd $P4FACTORY/tools/
sudo ./veth_setup.sh
注意,这里的$P4FACTORY指的是p4factory的目录。
The next step is to compile the target switch and to run it: 编译一个目的交换机,运行它
cd $P4FACTORY/targets/switch/
make bm-switchsai
sudo ./behavioral-model
Finally, you can run the example tests: 最后可以跑个例子来测试
cd <ptf-dir>/example/
sudo ../ptf --test-dir mytests/
--pypath $P4FACTORY/targets/switch/tests/pd_thrift/
--interface 0@veth1 --interface 1@veth3 --interface 2@veth5
--interface 3@veth7 --interface 4@veth9 --interface 5@veth11
--interface 6@veth13 --interface 7@veth15 --interface 8@veth17
这里的
指的是ptf的目录。
2016/11/27