# p4-env **Repository Path**: monkey113/p4-env ## Basic Information - **Project Name**: p4-env - **Description**: 在Ubuntu上快速搭建P4实验环境 - **Primary Language**: Shell - **License**: MIT - **Default Branch**: advanced - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 10 - **Created**: 2021-12-22 - **Last Updated**: 2021-12-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 为了那些不必要的痛苦(在Ubuntu中搭建基于P4的SDN实验环境) 本教程主要针对 **Ubuntu20.04** 系统,全面将实验环境升级至`python3`版本,提供`shell`脚本自动下载、编译及安装各个实验模块。 ![demo](./demo.png) 如果需要使用`Ubuntu18.04`或`python2`,请参考[主分支](https://gitee.com/poohdang/p4-env/tree/master/)。 **请不要**直接运行脚本而不浏览其内容! 安装过程中出现问题,尝试查看[FAQ](#faq)获取帮助。 --- * [实验环境](#实验环境) * [实验模块介绍](#实验模块介绍) * [环境搭建](#环境搭建) * [开始之前](#开始之前) * [下载源代码](#下载源代码) * [编译并安装](#编译并安装) * [快速开始第一个P4实验](#快速开始第一个p4实验) * [FAQ](#faq) ## 实验环境 * 操作系统:Ubuntu20.04 LTS * `python 3.x` 和 `pip3` > 请确保`python`指令指向python3.x > 通过`python -V`和`python -m pip -V`查看 * 推荐系统内存 2G 及以上 * 推荐swap分区 1G 及以上 ## 实验模块介绍 | Github项目 | 功能 | 版本 | 来自于 | | --- | --- | --- | --- | | [mininet](https://github.com/mininet/mininet) | 网络仿真器 | Latest | Mininet | | [protobuf](https://github.com/protocolbuffers/protobuf) | 数据消息交换格式,grpc的默认选项 | v3.12.2 | Google | | [grpc](https://github.com/grpc/grpc) | 谷歌开发的远程程序调用(RPC)框架,PI基于此实现 | v1.30.0 | Google | | [bmv2](https://github.com/p4lang/behavioral-model) | 支持P4编程的软件交换机 | Latest | P4lang | | [PI](https://github.com/p4lang/PI) | P4 Runtime Server | Latest | P4lang | | [p4c](https://github.com/p4lang/p4c) | P4 编译器 | Latest |P4lang | | [tutorials](https://github.com/p4lang/tutorials) | P4官方提供的快速上手教程 | Latest | P4lang | ## 环境搭建 #### 开始之前 1. 安装Git ``` $ sudo apt install git ``` 2. 设置工作目录并克隆本仓库 ``` # 以下工作目录可自定义,此处为示例 $ mkdir -p ~/Workspace/P4 && echo "export P4_HOME=~/Workspace/P4" >> ~/.bashrc $ source ~/.bashrc $ cd $P4_HOME # 该环境变量必须生效,后续脚本需要 $ git clone https://gitee.com/poohdang/p4-env.git $ cd p4-env ``` 3. 安装必要的依赖和编译工具 ``` $ sudo chmod 755 p4*.sh $ ./p4-deps.sh ``` #### 下载源代码 ###### 方法一:从Github上直接下载 (部分模块国内用户可能下载速度过慢) ``` $ ./p4-git.sh ``` ###### 方法二:对部分URL进行替换 (使用`https://hub.fastgit.org`加速的仓库) ``` $ ./p4-git-china.sh ``` #### 编译并安装 ``` $ ./p4-install.sh ``` ## 快速开始第一个P4实验 ``` $ cd tutorials/exercises/basic $ make mininet> ... ``` > 若Python报出 `No module named protobuf.internal` 的错误,执行以下指令 ``` $ cd /usr/local/lib/python3.8 $ sudo cp -rf dist-packages/protobuf-3.12.2-py3.8-linux-x86_64.egg/google/protobuf site-packages/google ``` #### 退出 ``` mininet> exit $ sudo make stop $ sudo make clean ``` 查看`basic/README.md`文件获取`basic`实验的详细说明 ## FAQ #### 一、为什么分为两个脚本? 将下载过程与编译/安装过程分离,同时针对下载过程进行优化。 #### 二、为什么在`p4_git.sh` 中特别指定`protobuf`和`grpc`的版本? 满足`PI`对两者的最低版本要求。可进入[PI的主页](https://github.com/p4lang/PI)进行确认,并按需对脚本进行更改。 #### 三、为什么在安装`Mininet` 时使用`-nvw`选项? -n: install Mini(N)et dependencies + core files -v: install Open (V)switch -w: install OpenFlow (W)ireshark dissector 通过`/util/install.sh -h`查看更多选项 ## 问题反馈 评论区,或 ndsczx@foxmail.com ## LICENSE [MIT](./LICENSE)