blob: 10680268bf4fa9df92d5bc6d55a37896117465bf [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;
20import org.onosproject.net.driver.HandlerBehaviour;
21import org.onosproject.net.flow.TrafficTreatment;
22import org.onosproject.net.flow.criteria.Criterion;
Andrea Campanella288b2732017-07-28 14:16:16 +020023import org.onosproject.net.packet.InboundPacket;
Andrea Campanella432f7182017-07-14 18:43:27 +020024import org.onosproject.net.packet.OutboundPacket;
Carmelo Casconef3a1a382017-07-27 12:04:39 -040025import org.onosproject.net.pi.runtime.PiAction;
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020026import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040027
Andrea Campanella432f7182017-07-14 18:43:27 +020028import java.util.Collection;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040029import java.util.Optional;
30
31/**
Carmelo Cascone87892e22017-11-13 16:01:29 -080032 * An interpreter of a PI pipeline model.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040033 */
34@Beta
35public interface PiPipelineInterpreter extends HandlerBehaviour {
36
37 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080038 * 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 Cascone1022a4e2017-05-25 00:16:18 -040040 *
41 * @param type criterion type
Carmelo Cascone87892e22017-11-13 16:01:29 -080042 * @return optional match field ID
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040043 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080044 Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040045
46 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080047 * 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 Cascone1022a4e2017-05-25 00:16:18 -040049 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080050 * @param fieldId match field ID
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040051 * @return optional criterion type
52 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080053 Optional<Criterion.Type> mapPiMatchFieldId(PiMatchFieldId fieldId);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040054
55 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080056 * 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 Casconef3a1a382017-07-27 12:04:39 -040058 * mapped to any table of the pipeline model.
Carmelo Cascone00a59962017-06-16 17:51:49 +090059 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080060 * @param flowRuleTableId a numeric table ID
61 * @return PI table ID
Carmelo Cascone00a59962017-06-16 17:51:49 +090062 */
63 Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId);
64
65 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080066 * Returns an integer table ID equivalent to the given PI table ID. If not present, it means that the given PI table
67 * ID refers to a table that does not exist, or that cannot be used for flow rule operations.
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020068 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080069 * @param piTableId PI table ID
70 * @return numeric table ID
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020071 */
72 Optional<Integer> mapPiTableId(PiTableId piTableId);
73
74 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080075 * Returns an action of a PI pipeline that is functionally equivalent to the given traffic treatment for the given
76 * table.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040077 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080078 * @param treatment traffic treatment
79 * @param piTableId PI table ID
80 * @return action object
81 * @throws PiInterpreterException if the treatment cannot be mapped to any PI action
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040082 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040083 PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040084 throws PiInterpreterException;
85
86 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080087 * Returns a PI direct counter ID for the given table, if present. If not present, it means that the given table
88 * does not support direct counters.
Carmelo Cascone7f75be42017-09-07 14:37:02 +020089 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080090 * @param piTableId table ID
91 * @return optional direct counter ID
Carmelo Cascone7f75be42017-09-07 14:37:02 +020092 */
93 Optional<PiCounterId> mapTableCounter(PiTableId piTableId);
94
95 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080096 * Returns a collection of PI packet operations equivalent to the given outbound packet instance.
Andrea Campanella432f7182017-07-14 18:43:27 +020097 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080098 * @param packet outbound packet
99 * @return collection of PI packet operations
100 * @throws PiInterpreterException if the packet treatments cannot be executed by this pipeline
Andrea Campanella432f7182017-07-14 18:43:27 +0200101 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -0400102 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
Andrea Campanella432f7182017-07-14 18:43:27 +0200103 throws PiInterpreterException;
104
105 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -0800106 * Returns an inbound packet equivalent to the given PI packet operation.
Andrea Campanella288b2732017-07-28 14:16:16 +0200107 *
Carmelo Cascone87892e22017-11-13 16:01:29 -0800108 * @param packetOperation packet operation
109 * @return inbound packet
110 * @throws PiInterpreterException if the packet operation cannot be mapped to an inbound packet
Andrea Campanella288b2732017-07-28 14:16:16 +0200111 */
Carmelo Cascone87892e22017-11-13 16:01:29 -0800112 InboundPacket mapInboundPacket(PiPacketOperation packetOperation)
Andrea Campanella288b2732017-07-28 14:16:16 +0200113 throws PiInterpreterException;
114
115 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -0400116 * Signals that an error was encountered while executing the interpreter.
117 */
118 @Beta
119 class PiInterpreterException extends Exception {
120 public PiInterpreterException(String message) {
121 super(message);
122 }
123 }
Carmelo Cascone87892e22017-11-13 16:01:29 -0800124}