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