热门标签 | 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



推荐阅读
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • CentOS7源码编译安装MySQL5.6
    2019独角兽企业重金招聘Python工程师标准一、先在cmake官网下个最新的cmake源码包cmake官网:https:www.cmake.org如此时最新 ... [详细]
  • XNA 3.0 游戏编程:从 XML 文件加载数据
    本文介绍如何在 XNA 3.0 游戏项目中从 XML 文件加载数据。我们将探讨如何将 XML 数据序列化为二进制文件,并通过内容管道加载到游戏中。此外,还会涉及自定义类型读取器和写入器的实现。 ... [详细]
  • 从 .NET 转 Java 的自学之路:IO 流基础篇
    本文详细介绍了 Java 中的 IO 流,包括字节流和字符流的基本概念及其操作方式。探讨了如何处理不同类型的文件数据,并结合编码机制确保字符数据的正确读写。同时,文中还涵盖了装饰设计模式的应用,以及多种常见的 IO 操作实例。 ... [详细]
  • 本文详细介绍了Python编程语言的学习路径,涵盖基础语法、常用组件、开发工具、数据库管理、Web服务开发、大数据分析、人工智能、爬虫开发及办公自动化等多个方向。通过系统化的学习计划,帮助初学者快速掌握Python的核心技能。 ... [详细]
  • Python第三方库安装的多种途径及注意事项
    本文详细介绍了Python第三方库的几种常见安装方法,包括使用pip命令、集成开发环境(如Anaconda)以及手动文件安装,并提供了每种方法的具体操作步骤和适用场景。 ... [详细]
  • CMake跨平台开发实践
    本文介绍如何使用CMake支持不同平台的代码编译。通过一个简单的示例,我们将展示如何编写CMakeLists.txt以适应Linux和Windows平台,并实现跨平台的函数调用。 ... [详细]
  • 如何配置Unturned服务器及其消息设置
    本文详细介绍了Unturned服务器的配置方法和消息设置技巧,帮助用户了解并优化服务器管理。同时,提供了关于云服务资源操作记录、远程登录设置以及文件传输的相关补充信息。 ... [详细]
  • 在Ubuntu 16.04 LTS上配置Qt Creator开发环境
    本文详细介绍了如何在Ubuntu 16.04 LTS系统中安装和配置Qt Creator,涵盖了从下载到安装的全过程,并提供了常见问题的解决方案。 ... [详细]
  • 本文深入探讨了Linux系统中网卡绑定(bonding)的七种工作模式。网卡绑定技术通过将多个物理网卡组合成一个逻辑网卡,实现网络冗余、带宽聚合和负载均衡,在生产环境中广泛应用。文章详细介绍了每种模式的特点、适用场景及配置方法。 ... [详细]
  • 掌握远程执行Linux脚本和命令的技巧
    本文将详细介绍如何利用Python的Paramiko库实现远程执行Linux脚本和命令,帮助读者快速掌握这一实用技能。通过具体的示例和详尽的解释,让初学者也能轻松上手。 ... [详细]
  • 根据最新发布的《互联网人才趋势报告》,尽管大量IT从业者已转向Python开发,但随着人工智能和大数据领域的迅猛发展,仍存在巨大的人才缺口。本文将详细介绍如何使用Python编写一个简单的爬虫程序,并提供完整的代码示例。 ... [详细]
  • 本文详细介绍了Linux系统中init进程的作用及其启动过程,解释了运行级别的概念,并提供了调整服务启动顺序的具体步骤和实例。通过了解这些内容,用户可以更好地管理系统的启动流程和服务配置。 ... [详细]
  • 在Python开发过程中,随着项目数量的增加,不同项目依赖于不同版本的库,容易引发依赖冲突。为了避免这些问题,并保持开发环境的整洁,可以使用Virtualenv和Virtualenvwrapper来创建和管理多个隔离的Python虚拟环境。 ... [详细]
  • Python入门:第一天准备与安装
    本文详细介绍了Python编程语言的基础知识和安装步骤,帮助初学者快速上手。涵盖Python的特点、应用场景以及Windows环境下Python和PyCharm的安装方法。 ... [详细]
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社区 版权所有