Updated P4 tutorial code/instructions for onos-1.13
Change-Id: Iccaa4114dbe2f408506ef5cf5e5cf7d3e22fb62e
diff --git a/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipelineInterpreterImpl.java b/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipelineInterpreterImpl.java
index 58afa10..77a6dc3 100644
--- a/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipelineInterpreterImpl.java
+++ b/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipelineInterpreterImpl.java
@@ -93,7 +93,7 @@
private static final PiActionId ACT_ID_SEND_TO_CPU =
PiActionId.of(C_INGRESS + DOT + "send_to_cpu");
private static final PiActionId ACT_ID_SET_EGRESS_PORT =
- PiActionId.of(C_INGRESS + DOT + "set_egress_port");
+ PiActionId.of(C_INGRESS + DOT + "set_out_port");
private static final PiActionParamId ACT_PARAM_ID_PORT =
PiActionParamId.of("port");
diff --git a/apps/p4-tutorial/pipeconf/src/main/resources/mytunnel.p4 b/apps/p4-tutorial/pipeconf/src/main/resources/mytunnel.p4
index 7d73489..36de752 100644
--- a/apps/p4-tutorial/pipeconf/src/main/resources/mytunnel.p4
+++ b/apps/p4-tutorial/pipeconf/src/main/resources/mytunnel.p4
@@ -14,6 +14,15 @@
* limitations under the License.
*/
+ /*
+ * This program describes a pipeline implementing a very simple
+ * tunneling protocol called MyTunnel. The pipeline defines also table called
+ * t_l2_fwd that provides basic L2 forwarding capabilities and actions to
+ * send packets to the controller. This table is needed to provide
+ * compatibility with existing ONOS applications such as Proxy-ARP, LLDP Link
+ * Discovery and Reactive Forwarding.
+ */
+
#include <core.p4>
#include <v1model.p4>
@@ -92,6 +101,9 @@
inout metadata_t meta,
inout standard_metadata_t standard_metadata) {
+ // A P4 parser is described as a state machine, with initial state "start"
+ // and final one "accept". Each intermediate state can specify the next
+ // state by using a select statement over the header fields extracted.
state start {
transition select(standard_metadata.ingress_port) {
CPU_PORT: parse_packet_out;
@@ -150,6 +162,8 @@
}
action set_out_port(port_t port) {
+ // Specifies the output port for this packet by setting the
+ // corresponding metadata.
standard_metadata.egress_spec = port;
}
@@ -170,6 +184,8 @@
hdr.my_tunnel.setInvalid();
}
+ // Table counter used to count packets and bytes matched by each entry of
+ // t_l2_fwd table.
direct_counter(CounterType.packets_and_bytes) l2_fwd_counter;
table t_l2_fwd {
@@ -180,9 +196,9 @@
hdr.ethernet.ether_type : ternary;
}
actions = {
- set_out_port();
- send_to_cpu();
- _drop();
+ set_out_port;
+ send_to_cpu;
+ _drop;
NoAction;
}
default_action = NoAction();
@@ -195,7 +211,7 @@
}
actions = {
my_tunnel_ingress;
- _drop();
+ _drop;
}
default_action = _drop();
}
@@ -207,12 +223,13 @@
actions = {
set_out_port;
my_tunnel_egress;
- _drop();
+ _drop;
}
default_action = _drop();
}
- // Define processing applied by this control block.
+ // Defines the processing applied by this control block. You can see this as
+ // the main function applied to every packet received by the switch.
apply {
if (standard_metadata.ingress_port == CPU_PORT) {
// Packet received from CPU_PORT, this is a packet-out sent by the
@@ -223,6 +240,7 @@
hdr.packet_out.setInvalid();
} else {
// Packet received from data plane port.
+ // Applies table t_l2_fwd to the packet.
if (t_l2_fwd.apply().hit) {
// Packet hit an entry in t_l2_fwd table. A forwarding action
// has already been taken. No need to apply other tables, exit