@Override public boolean inputThrottled(OFMessage ofm){
  if (ofm.getType() != OFType.PACKET_IN) {
    return false;
  }
  ctrSwitchPktin.updateCounterNoFlush();
  messageCount++;
  if (messageCount % 1000 == 0) {
    long now=System.currentTimeMillis();
    if (now != lastMessageTime) {
      currentRate=(int)(1000000 / (now - lastMessageTime));
      lastMessageTime=now;
    }
 else {
      currentRate=Integer.MAX_VALUE;
    }
  }
  if (!packetInThrottleEnabled) {
    if (currentRate <= packetInRateThresholdHigh) {
      return false;
    }
    enablePacketInThrottle();
  }
 else   if (currentRate < packetInRateThresholdLow) {
    disablePacketInThrottle();
    return false;
  }
  OFPacketIn pin=(OFPacketIn)ofm;
  OFMatch match=new OFMatch();
  match.loadFromPacket(pin.getPacketData(),pin.getInPort());
  if (ofMatchCache.update(match)) {
    ctrSwitchPktinDrops.updateCounterNoFlush();
    return true;
  }
  messageCountUniqueOFMatch++;
  if ((messageCountUniqueOFMatch % packetInRatePerMacThreshold) == 1) {
    checkPerSourceMacRate(pin);
  }
  if ((messageCountUniqueOFMatch % packetInRatePerPortThreshold) == 1) {
    checkPerPortRate(pin);
  }
  return false;
}

@ Override public boolean inputThrottled ( OFMessage ofm ) { if ( ofm . getType ( ) != OFType . PACKET_IN ) { return false ; } ctrSwitchPktin . updateCounterNoFlush ( ) ; messageCount ++ ; if ( messageCount % 1000 == 0 ) { long now = System . currentTimeMillis ( ) ; if ( now != lastMessageTime ) { currentRate = ( int ) ( 1000000 / ( now - lastMessageTime ) ) ; lastMessageTime = now ; } else { currentRate = Integer . MAX_VALUE ; } } if ( ! packetInThrottleEnabled ) { if ( currentRate <= packetInRateThresholdHigh ) { return false ; } enablePacketInThrottle ( ) ; } else if ( currentRate < packetInRateThresholdLow ) { disablePacketInThrottle ( ) ; return false ; } OFPacketIn pin = ( OFPacketIn ) ofm ; OFMatch match = new OFMatch ( ) ; match . loadFromPacket ( pin . getPacketData ( ) , pin . getInPort ( ) ) ; if ( ofMatchCache . update ( match ) ) { ctrSwitchPktinDrops . updateCounterNoFlush ( ) ; return true ; } messageCountUniqueOFMatch ++ ; if ( ( messageCountUniqueOFMatch % packetInRatePerMacThreshold ) == 1 ) { checkPerSourceMacRate ( pin ) ; } if ( ( messageCountUniqueOFMatch % packetInRatePerPortThreshold ) == 1 ) { checkPerPortRate ( pin ) ; } return false ; }
determine if this message should be dropped . we compute the current rate by taking a timestamp every 100 messages . could change to a more complex scheme if more accuracy is needed . enable throttling if the rate goes above packetinratethresholdhigh disable throttling when the rate drops below packetinratethresholdlow while throttling is enabled , we do the following : - remove duplicate packetin ' s mapped to the same ofmatch - after filtering , if packetin rate per host ( mac ) is above packetinratepermacthreshold , push a flow mod to block mac on port - after filtering , if packetin rate per port is above packetinrateperportthreshold , push a flow mod to block port - allow blocking flow mods have a hard timeout and expires automatically todo : keep a history of all events related in input throttling
