128 lines
4.0 KiB
Plaintext

/* -*- P4_16 -*- */
/*
* P4 Calculator
*
* This program implements a simple protocol. It can be carried over Ethernet
* (Ethertype 0x1234).
*
* The Protocol header looks like this:
*
* 0 1 2 3
* +----------------+----------------+----------------+---------------+
* | P | 4 | Version | Op |
* +----------------+----------------+----------------+---------------+
* | Operand A |
* +----------------+----------------+----------------+---------------+
* | Operand B |
* +----------------+----------------+----------------+---------------+
* | Result |
* +----------------+----------------+----------------+---------------+
*
* P is an ASCII Letter 'P' (0x50)
* 4 is an ASCII Letter '4' (0x34)
* Version is currently 0.1 (0x01)
* Op is an operation to Perform:
* '+' (0x2b) Result = OperandA + OperandB
* '-' (0x2d) Result = OperandA - OperandB
* '&' (0x26) Result = OperandA & OperandB
* '|' (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
* swapping the source and destination addresses.
*
* If an unknown operation is specified or the header is not valid, the packet
* is dropped
*/
#include <core.p4>
#include <v1model.p4>
/*
* Define the headers the program will recognize
*/
struct my_headers_t {
/* TODO: fill this in */
}
struct my_metadata_t {
/* In our case it is empty */
}
/*************************************************************************
*********************** P A R S E R ***********************************
*************************************************************************/
parser MyParser(
packet_in packet,
out my_headers_t hdr,
inout my_metadata_t meta,
inout standard_metadata_t standard_metadata)
{
state start { transition accept; }
}
/*************************************************************************
************ C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/
control MyVerifyChecksum(
inout my_headers_t hdr,
inout my_metadata_t meta)
{
apply {
}
}
/*************************************************************************
************** I N G R E S S P R O C E S S I N G *******************
*************************************************************************/
control MyIngress(
inout my_headers_t hdr,
inout my_metadata_t meta,
inout standard_metadata_t standard_metadata)
{
apply { }
}
/*************************************************************************
**************** E G R E S S P R O C E S S I N G *******************
*************************************************************************/
control MyEgress(
inout my_headers_t hdr,
inout my_metadata_t meta,
inout standard_metadata_t standard_metadata) {
apply { }
}
/*************************************************************************
************* C H E C K S U M C O M P U T A T I O N **************
*************************************************************************/
control MyComputeChecksum(
inout my_headers_t hdr,
inout my_metadata_t meta)
{
apply { }
}
/*************************************************************************
*********************** D E P A R S E R *******************************
*************************************************************************/
control MyDeparser(
packet_out packet,
in my_headers_t hdr)
{
apply { }
}
V1Switch(
MyParser(),
MyVerifyChecksum(),
MyIngress(),
MyEgress(),
MyComputeChecksum(),
MyDeparser()
) main;