From 4a8eb5b2b4f8f97f11eaeda6affe0f338a47f1d8 Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 26 May 2019 10:57:58 +0200 Subject: [PATCH] ad minip4, update paths --- netpfga/bashinit | 6 +- netpfga/minip4/src/minip4_solution.p4 | 109 ++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 netpfga/minip4/src/minip4_solution.p4 diff --git a/netpfga/bashinit b/netpfga/bashinit index e3af8d2..5c3d906 100644 --- a/netpfga/bashinit +++ b/netpfga/bashinit @@ -1,12 +1,14 @@ +export XILINXD_LICENSE_FILE=2100@samichlaus.ethz.ch + ##### Vivado ##### -. /opt/Xilinx/Vivado/2018.3/settings64.sh +. /opt/Xilinx/Vivado/2018.2/settings64.sh +export PATH=$PATH:/opt/Xilinx/Vivado/2018.2/bin #### P4-NetFPGA ##### . ~/projects/P4-NetFPGA/tools/settings.sh #### SDNet #### export PATH=$PATH:/opt/xilinx/SDNet/2018.2/bin -export PATH=$PATH:/opt/Xilinx/Vivado/2018.3/bin . /opt/xilinx/SDNet/2018.2/settings64.sh # set DISPLAY env variable so that xsct works properly from cmdline diff --git a/netpfga/minip4/src/minip4_solution.p4 b/netpfga/minip4/src/minip4_solution.p4 new file mode 100644 index 0000000..117c571 --- /dev/null +++ b/netpfga/minip4/src/minip4_solution.p4 @@ -0,0 +1,109 @@ +#include +#include + +/* + Switch Calculator: + P4 program to use switch as a calculator and key-value lookup engine + */ + +typedef bit<48> EthAddr_t; + +#define REG_READ 8w0 +#define REG_WRITE 8w1 + +#define INDEX_WIDTH 4 // determines depth of const register + +// define opCode types +#define ADD_OP 8w0 +#define SUB_OP 8w1 +#define LOOKUP_OP 8w2 +#define ADD_REG_OP 8w3 +#define SET_REG_OP 8w4 + +// standard Ethernet header +header Ethernet_h { + EthAddr_t dstAddr; + EthAddr_t srcAddr; + bit<16> etherType; +} + +// List of all recognized headers +struct Parsed_packet { + Ethernet_h ethernet; +} + +// user defined metadata: can be used to share information between +// TopParser, TopPipe, and TopDeparser +struct user_metadata_t { + bit<8> unused; +} + +// digest_data, MUST be 256 bits +struct digest_data_t { + bit<256> unused; +} + +// Parser Implementation +@Xilinx_MaxPacketRegion(1024) +parser TopParser(packet_in b, + out Parsed_packet p, + out user_metadata_t user_metadata, + out digest_data_t digest_data, + inout sume_metadata_t sume_metadata) { + state start { + b.extract(p.ethernet); + user_metadata.unused = 0; + digest_data.unused = 0; + + transition accept; + } +} + +// match-action pipeline +control TopPipe(inout Parsed_packet p, + inout user_metadata_t user_metadata, + inout digest_data_t digest_data, + inout sume_metadata_t sume_metadata) { + + action swap_eth_addresses() { + EthAddr_t temp = p.ethernet.dstAddr; + p.ethernet.dstAddr = p.ethernet.srcAddr; + p.ethernet.srcAddr = temp; + } + + action do_nothing() { + EthAddr_t temp = p.ethernet.dstAddr; + } + + table lookup_table { + key = { p.ethernet.dstAddr: exact; } + + actions = { + swap_eth_addresses; + do_nothing; + } + size = 64; + default_action = do_nothing; + } + + apply { + lookup_table.apply(); + } +} + + +// Deparser Implementation +@Xilinx_MaxPacketRegion(1024) +control TopDeparser(packet_out b, + in Parsed_packet p, + in user_metadata_t user_metadata, + inout digest_data_t digest_data, + inout sume_metadata_t sume_metadata) { + apply { + b.emit(p.ethernet); + } +} + + +// Instantiate the switch +SimpleSumeSwitch(TopParser(), TopPipe(), TopDeparser()) main;