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 | c78c1f5 | 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 | d57552d | 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; |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 28 | import org.onosproject.net.DeviceId; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 29 | import org.onosproject.net.Port; |
| 30 | import org.onosproject.net.PortNumber; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 31 | import org.onosproject.net.behaviour.NextGroup; |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 32 | import org.onosproject.net.behaviour.PipelinerContext; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 33 | import org.onosproject.net.flow.DefaultFlowRule; |
| 34 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 36 | import org.onosproject.net.flow.FlowRule; |
| 37 | import org.onosproject.net.flow.FlowRuleOperations; |
| 38 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 39 | import org.onosproject.net.flow.TrafficSelector; |
| 40 | import org.onosproject.net.flow.TrafficTreatment; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 41 | import org.onosproject.net.flow.criteria.Criteria; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 42 | import org.onosproject.net.flow.criteria.Criterion; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 43 | import org.onosproject.net.flow.criteria.EthCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 45 | import org.onosproject.net.flow.criteria.IPCriterion; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 46 | import org.onosproject.net.flow.criteria.Icmpv6CodeCriterion; |
| 47 | import org.onosproject.net.flow.criteria.Icmpv6TypeCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 48 | import org.onosproject.net.flow.criteria.MplsBosCriterion; |
| 49 | import org.onosproject.net.flow.criteria.MplsCriterion; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 50 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 51 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 52 | import org.onosproject.net.flow.instructions.Instruction; |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 53 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
Charles Chan | 3fe7171 | 2018-06-15 18:54:18 -0700 | [diff] [blame] | 54 | import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction; |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 55 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 56 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 57 | import org.onosproject.net.flowobjective.ObjectiveError; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 58 | import org.onosproject.net.group.DefaultGroupBucket; |
| 59 | import org.onosproject.net.group.DefaultGroupDescription; |
| 60 | import org.onosproject.net.group.DefaultGroupKey; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 61 | import org.onosproject.net.group.Group; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 62 | import org.onosproject.net.group.GroupBucket; |
| 63 | import org.onosproject.net.group.GroupBuckets; |
| 64 | import org.onosproject.net.group.GroupDescription; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 65 | import org.onosproject.net.group.GroupKey; |
Charles Chan | f57a825 | 2016-06-29 19:12:37 -0700 | [diff] [blame] | 66 | import org.onosproject.net.packet.PacketPriority; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 67 | import org.slf4j.Logger; |
| 68 | |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 69 | import java.util.ArrayList; |
| 70 | import java.util.Collection; |
| 71 | import java.util.Collections; |
| 72 | import java.util.Deque; |
| 73 | import java.util.List; |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 74 | import java.util.Objects; |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 75 | import java.util.Queue; |
| 76 | import java.util.concurrent.ConcurrentLinkedQueue; |
| 77 | import java.util.concurrent.Executors; |
| 78 | import java.util.concurrent.ScheduledExecutorService; |
| 79 | import java.util.concurrent.TimeUnit; |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 80 | import java.util.concurrent.locks.ReentrantLock; |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 81 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 82 | import static org.onlab.packet.IPv6.PROTOCOL_ICMP6; |
Charles Chan | d05f54b | 2017-02-13 11:56:54 -0800 | [diff] [blame] | 83 | import static org.onlab.packet.MacAddress.BROADCAST; |
| 84 | import static org.onlab.packet.MacAddress.NONE; |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 85 | import static org.onlab.util.Tools.groupedThreads; |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 86 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility.*; |
pier | 5c81758 | 2019-04-17 17:05:08 +0200 | [diff] [blame] | 87 | import static org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility.*; |
Jonathan Hart | 855179c | 2016-04-26 07:40:04 -0700 | [diff] [blame] | 88 | import static org.slf4j.LoggerFactory.getLogger; |
| 89 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 92 | * Driver for software switch emulation of the OFDPA pipeline. |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 93 | * The software switch is the CPqD OF 1.3 switch. Unfortunately the CPqD switch |
| 94 | * does not handle vlan tags and mpls labels simultaneously, which requires us |
| 95 | * to do some workarounds in the driver. This driver is meant for the use of |
| 96 | * the cpqd switch when MPLS is required. As a result this driver works only |
| 97 | * on incoming untagged packets. |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 98 | */ |
Charles Chan | 361154b | 2016-03-24 10:23:39 -0700 | [diff] [blame] | 99 | public class CpqdOfdpa2Pipeline extends Ofdpa2Pipeline { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 100 | |
| 101 | private final Logger log = getLogger(getClass()); |
| 102 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 103 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 104 | * Table that determines whether VLAN is popped before punting to controller. |
| 105 | * <p> |
| 106 | * This is a non-OFDPA table to emulate OFDPA packet in behavior. |
| 107 | * VLAN will be popped before punting if the VLAN is internally assigned. |
| 108 | * <p> |
| 109 | * Also note that 63 is the max table number in CpqD. |
| 110 | */ |
| 111 | private static final int PUNT_TABLE = 63; |
| 112 | |
| 113 | /** |
| 114 | * A static indirect group that pop vlan and punt to controller. |
| 115 | * <p> |
| 116 | * The purpose of using a group instead of immediate action is that this |
| 117 | * won't affect another copy on the data plane when write action exists. |
| 118 | */ |
| 119 | private static final int POP_VLAN_PUNT_GROUP_ID = 0xc0000000; |
| 120 | |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Executor for group checker thread that checks pop vlan punt group. |
| 123 | */ |
| 124 | private ScheduledExecutorService groupChecker; |
| 125 | |
| 126 | /** |
| 127 | * Queue for passing pop vlan punt group flow rules to the GroupChecker thread. |
| 128 | */ |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 129 | private Queue<FlowRule> flowRuleQueue; |
| 130 | |
| 131 | /** |
| 132 | * Lock used in synchronizing driver thread with groupCheckerThread. |
| 133 | */ |
| 134 | private ReentrantLock groupCheckerLock; |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 135 | |
Charles Chan | 053b1cb | 2017-03-22 16:56:35 -0700 | [diff] [blame] | 136 | @Override |
| 137 | protected boolean requireVlanExtensions() { |
| 138 | return false; |
| 139 | } |
| 140 | |
Harshada Chaundkar | b73d5d6 | 2019-08-05 15:33:30 +0000 | [diff] [blame] | 141 | @Override |
| 142 | protected boolean requireEthType() { |
| 143 | return false; |
| 144 | } |
| 145 | |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 146 | /** |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 147 | * Determines whether this pipeline support copy ttl instructions or not. |
| 148 | * |
| 149 | * @return true if copy ttl instructions are supported |
| 150 | */ |
| 151 | protected boolean supportCopyTtl() { |
| 152 | return true; |
| 153 | } |
| 154 | |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Determines whether this pipeline support push mpls to vlan-tagged packets or not. |
| 157 | * <p> |
| 158 | * If not support, pop vlan before push entering unicast and mpls table. |
| 159 | * Side effect: HostService learns redundant hosts with same MAC but |
| 160 | * different VLAN. No known side effect on the network reachability. |
| 161 | * |
| 162 | * @return true if push mpls to vlan-tagged packets is supported |
| 163 | */ |
| 164 | protected boolean supportTaggedMpls() { |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Determines whether this pipeline support punt action in group bucket. |
| 170 | * |
| 171 | * @return true if punt action in group bucket is supported |
| 172 | */ |
| 173 | protected boolean supportPuntGroup() { |
| 174 | return false; |
| 175 | } |
| 176 | |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 177 | @Override |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 178 | protected void initDriverId() { |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 179 | driverId = coreService.registerApplication( |
| 180 | "org.onosproject.driver.CpqdOfdpa2Pipeline"); |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 181 | } |
Charles Chan | 425854b | 2016-04-11 15:32:12 -0700 | [diff] [blame] | 182 | |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 183 | @Override |
| 184 | protected void initGroupHander(PipelinerContext context) { |
pier | 95e6251 | 2020-03-20 11:00:38 +0100 | [diff] [blame^] | 185 | // Terminate internal references |
| 186 | // We are terminating the references here |
| 187 | // because when the device is offline the apps |
| 188 | // are still sending flowobjectives |
| 189 | if (groupHandler != null) { |
| 190 | groupHandler.terminate(); |
| 191 | } |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 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 | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 196 | @Override |
| 197 | public void init(DeviceId deviceId, PipelinerContext context) { |
pier | 95e6251 | 2020-03-20 11:00:38 +0100 | [diff] [blame^] | 198 | synchronized (this) { |
| 199 | if (isReady()) { |
| 200 | return; |
| 201 | } |
| 202 | |
pier | a3b186e | 2020-02-28 09:24:11 +0100 | [diff] [blame] | 203 | if (supportPuntGroup()) { |
pier | 95e6251 | 2020-03-20 11:00:38 +0100 | [diff] [blame^] | 204 | // Terminate internal references |
| 205 | // We are terminating the references here |
| 206 | // because when the device is offline the apps |
| 207 | // are still sending flowobjectives |
| 208 | if (groupChecker != null) { |
| 209 | groupChecker.shutdown(); |
| 210 | } |
pier | a3b186e | 2020-02-28 09:24:11 +0100 | [diff] [blame] | 211 | // create a new executor at each init and a new empty queue |
| 212 | groupChecker = Executors.newSingleThreadScheduledExecutor(groupedThreads("onos/driver", |
| 213 | "cpqd-ofdpa-%d", log)); |
pier | 95e6251 | 2020-03-20 11:00:38 +0100 | [diff] [blame^] | 214 | if (flowRuleQueue != null) { |
| 215 | flowRuleQueue.clear(); |
| 216 | } |
pier | a3b186e | 2020-02-28 09:24:11 +0100 | [diff] [blame] | 217 | flowRuleQueue = new ConcurrentLinkedQueue<>(); |
| 218 | groupCheckerLock = new ReentrantLock(); |
| 219 | groupChecker.scheduleAtFixedRate(new PopVlanPuntGroupChecker(), 20, 50, TimeUnit.MILLISECONDS); |
| 220 | super.init(deviceId, context); |
| 221 | } |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 222 | } |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 223 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 224 | /* |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 225 | * Cpqd emulation does not require the non OF-standard rules for |
| 226 | * matching untagged packets that ofdpa uses. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 227 | * |
| 228 | * (non-Javadoc) |
| 229 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processVlanIdFilter |
| 230 | */ |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 231 | @Override |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 232 | protected List<List<FlowRule>> processVlanIdFilter(PortCriterion portCriterion, |
pier | b2f7114 | 2019-06-10 17:10:26 +0200 | [diff] [blame] | 233 | VlanIdCriterion vidCriterion, |
| 234 | VlanId assignedVlan, |
| 235 | ApplicationId applicationId, |
| 236 | boolean install) { |
Charles Chan | 7976923 | 2016-07-05 16:34:39 -0700 | [diff] [blame] | 237 | List<FlowRule> rules = new ArrayList<>(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 238 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 239 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 240 | selector.matchVlanId(vidCriterion.vlanId()); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 241 | treatment.transition(TMAC_TABLE); |
| 242 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 243 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 244 | // untagged packets are assigned vlans |
| 245 | treatment.pushVlan().setVlanId(assignedVlan); |
Pier | 3cc7e66 | 2018-03-07 11:42:50 +0100 | [diff] [blame] | 246 | } else if (!vidCriterion.vlanId().equals(assignedVlan)) { |
| 247 | // Rewrite with assigned vlans |
| 248 | treatment.setVlanId(assignedVlan); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 249 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 250 | |
| 251 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 252 | // rules for each port. |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 253 | List<PortNumber> portnums = new ArrayList<>(); |
Ray Milkey | 94542b0 | 2018-05-10 12:42:51 -0700 | [diff] [blame] | 254 | if (portCriterion != null) { |
| 255 | if (portCriterion.port() == PortNumber.ALL) { |
| 256 | for (Port port : deviceService.getPorts(deviceId)) { |
| 257 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 258 | portnums.add(port.number()); |
| 259 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 260 | } |
Ray Milkey | 94542b0 | 2018-05-10 12:42:51 -0700 | [diff] [blame] | 261 | } else { |
| 262 | portnums.add(portCriterion.port()); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 263 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 264 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 265 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 266 | for (PortNumber pnum : portnums) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 267 | // NOTE: Emulating OFDPA behavior by popping off internal assigned |
| 268 | // VLAN before sending to controller |
| 269 | if (supportPuntGroup() && vidCriterion.vlanId() == VlanId.NONE) { |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 270 | try { |
| 271 | groupCheckerLock.lock(); |
| 272 | if (flowRuleQueue == null) { |
| 273 | // this means that the group has been created |
| 274 | // and that groupChecker has destroyed the queue |
| 275 | log.debug("Installing punt table rule for untagged port {} and vlan {}.", |
| 276 | pnum, assignedVlan); |
| 277 | rules.add(buildPuntTableRule(pnum, assignedVlan)); |
| 278 | } else { |
| 279 | // The VLAN punt group may be held back due to device initial audit. |
| 280 | // In that case, we queue all punt table flow until the group has been created. |
| 281 | log.debug("popVlanPuntGroup not found in dev:{}, queueing this flow rule.", deviceId); |
| 282 | flowRuleQueue.add(buildPuntTableRule(pnum, assignedVlan)); |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 283 | } |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 284 | } finally { |
| 285 | groupCheckerLock.unlock(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 286 | } |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 287 | } else if (vidCriterion.vlanId() != VlanId.NONE) { |
| 288 | // for tagged ports just forward to the controller |
| 289 | log.debug("Installing punt rule for tagged port {} and vlan {}.", pnum, vidCriterion.vlanId()); |
| 290 | rules.add(buildPuntTableRuleTagged(pnum, vidCriterion.vlanId())); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 293 | // create rest of flowrule |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 294 | selector.matchInPort(pnum); |
| 295 | FlowRule rule = DefaultFlowRule.builder() |
| 296 | .forDevice(deviceId) |
| 297 | .withSelector(selector.build()) |
| 298 | .withTreatment(treatment.build()) |
| 299 | .withPriority(DEFAULT_PRIORITY) |
| 300 | .fromApp(applicationId) |
| 301 | .makePermanent() |
| 302 | .forTable(VLAN_TABLE).build(); |
| 303 | rules.add(rule); |
| 304 | } |
Charles Chan | f57a825 | 2016-06-29 19:12:37 -0700 | [diff] [blame] | 305 | |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 306 | return ImmutableList.of(rules); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 309 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 310 | * Creates punt table entry that matches IN_PORT and VLAN_VID and points to |
| 311 | * a group that pop vlan and punt. |
| 312 | * |
| 313 | * @param portNumber port number |
| 314 | * @param assignedVlan internally assigned vlan id |
| 315 | * @return punt table flow rule |
| 316 | */ |
| 317 | private FlowRule buildPuntTableRule(PortNumber portNumber, VlanId assignedVlan) { |
| 318 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 319 | .matchInPort(portNumber) |
| 320 | .matchVlanId(assignedVlan); |
| 321 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 322 | .group(new GroupId(POP_VLAN_PUNT_GROUP_ID)); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 323 | |
| 324 | return DefaultFlowRule.builder() |
| 325 | .forDevice(deviceId) |
| 326 | .withSelector(sbuilder.build()) |
| 327 | .withTreatment(tbuilder.build()) |
| 328 | .withPriority(PacketPriority.CONTROL.priorityValue()) |
| 329 | .fromApp(driverId) |
| 330 | .makePermanent() |
| 331 | .forTable(PUNT_TABLE).build(); |
| 332 | } |
| 333 | |
| 334 | /** |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 335 | * Creates punt table entry that matches IN_PORT and VLAN_VID and forwards |
| 336 | * packet to controller tagged. |
| 337 | * |
| 338 | * @param portNumber port number |
| 339 | * @param packetVlan vlan tag of the packet |
| 340 | * @return punt table flow rule |
| 341 | */ |
| 342 | private FlowRule buildPuntTableRuleTagged(PortNumber portNumber, VlanId packetVlan) { |
| 343 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 344 | .matchInPort(portNumber) |
| 345 | .matchVlanId(packetVlan); |
| 346 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().punt(); |
| 347 | |
| 348 | return DefaultFlowRule.builder() |
| 349 | .forDevice(deviceId) |
| 350 | .withSelector(sbuilder.build()) |
| 351 | .withTreatment(tbuilder.build()) |
| 352 | .withPriority(PacketPriority.CONTROL.priorityValue()) |
| 353 | .fromApp(driverId) |
| 354 | .makePermanent() |
| 355 | .forTable(PUNT_TABLE).build(); |
| 356 | } |
| 357 | |
| 358 | /** |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 359 | * Builds a punt to the controller rule for the arp protocol. |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 360 | * <p> |
| 361 | * NOTE: CpqD cannot punt correctly in group bucket. The current impl will |
| 362 | * pop VLAN before sending to controller disregarding whether |
| 363 | * it's an internally assigned VLAN or a natural VLAN. |
| 364 | * Therefore, trunk port is not supported in CpqD. |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 365 | * |
| 366 | * @param assignedVlan the internal assigned vlan id |
| 367 | * @param applicationId the application id |
| 368 | * @return the punt flow rule for the arp |
| 369 | */ |
| 370 | private FlowRule buildArpPunt(VlanId assignedVlan, ApplicationId applicationId) { |
| 371 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 372 | .matchEthType(Ethernet.TYPE_ARP) |
| 373 | .matchVlanId(assignedVlan); |
| 374 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
| 375 | .popVlan() |
| 376 | .punt(); |
| 377 | |
| 378 | return DefaultFlowRule.builder() |
| 379 | .forDevice(deviceId) |
| 380 | .withSelector(sbuilder.build()) |
| 381 | .withTreatment(tbuilder.build()) |
| 382 | .withPriority(PacketPriority.CONTROL.priorityValue() + 1) |
| 383 | .fromApp(applicationId) |
| 384 | .makePermanent() |
| 385 | .forTable(ACL_TABLE).build(); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Builds a punt to the controller rule for the icmp v6 messages. |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 390 | * <p> |
| 391 | * NOTE: CpqD cannot punt correctly in group bucket. The current impl will |
| 392 | * pop VLAN before sending to controller disregarding whether |
| 393 | * it's an internally assigned VLAN or a natural VLAN. |
| 394 | * Therefore, trunk port is not supported in CpqD. |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 395 | * |
| 396 | * @param assignedVlan the internal assigned vlan id |
| 397 | * @param applicationId the application id |
| 398 | * @return the punt flow rule for the icmp v6 messages |
| 399 | */ |
| 400 | private FlowRule buildIcmpV6Punt(VlanId assignedVlan, ApplicationId applicationId) { |
| 401 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder() |
| 402 | .matchVlanId(assignedVlan) |
| 403 | .matchEthType(Ethernet.TYPE_IPV6) |
| 404 | .matchIPProtocol(PROTOCOL_ICMP6); |
| 405 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder() |
| 406 | .popVlan() |
| 407 | .punt(); |
| 408 | |
| 409 | return DefaultFlowRule.builder() |
| 410 | .forDevice(deviceId) |
| 411 | .withSelector(sbuilder.build()) |
| 412 | .withTreatment(tbuilder.build()) |
| 413 | .withPriority(PacketPriority.CONTROL.priorityValue() + 1) |
| 414 | .fromApp(applicationId) |
| 415 | .makePermanent() |
| 416 | .forTable(ACL_TABLE).build(); |
| 417 | } |
| 418 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 419 | /* |
| 420 | * Cpqd emulation does not handle vlan tags and mpls labels correctly. |
| 421 | * Workaround requires popping off the VLAN tags in the TMAC table. |
| 422 | * |
| 423 | * (non-Javadoc) |
| 424 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthDstFilter |
| 425 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 426 | @Override |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 427 | protected List<List<FlowRule>> processEthDstFilter(PortCriterion portCriterion, |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 428 | EthCriterion ethCriterion, |
| 429 | VlanIdCriterion vidCriterion, |
| 430 | VlanId assignedVlan, |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 431 | MacAddress unicastMac, |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 432 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 433 | // Consider PortNumber.ANY as wildcard. Match ETH_DST only |
| 434 | if (portCriterion != null && portCriterion.port() == PortNumber.ANY) { |
| 435 | return processEthDstOnlyFilter(ethCriterion, applicationId); |
| 436 | } |
| 437 | |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 438 | // Multicast MAC |
| 439 | if (ethCriterion.mask() != null) { |
Charles Chan | d57552d | 2018-03-02 15:41:41 -0800 | [diff] [blame] | 440 | return processMcastEthDstFilter(ethCriterion, assignedVlan, unicastMac, applicationId); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 443 | //handling untagged packets via assigned VLAN |
| 444 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 445 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
| 446 | } |
| 447 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 448 | // rules for each port. |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 449 | List<PortNumber> portnums = new ArrayList<>(); |
Ray Milkey | ae4e5ed | 2018-01-17 15:24:52 -0800 | [diff] [blame] | 450 | if (portCriterion != null) { |
| 451 | if (portCriterion.port() == PortNumber.ALL) { |
| 452 | for (Port port : deviceService.getPorts(deviceId)) { |
| 453 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 454 | portnums.add(port.number()); |
| 455 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 456 | } |
Ray Milkey | ae4e5ed | 2018-01-17 15:24:52 -0800 | [diff] [blame] | 457 | } else { |
| 458 | portnums.add(portCriterion.port()); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 459 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 462 | List<FlowRule> rules = new ArrayList<>(); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 463 | for (PortNumber pnum : portnums) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 464 | // TMAC rules for unicast IP packets |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 465 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 466 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 467 | selector.matchInPort(pnum); |
| 468 | selector.matchVlanId(vidCriterion.vlanId()); |
| 469 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 470 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 471 | if (!supportTaggedMpls()) { |
| 472 | treatment.popVlan(); |
| 473 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 474 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 475 | FlowRule rule = DefaultFlowRule.builder() |
| 476 | .forDevice(deviceId) |
| 477 | .withSelector(selector.build()) |
| 478 | .withTreatment(treatment.build()) |
| 479 | .withPriority(DEFAULT_PRIORITY) |
| 480 | .fromApp(applicationId) |
| 481 | .makePermanent() |
| 482 | .forTable(TMAC_TABLE).build(); |
| 483 | rules.add(rule); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 484 | |
| 485 | // TMAC rules for MPLS packets |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 486 | selector = DefaultTrafficSelector.builder(); |
| 487 | treatment = DefaultTrafficTreatment.builder(); |
| 488 | selector.matchInPort(pnum); |
| 489 | selector.matchVlanId(vidCriterion.vlanId()); |
| 490 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 491 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 492 | if (!supportTaggedMpls()) { |
| 493 | treatment.popVlan(); |
| 494 | } |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 495 | treatment.transition(MPLS_TABLE_0); |
| 496 | rule = DefaultFlowRule.builder() |
| 497 | .forDevice(deviceId) |
| 498 | .withSelector(selector.build()) |
| 499 | .withTreatment(treatment.build()) |
| 500 | .withPriority(DEFAULT_PRIORITY) |
| 501 | .fromApp(applicationId) |
| 502 | .makePermanent() |
| 503 | .forTable(TMAC_TABLE).build(); |
| 504 | rules.add(rule); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 505 | |
| 506 | // TMAC rules for IPv6 packets |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 507 | selector = DefaultTrafficSelector.builder(); |
| 508 | treatment = DefaultTrafficTreatment.builder(); |
| 509 | selector.matchInPort(pnum); |
| 510 | selector.matchVlanId(vidCriterion.vlanId()); |
| 511 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 512 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 513 | if (!supportTaggedMpls()) { |
| 514 | treatment.popVlan(); |
| 515 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 516 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 517 | rule = DefaultFlowRule.builder() |
| 518 | .forDevice(deviceId) |
| 519 | .withSelector(selector.build()) |
| 520 | .withTreatment(treatment.build()) |
| 521 | .withPriority(DEFAULT_PRIORITY) |
| 522 | .fromApp(applicationId) |
| 523 | .makePermanent() |
| 524 | .forTable(TMAC_TABLE).build(); |
| 525 | rules.add(rule); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 526 | } |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 527 | return ImmutableList.of(rules); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 530 | @Override |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 531 | protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion, |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 532 | ApplicationId applicationId) { |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 533 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 534 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 535 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 536 | selector.matchEthDst(ethCriterion.mac()); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 537 | if (!supportTaggedMpls()) { |
| 538 | treatment.popVlan(); |
| 539 | } |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 540 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 541 | FlowRule rule = DefaultFlowRule.builder() |
| 542 | .forDevice(deviceId) |
| 543 | .withSelector(selector.build()) |
| 544 | .withTreatment(treatment.build()) |
| 545 | .withPriority(DEFAULT_PRIORITY) |
| 546 | .fromApp(applicationId) |
| 547 | .makePermanent() |
| 548 | .forTable(TMAC_TABLE).build(); |
Charles Chan | 206506b | 2018-03-02 16:43:28 -0800 | [diff] [blame] | 549 | return ImmutableList.of(ImmutableList.of(rule)); |
Charles Chan | 5270ed0 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 552 | /* |
| 553 | * Cpqd emulation allows MPLS ecmp. |
| 554 | * |
| 555 | * (non-Javadoc) |
| 556 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthTypeSpecific |
| 557 | */ |
| 558 | @Override |
| 559 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 560 | TrafficSelector selector = fwd.selector(); |
| 561 | EthTypeCriterion ethType = |
| 562 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 563 | if ((ethType == null) || |
| 564 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 565 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST) && |
| 566 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 567 | log.warn("processSpecific: Unsupported forwarding objective criteria" |
| 568 | + "ethType:{} in dev:{}", ethType, deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 569 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 570 | return Collections.emptySet(); |
| 571 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 572 | boolean defaultRule = false; |
Charles Chan | 9309035 | 2018-03-02 13:26:22 -0800 | [diff] [blame] | 573 | int forTableId; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 574 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 575 | TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder(); |
| 576 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 577 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 578 | IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 579 | if (ipv4Dst.isMulticast()) { |
| 580 | if (ipv4Dst.prefixLength() != 32) { |
| 581 | log.warn("Multicast specific forwarding objective can only be /32"); |
| 582 | fail(fwd, ObjectiveError.BADPARAMS); |
| 583 | return ImmutableSet.of(); |
| 584 | } |
| 585 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 586 | if (assignedVlan == null) { |
| 587 | log.warn("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 588 | fail(fwd, ObjectiveError.BADPARAMS); |
| 589 | return ImmutableSet.of(); |
| 590 | } |
| 591 | filteredSelector.matchVlanId(assignedVlan); |
| 592 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
| 593 | forTableId = MULTICAST_ROUTING_TABLE; |
| 594 | log.debug("processing IPv4 multicast specific forwarding objective {} -> next:{}" |
| 595 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 596 | } else { |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 597 | if (ipv4Dst.prefixLength() == 0) { |
| 598 | // The entire IPV4_DST field is wildcarded intentionally |
| 599 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 600 | } else { |
Charles Chan | f9e9865 | 2016-09-07 16:54:23 -0700 | [diff] [blame] | 601 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(ipv4Dst); |
Charles Chan | 5b9df8d | 2016-03-28 22:21:40 -0700 | [diff] [blame] | 602 | } |
| 603 | forTableId = UNICAST_ROUTING_TABLE; |
| 604 | log.debug("processing IPv4 unicast specific forwarding objective {} -> next:{}" |
| 605 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 606 | } |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 607 | } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV6) { |
Julia Ferguson | 65428c3 | 2017-08-10 18:15:24 +0000 | [diff] [blame] | 608 | IpPrefix ipv6Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV6_DST)).ip(); |
| 609 | if (ipv6Dst.isMulticast()) { |
| 610 | if (ipv6Dst.prefixLength() != IpAddress.INET6_BIT_LENGTH) { |
| 611 | log.debug("Multicast specific IPv6 forwarding objective can only be /128"); |
| 612 | fail(fwd, ObjectiveError.BADPARAMS); |
| 613 | return ImmutableSet.of(); |
| 614 | } |
| 615 | VlanId assignedVlan = readVlanFromSelector(fwd.meta()); |
| 616 | if (assignedVlan == null) { |
| 617 | log.debug("VLAN ID required by multicast specific fwd obj is missing. Abort."); |
| 618 | fail(fwd, ObjectiveError.BADPARAMS); |
| 619 | return ImmutableSet.of(); |
| 620 | } |
| 621 | filteredSelector.matchVlanId(assignedVlan); |
| 622 | filteredSelector.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Dst(ipv6Dst); |
| 623 | forTableId = MULTICAST_ROUTING_TABLE; |
| 624 | log.debug("processing IPv6 multicast specific forwarding objective {} -> next:{}" |
| 625 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
| 626 | } else { |
| 627 | if (buildIpv6Selector(filteredSelector, fwd) < 0) { |
| 628 | return Collections.emptyList(); |
| 629 | } |
| 630 | forTableId = UNICAST_ROUTING_TABLE; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 631 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 632 | } else { |
| 633 | filteredSelector |
| 634 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 635 | .matchMplsLabel(((MplsCriterion) |
| 636 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 637 | MplsBosCriterion bos = (MplsBosCriterion) selector |
| 638 | .getCriterion(Criterion.Type.MPLS_BOS); |
| 639 | if (bos != null) { |
| 640 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 641 | } |
| 642 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 643 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 644 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 648 | if (fwd.treatment() != null) { |
| 649 | for (Instruction i : fwd.treatment().allInstructions()) { |
Charles Chan | 40132b3 | 2017-01-22 00:19:37 -0800 | [diff] [blame] | 650 | if (!supportCopyTtl() && i instanceof L3ModificationInstruction) { |
| 651 | L3ModificationInstruction l3instr = (L3ModificationInstruction) i; |
| 652 | if (l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_IN) || |
| 653 | l3instr.subtype().equals(L3ModificationInstruction.L3SubType.TTL_OUT)) { |
| 654 | continue; |
| 655 | } |
| 656 | } |
Charles Chan | 7d10b16 | 2015-12-07 18:54:45 -0800 | [diff] [blame] | 657 | /* |
| 658 | * NOTE: OF-DPA does not support immediate instruction in |
| 659 | * L3 unicast and MPLS table. |
| 660 | */ |
| 661 | tb.deferred().add(i); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
| 665 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 666 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 667 | if (next != null) { |
| 668 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 669 | // we only need the top level group's key to point the flow to it |
| 670 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 671 | if (group == null) { |
Saurav Das | 1ce0a7b | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 672 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 673 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 674 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 675 | return Collections.emptySet(); |
| 676 | } |
| 677 | tb.deferred().group(group.id()); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 678 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 679 | } |
| 680 | tb.transition(ACL_TABLE); |
| 681 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 682 | .fromApp(fwd.appId()) |
| 683 | .withPriority(fwd.priority()) |
| 684 | .forDevice(deviceId) |
| 685 | .withSelector(filteredSelector.build()) |
| 686 | .withTreatment(tb.build()) |
| 687 | .forTable(forTableId); |
| 688 | |
| 689 | if (fwd.permanent()) { |
| 690 | ruleBuilder.makePermanent(); |
| 691 | } else { |
| 692 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 693 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 694 | Collection<FlowRule> flowRuleCollection = new ArrayList<>(); |
| 695 | flowRuleCollection.add(ruleBuilder.build()); |
| 696 | if (defaultRule) { |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 697 | flowRuleCollection.add( |
| 698 | defaultRoute(fwd, complementarySelector, forTableId, tb) |
| 699 | ); |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 700 | log.debug("Default rule 0.0.0.0/0 is being installed two rules"); |
| 701 | } |
Flavio Castro | e10fa24 | 2016-01-15 12:43:51 -0800 | [diff] [blame] | 702 | return flowRuleCollection; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Charles Chan | 1e492d3 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 705 | @Override |
| 706 | protected Collection<FlowRule> processEthDstSpecific(ForwardingObjective fwd) { |
| 707 | List<FlowRule> rules = new ArrayList<>(); |
| 708 | |
| 709 | // Build filtered selector |
| 710 | TrafficSelector selector = fwd.selector(); |
| 711 | EthCriterion ethCriterion = (EthCriterion) selector |
| 712 | .getCriterion(Criterion.Type.ETH_DST); |
| 713 | VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector |
| 714 | .getCriterion(Criterion.Type.VLAN_VID); |
| 715 | |
| 716 | if (vlanIdCriterion == null) { |
| 717 | log.warn("Forwarding objective for bridging requires vlan. Not " |
| 718 | + "installing fwd:{} in dev:{}", fwd.id(), deviceId); |
| 719 | fail(fwd, ObjectiveError.BADPARAMS); |
| 720 | return Collections.emptySet(); |
| 721 | } |
| 722 | |
| 723 | TrafficSelector.Builder filteredSelectorBuilder = |
| 724 | DefaultTrafficSelector.builder(); |
| 725 | // Do not match MacAddress for subnet broadcast entry |
Charles Chan | d05f54b | 2017-02-13 11:56:54 -0800 | [diff] [blame] | 726 | if (!ethCriterion.mac().equals(NONE) && !ethCriterion.mac().equals(BROADCAST)) { |
Charles Chan | 1e492d3 | 2016-01-30 23:22:37 -0800 | [diff] [blame] | 727 | filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); |
| 728 | log.debug("processing L2 forwarding objective:{} -> next:{} in dev:{}", |
| 729 | fwd.id(), fwd.nextId(), deviceId); |
| 730 | } else { |
| 731 | log.debug("processing L2 Broadcast forwarding objective:{} -> next:{} " |
| 732 | + "in dev:{} for vlan:{}", |
| 733 | fwd.id(), fwd.nextId(), deviceId, vlanIdCriterion.vlanId()); |
| 734 | } |
| 735 | filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); |
| 736 | TrafficSelector filteredSelector = filteredSelectorBuilder.build(); |
| 737 | |
| 738 | if (fwd.treatment() != null) { |
| 739 | log.warn("Ignoring traffic treatment in fwd rule {} meant for L2 table" |
| 740 | + "for dev:{}. Expecting only nextId", fwd.id(), deviceId); |
| 741 | } |
| 742 | |
| 743 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 744 | if (fwd.nextId() != null) { |
| 745 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 746 | if (next != null) { |
| 747 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 748 | // we only need the top level group's key to point the flow to it |
| 749 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 750 | if (group != null) { |
| 751 | treatmentBuilder.deferred().group(group.id()); |
| 752 | } else { |
| 753 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 754 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 755 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 756 | return Collections.emptySet(); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | treatmentBuilder.immediate().transition(ACL_TABLE); |
| 761 | TrafficTreatment filteredTreatment = treatmentBuilder.build(); |
| 762 | |
| 763 | // Build bridging table entries |
| 764 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); |
| 765 | flowRuleBuilder.fromApp(fwd.appId()) |
| 766 | .withPriority(fwd.priority()) |
| 767 | .forDevice(deviceId) |
| 768 | .withSelector(filteredSelector) |
| 769 | .withTreatment(filteredTreatment) |
| 770 | .forTable(BRIDGING_TABLE); |
| 771 | if (fwd.permanent()) { |
| 772 | flowRuleBuilder.makePermanent(); |
| 773 | } else { |
| 774 | flowRuleBuilder.makeTemporary(fwd.timeout()); |
| 775 | } |
| 776 | rules.add(flowRuleBuilder.build()); |
| 777 | return rules; |
| 778 | } |
| 779 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 780 | /* |
| 781 | * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the |
| 782 | * ACL table. Because we pop off vlan tags in TMAC table, |
| 783 | * we need to avoid matching on vlans in the ACL table. |
| 784 | */ |
| 785 | @Override |
| 786 | protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
| 787 | log.info("Processing versatile forwarding objective"); |
| 788 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 789 | if (fwd.nextId() == null && fwd.treatment() == null) { |
| 790 | log.error("Forwarding objective {} from {} must contain " |
| 791 | + "nextId or Treatment", fwd.selector(), fwd.appId()); |
| 792 | return Collections.emptySet(); |
| 793 | } |
| 794 | |
| 795 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 796 | fwd.selector().criteria().forEach(criterion -> { |
| 797 | if (criterion instanceof VlanIdCriterion) { |
| 798 | // avoid matching on vlans |
| 799 | return; |
Pier Ventre | e0ae7a3 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 800 | } else if (criterion instanceof Icmpv6TypeCriterion || |
| 801 | criterion instanceof Icmpv6CodeCriterion) { |
| 802 | /* |
| 803 | * We silenty discard these criterions, our current |
| 804 | * OFDPA platform does not support these matches on |
| 805 | * the ACL table. |
| 806 | */ |
| 807 | log.warn("ICMPv6 Type and ICMPv6 Code are not supported"); |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 808 | } else { |
| 809 | sbuilder.add(criterion); |
| 810 | } |
| 811 | }); |
| 812 | |
| 813 | // XXX driver does not currently do type checking as per Tables 65-67 in |
| 814 | // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller. |
| 815 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 816 | if (fwd.treatment() != null) { |
| 817 | for (Instruction ins : fwd.treatment().allInstructions()) { |
| 818 | if (ins instanceof OutputInstruction) { |
| 819 | OutputInstruction o = (OutputInstruction) ins; |
| 820 | if (o.port() == PortNumber.CONTROLLER) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 821 | ttBuilder.transition(PUNT_TABLE); |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 822 | } else { |
| 823 | log.warn("Only allowed treatments in versatile forwarding " |
| 824 | + "objectives are punts to the controller"); |
| 825 | } |
Charles Chan | 3fe7171 | 2018-06-15 18:54:18 -0700 | [diff] [blame] | 826 | } else if (ins instanceof NoActionInstruction) { |
| 827 | // No action is allowed and nothing needs to be done |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 828 | } else { |
| 829 | log.warn("Cannot process instruction in versatile fwd {}", ins); |
| 830 | } |
| 831 | } |
Charles Chan | 2df0e8a | 2017-01-09 11:45:08 -0800 | [diff] [blame] | 832 | if (fwd.treatment().clearedDeferred()) { |
| 833 | ttBuilder.wipeDeferred(); |
| 834 | } |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame] | 835 | } |
| 836 | if (fwd.nextId() != null) { |
| 837 | // overide case |
| 838 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 839 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 840 | // we only need the top level group's key to point the flow to it |
| 841 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 842 | if (group == null) { |
| 843 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 844 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 845 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 846 | return Collections.emptySet(); |
| 847 | } |
| 848 | ttBuilder.deferred().group(group.id()); |
| 849 | } |
| 850 | |
| 851 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 852 | .fromApp(fwd.appId()) |
| 853 | .withPriority(fwd.priority()) |
| 854 | .forDevice(deviceId) |
| 855 | .withSelector(sbuilder.build()) |
| 856 | .withTreatment(ttBuilder.build()) |
| 857 | .makePermanent() |
| 858 | .forTable(ACL_TABLE); |
| 859 | return Collections.singletonList(ruleBuilder.build()); |
| 860 | } |
| 861 | |
| 862 | /* |
| 863 | * Cpqd emulation requires table-miss-entries in forwarding tables. |
| 864 | * Real OFDPA does not require these rules as they are put in by default. |
| 865 | * |
| 866 | * (non-Javadoc) |
| 867 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#initializePipeline() |
| 868 | */ |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 869 | @Override |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 870 | protected void initializePipeline() { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 871 | initTableMiss(PORT_TABLE, VLAN_TABLE, null); |
| 872 | initTableMiss(VLAN_TABLE, ACL_TABLE, null); |
| 873 | initTableMiss(TMAC_TABLE, BRIDGING_TABLE, null); |
| 874 | initTableMiss(UNICAST_ROUTING_TABLE, ACL_TABLE, null); |
| 875 | initTableMiss(MULTICAST_ROUTING_TABLE, ACL_TABLE, null); |
| 876 | initTableMiss(MPLS_TABLE_0, MPLS_TABLE_1, null); |
| 877 | initTableMiss(MPLS_TABLE_1, ACL_TABLE, null); |
| 878 | initTableMiss(BRIDGING_TABLE, ACL_TABLE, null); |
| 879 | initTableMiss(ACL_TABLE, -1, null); |
Charles Chan | 4e9620d | 2019-11-01 16:00:39 -0700 | [diff] [blame] | 880 | initPuntTable(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 881 | |
| 882 | if (supportPuntGroup()) { |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 883 | initPopVlanPuntGroup(); |
| 884 | } else { |
| 885 | initTableMiss(PUNT_TABLE, -1, |
| 886 | DefaultTrafficTreatment.builder().popVlan().punt().build()); |
| 887 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 890 | /** |
| 891 | * Install table-miss flow entry. |
| 892 | * |
| 893 | * If treatment exists, use it directly. |
| 894 | * Else if treatment does not exist but nextTable > 0, transit to next table. |
| 895 | * Else apply empty treatment. |
| 896 | * |
| 897 | * @param thisTable this table ID |
| 898 | * @param nextTable next table ID |
| 899 | * @param treatment traffic treatment to apply. |
| 900 | */ |
| 901 | private void initTableMiss(int thisTable, int nextTable, TrafficTreatment treatment) { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 902 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 903 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 904 | |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 905 | if (treatment == null) { |
| 906 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 907 | if (nextTable > 0) { |
| 908 | tBuilder.transition(nextTable); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 909 | } |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 910 | treatment = tBuilder.build(); |
| 911 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 912 | |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 913 | FlowRule rule = DefaultFlowRule.builder() |
| 914 | .forDevice(deviceId) |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 915 | .withSelector(selector) |
| 916 | .withTreatment(treatment) |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 917 | .withPriority(LOWEST_PRIORITY) |
| 918 | .fromApp(driverId) |
| 919 | .makePermanent() |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 920 | .forTable(thisTable).build(); |
Charles Chan | b750439 | 2017-02-10 12:51:04 -0800 | [diff] [blame] | 921 | ops = ops.add(rule); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 922 | |
| 923 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 924 | @Override |
| 925 | public void onSuccess(FlowRuleOperations ops) { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 926 | log.info("Initialized table {} on {}", thisTable, deviceId); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 927 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 928 | @Override |
| 929 | public void onError(FlowRuleOperations ops) { |
Charles Chan | f6ec153 | 2017-02-08 16:10:40 -0800 | [diff] [blame] | 930 | log.warn("Failed to initialize table {} on {}", thisTable, deviceId); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 931 | } |
| 932 | })); |
| 933 | } |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 934 | |
| 935 | /** |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 936 | * Install lldp/bbdp matching rules at table PUNT_TABLE |
| 937 | * that forward traffic to controller. |
| 938 | * |
| 939 | */ |
Charles Chan | 4e9620d | 2019-11-01 16:00:39 -0700 | [diff] [blame] | 940 | private void initPuntTable() { |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 941 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 942 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build(); |
| 943 | |
Charles Chan | 4e9620d | 2019-11-01 16:00:39 -0700 | [diff] [blame] | 944 | // Add punt rule for LLDP and BDDP |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 945 | TrafficSelector.Builder lldpSelector = DefaultTrafficSelector.builder(); |
| 946 | lldpSelector.matchEthType(EthType.EtherType.LLDP.ethType().toShort()); |
| 947 | FlowRule lldpRule = DefaultFlowRule.builder() |
| 948 | .forDevice(deviceId) |
| 949 | .withSelector(lldpSelector.build()) |
| 950 | .withTreatment(treatment) |
| 951 | .withPriority(HIGHEST_PRIORITY) |
| 952 | .fromApp(driverId) |
| 953 | .makePermanent() |
| 954 | .forTable(PUNT_TABLE).build(); |
| 955 | ops = ops.add(lldpRule); |
| 956 | |
| 957 | TrafficSelector.Builder bbdpSelector = DefaultTrafficSelector.builder(); |
| 958 | bbdpSelector.matchEthType(EthType.EtherType.BDDP.ethType().toShort()); |
| 959 | FlowRule bbdpRule = DefaultFlowRule.builder() |
| 960 | .forDevice(deviceId) |
| 961 | .withSelector(bbdpSelector.build()) |
| 962 | .withTreatment(treatment) |
| 963 | .withPriority(HIGHEST_PRIORITY) |
| 964 | .fromApp(driverId) |
| 965 | .makePermanent() |
| 966 | .forTable(PUNT_TABLE).build(); |
| 967 | ops.add(bbdpRule); |
| 968 | |
| 969 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 970 | @Override |
| 971 | public void onSuccess(FlowRuleOperations ops) { |
Charles Chan | 4e9620d | 2019-11-01 16:00:39 -0700 | [diff] [blame] | 972 | log.info("Initialized table {} on {}", PUNT_TABLE, deviceId); |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 973 | } |
| 974 | @Override |
| 975 | public void onError(FlowRuleOperations ops) { |
Charles Chan | 4e9620d | 2019-11-01 16:00:39 -0700 | [diff] [blame] | 976 | log.warn("Failed to initialize table {} on {}", PUNT_TABLE, deviceId); |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 977 | } |
| 978 | })); |
| 979 | } |
| 980 | |
| 981 | /** |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 982 | * Builds a indirect group contains pop_vlan and punt actions. |
| 983 | * <p> |
| 984 | * Using group instead of immediate action to ensure that |
| 985 | * the copy of packet on the data plane is not affected by the pop vlan action. |
| 986 | */ |
| 987 | private void initPopVlanPuntGroup() { |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 988 | GroupKey groupKey = popVlanPuntGroupKey(); |
Charles Chan | 0f43e47 | 2017-02-14 14:00:16 -0800 | [diff] [blame] | 989 | TrafficTreatment bucketTreatment = DefaultTrafficTreatment.builder() |
| 990 | .popVlan().punt().build(); |
| 991 | GroupBucket bucket = |
| 992 | DefaultGroupBucket.createIndirectGroupBucket(bucketTreatment); |
| 993 | GroupDescription groupDesc = |
| 994 | new DefaultGroupDescription( |
| 995 | deviceId, |
| 996 | GroupDescription.Type.INDIRECT, |
| 997 | new GroupBuckets(Collections.singletonList(bucket)), |
| 998 | groupKey, |
| 999 | POP_VLAN_PUNT_GROUP_ID, |
| 1000 | driverId); |
| 1001 | groupService.addGroup(groupDesc); |
| 1002 | |
| 1003 | log.info("Initialized pop vlan punt group on {}", deviceId); |
| 1004 | } |
Yi Tseng | ef19de1 | 2017-04-24 11:33:05 -0700 | [diff] [blame] | 1005 | |
| 1006 | /** |
| 1007 | * Generates group key for a static indirect group that pop vlan and punt to |
| 1008 | * controller. |
| 1009 | * |
| 1010 | * @return the group key of the indirect table |
| 1011 | */ |
| 1012 | private GroupKey popVlanPuntGroupKey() { |
| 1013 | int hash = POP_VLAN_PUNT_GROUP_ID | (Objects.hash(deviceId) & FOUR_BIT_MASK); |
| 1014 | return new DefaultGroupKey(Ofdpa2Pipeline.appKryo.serialize(hash)); |
| 1015 | } |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1016 | |
| 1017 | private class PopVlanPuntGroupChecker implements Runnable { |
| 1018 | @Override |
| 1019 | public void run() { |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1020 | try { |
| 1021 | groupCheckerLock.lock(); |
| 1022 | // this can happen outside of the lock but I think it is safer |
| 1023 | // to include it here. |
| 1024 | Group group = groupService.getGroup(deviceId, popVlanPuntGroupKey()); |
| 1025 | if (group != null) { |
| 1026 | log.debug("PopVlanPuntGroupChecker: Installing {} missing rules at punt table.", |
| 1027 | flowRuleQueue.size()); |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1028 | |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1029 | // if we have pending flow rules install them |
| 1030 | if (flowRuleQueue.size() > 0) { |
| 1031 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 1032 | // we should not care about the context here, it can only be add |
| 1033 | // since when removing the rules the group should be there already. |
| 1034 | flowRuleQueue.forEach(ops::add); |
| 1035 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 1036 | @Override |
| 1037 | public void onSuccess(FlowRuleOperations ops) { |
| 1038 | log.debug("Applied {} pop vlan punt rules in device {}", |
| 1039 | ops.stages().get(0).size(), deviceId); |
| 1040 | } |
| 1041 | |
| 1042 | @Override |
| 1043 | public void onError(FlowRuleOperations ops) { |
| 1044 | log.error("Failed to apply all pop vlan punt rules in dev {}", deviceId); |
| 1045 | } |
| 1046 | })); |
| 1047 | } |
| 1048 | // this signifies that the group is created and now |
| 1049 | // flow rules can be installed directly |
| 1050 | flowRuleQueue = null; |
pier | 4d7fd09 | 2020-01-23 11:59:56 +0100 | [diff] [blame] | 1051 | // Schedule with an initial delay the miss table flow rule installation |
| 1052 | // the delay is to make sure the queued flows are all installed before |
| 1053 | // pushing the table miss flow rule |
| 1054 | // TODO it can be further optimized by using context and completable future |
| 1055 | groupChecker.schedule(new TableMissFlowInstaller(), 5000, TimeUnit.MILLISECONDS); |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1056 | } |
Andreas Pantelopoulos | c78c1f5 | 2018-06-04 15:10:35 -0700 | [diff] [blame] | 1057 | } finally { |
| 1058 | groupCheckerLock.unlock(); |
Andreas Pantelopoulos | 410d730 | 2018-05-30 14:30:24 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | } |
pier | 4d7fd09 | 2020-01-23 11:59:56 +0100 | [diff] [blame] | 1062 | |
| 1063 | private class TableMissFlowInstaller implements Runnable { |
| 1064 | @Override |
| 1065 | public void run() { |
| 1066 | // Add table miss flow rule |
| 1067 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 1068 | TrafficSelector.Builder defaultSelector = DefaultTrafficSelector.builder(); |
| 1069 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build(); |
| 1070 | FlowRule defaultRule = DefaultFlowRule.builder() |
| 1071 | .forDevice(deviceId) |
| 1072 | .withSelector(defaultSelector.build()) |
| 1073 | .withTreatment(treatment) |
| 1074 | .withPriority(LOWEST_PRIORITY) |
| 1075 | .fromApp(driverId) |
| 1076 | .makePermanent() |
| 1077 | .forTable(PUNT_TABLE).build(); |
| 1078 | ops.add(defaultRule); |
| 1079 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 1080 | @Override |
| 1081 | public void onSuccess(FlowRuleOperations ops) { |
| 1082 | log.info("Initialized table miss flow rule {} on {}", PUNT_TABLE, deviceId); |
| 1083 | } |
| 1084 | @Override |
| 1085 | public void onError(FlowRuleOperations ops) { |
| 1086 | log.warn("Failed to initialize table miss flow rule {} on {}", PUNT_TABLE, deviceId); |
| 1087 | } |
| 1088 | })); |
| 1089 | // shutdown the group checker gracefully |
| 1090 | groupChecker.shutdown(); |
| 1091 | } |
| 1092 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 1093 | } |