Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <core.p4> |
| 18 | #include <v1model.p4> |
| 19 | |
| 20 | #include "../define.p4" |
| 21 | #include "../header.p4" |
| 22 | #include "../action.p4" |
| 23 | |
| 24 | |
| 25 | control Forwarding ( |
| 26 | inout parsed_headers_t hdr, |
| 27 | inout fabric_metadata_t fabric_metadata, |
| 28 | inout standard_metadata_t standard_metadata) { |
| 29 | |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 30 | action drop() { |
| 31 | mark_to_drop(); |
| 32 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 33 | |
| 34 | action set_next_id(next_id_t next_id) { |
| 35 | fabric_metadata.next_id = next_id; |
| 36 | } |
| 37 | |
| 38 | action pop_mpls_and_next(next_id_t next_id) { |
| 39 | hdr.mpls.setInvalid(); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 40 | fabric_metadata.next_id = next_id; |
| 41 | } |
| 42 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 43 | action duplicate_to_controller() { |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 44 | standard_metadata.egress_spec = CPU_PORT; |
| 45 | } |
| 46 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 47 | table bridging { |
| 48 | key = { |
| 49 | hdr.vlan_tag.vlan_id: exact; |
| 50 | hdr.ethernet.dst_addr: ternary; |
| 51 | } |
| 52 | |
| 53 | actions = { |
| 54 | set_next_id; |
| 55 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | table mpls { |
| 59 | key = { |
| 60 | hdr.mpls.label: exact; |
| 61 | } |
| 62 | |
| 63 | actions = { |
| 64 | pop_mpls_and_next; |
| 65 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | table unicast_v4 { |
| 69 | key = { |
| 70 | hdr.ipv4.dst_addr: lpm; |
| 71 | } |
| 72 | |
| 73 | actions = { |
| 74 | set_next_id; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 75 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | table multicast_v4 { |
| 79 | key = { |
| 80 | hdr.vlan_tag.vlan_id: exact; |
| 81 | hdr.ipv4.dst_addr: lpm; |
| 82 | } |
| 83 | |
| 84 | actions = { |
| 85 | set_next_id; |
| 86 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | table unicast_v6 { |
| 90 | key = { |
| 91 | hdr.ipv6.dst_addr: lpm; |
| 92 | } |
| 93 | |
| 94 | actions = { |
| 95 | set_next_id; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 96 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | table multicast_v6 { |
| 100 | key = { |
| 101 | hdr.vlan_tag.vlan_id: exact; |
| 102 | hdr.ipv6.dst_addr: lpm; |
| 103 | } |
| 104 | |
| 105 | actions = { |
| 106 | set_next_id; |
| 107 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | table acl { |
| 111 | key = { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 112 | standard_metadata.ingress_port: ternary; // 9 |
| 113 | fabric_metadata.ip_proto: ternary; // 8 |
| 114 | fabric_metadata.l4_src_port: ternary; // 16 |
| 115 | fabric_metadata.l4_dst_port: ternary; // 16 |
Yi Tseng | c6844f5 | 2017-12-19 11:58:25 -0800 | [diff] [blame^] | 116 | fabric_metadata.original_ether_type: ternary; //16 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 117 | |
| 118 | hdr.ethernet.dst_addr: ternary; // 48 |
| 119 | hdr.ethernet.src_addr: ternary; // 48 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 120 | hdr.vlan_tag.vlan_id: ternary; // 12 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 121 | hdr.ipv4.src_addr: ternary; // 32 |
| 122 | hdr.ipv4.dst_addr: ternary; // 32 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 123 | hdr.icmp.icmp_type: ternary; // 8 |
| 124 | hdr.icmp.icmp_code: ternary; // 8 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | actions = { |
| 128 | set_next_id; |
| 129 | duplicate_to_controller; |
| 130 | drop; |
| 131 | nop; |
| 132 | } |
| 133 | |
| 134 | const default_action = nop(); |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 135 | size = 256; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | apply { |
| 139 | if(fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply(); |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 140 | else if (fabric_metadata.fwd_type == FWD_MPLS) { |
| 141 | mpls.apply(); |
| 142 | if (hdr.ipv4.isValid()) { |
| 143 | hdr.ethernet.ether_type = ETHERTYPE_IPV4; |
| 144 | fabric_metadata.original_ether_type = ETHERTYPE_IPV4; |
| 145 | } else { |
| 146 | hdr.ethernet.ether_type = ETHERTYPE_IPV6; |
| 147 | fabric_metadata.original_ether_type = ETHERTYPE_IPV6; |
| 148 | } |
| 149 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 150 | else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) unicast_v4.apply(); |
| 151 | else if (fabric_metadata.fwd_type == FWD_IPV4_MULTICAST) multicast_v4.apply(); |
| 152 | else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) unicast_v6.apply(); |
| 153 | else if (fabric_metadata.fwd_type == FWD_IPV6_MULTICAST) multicast_v6.apply(); |
| 154 | acl.apply(); |
| 155 | } |
| 156 | } |