Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 16 | package org.onosproject.driver.pipeline; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 20 | import java.util.ArrayList; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 21 | import java.util.Collection; |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 22 | import java.util.Collections; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 23 | import java.util.Deque; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 24 | import java.util.List; |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 25 | import java.util.Set; |
| 26 | import java.util.concurrent.ConcurrentHashMap; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 27 | |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 28 | import org.onlab.packet.Ethernet; |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame^] | 29 | import org.onlab.packet.MacAddress; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 30 | import org.onlab.packet.VlanId; |
| 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.net.Port; |
| 33 | import org.onosproject.net.PortNumber; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 34 | import org.onosproject.net.behaviour.NextGroup; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 35 | import org.onosproject.net.flow.DefaultFlowRule; |
| 36 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 37 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 38 | import org.onosproject.net.flow.FlowRule; |
| 39 | import org.onosproject.net.flow.FlowRuleOperations; |
| 40 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 41 | import org.onosproject.net.flow.TrafficSelector; |
| 42 | import org.onosproject.net.flow.TrafficTreatment; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 43 | import org.onosproject.net.flow.criteria.Criteria; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.criteria.Criterion; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 45 | import org.onosproject.net.flow.criteria.EthCriterion; |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 46 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 47 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 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; |
| 54 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
| 55 | import org.onosproject.net.flowobjective.FilteringObjective; |
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; |
| 58 | import org.onosproject.net.group.Group; |
| 59 | import org.onosproject.net.group.GroupKey; |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 60 | import org.slf4j.Logger; |
| 61 | |
| 62 | |
| 63 | /** |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 64 | * Driver for software switch emulation of the OFDPA 2.0 pipeline. |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame^] | 65 | * The software switch is the CPqD OF 1.3 switch. Unfortunately the CPqD switch |
| 66 | * does not handle vlan tags and mpls labels simultaneously, which requires us |
| 67 | * to do some workarounds in the driver. This driver is meant for the use of |
| 68 | * the cpqd switch when MPLS is required. As a result this driver works only |
| 69 | * on incoming untagged packets. |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 70 | */ |
Saurav Das | 822c4e2 | 2015-10-23 10:51:11 -0700 | [diff] [blame] | 71 | public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 72 | |
| 73 | private final Logger log = getLogger(getClass()); |
| 74 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 75 | /* |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame^] | 76 | * CPQD emulation does not require special untagged packet handling, unlike |
| 77 | * the real ofdpa. |
| 78 | */ |
| 79 | @Override |
| 80 | protected void processFilter(FilteringObjective filt, |
| 81 | boolean install, ApplicationId applicationId) { |
| 82 | // This driver only processes filtering criteria defined with switch |
| 83 | // ports as the key |
| 84 | PortCriterion portCriterion = null; |
| 85 | EthCriterion ethCriterion = null; |
| 86 | VlanIdCriterion vidCriterion = null; |
| 87 | Collection<IPCriterion> ips = new ArrayList<IPCriterion>(); |
| 88 | if (!filt.key().equals(Criteria.dummy()) && |
| 89 | filt.key().type() == Criterion.Type.IN_PORT) { |
| 90 | portCriterion = (PortCriterion) filt.key(); |
| 91 | } else { |
| 92 | log.warn("No key defined in filtering objective from app: {}. Not" |
| 93 | + "processing filtering objective", applicationId); |
| 94 | fail(filt, ObjectiveError.UNKNOWN); |
| 95 | return; |
| 96 | } |
| 97 | // convert filtering conditions for switch-intfs into flowrules |
| 98 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 99 | for (Criterion criterion : filt.conditions()) { |
| 100 | if (criterion.type() == Criterion.Type.ETH_DST) { |
| 101 | ethCriterion = (EthCriterion) criterion; |
| 102 | } else if (criterion.type() == Criterion.Type.VLAN_VID) { |
| 103 | vidCriterion = (VlanIdCriterion) criterion; |
| 104 | } else if (criterion.type() == Criterion.Type.IPV4_DST) { |
| 105 | ips.add((IPCriterion) criterion); |
| 106 | } else { |
| 107 | log.error("Unsupported filter {}", criterion); |
| 108 | fail(filt, ObjectiveError.UNSUPPORTED); |
| 109 | return; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | VlanId assignedVlan = null; |
| 114 | // For VLAN cross-connect packets, use the configured VLAN |
| 115 | if (vidCriterion != null) { |
| 116 | if (vidCriterion.vlanId() != VlanId.NONE) { |
| 117 | assignedVlan = vidCriterion.vlanId(); |
| 118 | |
| 119 | // For untagged packets, assign a VLAN ID |
| 120 | } else { |
| 121 | if (filt.meta() == null) { |
| 122 | log.error("Missing metadata in filtering objective required " + |
| 123 | "for vlan assignment in dev {}", deviceId); |
| 124 | fail(filt, ObjectiveError.BADPARAMS); |
| 125 | return; |
| 126 | } |
| 127 | for (Instruction i : filt.meta().allInstructions()) { |
| 128 | if (i instanceof ModVlanIdInstruction) { |
| 129 | assignedVlan = ((ModVlanIdInstruction) i).vlanId(); |
| 130 | } |
| 131 | } |
| 132 | if (assignedVlan == null) { |
| 133 | log.error("Driver requires an assigned vlan-id to tag incoming " |
| 134 | + "untagged packets. Not processing vlan filters on " |
| 135 | + "device {}", deviceId); |
| 136 | fail(filt, ObjectiveError.BADPARAMS); |
| 137 | return; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if (ethCriterion == null || ethCriterion.mac().equals(MacAddress.NONE)) { |
| 143 | log.debug("filtering objective missing dstMac, cannot program TMAC table"); |
| 144 | } else { |
| 145 | for (FlowRule tmacRule : processEthDstFilter(portCriterion, ethCriterion, |
| 146 | vidCriterion, assignedVlan, |
| 147 | applicationId)) { |
| 148 | log.debug("adding MAC filtering rules in TMAC table: {} for dev: {}", |
| 149 | tmacRule, deviceId); |
| 150 | ops = install ? ops.add(tmacRule) : ops.remove(tmacRule); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | if (ethCriterion == null || vidCriterion == null) { |
| 155 | log.debug("filtering objective missing dstMac or VLAN, " |
| 156 | + "cannot program VLAN Table"); |
| 157 | } else { |
| 158 | List<FlowRule> allRules = processVlanIdFilter( |
| 159 | portCriterion, vidCriterion, assignedVlan, applicationId); |
| 160 | for (FlowRule rule : allRules) { |
| 161 | log.debug("adding VLAN filtering rule in VLAN table: {} for dev: {}", |
| 162 | rule, deviceId); |
| 163 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | for (IPCriterion ipaddr : ips) { |
| 168 | // since we ignore port information for IP rules, and the same (gateway) IP |
| 169 | // can be configured on multiple ports, we make sure that we send |
| 170 | // only a single rule to the switch. |
| 171 | if (!sentIpFilters.contains(ipaddr)) { |
| 172 | sentIpFilters.add(ipaddr); |
| 173 | log.debug("adding IP filtering rules in ACL table {} for dev: {}", |
| 174 | ipaddr, deviceId); |
| 175 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 176 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 177 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 178 | selector.matchIPDst(ipaddr.ip()); |
| 179 | treatment.setOutput(PortNumber.CONTROLLER); |
| 180 | FlowRule rule = DefaultFlowRule.builder() |
| 181 | .forDevice(deviceId) |
| 182 | .withSelector(selector.build()) |
| 183 | .withTreatment(treatment.build()) |
| 184 | .withPriority(HIGHEST_PRIORITY) |
| 185 | .fromApp(applicationId) |
| 186 | .makePermanent() |
| 187 | .forTable(ACL_TABLE).build(); |
| 188 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // apply filtering flow rules |
| 193 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 194 | @Override |
| 195 | public void onSuccess(FlowRuleOperations ops) { |
| 196 | log.info("Applied {} filtering rules in device {}", |
| 197 | ops.stages().get(0).size(), deviceId); |
| 198 | pass(filt); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public void onError(FlowRuleOperations ops) { |
| 203 | log.info("Failed to apply all filtering rules in dev {}", deviceId); |
| 204 | fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED); |
| 205 | } |
| 206 | })); |
| 207 | |
| 208 | } |
| 209 | |
| 210 | /* |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 211 | * Cpqd emulation does not require the non-OF standard rules for |
| 212 | * matching untagged packets. |
| 213 | * |
| 214 | * (non-Javadoc) |
| 215 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processVlanIdFilter |
| 216 | */ |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 217 | @Override |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 218 | protected List<FlowRule> processVlanIdFilter(PortCriterion portCriterion, |
| 219 | VlanIdCriterion vidCriterion, |
| 220 | VlanId assignedVlan, |
| 221 | ApplicationId applicationId) { |
| 222 | List<FlowRule> rules = new ArrayList<FlowRule>(); |
| 223 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 224 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 225 | selector.matchVlanId(vidCriterion.vlanId()); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 226 | treatment.transition(TMAC_TABLE); |
| 227 | |
| 228 | VlanId storeVlan = null; |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 229 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 230 | // untagged packets are assigned vlans |
| 231 | treatment.pushVlan().setVlanId(assignedVlan); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 232 | storeVlan = assignedVlan; |
| 233 | } else { |
| 234 | storeVlan = vidCriterion.vlanId(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 235 | } |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 236 | |
| 237 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 238 | // rules for each port. |
| 239 | List<PortNumber> portnums = new ArrayList<PortNumber>(); |
| 240 | if (portCriterion.port() == PortNumber.ALL) { |
| 241 | for (Port port : deviceService.getPorts(deviceId)) { |
| 242 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 243 | portnums.add(port.number()); |
| 244 | } |
| 245 | } |
| 246 | } else { |
| 247 | portnums.add(portCriterion.port()); |
| 248 | } |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 249 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 250 | for (PortNumber pnum : portnums) { |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 251 | // update storage |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 252 | ofdpa2GroupHandler.port2Vlan.put(pnum, storeVlan); |
| 253 | Set<PortNumber> vlanPorts = ofdpa2GroupHandler.vlan2Port.get(storeVlan); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 254 | if (vlanPorts == null) { |
| 255 | vlanPorts = Collections.newSetFromMap( |
| 256 | new ConcurrentHashMap<PortNumber, Boolean>()); |
| 257 | vlanPorts.add(pnum); |
Charles Chan | 188ebf5 | 2015-12-23 00:15:11 -0800 | [diff] [blame] | 258 | ofdpa2GroupHandler.vlan2Port.put(storeVlan, vlanPorts); |
Saurav Das | 4f98008 | 2015-11-05 13:39:15 -0800 | [diff] [blame] | 259 | } else { |
| 260 | vlanPorts.add(pnum); |
| 261 | } |
| 262 | // create rest of flowrule |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 263 | selector.matchInPort(pnum); |
| 264 | FlowRule rule = DefaultFlowRule.builder() |
| 265 | .forDevice(deviceId) |
| 266 | .withSelector(selector.build()) |
| 267 | .withTreatment(treatment.build()) |
| 268 | .withPriority(DEFAULT_PRIORITY) |
| 269 | .fromApp(applicationId) |
| 270 | .makePermanent() |
| 271 | .forTable(VLAN_TABLE).build(); |
| 272 | rules.add(rule); |
| 273 | } |
| 274 | return rules; |
| 275 | } |
| 276 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 277 | /* |
| 278 | * Cpqd emulation does not handle vlan tags and mpls labels correctly. |
| 279 | * Workaround requires popping off the VLAN tags in the TMAC table. |
| 280 | * |
| 281 | * (non-Javadoc) |
| 282 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthDstFilter |
| 283 | */ |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 284 | @Override |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 285 | protected List<FlowRule> processEthDstFilter(PortCriterion portCriterion, |
| 286 | EthCriterion ethCriterion, |
| 287 | VlanIdCriterion vidCriterion, |
| 288 | VlanId assignedVlan, |
| 289 | ApplicationId applicationId) { |
| 290 | //handling untagged packets via assigned VLAN |
| 291 | if (vidCriterion.vlanId() == VlanId.NONE) { |
| 292 | vidCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); |
| 293 | } |
| 294 | // ofdpa cannot match on ALL portnumber, so we need to use separate |
| 295 | // rules for each port. |
| 296 | List<PortNumber> portnums = new ArrayList<PortNumber>(); |
| 297 | if (portCriterion.port() == PortNumber.ALL) { |
| 298 | for (Port port : deviceService.getPorts(deviceId)) { |
| 299 | if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { |
| 300 | portnums.add(port.number()); |
| 301 | } |
| 302 | } |
| 303 | } else { |
| 304 | portnums.add(portCriterion.port()); |
| 305 | } |
| 306 | |
| 307 | List<FlowRule> rules = new ArrayList<FlowRule>(); |
| 308 | for (PortNumber pnum : portnums) { |
| 309 | // for unicast IP packets |
| 310 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 311 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 312 | selector.matchInPort(pnum); |
| 313 | selector.matchVlanId(vidCriterion.vlanId()); |
| 314 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 315 | selector.matchEthDst(ethCriterion.mac()); |
| 316 | /* |
| 317 | * Note: CpqD switches do not handle MPLS-related operation properly |
| 318 | * for a packet with VLAN tag. We pop VLAN here as a workaround. |
| 319 | * Side effect: HostService learns redundant hosts with same MAC but |
| 320 | * different VLAN. No known side effect on the network reachability. |
| 321 | */ |
| 322 | treatment.popVlan(); |
| 323 | treatment.transition(UNICAST_ROUTING_TABLE); |
| 324 | FlowRule rule = DefaultFlowRule.builder() |
| 325 | .forDevice(deviceId) |
| 326 | .withSelector(selector.build()) |
| 327 | .withTreatment(treatment.build()) |
| 328 | .withPriority(DEFAULT_PRIORITY) |
| 329 | .fromApp(applicationId) |
| 330 | .makePermanent() |
| 331 | .forTable(TMAC_TABLE).build(); |
| 332 | rules.add(rule); |
| 333 | //for MPLS packets |
| 334 | selector = DefaultTrafficSelector.builder(); |
| 335 | treatment = DefaultTrafficTreatment.builder(); |
| 336 | selector.matchInPort(pnum); |
| 337 | selector.matchVlanId(vidCriterion.vlanId()); |
| 338 | selector.matchEthType(Ethernet.MPLS_UNICAST); |
| 339 | selector.matchEthDst(ethCriterion.mac()); |
| 340 | // workaround here again |
| 341 | treatment.popVlan(); |
| 342 | treatment.transition(MPLS_TABLE_0); |
| 343 | rule = DefaultFlowRule.builder() |
| 344 | .forDevice(deviceId) |
| 345 | .withSelector(selector.build()) |
| 346 | .withTreatment(treatment.build()) |
| 347 | .withPriority(DEFAULT_PRIORITY) |
| 348 | .fromApp(applicationId) |
| 349 | .makePermanent() |
| 350 | .forTable(TMAC_TABLE).build(); |
| 351 | rules.add(rule); |
| 352 | } |
| 353 | return rules; |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * Cpqd emulation allows MPLS ecmp. |
| 358 | * |
| 359 | * (non-Javadoc) |
| 360 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#processEthTypeSpecific |
| 361 | */ |
| 362 | @Override |
| 363 | protected Collection<FlowRule> processEthTypeSpecific(ForwardingObjective fwd) { |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 364 | TrafficSelector selector = fwd.selector(); |
| 365 | EthTypeCriterion ethType = |
| 366 | (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); |
| 367 | if ((ethType == null) || |
| 368 | (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && |
| 369 | (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 370 | log.warn("processSpecific: Unsupported forwarding objective criteria" |
| 371 | + "ethType:{} in dev:{}", ethType, deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 372 | fail(fwd, ObjectiveError.UNSUPPORTED); |
| 373 | return Collections.emptySet(); |
| 374 | } |
| 375 | |
| 376 | int forTableId = -1; |
| 377 | TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); |
| 378 | if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { |
| 379 | filteredSelector.matchEthType(Ethernet.TYPE_IPV4) |
| 380 | .matchIPDst(((IPCriterion) |
| 381 | selector.getCriterion(Criterion.Type.IPV4_DST)).ip()); |
| 382 | forTableId = UNICAST_ROUTING_TABLE; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 383 | log.debug("processing IPv4 specific forwarding objective {} -> next:{}" |
| 384 | + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 385 | } else { |
| 386 | filteredSelector |
| 387 | .matchEthType(Ethernet.MPLS_UNICAST) |
| 388 | .matchMplsLabel(((MplsCriterion) |
| 389 | selector.getCriterion(Criterion.Type.MPLS_LABEL)).label()); |
| 390 | MplsBosCriterion bos = (MplsBosCriterion) selector |
| 391 | .getCriterion(Criterion.Type.MPLS_BOS); |
| 392 | if (bos != null) { |
| 393 | filteredSelector.matchMplsBos(bos.mplsBos()); |
| 394 | } |
| 395 | forTableId = MPLS_TABLE_1; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 396 | log.debug("processing MPLS specific forwarding objective {} -> next:{}" |
| 397 | + " in dev {}", fwd.id(), fwd.nextId(), deviceId); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); |
| 401 | if (fwd.treatment() != null) { |
| 402 | for (Instruction i : fwd.treatment().allInstructions()) { |
Charles Chan | 7d10b16 | 2015-12-07 18:54:45 -0800 | [diff] [blame] | 403 | /* |
| 404 | * NOTE: OF-DPA does not support immediate instruction in |
| 405 | * L3 unicast and MPLS table. |
| 406 | */ |
| 407 | tb.deferred().add(i); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
| 411 | if (fwd.nextId() != null) { |
Saurav Das | 423fe2b | 2015-12-04 10:52:59 -0800 | [diff] [blame] | 412 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 413 | if (next != null) { |
| 414 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 415 | // we only need the top level group's key to point the flow to it |
| 416 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 417 | if (group == null) { |
| 418 | log.warn("The group left!"); |
| 419 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 420 | return Collections.emptySet(); |
| 421 | } |
| 422 | tb.deferred().group(group.id()); |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 423 | } |
Saurav Das | 8a0732e | 2015-11-20 15:27:53 -0800 | [diff] [blame] | 424 | } |
| 425 | tb.transition(ACL_TABLE); |
| 426 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 427 | .fromApp(fwd.appId()) |
| 428 | .withPriority(fwd.priority()) |
| 429 | .forDevice(deviceId) |
| 430 | .withSelector(filteredSelector.build()) |
| 431 | .withTreatment(tb.build()) |
| 432 | .forTable(forTableId); |
| 433 | |
| 434 | if (fwd.permanent()) { |
| 435 | ruleBuilder.makePermanent(); |
| 436 | } else { |
| 437 | ruleBuilder.makeTemporary(fwd.timeout()); |
| 438 | } |
| 439 | |
| 440 | return Collections.singletonList(ruleBuilder.build()); |
| 441 | } |
| 442 | |
Saurav Das | 5202596 | 2016-01-28 22:30:01 -0800 | [diff] [blame^] | 443 | /* |
| 444 | * In the OF-DPA 2.0 pipeline, versatile forwarding objectives go to the |
| 445 | * ACL table. Because we pop off vlan tags in TMAC table, |
| 446 | * we need to avoid matching on vlans in the ACL table. |
| 447 | */ |
| 448 | @Override |
| 449 | protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
| 450 | log.info("Processing versatile forwarding objective"); |
| 451 | |
| 452 | EthTypeCriterion ethType = |
| 453 | (EthTypeCriterion) fwd.selector().getCriterion(Criterion.Type.ETH_TYPE); |
| 454 | if (ethType == null) { |
| 455 | log.error("Versatile forwarding objective must include ethType"); |
| 456 | fail(fwd, ObjectiveError.BADPARAMS); |
| 457 | return Collections.emptySet(); |
| 458 | } |
| 459 | if (fwd.nextId() == null && fwd.treatment() == null) { |
| 460 | log.error("Forwarding objective {} from {} must contain " |
| 461 | + "nextId or Treatment", fwd.selector(), fwd.appId()); |
| 462 | return Collections.emptySet(); |
| 463 | } |
| 464 | |
| 465 | TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); |
| 466 | fwd.selector().criteria().forEach(criterion -> { |
| 467 | if (criterion instanceof VlanIdCriterion) { |
| 468 | // avoid matching on vlans |
| 469 | return; |
| 470 | } else { |
| 471 | sbuilder.add(criterion); |
| 472 | } |
| 473 | }); |
| 474 | |
| 475 | // XXX driver does not currently do type checking as per Tables 65-67 in |
| 476 | // OFDPA 2.0 spec. The only allowed treatment is a punt to the controller. |
| 477 | TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); |
| 478 | if (fwd.treatment() != null) { |
| 479 | for (Instruction ins : fwd.treatment().allInstructions()) { |
| 480 | if (ins instanceof OutputInstruction) { |
| 481 | OutputInstruction o = (OutputInstruction) ins; |
| 482 | if (o.port() == PortNumber.CONTROLLER) { |
| 483 | ttBuilder.add(o); |
| 484 | } else { |
| 485 | log.warn("Only allowed treatments in versatile forwarding " |
| 486 | + "objectives are punts to the controller"); |
| 487 | } |
| 488 | } else { |
| 489 | log.warn("Cannot process instruction in versatile fwd {}", ins); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | if (fwd.nextId() != null) { |
| 494 | // overide case |
| 495 | NextGroup next = getGroupForNextObjective(fwd.nextId()); |
| 496 | List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data()); |
| 497 | // we only need the top level group's key to point the flow to it |
| 498 | Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst()); |
| 499 | if (group == null) { |
| 500 | log.warn("Group with key:{} for next-id:{} not found in dev:{}", |
| 501 | gkeys.get(0).peekFirst(), fwd.nextId(), deviceId); |
| 502 | fail(fwd, ObjectiveError.GROUPMISSING); |
| 503 | return Collections.emptySet(); |
| 504 | } |
| 505 | ttBuilder.deferred().group(group.id()); |
| 506 | } |
| 507 | |
| 508 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 509 | .fromApp(fwd.appId()) |
| 510 | .withPriority(fwd.priority()) |
| 511 | .forDevice(deviceId) |
| 512 | .withSelector(sbuilder.build()) |
| 513 | .withTreatment(ttBuilder.build()) |
| 514 | .makePermanent() |
| 515 | .forTable(ACL_TABLE); |
| 516 | return Collections.singletonList(ruleBuilder.build()); |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * Cpqd emulation requires table-miss-entries in forwarding tables. |
| 521 | * Real OFDPA does not require these rules as they are put in by default. |
| 522 | * |
| 523 | * (non-Javadoc) |
| 524 | * @see org.onosproject.driver.pipeline.OFDPA2Pipeline#initializePipeline() |
| 525 | */ |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 526 | @Override |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 527 | protected void initializePipeline() { |
| 528 | processPortTable(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 529 | // vlan table processing not required, as default is to drop packets |
| 530 | // which can be accomplished without a table-miss-entry. |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 531 | processTmacTable(); |
| 532 | processIpTable(); |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 533 | processMplsTable(); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 534 | processBridgingTable(); |
Saurav Das | 337c7a4 | 2015-06-02 15:12:06 -0700 | [diff] [blame] | 535 | processAclTable(); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 538 | protected void processPortTable() { |
| 539 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 540 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 541 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 542 | treatment.transition(VLAN_TABLE); |
| 543 | FlowRule tmisse = DefaultFlowRule.builder() |
| 544 | .forDevice(deviceId) |
| 545 | .withSelector(selector.build()) |
| 546 | .withTreatment(treatment.build()) |
| 547 | .withPriority(LOWEST_PRIORITY) |
| 548 | .fromApp(driverId) |
| 549 | .makePermanent() |
| 550 | .forTable(PORT_TABLE).build(); |
| 551 | ops = ops.add(tmisse); |
| 552 | |
| 553 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 554 | @Override |
| 555 | public void onSuccess(FlowRuleOperations ops) { |
| 556 | log.info("Initialized port table"); |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public void onError(FlowRuleOperations ops) { |
| 561 | log.info("Failed to initialize port table"); |
| 562 | } |
| 563 | })); |
| 564 | } |
| 565 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 566 | protected void processTmacTable() { |
| 567 | //table miss entry |
| 568 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 569 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 570 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 571 | selector = DefaultTrafficSelector.builder(); |
| 572 | treatment = DefaultTrafficTreatment.builder(); |
| 573 | treatment.transition(BRIDGING_TABLE); |
| 574 | FlowRule rule = DefaultFlowRule.builder() |
| 575 | .forDevice(deviceId) |
| 576 | .withSelector(selector.build()) |
| 577 | .withTreatment(treatment.build()) |
| 578 | .withPriority(LOWEST_PRIORITY) |
| 579 | .fromApp(driverId) |
| 580 | .makePermanent() |
| 581 | .forTable(TMAC_TABLE).build(); |
| 582 | ops = ops.add(rule); |
| 583 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 584 | @Override |
| 585 | public void onSuccess(FlowRuleOperations ops) { |
| 586 | log.info("Initialized tmac table"); |
| 587 | } |
| 588 | |
| 589 | @Override |
| 590 | public void onError(FlowRuleOperations ops) { |
| 591 | log.info("Failed to initialize tmac table"); |
| 592 | } |
| 593 | })); |
| 594 | } |
| 595 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 596 | protected void processIpTable() { |
| 597 | //table miss entry |
| 598 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 599 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 600 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 601 | selector = DefaultTrafficSelector.builder(); |
| 602 | treatment = DefaultTrafficTreatment.builder(); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 603 | treatment.deferred().setOutput(PortNumber.CONTROLLER); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 604 | treatment.transition(ACL_TABLE); |
| 605 | FlowRule rule = DefaultFlowRule.builder() |
| 606 | .forDevice(deviceId) |
| 607 | .withSelector(selector.build()) |
| 608 | .withTreatment(treatment.build()) |
| 609 | .withPriority(LOWEST_PRIORITY) |
| 610 | .fromApp(driverId) |
| 611 | .makePermanent() |
| 612 | .forTable(UNICAST_ROUTING_TABLE).build(); |
| 613 | ops = ops.add(rule); |
| 614 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 615 | @Override |
| 616 | public void onSuccess(FlowRuleOperations ops) { |
| 617 | log.info("Initialized IP table"); |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public void onError(FlowRuleOperations ops) { |
| 622 | log.info("Failed to initialize unicast IP table"); |
| 623 | } |
| 624 | })); |
| 625 | } |
| 626 | |
Saurav Das | 2857f38 | 2015-11-03 14:39:27 -0800 | [diff] [blame] | 627 | protected void processMplsTable() { |
| 628 | //table miss entry |
| 629 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 630 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 631 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 632 | selector = DefaultTrafficSelector.builder(); |
| 633 | treatment = DefaultTrafficTreatment.builder(); |
| 634 | treatment.transition(MPLS_TABLE_1); |
| 635 | FlowRule rule = DefaultFlowRule.builder() |
| 636 | .forDevice(deviceId) |
| 637 | .withSelector(selector.build()) |
| 638 | .withTreatment(treatment.build()) |
| 639 | .withPriority(LOWEST_PRIORITY) |
| 640 | .fromApp(driverId) |
| 641 | .makePermanent() |
| 642 | .forTable(MPLS_TABLE_0).build(); |
| 643 | ops = ops.add(rule); |
| 644 | |
| 645 | treatment.transition(ACL_TABLE); |
| 646 | rule = DefaultFlowRule.builder() |
| 647 | .forDevice(deviceId) |
| 648 | .withSelector(selector.build()) |
| 649 | .withTreatment(treatment.build()) |
| 650 | .withPriority(LOWEST_PRIORITY) |
| 651 | .fromApp(driverId) |
| 652 | .makePermanent() |
| 653 | .forTable(MPLS_TABLE_1).build(); |
| 654 | ops = ops.add(rule); |
| 655 | |
| 656 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 657 | @Override |
| 658 | public void onSuccess(FlowRuleOperations ops) { |
| 659 | log.info("Initialized MPLS tables"); |
| 660 | } |
| 661 | |
| 662 | @Override |
| 663 | public void onError(FlowRuleOperations ops) { |
| 664 | log.info("Failed to initialize MPLS tables"); |
| 665 | } |
| 666 | })); |
| 667 | } |
| 668 | |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 669 | private void processBridgingTable() { |
| 670 | //table miss entry |
| 671 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 672 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 673 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 674 | selector = DefaultTrafficSelector.builder(); |
| 675 | treatment = DefaultTrafficTreatment.builder(); |
| 676 | treatment.transition(ACL_TABLE); |
| 677 | FlowRule rule = DefaultFlowRule.builder() |
| 678 | .forDevice(deviceId) |
| 679 | .withSelector(selector.build()) |
| 680 | .withTreatment(treatment.build()) |
| 681 | .withPriority(LOWEST_PRIORITY) |
| 682 | .fromApp(driverId) |
| 683 | .makePermanent() |
| 684 | .forTable(BRIDGING_TABLE).build(); |
| 685 | ops = ops.add(rule); |
| 686 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 687 | @Override |
| 688 | public void onSuccess(FlowRuleOperations ops) { |
| 689 | log.info("Initialized Bridging table"); |
| 690 | } |
| 691 | |
| 692 | @Override |
| 693 | public void onError(FlowRuleOperations ops) { |
| 694 | log.info("Failed to initialize Bridging table"); |
| 695 | } |
| 696 | })); |
Saurav Das | 337c7a4 | 2015-06-02 15:12:06 -0700 | [diff] [blame] | 697 | } |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 698 | |
Saurav Das | a07f203 | 2015-10-19 14:37:36 -0700 | [diff] [blame] | 699 | protected void processAclTable() { |
Saurav Das | 337c7a4 | 2015-06-02 15:12:06 -0700 | [diff] [blame] | 700 | //table miss entry - catch all to executed action-set |
| 701 | FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); |
| 702 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 703 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 704 | selector = DefaultTrafficSelector.builder(); |
| 705 | treatment = DefaultTrafficTreatment.builder(); |
| 706 | FlowRule rule = DefaultFlowRule.builder() |
| 707 | .forDevice(deviceId) |
| 708 | .withSelector(selector.build()) |
| 709 | .withTreatment(treatment.build()) |
| 710 | .withPriority(LOWEST_PRIORITY) |
| 711 | .fromApp(driverId) |
| 712 | .makePermanent() |
| 713 | .forTable(ACL_TABLE).build(); |
| 714 | ops = ops.add(rule); |
| 715 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| 716 | @Override |
| 717 | public void onSuccess(FlowRuleOperations ops) { |
| 718 | log.info("Initialized Acl table"); |
| 719 | } |
| 720 | |
| 721 | @Override |
| 722 | public void onError(FlowRuleOperations ops) { |
| 723 | log.info("Failed to initialize Acl table"); |
| 724 | } |
| 725 | })); |
Saurav Das | 558afec | 2015-05-31 17:12:48 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | } |