当前位置:网站首页>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。
边栏推荐
- VR panorama adds contrast function to make the display of differentiation effect more intuitive!
- Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
- Confirm() method of window
- 2022-2028 global weight loss ginger tea industry research and trend analysis report
- Redis based distributed lock
- New trend of embedded software development: Devops
- Docsify building a personal minimalist knowledge warehouse
- Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
- Solutions to errors in installing OpenSSL for CentOS 6.3 x64 PHP 5.2.6 extensions
- Interface documentation system - Yapi
猜你喜欢

ABAQUS 2022 latest edition - perfect realistic simulation solution

IFLYTEK active competition summary! (12)

Which is better, server rental or hosting services in the United States?

Oracle-数据完整性

Member management applet actual development 07 page Jump

Vulnerability discovery - App application vulnerability probe type utilization and repair

Docsify building a personal minimalist knowledge warehouse

2022-2028 global weight loss ginger tea industry research and trend analysis report

2022-2028 global capsule shell industry research and trend analysis report

20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
随机推荐
VR panorama adds contrast function to make the display of differentiation effect more intuitive!
Search rotation sort array
Makefile notes (Yiwen Institute makefile)
CTF tool (1) -- archpr -- including installation / use process
2022-2028 global retro glass industry research and trend analysis report
"Experience" my understanding of user growth "new users"
[PHP] self developed framework qphp, used by qphp framework
lvm-snapshot:基于LVM快照的备份之准备工作
Solutions to errors in installing OpenSSL for CentOS 6.3 x64 PHP 5.2.6 extensions
Operation record of reinitialization instance of Dameng database
Teach you how to use Hal library to get started -- become a lighting master
Kubernetes ---- pod configuration container start command
LVM snapshot: backup based on LVM snapshot
Using Excel to quickly generate SQL statements
Is it safe to choose mobile phone for stock trading account opening in Hangzhou?
20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
NE555波形发生器手把手教程之NE555内部结构(一)
Vulnerability discovery - App application vulnerability probe type utilization and repair
Repetition is the mother of skill
2022-2028 global rotary transmission system industry research and trend analysis report