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