blob: 394b7873055c3bfdb4da2cd71c70e8eb8f647e3d [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;
21import org.onosproject.net.flow.TrafficTreatment;
22import org.onosproject.net.flow.criteria.Criterion;
Andrea Campanella432f7182017-07-14 18:43:27 +020023import org.onosproject.net.packet.OutboundPacket;
Carmelo Casconef3a1a382017-07-27 12:04:39 -040024import org.onosproject.net.pi.runtime.PiAction;
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 Cascone00a59962017-06-16 17:51:49 +090027import org.onosproject.net.pi.runtime.PiTableId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040028
Andrea Campanella432f7182017-07-14 18:43:27 +020029import java.util.Collection;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040030import java.util.Optional;
31
32/**
Carmelo Cascone00a59962017-06-16 17:51:49 +090033 * An interpreter of a protocol-independent pipeline model.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040034 */
35@Beta
36public interface PiPipelineInterpreter extends HandlerBehaviour {
37
38 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040039 * Returns the protocol-independent header field identifier that is equivalent to the given criterion type, if
40 * present. If not present, it means that the given criterion type is not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040041 *
42 * @param type criterion type
43 * @return optional header field identifier
44 */
45 Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type);
46
47 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040048 * Returns the criterion type that is equivalent to the given protocol-independent header field identifier, if
49 * present. If not present, it means that the given field identifier is not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040050 *
51 * @param headerFieldId header field identifier
52 * @return optional criterion type
53 */
54 Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId);
55
56 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040057 * Returns a protocol-independent table id equivalent to the given numeric table id (as in {@link
58 * org.onosproject.net.flow.FlowRule#tableId()}). If not present, it means that the given numeric table id cannot be
59 * mapped to any table of the pipeline model.
Carmelo Cascone00a59962017-06-16 17:51:49 +090060 *
61 * @param flowRuleTableId a numeric table id
62 * @return a protocol-independent table id
63 */
64 Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId);
65
66 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040067 * Returns an action of a protocol-independent pipeline that is functionally equivalent to the given ONOS traffic
68 * treatment for the given table.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040069 *
70 * @param treatment a ONOS traffic treatment
Carmelo Casconef3a1a382017-07-27 12:04:39 -040071 * @param piTableId PI table identifier
72 * @return an action object
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040073 * @throws PiInterpreterException if the treatment cannot be mapped to any table action
74 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040075 PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040076 throws PiInterpreterException;
77
78 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040079 * Returns a collection of packet operations equivalent to the given OutboundPacket.
Andrea Campanella432f7182017-07-14 18:43:27 +020080 *
Carmelo Casconef3a1a382017-07-27 12:04:39 -040081 * @param packet a ONOS outbound packet
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020082 * @return a collection of packet operations
Andrea Campanella432f7182017-07-14 18:43:27 +020083 * @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata
84 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040085 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
Andrea Campanella432f7182017-07-14 18:43:27 +020086 throws PiInterpreterException;
87
88 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040089 * Signals that an error was encountered while executing the interpreter.
90 */
91 @Beta
92 class PiInterpreterException extends Exception {
93 public PiInterpreterException(String message) {
94 super(message);
95 }
96 }
Carmelo Cascone00a59962017-06-16 17:51:49 +090097}