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