blob: 02fa765a29334f7df139e445bbfebc64b70ebef2 [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 Start Time for Delay and Loss Measurements.
25 */
26public final class StartTime extends SoamTime {
27
28 protected StartTime(TimeOption option, Duration relativeStart, Instant absoluteStart) {
29 super(option, relativeStart, absoluteStart);
30 }
31
32 public static final StartTime immediate() {
33 return new StartTime(StartTimeOption.IMMEDIATE, null, null);
34 }
35
36 public static final StartTime relative(Duration relativeStart) {
37 return new StartTime(StartTimeOption.RELATIVE, relativeStart, null);
38 }
39
40 public static final StartTime absolute(Instant absoluteStart) {
41 return new StartTime(StartTimeOption.ABSOLUTE, null, absoluteStart);
42 }
43
44 @Override
45 public String toString() {
46 if (option == StartTimeOption.IMMEDIATE) {
47 return "immediate";
48 } else if (option == StartTimeOption.ABSOLUTE) {
49 return MoreObjects.toStringHelper(getClass()).add("absolute", absoluteTime).toString();
50 } else if (option == StartTimeOption.RELATIVE) {
51 return MoreObjects.toStringHelper(getClass()).add("relative", relativeTime).toString();
52 }
53 return "unknown";
54 }
55
56 /**
57 * Options for Start Time.
58 */
59 public enum StartTimeOption implements TimeOption {
60 IMMEDIATE,
61 RELATIVE,
62 ABSOLUTE;
63 }
64}