diff --git a/bin/checksum_from_scapy.py b/bin/checksum_from_scapy.py index 7638d3b..ebb7bb1 100644 --- a/bin/checksum_from_scapy.py +++ b/bin/checksum_from_scapy.py @@ -23,6 +23,8 @@ else: # create array with unsigned shorts, # sum it up -> results in 16 bit uint (?) s = sum(array.array("H", pkt)) + print("sum={}".format(s)) + # This step is understood # (s & 0xffff) -> mask for 16 bit, truncate rest # (s >> 16) right shift by 16 bits @@ -40,7 +42,6 @@ else: # over bits from the previous calculation s += s >> 16 - # according to https://stackoverflow.com/questions/8305199/the-tilde-operator-in-python # ~ is the bitwise complement operator in python # which essentially calculates -x - 1 @@ -65,3 +66,6 @@ if __name__ == '__main__': pkt_bytes = pkt.encode('utf-8') print(pkt_bytes) print(checksum(pkt_bytes)) + + ipv4 = "AAAA" + ipv6 = "BBAA" diff --git a/doc/plan.org b/doc/plan.org index 9e0255e..9e9597e 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -358,8 +358,30 @@ | | - 15m q&a | | | | | | | | | | +| 2019-06-24 | | | +| | Laurent meeting | | | | | | -| 2018-06-27 | | | +| | Checksums | | +| | - 16 bit sum of fields, later one/two complement | | +| | - various implementations | | +| | - is a sum -> commutative law | | +| | - overflow (delta > payload) handling unclear | | +| | | | +| | Netpfga | | +| | - Old one had several failure messages (one in DDR area) | | +| | - New one: tables can be written | | +| | - Need 3 ports: v4, v6, management | | +| | | | +| | Next steps: | | +| | - Test checksums delta on software switch | | +| | - Begin to port code to netpfga one-by-one | | +| | | | +| | Follow up notes: | | +| | - Checkout Hendrik thesis / right / left shift | | +| | - Fix computer in lab | | +| | | | +| | | | +| 2019-06-27 | | | | | Target Hardware: code running | | | | | | | 2019-07-11 | | | @@ -3000,6 +3022,76 @@ b'AAAA' [14:18] line:bin% python3 checksum_from_scapy.py BBAA b'BBAA' 31868 +[14:18] line:bin% python3 checksum_from_scapy.py AA +b'AA' +48830 +[14:20] line:bin% python3 checksum_from_scapy.py BB +b'BB' +48573 +>>> bin(48830) +'0b1011111010111110' +>>> bin(48573) +'0b1011110110111101' +>>> + +>>> array.array("H", "AAAA".encode("utf-8")) +array('H', [16705, 16705]) +>>> array.array("H", "AA".encode("utf-8")) +array('H', [16705]) + +-> bit concat on 16: +AA: +>>> 0b100000101000001 +16705 + +Order in 16 bit tuples does not matter: + +[14:24] line:bin% python3 checksum_from_scapy.py AABB +b'AABB' +sum=33667 +31868 +[14:28] line:bin% python3 checksum_from_scapy.py BBAA +b'BBAA' +sum=33667 +31868 + +[14:28] line:bin% python3 checksum_from_scapy.py BBCCAA +b'BBCCAA' +sum=50886 +14649 +[14:28] line:bin% python3 checksum_from_scapy.py BBAACC +b'BBAACC' +sum=50886 +14649 + +Sum on shorts does not stay in short area: + +>>> sum(array.array("H", [48830, 48573])) +97403 +>>> sum(array.array("H", "AAAA".encode("utf-8"))) +33410 +>>> sum(array.array("H", "AABB".encode("utf-8"))) +33667 +>>> sum(array.array("H", "AABBCC".encode("utf-8"))) +50886 +>>> sum(array.array("H", "AABBCCDD".encode("utf-8"))) +68362 + +Adding with overflow control works: + +>>> s = 97403 +>>> s = (s >> 16) + (s & 0xffff) +>>> s +31868 +>>> s += s >> 16 +>>> s +31868 + +[14:29] line:bin% python3 checksum_from_scapy.py AABB +b'AABB' +sum=33667 +31868 + #+END_CENTER *** TODO Get ANY p4 program to successfully run on netpfga diff --git a/netpfga/minip4/src/minip4_solution-nat64.p4 b/netpfga/minip4/src/minip4_solution-nat64.p4 index 1864c88..6250d43 100644 --- a/netpfga/minip4/src/minip4_solution-nat64.p4 +++ b/netpfga/minip4/src/minip4_solution-nat64.p4 @@ -2,6 +2,15 @@ #include #include "headers.p4" +/******************************************************************************** + * Possible bugs / things to fix: + +- Does NoAction exist? +- Aligment of "meta" +- replace metadate with our own + + */ + /******************************************************************************** * Header */ @@ -17,12 +26,6 @@ struct Parsed_packet { Ethernet_h ethernet; } -// user defined metadata: can be used to share information between -// TopParser, TopPipe, and TopDeparser -struct user_metadata_t { - bit<8> unused; -} - // digest_data, MUST be 256 bits -- what is this used for? struct digest_data_t { bit<256> unused; @@ -36,12 +39,11 @@ struct digest_data_t { @Xilinx_MaxPacketRegion(1024) parser TopParser(packet_in b, out Parsed_packet p, - out user_metadata_t user_metadata, + out metadata meta, out digest_data_t digest_data, inout sume_metadata_t sume_metadata) { state start { b.extract(p.ethernet); - user_metadata.unused = 0; digest_data.unused = 0; transition accept; @@ -52,511 +54,517 @@ parser TopParser(packet_in b, * Main */ control TopPipe(inout Parsed_packet p, - inout user_metadata_t user_metadata, + inout metadata meta, inout digest_data_t digest_data, inout sume_metadata_t sume_metadata) { + /* FIXME: not sure what to do on netpfga */ action drop() { +#ifndef _SUME_SWITCH_P4_ mark_to_drop(); +#endif } action set_egress_port (port_t out_port) { + #ifdef _SUME_SWITCH_P4_ + sume_metadata.dst_port = out_port; + #else standard_metadata.egress_spec = out_port; + #endif } action set_egress_port_and_mac (port_t out_port, mac_addr_t mac_addr) { hdr.ethernet.dst_addr = mac_addr; - standard_metadata.egress_spec = out_port; + set_egress_port(out_port); } - action controller_reply(task_t task) { - meta.task = task; - meta.ingress_port = standard_metadata.ingress_port; - clone3(CloneType.I2E, 100, meta); - } +// action controller_reply(task_t task) { +// meta.task = task; +// meta.ingress_port = standard_metadata.ingress_port; +// clone3(CloneType.I2E, 100, meta); +// } - action controller_debug_table_id(table_t table_id) { - meta.table_id = table_id; - controller_reply(TASK_DEBUG); - } +// action controller_debug_table_id(table_t table_id) { +// meta.table_id = table_id; +// controller_reply(TASK_DEBUG); +// } - action controller_debug() { - controller_reply(TASK_DEBUG); - } +// action controller_debug() { +// controller_reply(TASK_DEBUG); +// } - action multicast_pkg(mcast_t mcast_grp) { /* Output PKG on correct ports (plural) */ - standard_metadata.mcast_grp = mcast_grp; - } +// action multicast_pkg(mcast_t mcast_grp) { /* Output PKG on correct ports (plural) */ +// standard_metadata.mcast_grp = mcast_grp; +// } - /********************** NAT64 / NAT46 ACTIONS GENERIC ***********************************/ +// /********************** NAT64 / NAT46 ACTIONS GENERIC ***********************************/ - /* changes for icmp6 -> icmp */ - action nat64_icmp6_generic() - { - hdr.icmp.setValid(); - hdr.ipv4.protocol = PROTO_ICMP; // overwrite generic same protocol assumption +// /* changes for icmp6 -> icmp */ +// action nat64_icmp6_generic() +// { +// hdr.icmp.setValid(); +// hdr.ipv4.protocol = PROTO_ICMP; // overwrite generic same protocol assumption - /* trigger checksumming */ - meta.switch_task = TASK_CHECKSUM_ICMP; +// /* trigger checksumming */ +// meta.switch_task = TASK_CHECKSUM_ICMP; - meta.chk_icmp = 1; +// meta.chk_icmp = 1; - hdr.icmp6.setInvalid(); +// hdr.icmp6.setInvalid(); - /* not needed, as we don't translate them (yet/ever) */ - hdr.icmp6_na_ns.setInvalid(); - hdr.icmp6_option_link_layer_addr.setInvalid(); - } +// /* not needed, as we don't translate them (yet/ever) */ +// hdr.icmp6_na_ns.setInvalid(); +// hdr.icmp6_option_link_layer_addr.setInvalid(); +// } - /* NAT64 protocol unspecific changes */ - action nat64_generic(ipv4_addr_t src, ipv4_addr_t dst) { - hdr.ipv4.setValid(); - meta.chk_ipv4 = 1; /* need to calculate the hdrchecksum */ +// /* NAT64 protocol unspecific changes */ +// action nat64_generic(ipv4_addr_t src, ipv4_addr_t dst) { +// hdr.ipv4.setValid(); +// meta.chk_ipv4 = 1; /* need to calculate the hdrchecksum */ - /* Stuff that might need to be fixed */ - hdr.ipv4.version = (bit<4>)4; - hdr.ipv4.diff_serv = (bit<6>)0; // no ToS - hdr.ipv4.ecn = (bit<2>)0; // unsupported +// /* Stuff that might need to be fixed */ +// hdr.ipv4.version = (bit<4>)4; +// hdr.ipv4.diff_serv = (bit<6>)0; // no ToS +// hdr.ipv4.ecn = (bit<2>)0; // unsupported - /* 5 is ok as long as we don't use options / padding / - anything after the destination address */ - hdr.ipv4.ihl = (bit<4>) 5; // internet header length: 4*5 = 20 - hdr.ipv4.totalLen = (bit<16>) hdr.ipv6.payload_length + 20; // ok under above constraints +// /* 5 is ok as long as we don't use options / padding / +// anything after the destination address */ +// hdr.ipv4.ihl = (bit<4>) 5; // internet header length: 4*5 = 20 +// hdr.ipv4.totalLen = (bit<16>) hdr.ipv6.payload_length + 20; // ok under above constraints - hdr.ipv4.identification = (bit<16>) 0; // no support for fragments - hdr.ipv4.flags = (bit<3>) 0; // DF bit and more fragments - hdr.ipv4.fragOffset = (bit<13>) 0; // 0 as there are no fragments +// hdr.ipv4.identification = (bit<16>) 0; // no support for fragments +// hdr.ipv4.flags = (bit<3>) 0; // DF bit and more fragments +// hdr.ipv4.fragOffset = (bit<13>) 0; // 0 as there are no fragments - /* Stuff that should be fine */ - hdr.ethernet.ethertype = TYPE_IPV4; +// /* Stuff that should be fine */ +// hdr.ethernet.ethertype = TYPE_IPV4; - hdr.ipv4.dst_addr = dst; - hdr.ipv4.src_addr = src; +// hdr.ipv4.dst_addr = dst; +// hdr.ipv4.src_addr = src; - hdr.ipv4.ttl = hdr.ipv6.hop_limit; +// hdr.ipv4.ttl = hdr.ipv6.hop_limit; - hdr.ipv4.protocol = hdr.ipv6.next_header; +// hdr.ipv4.protocol = hdr.ipv6.next_header; - hdr.ipv6.setInvalid(); - } +// hdr.ipv6.setInvalid(); +// } - /* nat64_prefix is the same as the matching key, but without the mask */ - action nat64_static(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) { - ipv6_addr_t src_offset = hdr.ipv6.src_addr - v6_src; - ipv4_addr_t src = v4_dst + (ipv4_addr_t) src_offset; +// /* nat64_prefix is the same as the matching key, but without the mask */ +// action nat64_static(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) { +// ipv6_addr_t src_offset = hdr.ipv6.src_addr - v6_src; +// ipv4_addr_t src = v4_dst + (ipv4_addr_t) src_offset; - ipv4_addr_t dst = (ipv4_addr_t) (hdr.ipv6.dst_addr - nat64_prefix); +// ipv4_addr_t dst = (ipv4_addr_t) (hdr.ipv6.dst_addr - nat64_prefix); - nat64_generic(src, dst); - } +// nat64_generic(src, dst); +// } - /* From https://tools.ietf.org/html/rfc792 (IPv4) +// /* From https://tools.ietf.org/html/rfc792 (IPv4) -Echo or Echo Reply Message +// Echo or Echo Reply Message - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Code | Checksum | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Identifier | Sequence Number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Data ... - +-+-+-+-+- +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type | Code | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Identifier | Sequence Number | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Data ... +// +-+-+-+-+- - From https://tools.ietf.org/html/rfc4443#section-4.1 +// From https://tools.ietf.org/html/rfc4443#section-4.1 -4.1. Echo Request Message +// 4.1. Echo Request Message - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Code | Checksum | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Identifier | Sequence Number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Data ... - +-+-+-+-+- +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type | Code | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Identifier | Sequence Number | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Data ... +// +-+-+-+-+- -4.2. Echo Reply Message +// 4.2. Echo Reply Message - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Code | Checksum | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Identifier | Sequence Number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Data ... - +-+-+-+-+- - - - Type / code are different in ICMP4 and ICMP6! +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type | Code | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Identifier | Sequence Number | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Data ... +// +-+-+-+-+- + + +// Type / code are different in ICMP4 and ICMP6! - */ +// */ - /* changes for icmp6 -> icmp */ - action nat46_icmp_generic() - { - hdr.icmp6.setValid(); - hdr.ipv6.next_header = PROTO_ICMP6; - - meta.chk_icmp6 = 1; - meta.cast_length = (bit<32>) hdr.ipv6.payload_length; - - hdr.icmp.setInvalid(); - } - - /* NAT46: protocol unspecific changes */ - action nat46_generic(ipv6_addr_t src, ipv6_addr_t dst) { - hdr.ipv6.setValid(); - hdr.ipv4.setInvalid(); - - hdr.ethernet.ethertype = TYPE_IPV6; - - hdr.ipv6.dst_addr = dst; - hdr.ipv6.src_addr = src; - - hdr.ipv6.version = (bit<4>)6; - hdr.ipv6.traffic_class = (bit<8>) hdr.ipv4.diff_serv; - hdr.ipv6.flow_label = (bit<20>) 0; - hdr.ipv6.payload_length = (bit<16>) hdr.ipv4.totalLen - 20; - - hdr.ipv6.next_header = hdr.ipv4.protocol; - hdr.ipv6.hop_limit = hdr.ipv4.ttl; - - } - - - /* matching key: v4_network specified again */ - action nat46_static(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) { - ipv6_addr_t src = nat64_prefix + (ipv6_addr_t) hdr.ipv4.src_addr; - - ipv4_addr_t dst_offset = hdr.ipv4.dst_addr - v4_dst; - ipv6_addr_t dst = v6_src + (ipv6_addr_t) dst_offset; - - nat46_generic(src, dst); - } - - table nat64 { - key = { - hdr.ipv6.dst_addr: lpm; - } - actions = { - controller_debug; - nat64_static; - controller_debug_table_id; - NoAction; - } - size = NAT64_TABLE_SIZE; -// default_action = controller_debug_table_id(TABLE_NAT64); - default_action = NoAction; - } - - table nat46 { - key = { - hdr.ipv4.dst_addr: lpm; - } - actions = { - controller_debug; - nat46_static; - controller_debug_table_id; - NoAction; - } - size = NAT64_TABLE_SIZE; - default_action = controller_debug_table_id(TABLE_NAT46); - } - - /********************** NAT64 sessions ***********************************/ - - /* automatic translations */ - action nat64_tcp_session_translate( - ipv4_addr_t src_addr, - bit<16> src_port, - ipv4_addr_t dst_addr, - bit<16> dst_port) - { - hdr.ipv4.setValid(); - - hdr.tcp.src_port = src_port; - hdr.tcp.dst_port = dst_port; - - nat64_generic(src_addr, dst_addr); - } - - action nat46_tcp_session_translate( - ipv6_addr_t src_addr, - bit<16> src_port, - ipv6_addr_t dst_addr, - bit<16> dst_port) - { - hdr.ipv6.setValid(); - - hdr.tcp.src_port = src_port; - hdr.tcp.dst_port = dst_port; - - nat46_generic(src_addr, dst_addr); - } - - /* We are in the right range, need to create a session entry */ - action nat64_tcp_session_create() - { - controller_reply(TASK_NAT64_TCP_SESSION); - } - - - /* Used for detecting traffic that should have a session */ - table nat64_session { - key = { - hdr.ipv6.dst_addr: lpm; - } - actions = { - controller_debug_table_id; - NoAction; - } - size = NAT64_TABLE_SIZE; - default_action = controller_debug_table_id(TABLE_NAT64_SESSION); - } - - - table nat64_tcp_session { - key = { - hdr.ipv6.src_addr: exact; - hdr.ipv6.dst_addr: exact; - hdr.tcp.src_port: exact; - hdr.tcp.dst_port: exact; - } - actions = { - controller_debug_table_id; - nat64_tcp_session_create; - nat64_tcp_session_translate; - NoAction; - } - size = NAT64_TABLE_SIZE; - default_action = nat64_tcp_session_create; - } - - table nat46_tcp_session { - key = { - hdr.ipv6.src_addr: exact; - hdr.ipv6.dst_addr: exact; - hdr.tcp.src_port: exact; - hdr.tcp.dst_port: exact; - } - actions = { - controller_debug_table_id; - nat46_tcp_session_translate; - NoAction; - } - size = NAT64_TABLE_SIZE; - //default_action = controller_debug_table_id(TABLE_NAT64_TCP); - default_action = NoAction; - } - - - - /********************** ICMP6 + NDP + ICMP ***********************************/ - - /* old/unused action -- is it??*/ - 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; - } - } - } - - action icmp6_neighbor_solicitation(ipv6_addr_t addr, mac_addr_t mac_addr) { - /* egress = ingress */ - standard_metadata.egress_spec = standard_metadata.ingress_port; - - /* 1. IPv6 changes */ - hdr.ipv6.dst_addr = hdr.ipv6.src_addr; - hdr.ipv6.src_addr = addr; - - /* 2. ICMP6 changes */ - hdr.icmp6.type = ICMP6_NA; - hdr.icmp6.code = 0; - hdr.icmp6.checksum = 42; // checksum is calculated in deparser - marking with 42 to see whether it is calculated - - /* 3. icmp6/neighbor advertisement: values taken from real world answers */ - hdr.icmp6_na_ns.router = 0; - hdr.icmp6_na_ns.solicitated = 1; - hdr.icmp6_na_ns.override = 1; - hdr.icmp6_na_ns.reserved = 0; - hdr.icmp6_na_ns.target_addr = addr; - - /* 4. Link layer options */ - hdr.icmp6_option_link_layer_addr.type = ICMP6_NDP_OPT_TARGET_LL; - hdr.icmp6_option_link_layer_addr.ll_length = 1; /* 1* 64 bit */ - hdr.icmp6_option_link_layer_addr.mac_addr = mac_addr; - - /* 5. Checksum trigger/info */ - meta.chk_icmp6_na_ns = 1; - meta.cast_length = (bit<32>) hdr.ipv6.payload_length; - } - - action icmp6_echo_reply() { - mac_addr_t mac_tmp = hdr.ethernet.dst_addr; - hdr.ethernet.dst_addr = hdr.ethernet.src_addr; - hdr.ethernet.src_addr = mac_tmp; - - ipv6_addr_t addr_tmp = hdr.ipv6.dst_addr; - hdr.ipv6.dst_addr = hdr.ipv6.src_addr; - hdr.ipv6.src_addr = addr_tmp; - - hdr.icmp6.type = ICMP6_ECHO_REPLY; - - meta.chk_icmp6 = 1; - - meta.cast_length = (bit<32>) hdr.ipv6.payload_length; - } - - table icmp6 { - key = { - hdr.ipv6.dst_addr: lpm; - hdr.icmp6.type: exact; - } - actions = { - controller_debug; - icmp6_neighbor_solicitation; - icmp6_echo_reply; - controller_debug_table_id; - NoAction; - } - size = ICMP6_TABLE_SIZE; - default_action = controller_debug_table_id(TABLE_ICMP6); - } - - action icmp_echo_reply() { - mac_addr_t mac_tmp = hdr.ethernet.dst_addr; - ipv4_addr_t ipv4_tmp = hdr.ipv4.src_addr; - - /* swap ethernet addresses */ - hdr.ethernet.dst_addr = hdr.ethernet.src_addr; - hdr.ethernet.src_addr = mac_tmp; - - /* swap ipv4 addresses */ - hdr.ipv4.src_addr = hdr.ipv4.dst_addr; - hdr.ipv4.dst_addr = ipv4_tmp; - - /* set correct type */ - hdr.icmp.type = ICMP_ECHO_REPLY; - - meta.chk_icmp = 1; - } - - table icmp { - key = { - hdr.ipv4.dst_addr: lpm; - hdr.icmp.type: exact; - } - actions = { - icmp_echo_reply; - controller_debug_table_id; - NoAction; - } - size = ICMP_TABLE_SIZE; -// default_action = controller_debug_table_id(TABLE_ICMP); - default_action = NoAction; /* do not clone on miss */ - } - - /********************** ARP ***********************************/ - - action arp_reply(mac_addr_t mac_addr) { - /* swap */ - ipv4_addr_t ipv4_src = hdr.arp.dst_ipv4_addr; - ipv4_addr_t ipv4_dst = hdr.arp.src_ipv4_addr; - - /* swap/add */ - mac_addr_t mac_src = mac_addr; - mac_addr_t mac_dst = hdr.arp.src_mac_addr; - - /* fill the ethernet header */ - hdr.ethernet.dst_addr = mac_dst; - hdr.ethernet.src_addr = mac_src; - - /* fill the arp header */ - hdr.arp.dst_mac_addr = mac_dst; - hdr.arp.src_mac_addr = mac_src; - - /* swapping */ - hdr.arp.dst_ipv4_addr = ipv4_dst; - hdr.arp.src_ipv4_addr = ipv4_src; - - hdr.arp.opcode = ARP_REPLY; - } - - table v4_arp { - key = { - hdr.ethernet.dst_addr: exact; - hdr.arp.opcode: exact; - hdr.arp.dst_ipv4_addr: lpm; - } - actions = { - controller_debug_table_id; - arp_reply; - NoAction; - } - size = ICMP6_TABLE_SIZE; - default_action = controller_debug_table_id(TABLE_ARP); - } - - table v4_arp_egress { - key = { - hdr.arp.dst_ipv4_addr: lpm; - } - actions = { - controller_debug_table_id; - set_egress_port; - NoAction; - } - size = ICMP6_TABLE_SIZE; - default_action = controller_debug_table_id(TABLE_ARP_EGRESS); - } - - - /********************** ROUTING (egress definiton) TABLES ***********************************/ - - table v6_networks { - key = { - hdr.ipv6.dst_addr: lpm; - } - actions = { - set_egress_port; - set_egress_port_and_mac; - controller_debug; - controller_reply; - controller_debug_table_id; - NoAction; - } - size = ROUTING_TABLE_SIZE; - - default_action = controller_debug_table_id(TABLE_V6_NETWORKS); - } - - table v4_networks { - key = { - hdr.ipv4.dst_addr: lpm; - } - actions = { - set_egress_port; - set_egress_port_and_mac; - controller_debug; - controller_debug_table_id; - NoAction; - } - size = ROUTING_TABLE_SIZE; - default_action = controller_debug_table_id(TABLE_V4_NETWORKS); - } - +// /* changes for icmp6 -> icmp */ +// action nat46_icmp_generic() +// { +// hdr.icmp6.setValid(); +// hdr.ipv6.next_header = PROTO_ICMP6; + +// meta.chk_icmp6 = 1; +// meta.cast_length = (bit<32>) hdr.ipv6.payload_length; + +// hdr.icmp.setInvalid(); +// } + +// /* NAT46: protocol unspecific changes */ +// action nat46_generic(ipv6_addr_t src, ipv6_addr_t dst) { +// hdr.ipv6.setValid(); +// hdr.ipv4.setInvalid(); + +// hdr.ethernet.ethertype = TYPE_IPV6; + +// hdr.ipv6.dst_addr = dst; +// hdr.ipv6.src_addr = src; + +// hdr.ipv6.version = (bit<4>)6; +// hdr.ipv6.traffic_class = (bit<8>) hdr.ipv4.diff_serv; +// hdr.ipv6.flow_label = (bit<20>) 0; +// hdr.ipv6.payload_length = (bit<16>) hdr.ipv4.totalLen - 20; + +// hdr.ipv6.next_header = hdr.ipv4.protocol; +// hdr.ipv6.hop_limit = hdr.ipv4.ttl; + +// } + + +// /* matching key: v4_network specified again */ +// action nat46_static(ipv6_addr_t v6_src, ipv4_addr_t v4_dst, ipv6_addr_t nat64_prefix) { +// ipv6_addr_t src = nat64_prefix + (ipv6_addr_t) hdr.ipv4.src_addr; + +// ipv4_addr_t dst_offset = hdr.ipv4.dst_addr - v4_dst; +// ipv6_addr_t dst = v6_src + (ipv6_addr_t) dst_offset; + +// nat46_generic(src, dst); +// } + +// table nat64 { +// key = { +// hdr.ipv6.dst_addr: lpm; +// } +// actions = { +// controller_debug; +// nat64_static; +// controller_debug_table_id; +// NoAction; +// } +// size = NAT64_TABLE_SIZE; +// // default_action = controller_debug_table_id(TABLE_NAT64); +// default_action = NoAction; +// } + +// table nat46 { +// key = { +// hdr.ipv4.dst_addr: lpm; +// } +// actions = { +// controller_debug; +// nat46_static; +// controller_debug_table_id; +// NoAction; +// } +// size = NAT64_TABLE_SIZE; +// default_action = controller_debug_table_id(TABLE_NAT46); +// } + +// /********************** NAT64 sessions ***********************************/ + +// /* automatic translations */ +// action nat64_tcp_session_translate( +// ipv4_addr_t src_addr, +// bit<16> src_port, +// ipv4_addr_t dst_addr, +// bit<16> dst_port) +// { +// hdr.ipv4.setValid(); + +// hdr.tcp.src_port = src_port; +// hdr.tcp.dst_port = dst_port; + +// nat64_generic(src_addr, dst_addr); +// } + +// action nat46_tcp_session_translate( +// ipv6_addr_t src_addr, +// bit<16> src_port, +// ipv6_addr_t dst_addr, +// bit<16> dst_port) +// { +// hdr.ipv6.setValid(); + +// hdr.tcp.src_port = src_port; +// hdr.tcp.dst_port = dst_port; + +// nat46_generic(src_addr, dst_addr); +// } + +// /* We are in the right range, need to create a session entry */ +// action nat64_tcp_session_create() +// { +// controller_reply(TASK_NAT64_TCP_SESSION); +// } + + +// /* Used for detecting traffic that should have a session */ +// table nat64_session { +// key = { +// hdr.ipv6.dst_addr: lpm; +// } +// actions = { +// controller_debug_table_id; +// NoAction; +// } +// size = NAT64_TABLE_SIZE; +// default_action = controller_debug_table_id(TABLE_NAT64_SESSION); +// } + + +// table nat64_tcp_session { +// key = { +// hdr.ipv6.src_addr: exact; +// hdr.ipv6.dst_addr: exact; +// hdr.tcp.src_port: exact; +// hdr.tcp.dst_port: exact; +// } +// actions = { +// controller_debug_table_id; +// nat64_tcp_session_create; +// nat64_tcp_session_translate; +// NoAction; +// } +// size = NAT64_TABLE_SIZE; +// default_action = nat64_tcp_session_create; +// } + +// table nat46_tcp_session { +// key = { +// hdr.ipv6.src_addr: exact; +// hdr.ipv6.dst_addr: exact; +// hdr.tcp.src_port: exact; +// hdr.tcp.dst_port: exact; +// } +// actions = { +// controller_debug_table_id; +// nat46_tcp_session_translate; +// NoAction; +// } +// size = NAT64_TABLE_SIZE; +// //default_action = controller_debug_table_id(TABLE_NAT64_TCP); +// default_action = NoAction; +// } + + + +// /********************** ICMP6 + NDP + ICMP ***********************************/ + +// /* old/unused action -- is it??*/ +// 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; +// } +// } +// } + +// action icmp6_neighbor_solicitation(ipv6_addr_t addr, mac_addr_t mac_addr) { +// /* egress = ingress */ +// standard_metadata.egress_spec = standard_metadata.ingress_port; + +// /* 1. IPv6 changes */ +// hdr.ipv6.dst_addr = hdr.ipv6.src_addr; +// hdr.ipv6.src_addr = addr; + +// /* 2. ICMP6 changes */ +// hdr.icmp6.type = ICMP6_NA; +// hdr.icmp6.code = 0; +// hdr.icmp6.checksum = 42; // checksum is calculated in deparser - marking with 42 to see whether it is calculated + +// /* 3. icmp6/neighbor advertisement: values taken from real world answers */ +// hdr.icmp6_na_ns.router = 0; +// hdr.icmp6_na_ns.solicitated = 1; +// hdr.icmp6_na_ns.override = 1; +// hdr.icmp6_na_ns.reserved = 0; +// hdr.icmp6_na_ns.target_addr = addr; + +// /* 4. Link layer options */ +// hdr.icmp6_option_link_layer_addr.type = ICMP6_NDP_OPT_TARGET_LL; +// hdr.icmp6_option_link_layer_addr.ll_length = 1; /* 1* 64 bit */ +// hdr.icmp6_option_link_layer_addr.mac_addr = mac_addr; + +// /* 5. Checksum trigger/info */ +// meta.chk_icmp6_na_ns = 1; +// meta.cast_length = (bit<32>) hdr.ipv6.payload_length; +// } + +// action icmp6_echo_reply() { +// mac_addr_t mac_tmp = hdr.ethernet.dst_addr; +// hdr.ethernet.dst_addr = hdr.ethernet.src_addr; +// hdr.ethernet.src_addr = mac_tmp; + +// ipv6_addr_t addr_tmp = hdr.ipv6.dst_addr; +// hdr.ipv6.dst_addr = hdr.ipv6.src_addr; +// hdr.ipv6.src_addr = addr_tmp; + +// hdr.icmp6.type = ICMP6_ECHO_REPLY; + +// meta.chk_icmp6 = 1; + +// meta.cast_length = (bit<32>) hdr.ipv6.payload_length; +// } + +// table icmp6 { +// key = { +// hdr.ipv6.dst_addr: lpm; +// hdr.icmp6.type: exact; +// } +// actions = { +// controller_debug; +// icmp6_neighbor_solicitation; +// icmp6_echo_reply; +// controller_debug_table_id; +// NoAction; +// } +// size = ICMP6_TABLE_SIZE; +// default_action = controller_debug_table_id(TABLE_ICMP6); +// } + +// action icmp_echo_reply() { +// mac_addr_t mac_tmp = hdr.ethernet.dst_addr; +// ipv4_addr_t ipv4_tmp = hdr.ipv4.src_addr; + +// /* swap ethernet addresses */ +// hdr.ethernet.dst_addr = hdr.ethernet.src_addr; +// hdr.ethernet.src_addr = mac_tmp; + +// /* swap ipv4 addresses */ +// hdr.ipv4.src_addr = hdr.ipv4.dst_addr; +// hdr.ipv4.dst_addr = ipv4_tmp; + +// /* set correct type */ +// hdr.icmp.type = ICMP_ECHO_REPLY; + +// meta.chk_icmp = 1; +// } + +// table icmp { +// key = { +// hdr.ipv4.dst_addr: lpm; +// hdr.icmp.type: exact; +// } +// actions = { +// icmp_echo_reply; +// controller_debug_table_id; +// NoAction; +// } +// size = ICMP_TABLE_SIZE; +// // default_action = controller_debug_table_id(TABLE_ICMP); +// default_action = NoAction; /* do not clone on miss */ +// } + +// /********************** ARP ***********************************/ + +// action arp_reply(mac_addr_t mac_addr) { +// /* swap */ +// ipv4_addr_t ipv4_src = hdr.arp.dst_ipv4_addr; +// ipv4_addr_t ipv4_dst = hdr.arp.src_ipv4_addr; + +// /* swap/add */ +// mac_addr_t mac_src = mac_addr; +// mac_addr_t mac_dst = hdr.arp.src_mac_addr; + +// /* fill the ethernet header */ +// hdr.ethernet.dst_addr = mac_dst; +// hdr.ethernet.src_addr = mac_src; + +// /* fill the arp header */ +// hdr.arp.dst_mac_addr = mac_dst; +// hdr.arp.src_mac_addr = mac_src; + +// /* swapping */ +// hdr.arp.dst_ipv4_addr = ipv4_dst; +// hdr.arp.src_ipv4_addr = ipv4_src; + +// hdr.arp.opcode = ARP_REPLY; +// } + +// table v4_arp { +// key = { +// hdr.ethernet.dst_addr: exact; +// hdr.arp.opcode: exact; +// hdr.arp.dst_ipv4_addr: lpm; +// } +// actions = { +// controller_debug_table_id; +// arp_reply; +// NoAction; +// } +// size = ICMP6_TABLE_SIZE; +// default_action = controller_debug_table_id(TABLE_ARP); +// } + +// table v4_arp_egress { +// key = { +// hdr.arp.dst_ipv4_addr: lpm; +// } +// actions = { +// controller_debug_table_id; +// set_egress_port; +// NoAction; +// } +// size = ICMP6_TABLE_SIZE; +// default_action = controller_debug_table_id(TABLE_ARP_EGRESS); +// } + + +// /********************** ROUTING (egress definiton) TABLES ***********************************/ + +// table v6_networks { +// key = { +// hdr.ipv6.dst_addr: lpm; +// } +// actions = { +// set_egress_port; +// set_egress_port_and_mac; +// controller_debug; +// controller_reply; +// controller_debug_table_id; +// NoAction; +// } +// size = ROUTING_TABLE_SIZE; + +// default_action = controller_debug_table_id(TABLE_V6_NETWORKS); +// } + +// table v4_networks { +// key = { +// hdr.ipv4.dst_addr: lpm; +// } +// actions = { +// set_egress_port; +// set_egress_port_and_mac; +// controller_debug; +// controller_debug_table_id; +// NoAction; +// } +// size = ROUTING_TABLE_SIZE; +// default_action = controller_debug_table_id(TABLE_V4_NETWORKS); +// } action swap_eth_addresses() { @@ -569,20 +577,21 @@ Echo or Echo Reply Message } action send_to_port1() { - sume_metadata.dst_port = 1; + set_egress_port(1); +// sume_metadata.dst_port = 1; } - action send_to_all_ports() { - /* Taken from commands.txt of the "int" project: - table_cam_add_entry forward set_output_port 0xffffffffffff => 0b01010101 + // action send_to_all_ports() { + // /* Taken from commands.txt of the "int" project: + // table_cam_add_entry forward set_output_port 0xffffffffffff => 0b01010101 - python convert: - >>> 0b01010101 - 85 + // python convert: + // >>> 0b01010101 + // 85 - */ - sume_metadata.dst_port = 85; - } + // */ + // sume_metadata.dst_port = 85; + // } action do_nothing() { EthAddr_t temp = p.ethernet.dstAddr; @@ -597,9 +606,9 @@ Echo or Echo Reply Message swap_eth_addresses; do_nothing; send_to_port1; - send_to_all_ports; +// send_to_all_ports; } - size = 64; + size = TEST_TABLE_SIZE; // default_action = swap_eth_addresses; // test_mirror(): in gen_testdata.py default_action = send_to_port1; // test_port1() // default_action = send_to_all_ports; // test_allports(): diff --git a/netpfga/minip4/src/minip4_solution.p4 b/netpfga/minip4/src/minip4_solution.p4 index 19418c9..7f37e4f 120000 --- a/netpfga/minip4/src/minip4_solution.p4 +++ b/netpfga/minip4/src/minip4_solution.p4 @@ -1 +1 @@ -minip4_solution-v6zero.p4 \ No newline at end of file +minip4_solution-nat64.p4 \ No newline at end of file diff --git a/netpfga/minip4/src/settings.p4 b/netpfga/minip4/src/settings.p4 new file mode 120000 index 0000000..0c5f2be --- /dev/null +++ b/netpfga/minip4/src/settings.p4 @@ -0,0 +1 @@ +../../../p4src/settings.p4 \ No newline at end of file diff --git a/p4src/settings.p4 b/p4src/settings.p4 index bff5518..e2014b1 100644 --- a/p4src/settings.p4 +++ b/p4src/settings.p4 @@ -10,5 +10,6 @@ #define ICMP6_TABLE_SIZE 64 /* icmp6 handlers */ #define ICMP_TABLE_SIZE 64 /* icmp6 handlers */ #define NAT64_TABLE_SIZE 64 /* nat64 and nat46 entries */ +#define TEST_TABLE_SIZE 64 /* nat64 and nat46 entries */ #endif