Added p4-code tested with

Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
Tuan-Dat Tran
2024-12-23 16:49:32 +01:00
parent df9c620d97
commit 9c3ef212c2
3 changed files with 834 additions and 0 deletions

124
l1switch/header.p4 Normal file
View File

@@ -0,0 +1,124 @@
/*
* Copyright 2022-present Nehal Baganal
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
enum bit<16> ether_type_t {
IPV4 = 0x0800,
ARP = 0x0806,
TPID = 0x8100,
IPV6 = 0x86DD,
MPLS = 0x8847
}
enum bit<8> ip_proto_t {
TCP = 6,
ICMP = 1,
UDP = 17
}
header ethernet_h {
bit<48> dstAddr;
bit<48> srcAddr;
bit<16> etherType;
}
header ipv4_h {
bit<4> version;
bit<4> ihl;
bit<6> diffserv;
bit<2> ECN;
bit<16> total_len;
bit<16> identification;
bit<3> flags;
bit<13> frag_offset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdr_checksum;
bit<32> src_addr;
bit<32> dst_addr;
}
header tcp_h {
bit<16> src_port;
bit<16> dst_port;
bit<32> seq_no;
bit<32> ack_no;
bit<4> data_offset;
bit<4> res;
// bit<8> flags;
bit<1> CWR;
bit<1> ECE;
bit<1> URG;
bit<1> ACK;
bit<1> PSH;
bit<1> RST;
bit<1> SYN;
bit<1> FIN;
bit<16> window;
bit<16> checksum;
bit<16> urgent_ptr;
}
header tcp_opt_h {
bit<32> data;
}
typedef tcp_opt_h[10] tcp_opt_t;
header udp_h {
bit<16> src_port;
bit<16> dst_port;
bit<16> len;
bit<16> checksum;
}
header icmp_h {
bit<16> type_code;
bit<16> checksum;
}
header my_tstamp_t {
bit<8> drop_flag; //To make the header byte size
//bit<1> ECE_flag; //To indicate that payload has ECE timestamp
//bit<1> CWR_flag; //To indicate that payload has CWR timestamp
bit<16> drop_tstamp_high;
bit<32> drop_tstamp_low;
}
struct headers_t {
ethernet_h ethernet;
ipv4_h ipv4;
icmp_h icmp;
tcp_h tcp;
tcp_opt_h[10] tcp_opt;
udp_h udp;
my_tstamp_t my_tstamp;
}
header bridged_metadata_t {
bit<48> ingress_tstamp;
bit<8> ingress_port;
bit<4> drop_counter_result;
bit<4> dummy;
bit<13> temp_frag_offset;
bit<3> dummy1;
}
struct my_metadata_t {
bridged_metadata_t bridged_metadata;
}