├── int-demo ├── README.md └── int-demo.pdf └── sosr15 ├── DC.p4 ├── DC.p4 ├── includes │ ├── constants.h │ ├── egress_metadata.p4 │ ├── headers.p4 │ ├── ingress_metadata.p4 │ ├── intrinsic.p4 │ ├── null_actions.p4 │ ├── p4features.h │ ├── parser.p4 │ └── table_sizes.h └── table_definitions │ ├── egress │ ├── cpu_rewrite.p4 │ ├── egress_bd_map.p4 │ ├── egress_block.p4 │ ├── egress_system_acl.p4 │ ├── egress_vlan_xlate.p4 │ ├── outer_mac.p4 │ ├── rewrite.p4 │ ├── rid.p4 │ ├── tunnel_decap.p4 │ ├── tunnel_dst_rewrite.p4 │ ├── tunnel_rewrite.p4 │ └── tunnel_src_rewrite.p4 │ ├── egress_tables.p4 │ ├── ingress │ ├── bd.p4 │ ├── dmac.p4 │ ├── ecmp_group.p4 │ ├── fwd_result.p4 │ ├── ip_fib.p4 │ ├── ip_racl.p4 │ ├── ipv4_dest_vtep.p4 │ ├── ipv4_src_vtep.p4 │ ├── lag_group.p4 │ ├── learn_notify.p4 │ ├── mac_ip_acl.p4 │ ├── mirror_acl.p4 │ ├── next_hop.p4 │ ├── outer_rmac.p4 │ ├── port_mapping.p4 │ ├── port_vlan_mapping.p4 │ ├── rmac.p4 │ ├── smac.p4 │ ├── spanning_tree.p4 │ ├── system_acl.p4 │ ├── tunnel.p4 │ ├── validate_outer_ethernet.p4 │ ├── validate_outer_ipv4_packet.p4 │ └── validate_packet.p4 │ └── ingress_tables.p4 ├── README.md └── sosr-dc-p4.pdf /int-demo/README.md: -------------------------------------------------------------------------------- 1 | Open-source code for INT is available at: https://github.com/p4lang/ntf/tree/int-demo/apps/int 2 | -------------------------------------------------------------------------------- /int-demo/int-demo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p4lang/papers/1bef7268cba561a2ef8ca77a089947097215912b/int-demo/int-demo.pdf -------------------------------------------------------------------------------- /sosr15/DC.p4/DC.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "includes/headers.p4" 16 | #include "includes/parser.p4" 17 | #include "includes/p4features.h" 18 | #include "includes/intrinsic.p4" 19 | #include "includes/table_sizes.h" 20 | #include "includes/constants.h" 21 | 22 | /* Define metadata variables for ingress and egress metadata */ 23 | #include "includes/ingress_metadata.p4" 24 | #include "includes/egress_metadata.p4" 25 | metadata ingress_metadata_t ingress_metadata; 26 | metadata egress_metadata_t egress_metadata; 27 | 28 | /* Null actions, nop() and on_miss() */ 29 | #include "includes/null_actions.p4" 30 | 31 | /* All ingress tables */ 32 | #include "table_definitions/ingress_tables.p4" 33 | 34 | control ingress { 35 | 36 | /* Check to see the whole stage needs to be bypassed */ 37 | if(ingress_metadata.ingress_bypass == FALSE) { 38 | 39 | /* validate the ethernet header */ 40 | apply(validate_outer_ethernet); 41 | 42 | /* validate input packet and perform basic validations */ 43 | if (valid(ipv4)) { 44 | apply(validate_outer_ipv4_packet); 45 | } 46 | 47 | /* input mapping - derive an ifindex */ 48 | apply(port_mapping); 49 | 50 | /* derive lif, bd */ 51 | apply(port_vlan_mapping); 52 | 53 | if (ingress_metadata.stp_group != STP_GROUP_NONE) { 54 | apply(spanning_tree); 55 | } 56 | 57 | #ifndef TUNNEL_DISABLE 58 | 59 | /* outer RMAC lookup for tunnel termination */ 60 | apply(outer_rmac); 61 | 62 | /* src vtep table lookup */ 63 | if (valid(ipv4)) { 64 | apply(ipv4_src_vtep); 65 | } 66 | 67 | if (ingress_metadata.lkp_pkt_type == L2_UNICAST) { 68 | /* check for ipv4 unicast tunnel termination */ 69 | if ((ingress_metadata.lkp_ip_type == IPTYPE_IPV4) and 70 | (ingress_metadata.ipv4_unicast_enabled == TRUE)) { 71 | apply(ipv4_dest_vtep); 72 | } 73 | } 74 | #endif /* TUNNEL_DISABLE */ 75 | 76 | #ifndef TUNNEL_DISABLE 77 | /* perform tunnel termination */ 78 | if ((ingress_metadata.src_vtep_miss == FALSE) and 79 | (((ingress_metadata.outer_rmac_hit == TRUE) and 80 | (ingress_metadata.tunnel_terminate == TRUE)) or 81 | ((ingress_metadata.lkp_pkt_type == L2_MULTICAST) and 82 | (ingress_metadata.tunnel_terminate == TRUE)))) { 83 | apply(tunnel); 84 | } 85 | else { 86 | #endif /* TUNNEL_DISABLE */ 87 | /* extract BD related parameters */ 88 | apply(bd); 89 | #ifndef TUNNEL_DISABLE 90 | } 91 | #endif /* TUNNEL_DISABLE */ 92 | 93 | /* validate packet */ 94 | apply(validate_packet); 95 | 96 | /* l2 lookups */ 97 | apply(smac); 98 | 99 | /* generate learn notify digest if permitted */ 100 | apply(learn_notify); 101 | 102 | #ifndef ACL_DISABLE 103 | /* mirror ACL */ 104 | apply(mirror_acl); 105 | 106 | /* port and vlan ACL */ 107 | if (ingress_metadata.lkp_ip_type == IPTYPE_NONE) { 108 | apply(mac_acl); 109 | } 110 | else { 111 | if (ingress_metadata.lkp_ip_type == IPTYPE_IPV4) { 112 | apply(ip_acl); 113 | } 114 | } 115 | #endif /* ACL DISABLE */ 116 | 117 | apply(rmac) { 118 | on_miss { 119 | apply(dmac); 120 | } 121 | default { 122 | if ((ingress_metadata.lkp_ip_type == IPTYPE_IPV4) and 123 | (ingress_metadata.ipv4_unicast_enabled == TRUE)) { 124 | 125 | #ifndef ACL_DISABLE 126 | /* router ACL/PBR */ 127 | apply(ip_racl); 128 | #endif /* ACL_DISABLE */ 129 | 130 | /* fib lookup */ 131 | apply(ipv4_fib) { 132 | on_miss { 133 | apply(ipv4_fib_lpm); 134 | } 135 | } 136 | } 137 | } 138 | } 139 | /* merge the results and decide whice one to use */ 140 | apply(fwd_result); 141 | 142 | /* resolve ecmp */ 143 | if (ingress_metadata.ecmp_index != 0) { 144 | apply(ecmp_group); 145 | } else { 146 | /* resolve nexthop */ 147 | apply(nexthop); 148 | } 149 | 150 | /* resolve final egress port for unicast traffic */ 151 | apply(lag_group); 152 | 153 | #ifndef ACL_DISABLE 154 | /* system acls */ 155 | apply(system_acl); 156 | #endif /* ACL_DISABLE */ 157 | } 158 | } 159 | 160 | /* Egress tables */ 161 | #include "table_definitions/egress_tables.p4" 162 | 163 | control egress { 164 | if (egress_metadata.egress_bypass == FALSE) { 165 | 166 | #ifndef MULTICAST_DISABLE 167 | if(intrinsic_metadata.replication_id != 0) { 168 | /* set info from rid */ 169 | apply(rid); 170 | } 171 | #endif /* MULTICAST_DISABLE */ 172 | 173 | #ifndef TUNNEL_DISABLE 174 | /* perform tunnel decap */ 175 | if (ingress_metadata.tunnel_terminate == TRUE) { 176 | if (egress_metadata.replica == FALSE) { 177 | apply(tunnel_decap); 178 | } 179 | } 180 | 181 | /* egress bd to vnid mapping */ 182 | apply(egress_bd_map); 183 | #endif /* TUNNEL_DISABLE */ 184 | 185 | /* apply nexthop_index based packet rewrites */ 186 | apply(rewrite); 187 | 188 | #ifndef TUNNEL_DISABLE 189 | if (egress_metadata.tunnel_type != EGRESS_TUNNEL_TYPE_NONE) { 190 | /* tunnel rewrites */ 191 | apply(tunnel_rewrite); 192 | 193 | /* rewrite tunnel src and dst ip */ 194 | apply(tunnel_src_rewrite); 195 | apply(tunnel_dst_rewrite); 196 | } 197 | #endif /* TUNNEL_DISABLE */ 198 | 199 | /* rewrite source/destination mac if needed */ 200 | if (egress_metadata.routed == TRUE) { 201 | apply(outer_mac); 202 | } 203 | 204 | apply(egress_block) { 205 | on_miss { 206 | /* egress vlan translation */ 207 | apply(egress_vlan_xlate); 208 | } 209 | } 210 | 211 | #ifndef ACL_DISABLE 212 | /* apply egress acl */ 213 | apply(egress_system_acl); 214 | #endif /* ACL_DISABLE */ 215 | 216 | apply(cpu_rewrite); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/constants.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* #define constants that are used elsewhere */ 16 | 17 | /* Boolean */ 18 | #define FALSE 0 19 | #define TRUE 1 20 | 21 | /* Packet types */ 22 | #define L2_UNICAST 1 23 | #define L2_MULTICAST 2 24 | #define L2_BROADCAST 4 25 | 26 | /* IP types */ 27 | #define IPTYPE_NONE 0 28 | #define IPTYPE_IPV4 1 29 | 30 | /* Egress tunnel types */ 31 | #define EGRESS_TUNNEL_TYPE_NONE 0 32 | #define EGRESS_TUNNEL_TYPE_IPV4_VXLAN 1 33 | #define EGRESS_TUNNEL_TYPE_IPV4_GENEVE 2 34 | #define EGRESS_TUNNEL_TYPE_IPV4_NVGRE 3 35 | #define EGRESS_TUNNEL_TYPE_IPV4_ERSPANV2 4 36 | 37 | #define VRF_BIT_WIDTH 12 38 | #define BD_BIT_WIDTH 16 39 | #define ECMP_BIT_WIDTH 10 40 | #define LAG_BIT_WIDTH 8 41 | #define IFINDEX_BIT_WIDTH 10 42 | 43 | #define STP_GROUP_NONE 0 44 | 45 | /* Egress spec */ 46 | #define CPU_PORT 250 47 | 48 | /* Learning Recievers */ 49 | #define MAC_LEARN_RECIEVER 1024 50 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/egress_metadata.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | header_type egress_metadata_t { 16 | fields { 17 | smac_idx : 9; /* index into source mac table */ 18 | bd : BD_BIT_WIDTH; /* egress inner bd */ 19 | replica : 1; /* is this a replica */ 20 | vnid : 24; /* tunnel vnid */ 21 | mac_da : 48; /* final mac da */ 22 | routed : 1; /* is this replica routed */ 23 | 24 | mtu_check_fail : 1; /* MTU check failed */ 25 | 26 | tunnel_type : 4; /* type of tunnel */ 27 | tunnel_src_index : 9; /* index to tunnel src ip */ 28 | tunnel_dst_index : 14; /* index to tunnel dst ip */ 29 | 30 | drop_reason : 8; /* drop reason */ 31 | egress_bypass : 1; /* skip the entire egress pipeline */ 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/headers.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | header_type ethernet_t { 16 | fields { 17 | dstAddr : 48; 18 | srcAddr : 48; 19 | etherType : 16; 20 | } 21 | } 22 | 23 | header_type snap_header_t { 24 | fields { 25 | dsap : 8; 26 | ssap : 8; 27 | control_ : 8; 28 | oui : 24; 29 | type_ : 16; 30 | } 31 | } 32 | 33 | header_type roce_header_t { 34 | fields { 35 | ib_grh : 320; 36 | ib_bth : 96; 37 | } 38 | } 39 | 40 | header_type roce_v2_header_t { 41 | fields { 42 | ib_bth : 96; 43 | } 44 | } 45 | 46 | header_type fcoe_header_t { 47 | fields { 48 | version : 4; 49 | type_ : 4; 50 | sof : 8; 51 | rsvd1 : 32; 52 | ts_upper : 32; 53 | ts_lower : 32; 54 | size_ : 32; 55 | eof : 8; 56 | rsvd2 : 24; 57 | } 58 | } 59 | 60 | header_type cpu_header_t { 61 | fields { 62 | qid : 3; 63 | pad : 1; 64 | reason_code : 12; 65 | rxhash : 16; 66 | bridge_domain : 16; 67 | ingress_lif : 16; 68 | egress_lif : 16; 69 | lu_bypass_ingress : 1; 70 | lu_bypass_egress : 1; 71 | pad1 : 14; 72 | etherType : 16; 73 | } 74 | } 75 | 76 | header_type vlan_tag_t { 77 | fields { 78 | pcp : 3; 79 | cfi : 1; 80 | vid : 12; 81 | etherType : 16; 82 | } 83 | } 84 | 85 | header_type ipv4_t { 86 | fields { 87 | version : 4; 88 | ihl : 4; 89 | diffserv : 8; 90 | totalLen : 16; 91 | identification : 16; 92 | flags : 3; 93 | fragOffset : 13; 94 | ttl : 8; 95 | protocol : 8; 96 | hdrChecksum : 16; 97 | srcAddr : 32; 98 | dstAddr: 32; 99 | } 100 | } 101 | 102 | header_type ipv6_t { 103 | fields { 104 | version : 4; 105 | trafficClass : 8; 106 | flowLabel : 20; 107 | payloadLen : 16; 108 | nextHdr : 8; 109 | hopLimit : 8; 110 | srcAddr : 128; 111 | dstAddr : 128; 112 | } 113 | } 114 | 115 | header_type icmp_t { 116 | fields { 117 | type_ : 8; 118 | code : 8; 119 | hdrChecksum : 16; 120 | } 121 | } 122 | 123 | header_type icmpv6_t { 124 | fields { 125 | type_ : 8; 126 | code : 8; 127 | hdrChecksum : 16; 128 | } 129 | } 130 | 131 | header_type tcp_t { 132 | fields { 133 | srcPort : 16; 134 | dstPort : 16; 135 | seqNo : 32; 136 | ackNo : 32; 137 | dataOffset : 4; 138 | res : 4; 139 | flags : 8; 140 | window : 16; 141 | checksum : 16; 142 | urgentPtr : 16; 143 | } 144 | } 145 | 146 | header_type udp_t { 147 | fields { 148 | srcPort : 16; 149 | dstPort : 16; 150 | length_ : 16; 151 | checksum : 16; 152 | } 153 | } 154 | 155 | header_type gre_t { 156 | fields { 157 | C : 1; 158 | R : 1; 159 | K : 1; 160 | S : 1; 161 | s : 1; 162 | recurse : 3; 163 | flags : 5; 164 | ver : 3; 165 | proto : 16; 166 | } 167 | } 168 | 169 | header_type nvgre_t { 170 | fields { 171 | tni : 24; 172 | reserved : 8; 173 | } 174 | } 175 | 176 | /* 8 bytes */ 177 | header_type erspan_header_v1_t { 178 | fields { 179 | version : 4; 180 | vlan : 12; 181 | priority : 6; 182 | span_id : 10; 183 | direction : 8; 184 | truncated: 8; 185 | } 186 | } 187 | 188 | /* 8 bytes */ 189 | header_type erspan_header_v2_t { 190 | fields { 191 | version : 4; 192 | vlan : 12; 193 | priority : 6; 194 | span_id : 10; 195 | unknown7 : 32; 196 | } 197 | } 198 | 199 | header_type arp_rarp_t { 200 | fields { 201 | hwType : 16; 202 | protoType : 16; 203 | hwAddrLen : 8; 204 | protoAddrLen : 8; 205 | opcode : 16; 206 | } 207 | } 208 | 209 | header_type arp_rarp_ipv4_t { 210 | fields { 211 | srcHwAddr : 48; 212 | srcProtoAddr : 32; 213 | dstHwAddr : 48; 214 | dstProtoAddr : 32; 215 | } 216 | } 217 | 218 | header_type vxlan_t { 219 | fields { 220 | flags : 8; 221 | reserved : 24; 222 | vni : 24; 223 | reserved2 : 8; 224 | } 225 | } 226 | 227 | header_type nsh_t { 228 | fields { 229 | oam : 1; 230 | context : 1; 231 | flags : 6; 232 | reserved : 8; 233 | protoType: 16; 234 | spath : 24; 235 | sindex : 8; 236 | } 237 | } 238 | 239 | header_type nsh_context_t { 240 | fields { 241 | network_platform : 32; 242 | network_shared : 32; 243 | service_platform : 32; 244 | service_shared : 32; 245 | } 246 | } 247 | 248 | /* GENEVE HEADERS 249 | 3 possible options with known type, known length */ 250 | 251 | header_type genv_t { 252 | fields { 253 | ver : 2; 254 | optLen : 6; 255 | oam : 1; 256 | critical : 1; 257 | reserved : 6; 258 | protoType : 16; 259 | vni : 24; 260 | reserved2 : 8; 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/ingress_metadata.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* METADATA */ 16 | header_type ingress_metadata_t { 17 | fields { 18 | lkp_pkt_type : 3; 19 | lkp_mac_sa : 48; 20 | lkp_mac_da : 48; 21 | lkp_mac_type : 16; 22 | lkp_ip_type : 2; 23 | lkp_ipv4_sa : 32; 24 | lkp_ipv4_da : 32; 25 | lkp_ip_proto : 8; 26 | lkp_ip_tc : 8; 27 | lkp_ip_ttl : 8; 28 | lkp_icmp_type : 16; 29 | lkp_icmp_code : 16; 30 | 31 | lkp_l4_sport : 16; 32 | lkp_l4_dport : 16; 33 | lkp_inner_l4_sport : 16; 34 | lkp_inner_l4_dport : 16; 35 | 36 | l3_length : 16; /* l3 length */ 37 | 38 | ifindex : IFINDEX_BIT_WIDTH; /* input interface index - MSB bit lag*/ 39 | lif : 16; /* logical interface */ 40 | vrf : VRF_BIT_WIDTH; /* VRF */ 41 | 42 | tunnel_type : 4; /* tunnel type from parser */ 43 | tunnel_terminate : 1; /* should tunnel be terminated */ 44 | tunnel_vni : 24; /* tunnel id */ 45 | tunnel_lif : 16; /* tunnel ingress logical interface */ 46 | src_vtep_miss : 1; /* src vtep lookup failed */ 47 | 48 | outer_bd : 8; /* outer BD */ 49 | outer_rmac_group : 10; /* Rmac group, for rmac indirection */ 50 | outer_rmac_hit : 1; /* dst mac is the router's mac */ 51 | outer_dscp : 8; /* outer dscp */ 52 | outer_ttl : 8; /* outer ttl */ 53 | 54 | l2_multicast : 1; /* packet is l2 multicast */ 55 | src_is_link_local : 1; /* source is link local address */ 56 | bd : BD_BIT_WIDTH; /* inner BD */ 57 | ipv4_unicast_enabled : 1; /* is ipv4 unicast routing enabled on BD */ 58 | igmp_snooping_enabled : 1; /* is IGMP snooping enabled on BD */ 59 | rmac_group : 10; /* Rmac group, for rmac indirection */ 60 | rmac_hit : 1; /* dst mac is the router's mac */ 61 | uuc_mc_index : 16; /* unknown unicast multicast index */ 62 | umc_mc_index : 16; /* unknown multicast multicast index */ 63 | bcast_mc_index : 16; /* broadcast multicast index */ 64 | multicast_bridge_mc_index : 16; /* multicast index from igmp/mld snoop */ 65 | routed : 1; /* is packet routed */ 66 | 67 | if_label : 16; /* if label for acls */ 68 | bd_label : 16; /* bd label for acls */ 69 | 70 | l2_src_miss : 1; /* l2 source miss */ 71 | l2_src_move : IFINDEX_BIT_WIDTH; /* l2 source interface mis-match */ 72 | acl_deny : 1; /* ifacl/vacl deny action */ 73 | racl_deny : 1; /* racl deny action */ 74 | l2_redirect : 1; /* l2 redirect action */ 75 | acl_redirect : 1; /* ifacl/vacl redirect action */ 76 | racl_redirect : 1; /* racl redirect action */ 77 | fib_hit : 1; /* fib hit */ 78 | 79 | learn_mac : 48; /* mac learn data */ 80 | 81 | l2_nexthop : 16; /* next hop from l2 */ 82 | acl_nexthop : 16; /* next hop from ifacl/vacl */ 83 | racl_nexthop : 16; /* next hop from racl */ 84 | fib_nexthop : 16; /* next hop from fib */ 85 | l2_ecmp : 10; /* ecmp index from l2 */ 86 | acl_ecmp : 10; /* ecmp index from ifacl */ 87 | racl_ecmp : 10; /* ecmp index from racl */ 88 | fib_ecmp : 10; /* ecmp index from fib */ 89 | ecmp_index : 10; /* final ecmp index */ 90 | ecmp_offset : 14; /* offset into the ecmp table */ 91 | nexthop_index : 16; /* final next hop index */ 92 | lag_offset : 14; /* numer of lag members */ 93 | 94 | ttl : 8; /* update ttl */ 95 | 96 | egress_ifindex : IFINDEX_BIT_WIDTH; /* egress interface index */ 97 | egress_bd : BD_BIT_WIDTH; /* egress BD */ 98 | 99 | ingress_bypass : 1; /* skip the entire ingress pipeline */ 100 | ipv4_dstaddr_24b : 24; /* first 24b of ipv4 dst addr */ 101 | drop_0 : 1; /* dummy */ 102 | drop_reason : 8; /* drop reason */ 103 | msg_type : 8; 104 | stp_group: 10; /* spanning tree group id */ 105 | stp_state : 3; /* spanning tree port state */ 106 | stp_enabled: 1; /* spanning tree is enabled */ 107 | control_frame: 1; /* control frame */ 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/intrinsic.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | header_type intrinsic_metadata_t { 16 | fields { 17 | eg_mcast_group : 16; // multicast group id (key for the mcast replication table) 18 | replication_id : 16; // Replication ID for multicast 19 | lf_field_list : 32; // Learn filter field list 20 | } 21 | } 22 | 23 | metadata intrinsic_metadata_t intrinsic_metadata; 24 | 25 | #define EGSPEC_UCAST_CPU_PORT 0xFF00000000 26 | #define EGSPEC_NULL_PORT 0x0000000000 27 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/null_actions.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action nop() { 16 | } 17 | 18 | action on_miss() { 19 | } 20 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/p4features.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Profiles control 16 | 17 | // #define MULTICAST_DISABLE 18 | // #define TUNNEL_DISABLE 19 | // #define ACL_DISABLE 20 | 21 | #ifdef MULTICAST_DISABLE 22 | #define P4_MULTICAST_DISABLE 23 | #endif 24 | 25 | #ifdef TUNNEL_DISABLE 26 | #define P4_TUNNEL_DISABLE 27 | #endif 28 | 29 | #ifdef ACL_DISABLE 30 | #define P4_ACL_DISABLE 31 | #endif 32 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/parser.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | parser start { 16 | set_metadata(ingress_metadata.drop_0, 0); 17 | return parse_ethernet; 18 | } 19 | 20 | #define ETHERTYPE_CPU 0x9000, 0x010c 21 | #define ETHERTYPE_VLAN 0x8100, 0x9100, 0x9200, 0x9300 22 | #define ETHERTYPE_MPLS 0x8847 23 | #define ETHERTYPE_IPV4 0x0800 24 | #define ETHERTYPE_IPV6 0x86dd 25 | #define ETHERTYPE_ARP 0x0806 26 | #define ETHERTYPE_RARP 0x8035 27 | #define ETHERTYPE_NSH 0x894f 28 | #define ETHERTYPE_ETHERNET 0x6558 29 | #define ETHERTYPE_ROCE 0x8915 30 | #define ETHERTYPE_FCOE 0x8906 31 | /* missing: vlan_3b, vlan_5b, ieee802_1q, ieee802_1ad */ 32 | 33 | #define IPV4_MULTICAST_MAC 0x01005E 34 | #define IPV6_MULTICAST_MAC 0x3333 35 | 36 | /* Tunnel types */ 37 | #define TUNNEL_TYPE_NONE 0 38 | #define TUNNEL_TYPE_VXLAN 1 39 | #define TUNNEL_TYPE_GRE 2 40 | #define TUNNEL_TYPE_GENEVE 3 41 | #define TUNNEL_TYPE_NVGRE 4 42 | #define TUNNEL_TYPE_MPLS 5 43 | 44 | header ethernet_t ethernet; 45 | 46 | parser parse_ethernet { 47 | extract(ethernet); 48 | return select(latest.etherType) { 49 | 0 mask 0xf800: parse_snap_header; /* < 1536 */ 50 | ETHERTYPE_CPU : parse_cpu_header; 51 | ETHERTYPE_VLAN : parse_vlan; 52 | ETHERTYPE_IPV4 : parse_ipv4; 53 | ETHERTYPE_IPV6 : parse_ipv6; 54 | ETHERTYPE_ARP : parse_arp_rarp; 55 | ETHERTYPE_RARP : parse_arp_rarp; 56 | ETHERTYPE_NSH : parse_nsh; 57 | ETHERTYPE_ROCE: parse_roce; 58 | ETHERTYPE_FCOE: parse_fcoe; 59 | default: ingress; 60 | } 61 | } 62 | 63 | header snap_header_t snap_header; 64 | 65 | parser parse_snap_header { 66 | extract(snap_header); 67 | return ingress; 68 | } 69 | 70 | header roce_header_t roce; 71 | 72 | parser parse_roce { 73 | extract(roce); 74 | return ingress; 75 | } 76 | 77 | header fcoe_header_t fcoe; 78 | 79 | parser parse_fcoe { 80 | extract(fcoe); 81 | return ingress; 82 | } 83 | 84 | header cpu_header_t cpu_header; 85 | 86 | parser parse_cpu_header { 87 | extract(cpu_header); 88 | set_metadata(ingress_metadata.ingress_bypass, 1); 89 | set_metadata(standard_metadata.egress_spec, latest.egress_lif); 90 | return select(latest.etherType) { 91 | 0 mask 0xf800: parse_snap_header; /* < 1536 */ 92 | ETHERTYPE_VLAN : parse_vlan; 93 | ETHERTYPE_IPV4 : parse_ipv4; 94 | ETHERTYPE_IPV6 : parse_ipv6; 95 | ETHERTYPE_ARP : parse_arp_rarp; 96 | ETHERTYPE_RARP : parse_arp_rarp; 97 | ETHERTYPE_NSH : parse_nsh; 98 | ETHERTYPE_ROCE: parse_roce; 99 | ETHERTYPE_FCOE: parse_fcoe; 100 | default: ingress; 101 | } 102 | } 103 | 104 | #define VLAN_DEPTH 2 105 | header vlan_tag_t vlan_tag_[VLAN_DEPTH]; 106 | 107 | parser parse_vlan { 108 | extract(vlan_tag_[next]); 109 | return select(latest.etherType) { 110 | ETHERTYPE_VLAN : parse_vlan; 111 | ETHERTYPE_IPV4 : parse_ipv4; 112 | ETHERTYPE_IPV6 : parse_ipv6; 113 | ETHERTYPE_ARP : parse_arp_rarp; 114 | ETHERTYPE_RARP : parse_arp_rarp; 115 | default: ingress; 116 | } 117 | } 118 | 119 | #define IP_PROTOCOLS_ICMP 1 120 | #define IP_PROTOCOLS_TCP 6 121 | #define IP_PROTOCOLS_UDP 17 122 | #define IP_PROTOCOLS_GRE 47 123 | #define IP_PROTOCOLS_IPSEC_ESP 50 124 | #define IP_PROTOCOLS_IPSEC_AH 51 125 | #define IP_PROTOCOLS_ICMPV6 58 126 | #define IP_PROTOCOLS_SCTP 132 127 | 128 | header ipv4_t ipv4; 129 | 130 | field_list ipv4_checksum_list { 131 | ipv4.version; 132 | ipv4.ihl; 133 | ipv4.diffserv; 134 | ipv4.totalLen; 135 | ipv4.identification; 136 | ipv4.flags; 137 | ipv4.fragOffset; 138 | ipv4.ttl; 139 | ipv4.protocol; 140 | ipv4.srcAddr; 141 | ipv4.dstAddr; 142 | } 143 | 144 | field_list_calculation ipv4_checksum { 145 | input { 146 | ipv4_checksum_list; 147 | } 148 | algorithm : csum16; 149 | output_width : 16; 150 | } 151 | 152 | calculated_field ipv4.hdrChecksum { 153 | verify ipv4_checksum; 154 | update ipv4_checksum; 155 | } 156 | 157 | parser parse_ipv4 { 158 | extract(ipv4); 159 | set_metadata(ingress_metadata.ipv4_dstaddr_24b, latest.dstAddr); 160 | return select(latest.fragOffset, latest.protocol) { 161 | IP_PROTOCOLS_ICMP : parse_icmp; 162 | IP_PROTOCOLS_TCP : parse_tcp; 163 | IP_PROTOCOLS_UDP : parse_udp; 164 | IP_PROTOCOLS_GRE : parse_gre; 165 | // IP_PROTOCOLS_SCTP : parse_sctp; 166 | default: ingress; 167 | } 168 | } 169 | 170 | header ipv6_t ipv6; 171 | 172 | parser parse_ipv6 { 173 | extract(ipv6); 174 | return select(latest.nextHdr) { 175 | IP_PROTOCOLS_ICMPV6 : parse_icmpv6; 176 | IP_PROTOCOLS_TCP : parse_tcp; 177 | IP_PROTOCOLS_UDP : parse_udp; 178 | IP_PROTOCOLS_GRE : parse_gre; 179 | // IP_PROTOCOLS_SCTP : parse_sctp; 180 | default: ingress; 181 | } 182 | } 183 | 184 | header icmp_t icmp; 185 | 186 | parser parse_icmp { 187 | extract(icmp); 188 | set_metadata(ingress_metadata.msg_type, icmp.code); 189 | return ingress; 190 | } 191 | 192 | header icmpv6_t icmpv6; 193 | 194 | parser parse_icmpv6 { 195 | extract(icmpv6); 196 | set_metadata(ingress_metadata.msg_type, icmpv6.code); 197 | return ingress; 198 | } 199 | 200 | header tcp_t tcp; 201 | 202 | parser parse_tcp { 203 | extract(tcp); 204 | set_metadata(ingress_metadata.lkp_l4_sport, latest.srcPort); 205 | set_metadata(ingress_metadata.lkp_l4_dport, latest.dstPort); 206 | return ingress; 207 | } 208 | 209 | #define UDP_PORT_VXLAN 4789 210 | #define UDP_PORT_GENV 6081 211 | // Check IANA UDP port number 212 | #define UDP_PORT_ROCE_V2 1021 213 | 214 | header udp_t udp; 215 | 216 | header roce_v2_header_t roce_v2; 217 | 218 | parser parse_roce_v2 { 219 | extract(roce_v2); 220 | return ingress; 221 | } 222 | 223 | parser parse_udp { 224 | extract(udp); 225 | set_metadata(ingress_metadata.lkp_l4_sport, latest.srcPort); 226 | set_metadata(ingress_metadata.lkp_l4_dport, latest.dstPort); 227 | return select(latest.dstPort) { 228 | UDP_PORT_VXLAN : parse_vxlan; 229 | UDP_PORT_GENV: parse_geneve; 230 | UDP_PORT_ROCE_V2: parse_roce_v2; 231 | default: ingress; 232 | } 233 | } 234 | 235 | #define GRE_PROTOCOLS_NVGRE 0x6558 236 | #define GRE_PROTOCOLS_GRE 0x6559 237 | #define GRE_PROTOCOLS_ERSPAN_V1 0x88BE 238 | #define GRE_PROTOCOLS_ERSPAN_V2 0x22EB 239 | 240 | #define GRE_DEPTH 2 241 | 242 | //header gre_t gre[GRE_DEPTH]; 243 | header gre_t gre; 244 | 245 | #if 0 246 | header_type gre_opt_t { 247 | fields { 248 | key : 32; 249 | } 250 | } 251 | 252 | header gre_opt_t gre_opt; 253 | 254 | parser parse_gre_key { 255 | extract(gre_opt); 256 | set_metadata(ingress_metadata.tunnel_vni, gre_opt.key); 257 | return ingress; 258 | } 259 | parser parse_gre_key2 { 260 | extract(gre_opt); 261 | set_metadata(ingress_metadata.tunnel_vni, gre_opt.key); 262 | extract(gre_opt); 263 | return ingress; 264 | } 265 | parser parse_gre_key22 { 266 | extract(gre_opt); 267 | extract(gre_opt); 268 | set_metadata(ingress_metadata.tunnel_vni, gre_opt.key); 269 | return ingress; 270 | } 271 | parser parse_gre_opt1 { 272 | extract(gre_opt); 273 | return ingress; 274 | } 275 | parser parse_gre_opt2 { 276 | extract(gre_opt); 277 | extract(gre_opt); 278 | return ingress; 279 | } 280 | parser parse_gre_opt3 { 281 | extract(gre_opt); 282 | extract(gre_opt); 283 | set_metadata(ingress_metadata.tunnel_vni, gre_opt.key); 284 | extract(gre_opt); 285 | return ingress; 286 | } 287 | 288 | parser parse_gre_opts { 289 | return select(latest.C, latest.S, latest.K) { 290 | 1 mask 0x0000 : parse_gre_key; 291 | 2 mask 0x0000 : parse_gre_opt1; 292 | 3 mask 0x0000 : parse_gre_key2; 293 | 4 mask 0x0000 : parse_gre_opt1; 294 | 5 mask 0x0000 : parse_gre_key22; 295 | 6 mask 0x0000 : parse_gre_opt2; 296 | 7 mask 0x0000 : parse_gre_opt3; 297 | default: ingress; 298 | } 299 | } 300 | #endif 301 | 302 | parser parse_gre { 303 | extract(gre); 304 | set_metadata(ingress_metadata.tunnel_type, TUNNEL_TYPE_GRE); 305 | // parse_gre_opts; 306 | return select(latest.K, latest.proto) { 307 | GRE_PROTOCOLS_NVGRE : parse_nvgre; 308 | // GRE_PROTOCOLS_GRE : parse_gre; 309 | GRE_PROTOCOLS_ERSPAN_V1 : parse_erspan_v1; 310 | GRE_PROTOCOLS_ERSPAN_V2 : parse_erspan_v2; 311 | ETHERTYPE_NSH : parse_nsh; 312 | default: ingress; 313 | } 314 | } 315 | 316 | header nvgre_t nvgre; 317 | header ethernet_t inner_ethernet; 318 | 319 | header ipv4_t inner_ipv4; 320 | header ipv6_t inner_ipv6; 321 | 322 | field_list inner_ipv4_checksum_list { 323 | inner_ipv4.version; 324 | inner_ipv4.ihl; 325 | inner_ipv4.diffserv; 326 | inner_ipv4.totalLen; 327 | inner_ipv4.identification; 328 | inner_ipv4.flags; 329 | inner_ipv4.fragOffset; 330 | inner_ipv4.ttl; 331 | inner_ipv4.protocol; 332 | inner_ipv4.srcAddr; 333 | inner_ipv4.dstAddr; 334 | } 335 | 336 | field_list_calculation inner_ipv4_checksum { 337 | input { 338 | inner_ipv4_checksum_list; 339 | } 340 | algorithm : csum16; 341 | output_width : 16; 342 | } 343 | 344 | calculated_field inner_ipv4.hdrChecksum { 345 | verify inner_ipv4_checksum if(valid(ipv4)); 346 | update inner_ipv4_checksum if(valid(ipv4)); 347 | } 348 | 349 | parser parse_nvgre { 350 | extract(nvgre); 351 | set_metadata(ingress_metadata.tunnel_type, TUNNEL_TYPE_NVGRE); 352 | set_metadata(ingress_metadata.tunnel_vni, latest.tni); 353 | return parse_inner_ethernet; 354 | } 355 | 356 | header erspan_header_v1_t erspan_v1_header; 357 | 358 | parser parse_erspan_v1 { 359 | extract(erspan_v1_header); 360 | return ingress; 361 | } 362 | 363 | header erspan_header_v2_t erspan_v2_header; 364 | 365 | parser parse_erspan_v2 { 366 | extract(erspan_v2_header); 367 | return ingress; 368 | } 369 | 370 | #define ARP_PROTOTYPES_ARP_RARP_IPV4 0x0800 371 | 372 | header arp_rarp_t arp_rarp; 373 | 374 | parser parse_arp_rarp { 375 | extract(arp_rarp); 376 | return select(latest.protoType) { 377 | ARP_PROTOTYPES_ARP_RARP_IPV4 : parse_arp_rarp_ipv4; 378 | default: ingress; 379 | } 380 | } 381 | 382 | header arp_rarp_ipv4_t arp_rarp_ipv4; 383 | 384 | parser parse_arp_rarp_ipv4 { 385 | extract(arp_rarp_ipv4); 386 | return ingress; 387 | } 388 | 389 | header vxlan_t vxlan; 390 | 391 | parser parse_vxlan { 392 | extract(vxlan); 393 | set_metadata(ingress_metadata.tunnel_type, TUNNEL_TYPE_VXLAN); 394 | set_metadata(ingress_metadata.tunnel_vni, latest.vni); 395 | return parse_inner_ethernet; 396 | } 397 | 398 | header genv_t genv; 399 | 400 | parser parse_geneve { 401 | extract(genv); 402 | set_metadata(ingress_metadata.tunnel_vni, latest.vni); 403 | set_metadata(ingress_metadata.tunnel_type, TUNNEL_TYPE_GENEVE); 404 | /* 405 | counter_init(counter_1, latest.optLen); 406 | return select(latest.optLen) { 407 | 0 : parse_genv_inner; 408 | default : parse_genv_opts; 409 | } 410 | */ 411 | return parse_genv_inner; 412 | } 413 | 414 | #if 0 415 | 416 | parser parse_genv_opts { 417 | /* switching on combined class and type */ 418 | return select(current(0, 24)) { 419 | GENV_OPTION_A_TYPE: parse_genv_opt_A; 420 | GENV_OPTION_B_TYPE: parse_genv_opt_B; 421 | GENV_OPTION_C_TYPE: parse_genv_opt_C; 422 | } 423 | } 424 | 425 | parser parse_genv_opt_A { 426 | extract(genv_opt_A); 427 | counter_decrement(counter_1, GENV_OPTION_A_LENGTH); 428 | return select(counter_1) { 429 | 0 : parse_genv_inner; 430 | default : parse_genv_opts; 431 | } 432 | } 433 | 434 | parser parse_genv_opt_B { 435 | extract(genv_opt_B); 436 | counter_decrement(counter_1, GENV_OPTION_B_LENGTH); 437 | return select(counter_1) { 438 | 0 : parse_genv_inner; 439 | default : parse_genv_opts; 440 | } 441 | } 442 | 443 | parser parse_genv_opt_C { 444 | extract(genv_opt_C); 445 | counter_decrement(counter_1, GENV_OPTION_C_LENGTH); 446 | return select(counter_1) { 447 | 0 : parse_genv_inner; 448 | default : parse_genv_opts; 449 | } 450 | } 451 | #endif 452 | 453 | parser parse_genv_inner { 454 | return select(genv.protoType) { 455 | ETHERTYPE_ETHERNET : parse_inner_ethernet; 456 | ETHERTYPE_IPV4 : parse_inner_ipv4; 457 | ETHERTYPE_IPV6 : parse_inner_ipv6; 458 | default : ingress; 459 | } 460 | } 461 | 462 | header nsh_t nsh; 463 | header nsh_context_t nsh_context; 464 | 465 | parser parse_nsh { 466 | extract(nsh); 467 | extract(nsh_context); 468 | return select(nsh.protoType) { 469 | ETHERTYPE_IPV4 : parse_inner_ipv4; 470 | ETHERTYPE_IPV6 : parse_inner_ipv6; 471 | ETHERTYPE_ETHERNET : parse_inner_ethernet; 472 | default: ingress; 473 | } 474 | } 475 | 476 | parser parse_inner_ipv4 { 477 | extract(inner_ipv4); 478 | return select(latest.fragOffset, latest.protocol) { 479 | IP_PROTOCOLS_ICMP : parse_inner_icmp; 480 | IP_PROTOCOLS_TCP : parse_inner_tcp; 481 | IP_PROTOCOLS_UDP : parse_inner_udp; 482 | default: ingress; 483 | } 484 | } 485 | 486 | header icmp_t inner_icmp; 487 | 488 | parser parse_inner_icmp { 489 | extract(inner_icmp); 490 | return ingress; 491 | } 492 | 493 | header tcp_t inner_tcp; 494 | 495 | parser parse_inner_tcp { 496 | extract(inner_tcp); 497 | set_metadata(ingress_metadata.lkp_inner_l4_sport, latest.srcPort); 498 | set_metadata(ingress_metadata.lkp_inner_l4_dport, latest.dstPort); 499 | return ingress; 500 | } 501 | 502 | header udp_t inner_udp; 503 | 504 | parser parse_inner_udp { 505 | extract(inner_udp); 506 | set_metadata(ingress_metadata.lkp_inner_l4_sport, latest.srcPort); 507 | set_metadata(ingress_metadata.lkp_inner_l4_dport, latest.dstPort); 508 | return ingress; 509 | } 510 | 511 | parser parse_inner_ipv6 { 512 | extract(inner_ipv6); 513 | return select(latest.nextHdr) { 514 | IP_PROTOCOLS_ICMPV6 : parse_inner_icmpv6; 515 | IP_PROTOCOLS_TCP : parse_inner_tcp; 516 | IP_PROTOCOLS_UDP : parse_inner_udp; 517 | default: ingress; 518 | } 519 | } 520 | 521 | header icmpv6_t inner_icmpv6; 522 | 523 | parser parse_inner_icmpv6 { 524 | extract(inner_icmpv6); 525 | return ingress; 526 | } 527 | 528 | parser parse_inner_ethernet { 529 | extract(inner_ethernet); 530 | return select(latest.etherType) { 531 | ETHERTYPE_IPV4 : parse_inner_ipv4; 532 | ETHERTYPE_IPV6 : parse_inner_ipv6; 533 | default: ingress; 534 | } 535 | } 536 | 537 | -------------------------------------------------------------------------------- /sosr15/DC.p4/includes/table_sizes.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #define VALIDATE_PACKET_TABLE_SIZE 64 16 | #define PORTMAP_TABLE_SIZE 258 17 | #define PORT_VLAN_TABLE_SIZE 512 18 | #define OUTER_BD_TABLE_SIZE 256 19 | #define OUTER_ROUTER_MAC_TABLE_SIZE 256 20 | #define DEST_TUNNEL_TABLE_SIZE 512 21 | #define SRC_TUNNEL_TABLE_SIZE 512 22 | #define VNID_MAPPING_TABLE_SIZE 512 23 | #define BD_TABLE_SIZE 512 24 | 25 | #define ROUTER_MAC_TABLE_SIZE 512 26 | #define DMAC_TABLE_SIZE 512 27 | #define SMAC_TABLE_SIZE 512 28 | #define INGRESS_MAC_ACL_TABLE_SIZE 512 29 | #define INGRESS_IP_ACL_TABLE_SIZE 512 30 | #define INGRESS_IP_RACL_TABLE_SIZE 512 31 | #define IPV4_LPM_TABLE_SIZE 512 32 | #define IPV4_HOST_TABLE_SIZE 512 33 | #define FWD_RESULT_TABLE_SIZE 512 34 | #define ECMP_GROUP_TABLE_SIZE 512 35 | #define ECMP_SELECT_TABLE_SIZE 512 36 | #define NEXTHOP_TABLE_SIZE 512 37 | #define LAG_GROUP_TABLE_SIZE 512 38 | #define LAG_SELECT_TABLE_SIZE 512 39 | #define SYSTEM_ACL_SIZE 256 40 | #define LEARN_NOTIFY_TABLE_SIZE 512 41 | 42 | #define SOURCE_MAC_TABLE_SIZE 512 43 | #define EGRESS_VNID_MAPPING_TABLE_SIZE 512 44 | #define REPLICA_TYPE_TABLE_SIZE 16 45 | #define TUNNEL_REWRITE_TABLE_SIZE 256 46 | #define RID_TABLE_SIZE 512 47 | #define TUNNEL_DECAP_TABLE_SIZE 512 48 | #define EGRESS_SYSTEM_ACL_TABLE_SIZE 512 49 | #define EGRESS_BLOCK_TABLE_SIZE 256 50 | #define EGRESS_VLAN_XLATE_TABLE_SIZE 512 51 | #define SPANNING_TREE_TABLE_SIZE 512 52 | #define CPU_REWRITE_TABLE_SIZE 512 53 | #define INGRESS_MIRROR_ACL_TABLE_SIZE 512 54 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/cpu_rewrite.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_cpu_tx_rewrite() { 16 | modify_field(ethernet.etherType, cpu_header.etherType); 17 | remove_header(cpu_header); 18 | } 19 | 20 | action set_cpu_rx_rewrite() { 21 | add_header(cpu_header); 22 | modify_field(cpu_header.etherType, ethernet.etherType); 23 | modify_field(cpu_header.ingress_lif, standard_metadata.ingress_port); 24 | } 25 | 26 | table cpu_rewrite { 27 | reads { 28 | standard_metadata.egress_port : ternary; 29 | standard_metadata.ingress_port : ternary; 30 | } 31 | actions { 32 | nop; 33 | set_cpu_tx_rewrite; 34 | set_cpu_rx_rewrite; 35 | } 36 | size : CPU_REWRITE_TABLE_SIZE; 37 | } 38 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/egress_bd_map.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_egress_bd_properties(vnid ) { 16 | modify_field(egress_metadata.vnid, vnid); 17 | } 18 | 19 | table egress_bd_map { 20 | reads { 21 | ingress_metadata.egress_bd : exact; 22 | } 23 | actions { 24 | nop; 25 | set_egress_bd_properties; 26 | } 27 | size : EGRESS_VNID_MAPPING_TABLE_SIZE; 28 | } 29 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/egress_block.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action egress_drop () { 16 | drop(); 17 | } 18 | 19 | table egress_block { 20 | reads { 21 | standard_metadata.egress_port : exact; 22 | intrinsic_metadata.replication_id : exact; 23 | } 24 | actions { 25 | on_miss; 26 | egress_drop; 27 | } 28 | size : EGRESS_BLOCK_TABLE_SIZE; 29 | } 30 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/egress_system_acl.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action egress_redirect_to_cpu() { 16 | } 17 | 18 | table egress_system_acl { 19 | reads { 20 | egress_metadata.mtu_check_fail : ternary; 21 | } 22 | actions { 23 | nop; 24 | egress_redirect_to_cpu; 25 | } 26 | size : EGRESS_SYSTEM_ACL_TABLE_SIZE; 27 | } 28 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/egress_vlan_xlate.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_egress_packet_vlan_tagged(vlan_id) { 16 | add_header(vlan_tag_[0]); 17 | modify_field(vlan_tag_[0].vid, vlan_id); 18 | } 19 | 20 | action set_egress_packet_vlan_untagged() { 21 | remove_header(vlan_tag_[0]); 22 | } 23 | 24 | table egress_vlan_xlate { 25 | reads { 26 | standard_metadata.egress_port : exact; 27 | egress_metadata.bd : exact; 28 | } 29 | actions { 30 | nop; 31 | set_egress_packet_vlan_tagged; 32 | set_egress_packet_vlan_untagged; 33 | } 34 | size : EGRESS_VLAN_XLATE_TABLE_SIZE; 35 | } 36 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/outer_mac.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action rewrite_unicast_mac(smac) { 16 | modify_field(ethernet.srcAddr, smac); 17 | modify_field(ethernet.dstAddr, egress_metadata.mac_da); 18 | } 19 | 20 | action rewrite_multicast_mac(smac) { 21 | modify_field(ethernet.srcAddr, smac); 22 | modify_field(ethernet.dstAddr, 0x01005E000000); 23 | modify_field(ethernet.dstAddr, ipv4.dstAddr, 0x7FFFFF); 24 | add_to_field(ipv4.ttl, -1); 25 | } 26 | 27 | table outer_mac { 28 | reads { 29 | egress_metadata.smac_idx : exact; 30 | ipv4.dstAddr : ternary; 31 | } 32 | actions { 33 | nop; 34 | rewrite_unicast_mac; 35 | rewrite_multicast_mac; 36 | } 37 | size : SOURCE_MAC_TABLE_SIZE; 38 | } 39 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/rewrite.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_l2_rewrite() { 16 | modify_field(egress_metadata.routed, FALSE); 17 | } 18 | 19 | action set_ipv4_unicast_rewrite(smac_idx, dmac) { 20 | modify_field(egress_metadata.smac_idx, smac_idx); 21 | modify_field(egress_metadata.mac_da, dmac); 22 | modify_field(egress_metadata.routed, TRUE); 23 | modify_field(ipv4.ttl, ingress_metadata.ttl); 24 | } 25 | 26 | action set_ipv4_vxlan_rewrite(outer_bd, tunnel_src_index, tunnel_dst_index, 27 | smac_idx, dmac) { 28 | modify_field(egress_metadata.bd, outer_bd); 29 | modify_field(egress_metadata.smac_idx, smac_idx); 30 | modify_field(egress_metadata.mac_da, dmac); 31 | modify_field(egress_metadata.tunnel_src_index, tunnel_src_index); 32 | modify_field(egress_metadata.tunnel_dst_index, tunnel_dst_index); 33 | modify_field(egress_metadata.routed, TRUE); 34 | modify_field(egress_metadata.tunnel_type, EGRESS_TUNNEL_TYPE_IPV4_VXLAN); 35 | } 36 | 37 | action set_ipv4_geneve_rewrite(outer_bd, tunnel_src_index, tunnel_dst_index, 38 | smac_idx, dmac) { 39 | modify_field(egress_metadata.bd, outer_bd); 40 | modify_field(egress_metadata.smac_idx, smac_idx); 41 | modify_field(egress_metadata.mac_da, dmac); 42 | modify_field(egress_metadata.tunnel_src_index, tunnel_src_index); 43 | modify_field(egress_metadata.tunnel_dst_index, tunnel_dst_index); 44 | modify_field(egress_metadata.routed, TRUE); 45 | modify_field(egress_metadata.tunnel_type, EGRESS_TUNNEL_TYPE_IPV4_GENEVE); 46 | } 47 | 48 | action set_ipv4_nvgre_rewrite(outer_bd, tunnel_src_index, tunnel_dst_index, 49 | smac_idx, dmac) { 50 | modify_field(egress_metadata.bd, outer_bd); 51 | modify_field(egress_metadata.smac_idx, smac_idx); 52 | modify_field(egress_metadata.mac_da, dmac); 53 | modify_field(egress_metadata.tunnel_src_index, tunnel_src_index); 54 | modify_field(egress_metadata.tunnel_dst_index, tunnel_dst_index); 55 | modify_field(egress_metadata.routed, TRUE); 56 | modify_field(egress_metadata.tunnel_type, EGRESS_TUNNEL_TYPE_IPV4_NVGRE); 57 | } 58 | 59 | action set_ipv4_erspan_v2_rewrite(outer_bd, tunnel_src_index, tunnel_dst_index, 60 | smac_idx, dmac) { 61 | modify_field(egress_metadata.bd, outer_bd); 62 | modify_field(egress_metadata.smac_idx, smac_idx); 63 | modify_field(egress_metadata.mac_da, dmac); 64 | modify_field(egress_metadata.tunnel_src_index, tunnel_src_index); 65 | modify_field(egress_metadata.tunnel_dst_index, tunnel_dst_index); 66 | modify_field(egress_metadata.routed, TRUE); 67 | modify_field(egress_metadata.tunnel_type, EGRESS_TUNNEL_TYPE_IPV4_ERSPANV2); 68 | } 69 | 70 | table rewrite { 71 | reads { 72 | ingress_metadata.nexthop_index : exact; 73 | } 74 | actions { 75 | nop; 76 | set_l2_rewrite; 77 | set_ipv4_unicast_rewrite; 78 | set_ipv4_vxlan_rewrite; 79 | set_ipv4_geneve_rewrite; 80 | set_ipv4_nvgre_rewrite; 81 | set_ipv4_erspan_v2_rewrite; 82 | } 83 | size : NEXTHOP_TABLE_SIZE; 84 | } 85 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/rid.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MULTICAST_DISABLE 16 | action replica_from_rid(bd) { 17 | modify_field(ingress_metadata.egress_bd, bd); 18 | modify_field(egress_metadata.replica, TRUE); 19 | } 20 | 21 | table rid { 22 | reads { 23 | intrinsic_metadata.replication_id : exact; 24 | } 25 | actions { 26 | nop; 27 | replica_from_rid; 28 | } 29 | size : RID_TABLE_SIZE; 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/tunnel_decap.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action decapsulate_vxlan_packet_inner_ipv4_udp() { 16 | copy_header(ethernet, inner_ethernet); 17 | add_header(ipv4); 18 | copy_header(ipv4, inner_ipv4); 19 | copy_header(udp, inner_udp); 20 | remove_header(inner_ethernet); 21 | remove_header(inner_ipv4); 22 | remove_header(inner_udp); 23 | remove_header(vxlan); 24 | modify_field(ingress_metadata.ttl, ingress_metadata.outer_ttl); 25 | } 26 | 27 | action decapsulate_vxlan_packet_inner_ipv4_tcp() { 28 | copy_header(ethernet, inner_ethernet); 29 | add_header(ipv4); 30 | copy_header(ipv4, inner_ipv4); 31 | add_header(tcp); 32 | copy_header(tcp, inner_tcp); 33 | remove_header(inner_ethernet); 34 | remove_header(inner_ipv4); 35 | remove_header(inner_tcp); 36 | remove_header(udp); 37 | remove_header(vxlan); 38 | modify_field(ingress_metadata.ttl, ingress_metadata.outer_ttl); 39 | } 40 | 41 | action decapsulate_geneve_packet_inner_ipv4_udp() { 42 | copy_header(ethernet, inner_ethernet); 43 | add_header(ipv4); 44 | copy_header(ipv4, inner_ipv4); 45 | copy_header(udp, inner_udp); 46 | remove_header(inner_ethernet); 47 | remove_header(inner_ipv4); 48 | remove_header(inner_udp); 49 | remove_header(genv); 50 | modify_field(ingress_metadata.ttl, ingress_metadata.outer_ttl); 51 | } 52 | 53 | action decapsulate_geneve_packet_inner_ipv4_tcp() { 54 | copy_header(ethernet, inner_ethernet); 55 | add_header(ipv4); 56 | copy_header(ipv4, inner_ipv4); 57 | add_header(tcp); 58 | copy_header(tcp, inner_tcp); 59 | remove_header(inner_ethernet); 60 | remove_header(inner_ipv4); 61 | remove_header(inner_tcp); 62 | remove_header(udp); 63 | remove_header(genv); 64 | modify_field(ingress_metadata.ttl, ingress_metadata.outer_ttl); 65 | } 66 | 67 | action decapsulate_nvgre_packet_inner_ipv4_udp() { 68 | copy_header(ethernet, inner_ethernet); 69 | add_header(ipv4); 70 | copy_header(ipv4, inner_ipv4); 71 | copy_header(udp, inner_udp); 72 | remove_header(inner_ethernet); 73 | remove_header(inner_ipv4); 74 | remove_header(inner_udp); 75 | remove_header(nvgre); 76 | remove_header(gre); 77 | modify_field(ingress_metadata.ttl, ingress_metadata.outer_ttl); 78 | } 79 | 80 | action decapsulate_nvgre_packet_inner_ipv4_tcp() { 81 | copy_header(ethernet, inner_ethernet); 82 | add_header(ipv4); 83 | copy_header(ipv4, inner_ipv4); 84 | add_header(tcp); 85 | copy_header(tcp, inner_tcp); 86 | remove_header(inner_ethernet); 87 | remove_header(inner_ipv4); 88 | remove_header(inner_tcp); 89 | remove_header(nvgre); 90 | remove_header(gre); 91 | modify_field(ingress_metadata.ttl, ingress_metadata.outer_ttl); 92 | } 93 | 94 | table tunnel_decap { 95 | reads { 96 | ingress_metadata.tunnel_type : exact; 97 | inner_ipv4 : valid; 98 | inner_tcp : valid; 99 | inner_udp : valid; 100 | } 101 | actions { 102 | decapsulate_vxlan_packet_inner_ipv4_udp; 103 | decapsulate_vxlan_packet_inner_ipv4_tcp; 104 | decapsulate_geneve_packet_inner_ipv4_udp; 105 | decapsulate_geneve_packet_inner_ipv4_tcp; 106 | decapsulate_nvgre_packet_inner_ipv4_udp; 107 | decapsulate_nvgre_packet_inner_ipv4_tcp; 108 | } 109 | size : TUNNEL_DECAP_TABLE_SIZE; 110 | } 111 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/tunnel_dst_rewrite.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action rewrite_tunnel_ipv4_dst(ip) { 16 | modify_field(ipv4.dstAddr, ip); 17 | } 18 | 19 | table tunnel_dst_rewrite { 20 | reads { 21 | egress_metadata.tunnel_dst_index : exact; 22 | } 23 | actions { 24 | rewrite_tunnel_ipv4_dst; 25 | } 26 | size : SRC_TUNNEL_TABLE_SIZE; 27 | } 28 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/tunnel_rewrite.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | field_list entropy_hash_fields { 16 | inner_ethernet.srcAddr; 17 | inner_ethernet.dstAddr; 18 | inner_ethernet.etherType; 19 | inner_ipv4.srcAddr; 20 | inner_ipv4.dstAddr; 21 | inner_ipv4.protocol; 22 | } 23 | 24 | field_list_calculation entropy_hash { 25 | input { 26 | entropy_hash_fields; 27 | } 28 | algorithm : crc16; 29 | output_width : 16; 30 | } 31 | 32 | action f_copy_ipv4_to_inner() { 33 | add_header(inner_ethernet); 34 | copy_header(inner_ethernet, ethernet); 35 | add_header(inner_ipv4); 36 | copy_header(inner_ipv4, ipv4); 37 | modify_field(inner_ipv4.ttl, ingress_metadata.ttl); 38 | remove_header(ipv4); 39 | } 40 | 41 | action f_copy_ipv4_udp_to_inner() { 42 | f_copy_ipv4_to_inner(); 43 | add_header(inner_udp); 44 | copy_header(inner_udp, udp); 45 | remove_header(udp); 46 | } 47 | 48 | action f_copy_ipv4_tcp_to_inner() { 49 | f_copy_ipv4_to_inner(); 50 | add_header(inner_tcp); 51 | copy_header(inner_tcp, tcp); 52 | remove_header(tcp); 53 | } 54 | 55 | action f_insert_vxlan_header() { 56 | add_header(udp); 57 | add_header(vxlan); 58 | 59 | modify_field_with_hash_based_offset(udp.srcPort, 0, entropy_hash, 16384); 60 | modify_field(udp.dstPort, UDP_PORT_VXLAN); 61 | modify_field(udp.checksum, 0); 62 | modify_field(udp.length_, ingress_metadata.l3_length); 63 | add_to_field(udp.length_, 30); // 8+8+14 64 | 65 | modify_field(vxlan.flags, 0x8); 66 | modify_field(vxlan.vni, egress_metadata.vnid); 67 | } 68 | 69 | action f_insert_ipv4_header(proto) { 70 | add_header(ipv4); 71 | modify_field(ipv4.protocol, proto); 72 | modify_field(ipv4.ttl, ingress_metadata.ttl); 73 | modify_field(ipv4.version, 0x4); 74 | modify_field(ipv4.ihl, 0x5); 75 | } 76 | 77 | action ipv4_vxlan_inner_ipv4_udp_rewrite() { 78 | f_copy_ipv4_udp_to_inner(); 79 | f_insert_vxlan_header(); 80 | f_insert_ipv4_header(IP_PROTOCOLS_UDP); 81 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 82 | add_to_field(ipv4.totalLen, 50); 83 | } 84 | 85 | action ipv4_vxlan_inner_ipv4_tcp_rewrite() { 86 | f_copy_ipv4_tcp_to_inner(); 87 | f_insert_vxlan_header(); 88 | f_insert_ipv4_header(IP_PROTOCOLS_UDP); 89 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 90 | add_to_field(ipv4.totalLen, 50); 91 | } 92 | 93 | action f_insert_genv_header() { 94 | add_header(udp); 95 | add_header(genv); 96 | 97 | modify_field_with_hash_based_offset(udp.srcPort, 0, entropy_hash, 16384); 98 | modify_field(udp.dstPort, UDP_PORT_GENV); 99 | modify_field(udp.checksum, 0); 100 | modify_field(udp.length_, ingress_metadata.l3_length); 101 | add_to_field(udp.length_, 30); // 8+8+14 102 | 103 | modify_field(genv.ver, 0); 104 | modify_field(genv.oam, 0); 105 | modify_field(genv.critical, 0); 106 | modify_field(genv.optLen, 0); 107 | modify_field(genv.protoType, 0x6558); 108 | modify_field(genv.vni, egress_metadata.vnid); 109 | } 110 | 111 | action ipv4_genv_inner_ipv4_udp_rewrite() { 112 | f_copy_ipv4_udp_to_inner(); 113 | f_insert_genv_header(); 114 | f_insert_ipv4_header(IP_PROTOCOLS_UDP); 115 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 116 | add_to_field(ipv4.totalLen, 50); 117 | } 118 | 119 | action ipv4_genv_inner_ipv4_tcp_rewrite() { 120 | f_copy_ipv4_tcp_to_inner(); 121 | f_insert_genv_header(); 122 | f_insert_ipv4_header(IP_PROTOCOLS_UDP); 123 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 124 | add_to_field(ipv4.totalLen, 50); 125 | } 126 | 127 | action f_insert_nvgre_header() { 128 | add_header(gre); 129 | add_header(nvgre); 130 | modify_field(gre.proto, 0x6558); 131 | modify_field(gre.K, 1); 132 | modify_field(gre.C, 0); 133 | modify_field(gre.S, 0); 134 | modify_field(nvgre.tni, egress_metadata.vnid); 135 | } 136 | 137 | action ipv4_nvgre_inner_ipv4_udp_rewrite() { 138 | f_copy_ipv4_udp_to_inner(); 139 | f_insert_nvgre_header(); 140 | f_insert_ipv4_header(IP_PROTOCOLS_GRE); 141 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 142 | add_to_field(ipv4.totalLen, 42); 143 | } 144 | 145 | action ipv4_nvgre_inner_ipv4_tcp_rewrite() { 146 | f_copy_ipv4_tcp_to_inner(); 147 | f_insert_nvgre_header(); 148 | f_insert_ipv4_header(IP_PROTOCOLS_GRE); 149 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 150 | add_to_field(ipv4.totalLen, 42); 151 | } 152 | 153 | action f_insert_erspan_v2_header() { 154 | add_header(gre); 155 | add_header(erspan_v2_header); 156 | modify_field(gre.proto, GRE_PROTOCOLS_ERSPAN_V2); 157 | modify_field(erspan_v2_header.version, 1); 158 | modify_field(erspan_v2_header.vlan, egress_metadata.vnid); 159 | } 160 | 161 | action ipv4_erspan_v2_inner_ipv4_udp_rewrite() { 162 | f_copy_ipv4_udp_to_inner(); 163 | f_insert_erspan_v2_header(); 164 | f_insert_ipv4_header(IP_PROTOCOLS_GRE); 165 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 166 | add_to_field(ipv4.totalLen, 46); 167 | } 168 | 169 | action ipv4_erspan_v2_inner_ipv4_tcp_rewrite() { 170 | f_copy_ipv4_tcp_to_inner(); 171 | f_insert_erspan_v2_header(); 172 | f_insert_ipv4_header(IP_PROTOCOLS_GRE); 173 | modify_field(ipv4.totalLen, ingress_metadata.l3_length); 174 | add_to_field(ipv4.totalLen, 46); 175 | } 176 | 177 | 178 | table tunnel_rewrite { 179 | reads { 180 | egress_metadata.tunnel_type : exact; 181 | ipv4 : valid; 182 | tcp : valid; 183 | udp : valid; 184 | } 185 | actions { 186 | /* 187 | * These actions encapsulate a packet. 188 | * Sequence of modifications in each action is: 189 | * 1. Add inner L3/L4 header. The type of these headers should be same as that 190 | * of the packet being encapsulated. 191 | * 2. Copy outer L3/L4 headers to inner L3/L4 headers. 192 | * 3. Remove outer L3/L4 headers. 193 | * 4. Add outer L3 header and encapsulation header. 194 | * For each encapsulation type, we need 8 actions to handle 8 different 195 | * combinations: 196 | * Outer L3 (IPv4) X Inner L3 (IPv4) X Inner L4 (TCP/UDP) 197 | */ 198 | ipv4_vxlan_inner_ipv4_udp_rewrite; 199 | ipv4_vxlan_inner_ipv4_tcp_rewrite; 200 | ipv4_genv_inner_ipv4_udp_rewrite; 201 | ipv4_genv_inner_ipv4_tcp_rewrite; 202 | ipv4_nvgre_inner_ipv4_udp_rewrite; 203 | ipv4_nvgre_inner_ipv4_tcp_rewrite; 204 | ipv4_erspan_v2_inner_ipv4_udp_rewrite; 205 | ipv4_erspan_v2_inner_ipv4_tcp_rewrite; 206 | } 207 | size : TUNNEL_REWRITE_TABLE_SIZE; 208 | } 209 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress/tunnel_src_rewrite.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action rewrite_tunnel_ipv4_src(ip) { 16 | modify_field(ipv4.srcAddr, ip); 17 | } 18 | 19 | table tunnel_src_rewrite { 20 | reads { 21 | egress_metadata.tunnel_src_index : exact; 22 | } 23 | actions { 24 | rewrite_tunnel_ipv4_src; 25 | } 26 | size : DEST_TUNNEL_TABLE_SIZE; 27 | } 28 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/egress_tables.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* RID table, RID: Replication ID */ 16 | #include "egress/rid.p4" 17 | 18 | /* Tunnel decap table */ 19 | #include "egress/tunnel_decap.p4" 20 | 21 | /* egress_bd_map table */ 22 | #include "egress/egress_bd_map.p4" 23 | 24 | /* rewrite table */ 25 | #include "egress/rewrite.p4" 26 | 27 | /* tunnel_rewrite table */ 28 | #include "egress/tunnel_rewrite.p4" 29 | 30 | /* tunnel_src_rewrite table */ 31 | #include "egress/tunnel_src_rewrite.p4" 32 | 33 | /* tunnel_dst_rewrite table */ 34 | #include "egress/tunnel_dst_rewrite.p4" 35 | 36 | /* outer_mac table */ 37 | #include "egress/outer_mac.p4" 38 | 39 | /* egress_block table */ 40 | #include "egress/egress_block.p4" 41 | 42 | /* egress_vlan_xlate table */ 43 | #include "egress/egress_vlan_xlate.p4" 44 | 45 | /* egress_system_acl table */ 46 | #include "egress/egress_system_acl.p4" 47 | 48 | /* cpu_rewrite table */ 49 | #include "egress/cpu_rewrite.p4" 50 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/bd.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_bd_info(vrf, rmac_group, 16 | bd_label, uuc_mc_index, bcast_mc_index, umc_mc_index, 17 | ipv4_unicast_enabled, 18 | igmp_snooping_enabled, stp_group) { 19 | modify_field(ingress_metadata.vrf, vrf); 20 | modify_field(ingress_metadata.ipv4_unicast_enabled, ipv4_unicast_enabled); 21 | modify_field(ingress_metadata.igmp_snooping_enabled, igmp_snooping_enabled); 22 | modify_field(ingress_metadata.rmac_group, rmac_group); 23 | modify_field(ingress_metadata.uuc_mc_index, uuc_mc_index); 24 | modify_field(ingress_metadata.umc_mc_index, umc_mc_index); 25 | modify_field(ingress_metadata.bcast_mc_index, bcast_mc_index); 26 | modify_field(ingress_metadata.bd_label, bd_label); 27 | modify_field(ingress_metadata.stp_group, stp_group); 28 | } 29 | 30 | /* 31 | * extract all the bridge domain parameters for non-tunneled 32 | * packets 33 | */ 34 | table bd { 35 | reads { 36 | ingress_metadata.bd : exact; 37 | } 38 | actions { 39 | set_bd_info; 40 | } 41 | size : BD_TABLE_SIZE; 42 | } 43 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/dmac.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action dmac_hit(ifindex) { 16 | modify_field(ingress_metadata.egress_ifindex, ifindex); 17 | modify_field(ingress_metadata.egress_bd, ingress_metadata.bd); 18 | } 19 | 20 | action dmac_multicast_hit(mc_index) { 21 | modify_field(intrinsic_metadata.eg_mcast_group, mc_index); 22 | modify_field(ingress_metadata.egress_bd, ingress_metadata.bd); 23 | } 24 | 25 | action dmac_miss() { 26 | modify_field(intrinsic_metadata.eg_mcast_group, ingress_metadata.uuc_mc_index); 27 | } 28 | 29 | action dmac_redirect_nexthop(nexthop_index) { 30 | modify_field(ingress_metadata.l2_redirect, TRUE); 31 | modify_field(ingress_metadata.l2_nexthop, nexthop_index); 32 | } 33 | 34 | action dmac_redirect_ecmp(ecmp_index) { 35 | modify_field(ingress_metadata.l2_redirect, TRUE); 36 | modify_field(ingress_metadata.l2_ecmp, ecmp_index); 37 | } 38 | 39 | table dmac { 40 | reads { 41 | ingress_metadata.bd : exact; 42 | ingress_metadata.lkp_mac_da : exact; 43 | } 44 | actions { 45 | nop; 46 | dmac_hit; 47 | dmac_multicast_hit; 48 | dmac_miss; 49 | dmac_redirect_nexthop; 50 | dmac_redirect_ecmp; 51 | } 52 | size : DMAC_TABLE_SIZE; 53 | support_timeout: true; 54 | } 55 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/ecmp_group.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | field_list l3_hash_fields { 16 | ingress_metadata.lkp_ipv4_sa; 17 | ingress_metadata.lkp_ipv4_da; 18 | ingress_metadata.lkp_ip_proto; 19 | ingress_metadata.lkp_l4_sport; 20 | ingress_metadata.lkp_l4_dport; 21 | } 22 | 23 | field_list_calculation ecmp_hash { 24 | input { 25 | l3_hash_fields; 26 | } 27 | algorithm : crc16; 28 | output_width : ECMP_BIT_WIDTH; 29 | } 30 | 31 | action set_ecmp_nexthop_details(ifindex, bd, nhop_index) { 32 | modify_field(ingress_metadata.egress_ifindex, ifindex); 33 | modify_field(ingress_metadata.egress_bd, bd); 34 | modify_field(ingress_metadata.nexthop_index, nhop_index); 35 | } 36 | 37 | action set_ecmp_nexthop_details_for_post_routed_flood(bd, uuc_mc_index, nhop_index) { 38 | modify_field(intrinsic_metadata.eg_mcast_group, uuc_mc_index); 39 | modify_field(ingress_metadata.egress_bd, bd); 40 | modify_field(ingress_metadata.nexthop_index, nhop_index); 41 | } 42 | 43 | action_selector ecmp_selector { 44 | selection_key : ecmp_hash; 45 | } 46 | 47 | action_profile ecmp_action_profile { 48 | actions { 49 | nop; 50 | set_ecmp_nexthop_details; 51 | set_ecmp_nexthop_details_for_post_routed_flood; 52 | } 53 | size : ECMP_SELECT_TABLE_SIZE; 54 | dynamic_action_selection : ecmp_selector; 55 | } 56 | 57 | table ecmp_group { 58 | reads { 59 | ingress_metadata.ecmp_index : exact; 60 | } 61 | action_profile: ecmp_action_profile; 62 | size : ECMP_GROUP_TABLE_SIZE; 63 | } 64 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/fwd_result.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_l2_redirect_action() { 16 | modify_field(ingress_metadata.nexthop_index, ingress_metadata.l2_nexthop); 17 | modify_field(ingress_metadata.ecmp_index, ingress_metadata.l2_ecmp); 18 | modify_field(ingress_metadata.ttl, ingress_metadata.lkp_ip_ttl); 19 | } 20 | 21 | action set_acl_redirect_action() { 22 | modify_field(ingress_metadata.nexthop_index, ingress_metadata.acl_nexthop); 23 | modify_field(ingress_metadata.ecmp_index, ingress_metadata.acl_ecmp); 24 | } 25 | 26 | action set_racl_redirect_action() { 27 | modify_field(ingress_metadata.nexthop_index, ingress_metadata.racl_nexthop); 28 | modify_field(ingress_metadata.ecmp_index, ingress_metadata.racl_ecmp); 29 | modify_field(ingress_metadata.routed, TRUE); 30 | modify_field(ingress_metadata.ttl, ingress_metadata.lkp_ip_ttl); 31 | add_to_field(ingress_metadata.ttl, -1); 32 | } 33 | 34 | action set_fib_redirect_action() { 35 | modify_field(ingress_metadata.nexthop_index, ingress_metadata.fib_nexthop); 36 | modify_field(ingress_metadata.ecmp_index, ingress_metadata.fib_ecmp); 37 | modify_field(ingress_metadata.routed, TRUE); 38 | modify_field(ingress_metadata.ttl, ingress_metadata.lkp_ip_ttl); 39 | add_to_field(ingress_metadata.ttl, -1); 40 | } 41 | 42 | table fwd_result { 43 | reads { 44 | ingress_metadata.l2_redirect : ternary; 45 | ingress_metadata.acl_redirect : ternary; 46 | ingress_metadata.racl_redirect : ternary; 47 | ingress_metadata.fib_hit : ternary; 48 | } 49 | actions { 50 | nop; 51 | set_l2_redirect_action; 52 | set_acl_redirect_action; 53 | set_racl_redirect_action; 54 | set_fib_redirect_action; 55 | } 56 | size : FWD_RESULT_TABLE_SIZE; 57 | } 58 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/ip_fib.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action fib_hit_nexthop(nexthop_index) { 16 | modify_field(ingress_metadata.fib_hit, TRUE); 17 | modify_field(ingress_metadata.fib_nexthop, nexthop_index); 18 | } 19 | 20 | action fib_hit_ecmp(ecmp_index) { 21 | modify_field(ingress_metadata.fib_hit, TRUE); 22 | modify_field(ingress_metadata.fib_ecmp, ecmp_index); 23 | } 24 | 25 | table ipv4_fib_lpm { 26 | reads { 27 | ingress_metadata.vrf : exact; 28 | ingress_metadata.lkp_ipv4_da : lpm; 29 | } 30 | actions { 31 | fib_hit_nexthop; 32 | fib_hit_ecmp; 33 | } 34 | size : IPV4_LPM_TABLE_SIZE; 35 | } 36 | 37 | table ipv4_fib { 38 | reads { 39 | ingress_metadata.vrf : exact; 40 | ingress_metadata.lkp_ipv4_da : exact; 41 | } 42 | actions { 43 | on_miss; 44 | fib_hit_nexthop; 45 | fib_hit_ecmp; 46 | } 47 | size : IPV4_HOST_TABLE_SIZE; 48 | } 49 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/ip_racl.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action racl_log() { 16 | } 17 | 18 | action racl_deny() { 19 | modify_field(ingress_metadata.racl_deny, TRUE); 20 | } 21 | 22 | action racl_permit() { 23 | } 24 | 25 | action racl_redirect_nexthop(nexthop_index) { 26 | modify_field(ingress_metadata.racl_redirect, TRUE); 27 | modify_field(ingress_metadata.racl_nexthop, nexthop_index); 28 | } 29 | 30 | action racl_redirect_ecmp(ecmp_index) { 31 | modify_field(ingress_metadata.racl_redirect, TRUE); 32 | modify_field(ingress_metadata.racl_ecmp, ecmp_index); 33 | } 34 | 35 | table ip_racl { 36 | reads { 37 | ingress_metadata.bd_label : ternary; 38 | 39 | ingress_metadata.lkp_ipv4_sa : ternary; 40 | ingress_metadata.lkp_ipv4_da : ternary; 41 | ingress_metadata.lkp_ip_proto : ternary; 42 | ingress_metadata.lkp_l4_sport : ternary; 43 | ingress_metadata.lkp_l4_dport : ternary; 44 | } 45 | actions { 46 | nop; 47 | racl_log; 48 | racl_deny; 49 | racl_permit; 50 | racl_redirect_nexthop; 51 | racl_redirect_ecmp; 52 | } 53 | size : INGRESS_IP_RACL_TABLE_SIZE; 54 | } 55 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/ipv4_dest_vtep.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_tunnel_termination_flag() { 16 | modify_field(ingress_metadata.tunnel_terminate, TRUE); 17 | } 18 | 19 | table ipv4_dest_vtep { 20 | reads { 21 | ingress_metadata.vrf : exact; 22 | ingress_metadata.lkp_ipv4_da : exact; 23 | ingress_metadata.lkp_ip_proto : exact; 24 | ingress_metadata.lkp_l4_dport : exact; 25 | } 26 | actions { 27 | nop; 28 | set_tunnel_termination_flag; 29 | } 30 | size : DEST_TUNNEL_TABLE_SIZE; 31 | } 32 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/ipv4_src_vtep.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_src_vtep_miss_flag() { 16 | modify_field(ingress_metadata.src_vtep_miss, TRUE); 17 | } 18 | 19 | action set_tunnel_lif(lif) { 20 | modify_field(ingress_metadata.tunnel_lif, lif); 21 | } 22 | 23 | table ipv4_src_vtep { 24 | reads { 25 | ingress_metadata.vrf : exact; 26 | ingress_metadata.lkp_ipv4_sa : exact; 27 | } 28 | actions { 29 | nop; 30 | set_tunnel_lif; 31 | set_src_vtep_miss_flag; 32 | } 33 | size : SRC_TUNNEL_TABLE_SIZE; 34 | } 35 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/lag_group.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | field_list lag_hash_fields { 16 | ingress_metadata.lkp_mac_sa; 17 | ingress_metadata.lkp_mac_da; 18 | ingress_metadata.lkp_mac_type; 19 | ingress_metadata.lkp_ipv4_sa; 20 | ingress_metadata.lkp_ipv4_da; 21 | ingress_metadata.lkp_ip_proto; 22 | ingress_metadata.lkp_l4_sport; 23 | ingress_metadata.lkp_l4_dport; 24 | } 25 | 26 | field_list_calculation lag_hash { 27 | input { 28 | lag_hash_fields; 29 | } 30 | algorithm : crc16; 31 | output_width : LAG_BIT_WIDTH; 32 | } 33 | 34 | action_selector lag_selector { 35 | selection_key : lag_hash; 36 | } 37 | 38 | action set_lag_port(port) { 39 | modify_field(standard_metadata.egress_spec, port); 40 | } 41 | 42 | action_profile lag_action_profile { 43 | actions { 44 | nop; 45 | set_lag_port; 46 | } 47 | size : LAG_GROUP_TABLE_SIZE; 48 | dynamic_action_selection : lag_selector; 49 | } 50 | 51 | table lag_group { 52 | reads { 53 | ingress_metadata.egress_ifindex : exact; 54 | } 55 | action_profile: lag_action_profile; 56 | size : LAG_SELECT_TABLE_SIZE; 57 | } 58 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/learn_notify.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | field_list mac_learn_digest { 16 | ingress_metadata.bd; 17 | ingress_metadata.lkp_mac_sa; 18 | ingress_metadata.ifindex; 19 | } 20 | 21 | action generate_learn_notify() { 22 | generate_digest(MAC_LEARN_RECIEVER, mac_learn_digest); 23 | } 24 | 25 | table learn_notify { 26 | reads { 27 | ingress_metadata.l2_src_miss : ternary; 28 | ingress_metadata.l2_src_move : ternary; 29 | ingress_metadata.stp_state : ternary; 30 | } 31 | actions { 32 | nop; 33 | generate_learn_notify; 34 | } 35 | size : LEARN_NOTIFY_TABLE_SIZE; 36 | } 37 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/mac_ip_acl.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action acl_log() { 16 | } 17 | 18 | action acl_deny() { 19 | modify_field(ingress_metadata.acl_deny, TRUE); 20 | } 21 | 22 | action acl_permit() { 23 | } 24 | 25 | action acl_redirect_nexthop(nexthop_index) { 26 | modify_field(ingress_metadata.acl_redirect, TRUE); 27 | modify_field(ingress_metadata.acl_nexthop, nexthop_index); 28 | } 29 | 30 | action acl_redirect_ecmp(ecmp_index) { 31 | modify_field(ingress_metadata.acl_redirect, TRUE); 32 | modify_field(ingress_metadata.acl_ecmp, ecmp_index); 33 | } 34 | 35 | table mac_acl { 36 | reads { 37 | ingress_metadata.if_label : ternary; 38 | ingress_metadata.bd_label : ternary; 39 | 40 | ingress_metadata.lkp_mac_sa : ternary; 41 | ingress_metadata.lkp_mac_da : ternary; 42 | ingress_metadata.lkp_mac_type : ternary; 43 | } 44 | actions { 45 | nop; 46 | acl_log; 47 | acl_deny; 48 | acl_permit; 49 | } 50 | size : INGRESS_MAC_ACL_TABLE_SIZE; 51 | } 52 | 53 | counter ip_acl_counters { 54 | type : packets; 55 | direct : ip_acl; 56 | } 57 | 58 | table ip_acl { 59 | reads { 60 | ingress_metadata.if_label : ternary; 61 | ingress_metadata.bd_label : ternary; 62 | 63 | ingress_metadata.lkp_ipv4_sa : ternary; 64 | ingress_metadata.lkp_ipv4_da : ternary; 65 | ingress_metadata.lkp_ip_proto : ternary; 66 | ingress_metadata.lkp_l4_sport : ternary; 67 | ingress_metadata.lkp_l4_dport : ternary; 68 | 69 | ingress_metadata.lkp_mac_type : ternary; 70 | ingress_metadata.msg_type : ternary; /* ICMP code */ 71 | tcp : valid; 72 | tcp.flags : ternary; 73 | ingress_metadata.ttl : ternary; 74 | } 75 | actions { 76 | nop; 77 | acl_log; 78 | acl_deny; 79 | acl_permit; 80 | acl_redirect_nexthop; 81 | acl_redirect_ecmp; 82 | } 83 | size : INGRESS_IP_ACL_TABLE_SIZE; 84 | } 85 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/mirror_acl.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_mirror_id(session_id) { 16 | clone_ingress_pkt_to_egress(session_id); 17 | } 18 | 19 | table mirror_acl { 20 | reads { 21 | ingress_metadata.if_label : ternary; 22 | ingress_metadata.bd_label : ternary; 23 | 24 | /* ip acl */ 25 | ingress_metadata.lkp_ipv4_sa : ternary; 26 | ingress_metadata.lkp_ipv4_da : ternary; 27 | ingress_metadata.lkp_ip_proto : ternary; 28 | 29 | /* mac acl */ 30 | ingress_metadata.lkp_mac_sa : ternary; 31 | ingress_metadata.lkp_mac_da : ternary; 32 | ingress_metadata.lkp_mac_type : ternary; 33 | } 34 | actions { 35 | nop; 36 | set_mirror_id; 37 | } 38 | size : INGRESS_MIRROR_ACL_TABLE_SIZE; 39 | } 40 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/next_hop.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_nexthop_details(ifindex, bd) { 16 | modify_field(ingress_metadata.egress_ifindex, ifindex); 17 | modify_field(ingress_metadata.egress_bd, bd); 18 | } 19 | 20 | /* 21 | * If dest mac is not known, then unicast packet needs to be flooded in 22 | * egress BD 23 | */ 24 | action set_nexthop_details_for_post_routed_flood(bd, uuc_mc_index) { 25 | modify_field(intrinsic_metadata.eg_mcast_group, uuc_mc_index); 26 | modify_field(ingress_metadata.egress_bd, bd); 27 | } 28 | 29 | table nexthop { 30 | reads { 31 | ingress_metadata.nexthop_index : exact; 32 | } 33 | actions { 34 | nop; 35 | set_nexthop_details; 36 | set_nexthop_details_for_post_routed_flood; 37 | } 38 | size : NEXTHOP_TABLE_SIZE; 39 | } 40 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/outer_rmac.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_outer_rmac_hit_flag() { 16 | modify_field(ingress_metadata.outer_rmac_hit, TRUE); 17 | } 18 | 19 | table outer_rmac { 20 | reads { 21 | ingress_metadata.outer_rmac_group : exact; 22 | ingress_metadata.lkp_mac_da : exact; 23 | } 24 | actions { 25 | nop; 26 | set_outer_rmac_hit_flag; 27 | } 28 | size : OUTER_ROUTER_MAC_TABLE_SIZE; 29 | } 30 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/port_mapping.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_ifindex(ifindex, if_label) { 16 | modify_field(ingress_metadata.ifindex, ifindex); 17 | modify_field(ingress_metadata.if_label, if_label); 18 | } 19 | 20 | table port_mapping { 21 | reads { 22 | standard_metadata.ingress_port : exact; 23 | } 24 | actions { 25 | set_ifindex; 26 | } 27 | size : PORTMAP_TABLE_SIZE; 28 | } 29 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/port_vlan_mapping.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_bd(outer_vlan_bd, vrf, rmac_group, 16 | ipv4_unicast_enabled, 17 | stp_group) { 18 | modify_field(ingress_metadata.vrf, vrf); 19 | modify_field(ingress_metadata.ipv4_unicast_enabled, ipv4_unicast_enabled); 20 | modify_field(ingress_metadata.outer_rmac_group, rmac_group); 21 | modify_field(ingress_metadata.bd, outer_vlan_bd); 22 | modify_field(ingress_metadata.stp_group, stp_group); 23 | } 24 | 25 | /* 26 | * outer_bd is used to extract the tunnel termination 27 | * actions 28 | */ 29 | action_profile outer_bd_action_profile { 30 | actions { 31 | set_bd; 32 | } 33 | size : OUTER_BD_TABLE_SIZE; 34 | } 35 | 36 | table port_vlan_mapping { 37 | reads { 38 | ingress_metadata.ifindex : exact; 39 | vlan_tag_[0] : valid; 40 | vlan_tag_[0].vid : exact; 41 | vlan_tag_[1] : valid; 42 | vlan_tag_[1].vid : exact; 43 | } 44 | 45 | action_profile: outer_bd_action_profile; 46 | size : PORT_VLAN_TABLE_SIZE; 47 | } 48 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/rmac.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_rmac_hit_flag() { 16 | modify_field(ingress_metadata.rmac_hit, TRUE); 17 | } 18 | 19 | table rmac { 20 | reads { 21 | ingress_metadata.rmac_group : exact; 22 | ingress_metadata.lkp_mac_da : exact; 23 | } 24 | actions { 25 | on_miss; 26 | set_rmac_hit_flag; 27 | } 28 | size : ROUTER_MAC_TABLE_SIZE; 29 | } 30 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/smac.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action smac_miss() { 16 | modify_field(ingress_metadata.l2_src_miss, TRUE); 17 | } 18 | 19 | action smac_hit(ifindex) { 20 | bit_xor(ingress_metadata.l2_src_move, ingress_metadata.ifindex, ifindex); 21 | add_to_field(ingress_metadata.egress_bd, 0); 22 | } 23 | 24 | table smac { 25 | reads { 26 | ingress_metadata.bd : exact; 27 | ingress_metadata.lkp_mac_sa : exact; 28 | } 29 | actions { 30 | nop; 31 | smac_miss; 32 | smac_hit; 33 | } 34 | size : SMAC_TABLE_SIZE; 35 | } 36 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/spanning_tree.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_stp_state(stp_state) { 16 | modify_field(ingress_metadata.stp_state, stp_state); 17 | } 18 | 19 | table spanning_tree { 20 | reads { 21 | ingress_metadata.ifindex : exact; 22 | ingress_metadata.stp_group: exact; 23 | } 24 | actions { 25 | set_stp_state; 26 | } 27 | size : SPANNING_TREE_TABLE_SIZE; 28 | } 29 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/system_acl.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action redirect_to_cpu() { 16 | modify_field(standard_metadata.egress_spec, CPU_PORT); 17 | modify_field(intrinsic_metadata.eg_mcast_group, 0); 18 | } 19 | 20 | action copy_to_cpu() { 21 | clone_ingress_pkt_to_egress(CPU_PORT); 22 | } 23 | 24 | action drop_packet() { 25 | modify_field(intrinsic_metadata.eg_mcast_group, 0); 26 | drop(); 27 | } 28 | 29 | table system_acl { 30 | reads { 31 | ingress_metadata.if_label : ternary; 32 | ingress_metadata.bd_label : ternary; 33 | 34 | /* ip acl */ 35 | ingress_metadata.lkp_ipv4_sa : ternary; 36 | ingress_metadata.lkp_ipv4_da : ternary; 37 | ingress_metadata.lkp_ip_proto : ternary; 38 | 39 | /* mac acl */ 40 | ingress_metadata.lkp_mac_sa : ternary; 41 | ingress_metadata.lkp_mac_da : ternary; 42 | ingress_metadata.lkp_mac_type : ternary; 43 | 44 | /* drop reasons */ 45 | ingress_metadata.acl_deny : ternary; 46 | ingress_metadata.racl_deny: ternary; 47 | 48 | /* other checks, routed link_local packet, l3 same if check, expired ttl */ 49 | ingress_metadata.src_vtep_miss : ternary; 50 | ingress_metadata.routed : ternary; 51 | ingress_metadata.src_is_link_local : ternary; 52 | ingress_metadata.ttl : ternary; 53 | ingress_metadata.stp_state : ternary; 54 | ingress_metadata.control_frame: ternary; 55 | 56 | /* egress information */ 57 | standard_metadata.egress_spec : ternary; 58 | } 59 | actions { 60 | nop; 61 | redirect_to_cpu; 62 | copy_to_cpu; 63 | drop_packet; 64 | } 65 | size : SYSTEM_ACL_SIZE; 66 | } 67 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/tunnel.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action terminate_tunnel_inner_ipv4(bd, vrf, 16 | rmac_group, bd_label, 17 | uuc_mc_index, bcast_mc_index, umc_mc_index, 18 | ipv4_unicast_enabled, igmp_snooping_enabled) 19 | { 20 | modify_field(ingress_metadata.bd, bd); 21 | modify_field(ingress_metadata.vrf, vrf); 22 | modify_field(ingress_metadata.outer_dscp, ingress_metadata.lkp_ip_tc); 23 | // This implements tunnel in 'uniform' mode i.e. the TTL from the outer IP 24 | // header is copied into the header of decapsulated packet. 25 | // For decapsulation, the TTL in the outer IP header is copied to 26 | // ingress_metadata.lkp_ip_ttl in validate_outer_ipv4_packet action 27 | modify_field(ingress_metadata.outer_ttl, ingress_metadata.lkp_ip_ttl); 28 | add_to_field(ingress_metadata.outer_ttl, -1); 29 | 30 | modify_field(ingress_metadata.lkp_mac_sa, inner_ethernet.srcAddr); 31 | modify_field(ingress_metadata.lkp_mac_da, inner_ethernet.dstAddr); 32 | modify_field(ingress_metadata.lkp_ip_type, IPTYPE_IPV4); 33 | modify_field(ingress_metadata.lkp_ipv4_sa, inner_ipv4.srcAddr); 34 | modify_field(ingress_metadata.lkp_ipv4_da, inner_ipv4.dstAddr); 35 | modify_field(ingress_metadata.lkp_ip_proto, inner_ipv4.protocol); 36 | modify_field(ingress_metadata.lkp_ip_tc, inner_ipv4.diffserv); 37 | modify_field(ingress_metadata.lkp_l4_sport, ingress_metadata.lkp_inner_l4_sport); 38 | modify_field(ingress_metadata.lkp_l4_dport, ingress_metadata.lkp_inner_l4_dport); 39 | 40 | modify_field(ingress_metadata.ipv4_unicast_enabled, ipv4_unicast_enabled); 41 | modify_field(ingress_metadata.igmp_snooping_enabled, igmp_snooping_enabled); 42 | modify_field(ingress_metadata.rmac_group, rmac_group); 43 | modify_field(ingress_metadata.uuc_mc_index, uuc_mc_index); 44 | modify_field(ingress_metadata.umc_mc_index, umc_mc_index); 45 | modify_field(ingress_metadata.bcast_mc_index, bcast_mc_index); 46 | modify_field(ingress_metadata.bd_label, bd_label); 47 | modify_field(ingress_metadata.l3_length, inner_ipv4.totalLen); 48 | } 49 | 50 | table tunnel { 51 | reads { 52 | ingress_metadata.tunnel_vni : exact; 53 | ingress_metadata.tunnel_type : exact; 54 | inner_ipv4 : valid; 55 | } 56 | actions { 57 | terminate_tunnel_inner_ipv4; 58 | } 59 | size : VNID_MAPPING_TABLE_SIZE; 60 | } 61 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/validate_outer_ethernet.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_valid_outer_unicast_packet() { 16 | modify_field(ingress_metadata.lkp_pkt_type, L2_UNICAST); 17 | modify_field(ingress_metadata.lkp_mac_sa, ethernet.srcAddr); 18 | modify_field(ingress_metadata.lkp_mac_da, ethernet.dstAddr); 19 | modify_field(ingress_metadata.lkp_mac_type, ethernet.etherType); 20 | } 21 | 22 | action set_valid_outer_multicast_packet() { 23 | modify_field(ingress_metadata.lkp_pkt_type, L2_MULTICAST); 24 | modify_field(ingress_metadata.lkp_mac_sa, ethernet.srcAddr); 25 | modify_field(ingress_metadata.lkp_mac_da, ethernet.dstAddr); 26 | modify_field(ingress_metadata.lkp_mac_type, ethernet.etherType); 27 | } 28 | 29 | action set_valid_outer_broadcast_packet() { 30 | modify_field(ingress_metadata.lkp_pkt_type, L2_BROADCAST); 31 | modify_field(ingress_metadata.lkp_mac_sa, ethernet.srcAddr); 32 | modify_field(ingress_metadata.lkp_mac_da, ethernet.dstAddr); 33 | modify_field(ingress_metadata.lkp_mac_type, ethernet.etherType); 34 | } 35 | 36 | table validate_outer_ethernet { 37 | reads { 38 | ethernet.dstAddr : ternary; 39 | } 40 | actions { 41 | set_valid_outer_unicast_packet; 42 | set_valid_outer_multicast_packet; 43 | set_valid_outer_broadcast_packet; 44 | } 45 | size : VALIDATE_PACKET_TABLE_SIZE; 46 | } 47 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/validate_outer_ipv4_packet.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_valid_outer_ipv4_packet() { 16 | modify_field(ingress_metadata.lkp_ip_type, IPTYPE_IPV4); 17 | modify_field(ingress_metadata.lkp_ipv4_sa, ipv4.srcAddr); 18 | modify_field(ingress_metadata.lkp_ipv4_da, ipv4.dstAddr); 19 | modify_field(ingress_metadata.lkp_ip_proto, ipv4.protocol); 20 | modify_field(ingress_metadata.lkp_ip_tc, ipv4.diffserv); 21 | modify_field(ingress_metadata.lkp_ip_ttl, ipv4.ttl); 22 | modify_field(ingress_metadata.l3_length, ipv4.totalLen); 23 | } 24 | 25 | action set_malformed_outer_ipv4_packet() { 26 | } 27 | 28 | table validate_outer_ipv4_packet { 29 | reads { 30 | ipv4.version : exact; 31 | ipv4.ihl : exact; 32 | ipv4.ttl : exact; 33 | ipv4.srcAddr : ternary; 34 | ipv4.dstAddr : ternary; 35 | } 36 | actions { 37 | set_valid_outer_ipv4_packet; 38 | set_malformed_outer_ipv4_packet; 39 | } 40 | size : VALIDATE_PACKET_TABLE_SIZE; 41 | } 42 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress/validate_packet.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | action set_l2_multicast() { 16 | modify_field(ingress_metadata.l2_multicast, TRUE); 17 | } 18 | 19 | action set_src_is_link_local() { 20 | modify_field(ingress_metadata.src_is_link_local, TRUE); 21 | } 22 | 23 | action set_malformed_packet() { 24 | } 25 | 26 | table validate_packet { 27 | reads { 28 | ingress_metadata.lkp_mac_da : ternary; 29 | ingress_metadata.lkp_ipv4_da : ternary; 30 | } 31 | actions { 32 | nop; 33 | set_l2_multicast; 34 | set_src_is_link_local; 35 | set_malformed_packet; 36 | } 37 | size : VALIDATE_PACKET_TABLE_SIZE; 38 | } 39 | -------------------------------------------------------------------------------- /sosr15/DC.p4/table_definitions/ingress_tables.p4: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Barefoot Networks, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* Table to validate outer ethernet header */ 16 | #include "ingress/validate_outer_ethernet.p4" 17 | 18 | /* Table to validate outer IP header */ 19 | #include "ingress/validate_outer_ipv4_packet.p4" 20 | 21 | /* Port mapping table, sets ifindex and if_label depending on ingress port */ 22 | #include "ingress/port_mapping.p4" 23 | 24 | /* Port VLAN mapping table, set Bridging Domain, RMAC group, VRF and STP group based on ifindex and VLAN tag */ 25 | #include "ingress/port_vlan_mapping.p4" 26 | 27 | /* Spanning tree table */ 28 | #include "ingress/spanning_tree.p4" 29 | 30 | /* Outer RMAC table, for tunnel termination */ 31 | #include "ingress/outer_rmac.p4" 32 | 33 | /* IPv4 Dest VTEP table, terminate tunnel if you are the destination IP */ 34 | #include "ingress/ipv4_dest_vtep.p4" 35 | 36 | /* IPv4 Src VTEP table, create tunnel if you are the source IP */ 37 | #include "ingress/ipv4_src_vtep.p4" 38 | 39 | /* Tunnel table, terminate tunnel */ 40 | #include "ingress/tunnel.p4" 41 | 42 | /* BD table */ 43 | #include "ingress/bd.p4" 44 | 45 | /* validate packet table, check if link local, or malformed based on MAC DST and IPv4 DST */ 46 | #include "ingress/validate_packet.p4" 47 | 48 | /* SMAC table, SMAC: source MAC */ 49 | #include "ingress/smac.p4" 50 | 51 | /* DMAC table, DMAC: Destination MAC */ 52 | #include "ingress/dmac.p4" 53 | 54 | /* RMAC table, RMAC: Router MAC */ 55 | #include "ingress/rmac.p4" 56 | 57 | /* MAC and IP ACL */ 58 | #include "ingress/mac_ip_acl.p4" 59 | 60 | /* Mirror ACL */ 61 | #include "ingress/mirror_acl.p4" 62 | 63 | /* IP_RACL table, What is RACL? */ 64 | #include "ingress/ip_racl.p4" 65 | 66 | /* IP FIB tables, both lpm and ternary */ 67 | #include "ingress/ip_fib.p4" 68 | 69 | /* fwd_result table */ 70 | #include "ingress/fwd_result.p4" 71 | 72 | /* ecmp_group table */ 73 | #include "ingress/ecmp_group.p4" 74 | 75 | /* next hop table */ 76 | #include "ingress/next_hop.p4" 77 | 78 | /* LAG group table */ 79 | #include "ingress/lag_group.p4" 80 | 81 | /* system_acl table */ 82 | #include "ingress/system_acl.p4" 83 | 84 | /* learn_notify table */ 85 | #include "ingress/learn_notify.p4" 86 | -------------------------------------------------------------------------------- /sosr15/README.md: -------------------------------------------------------------------------------- 1 | These instructions exist for archival purposes. A more recent version of this program, switch.p4, with more features is available at: https://github.com/p4lang/switch. 2 | 3 | Instructions to reproduce results from SOSR 2015 paper 4 | 5 | DC.p4: Programming the Forwarding Plane of a Data-Center Switch 6 | 7 | (The below instructions were tested on a fresh Ubuntu 14.04 EC2 instance) 8 | 9 | (Assume we start at the home directory ~) 10 | 11 | 0. sudo apt-get install git make 12 | 1. git clone https://github.com/p4lang/papers/ 13 | 2. git clone https://github.com/p4lang/p4factory/ 14 | 3. cd ~/p4factory 15 | 4. git checkout sosr-dc-p4 16 | 5. # Follow the instructions in https://github.com/p4lang/p4factory/#quickstart to install the P4 development environment 17 | 6. cd ~/p4factory/targets 18 | 7. ~/p4factory/tools/newtarget.py DC 19 | 8. cp -r ~/papers/sosr15/DC.p4/* ~/p4factory/targets/DC/p4src 20 | 9. cd ~/p4factory/targets/DC/ 21 | 10. make # To compile executable version of DC.p4 22 | 11. sudo ./behavioral-model # To run it 23 | 12. sudo python run_tests.py --test-dir of-tests/tests/ # Simple echo test using run-time API; run in a different terminal 24 | 25 | If something doesn't work, please email me at anirudh@csail.mit.edu 26 | -------------------------------------------------------------------------------- /sosr15/sosr-dc-p4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p4lang/papers/1bef7268cba561a2ef8ca77a089947097215912b/sosr15/sosr-dc-p4.pdf --------------------------------------------------------------------------------