当前位置:网站首页>P4学习——p4runtime
P4学习——p4runtime
2022-07-01 00:32:00 【Sunny_范】
参考:https://blog.csdn.net/qq_33681684/article/details/123646883
在这个练习中,我们将使用P4Runtime向交换机发送流条目,而不是使用交换机的CLI。我们将基于您在basic_tunnel练习中使用的相同的P4程序进行构建。P4程序已被重命名为advanced_tunnel。p4和增加了两个计数器(ingressTunnelCounter, egressTunnelCounter)和两个新动作(myTunnel_ingress, myTunnel_egress)。
您将使用starter程序mycontroller.py和p4runtime_lib目录中的几个助手库来创建主机1和主机2之间的通道通信所需的表条目。
关于控制平面的说明
P4程序定义了一个包处理管道,但是每个表中的规则是由控制平面插入的。在本例中,mycontroller.py实现了我们的控制平面,而不是像我们在前面的练习中那样安装静态表条目。
重要提示:一个.p4的文件会编译生成一个Info文件里面是含有table id等信息是控制平面下发具体规则的依据;再生成一个配置文件(格式根据target而定)下发数据平面作为包处理的pipeline。控制平面还通过p4runtime对数据平面管理。
步骤一:运行不完整代码
- sudo make run (编译advanced_tunnel.p4,启动mininet实例搭建拓扑,为hosts分配IP)
- h1 ping h2,此时还不能正常通信,因为此时交换机上还没有任何规则,所以不能够收到任何的回复
- 打开另一个终端,运行mycontroller.py。这将安装advanced_tunnel。p4在交换机上编程并加载tunnel ingress rules。该程序每2秒打印一次tunnel ingress 和 egres计数。您应该看到s1的tunnel ingress计数器在增加:
因为s1和s2之间的transit rules还没有,所以只能看到s1 进入隧道计数。 - Ctrl-C 停止mycontroller.py,完成switches间的流量基于隧道ID转发的rules。打开mycontroller.py,完成TODO部分。目前每个交换机都在根据目的IP地址将流量映射到隧道中。目标是编写基于隧道ID在交换机之间转发流量的规则。
步骤二:开始实现隧道转发
mycontroller.py 是一个基础的控制平面,它会做以下操作:
1.为P4Runtime服务建立到switches的gRPC连接;
2.Pushes the P4 program to each switch.推送P4程序到每台switches;
3.为h1到h2间的两个隧道编写规则,h1到h2隧道ID 100,h2到h1隧道ID 200;
4.每2秒钟读取一次tunnel ingress和egress 的计数。
工作将是在writeTunnelRules函数中编写隧道传输规则,该函数将匹配隧道ID并将数据包转发到下一跳。
在实验中,会使用p4runtime_lib下的一些类和方法:
helper.py
包含用于解析p4info文件的 P4InfoHelper 类。
提供实体名称与ID的转换方法。
构建P4Runtime table的P4程序相关部分。
switch.py
包含SwitchConnection类,该类获取gRPC客户端stub,并建立到交换机的连接。
提供helper方法,用于构造P4Runtime协议缓冲区消息并进行P4Runtime gRPC服务调用
bmv2.py
包含Bmv2SwitchConnection,它扩展了SwitchConnections,并提供BMv2特定的设备载荷以加载P4程序。
convert.py
提供便捷的方法,将friendly字符串和数字编码、解码成协议缓冲区消息所需的字节字符串。
Helper.py 使用
步骤三:运行解决方案
打开另一个终端执行python文件,控制平面会把rules下发到数据平面。这时会看到计数增长
./my_controller.py
这时通过命令行登录s1,看下switch的转发规则如下:
simple_switch_CLI --thrift-port 9090
目的IP10.0.2.2/32进行LPM匹配,送进隧道100(显示的64是十六进制)。
精确匹配隧道ID100,送到接口2。
隧道ID是200(显示c8是十六进制),封装08–0111的h1的Mac,送到接口1。
边栏推荐
- 2022-06-30:以下golang代码输出什么?A:0;B:2;C:运行错误。 package main import “fmt“ func main()
- 2022-2028 global electric yacht industry research and trend analysis report
- Redis - sentinel mode
- 2022-2028 global PTFE lined valve industry research and trend analysis report
- Query points in MATLAB Delaunay triangulation
- Thoughts on the future of data analysis in "miscellaneous talk"
- How to specify the number of cycles in JSTL- How to loop over something a specified number of times in JSTL?
- Detailed explanation of conv2d -- use in arrays and images
- ABAQUS 2022 software installation package and installation tutorial
- Vulnerability discovery - App application vulnerability probe type utilization and repair
猜你喜欢
From January 11, 2007 to January 11, 2022, I have been in SAP Chengdu Research Institute for 15 years
2022-2028 global public address fire alarm system industry research and trend analysis report
To tell you the truth, ThreadLocal is really not an advanced thing
Gateway service gateway
Wechat official account development (1) introduction to wechat official account
VR panorama adds contrast function to make the display of differentiation effect more intuitive!
ABAQUS 2022 latest edition - perfect realistic simulation solution
Bugku CTF daily one question dark cloud invitation code
Docsify building a personal minimalist knowledge warehouse
MySQL variables, stored procedures and functions
随机推荐
Bugku CTF daily one question dark cloud invitation code
JS bubble sort and select sort
When is it appropriate to replace a virtual machine with a virtual machine?
Matlab saves triangulation results as STL files
[designmode] singleton pattern
What value should testers play in requirements review? Two minutes will stop you from being stupid
The programmer's girlfriend gave me a fatigue driving test
Yboj mesh sequence [Lagrange interpolation]
New trend of embedded software development: Devops
A detailed explanation of the implementation principle of go Distributed Link Tracking
NATs cluster deployment
Analysis of 8253a register
需求评审,测试人员应该发挥怎样的价值?两分钟让你不再懵逼
2022-2028 global carbon fiber room scraper system industry research and trend analysis report
Error 2059 when Navicat connects to MySQL
Explain kubernetes backup and recovery tools velero | learn more about carina series phase III
20220215-ctf-misc-buuctf-einstein-binwalk analyze picture-dd command separate zip file -- look for password in picture attribute
Is it safe to buy funds on the compass?
Vmware16 installing win11 virtual machine (the most complete step + stepping on the pit)
Thoughts on the future of data analysis in "miscellaneous talk"