Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.incubator.net.l2monitoring.soam.delay; |
| 17 | |
| 18 | import java.time.Duration; |
| 19 | import java.util.ArrayList; |
| 20 | import java.util.Collection; |
| 21 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 22 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 23 | import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException; |
| 24 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
| 25 | |
| 26 | import com.google.common.collect.Lists; |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 27 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 28 | |
| 29 | /** |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 30 | * The default implementation of {@link DelayMeasurementEntry}. |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 31 | */ |
| 32 | public final class DefaultDelayMeasurementEntry |
| 33 | extends DefaultDelayMeasurementCreate implements DelayMeasurementEntry { |
| 34 | |
| 35 | private final SoamId dmId; |
| 36 | private final SessionStatus sessionStatus; |
| 37 | private final Duration frameDelayTwoWay; |
| 38 | private final Duration frameDelayForward; |
| 39 | private final Duration frameDelayBackward; |
| 40 | private final Duration interFrameDelayVariationTwoWay; |
| 41 | private final Duration interFrameDelayVariationForward; |
| 42 | private final Duration interFrameDelayVariationBackward; |
| 43 | private final DelayMeasurementStatCurrent currentResult; |
| 44 | private final Collection<DelayMeasurementStatHistory> historicalResults; |
| 45 | |
| 46 | private DefaultDelayMeasurementEntry(DefaultDmEntryBuilder builder) { |
| 47 | super(builder); |
| 48 | this.dmId = builder.dmId; |
| 49 | this.currentResult = builder.currentResult; |
| 50 | this.historicalResults = builder.historicalResults; |
| 51 | |
| 52 | this.sessionStatus = builder.sessionStatus; |
| 53 | this.frameDelayTwoWay = builder.frameDelayTwoWay; |
| 54 | this.frameDelayForward = builder.frameDelayForward; |
| 55 | this.frameDelayBackward = builder.frameDelayBackward; |
| 56 | this.interFrameDelayVariationTwoWay = builder.interFrameDelayVariationTwoWay; |
| 57 | this.interFrameDelayVariationForward = builder.interFrameDelayVariationForward; |
| 58 | this.interFrameDelayVariationBackward = builder.interFrameDelayVariationBackward; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public SoamId dmId() { |
| 63 | return dmId; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public SessionStatus sessionStatus() { |
| 68 | return sessionStatus; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public Duration frameDelayTwoWay() { |
| 73 | return frameDelayTwoWay; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Duration frameDelayForward() { |
| 78 | return frameDelayForward; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Duration frameDelayBackward() { |
| 83 | return frameDelayBackward; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public Duration interFrameDelayVariationTwoWay() { |
| 88 | return interFrameDelayVariationTwoWay; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public Duration interFrameDelayVariationForward() { |
| 93 | return interFrameDelayVariationForward; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public Duration interFrameDelayVariationBackward() { |
| 98 | return interFrameDelayVariationBackward; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public DelayMeasurementStatCurrent currentResult() { |
| 103 | return currentResult; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public Collection<DelayMeasurementStatHistory> historicalResults() { |
| 108 | if (historicalResults != null) { |
| 109 | return Lists.newArrayList(historicalResults); |
| 110 | } |
| 111 | return null; |
| 112 | } |
| 113 | |
| 114 | public static DmEntryBuilder builder(SoamId dmId, DmType dmCfgType, |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 115 | Version version, MepId remoteMepId, Mep.Priority priority) |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 116 | throws SoamConfigException { |
| 117 | return new DefaultDmEntryBuilder(dmId, dmCfgType, version, |
| 118 | remoteMepId, priority); |
| 119 | } |
| 120 | |
| 121 | /** |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 122 | * Builder for {@link DelayMeasurementEntry}. |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 123 | */ |
| 124 | private static final class DefaultDmEntryBuilder extends DefaultDmCreateBuilder |
| 125 | implements DmEntryBuilder { |
| 126 | private final SoamId dmId; |
| 127 | private SessionStatus sessionStatus; |
| 128 | private Duration frameDelayTwoWay; |
| 129 | private Duration frameDelayForward; |
| 130 | private Duration frameDelayBackward; |
| 131 | private Duration interFrameDelayVariationTwoWay; |
| 132 | private Duration interFrameDelayVariationForward; |
| 133 | private Duration interFrameDelayVariationBackward; |
| 134 | private DelayMeasurementStatCurrent currentResult; |
| 135 | private Collection<DelayMeasurementStatHistory> historicalResults; |
| 136 | |
| 137 | private DefaultDmEntryBuilder(SoamId dmId, DmType dmCfgType, |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 138 | Version version, MepId remoteMepId, Mep.Priority priority) |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 139 | throws SoamConfigException { |
| 140 | super(dmCfgType, version, remoteMepId, priority); |
| 141 | if (dmId == null) { |
| 142 | throw new SoamConfigException("DmId is null"); |
| 143 | } |
| 144 | this.dmId = dmId; |
| 145 | historicalResults = new ArrayList<>(); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public DmEntryBuilder sessionStatus(SessionStatus sessionStatus) { |
| 150 | this.sessionStatus = sessionStatus; |
| 151 | return this; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public DmEntryBuilder frameDelayTwoWay(Duration frameDelayTwoWay) { |
| 156 | this.frameDelayTwoWay = frameDelayTwoWay; |
| 157 | return this; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public DmEntryBuilder frameDelayForward(Duration frameDelayForward) { |
| 162 | this.frameDelayForward = frameDelayForward; |
| 163 | return this; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public DmEntryBuilder frameDelayBackward(Duration frameDelayBackward) { |
| 168 | this.frameDelayBackward = frameDelayBackward; |
| 169 | return this; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public DmEntryBuilder interFrameDelayVariationTwoWay( |
| 174 | Duration interFrameDelayVariationTwoWay) { |
| 175 | this.interFrameDelayVariationTwoWay = interFrameDelayVariationTwoWay; |
| 176 | return this; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public DmEntryBuilder interFrameDelayVariationForward( |
| 181 | Duration interFrameDelayVariationForward) { |
| 182 | this.interFrameDelayVariationForward = interFrameDelayVariationForward; |
| 183 | return this; |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public DmEntryBuilder interFrameDelayVariationBackward( |
| 188 | Duration interFrameDelayVariationBackward) { |
| 189 | this.interFrameDelayVariationBackward = interFrameDelayVariationBackward; |
| 190 | return this; |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public DmEntryBuilder currentResult(DelayMeasurementStatCurrent currentResult) { |
| 195 | this.currentResult = currentResult; |
| 196 | return this; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public DmEntryBuilder addToHistoricalResults( |
| 201 | DelayMeasurementStatHistory historicalResult) { |
| 202 | this.historicalResults.add(historicalResult); |
| 203 | return this; |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public DelayMeasurementEntry build() { |
| 208 | return new DefaultDelayMeasurementEntry(this); |
| 209 | } |
| 210 | } |
| 211 | } |