blob: 25962caab108987c938be6409a33e60a151bfa55 [file] [log] [blame]
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04001/*
2 * Copyright 2017-present Open Networking Laboratory
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
17package org.onosproject.net.pi.model;
18
19import com.google.common.annotations.Beta;
20import org.onosproject.net.driver.HandlerBehaviour;
Carmelo Cascone00a59962017-06-16 17:51:49 +090021import org.onosproject.net.flow.FlowRule;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040022import org.onosproject.net.flow.TrafficTreatment;
23import org.onosproject.net.flow.criteria.Criterion;
Andrea Campanella432f7182017-07-14 18:43:27 +020024import org.onosproject.net.packet.OutboundPacket;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040025import org.onosproject.net.pi.runtime.PiHeaderFieldId;
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020026import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040027import org.onosproject.net.pi.runtime.PiTableAction;
Carmelo Cascone00a59962017-06-16 17:51:49 +090028import org.onosproject.net.pi.runtime.PiTableId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040029
Andrea Campanella432f7182017-07-14 18:43:27 +020030import java.util.Collection;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040031import java.util.Optional;
32
33/**
Carmelo Cascone00a59962017-06-16 17:51:49 +090034 * An interpreter of a protocol-independent pipeline model.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040035 */
36@Beta
37public interface PiPipelineInterpreter extends HandlerBehaviour {
38
39 /**
40 * Returns the protocol-independent header field identifier that is equivalent to the given
41 * criterion type, if present. If not present, it means that the given criterion type is not
42 * supported by this interpreter.
43 *
44 * @param type criterion type
45 * @return optional header field identifier
46 */
47 Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type);
48
49 /**
50 * Returns the criterion type that is equivalent to the given protocol-independent header field
51 * identifier, if present. If not present, it means that the given field identifier is not
52 * supported by this interpreter.
53 *
54 * @param headerFieldId header field identifier
55 * @return optional criterion type
56 */
57 Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId);
58
59 /**
Carmelo Cascone00a59962017-06-16 17:51:49 +090060 * Returns a protocol-independent table id equivalent to the given numeric table id (as in
61 * {@link FlowRule#tableId()}). If not present, it means that the given numeric table id cannot
62 * be mapped to any table of the pipeline model.
63 *
64 * @param flowRuleTableId a numeric table id
65 * @return a protocol-independent table id
66 */
67 Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId);
68
69 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040070 * Returns a table action of a protocol-independent pipeline that is functionally equivalent to
71 * the given ONOS traffic treatment for the given pipeline configuration.
72 *
73 * @param treatment a ONOS traffic treatment
74 * @param pipeconf a pipeline configuration
75 * @return a table action object
76 * @throws PiInterpreterException if the treatment cannot be mapped to any table action
77 */
78 PiTableAction mapTreatment(TrafficTreatment treatment, PiPipeconf pipeconf)
79 throws PiInterpreterException;
80
81 /**
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020082 * Returns a collection of packet operations equivalent to the given OutboundPacket, for the given
83 * pipeline configuration.
Andrea Campanella432f7182017-07-14 18:43:27 +020084 *
85 * @param packet a ONOS outbound packet
86 * @param pipeconf a pipeline configuration
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020087 * @return a collection of packet operations
Andrea Campanella432f7182017-07-14 18:43:27 +020088 * @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata
89 */
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020090 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet, PiPipeconf pipeconf)
Andrea Campanella432f7182017-07-14 18:43:27 +020091 throws PiInterpreterException;
92
93 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040094 * Signals that an error was encountered while executing the interpreter.
95 */
96 @Beta
97 class PiInterpreterException extends Exception {
98 public PiInterpreterException(String message) {
99 super(message);
100 }
101 }
Carmelo Cascone00a59962017-06-16 17:51:49 +0900102}