Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 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; |
| 21 | import org.onosproject.net.flow.TrafficTreatment; |
| 22 | import org.onosproject.net.flow.criteria.Criterion; |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 23 | import org.onosproject.net.packet.InboundPacket; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 24 | import org.onosproject.net.packet.OutboundPacket; |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 25 | import org.onosproject.net.pi.runtime.PiAction; |
Andrea Campanella | fc1d34c | 2017-07-18 17:01:41 +0200 | [diff] [blame] | 26 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 27 | |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 28 | import java.util.Collection; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 29 | import java.util.Optional; |
| 30 | |
| 31 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 32 | * An interpreter of a PI pipeline model. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 33 | */ |
| 34 | @Beta |
| 35 | public interface PiPipelineInterpreter extends HandlerBehaviour { |
| 36 | |
| 37 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 38 | * Returns a PI match field ID that is equivalent to the given criterion type, if present. If not present, it means |
| 39 | * that the given criterion type is not supported by this interpreter. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 40 | * |
| 41 | * @param type criterion type |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 42 | * @return optional match field ID |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 43 | */ |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 44 | Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 45 | |
| 46 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 47 | * Returns the criterion type that is equivalent to the given PI match field ID, if present. If not present, it |
| 48 | * means that the given match field is not supported by this interpreter. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 49 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 50 | * @param fieldId match field ID |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 51 | * @return optional criterion type |
| 52 | */ |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 53 | Optional<Criterion.Type> mapPiMatchFieldId(PiMatchFieldId fieldId); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 54 | |
| 55 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 56 | * Returns a PI table ID equivalent to the given numeric table ID (as in {@link |
| 57 | * org.onosproject.net.flow.FlowRule#tableId()}). If not present, it means that the given integer table ID cannot be |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 58 | * mapped to any table of the pipeline model. |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 59 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 60 | * @param flowRuleTableId a numeric table ID |
| 61 | * @return PI table ID |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 62 | */ |
| 63 | Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId); |
| 64 | |
| 65 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 66 | * Returns an integer table ID equivalent to the given PI table ID. If not present, it means that the given PI table |
Carmelo Cascone | 03f343d | 2017-11-13 16:54:39 -0800 | [diff] [blame^] | 67 | * ID cannot be mapped to any integer table ID, because such mapping would be meaningless or because such PI table |
| 68 | * ID is not defined by the pipeline model. |
Carmelo Cascone | 0b22d8f | 2017-07-31 07:22:27 +0200 | [diff] [blame] | 69 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 70 | * @param piTableId PI table ID |
| 71 | * @return numeric table ID |
Carmelo Cascone | 0b22d8f | 2017-07-31 07:22:27 +0200 | [diff] [blame] | 72 | */ |
| 73 | Optional<Integer> mapPiTableId(PiTableId piTableId); |
| 74 | |
| 75 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 76 | * Returns an action of a PI pipeline that is functionally equivalent to the given traffic treatment for the given |
| 77 | * table. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 78 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 79 | * @param treatment traffic treatment |
| 80 | * @param piTableId PI table ID |
| 81 | * @return action object |
| 82 | * @throws PiInterpreterException if the treatment cannot be mapped to any PI action |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 83 | */ |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 84 | PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 85 | throws PiInterpreterException; |
| 86 | |
| 87 | /** |
Carmelo Cascone | 03f343d | 2017-11-13 16:54:39 -0800 | [diff] [blame^] | 88 | * Returns a PI direct counter ID for the given table to be used to to compute flow entry statistics, if present. If |
| 89 | * not present, it means that the given table does not offer any counter suitable for the purpose of computing flow |
| 90 | * rule statistics. Other direct counters might be defined for the given table (check pipeline model), however none |
| 91 | * of them should be used for flow entry statistics except for this one. |
Carmelo Cascone | 7f75be4 | 2017-09-07 14:37:02 +0200 | [diff] [blame] | 92 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 93 | * @param piTableId table ID |
| 94 | * @return optional direct counter ID |
Carmelo Cascone | 7f75be4 | 2017-09-07 14:37:02 +0200 | [diff] [blame] | 95 | */ |
| 96 | Optional<PiCounterId> mapTableCounter(PiTableId piTableId); |
| 97 | |
| 98 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 99 | * Returns a collection of PI packet operations equivalent to the given outbound packet instance. |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 100 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 101 | * @param packet outbound packet |
| 102 | * @return collection of PI packet operations |
| 103 | * @throws PiInterpreterException if the packet treatments cannot be executed by this pipeline |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 104 | */ |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 105 | Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 106 | throws PiInterpreterException; |
| 107 | |
| 108 | /** |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 109 | * Returns an inbound packet equivalent to the given PI packet operation. |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 110 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 111 | * @param packetOperation packet operation |
| 112 | * @return inbound packet |
| 113 | * @throws PiInterpreterException if the packet operation cannot be mapped to an inbound packet |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 114 | */ |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 115 | InboundPacket mapInboundPacket(PiPacketOperation packetOperation) |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 116 | throws PiInterpreterException; |
| 117 | |
| 118 | /** |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 119 | * Signals that an error was encountered while executing the interpreter. |
| 120 | */ |
| 121 | @Beta |
| 122 | class PiInterpreterException extends Exception { |
| 123 | public PiInterpreterException(String message) { |
| 124 | super(message); |
| 125 | } |
| 126 | } |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 127 | } |