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; |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 20 | import org.onosproject.net.DeviceId; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 21 | import org.onosproject.net.driver.HandlerBehaviour; |
| 22 | import org.onosproject.net.flow.TrafficTreatment; |
| 23 | import org.onosproject.net.flow.criteria.Criterion; |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 24 | import org.onosproject.net.packet.InboundPacket; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 25 | import org.onosproject.net.packet.OutboundPacket; |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 26 | import org.onosproject.net.pi.runtime.PiAction; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 27 | import org.onosproject.net.pi.runtime.PiHeaderFieldId; |
Andrea Campanella | fc1d34c | 2017-07-18 17:01:41 +0200 | [diff] [blame] | 28 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 29 | import org.onosproject.net.pi.runtime.PiTableId; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 30 | |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 31 | import java.util.Collection; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 32 | import java.util.Optional; |
| 33 | |
| 34 | /** |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 35 | * An interpreter of a protocol-independent pipeline model. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 36 | */ |
| 37 | @Beta |
| 38 | public interface PiPipelineInterpreter extends HandlerBehaviour { |
| 39 | |
| 40 | /** |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 41 | * Returns the protocol-independent header field identifier that is equivalent to the given criterion type, if |
| 42 | * present. If not present, it means that the given criterion type is not supported by this interpreter. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 43 | * |
| 44 | * @param type criterion type |
| 45 | * @return optional header field identifier |
| 46 | */ |
| 47 | Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type); |
| 48 | |
| 49 | /** |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 50 | * Returns the criterion type that is equivalent to the given protocol-independent header field identifier, if |
| 51 | * present. If not present, it means that the given field identifier is not supported by this interpreter. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 52 | * |
| 53 | * @param headerFieldId header field identifier |
| 54 | * @return optional criterion type |
| 55 | */ |
| 56 | Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId); |
| 57 | |
| 58 | /** |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 59 | * Returns a protocol-independent table id equivalent to the given numeric table id (as in {@link |
| 60 | * org.onosproject.net.flow.FlowRule#tableId()}). If not present, it means that the given numeric table id cannot be |
| 61 | * mapped to any table of the pipeline model. |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 62 | * |
| 63 | * @param flowRuleTableId a numeric table id |
| 64 | * @return a protocol-independent table id |
| 65 | */ |
| 66 | Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId); |
| 67 | |
| 68 | /** |
Carmelo Cascone | 0b22d8f | 2017-07-31 07:22:27 +0200 | [diff] [blame] | 69 | * Returns a numeric table id (as in {@link org.onosproject.net.flow.FlowRule#tableId()}) equivalent to the given |
| 70 | * protocol-independent table id. If not present, it means that the given protocol-independent table id refers to a |
| 71 | * table that does not exist, or that cannot be used for flow rule operations. |
| 72 | * |
| 73 | * @param piTableId protocol-independent table id |
| 74 | * @return numeric table id |
| 75 | */ |
| 76 | Optional<Integer> mapPiTableId(PiTableId piTableId); |
| 77 | |
| 78 | /** |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 79 | * Returns an action of a protocol-independent pipeline that is functionally equivalent to the given ONOS traffic |
| 80 | * treatment for the given table. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 81 | * |
| 82 | * @param treatment a ONOS traffic treatment |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 83 | * @param piTableId PI table identifier |
| 84 | * @return an action object |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 85 | * @throws PiInterpreterException if the treatment cannot be mapped to any table action |
| 86 | */ |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 87 | PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 88 | throws PiInterpreterException; |
| 89 | |
| 90 | /** |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 91 | * Returns a collection of packet operations equivalent to the given OutboundPacket. |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 92 | * |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 93 | * @param packet a ONOS outbound packet |
Andrea Campanella | fc1d34c | 2017-07-18 17:01:41 +0200 | [diff] [blame] | 94 | * @return a collection of packet operations |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 95 | * @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata |
| 96 | */ |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 97 | Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 98 | throws PiInterpreterException; |
| 99 | |
| 100 | /** |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 101 | * Returns a InboundPacket equivalent to the given packet operation. |
| 102 | * |
| 103 | * @param deviceId the device that originated the packet-in |
| 104 | * @param packetInOperation the packet operation |
| 105 | * @return an ONOS inbound packet |
| 106 | * @throws PiInterpreterException if the port can't be extracted from the packet metadata |
| 107 | */ |
| 108 | InboundPacket mapInboundPacket(DeviceId deviceId, PiPacketOperation packetInOperation) |
| 109 | throws PiInterpreterException; |
| 110 | |
| 111 | /** |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 112 | * Signals that an error was encountered while executing the interpreter. |
| 113 | */ |
| 114 | @Beta |
| 115 | class PiInterpreterException extends Exception { |
| 116 | public PiInterpreterException(String message) { |
| 117 | super(message); |
| 118 | } |
| 119 | } |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 120 | } |