blob: 738996fecc74e860df4141cf404040d09766f444 [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 Cascone7f75be42017-09-07 14:37:02 +020027import org.onosproject.net.pi.runtime.PiCounterId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040028import org.onosproject.net.pi.runtime.PiHeaderFieldId;
Andrea Campanellafc1d34c2017-07-18 17:01:41 +020029import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Cascone00a59962017-06-16 17:51:49 +090030import org.onosproject.net.pi.runtime.PiTableId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040031
Andrea Campanella432f7182017-07-14 18:43:27 +020032import java.util.Collection;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040033import java.util.Optional;
34
35/**
Carmelo Cascone00a59962017-06-16 17:51:49 +090036 * An interpreter of a protocol-independent pipeline model.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040037 */
38@Beta
39public interface PiPipelineInterpreter extends HandlerBehaviour {
40
41 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040042 * Returns the protocol-independent header field identifier that is equivalent to the given criterion type, if
43 * present. If not present, it means that the given criterion type is not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040044 *
45 * @param type criterion type
46 * @return optional header field identifier
47 */
48 Optional<PiHeaderFieldId> mapCriterionType(Criterion.Type type);
49
50 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040051 * Returns the criterion type that is equivalent to the given protocol-independent header field identifier, if
52 * present. If not present, it means that the given field identifier is not supported by this interpreter.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040053 *
54 * @param headerFieldId header field identifier
55 * @return optional criterion type
56 */
57 Optional<Criterion.Type> mapPiHeaderFieldId(PiHeaderFieldId headerFieldId);
58
59 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040060 * Returns a protocol-independent table id equivalent to the given numeric table id (as in {@link
61 * org.onosproject.net.flow.FlowRule#tableId()}). If not present, it means that the given numeric table id cannot be
62 * mapped to any table of the pipeline model.
Carmelo Cascone00a59962017-06-16 17:51:49 +090063 *
64 * @param flowRuleTableId a numeric table id
65 * @return a protocol-independent table id
66 */
67 Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId);
68
69 /**
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020070 * Returns a numeric table id (as in {@link org.onosproject.net.flow.FlowRule#tableId()}) equivalent to the given
71 * protocol-independent table id. If not present, it means that the given protocol-independent table id refers to a
72 * table that does not exist, or that cannot be used for flow rule operations.
73 *
74 * @param piTableId protocol-independent table id
75 * @return numeric table id
76 */
77 Optional<Integer> mapPiTableId(PiTableId piTableId);
78
79 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -040080 * Returns an action of a protocol-independent pipeline that is functionally equivalent to the given ONOS traffic
81 * treatment for the given table.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040082 *
83 * @param treatment a ONOS traffic treatment
Carmelo Casconef3a1a382017-07-27 12:04:39 -040084 * @param piTableId PI table identifier
85 * @return an action object
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040086 * @throws PiInterpreterException if the treatment cannot be mapped to any table action
87 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -040088 PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId)
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040089 throws PiInterpreterException;
90
91 /**
Carmelo Cascone7f75be42017-09-07 14:37:02 +020092 * Returns a protocol-independent direct counter identifier for the given table, if present. If not present, it
93 * means that the given table does not support direct counters.
94 *
95 * @param piTableId table identifier
96 * @return optional direct counter identifier
97 */
98 Optional<PiCounterId> mapTableCounter(PiTableId piTableId);
99
100 /**
Carmelo Casconef3a1a382017-07-27 12:04:39 -0400101 * Returns a collection of packet operations equivalent to the given OutboundPacket.
Andrea Campanella432f7182017-07-14 18:43:27 +0200102 *
Carmelo Casconef3a1a382017-07-27 12:04:39 -0400103 * @param packet a ONOS outbound packet
Andrea Campanellafc1d34c2017-07-18 17:01:41 +0200104 * @return a collection of packet operations
Andrea Campanella432f7182017-07-14 18:43:27 +0200105 * @throws PiInterpreterException if the packet treatments cannot be mapped to any metadata
106 */
Carmelo Casconef3a1a382017-07-27 12:04:39 -0400107 Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet)
Andrea Campanella432f7182017-07-14 18:43:27 +0200108 throws PiInterpreterException;
109
110 /**
Andrea Campanella288b2732017-07-28 14:16:16 +0200111 * Returns a InboundPacket equivalent to the given packet operation.
112 *
113 * @param deviceId the device that originated the packet-in
114 * @param packetInOperation the packet operation
115 * @return an ONOS inbound packet
116 * @throws PiInterpreterException if the port can't be extracted from the packet metadata
117 */
118 InboundPacket mapInboundPacket(DeviceId deviceId, PiPacketOperation packetInOperation)
119 throws PiInterpreterException;
120
121 /**
Carmelo Cascone1022a4e2017-05-25 00:16:18 -0400122 * Signals that an error was encountered while executing the interpreter.
123 */
124 @Beta
125 class PiInterpreterException extends Exception {
126 public PiInterpreterException(String message) {
127 super(message);
128 }
129 }
Carmelo Cascone00a59962017-06-16 17:51:49 +0900130}