blob: 4cc1ff2f28415913f93cca3c36d7d17857da1bae [file] [log] [blame]
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -07001/*
2 * Copyright 2015-present Open Networking Foundation
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 */
16package org.onosproject.inbandtelemetry.api;
17
18import com.google.common.annotations.Beta;
19import org.onosproject.net.flow.DefaultTrafficSelector;
20import org.onosproject.net.flow.TrafficSelector;
21
22import java.util.HashSet;
23import java.util.Set;
24
25import static com.google.common.base.Preconditions.checkArgument;
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Represents an INT monitoring intent. Each intent is made up of a traffic slice
30 * to be monitored, as a form of TrafficSelector, types of metadata to collect,
31 * and other required parameters (INT header type, INT Report type, and Telemetry mode).
32 *
33 * IntIntent is converted to a set of flow rules to be installed on each INT-capable
34 * switch in the network, by IntService.
35 *
36 * Terminologies and descriptions are borrowed from INT specification.
37 *
38 * @see <a href="https://github.com/p4lang/p4-applications/blob/master/docs/INT.pdf">
39 * INT sepcification</a>
40 */
41@Beta
42public final class IntIntent {
43 /**
44 * Represents a type of INT metadata.
45 */
46 public enum IntMetadataType {
47 /**
48 * The unique ID of a switch.
49 */
50 SWITCH_ID,
51 /**
52 * The ports on which the INT packet was received and sent out.
53 */
54 L1_PORT_ID,
55 /**
56 * Time taken for the INT packet to be switched within the device.
57 */
58 HOP_LATENCY,
59 /**
60 * The build-up of traffic in the queue that the INT packet observes
61 * in the device while being forwarded.
62 */
63 QUEUE_OCCUPANCY,
64 /**
65 * The device local time when the INT packet was received on the ingress port.
66 */
67 INGRESS_TIMESTAMP,
68 /**
69 * The device local time when the INT packet was processed by the egress port.
70 */
71 EGRESS_TIMESTAMP,
72 /**
73 * The logical ports on which the INT packet was received and sent out.
74 */
75 L2_PORT_ID,
76 /**
77 * Current utilization of the egress port via witch the INT packet was sent out.
78 */
79 EGRESS_TX_UTIL
80 }
81
82 /**
83 * Represents an INT header type.
84 */
85 public enum IntHeaderType {
86 /**
87 * Intemediate devices must process this type of INT header.
88 */
89 HOP_BY_HOP,
90 /**
91 * Intemediate devices must ignore this type of INT header.
92 */
93 DESTINATION
94 }
95
96 /**
97 * Represents a type of telemetry report.
98 */
99 public enum IntReportType {
100 /**
101 * Report for flows matching certain definitions.
102 */
103 TRACKED_FLOW,
104 /**
105 * Reports for all dropeed packets matching a drop watchlist.
106 */
107 DROPPED_PACKET,
108 /**
109 * Reports for traffic entering a specific queue during a period of queue congestion.
110 */
111 CONGESTED_QUEUE
112 }
113
114 /**
115 * Represents telemetry mode.
116 */
117 public enum TelemetryMode {
118 /**
119 * Each network device generates its own telemetry reports.
120 */
121 POSTCARD,
122 /**
123 * Telemetry metadata is embedded in between the original
124 * headers of data packets as they traverse the network.
125 */
126 INBAND_TELEMETRY
127 }
128
129 private static final int DEFAULT_PRIORITY = 10;
130
131 // TrafficSelector to describe target flows to monitor
132 private final TrafficSelector selector;
133 // set of metadata type to collect
134 private final Set<IntMetadataType> metadataTypes;
135 // hop-by-hop or destination
136 private final IntHeaderType headerType;
137 // telemetry report types
138 private final Set<IntReportType> reportTypes;
139 // telemetry mode
140 private final TelemetryMode telemetryMode;
141
142 /**
143 * Creates an IntIntent.
144 *
145 * @param selector the traffic selector that identifies traffic to enable INT
146 * @param metadataTypes the types of metadata to collect
147 * @param headerType the type of INT header
148 * @param reportTypes the types of report to be generated
149 * @param telemetryMode the telemetry mode
150 */
151 private IntIntent(TrafficSelector selector, Set<IntMetadataType> metadataTypes,
152 IntHeaderType headerType, Set<IntReportType> reportTypes,
153 TelemetryMode telemetryMode) {
154 this.selector = selector;
155 this.metadataTypes = new HashSet<>(metadataTypes);
156 this.headerType = headerType;
157 this.reportTypes = new HashSet<>(reportTypes);
158 this.telemetryMode = telemetryMode;
159 }
160
161 /**
162 * Returns traffic selector of this intent.
163 *
164 * @return traffic selector
165 */
166 public TrafficSelector selector() {
167 return selector;
168 }
169
170 /**
171 * Returns a set of metadata type to be collected by this intent.
172 *
173 * @return set of metadata type
174 */
175 public Set<IntMetadataType> metadataTypes() {
176 return metadataTypes;
177 }
178
179 /**
180 * Returns a INT header type specified in this intent.
181 *
182 * @return INT header type
183 */
184 public IntHeaderType headerType() {
185 return headerType;
186 }
187
188 /**
189 * Returns a set of report type to be generated.
190 *
191 * @return set of report type
192 */
193 public Set<IntReportType> reportTypes() {
194 return reportTypes;
195 }
196
197 /**
198 * Returns a telemetry mode specified in this intent.
199 *
200 * @return telemtry mode
201 */
202 public TelemetryMode telemetryMode() {
203 return telemetryMode;
204 }
205
206 /**
207 * An IntIntent builder.
208 */
209 public static final class Builder {
210 private TrafficSelector selector = DefaultTrafficSelector.emptySelector();
211 private Set<IntMetadataType> metadataTypes = new HashSet<>();
212 private IntHeaderType headerType = IntHeaderType.HOP_BY_HOP;
213 private Set<IntReportType> reportTypes = new HashSet<>();
214 private TelemetryMode telemetryMode = TelemetryMode.INBAND_TELEMETRY;
215
216 /**
217 * Assigns a selector to the IntIntent.
218 *
219 * @param selector a traffic selector
220 * @return an IntIntent builder
221 */
222 public IntIntent.Builder withSelector(TrafficSelector selector) {
223 this.selector = selector;
224 return this;
225 }
226
227 /**
228 * Add a metadata type to the IntIntent.
229 *
230 * @param metadataType a type of metadata to collect
231 * @return an IntIntent builder
232 */
233 public IntIntent.Builder withMetadataType(IntMetadataType metadataType) {
234 this.metadataTypes.add(metadataType);
235 return this;
236 }
237
238 /**
239 * Assigns a header type to the IntIntent.
240 *
241 * @param headerType a header type
242 * @return an IntIntent builder
243 */
244 public IntIntent.Builder withHeaderType(IntHeaderType headerType) {
245 this.headerType = headerType;
246 return this;
247 }
248
249 /**
250 * Add a report type to the IntIntent.
251 *
252 * @param reportType a type of report
253 * @return an IntIntent builder
254 */
255 public IntIntent.Builder withReportType(IntReportType reportType) {
256 this.reportTypes.add(reportType);
257 return this;
258 }
259
260 /**
261 * Assigns a telemetry mode to the IntIntent.
262 *
263 * @param telemetryMode a telemetry mode
264 * @return an IntIntent builder
265 */
266 public IntIntent.Builder withTelemetryMode(TelemetryMode telemetryMode) {
267 this.telemetryMode = telemetryMode;
268 return this;
269 }
270
271 /**
272 * Builds the IntIntent.
273 *
274 * @return an IntIntent
275 */
276 public IntIntent build() {
277 checkArgument(!selector.criteria().isEmpty(), "Empty selector cannot match any flow.");
278 checkArgument(!metadataTypes.isEmpty(), "Metadata types cannot be empty.");
279 checkNotNull(headerType, "Header type cannot be null.");
280 checkNotNull(!reportTypes.isEmpty(), "Report types cannot be empty.");
281 checkNotNull(telemetryMode, "Telemetry mode cannot be null.");
282
283 return new IntIntent(selector, metadataTypes, headerType, reportTypes, telemetryMode);
284 }
285 }
286}