Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.inbandtelemetry.api; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 20 | import org.onosproject.net.flow.TrafficSelector; |
| 21 | |
| 22 | import java.util.HashSet; |
| 23 | import java.util.Set; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkArgument; |
| 26 | import 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 |
| 42 | public 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 | /** |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame^] | 207 | * Returns a new builder. |
| 208 | * |
| 209 | * @return new builder |
| 210 | */ |
| 211 | public static Builder builder() { |
| 212 | return new Builder(); |
| 213 | } |
| 214 | |
| 215 | /** |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 216 | * An IntIntent builder. |
| 217 | */ |
| 218 | public static final class Builder { |
| 219 | private TrafficSelector selector = DefaultTrafficSelector.emptySelector(); |
| 220 | private Set<IntMetadataType> metadataTypes = new HashSet<>(); |
| 221 | private IntHeaderType headerType = IntHeaderType.HOP_BY_HOP; |
| 222 | private Set<IntReportType> reportTypes = new HashSet<>(); |
| 223 | private TelemetryMode telemetryMode = TelemetryMode.INBAND_TELEMETRY; |
| 224 | |
| 225 | /** |
| 226 | * Assigns a selector to the IntIntent. |
| 227 | * |
| 228 | * @param selector a traffic selector |
| 229 | * @return an IntIntent builder |
| 230 | */ |
| 231 | public IntIntent.Builder withSelector(TrafficSelector selector) { |
| 232 | this.selector = selector; |
| 233 | return this; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Add a metadata type to the IntIntent. |
| 238 | * |
| 239 | * @param metadataType a type of metadata to collect |
| 240 | * @return an IntIntent builder |
| 241 | */ |
| 242 | public IntIntent.Builder withMetadataType(IntMetadataType metadataType) { |
| 243 | this.metadataTypes.add(metadataType); |
| 244 | return this; |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Assigns a header type to the IntIntent. |
| 249 | * |
| 250 | * @param headerType a header type |
| 251 | * @return an IntIntent builder |
| 252 | */ |
| 253 | public IntIntent.Builder withHeaderType(IntHeaderType headerType) { |
| 254 | this.headerType = headerType; |
| 255 | return this; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Add a report type to the IntIntent. |
| 260 | * |
| 261 | * @param reportType a type of report |
| 262 | * @return an IntIntent builder |
| 263 | */ |
| 264 | public IntIntent.Builder withReportType(IntReportType reportType) { |
| 265 | this.reportTypes.add(reportType); |
| 266 | return this; |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Assigns a telemetry mode to the IntIntent. |
| 271 | * |
| 272 | * @param telemetryMode a telemetry mode |
| 273 | * @return an IntIntent builder |
| 274 | */ |
| 275 | public IntIntent.Builder withTelemetryMode(TelemetryMode telemetryMode) { |
| 276 | this.telemetryMode = telemetryMode; |
| 277 | return this; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Builds the IntIntent. |
| 282 | * |
| 283 | * @return an IntIntent |
| 284 | */ |
| 285 | public IntIntent build() { |
| 286 | checkArgument(!selector.criteria().isEmpty(), "Empty selector cannot match any flow."); |
| 287 | checkArgument(!metadataTypes.isEmpty(), "Metadata types cannot be empty."); |
| 288 | checkNotNull(headerType, "Header type cannot be null."); |
| 289 | checkNotNull(!reportTypes.isEmpty(), "Report types cannot be empty."); |
| 290 | checkNotNull(telemetryMode, "Telemetry mode cannot be null."); |
| 291 | |
| 292 | return new IntIntent(selector, metadataTypes, headerType, reportTypes, telemetryMode); |
| 293 | } |
| 294 | } |
| 295 | } |