blob: a3e614808fd12789fcf12ff7e6f03d445b27c388 [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 */
16package org.onosproject.inbandtelemetry.api;
17
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
23import static com.google.common.base.Preconditions.checkNotNull;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070024
25/**
26 * Network-level INT configuration.
27 */
28@Beta
29public final class IntConfig {
30 /**
31 * Represents a type of telemetry spec to collect in the dataplane.
32 */
33 enum TelemetrySpec {
34 /**
35 * Embeds telemetry metadata according to the INT specification.
36 *
37 * @see <a href="https://github.com/p4lang/p4-applications/blob/master/docs/INT.pdf">
38 * INT sepcification</a>
39 */
40 INT,
41 /**
42 * Embeds telemetry metadata according to the OAM specification.
43 *
44 * @see <a href="https://tools.ietf.org/html/draft-ietf-ippm-ioam-data">
45 * Data fields for In-situ OAM</a>
46 */
47 IOAM
48 }
49
50 private final IpAddress collectorIp;
Jonghwan Hyun722275f2018-05-14 15:44:56 -070051 private final TpPort collectorPort;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070052 private final MacAddress collectorNextHopMac;
53 private final IpAddress sinkIp;
54 private final MacAddress sinkMac;
55 private final TelemetrySpec spec;
56 private boolean enabled;
57
Jonghwan Hyun722275f2018-05-14 15:44:56 -070058 private IntConfig(IpAddress collectorIp, TpPort collectorPort, MacAddress collectorNextHopMac,
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070059 IpAddress sinkIp, MacAddress sinkMac, TelemetrySpec spec, boolean enabled) {
60 this.collectorIp = collectorIp;
61 this.collectorPort = collectorPort;
62 this.collectorNextHopMac = collectorNextHopMac;
63 this.sinkIp = sinkIp;
64 this.sinkMac = sinkMac;
65 this.spec = spec;
66 this.enabled = enabled;
67 }
68
69 /**
70 * Returns IP address of the collector.
71 * This is the destination IP address that will be used for all INT reports
72 * generated by all sink devices.
73 *
74 * @return collector IP address
75 */
76 public IpAddress collectorIp() {
77 return collectorIp;
78 }
79
80 /**
81 * Returns UDP port number of the collector.
82 * This is the destination UDP port number that will be used for all INT reports
83 * generated by all sink devices.
84 *
85 * @return collector UDP port number
86 */
Jonghwan Hyun722275f2018-05-14 15:44:56 -070087 public TpPort collectorPort() {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -070088 return collectorPort;
89 }
90
91 /**
92 * Returns MAC address of next hop of INT report packets.
93 * This can be either MAC address of the collector or a router.
94 * This is an optional parameter, which means that the usage of this
95 * parameter depends on IntProgrammable implementation.
96 * (e.g., If a report packet needs to be routed to reach the collector,
97 * IntProgrammable will ignore this value and choose next hop router's MAC address.
98 * If a collector itself is the next hop of INT report packets, then
99 * this value will be used as a destination MAC address for all INT report packets.)
100 *
101 * @return MAC address of next hop of INT report packets
102 */
103 public MacAddress collectorNextHopMac() {
104 return collectorNextHopMac;
105 }
106
107 /**
108 * Returns IP address of the sink device.
109 * All sink devices share this address as the source IP address
110 * for all INT reports.
111 *
112 * @return sink device's IP address
113 */
114 public IpAddress sinkIp() {
115 return sinkIp;
116 }
117
118 /**
119 * Returns MAC address of the sink device.
120 * All sink devices share this address as the source MAC address
121 * for all INT reports.
122 *
123 * @return sink device's MAC address
124 */
125 public MacAddress sinkMac() {
126 return sinkMac;
127 }
128
129 /**
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700130 * Returns the type of telemetry spec as per {@link TelemetrySpec}.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700131 *
132 * @return telemetry spec
133 */
134 public TelemetrySpec spec() {
135 return spec;
136 }
137
138 /**
139 * Returns the status of INT functionality.
140 *
141 * @return true if INT is enabled; false otherwise.
142 */
143 public boolean enabled() {
144 return enabled;
145 }
146
147 /**
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700148 * Returns a new builder.
149 *
150 * @return new builder
151 */
152 public static Builder builder() {
153 return new Builder();
154 }
155
156 /**
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700157 * An IntConfig object builder.
158 */
159 public static final class Builder {
160
161 private IpAddress collectorIp;
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700162 private TpPort collectorPort;
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700163 private MacAddress collectorNextHopMac;
164 private IpAddress sinkIp;
165 private MacAddress sinkMac;
166 private TelemetrySpec spec = TelemetrySpec.INT;
167 private boolean enabled = false;
168
169 /**
170 * Assigns a collector IP address to the IntConfig object.
171 *
172 * @param collectorIp IP address of the collector
173 * @return an IntConfig builder
174 */
175 public IntConfig.Builder withCollectorIp(IpAddress collectorIp) {
176 this.collectorIp = collectorIp;
177 return this;
178 }
179
180 /**
181 * Assigns a collector UDP port to the IntConfig object.
182 *
183 * @param collectorPort UDP port number of the collector
184 * @return an IntConfig builder
185 */
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700186 public IntConfig.Builder withCollectorPort(TpPort collectorPort) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700187 this.collectorPort = collectorPort;
188 return this;
189 }
190
191 /**
192 * Assigns a MAC address of the next hop to the collector
193 * to the IntConfig object.
194 *
195 * @param collectorNextHopMac MAC address of the collector
196 * @return an IntConfig builder
197 */
198 public IntConfig.Builder withCollectorNextHopMac(MacAddress collectorNextHopMac) {
199 this.collectorNextHopMac = collectorNextHopMac;
200 return this;
201 }
202
203 /**
204 * Assigns an IP address of the sink device to the IntConfig object.
205 *
206 * @param sinkIp sink device's IP address
207 * @return an IntConfig builder
208 */
209 public IntConfig.Builder withSinkIp(IpAddress sinkIp) {
210 this.sinkIp = sinkIp;
211 return this;
212 }
213
214 /**
215 * Assigns a MAC address of the sink device to the IntConfig object.
216 *
217 * @param sinkMac sink device's MAC address
218 * @return an IntConfig builder
219 */
220 public IntConfig.Builder withSinkMac(MacAddress sinkMac) {
221 this.sinkMac = sinkMac;
222 return this;
223 }
224
225 /**
226 * Assigns the type of telemetry spec to the IntConfig object.
227 *
228 * @param spec telemetry spec
229 * @return an IntConfig builder
230 */
231 public IntConfig.Builder withTelemetrySpec(TelemetrySpec spec) {
232 this.spec = spec;
233 return this;
234 }
235
236 /**
237 * Assigns the status of INT.
238 * True to enable INT functionality, false otherwise.
239 *
240 * @param enabled the status of INT
241 * @return an IntConfig builder
242 */
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700243 public IntConfig.Builder enabled(boolean enabled) {
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700244 this.enabled = enabled;
245 return this;
246 }
247
248 /**
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700249 * Builds the IntConfig object.
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700250 *
251 * @return an IntConfig object
252 */
253 public IntConfig build() {
Jonghwan Hyun722275f2018-05-14 15:44:56 -0700254 checkNotNull(collectorIp, "Collector IP should be specified.");
255 checkNotNull(collectorPort, "Collector port number should be specified.");
256 checkNotNull(collectorNextHopMac, "Next hop MAC address for report packets should be provided.");
257 checkNotNull(sinkIp, "Sink IP address for report packets should be specified.");
258 checkNotNull(sinkMac, "Sink MAC address for report packets should be specified.");
Jonghwan Hyun71d42cd2018-03-13 13:23:01 -0700259 return new IntConfig(collectorIp, collectorPort, collectorNextHopMac,
260 sinkIp, sinkMac, spec, enabled);
261 }
262 }
263}