blob: ff069327346af3ad9c99dc8917b6e934aca4e467 [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-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.incubator.net.l2monitoring.cfm;
17
18import java.time.Duration;
19import java.util.HashSet;
20import java.util.Set;
21
22import org.onlab.packet.IpAddress;
23import org.onlab.packet.VlanId;
24import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
25import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
26import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId;
27import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.NetworkResource;
30import org.onosproject.net.PortNumber;
31
32/**
33 * A model of the Maintenance Association Endpoint.
34 *
35 * See IEE 802.1Q Section 12.14.7.1.3 for reference
36 */
37public interface Mep extends NetworkResource {
38
39 /**
40 * Get the ID of the MEP.
41 *
42 * @return The MEPID is an integer in the range 1–8191
43 */
44 MepId mepId();
45
46 /**
47 * Get the Device ID which the MEP is realized on.
48 *
49 * @return The DeviceID to which this Mep is associated
50 */
51 DeviceId deviceId();
52
53 /**
54 * Get the port to which the MEP is attached.
55 *
56 * @return An port to which the MEP is attached
57 */
58 PortNumber port();
59
60 /**
61 * Get the MEP direction.
62 *
63 * @return A value indicating the direction in which the MEP faces on the interface
64 */
65 MepDirection direction();
66
67 /**
68 * Get the Maintenance Domain reference.
69 *
70 * @return The name of the containing Maintenance Domain
71 */
72 MdId mdId();
73
74 /**
75 * Get the Maintenance Association reference.
76 *
77 * @return The name of the containing Maintenance Association
78 */
79 MaIdShort maId();
80
81 /**
82 * Get the Primary VID of the MEP.
83 * The value 0 indicates that either the Primary VID is that
84 * of the MEP's MA or that the MEP's MA is associated with no VID.
85 *
86 * @return An integer in the range 0-4094
87 */
88 VlanId primaryVid();
89
90 /**
91 * Set the Primary VID of the MEP.
92 *
93 * @param primaryVid An integer between 0 and 4094
94 * @return A new MEP with this value set
95 */
96 Mep withPrimaryVid(VlanId primaryVid);
97
98 /**
99 * Get the administrative state of the MEP.
100 *
101 * @return The administrative state of the MEP
102 */
103 boolean administrativeState();
104
105 /**
106 * Set the administrative state of the MEP.
107 *
108 * @param adminState The administrative state of the MEP
109 * @return A new MEP with this value set
110 */
111 Mep withAdministrativeState(boolean adminState);
112
113 /**
114 * Get whether the MEP is or is not to generate CCMs.
115 *
116 * CCMs are Continuity Check Messages
117 *
118 * @return boolean value indicating whether the MEP is or is not to generate CCMs
119 */
120 Boolean cciEnabled();
121
122 /**
123 * Enable or disable the generation of CCMs by the MEP.
124 *
125 * @param cciEnabled boolean value dictating whether CCMs are sent or not
126 * @return A new MEP with this value set
127 */
128 Mep withCciEnabled(boolean cciEnabled);
129
130 /**
131 * Get the priority parameter for CCMs and LTMs transmitted by the MEP.
132 *
133 * @return The priority parameter for CCMs and LTMs transmitted by the MEP
134 */
135 Priority ccmLtmPriority();
136
137 /**
138 * Set the priority parameter for CCMs and LTMs transmitted by the MEP.
139 *
140 * @param priority An integer value between 0 and 7 inclusive
141 * @return A new MEP with this value set
142 */
143 Mep withCcmLtmPriority(Priority priority);
144
145 /**
146 * Get the network address to which Fault Alarms are to be transmitted.
147 *
148 * @return The IP address to which Fault Alarms are to be transmitted
149 */
150 FngAddress fngAddress();
151
152 /**
153 * Set the network address to which Fault Alarms are to be transmitted.
154 *
155 * If “not specified,” the address used is that from the Maintenance Association managed object
156 *
157 * @param address Address type or indicator that address is not specified or alarms are not to be transmitted
158 * @return A new MEP with this value set
159 */
160 Mep withFngAddress(FngAddress address);
161
162 /**
163 * Get the lowest priority defect that is allowed to generate a Fault Alarm.
164 * @return The lowest priority defect that is allowed to generate a Fault Alarm
165 */
166 LowestFaultDefect lowestFaultPriorityDefect();
167
168 /**
169 * Set the lowest priority defect that is allowed to generate a Fault Alarm.
170 * @param lowestFdType The lowest priority defect that is allowed to generate a Fault Alarm
171 * @return A new MEP with this value set
172 */
173 Mep withLowestFaultPriorityDefect(LowestFaultDefect lowestFdType);
174
175 /**
176 * Get the time that the Fault must be present before it is issued.
177 * @return The time that the Fault must be present before it is issued
178 */
179 Duration defectPresentTime();
180
181 /**
182 * Set the time that the Fault must be present before it is issued.
183 *
184 * The default is 2500ms (2.5 seconds) if not specified
185 * @param duration The time that the Fault must be present before it is issued
186 * @return A new MEP with this value set
187 */
188 Mep withDefectPresentTime(Duration duration);
189
190 /**
191 * Get the time that the Fault must be absent before it is reset.
192 * @return The time that the Fault must be absent before it is reset
193 */
194 Duration defectAbsentTime();
195
196 /**
197 * Set the time that the Fault must be absent before it is reset.
198 *
199 * The default is 10000ms (10 seconds) if not specified
200 * @param duration The time that the Fault must be absent before it is reset
201 * @return A new MEP with this value set
202 */
203 Mep withDefectAbsentTime(Duration duration);
204
205 /**
206 * Enumerated options for MEP Directions.
207 */
208 public enum MepDirection {
209 UP_MEP,
210 DOWN_MEP
211 }
212
213 /**
214 * Supported FNG Address Types.
215 * See {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep.FngAddress}
216 */
217 public enum FngAddressType {
218 IPV4,
219 IPV6,
220 NOT_SPECIFIED,
221 NOT_TRANSMITTED;
222 }
223
224 /**
225 * Supported Fault Defect Types.
226 */
227 public enum FaultDefectType {
228 DEF_NONE,
229 DEF_RDI_CCM,
230 DEF_MAC_STATUS,
231 DEF_REMOTE_CCM,
232 DEF_ERROR_CCM,
233 DEF_XCON_CCM
234 }
235
236 /**
237 * Options for setting the lowest fault defect.
238 * Each comprises a set of {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep.FaultDefectType}
239 */
240 public enum LowestFaultDefect {
241 ALL_DEFECTS(FaultDefectType.DEF_RDI_CCM,
242 FaultDefectType.DEF_MAC_STATUS,
243 FaultDefectType.DEF_REMOTE_CCM,
244 FaultDefectType.DEF_ERROR_CCM,
245 FaultDefectType.DEF_XCON_CCM),
246 MAC_FD_PLUS(FaultDefectType.DEF_MAC_STATUS,
247 FaultDefectType.DEF_REMOTE_CCM,
248 FaultDefectType.DEF_ERROR_CCM,
249 FaultDefectType.DEF_XCON_CCM),
250 REMOTE_FD_PLUS(FaultDefectType.DEF_REMOTE_CCM,
251 FaultDefectType.DEF_ERROR_CCM,
252 FaultDefectType.DEF_XCON_CCM),
253 ERROR_FD_PLUS(FaultDefectType.DEF_ERROR_CCM,
254 FaultDefectType.DEF_XCON_CCM),
255 XCON_FD_ONLY(FaultDefectType.DEF_XCON_CCM);
256
257 private Set<FaultDefectType> defectTypes = new HashSet<>();
258
259 private LowestFaultDefect(FaultDefectType... defectTypes) {
260 for (FaultDefectType defectType:defectTypes) {
261 this.defectTypes.add(defectType);
262 }
263 }
264
265 public Set<FaultDefectType> getDefectTypes() {
266 return defectTypes;
267 }
268 }
269
270 /**
271 * An enumerated set of values to represent Priority.
272 */
273 public enum Priority {
274 PRIO0, PRIO1, PRIO2, PRIO3, PRIO4, PRIO5, PRIO6, PRIO7
275 }
276
277 /**
278 * A simple class to join an FngAddressType and an IpAddress.
279 */
280 public final class FngAddress {
281 private final FngAddressType addressType;
282 private final IpAddress ipAddress;
283
284 private FngAddress(FngAddressType addressType, IpAddress ipAddress) {
285 this.addressType = addressType;
286 this.ipAddress = ipAddress;
287 }
288
289 public FngAddressType addressType() {
290 return addressType;
291 }
292
293 public IpAddress ipAddress() {
294 return ipAddress;
295 }
296
297 public static FngAddress ipV4Address(IpAddress ipAddress) {
298 return new FngAddress(FngAddressType.IPV4, ipAddress);
299 }
300
301 public static FngAddress ipV6Address(IpAddress ipAddress) {
302 return new FngAddress(FngAddressType.IPV6, ipAddress);
303 }
304
305 public static FngAddress notSpecified() {
306 return new FngAddress(FngAddressType.NOT_SPECIFIED, null);
307 }
308
309 public static FngAddress notTransmitted(IpAddress ipAddress) {
310 return new FngAddress(FngAddressType.NOT_TRANSMITTED, ipAddress);
311 }
312
313 @Override
314 public String toString() {
315 return "FngAddress{" +
316 "addressType=" + addressType +
317 ", ipAddress=" + ipAddress +
318 '}';
319 }
320
321 @Override
322 public boolean equals(Object o) {
323 if (this == o) {
324 return true;
325 }
326 if (o == null || getClass() != o.getClass()) {
327 return false;
328 }
329
330 FngAddress that = (FngAddress) o;
331
332 if (addressType != that.addressType) {
333 return false;
334 }
335 return ipAddress != null ? ipAddress.equals(that.ipAddress) : that.ipAddress == null;
336 }
337
338 @Override
339 public int hashCode() {
340 int result = addressType.hashCode();
341 result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0);
342 return result;
343 }
344 }
345
346 /**
347 * Builder for {@link org.onosproject.incubator.net.l2monitoring.cfm.Mep}.
348 */
349 interface MepBuilder {
350
351 MepBuilder primaryVid(VlanId primaryVid);
352
353 MepBuilder administrativeState(boolean administrativeState);
354
355 MepBuilder cciEnabled(boolean cciEnabled);
356
357 MepBuilder ccmLtmPriority(Priority ccmLtmPriority);
358
359 MepBuilder fngAddress(FngAddress fngAddress);
360
361 MepBuilder lowestFaultPriorityDefect(LowestFaultDefect lowestFaultPriorityDefect);
362
363 MepBuilder defectPresentTime(Duration defectPresentTime);
364
365 MepBuilder defectAbsentTime(Duration defectAbsentTime);
366
367 Mep build() throws CfmConfigException;
368 }
369}