master-thesis/p4src/actions_delta_checksum.p4

41 lines
2 KiB
Text
Raw Normal View History

2019-07-10 07:07:17 +00:00
#ifndef NICO_DELTA_CHECKSUM
#define NICO_DELTA_CHECKSUM
action v4sum() {
bit<16> localsum = 0;
localsum = localsum + hdr.ipv4.src_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv4.src_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv4.dst_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv4.dst_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv4.totalLen -20; // 16 bit
localsum = localsum + (bit<16>) hdr.ipv4.protocol; // 8 bit
}
action v6sum() {
bit<16> localsum = 0;
localsum = localsum + hdr.ipv6.src_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[47:32]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[63:48]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[79:64]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[95:80]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[111:96]; // 16 bit
localsum = localsum + hdr.ipv6.src_addr[127:112]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[15:0]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[31:16]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[47:32]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[63:48]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[79:64]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[95:80]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[111:96]; // 16 bit
localsum = localsum + hdr.ipv6.dst_addr[127:112]; // 16 bit
localsum = localsum + hdr.ipv6.payload_length; // 16 bit
localsum = localsum + (bit<16>) hdr.ipv6.next_header; // 8 bit
}
#endif