2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.impl.device;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 final class PacketInRateLimiter extends SimpleRatelimiter {
18 private static final Logger LOG = LoggerFactory.getLogger(PacketInRateLimiter.class);
19 private final float rejectedDrainFactor;
20 private final ConnectionAdapter connectionAdapter;
21 private final MessageSpy messageSpy;
23 PacketInRateLimiter(final ConnectionAdapter connectionAdapter, final int lowWatermark, final int highWatermark, final MessageSpy messageSpy, float rejectedDrainFactor) {
24 super(lowWatermark, highWatermark);
25 Preconditions.checkArgument(rejectedDrainFactor > 0 && rejectedDrainFactor < 1);
26 this.rejectedDrainFactor = rejectedDrainFactor;
27 this.connectionAdapter = Preconditions.checkNotNull(connectionAdapter);
28 this.messageSpy = Preconditions.checkNotNull(messageSpy);
32 protected void disableFlow() {
33 messageSpy.spyMessage(DeviceContext.class, MessageSpy.StatisticsGroup.OFJ_BACKPRESSURE_ON);
34 connectionAdapter.setPacketInFiltering(true);
35 LOG.debug("PacketIn filtering on: {}", connectionAdapter.getRemoteAddress());
39 protected void enableFlow() {
40 messageSpy.spyMessage(DeviceContext.class, MessageSpy.StatisticsGroup.OFJ_BACKPRESSURE_OFF);
41 connectionAdapter.setPacketInFiltering(false);
42 LOG.debug("PacketIn filtering off: {}", connectionAdapter.getRemoteAddress());
45 public void drainLowWaterMark() {
46 adaptLowWaterMarkAndDisableFlow((int) (getOccupiedPermits() * rejectedDrainFactor));