Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 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 | */ |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.pipeline.ofdpa; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 17 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 20 | import org.onlab.osgi.ServiceDirectory; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 21 | import org.onlab.packet.Ethernet; |
Alex Yashchuk | a367953 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 22 | import org.onlab.packet.EthType.EtherType; |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 24 | import org.onlab.packet.IpPrefix; |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 26 | import org.onlab.packet.VlanId; |
| 27 | import org.onlab.util.KryoNamespace; |
| 28 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreService; |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 30 | import org.onosproject.driver.extensions.Ofdpa3MplsType; |
| 31 | import org.onosproject.driver.extensions.Ofdpa3SetMplsType; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 32 | import org.onosproject.driver.extensions.OfdpaMatchVlanVid; |
| 33 | import org.onosproject.driver.extensions.OfdpaSetVlanVid; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 34 | import org.onosproject.net.DeviceId; |
| 35 | import org.onosproject.net.Port; |
| 36 | import org.onosproject.net.PortNumber; |
| 37 | import org.onosproject.net.behaviour.NextGroup; |
| 38 | import org.onosproject.net.behaviour.Pipeliner; |
| 39 | import org.onosproject.net.behaviour.PipelinerContext; |
| 40 | import org.onosproject.net.device.DeviceService; |
| 41 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 42 | import org.onosproject.net.flow.DefaultFlowRule; |
| 43 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 44 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 45 | import org.onosproject.net.flow.FlowRule; |
| 46 | import org.onosproject.net.flow.FlowRuleOperations; |
| 47 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 48 | import org.onosproject.net.flow.FlowRuleService; |
| 49 | import org.onosproject.net.flow.TrafficSelector; |
| 50 | import org.onosproject.net.flow.TrafficTreatment; |
| 51 | import org.onosproject.net.flow.criteria.Criteria; |
| 52 | import org.onosproject.net.flow.criteria.Criterion; |
| 53 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 54 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 55 | import org.onosproject.net.flow.criteria.IPCriterion; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 56 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 57 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 58 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 59 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 60 | import org.onosproject.net.flow.criteria.PortCriterion; |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 61 | import org.onosproject.net.flow.criteria.TcpPortCriterion; |
| 62 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 63 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 64 | import org.onosproject.net.flow.instructions.Instruction; |
| 65 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 66 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 67 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 68 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 69 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
Alex Yashchuk | a367953 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 70 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction; |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 71 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
| 72 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 73 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 74 | import org.onosproject.net.flowobjective.FlowObjectiveStore; |
| 75 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 76 | import org.onosproject.net.flowobjective.NextObjective; |
| 77 | import org.onosproject.net.flowobjective.Objective; |
| 78 | import org.onosproject.net.flowobjective.ObjectiveError; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 79 | import org.onosproject.net.group.DefaultGroupKey; |
| 80 | import org.onosproject.net.group.Group; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 81 | import org.onosproject.net.group.GroupKey; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 82 | import org.onosproject.net.group.GroupService; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 83 | import org.onosproject.store.serializers.KryoNamespaces; |
| 84 | import org.slf4j.Logger; |
| 85 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 86 | import java.util.ArrayDeque; |
| 87 | import java.util.ArrayList; |
| 88 | import java.util.Collection; |
| 89 | import java.util.Collections; |
| 90 | import java.util.Deque; |
| 91 | import java.util.List; |
| 92 | import java.util.Objects; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 93 | import java.util.concurrent.ScheduledExecutorService; |
| 94 | import java.util.concurrent.TimeUnit; |
| 95 | |
| 96 | import static java.util.concurrent.Executors.newScheduledThreadPool; |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 97 | import static org.onlab.packet.MacAddress.BROADCAST; |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 98 | import static org.onlab.packet.MacAddress.IPV4_MULTICAST; |
| 99 | import static org.onlab.packet.MacAddress.IPV6_MULTICAST; |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 100 | import static org.onlab.packet.MacAddress.NONE; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 101 | import static org.onlab.util.Tools.groupedThreads; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 102 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*; |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 103 | import static org.onosproject.net.flow.criteria.Criterion.Type.ETH_TYPE; |
Pier Luigi | 5af88fe | 2018-02-01 10:23:12 +0100 | [diff] [blame] | 104 | import static org.onosproject.net.group.GroupDescription.Type.SELECT; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 105 | import static org.slf4j.LoggerFactory.getLogger; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 106 | import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 107 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Driver for Broadcom's OF-DPA v2.0 TTP. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 110 | */ |
Charles Chan | 361154b | 2016-03-24 10:23:39 -0700 | [diff] [blame] | 111 | public class Ofdpa2Pipeline extends AbstractHandlerBehaviour implements Pipeliner { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 112 | protected static final int PORT_TABLE = 0; |
| 113 | protected static final int VLAN_TABLE = 10; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 114 | protected static final int VLAN_1_TABLE = 11; |
| 115 | protected static final int MPLS_L2_PORT_FLOW_TABLE = 13; |
| 116 | protected static final int MPLS_L2_PORT_PCP_TRUST_FLOW_TABLE = 16; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 117 | protected static final int TMAC_TABLE = 20; |
| 118 | protected static final int UNICAST_ROUTING_TABLE = 30; |
| 119 | protected static final int MULTICAST_ROUTING_TABLE = 40; |
| 120 | protected static final int MPLS_TABLE_0 = 23; |
| 121 | protected static final int MPLS_TABLE_1 = 24; |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 122 | protected static final int MPLS_L3_TYPE_TABLE = 27; |
| 123 | protected static final int MPLS_TYPE_TABLE = 29; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 124 | protected static final int BRIDGING_TABLE = 50; |
| 125 | protected static final int ACL_TABLE = 60; |
| 126 | protected static final int MAC_LEARNING_TABLE = 254; |
| 127 | protected static final long OFPP_MAX = 0xffffff00L; |
| 128 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 129 | protected static final int HIGHEST_PRIORITY = 0xffff; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 130 | protected static final int DEFAULT_PRIORITY = 0x8000; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 131 | protected static final int LOWEST_PRIORITY = 0x0; |
| 132 | |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 133 | protected static final int MPLS_L2_PORT_PRIORITY = 2; |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 134 | protected static final int MPLS_TUNNEL_ID_BASE = 0x10000; |
| 135 | protected static final int MPLS_TUNNEL_ID_MAX = 0x1FFFF; |
| 136 | |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 137 | protected static final int MPLS_UNI_PORT_MAX = 0x0000FFFF; |
Pier Ventre | 70d53ba | 2016-11-17 22:26:29 -0800 | [diff] [blame] | 138 | protected static final int MPLS_NNI_PORT_BASE = 0x00020000; |
| 139 | protected static final int MPLS_NNI_PORT_MAX = 0x0002FFFF; |
| 140 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 141 | private final Logger log = getLogger(getClass()); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 142 | protected ServiceDirectory serviceDirectory; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 143 | protected FlowRuleService flowRuleService; |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 144 | protected CoreService coreService; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 145 | protected GroupService groupService; |
| 146 | protected FlowObjectiveStore flowObjectiveStore; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 147 | protected DeviceId deviceId; |
| 148 | protected ApplicationId driverId; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 149 | protected DeviceService deviceService; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 150 | protected static KryoNamespace appKryo = new KryoNamespace.Builder() |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 151 | .register(KryoNamespaces.API) |
| 152 | .register(GroupKey.class) |
| 153 | .register(DefaultGroupKey.class) |
| 154 | .register(OfdpaNextGroup.class) |
| 155 | .register(ArrayDeque.class) |
| 156 | .build("Ofdpa2Pipeline"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 157 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 158 | protected Ofdpa2GroupHandler groupHandler; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 159 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 160 | // flows installations to be retried |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 161 | private ScheduledExecutorService executorService |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 162 | = newScheduledThreadPool(5, groupedThreads("OfdpaPipeliner", "retry-%d", log)); |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 163 | private static final int MAX_RETRY_ATTEMPTS = 10; |
| 164 | private static final int RETRY_MS = 1000; |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 165 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 166 | @Override |
| 167 | public void init(DeviceId deviceId, PipelinerContext context) { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 168 | this.deviceId = deviceId; |
| 169 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 170 | serviceDirectory = context.directory(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 171 | coreService = serviceDirectory.get(CoreService.class); |
| 172 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
| 173 | groupService = serviceDirectory.get(GroupService.class); |
| 174 | flowObjectiveStore = context.store(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 175 | deviceService = serviceDirectory.get(DeviceService.class); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 176 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 177 | initDriverId(); |
| 178 | initGroupHander(context); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 179 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 180 | initializePipeline(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 183 | protected void initDriverId() { |
| 184 | driverId = coreService.registerApplication( |
| 185 | "org.onosproject.driver.Ofdpa2Pipeline"); |
| 186 | } |
| 187 | |
| 188 | protected void initGroupHander(PipelinerContext context) { |
| 189 | groupHandler = new Ofdpa2GroupHandler(); |
| 190 | groupHandler.init(deviceId, context); |
| 191 | } |
| 192 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 193 | protected void initializePipeline() { |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 194 | // OF-DPA does not require initializing the pipeline as it puts default |
| 195 | // rules automatically in the hardware. However emulation of OFDPA in |
| 196 | // software switches does require table-miss-entries. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 199 | /** |
Alex Yashchuk | a367953 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 200 | * Determines whether this pipeline requires MPLS POP instruction. |
| 201 | * |
| 202 | * @return true to use MPLS POP instruction |
| 203 | */ |
| 204 | public boolean requireMplsPop() { |
| 205 | return true; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Determines whether this pipeline requires MPLS BOS match. |
| 210 | * |
| 211 | * @return true to use MPLS BOS match |
| 212 | */ |
| 213 | public boolean requireMplsBosMatch() { |
| 214 | return true; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Determines whether this pipeline requires MPLS TTL decrement and copy. |
| 219 | * |
| 220 | * @return true to use MPLS TTL decrement and copy |
| 221 | */ |
| 222 | public boolean requireMplsTtlModification() { |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | /** |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 227 | * Determines whether this pipeline requires OFDPA match and set VLAN extensions. |
| 228 | * |
| 229 | * @return true to use the extensions |
| 230 | */ |
| 231 | protected boolean requireVlanExtensions() { |
| 232 | return true; |
| 233 | } |
| 234 | |
Saurav Das | 86d13e8 | 2017-04-28 17:03:48 -0700 | [diff] [blame] | 235 | /** |
| 236 | * Determines whether in-port should be matched on in TMAC table rules. |
| 237 | * |
| 238 | * @return true if match on in-port should be programmed |
| 239 | */ |
| 240 | protected boolean matchInPortTmacTable() { |
| 241 | return true; |
| 242 | } |
| 243 | |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 244 | /** |
| 245 | * Determines whether matching L4 destination port on IPv6 packets is supported in ACL table. |
| 246 | * |
| 247 | * @return true if matching L4 destination port on IPv6 packets is supported in ACL table. |
| 248 | */ |
| 249 | protected boolean supportIpv6L4Dst() { |
| 250 | return true; |
| 251 | } |
| 252 | |
Saurav Das | f3f7594 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 253 | /** |
| 254 | * Determines whether this driver should continue to retry flows that point |
| 255 | * to empty groups. See CORD-554. |
| 256 | * |
| 257 | * @return true if the driver should retry flows |
| 258 | */ |
| 259 | protected boolean shouldRetry() { |
| 260 | return true; |
| 261 | } |
| 262 | |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 263 | /** |
| 264 | * Determines whether this driver requires unicast flow to be installed before multicast flow |
| 265 | * in TMAC table. |
| 266 | * |
| 267 | * @return true if required |
| 268 | */ |
| 269 | protected boolean requireUnicastBeforeMulticast() { |
| 270 | return false; |
| 271 | } |
| 272 | |
Andrea Campanella | 84ac4df | 2018-04-30 11:48:55 +0200 | [diff] [blame] | 273 | /** |
| 274 | * Determines whether this driver supports installing a clearDeferred action on table 30. |
| 275 | * |
| 276 | * @return true if required |
| 277 | */ |
| 278 | protected boolean supportsUnicastBlackHole() { |
| 279 | return true; |
| 280 | } |
| 281 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 282 | ////////////////////////////////////// |
| 283 | // Flow Objectives |
| 284 | ////////////////////////////////////// |
| 285 | |
| 286 | @Override |
| 287 | public void filter(FilteringObjective filteringObjective) { |
| 288 | if (filteringObjective.type() == FilteringObjective.Type.PERMIT) { |
| 289 | processFilter(filteringObjective, |
| 290 | filteringObjective.op() == Objective.Operation.ADD, |
| 291 | filteringObjective.appId()); |
| 292 | } else { |
| 293 | // Note that packets that don't match the PERMIT filter are |
| 294 | // automatically denied. The DENY filter is used to deny packets |
| 295 | // that are otherwise permitted by the PERMIT filter. |
| 296 | // Use ACL table flow rules here for DENY filtering objectives |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 297 | log.warn("filter objective other than PERMIT currently not supported"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 298 | fail(filteringObjective, ObjectiveError.UNSUPPORTED); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public void forward(ForwardingObjective fwd) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 304 | Collection<FlowRule> rules = processForward(fwd); |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 305 | if (rules == null || rules.isEmpty()) { |
| 306 | // Assumes fail message has already been generated to the objective |
| 307 | // context. Returning here prevents spurious pass message to be |
| 308 | // generated by FlowRule service for empty flowOps. |
| 309 | return; |
| 310 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 311 | sendForward(fwd, rules); |
| 312 | } |
| 313 | |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 314 | private void sendForward(ForwardingObjective fwd, Collection<FlowRule> rules) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 315 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 316 | switch (fwd.op()) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 317 | case ADD: |
| 318 | rules.stream() |
| 319 | .filter(Objects::nonNull) |
| 320 | .forEach(flowOpsBuilder::add); |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 321 | log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 322 | break; |
| 323 | case REMOVE: |
| 324 | rules.stream() |
| 325 | .filter(Objects::nonNull) |
| 326 | .forEach(flowOpsBuilder::remove); |
Pier Ventre | 42287df | 2016-11-09 14:17:26 -0800 | [diff] [blame] | 327 | log.debug("Deleting a flow rule to sw:{}", deviceId); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 328 | break; |
| 329 | default: |
| 330 | fail(fwd, ObjectiveError.UNKNOWN); |
| 331 | log.warn("Unknown forwarding type {}", fwd.op()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 334 | flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() { |
| 335 | @Override |
| 336 | public void onSuccess(FlowRuleOperations ops) { |
| 337 | pass(fwd); |
| 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public void onError(FlowRuleOperations ops) { |
| 342 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 343 | } |
| 344 | })); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public void next(NextObjective nextObjective) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 349 | NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id()); |
| 350 | switch (nextObjective.op()) { |
| 351 | case ADD: |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 352 | if (nextGroup != null) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 353 | log.warn("Cannot add next {} that already exists in device {}", |
| 354 | nextObjective.id(), deviceId); |
| 355 | return; |
| 356 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 357 | log.debug("Processing NextObjective id {} in dev {} - add group", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 358 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 359 | groupHandler.addGroup(nextObjective); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 360 | break; |
| 361 | case ADD_TO_EXISTING: |
| 362 | if (nextGroup != null) { |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 363 | log.debug("Processing NextObjective id {} in dev {} - add bucket", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 364 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 365 | groupHandler.addBucketToGroup(nextObjective, nextGroup); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 366 | } else { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 367 | // it is possible that group-chain has not been fully created yet |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 368 | log.debug("Waiting to add bucket to group for next-id:{} in dev:{}", |
| 369 | nextObjective.id(), deviceId); |
Yi Tseng | 47f82dc | 2017-03-05 22:48:39 -0800 | [diff] [blame] | 370 | |
| 371 | // by design multiple pending bucket is allowed for the group |
| 372 | groupHandler.pendingBuckets.compute(nextObjective.id(), (nextId, pendBkts) -> { |
| 373 | if (pendBkts == null) { |
| 374 | pendBkts = Sets.newHashSet(); |
| 375 | } |
| 376 | pendBkts.add(nextObjective); |
| 377 | return pendBkts; |
| 378 | }); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 379 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 380 | break; |
| 381 | case REMOVE: |
| 382 | if (nextGroup == null) { |
| 383 | log.warn("Cannot remove next {} that does not exist in device {}", |
| 384 | nextObjective.id(), deviceId); |
| 385 | return; |
| 386 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 387 | log.debug("Processing NextObjective id {} in dev {} - remove group", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 388 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 389 | groupHandler.removeGroup(nextObjective, nextGroup); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 390 | break; |
| 391 | case REMOVE_FROM_EXISTING: |
| 392 | if (nextGroup == null) { |
| 393 | log.warn("Cannot remove from next {} that does not exist in device {}", |
| 394 | nextObjective.id(), deviceId); |
| 395 | return; |
| 396 | } |
Saurav Das | 1547b3f | 2017-05-05 17:01:08 -0700 | [diff] [blame] | 397 | log.debug("Processing NextObjective id {} in dev {} - remove bucket", |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 398 | nextObjective.id(), deviceId); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 399 | groupHandler.removeBucketFromGroup(nextObjective, nextGroup); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 400 | break; |
Jonghwan Hyun | 25199f2 | 2018-02-12 16:43:45 +0900 | [diff] [blame] | 401 | case MODIFY: |
| 402 | if (nextGroup == null) { |
| 403 | log.warn("Cannot modify next {} that does not exist in device {}", |
| 404 | nextObjective.id(), deviceId); |
| 405 | return; |
| 406 | } |
| 407 | log.debug("Processing NextObjective id {} in dev {} - modify bucket", |
| 408 | nextObjective.id(), deviceId); |
| 409 | groupHandler.modifyBucketFromGroup(nextObjective, nextGroup); |
| 410 | break; |
Saurav Das | ceccf24 | 2017-08-03 18:30:35 -0700 | [diff] [blame] | 411 | case VERIFY: |
| 412 | if (nextGroup == null) { |
| 413 | log.warn("Cannot verify next {} that does not exist in device {}", |
| 414 | nextObjective.id(), deviceId); |
| 415 | return; |
| 416 | } |
| 417 | log.debug("Processing NextObjective id {} in dev {} - verify", |
| 418 | nextObjective.id(), deviceId); |
| 419 | groupHandler.verifyGroup(nextObjective, nextGroup); |
| 420 | break; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 421 | default: |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 422 | log.warn("Unsupported operation {}", nextObjective.op()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | ////////////////////////////////////// |
| 427 | // Flow handling |
| 428 | ////////////////////////////////////// |
| 429 | |
| 430 | /** |
Yi Tseng | 0fdc07e | 2017-04-24 19:17:08 -0700 | [diff] [blame] | 431 | * As per OFDPA 2.0 TTP, filtering of VLAN ids and MAC addresses (for routing) |
| 432 | * configured on switch ports happen in different tables. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 433 | * |
| 434 | * @param filt the filtering objective |
| 435 | * @param install indicates whether to add or remove the objective |
| 436 | * @param applicationId the application that sent this objective |
| 437 | */ |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 438 | protected void processFilter(FilteringObjective filt, |
| 439 | boolean install, ApplicationId applicationId) { |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 440 | // This driver only processes filtering criteria defined with switch |
| 441 | // ports as the key |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 442 | PortCriterion portCriterion = null; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 443 | EthCriterion ethCriterion = null; |
| 444 | VlanIdCriterion vidCriterion = null; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 445 | if (!filt.key().equals(Criteria.dummy()) && |
| 446 | filt.key().type() == Criterion.Type.IN_PORT) { |
| 447 | portCriterion = (PortCriterion) filt.key(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 448 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 449 | if (portCriterion == null) { |
| 450 | log.debug("No IN_PORT defined in filtering objective from app: {}", |
| 451 | applicationId); |
| 452 | } else { |
| 453 | log.debug("Received filtering objective for dev/port: {}/{}", deviceId, |
| 454 | portCriterion.port()); |
| 455 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 456 | // convert filtering conditions for switch-intfs into flowrules |
| 457 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 458 | for (Criterion criterion : filt.conditions()) { |
Yi Tseng | 0fdc07e | 2017-04-24 19:17:08 -0700 | [diff] [blame] | 459 | switch (criterion.type()) { |
| 460 | case ETH_DST: |
| 461 | case ETH_DST_MASKED: |
| 462 | ethCriterion = (EthCriterion) criterion; |
| 463 | break; |
| 464 | case VLAN_VID: |
| 465 | vidCriterion = (VlanIdCriterion) criterion; |
| 466 | break; |
| 467 | default: |
| 468 | log.warn("Unsupported filter {}", criterion); |
| 469 | fail(filt, ObjectiveError.UNSUPPORTED); |
| 470 | return; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 474 | VlanId assignedVlan = null; |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 475 | if (vidCriterion != null) { |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 476 | // Use the VLAN in criterion if metadata is not present and the traffic is tagged |
Charles Chan | 9174e6b | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 477 | if (!vidCriterion.vlanId().equals(VlanId.NONE)) { |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 478 | assignedVlan = vidCriterion.vlanId(); |
Pier | 3cc7e66 | 2018-03-07 11:42:50 +0100 | [diff] [blame] | 479 | } |
| 480 | // If the meta VLAN is present let's update the assigned vlan |
| 481 | if (filt.meta() != null) { |
| 482 | VlanId metaVlan = readVlanFromTreatment(filt.meta()); |
| 483 | if (metaVlan != null) { |
| 484 | assignedVlan = metaVlan; |
| 485 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 486 | } |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 487 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 488 | if (assignedVlan == null) { |
| 489 | log.error("Driver fails to extract VLAN information. " |
Frank Wang | d8ab096 | 2017-08-11 11:09:30 +0800 | [diff] [blame] | 490 | + "Not processing VLAN filters on device {}.", deviceId); |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 491 | log.debug("VLAN ID in criterion={}, metadata={}", |
| 492 | readVlanFromTreatment(filt.meta()), vidCriterion.vlanId()); |
| 493 | fail(filt, ObjectiveError.BADPARAMS); |
| 494 | return; |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 498 | if (ethCriterion == null || ethCriterion.mac().equals(NONE)) { |
Charles Chan | 985b12e | 2016-05-11 19:47:22 -0700 | [diff] [blame] | 499 | // NOTE: it is possible that a filtering objective only has vidCriterion |
Saurav Das | 961beb2 | 2017-03-29 19:09:17 -0700 | [diff] [blame] | 500 | log.warn("filtering objective missing dstMac, cannot program TMAC table"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 501 | } else { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 502 | MacAddress unicastMac = readEthDstFromTreatment(filt.meta()); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 503 | List<List<FlowRule>> allStages = processEthDstFilter(portCriterion, ethCriterion, |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 504 | vidCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 505 | for (List<FlowRule> flowRules : allStages) { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 506 | log.trace("Starting a new flow rule stage for TMAC table flow"); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 507 | ops.newStage(); |
Charles Chan | 9174e6b | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 508 | |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 509 | for (FlowRule flowRule : flowRules) { |
| 510 | log.trace("{} flow rules in TMAC table: {} for dev: {}", |
| 511 | (install) ? "adding" : "removing", flowRules, deviceId); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 512 | if (install) { |
| 513 | ops = ops.add(flowRule); |
Charles Chan | 9174e6b | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 514 | } else { |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 515 | // NOTE: Only remove TMAC flow when there is no more enabled port within the |
| 516 | // same VLAN on this device if TMAC doesn't support matching on in_port. |
| 517 | if (matchInPortTmacTable() || (filt.meta() != null && filt.meta().clearedDeferred())) { |
| 518 | ops = ops.remove(flowRule); |
| 519 | } else { |
| 520 | log.debug("Abort TMAC flow removal on {}. Some other ports still share this TMAC flow"); |
| 521 | } |
Charles Chan | 9174e6b | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 522 | } |
| 523 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
Charles Chan | 985b12e | 2016-05-11 19:47:22 -0700 | [diff] [blame] | 527 | if (vidCriterion == null) { |
| 528 | // NOTE: it is possible that a filtering objective only has ethCriterion |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 529 | log.info("filtering objective missing VLAN, cannot program VLAN Table"); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 530 | } else { |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 531 | List<List<FlowRule>> allStages = processVlanIdFilter( |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 532 | portCriterion, vidCriterion, assignedVlan, applicationId); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 533 | for (List<FlowRule> flowRules : allStages) { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 534 | log.trace("Starting a new flow rule stage for VLAN table flow"); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 535 | ops.newStage(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 536 | |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 537 | for (FlowRule flowRule : flowRules) { |
| 538 | log.trace("{} flow rules in VLAN table: {} for dev: {}", |
| 539 | (install) ? "adding" : "removing", flowRule, deviceId); |
| 540 | ops = install ? ops.add(flowRule) : ops.remove(flowRule); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 541 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 545 | // apply filtering flow rules |
| 546 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 547 | @Override |
| 548 | public void onSuccess(FlowRuleOperations ops) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 549 | log.debug("Applied {} filtering rules in device {}", |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 550 | ops.stages().get(0).size(), deviceId); |
| 551 | pass(filt); |
| 552 | } |
| 553 | |
| 554 | @Override |
| 555 | public void onError(FlowRuleOperations ops) { |
| 556 | log.info("Failed to apply all filtering rules in dev {}", deviceId); |
| 557 | fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 558 | } |
| 559 | })); |
| 560 | |
| 561 | } |
| 562 | |
| 563 | /** |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 564 | * Internal implementation of processVlanIdFilter. |
| 565 | * <p> |
| 566 | * The is_present bit in set_vlan_vid action is required to be 0 in OFDPA i12. |
| 567 | * Since it is non-OF spec, we need an extension treatment for that. |
| 568 | * The useVlanExtension must be set to false for OFDPA i12. |
| 569 | * </p> |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 570 | * <p> |
| 571 | * NOTE: Separate VLAN filtering rules and assignment rules |
| 572 | * into different stages in order to guarantee that filtering rules |
| 573 | * always go first, as required by OFDPA. |
| 574 | * </p> |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 575 | * |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 576 | * @param portCriterion port on device for which this filter is programmed |
| 577 | * @param vidCriterion vlan assigned to port, or NONE for untagged |
| 578 | * @param assignedVlan assigned vlan-id for untagged packets |
| 579 | * @param applicationId for application programming this filter |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 580 | * @return stages of flow rules for port-vlan filters |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 581 | */ |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 582 | protected List<List<FlowRule>> processVlanIdFilter(PortCriterion portCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 583 | VlanIdCriterion vidCriterion, |
| 584 | VlanId assignedVlan, |
| 585 | ApplicationId applicationId) { |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 586 | List<FlowRule> filteringRules = new ArrayList<>(); |
| 587 | List<FlowRule> assignmentRules = new ArrayList<>(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 588 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 589 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 590 | TrafficSelector.Builder preSelector = null; |
| 591 | TrafficTreatment.Builder preTreatment = null; |
| 592 | |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 593 | treatment.transition(TMAC_TABLE); |
| 594 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 595 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 596 | // untagged packets are assigned vlans |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 597 | preSelector = DefaultTrafficSelector.builder(); |
| 598 | if (requireVlanExtensions()) { |
| 599 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(VlanId.NONE); |
| 600 | selector.extension(ofdpaMatchVlanVid, deviceId); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 601 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan); |
| 602 | treatment.extension(ofdpaSetVlanVid, deviceId); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 603 | |
| 604 | OfdpaMatchVlanVid preOfdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 605 | preSelector.extension(preOfdpaMatchVlanVid, deviceId); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 606 | } else { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 607 | selector.matchVlanId(VlanId.NONE); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 608 | treatment.setVlanId(assignedVlan); |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 609 | |
| 610 | preSelector.matchVlanId(assignedVlan); |
| 611 | } |
| 612 | preTreatment = DefaultTrafficTreatment.builder().transition(TMAC_TABLE); |
| 613 | } else { |
| 614 | if (requireVlanExtensions()) { |
| 615 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId()); |
| 616 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 617 | } else { |
| 618 | selector.matchVlanId(vidCriterion.vlanId()); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 619 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 620 | |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 621 | if (!assignedVlan.equals(vidCriterion.vlanId())) { |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 622 | if (requireVlanExtensions()) { |
Charles Chan | c03782d | 2017-01-31 13:57:55 -0800 | [diff] [blame] | 623 | OfdpaSetVlanVid ofdpaSetVlanVid = new OfdpaSetVlanVid(assignedVlan); |
| 624 | treatment.extension(ofdpaSetVlanVid, deviceId); |
| 625 | } else { |
| 626 | treatment.setVlanId(assignedVlan); |
| 627 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 628 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 629 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 630 | |
| 631 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 632 | // rules for each port. |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 633 | List<PortNumber> portnums = new ArrayList<>(); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 634 | if (portCriterion != null) { |
| 635 | if (PortNumber.ALL.equals(portCriterion.port())) { |
| 636 | for (Port port : deviceService.getPorts(deviceId)) { |
| 637 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 638 | portnums.add(port.number()); |
| 639 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 640 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 641 | } else { |
| 642 | portnums.add(portCriterion.port()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 643 | } |
| 644 | } else { |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 645 | log.warn("Filtering Objective missing Port Criterion . " + |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 646 | "VLAN Table cannot be programmed for {}", deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 647 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 648 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 649 | for (PortNumber pnum : portnums) { |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 650 | // create rest of flowrule |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 651 | selector.matchInPort(pnum); |
| 652 | FlowRule rule = DefaultFlowRule.builder() |
| 653 | .forDevice(deviceId) |
| 654 | .withSelector(selector.build()) |
| 655 | .withTreatment(treatment.build()) |
| 656 | .withPriority(DEFAULT_PRIORITY) |
| 657 | .fromApp(applicationId) |
| 658 | .makePermanent() |
| 659 | .forTable(VLAN_TABLE).build(); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 660 | assignmentRules.add(rule); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 661 | |
| 662 | if (preSelector != null) { |
| 663 | preSelector.matchInPort(pnum); |
| 664 | FlowRule preRule = DefaultFlowRule.builder() |
| 665 | .forDevice(deviceId) |
| 666 | .withSelector(preSelector.build()) |
| 667 | .withTreatment(preTreatment.build()) |
| 668 | .withPriority(DEFAULT_PRIORITY) |
| 669 | .fromApp(applicationId) |
| 670 | .makePermanent() |
| 671 | .forTable(VLAN_TABLE).build(); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 672 | filteringRules.add(preRule); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 673 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 674 | } |
Charles Chan | 1e58aa6 | 2018-03-06 22:10:15 -0800 | [diff] [blame] | 675 | return ImmutableList.of(filteringRules, assignmentRules); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Allows routed packets with correct destination MAC to be directed |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 680 | * to unicast routing table, multicast routing table or MPLS forwarding table. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 681 | * |
| 682 | * @param portCriterion port on device for which this filter is programmed |
| 683 | * @param ethCriterion dstMac of device for which is filter is programmed |
| 684 | * @param vidCriterion vlan assigned to port, or NONE for untagged |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 685 | * @param assignedVlan assigned vlan-id for untagged packets |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 686 | * @param unicastMac some switches require a unicast TMAC flow to be programmed before multicast |
| 687 | * TMAC flow. This MAC address will be used for the unicast TMAC flow. |
| 688 | * This is unused if the filtering objective is a unicast. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 689 | * @param applicationId for application programming this filter |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 690 | * @return stages of flow rules for port-vlan filters |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 691 | |
| 692 | */ |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 693 | protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion, |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 694 | EthCriterion ethCriterion, |
| 695 | VlanIdCriterion vidCriterion, |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 696 | VlanId assignedVlan, |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 697 | MacAddress unicastMac, |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 698 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 699 | // Consider PortNumber.ANY as wildcard. Match ETH_DST only |
Sivachidambaram Subramanian | c598d06 | 2017-05-16 22:42:06 +0530 | [diff] [blame] | 700 | if (portCriterion != null && PortNumber.ANY.equals(portCriterion.port())) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 701 | return processEthDstOnlyFilter(ethCriterion, applicationId); |
| 702 | } |
| 703 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 704 | // Multicast MAC |
| 705 | if (ethCriterion.mask() != null) { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 706 | return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 709 | //handling untagged packets via assigned VLAN |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 710 | if (vidCriterion != null && vidCriterion.vlanId() == VlanId.NONE) { |
Saurav Das | 0e99e2b | 2015-10-28 12:39:42 -0700 | [diff] [blame] | 711 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 712 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 713 | List<FlowRule> rules = new ArrayList<>(); |
| 714 | OfdpaMatchVlanVid ofdpaMatchVlanVid = null; |
| 715 | if (vidCriterion != null && requireVlanExtensions()) { |
| 716 | ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vidCriterion.vlanId()); |
| 717 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 718 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 719 | // rules for each port. |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 720 | List<PortNumber> portnums = new ArrayList<>(); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 721 | if (portCriterion != null) { |
| 722 | if (PortNumber.ALL.equals(portCriterion.port())) { |
| 723 | for (Port port : deviceService.getPorts(deviceId)) { |
| 724 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 725 | portnums.add(port.number()); |
| 726 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 727 | } |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 728 | } else { |
| 729 | portnums.add(portCriterion.port()); |
| 730 | } |
| 731 | for (PortNumber pnum : portnums) { |
| 732 | rules.add(buildTmacRuleForIpv4(ethCriterion, |
| 733 | vidCriterion, |
| 734 | ofdpaMatchVlanVid, |
| 735 | applicationId, |
| 736 | pnum)); |
| 737 | rules.add(buildTmacRuleForMpls(ethCriterion, |
| 738 | vidCriterion, |
| 739 | ofdpaMatchVlanVid, |
| 740 | applicationId, |
| 741 | pnum)); |
| 742 | rules.add(buildTmacRuleForIpv6(ethCriterion, |
| 743 | vidCriterion, |
| 744 | ofdpaMatchVlanVid, |
| 745 | applicationId, |
| 746 | pnum)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 747 | } |
| 748 | } else { |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 749 | rules.add(buildTmacRuleForIpv4(ethCriterion, |
| 750 | vidCriterion, |
| 751 | ofdpaMatchVlanVid, |
| 752 | applicationId, |
| 753 | null)); |
| 754 | rules.add(buildTmacRuleForMpls(ethCriterion, |
| 755 | vidCriterion, |
| 756 | ofdpaMatchVlanVid, |
| 757 | applicationId, |
| 758 | null)); |
| 759 | rules.add(buildTmacRuleForIpv6(ethCriterion, |
| 760 | vidCriterion, |
| 761 | ofdpaMatchVlanVid, |
| 762 | applicationId, |
| 763 | null)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 764 | } |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 765 | return ImmutableList.of(rules); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 768 | /** |
| 769 | * Builds TMAC rules for IPv4 packets. |
| 770 | * |
Charles Chan | 9174e6b | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 771 | * @param ethCriterion dst mac matching |
| 772 | * @param vidCriterion vlan id assigned to the port |
| 773 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 774 | * @param applicationId application id |
| 775 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 776 | * @return TMAC rule for IPV4 packets |
| 777 | */ |
| 778 | private FlowRule buildTmacRuleForIpv4(EthCriterion ethCriterion, |
| 779 | VlanIdCriterion vidCriterion, |
| 780 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 781 | ApplicationId applicationId, |
| 782 | PortNumber pnum) { |
| 783 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 784 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 785 | if (pnum != null) { |
| 786 | if (matchInPortTmacTable()) { |
| 787 | selector.matchInPort(pnum); |
| 788 | } else { |
Saurav Das | 73a6cc1 | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 789 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 790 | "ignoring the IN_PORT criteria"); |
| 791 | } |
| 792 | } |
| 793 | if (vidCriterion != null) { |
| 794 | if (requireVlanExtensions()) { |
| 795 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 796 | } else { |
| 797 | selector.matchVlanId(vidCriterion.vlanId()); |
| 798 | } |
| 799 | } |
| 800 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 801 | selector.matchEthDst(ethCriterion.mac()); |
| 802 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 803 | return DefaultFlowRule.builder() |
| 804 | .forDevice(deviceId) |
| 805 | .withSelector(selector.build()) |
| 806 | .withTreatment(treatment.build()) |
| 807 | .withPriority(DEFAULT_PRIORITY) |
| 808 | .fromApp(applicationId) |
| 809 | .makePermanent() |
| 810 | .forTable(TMAC_TABLE).build(); |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Builds TMAC rule for MPLS packets. |
| 815 | * |
Charles Chan | 9174e6b | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 816 | * @param ethCriterion dst mac matching |
| 817 | * @param vidCriterion vlan id assigned to the port |
| 818 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 819 | * @param applicationId application id |
| 820 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 821 | * @return TMAC rule for MPLS packets |
| 822 | */ |
| 823 | private FlowRule buildTmacRuleForMpls(EthCriterion ethCriterion, |
| 824 | VlanIdCriterion vidCriterion, |
| 825 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 826 | ApplicationId applicationId, |
| 827 | PortNumber pnum) { |
| 828 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 829 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 830 | if (pnum != null) { |
| 831 | if (matchInPortTmacTable()) { |
| 832 | selector.matchInPort(pnum); |
| 833 | } else { |
Saurav Das | 73a6cc1 | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 834 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 835 | "ignoring the IN_PORT criteria"); |
| 836 | } |
| 837 | } |
| 838 | if (vidCriterion != null) { |
| 839 | if (requireVlanExtensions()) { |
| 840 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 841 | } else { |
| 842 | selector.matchVlanId(vidCriterion.vlanId()); |
| 843 | } |
| 844 | } |
| 845 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 846 | selector.matchEthDst(ethCriterion.mac()); |
| 847 | treatment.transition(MPLS_TABLE_0); |
| 848 | return DefaultFlowRule.builder() |
| 849 | .forDevice(deviceId) |
| 850 | .withSelector(selector.build()) |
| 851 | .withTreatment(treatment.build()) |
| 852 | .withPriority(DEFAULT_PRIORITY) |
| 853 | .fromApp(applicationId) |
| 854 | .makePermanent() |
| 855 | .forTable(TMAC_TABLE).build(); |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Builds TMAC rules for IPv6 packets. |
| 860 | * |
Charles Chan | 9174e6b | 2017-12-19 19:55:57 -0800 | [diff] [blame] | 861 | * @param ethCriterion dst mac matching |
| 862 | * @param vidCriterion vlan id assigned to the port |
| 863 | * @param ofdpaMatchVlanVid OFDPA vlan id matching |
| 864 | * @param applicationId application id |
| 865 | * @param pnum port number |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 866 | * @return TMAC rule for IPV6 packets |
| 867 | */ |
| 868 | private FlowRule buildTmacRuleForIpv6(EthCriterion ethCriterion, |
| 869 | VlanIdCriterion vidCriterion, |
| 870 | OfdpaMatchVlanVid ofdpaMatchVlanVid, |
| 871 | ApplicationId applicationId, |
| 872 | PortNumber pnum) { |
| 873 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 874 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 875 | if (pnum != null) { |
| 876 | if (matchInPortTmacTable()) { |
| 877 | selector.matchInPort(pnum); |
| 878 | } else { |
Saurav Das | 73a6cc1 | 2017-12-05 15:00:23 -0800 | [diff] [blame] | 879 | log.debug("Pipeline does not support IN_PORT matching in TMAC table, " + |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 880 | "ignoring the IN_PORT criteria"); |
| 881 | } |
| 882 | } |
| 883 | if (vidCriterion != null) { |
| 884 | if (requireVlanExtensions()) { |
| 885 | selector.extension(ofdpaMatchVlanVid, deviceId); |
| 886 | } else { |
| 887 | selector.matchVlanId(vidCriterion.vlanId()); |
| 888 | } |
| 889 | } |
| 890 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 891 | selector.matchEthDst(ethCriterion.mac()); |
| 892 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 893 | return DefaultFlowRule.builder() |
| 894 | .forDevice(deviceId) |
| 895 | .withSelector(selector.build()) |
| 896 | .withTreatment(treatment.build()) |
| 897 | .withPriority(DEFAULT_PRIORITY) |
| 898 | .fromApp(applicationId) |
| 899 | .makePermanent() |
| 900 | .forTable(TMAC_TABLE).build(); |
| 901 | } |
| 902 | |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 903 | protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 904 | ApplicationId applicationId) { |
Pier Luigi | 0e35863 | 2017-01-31 09:35:05 -0800 | [diff] [blame] | 905 | ImmutableList.Builder<FlowRule> builder = ImmutableList.builder(); |
| 906 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 907 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 908 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 909 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 910 | selector.matchEthDst(ethCriterion.mac()); |
| 911 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 912 | FlowRule rule = DefaultFlowRule.builder() |
| 913 | .forDevice(deviceId) |
| 914 | .withSelector(selector.build()) |
| 915 | .withTreatment(treatment.build()) |
| 916 | .withPriority(DEFAULT_PRIORITY) |
| 917 | .fromApp(applicationId) |
| 918 | .makePermanent() |
| 919 | .forTable(TMAC_TABLE).build(); |
Pier Luigi | 0e35863 | 2017-01-31 09:35:05 -0800 | [diff] [blame] | 920 | builder.add(rule); |
| 921 | |
| 922 | selector = DefaultTrafficSelector.builder(); |
| 923 | treatment = DefaultTrafficTreatment.builder(); |
| 924 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 925 | selector.matchEthDst(ethCriterion.mac()); |
| 926 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 927 | rule = DefaultFlowRule.builder() |
| 928 | .forDevice(deviceId) |
| 929 | .withSelector(selector.build()) |
| 930 | .withTreatment(treatment.build()) |
| 931 | .withPriority(DEFAULT_PRIORITY) |
| 932 | .fromApp(applicationId) |
| 933 | .makePermanent() |
| 934 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 935 | return ImmutableList.of(builder.add(rule).build()); |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 936 | } |
| 937 | |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 938 | List<List<FlowRule>> processMcastEthDstFilter(EthCriterion ethCriterion, |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 939 | VlanId assignedVlan, |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 940 | MacAddress unicastMac, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 941 | ApplicationId applicationId) { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 942 | ImmutableList.Builder<FlowRule> unicastFlows = ImmutableList.builder(); |
| 943 | ImmutableList.Builder<FlowRule> multicastFlows = ImmutableList.builder(); |
| 944 | TrafficSelector.Builder selector; |
| 945 | TrafficTreatment.Builder treatment; |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 946 | FlowRule rule; |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 947 | |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 948 | if (IPV4_MULTICAST.equals(ethCriterion.mac())) { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 949 | if (requireUnicastBeforeMulticast()) { |
| 950 | selector = DefaultTrafficSelector.builder(); |
| 951 | treatment = DefaultTrafficTreatment.builder(); |
| 952 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 953 | selector.matchEthDst(unicastMac); |
| 954 | selector.matchVlanId(assignedVlan); |
| 955 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 956 | rule = DefaultFlowRule.builder() |
| 957 | .forDevice(deviceId) |
| 958 | .withSelector(selector.build()) |
| 959 | .withTreatment(treatment.build()) |
| 960 | .withPriority(DEFAULT_PRIORITY) |
| 961 | .fromApp(applicationId) |
| 962 | .makePermanent() |
| 963 | .forTable(TMAC_TABLE).build(); |
| 964 | unicastFlows.add(rule); |
| 965 | } |
| 966 | |
| 967 | selector = DefaultTrafficSelector.builder(); |
| 968 | treatment = DefaultTrafficTreatment.builder(); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 969 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 970 | selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask()); |
| 971 | selector.matchVlanId(assignedVlan); |
| 972 | treatment.transition(MULTICAST_ROUTING_TABLE); |
| 973 | rule = DefaultFlowRule.builder() |
| 974 | .forDevice(deviceId) |
| 975 | .withSelector(selector.build()) |
| 976 | .withTreatment(treatment.build()) |
| 977 | .withPriority(DEFAULT_PRIORITY) |
| 978 | .fromApp(applicationId) |
| 979 | .makePermanent() |
| 980 | .forTable(TMAC_TABLE).build(); |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 981 | multicastFlows.add(rule); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | if (IPV6_MULTICAST.equals(ethCriterion.mac())) { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 985 | if (requireUnicastBeforeMulticast()) { |
| 986 | selector = DefaultTrafficSelector.builder(); |
| 987 | treatment = DefaultTrafficTreatment.builder(); |
| 988 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 989 | selector.matchEthDst(unicastMac); |
| 990 | selector.matchVlanId(assignedVlan); |
| 991 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 992 | rule = DefaultFlowRule.builder() |
| 993 | .forDevice(deviceId) |
| 994 | .withSelector(selector.build()) |
| 995 | .withTreatment(treatment.build()) |
| 996 | .withPriority(DEFAULT_PRIORITY) |
| 997 | .fromApp(applicationId) |
| 998 | .makePermanent() |
| 999 | .forTable(TMAC_TABLE).build(); |
| 1000 | unicastFlows.add(rule); |
| 1001 | } |
| 1002 | |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1003 | selector = DefaultTrafficSelector.builder(); |
| 1004 | treatment = DefaultTrafficTreatment.builder(); |
| 1005 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 1006 | selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask()); |
| 1007 | selector.matchVlanId(assignedVlan); |
| 1008 | treatment.transition(MULTICAST_ROUTING_TABLE); |
| 1009 | rule = DefaultFlowRule.builder() |
| 1010 | .forDevice(deviceId) |
| 1011 | .withSelector(selector.build()) |
| 1012 | .withTreatment(treatment.build()) |
| 1013 | .withPriority(DEFAULT_PRIORITY) |
| 1014 | .fromApp(applicationId) |
| 1015 | .makePermanent() |
| 1016 | .forTable(TMAC_TABLE).build(); |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1017 | multicastFlows.add(rule); |
Charles Chan | b4879a5 | 2017-10-20 19:09:16 -0700 | [diff] [blame] | 1018 | } |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1019 | return ImmutableList.of(unicastFlows.build(), multicastFlows.build()); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1022 | private Collection<FlowRule> processForward(ForwardingObjective fwd) { |
| 1023 | switch (fwd.flag()) { |
| 1024 | case SPECIFIC: |
| 1025 | return processSpecific(fwd); |
| 1026 | case VERSATILE: |
| 1027 | return processVersatile(fwd); |
| 1028 | default: |
| 1029 | fail(fwd, ObjectiveError.UNKNOWN); |
| 1030 | log.warn("Unknown forwarding flag {}", fwd.flag()); |
| 1031 | } |
| 1032 | return Collections.emptySet(); |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the |
| 1037 | * ACL table. |
| 1038 | * @param fwd the forwarding objective of type 'versatile' |
| 1039 | * @return a collection of flow rules to be sent to the switch. An empty |
| 1040 | * collection may be returned if there is a problem in processing |
| 1041 | * the flow rule |
| 1042 | */ |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1043 | protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
Saurav Das | 018605f | 2017-02-18 14:05:44 -0800 | [diff] [blame] | 1044 | log.debug("Processing versatile forwarding objective:{} in dev:{}", |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1045 | fwd.id(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1046 | |
| 1047 | EthTypeCriterion ethType = |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1048 | (EthTypeCriterion) fwd.selector().getCriterion(Criterion.Type.ETH_TYPE); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1049 | if (ethType == null) { |
Saurav Das | d2fded0 | 2016-12-02 15:43:47 -0800 | [diff] [blame] | 1050 | log.error("Versatile forwarding objective:{} must include ethType", |
| 1051 | fwd.id()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1052 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1053 | return Collections.emptySet(); |
| 1054 | } |
| 1055 | if (fwd.nextId() == null && fwd.treatment() == null) { |
| 1056 | log.error("Forwarding objective {} from {} must contain " |
| 1057 | + "nextId or Treatment", fwd.selector(), fwd.appId()); |
Zsolt Haraszti | 9faab75 | 2016-02-17 15:55:20 -0800 | [diff] [blame] | 1058 | fail(fwd, ObjectiveError.BADPARAMS); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1059 | return Collections.emptySet(); |
| 1060 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1061 | |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1062 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1063 | fwd.selector().criteria().forEach(criterion -> { |
| 1064 | if (criterion instanceof VlanIdCriterion) { |
| 1065 | VlanId vlanId = ((VlanIdCriterion) criterion).vlanId(); |
| 1066 | // ensure that match does not include vlan = NONE as OF-DPA does not |
| 1067 | // match untagged packets this way in the ACL table. |
| 1068 | if (vlanId.equals(VlanId.NONE)) { |
| 1069 | return; |
| 1070 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1071 | if (requireVlanExtensions()) { |
| 1072 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanId); |
| 1073 | sbuilder.extension(ofdpaMatchVlanVid, deviceId); |
| 1074 | } else { |
| 1075 | sbuilder.matchVlanId(vlanId); |
| 1076 | } |
Charles Chan | 393339f | 2018-01-11 11:48:18 -0800 | [diff] [blame] | 1077 | } else if (criterion instanceof Icmpv6TypeCriterion) { |
| 1078 | byte icmpv6Type = (byte) ((Icmpv6TypeCriterion) criterion).icmpv6Type(); |
| 1079 | sbuilder.matchIcmpv6Type(icmpv6Type); |
| 1080 | } else if (criterion instanceof Icmpv6CodeCriterion) { |
| 1081 | byte icmpv6Code = (byte) ((Icmpv6CodeCriterion) criterion).icmpv6Code(); |
| 1082 | sbuilder.matchIcmpv6Type(icmpv6Code); |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1083 | } else if (criterion instanceof TcpPortCriterion || criterion instanceof UdpPortCriterion) { |
| 1084 | // FIXME: QMX switches do not support L4 dst port matching in ACL table. |
| 1085 | // Currently L4 dst port matching is only used by DHCP relay feature |
| 1086 | // and therefore is safe to be replaced with L4 src port matching. |
| 1087 | // We need to revisit this if L4 dst port is used for other purpose in the future. |
| 1088 | if (!supportIpv6L4Dst() && isIpv6(fwd.selector())) { |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1089 | switch (criterion.type()) { |
| 1090 | case UDP_DST: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1091 | case UDP_DST_MASKED: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1092 | case TCP_DST: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1093 | case TCP_DST_MASKED: |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1094 | break; |
| 1095 | default: |
| 1096 | sbuilder.add(criterion); |
| 1097 | } |
| 1098 | } else { |
| 1099 | sbuilder.add(criterion); |
| 1100 | } |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1101 | } else { |
| 1102 | sbuilder.add(criterion); |
| 1103 | } |
| 1104 | }); |
| 1105 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1106 | // XXX driver does not currently do type checking as per Tables 65-67 in |
| 1107 | // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller. |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1108 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 1109 | if (fwd.treatment() != null) { |
| 1110 | for (Instruction ins : fwd.treatment().allInstructions()) { |
| 1111 | if (ins instanceof OutputInstruction) { |
| 1112 | OutputInstruction o = (OutputInstruction) ins; |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1113 | if (PortNumber.CONTROLLER.equals(o.port())) { |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1114 | ttBuilder.add(o); |
| 1115 | } else { |
| 1116 | log.warn("Only allowed treatments in versatile forwarding " |
| 1117 | + "objectives are punts to the controller"); |
| 1118 | } |
| 1119 | } else { |
| 1120 | log.warn("Cannot process instruction in versatile fwd {}", ins); |
| 1121 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1122 | } |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 1123 | if (fwd.treatment().clearedDeferred()) { |
| 1124 | ttBuilder.wipeDeferred(); |
| 1125 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1126 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1127 | if (fwd.nextId() != null) { |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1128 | // overide case |
| 1129 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
Sivachidambaram Subramanian | a0efdcc | 2017-06-22 05:26:46 +0530 | [diff] [blame] | 1130 | if (next == null) { |
| 1131 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1132 | return Collections.emptySet(); |
| 1133 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1134 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1135 | // we only need the top level group's key to point the flow to it |
| 1136 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1137 | if (group == null) { |
| 1138 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1139 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1140 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1141 | return Collections.emptySet(); |
| 1142 | } |
| 1143 | ttBuilder.deferred().group(group.id()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1144 | } |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1145 | |
| 1146 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1147 | .fromApp(fwd.appId()) |
| 1148 | .withPriority(fwd.priority()) |
| 1149 | .forDevice(deviceId) |
Saurav Das | 77b5e90 | 2016-01-27 17:01:59 -0800 | [diff] [blame] | 1150 | .withSelector(sbuilder.build()) |
Saurav Das | 49cb5a1 | 2016-01-16 22:54:07 -0800 | [diff] [blame] | 1151 | .withTreatment(ttBuilder.build()) |
| 1152 | .makePermanent() |
| 1153 | .forTable(ACL_TABLE); |
| 1154 | return Collections.singletonList(ruleBuilder.build()); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /** |
| 1158 | * In the OF-DPA 2.0 pipeline, specific forwarding refers to the IP table |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1159 | * (unicast or multicast) or the L2 table (mac + vlan) or the MPLS table. |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1160 | * |
| 1161 | * @param fwd the forwarding objective of type 'specific' |
| 1162 | * @return a collection of flow rules. Typically there will be only one |
| 1163 | * for this type of forwarding objective. An empty set may be |
| 1164 | * returned if there is an issue in processing the objective. |
| 1165 | */ |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1166 | private Collection<FlowRule> processSpecific(ForwardingObjective fwd) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1167 | log.debug("Processing specific fwd objective:{} in dev:{} with next:{}", |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1168 | fwd.id(), deviceId, fwd.nextId()); |
| 1169 | boolean isEthTypeObj = isSupportedEthTypeObjective(fwd); |
| 1170 | boolean isEthDstObj = isSupportedEthDstObjective(fwd); |
| 1171 | |
| 1172 | if (isEthTypeObj) { |
| 1173 | return processEthTypeSpecific(fwd); |
| 1174 | } else if (isEthDstObj) { |
| 1175 | return processEthDstSpecific(fwd); |
| 1176 | } else { |
| 1177 | log.warn("processSpecific: Unsupported forwarding objective " |
| 1178 | + "criteria fwd:{} in dev:{}", fwd.nextId(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1179 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 1180 | return Collections.emptySet(); |
| 1181 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1184 | /** |
| 1185 | * Handles forwarding rules to the IP and MPLS tables. |
| 1186 | * |
| 1187 | * @param fwd the forwarding objective |
| 1188 | * @return A collection of flow rules, or an empty set |
| 1189 | */ |
| 1190 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1191 | return processEthTypeSpecificInternal(fwd, false, ACL_TABLE); |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /** |
| 1195 | * Internal implementation of processEthTypeSpecific. |
| 1196 | * <p> |
| 1197 | * Wildcarded IPv4_DST is not supported in OFDPA i12. Therefore, we break |
| 1198 | * the rule into 0.0.0.0/1 and 128.0.0.0/1. |
| 1199 | * The allowDefaultRoute must be set to false for OFDPA i12. |
| 1200 | * </p> |
| 1201 | * |
| 1202 | * @param fwd the forwarding objective |
| 1203 | * @param allowDefaultRoute allow wildcarded IPv4_DST or not |
Ray Milkey | 0bb1e10 | 2016-11-10 14:51:27 -0800 | [diff] [blame] | 1204 | * @param mplsNextTable next MPLS table |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1205 | * @return A collection of flow rules, or an empty set |
| 1206 | */ |
| 1207 | protected Collection<FlowRule> processEthTypeSpecificInternal(ForwardingObjective fwd, |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1208 | boolean allowDefaultRoute, |
| 1209 | int mplsNextTable) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1210 | TrafficSelector selector = fwd.selector(); |
| 1211 | EthTypeCriterion ethType = |
| 1212 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1213 | boolean emptyGroup = false; |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1214 | int forTableId; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1215 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1216 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1217 | TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder(); |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1218 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1219 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1220 | if (buildIpv4Selector(filteredSelector, complementarySelector, fwd, allowDefaultRoute) < 0) { |
| 1221 | return Collections.emptyList(); |
| 1222 | } |
| 1223 | // We need to set properly the next table |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1224 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1225 | if (ipv4Dst.isMulticast()) { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1226 | forTableId = MULTICAST_ROUTING_TABLE; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1227 | } else { |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1228 | forTableId = UNICAST_ROUTING_TABLE; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1229 | } |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1230 | |
Charles Chan | 7feb6c8 | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1231 | // TODO decrementing IP ttl is done automatically for routing, this |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1232 | // action is ignored or rejected in ofdpa as it is not fully implemented |
Charles Chan | 7feb6c8 | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1233 | // if (fwd.treatment() != null) { |
| 1234 | // for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1235 | // if (instr instanceof L3ModificationInstruction && |
| 1236 | // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1237 | // tb.deferred().add(instr); |
| 1238 | // } |
| 1239 | // } |
| 1240 | // } |
| 1241 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1242 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) { |
| 1243 | if (buildIpv6Selector(filteredSelector, fwd) < 0) { |
| 1244 | return Collections.emptyList(); |
| 1245 | } |
Kalhee Kim | 3d26bf0 | 2017-10-04 14:59:11 +0000 | [diff] [blame] | 1246 | //We need to set the proper next table |
| 1247 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 1248 | if (ipv6Dst.isMulticast()) { |
| 1249 | forTableId = MULTICAST_ROUTING_TABLE; |
| 1250 | } else { |
| 1251 | forTableId = UNICAST_ROUTING_TABLE; |
| 1252 | } |
| 1253 | |
Charles Chan | 7feb6c8 | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1254 | // TODO decrementing IP ttl is done automatically for routing, this |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1255 | // action is ignored or rejected in ofdpa as it is not fully implemented |
Charles Chan | 7feb6c8 | 2018-03-05 11:28:23 -0800 | [diff] [blame] | 1256 | // if (fwd.treatment() != null) { |
| 1257 | // for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1258 | // if (instr instanceof L3ModificationInstruction && |
| 1259 | // ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1260 | // tb.deferred().add(instr); |
| 1261 | // } |
| 1262 | // } |
| 1263 | // } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1264 | } else { |
| 1265 | filteredSelector |
| 1266 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 1267 | .matchMplsLabel(((MplsCriterion) |
| 1268 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 1269 | MplsBosCriterion bos = (MplsBosCriterion) selector |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1270 | .getCriterion(MPLS_BOS); |
Alex Yashchuk | a367953 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1271 | if (bos != null && requireMplsBosMatch()) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1272 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 1273 | } |
| 1274 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1275 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 1276 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1277 | |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1278 | if (fwd.treatment() != null) { |
| 1279 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1280 | if (instr instanceof L2ModificationInstruction && |
| 1281 | ((L2ModificationInstruction) instr).subtype() == L2SubType.MPLS_POP) { |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1282 | // OF-DPA does not pop in MPLS table in some cases. For the L3 VPN, it requires |
Saurav Das | 9c70534 | 2017-01-06 11:36:01 -0800 | [diff] [blame] | 1283 | // setting the MPLS_TYPE so pop can happen down the pipeline |
Alex Yashchuk | a367953 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1284 | if (requireMplsPop()) { |
| 1285 | if (mplsNextTable == MPLS_TYPE_TABLE && isNotMplsBos(selector)) { |
| 1286 | tb.immediate().popMpls(); |
| 1287 | } |
| 1288 | } else { |
| 1289 | // Skip mpls pop action for mpls_unicast label |
| 1290 | if (instr instanceof ModMplsHeaderInstruction && |
| 1291 | !((ModMplsHeaderInstruction) instr).ethernetType() |
| 1292 | .equals(EtherType.MPLS_UNICAST.ethType())) { |
| 1293 | tb.immediate().add(instr); |
| 1294 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1295 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1296 | } |
Alex Yashchuk | a367953 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1297 | |
| 1298 | if (requireMplsTtlModification()) { |
| 1299 | if (instr instanceof L3ModificationInstruction && |
| 1300 | ((L3ModificationInstruction) instr).subtype() == L3SubType.DEC_TTL) { |
| 1301 | // FIXME Should modify the app to send the correct DEC_MPLS_TTL instruction |
| 1302 | tb.immediate().decMplsTtl(); |
| 1303 | } |
| 1304 | if (instr instanceof L3ModificationInstruction && |
| 1305 | ((L3ModificationInstruction) instr).subtype() == L3SubType.TTL_IN) { |
| 1306 | tb.immediate().add(instr); |
| 1307 | } |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 1308 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1312 | |
| 1313 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1314 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 1315 | if (next != null) { |
| 1316 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1317 | // we only need the top level group's key to point the flow to it |
| 1318 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1319 | if (group == null) { |
| 1320 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1321 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1322 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1323 | return Collections.emptySet(); |
| 1324 | } |
Saurav Das | a89b95a | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1325 | if (isNotMplsBos(selector) && group.type().equals(SELECT)) { |
| 1326 | log.warn("SR CONTINUE case cannot be handled as MPLS ECMP " |
| 1327 | + "is not implemented in OF-DPA yet. Aborting flow {} -> next:{} " |
| 1328 | + "in this device {}", fwd.id(), fwd.nextId(), deviceId); |
| 1329 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 1330 | return Collections.emptySet(); |
| 1331 | } |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1332 | tb.deferred().group(group.id()); |
Saurav Das | f3f7594 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1333 | // retrying flows may be necessary due to bug CORD-554 |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1334 | if (gkeys.size() == 1 && gkeys.get(0).size() == 1) { |
Saurav Das | f3f7594 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1335 | if (shouldRetry()) { |
| 1336 | log.warn("Found empty group 0x{} in dev:{} .. will retry fwd:{}", |
| 1337 | Integer.toHexString(group.id().id()), deviceId, |
| 1338 | fwd.id()); |
| 1339 | emptyGroup = true; |
| 1340 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1341 | } |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1342 | } else { |
| 1343 | log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", |
| 1344 | fwd.nextId(), deviceId, fwd.id()); |
| 1345 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 1346 | return Collections.emptySet(); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1347 | } |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1348 | } |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1349 | |
| 1350 | if (forTableId == MPLS_TABLE_1) { |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1351 | if (mplsNextTable == MPLS_L3_TYPE_TABLE) { |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1352 | Ofdpa3SetMplsType setMplsType = new Ofdpa3SetMplsType(Ofdpa3MplsType.L3_PHP); |
Saurav Das | 9c70534 | 2017-01-06 11:36:01 -0800 | [diff] [blame] | 1353 | // set mpls type as apply_action |
| 1354 | tb.immediate().extension(setMplsType, deviceId); |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1355 | } |
| 1356 | tb.transition(mplsNextTable); |
| 1357 | } else { |
| 1358 | tb.transition(ACL_TABLE); |
| 1359 | } |
| 1360 | |
Andrea Campanella | 84ac4df | 2018-04-30 11:48:55 +0200 | [diff] [blame] | 1361 | if (fwd.treatment() != null && fwd.treatment().clearedDeferred()) { |
| 1362 | if (supportsUnicastBlackHole()) { |
| 1363 | tb.wipeDeferred(); |
| 1364 | } else { |
| 1365 | log.warn("Clear Deferred is not supported Unicast Routing Table on device {}", deviceId); |
| 1366 | return Collections.emptySet(); |
| 1367 | } |
| 1368 | } |
| 1369 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1370 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1371 | .fromApp(fwd.appId()) |
| 1372 | .withPriority(fwd.priority()) |
| 1373 | .forDevice(deviceId) |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1374 | .withSelector(filteredSelector.build()) |
| 1375 | .withTreatment(tb.build()) |
| 1376 | .forTable(forTableId); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1377 | |
| 1378 | if (fwd.permanent()) { |
| 1379 | ruleBuilder.makePermanent(); |
| 1380 | } else { |
| 1381 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 1382 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1383 | Collection<FlowRule> flowRuleCollection = new ArrayList<>(); |
| 1384 | flowRuleCollection.add(ruleBuilder.build()); |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1385 | if (!allowDefaultRoute) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1386 | flowRuleCollection.add( |
| 1387 | defaultRoute(fwd, complementarySelector, forTableId, tb) |
| 1388 | ); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1389 | log.debug("Default rule 0.0.0.0/0 is being installed two rules"); |
| 1390 | } |
Saurav Das | f3f7594 | 2018-01-25 09:49:01 -0800 | [diff] [blame] | 1391 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1392 | if (emptyGroup) { |
| 1393 | executorService.schedule(new RetryFlows(fwd, flowRuleCollection), |
| 1394 | RETRY_MS, TimeUnit.MILLISECONDS); |
| 1395 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1396 | return flowRuleCollection; |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1399 | private int buildIpv4Selector(TrafficSelector.Builder builderToUpdate, |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1400 | TrafficSelector.Builder extBuilder, |
| 1401 | ForwardingObjective fwd, |
| 1402 | boolean allowDefaultRoute) { |
| 1403 | TrafficSelector selector = fwd.selector(); |
| 1404 | |
| 1405 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
| 1406 | if (ipv4Dst.isMulticast()) { |
| 1407 | if (ipv4Dst.prefixLength() != 32) { |
| 1408 | log.warn("Multicast specific forwarding objective can only be /32"); |
| 1409 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1410 | return -1; |
| 1411 | } |
| 1412 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1413 | if (assignedVlan == null) { |
| 1414 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1415 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1416 | return -1; |
| 1417 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1418 | if (requireVlanExtensions()) { |
| 1419 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 1420 | builderToUpdate.extension(ofdpaMatchVlanVid, deviceId); |
| 1421 | } else { |
| 1422 | builderToUpdate.matchVlanId(assignedVlan); |
| 1423 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1424 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 1425 | log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}" |
| 1426 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1427 | } else { |
| 1428 | if (ipv4Dst.prefixLength() == 0) { |
| 1429 | if (allowDefaultRoute) { |
| 1430 | // The entire IPV4_DST field is wildcarded intentionally |
| 1431 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4); |
| 1432 | } else { |
| 1433 | // NOTE: The switch does not support matching 0.0.0.0/0 |
| 1434 | // Split it into 0.0.0.0/1 and 128.0.0.0/1 |
| 1435 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4) |
| 1436 | .matchIPDst(IpPrefix.valueOf("0.0.0.0/1")); |
| 1437 | extBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 1438 | .matchIPDst(IpPrefix.valueOf("128.0.0.0/1")); |
| 1439 | } |
| 1440 | } else { |
| 1441 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 1442 | } |
| 1443 | log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}" |
| 1444 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1445 | } |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
| 1449 | /** |
| 1450 | * Helper method to build Ipv6 selector using the selector provided by |
| 1451 | * a forwarding objective. |
| 1452 | * |
| 1453 | * @param builderToUpdate the builder to update |
| 1454 | * @param fwd the selector to read |
| 1455 | * @return 0 if the update ends correctly. -1 if the matches |
| 1456 | * are not yet supported |
| 1457 | */ |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1458 | int buildIpv6Selector(TrafficSelector.Builder builderToUpdate, |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1459 | ForwardingObjective fwd) { |
| 1460 | |
| 1461 | TrafficSelector selector = fwd.selector(); |
| 1462 | |
| 1463 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 1464 | if (ipv6Dst.isMulticast()) { |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1465 | if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) { |
| 1466 | log.warn("Multicast specific forwarding objective can only be /128"); |
| 1467 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1468 | return -1; |
| 1469 | } |
| 1470 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1471 | if (assignedVlan == null) { |
| 1472 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1473 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1474 | return -1; |
| 1475 | } |
| 1476 | if (requireVlanExtensions()) { |
| 1477 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(assignedVlan); |
| 1478 | builderToUpdate.extension(ofdpaMatchVlanVid, deviceId); |
| 1479 | } else { |
| 1480 | builderToUpdate.matchVlanId(assignedVlan); |
| 1481 | } |
| 1482 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst); |
| 1483 | log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" |
| 1484 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1485 | } else { |
| 1486 | if (ipv6Dst.prefixLength() != 0) { |
| 1487 | builderToUpdate.matchIPv6Dst(ipv6Dst); |
| 1488 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1489 | builderToUpdate.matchEthType(Ethernet.TYPE_IPV6); |
| 1490 | log.debug("processing IPv6 unicast specific forwarding objective {} -> next:{}" |
| 1491 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1492 | } |
Pier Luigi | 3bfe32c | 2017-01-30 09:47:36 -0800 | [diff] [blame] | 1493 | return 0; |
| 1494 | } |
| 1495 | |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1496 | FlowRule defaultRoute(ForwardingObjective fwd, |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1497 | TrafficSelector.Builder complementarySelector, |
| 1498 | int forTableId, |
| 1499 | TrafficTreatment.Builder tb) { |
| 1500 | FlowRule.Builder rule = DefaultFlowRule.builder() |
| 1501 | .fromApp(fwd.appId()) |
| 1502 | .withPriority(fwd.priority()) |
| 1503 | .forDevice(deviceId) |
| 1504 | .withSelector(complementarySelector.build()) |
| 1505 | .withTreatment(tb.build()) |
| 1506 | .forTable(forTableId); |
| 1507 | if (fwd.permanent()) { |
| 1508 | rule.makePermanent(); |
| 1509 | } else { |
| 1510 | rule.makeTemporary(fwd.timeout()); |
| 1511 | } |
| 1512 | return rule.build(); |
| 1513 | } |
| 1514 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1515 | /** |
| 1516 | * Handles forwarding rules to the L2 bridging table. Flow actions are not |
| 1517 | * allowed in the bridging table - instead we use L2 Interface group or |
| 1518 | * L2 flood group |
| 1519 | * |
| 1520 | * @param fwd the forwarding objective |
| 1521 | * @return A collection of flow rules, or an empty set |
| 1522 | */ |
| 1523 | protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { |
| 1524 | List<FlowRule> rules = new ArrayList<>(); |
| 1525 | |
| 1526 | // Build filtered selector |
| 1527 | TrafficSelector selector = fwd.selector(); |
| 1528 | EthCriterion ethCriterion = (EthCriterion) selector |
| 1529 | .getCriterion(Criterion.Type.ETH_DST); |
| 1530 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector |
| 1531 | .getCriterion(Criterion.Type.VLAN_VID); |
| 1532 | |
| 1533 | if (vlanIdCriterion == null) { |
| 1534 | log.warn("Forwarding objective for bridging requires vlan. Not " |
| 1535 | + "installing fwd:{} in dev:{}", fwd.id(), deviceId); |
| 1536 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1537 | return Collections.emptySet(); |
| 1538 | } |
| 1539 | |
| 1540 | TrafficSelector.Builder filteredSelectorBuilder = |
| 1541 | DefaultTrafficSelector.builder(); |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 1542 | |
| 1543 | if (!ethCriterion.mac().equals(NONE) && |
| 1544 | !ethCriterion.mac().equals(BROADCAST)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1545 | filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); |
| 1546 | log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", |
| 1547 | fwd.id(), fwd.nextId(), deviceId); |
| 1548 | } else { |
Yi Tseng | 3a77b4f | 2017-02-06 15:02:17 -0800 | [diff] [blame] | 1549 | // Use wildcard DST_MAC if the MacAddress is None or Broadcast |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1550 | log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " |
| 1551 | + "in dev:{} for vlan:{}", |
| 1552 | fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); |
| 1553 | } |
Charles Chan | d117263 | 2017-03-15 17:33:09 -0700 | [diff] [blame] | 1554 | if (requireVlanExtensions()) { |
| 1555 | OfdpaMatchVlanVid ofdpaMatchVlanVid = new OfdpaMatchVlanVid(vlanIdCriterion.vlanId()); |
| 1556 | filteredSelectorBuilder.extension(ofdpaMatchVlanVid, deviceId); |
| 1557 | } else { |
| 1558 | filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); |
| 1559 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1560 | TrafficSelector filteredSelector = filteredSelectorBuilder.build(); |
| 1561 | |
| 1562 | if (fwd.treatment() != null) { |
| 1563 | log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" |
| 1564 | + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); |
| 1565 | } |
| 1566 | |
| 1567 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1568 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1569 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1570 | if (next != null) { |
| 1571 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1572 | // we only need the top level group's key to point the flow to it |
| 1573 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1574 | if (group != null) { |
| 1575 | treatmentBuilder.deferred().group(group.id()); |
| 1576 | } else { |
| 1577 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1578 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1579 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1580 | return Collections.emptySet(); |
| 1581 | } |
| 1582 | } |
| 1583 | } |
| 1584 | treatmentBuilder.immediate().transition(ACL_TABLE); |
| 1585 | TrafficTreatment filteredTreatment = treatmentBuilder.build(); |
| 1586 | |
| 1587 | // Build bridging table entries |
| 1588 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); |
| 1589 | flowRuleBuilder.fromApp(fwd.appId()) |
| 1590 | .withPriority(fwd.priority()) |
| 1591 | .forDevice(deviceId) |
| 1592 | .withSelector(filteredSelector) |
| 1593 | .withTreatment(filteredTreatment) |
| 1594 | .forTable(BRIDGING_TABLE); |
| 1595 | if (fwd.permanent()) { |
| 1596 | flowRuleBuilder.makePermanent(); |
| 1597 | } else { |
| 1598 | flowRuleBuilder.makeTemporary(fwd.timeout()); |
| 1599 | } |
| 1600 | rules.add(flowRuleBuilder.build()); |
| 1601 | return rules; |
| 1602 | } |
| 1603 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1604 | ////////////////////////////////////// |
| 1605 | // Helper Methods and Classes |
| 1606 | ////////////////////////////////////// |
| 1607 | |
| 1608 | private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) { |
| 1609 | TrafficSelector selector = fwd.selector(); |
| 1610 | EthTypeCriterion ethType = (EthTypeCriterion) selector |
| 1611 | .getCriterion(Criterion.Type.ETH_TYPE); |
| 1612 | return !((ethType == null) || |
| 1613 | ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1614 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) && |
| 1615 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | private boolean isSupportedEthDstObjective(ForwardingObjective fwd) { |
| 1619 | TrafficSelector selector = fwd.selector(); |
| 1620 | EthCriterion ethDst = (EthCriterion) selector |
| 1621 | .getCriterion(Criterion.Type.ETH_DST); |
| 1622 | VlanIdCriterion vlanId = (VlanIdCriterion) selector |
| 1623 | .getCriterion(Criterion.Type.VLAN_VID); |
| 1624 | return !(ethDst == null && vlanId == null); |
| 1625 | } |
| 1626 | |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1627 | NextGroup getGroupForNextObjective(Integer nextId) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1628 | NextGroup next = flowObjectiveStore.getNextGroup(nextId); |
| 1629 | if (next != null) { |
| 1630 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1631 | if (gkeys != null && !gkeys.isEmpty()) { |
| 1632 | return next; |
| 1633 | } else { |
| 1634 | log.warn("Empty next group found in FlowObjective store for " |
| 1635 | + "next-id:{} in dev:{}", nextId, deviceId); |
| 1636 | } |
| 1637 | } else { |
| 1638 | log.warn("next-id {} not found in Flow objective store for dev:{}", |
| 1639 | nextId, deviceId); |
| 1640 | } |
| 1641 | return null; |
| 1642 | } |
| 1643 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1644 | protected static void pass(Objective obj) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 1645 | obj.context().ifPresent(context -> context.onSuccess(obj)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 1648 | protected static void fail(Objective obj, ObjectiveError error) { |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 1649 | obj.context().ifPresent(context -> context.onError(obj, error)); |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1650 | } |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1651 | |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1652 | @Override |
| 1653 | public List<String> getNextMappings(NextGroup nextGroup) { |
| 1654 | List<String> mappings = new ArrayList<>(); |
| 1655 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(nextGroup.data()); |
| 1656 | for (Deque<GroupKey> gkd : gkeys) { |
| 1657 | Group lastGroup = null; |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 1658 | StringBuilder gchain = new StringBuilder(); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1659 | for (GroupKey gk : gkd) { |
| 1660 | Group g = groupService.getGroup(deviceId, gk); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1661 | if (g == null) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1662 | gchain.append(" NoGrp").append(" -->"); |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1663 | continue; |
| 1664 | } |
| 1665 | gchain.append(" 0x").append(Integer.toHexString(g.id().id())) |
| 1666 | .append(" -->"); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1667 | lastGroup = g; |
| 1668 | } |
| 1669 | // add port information for last group in group-chain |
Yuta HIGUCHI | 2dce08a | 2017-04-20 21:57:48 -0700 | [diff] [blame] | 1670 | List<Instruction> lastGroupIns = new ArrayList<>(); |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1671 | if (lastGroup != null && !lastGroup.buckets().buckets().isEmpty()) { |
Saurav Das | 2519081 | 2016-05-27 13:54:07 -0700 | [diff] [blame] | 1672 | lastGroupIns = lastGroup.buckets().buckets().get(0) |
| 1673 | .treatment().allInstructions(); |
| 1674 | } |
| 1675 | for (Instruction i: lastGroupIns) { |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1676 | if (i instanceof OutputInstruction) { |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1677 | gchain.append(" port:").append(((OutputInstruction) i).port()); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1678 | } |
| 1679 | } |
Saurav Das | 8be4e3a | 2016-03-11 17:19:07 -0800 | [diff] [blame] | 1680 | mappings.add(gchain.toString()); |
Saurav Das | 2443119 | 2016-03-07 19:13:00 -0800 | [diff] [blame] | 1681 | } |
| 1682 | return mappings; |
| 1683 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1684 | |
Saurav Das | a89b95a | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1685 | /** |
| 1686 | * Returns true iff the given selector matches on BOS==true, indicating that |
| 1687 | * the selector is trying to match on a label that is bottom-of-stack. |
| 1688 | * |
| 1689 | * @param selector the given match |
| 1690 | * @return true iff BoS==true; false if BOS==false, or BOS matching is not |
| 1691 | * expressed in the given selector |
| 1692 | */ |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1693 | static boolean isMplsBos(TrafficSelector selector) { |
| 1694 | MplsBosCriterion bosCriterion = (MplsBosCriterion) selector.getCriterion(MPLS_BOS); |
| 1695 | return bosCriterion != null && bosCriterion.mplsBos(); |
| 1696 | } |
| 1697 | |
Saurav Das | a89b95a | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1698 | /** |
| 1699 | * Returns true iff the given selector matches on BOS==false, indicating |
| 1700 | * that the selector is trying to match on a label that is not the |
| 1701 | * bottom-of-stack label. |
| 1702 | * |
| 1703 | * @param selector the given match |
| 1704 | * @return true iff BoS==false; |
| 1705 | * false if BOS==true, or BOS matching is not expressed in the given selector |
| 1706 | */ |
Pier Ventre | 140a894 | 2016-11-02 07:26:38 -0700 | [diff] [blame] | 1707 | static boolean isNotMplsBos(TrafficSelector selector) { |
| 1708 | MplsBosCriterion bosCriterion = (MplsBosCriterion) selector.getCriterion(MPLS_BOS); |
| 1709 | return bosCriterion != null && !bosCriterion.mplsBos(); |
| 1710 | } |
| 1711 | |
Saurav Das | a89b95a | 2018-02-14 14:14:54 -0800 | [diff] [blame] | 1712 | /** |
| 1713 | * Returns true iff the forwarding objective includes a treatment to pop the |
| 1714 | * MPLS label. |
| 1715 | * |
| 1716 | * @param fwd the given forwarding objective |
| 1717 | * @return true iff mpls pop treatment exists |
| 1718 | */ |
| 1719 | static boolean isMplsPop(ForwardingObjective fwd) { |
| 1720 | if (fwd.treatment() != null) { |
| 1721 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 1722 | if (instr instanceof L2ModificationInstruction |
| 1723 | && ((L2ModificationInstruction) instr) |
| 1724 | .subtype() == L2SubType.MPLS_POP) { |
| 1725 | return true; |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | return false; |
| 1730 | } |
| 1731 | |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1732 | private static boolean isIpv6(TrafficSelector selector) { |
| 1733 | EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) selector.getCriterion(ETH_TYPE); |
| 1734 | return ethTypeCriterion != null && ethTypeCriterion.ethType().toShort() == Ethernet.TYPE_IPV6; |
| 1735 | } |
| 1736 | |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1737 | static VlanId readVlanFromSelector(TrafficSelector selector) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1738 | if (selector == null) { |
| 1739 | return null; |
| 1740 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1741 | Criterion criterion = selector.getCriterion(Criterion.Type.VLAN_VID); |
| 1742 | return (criterion == null) |
| 1743 | ? null : ((VlanIdCriterion) criterion).vlanId(); |
| 1744 | } |
| 1745 | |
Charles Chan | d9e47c6 | 2017-10-05 15:17:15 -0700 | [diff] [blame] | 1746 | static IpPrefix readIpDstFromSelector(TrafficSelector selector) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1747 | if (selector == null) { |
| 1748 | return null; |
| 1749 | } |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1750 | Criterion criterion = selector.getCriterion(Criterion.Type.IPV4_DST); |
| 1751 | return (criterion == null) ? null : ((IPCriterion) criterion).ip(); |
| 1752 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1753 | |
| 1754 | private static VlanId readVlanFromTreatment(TrafficTreatment treatment) { |
Saurav Das | 59232cf | 2016-04-27 18:35:50 -0700 | [diff] [blame] | 1755 | if (treatment == null) { |
| 1756 | return null; |
| 1757 | } |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1758 | for (Instruction i : treatment.allInstructions()) { |
| 1759 | if (i instanceof ModVlanIdInstruction) { |
| 1760 | return ((ModVlanIdInstruction) i).vlanId(); |
| 1761 | } |
| 1762 | } |
| 1763 | return null; |
| 1764 | } |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1765 | |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 1766 | private static MacAddress readEthDstFromTreatment(TrafficTreatment treatment) { |
| 1767 | if (treatment == null) { |
| 1768 | return null; |
| 1769 | } |
| 1770 | for (Instruction i : treatment.allInstructions()) { |
| 1771 | if (i instanceof ModEtherInstruction) { |
| 1772 | ModEtherInstruction modEtherInstruction = (ModEtherInstruction) i; |
| 1773 | if (modEtherInstruction.subtype() == L2SubType.ETH_DST) { |
| 1774 | return modEtherInstruction.mac(); |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | return null; |
| 1779 | } |
| 1780 | |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1781 | /** |
| 1782 | * Utility class that retries sending flows a fixed number of times, even if |
| 1783 | * some of the attempts are successful. Used only for forwarding objectives. |
| 1784 | */ |
Alex Yashchuk | a367953 | 2017-12-08 17:40:05 +0200 | [diff] [blame] | 1785 | public final class RetryFlows implements Runnable { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1786 | int attempts = MAX_RETRY_ATTEMPTS; |
| 1787 | private Collection<FlowRule> retryFlows; |
| 1788 | private ForwardingObjective fwd; |
| 1789 | |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1790 | RetryFlows(ForwardingObjective fwd, Collection<FlowRule> retryFlows) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1791 | this.fwd = fwd; |
| 1792 | this.retryFlows = retryFlows; |
| 1793 | } |
| 1794 | |
| 1795 | @Override |
| 1796 | public void run() { |
| 1797 | log.info("RETRY FLOWS ATTEMPT# {} for fwd:{} rules:{}", |
| 1798 | MAX_RETRY_ATTEMPTS - attempts, fwd.id(), retryFlows.size()); |
| 1799 | sendForward(fwd, retryFlows); |
| 1800 | if (--attempts > 0) { |
| 1801 | executorService.schedule(this, RETRY_MS, TimeUnit.MILLISECONDS); |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 1806 | } |