Tofino 实现多pipeline不同程序的方法

PS:tna_32q_multiprogram的原始位置为: /home/admin/bin/bf-sde-9.7.0/pkgsrc/p4-examples/p4_16_programs/tna_32q_multiprogram
本教程当前版本仅仅关心它的P4文件,控制面下表暂未探索

  1. 编译:分别编译两个文件,案例如下:
1
2
~/bin/bf-sde-9.7.0/tools/p4_build.sh ~/p4_program/tna_32q_multiprogram/program_a/tna_32q_multiprogram_a.p4
~/bin/bf-sde-9.7.0/tools/p4_build.sh ~/p4_program/tna_32q_multiprogram/program_b/tna_32q_multiprogram_b.p4
  1. 修改.conf文件:
    1. 通过第一步之后,在形如/home/admin/bin/bf-sde-9.7.0/install/share/p4/targets/tofino 的文件夹中会有.conf文件,案例中名称为tna_32q_multiprogram_a.conf和tna_32q_multiprogram_b.conf;
    2. 复制tna_32q_multiprogram_a.conf,重命名为tna_32q_multiprogram.conf
    3. 在新文件中复制tna_32q_multiprogram_b.conf的”p4_programs”中的大括号的内容到tna_32q_multiprogram.conf中,并且修改pipe_scope变量指定pipeline;注意:我们的tofino1交换机只有两个pipeline 因此应该分别为0和1;
  2. 运行:$SDE/run_switchd.sh -p tna_32q_multiprogram 这一步最后的名字和conf文件的前半部分相同。

案例中的文件

  1. tna_32q_multiprogram_a.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
"chip_list": [
{
"id": "asic-0",
"chip_family": "tofino",
"instance": 0,
"pcie_sysfs_prefix": "/sys/devices/pci0000:00/0000:00:03.0/0000:05:00.0",
"pcie_domain": 0,
"pcie_bus": 5,
"pcie_fn": 0,
"pcie_dev": 0,
"pcie_int_mode": 1,
"sds_fw_path": "share/tofino_sds_fw/avago/firmware"
"sds_fw_path": "share/tofino_sds_fw/avago/firmware"
}
],
"instance": 0,
"p4_devices": [
{
"device-id": 0,
"p4_programs": [
{
"program-name": "tna_32q_multiprogram_a",
"bfrt-config": "share/tofinopd/tna_32q_multiprogram_a/bf-rt.json",
"p4_pipelines": [
{
"p4_pipeline_name": "profile_a",
"context": "share/tofinopd/tna_32q_multiprogram_a/profile_a/context.json",
"config": "share/tofinopd/tna_32q_multiprogram_a/profile_a/tofino.bin",
"pipe_scope": [
0,
1,
2,
3
],
"path": "share/tofinopd/tna_32q_multiprogram_a"
}
]
}
],
"agent0": "lib/libpltfm_mgr.so"
}
]
}
  1. tna_32q_multiprogram_b.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
"chip_list": [
{
"id": "asic-0",
"chip_family": "tofino",
"instance": 0,
"pcie_sysfs_prefix": "/sys/devices/pci0000:00/0000:00:03.0/0000:05:00.0",
"pcie_domain": 0,
"pcie_bus": 5,
"pcie_fn": 0,
"pcie_dev": 0,
"pcie_int_mode": 1,
"sds_fw_path": "share/tofino_sds_fw/avago/firmware"
}
],
"instance": 0,
"p4_devices": [
{
"device-id": 0,
"p4_programs": [
{
"program-name": "tna_32q_multiprogram_b",
"bfrt-config": "share/tofinopd/tna_32q_multiprogram_b/bf-rt.json",
"p4_pipelines": [
{
"p4_pipeline_name": "profile_b",
"context": "share/tofinopd/tna_32q_multiprogram_b/profile_b/context.json",
"config": "share/tofinopd/tna_32q_multiprogram_b/profile_b/tofino.bin",
"pipe_scope": [
0,
1,
2,
3
],
"path": "share/tofinopd/tna_32q_multiprogram_b"
}
]
}
],
"agent0": "lib/libpltfm_mgr.so"
}
]
}
  1. tna_32q_multiprogram.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
"chip_list": [
{
"id": "asic-0",
"chip_family": "tofino",
"instance": 0,
"pcie_sysfs_prefix": "/sys/devices/pci0000:00/0000:00:03.0/0000:05:00.0",
"pcie_domain": 0,
"pcie_bus": 5,
"pcie_fn": 0,
"pcie_dev": 0,
"pcie_int_mode": 1,
"sds_fw_path": "share/tofino_sds_fw/avago/firmware"

}
],
"instance": 0,
"p4_devices": [
{
"device-id": 0,
"p4_programs": [
{
"program-name": "tna_32q_multiprogram_a",
"bfrt-config": "share/tofinopd/tna_32q_multiprogram_a/bf-rt.json",
"p4_pipelines": [
{
"p4_pipeline_name": "profile_a",
"context": "share/tofinopd/tna_32q_multiprogram_a/profile_a/context.json",
"config": "share/tofinopd/tna_32q_multiprogram_a/profile_a/tofino.bin",
"pipe_scope": [
0
],
"path": "share/tofinopd/tna_32q_multiprogram_a"
}
]
},
{
"program-name": "tna_32q_multiprogram_b",
"bfrt-config": "share/tofinopd/tna_32q_multiprogram_b/bf-rt.json",
"p4_pipelines": [
{
"p4_pipeline_name": "profile_b",
"context": "share/tofinopd/tna_32q_multiprogram_b/profile_b/context.json",
"config": "share/tofinopd/tna_32q_multiprogram_b/profile_b/tofino.bin",
"pipe_scope": [
1
],
"path": "share/tofinopd/tna_32q_multiprogram_b"
}
]
}
],
"agent0": "lib/libpltfm_mgr.so"
}
]
}