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; |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 20 | import org.onosproject.net.DeviceId; |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 21 | import org.onosproject.net.PortNumber; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 22 | import org.onosproject.net.driver.HandlerBehaviour; |
| 23 | import org.onosproject.net.flow.TrafficTreatment; |
| 24 | import org.onosproject.net.flow.criteria.Criterion; |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 25 | import org.onosproject.net.packet.InboundPacket; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 26 | import org.onosproject.net.packet.OutboundPacket; |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 27 | import org.onosproject.net.pi.runtime.PiAction; |
Andrea Campanella | fc1d34c | 2017-07-18 17:01:41 +0200 | [diff] [blame] | 28 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
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 | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 34 | * An interpreter of a PI 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 | /** |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 40 | * Returns a PI match field ID that is equivalent to the given criterion |
| 41 | * type, if present. If not present, it means that the given criterion type |
| 42 | * is not supported by this interpreter. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 43 | * |
| 44 | * @param type criterion type |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 45 | * @return optional match field ID |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 46 | */ |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 47 | Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 48 | |
| 49 | /** |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 50 | * Returns a PI table ID equivalent to the given numeric table ID (as in |
| 51 | * {@link org.onosproject.net.flow.FlowRule#tableId()}). If not present, it |
| 52 | * means that the given integer table ID cannot be mapped to any table of |
| 53 | * the pipeline model. |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 54 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 55 | * @param flowRuleTableId a numeric table ID |
| 56 | * @return PI table ID |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 57 | */ |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 58 | // FIXME: remove this method. The only place where this mapping seems useful |
| 59 | // is when using the default single table pipeliner which produces flow |
| 60 | // rules for table 0. Instead, PI pipeliners should provide a mapping to a |
| 61 | // specific PiTableId even when mapping to a single table. |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 62 | Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId); |
| 63 | |
| 64 | /** |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 65 | * Returns an action of a PI pipeline that is functionally equivalent to the |
| 66 | * given traffic treatment for the given table. |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 67 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 68 | * @param treatment traffic treatment |
| 69 | * @param piTableId PI table ID |
| 70 | * @return action object |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 71 | * @throws PiInterpreterException if the treatment cannot be mapped to any |
| 72 | * PI action |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 73 | */ |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 74 | PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 75 | throws PiInterpreterException; |
| 76 | |
| 77 | /** |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 78 | * Returns a collection of PI packet operations equivalent to the given |
| 79 | * outbound packet instance. |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 80 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 81 | * @param packet outbound packet |
| 82 | * @return collection of PI packet operations |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 83 | * @throws PiInterpreterException if the packet treatments cannot be |
| 84 | * executed by this pipeline |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 85 | */ |
Carmelo Cascone | f3a1a38 | 2017-07-27 12:04:39 -0400 | [diff] [blame] | 86 | Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 87 | throws PiInterpreterException; |
| 88 | |
| 89 | /** |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 90 | * Returns an inbound packet equivalent to the given PI packet-in operation |
| 91 | * for the given device. |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 92 | * |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 93 | * @param packetOperation packet operation |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 94 | * @param deviceId ID of the device that originated the packet-in |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 95 | * @return inbound packet |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 96 | * @throws PiInterpreterException if the packet operation cannot be mapped |
| 97 | * to an inbound packet |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 98 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 99 | InboundPacket mapInboundPacket(PiPacketOperation packetOperation, DeviceId deviceId) |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 100 | throws PiInterpreterException; |
| 101 | |
| 102 | /** |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 103 | * Maps the given logical port number to the data plane port ID (integer) |
| 104 | * identifying the same port for this pipeconf, if such mapping is |
| 105 | * possible. |
| 106 | * |
| 107 | * @param port port number |
| 108 | * @return optional integer |
| 109 | */ |
| 110 | default Optional<Integer> mapLogicalPortNumber(PortNumber port) { |
| 111 | return Optional.empty(); |
| 112 | } |
| 113 | |
| 114 | /** |
Carmelo Cascone | 50d195f | 2018-09-11 13:26:38 -0700 | [diff] [blame] | 115 | * If the given table allows for mutable default actions, this method |
| 116 | * returns an action instance to be used when ONOS tries to remove a |
| 117 | * different default action previously set. |
| 118 | * |
| 119 | * @param tableId table ID |
| 120 | * @return optional default action |
| 121 | */ |
| 122 | default Optional<PiAction> getOriginalDefaultAction(PiTableId tableId) { |
| 123 | return Optional.empty(); |
| 124 | } |
| 125 | |
| 126 | /** |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 127 | * Signals that an error was encountered while executing the interpreter. |
| 128 | */ |
| 129 | @Beta |
| 130 | class PiInterpreterException extends Exception { |
| 131 | public PiInterpreterException(String message) { |
| 132 | super(message); |
| 133 | } |
| 134 | } |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 135 | } |