blob: a28c5f19c9bb3d400af22bd5a8f6ea019dd721d9 [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
Carmelo Cascone03f343d2017-11-13 16:54:39 -080067 * 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 Cascone0b22d8f2017-07-31 07:22:27 +020069 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080070 * @param piTableId PI table ID
71 * @return numeric table ID
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020072 */
73 Optional<Integer> mapPiTableId(PiTableId piTableId);
74
75 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080076 * Returns an action of a PI pipeline that is functionally equivalent to the given traffic treatment for the given
77 * table.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040078 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080079 * @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 Cascone1022a4e2017-05-25 00:16:18 -040083 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040084 PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040085 throws PiInterpreterException;
86
87 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080088 * Returns a collection of PI packet operations equivalent to the given outbound packet instance.
Andrea Campanella432f7182017-07-14 18:43:27 +020089 *
Carmelo Cascone87892e22017-11-13 16:01:29 -080090 * @param packet outbound packet
91 * @return collection of PI packet operations
92 * @throws PiInterpreterException if the packet treatments cannot be executed by this pipeline
Andrea Campanella432f7182017-07-14 18:43:27 +020093 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040094 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
Andrea Campanella432f7182017-07-14 18:43:27 +020095 throws PiInterpreterException;
96
97 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080098 * Returns an inbound packet equivalent to the given PI packet operation.
Andrea Campanella288b2732017-07-28 14:16:16 +020099 *
Carmelo Cascone87892e22017-11-13 16:01:29 -0800100 * @param packetOperation packet operation
101 * @return inbound packet
102 * @throws PiInterpreterException if the packet operation cannot be mapped to an inbound packet
Andrea Campanella288b2732017-07-28 14:16:16 +0200103 */
Carmelo Cascone87892e22017-11-13 16:01:29 -0800104 InboundPacket mapInboundPacket(PiPacketOperation packetOperation)
Andrea Campanella288b2732017-07-28 14:16:16 +0200105 throws PiInterpreterException;
106
107 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -0400108 * Signals that an error was encountered while executing the interpreter.
109 */
110 @Beta
111 class PiInterpreterException extends Exception {
112 public PiInterpreterException(String message) {
113 super(message);
114 }
115 }
Carmelo Cascone87892e22017-11-13 16:01:29 -0800116}