Skip to content

Commit

Permalink
clean-up trailing whitespace (p4lang#453)
Browse files Browse the repository at this point in the history
These changes have been mostly auto-generated with:

	find . -type f -print0 | xargs -0 perl -pi -e 's/ +$//'

Signed-off-by: Radostin Stoyanov <[email protected]>
  • Loading branch information
rst0git authored Feb 24, 2022
1 parent 071b89a commit 50f397b
Show file tree
Hide file tree
Showing 42 changed files with 275 additions and 275 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ you get started with P4 programming, organized into several modules:
* [Firewall](./exercises/firewall)
* [Link Monitoring](./exercises/link_monitor)

## Presentation
## Presentation

The slides are available [online](http://bit.ly/p4d2-2018-spring) and
in the P4_tutorial.pdf in the tutorial directory.
Expand All @@ -46,7 +46,7 @@ The documentation for P4_16 and P4Runtime is available [here](https://p4.org/spe
All excercises in this repository use the v1model architecture, the documentation for which is available at:
1. The BMv2 Simple Switch target document accessible [here](https://github.com/p4lang/behavioral-model/blob/master/docs/simple_switch.md) talks mainly about the v1model architecture.
2. The include file `v1model.p4` has extensive comments and can be accessed [here](https://github.com/p4lang/p4c/blob/master/p4include/v1model.p4).

## Obtaining required software

If you are starting this tutorial at one of the proctored tutorial events,
Expand Down
14 changes: 7 additions & 7 deletions exercises/basic/basic.p4
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ parser MyParser(packet_in packet,
************ C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/

control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}

Expand All @@ -77,11 +77,11 @@ control MyIngress(inout headers hdr,
action drop() {
mark_to_drop(standard_metadata);
}

action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
/* TODO: fill out code in action body */
}

table ipv4_lpm {
key = {
hdr.ipv4.dstAddr: lpm;
Expand All @@ -94,7 +94,7 @@ control MyIngress(inout headers hdr,
size = 1024;
default_action = NoAction();
}

apply {
/* TODO: fix ingress control logic
* - ipv4_lpm should be applied only when IPv4 header is valid
Expand All @@ -119,10 +119,10 @@ control MyEgress(inout headers hdr,

control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply {
update_checksum(
hdr.ipv4.isValid(),
update_checksum(
hdr.ipv4.isValid(),
{ hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.ihl,
hdr.ipv4.diffserv,
hdr.ipv4.totalLen,
hdr.ipv4.identification,
Expand Down
14 changes: 7 additions & 7 deletions exercises/basic/solution/basic.p4
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ parser MyParser(packet_in packet,
************ C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/

control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}

Expand All @@ -89,14 +89,14 @@ control MyIngress(inout headers hdr,
action drop() {
mark_to_drop(standard_metadata);
}

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;
}

table ipv4_lpm {
key = {
hdr.ipv4.dstAddr: lpm;
Expand All @@ -109,7 +109,7 @@ control MyIngress(inout headers hdr,
size = 1024;
default_action = drop();
}

apply {
if (hdr.ipv4.isValid()) {
ipv4_lpm.apply();
Expand All @@ -133,10 +133,10 @@ control MyEgress(inout headers hdr,

control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply {
update_checksum(
hdr.ipv4.isValid(),
update_checksum(
hdr.ipv4.isValid(),
{ hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.ihl,
hdr.ipv4.diffserv,
hdr.ipv4.totalLen,
hdr.ipv4.identification,
Expand Down
2 changes: 1 addition & 1 deletion exercises/basic/triangle-topo/topology.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"s3": { "runtime_json" : "triangle-topo/s3-runtime.json" }
},
"links": [
["h1", "s1-p1"], ["s1-p2", "s2-p2"], ["s1-p3", "s3-p2"],
["h1", "s1-p1"], ["s1-p2", "s2-p2"], ["s1-p3", "s3-p2"],
["s3-p3", "s2-p3"], ["h2", "s2-p1"], ["h3", "s3-p1"]
]
}
12 changes: 6 additions & 6 deletions exercises/basic_tunnel/basic_tunnel.p4
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ parser MyParser(packet_in packet,
************ C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/

control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}

Expand All @@ -101,14 +101,14 @@ control MyIngress(inout headers hdr,
action drop() {
mark_to_drop(standard_metadata);
}

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;
}

table ipv4_lpm {
key = {
hdr.ipv4.dstAddr: lpm;
Expand Down Expand Up @@ -153,10 +153,10 @@ control MyEgress(inout headers hdr,

control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply {
update_checksum(
hdr.ipv4.isValid(),
update_checksum(
hdr.ipv4.isValid(),
{ hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.ihl,
hdr.ipv4.diffserv,
hdr.ipv4.totalLen,
hdr.ipv4.identification,
Expand Down
14 changes: 7 additions & 7 deletions exercises/basic_tunnel/solution/basic_tunnel.p4
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ parser MyParser(packet_in packet,
************ C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/

control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}

Expand All @@ -105,14 +105,14 @@ control MyIngress(inout headers hdr,
action drop() {
mark_to_drop(standard_metadata);
}

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;
}

table ipv4_lpm {
key = {
hdr.ipv4.dstAddr: lpm;
Expand All @@ -125,7 +125,7 @@ control MyIngress(inout headers hdr,
size = 1024;
default_action = drop();
}

action myTunnel_forward(egressSpec_t port) {
standard_metadata.egress_spec = port;
}
Expand Down Expand Up @@ -171,10 +171,10 @@ control MyEgress(inout headers hdr,

control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply {
update_checksum(
hdr.ipv4.isValid(),
update_checksum(
hdr.ipv4.isValid(),
{ hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.ihl,
hdr.ipv4.diffserv,
hdr.ipv4.totalLen,
hdr.ipv4.identification,
Expand Down
10 changes: 5 additions & 5 deletions exercises/calc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ switch in Mininet to test its behavior.
```
This will:
* compile `calc.p4`, and

* start a Mininet instance with one switches (`s1`) connected to
two hosts (`h1`, `h2`).
* The hosts are assigned IPs of `10.0.1.1` and `10.0.1.2`.
Expand All @@ -33,8 +33,8 @@ you to test your calculator. You can run the driver program directly
from the Mininet command prompt:

```
mininet> h1 python calc.py
>
mininet> h1 python calc.py
>
```

3. The driver program will provide a new prompt, at which you can type
Expand Down Expand Up @@ -70,7 +70,7 @@ We will use the following header format:
+----------------+----------------+----------------+---------------+
| Result |
+----------------+----------------+----------------+---------------+


- P is an ASCII Letter 'P' (0x50)
- 4 is an ASCII Letter '4' (0x34)
Expand All @@ -81,7 +81,7 @@ We will use the following header format:
- '&' (0x26) Result = OperandA & OperandB
- '|' (0x7c) Result = OperandA | OperandB
- '^' (0x5e) Result = OperandA ^ OperandB


We will assume that the calculator header is carried over Ethernet,
and we will use the Ethernet type 0x1234 to indicate the presence of
Expand Down
38 changes: 19 additions & 19 deletions exercises/calc/calc.p4
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
* '|' (0x7c) Result = OperandA | OperandB
* '^' (0x5e) Result = OperandA ^ OperandB
*
* The device receives a packet, performs the requested operation, fills in the
* result and sends the packet back out of the same port it came in on, while
* The device receives a packet, performs the requested operation, fills in the
* result and sends the packet back out of the same port it came in on, while
* swapping the source and destination addresses.
*
* If an unknown operation is specified or the header is not valid, the packet
* is dropped
* is dropped
*/

#include <core.p4>
Expand All @@ -45,7 +45,7 @@
*/

/*
* Standard Ethernet header
* Standard Ethernet header
*/
header ethernet_t {
bit<48> dstAddr;
Expand All @@ -54,7 +54,7 @@ header ethernet_t {
}

/*
* This is a custom protocol header for the calculator. We'll use
* This is a custom protocol header for the calculator. We'll use
* etherType 0x1234 for it (see parser)
*/
const bit<16> P4CALC_ETYPE = 0x1234;
Expand Down Expand Up @@ -86,12 +86,12 @@ struct headers {
}

/*
* All metadata, globally used in the program, also needs to be assembled
* into a single struct. As in the case of the headers, we only need to
* All metadata, globally used in the program, also needs to be assembled
* into a single struct. As in the case of the headers, we only need to
* declare the type, but there is no need to instantiate it,
* because it is done "by the architecture", i.e. outside of P4 functions
*/

struct metadata {
/* In our case it is empty */
}
Expand All @@ -102,18 +102,18 @@ struct metadata {
parser MyParser(packet_in packet,
out headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
inout standard_metadata_t standard_metadata) {
state start {
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.etherType) {
P4CALC_ETYPE : check_p4calc;
default : accept;
}
}

state check_p4calc {
/* TODO: just uncomment the following parse block */
/*
/*
transition select(packet.lookahead<p4calc_t>().p,
packet.lookahead<p4calc_t>().four,
packet.lookahead<p4calc_t>().ver) {
Expand All @@ -122,7 +122,7 @@ parser MyParser(packet_in packet,
}
*/
}

state parse_p4calc {
packet.extract(hdr.p4calc);
transition accept;
Expand Down Expand Up @@ -151,21 +151,21 @@ control MyIngress(inout headers hdr,
* - Send the packet back to the port it came from
by saving standard_metadata.ingress_port into
standard_metadata.egress_spec
*/
*/
}

action operation_add() {
/* TODO call send_back with operand_a + operand_b */
}

action operation_sub() {
/* TODO call send_back with operand_a - operand_b */
}

action operation_and() {
/* TODO call send_back with operand_a & operand_b */
}

action operation_or() {
/* TODO call send_back with operand_a | operand_b */
}
Expand All @@ -177,7 +177,7 @@ control MyIngress(inout headers hdr,
action operation_drop() {
mark_to_drop(standard_metadata);
}

table calculate {
key = {
hdr.p4calc.op : exact;
Expand All @@ -199,7 +199,7 @@ control MyIngress(inout headers hdr,
P4CALC_CARET: operation_xor();
}
}

apply {
if (hdr.p4calc.isValid()) {
calculate.apply();
Expand Down
Loading

0 comments on commit 50f397b

Please sign in to comment.