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 java.util.Collection; |
| 19 | import java.util.Optional; |
| 20 | |
| 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | import org.apache.felix.scr.annotations.Service; |
| 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.core.CoreService; |
| 29 | import org.onosproject.incubator.net.l2monitoring.cfm.MepEntry; |
| 30 | import org.onosproject.incubator.net.l2monitoring.cfm.MepTsCreate; |
| 31 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort; |
| 32 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 33 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
| 34 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 35 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService; |
| 36 | import org.onosproject.incubator.net.l2monitoring.soam.SoamConfigException; |
| 37 | import org.onosproject.incubator.net.l2monitoring.soam.SoamDmProgrammable; |
| 38 | import org.onosproject.incubator.net.l2monitoring.soam.SoamId; |
| 39 | import org.onosproject.incubator.net.l2monitoring.soam.SoamService; |
| 40 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementCreate; |
| 41 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementEntry; |
| 42 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatCurrent; |
| 43 | import org.onosproject.incubator.net.l2monitoring.soam.delay.DelayMeasurementStatHistory; |
| 44 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementCreate; |
| 45 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementEntry; |
| 46 | import org.onosproject.incubator.net.l2monitoring.soam.loss.LossMeasurementStatCurrent; |
| 47 | import org.onosproject.net.DeviceId; |
| 48 | import org.onosproject.net.device.DeviceService; |
| 49 | import org.slf4j.Logger; |
| 50 | import org.slf4j.LoggerFactory; |
| 51 | |
| 52 | /** |
| 53 | * ONOS application component. |
| 54 | */ |
| 55 | @Component(immediate = true) |
| 56 | @Service |
| 57 | public class SoamManager implements SoamService { |
| 58 | |
| 59 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 60 | private static final String APP_ID = "org.onosproject.app.soam"; |
| 61 | |
| 62 | private ApplicationId appId; |
| 63 | |
| 64 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 65 | protected DeviceService deviceService; |
| 66 | |
| 67 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 68 | protected CoreService coreService; |
| 69 | |
| 70 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 71 | protected CfmMepService cfmMepService; |
| 72 | |
| 73 | @Activate |
| 74 | protected void activate() { |
| 75 | appId = coreService.registerApplication(APP_ID); |
| 76 | |
| 77 | log.info("SOAM Service Started"); |
| 78 | } |
| 79 | |
| 80 | @Deactivate |
| 81 | protected void deactivate() { |
| 82 | log.info("SOAM Service Stopped"); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Collection<DelayMeasurementEntry> getAllDms( |
| 87 | MdId mdName, MaIdShort maName, MepId mepId) |
| 88 | throws CfmConfigException, SoamConfigException { |
| 89 | MepEntry mep = cfmMepService.getMep(mdName, maName, mepId); |
Sean Condon | 085621b | 2017-10-29 23:27:32 +0000 | [diff] [blame] | 90 | if (mep == null || mep.deviceId() == null) { |
| 91 | throw new CfmConfigException("MEP :" |
| 92 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 93 | } else if (deviceService.getDevice(mep.deviceId()) == null) { |
| 94 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 95 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 96 | } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) { |
| 97 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 98 | + mdName + "/" + maName + "/" + mepId + |
| 99 | " does not implement SoamDmProgrammable"); |
| 100 | } |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 101 | log.debug("Retrieving DMs for MD {}, MA {}, MEP {} on Device {}", |
| 102 | mdName, maName, mepId, mep.deviceId()); |
Sean Condon | 085621b | 2017-10-29 23:27:32 +0000 | [diff] [blame] | 103 | |
| 104 | return deviceService.getDevice(mep.deviceId()) |
| 105 | .as(SoamDmProgrammable.class).getAllDms(mdName, maName, mepId); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | @Override |
| 109 | public DelayMeasurementEntry getDm(MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 110 | throws CfmConfigException, SoamConfigException { |
| 111 | MepEntry mep = cfmMepService.getMep(mdName, maName, mepId); |
| 112 | if (mep == null || mep.deviceId() == null) { |
| 113 | throw new CfmConfigException("MEP :" |
| 114 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 115 | } else if (deviceService.getDevice(mep.deviceId()) == null) { |
| 116 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 117 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 118 | } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) { |
| 119 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 120 | + mdName + "/" + maName + "/" + mepId + |
| 121 | " does not implement SoamDmProgrammable"); |
| 122 | } |
| 123 | log.debug("Retrieving DM for DM {} in MD {}, MA {}, MEP {} on Device {}", |
| 124 | dmId, mdName, maName, mepId, mep.deviceId()); |
| 125 | return deviceService.getDevice(mep.deviceId()) |
| 126 | .as(SoamDmProgrammable.class).getDm(mdName, maName, mepId, dmId); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public DelayMeasurementStatCurrent getDmCurrentStat(MdId mdName, |
| 131 | MaIdShort maName, MepId mepId, SoamId dmId) |
| 132 | throws CfmConfigException, SoamConfigException { |
| 133 | MepEntry mep = cfmMepService.getMep(mdName, maName, mepId); |
| 134 | if (mep == null || mep.deviceId() == null) { |
| 135 | throw new CfmConfigException("MEP :" |
| 136 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 137 | } else if (deviceService.getDevice(mep.deviceId()) == null) { |
| 138 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 139 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 140 | } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) { |
| 141 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 142 | + mdName + "/" + maName + "/" + mepId + |
| 143 | " does not implement SoamDmProgrammable"); |
| 144 | } |
| 145 | log.debug("Retrieving Current Stats for DM {} in MD {}, MA {}, MEP {} " |
| 146 | + "on Device {}", dmId, mdName, maName, mepId, mep.deviceId()); |
| 147 | return deviceService.getDevice(mep.deviceId()) |
| 148 | .as(SoamDmProgrammable.class).getDmCurrentStat(mdName, maName, mepId, dmId); |
| 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public Collection<DelayMeasurementStatHistory> getDmHistoricalStats( |
| 153 | MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 154 | throws SoamConfigException, CfmConfigException { |
| 155 | MepEntry mep = cfmMepService.getMep(mdName, maName, mepId); |
| 156 | if (mep == null || mep.deviceId() == null) { |
| 157 | throw new CfmConfigException("MEP :" |
| 158 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 159 | } else if (deviceService.getDevice(mep.deviceId()) == null) { |
| 160 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 161 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 162 | } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) { |
| 163 | throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :" |
| 164 | + mdName + "/" + maName + "/" + mepId + |
| 165 | " does not implement SoamDmProgrammable"); |
| 166 | } |
| 167 | log.debug("Retrieving History Stats for DM {} in MD {}, MA {}, MEP {} " |
| 168 | + "on Device {}", dmId, mdName, maName, mepId, mep.deviceId()); |
| 169 | return deviceService.getDevice(mep.deviceId()) |
| 170 | .as(SoamDmProgrammable.class).getDmHistoricalStats(mdName, maName, mepId, dmId); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public Optional<SoamId> createDm(MdId mdName, MaIdShort maName, MepId mepId, |
| 175 | DelayMeasurementCreate dmNew) |
| 176 | throws CfmConfigException, SoamConfigException { |
| 177 | DeviceId mepDeviceId = cfmMepService.getMep(mdName, maName, mepId).deviceId(); |
| 178 | if (mepDeviceId == null) { |
| 179 | throw new CfmConfigException("Unable to create DM. MEP :" |
| 180 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 181 | } else if (deviceService.getDevice(mepDeviceId) == null) { |
| 182 | throw new CfmConfigException("Device " + mepDeviceId + " from MEP :" |
| 183 | + mdName + "/" + maName + "/" + mepId + " does not exist"); |
| 184 | } else if (!deviceService.getDevice(mepDeviceId).is(SoamDmProgrammable.class)) { |
| 185 | throw new CfmConfigException("Device " + mepDeviceId + " from MEP :" |
| 186 | + mdName + "/" + maName + "/" + mepId + |
| 187 | " does not implement SoamDmProgrammable"); |
| 188 | } |
| 189 | log.debug("Creating new DM in MD {}, MA {}, MEP {} on Device {}", |
| 190 | mdName, maName, mepId, mepDeviceId); |
| 191 | return deviceService.getDevice(mepDeviceId) |
| 192 | .as(SoamDmProgrammable.class).createDm(mdName, maName, mepId, dmNew); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void abortDm(MdId mdName, MaIdShort maName, MepId mepId) |
| 197 | throws CfmConfigException { |
| 198 | throw new UnsupportedOperationException("Not yet implemented"); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public void abortDm(MdId mdName, MaIdShort maName, MepId mepId, SoamId dmId) |
| 203 | throws CfmConfigException { |
| 204 | throw new UnsupportedOperationException("Not yet implemented"); |
| 205 | } |
| 206 | |
| 207 | @Override |
| 208 | public void clearDelayHistoryStats(MdId mdName, MaIdShort maName, |
| 209 | MepId mepId) throws CfmConfigException { |
| 210 | throw new UnsupportedOperationException("Not yet implemented"); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void clearDelayHistoryStats(MdId mdName, MaIdShort maName, |
| 215 | MepId mepId, SoamId dmId) throws CfmConfigException { |
| 216 | throw new UnsupportedOperationException("Not yet implemented"); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public Collection<LossMeasurementEntry> getAllLms(MdId mdName, |
| 221 | MaIdShort maName, MepId mepId) throws CfmConfigException { |
| 222 | throw new UnsupportedOperationException("Not yet implemented"); |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public LossMeasurementEntry getLm(MdId mdName, MaIdShort maName, |
| 227 | MepId mepId, SoamId lmId) throws CfmConfigException { |
| 228 | throw new UnsupportedOperationException("Not yet implemented"); |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public LossMeasurementStatCurrent getLmCurrentStat(MdId mdName, |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 233 | MaIdShort maName, MepId mepId, SoamId lmId) { |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 234 | throw new UnsupportedOperationException("Not yet implemented"); |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public Collection<LossMeasurementStatCurrent> getLmHistoricalStats( |
| 239 | MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) { |
| 240 | throw new UnsupportedOperationException("Not yet implemented"); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public Optional<SoamId> createLm(MdId mdName, MaIdShort maName, MepId mepId, |
| 245 | LossMeasurementCreate lm) throws CfmConfigException { |
| 246 | throw new UnsupportedOperationException("Not yet implemented"); |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public void abortLm(MdId mdName, MaIdShort maName, MepId mepId) |
| 251 | throws CfmConfigException { |
| 252 | throw new UnsupportedOperationException("Not yet implemented"); |
| 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public void abortLm(MdId mdName, MaIdShort maName, MepId mepId, SoamId lmId) |
| 257 | throws CfmConfigException { |
| 258 | throw new UnsupportedOperationException("Not yet implemented"); |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public void clearLossHistoryStats(MdId mdName, MaIdShort maName, |
| 263 | MepId mepId) throws CfmConfigException { |
| 264 | throw new UnsupportedOperationException("Not yet implemented"); |
| 265 | } |
| 266 | |
| 267 | @Override |
| 268 | public void clearLossHistoryStats(MdId mdName, MaIdShort maName, |
| 269 | MepId mepId, SoamId lmId) throws CfmConfigException { |
| 270 | throw new UnsupportedOperationException("Not yet implemented"); |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public void createTestSignal(MdId mdName, MaIdShort maName, MepId mepId, |
| 275 | MepTsCreate tsCreate) throws CfmConfigException { |
| 276 | throw new UnsupportedOperationException("Not yet implemented"); |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void abortTestSignal(MdId mdName, MaIdShort maName, MepId mepId) |
| 281 | throws CfmConfigException { |
| 282 | throw new UnsupportedOperationException("Not yet implemented"); |
| 283 | } |
| 284 | } |