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 { |
| 96 | return null; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public DelayMeasurementEntry getDm( |
| 101 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 102 | throws CfmConfigException, SoamConfigException { |
| 103 | if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) { |
| 104 | return dmEntry1; |
| 105 | } |
| 106 | return null; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public DelayMeasurementStatCurrent getDmCurrentStat( |
| 111 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 112 | throws CfmConfigException, SoamConfigException { |
| 113 | if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) { |
| 114 | return dmEntry1.currentResult(); |
| 115 | } |
| 116 | return null; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public Collection<DelayMeasurementStatHistory> getDmHistoricalStats( |
| 121 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 122 | throws CfmConfigException, SoamConfigException { |
| 123 | if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) { |
| 124 | return dmEntry1.historicalResults(); |
| 125 | } |
| 126 | return null; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public Optional<SoamId> createDm( |
| 131 | MdId mdName, MaIdShort maName, MepId mepId, DelayMeasurementCreate dm) |
| 132 | throws CfmConfigException, SoamConfigException { |
| 133 | return Optional.ofNullable(SoamId.valueOf(1000)); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public void abortDm( |
| 138 | MdId mdName, MaIdShort maName, MepId mepId) |
| 139 | throws CfmConfigException { |
| 140 | |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public void abortDm( |
| 145 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 146 | throws CfmConfigException { |
| 147 | |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void clearDelayHistoryStats( |
| 152 | MdId mdName, MaIdShort maName, MepId mepId) |
| 153 | throws CfmConfigException { |
| 154 | |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void clearDelayHistoryStats( |
| 159 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 160 | throws CfmConfigException { |
| 161 | |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public Collection<LossMeasurementEntry> getAllLms( |
| 166 | MdId mdName, MaIdShort maName, MepId mepId) |
| 167 | throws CfmConfigException, SoamConfigException { |
| 168 | return null; |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public LossMeasurementEntry getLm( |
| 173 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 174 | throws CfmConfigException, SoamConfigException { |
| 175 | return null; |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public LossMeasurementStatCurrent getLmCurrentStat( |
| 180 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) { |
| 181 | return null; |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public Collection<LossMeasurementStatCurrent> getLmHistoricalStats( |
| 186 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) { |
| 187 | return new ArrayList<LossMeasurementStatCurrent>(); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public Optional<SoamId> createLm( |
| 192 | MdId mdName, MaIdShort maName, MepId mepId, LossMeasurementCreate lm) |
| 193 | throws CfmConfigException, SoamConfigException { |
| 194 | return Optional.empty(); |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void abortLm( |
| 199 | MdId mdName, MaIdShort maName, MepId mepId) |
| 200 | throws CfmConfigException { |
| 201 | |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void abortLm( |
| 206 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 207 | throws CfmConfigException { |
| 208 | |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public void clearLossHistoryStats( |
| 213 | MdId mdName, MaIdShort maName, MepId mepId) |
| 214 | throws CfmConfigException { |
| 215 | |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public void clearLossHistoryStats( |
| 220 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 221 | throws CfmConfigException { |
| 222 | |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public void createTestSignal( |
| 227 | MdId mdName, MaIdShort maName, MepId mepId, MepTsCreate tsCreate) |
| 228 | throws CfmConfigException { |
| 229 | |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void abortTestSignal( |
| 234 | MdId mdName, MaIdShort maName, MepId mepId) |
| 235 | throws CfmConfigException { |
| 236 | |
| 237 | } |
| 238 | } |