blob: b58103648e78f9f6d32a3c838c45aaafd6febbbc [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.soam;
17
18import java.time.Duration;
19import java.time.Instant;
20
21import com.google.common.base.MoreObjects;
22
23/**
24 * A utility class for specifying a Stop Time for Delay and Loss Measurements.
25 */
26public final class StopTime extends SoamTime {
27
28 private StopTime(TimeOption option, Duration relativeStart, Instant absoluteStart) {
29 super(option, relativeStart, absoluteStart);
30 }
31
32 public static final StopTime none() {
33 return new StopTime(StopTimeOption.NONE, null, null);
34 }
35
36 public static final StopTime relative(Duration relativeStop) {
37 return new StopTime(StopTimeOption.RELATIVE, relativeStop, null);
38 }
39
40 public static final StopTime absolute(Instant absoluteStop) {
41 return new StopTime(StopTimeOption.ABSOLUTE, null, absoluteStop);
42 }
43
44 @Override
45 public String toString() {
46 if (option == StopTimeOption.NONE) {
47 return "none";
48 } else if (option == StopTimeOption.ABSOLUTE) {
49 return MoreObjects.toStringHelper(getClass()).add("absolute", absoluteTime).toString();
50 } else if (option == StopTimeOption.RELATIVE) {
51 return MoreObjects.toStringHelper(getClass()).add("relative", relativeTime).toString();
52 }
53 return "unknown";
54 }
55
56 /**
57 * Options for Stop Time.
58 */
59 public enum StopTimeOption implements TimeOption {
60 NONE,
61 RELATIVE,
62 ABSOLUTE;
63 }
64}