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.drivers.microsemi; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.time.Duration; |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.BitSet; |
| 24 | import java.util.Collection; |
| 25 | import java.util.HashMap; |
| 26 | import java.util.Iterator; |
| 27 | import java.util.Map; |
| 28 | import java.util.Optional; |
| 29 | |
| 30 | import org.onosproject.drivers.microsemi.yang.MseaCfmNetconfService; |
| 31 | import org.onosproject.drivers.microsemi.yang.MseaCfmNetconfService.DmEntryParts; |
| 32 | import org.onosproject.drivers.microsemi.yang.utils.IetfYangTypesUtils; |
| 33 | import org.onosproject.drivers.microsemi.yang.utils.MepIdUtil; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.Mep.Priority; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.MepTsCreate; |
| 36 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 37 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 38 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 39 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 40 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService; |
| 41 | import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException; |
| 42 | import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable; |
| 43 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
| 44 | import org.onosproject.incubator.net.l2monitoring.soam.StartTime.StartTimeOption; |
| 45 | import org.onosproject.incubator.net.l2monitoring.soam.StopTime.StopTimeOption; |
| 46 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementEntry; |
| 47 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementStatCurrent; |
| 48 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DefaultDelayMeasurementStatHistory; |
| 49 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate; |
| 50 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.DmType; |
| 51 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.MeasurementOption; |
| 52 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate.Version; |
| 53 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry; |
| 54 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry.DmEntryBuilder; |
| 55 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry.SessionStatus; |
| 56 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent; |
| 57 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent.DmStatCurrentBuilder; |
| 58 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory; |
| 59 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory.DmStatHistoryBuilder; |
| 60 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate; |
| 61 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry; |
| 62 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent; |
| 63 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 64 | import org.onosproject.netconf.DatastoreId; |
| 65 | import org.onosproject.netconf.NetconfController; |
| 66 | import org.onosproject.netconf.NetconfException; |
| 67 | import org.onosproject.netconf.NetconfSession; |
| 68 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfm; |
| 69 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.MseaCfmOpParam; |
| 70 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.DefaultMefCfm; |
| 71 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.MefCfm; |
| 72 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.DefaultMaintenanceDomain; |
| 73 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.DefaultMaintenanceAssociation; |
| 74 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.DefaultMaintenanceAssociationEndPoint; |
| 75 | import org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain.maintenanceassociation.MaintenanceAssociationEndPoint; |
| 76 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.delaymeasurementbinsgroup.bins.FrameDelay; |
| 77 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.delaymeasurementbinsgroup.bins.InterFrameDelayVariation; |
| 78 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.AugmentedMseaCfmMaintenanceAssociationEndPoint; |
| 79 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint; |
| 80 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.DefaultDelayMeasurements; |
| 81 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.DelayMeasurements; |
| 82 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements.DefaultDelayMeasurement; |
| 83 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements.DelayMeasurement; |
| 84 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements.delaymeasurement.HistoryStats; |
| 85 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements.delaymeasurement.MeasurementEnable; |
| 86 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain.maintenanceassociation.maintenanceassociationendpoint.augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements.delaymeasurement.MessagePeriodEnum; |
| 87 | import org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.remotemepgroup.remotemep.DefaultMepId; |
| 88 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.MepIdType; |
| 89 | import org.onosproject.yang.gen.v1.mseatypes.rev20160229.mseatypes.PriorityType; |
| 90 | import org.slf4j.Logger; |
| 91 | |
| 92 | /** |
| 93 | * Implementation of SoamDmProgrammable for Microsemi EA1000. |
| 94 | */ |
| 95 | public class EA1000SoamDmProgrammable extends AbstractHandlerBehaviour |
| 96 | implements SoamDmProgrammable { |
| 97 | private static final Logger log = getLogger(EA1000SoamDmProgrammable.class); |
| 98 | private static final int MAX_DMS = 2; |
| 99 | |
| 100 | public EA1000SoamDmProgrammable() { |
| 101 | log.debug("Loaded handler behaviour EA1000SoamDmProgrammable"); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Collection<DelayMeasurementEntry> getAllDms( |
| 106 | MdId mdName, MaIdShort maName, MepId mepId) |
| 107 | throws CfmConfigException, SoamConfigException { |
| 108 | return getAllDmsOrOneDm(mdName, maName, mepId, null, DmEntryParts.ALL_PARTS); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public DelayMeasurementEntry getDm(MdId mdName, MaIdShort maName, |
| 113 | MepId mepId, SoamId dmId) throws CfmConfigException, SoamConfigException { |
| 114 | Collection<DelayMeasurementEntry> allDms = |
| 115 | getAllDmsOrOneDm(mdName, maName, mepId, dmId, DmEntryParts.ALL_PARTS); |
| 116 | |
| 117 | if (allDms != null && allDms.size() >= 1) { |
| 118 | return allDms.toArray(new DelayMeasurementEntry[1])[0]; |
| 119 | } |
| 120 | return null; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public DelayMeasurementStatCurrent getDmCurrentStat( |
| 125 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 126 | throws CfmConfigException, SoamConfigException { |
| 127 | Collection<DelayMeasurementEntry> dms = |
| 128 | getAllDmsOrOneDm(mdName, maName, mepId, dmId, DmEntryParts.CURRENT_ONLY); |
| 129 | |
| 130 | //There should be only one |
| 131 | if (dms != null && dms.size() == 1) { |
| 132 | return dms.toArray((new DelayMeasurementEntry[1]))[0].currentResult(); |
| 133 | } |
| 134 | return null; |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public Collection<DelayMeasurementStatHistory> getDmHistoricalStats( |
| 139 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 140 | throws CfmConfigException, SoamConfigException { |
| 141 | Collection<DelayMeasurementEntry> dms = |
| 142 | getAllDmsOrOneDm(mdName, maName, mepId, dmId, DmEntryParts.HISTORY_ONLY); |
| 143 | |
| 144 | //There should only be one in the result |
| 145 | if (dms != null && dms.size() == 1) { |
| 146 | return dms.toArray(new DelayMeasurementEntry[1])[0].historicalResults(); |
| 147 | } |
| 148 | return new ArrayList<>(); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public Optional<SoamId> createDm( |
| 153 | MdId mdName, MaIdShort maName, MepId mepId, DelayMeasurementCreate dm) |
| 154 | throws CfmConfigException, SoamConfigException { |
| 155 | NetconfController controller = checkNotNull(handler().get(NetconfController.class)); |
| 156 | NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); |
| 157 | MseaCfmNetconfService mseaCfmService = checkNotNull(handler().get(MseaCfmNetconfService.class)); |
| 158 | |
| 159 | MseaCfm mepEssentials; |
| 160 | try { |
| 161 | mepEssentials = mseaCfmService.getMepEssentials( |
| 162 | mdName, maName, mepId, session); |
| 163 | } catch (NetconfException e) { |
| 164 | throw new CfmConfigException(e); |
| 165 | } |
| 166 | short mdNumber = mepEssentials.mefCfm().maintenanceDomain().get(0).id(); |
| 167 | short maNumber = mepEssentials.mefCfm().maintenanceDomain().get(0) |
| 168 | .maintenanceAssociation().get(0).id(); |
| 169 | MaintenanceAssociationEndPoint currentMep = |
| 170 | mepEssentials.mefCfm().maintenanceDomain().get(0) |
| 171 | .maintenanceAssociation().get(0) |
| 172 | .maintenanceAssociationEndPoint().get(0); |
| 173 | AugmentedMseaCfmMaintenanceAssociationEndPoint currAugMep = |
| 174 | currentMep.augmentation(DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint.class); |
| 175 | |
| 176 | if (dm.startTime() != null && !dm.startTime().option().equals(StartTimeOption.IMMEDIATE)) { |
| 177 | throw new SoamConfigException( |
| 178 | "Only start time: IMMEDIATE is supported on EA1000"); |
| 179 | } else if (dm.stopTime() != null && !dm.stopTime().option().equals(StopTimeOption.NONE)) { |
| 180 | throw new SoamConfigException( |
| 181 | "Only stop time: NONE is supported on EA1000"); |
| 182 | } |
| 183 | |
| 184 | MessagePeriodEnum mpEnum = MessagePeriodEnum.YANGAUTOPREFIX1000MS; |
| 185 | if (dm.messagePeriod() != null) { |
| 186 | if (dm.messagePeriod().toMillis() == 1000) { |
| 187 | mpEnum = MessagePeriodEnum.YANGAUTOPREFIX1000MS; |
| 188 | } else if (dm.messagePeriod().toMillis() == 100) { |
| 189 | mpEnum = MessagePeriodEnum.YANGAUTOPREFIX100MS; |
| 190 | } else if (dm.messagePeriod().toMillis() == 10) { |
| 191 | mpEnum = MessagePeriodEnum.YANGAUTOPREFIX10MS; |
| 192 | } else if (dm.messagePeriod().toMillis() == 3) { |
| 193 | mpEnum = MessagePeriodEnum.YANGAUTOPREFIX3MS; |
| 194 | } else { |
| 195 | throw new SoamConfigException("EA1000 supports only Message " |
| 196 | + "Periods 1000ms,100ms, 10ms and 3ms for Delay Measurements"); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | short lastDmId = 0; |
| 201 | short newDmId = 1; |
| 202 | if (currAugMep != null && currAugMep.delayMeasurements() != null) { |
| 203 | Iterator<DelayMeasurement> dmIterator = |
| 204 | currAugMep.delayMeasurements().delayMeasurement().iterator(); |
| 205 | while (dmIterator.hasNext()) { |
| 206 | lastDmId = dmIterator.next().dmId(); |
| 207 | } |
| 208 | |
| 209 | if (lastDmId == 0) { |
| 210 | //Indicates that no DM was found under this MEP. |
| 211 | //We will just create the next one as 1 |
| 212 | log.info("Creating DM 1"); |
| 213 | newDmId = 1; |
| 214 | } else if (lastDmId == 1) { |
| 215 | log.info("Creating DM 2"); |
| 216 | newDmId = 2; |
| 217 | } else if (lastDmId == MAX_DMS) { |
| 218 | log.warn("Maximum number of DMs (2) have been created on MEP {}/{}/{}" |
| 219 | + "on device {} - delete DMs before creating more", |
| 220 | mdName.mdName(), maName.maName(), mepId.id(), |
| 221 | handler().data().deviceId()); |
| 222 | throw new CfmConfigException("Maximum number of DMs (2) exist on MEP. " |
| 223 | + "Please call abort on a DM before creating more"); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | |
| 228 | DelayMeasurement dmBuilder = new DefaultDelayMeasurement(); |
| 229 | dmBuilder.dmId((short) newDmId); |
| 230 | DefaultMepId dMepId = new DefaultMepId(); |
| 231 | dMepId.mepId(MepIdType.of(dm.remoteMepId().id())); |
| 232 | dmBuilder.remoteMep(dMepId); |
| 233 | |
| 234 | BitSet measurementEnable = getMeasurementEnabledSet(dm.measurementsEnabled()); |
| 235 | if (measurementEnable != null && !measurementEnable.isEmpty()) { |
| 236 | dmBuilder.measurementEnable(measurementEnable); |
| 237 | } |
| 238 | dmBuilder.administrativeState(true); |
| 239 | dmBuilder.priority(PriorityType.of((short) dm.priority().ordinal())); |
| 240 | dmBuilder.messagePeriod(mpEnum); |
| 241 | |
| 242 | if (dm.numberIntervalsStored() != null) { |
| 243 | //Here we pass in num intervals stored - for EA1000 32 are always |
| 244 | //stored so it's not controllable - instead we set number returned |
| 245 | dmBuilder.numberIntervalsReturned(dm.numberIntervalsStored()); |
| 246 | } |
| 247 | |
| 248 | if (dm.measurementInterval() != null) { |
| 249 | dmBuilder.measurementInterval(dm.measurementInterval().toMinutes()); |
| 250 | } |
| 251 | if (dm.frameSize() != null) { |
| 252 | dmBuilder.frameSize(dm.frameSize()); |
| 253 | } |
| 254 | DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint augmentedMep = |
| 255 | new DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint(); |
| 256 | DelayMeasurements dms = new DefaultDelayMeasurements(); |
| 257 | dms.addToDelayMeasurement(dmBuilder); |
| 258 | augmentedMep.delayMeasurements(dms); |
| 259 | |
| 260 | MaintenanceAssociationEndPoint mep = |
| 261 | new DefaultMaintenanceAssociationEndPoint(); |
| 262 | mep.mepIdentifier(MepIdType.of(mepId.id())); |
| 263 | mep.addAugmentation(augmentedMep); |
| 264 | |
| 265 | |
| 266 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm.maintenancedomain |
| 267 | .MaintenanceAssociation yangMa = new DefaultMaintenanceAssociation(); |
| 268 | yangMa.id(maNumber); |
| 269 | yangMa.addToMaintenanceAssociationEndPoint(mep); |
| 270 | |
| 271 | org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 272 | .MaintenanceDomain yangMd = new DefaultMaintenanceDomain(); |
| 273 | yangMd.id(mdNumber); |
| 274 | yangMd.addToMaintenanceAssociation(yangMa); |
| 275 | |
| 276 | MefCfm mefCfm = new DefaultMefCfm(); |
| 277 | mefCfm.addToMaintenanceDomain(yangMd); |
| 278 | |
| 279 | MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam(); |
| 280 | mseaCfmOpParam.mefCfm(mefCfm); |
| 281 | |
| 282 | try { |
| 283 | mseaCfmService.setMseaCfm(mseaCfmOpParam, session, DatastoreId.RUNNING); |
| 284 | return Optional.empty(); |
| 285 | } catch (NetconfException e) { |
| 286 | log.error("Unable to create DM {}/{}/{} on device {}", |
| 287 | mdName, maName, mepId, handler().data().deviceId()); |
| 288 | throw new CfmConfigException("Unable to create DM :" + e.getMessage()); |
| 289 | } |
| 290 | |
| 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public void abortDm(MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 295 | throws CfmConfigException { |
| 296 | NetconfController controller = checkNotNull(handler().get(NetconfController.class)); |
| 297 | NetconfSession session = controller.getDevicesMap().get(handler().data() |
| 298 | .deviceId()).getSession(); |
| 299 | MseaCfmNetconfService mseaCfmService = checkNotNull(handler() |
| 300 | .get(MseaCfmNetconfService.class)); |
| 301 | CfmMdService cfmMdService = checkNotNull(handler().get(CfmMdService.class)); |
| 302 | |
| 303 | |
| 304 | org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.mefcfm.maintenancedomain |
| 305 | .maintenanceassociation.maintenanceassociationendpoint |
| 306 | .augmentedmseacfmmaintenanceassociationendpoint.delaymeasurements |
| 307 | .DelayMeasurement dm = new DefaultDelayMeasurement(); |
| 308 | dm.dmId(dmId.id().shortValue()); |
| 309 | |
| 310 | DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint augmentedMep = |
| 311 | new DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint(); |
| 312 | DelayMeasurements ddms = new DefaultDelayMeasurements(); |
| 313 | ddms.addToDelayMeasurement(dm); |
| 314 | augmentedMep.delayMeasurements(ddms); |
| 315 | |
| 316 | MaintenanceAssociationEndPoint mep = |
| 317 | new DefaultMaintenanceAssociationEndPoint(); |
| 318 | mep.mepIdentifier(MepIdType.of(mepId.id())); |
| 319 | mep.addAugmentation(augmentedMep); |
| 320 | |
| 321 | |
| 322 | short mdNumericId = cfmMdService.getMaintenanceDomain(mdName).get().mdNumericId(); |
| 323 | short maNumericId = cfmMdService |
| 324 | .getMaintenanceAssociation(mdName, maName).get().maNumericId(); |
| 325 | |
| 326 | DefaultMaintenanceAssociation yangMa = new DefaultMaintenanceAssociation(); |
| 327 | yangMa.id(maNumericId); |
| 328 | yangMa.addToMaintenanceAssociationEndPoint(mep); |
| 329 | |
| 330 | DefaultMaintenanceDomain yangMd = new DefaultMaintenanceDomain(); |
| 331 | yangMd.id(mdNumericId); |
| 332 | yangMd.addToMaintenanceAssociation(yangMa); |
| 333 | |
| 334 | MefCfm mefCfm = new DefaultMefCfm(); |
| 335 | mefCfm.addToMaintenanceDomain(yangMd); |
| 336 | |
| 337 | MseaCfmOpParam mseaCfmOpParam = new MseaCfmOpParam(); |
| 338 | mseaCfmOpParam.mefCfm(mefCfm); |
| 339 | |
| 340 | try { |
| 341 | mseaCfmService.deleteMseaCfmDm(mseaCfmOpParam, session, DatastoreId.RUNNING); |
| 342 | } catch (NetconfException e) { |
| 343 | log.error("Unable to delete DM {}/{}/{}/{} on device {}", |
| 344 | mdName, maName, mepId, dm.dmId(), handler().data().deviceId()); |
| 345 | throw new CfmConfigException("Unable to delete DM :" + e.getMessage()); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public void abortDm(MdId mdName, MaIdShort maName, MepId mepId) |
| 351 | throws CfmConfigException { |
| 352 | throw new UnsupportedOperationException("Not yet implemented"); |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public void clearDelayHistoryStats(MdId mdName, MaIdShort maName, |
| 357 | MepId mepId) throws CfmConfigException { |
| 358 | throw new UnsupportedOperationException("Not yet implemented"); |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void clearDelayHistoryStats(MdId mdName, MaIdShort maName, |
| 363 | MepId mepId, SoamId dmId) throws CfmConfigException { |
| 364 | throw new UnsupportedOperationException("Not yet implemented"); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public Collection<LossMeasurementEntry> getAllLms(MdId mdName, |
| 369 | MaIdShort maName, MepId mepId) throws CfmConfigException { |
| 370 | throw new UnsupportedOperationException("Not yet implemented"); |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public LossMeasurementEntry getLm(MdId mdName, MaIdShort maName, |
| 375 | MepId mepId, SoamId lmId) throws CfmConfigException { |
| 376 | throw new UnsupportedOperationException("Not yet implemented"); |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public LossMeasurementStatCurrent getLmCurrentStat(MdId mdName, |
| 381 | MaIdShort maName, MepId mepId, SoamId lmId) { |
| 382 | throw new UnsupportedOperationException("Not yet implemented"); |
| 383 | } |
| 384 | |
| 385 | @Override |
| 386 | public Collection<LossMeasurementStatCurrent> getLmHistoricalStats( |
| 387 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) { |
| 388 | throw new UnsupportedOperationException("Not yet implemented"); |
| 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public Optional<SoamId> createLm(MdId mdName, MaIdShort maName, MepId mepId, |
| 393 | LossMeasurementCreate lm) throws CfmConfigException { |
| 394 | throw new UnsupportedOperationException("Not yet implemented"); |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public void abortLm(MdId mdName, MaIdShort maName, MepId mepId) |
| 399 | throws CfmConfigException { |
| 400 | throw new UnsupportedOperationException("Not yet implemented"); |
| 401 | } |
| 402 | |
| 403 | @Override |
| 404 | public void abortLm(MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 405 | throws CfmConfigException { |
| 406 | throw new UnsupportedOperationException("Not yet implemented"); |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public void clearLossHistoryStats(MdId mdName, MaIdShort maName, |
| 411 | MepId mepId) throws CfmConfigException { |
| 412 | throw new UnsupportedOperationException("Not yet implemented"); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public void clearLossHistoryStats(MdId mdName, MaIdShort maName, |
| 417 | MepId mepId, SoamId lmId) throws CfmConfigException { |
| 418 | throw new UnsupportedOperationException("Not yet implemented"); |
| 419 | } |
| 420 | |
| 421 | @Override |
| 422 | public void createTestSignal(MdId mdName, MaIdShort maName, MepId mepId, |
| 423 | MepTsCreate tsCreate) throws CfmConfigException { |
| 424 | throw new UnsupportedOperationException("Not supported by EA1000"); |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public void abortTestSignal(MdId mdName, MaIdShort maName, MepId mepId) |
| 429 | throws CfmConfigException { |
| 430 | throw new UnsupportedOperationException("Not supported by EA1000"); |
| 431 | } |
| 432 | |
| 433 | private static DelayMeasurementEntry buildApiDmFromYangDm(DelayMeasurement dm, |
| 434 | MdId mdName, MaIdShort maName, MepId mepId) |
| 435 | throws SoamConfigException, CfmConfigException { |
| 436 | |
| 437 | org.onosproject.yang.gen.v1.mseasoampm.rev20160229.mseasoampm.remotemepgroup.remotemep |
| 438 | .MepId rmep = MepIdUtil.convertRemoteMepId(dm.remoteMep()); |
| 439 | |
| 440 | DmEntryBuilder dmBuilder = (DmEntryBuilder) DefaultDelayMeasurementEntry.builder( |
| 441 | SoamId.valueOf(dm.dmId()), DmType.DMDMM, Version.Y17312011, |
| 442 | MepId.valueOf((short) ((MepIdType) rmep.mepId()).uint16()), |
| 443 | Priority.values()[dm.priority().uint8()]); |
| 444 | if (dm.sessionStatus() != null) { |
| 445 | dmBuilder = dmBuilder.sessionStatus(SessionStatus.valueOf( |
| 446 | dm.sessionStatus().enumeration().name())); |
| 447 | } |
| 448 | |
| 449 | if (dm.frameDelayTwoWay() != null) { |
| 450 | dmBuilder = dmBuilder.frameDelayTwoWay(Duration.ofNanos( |
| 451 | dm.frameDelayTwoWay().uint32() * 1000)); |
| 452 | } |
| 453 | if (dm.interFrameDelayVariationTwoWay() != null) { |
| 454 | dmBuilder = dmBuilder.interFrameDelayVariationTwoWay(Duration.ofNanos( |
| 455 | dm.interFrameDelayVariationTwoWay().uint32() * 1000)); |
| 456 | } |
| 457 | |
| 458 | if (dm.frameSize() != 0) { |
| 459 | dmBuilder = (DmEntryBuilder) dmBuilder.frameSize((short) dm.frameSize()); |
| 460 | } |
| 461 | |
| 462 | if (dm.messagePeriod() != null) { |
| 463 | switch (dm.messagePeriod()) { |
| 464 | case YANGAUTOPREFIX1000MS: |
| 465 | dmBuilder = (DmEntryBuilder) dmBuilder.messagePeriod(Duration.ofMillis(1000)); |
| 466 | break; |
| 467 | case YANGAUTOPREFIX100MS: |
| 468 | dmBuilder = (DmEntryBuilder) dmBuilder.messagePeriod(Duration.ofMillis(100)); |
| 469 | break; |
| 470 | case YANGAUTOPREFIX10MS: |
| 471 | dmBuilder = (DmEntryBuilder) dmBuilder.messagePeriod(Duration.ofMillis(10)); |
| 472 | break; |
| 473 | case YANGAUTOPREFIX3MS: |
| 474 | dmBuilder = (DmEntryBuilder) dmBuilder.messagePeriod(Duration.ofMillis(3)); |
| 475 | break; |
| 476 | default: |
| 477 | throw new SoamConfigException("EA1000 supports only 1000," |
| 478 | + "100, 10 and 3ms for Message Period on DM"); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | Collection<MeasurementOption> moSet = |
| 483 | EA1000SoamDmProgrammable.getMeasurementOptions(dm.measurementEnable()); |
| 484 | moSet.forEach(dmBuilder::addToMeasurementsEnabled); |
| 485 | |
| 486 | dmBuilder = dmBuilder |
| 487 | .currentResult(buildApiDmCurrFromYangDmCurr(dm, mdName, maName, mepId)); |
| 488 | |
| 489 | for (DelayMeasurementStatHistory historyStat: |
| 490 | buildApiDmHistFromYangDm(dm, mdName, maName, mepId)) { |
| 491 | dmBuilder = dmBuilder.addToHistoricalResults(historyStat); |
| 492 | } |
| 493 | |
| 494 | return dmBuilder.build(); |
| 495 | } |
| 496 | |
| 497 | private static Collection<DelayMeasurementStatHistory> buildApiDmHistFromYangDm( |
| 498 | DelayMeasurement dm, MdId mdName, MaIdShort maName, MepId mepId) |
| 499 | throws SoamConfigException, CfmConfigException { |
| 500 | |
| 501 | Collection<DelayMeasurementStatHistory> historyStatsCollection = new ArrayList<>(); |
| 502 | if (dm.historyStats() != null) { |
| 503 | for (HistoryStats dmHistory:dm.historyStats()) { |
| 504 | DmStatHistoryBuilder historyBuilder = |
| 505 | DefaultDelayMeasurementStatHistory.builder( |
| 506 | SoamId.valueOf((int) dmHistory.id()), |
| 507 | Duration.ofMillis(dmHistory.elapsedTime() * 10), //Values are in 1/100th sec |
| 508 | dmHistory.suspectStatus() != null ? |
| 509 | dmHistory.suspectStatus().yangAutoPrefixBoolean() : false); |
| 510 | historyBuilder = historyBuilder.endTime( |
| 511 | IetfYangTypesUtils.fromYangDateTimeToInstant(dmHistory.endTime())); |
| 512 | |
| 513 | if (dmHistory.frameDelayTwoWayMin() != null) { |
| 514 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 515 | .frameDelayTwoWayMin(Duration.ofNanos(dmHistory.frameDelayTwoWayMin().uint32() * 1000)); |
| 516 | } |
| 517 | |
| 518 | if (dmHistory.frameDelayTwoWayMax() != null) { |
| 519 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 520 | .frameDelayTwoWayMax(Duration.ofNanos(dmHistory.frameDelayTwoWayMax().uint32() * 1000)); |
| 521 | } |
| 522 | |
| 523 | if (dmHistory.frameDelayTwoWayAverage() != null) { |
| 524 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 525 | .frameDelayTwoWayAvg(Duration.ofNanos(dmHistory.frameDelayTwoWayAverage().uint32() * 1000)); |
| 526 | } |
| 527 | |
| 528 | if (dmHistory.interFrameDelayVariationTwoWayMin() != null) { |
| 529 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 530 | .interFrameDelayVariationTwoWayMin(Duration.ofNanos( |
| 531 | dmHistory.interFrameDelayVariationTwoWayMin().uint32() * 1000)); |
| 532 | } |
| 533 | |
| 534 | if (dmHistory.interFrameDelayVariationTwoWayMax() != null) { |
| 535 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 536 | .interFrameDelayVariationTwoWayMax(Duration.ofNanos( |
| 537 | dmHistory.interFrameDelayVariationTwoWayMax().uint32() * 1000)); |
| 538 | } |
| 539 | |
| 540 | if (dmHistory.interFrameDelayVariationTwoWayAverage() != null) { |
| 541 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 542 | .interFrameDelayVariationTwoWayAvg(Duration.ofNanos( |
| 543 | dmHistory.interFrameDelayVariationTwoWayAverage().uint32() * 1000)); |
| 544 | } |
| 545 | |
| 546 | if (dmHistory.soamPdusReceived() != null) { |
| 547 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 548 | .soamPdusReceived(Integer.valueOf((int) dmHistory.soamPdusReceived().uint32())); |
| 549 | } |
| 550 | |
| 551 | if (dmHistory.bins() != null && dmHistory.bins().frameDelay() != null) { |
| 552 | Map<Duration, Integer> frameDelayTwoWayBins = new HashMap<>(); |
| 553 | for (FrameDelay fdBin:dmHistory.bins().frameDelay()) { |
| 554 | frameDelayTwoWayBins.put( |
| 555 | Duration.ofNanos(fdBin.lowerBound().uint32() * 1000), |
| 556 | Integer.valueOf((int) fdBin.counter().uint32())); |
| 557 | } |
| 558 | historyBuilder = (DmStatHistoryBuilder) historyBuilder |
| 559 | .frameDelayTwoWayBins(frameDelayTwoWayBins); |
| 560 | } |
| 561 | |
| 562 | if (dmHistory.bins() != null && dmHistory.bins().interFrameDelayVariation() != null) { |
| 563 | Map<Duration, Integer> ifdvTwoWayBins = new HashMap<>(); |
| 564 | for (InterFrameDelayVariation ifdvBin:dmHistory.bins().interFrameDelayVariation()) { |
| 565 | ifdvTwoWayBins.put( |
| 566 | Duration.ofNanos(ifdvBin.lowerBound().uint32() * 1000), |
| 567 | Integer.valueOf((int) ifdvBin.counter().uint32())); |
| 568 | } |
| 569 | historyBuilder = |
| 570 | (DmStatHistoryBuilder) historyBuilder.interFrameDelayVariationTwoWayBins(ifdvTwoWayBins); |
| 571 | } |
| 572 | |
| 573 | historyStatsCollection.add((DelayMeasurementStatHistory) historyBuilder.build()); |
| 574 | } |
| 575 | } |
| 576 | return historyStatsCollection; |
| 577 | } |
| 578 | |
| 579 | private static DelayMeasurementStatCurrent buildApiDmCurrFromYangDmCurr( |
| 580 | DelayMeasurement dm, MdId mdName, MaIdShort maName, MepId mepId) |
| 581 | throws SoamConfigException, CfmConfigException { |
| 582 | if (dm == null || dm.currentStats() == null || mdName == null || |
| 583 | maName == null || mepId == null) { |
| 584 | return null; |
| 585 | } |
| 586 | |
| 587 | DmStatCurrentBuilder statCurrBuilder = |
| 588 | DefaultDelayMeasurementStatCurrent.builder( |
| 589 | Duration.ofMillis(dm.currentStats().elapsedTime() * 10), //Values are in 1/100th sec |
| 590 | dm.currentStats().suspectStatus() != null ? |
| 591 | dm.currentStats().suspectStatus().yangAutoPrefixBoolean() : false); |
| 592 | statCurrBuilder = statCurrBuilder.startTime( |
| 593 | IetfYangTypesUtils.fromYangDateTimeToInstant(dm.currentStats().startTime())); |
| 594 | |
| 595 | if (dm.currentStats().frameDelayTwoWayMin() != null) { |
| 596 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder |
| 597 | .frameDelayTwoWayMin(Duration.ofNanos( |
| 598 | dm.currentStats().frameDelayTwoWayMin().uint32() * 1000)); |
| 599 | } |
| 600 | |
| 601 | if (dm.currentStats().frameDelayTwoWayMax() != null) { |
| 602 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder |
| 603 | .frameDelayTwoWayMax(Duration.ofNanos( |
| 604 | dm.currentStats().frameDelayTwoWayMax().uint32() * 1000)); |
| 605 | } |
| 606 | |
| 607 | if (dm.currentStats().frameDelayTwoWayAverage() != null) { |
| 608 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder |
| 609 | .frameDelayTwoWayAvg(Duration.ofNanos( |
| 610 | dm.currentStats().frameDelayTwoWayAverage().uint32() * 1000)); |
| 611 | } |
| 612 | |
| 613 | if (dm.currentStats().interFrameDelayVariationTwoWayMin() != null) { |
| 614 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder |
| 615 | .interFrameDelayVariationTwoWayMin(Duration.ofNanos( |
| 616 | dm.currentStats().interFrameDelayVariationTwoWayMin().uint32() * 1000)); |
| 617 | } |
| 618 | |
| 619 | if (dm.currentStats().interFrameDelayVariationTwoWayMax() != null) { |
| 620 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder |
| 621 | .interFrameDelayVariationTwoWayMax(Duration.ofNanos( |
| 622 | dm.currentStats().interFrameDelayVariationTwoWayMax().uint32() * 1000)); |
| 623 | } |
| 624 | |
| 625 | if (dm.currentStats().interFrameDelayVariationTwoWayAverage() != null) { |
| 626 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder |
| 627 | .interFrameDelayVariationTwoWayAvg(Duration.ofNanos( |
| 628 | dm.currentStats().interFrameDelayVariationTwoWayAverage().uint32() * 1000)); |
| 629 | } |
| 630 | |
| 631 | if (dm.currentStats().soamPdusReceived() != null) { |
| 632 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder |
| 633 | .soamPdusReceived(Integer.valueOf((int) dm.currentStats().soamPdusReceived().uint32())); |
| 634 | } |
| 635 | |
| 636 | if (dm.currentStats().bins() != null && dm.currentStats().bins().frameDelay() != null) { |
| 637 | Map<Duration, Integer> frameDelayTwoWayBins = new HashMap<>(); |
| 638 | for (FrameDelay fdBin:dm.currentStats().bins().frameDelay()) { |
| 639 | frameDelayTwoWayBins.put( |
| 640 | Duration.ofNanos(fdBin.lowerBound().uint32() * 1000), |
| 641 | Integer.valueOf((int) fdBin.counter().uint32())); |
| 642 | } |
| 643 | statCurrBuilder = (DmStatCurrentBuilder) statCurrBuilder.frameDelayTwoWayBins(frameDelayTwoWayBins); |
| 644 | } |
| 645 | |
| 646 | if (dm.currentStats().bins() != null && dm.currentStats().bins().interFrameDelayVariation() != null) { |
| 647 | Map<Duration, Integer> ifdvTwoWayBins = new HashMap<>(); |
| 648 | for (InterFrameDelayVariation ifdvBin:dm.currentStats().bins().interFrameDelayVariation()) { |
| 649 | ifdvTwoWayBins.put( |
| 650 | Duration.ofNanos(ifdvBin.lowerBound().uint32() * 1000), |
| 651 | Integer.valueOf((int) ifdvBin.counter().uint32())); |
| 652 | } |
| 653 | statCurrBuilder = |
| 654 | (DmStatCurrentBuilder) statCurrBuilder.interFrameDelayVariationTwoWayBins(ifdvTwoWayBins); |
| 655 | } |
| 656 | |
| 657 | return (DelayMeasurementStatCurrent) statCurrBuilder.build(); |
| 658 | } |
| 659 | |
| 660 | private Collection<DelayMeasurementEntry> getAllDmsOrOneDm( |
| 661 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId, DmEntryParts parts) |
| 662 | throws CfmConfigException, SoamConfigException { |
| 663 | NetconfController controller = |
| 664 | checkNotNull(handler().get(NetconfController.class)); |
| 665 | NetconfSession session = |
| 666 | controller.getDevicesMap().get(handler().data().deviceId()).getSession(); |
| 667 | MseaCfmNetconfService mseaCfmService = |
| 668 | checkNotNull(handler().get(MseaCfmNetconfService.class)); |
| 669 | |
| 670 | Collection<DelayMeasurementEntry> dmResults = new ArrayList<>(); |
| 671 | try { |
| 672 | MseaCfm mseacfm = |
| 673 | mseaCfmService.getSoamDm(mdName, maName, mepId, dmId, parts, session); |
| 674 | for (org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm.mefcfm |
| 675 | .MaintenanceDomain replyMd:mseacfm.mefCfm().maintenanceDomain()) { |
| 676 | for (org.onosproject.yang.gen.v1.mseacfm.rev20160229.mseacfm |
| 677 | .mefcfm.maintenancedomain.MaintenanceAssociation replyMa: |
| 678 | replyMd.maintenanceAssociation()) { |
| 679 | for (MaintenanceAssociationEndPoint replyMep: |
| 680 | replyMa.maintenanceAssociationEndPoint()) { |
| 681 | AugmentedMseaCfmMaintenanceAssociationEndPoint augmentedMep = |
| 682 | replyMep.augmentation( |
| 683 | DefaultAugmentedMseaCfmMaintenanceAssociationEndPoint.class); |
| 684 | if (augmentedMep == null || |
| 685 | augmentedMep.delayMeasurements() == null || |
| 686 | augmentedMep.delayMeasurements() |
| 687 | .delayMeasurement().isEmpty()) { |
| 688 | log.info("No Delay Measurements retrieved from MEP " + |
| 689 | mdName + "/" + maName + "/" + mepId); |
| 690 | } else { |
| 691 | for (org.onosproject.yang.gen.v1.mseasoampm.rev20160229 |
| 692 | .mseasoampm.mefcfm.maintenancedomain.maintenanceassociation |
| 693 | .maintenanceassociationendpoint |
| 694 | .augmentedmseacfmmaintenanceassociationendpoint |
| 695 | .delaymeasurements.DelayMeasurement dm |
| 696 | :augmentedMep.delayMeasurements().delayMeasurement()) { |
| 697 | dmResults.add(buildApiDmFromYangDm(dm, mdName, maName, mepId)); |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | return dmResults; |
| 704 | } catch (NetconfException e) { |
| 705 | log.error("Unable to get MEP {}/{}/{} on device {}", |
| 706 | mdName, maName, mepId, handler().data().deviceId()); |
| 707 | throw new CfmConfigException("Unable to create MEP :" + e.getMessage()); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | |
| 712 | protected static BitSet getMeasurementEnabledSet( |
| 713 | Collection<MeasurementOption> measEnabled) throws SoamConfigException { |
| 714 | BitSet measurementEnable = new BitSet(); |
| 715 | try { |
| 716 | measEnabled.forEach(mo -> { |
| 717 | MeasurementEnable me = MeasurementEnable.valueOf(mo.name()); |
| 718 | measurementEnable.set(me.measurementEnable()); |
| 719 | }); |
| 720 | } catch (IllegalArgumentException e) { |
| 721 | throw new SoamConfigException( |
| 722 | "Measurement Option is not supported on EA1000: ", e); |
| 723 | } |
| 724 | |
| 725 | return measurementEnable; |
| 726 | } |
| 727 | |
| 728 | protected static Collection<MeasurementOption> getMeasurementOptions(BitSet meBs) { |
| 729 | Collection<MeasurementOption> meList = new ArrayList<>(); |
| 730 | if (meBs != null && !meBs.isEmpty()) { |
| 731 | for (int i = 0; i < meBs.size(); i++) { |
| 732 | if (meBs.get(i)) { |
| 733 | meList.add(MeasurementOption.valueOf(MeasurementEnable.of(i).name())); |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | return meList; |
| 739 | } |
| 740 | } |