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