Back to 16 bit arithmetic
This commit is contained in:
parent
428faead17
commit
ecab110d7c
3 changed files with 54 additions and 56 deletions
19
doc/plan.org
19
doc/plan.org
|
@ -5309,6 +5309,25 @@ This is used to correct endianness!
|
|||
|
||||
-> not needed in our case
|
||||
|
||||
*** TODO 2019-07-16: Wraptest in P4
|
||||
#+BEGIN_CENTER
|
||||
mx h3
|
||||
arp -s 10.0.0.2 00:00:0a:00:00:02
|
||||
echo V4-OK | socat - TCP:10.0.0.2:2342
|
||||
|
||||
#+END_CENTER
|
||||
|
||||
Result on the wire of the wraptest:
|
||||
#+BEGIN_CENTER
|
||||
10.0.0.3.60106 > 10.0.0.2.2342: Flags [S], cksum 0x0001 (incorrect ->
|
||||
0xc7f9), seq 3677403557, win 28380, options [mss 9460
|
||||
,sackOK,TS val 2328087128 ecr 0,nop,wscale 9], length 0
|
||||
#+END_CENTER
|
||||
|
||||
0xffff + 2 = 1
|
||||
-> as expected
|
||||
|
||||
Thus carryover is already implemented. Try to use 16 bit ints
|
||||
** The NetPFGA saga
|
||||
Problems encountered:
|
||||
- The logfile for a compile run is 10k+ lines
|
||||
|
|
|
@ -2,95 +2,74 @@
|
|||
#define NICO_DELTA_CHECKSUM
|
||||
|
||||
action v4sum() {
|
||||
bit<32> tmp = 0;
|
||||
bit<32> carryover = 0;
|
||||
bit<16> tmp = 0;
|
||||
|
||||
tmp = tmp + (bit<32>) hdr.ipv4.src_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv4.src_addr[31:16]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv4.dst_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv4.dst_addr[31:16]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv4.src_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv4.src_addr[31:16]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv4.dst_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv4.dst_addr[31:16]; // 16 bit
|
||||
|
||||
tmp = tmp + (bit<32>) hdr.ipv4.totalLen -20; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv4.protocol; // 8 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv4.totalLen -20; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv4.protocol; // 8 bit
|
||||
|
||||
/* filtering code copied from scapy */
|
||||
tmp = (tmp >> 16) + (tmp & 0xffff);
|
||||
tmp = (tmp >> 16) + (tmp & 0xffff);
|
||||
tmp = ~tmp;
|
||||
// meta.v4sum = (bit<16>) ((((tmp>>8) & 0xff)|tmp<<8) & 0xffff);
|
||||
meta.v4sum = (bit<16>) tmp;
|
||||
|
||||
meta.v4sum = tmp;
|
||||
}
|
||||
|
||||
action v6sum() {
|
||||
bit<32> tmp = 0;
|
||||
bit<32> carryover = 0;
|
||||
bit<16> tmp = 0;
|
||||
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[31:16]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[47:32]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[63:48]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[79:64]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[95:80]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[111:96]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.src_addr[127:112]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[31:16]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[47:32]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[63:48]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[79:64]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[95:80]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[111:96]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.src_addr[127:112]; // 16 bit
|
||||
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[31:16]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[47:32]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[63:48]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[79:64]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[95:80]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[111:96]; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.dst_addr[127:112]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[15:0]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[31:16]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[47:32]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[63:48]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[79:64]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[95:80]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[111:96]; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.dst_addr[127:112]; // 16 bit
|
||||
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.payload_length; // 16 bit
|
||||
tmp = tmp + (bit<32>) hdr.ipv6.next_header; // 8 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.payload_length; // 16 bit
|
||||
tmp = tmp + (bit<16>) hdr.ipv6.next_header; // 8 bit
|
||||
|
||||
/* filtering code copied from scapy */
|
||||
tmp = (tmp >> 16) + (tmp & 0xffff);
|
||||
tmp = (tmp >> 16) + (tmp & 0xffff);
|
||||
// tmp = tmp + (tmp >> 16);
|
||||
tmp = ~tmp;
|
||||
|
||||
meta.v6sum = (bit<16>) tmp;
|
||||
meta.v6sum = tmp;
|
||||
}
|
||||
|
||||
|
||||
action delta_prepare()
|
||||
{
|
||||
v4sum();
|
||||
v6sum();
|
||||
if(meta.v6sum > meta.v4sum) {
|
||||
meta.headerdiff = meta.v6sum - meta.v4sum;
|
||||
} else {
|
||||
meta.headerdiff = meta.v4sum - meta.v6sum;
|
||||
}
|
||||
}
|
||||
|
||||
action delta_udp_from_v4_to_v6()
|
||||
{
|
||||
v4sum();
|
||||
v6sum();
|
||||
|
||||
/* here is also a possible overflow in both directions */
|
||||
delta_prepare();
|
||||
hdr.udp.checksum = hdr.udp.checksum + meta.v6sum - meta.v4sum;
|
||||
}
|
||||
|
||||
action delta_tcp_from_v4_to_v6()
|
||||
{
|
||||
v4sum();
|
||||
v6sum();
|
||||
|
||||
/* here is also a possible overflow in both directions */
|
||||
delta_prepare();
|
||||
hdr.tcp.checksum = hdr.tcp.checksum + meta.v6sum - meta.v4sum;
|
||||
}
|
||||
|
||||
action delta_ipv4_from_v6_to_v4()
|
||||
{
|
||||
delta_prepare();
|
||||
/* TO BE DONE! */
|
||||
|
||||
/* we don't have ANY checksum, but tcp or udp: we can
|
||||
base on that ones for calculating the diff for IPv4
|
||||
*/
|
||||
hdr.ipv4.checksum = 0; /* TO BE DONE! */
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ header ipv4_t {
|
|||
bit<13> fragOffset;
|
||||
bit<8> ttl;
|
||||
bit<8> protocol;
|
||||
bit<16> hdrChecksum;
|
||||
bit<16> checksum;
|
||||
ipv4_addr_t src_addr;
|
||||
ipv4_addr_t dst_addr;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue