blob: cada0f95ca99e45e19f6e0c59aa2511b9a5c86c8 [file] [log] [blame]
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04003 *
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
17package org.onosproject.net.pi.model;
18
19import com.google.common.annotations.Beta;
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020020import org.onosproject.net.PortNumber;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040021import org.onosproject.net.driver.HandlerBehaviour;
22import org.onosproject.net.flow.TrafficTreatment;
23import org.onosproject.net.flow.criteria.Criterion;
Andrea Campanella288b2732017-07-28 14:16:16 +020024import org.onosproject.net.packet.InboundPacket;
Andrea Campanella432f7182017-07-14 18:43:27 +020025import org.onosproject.net.packet.OutboundPacket;
Carmelo Casconef3a1a382017-07-27 12:04:39 -040026import org.onosproject.net.pi.runtime.PiAction;
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020027import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040028
Andrea Campanella432f7182017-07-14 18:43:27 +020029import java.util.Collection;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040030import java.util.Optional;
31
32/**
Carmelo Cascone87892e22017-11-13 16:01:29 -080033 * An interpreter of a PI pipeline model.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040034 */
35@Beta
36public interface PiPipelineInterpreter extends HandlerBehaviour {
37
38 /**
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020039 * Returns a PI match field ID that is equivalent to the given criterion
40 * type, if present. If not present, it means that the given criterion type
41 * is not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040042 *
43 * @param type criterion type
Carmelo Cascone87892e22017-11-13 16:01:29 -080044 * @return optional match field ID
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040045 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080046 Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040047
48 /**
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020049 * Returns the criterion type that is equivalent to the given PI match field
50 * ID, if present. If not present, it means that the given match field is
51 * not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040052 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080053 * @param fieldId match field ID
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040054 * @return optional criterion type
55 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080056 Optional<Criterion.Type> mapPiMatchFieldId(PiMatchFieldId fieldId);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040057
58 /**
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020059 * Returns a PI table ID equivalent to the given numeric table ID (as in
60 * {@link org.onosproject.net.flow.FlowRule#tableId()}). If not present, it
61 * means that the given integer table ID cannot be mapped to any table of
62 * the pipeline model.
Carmelo Cascone00a59962017-06-16 17:51:49 +090063 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080064 * @param flowRuleTableId a numeric table ID
65 * @return PI table ID
Carmelo Cascone00a59962017-06-16 17:51:49 +090066 */
Carmelo Casconeb5324e72018-11-25 02:26:32 -080067 // FIXME: remove this method. The only place where this mapping seems useful
68 // is when using the default single table pipeliner which produces flow
69 // rules for table 0. Instead, PI pipeliners should provide a mapping to a
70 // specific PiTableId even when mapping to a single table.
Carmelo Cascone00a59962017-06-16 17:51:49 +090071 Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId);
72
73 /**
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020074 * Returns an integer table ID equivalent to the given PI table ID. If not
75 * present, it means that the given PI table ID cannot be mapped to any
76 * integer table ID, because such mapping would be meaningless or because
77 * such PI table ID is not defined by the pipeline model.
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020078 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080079 * @param piTableId PI table ID
80 * @return numeric table ID
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020081 */
Carmelo Casconeb5324e72018-11-25 02:26:32 -080082 // FIXME: as above
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020083 Optional<Integer> mapPiTableId(PiTableId piTableId);
84
85 /**
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020086 * Returns an action of a PI pipeline that is functionally equivalent to the
87 * given traffic treatment for the given table.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040088 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080089 * @param treatment traffic treatment
90 * @param piTableId PI table ID
91 * @return action object
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020092 * @throws PiInterpreterException if the treatment cannot be mapped to any
93 * PI action
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040094 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040095 PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040096 throws PiInterpreterException;
97
98 /**
Carmelo Cascone1e8843f2018-07-19 19:01:12 +020099 * Returns a collection of PI packet operations equivalent to the given
100 * outbound packet instance.
Andrea Campanella432f7182017-07-14 18:43:27 +0200101 *
Carmelo Cascone87892e22017-11-13 16:01:29 -0800102 * @param packet outbound packet
103 * @return collection of PI packet operations
Carmelo Cascone1e8843f2018-07-19 19:01:12 +0200104 * @throws PiInterpreterException if the packet treatments cannot be
105 * executed by this pipeline
Andrea Campanella432f7182017-07-14 18:43:27 +0200106 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -0400107 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
Andrea Campanella432f7182017-07-14 18:43:27 +0200108 throws PiInterpreterException;
109
110 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -0800111 * Returns an inbound packet equivalent to the given PI packet operation.
Andrea Campanella288b2732017-07-28 14:16:16 +0200112 *
Carmelo Cascone87892e22017-11-13 16:01:29 -0800113 * @param packetOperation packet operation
114 * @return inbound packet
Carmelo Cascone1e8843f2018-07-19 19:01:12 +0200115 * @throws PiInterpreterException if the packet operation cannot be mapped
116 * to an inbound packet
Andrea Campanella288b2732017-07-28 14:16:16 +0200117 */
Carmelo Cascone87892e22017-11-13 16:01:29 -0800118 InboundPacket mapInboundPacket(PiPacketOperation packetOperation)
Andrea Campanella288b2732017-07-28 14:16:16 +0200119 throws PiInterpreterException;
120
121 /**
Carmelo Cascone1e8843f2018-07-19 19:01:12 +0200122 * Maps the given logical port number to the data plane port ID (integer)
123 * identifying the same port for this pipeconf, if such mapping is
124 * possible.
125 *
126 * @param port port number
127 * @return optional integer
128 */
129 default Optional<Integer> mapLogicalPortNumber(PortNumber port) {
130 return Optional.empty();
131 }
132
133 /**
Carmelo Cascone50d195f2018-09-11 13:26:38 -0700134 * If the given table allows for mutable default actions, this method
135 * returns an action instance to be used when ONOS tries to remove a
136 * different default action previously set.
137 *
138 * @param tableId table ID
139 * @return optional default action
140 */
141 default Optional<PiAction> getOriginalDefaultAction(PiTableId tableId) {
142 return Optional.empty();
143 }
144
145 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -0400146 * Signals that an error was encountered while executing the interpreter.
147 */
148 @Beta
149 class PiInterpreterException extends Exception {
150 public PiInterpreterException(String message) {
151 super(message);
152 }
153 }
Carmelo Cascone87892e22017-11-13 16:01:29 -0800154}