blob: a85d80c0b9f675a4dbbaba8e9ec771b45c395630 [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;
Andrea Campanella288b2732017-07-28 14:16:16 +020020import org.onosproject.net.DeviceId;
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;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040027import org.onosproject.net.pi.runtime.PiHeaderFieldId;
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020028import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Cascone00a59962017-06-16 17:51:49 +090029import org.onosproject.net.pi.runtime.PiTableId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040030
Andrea Campanella432f7182017-07-14 18:43:27 +020031import java.util.Collection;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040032import java.util.Optional;
33
34/**
Carmelo Cascone00a59962017-06-16 17:51:49 +090035 * An interpreter of a protocol-independent pipeline model.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040036 */
37@Beta
38public interface PiPipelineInterpreter extends HandlerBehaviour {
39
40 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040041 * Returns the protocol-independent header field identifier that is equivalent to the given criterion type, if
42 * present. If not present, it means that the given criterion type is not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040043 *
44 * @param type criterion type
45 * @return optional header field identifier
46 */
47 Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type);
48
49 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040050 * Returns the criterion type that is equivalent to the given protocol-independent header field identifier, if
51 * present. If not present, it means that the given field identifier is not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040052 *
53 * @param headerFieldId header field identifier
54 * @return optional criterion type
55 */
56 Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId);
57
58 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040059 * Returns a protocol-independent table id equivalent to the given numeric table id (as in {@link
60 * org.onosproject.net.flow.FlowRule#tableId()}). If not present, it means that the given numeric table id cannot be
61 * mapped to any table of the pipeline model.
Carmelo Cascone00a59962017-06-16 17:51:49 +090062 *
63 * @param flowRuleTableId a numeric table id
64 * @return a protocol-independent table id
65 */
66 Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId);
67
68 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040069 * Returns an action of a protocol-independent pipeline that is functionally equivalent to the given ONOS traffic
70 * treatment for the given table.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040071 *
72 * @param treatment a ONOS traffic treatment
Carmelo Casconef3a1a382017-07-27 12:04:39 -040073 * @param piTableId PI table identifier
74 * @return an action object
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040075 * @throws PiInterpreterException if the treatment cannot be mapped to any table action
76 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040077 PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040078 throws PiInterpreterException;
79
80 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040081 * Returns a collection of packet operations equivalent to the given OutboundPacket.
Andrea Campanella432f7182017-07-14 18:43:27 +020082 *
Carmelo Casconef3a1a382017-07-27 12:04:39 -040083 * @param packet a ONOS outbound packet
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020084 * @return a collection of packet operations
Andrea Campanella432f7182017-07-14 18:43:27 +020085 * @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata
86 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040087 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
Andrea Campanella432f7182017-07-14 18:43:27 +020088 throws PiInterpreterException;
89
90 /**
Andrea Campanella288b2732017-07-28 14:16:16 +020091 * Returns a InboundPacket equivalent to the given packet operation.
92 *
93 * @param deviceId the device that originated the packet-in
94 * @param packetInOperation the packet operation
95 * @return an ONOS inbound packet
96 * @throws PiInterpreterException if the port can't be extracted from the packet metadata
97 */
98 InboundPacket mapInboundPacket(DeviceId deviceId, PiPacketOperation packetInOperation)
99 throws PiInterpreterException;
100
101 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -0400102 * Signals that an error was encountered while executing the interpreter.
103 */
104 @Beta
105 class PiInterpreterException extends Exception {
106 public PiInterpreterException(String message) {
107 super(message);
108 }
109 }
Carmelo Cascone00a59962017-06-16 17:51:49 +0900110}