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