blob: 6358ca92c83dbbd2fd1528a5c40287ba26fa7708 [file] [log] [blame]
chengfan2fff70f2015-08-24 18:20:19 -05001/*
2 *
3 * * Copyright 2015 Open Networking Laboratory
4 * *
5 * * Licensed under the Apache License, Version 2.0 (the "License");
6 * * you may not use this file except in compliance with the License.
7 * * You may obtain a copy of the License at
8 * *
9 * * http://www.apache.org/licenses/LICENSE-2.0
10 * *
11 * * Unless required by applicable law or agreed to in writing, software
12 * * distributed under the License is distributed on an "AS IS" BASIS,
13 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * * See the License for the specific language governing permissions and
15 * * limitations under the License.
16 *
17 */
18
19package org.onosproject.incubator.net.tunnel;
20
21import java.time.Duration;
22import java.util.List;
23
24/**
25 * Default implementation of immutable tunnel statistics.
26 */
27public final class DefaultTunnelStatistics implements TunnelStatistics {
28 private final TunnelId tunnelId;
29 private final double bwUtilization;
30 private final double packetLossRatio;
31 private final Duration flowDelay;
32 private final List<String> alarms;
33
34 private DefaultTunnelStatistics(TunnelId tunnelId,
35 double bwUtilization,
36 double packetLossRatio,
37 Duration flowDelay,
38 List<String> alarms) {
39 this.tunnelId = tunnelId;
40 this.bwUtilization = bwUtilization;
41 this.packetLossRatio = packetLossRatio;
42 this.flowDelay = flowDelay;
43 this.alarms = alarms;
44 }
45
46 private DefaultTunnelStatistics() {
47 this.tunnelId = null;
48 this.bwUtilization = 0;
49 this.packetLossRatio = 0;
50 this.flowDelay = null;
51 this.alarms = null;
52 }
53
54
55 @Override
56 public TunnelId id() {
57 return this.tunnelId;
58 }
59
60 @Override
61 public double bandwidthUtilization() {
62 return this.bwUtilization;
63 }
64
65 @Override
66 public double packetLossRate() {
67 return this.packetLossRatio;
68 }
69
70 @Override
71 public Duration flowDelay() {
72 return this.flowDelay;
73 }
74
75
76 @Override
77 public List<String> alarms() {
78 return this.alarms;
79 }
80
81 /**
82 * Builder for tunnelStatistics.
83 */
84 public static final class Builder {
85 TunnelId tunnelId;
86 double bwUtilization;
87 double packetLossRatio;
88 Duration flowDelay;
89 List<String> alarms;
90
91 public Builder() {
92
93 }
94
95 /**
96 * Set tunnel id.
97 *
98 * @param tunnelId tunnel id
99 * @return builder object
100 */
101 public Builder setTunnelId(TunnelId tunnelId) {
102 this.tunnelId = tunnelId;
103
104 return this;
105 }
106
107 /**
108 * set bandwidth utilization.
109 *
110 * @param bwUtilization bandwidth utilization
111 * @return builder object
112 */
113 public Builder setBwUtilization(double bwUtilization) {
114 this.bwUtilization = bwUtilization;
115
116 return this;
117 }
118
119 /**
120 * Set packet loss ratio.
121 *
122 * @param packetLossRatio packet loss ratio
123 * @return builder object
124 */
125 public Builder setPacketLossRatio(double packetLossRatio) {
126 this.packetLossRatio = packetLossRatio;
127
128 return this;
129 }
130
131 /**
132 * Set flow delay.
133 *
134 * @param flowDelay flow delay
135 * @return builder object
136 */
137 public Builder setFlowDelay(Duration flowDelay) {
138 this.flowDelay = flowDelay;
139
140 return this;
141 }
142
143 /**
144 * Set alarms.
145 *
146 * @param alarms alarms of a tunnel
147 * @return builder object
148 */
149 public Builder setAlarms(List<String> alarms) {
150 this.alarms = alarms;
151
152 return this;
153 }
154
155 /**
156 * Creates a TunnelStatistics object.
157 *
158 * @return DefaultTunnelStatistics
159 */
160 public DefaultTunnelStatistics build() {
161 return new DefaultTunnelStatistics(tunnelId,
162 bwUtilization,
163 packetLossRatio,
164 flowDelay,
165 alarms);
166 }
167 }
168}