blob: 158a992de08ce0a6c6287596c79010f47af587fb [file] [log] [blame]
Yi Tsengda707962020-09-18 11:10:47 -07001/*
2 * Copyright 2020-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.net.behaviour.inbandtelemetry;
17
Yi Tseng83a640a2021-03-29 01:58:15 -070018import com.fasterxml.jackson.databind.node.ArrayNode;
Yi Tsengda707962020-09-18 11:10:47 -070019import com.google.common.annotations.Beta;
Yi Tseng83a640a2021-03-29 01:58:15 -070020import com.google.common.collect.Sets;
Yi Tsengda707962020-09-18 11:10:47 -070021import org.onlab.packet.IpAddress;
Yi Tseng83a640a2021-03-29 01:58:15 -070022import org.onlab.packet.IpPrefix;
Yi Tsengda707962020-09-18 11:10:47 -070023import org.onlab.packet.MacAddress;
24import org.onlab.packet.TpPort;
25import org.onosproject.core.ApplicationId;
26import org.onosproject.net.config.Config;
27import org.onosproject.ui.JsonUtils;
28
Yi Tseng83a640a2021-03-29 01:58:15 -070029import java.util.Collections;
30import java.util.Set;
31
Yi Tsengda707962020-09-18 11:10:47 -070032/**
33 * Application level configuration of the INT process.
34 * Config example:
35 * {
36 * "apps": {
37 * "org.onosproject.inbandtelemetry": {
38 * "report": {
39 * "collectorIp": "192.168.0.1",
40 * "collectorPort": 5500,
Yi Tseng83a640a2021-03-29 01:58:15 -070041 * "minFlowHopLatencyChangeNs": 300,
42 * "watchSubnets": [
43 * "192.168.0.0/24",
44 * "10.140.0.0/16"
45 * ]
Yi Tsengda707962020-09-18 11:10:47 -070046 * }
47 * }
48 * }
49 * }
50 */
51@Beta
52public final class IntReportConfig extends Config<ApplicationId> {
53 private static final String COLLECTOR_IP = "collectorIp";
54 private static final String COLLECTOR_PORT = "collectorPort";
55 private static final String MIN_FLOW_HOP_LATENCY_CHANGE_NS = "minFlowHopLatencyChangeNs";
56 private static final String COLLECTOR_NEXT_HOP_MAC = "collectorNextHopMac";
57 private static final String SINK_IP = "sinkIp";
58 private static final String SINK_MAC = "sinkMac";
Yi Tseng83a640a2021-03-29 01:58:15 -070059 private static final String WATCH_SUBNETS = "watchSubnets";
Yi Tsengda707962020-09-18 11:10:47 -070060
61 /**
62 * IP address of the collector.
63 * This is the destination IP address that will be used for all INT reports
64 * generated by all INT devices.
65 *
66 * @return collector IP address, null if not present
67 */
68 public IpAddress collectorIp() {
69 if (object.hasNonNull(COLLECTOR_IP)) {
70 return IpAddress.valueOf(JsonUtils.string(object, COLLECTOR_IP));
71 } else {
72 return null;
73 }
74 }
75
76 /**
77 * UDP port number of the collector.
78 * This is the destination UDP port number that will be used for all INT reports
79 * generated by all INT devices.
80 *
81 * @return collector UDP port number, null if not present
82 */
83 public TpPort collectorPort() {
84 if (object.hasNonNull(COLLECTOR_PORT)) {
85 return TpPort.tpPort((int) JsonUtils.number(object, COLLECTOR_PORT));
86 } else {
87 return null;
88 }
89 }
90
91 /**
92 * Gets the minimal interval of hop latency change for a flow.
93 * This value is used to instruct an INT-capable device to produce reports
94 * only for packets which hop latency changed by at least minFlowHopLatencyChangeNs
95 * from the previously reported value for the same flow (5-tuple), i.e., produce a
Thomas Vachuska4f0252c2020-09-28 11:15:45 -070096 * report only if `(currentHopLatency - previousHopLatency) &gt; minFlowHopLatencyChangeNs`.
Yi Tsengda707962020-09-18 11:10:47 -070097 * Some device implementations might support only specific intervals, e.g., powers of 2.
98 *
99 * @return Interval in nanoseconds
100 */
101 public int minFlowHopLatencyChangeNs() {
102 if (object.hasNonNull(MIN_FLOW_HOP_LATENCY_CHANGE_NS)) {
103 return (int) JsonUtils.number(object, MIN_FLOW_HOP_LATENCY_CHANGE_NS);
104 } else {
105 return 0;
106 }
107 }
108
109 /**
110 * Returns MAC address of next hop of INT report packets.
111 * This can be either MAC address of the collector or a router.
112 * This is an optional parameter, which means that the usage of this
113 * parameter depends on IntProgrammable implementation.
114 * (e.g., If a report packet needs to be routed to reach the collector,
115 * IntProgrammable will ignore this value and choose next hop router's MAC address.
116 * If a collector itself is the next hop of INT report packets, then
117 * this value will be used as a destination MAC address for all INT report packets.)
118 *
119 * @return MAC address of next hop of INT report packets, null if not present
120 */
121 public MacAddress collectorNextHopMac() {
122 if (object.hasNonNull(COLLECTOR_NEXT_HOP_MAC)) {
123 return MacAddress.valueOf(JsonUtils.string(object, COLLECTOR_NEXT_HOP_MAC));
124 } else {
125 return null;
126 }
127 }
128
129 /**
130 * Returns IP address of the sink device.
131 * All sink devices share this address as the source IP address
132 * for all INT reports.
133 *
134 * @return sink device's IP address, null if not present
135 */
136 public IpAddress sinkIp() {
137 if (object.hasNonNull(SINK_IP)) {
138 return IpAddress.valueOf(JsonUtils.string(object, SINK_IP));
139 } else {
140 return null;
141 }
142 }
143
144 /**
145 * Returns MAC address of the sink device.
146 * All sink devices share this address as the source MAC address
147 * for all INT reports.
148 *
149 * @return sink device's MAC address, null if not present
150 */
151 public MacAddress sinkMac() {
152 if (object.hasNonNull(SINK_MAC)) {
153 return MacAddress.valueOf(JsonUtils.string(object, SINK_MAC));
154 } else {
155 return null;
156 }
157 }
158
159 /**
Yi Tseng83a640a2021-03-29 01:58:15 -0700160 * Gets subnets to be watched.
161 *
162 * @return subnets to be watched
163 */
164 public Set<IpPrefix> watchSubnets() {
165 if (object.hasNonNull(WATCH_SUBNETS) && object.path(WATCH_SUBNETS).isArray()) {
166 Set<IpPrefix> subnets = Sets.newHashSet();
167 ArrayNode subnetArray = (ArrayNode) object.path(WATCH_SUBNETS);
168 subnetArray.forEach(subnetNode -> {
169 subnets.add(IpPrefix.valueOf(subnetNode.asText()));
170 });
171 return subnets;
172 } else {
173 return Collections.EMPTY_SET;
174 }
175 }
176
177 /**
Yi Tsengda707962020-09-18 11:10:47 -0700178 * Sets the collector IP to the config.
179 *
180 * @param collectorIp the collector IP
181 * @return the config
182 */
183 public IntReportConfig setCollectorIp(IpAddress collectorIp) {
184 return (IntReportConfig) setOrClear(COLLECTOR_IP, collectorIp.toString());
185 }
186
187 /**
188 * Sets the collector port to the config.
189 *
190 * @param port the collector port
191 * @return the config
192 */
193 public IntReportConfig setCollectorPort(TpPort port) {
194 return (IntReportConfig) setOrClear(COLLECTOR_PORT, port.toInt());
195 }
196
197 /**
198 * Sets the minimal interval of hop latency change
199 * for a flow to the config.
200 *
201 * @param ns the value of hop latency change
202 * @return the config
203 */
204 public IntReportConfig setMinFlowHopLatencyChangeNs(int ns) {
205 return (IntReportConfig) setOrClear(MIN_FLOW_HOP_LATENCY_CHANGE_NS, ns);
206 }
207
208 /**
209 * Sets collector next hop mac address to the config.
210 *
211 * @param collectorNextHopMac the collector next hop mac address
212 * @return the config
213 */
214 public IntReportConfig setCollectorNextHopMac(MacAddress collectorNextHopMac) {
215 return (IntReportConfig) setOrClear(COLLECTOR_NEXT_HOP_MAC, collectorNextHopMac.toString());
216 }
217
218 /**
219 * Sets the sink IP address to the config.
220 *
221 * @param sinkIp the sink IP address
222 * @return the config
223 */
224 public IntReportConfig setSinkIp(IpAddress sinkIp) {
225 return (IntReportConfig) setOrClear(SINK_IP, sinkIp.toString());
226 }
227
228 /**
229 * Sets the sink mac address to the config.
230 *
231 * @param sinkMac the sink mac address
232 * @return the config
233 */
234 public IntReportConfig setSinkMac(MacAddress sinkMac) {
235 return (IntReportConfig) setOrClear(SINK_MAC, sinkMac.toString());
236 }
Yi Tseng83a640a2021-03-29 01:58:15 -0700237
238 /**
239 * Sets subnets to be watched.
240 *
241 * @param subnets subnets to be watched.
242 * @return the config
243 */
244 public IntReportConfig setWatchSubnets(Set<IpPrefix> subnets) {
245 return (IntReportConfig) setOrClear(WATCH_SUBNETS, subnets);
246 }
Yi Tsengda707962020-09-18 11:10:47 -0700247}