diff --git a/p4app/controller.py b/p4app/controller.py index 0669137..3db1087 100644 --- a/p4app/controller.py +++ b/p4app/controller.py @@ -110,8 +110,7 @@ class L2Controller(object): self.controller.table_clear("v6_addresses") for v6addr in self.v6_addresses[self.mode]: - self.controller.table_add("v6_addresses", "icmp6_answer", [v6addr['addr']], [v6addr['port']]) - + self.controller.table_add("v6_addresses", "icmp6_answer", [v6addr['addr']]) def config_hosts(self): @@ -133,6 +132,14 @@ class L2Controller(object): # mx h$i "ip -6 route add default via 2001:db8:6::42" #for v4route in self.v4_routes[self.mode]: + # Todo: add v4 routes / ip addresses + + # Fake mac addresses - this gets REALLY messy now + # for host in range(4): + # macrange = [1, 2, 3, 4, 42] + + # for mac in macrange: + # subprocess.call(["mx", host, "ip", "addr", "add", ipaddr, "dev", dev]) def debug_print_pkg(self, pkg, msg="INCOMING"): diff --git a/p4app/static-mapping.sh b/p4app/static-mapping.sh index d6d50f8..12fc862 100644 --- a/p4app/static-mapping.sh +++ b/p4app/static-mapping.sh @@ -17,7 +17,8 @@ for i in 1 2; do # add neighbors for j in 1 2 42; do - mx h$i "ip -6 neigh add 2001:db8:6::${j} dev $dev lladdr 00:00:0a:00:00:0${j}" + mx h$i "ip -6 neigh add 2001:db8:61::${j} dev $dev lladdr 00:00:0a:00:00:0${j}" + mx h$i "ip -6 neigh add 2001:db8:62::${j} dev $dev lladdr 00:00:0a:00:00:0${j}" done done diff --git a/p4src/checksums.p4 b/p4src/checksums.p4 index b202b43..5c58803 100644 --- a/p4src/checksums.p4 +++ b/p4src/checksums.p4 @@ -21,6 +21,38 @@ control MyVerifyChecksum(inout headers hdr, inout metadata meta) { control MyComputeChecksum(inout headers hdr, inout metadata meta) { apply { + /* 512 bit+ according to + https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_checksum_for_IPv4 + */ + update_checksum_with_payload( + hdr.ipv6.isValid(), + { + hdr.ipv6.src_addr, /* 128 */ + hdr.ipv6.dst_addr, /* 128 */ + meta.tcpLength, + 24w0, + hdr.ipv6.next_header, + // TCP header + hdr.tcp.src_port, + hdr.tcp.dst_port, + hdr.tcp.seqNo, + hdr.tcp.ackNo, + hdr.tcp.data_offset, + hdr.tcp.res, + hdr.tcp.cwr, + hdr.tcp.ece, + hdr.tcp.urg, + hdr.tcp.ack, + hdr.tcp.psh, + hdr.tcp.rst, + hdr.tcp.syn, + hdr.tcp.fin, + hdr.tcp.window, + hdr.tcp.urgentPtr + }, + hdr.tcp.checksum, + HashAlgorithm.csum16); + } } diff --git a/p4src/headers.p4 b/p4src/headers.p4 index ca65fd2..5c28e1a 100644 --- a/p4src/headers.p4 +++ b/p4src/headers.p4 @@ -21,6 +21,9 @@ const bit<8> PROTO_ICMP6 = 58; const bit<8> TCP_SEQ_LEN = 4; +const bit<8> ICMP6_ECHO_REQUEST = 128; +const bit<8> ICMP6_ECHO_REPLY = 129; + header ethernet_t { mac_addr_t dst_addr; diff --git a/p4src/static-mapping.p4 b/p4src/static-mapping.p4 index 629a137..64d8e73 100644 --- a/p4src/static-mapping.p4 +++ b/p4src/static-mapping.p4 @@ -17,7 +17,17 @@ control MyIngress(inout headers hdr, inout standard_metadata_t standard_metadata) { /********************** ADDRESS TABLES ***********************************/ - action icmp6_answer(port_t port) { + action icmp6_answer() { + + if(hdr.icmp6.isValid()) { + if(hdr.icmp6.code == ICMP6_ECHO_REQUEST) { + ipv6_addr_t tmp = hdr.ipv6.src_addr; + hdr.ipv6.src_addr = hdr.ipv6.dst_addr; + hdr.ipv6.dst_addr = tmp; + hdr.icmp6.code = ICMP6_ECHO_REPLY; + } + } + /* do something: - change src/dst - change type @@ -27,6 +37,7 @@ control MyIngress(inout headers hdr, table v6_addresses { key = { hdr.ipv6.dst_addr: exact; +// hdr.ipv6.next_header: exact; } actions = { icmp6_answer;