blob: a21a2aeef41a6a8193272c3842c43aa6cc04a094 [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 Casconedefc74e2020-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;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
Jonghwan Hyun722275f2018-05-14 15:44:56 -070021import org.onlab.packet.TpPort;
22
Yi Tseng0f1ffd12020-09-18 11:10:47 -070023import static com.google.common.base.Preconditions.checkArgument;
Jonghwan Hyun722275f2018-05-14 15:44:56 -070024import static com.google.common.base.Preconditions.checkNotNull;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070025
26/**
Carmelo Casconedefc74e2020-07-17 15:27:02 -070027 * Device-level configuration of the INT process.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070028 */
29@Beta
Carmelo Casconedefc74e2020-07-17 15:27:02 -070030public final class IntDeviceConfig {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070031 /**
32 * Represents a type of telemetry spec to collect in the dataplane.
33 */
Carmelo Casconefa421582018-09-13 10:05:57 -070034 public enum TelemetrySpec {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070035 /**
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 Hyun722275f2018-05-14 15:44:56 -070052 private final TpPort collectorPort;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070053 private final MacAddress collectorNextHopMac;
54 private final IpAddress sinkIp;
55 private final MacAddress sinkMac;
56 private final TelemetrySpec spec;
57 private boolean enabled;
Yi Tseng0f1ffd12020-09-18 11:10:47 -070058 private int hopLatencySensitivity;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070059
Carmelo Casconedefc74e2020-07-17 15:27:02 -070060 private IntDeviceConfig(IpAddress collectorIp, TpPort collectorPort, MacAddress collectorNextHopMac,
Yi Tseng0f1ffd12020-09-18 11:10:47 -070061 IpAddress sinkIp, MacAddress sinkMac, TelemetrySpec spec, boolean enabled,
62 int hopLatencySensitivity) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070063 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 Tseng0f1ffd12020-09-18 11:10:47 -070070 this.hopLatencySensitivity = hopLatencySensitivity;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070071 }
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 Hyun722275f2018-05-14 15:44:56 -070091 public TpPort collectorPort() {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070092 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 Hyun722275f2018-05-14 15:44:56 -0700134 * Returns the type of telemetry spec as per {@link TelemetrySpec}.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700135 *
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 Tseng0f1ffd12020-09-18 11:10:47 -0700152 * 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 Hyun722275f2018-05-14 15:44:56 -0700161 * Returns a new builder.
162 *
163 * @return new builder
164 */
165 public static Builder builder() {
166 return new Builder();
167 }
168
169 /**
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700170 * An IntConfig object builder.
171 */
172 public static final class Builder {
Yi Tseng930b0cd2020-10-04 22:33:22 -0700173 private IpAddress collectorIp = IpAddress.valueOf(0);
174 private TpPort collectorPort = TpPort.tpPort(0);
175 private MacAddress collectorNextHopMac = MacAddress.valueOf(0);
176 private IpAddress sinkIp = IpAddress.valueOf(0);
177 private MacAddress sinkMac = MacAddress.valueOf(0);
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700178 private TelemetrySpec spec = TelemetrySpec.INT;
179 private boolean enabled = false;
Yi Tseng0f1ffd12020-09-18 11:10:47 -0700180 int minFlowHopLatencyChangeNs = 0;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700181
182 /**
183 * Assigns a collector IP address to the IntConfig object.
184 *
185 * @param collectorIp IP address of the collector
186 * @return an IntConfig builder
187 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700188 public IntDeviceConfig.Builder withCollectorIp(IpAddress collectorIp) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700189 this.collectorIp = collectorIp;
190 return this;
191 }
192
193 /**
194 * Assigns a collector UDP port to the IntConfig object.
195 *
196 * @param collectorPort UDP port number of the collector
197 * @return an IntConfig builder
198 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700199 public IntDeviceConfig.Builder withCollectorPort(TpPort collectorPort) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700200 this.collectorPort = collectorPort;
201 return this;
202 }
203
204 /**
205 * Assigns a MAC address of the next hop to the collector
206 * to the IntConfig object.
207 *
208 * @param collectorNextHopMac MAC address of the collector
209 * @return an IntConfig builder
210 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700211 public IntDeviceConfig.Builder withCollectorNextHopMac(MacAddress collectorNextHopMac) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700212 this.collectorNextHopMac = collectorNextHopMac;
213 return this;
214 }
215
216 /**
217 * Assigns an IP address of the sink device to the IntConfig object.
218 *
219 * @param sinkIp sink device's IP address
220 * @return an IntConfig builder
221 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700222 public IntDeviceConfig.Builder withSinkIp(IpAddress sinkIp) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700223 this.sinkIp = sinkIp;
224 return this;
225 }
226
227 /**
228 * Assigns a MAC address of the sink device to the IntConfig object.
229 *
230 * @param sinkMac sink device's MAC address
231 * @return an IntConfig builder
232 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700233 public IntDeviceConfig.Builder withSinkMac(MacAddress sinkMac) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700234 this.sinkMac = sinkMac;
235 return this;
236 }
237
238 /**
239 * Assigns the type of telemetry spec to the IntConfig object.
240 *
241 * @param spec telemetry spec
242 * @return an IntConfig builder
243 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700244 public IntDeviceConfig.Builder withTelemetrySpec(TelemetrySpec spec) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700245 this.spec = spec;
246 return this;
247 }
248
249 /**
250 * Assigns the status of INT.
251 * True to enable INT functionality, false otherwise.
252 *
253 * @param enabled the status of INT
254 * @return an IntConfig builder
255 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700256 public IntDeviceConfig.Builder enabled(boolean enabled) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700257 this.enabled = enabled;
258 return this;
259 }
260
261 /**
Yi Tseng0f1ffd12020-09-18 11:10:47 -0700262 * Sets the minimal interval of hop latency change for a flow.
263 *
264 * @param value the minimal interval of hop latency change for a flow
265 * @return an IntConfig builder
266 */
267 public IntDeviceConfig.Builder withMinFlowHopLatencyChangeNs(int value) {
268 this.minFlowHopLatencyChangeNs = value;
269 return this;
270 }
271
272 /**
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700273 * Builds the IntConfig object.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700274 *
275 * @return an IntConfig object
276 */
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700277 public IntDeviceConfig build() {
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700278 checkNotNull(collectorIp, "Collector IP should be specified.");
279 checkNotNull(collectorPort, "Collector port number should be specified.");
Yi Tseng0f1ffd12020-09-18 11:10:47 -0700280 checkArgument(minFlowHopLatencyChangeNs >= 0, "Hop latency sensitivity must be positive or zero");
281
Carmelo Casconedefc74e2020-07-17 15:27:02 -0700282 return new IntDeviceConfig(collectorIp, collectorPort, collectorNextHopMac,
Yi Tseng0f1ffd12020-09-18 11:10:47 -0700283 sinkIp, sinkMac, spec, enabled, minFlowHopLatencyChangeNs);
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700284 }
285 }
286}