blob: 95a8fe5143e1a3d8fb76dc5e7c8b182d19ff2598 [file] [log] [blame]
Yi Tseng0f1ffd12020-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
18import com.google.common.annotations.Beta;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.TpPort;
22import org.onosproject.core.ApplicationId;
23import org.onosproject.net.config.Config;
24import org.onosproject.ui.JsonUtils;
25
26/**
27 * Application level configuration of the INT process.
28 * Config example:
29 * {
30 * "apps": {
31 * "org.onosproject.inbandtelemetry": {
32 * "report": {
33 * "collectorIp": "192.168.0.1",
34 * "collectorPort": 5500,
35 * "minFlowHopLatencyChangeNs": 300
36 * }
37 * }
38 * }
39 * }
40 */
41@Beta
42public final class IntReportConfig extends Config<ApplicationId> {
43 private static final String COLLECTOR_IP = "collectorIp";
44 private static final String COLLECTOR_PORT = "collectorPort";
45 private static final String MIN_FLOW_HOP_LATENCY_CHANGE_NS = "minFlowHopLatencyChangeNs";
46 private static final String COLLECTOR_NEXT_HOP_MAC = "collectorNextHopMac";
47 private static final String SINK_IP = "sinkIp";
48 private static final String SINK_MAC = "sinkMac";
49
50 /**
51 * IP address of the collector.
52 * This is the destination IP address that will be used for all INT reports
53 * generated by all INT devices.
54 *
55 * @return collector IP address, null if not present
56 */
57 public IpAddress collectorIp() {
58 if (object.hasNonNull(COLLECTOR_IP)) {
59 return IpAddress.valueOf(JsonUtils.string(object, COLLECTOR_IP));
60 } else {
61 return null;
62 }
63 }
64
65 /**
66 * UDP port number of the collector.
67 * This is the destination UDP port number that will be used for all INT reports
68 * generated by all INT devices.
69 *
70 * @return collector UDP port number, null if not present
71 */
72 public TpPort collectorPort() {
73 if (object.hasNonNull(COLLECTOR_PORT)) {
74 return TpPort.tpPort((int) JsonUtils.number(object, COLLECTOR_PORT));
75 } else {
76 return null;
77 }
78 }
79
80 /**
81 * Gets the minimal interval of hop latency change for a flow.
82 * This value is used to instruct an INT-capable device to produce reports
83 * only for packets which hop latency changed by at least minFlowHopLatencyChangeNs
84 * from the previously reported value for the same flow (5-tuple), i.e., produce a
85 * report only if `(currentHopLatency - previousHopLatency) > minFlowHopLatencyChangeNs`.
86 * Some device implementations might support only specific intervals, e.g., powers of 2.
87 *
88 * @return Interval in nanoseconds
89 */
90 public int minFlowHopLatencyChangeNs() {
91 if (object.hasNonNull(MIN_FLOW_HOP_LATENCY_CHANGE_NS)) {
92 return (int) JsonUtils.number(object, MIN_FLOW_HOP_LATENCY_CHANGE_NS);
93 } else {
94 return 0;
95 }
96 }
97
98 /**
99 * Returns MAC address of next hop of INT report packets.
100 * This can be either MAC address of the collector or a router.
101 * This is an optional parameter, which means that the usage of this
102 * parameter depends on IntProgrammable implementation.
103 * (e.g., If a report packet needs to be routed to reach the collector,
104 * IntProgrammable will ignore this value and choose next hop router's MAC address.
105 * If a collector itself is the next hop of INT report packets, then
106 * this value will be used as a destination MAC address for all INT report packets.)
107 *
108 * @return MAC address of next hop of INT report packets, null if not present
109 */
110 public MacAddress collectorNextHopMac() {
111 if (object.hasNonNull(COLLECTOR_NEXT_HOP_MAC)) {
112 return MacAddress.valueOf(JsonUtils.string(object, COLLECTOR_NEXT_HOP_MAC));
113 } else {
114 return null;
115 }
116 }
117
118 /**
119 * Returns IP address of the sink device.
120 * All sink devices share this address as the source IP address
121 * for all INT reports.
122 *
123 * @return sink device's IP address, null if not present
124 */
125 public IpAddress sinkIp() {
126 if (object.hasNonNull(SINK_IP)) {
127 return IpAddress.valueOf(JsonUtils.string(object, SINK_IP));
128 } else {
129 return null;
130 }
131 }
132
133 /**
134 * Returns MAC address of the sink device.
135 * All sink devices share this address as the source MAC address
136 * for all INT reports.
137 *
138 * @return sink device's MAC address, null if not present
139 */
140 public MacAddress sinkMac() {
141 if (object.hasNonNull(SINK_MAC)) {
142 return MacAddress.valueOf(JsonUtils.string(object, SINK_MAC));
143 } else {
144 return null;
145 }
146 }
147
148 /**
149 * Sets the collector IP to the config.
150 *
151 * @param collectorIp the collector IP
152 * @return the config
153 */
154 public IntReportConfig setCollectorIp(IpAddress collectorIp) {
155 return (IntReportConfig) setOrClear(COLLECTOR_IP, collectorIp.toString());
156 }
157
158 /**
159 * Sets the collector port to the config.
160 *
161 * @param port the collector port
162 * @return the config
163 */
164 public IntReportConfig setCollectorPort(TpPort port) {
165 return (IntReportConfig) setOrClear(COLLECTOR_PORT, port.toInt());
166 }
167
168 /**
169 * Sets the minimal interval of hop latency change
170 * for a flow to the config.
171 *
172 * @param ns the value of hop latency change
173 * @return the config
174 */
175 public IntReportConfig setMinFlowHopLatencyChangeNs(int ns) {
176 return (IntReportConfig) setOrClear(MIN_FLOW_HOP_LATENCY_CHANGE_NS, ns);
177 }
178
179 /**
180 * Sets collector next hop mac address to the config.
181 *
182 * @param collectorNextHopMac the collector next hop mac address
183 * @return the config
184 */
185 public IntReportConfig setCollectorNextHopMac(MacAddress collectorNextHopMac) {
186 return (IntReportConfig) setOrClear(COLLECTOR_NEXT_HOP_MAC, collectorNextHopMac.toString());
187 }
188
189 /**
190 * Sets the sink IP address to the config.
191 *
192 * @param sinkIp the sink IP address
193 * @return the config
194 */
195 public IntReportConfig setSinkIp(IpAddress sinkIp) {
196 return (IntReportConfig) setOrClear(SINK_IP, sinkIp.toString());
197 }
198
199 /**
200 * Sets the sink mac address to the config.
201 *
202 * @param sinkMac the sink mac address
203 * @return the config
204 */
205 public IntReportConfig setSinkMac(MacAddress sinkMac) {
206 return (IntReportConfig) setOrClear(SINK_MAC, sinkMac.toString());
207 }
208}