---
title: "p4lang: switch-更完善的P4例子"
author: "steeven"
date: "2016-10-16T21:56:14Z"
tags: []
categories: ["开源软件"]
slug: "p4lang-switch-p4"
draft: false
lastmod: "2016-10-16T21:56:14Z"
id: 2330864
url: "https://steeven.iteye.com/blog/2330864"
---

10/16/2016 发现CI/travis目录下面有依赖工具的安装脚本，供参考

switch是个参考的switch例子，很多表可以参考，并且生成了SAI等API供调用。
============================================

首先要参照前面两篇文章安装BMv2(p4-behavioral-model)和p4c-bmv2(p4c-bm)

安装PTF：
git clone https://github.com/p4lang/ptf.git 
cd ptf; sudo python setup.py install

安装switch：
git clone https://github.com/p4lang/switch.git
cd switch
git submodule update --init --recursive 
./autogen.sh
./configure --with-bmv2 --with-switchsai
make
#如果在configure步骤找不到bm相关头文件，需要进入behavioral-model项目执行sudo make install

运行：
sudo tools/veth_setup.sh
sudo bmv2/run_bm.sh
新窗口： 
sudo bmv2/run_drivers.sh

测试脚本：
sudo ./bmv2/run_tests.sh --test-dir tests/ptf-tests/pd-tests # for the PD tests
sudo ./bmv2/run_tests.sh --test-dir tests/ptf-tests/api-tests  # for the switchapi tests
sudo ./bmv2/run_tests.sh --test-dir tests/ptf-tests/sai-tests  # for the switchsai tests

BMv2的命令行调试工具：
bm_CLI 
#show_ports, show_tables, switch_info...