How JSON Runtime files work

Hello everyone,

I just started learning the p4 and I have some trouble. Firstly, I started using the tutorials that I found on GitHub and they are very helpful but I need someone to explain/ confirm if I understand right how the JSON files work.

For instance, the basic exercise (tutorials/exercises/basic at master · p4lang/tutorials · GitHub) inside the s1-runtime has this:

 {
      "table": "MyIngress.ipv4_lpm",
      "match": {
        "hdr.ipv4.dstAddr": ["10.0.2.2", 32]
      },
      "action_name": "MyIngress.ipv4_forward",
      "action_params": {
        "dstAddr": "08:00:00:00:02:00",
        "port": 2
      }
 }

So, if I’m right whenever a packet arrives at the switch it “searches” (in the basic.p4) for the table that is inside the MyIngress controller with the name “ipv4_lpm”. Then if the “hdr.ipv4.dstAddr” matches with the “10.0.2.2” it enables the action MyIngress.ipv4_forward which has some parameters.

If my assumption of how the JSON file works is correct, I have two questions:

  1. what is the initial value of the hdr.ipv4.dstAddr so the tables can match it with the “10.0.2.2”?
  2. Are these parameters used as variables for the action ipv4_forward? To be more clear here:
 action ipv4_forward(macAddr_t **dstAddr**, egressSpec_t port) {
        standard_metadata.egress_spec = port;
        hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
        hdr.ethernet.dstAddr = dstAddr;
        hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
    }

The dstAddr = 08:00:00:00:02:00 because of the “action_params”: {…} and thus hdr.ethernet.srcAddr = 08:00:00:00:02:00?

Thanks in advance!

The s1-runtime.json, and other -runtime.json, are a data file format specific to the tutorials repository software. Perhaps others have copied that format and used it in other projects, too, but if so I am not aware of which other projects it might also be used in.

The intent is that some Python code in the tutorials repository reads those -runtime.json files during initialization of the simulated set of switches and hosts. After one simple_switch_grpc process has been started for each simulated switch, the -runtime.json file is read, and is parsed to see if it contains any initial table entries to be added to one or more P4 tables.

When a packet is processed by the P4 program, it first parses the packet headers according to the P4 parser code, and then it runs the P4 control called ingress. That ingress control calls ipv4_lpm.apply(), which causes the value of the header field hdr.ipv4.dstAddr, which is a value from the parsed input packet, to be searched among all table entries that have been added to the table ipv4_lpm. The -runtime.json specifies what entries are added to that table before packets start flowing through the simulated network.

1 Like