Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 1 | /* |
| 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 Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 16 | package org.onosproject.net.behaviour.inbandtelemetry; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 21 | import org.onlab.packet.TpPort; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 26 | * Device-level configuration of the INT process. |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 27 | */ |
| 28 | @Beta |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 29 | public final class IntDeviceConfig { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Represents a type of telemetry spec to collect in the dataplane. |
| 32 | */ |
Carmelo Cascone | fa42158 | 2018-09-13 10:05:57 -0700 | [diff] [blame] | 33 | public enum TelemetrySpec { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 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 Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 51 | private final TpPort collectorPort; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 52 | private final MacAddress collectorNextHopMac; |
| 53 | private final IpAddress sinkIp; |
| 54 | private final MacAddress sinkMac; |
| 55 | private final TelemetrySpec spec; |
| 56 | private boolean enabled; |
| 57 | |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 58 | private IntDeviceConfig(IpAddress collectorIp, TpPort collectorPort, MacAddress collectorNextHopMac, |
| 59 | IpAddress sinkIp, MacAddress sinkMac, TelemetrySpec spec, boolean enabled) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 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 Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 87 | public TpPort collectorPort() { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 88 | 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 Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 130 | * Returns the type of telemetry spec as per {@link TelemetrySpec}. |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 131 | * |
| 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 Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 148 | * Returns a new builder. |
| 149 | * |
| 150 | * @return new builder |
| 151 | */ |
| 152 | public static Builder builder() { |
| 153 | return new Builder(); |
| 154 | } |
| 155 | |
| 156 | /** |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 157 | * An IntConfig object builder. |
| 158 | */ |
| 159 | public static final class Builder { |
| 160 | |
| 161 | private IpAddress collectorIp; |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 162 | private TpPort collectorPort; |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 163 | 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 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 175 | public IntDeviceConfig.Builder withCollectorIp(IpAddress collectorIp) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 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 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 186 | public IntDeviceConfig.Builder withCollectorPort(TpPort collectorPort) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 187 | 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 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 198 | public IntDeviceConfig.Builder withCollectorNextHopMac(MacAddress collectorNextHopMac) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 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 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 209 | public IntDeviceConfig.Builder withSinkIp(IpAddress sinkIp) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 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 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 220 | public IntDeviceConfig.Builder withSinkMac(MacAddress sinkMac) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 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 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 231 | public IntDeviceConfig.Builder withTelemetrySpec(TelemetrySpec spec) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 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 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 243 | public IntDeviceConfig.Builder enabled(boolean enabled) { |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 244 | this.enabled = enabled; |
| 245 | return this; |
| 246 | } |
| 247 | |
| 248 | /** |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 249 | * Builds the IntConfig object. |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 250 | * |
| 251 | * @return an IntConfig object |
| 252 | */ |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 253 | public IntDeviceConfig build() { |
Jonghwan Hyun | 722275f | 2018-05-14 15:44:56 -0700 | [diff] [blame] | 254 | 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."); |
Carmelo Cascone | defc74e | 2020-07-17 15:27:02 -0700 | [diff] [blame] | 259 | return new IntDeviceConfig(collectorIp, collectorPort, collectorNextHopMac, |
Jonghwan Hyun | 71d42cd | 2018-03-13 13:23:01 -0700 | [diff] [blame] | 260 | sinkIp, sinkMac, spec, enabled); |
| 261 | } |
| 262 | } |
| 263 | } |