65 lines
No EOL
2.4 KiB
Text
65 lines
No EOL
2.4 KiB
Text
#ifndef NICO_DELTA_CHECKSUM
|
|
#define NICO_DELTA_CHECKSUM
|
|
|
|
action v4sum() {
|
|
meta.v4sum = 0;
|
|
|
|
meta.v4sum = meta.v4sum + hdr.ipv4.src_addr[15:0]; // 16 bit
|
|
meta.v4sum = meta.v4sum + hdr.ipv4.src_addr[31:16]; // 16 bit
|
|
meta.v4sum = meta.v4sum + hdr.ipv4.dst_addr[15:0]; // 16 bit
|
|
meta.v4sum = meta.v4sum + hdr.ipv4.dst_addr[31:16]; // 16 bit
|
|
|
|
meta.v4sum = meta.v4sum + hdr.ipv4.totalLen -20; // 16 bit
|
|
meta.v4sum = meta.v4sum + (bit<16>) hdr.ipv4.protocol; // 8 bit
|
|
}
|
|
|
|
action v6sum() {
|
|
meta.v6sum = 0;
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[15:0]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[31:16]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[47:32]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[63:48]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[79:64]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[95:80]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[111:96]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.src_addr[127:112]; // 16 bit
|
|
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[15:0]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[31:16]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[47:32]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[63:48]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[79:64]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[95:80]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[111:96]; // 16 bit
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.dst_addr[127:112]; // 16 bit
|
|
|
|
meta.v6sum = meta.v6sum + hdr.ipv6.payload_length; // 16 bit
|
|
meta.v6sum = meta.v6sum + (bit<16>) hdr.ipv6.next_header; // 8 bit
|
|
}
|
|
|
|
action delta_udp_from_v4_to_v6()
|
|
{
|
|
v4sum();
|
|
v6sum();
|
|
bit<16> diff = meta.v6sum - meta.v4sum;
|
|
hdr.udp.checksum = hdr.udp.checksum + ~diff +1;
|
|
}
|
|
|
|
action delta_tcp_from_v4_to_v6()
|
|
{
|
|
v4sum();
|
|
v6sum();
|
|
bit<16> diff = meta.v6sum - meta.v4sum;
|
|
hdr.tcp.checksum = hdr.tcp.checksum + ~diff +1;
|
|
}
|
|
|
|
action delta_ipv4_from_v6_to_v4()
|
|
{
|
|
v4sum();
|
|
v6sum();
|
|
bit<16> diff = meta.v6sum - meta.v4sum;
|
|
hdr.tcp.checksum = hdr.tcp.checksum + ~diff +1;
|
|
}
|
|
|
|
|
|
#endif |