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.impl; |
| 17 | |
| 18 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep; |
| 19 | import org.onosproject.incubator.net.l2monitoring.cfm.MepTsCreate; |
| 20 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 23 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 24 | import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException; |
| 25 | import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable; |
| 26 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
| 27 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry; |
| 28 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementStatCurrent; |
| 29 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementStatHistory; |
| 30 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate; |
| 31 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry; |
| 32 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent; |
| 33 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory; |
| 34 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate; |
| 35 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry; |
| 36 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent; |
| 37 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 38 | |
| 39 | import java.time.Duration; |
| 40 | import java.time.Instant; |
| 41 | import java.util.ArrayList; |
| 42 | import java.util.Collection; |
| 43 | import java.util.Optional; |
| 44 | |
| 45 | import static org.onosproject.incubator.net.l2monitoring.soam.impl.SoamManagerTest.*; |
| 46 | |
| 47 | /** |
| 48 | * A dummy implementation of the SoamDmProgrammable for test purposes. |
| 49 | */ |
| 50 | public class TestSoamDmProgrammable extends AbstractHandlerBehaviour implements SoamDmProgrammable { |
| 51 | private DelayMeasurementEntry dmEntry1; |
| 52 | |
| 53 | public TestSoamDmProgrammable() throws SoamConfigException { |
| 54 | long nowMs = System.currentTimeMillis(); |
| 55 | long lastSecond = nowMs - nowMs % 1000; |
| 56 | DelayMeasurementStatCurrent current = |
| 57 | (DelayMeasurementStatCurrent) DefaultDelayMeasurementStatCurrent |
| 58 | .builder(Duration.ofSeconds(37), false) |
| 59 | .startTime(Instant.ofEpochMilli(lastSecond)) |
| 60 | .build(); |
| 61 | |
| 62 | long lastMinute = nowMs - nowMs % (60 * 1000); |
| 63 | DelayMeasurementStatHistory history1 = |
| 64 | (DelayMeasurementStatHistory) DefaultDelayMeasurementStatHistory |
| 65 | .builder(SoamId.valueOf(67), Duration.ofSeconds(60), false) |
| 66 | .endTime(Instant.ofEpochMilli(lastMinute)) |
| 67 | .frameDelayForwardMin(Duration.ofMillis(107)) |
| 68 | .frameDelayForwardMax(Duration.ofMillis(109)) |
| 69 | .frameDelayForwardAvg(Duration.ofMillis(108)) |
| 70 | .build(); |
| 71 | |
| 72 | long lastMinute2 = lastMinute - (60 * 1000); |
| 73 | DelayMeasurementStatHistory history2 = |
| 74 | (DelayMeasurementStatHistory) DefaultDelayMeasurementStatHistory |
| 75 | .builder(SoamId.valueOf(66), Duration.ofSeconds(60), false) |
| 76 | .endTime(Instant.ofEpochMilli(lastMinute2)) |
| 77 | .frameDelayForwardMin(Duration.ofMillis(117)) |
| 78 | .frameDelayForwardMax(Duration.ofMillis(119)) |
| 79 | .frameDelayForwardAvg(Duration.ofMillis(118)) |
| 80 | .build(); |
| 81 | |
| 82 | dmEntry1 = DefaultDelayMeasurementEntry |
| 83 | .builder(DMID101, DelayMeasurementCreate.DmType.DM1DMTX, |
| 84 | DelayMeasurementCreate.Version.Y17312011, |
| 85 | MepId.valueOf((short) 11), Mep.Priority.PRIO5) |
| 86 | .currentResult(current) |
| 87 | .addToHistoricalResults(history1) |
| 88 | .addToHistoricalResults(history2) |
| 89 | .build(); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public Collection<DelayMeasurementEntry> getAllDms( |
| 94 | MdId mdName, MaIdShort maName, MepId mepId) |
| 95 | throws CfmConfigException, SoamConfigException { |
Sean Condon | 085621b | 2017-10-29 23:27:32 +0000 | [diff] [blame] | 96 | Collection<DelayMeasurementEntry> dmEntries = new ArrayList<>(); |
| 97 | if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) { |
| 98 | dmEntries.add(dmEntry1); |
| 99 | return dmEntries; |
| 100 | } |
| 101 | return new ArrayList<>(); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public DelayMeasurementEntry getDm( |
| 106 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 107 | throws CfmConfigException, SoamConfigException { |
| 108 | if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) { |
| 109 | return dmEntry1; |
| 110 | } |
| 111 | return null; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public DelayMeasurementStatCurrent getDmCurrentStat( |
| 116 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 117 | throws CfmConfigException, SoamConfigException { |
| 118 | if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) { |
| 119 | return dmEntry1.currentResult(); |
| 120 | } |
| 121 | return null; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public Collection<DelayMeasurementStatHistory> getDmHistoricalStats( |
| 126 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 127 | throws CfmConfigException, SoamConfigException { |
| 128 | if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) { |
| 129 | return dmEntry1.historicalResults(); |
| 130 | } |
| 131 | return null; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public Optional<SoamId> createDm( |
| 136 | MdId mdName, MaIdShort maName, MepId mepId, DelayMeasurementCreate dm) |
| 137 | throws CfmConfigException, SoamConfigException { |
| 138 | return Optional.ofNullable(SoamId.valueOf(1000)); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void abortDm( |
| 143 | MdId mdName, MaIdShort maName, MepId mepId) |
| 144 | throws CfmConfigException { |
| 145 | |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void abortDm( |
| 150 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 151 | throws CfmConfigException { |
| 152 | |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public void clearDelayHistoryStats( |
| 157 | MdId mdName, MaIdShort maName, MepId mepId) |
| 158 | throws CfmConfigException { |
| 159 | |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void clearDelayHistoryStats( |
| 164 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 165 | throws CfmConfigException { |
| 166 | |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public Collection<LossMeasurementEntry> getAllLms( |
| 171 | MdId mdName, MaIdShort maName, MepId mepId) |
| 172 | throws CfmConfigException, SoamConfigException { |
| 173 | return null; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public LossMeasurementEntry getLm( |
| 178 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 179 | throws CfmConfigException, SoamConfigException { |
| 180 | return null; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public LossMeasurementStatCurrent getLmCurrentStat( |
| 185 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) { |
| 186 | return null; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public Collection<LossMeasurementStatCurrent> getLmHistoricalStats( |
| 191 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) { |
| 192 | return new ArrayList<LossMeasurementStatCurrent>(); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public Optional<SoamId> createLm( |
| 197 | MdId mdName, MaIdShort maName, MepId mepId, LossMeasurementCreate lm) |
| 198 | throws CfmConfigException, SoamConfigException { |
| 199 | return Optional.empty(); |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public void abortLm( |
| 204 | MdId mdName, MaIdShort maName, MepId mepId) |
| 205 | throws CfmConfigException { |
| 206 | |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void abortLm( |
| 211 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 212 | throws CfmConfigException { |
| 213 | |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void clearLossHistoryStats( |
| 218 | MdId mdName, MaIdShort maName, MepId mepId) |
| 219 | throws CfmConfigException { |
| 220 | |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void clearLossHistoryStats( |
| 225 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 226 | throws CfmConfigException { |
| 227 | |
| 228 | } |
| 229 | |
| 230 | @Override |
| 231 | public void createTestSignal( |
| 232 | MdId mdName, MaIdShort maName, MepId mepId, MepTsCreate tsCreate) |
| 233 | throws CfmConfigException { |
| 234 | |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public void abortTestSignal( |
| 239 | MdId mdName, MaIdShort maName, MepId mepId) |
| 240 | throws CfmConfigException { |
| 241 | |
| 242 | } |
| 243 | } |