blob: df1b3834dfe594a23c4ac8ccb49152a8f1568883 [file] [log] [blame]
chengfan2fff70f2015-08-24 18:20:19 -05001/*
Thomas Vachuska58de4162015-09-10 16:15:33 -07002 * Copyright 2015 Open Networking Laboratory
chengfan2fff70f2015-08-24 18:20:19 -05003 *
Thomas Vachuska58de4162015-09-10 16:15:33 -07004 * 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
chengfan2fff70f2015-08-24 18:20:19 -05007 *
Thomas Vachuska58de4162015-09-10 16:15:33 -07008 * 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.
chengfan2fff70f2015-08-24 18:20:19 -050015 */
16
17package org.onosproject.incubator.net.tunnel;
18
19import java.time.Duration;
20import java.util.List;
21
22/**
23 * Default implementation of immutable tunnel statistics.
24 */
25public final class DefaultTunnelStatistics implements TunnelStatistics {
26 private final TunnelId tunnelId;
27 private final double bwUtilization;
28 private final double packetLossRatio;
29 private final Duration flowDelay;
30 private final List<String> alarms;
31
32 private DefaultTunnelStatistics(TunnelId tunnelId,
33 double bwUtilization,
34 double packetLossRatio,
35 Duration flowDelay,
36 List<String> alarms) {
37 this.tunnelId = tunnelId;
38 this.bwUtilization = bwUtilization;
39 this.packetLossRatio = packetLossRatio;
40 this.flowDelay = flowDelay;
41 this.alarms = alarms;
42 }
43
44 private DefaultTunnelStatistics() {
45 this.tunnelId = null;
46 this.bwUtilization = 0;
47 this.packetLossRatio = 0;
48 this.flowDelay = null;
49 this.alarms = null;
50 }
51
52
53 @Override
54 public TunnelId id() {
55 return this.tunnelId;
56 }
57
58 @Override
59 public double bandwidthUtilization() {
60 return this.bwUtilization;
61 }
62
63 @Override
64 public double packetLossRate() {
65 return this.packetLossRatio;
66 }
67
68 @Override
69 public Duration flowDelay() {
70 return this.flowDelay;
71 }
72
73
74 @Override
75 public List<String> alarms() {
76 return this.alarms;
77 }
78
79 /**
80 * Builder for tunnelStatistics.
81 */
82 public static final class Builder {
83 TunnelId tunnelId;
84 double bwUtilization;
85 double packetLossRatio;
86 Duration flowDelay;
87 List<String> alarms;
88
89 public Builder() {
90
91 }
92
93 /**
94 * Set tunnel id.
95 *
96 * @param tunnelId tunnel id
97 * @return builder object
98 */
99 public Builder setTunnelId(TunnelId tunnelId) {
100 this.tunnelId = tunnelId;
101
102 return this;
103 }
104
105 /**
106 * set bandwidth utilization.
107 *
108 * @param bwUtilization bandwidth utilization
109 * @return builder object
110 */
111 public Builder setBwUtilization(double bwUtilization) {
112 this.bwUtilization = bwUtilization;
113
114 return this;
115 }
116
117 /**
118 * Set packet loss ratio.
119 *
120 * @param packetLossRatio packet loss ratio
121 * @return builder object
122 */
123 public Builder setPacketLossRatio(double packetLossRatio) {
124 this.packetLossRatio = packetLossRatio;
125
126 return this;
127 }
128
129 /**
130 * Set flow delay.
131 *
132 * @param flowDelay flow delay
133 * @return builder object
134 */
135 public Builder setFlowDelay(Duration flowDelay) {
136 this.flowDelay = flowDelay;
137
138 return this;
139 }
140
141 /**
142 * Set alarms.
143 *
144 * @param alarms alarms of a tunnel
145 * @return builder object
146 */
147 public Builder setAlarms(List<String> alarms) {
148 this.alarms = alarms;
149
150 return this;
151 }
152
153 /**
154 * Creates a TunnelStatistics object.
155 *
156 * @return DefaultTunnelStatistics
157 */
158 public DefaultTunnelStatistics build() {
159 return new DefaultTunnelStatistics(tunnelId,
160 bwUtilization,
161 packetLossRatio,
162 flowDelay,
163 alarms);
164 }
165 }
166}