Skip to content

Commit 8ac4f12

Browse files
authored
Fix duplication and clarify P4 parsing instructions
Removed duplicate instructions for running the P4 program and clarified the parsing process in P4 with examples.
1 parent 1f50a85 commit 8ac4f12

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,12 @@ struct standard_metadata_t {
266266
- `bmv2.json`: This file contains the compiled P4 program in JSON format, which is used by the Stratum software switch to configure the P4 pipeline.
267267
- `p4info.txt`: This file contains details that can be used by the P4 Runtime controller to interact with the P4 program running in the switch. This is something that we will explore in more detail in future exercises.
268268

269-
When you run the command `make start`, the Makefile will automatically compile the P4 program and load it into the Stratum software switch. You can check the switch's logs to see if the P4 program loaded successfully. If everything went well, you should see a message like this in the logs: `I0106 11:32:50.123456 88 p4_pipeline_builder.cc:123] P4 pipeline successfully loaded`. Furthermore, you can use the small `send_receive.py` script located in the `mininet/` folder (inside the `mn-stratum` container this is directory is mounted a `/mininet/`) to test the functionality of the switch. This script sends a packet from a host to the switch and waits for a copy of the packet. If you connect to the mininet CLI using the command `make mn-cli` and run the command `mininet> homePC python3 /mininet/send_receive.py 192.168.0.5`, you should see that the packet is sent from the phone host to the switch and read the following output:
269+
When you run the command `make start`, the Makefile will automatically compile the P4 program and load it into the Stratum software switch. You can check the switch's logs to see if the P4 program loaded successfully. If everything went well, you should see a message like this in the logs: `I0106 11:32:50.123456 88 p4_pipeline_builder.cc:123] P4 pipeline successfully loaded`. Furthermore, you can use the small `send_receive.py` script located in the `mininet/` folder (inside the `mn-stratum` container this is directory is mounted a `/mininet/`) to test the functionality of the switch. This script sends a packet from a host to the switch and waits for a copy of the packet. If you connect to the mininet CLI using the command `make mn-cli` and run the command `mininet> homePC python3 /mininet/send_receive.py 192.168.0.5`, you should see that the packet is sent from the phone host to the switch and read the following output (**The message should appear twice. If the P4 program is not loaded correctly, then you will see the message only once, for the outgoing packet.**):
270270

271271
```
272+
[!] A packet was reflected from the switch:
273+
[!] Info: 00:01:02:03:04:05 -> da:2a:0a:c7:d7:96
274+
272275
[!] A packet was reflected from the switch:
273276
[!] Info: 00:01:02:03:04:05 -> da:2a:0a:c7:d7:96
274277
```
@@ -323,7 +326,7 @@ parser MyParser(packet_in packet,
323326
324327
This code block updates the `MyParser` block to extract the Ethernet header from the incoming packet. The `packet.extract(hdr.ethernet);` line extracts the Ethernet header and stores it in the `hdr.ethernet` field of the `headers` struct. The parser then transitions to the `accept` state, indicating that the parsing is complete.
325328
326-
Parsing in P4 is performed [using a state machine](https://p4.org/wp-content/uploads/sites/53/2024/10/P4-16-spec-v1.2.5.pdf#page=104.63), where each state corresponds to a specific parsing step. In this case, we have a single state called `start`, which extracts the Ethernet header and then transitions to the `accept` state. You can add more states to the parser to extract additional headers as needed. Lets consider a hypothetical more complex example of a P4 program processing IPv4 and IPv6 packets. In this case, you will need to extract the IP header using a different header structure, depending on the type value in the Ethernet header. You should add two new states that extracts the different IP header after the Ethernet header has been parsed, while the start logic would transition to that new state instead of directly to accept, based on the `etherType` field of the Ethernet header. For example:
329+
Parsing in P4 is performed [using a state machine](https://p4.org/wp-content/uploads/sites/53/2024/10/P4-16-spec-v1.2.5.pdf#page=104.63), where each state corresponds to a specific parsing step. In this case, we have a single state called `start`, which extracts the Ethernet header and then transitions to the `accept` state. You can add more states to the parser to extract additional headers as needed. Let's consider a **hypothetical**, more complex example of a P4 program processing IPv4 and IPv6 packets. In this case, you will need to extract the IP header using a different header structure, depending on the Ethernet header's ethType value. You should add two new states that extract the different IP headers after the Ethernet header has been parsed, while the start logic would transition to that new state instead of directly to accept, based on the `etherType` field of the Ethernet header. For example:
327330
328331
```C
329332
state start{

0 commit comments

Comments
 (0)