热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

RunP4withoutP4factoryASimpleExampleInTutorials.

前言本文是我运行P4社区于Github开源教程Tutorials中的P4SIGCOMM2015Tutorial一些实战小结,Github链接:Githu

前言

本文是我运行P4社区于Github开源教程Tutorials中的P4 SIGCOMM 2015 Tutorial一些实战小结,Github链接:

  • Github。

测试的例子:P4 SIGCOMM 2015 - Source Routing

实验环境:

Linux,Ubuntu 14.04 64bit。

实验步骤:

准备工作:

安装 bmv2 和 p4c-bm:

请移步我的另外一篇博客:

  • P4 前端编译器p4c-bm、后端编译器bmv2命令安装 make error问题

上面给出的博文中,还有一个小bug还在处理中。

安装pip:

请移步:

  • Linux 安装pip

安装Mininet:

请移步:

  • Mininet实验 源码安装Mininet

安装其他工具:

命令:

sudo pip install scapy thrift networkx

关于thrift的安装遇到的一些问题:

  • 解决thrift: ···No such file or directory问题
  • P4行为模型BMV2依赖关系安装:thrift nanomsg nnpy安装

准备完毕之后:

bmv2:/home/wasdns/bmv2

p4c-bm:/home/wasdns/p4c-bmv2

java -version(比较老的版本):

java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

python -V:

Python 2.7.6

thrift -version:

Thrift version 1.0.0-dev

就不一一列举了。

实验步骤

1.将Github上的Tutorials下载下来:

git clone https://github.com/p4lang/tutorials.git

2.更改env.sh脚本中的路径信息:

命令:

vim env.sh

env.sh脚本:

THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )# ---------------- EDIT THIS ------------------
BMV2_PATH=$THIS_DIR/../bmv2
# e.g. BMV2_PATH=$THIS_DIR/../bmv2
P4C_BM_PATH=$THIS_DIR/../p4c-bmv2
# e.g P4C_BM_PATH=$THIS_DIR/../p4c-bm
# ---------------- END ------------------

我没有使用THIS_DIR的路径,直接修改为:

THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )# ---------------- EDIT THIS ------------------
BMV2_PATH=/home/wasdns/bmv2
# e.g. BMV2_PATH=$THIS_DIR/../bmv2
P4C_BM_PATH=/home/wasdns/p4c-bmv2
# e.g P4C_BM_PATH=$THIS_DIR/../p4c-bm
# ---------------- END ------------------

:wq保存退出。

3.进入source_routing目录

root@ubuntu:/home/wasdns/tutorials# cd SIGCOMM_2015
root@ubuntu:/home/wasdns/tutorials/SIGCOMM_2015# cd source_routing/

4.对本实验的简单介绍

请参考:

  • Description of the EasyRoute protocol

5.解压solution.tar.gz

tar -zxvf solution.tar.gz

这里借用了barefoot提供的现成的解决方案,p4源程序source_routing.p4如下:

/*
Copyright 2013-present Barefoot Networks, Inc. Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/header_type easyroute_head_t {fields {preamble: 64;num_valid: 32;}
}header easyroute_head_t easyroute_head;header_type easyroute_port_t {fields {port: 8;}
}header easyroute_port_t easyroute_port;parser start {return select(current(0, 64)) {0: parse_head;default: ingress;}
}parser parse_head {extract(easyroute_head);return select(latest.num_valid) {0: ingress;default: parse_port;}
}parser parse_port {extract(easyroute_port);return ingress;
}action _drop() {drop();
}action route() {modify_field(standard_metadata.egress_spec, easyroute_port.port);add_to_field(easyroute_head.num_valid, -1);remove_header(easyroute_port);
}table route_pkt {reads {easyroute_port: valid;}actions {_drop;route;}size: 1;
}control ingress {apply(route_pkt);
}control egress {// leave empty
}

并将该p4程序及其目录p4src拷贝至source_routing目录下:

mv /home/wasdns/tutorials/SIGCOMM_2015/source_routing/p4src /home/wasdns/tutorials/SIGCOMM_2015/source_routing/p4src1cp -r /home/wasdns/tutorials/SIGCOMM_2015/source_routing/solution/p4src /home/wasdns/tutorials/SIGCOMM_2015/source_routing

6.将env.sh拷贝至source_routing目录下:

cp -r /home/wasdns/tutorials/env.sh /home/wasdns/tutorials/SIGCOMM_2015/source_routing

7.修改run_demo.sh脚本内容:

run_demo.sh脚本:

#!/bin/bash# Copyright 2013-present Barefoot Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )source $THIS_DIR/../../env.shP4C_BM_SCRIPT=$P4C_BM_PATH/p4c_bm/__main__.pySWITCH_PATH=$BMV2_PATH/targets/simple_switch/simple_switchCLI_PATH=$BMV2_PATH/tools/runtime_CLI.py$P4C_BM_SCRIPT p4src/source_routing.p4 --json source_routing.json
# This gives libtool the opportunity to "warm-up"
sudo $SWITCH_PATH >/dev/null 2>&1
sudo PYTHONPATH=$PYTHONPATH:$BMV2_PATH/mininet/ python topo.py \--behavioral-exe $SWITCH_PATH \--json source_routing.json \
--cli $CLI_PATH

source $THIS_DIR/../../env.sh

改为:

source $THIS_DIR/env.sh

8.添加python模块p4_mininet:

请移步:

  • P4实验问题 解决python模块导入

9.修改command.txt:

在我第一次做这个实验的时候,h1发送的数据报是到达不了h3的,RunTimeCmd报错如下:

/home/wasdns/bmv2/tools/runtime_CLI.py --json source_routing.json --thrift-port 22222
Control utility for runtime P4 table manipulation
RuntimeCmd: Error: Invalid table name (ecmp_group)
RuntimeCmd: Error: Invalid table name (ecmp_nhop)
RuntimeCmd: Error: Invalid table name (forward)
RuntimeCmd: Error: Invalid table name (send_frame)
RuntimeCmd: Error: Invalid table name (ecmp_group)
RuntimeCmd: Error: Invalid table name (ecmp_nhop)
RuntimeCmd: Error: Invalid table name (ecmp_nhop)
RuntimeCmd: Error: Invalid table name (forward)
RuntimeCmd: Error: Invalid table name (forward)
RuntimeCmd: Error: Invalid table name (send_frame)
RuntimeCmd: Error: Invalid table name (send_frame)
RuntimeCmd:

原因是因为我没有仔细阅读ReadMe,直接把另外一个P4程序的command.txt拿来用了,本实验的P4程序没有这个表的定义,自然报错。

依照ReadMe,了解以下两种command即可:

1. table_set_default [action_data]: this is used to set the default action of a given table2. table_add => [action_data]: this is used to add an entry to a table

ReadMe中也给出了一个具体的依照P4程序编写命令的model:

  • simple_router.p4
  • 依照上面p4写的command.txt

于是,我依照上面的model以及本次实验所用的source_routing.p4程序,写了一个命令来修改command.txt,内容如下。

command.txt:

table_set_default route_pkt route

我也在Github中询问了这个问题,最后自己解决了:)A ping problem in SIGCOMM2015/source_routing

10.启动虚拟端口:

sh /home/wasdns/bmv2/tools/veth_setup.sh

可以使用ifconfig命令验证是否开启。

11.运行脚本:

./run_demo.sh

12.在启动的mininet中打开h1和h3的终端:

xterm h1
xterm h3

13.分别在h1和h3终端上运行脚本:

先执行h3终端上的脚本:

./receive.py

再执行h1终端上的脚本:

./send.py h1 h3

实验结果:

885822-20161219165935963-1047313679.jpg

在h1的xterm上输入文本信息,在h3的xterm上能够接收。但是在mininet中执行h1 ping h3是没有办法ping通的,由此可以证实P4交换机在处理数据报的过程中,进行了协议匹配:当easyroute_port与valid相匹配时,执行route()动作。

总结:

1.勤奋搜索。

2.要理解每一个操作步骤在整个实验中的作用,能够解决很多搜索解决不了的问题。

参考:

  • Github p4lang/tutorial

2016/12/19


转:https://www.cnblogs.com/qq952693358/p/6195385.html



推荐阅读
  • 31.项目部署
    目录1一些概念1.1项目部署1.2WSGI1.3uWSGI1.4Nginx2安装环境与迁移项目2.1项目内容2.2项目配置2.2.1DEBUG2.2.2STAT ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 树莓派语音控制的配置方法和步骤
    本文介绍了在树莓派上实现语音控制的配置方法和步骤。首先感谢博主Eoman的帮助,文章参考了他的内容。树莓派的配置需要通过sudo raspi-config进行,然后使用Eoman的控制方法,即安装wiringPi库并编写控制引脚的脚本。具体的安装步骤和脚本编写方法在文章中详细介绍。 ... [详细]
  • Python已成为全球最受欢迎的编程语言之一,然而Python程序的安全运行存在一定的风险。本文介绍了Python程序安全运行需要满足的三个条件,即系统路径上的每个条目都处于安全的位置、"主脚本"所在的目录始终位于系统路径中、若python命令使用-c和-m选项,调用程序的目录也必须是安全的。同时,文章还提出了一些预防措施,如避免将下载文件夹作为当前工作目录、使用pip所在路径而不是直接使用python命令等。对于初学Python的读者来说,这些内容将有所帮助。 ... [详细]
  • Python实现变声器功能(萝莉音御姐音)的方法及步骤
    本文介绍了使用Python实现变声器功能(萝莉音御姐音)的方法及步骤。首先登录百度AL开发平台,选择语音合成,创建应用并填写应用信息,获取Appid、API Key和Secret Key。然后安装pythonsdk,可以通过pip install baidu-aip或python setup.py install进行安装。最后,书写代码实现变声器功能,使用AipSpeech库进行语音合成,可以设置音量等参数。 ... [详细]
  • 本文介绍了在mac环境下使用nginx配置nodejs代理服务器的步骤,包括安装nginx、创建目录和文件、配置代理的域名和日志记录等。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • 基于dlib的人脸68特征点提取(眨眼张嘴检测)python版本
    文章目录引言开发环境和库流程设计张嘴和闭眼的检测引言(1)利用Dlib官方训练好的模型“shape_predictor_68_face_landmarks.dat”进行68个点标定 ... [详细]
  • Vagrant虚拟化工具的安装和使用教程
    本文介绍了Vagrant虚拟化工具的安装和使用教程。首先介绍了安装virtualBox和Vagrant的步骤。然后详细说明了Vagrant的安装和使用方法,包括如何检查安装是否成功。最后介绍了下载虚拟机镜像的步骤,以及Vagrant镜像网站的相关信息。 ... [详细]
  • 本文介绍了解决github无法访问和克隆项目到本地的问题。作者建议通过修改配置文件中的用户名和密码来解决访问失败的问题,并提供了详细步骤。同时,还提醒读者注意输入的用户名和密码是否正确。 ... [详细]
  • 本文介绍了在Ubuntu下制作deb安装包及离线安装包的方法,通过备份/var/cache/apt/archives文件夹中的安装包,并建立包列表及依赖信息文件,添加本地源,更新源列表,可以在没有网络的情况下更新系统。同时提供了命令示例和资源下载链接。 ... [详细]
  • Python操作MySQL(pymysql模块)详解及示例代码
    本文介绍了使用Python操作MySQL数据库的方法,详细讲解了pymysql模块的安装和连接MySQL数据库的步骤,并提供了示例代码。内容涵盖了创建表、插入数据、查询数据等操作,帮助读者快速掌握Python操作MySQL的技巧。 ... [详细]
  • python中安装并使用redis相关的知识
    本文介绍了在python中安装并使用redis的相关知识,包括redis的数据缓存系统和支持的数据类型,以及在pycharm中安装redis模块和常用的字符串操作。 ... [详细]
  • 本文介绍了在Android Studio中使用命令行build gradle的方法,并解决了一些常见问题,包括手动配置gradle环境变量和解决External Native Build Issues的方法。同时提供了相关参考文章链接。 ... [详细]
author-avatar
李东润
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有