Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | */ |
| 16 | |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 17 | package org.onosproject.pipelines.fabric.impl.behaviour.pipeliner; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 18 | |
| 19 | import com.google.common.collect.Lists; |
| 20 | import org.onlab.packet.Ethernet; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onlab.packet.VlanId; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 26 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 27 | import org.onosproject.net.flow.FlowRule; |
| 28 | import org.onosproject.net.flow.TrafficSelector; |
| 29 | import org.onosproject.net.flow.TrafficTreatment; |
| 30 | import org.onosproject.net.flow.criteria.Criterion; |
| 31 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 32 | import org.onosproject.net.flow.criteria.PiCriterion; |
| 33 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 34 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 35 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType; |
| 36 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 37 | import org.onosproject.net.flowobjective.FilteringObjective; |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 38 | import org.onosproject.net.flowobjective.Objective; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 39 | import org.onosproject.net.flowobjective.ObjectiveError; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 40 | import org.onosproject.net.pi.model.PiTableId; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 41 | import org.onosproject.net.pi.runtime.PiAction; |
| 42 | import org.onosproject.net.pi.runtime.PiActionParam; |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 43 | import org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities; |
Carmelo Cascone | 2102bfb | 2020-12-04 16:54:24 -0800 | [diff] [blame] | 44 | import org.onosproject.pipelines.fabric.FabricConstants; |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 45 | import org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 46 | |
| 47 | import java.util.Collection; |
| 48 | import java.util.List; |
| 49 | |
| 50 | import static java.lang.String.format; |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 51 | import static org.onosproject.net.flow.criteria.Criterion.Type.INNER_VLAN_VID; |
| 52 | import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 53 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID; |
| 54 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP; |
| 55 | import static org.onosproject.net.pi.model.PiPipelineInterpreter.PiInterpreterException; |
pierventre | 4d29d3c | 2021-08-27 17:20:00 +0200 | [diff] [blame^] | 56 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.CLEANUP_DOUBLE_TAGGED_HOST_ENTRIES; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 57 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.ETH_TYPE_EXACT_MASK; |
| 58 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_MPLS; |
| 59 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV4_ROUTING; |
| 60 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV6_ROUTING; |
pierventre | 4d29d3c | 2021-08-27 17:20:00 +0200 | [diff] [blame^] | 61 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.INTERFACE_CONFIG_UPDATE; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 62 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.ONE; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 63 | import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.ZERO; |
pierventre | 4d29d3c | 2021-08-27 17:20:00 +0200 | [diff] [blame^] | 64 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.isSrMetadataSet; |
| 65 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.isValidSrMetadata; |
| 66 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.portType; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 67 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2InstructionOrFail; |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 68 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.criterion; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 69 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instruction; |
| 70 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 71 | /** |
| 72 | * ObjectiveTranslator implementation for FilteringObjective. |
| 73 | */ |
| 74 | class FilteringObjectiveTranslator |
| 75 | extends AbstractObjectiveTranslator<FilteringObjective> { |
| 76 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 77 | private static final PiAction DENY = PiAction.builder() |
| 78 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_DENY) |
| 79 | .build(); |
| 80 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 81 | FilteringObjectiveTranslator(DeviceId deviceId, FabricCapabilities capabilities) { |
| 82 | super(deviceId, capabilities); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public ObjectiveTranslation doTranslate(FilteringObjective obj) |
| 87 | throws FabricPipelinerException { |
| 88 | |
| 89 | final ObjectiveTranslation.Builder resultBuilder = |
| 90 | ObjectiveTranslation.builder(); |
| 91 | |
| 92 | if (obj.key() == null || obj.key().type() != Criterion.Type.IN_PORT) { |
| 93 | throw new FabricPipelinerException( |
| 94 | format("Unsupported or missing filtering key: key=%s", obj.key()), |
| 95 | ObjectiveError.BADPARAMS); |
| 96 | } |
| 97 | |
pierventre | 4d29d3c | 2021-08-27 17:20:00 +0200 | [diff] [blame^] | 98 | if (!isValidSrMetadata(obj)) { |
| 99 | throw new FabricPipelinerException( |
| 100 | format("Unsupported metadata configuration: metadata=%s", obj.meta()), |
| 101 | ObjectiveError.BADPARAMS); |
| 102 | } |
| 103 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 104 | final PortCriterion inPort = (PortCriterion) obj.key(); |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 105 | |
| 106 | final VlanIdCriterion outerVlan = (VlanIdCriterion) criterion( |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 107 | obj.conditions(), Criterion.Type.VLAN_VID); |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 108 | final VlanIdCriterion innerVlan = (VlanIdCriterion) criterion( |
| 109 | obj.conditions(), Criterion.Type.INNER_VLAN_VID); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 110 | final EthCriterion ethDst = (EthCriterion) criterion( |
| 111 | obj.conditions(), Criterion.Type.ETH_DST); |
| 112 | final EthCriterion ethDstMasked = (EthCriterion) criterion( |
| 113 | obj.conditions(), Criterion.Type.ETH_DST_MASKED); |
| 114 | |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 115 | ingressPortVlanRule(obj, inPort, outerVlan, innerVlan, resultBuilder); |
pierventre | 167d448 | 2021-01-08 17:35:47 +0100 | [diff] [blame] | 116 | if (shouldModifyFwdClassifierTable(obj)) { |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 117 | fwdClassifierRules(obj, inPort, ethDst, ethDstMasked, resultBuilder); |
| 118 | } else { |
| 119 | log.debug("Skipping fwd classifier rules for device {}.", deviceId); |
| 120 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 121 | return resultBuilder.build(); |
| 122 | } |
| 123 | |
pierventre | 167d448 | 2021-01-08 17:35:47 +0100 | [diff] [blame] | 124 | private boolean shouldModifyFwdClassifierTable(FilteringObjective obj) { |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 125 | // NOTE: in fabric pipeline the forwarding classifier acts similarly |
| 126 | // to the TMAC table of OFDPA that matches on input port. |
pierventre | 167d448 | 2021-01-08 17:35:47 +0100 | [diff] [blame] | 127 | // NOTE: that SR signals when it is a port update event by not setting |
| 128 | // the INTERFACE_CONFIG_UPDATE metadata. During the INTERFACE_CONFIG_UPDATE |
| 129 | // there is no need to add/remove rules in the fwd_classifier table. |
| 130 | // NOTE: that in scenarios like (T, N) -> T where we remove only the native |
| 131 | // VLAN there is not an ADD following the remove. |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 132 | |
pierventre | 167d448 | 2021-01-08 17:35:47 +0100 | [diff] [blame] | 133 | // Forwarding classifier rules should be added/removed to translation when: |
| 134 | // - the operation is ADD |
| 135 | // AND it is a port update event (ADD or UPDATE) OR |
| 136 | // - it doesn't refer to double tagged traffic |
| 137 | // AND it is a port REMOVE event OR |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 138 | // - it refers to double tagged traffic |
| 139 | // and SR is triggering the removal of forwarding classifier rules. |
pierventre | 4d29d3c | 2021-08-27 17:20:00 +0200 | [diff] [blame^] | 140 | return (obj.op() == Objective.Operation.ADD && !isSrMetadataSet(obj, INTERFACE_CONFIG_UPDATE)) || |
| 141 | (!isDoubleTagged(obj) && !isSrMetadataSet(obj, INTERFACE_CONFIG_UPDATE)) || |
| 142 | (isDoubleTagged(obj) && isSrMetadataSet(obj, CLEANUP_DOUBLE_TAGGED_HOST_ENTRIES)); |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | private boolean isDoubleTagged(FilteringObjective obj) { |
| 146 | return obj.meta() != null && |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 147 | FabricUtils.l2Instruction(obj.meta(), L2SubType.VLAN_POP) != null && |
Daniele Moro | 41ec148 | 2019-10-29 18:45:33 -0700 | [diff] [blame] | 148 | FabricUtils.criterion(obj.conditions(), VLAN_VID) != null && |
| 149 | FabricUtils.criterion(obj.conditions(), INNER_VLAN_VID) != null; |
| 150 | } |
| 151 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 152 | private void ingressPortVlanRule( |
| 153 | FilteringObjective obj, |
| 154 | Criterion inPortCriterion, |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 155 | VlanIdCriterion outerVlanCriterion, |
| 156 | VlanIdCriterion innerVlanCriterion, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 157 | ObjectiveTranslation.Builder resultBuilder) |
| 158 | throws FabricPipelinerException { |
| 159 | |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 160 | final boolean outerVlanValid = outerVlanCriterion != null |
| 161 | && !outerVlanCriterion.vlanId().equals(VlanId.NONE); |
| 162 | final boolean innerVlanValid = innerVlanCriterion != null |
| 163 | && !innerVlanCriterion.vlanId().equals(VlanId.NONE); |
| 164 | |
Daniele Moro | b3d199b | 2019-11-01 14:01:46 -0700 | [diff] [blame] | 165 | if (innerVlanValid && !capabilities.supportDoubleVlanTerm()) { |
| 166 | throw new FabricPipelinerException( |
| 167 | "Found 2 VLAN IDs, but the pipeline does not support double VLAN termination", |
| 168 | ObjectiveError.UNSUPPORTED); |
| 169 | } |
| 170 | |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 171 | final PiCriterion piCriterion = PiCriterion.builder() |
| 172 | .matchExact(FabricConstants.HDR_VLAN_IS_VALID, outerVlanValid ? ONE : ZERO) |
| 173 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 174 | |
| 175 | final TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| 176 | .add(inPortCriterion) |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 177 | .add(piCriterion); |
| 178 | if (outerVlanValid) { |
| 179 | selector.add(outerVlanCriterion); |
| 180 | } |
| 181 | if (innerVlanValid) { |
| 182 | selector.add(innerVlanCriterion); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 185 | final TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 186 | if (obj.type().equals(FilteringObjective.Type.DENY)) { |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 187 | treatmentBuilder.piTableAction(DENY); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 188 | } else { |
pierventre | 4d29d3c | 2021-08-27 17:20:00 +0200 | [diff] [blame^] | 189 | // FIXME SDFAB-52 to complete the work on metadata |
| 190 | Byte portType = portType(obj); |
| 191 | if (portType == null) { |
| 192 | throw new FabricPipelinerException( |
| 193 | format("Unsupported port_type configuration: metadata=%s", obj.meta()), |
| 194 | ObjectiveError.BADPARAMS); |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 195 | } |
| 196 | try { |
| 197 | treatmentBuilder.piTableAction(mapFilteringTreatment(obj.meta(), |
| 198 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN, portType)); |
| 199 | } catch (PiInterpreterException ex) { |
| 200 | throw new FabricPipelinerException(format("Unable to map treatment for table '%s': %s", |
| 201 | FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN, |
| 202 | ex.getMessage()), ObjectiveError.UNSUPPORTED); |
| 203 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 204 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 205 | resultBuilder.addFlowRule(flowRule( |
| 206 | obj, FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN, |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame] | 207 | selector.build(), treatmentBuilder.build())); |
| 208 | } |
| 209 | |
| 210 | private PiAction mapFilteringTreatment(TrafficTreatment treatment, PiTableId tableId, byte portType) |
| 211 | throws PiInterpreterException { |
| 212 | if (treatment == null) { |
| 213 | treatment = DefaultTrafficTreatment.emptyTreatment(); |
| 214 | } |
| 215 | // VLAN_POP action is equivalent to the permit action (VLANs pop is done anyway) |
| 216 | if (isFilteringNoAction(treatment) || isFilteringPopAction(treatment)) { |
| 217 | // Permit action if table is ingress_port_vlan; |
| 218 | return PiAction.builder() |
| 219 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT) |
| 220 | .withParameter(new PiActionParam(FabricConstants.PORT_TYPE, portType)) |
| 221 | .build(); |
| 222 | } |
| 223 | |
| 224 | final ModVlanIdInstruction setVlanInst = (ModVlanIdInstruction) l2InstructionOrFail( |
| 225 | treatment, VLAN_ID, tableId); |
| 226 | return PiAction.builder() |
| 227 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN) |
| 228 | .withParameter(new PiActionParam(FabricConstants.VLAN_ID, setVlanInst.vlanId().toShort())) |
| 229 | .withParameter(new PiActionParam(FabricConstants.PORT_TYPE, portType)) |
| 230 | .build(); |
| 231 | } |
| 232 | |
| 233 | // NOTE: we use clearDeferred to signal when there are no more ports associated to a given vlan |
| 234 | private static boolean isFilteringNoAction(TrafficTreatment treatment) { |
| 235 | return treatment.equals(DefaultTrafficTreatment.emptyTreatment()) || |
| 236 | (treatment.allInstructions().isEmpty()) || |
| 237 | (treatment.allInstructions().size() == 1 && treatment.writeMetadata() != null); |
| 238 | } |
| 239 | |
| 240 | private boolean isFilteringPopAction(TrafficTreatment treatment) { |
| 241 | return l2Instruction(treatment, VLAN_POP) != null; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | private void fwdClassifierRules( |
| 245 | FilteringObjective obj, |
| 246 | PortCriterion inPortCriterion, |
| 247 | EthCriterion ethDstCriterion, |
| 248 | EthCriterion ethDstMaskedCriterion, |
| 249 | ObjectiveTranslation.Builder resultBuilder) |
| 250 | throws FabricPipelinerException { |
| 251 | |
| 252 | final List<FlowRule> flowRules = Lists.newArrayList(); |
| 253 | |
| 254 | final PortNumber inPort = inPortCriterion.port(); |
| 255 | if (ethDstCriterion == null) { |
| 256 | if (ethDstMaskedCriterion == null) { |
| 257 | // No match. Do bridging (default action). |
| 258 | return; |
| 259 | } |
| 260 | // Masked fwd classifier rule |
| 261 | final MacAddress dstMac = ethDstMaskedCriterion.mac(); |
| 262 | final MacAddress dstMacMask = ethDstMaskedCriterion.mask(); |
| 263 | flowRules.add(maskedFwdClassifierRule(inPort, dstMac, dstMacMask, obj)); |
| 264 | } else { |
| 265 | final MacAddress dstMac = ethDstCriterion.mac(); |
| 266 | flowRules.addAll(ipFwdClassifierRules(inPort, dstMac, obj)); |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 267 | flowRules.addAll(mplsFwdClassifierRules(inPort, dstMac, obj)); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | for (FlowRule f : flowRules) { |
| 271 | resultBuilder.addFlowRule(f); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | private FlowRule maskedFwdClassifierRule( |
| 276 | PortNumber inPort, MacAddress dstMac, MacAddress dstMacMask, |
| 277 | FilteringObjective obj) |
| 278 | throws FabricPipelinerException { |
| 279 | final TrafficTreatment treatment; |
| 280 | final short ethType; |
| 281 | if (dstMac.equals(MacAddress.IPV4_MULTICAST) |
| 282 | && dstMacMask.equals(MacAddress.IPV4_MULTICAST_MASK)) { |
| 283 | treatment = fwdClassifierTreatment(FWD_IPV4_ROUTING); |
| 284 | ethType = Ethernet.TYPE_IPV4; |
| 285 | } else if (dstMac.equals(MacAddress.IPV6_MULTICAST) |
| 286 | && dstMacMask.equals(MacAddress.IPV6_MULTICAST_MASK)) { |
| 287 | treatment = fwdClassifierTreatment(FWD_IPV6_ROUTING); |
| 288 | ethType = Ethernet.TYPE_IPV6; |
| 289 | } else { |
| 290 | throw new FabricPipelinerException(format( |
| 291 | "Unsupported masked Ethernet address for fwd " + |
| 292 | "classifier rule (mac=%s, mask=%s)", |
| 293 | dstMac, dstMacMask)); |
| 294 | } |
| 295 | return fwdClassifierRule(inPort, ethType, dstMac, dstMacMask, treatment, obj); |
| 296 | } |
| 297 | |
| 298 | private Collection<FlowRule> ipFwdClassifierRules( |
| 299 | PortNumber inPort, MacAddress dstMac, FilteringObjective obj) |
| 300 | throws FabricPipelinerException { |
| 301 | final Collection<FlowRule> flowRules = Lists.newArrayList(); |
| 302 | flowRules.add(fwdClassifierRule( |
| 303 | inPort, Ethernet.TYPE_IPV4, dstMac, null, |
| 304 | fwdClassifierTreatment(FWD_IPV4_ROUTING), obj)); |
| 305 | flowRules.add(fwdClassifierRule( |
| 306 | inPort, Ethernet.TYPE_IPV6, dstMac, null, |
| 307 | fwdClassifierTreatment(FWD_IPV6_ROUTING), obj)); |
| 308 | return flowRules; |
| 309 | } |
| 310 | |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 311 | private Collection<FlowRule> mplsFwdClassifierRules( |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 312 | PortNumber inPort, MacAddress dstMac, FilteringObjective obj) |
| 313 | throws FabricPipelinerException { |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 314 | // Forwarding classifier for MPLS is composed of 2 rules |
| 315 | // with higher priority wrt standard forwarding classifier rules, |
| 316 | // this is due to overlap on ternary matching. |
| 317 | TrafficTreatment treatment = fwdClassifierTreatment(FWD_MPLS); |
| 318 | final PiCriterion ethTypeMplsIpv4 = PiCriterion.builder() |
| 319 | .matchTernary(FabricConstants.HDR_ETH_TYPE, |
| 320 | Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK) |
| 321 | .matchExact(FabricConstants.HDR_IP_ETH_TYPE, |
| 322 | Ethernet.TYPE_IPV4) |
| 323 | .build(); |
| 324 | final TrafficSelector selectorMplsIpv4 = DefaultTrafficSelector.builder() |
| 325 | .matchInPort(inPort) |
| 326 | .matchPi(ethTypeMplsIpv4) |
| 327 | .matchEthDstMasked(dstMac, MacAddress.EXACT_MASK) |
| 328 | .build(); |
| 329 | |
| 330 | final PiCriterion ethTypeMplsIpv6 = PiCriterion.builder() |
| 331 | .matchTernary(FabricConstants.HDR_ETH_TYPE, |
| 332 | Ethernet.MPLS_UNICAST, ETH_TYPE_EXACT_MASK) |
| 333 | .matchExact(FabricConstants.HDR_IP_ETH_TYPE, |
| 334 | Ethernet.TYPE_IPV6) |
| 335 | .build(); |
| 336 | final TrafficSelector selectorMplsIpv6 = DefaultTrafficSelector.builder() |
| 337 | .matchInPort(inPort) |
| 338 | .matchPi(ethTypeMplsIpv6) |
| 339 | .matchEthDstMasked(dstMac, MacAddress.EXACT_MASK) |
| 340 | .build(); |
| 341 | |
| 342 | return List.of( |
| 343 | flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER, |
| 344 | selectorMplsIpv4, treatment, obj.priority() + 1), |
| 345 | flowRule(obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER, |
| 346 | selectorMplsIpv6, treatment, obj.priority() + 1) |
| 347 | ); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | private FlowRule fwdClassifierRule( |
| 351 | PortNumber inPort, short ethType, MacAddress dstMac, MacAddress dstMacMask, |
| 352 | TrafficTreatment treatment, FilteringObjective obj) |
| 353 | throws FabricPipelinerException { |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 354 | // Match on ip_eth_type that is the eth_type of the L3 protocol. |
| 355 | // i.e., if the packet has an IP header, ip_eth_type should |
| 356 | // contain the corresponding eth_type (for IPv4 or IPv6) |
| 357 | final PiCriterion ethTypeCriterion = PiCriterion.builder() |
| 358 | .matchExact(FabricConstants.HDR_IP_ETH_TYPE, ethType) |
| 359 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 360 | final TrafficSelector selector = DefaultTrafficSelector.builder() |
| 361 | .matchInPort(inPort) |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 362 | .matchPi(ethTypeCriterion) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 363 | .matchEthDstMasked(dstMac, dstMacMask == null |
| 364 | ? MacAddress.EXACT_MASK : dstMacMask) |
| 365 | .build(); |
| 366 | return flowRule( |
| 367 | obj, FabricConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER, |
| 368 | selector, treatment); |
| 369 | } |
| 370 | |
| 371 | private TrafficTreatment fwdClassifierTreatment(byte fwdType) { |
| 372 | final PiActionParam param = new PiActionParam(FabricConstants.FWD_TYPE, fwdType); |
| 373 | final PiAction action = PiAction.builder() |
| 374 | .withId(FabricConstants.FABRIC_INGRESS_FILTERING_SET_FORWARDING_TYPE) |
| 375 | .withParameter(param) |
| 376 | .build(); |
| 377 | return DefaultTrafficTreatment.builder() |
| 378 | .piTableAction(action) |
| 379 | .build(); |
| 380 | |
| 381 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 382 | } |