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 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 16 | package org.onosproject.net.behaviour.inbandtelemetry; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.annotations.Beta; |
Yi Tseng | d14f1a3 | 2020-10-13 19:15:12 -0700 | [diff] [blame] | 19 | import com.google.common.base.Objects; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.MacAddress; |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 22 | import org.onlab.packet.TpPort; |
| 23 | |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkArgument; |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 28 | * Device-level configuration of the INT process. |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 29 | */ |
| 30 | @Beta |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 31 | public final class IntDeviceConfig { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Represents a type of telemetry spec to collect in the dataplane. |
| 34 | */ |
Carmelo Cascone | fa42158 | 2018-09-13 10:05:57 -0700 | [diff] [blame] | 35 | public enum TelemetrySpec { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Embeds telemetry metadata according to the INT specification. |
| 38 | * |
| 39 | * @see <a href="https://github.com/p4lang/p4-applications/blob/master/docs/INT.pdf"> |
Yi Tseng | d14f1a3 | 2020-10-13 19:15:12 -0700 | [diff] [blame] | 40 | * INT sepcification</a> |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 41 | */ |
| 42 | INT, |
| 43 | /** |
| 44 | * Embeds telemetry metadata according to the OAM specification. |
| 45 | * |
| 46 | * @see <a href="https://tools.ietf.org/html/draft-ietf-ippm-ioam-data"> |
Yi Tseng | d14f1a3 | 2020-10-13 19:15:12 -0700 | [diff] [blame] | 47 | * Data fields for In-situ OAM</a> |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 48 | */ |
| 49 | IOAM |
| 50 | } |
| 51 | |
| 52 | private final IpAddress collectorIp; |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 53 | private final TpPort collectorPort; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 54 | private final MacAddress collectorNextHopMac; |
| 55 | private final IpAddress sinkIp; |
| 56 | private final MacAddress sinkMac; |
| 57 | private final TelemetrySpec spec; |
| 58 | private boolean enabled; |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 59 | private int hopLatencySensitivity; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 60 | |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 61 | private IntDeviceConfig(IpAddress collectorIp, TpPort collectorPort, MacAddress collectorNextHopMac, |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 62 | IpAddress sinkIp, MacAddress sinkMac, TelemetrySpec spec, boolean enabled, |
| 63 | int hopLatencySensitivity) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 64 | this.collectorIp = collectorIp; |
| 65 | this.collectorPort = collectorPort; |
| 66 | this.collectorNextHopMac = collectorNextHopMac; |
| 67 | this.sinkIp = sinkIp; |
| 68 | this.sinkMac = sinkMac; |
| 69 | this.spec = spec; |
| 70 | this.enabled = enabled; |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 71 | this.hopLatencySensitivity = hopLatencySensitivity; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns IP address of the collector. |
| 76 | * This is the destination IP address that will be used for all INT reports |
| 77 | * generated by all sink devices. |
| 78 | * |
| 79 | * @return collector IP address |
| 80 | */ |
| 81 | public IpAddress collectorIp() { |
| 82 | return collectorIp; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns UDP port number of the collector. |
| 87 | * This is the destination UDP port number that will be used for all INT reports |
| 88 | * generated by all sink devices. |
| 89 | * |
| 90 | * @return collector UDP port number |
| 91 | */ |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 92 | public TpPort collectorPort() { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 93 | return collectorPort; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Returns MAC address of next hop of INT report packets. |
| 98 | * This can be either MAC address of the collector or a router. |
| 99 | * This is an optional parameter, which means that the usage of this |
| 100 | * parameter depends on IntProgrammable implementation. |
| 101 | * (e.g., If a report packet needs to be routed to reach the collector, |
| 102 | * IntProgrammable will ignore this value and choose next hop router's MAC address. |
| 103 | * If a collector itself is the next hop of INT report packets, then |
| 104 | * this value will be used as a destination MAC address for all INT report packets.) |
| 105 | * |
| 106 | * @return MAC address of next hop of INT report packets |
| 107 | */ |
| 108 | public MacAddress collectorNextHopMac() { |
| 109 | return collectorNextHopMac; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns IP address of the sink device. |
| 114 | * All sink devices share this address as the source IP address |
| 115 | * for all INT reports. |
| 116 | * |
| 117 | * @return sink device's IP address |
| 118 | */ |
| 119 | public IpAddress sinkIp() { |
| 120 | return sinkIp; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Returns MAC address of the sink device. |
| 125 | * All sink devices share this address as the source MAC address |
| 126 | * for all INT reports. |
| 127 | * |
| 128 | * @return sink device's MAC address |
| 129 | */ |
| 130 | public MacAddress sinkMac() { |
| 131 | return sinkMac; |
| 132 | } |
| 133 | |
| 134 | /** |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 135 | * Returns the type of telemetry spec as per {@link TelemetrySpec}. |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 136 | * |
| 137 | * @return telemetry spec |
| 138 | */ |
| 139 | public TelemetrySpec spec() { |
| 140 | return spec; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Returns the status of INT functionality. |
| 145 | * |
| 146 | * @return true if INT is enabled; false otherwise. |
| 147 | */ |
| 148 | public boolean enabled() { |
| 149 | return enabled; |
| 150 | } |
| 151 | |
| 152 | /** |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 153 | * Returns the minimal interval of hop latency change for a flow. |
| 154 | * |
| 155 | * @return the minimal interval of hop latency change for a flow. |
| 156 | */ |
| 157 | public int minFlowHopLatencyChangeNs() { |
| 158 | return hopLatencySensitivity; |
| 159 | } |
| 160 | |
| 161 | /** |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 162 | * Returns a new builder. |
| 163 | * |
| 164 | * @return new builder |
| 165 | */ |
| 166 | public static Builder builder() { |
| 167 | return new Builder(); |
| 168 | } |
| 169 | |
Yi Tseng | d14f1a3 | 2020-10-13 19:15:12 -0700 | [diff] [blame] | 170 | @Override |
| 171 | public boolean equals(Object o) { |
| 172 | if (this == o) { |
| 173 | return true; |
| 174 | } |
| 175 | if (o == null || getClass() != o.getClass()) { |
| 176 | return false; |
| 177 | } |
| 178 | IntDeviceConfig that = (IntDeviceConfig) o; |
| 179 | return enabled == that.enabled && |
| 180 | hopLatencySensitivity == that.hopLatencySensitivity && |
| 181 | Objects.equal(collectorIp, that.collectorIp) && |
| 182 | Objects.equal(collectorPort, that.collectorPort) && |
| 183 | Objects.equal(collectorNextHopMac, that.collectorNextHopMac) && |
| 184 | Objects.equal(sinkIp, that.sinkIp) && |
| 185 | Objects.equal(sinkMac, that.sinkMac) && |
| 186 | spec == that.spec; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public int hashCode() { |
| 191 | return Objects.hashCode(collectorIp, collectorPort, collectorNextHopMac, |
| 192 | sinkIp, sinkMac, spec, enabled, hopLatencySensitivity); |
| 193 | } |
| 194 | |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 195 | /** |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 196 | * An IntConfig object builder. |
| 197 | */ |
| 198 | public static final class Builder { |
Yi Tseng | c4f90a5 | 2020-10-04 22:33:22 -0700 | [diff] [blame] | 199 | private IpAddress collectorIp = IpAddress.valueOf(0); |
| 200 | private TpPort collectorPort = TpPort.tpPort(0); |
| 201 | private MacAddress collectorNextHopMac = MacAddress.valueOf(0); |
| 202 | private IpAddress sinkIp = IpAddress.valueOf(0); |
| 203 | private MacAddress sinkMac = MacAddress.valueOf(0); |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 204 | private TelemetrySpec spec = TelemetrySpec.INT; |
| 205 | private boolean enabled = false; |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 206 | int minFlowHopLatencyChangeNs = 0; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * Assigns a collector IP address to the IntConfig object. |
| 210 | * |
| 211 | * @param collectorIp IP address of the collector |
| 212 | * @return an IntConfig builder |
| 213 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 214 | public IntDeviceConfig.Builder withCollectorIp(IpAddress collectorIp) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 215 | this.collectorIp = collectorIp; |
| 216 | return this; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Assigns a collector UDP port to the IntConfig object. |
| 221 | * |
| 222 | * @param collectorPort UDP port number of the collector |
| 223 | * @return an IntConfig builder |
| 224 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 225 | public IntDeviceConfig.Builder withCollectorPort(TpPort collectorPort) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 226 | this.collectorPort = collectorPort; |
| 227 | return this; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Assigns a MAC address of the next hop to the collector |
| 232 | * to the IntConfig object. |
| 233 | * |
| 234 | * @param collectorNextHopMac MAC address of the collector |
| 235 | * @return an IntConfig builder |
| 236 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 237 | public IntDeviceConfig.Builder withCollectorNextHopMac(MacAddress collectorNextHopMac) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 238 | this.collectorNextHopMac = collectorNextHopMac; |
| 239 | return this; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Assigns an IP address of the sink device to the IntConfig object. |
| 244 | * |
| 245 | * @param sinkIp sink device's IP address |
| 246 | * @return an IntConfig builder |
| 247 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 248 | public IntDeviceConfig.Builder withSinkIp(IpAddress sinkIp) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 249 | this.sinkIp = sinkIp; |
| 250 | return this; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Assigns a MAC address of the sink device to the IntConfig object. |
| 255 | * |
| 256 | * @param sinkMac sink device's MAC address |
| 257 | * @return an IntConfig builder |
| 258 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 259 | public IntDeviceConfig.Builder withSinkMac(MacAddress sinkMac) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 260 | this.sinkMac = sinkMac; |
| 261 | return this; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Assigns the type of telemetry spec to the IntConfig object. |
| 266 | * |
| 267 | * @param spec telemetry spec |
| 268 | * @return an IntConfig builder |
| 269 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 270 | public IntDeviceConfig.Builder withTelemetrySpec(TelemetrySpec spec) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 271 | this.spec = spec; |
| 272 | return this; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Assigns the status of INT. |
| 277 | * True to enable INT functionality, false otherwise. |
| 278 | * |
| 279 | * @param enabled the status of INT |
| 280 | * @return an IntConfig builder |
| 281 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 282 | public IntDeviceConfig.Builder enabled(boolean enabled) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 283 | this.enabled = enabled; |
| 284 | return this; |
| 285 | } |
| 286 | |
| 287 | /** |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 288 | * Sets the minimal interval of hop latency change for a flow. |
| 289 | * |
| 290 | * @param value the minimal interval of hop latency change for a flow |
| 291 | * @return an IntConfig builder |
| 292 | */ |
| 293 | public IntDeviceConfig.Builder withMinFlowHopLatencyChangeNs(int value) { |
| 294 | this.minFlowHopLatencyChangeNs = value; |
| 295 | return this; |
| 296 | } |
| 297 | |
| 298 | /** |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 299 | * Builds the IntConfig object. |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 300 | * |
| 301 | * @return an IntConfig object |
| 302 | */ |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 303 | public IntDeviceConfig build() { |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 304 | checkNotNull(collectorIp, "Collector IP should be specified."); |
| 305 | checkNotNull(collectorPort, "Collector port number should be specified."); |
Yi Tseng | da70796 | 2020-09-18 11:10:47 -0700 | [diff] [blame] | 306 | checkArgument(minFlowHopLatencyChangeNs >= 0, "Hop latency sensitivity must be positive or zero"); |
| 307 | |
Carmelo Cascone | b330fc7 | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 308 | return new IntDeviceConfig(collectorIp, collectorPort, collectorNextHopMac, |
Yi Tseng | d14f1a3 | 2020-10-13 19:15:12 -0700 | [diff] [blame] | 309 | sinkIp, sinkMac, spec, enabled, minFlowHopLatencyChangeNs); |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |