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