p4lang / tutorials

P4 language tutorials
Apache License 2.0
1.33k stars 878 forks source link

Add support of pakcetio #542

Closed wei-coding closed 7 months ago

wei-coding commented 7 months ago

By default, when executing the make command in the tutorial exercise, the cpu port option in bmv2 is not provided, rendering the packet in function unusable. I have added a parser option to parse the JSON parameter in the topology.json file to enable the CPU port for the switch. An example of the CPU port option is as follows:

"switches": {
    "s1": {
        "runtime_json": "sig-topo/s1-runtime.json",
        "cpu_port": 255
    }
}
jafingerhut commented 7 months ago

@wei-coding This looks like a useful addition to me. I have not tried testing with it, but I am hoping you have verified that with these changes the existing exercises continue working without needing any changes?

wei-coding commented 7 months ago

Yes, I have tested it on all exercises, and none of them were affected. Additionally, this function will only impact those exercises that require packetio, which is not present in this tutorial. I can upload an exercise I created that uses packetio to implement a learning switch in another pull request (PR).

jafingerhut commented 7 months ago

An exercise that demonstrates packetio definitely sounds like a good one to have in the tutorials exercise collection, if you are interested in submitting one.