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