diff --git a/sirius-pipeline/README.md b/sirius-pipeline/README.md index 7f1ac2164..2c19dfc03 100644 --- a/sirius-pipeline/README.md +++ b/sirius-pipeline/README.md @@ -28,10 +28,12 @@ table_add direction_lookup set_direction 70 => 2 table_add eni_lookup_from_vm outbound.set_eni cc:cc:cc:cc:cc:cc => 7 table_add eni_lookup_to_vm inbound.set_eni c:cc:cc:cc:cc:cc => 7 table_add eni_to_vni set_vni 7 => 9 -table_add routing route_vnet 7 0x01010100/24 => 14 -table_add ca_to_pa set_tunnel_mapping 14 0x01010102 => 0x02020202 88:88:88:88:88:88 1 -table_add ca_to_pa set_tunnel_mapping 14 0x01010103 => 0x02020202 88:88:88:88:88:88 0 +table_add routing route_vnet 7 0 0x01010100/24 => 14 +table_add ca_to_pa set_tunnel_mapping 14 0 0x01010102 => 0x02020202 88:88:88:88:88:88 1 +table_add ca_to_pa set_tunnel_mapping 14 0 0x01010103 => 0x02020202 88:88:88:88:88:88 0 table_add appliance set_appliance 0&&&0 => 77:77:77:77:77:77 66:66:66:66:66:66 0x02020201 0 +table_add ca_to_pa set_tunnel_mapping 14 1 0x01010104 => 0x02020202 88:88:88:88:88:88 1 +table_add ca_to_pa set_tunnel_mapping 14 1 0x01010105 => 0x02020202 88:88:88:88:88:88 0 ``` # Sirius Pipeline P4 Behavior Models diff --git a/sirius-pipeline/bmv2/sirius_headers.p4 b/sirius-pipeline/bmv2/sirius_headers.p4 index dfadb5317..2eecb6ec8 100644 --- a/sirius-pipeline/bmv2/sirius_headers.p4 +++ b/sirius-pipeline/bmv2/sirius_headers.p4 @@ -4,6 +4,7 @@ typedef bit<48> EthernetAddress; typedef bit<32> IPv4Address; typedef bit<128> IPv6Address; +typedef bit<128> IPv4ORv6Address; header ethernet_t { EthernetAddress dst_addr; diff --git a/sirius-pipeline/bmv2/sirius_metadata.p4 b/sirius-pipeline/bmv2/sirius_metadata.p4 index a911e4fdf..a5773d8ec 100644 --- a/sirius-pipeline/bmv2/sirius_metadata.p4 +++ b/sirius-pipeline/bmv2/sirius_metadata.p4 @@ -32,6 +32,8 @@ struct metadata_t { bit<16> eni; bit<16> vm_id; bit<8> appliance_id; + bit<1> is_dst_ip_v6; + IPv4ORv6Address dst_ip_addr; conntrack_data_t conntrack_data; } diff --git a/sirius-pipeline/bmv2/sirius_outbound.p4 b/sirius-pipeline/bmv2/sirius_outbound.p4 index d8390f038..70d300a57 100644 --- a/sirius-pipeline/bmv2/sirius_outbound.p4 +++ b/sirius-pipeline/bmv2/sirius_outbound.p4 @@ -32,7 +32,8 @@ control outbound(inout headers_t hdr, table routing { key = { meta.eni : exact @name("meta.eni:eni"); - hdr.ipv4.dst_addr : lpm @name("hdr.ipv4.dst_addr:destination"); + meta.is_dst_ip_v6 : exact @name("meta.is_dst_ip_v6:v4_or_v6"); + meta.dst_ip_addr : lpm @name("meta.dst_ip_addr:destination"); } actions = { @@ -62,7 +63,8 @@ control outbound(inout headers_t hdr, key = { /* Flow for express route */ meta.encap_data.dest_vnet_vni : exact @name("meta.encap_data.dest_vnet_vni:dest_vni"); - hdr.ipv4.dst_addr : exact @name("hdr.ipv4.dst_addr:dip"); + meta.is_dst_ip_v6 : exact @name("meta.is_dst_ip_v6:v4_or_v6"); + meta.dst_ip_addr : exact @name("meta.dst_ip_addr:dip"); } actions = { @@ -107,8 +109,8 @@ control outbound(inout headers_t hdr, meta.encap_data.underlay_sip, meta.encap_data.overlay_dmac, meta.encap_data.vni); - } - } + } + } } } diff --git a/sirius-pipeline/bmv2/sirius_parser.p4 b/sirius-pipeline/bmv2/sirius_parser.p4 index 85884d10d..3e60dfc59 100644 --- a/sirius-pipeline/bmv2/sirius_parser.p4 +++ b/sirius-pipeline/bmv2/sirius_parser.p4 @@ -11,7 +11,7 @@ error { #define UDP_PORT_VXLAN 4789 #define UDP_PROTO 17 #define TCP_PROTO 6 -#define IPV4_ETHTYPE 0x800 +#define IPV4_ETHTYPE 0x0800 #define IPV6_ETHTYPE 0x86dd parser sirius_parser(packet_in packet, @@ -22,7 +22,8 @@ parser sirius_parser(packet_in packet, state start { packet.extract(hd.ethernet); transition select(hd.ethernet.ether_type) { - 0x0800: parse_ipv4; + IPV4_ETHTYPE: parse_ipv4; + IPV6_ETHTYPE: parse_ipv6; default: accept; } } @@ -38,6 +39,15 @@ parser sirius_parser(packet_in packet, } } + state parse_ipv6 { + packet.extract(hd.ipv6); + transition select(hd.ipv6.next_header) { + UDP_PROTO: parse_udp; + TCP_PROTO: parse_tcp; + default: accept; + } + } + state parse_udp { packet.extract(hd.udp); transition select(hd.udp.dst_port) { @@ -60,6 +70,7 @@ parser sirius_parser(packet_in packet, packet.extract(hd.inner_ethernet); transition select(hd.ethernet.ether_type) { IPV4_ETHTYPE: parse_inner_ipv4; + IPV6_ETHTYPE: parse_inner_ipv6; default: accept; } } @@ -75,6 +86,15 @@ parser sirius_parser(packet_in packet, } } + state parse_inner_ipv6 { + packet.extract(hd.inner_ipv6); + transition select(hd.inner_ipv6.next_header) { + UDP_PROTO: parse_inner_udp; + TCP_PROTO: parse_inner_tcp; + default: accept; + } + } + state parse_inner_tcp { packet.extract(hd.inner_tcp); transition accept; diff --git a/sirius-pipeline/bmv2/sirius_pipeline.p4 b/sirius-pipeline/bmv2/sirius_pipeline.p4 index 1955e8f1a..19bfcd93f 100644 --- a/sirius-pipeline/bmv2/sirius_pipeline.p4 +++ b/sirius-pipeline/bmv2/sirius_pipeline.p4 @@ -121,6 +121,15 @@ control sirius_ingress(inout headers_t hdr, inbound_routing.apply(); } + meta.dst_ip_addr = 0; + meta.is_dst_ip_v6 = 0; + if (hdr.ipv6.isValid()) { + meta.dst_ip_addr = hdr.ipv6.dst_addr; + meta.is_dst_ip_v6 = 1; + } else if (hdr.ipv4.isValid()) { + meta.dst_ip_addr = (bit<128>)hdr.ipv4.dst_addr; + } + /* At this point the processing is done on customer headers */ /* Put VM's MAC in the direction agnostic metadata field */