Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [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; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 18 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 20 | import org.onosproject.net.PortNumber; |
Yi Tseng | df3eec5 | 2018-02-15 14:56:02 -0800 | [diff] [blame] | 21 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 22 | import org.onosproject.net.flow.TrafficTreatment; |
| 23 | import org.onosproject.net.flow.instructions.Instruction; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 24 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 25 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 26 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 27 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 28 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; |
| 29 | import org.onosproject.net.pi.model.PiActionId; |
| 30 | import org.onosproject.net.pi.model.PiPipelineInterpreter.PiInterpreterException; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 31 | import org.onosproject.net.pi.model.PiTableId; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 32 | import org.onosproject.net.pi.runtime.PiAction; |
| 33 | import org.onosproject.net.pi.runtime.PiActionParam; |
Carmelo Cascone | 2102bfb | 2020-12-04 16:54:24 -0800 | [diff] [blame] | 34 | import org.onosproject.pipelines.fabric.FabricConstants; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 35 | |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 36 | import java.util.List; |
| 37 | import java.util.stream.Collectors; |
| 38 | |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 39 | import static java.lang.String.format; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 40 | import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT; |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 41 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_DST; |
| 42 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_SRC; |
| 43 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.MPLS_LABEL; |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 44 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID; |
| 45 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP; |
| 46 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_PUSH; |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 47 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.instruction; |
| 48 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instruction; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 49 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2InstructionOrFail; |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 50 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instructions; |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 51 | import static org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.treatmentException; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 52 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 53 | /** |
| 54 | * Treatment translation logic. |
| 55 | */ |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 56 | final class FabricTreatmentInterpreter { |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 57 | |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 58 | private final FabricCapabilities capabilities; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 59 | private static final ImmutableMap<PiTableId, PiActionId> NOP_ACTIONS = |
| 60 | ImmutableMap.<PiTableId, PiActionId>builder() |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 61 | .put(FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, |
| 62 | FabricConstants.FABRIC_INGRESS_FORWARDING_NOP_ROUTING_V4) |
| 63 | .put(FabricConstants.FABRIC_INGRESS_ACL_ACL, |
| 64 | FabricConstants.FABRIC_INGRESS_ACL_NOP_ACL) |
| 65 | .put(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN, |
| 66 | FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN) |
| 67 | .build(); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 68 | |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 69 | |
| 70 | FabricTreatmentInterpreter(FabricCapabilities capabilities) { |
| 71 | this.capabilities = capabilities; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 74 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 75 | static PiAction mapForwardingTreatment(TrafficTreatment treatment, PiTableId tableId) |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 76 | throws PiInterpreterException { |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 77 | if (isNoAction(treatment)) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 78 | return nop(tableId); |
Yi Tseng | df3eec5 | 2018-02-15 14:56:02 -0800 | [diff] [blame] | 79 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 80 | treatmentException( |
| 81 | tableId, treatment, |
| 82 | "supports mapping only for empty/no-action treatments"); |
| 83 | return null; |
| 84 | } |
| 85 | |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 86 | PiAction mapPreNextTreatment(TrafficTreatment treatment, PiTableId tableId) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 87 | throws PiInterpreterException { |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 88 | if (tableId == FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS) { |
| 89 | return mapNextMplsTreatment(treatment, tableId); |
| 90 | } else if (tableId == FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 91 | return mapNextVlanTreatment(treatment, tableId); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 92 | } |
| 93 | throw new PiInterpreterException(format( |
| 94 | "Treatment mapping not supported for table '%s'", tableId)); |
| 95 | } |
| 96 | |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 97 | PiAction mapNextTreatment(TrafficTreatment treatment, PiTableId tableId) |
| 98 | throws PiInterpreterException { |
| 99 | if (tableId == FabricConstants.FABRIC_INGRESS_NEXT_HASHED) { |
| 100 | return mapNextHashedOrSimpleTreatment(treatment, tableId, false); |
| 101 | } else if (tableId == FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE) { |
| 102 | return mapNextHashedOrSimpleTreatment(treatment, tableId, true); |
| 103 | } else if (tableId == FabricConstants.FABRIC_INGRESS_NEXT_XCONNECT) { |
| 104 | return mapNextXconnect(treatment, tableId); |
| 105 | } |
| 106 | throw new PiInterpreterException(format( |
| 107 | "Treatment mapping not supported for table '%s'", tableId)); |
| 108 | } |
| 109 | |
| 110 | private static PiAction mapNextMplsTreatment(TrafficTreatment treatment, PiTableId tableId) |
| 111 | throws PiInterpreterException { |
| 112 | final ModMplsLabelInstruction mplsLabel = (ModMplsLabelInstruction) l2Instruction( |
| 113 | treatment, MPLS_LABEL); |
| 114 | if (mplsLabel != null) { |
| 115 | return PiAction.builder() |
| 116 | .withParameter(new PiActionParam(FabricConstants.LABEL, mplsLabel.label().toInt())) |
| 117 | .withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_MPLS_LABEL) |
| 118 | .build(); |
| 119 | } |
| 120 | throw new PiInterpreterException("There is no MPLS instruction"); |
| 121 | } |
| 122 | |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 123 | private PiAction mapNextVlanTreatment(TrafficTreatment treatment, PiTableId tableId) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 124 | throws PiInterpreterException { |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 125 | final List<ModVlanIdInstruction> modVlanIdInst = l2InstructionsOrFail(treatment, VLAN_ID, tableId) |
| 126 | .stream().map(i -> (ModVlanIdInstruction) i).collect(Collectors.toList()); |
| 127 | if (modVlanIdInst.size() == 1) { |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 128 | return PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_VLAN) |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 129 | .withParameter(new PiActionParam( |
| 130 | FabricConstants.VLAN_ID, |
| 131 | modVlanIdInst.get(0).vlanId().toShort())) |
| 132 | .build(); |
| 133 | } |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 134 | // next_vlan has been moved to pre_next |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 135 | if (modVlanIdInst.size() == 2 && capabilities.supportDoubleVlanTerm()) { |
| 136 | return PiAction.builder() |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 137 | .withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_DOUBLE_VLAN) |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 138 | .withParameter(new PiActionParam( |
| 139 | FabricConstants.INNER_VLAN_ID, |
| 140 | modVlanIdInst.get(0).vlanId().toShort())) |
| 141 | .withParameter(new PiActionParam( |
| 142 | FabricConstants.OUTER_VLAN_ID, |
| 143 | modVlanIdInst.get(1).vlanId().toShort())) |
| 144 | .build(); |
| 145 | } |
| 146 | throw new PiInterpreterException("Too many VLAN instructions"); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | private static PiAction mapNextHashedOrSimpleTreatment( |
| 150 | TrafficTreatment treatment, PiTableId tableId, boolean simple) |
| 151 | throws PiInterpreterException { |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 152 | // Provide mapping for output_hashed and routing_hashed; multicast_hashed |
| 153 | // can only be invoked with PiAction, hence no mapping. outPort required for |
| 154 | // all actions. Presence of other instructions will determine which action to map to. |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 155 | final PortNumber outPort = ((OutputInstruction) instructionOrFail( |
| 156 | treatment, OUTPUT, tableId)).port(); |
| 157 | final ModEtherInstruction ethDst = (ModEtherInstruction) l2Instruction( |
| 158 | treatment, ETH_DST); |
| 159 | final ModEtherInstruction ethSrc = (ModEtherInstruction) l2Instruction( |
| 160 | treatment, ETH_SRC); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 161 | |
| 162 | final PiAction.Builder actionBuilder = PiAction.builder() |
| 163 | .withParameter(new PiActionParam(FabricConstants.PORT_NUM, outPort.toLong())); |
| 164 | |
| 165 | if (ethDst != null && ethSrc != null) { |
| 166 | actionBuilder.withParameter(new PiActionParam( |
| 167 | FabricConstants.SMAC, ethSrc.mac().toBytes())); |
| 168 | actionBuilder.withParameter(new PiActionParam( |
| 169 | FabricConstants.DMAC, ethDst.mac().toBytes())); |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 170 | // routing_hashed |
| 171 | return actionBuilder |
| 172 | .withId(simple ? FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE |
| 173 | : FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED) |
| 174 | .build(); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 175 | } else { |
| 176 | // output_hashed |
| 177 | return actionBuilder |
| 178 | .withId(simple ? FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE |
| 179 | : FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_HASHED) |
| 180 | .build(); |
| 181 | } |
| 182 | } |
| 183 | |
Carmelo Cascone | 45cc086 | 2018-11-26 11:50:41 -0800 | [diff] [blame] | 184 | private static PiAction mapNextXconnect( |
| 185 | TrafficTreatment treatment, PiTableId tableId) |
| 186 | throws PiInterpreterException { |
| 187 | final PortNumber outPort = ((OutputInstruction) instructionOrFail( |
| 188 | treatment, OUTPUT, tableId)).port(); |
| 189 | return PiAction.builder() |
| 190 | .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_XCONNECT) |
| 191 | .withParameter(new PiActionParam( |
| 192 | FabricConstants.PORT_NUM, outPort.toLong())) |
| 193 | .build(); |
| 194 | } |
| 195 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 196 | static PiAction mapAclTreatment(TrafficTreatment treatment, PiTableId tableId) |
| 197 | throws PiInterpreterException { |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 198 | if (isDrop(treatment)) { |
| 199 | return drop(tableId); |
| 200 | } |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 201 | if (isNoAction(treatment)) { |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 202 | return nop(tableId); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 203 | } |
Daniele Moro | 01ca2ab | 2019-06-25 11:48:48 -0700 | [diff] [blame] | 204 | treatmentException( |
| 205 | tableId, treatment, |
| 206 | "unsupported treatment"); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 207 | |
Daniele Moro | 01ca2ab | 2019-06-25 11:48:48 -0700 | [diff] [blame] | 208 | // This function will never return null |
| 209 | return null; |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 212 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 213 | static PiAction mapEgressNextTreatment( |
| 214 | TrafficTreatment treatment, PiTableId tableId) |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 215 | throws PiInterpreterException { |
pierventre | 48e7882 | 2020-12-15 17:34:54 +0100 | [diff] [blame] | 216 | L2ModificationInstruction pushVlan = l2Instruction(treatment, VLAN_PUSH); |
| 217 | if (pushVlan != null) { |
| 218 | return PiAction.builder() |
| 219 | .withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_PUSH_VLAN) |
| 220 | .build(); |
| 221 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 222 | l2InstructionOrFail(treatment, VLAN_POP, tableId); |
| 223 | return PiAction.builder() |
| 224 | .withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN) |
| 225 | .build(); |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 226 | |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 227 | } |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 228 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 229 | private static PiAction nop(PiTableId tableId) throws PiInterpreterException { |
| 230 | if (!NOP_ACTIONS.containsKey(tableId)) { |
| 231 | throw new PiInterpreterException(format("table '%s' doe not specify a nop action", tableId)); |
| 232 | } |
| 233 | return PiAction.builder().withId(NOP_ACTIONS.get(tableId)).build(); |
| 234 | } |
| 235 | |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 236 | private static PiAction drop(PiTableId tableId) throws PiInterpreterException { |
| 237 | if (!tableId.equals(FabricConstants.FABRIC_INGRESS_ACL_ACL)) { |
| 238 | throw new PiInterpreterException(format("table '%s' doe not specify a nop action", tableId)); |
| 239 | } |
| 240 | return PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_DROP).build(); |
| 241 | } |
| 242 | |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 243 | // NOTE: clearDeferred is used by the routing application to implement ACL drop and route black-holing |
Wailok Shum | fb7e787 | 2021-06-18 17:30:08 +0800 | [diff] [blame^] | 244 | private static boolean isNoAction(TrafficTreatment treatment) { |
Wailok Shum | 4f51bde | 2021-06-11 22:48:41 +0800 | [diff] [blame] | 245 | return treatment.equals(DefaultTrafficTreatment.emptyTreatment()) || |
| 246 | (treatment.allInstructions().isEmpty() && !treatment.clearedDeferred()) || |
| 247 | (treatment.allInstructions().size() == 1 && treatment.writeMetadata() != null); |
| 248 | } |
| 249 | |
| 250 | private static boolean isDrop(TrafficTreatment treatment) { |
| 251 | return treatment.allInstructions().isEmpty() && treatment.clearedDeferred(); |
| 252 | } |
| 253 | |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 254 | private static List<L2ModificationInstruction> l2InstructionsOrFail( |
| 255 | TrafficTreatment treatment, |
| 256 | L2ModificationInstruction.L2SubType subType, PiTableId tableId) |
| 257 | throws PiInterpreterException { |
| 258 | final List<L2ModificationInstruction> inst = l2Instructions(treatment, subType); |
| 259 | if (inst == null || inst.isEmpty()) { |
| 260 | treatmentException(tableId, treatment, format("missing %s instruction", subType)); |
| 261 | } |
| 262 | return inst; |
| 263 | } |
| 264 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 265 | private static Instruction instructionOrFail( |
| 266 | TrafficTreatment treatment, Instruction.Type type, PiTableId tableId) |
| 267 | throws PiInterpreterException { |
| 268 | final Instruction inst = instruction(treatment, type); |
| 269 | if (inst == null) { |
| 270 | treatmentException(tableId, treatment, format("missing %s instruction", type)); |
| 271 | } |
| 272 | return inst; |
| 273 | } |
Yi Tseng | fa4a1c7 | 2017-11-03 10:22:38 -0700 | [diff] [blame] | 274 | } |