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