blob: 6b93f5d033082c450567ec184504cc9b4731b696 [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;
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 Cascone0b22d8f2017-07-31 07:22:27 +020069 * Returns a numeric table id (as in {@link org.onosproject.net.flow.FlowRule#tableId()}) equivalent to the given
70 * protocol-independent table id. If not present, it means that the given protocol-independent table id refers to a
71 * table that does not exist, or that cannot be used for flow rule operations.
72 *
73 * @param piTableId protocol-independent table id
74 * @return numeric table id
75 */
76 Optional<Integer> mapPiTableId(PiTableId piTableId);
77
78 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040079 * Returns an action of a protocol-independent pipeline that is functionally equivalent to the given ONOS traffic
80 * treatment for the given table.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040081 *
82 * @param treatment a ONOS traffic treatment
Carmelo Casconef3a1a382017-07-27 12:04:39 -040083 * @param piTableId PI table identifier
84 * @return an action object
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040085 * @throws PiInterpreterException if the treatment cannot be mapped to any table action
86 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040087 PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040088 throws PiInterpreterException;
89
90 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040091 * Returns a collection of packet operations equivalent to the given OutboundPacket.
Andrea Campanella432f7182017-07-14 18:43:27 +020092 *
Carmelo Casconef3a1a382017-07-27 12:04:39 -040093 * @param packet a ONOS outbound packet
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020094 * @return a collection of packet operations
Andrea Campanella432f7182017-07-14 18:43:27 +020095 * @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata
96 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040097 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
Andrea Campanella432f7182017-07-14 18:43:27 +020098 throws PiInterpreterException;
99
100 /**
Andrea Campanella288b2732017-07-28 14:16:16 +0200101 * Returns a InboundPacket equivalent to the given packet operation.
102 *
103 * @param deviceId the device that originated the packet-in
104 * @param packetInOperation the packet operation
105 * @return an ONOS inbound packet
106 * @throws PiInterpreterException if the port can't be extracted from the packet metadata
107 */
108 InboundPacket mapInboundPacket(DeviceId deviceId, PiPacketOperation packetInOperation)
109 throws PiInterpreterException;
110
111 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -0400112 * Signals that an error was encountered while executing the interpreter.
113 */
114 @Beta
115 class PiInterpreterException extends Exception {
116 public PiInterpreterException(String message) {
117 super(message);
118 }
119 }
Carmelo Cascone00a59962017-06-16 17:51:49 +0900120}