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; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame^] | 24 | import org.onosproject.net.packet.OutboundPacket; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 25 | import org.onosproject.net.pi.runtime.PiHeaderFieldId; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame^] | 26 | import org.onosproject.net.pi.runtime.PiPacketMetadata; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 27 | import org.onosproject.net.pi.runtime.PiTableAction; |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 28 | import org.onosproject.net.pi.runtime.PiTableId; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 29 | |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame^] | 30 | import java.util.Collection; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 31 | import java.util.Optional; |
| 32 | |
| 33 | /** |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 34 | * An interpreter of a protocol-independent pipeline model. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 35 | */ |
| 36 | @Beta |
| 37 | public interface PiPipelineInterpreter extends HandlerBehaviour { |
| 38 | |
| 39 | /** |
| 40 | * Returns the protocol-independent header field identifier that is equivalent to the given |
| 41 | * criterion type, if present. If not present, it means that the given criterion type is not |
| 42 | * supported by this interpreter. |
| 43 | * |
| 44 | * @param type criterion type |
| 45 | * @return optional header field identifier |
| 46 | */ |
| 47 | Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type); |
| 48 | |
| 49 | /** |
| 50 | * Returns the criterion type that is equivalent to the given protocol-independent header field |
| 51 | * identifier, if present. If not present, it means that the given field identifier is not |
| 52 | * supported by this interpreter. |
| 53 | * |
| 54 | * @param headerFieldId header field identifier |
| 55 | * @return optional criterion type |
| 56 | */ |
| 57 | Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId); |
| 58 | |
| 59 | /** |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 60 | * Returns a protocol-independent table id equivalent to the given numeric table id (as in |
| 61 | * {@link FlowRule#tableId()}). If not present, it means that the given numeric table id cannot |
| 62 | * be mapped to any table of the pipeline model. |
| 63 | * |
| 64 | * @param flowRuleTableId a numeric table id |
| 65 | * @return a protocol-independent table id |
| 66 | */ |
| 67 | Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId); |
| 68 | |
| 69 | /** |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 70 | * Returns a table action of a protocol-independent pipeline that is functionally equivalent to |
| 71 | * the given ONOS traffic treatment for the given pipeline configuration. |
| 72 | * |
| 73 | * @param treatment a ONOS traffic treatment |
| 74 | * @param pipeconf a pipeline configuration |
| 75 | * @return a table action object |
| 76 | * @throws PiInterpreterException if the treatment cannot be mapped to any table action |
| 77 | */ |
| 78 | PiTableAction mapTreatment(TrafficTreatment treatment, PiPipeconf pipeconf) |
| 79 | throws PiInterpreterException; |
| 80 | |
| 81 | /** |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame^] | 82 | * Returns a collection of metadatas for a packet-out operation that are equivalent to |
| 83 | * the traffic treatment of the given OutboundPacket, for the given pipeline configuration. |
| 84 | * |
| 85 | * @param packet a ONOS outbound packet |
| 86 | * @param pipeconf a pipeline configuration |
| 87 | * @return a collection of packet metadata |
| 88 | * @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata |
| 89 | */ |
| 90 | Collection<PiPacketMetadata> mapOutboundPacket(OutboundPacket packet, PiPipeconf pipeconf) |
| 91 | throws PiInterpreterException; |
| 92 | |
| 93 | /** |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 94 | * Signals that an error was encountered while executing the interpreter. |
| 95 | */ |
| 96 | @Beta |
| 97 | class PiInterpreterException extends Exception { |
| 98 | public PiInterpreterException(String message) { |
| 99 | super(message); |
| 100 | } |
| 101 | } |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 102 | } |