blob: 92e5fa21b50bb76363a1f817187923cccce3fed4 [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 */
Carmelo Casconeb330fc72020-07-17 15:27:02 -070016package org.onosproject.net.behaviour.inbandtelemetry;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070017
18import com.google.common.annotations.Beta;
Yi Tsengd14f1a32020-10-13 19:15:12 -070019import com.google.common.base.Objects;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070020import org.onlab.packet.IpAddress;
21import org.onlab.packet.MacAddress;
Jonghwan Hyun722275f2018-05-14 15:44:56 -070022import org.onlab.packet.TpPort;
23
Yi Tsengda707962020-09-18 11:10:47 -070024import static com.google.common.base.Preconditions.checkArgument;
Jonghwan Hyun722275f2018-05-14 15:44:56 -070025import static com.google.common.base.Preconditions.checkNotNull;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070026
27/**
Carmelo Casconeb330fc72020-07-17 15:27:02 -070028 * Device-level configuration of the INT process.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070029 */
30@Beta
Carmelo Casconeb330fc72020-07-17 15:27:02 -070031public final class IntDeviceConfig {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070032 /**
33 * Represents a type of telemetry spec to collect in the dataplane.
34 */
Carmelo Casconefa421582018-09-13 10:05:57 -070035 public enum TelemetrySpec {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070036 /**
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 Tsengd14f1a32020-10-13 19:15:12 -070040 * INT sepcification</a>
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070041 */
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 Tsengd14f1a32020-10-13 19:15:12 -070047 * Data fields for In-situ OAM</a>
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070048 */
49 IOAM
50 }
51
52 private final IpAddress collectorIp;
Jonghwan Hyun722275f2018-05-14 15:44:56 -070053 private final TpPort collectorPort;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070054 private final MacAddress collectorNextHopMac;
55 private final IpAddress sinkIp;
56 private final MacAddress sinkMac;
57 private final TelemetrySpec spec;
58 private boolean enabled;
Yi Tsengda707962020-09-18 11:10:47 -070059 private int hopLatencySensitivity;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070060
Carmelo Casconeb330fc72020-07-17 15:27:02 -070061 private IntDeviceConfig(IpAddress collectorIp, TpPort collectorPort, MacAddress collectorNextHopMac,
Yi Tsengda707962020-09-18 11:10:47 -070062 IpAddress sinkIp, MacAddress sinkMac, TelemetrySpec spec, boolean enabled,
63 int hopLatencySensitivity) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070064 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 Tsengda707962020-09-18 11:10:47 -070071 this.hopLatencySensitivity = hopLatencySensitivity;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070072 }
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 Hyun722275f2018-05-14 15:44:56 -070092 public TpPort collectorPort() {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070093 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 Hyun722275f2018-05-14 15:44:56 -0700135 * Returns the type of telemetry spec as per {@link TelemetrySpec}.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700136 *
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 Tsengda707962020-09-18 11:10:47 -0700153 * 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 Hyun722275f2018-05-14 15:44:56 -0700162 * Returns a new builder.
163 *
164 * @return new builder
165 */
166 public static Builder builder() {
167 return new Builder();
168 }
169
Yi Tsengd14f1a32020-10-13 19:15:12 -0700170 @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 Hyun722275f2018-05-14 15:44:56 -0700195 /**
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700196 * An IntConfig object builder.
197 */
198 public static final class Builder {
Yi Tsengc4f90a52020-10-04 22:33:22 -0700199 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 Hyun71d42cd2018-03-13 13:23:01 -0700204 private TelemetrySpec spec = TelemetrySpec.INT;
205 private boolean enabled = false;
Yi Tsengda707962020-09-18 11:10:47 -0700206 int minFlowHopLatencyChangeNs = 0;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700207
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 Casconeb330fc72020-07-17 15:27:02 -0700214 public IntDeviceConfig.Builder withCollectorIp(IpAddress collectorIp) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700215 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 Casconeb330fc72020-07-17 15:27:02 -0700225 public IntDeviceConfig.Builder withCollectorPort(TpPort collectorPort) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700226 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 Casconeb330fc72020-07-17 15:27:02 -0700237 public IntDeviceConfig.Builder withCollectorNextHopMac(MacAddress collectorNextHopMac) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700238 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 Casconeb330fc72020-07-17 15:27:02 -0700248 public IntDeviceConfig.Builder withSinkIp(IpAddress sinkIp) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700249 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 Casconeb330fc72020-07-17 15:27:02 -0700259 public IntDeviceConfig.Builder withSinkMac(MacAddress sinkMac) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700260 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 Casconeb330fc72020-07-17 15:27:02 -0700270 public IntDeviceConfig.Builder withTelemetrySpec(TelemetrySpec spec) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700271 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 Casconeb330fc72020-07-17 15:27:02 -0700282 public IntDeviceConfig.Builder enabled(boolean enabled) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700283 this.enabled = enabled;
284 return this;
285 }
286
287 /**
Yi Tsengda707962020-09-18 11:10:47 -0700288 * 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 Hyun722275f2018-05-14 15:44:56 -0700299 * Builds the IntConfig object.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700300 *
301 * @return an IntConfig object
302 */
Carmelo Casconeb330fc72020-07-17 15:27:02 -0700303 public IntDeviceConfig build() {
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700304 checkNotNull(collectorIp, "Collector IP should be specified.");
305 checkNotNull(collectorPort, "Collector port number should be specified.");
Yi Tsengda707962020-09-18 11:10:47 -0700306 checkArgument(minFlowHopLatencyChangeNs >= 0, "Hop latency sensitivity must be positive or zero");
307
Carmelo Casconeb330fc72020-07-17 15:27:02 -0700308 return new IntDeviceConfig(collectorIp, collectorPort, collectorNextHopMac,
Yi Tsengd14f1a32020-10-13 19:15:12 -0700309 sinkIp, sinkMac, spec, enabled, minFlowHopLatencyChangeNs);
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700310 }
311 }
312}