# p4-env **Repository Path**: Mainblack/p4-env ## Basic Information - **Project Name**: p4-env - **Description**: 在Ubuntu上快速搭建P4实验环境 - **Primary Language**: Shell - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 10 - **Created**: 2020-04-07 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 为了那些不必要的痛苦(在Ubuntu中搭建P4实验环境) 本教程是对[P4编程理论与实践(2)—快速上手](https://www.sdnlab.com/22512.html)一文环境安装部分的整理,针对 **Ubuntu18.04** 作调整,提供`shell`脚本自动下载、编译及安装各个实验模块。 ![demo](./demo.png) **请不要**直接运行脚本而不浏览其内容! 初次安装者请认真阅读本教程。 --- ## 实验环境 * 操作系统:Ubuntu18.04 LTS (理论上Ubuntu16.04同样适用) * `python 2.7.x` 和 `pip` * 推荐系统内存 2G 及以上 * 推荐swap分区 1G及以上 ## 实验模块介绍 | Github项目 | 功能 | 来自于 | | --- | --- | --- | | [mininet](https://github.com/mininet/mininet) | 网络仿真器 | Mininet | | [protobuf](https://github.com/protocolbuffers/protobuf) | 谷歌开发的数据交换格式,作为 PI 的依赖模块 | Google | | [grpc](https://github.com/grpc/grpc) | 远程程序调用(RPC)框架,作为 PI 的依赖模块 | Google | | [bmv2](https://github.com/p4lang/behavioral-model) | 支持P4编程的软件交换机 | P4lang | | [PI](https://github.com/p4lang/PI) | P4-runtime库,南向协议 | P4lang | | [p4c](https://github.com/p4lang/p4c) | p4c 编译器 | P4lang | | [tutorials](https://github.com/p4lang/tutorials) | P4官方提供的快速上手教程 | P4lang | ## 环境搭建 ### 开始之前 1. 安装必要的依赖和工具 ```SH $ sudo apt-get update $ sudo apt-get install build-essential automake cmake -y $ sudo apt-get install net-tools tcpdump curl git -y $ sudo apt-get install libjudy-dev libpcap-dev libboost-dev libboost-test-dev \ libboost-program-options-dev libboost-system-dev libboost-filesystem-dev \ libboost-thread-dev libevent-dev libtool flex bison g++ libssl-dev -y $ sudo apt-get install libgc-dev libfl-dev libgmp-dev libboost-iostreams-dev \ libboost-graph-dev llvm pkg-config python-scapy python-ipaddr python-ply \ libreadline-dev -y $ sudo pip install psutil $ sudo pip install crcmod ``` 2. 为安装脚本设置工作目录 ```SH $ echo "P4_HOME=~/Workspace/P4" >> ~/.bashrc #可以自定义工作目录,此处为示例 $ source ~/.bashrc $ cd $P4_HOME ``` ### 下载源代码 #### 方法一:从Github上直接下载 (部分模块国内用户可能下载速度过慢) 将[`git-p4.sh`](./git-p4.sh)拷贝至当前工作目录并运行 ``` $ ./git-p4.sh ``` #### 方法二:百度网盘下载本教程提供的源码压缩包 (下载于2020年3月28日) 链接: https://pan.baidu.com/s/1EZCZa1ZIYg-9maxj_E8P8Q 提取码: sxw3 ### 编译并安装 将[`p4env-up.sh`](./p4env-up.sh)拷贝至当前工作目录并运行 ``` $ ./p4env-up.sh ``` ## 快速开始第一个P4实验 ``` $ cd tutorials/exercises/basic $ make ``` ##### 退出 ``` mininet> exit $ sudo make stop $ sudo make clean ``` 查看`basic/README.md`文件获取更多细节 ## 问题反馈 欢迎大家在评论区进行交流,或者邮箱联系我: ndsczx@foxmail.com ## LICENSE [MIT](./LICENSE)