alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.provider.of.meter.impl; |
| 18 | |
alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 19 | |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 20 | import com.google.common.cache.Cache; |
| 21 | import com.google.common.cache.CacheBuilder; |
| 22 | import com.google.common.cache.RemovalCause; |
| 23 | import com.google.common.cache.RemovalNotification; |
Yuta HIGUCHI | 67f2cca | 2017-01-19 19:31:58 -0800 | [diff] [blame^] | 24 | import com.google.common.collect.ImmutableSet; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 25 | import com.google.common.collect.Maps; |
| 26 | import org.apache.felix.scr.annotations.Activate; |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 27 | import org.apache.felix.scr.annotations.Component; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 28 | import org.apache.felix.scr.annotations.Deactivate; |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 29 | import org.apache.felix.scr.annotations.Reference; |
| 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 31 | import org.onosproject.core.CoreService; |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 32 | import org.onosproject.net.meter.Band; |
| 33 | import org.onosproject.net.meter.DefaultBand; |
| 34 | import org.onosproject.net.meter.DefaultMeter; |
| 35 | import org.onosproject.net.meter.Meter; |
| 36 | import org.onosproject.net.meter.MeterFailReason; |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 37 | import org.onosproject.net.meter.MeterId; |
alshabib | 10c810b | 2015-08-18 16:59:04 -0700 | [diff] [blame] | 38 | import org.onosproject.net.meter.MeterOperation; |
| 39 | import org.onosproject.net.meter.MeterOperations; |
| 40 | import org.onosproject.net.meter.MeterProvider; |
| 41 | import org.onosproject.net.meter.MeterProviderRegistry; |
| 42 | import org.onosproject.net.meter.MeterProviderService; |
| 43 | import org.onosproject.net.meter.MeterState; |
Yuta HIGUCHI | 67f2cca | 2017-01-19 19:31:58 -0800 | [diff] [blame^] | 44 | import org.onosproject.net.Device; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 45 | import org.onosproject.net.DeviceId; |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 46 | import org.onosproject.net.provider.AbstractProvider; |
| 47 | import org.onosproject.net.provider.ProviderId; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 48 | import org.onosproject.openflow.controller.Dpid; |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 49 | import org.onosproject.openflow.controller.OpenFlowController; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 50 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
| 51 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 52 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
| 53 | import org.onosproject.openflow.controller.RoleState; |
| 54 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 55 | import org.projectfloodlight.openflow.protocol.OFErrorType; |
| 56 | import org.projectfloodlight.openflow.protocol.OFMessage; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 57 | import org.projectfloodlight.openflow.protocol.OFMeterBandStats; |
| 58 | import org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply; |
| 59 | import org.projectfloodlight.openflow.protocol.OFMeterStats; |
| 60 | import org.projectfloodlight.openflow.protocol.OFMeterStatsReply; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 61 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
| 62 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 63 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 64 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 65 | import org.projectfloodlight.openflow.protocol.errormsg.OFMeterModFailedErrorMsg; |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 66 | import org.slf4j.Logger; |
| 67 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 68 | import java.util.Collection; |
Yuta HIGUCHI | 67f2cca | 2017-01-19 19:31:58 -0800 | [diff] [blame^] | 69 | import java.util.EnumSet; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 70 | import java.util.List; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 71 | import java.util.Map; |
Yuta HIGUCHI | 67f2cca | 2017-01-19 19:31:58 -0800 | [diff] [blame^] | 72 | import java.util.Set; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 73 | import java.util.concurrent.TimeUnit; |
| 74 | import java.util.concurrent.atomic.AtomicLong; |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 75 | import java.util.stream.Collectors; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 76 | |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 77 | import static org.slf4j.LoggerFactory.getLogger; |
| 78 | |
| 79 | /** |
| 80 | * Provider which uses an OpenFlow controller to handle meters. |
| 81 | */ |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 82 | @Component(immediate = true, enabled = true) |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 83 | public class OpenFlowMeterProvider extends AbstractProvider implements MeterProvider { |
| 84 | |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 85 | |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 86 | private final Logger log = getLogger(getClass()); |
| 87 | |
| 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 89 | protected OpenFlowController controller; |
| 90 | |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 92 | protected MeterProviderRegistry providerRegistry; |
| 93 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 95 | protected CoreService coreService; |
| 96 | |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 97 | private MeterProviderService providerService; |
| 98 | |
| 99 | private static final AtomicLong XID_COUNTER = new AtomicLong(1); |
| 100 | |
| 101 | static final int POLL_INTERVAL = 10; |
| 102 | static final long TIMEOUT = 30; |
| 103 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 104 | private Cache<Long, MeterOperation> pendingOperations; |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 105 | |
| 106 | |
| 107 | private InternalMeterListener listener = new InternalMeterListener(); |
| 108 | private Map<Dpid, MeterStatsCollector> collectors = Maps.newHashMap(); |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 109 | |
Yuta HIGUCHI | 67f2cca | 2017-01-19 19:31:58 -0800 | [diff] [blame^] | 110 | private static final Set<Device.Type> NO_METER_SUPPORT = |
| 111 | ImmutableSet.copyOf(EnumSet.of(Device.Type.ROADM, |
| 112 | Device.Type.ROADM_OTN, |
| 113 | Device.Type.FIBER_SWITCH, |
| 114 | Device.Type.OTN)); |
| 115 | |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 116 | /** |
| 117 | * Creates a OpenFlow meter provider. |
| 118 | */ |
| 119 | public OpenFlowMeterProvider() { |
| 120 | super(new ProviderId("of", "org.onosproject.provider.meter")); |
| 121 | } |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 122 | |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 123 | @Activate |
| 124 | public void activate() { |
| 125 | providerService = providerRegistry.register(this); |
| 126 | |
| 127 | pendingOperations = CacheBuilder.newBuilder() |
| 128 | .expireAfterWrite(TIMEOUT, TimeUnit.SECONDS) |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 129 | .removalListener((RemovalNotification<Long, MeterOperation> notification) -> { |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 130 | if (notification.getCause() == RemovalCause.EXPIRED) { |
| 131 | providerService.meterOperationFailed(notification.getValue(), |
| 132 | MeterFailReason.TIMEOUT); |
| 133 | } |
| 134 | }).build(); |
| 135 | |
| 136 | controller.addEventListener(listener); |
| 137 | controller.addListener(listener); |
| 138 | |
| 139 | controller.getSwitches().forEach((sw -> createStatsCollection(sw))); |
| 140 | } |
| 141 | |
| 142 | @Deactivate |
| 143 | public void deactivate() { |
| 144 | providerRegistry.unregister(this); |
Charles Chan | ecfdfb7 | 2015-11-24 19:05:50 -0800 | [diff] [blame] | 145 | collectors.values().forEach(MeterStatsCollector::stop); |
| 146 | collectors.clear(); |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 147 | controller.removeEventListener(listener); |
| 148 | controller.removeListener(listener); |
| 149 | providerService = null; |
| 150 | } |
| 151 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 152 | @Override |
| 153 | public void performMeterOperation(DeviceId deviceId, MeterOperations meterOps) { |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 154 | Dpid dpid = Dpid.dpid(deviceId.uri()); |
| 155 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 156 | if (sw == null) { |
| 157 | log.error("Unknown device {}", deviceId); |
| 158 | meterOps.operations().forEach(op -> |
| 159 | providerService.meterOperationFailed(op, |
| 160 | MeterFailReason.UNKNOWN_DEVICE) |
| 161 | ); |
| 162 | return; |
| 163 | } |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 164 | |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 165 | meterOps.operations().forEach(op -> performOperation(sw, op)); |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void performMeterOperation(DeviceId deviceId, MeterOperation meterOp) { |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 170 | Dpid dpid = Dpid.dpid(deviceId.uri()); |
| 171 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 172 | if (sw == null) { |
| 173 | log.error("Unknown device {}", deviceId); |
| 174 | providerService.meterOperationFailed(meterOp, |
| 175 | MeterFailReason.UNKNOWN_DEVICE); |
| 176 | return; |
| 177 | } |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 178 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 179 | performOperation(sw, meterOp); |
| 180 | |
alshabib | bc37196 | 2015-07-09 22:26:21 -0700 | [diff] [blame] | 181 | } |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 182 | |
| 183 | private void performOperation(OpenFlowSwitch sw, MeterOperation op) { |
| 184 | |
| 185 | pendingOperations.put(op.meter().id().id(), op); |
| 186 | |
| 187 | |
| 188 | Meter meter = op.meter(); |
| 189 | MeterModBuilder builder = MeterModBuilder.builder(meter.id().id(), sw.factory()); |
| 190 | if (meter.isBurst()) { |
| 191 | builder.burst(); |
| 192 | } |
| 193 | builder.withBands(meter.bands()) |
| 194 | .withId(meter.id()) |
| 195 | .withRateUnit(meter.unit()); |
| 196 | |
| 197 | switch (op.type()) { |
| 198 | case ADD: |
| 199 | sw.sendMsg(builder.add()); |
| 200 | break; |
| 201 | case REMOVE: |
| 202 | sw.sendMsg(builder.remove()); |
| 203 | break; |
| 204 | case MODIFY: |
| 205 | sw.sendMsg(builder.modify()); |
| 206 | break; |
| 207 | default: |
| 208 | log.warn("Unknown Meter command {}; not sending anything", |
| 209 | op.type()); |
| 210 | providerService.meterOperationFailed(op, |
| 211 | MeterFailReason.UNKNOWN_COMMAND); |
| 212 | } |
| 213 | |
| 214 | } |
| 215 | |
| 216 | private void createStatsCollection(OpenFlowSwitch sw) { |
Madan Jampani | 84382b9 | 2016-06-22 08:26:49 -0700 | [diff] [blame] | 217 | if (sw != null && isMeterSupported(sw)) { |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 218 | MeterStatsCollector msc = new MeterStatsCollector(sw, POLL_INTERVAL); |
| 219 | msc.start(); |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 220 | stopCollectorIfNeeded(collectors.put(new Dpid(sw.getId()), msc)); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | private void stopCollectorIfNeeded(MeterStatsCollector collector) { |
| 225 | if (collector != null) { |
| 226 | collector.stop(); |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 230 | // TODO: ONOS-3546 Support per device enabling/disabling via network config |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 231 | private boolean isMeterSupported(OpenFlowSwitch sw) { |
| 232 | if (sw.factory().getVersion() == OFVersion.OF_10 || |
| 233 | sw.factory().getVersion() == OFVersion.OF_11 || |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 234 | sw.factory().getVersion() == OFVersion.OF_12 || |
Yuta HIGUCHI | 67f2cca | 2017-01-19 19:31:58 -0800 | [diff] [blame^] | 235 | NO_METER_SUPPORT.contains(sw.deviceType()) || |
Charles Chan | 14967c2 | 2015-12-07 11:11:50 -0800 | [diff] [blame] | 236 | sw.softwareDescription().equals("OF-DPA 2.0")) { |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 237 | return false; |
| 238 | } |
| 239 | |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | private void pushMeterStats(Dpid dpid, OFStatsReply msg) { |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 244 | DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 245 | |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 246 | if (msg.getStatsType() == OFStatsType.METER) { |
| 247 | OFMeterStatsReply reply = (OFMeterStatsReply) msg; |
| 248 | Collection<Meter> meters = buildMeters(deviceId, reply.getEntries()); |
| 249 | //TODO do meter accounting here. |
| 250 | providerService.pushMeterMetrics(deviceId, meters); |
| 251 | } else if (msg.getStatsType() == OFStatsType.METER_CONFIG) { |
| 252 | OFMeterConfigStatsReply reply = (OFMeterConfigStatsReply) msg; |
| 253 | // FIXME: Map<Long, Meter> meters = collectMeters(deviceId, reply); |
| 254 | } |
| 255 | |
| 256 | } |
| 257 | |
| 258 | private Map<Long, Meter> collectMeters(DeviceId deviceId, |
| 259 | OFMeterConfigStatsReply reply) { |
| 260 | return Maps.newHashMap(); |
| 261 | //TODO: Needs a fix to be applied to loxi MeterConfig stat is incorrect |
| 262 | } |
| 263 | |
| 264 | private Collection<Meter> buildMeters(DeviceId deviceId, |
| 265 | List<OFMeterStats> entries) { |
| 266 | return entries.stream().map(stat -> { |
| 267 | DefaultMeter.Builder builder = DefaultMeter.builder(); |
| 268 | Collection<Band> bands = buildBands(stat.getBandStats()); |
| 269 | builder.forDevice(deviceId) |
alshabib | 58fe6dc | 2015-08-19 17:16:13 -0700 | [diff] [blame] | 270 | .withId(MeterId.meterId(stat.getMeterId())) |
alshabib | 7bb0501 | 2015-08-05 10:15:09 -0700 | [diff] [blame] | 271 | //FIXME: need to encode appId in meter id, but that makes |
| 272 | // things a little annoying for debugging |
| 273 | .fromApp(coreService.getAppId("org.onosproject.core")) |
| 274 | .withBands(bands); |
| 275 | DefaultMeter meter = builder.build(); |
| 276 | meter.setState(MeterState.ADDED); |
| 277 | meter.setLife(stat.getDurationSec()); |
| 278 | meter.setProcessedBytes(stat.getByteInCount().getValue()); |
| 279 | meter.setProcessedPackets(stat.getPacketInCount().getValue()); |
| 280 | meter.setReferenceCount(stat.getFlowCount()); |
| 281 | |
| 282 | // marks the meter as seen on the dataplane |
| 283 | pendingOperations.invalidate(stat.getMeterId()); |
| 284 | return meter; |
| 285 | }).collect(Collectors.toSet()); |
| 286 | } |
| 287 | |
| 288 | private Collection<Band> buildBands(List<OFMeterBandStats> bandStats) { |
| 289 | return bandStats.stream().map(stat -> { |
| 290 | DefaultBand band = DefaultBand.builder().build(); |
| 291 | band.setBytes(stat.getByteBandCount().getValue()); |
| 292 | band.setPackets(stat.getPacketBandCount().getValue()); |
| 293 | return band; |
| 294 | }).collect(Collectors.toSet()); |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | private void signalMeterError(OFMeterModFailedErrorMsg meterError, |
| 298 | MeterOperation op) { |
| 299 | switch (meterError.getCode()) { |
| 300 | case UNKNOWN: |
| 301 | providerService.meterOperationFailed(op, |
| 302 | MeterFailReason.UNKNOWN_DEVICE); |
| 303 | break; |
| 304 | case METER_EXISTS: |
| 305 | providerService.meterOperationFailed(op, |
| 306 | MeterFailReason.EXISTING_METER); |
| 307 | break; |
| 308 | case INVALID_METER: |
| 309 | providerService.meterOperationFailed(op, |
| 310 | MeterFailReason.INVALID_METER); |
| 311 | break; |
| 312 | case UNKNOWN_METER: |
| 313 | providerService.meterOperationFailed(op, |
| 314 | MeterFailReason.UNKNOWN); |
| 315 | break; |
| 316 | case BAD_COMMAND: |
| 317 | providerService.meterOperationFailed(op, |
| 318 | MeterFailReason.UNKNOWN_COMMAND); |
| 319 | break; |
| 320 | case BAD_FLAGS: |
| 321 | providerService.meterOperationFailed(op, |
| 322 | MeterFailReason.UNKNOWN_FLAGS); |
| 323 | break; |
| 324 | case BAD_RATE: |
| 325 | providerService.meterOperationFailed(op, |
| 326 | MeterFailReason.BAD_RATE); |
| 327 | break; |
| 328 | case BAD_BURST: |
| 329 | providerService.meterOperationFailed(op, |
| 330 | MeterFailReason.BAD_BURST); |
| 331 | break; |
| 332 | case BAD_BAND: |
| 333 | providerService.meterOperationFailed(op, |
| 334 | MeterFailReason.BAD_BAND); |
| 335 | break; |
| 336 | case BAD_BAND_VALUE: |
| 337 | providerService.meterOperationFailed(op, |
| 338 | MeterFailReason.BAD_BAND_VALUE); |
| 339 | break; |
| 340 | case OUT_OF_METERS: |
| 341 | providerService.meterOperationFailed(op, |
| 342 | MeterFailReason.OUT_OF_METERS); |
| 343 | break; |
| 344 | case OUT_OF_BANDS: |
| 345 | providerService.meterOperationFailed(op, |
| 346 | MeterFailReason.OUT_OF_BANDS); |
| 347 | break; |
| 348 | default: |
| 349 | providerService.meterOperationFailed(op, |
| 350 | MeterFailReason.UNKNOWN); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | private class InternalMeterListener |
| 355 | implements OpenFlowSwitchListener, OpenFlowEventListener { |
| 356 | @Override |
| 357 | public void handleMessage(Dpid dpid, OFMessage msg) { |
| 358 | switch (msg.getType()) { |
| 359 | case STATS_REPLY: |
| 360 | pushMeterStats(dpid, (OFStatsReply) msg); |
| 361 | break; |
| 362 | case ERROR: |
| 363 | OFErrorMsg error = (OFErrorMsg) msg; |
| 364 | if (error.getErrType() == OFErrorType.METER_MOD_FAILED) { |
| 365 | MeterOperation op = |
| 366 | pendingOperations.getIfPresent(error.getXid()); |
| 367 | pendingOperations.invalidate(error.getXid()); |
| 368 | if (op == null) { |
| 369 | log.warn("Unknown Meter operation failed {}", error); |
| 370 | } else { |
| 371 | OFMeterModFailedErrorMsg meterError = |
| 372 | (OFMeterModFailedErrorMsg) error; |
| 373 | signalMeterError(meterError, op); |
| 374 | } |
| 375 | } |
| 376 | break; |
| 377 | default: |
| 378 | break; |
| 379 | } |
| 380 | |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public void switchAdded(Dpid dpid) { |
| 385 | createStatsCollection(controller.getSwitch(dpid)); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void switchRemoved(Dpid dpid) { |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 390 | stopCollectorIfNeeded(collectors.remove(dpid)); |
alshabib | c791179 | 2015-07-30 17:55:30 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | @Override |
| 394 | public void switchChanged(Dpid dpid) { |
| 395 | |
| 396 | } |
| 397 | |
| 398 | @Override |
| 399 | public void portChanged(Dpid dpid, OFPortStatus status) { |
| 400 | |
| 401 | } |
| 402 | |
| 403 | @Override |
| 404 | public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
| 405 | |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | |
| 410 | |
alshabib | e27055b | 2015-07-09 21:43:10 -0700 | [diff] [blame] | 411 | } |