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,
24 final int lowWatermark,
25 final int highWatermark,
26 final MessageSpy messageSpy,
27 float rejectedDrainFactor) {
28 super(lowWatermark, highWatermark);
29 Preconditions.checkArgument(rejectedDrainFactor > 0 && rejectedDrainFactor < 1);
30 this.rejectedDrainFactor = rejectedDrainFactor;
31 this.connectionAdapter = Preconditions.checkNotNull(connectionAdapter);
32 this.messageSpy = Preconditions.checkNotNull(messageSpy);
36 protected void disableFlow() {
37 messageSpy.spyMessage(DeviceContext.class, MessageSpy.StatisticsGroup.OFJ_BACKPRESSURE_ON);
38 connectionAdapter.setPacketInFiltering(true);
39 LOG.debug("PacketIn filtering on: {}", connectionAdapter.getRemoteAddress());
43 protected void enableFlow() {
44 messageSpy.spyMessage(DeviceContext.class, MessageSpy.StatisticsGroup.OFJ_BACKPRESSURE_OFF);
45 connectionAdapter.setPacketInFiltering(false);
46 LOG.debug("PacketIn filtering off: {}", connectionAdapter.getRemoteAddress());
49 public void drainLowWaterMark() {
50 adaptLowWaterMarkAndDisableFlow((int) (getOccupiedPermits() * rejectedDrainFactor));