2019-07-23 10:21:49 +00:00
|
|
|
#include <core.p4>
|
|
|
|
#include <sume_switch.p4>
|
|
|
|
#include "headers.p4"
|
|
|
|
|
2019-07-24 10:15:26 +00:00
|
|
|
#define Parsed_packet headers
|
|
|
|
#define user_metadata_t metadata
|
2019-07-24 10:01:47 +00:00
|
|
|
|
2019-07-24 21:45:40 +00:00
|
|
|
// digest_data, MUST be 256 bits -- not using it
|
2019-07-23 10:21:49 +00:00
|
|
|
struct digest_data_t {
|
|
|
|
bit<256> unused;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
* Parser
|
2019-07-24 07:49:17 +00:00
|
|
|
*/
|
|
|
|
parser RealParser(
|
|
|
|
packet_in packet,
|
|
|
|
out Parsed_packet hdr,
|
|
|
|
out user_metadata_t meta,
|
|
|
|
out digest_data_t digest_data,
|
|
|
|
inout sume_metadata_t standard_metadata) {
|
|
|
|
|
|
|
|
state start {
|
2019-07-24 07:57:16 +00:00
|
|
|
packet.extract(hdr.ethernet);
|
2019-07-24 10:15:26 +00:00
|
|
|
// meta.unused = 0;
|
2019-07-24 07:57:16 +00:00
|
|
|
digest_data.unused = 0;
|
|
|
|
transition accept;
|
2019-07-24 07:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 10:21:49 +00:00
|
|
|
|
|
|
|
@Xilinx_MaxPacketRegion(1024)
|
2019-07-23 21:20:41 +00:00
|
|
|
parser TopParser(
|
2019-07-24 07:36:24 +00:00
|
|
|
packet_in b,
|
|
|
|
out Parsed_packet p,
|
2019-07-23 21:20:41 +00:00
|
|
|
out user_metadata_t user_metadata,
|
|
|
|
out digest_data_t digest_data,
|
2019-07-24 07:36:24 +00:00
|
|
|
inout sume_metadata_t sume_metadata) {
|
2019-07-23 21:20:41 +00:00
|
|
|
|
2019-07-24 07:49:17 +00:00
|
|
|
RealParser() realparser;
|
2019-07-23 14:06:18 +00:00
|
|
|
|
2019-07-24 07:53:13 +00:00
|
|
|
state start {
|
2019-07-24 07:49:17 +00:00
|
|
|
realparser.apply(b, p, user_metadata, digest_data, sume_metadata);
|
2019-07-23 14:06:18 +00:00
|
|
|
transition accept;
|
|
|
|
}
|
2019-07-23 21:20:41 +00:00
|
|
|
}
|
2019-07-23 10:22:31 +00:00
|
|
|
|
2019-07-23 21:20:41 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Main
|
2019-07-24 09:22:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
control RealMain(
|
|
|
|
inout Parsed_packet hdr,
|
|
|
|
inout user_metadata_t meta,
|
2019-07-23 21:20:41 +00:00
|
|
|
inout digest_data_t digest_data,
|
|
|
|
inout sume_metadata_t sume_metadata) {
|
|
|
|
|
2019-07-24 09:45:37 +00:00
|
|
|
#include "actions_nat64_generic.p4"
|
2019-07-24 11:08:02 +00:00
|
|
|
#include "actions_egress.p4"
|
2019-07-24 20:48:21 +00:00
|
|
|
#include "actions_delta_checksum.p4"
|
2019-07-24 20:27:36 +00:00
|
|
|
|
2019-07-24 09:45:37 +00:00
|
|
|
|
2019-07-23 21:20:41 +00:00
|
|
|
action swap_eth_addresses() {
|
2019-07-24 10:15:26 +00:00
|
|
|
mac_addr_t temp = hdr.ethernet.dst_addr;
|
|
|
|
hdr.ethernet.dst_addr = hdr.ethernet.src_addr;
|
|
|
|
hdr.ethernet.src_addr = temp;
|
2019-07-23 21:20:41 +00:00
|
|
|
|
|
|
|
/* set egress port */
|
|
|
|
sume_metadata.dst_port = sume_metadata.src_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
action send_to_port1() {
|
|
|
|
sume_metadata.dst_port = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
action send_to_all_ports() {
|
|
|
|
/* Taken from commands.txt of the "int" project:
|
|
|
|
table_cam_add_entry forward set_output_port 0xffffffffffff => 0b01010101
|
|
|
|
|
|
|
|
python convert:
|
|
|
|
>>> 0b01010101
|
|
|
|
85
|
|
|
|
|
|
|
|
*/
|
|
|
|
sume_metadata.dst_port = 85;
|
|
|
|
}
|
|
|
|
|
|
|
|
action do_nothing() {
|
2019-07-24 10:15:26 +00:00
|
|
|
mac_addr_t temp = hdr.ethernet.dst_addr;
|
2019-07-23 21:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
table lookup_table {
|
|
|
|
key = {
|
2019-07-24 10:15:26 +00:00
|
|
|
hdr.ethernet.dst_addr: exact;
|
2019-07-23 21:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
swap_eth_addresses;
|
|
|
|
do_nothing;
|
|
|
|
send_to_port1;
|
|
|
|
send_to_all_ports;
|
|
|
|
}
|
|
|
|
size = 64;
|
|
|
|
default_action = send_to_port1; // test_port1()
|
|
|
|
}
|
|
|
|
|
|
|
|
apply {
|
2019-07-24 21:45:40 +00:00
|
|
|
bit<17> tmp17 = 0;
|
2019-07-24 11:08:02 +00:00
|
|
|
if(hdr.ipv6.isValid()) {
|
|
|
|
if(nat64.apply().hit) { /* generic / static nat64 done */
|
|
|
|
if(hdr.icmp6.isValid()) {
|
|
|
|
nat64_icmp6_generic();
|
2019-07-24 20:48:21 +00:00
|
|
|
|
2019-07-24 11:08:02 +00:00
|
|
|
if(hdr.icmp6.type == ICMP6_ECHO_REPLY) {
|
|
|
|
hdr.icmp.type = ICMP_ECHO_REPLY;
|
|
|
|
hdr.icmp.code = 0;
|
|
|
|
}
|
|
|
|
if(hdr.icmp6.type == ICMP6_ECHO_REQUEST) {
|
|
|
|
hdr.icmp.type = ICMP_ECHO_REQUEST;
|
|
|
|
hdr.icmp.code = 0;
|
|
|
|
}
|
2019-07-24 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(hdr.udp.isValid()) {
|
2019-07-24 21:28:05 +00:00
|
|
|
delta_udp_from_v6_to_v4
|
2019-07-24 21:22:14 +00:00
|
|
|
}
|
2019-07-24 21:45:40 +00:00
|
|
|
|
|
|
|
if(hdr.tcp.isValid()) {
|
|
|
|
delta_tcp_from_v6_to_v4
|
|
|
|
}
|
2019-07-24 11:08:02 +00:00
|
|
|
|
2019-07-24 20:48:21 +00:00
|
|
|
v4_networks.apply(); /* apply egress for IPv4 */
|
|
|
|
exit; /* no further v6 processing */
|
2019-07-24 21:22:14 +00:00
|
|
|
|
2019-07-24 11:08:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 21:20:41 +00:00
|
|
|
lookup_table.apply();
|
|
|
|
}
|
2019-07-23 10:21:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 09:22:32 +00:00
|
|
|
control TopPipe(
|
|
|
|
inout Parsed_packet p,
|
|
|
|
inout user_metadata_t user_metadata,
|
|
|
|
inout digest_data_t digest_data,
|
|
|
|
inout sume_metadata_t sume_metadata) {
|
|
|
|
|
|
|
|
RealMain() realmain;
|
|
|
|
|
|
|
|
apply {
|
|
|
|
realmain.apply(p, user_metadata, digest_data, sume_metadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 21:20:41 +00:00
|
|
|
/********************************************************************************
|
|
|
|
* Deparser
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Xilinx_MaxPacketRegion(1024)
|
|
|
|
control TopDeparser(
|
2019-07-24 07:36:24 +00:00
|
|
|
packet_out b,
|
|
|
|
in Parsed_packet p,
|
2019-07-23 21:20:41 +00:00
|
|
|
in user_metadata_t user_metadata,
|
|
|
|
inout digest_data_t digest_data,
|
|
|
|
inout sume_metadata_t sume_metadata) {
|
|
|
|
|
|
|
|
apply {
|
2019-07-24 07:36:24 +00:00
|
|
|
b.emit(p.ethernet);
|
2019-07-23 21:20:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 10:22:31 +00:00
|
|
|
|
2019-07-23 10:21:49 +00:00
|
|
|
/********************************************************************************
|
2019-07-23 21:20:41 +00:00
|
|
|
* Switch
|
|
|
|
*/
|
|
|
|
|
|
|
|
SimpleSumeSwitch(
|
|
|
|
TopParser(),
|
|
|
|
TopPipe(),
|
|
|
|
TopDeparser()
|
2019-07-24 07:36:24 +00:00
|
|
|
) main;
|