Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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 | */ |
| 16 | |
| 17 | package org.onosproject.net.pi.model; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.net.driver.HandlerBehaviour; |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame^] | 21 | import org.onosproject.net.flow.FlowRule; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 22 | import org.onosproject.net.flow.TrafficTreatment; |
| 23 | import org.onosproject.net.flow.criteria.Criterion; |
| 24 | import org.onosproject.net.pi.runtime.PiHeaderFieldId; |
| 25 | import org.onosproject.net.pi.runtime.PiTableAction; |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame^] | 26 | import org.onosproject.net.pi.runtime.PiTableId; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 27 | |
| 28 | import java.util.Optional; |
| 29 | |
| 30 | /** |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame^] | 31 | * An interpreter of a protocol-independent pipeline model. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 32 | */ |
| 33 | @Beta |
| 34 | public interface PiPipelineInterpreter extends HandlerBehaviour { |
| 35 | |
| 36 | /** |
| 37 | * Returns the protocol-independent header field identifier that is equivalent to the given |
| 38 | * criterion type, if present. If not present, it means that the given criterion type is not |
| 39 | * supported by this interpreter. |
| 40 | * |
| 41 | * @param type criterion type |
| 42 | * @return optional header field identifier |
| 43 | */ |
| 44 | Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type); |
| 45 | |
| 46 | /** |
| 47 | * Returns the criterion type that is equivalent to the given protocol-independent header field |
| 48 | * identifier, if present. If not present, it means that the given field identifier is not |
| 49 | * supported by this interpreter. |
| 50 | * |
| 51 | * @param headerFieldId header field identifier |
| 52 | * @return optional criterion type |
| 53 | */ |
| 54 | Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId); |
| 55 | |
| 56 | /** |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame^] | 57 | * Returns a protocol-independent table id equivalent to the given numeric table id (as in |
| 58 | * {@link FlowRule#tableId()}). If not present, it means that the given numeric table id cannot |
| 59 | * be mapped to any table of the pipeline model. |
| 60 | * |
| 61 | * @param flowRuleTableId a numeric table id |
| 62 | * @return a protocol-independent table id |
| 63 | */ |
| 64 | Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId); |
| 65 | |
| 66 | /** |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 67 | * Returns a table action of a protocol-independent pipeline that is functionally equivalent to |
| 68 | * the given ONOS traffic treatment for the given pipeline configuration. |
| 69 | * |
| 70 | * @param treatment a ONOS traffic treatment |
| 71 | * @param pipeconf a pipeline configuration |
| 72 | * @return a table action object |
| 73 | * @throws PiInterpreterException if the treatment cannot be mapped to any table action |
| 74 | */ |
| 75 | PiTableAction mapTreatment(TrafficTreatment treatment, PiPipeconf pipeconf) |
| 76 | throws PiInterpreterException; |
| 77 | |
| 78 | /** |
| 79 | * Signals that an error was encountered while executing the interpreter. |
| 80 | */ |
| 81 | @Beta |
| 82 | class PiInterpreterException extends Exception { |
| 83 | public PiInterpreterException(String message) { |
| 84 | super(message); |
| 85 | } |
| 86 | } |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame^] | 87 | } |