Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -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 | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 17 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableSet; |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 20 | import org.onlab.packet.EthType; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [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; |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 23 | import org.onlab.packet.IpPrefix; |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 25 | import org.onlab.packet.VlanId; |
| 26 | import org.onosproject.core.ApplicationId; |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 27 | import org.onosproject.core.GroupId; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 28 | import org.onosproject.net.ConnectPoint; |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 30 | import org.onosproject.driver.extensions.OfdpaMatchActsetOutput; |
| 31 | import org.onosproject.net.Host; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 32 | import org.onosproject.net.Port; |
| 33 | import org.onosproject.net.PortNumber; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 34 | import org.onosproject.net.behaviour.NextGroup; |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 35 | import org.onosproject.net.behaviour.PipelinerContext; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 36 | import org.onosproject.net.flow.DefaultFlowRule; |
| 37 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 38 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 39 | import org.onosproject.net.flow.FlowRule; |
| 40 | import org.onosproject.net.flow.FlowRuleOperations; |
| 41 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 42 | import org.onosproject.net.flow.TrafficSelector; |
| 43 | import org.onosproject.net.flow.TrafficTreatment; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.criteria.Criteria; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 45 | import org.onosproject.net.flow.criteria.Criterion; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 46 | import org.onosproject.net.flow.criteria.EthCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 47 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 48 | import org.onosproject.net.flow.criteria.IPCriterion; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 49 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 50 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 51 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 52 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 53 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 54 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 55 | import org.onosproject.net.flow.instructions.Instruction; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 56 | import org.onosproject.net.flow.instructions.Instructions; |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 57 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
Charles Chan | f76de30 | 2018-06-15 18:54:18 -0700 | [diff] [blame] | 58 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 59 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 60 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 61 | import org.onosproject.net.flowobjective.FilteringObjective; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 62 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 63 | import org.onosproject.net.flowobjective.ObjectiveError; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 64 | import org.onosproject.net.group.DefaultGroupBucket; |
| 65 | import org.onosproject.net.group.DefaultGroupDescription; |
| 66 | import org.onosproject.net.group.DefaultGroupKey; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 67 | import org.onosproject.net.group.Group; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 68 | import org.onosproject.net.group.GroupBucket; |
| 69 | import org.onosproject.net.group.GroupBuckets; |
| 70 | import org.onosproject.net.group.GroupDescription; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 71 | import org.onosproject.net.group.GroupKey; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 72 | import org.onosproject.net.host.HostService; |
Charles Chan | f57a825 | 2016-06-29 19:12:37 -0700 | [diff] [blame] | 73 | import org.onosproject.net.packet.PacketPriority; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 74 | import org.slf4j.Logger; |
| 75 | |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 76 | import java.util.ArrayList; |
| 77 | import java.util.Collection; |
| 78 | import java.util.Collections; |
| 79 | import java.util.Deque; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 80 | import java.util.HashSet; |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 81 | import java.util.List; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 82 | import java.util.Objects; |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 83 | import java.util.Queue; |
| 84 | import java.util.concurrent.ConcurrentLinkedQueue; |
| 85 | import java.util.concurrent.Executors; |
| 86 | import java.util.concurrent.ScheduledExecutorService; |
| 87 | import java.util.concurrent.TimeUnit; |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 88 | import java.util.concurrent.locks.ReentrantLock; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 89 | import java.util.Optional; |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 90 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 91 | import static org.onlab.packet.IPv6.PROTOCOL_ICMP6; |
Charles Chan | d05f54b | 2017-02-13 11:56:54 -0800 | [diff] [blame] | 92 | import static org.onlab.packet.MacAddress.BROADCAST; |
| 93 | import static org.onlab.packet.MacAddress.NONE; |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 94 | import static org.onlab.util.Tools.groupedThreads; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 95 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*; |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 96 | import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID; |
| 97 | import static org.onosproject.net.flow.instructions.Instruction.Type.L2MODIFICATION; |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 98 | import static org.slf4j.LoggerFactory.getLogger; |
| 99 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 102 | * Driver for software switch emulation of the OFDPA pipeline. |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 103 | * The software switch is the CPqD OF 1.3 switch. Unfortunately the CPqD switch |
| 104 | * does not handle vlan tags and mpls labels simultaneously, which requires us |
| 105 | * to do some workarounds in the driver. This driver is meant for the use of |
| 106 | * the cpqd switch when MPLS is required. As a result this driver works only |
| 107 | * on incoming untagged packets. |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 108 | */ |
Charles Chan | 361154b | 2016-03-24 10:23:39 -0700 | [diff] [blame] | 109 | public class CpqdOfdpa2Pipeline extends Ofdpa2Pipeline { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 110 | |
| 111 | private final Logger log = getLogger(getClass()); |
| 112 | |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 113 | private static final int EGRESS_VLAN_FLOW_TABLE_IN_INGRESS = 31; |
| 114 | private static final int UNICAST_ROUTING_TABLE_1 = 32; |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 115 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 116 | * Table that determines whether VLAN is popped before punting to controller. |
| 117 | * <p> |
| 118 | * This is a non-OFDPA table to emulate OFDPA packet in behavior. |
| 119 | * VLAN will be popped before punting if the VLAN is internally assigned. |
| 120 | * <p> |
| 121 | * Also note that 63 is the max table number in CpqD. |
| 122 | */ |
| 123 | private static final int PUNT_TABLE = 63; |
| 124 | |
| 125 | /** |
| 126 | * A static indirect group that pop vlan and punt to controller. |
| 127 | * <p> |
| 128 | * The purpose of using a group instead of immediate action is that this |
| 129 | * won't affect another copy on the data plane when write action exists. |
| 130 | */ |
| 131 | private static final int POP_VLAN_PUNT_GROUP_ID = 0xc0000000; |
| 132 | |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Executor for group checker thread that checks pop vlan punt group. |
| 135 | */ |
| 136 | private ScheduledExecutorService groupChecker; |
| 137 | |
| 138 | /** |
| 139 | * Queue for passing pop vlan punt group flow rules to the GroupChecker thread. |
| 140 | */ |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 141 | private Queue<FlowRule> flowRuleQueue; |
| 142 | |
| 143 | /** |
| 144 | * Lock used in synchronizing driver thread with groupCheckerThread. |
| 145 | */ |
| 146 | private ReentrantLock groupCheckerLock; |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 147 | |
Charles Chan | 053b1cb | 2017-03-22 16:56:35 -0700 | [diff] [blame] | 148 | @Override |
| 149 | protected boolean requireVlanExtensions() { |
| 150 | return false; |
| 151 | } |
| 152 | |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 153 | /** |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 154 | * Determines whether this pipeline support copy ttl instructions or not. |
| 155 | * |
| 156 | * @return true if copy ttl instructions are supported |
| 157 | */ |
| 158 | protected boolean supportCopyTtl() { |
| 159 | return true; |
| 160 | } |
| 161 | |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 162 | /** |
| 163 | * Determines whether this pipeline support push mpls to vlan-tagged packets or not. |
| 164 | * <p> |
| 165 | * If not support, pop vlan before push entering unicast and mpls table. |
| 166 | * Side effect: HostService learns redundant hosts with same MAC but |
| 167 | * different VLAN. No known side effect on the network reachability. |
| 168 | * |
| 169 | * @return true if push mpls to vlan-tagged packets is supported |
| 170 | */ |
| 171 | protected boolean supportTaggedMpls() { |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Determines whether this pipeline support punt action in group bucket. |
| 177 | * |
| 178 | * @return true if punt action in group bucket is supported |
| 179 | */ |
| 180 | protected boolean supportPuntGroup() { |
| 181 | return false; |
| 182 | } |
| 183 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 184 | @Override |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 185 | protected void initDriverId() { |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 186 | driverId = coreService.registerApplication( |
| 187 | "org.onosproject.driver.CpqdOfdpa2Pipeline"); |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 188 | } |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 189 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 190 | @Override |
| 191 | protected void initGroupHander(PipelinerContext context) { |
| 192 | groupHandler = new CpqdOfdpa2GroupHandler(); |
| 193 | groupHandler.init(deviceId, context); |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 196 | @Override |
| 197 | public void init(DeviceId deviceId, PipelinerContext context) { |
| 198 | |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 199 | if (supportPuntGroup()) { |
| 200 | // create a new executor at each init and a new empty queue |
| 201 | groupChecker = Executors.newSingleThreadScheduledExecutor(groupedThreads("onos/driver", |
| 202 | "cpqd-ofdpa-%d", log)); |
| 203 | flowRuleQueue = new ConcurrentLinkedQueue<>(); |
| 204 | groupCheckerLock = new ReentrantLock(); |
| 205 | groupChecker.scheduleAtFixedRate(new PopVlanPuntGroupChecker(), 20, 50, TimeUnit.MILLISECONDS); |
| 206 | super.init(deviceId, context); |
| 207 | } |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 208 | } |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 209 | protected void processFilter(FilteringObjective filteringObjective, |
| 210 | boolean install, |
| 211 | ApplicationId applicationId) { |
| 212 | if (isDoubleTagged(filteringObjective)) { |
| 213 | processDoubleTaggedFilter(filteringObjective, install, applicationId); |
| 214 | } else { |
| 215 | // If it is not a double-tagged filter, we fall back |
| 216 | // to the OFDPA 2.0 pipeline. |
| 217 | super.processFilter(filteringObjective, install, applicationId); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Determines if the filtering objective will be used for double-tagged packets. |
| 223 | * |
| 224 | * @param fob Filtering objective |
| 225 | * @return True if the objective was created for double-tagged packets, false otherwise. |
| 226 | */ |
| 227 | private boolean isDoubleTagged(FilteringObjective fob) { |
| 228 | return fob.meta() != null && |
| 229 | fob.meta().allInstructions().stream().anyMatch(inst -> inst.type() == L2MODIFICATION |
| 230 | && ((L2ModificationInstruction) inst).subtype() == |
| 231 | L2ModificationInstruction.L2SubType.VLAN_POP) && |
| 232 | fob.conditions().stream().filter(criterion -> criterion.type() == VLAN_VID).count() == 2; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Determines if the forwarding objective will be used for double-tagged packets. |
| 237 | * |
| 238 | * @param fwd Forwarding objective |
| 239 | * @return True if the objective was created for double-tagged packets, false otherwise. |
| 240 | */ |
| 241 | private boolean isDoubleTagged(ForwardingObjective fwd) { |
| 242 | if (fwd.nextId() != null) { |
| 243 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 244 | if (next != null) { |
| 245 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 246 | // we only need the top level group's key |
| 247 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 248 | if (group != null) { |
| 249 | int groupId = group.id().id(); |
| 250 | if (((groupId & ~TYPE_MASK) == L3_UNICAST_TYPE) && |
| 251 | ((groupId & TYPE_L3UG_DOUBLE_VLAN_MASK) == TYPE_L3UG_DOUBLE_VLAN_MASK)) { |
| 252 | return true; |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | return false; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Configure filtering rules of outer and inner VLAN IDs, and a MAC address. |
| 262 | * Filtering happens in three tables (VLAN_TABLE, VLAN_1_TABLE, TMAC_TABLE). |
| 263 | * |
| 264 | * @param filteringObjective the filtering objective |
| 265 | * @param install true to add, false to remove |
| 266 | * @param applicationId for application programming this filter |
| 267 | */ |
| 268 | private void processDoubleTaggedFilter(FilteringObjective filteringObjective, |
| 269 | boolean install, |
| 270 | ApplicationId applicationId) { |
| 271 | PortCriterion portCriterion = null; |
| 272 | EthCriterion ethCriterion = null; |
| 273 | VlanIdCriterion innervidCriterion = null; |
| 274 | VlanIdCriterion outerVidCriterion = null; |
| 275 | boolean popVlan = false; |
| 276 | TrafficTreatment meta = filteringObjective.meta(); |
| 277 | if (!filteringObjective.key().equals(Criteria.dummy()) && |
| 278 | filteringObjective.key().type() == Criterion.Type.IN_PORT) { |
| 279 | portCriterion = (PortCriterion) filteringObjective.key(); |
| 280 | } |
| 281 | if (portCriterion == null) { |
| 282 | log.warn("No IN_PORT defined in filtering objective from app: {}" + |
| 283 | "Failed to program VLAN tables.", applicationId); |
| 284 | return; |
| 285 | } else { |
| 286 | log.debug("Received filtering objective for dev/port: {}/{}", deviceId, |
| 287 | portCriterion.port()); |
| 288 | } |
| 289 | |
| 290 | // meta should have only one instruction, popVlan. |
| 291 | if (meta != null && meta.allInstructions().size() == 1) { |
| 292 | L2ModificationInstruction l2Inst = (L2ModificationInstruction) meta.allInstructions().get(0); |
| 293 | if (l2Inst.subtype().equals(L2ModificationInstruction.L2SubType.VLAN_POP)) { |
| 294 | popVlan = true; |
| 295 | } else { |
| 296 | log.warn("Filtering objective can have only VLAN_POP instruction."); |
| 297 | return; |
| 298 | } |
| 299 | } else { |
| 300 | log.warn("Filtering objective should have one instruction."); |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 305 | for (Criterion criterion : filteringObjective.conditions()) { |
| 306 | switch (criterion.type()) { |
| 307 | case ETH_DST: |
| 308 | case ETH_DST_MASKED: |
| 309 | ethCriterion = (EthCriterion) criterion; |
| 310 | break; |
| 311 | case VLAN_VID: |
| 312 | if (innervidCriterion == null) { |
| 313 | innervidCriterion = (VlanIdCriterion) criterion; |
| 314 | } else { |
| 315 | outerVidCriterion = innervidCriterion; |
| 316 | innervidCriterion = (VlanIdCriterion) criterion; |
| 317 | } |
| 318 | break; |
| 319 | default: |
| 320 | log.warn("Unsupported filter {}", criterion); |
| 321 | fail(filteringObjective, ObjectiveError.UNSUPPORTED); |
| 322 | return; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if (innervidCriterion == null || outerVidCriterion == null) { |
| 327 | log.warn("filtering objective should have two vidCriterion."); |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | if (ethCriterion == null || ethCriterion.mac().equals(NONE)) { |
| 332 | // NOTE: it is possible that a filtering objective only has vidCriterion |
| 333 | log.warn("filtering objective missing dstMac, cannot program TMAC table"); |
| 334 | return; |
| 335 | } else { |
| 336 | MacAddress unicastMac = readEthDstFromTreatment(filteringObjective.meta()); |
| 337 | List<List<FlowRule>> allStages = processEthDstFilter(portCriterion, ethCriterion, innervidCriterion, |
| 338 | innervidCriterion.vlanId(), unicastMac, |
| 339 | applicationId); |
| 340 | for (List<FlowRule> flowRules : allStages) { |
| 341 | log.trace("Starting a new flow rule stage for TMAC table flow"); |
| 342 | ops.newStage(); |
| 343 | |
| 344 | for (FlowRule flowRule : flowRules) { |
| 345 | log.trace("{} flow rules in TMAC table: {} for dev: {}", |
| 346 | (install) ? "adding" : "removing", flowRules, deviceId); |
| 347 | if (install) { |
| 348 | ops = ops.add(flowRule); |
| 349 | } else { |
| 350 | // NOTE: Only remove TMAC flow when there is no more enabled port within the |
| 351 | // same VLAN on this device if TMAC doesn't support matching on in_port. |
| 352 | if (matchInPortTmacTable() |
| 353 | || (filteringObjective.meta() != null |
| 354 | && filteringObjective.meta().clearedDeferred())) { |
| 355 | ops = ops.remove(flowRule); |
| 356 | } else { |
| 357 | log.debug("Abort TMAC flow removal on {}. Some other ports still share this TMAC flow"); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | List<FlowRule> rules; |
| 365 | rules = processDoubleVlanIdFilter(portCriterion, innervidCriterion, |
| 366 | outerVidCriterion, popVlan, applicationId); |
| 367 | for (FlowRule flowRule : rules) { |
| 368 | log.trace("{} flow rule in VLAN table: {} for dev: {}", |
| 369 | (install) ? "adding" : "removing", flowRule, deviceId); |
| 370 | ops = install ? ops.add(flowRule) : ops.remove(flowRule); |
| 371 | } |
| 372 | |
| 373 | // apply filtering flow rules |
| 374 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 375 | @Override |
| 376 | public void onSuccess(FlowRuleOperations ops) { |
| 377 | log.debug("Applied {} filtering rules in device {}", |
| 378 | ops.stages().get(0).size(), deviceId); |
| 379 | pass(filteringObjective); |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void onError(FlowRuleOperations ops) { |
| 384 | log.info("Failed to apply all filtering rules in dev {}", deviceId); |
| 385 | fail(filteringObjective, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 386 | } |
| 387 | })); |
| 388 | |
| 389 | } |
| 390 | /** |
| 391 | * Internal implementation of processDoubleVlanIdFilter. |
| 392 | * |
| 393 | * @param portCriterion port on device for which this filter is programmed |
| 394 | * @param innerVidCriterion inner vlan |
| 395 | * @param outerVidCriterion outer vlan |
| 396 | * @param popVlan true if outer vlan header needs to be removed |
| 397 | * @param applicationId for application programming this filter |
| 398 | * @return flow rules for port-vlan filters |
| 399 | */ |
| 400 | private List<FlowRule> processDoubleVlanIdFilter(PortCriterion portCriterion, |
| 401 | VlanIdCriterion innerVidCriterion, |
| 402 | VlanIdCriterion outerVidCriterion, |
| 403 | boolean popVlan, |
| 404 | ApplicationId applicationId) { |
| 405 | List<FlowRule> rules = new ArrayList<>(); |
| 406 | TrafficSelector.Builder outerSelector = DefaultTrafficSelector.builder(); |
| 407 | TrafficTreatment.Builder outerTreatment = DefaultTrafficTreatment.builder(); |
| 408 | TrafficSelector.Builder innerSelector = DefaultTrafficSelector.builder(); |
| 409 | TrafficTreatment.Builder innerTreatment = DefaultTrafficTreatment.builder(); |
| 410 | |
| 411 | VlanId outerVlanId = outerVidCriterion.vlanId(); |
| 412 | VlanId innerVlanId = innerVidCriterion.vlanId(); |
| 413 | PortNumber portNumber = portCriterion.port(); |
| 414 | // Check arguments |
| 415 | if (PortNumber.ALL.equals(portNumber) |
| 416 | || outerVlanId.equals(VlanId.NONE) |
| 417 | || innerVlanId.equals(VlanId.NONE)) { |
| 418 | log.warn("Incomplete Filtering Objective. " + |
| 419 | "VLAN Table cannot be programmed for {}", deviceId); |
| 420 | return ImmutableList.of(); |
| 421 | } else { |
| 422 | outerSelector.matchInPort(portNumber); |
| 423 | innerSelector.matchInPort(portNumber); |
| 424 | outerTreatment.transition(VLAN_1_TABLE); |
| 425 | innerTreatment.transition(TMAC_TABLE); |
| 426 | outerTreatment.writeMetadata(outerVlanId.toShort(), 0xFFF); |
| 427 | |
| 428 | outerSelector.matchVlanId(outerVlanId); |
| 429 | innerSelector.matchVlanId(innerVlanId); |
| 430 | //force recompilation |
| 431 | //FIXME might be issue due tu /fff mask |
| 432 | innerSelector.matchMetadata(outerVlanId.toShort()); |
| 433 | |
| 434 | if (popVlan) { |
| 435 | outerTreatment.popVlan(); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | // NOTE: for double-tagged packets, restore original outer vlan |
| 440 | // before sending it to the controller. |
| 441 | if (supportPuntGroup()) { |
| 442 | GroupKey groupKey = popVlanPuntGroupKey(); |
| 443 | Group group = groupService.getGroup(deviceId, groupKey); |
| 444 | if (group != null) { |
| 445 | // push outer vlan and send to controller |
| 446 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 447 | .matchInPort(portNumber) |
| 448 | .matchVlanId(innerVlanId); |
| 449 | Host host = handler().get(HostService.class).getConnectedHosts(ConnectPoint. |
| 450 | deviceConnectPoint(deviceId + "/" + portNumber.toLong())).stream().filter(h -> |
| 451 | h.vlan().equals(outerVlanId)).findFirst().orElse(null); |
| 452 | EthType vlanType = EthType.EtherType.VLAN.ethType(); |
| 453 | if (host != null) { |
| 454 | vlanType = host.tpid(); |
| 455 | } |
| 456 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
| 457 | .pushVlan(vlanType).setVlanId(outerVlanId).punt(); |
| 458 | |
| 459 | rules.add(DefaultFlowRule.builder() |
| 460 | .forDevice(deviceId) |
| 461 | .withSelector(sbuilder.build()) |
| 462 | .withTreatment(tbuilder.build()) |
| 463 | .withPriority(PacketPriority.CONTROL.priorityValue()) |
| 464 | .fromApp(driverId) |
| 465 | .makePermanent() |
| 466 | .forTable(PUNT_TABLE).build()); |
| 467 | } else { |
| 468 | log.info("popVlanPuntGroup not found in dev:{}", deviceId); |
| 469 | return Collections.emptyList(); |
| 470 | } |
| 471 | } |
| 472 | FlowRule outerRule = DefaultFlowRule.builder() |
| 473 | .forDevice(deviceId) |
| 474 | .withSelector(outerSelector.build()) |
| 475 | .withTreatment(outerTreatment.build()) |
| 476 | .withPriority(DEFAULT_PRIORITY) |
| 477 | .fromApp(applicationId) |
| 478 | .makePermanent() |
| 479 | .forTable(VLAN_TABLE) |
| 480 | .build(); |
| 481 | FlowRule innerRule = DefaultFlowRule.builder() |
| 482 | .forDevice(deviceId) |
| 483 | .withSelector(innerSelector.build()) |
| 484 | .withTreatment(innerTreatment.build()) |
| 485 | .withPriority(DEFAULT_PRIORITY) |
| 486 | .fromApp(applicationId) |
| 487 | .makePermanent() |
| 488 | .forTable(VLAN_1_TABLE) |
| 489 | .build(); |
| 490 | rules.add(outerRule); |
| 491 | rules.add(innerRule); |
| 492 | |
| 493 | return rules; |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the |
| 498 | * egress tables. |
| 499 | * @param fwd the forwarding objective of type 'egress' |
| 500 | * @return a collection of flow rules to be sent to the switch. An empty |
| 501 | * collection may be returned if there is a problem in processing |
| 502 | * the flow rule |
| 503 | */ |
| 504 | @Override |
| 505 | protected Collection<FlowRule> processEgress(ForwardingObjective fwd) { |
| 506 | log.debug("Processing egress forwarding objective:{} in dev:{}", |
| 507 | fwd, deviceId); |
| 508 | |
| 509 | List<FlowRule> rules = new ArrayList<>(); |
| 510 | |
| 511 | // Build selector |
| 512 | TrafficSelector.Builder sb = DefaultTrafficSelector.builder(); |
| 513 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID); |
| 514 | if (vlanIdCriterion == null) { |
| 515 | log.error("Egress forwarding objective:{} must include vlanId", fwd.id()); |
| 516 | fail(fwd, ObjectiveError.BADPARAMS); |
| 517 | return rules; |
| 518 | } |
| 519 | |
| 520 | Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream() |
| 521 | .filter(instruction -> instruction instanceof Instructions.OutputInstruction).findFirst(); |
| 522 | if (!outInstr.isPresent()) { |
| 523 | log.error("Egress forwarding objective:{} must include output port", fwd.id()); |
| 524 | fail(fwd, ObjectiveError.BADPARAMS); |
| 525 | return rules; |
| 526 | } |
| 527 | |
| 528 | PortNumber portNumber = ((Instructions.OutputInstruction) outInstr.get()).port(); |
| 529 | |
| 530 | sb.matchVlanId(vlanIdCriterion.vlanId()); |
| 531 | OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber); |
| 532 | sb.extension(actsetOutput, deviceId); |
| 533 | |
| 534 | // Build a flow rule for Egress VLAN Flow table |
| 535 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 536 | tb.transition(UNICAST_ROUTING_TABLE_1); |
| 537 | if (fwd.treatment() != null) { |
| 538 | for (Instruction instr : fwd.treatment().allInstructions()) { |
| 539 | if (instr instanceof L2ModificationInstruction && |
| 540 | ((L2ModificationInstruction) instr).subtype() == |
| 541 | L2ModificationInstruction.L2SubType.VLAN_ID) { |
| 542 | tb.immediate().add(instr); |
| 543 | } |
| 544 | if (instr instanceof L2ModificationInstruction && |
| 545 | ((L2ModificationInstruction) instr).subtype() == |
| 546 | L2ModificationInstruction.L2SubType.VLAN_PUSH) { |
| 547 | EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType(); |
| 548 | tb.immediate().pushVlan(ethType); |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 554 | .fromApp(fwd.appId()) |
| 555 | .withPriority(fwd.priority()) |
| 556 | .forDevice(deviceId) |
| 557 | .withSelector(sb.build()) |
| 558 | .withTreatment(tb.build()) |
| 559 | .makePermanent() |
| 560 | .forTable(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS); |
| 561 | rules.add(ruleBuilder.build()); |
| 562 | return rules; |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * Handles forwarding rules to the IP Unicast Routing. |
| 567 | * |
| 568 | * @param fwd the forwarding objective |
| 569 | * @return A collection of flow rules, or an empty set |
| 570 | */ |
| 571 | protected Collection<FlowRule> processDoubleTaggedFwd(ForwardingObjective fwd) { |
| 572 | // inner for UNICAST_ROUTING_TABLE_1, outer for UNICAST_ROUTING_TABLE |
| 573 | TrafficSelector selector = fwd.selector(); |
| 574 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 575 | TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder(); |
| 576 | TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder(); |
| 577 | |
| 578 | EthTypeCriterion ethType = |
| 579 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 580 | |
| 581 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
| 582 | sBuilder.matchEthType(Ethernet.TYPE_IPV4); |
| 583 | sBuilder.matchVlanId(VlanId.ANY); |
| 584 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
| 585 | if (!ipv4Dst.isMulticast() && ipv4Dst.prefixLength() == 32) { |
| 586 | sBuilder.matchIPDst(ipv4Dst); |
| 587 | if (fwd.nextId() != null) { |
| 588 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 589 | if (next != null) { |
| 590 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 591 | // we only need the top level group's key to point the flow to it |
| 592 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 593 | if (group == null) { |
| 594 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 595 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 596 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 597 | return Collections.emptySet(); |
| 598 | } |
| 599 | outerTtb.immediate().setVlanId(extractDummyVlanIdFromGroupId(group.id().id())); |
| 600 | //ACTSET_OUTPUT in OVS will match output action in write_action() set. |
| 601 | outerTtb.deferred().setOutput(extractOutputPortFromGroupId(group.id().id())); |
| 602 | outerTtb.transition(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS); |
| 603 | innerTtb.deferred().group(group.id()); |
| 604 | innerTtb.transition(ACL_TABLE); |
| 605 | |
| 606 | FlowRule.Builder innerRuleBuilder = DefaultFlowRule.builder() |
| 607 | .fromApp(fwd.appId()) |
| 608 | .withPriority(fwd.priority()) |
| 609 | .forDevice(deviceId) |
| 610 | .withSelector(sBuilder.build()) |
| 611 | .withTreatment(innerTtb.build()) |
| 612 | .forTable(UNICAST_ROUTING_TABLE_1); |
| 613 | if (fwd.permanent()) { |
| 614 | innerRuleBuilder.makePermanent(); |
| 615 | } else { |
| 616 | innerRuleBuilder.makeTemporary(fwd.timeout()); |
| 617 | } |
| 618 | Collection<FlowRule> flowRuleCollection = new HashSet<>(); |
| 619 | flowRuleCollection.add(innerRuleBuilder.build()); |
| 620 | |
| 621 | FlowRule.Builder outerRuleBuilder = DefaultFlowRule.builder() |
| 622 | .fromApp(fwd.appId()) |
| 623 | .withPriority(fwd.priority()) |
| 624 | .forDevice(deviceId) |
| 625 | .withSelector(sBuilder.build()) |
| 626 | .withTreatment(outerTtb.build()) |
| 627 | .forTable(UNICAST_ROUTING_TABLE); |
| 628 | if (fwd.permanent()) { |
| 629 | outerRuleBuilder.makePermanent(); |
| 630 | } else { |
| 631 | outerRuleBuilder.makeTemporary(fwd.timeout()); |
| 632 | } |
| 633 | flowRuleCollection.add(innerRuleBuilder.build()); |
| 634 | flowRuleCollection.add(outerRuleBuilder.build()); |
| 635 | return flowRuleCollection; |
| 636 | } else { |
| 637 | log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", |
| 638 | fwd.nextId(), deviceId, fwd.id()); |
| 639 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 640 | return Collections.emptySet(); |
| 641 | } |
| 642 | } else { |
| 643 | log.warn("NextId is not specified in fwd:{}", fwd.id()); |
| 644 | fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 645 | return Collections.emptySet(); |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | return Collections.emptySet(); |
| 650 | } |
| 651 | |
| 652 | private static VlanId extractDummyVlanIdFromGroupId(int groupId) { |
| 653 | short vlanId = (short) ((groupId & 0x7FF8000) >> 15); |
| 654 | return VlanId.vlanId(vlanId); |
| 655 | } |
| 656 | |
| 657 | private static PortNumber extractOutputPortFromGroupId(int groupId) { |
| 658 | return PortNumber.portNumber(groupId & 0x7FFF); |
| 659 | } |
| 660 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 661 | /* |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 662 | * Cpqd emulation does not require the non OF-standard rules for |
| 663 | * matching untagged packets that ofdpa uses. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 664 | * |
| 665 | * (non-Javadoc) |
| 666 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processVlanIdFilter |
| 667 | */ |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 668 | @Override |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 669 | protected List<List<FlowRule>> processVlanIdFilter(PortCriterion portCriterion, |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 670 | VlanIdCriterion vidCriterion, |
| 671 | VlanId assignedVlan, |
| 672 | ApplicationId applicationId) { |
Charles Chan | 7976923 | 2016-07-05 16:34:39 -0700 | [diff] [blame] | 673 | List<FlowRule> rules = new ArrayList<>(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 674 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 675 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 676 | selector.matchVlanId(vidCriterion.vlanId()); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 677 | treatment.transition(TMAC_TABLE); |
| 678 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 679 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 680 | // untagged packets are assigned vlans |
| 681 | treatment.pushVlan().setVlanId(assignedVlan); |
Pier | e5bff48 | 2018-03-07 11:42:50 +0100 | [diff] [blame] | 682 | } else if (!vidCriterion.vlanId().equals(assignedVlan)) { |
| 683 | // Rewrite with assigned vlans |
| 684 | treatment.setVlanId(assignedVlan); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 685 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 686 | |
| 687 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 688 | // rules for each port. |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 689 | List<PortNumber> portnums = new ArrayList<>(); |
Ray Milkey | be9f3bc | 2018-05-10 12:42:51 -0700 | [diff] [blame] | 690 | if (portCriterion != null) { |
| 691 | if (portCriterion.port() == PortNumber.ALL) { |
| 692 | for (Port port : deviceService.getPorts(deviceId)) { |
| 693 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 694 | portnums.add(port.number()); |
| 695 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 696 | } |
Ray Milkey | be9f3bc | 2018-05-10 12:42:51 -0700 | [diff] [blame] | 697 | } else { |
| 698 | portnums.add(portCriterion.port()); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 699 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 700 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 701 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 702 | for (PortNumber pnum : portnums) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 703 | // NOTE: Emulating OFDPA behavior by popping off internal assigned |
| 704 | // VLAN before sending to controller |
| 705 | if (supportPuntGroup() && vidCriterion.vlanId() == VlanId.NONE) { |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 706 | try { |
| 707 | groupCheckerLock.lock(); |
| 708 | if (flowRuleQueue == null) { |
| 709 | // this means that the group has been created |
| 710 | // and that groupChecker has destroyed the queue |
| 711 | log.debug("Installing punt table rule for untagged port {} and vlan {}.", |
| 712 | pnum, assignedVlan); |
| 713 | rules.add(buildPuntTableRule(pnum, assignedVlan)); |
| 714 | } else { |
| 715 | // The VLAN punt group may be held back due to device initial audit. |
| 716 | // In that case, we queue all punt table flow until the group has been created. |
| 717 | log.debug("popVlanPuntGroup not found in dev:{}, queueing this flow rule.", deviceId); |
| 718 | flowRuleQueue.add(buildPuntTableRule(pnum, assignedVlan)); |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 719 | } |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 720 | } finally { |
| 721 | groupCheckerLock.unlock(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 722 | } |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 723 | } else if (vidCriterion.vlanId() != VlanId.NONE) { |
| 724 | // for tagged ports just forward to the controller |
| 725 | log.debug("Installing punt rule for tagged port {} and vlan {}.", pnum, vidCriterion.vlanId()); |
| 726 | rules.add(buildPuntTableRuleTagged(pnum, vidCriterion.vlanId())); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 729 | // create rest of flowrule |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 730 | selector.matchInPort(pnum); |
| 731 | FlowRule rule = DefaultFlowRule.builder() |
| 732 | .forDevice(deviceId) |
| 733 | .withSelector(selector.build()) |
| 734 | .withTreatment(treatment.build()) |
| 735 | .withPriority(DEFAULT_PRIORITY) |
| 736 | .fromApp(applicationId) |
| 737 | .makePermanent() |
| 738 | .forTable(VLAN_TABLE).build(); |
| 739 | rules.add(rule); |
| 740 | } |
Charles Chan | f57a825 | 2016-06-29 19:12:37 -0700 | [diff] [blame] | 741 | |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 742 | return ImmutableList.of(rules); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 743 | } |
| 744 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 745 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 746 | * Creates punt table entry that matches IN_PORT and VLAN_VID and points to |
| 747 | * a group that pop vlan and punt. |
| 748 | * |
| 749 | * @param portNumber port number |
| 750 | * @param assignedVlan internally assigned vlan id |
| 751 | * @return punt table flow rule |
| 752 | */ |
| 753 | private FlowRule buildPuntTableRule(PortNumber portNumber, VlanId assignedVlan) { |
| 754 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 755 | .matchInPort(portNumber) |
| 756 | .matchVlanId(assignedVlan); |
| 757 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 758 | .group(new GroupId(POP_VLAN_PUNT_GROUP_ID)); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 759 | |
| 760 | return DefaultFlowRule.builder() |
| 761 | .forDevice(deviceId) |
| 762 | .withSelector(sbuilder.build()) |
| 763 | .withTreatment(tbuilder.build()) |
| 764 | .withPriority(PacketPriority.CONTROL.priorityValue()) |
| 765 | .fromApp(driverId) |
| 766 | .makePermanent() |
| 767 | .forTable(PUNT_TABLE).build(); |
| 768 | } |
| 769 | |
| 770 | /** |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 771 | * Creates punt table entry that matches IN_PORT and VLAN_VID and forwards |
| 772 | * packet to controller tagged. |
| 773 | * |
| 774 | * @param portNumber port number |
| 775 | * @param packetVlan vlan tag of the packet |
| 776 | * @return punt table flow rule |
| 777 | */ |
| 778 | private FlowRule buildPuntTableRuleTagged(PortNumber portNumber, VlanId packetVlan) { |
| 779 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 780 | .matchInPort(portNumber) |
| 781 | .matchVlanId(packetVlan); |
| 782 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().punt(); |
| 783 | |
| 784 | return DefaultFlowRule.builder() |
| 785 | .forDevice(deviceId) |
| 786 | .withSelector(sbuilder.build()) |
| 787 | .withTreatment(tbuilder.build()) |
| 788 | .withPriority(PacketPriority.CONTROL.priorityValue()) |
| 789 | .fromApp(driverId) |
| 790 | .makePermanent() |
| 791 | .forTable(PUNT_TABLE).build(); |
| 792 | } |
| 793 | |
| 794 | /** |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 795 | * Builds a punt to the controller rule for the arp protocol. |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 796 | * <p> |
| 797 | * NOTE: CpqD cannot punt correctly in group bucket. The current impl will |
| 798 | * pop VLAN before sending to controller disregarding whether |
| 799 | * it's an internally assigned VLAN or a natural VLAN. |
| 800 | * Therefore, trunk port is not supported in CpqD. |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 801 | * |
| 802 | * @param assignedVlan the internal assigned vlan id |
| 803 | * @param applicationId the application id |
| 804 | * @return the punt flow rule for the arp |
| 805 | */ |
| 806 | private FlowRule buildArpPunt(VlanId assignedVlan, ApplicationId applicationId) { |
| 807 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 808 | .matchEthType(Ethernet.TYPE_ARP) |
| 809 | .matchVlanId(assignedVlan); |
| 810 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
| 811 | .popVlan() |
| 812 | .punt(); |
| 813 | |
| 814 | return DefaultFlowRule.builder() |
| 815 | .forDevice(deviceId) |
| 816 | .withSelector(sbuilder.build()) |
| 817 | .withTreatment(tbuilder.build()) |
| 818 | .withPriority(PacketPriority.CONTROL.priorityValue() + 1) |
| 819 | .fromApp(applicationId) |
| 820 | .makePermanent() |
| 821 | .forTable(ACL_TABLE).build(); |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * Builds a punt to the controller rule for the icmp v6 messages. |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 826 | * <p> |
| 827 | * NOTE: CpqD cannot punt correctly in group bucket. The current impl will |
| 828 | * pop VLAN before sending to controller disregarding whether |
| 829 | * it's an internally assigned VLAN or a natural VLAN. |
| 830 | * Therefore, trunk port is not supported in CpqD. |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 831 | * |
| 832 | * @param assignedVlan the internal assigned vlan id |
| 833 | * @param applicationId the application id |
| 834 | * @return the punt flow rule for the icmp v6 messages |
| 835 | */ |
| 836 | private FlowRule buildIcmpV6Punt(VlanId assignedVlan, ApplicationId applicationId) { |
| 837 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 838 | .matchVlanId(assignedVlan) |
| 839 | .matchEthType(Ethernet.TYPE_IPV6) |
| 840 | .matchIPProtocol(PROTOCOL_ICMP6); |
| 841 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
| 842 | .popVlan() |
| 843 | .punt(); |
| 844 | |
| 845 | return DefaultFlowRule.builder() |
| 846 | .forDevice(deviceId) |
| 847 | .withSelector(sbuilder.build()) |
| 848 | .withTreatment(tbuilder.build()) |
| 849 | .withPriority(PacketPriority.CONTROL.priorityValue() + 1) |
| 850 | .fromApp(applicationId) |
| 851 | .makePermanent() |
| 852 | .forTable(ACL_TABLE).build(); |
| 853 | } |
| 854 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 855 | /* |
| 856 | * Cpqd emulation does not handle vlan tags and mpls labels correctly. |
| 857 | * Workaround requires popping off the VLAN tags in the TMAC table. |
| 858 | * |
| 859 | * (non-Javadoc) |
| 860 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthDstFilter |
| 861 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 862 | @Override |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 863 | protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion, |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 864 | EthCriterion ethCriterion, |
| 865 | VlanIdCriterion vidCriterion, |
| 866 | VlanId assignedVlan, |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 867 | MacAddress unicastMac, |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 868 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 869 | // Consider PortNumber.ANY as wildcard. Match ETH_DST only |
| 870 | if (portCriterion != null && portCriterion.port() == PortNumber.ANY) { |
| 871 | return processEthDstOnlyFilter(ethCriterion, applicationId); |
| 872 | } |
| 873 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 874 | // Multicast MAC |
| 875 | if (ethCriterion.mask() != null) { |
Charles Chan | 45b69ab | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 876 | return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 879 | //handling untagged packets via assigned VLAN |
| 880 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 881 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
| 882 | } |
| 883 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 884 | // rules for each port. |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 885 | List<PortNumber> portnums = new ArrayList<>(); |
Ray Milkey | 74e5913 | 2018-01-17 15:24:52 -0800 | [diff] [blame] | 886 | if (portCriterion != null) { |
| 887 | if (portCriterion.port() == PortNumber.ALL) { |
| 888 | for (Port port : deviceService.getPorts(deviceId)) { |
| 889 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 890 | portnums.add(port.number()); |
| 891 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 892 | } |
Ray Milkey | 74e5913 | 2018-01-17 15:24:52 -0800 | [diff] [blame] | 893 | } else { |
| 894 | portnums.add(portCriterion.port()); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 895 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 896 | } |
| 897 | |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 898 | List<FlowRule> rules = new ArrayList<>(); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 899 | for (PortNumber pnum : portnums) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 900 | // TMAC rules for unicast IP packets |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 901 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 902 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 903 | selector.matchInPort(pnum); |
| 904 | selector.matchVlanId(vidCriterion.vlanId()); |
| 905 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 906 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 907 | if (!supportTaggedMpls()) { |
| 908 | treatment.popVlan(); |
| 909 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 910 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 911 | FlowRule rule = DefaultFlowRule.builder() |
| 912 | .forDevice(deviceId) |
| 913 | .withSelector(selector.build()) |
| 914 | .withTreatment(treatment.build()) |
| 915 | .withPriority(DEFAULT_PRIORITY) |
| 916 | .fromApp(applicationId) |
| 917 | .makePermanent() |
| 918 | .forTable(TMAC_TABLE).build(); |
| 919 | rules.add(rule); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 920 | |
| 921 | // TMAC rules for MPLS packets |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 922 | selector = DefaultTrafficSelector.builder(); |
| 923 | treatment = DefaultTrafficTreatment.builder(); |
| 924 | selector.matchInPort(pnum); |
| 925 | selector.matchVlanId(vidCriterion.vlanId()); |
| 926 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 927 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 928 | if (!supportTaggedMpls()) { |
| 929 | treatment.popVlan(); |
| 930 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 931 | treatment.transition(MPLS_TABLE_0); |
| 932 | rule = DefaultFlowRule.builder() |
| 933 | .forDevice(deviceId) |
| 934 | .withSelector(selector.build()) |
| 935 | .withTreatment(treatment.build()) |
| 936 | .withPriority(DEFAULT_PRIORITY) |
| 937 | .fromApp(applicationId) |
| 938 | .makePermanent() |
| 939 | .forTable(TMAC_TABLE).build(); |
| 940 | rules.add(rule); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 941 | |
| 942 | // TMAC rules for IPv6 packets |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 943 | selector = DefaultTrafficSelector.builder(); |
| 944 | treatment = DefaultTrafficTreatment.builder(); |
| 945 | selector.matchInPort(pnum); |
| 946 | selector.matchVlanId(vidCriterion.vlanId()); |
| 947 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 948 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 949 | if (!supportTaggedMpls()) { |
| 950 | treatment.popVlan(); |
| 951 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 952 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 953 | rule = DefaultFlowRule.builder() |
| 954 | .forDevice(deviceId) |
| 955 | .withSelector(selector.build()) |
| 956 | .withTreatment(treatment.build()) |
| 957 | .withPriority(DEFAULT_PRIORITY) |
| 958 | .fromApp(applicationId) |
| 959 | .makePermanent() |
| 960 | .forTable(TMAC_TABLE).build(); |
| 961 | rules.add(rule); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 962 | } |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 963 | return ImmutableList.of(rules); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 964 | } |
| 965 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 966 | @Override |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 967 | protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 968 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 969 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 970 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 971 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 972 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 973 | if (!supportTaggedMpls()) { |
| 974 | treatment.popVlan(); |
| 975 | } |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 976 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 977 | FlowRule rule = DefaultFlowRule.builder() |
| 978 | .forDevice(deviceId) |
| 979 | .withSelector(selector.build()) |
| 980 | .withTreatment(treatment.build()) |
| 981 | .withPriority(DEFAULT_PRIORITY) |
| 982 | .fromApp(applicationId) |
| 983 | .makePermanent() |
| 984 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 6629150 | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 985 | return ImmutableList.of(ImmutableList.of(rule)); |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 986 | } |
| 987 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 988 | /* |
| 989 | * Cpqd emulation allows MPLS ecmp. |
| 990 | * |
| 991 | * (non-Javadoc) |
| 992 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthTypeSpecific |
| 993 | */ |
| 994 | @Override |
| 995 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 996 | if (isDoubleTagged(fwd)) { |
| 997 | return processDoubleTaggedFwd(fwd); |
| 998 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 999 | TrafficSelector selector = fwd.selector(); |
| 1000 | EthTypeCriterion ethType = |
| 1001 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 1002 | if ((ethType == null) || |
| 1003 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1004 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST) && |
| 1005 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1006 | log.warn("processSpecific: Unsupported forwarding objective criteria" |
| 1007 | + "ethType:{} in dev:{}", ethType, deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1008 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 1009 | return Collections.emptySet(); |
| 1010 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1011 | boolean defaultRule = false; |
Charles Chan | 50d900c | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 1012 | int forTableId; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1013 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1014 | TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder(); |
| 1015 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1016 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1017 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1018 | if (ipv4Dst.isMulticast()) { |
| 1019 | if (ipv4Dst.prefixLength() != 32) { |
| 1020 | log.warn("Multicast specific forwarding objective can only be /32"); |
| 1021 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1022 | return ImmutableSet.of(); |
| 1023 | } |
| 1024 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1025 | if (assignedVlan == null) { |
| 1026 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1027 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1028 | return ImmutableSet.of(); |
| 1029 | } |
| 1030 | filteredSelector.matchVlanId(assignedVlan); |
| 1031 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 1032 | forTableId = MULTICAST_ROUTING_TABLE; |
| 1033 | log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}" |
| 1034 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1035 | } else { |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1036 | if (ipv4Dst.prefixLength() == 0) { |
| 1037 | // The entire IPV4_DST field is wildcarded intentionally |
| 1038 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1039 | } else { |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 1040 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 1041 | } |
| 1042 | forTableId = UNICAST_ROUTING_TABLE; |
| 1043 | log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}" |
| 1044 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1045 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1046 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) { |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 1047 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 1048 | if (ipv6Dst.isMulticast()) { |
| 1049 | if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) { |
| 1050 | log.debug("Multicast specific IPv6 forwarding objective can only be /128"); |
| 1051 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1052 | return ImmutableSet.of(); |
| 1053 | } |
| 1054 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 1055 | if (assignedVlan == null) { |
| 1056 | log.debug("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 1057 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1058 | return ImmutableSet.of(); |
| 1059 | } |
| 1060 | filteredSelector.matchVlanId(assignedVlan); |
| 1061 | filteredSelector.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst); |
| 1062 | forTableId = MULTICAST_ROUTING_TABLE; |
| 1063 | log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" |
| 1064 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 1065 | } else { |
| 1066 | if (buildIpv6Selector(filteredSelector, fwd) < 0) { |
| 1067 | return Collections.emptyList(); |
| 1068 | } |
| 1069 | forTableId = UNICAST_ROUTING_TABLE; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1070 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1071 | } else { |
| 1072 | filteredSelector |
| 1073 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 1074 | .matchMplsLabel(((MplsCriterion) |
| 1075 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 1076 | MplsBosCriterion bos = (MplsBosCriterion) selector |
| 1077 | .getCriterion(Criterion.Type.MPLS_BOS); |
| 1078 | if (bos != null) { |
| 1079 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 1080 | } |
| 1081 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 1082 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 1083 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 1087 | if (fwd.treatment() != null) { |
| 1088 | for (Instruction i : fwd.treatment().allInstructions()) { |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 1089 | if (!supportCopyTtl() && i instanceof L3ModificationInstruction) { |
| 1090 | L3ModificationInstruction l3instr = (L3ModificationInstruction) i; |
| 1091 | if (l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_IN) || |
| 1092 | l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_OUT)) { |
| 1093 | continue; |
| 1094 | } |
| 1095 | } |
Charles Chan | 7d10b16 | 2015-12-07 18:54:45 -0800 | [diff] [blame] | 1096 | /* |
| 1097 | * NOTE: OF-DPA does not support immediate instruction in |
| 1098 | * L3 unicast and MPLS table. |
| 1099 | */ |
| 1100 | tb.deferred().add(i); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1105 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 1106 | if (next != null) { |
| 1107 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1108 | // we only need the top level group's key to point the flow to it |
| 1109 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1110 | if (group == null) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 1111 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1112 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 1113 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1114 | return Collections.emptySet(); |
| 1115 | } |
| 1116 | tb.deferred().group(group.id()); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1117 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1118 | } |
| 1119 | tb.transition(ACL_TABLE); |
| 1120 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1121 | .fromApp(fwd.appId()) |
| 1122 | .withPriority(fwd.priority()) |
| 1123 | .forDevice(deviceId) |
| 1124 | .withSelector(filteredSelector.build()) |
| 1125 | .withTreatment(tb.build()) |
| 1126 | .forTable(forTableId); |
| 1127 | |
| 1128 | if (fwd.permanent()) { |
| 1129 | ruleBuilder.makePermanent(); |
| 1130 | } else { |
| 1131 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 1132 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1133 | Collection<FlowRule> flowRuleCollection = new ArrayList<>(); |
| 1134 | flowRuleCollection.add(ruleBuilder.build()); |
| 1135 | if (defaultRule) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1136 | flowRuleCollection.add( |
| 1137 | defaultRoute(fwd, complementarySelector, forTableId, tb) |
| 1138 | ); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1139 | log.debug("Default rule 0.0.0.0/0 is being installed two rules"); |
| 1140 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 1141 | return flowRuleCollection; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Charles Chan | 1e492d3 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1144 | @Override |
| 1145 | protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { |
| 1146 | List<FlowRule> rules = new ArrayList<>(); |
| 1147 | |
| 1148 | // Build filtered selector |
| 1149 | TrafficSelector selector = fwd.selector(); |
| 1150 | EthCriterion ethCriterion = (EthCriterion) selector |
| 1151 | .getCriterion(Criterion.Type.ETH_DST); |
| 1152 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 1153 | .getCriterion(VLAN_VID); |
Charles Chan | 1e492d3 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1154 | |
| 1155 | if (vlanIdCriterion == null) { |
| 1156 | log.warn("Forwarding objective for bridging requires vlan. Not " |
| 1157 | + "installing fwd:{} in dev:{}", fwd.id(), deviceId); |
| 1158 | fail(fwd, ObjectiveError.BADPARAMS); |
| 1159 | return Collections.emptySet(); |
| 1160 | } |
| 1161 | |
| 1162 | TrafficSelector.Builder filteredSelectorBuilder = |
| 1163 | DefaultTrafficSelector.builder(); |
| 1164 | // Do not match MacAddress for subnet broadcast entry |
Charles Chan | d05f54b | 2017-02-13 11:56:54 -0800 | [diff] [blame] | 1165 | if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) { |
Charles Chan | 1e492d3 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 1166 | filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); |
| 1167 | log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", |
| 1168 | fwd.id(), fwd.nextId(), deviceId); |
| 1169 | } else { |
| 1170 | log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " |
| 1171 | + "in dev:{} for vlan:{}", |
| 1172 | fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); |
| 1173 | } |
| 1174 | filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); |
| 1175 | TrafficSelector filteredSelector = filteredSelectorBuilder.build(); |
| 1176 | |
| 1177 | if (fwd.treatment() != null) { |
| 1178 | log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" |
| 1179 | + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); |
| 1180 | } |
| 1181 | |
| 1182 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1183 | if (fwd.nextId() != null) { |
| 1184 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 1185 | if (next != null) { |
| 1186 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1187 | // we only need the top level group's key to point the flow to it |
| 1188 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1189 | if (group != null) { |
| 1190 | treatmentBuilder.deferred().group(group.id()); |
| 1191 | } else { |
| 1192 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1193 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1194 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1195 | return Collections.emptySet(); |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | treatmentBuilder.immediate().transition(ACL_TABLE); |
| 1200 | TrafficTreatment filteredTreatment = treatmentBuilder.build(); |
| 1201 | |
| 1202 | // Build bridging table entries |
| 1203 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); |
| 1204 | flowRuleBuilder.fromApp(fwd.appId()) |
| 1205 | .withPriority(fwd.priority()) |
| 1206 | .forDevice(deviceId) |
| 1207 | .withSelector(filteredSelector) |
| 1208 | .withTreatment(filteredTreatment) |
| 1209 | .forTable(BRIDGING_TABLE); |
| 1210 | if (fwd.permanent()) { |
| 1211 | flowRuleBuilder.makePermanent(); |
| 1212 | } else { |
| 1213 | flowRuleBuilder.makeTemporary(fwd.timeout()); |
| 1214 | } |
| 1215 | rules.add(flowRuleBuilder.build()); |
| 1216 | return rules; |
| 1217 | } |
| 1218 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1219 | /* |
| 1220 | * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the |
| 1221 | * ACL table. Because we pop off vlan tags in TMAC table, |
| 1222 | * we need to avoid matching on vlans in the ACL table. |
| 1223 | */ |
| 1224 | @Override |
| 1225 | protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
| 1226 | log.info("Processing versatile forwarding objective"); |
| 1227 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1228 | if (fwd.nextId() == null && fwd.treatment() == null) { |
| 1229 | log.error("Forwarding objective {} from {} must contain " |
| 1230 | + "nextId or Treatment", fwd.selector(), fwd.appId()); |
| 1231 | return Collections.emptySet(); |
| 1232 | } |
| 1233 | |
| 1234 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 1235 | fwd.selector().criteria().forEach(criterion -> { |
| 1236 | if (criterion instanceof VlanIdCriterion) { |
| 1237 | // avoid matching on vlans |
| 1238 | return; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 1239 | } else if (criterion instanceof Icmpv6TypeCriterion || |
| 1240 | criterion instanceof Icmpv6CodeCriterion) { |
| 1241 | /* |
| 1242 | * We silenty discard these criterions, our current |
| 1243 | * OFDPA platform does not support these matches on |
| 1244 | * the ACL table. |
| 1245 | */ |
| 1246 | log.warn("ICMPv6 Type and ICMPv6 Code are not supported"); |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1247 | } else { |
| 1248 | sbuilder.add(criterion); |
| 1249 | } |
| 1250 | }); |
| 1251 | |
| 1252 | // XXX driver does not currently do type checking as per Tables 65-67 in |
| 1253 | // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller. |
| 1254 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 1255 | if (fwd.treatment() != null) { |
| 1256 | for (Instruction ins : fwd.treatment().allInstructions()) { |
| 1257 | if (ins instanceof OutputInstruction) { |
| 1258 | OutputInstruction o = (OutputInstruction) ins; |
| 1259 | if (o.port() == PortNumber.CONTROLLER) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 1260 | ttBuilder.transition(PUNT_TABLE); |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1261 | } else { |
| 1262 | log.warn("Only allowed treatments in versatile forwarding " |
| 1263 | + "objectives are punts to the controller"); |
| 1264 | } |
Charles Chan | f76de30 | 2018-06-15 18:54:18 -0700 | [diff] [blame] | 1265 | } else if (ins instanceof NoActionInstruction) { |
| 1266 | // No action is allowed and nothing needs to be done |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1267 | } else { |
| 1268 | log.warn("Cannot process instruction in versatile fwd {}", ins); |
| 1269 | } |
| 1270 | } |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 1271 | if (fwd.treatment().clearedDeferred()) { |
| 1272 | ttBuilder.wipeDeferred(); |
| 1273 | } |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 1274 | } |
| 1275 | if (fwd.nextId() != null) { |
| 1276 | // overide case |
| 1277 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 1278 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 1279 | // we only need the top level group's key to point the flow to it |
| 1280 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 1281 | if (group == null) { |
| 1282 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 1283 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 1284 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 1285 | return Collections.emptySet(); |
| 1286 | } |
| 1287 | ttBuilder.deferred().group(group.id()); |
| 1288 | } |
| 1289 | |
| 1290 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 1291 | .fromApp(fwd.appId()) |
| 1292 | .withPriority(fwd.priority()) |
| 1293 | .forDevice(deviceId) |
| 1294 | .withSelector(sbuilder.build()) |
| 1295 | .withTreatment(ttBuilder.build()) |
| 1296 | .makePermanent() |
| 1297 | .forTable(ACL_TABLE); |
| 1298 | return Collections.singletonList(ruleBuilder.build()); |
| 1299 | } |
| 1300 | |
| 1301 | /* |
| 1302 | * Cpqd emulation requires table-miss-entries in forwarding tables. |
| 1303 | * Real OFDPA does not require these rules as they are put in by default. |
| 1304 | * |
| 1305 | * (non-Javadoc) |
| 1306 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#initializePipeline() |
| 1307 | */ |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1308 | @Override |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1309 | protected void initializePipeline() { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1310 | initTableMiss(PORT_TABLE, VLAN_TABLE, null); |
| 1311 | initTableMiss(VLAN_TABLE, ACL_TABLE, null); |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 1312 | initTableMiss(VLAN_1_TABLE, ACL_TABLE, null); |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1313 | initTableMiss(TMAC_TABLE, BRIDGING_TABLE, null); |
| 1314 | initTableMiss(UNICAST_ROUTING_TABLE, ACL_TABLE, null); |
| 1315 | initTableMiss(MULTICAST_ROUTING_TABLE, ACL_TABLE, null); |
Andrea Campanella | 7c977b9 | 2018-05-30 21:39:45 -0700 | [diff] [blame^] | 1316 | initTableMiss(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS, ACL_TABLE, null); |
| 1317 | initTableMiss(UNICAST_ROUTING_TABLE_1, ACL_TABLE, null); |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1318 | initTableMiss(MPLS_TABLE_0, MPLS_TABLE_1, null); |
| 1319 | initTableMiss(MPLS_TABLE_1, ACL_TABLE, null); |
| 1320 | initTableMiss(BRIDGING_TABLE, ACL_TABLE, null); |
| 1321 | initTableMiss(ACL_TABLE, -1, null); |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1322 | linkDiscoveryPuntTableRules(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 1323 | |
| 1324 | if (supportPuntGroup()) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 1325 | initPopVlanPuntGroup(); |
| 1326 | } else { |
| 1327 | initTableMiss(PUNT_TABLE, -1, |
| 1328 | DefaultTrafficTreatment.builder().popVlan().punt().build()); |
| 1329 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1332 | /** |
| 1333 | * Install table-miss flow entry. |
| 1334 | * |
| 1335 | * If treatment exists, use it directly. |
| 1336 | * Else if treatment does not exist but nextTable > 0, transit to next table. |
| 1337 | * Else apply empty treatment. |
| 1338 | * |
| 1339 | * @param thisTable this table ID |
| 1340 | * @param nextTable next table ID |
| 1341 | * @param treatment traffic treatment to apply. |
| 1342 | */ |
| 1343 | private void initTableMiss(int thisTable, int nextTable, TrafficTreatment treatment) { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1344 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1345 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1346 | |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1347 | if (treatment == null) { |
| 1348 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1349 | if (nextTable > 0) { |
| 1350 | tBuilder.transition(nextTable); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1351 | } |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1352 | treatment = tBuilder.build(); |
| 1353 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1354 | |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 1355 | FlowRule rule = DefaultFlowRule.builder() |
| 1356 | .forDevice(deviceId) |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1357 | .withSelector(selector) |
| 1358 | .withTreatment(treatment) |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 1359 | .withPriority(LOWEST_PRIORITY) |
| 1360 | .fromApp(driverId) |
| 1361 | .makePermanent() |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1362 | .forTable(thisTable).build(); |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 1363 | ops = ops.add(rule); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1364 | |
| 1365 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 1366 | @Override |
| 1367 | public void onSuccess(FlowRuleOperations ops) { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1368 | log.info("Initialized table {} on {}", thisTable, deviceId); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1369 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1370 | @Override |
| 1371 | public void onError(FlowRuleOperations ops) { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 1372 | log.warn("Failed to initialize table {} on {}", thisTable, deviceId); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 1373 | } |
| 1374 | })); |
| 1375 | } |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 1376 | |
| 1377 | /** |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1378 | * Install lldp/bbdp matching rules at table PUNT_TABLE |
| 1379 | * that forward traffic to controller. |
| 1380 | * |
| 1381 | */ |
| 1382 | private void linkDiscoveryPuntTableRules() { |
| 1383 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 1384 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build(); |
| 1385 | |
| 1386 | TrafficSelector.Builder lldpSelector = DefaultTrafficSelector.builder(); |
| 1387 | lldpSelector.matchEthType(EthType.EtherType.LLDP.ethType().toShort()); |
| 1388 | FlowRule lldpRule = DefaultFlowRule.builder() |
| 1389 | .forDevice(deviceId) |
| 1390 | .withSelector(lldpSelector.build()) |
| 1391 | .withTreatment(treatment) |
| 1392 | .withPriority(HIGHEST_PRIORITY) |
| 1393 | .fromApp(driverId) |
| 1394 | .makePermanent() |
| 1395 | .forTable(PUNT_TABLE).build(); |
| 1396 | ops = ops.add(lldpRule); |
| 1397 | |
| 1398 | TrafficSelector.Builder bbdpSelector = DefaultTrafficSelector.builder(); |
| 1399 | bbdpSelector.matchEthType(EthType.EtherType.BDDP.ethType().toShort()); |
| 1400 | FlowRule bbdpRule = DefaultFlowRule.builder() |
| 1401 | .forDevice(deviceId) |
| 1402 | .withSelector(bbdpSelector.build()) |
| 1403 | .withTreatment(treatment) |
| 1404 | .withPriority(HIGHEST_PRIORITY) |
| 1405 | .fromApp(driverId) |
| 1406 | .makePermanent() |
| 1407 | .forTable(PUNT_TABLE).build(); |
| 1408 | ops.add(bbdpRule); |
| 1409 | |
| 1410 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 1411 | @Override |
| 1412 | public void onSuccess(FlowRuleOperations ops) { |
| 1413 | log.info("Added lldp/bbdp rules for table {} on {}", PUNT_TABLE, deviceId); |
| 1414 | } |
| 1415 | @Override |
| 1416 | public void onError(FlowRuleOperations ops) { |
| 1417 | log.warn("Failed to initialize lldp/bbdp rules for table {} on {}", PUNT_TABLE, deviceId); |
| 1418 | } |
| 1419 | })); |
| 1420 | } |
| 1421 | |
| 1422 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 1423 | * Builds a indirect group contains pop_vlan and punt actions. |
| 1424 | * <p> |
| 1425 | * Using group instead of immediate action to ensure that |
| 1426 | * the copy of packet on the data plane is not affected by the pop vlan action. |
| 1427 | */ |
| 1428 | private void initPopVlanPuntGroup() { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1429 | GroupKey groupKey = popVlanPuntGroupKey(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 1430 | TrafficTreatment bucketTreatment = DefaultTrafficTreatment.builder() |
| 1431 | .popVlan().punt().build(); |
| 1432 | GroupBucket bucket = |
| 1433 | DefaultGroupBucket.createIndirectGroupBucket(bucketTreatment); |
| 1434 | GroupDescription groupDesc = |
| 1435 | new DefaultGroupDescription( |
| 1436 | deviceId, |
| 1437 | GroupDescription.Type.INDIRECT, |
| 1438 | new GroupBuckets(Collections.singletonList(bucket)), |
| 1439 | groupKey, |
| 1440 | POP_VLAN_PUNT_GROUP_ID, |
| 1441 | driverId); |
| 1442 | groupService.addGroup(groupDesc); |
| 1443 | |
| 1444 | log.info("Initialized pop vlan punt group on {}", deviceId); |
| 1445 | } |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1446 | |
| 1447 | /** |
| 1448 | * Generates group key for a static indirect group that pop vlan and punt to |
| 1449 | * controller. |
| 1450 | * |
| 1451 | * @return the group key of the indirect table |
| 1452 | */ |
| 1453 | private GroupKey popVlanPuntGroupKey() { |
| 1454 | int hash = POP_VLAN_PUNT_GROUP_ID | (Objects.hash(deviceId) & FOUR_BIT_MASK); |
| 1455 | return new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(hash)); |
| 1456 | } |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1457 | |
| 1458 | private class PopVlanPuntGroupChecker implements Runnable { |
| 1459 | @Override |
| 1460 | public void run() { |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1461 | try { |
| 1462 | groupCheckerLock.lock(); |
| 1463 | // this can happen outside of the lock but I think it is safer |
| 1464 | // to include it here. |
| 1465 | Group group = groupService.getGroup(deviceId, popVlanPuntGroupKey()); |
| 1466 | if (group != null) { |
| 1467 | log.debug("PopVlanPuntGroupChecker: Installing {} missing rules at punt table.", |
| 1468 | flowRuleQueue.size()); |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1469 | |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1470 | // if we have pending flow rules install them |
| 1471 | if (flowRuleQueue.size() > 0) { |
| 1472 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 1473 | // we should not care about the context here, it can only be add |
| 1474 | // since when removing the rules the group should be there already. |
| 1475 | flowRuleQueue.forEach(ops::add); |
| 1476 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 1477 | @Override |
| 1478 | public void onSuccess(FlowRuleOperations ops) { |
| 1479 | log.debug("Applied {} pop vlan punt rules in device {}", |
| 1480 | ops.stages().get(0).size(), deviceId); |
| 1481 | } |
| 1482 | |
| 1483 | @Override |
| 1484 | public void onError(FlowRuleOperations ops) { |
| 1485 | log.error("Failed to apply all pop vlan punt rules in dev {}", deviceId); |
| 1486 | } |
| 1487 | })); |
| 1488 | } |
| 1489 | // this signifies that the group is created and now |
| 1490 | // flow rules can be installed directly |
| 1491 | flowRuleQueue = null; |
| 1492 | // shutdown the group checker gracefully |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1493 | groupChecker.shutdown(); |
| 1494 | } |
Andreas Pantelopoulos | 470865e | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1495 | } finally { |
| 1496 | groupCheckerLock.unlock(); |
Andreas Pantelopoulos | 8936946 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1497 | } |
| 1498 | } |
| 1499 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1500 | } |