Updates to basic_tunnel and basic (#78)

* Adding initial implementation of basic_encap example

* Updated basic_encap example to count the number of valid packets

* Updated basic_encap example to put encapsulation layer after Ethernet
header.

* Added solution file for basic_encap example

* Changed the name of the basic_encap example to basic_tunnel and called
the new header myTunnel. Also changed the myTunnel field names slightly.

* Updated the README file for the basic_tunnel exercise. Also added topo.pdf
image to serve as a reference during implementation.

* Updated basic/README.md to point to basic_tunnel as the next exercise.

* Updated the README for basic to point to basic_tunnel.

Updated the starter code for basic_tunnel to look like basic
solution with todo comments.

Updated send.py and receive.py to be able to send both plain IP
packets and tunneled IP packets.

Updated basic_tunnel.p4 to have same control flow as p4runtime
exercise.
This commit is contained in:
sibanez12
2017-11-03 21:03:06 -07:00
committed by Robert Soule
parent 66c2cba1b5
commit 6c82b6fbe7
8 changed files with 128 additions and 125 deletions

View File

@@ -2,6 +2,7 @@
#include <core.p4>
#include <v1model.p4>
// NOTE: new type added here
const bit<16> TYPE_MYTUNNEL = 0x1212;
const bit<16> TYPE_IPV4 = 0x800;
@@ -19,6 +20,7 @@ header ethernet_t {
bit<16> etherType;
}
// NOTE: added new header type
header myTunnel_t {
bit<16> proto_id;
bit<16> dst_id;
@@ -43,6 +45,7 @@ struct metadata {
/* empty */
}
// NOTE: Added new header type to headers struct
struct headers {
ethernet_t ethernet;
myTunnel_t myTunnel;
@@ -53,6 +56,7 @@ struct headers {
*********************** P A R S E R ***********************************
*************************************************************************/
// TODO: Update the parser to parse the myTunel header as well
parser MyParser(packet_in packet,
out headers hdr,
inout metadata meta,
@@ -65,17 +69,8 @@ parser MyParser(packet_in packet,
state parse_ethernet {
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.etherType) {
TYPE_MYTUNNEL: parse_myTunnel;
TYPE_IPV4: parse_ipv4;
default: accept;
}
}
state parse_myTunnel {
packet.extract(hdr.myTunnel);
transition select(hdr.myTunnel.proto_id) {
TYPE_IPV4: parse_ipv4;
default: accept;
TYPE_IPV4 : parse_ipv4;
default : accept;
}
}
@@ -84,6 +79,7 @@ parser MyParser(packet_in packet,
transition accept;
}
}
/*************************************************************************
@@ -125,27 +121,17 @@ control MyIngress(inout headers hdr,
size = 1024;
default_action = NoAction();
}
action myTunnel_forward(egressSpec_t port) {
standard_metadata.egress_spec = port;
}
table myTunnel_exact {
key = {
hdr.myTunnel.dst_id: exact;
}
actions = {
myTunnel_forward;
drop;
}
size = 1024;
default_action = drop();
}
// TODO: declare a new action: myTunnel_forward(egressSpec_t port)
// TODO: declare a new table: myTunnel_exact
// TODO: also remember to add table entries!
apply {
if (hdr.myTunnel.isValid()) {
myTunnel_exact.apply();
} else if (hdr.ipv4.isValid()) {
// TODO: Update control flow
if (hdr.ipv4.isValid()) {
ipv4_lpm.apply();
}
}
@@ -192,7 +178,7 @@ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
control MyDeparser(packet_out packet, in headers hdr) {
apply {
packet.emit(hdr.ethernet);
packet.emit(hdr.myTunnel);
// TODO: emit myTunnel header as well
packet.emit(hdr.ipv4);
}
}