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