run_exercise.py思考
-
一个P4程序的生命周期要经历:
- 1编写:
- 2编译:
p4c -b bmv2 test.p4 -o test.bmv2
p4c-bm2-ss --p4v 16 --p4runtime-files build/basic.p4.p4info.txt -o build/basic.json basic.p4 - 3构建Mininet拓扑:解析读入的topo文件,指定主机、交换机、链路的种类
调用Mininet的start()方法
def start( self ):
"Start controller and switches."simple_switch_grpc 在启动的时候要指定需要加载的P4.json文件
sudo simple_switch --interface 0@veth0 --interface 1@veth2 --interface 2@veth4 test.bmv2/test.json & - 4安装到P4Switch:由控制平面 或 在启动Mininet拓扑时完成(交换机在步骤3启动,可以无P4.json启动。Makefile中的:
NO_P4 = true起这个作用),# Define NO_P4 to start BMv2 without a program #没有定义NO_P4,则指定P4.json路径,定义了 `NO_P4 = true` 则无P4.json启动 ifndef NO_P4 #ifndef是"if not defined"的简写 run_args += -j $(compiled_json) endif - 5控制平面注入流表:tutorials/p4runtime
- 6simple_switch_CLI:通过thrift端口,直接控制交换机,检查或改变switch的配置,如:注入流表、查看流表
simple_switch_CLI的一些基本命令及示例参考:实验/NO_P4参数作用
-
控制平面:控制平面的功能和SDN中控制平面的功能相比,除了多出一个1,其它完全相同。都是Mininet的基本功能和操作。
- 1安装P编译后的4代码到P4Switch中
- 2向Switch中的流表注入流表项
- 3读取Switch的信息(由P4程序在编写的时候定义那些信息可以读取),如:计数器
备注:
输入:
-
拓扑文件,格式如下。注意:
- 指定:主机名、交换机名、链路名 + 流表项文件名(对应交换机)
- 无需指定:IP地址、MAC地址(run_exercise.py生成)
字典格式:key:"hosts",value:是一个list { "hosts": [ "h1", "h2", "h3" ], "switches": { "s1": { "runtime_json" : "s1-runtime.json" }, "s2": { "runtime_json" : "s2-runtime.json" }, "s3": { "runtime_json" : "s3-runtime.json" } }, "links": [ ["h1", "s1"], ["s1", "s2"], ["s1", "s3"], ["s3", "s2"], ["s2", "h2"], ["s3", "h3"] ] }

浙公网安备 33010602011771号