private void checkPerSourceMacRate(OFPacketIn pin){
  byte[] data=pin.getPacketData();
  byte[] mac=Arrays.copyOfRange(data,6,12);
  MACAddress srcMac=MACAddress.valueOf(mac);
  short ethType=(short)(((data[12] & 0xff) << 8) + (data[13] & 0xff));
  if (ethType != Ethernet.TYPE_LLDP && ethType != Ethernet.TYPE_BSN && macCache.update(srcMac.toLong())) {
    if (macBlockedCache.update(srcMac.toLong())) {
      return;
    }
    int port=pin.getInPort();
    SwitchPort swPort=new SwitchPort(getId(),port);
    ForwardingBase.blockHost(floodlightProvider,swPort,srcMac.toLong(),(short)5,AppCookie.makeCookie(OFSWITCH_APP_ID,0));
    floodlightProvider.addSwitchEvent(this.datapathId,"SWITCH_PORT_BLOCKED_TEMPORARILY " + "OFPort " + port + " mac "+ srcMac,false);
    log.info("Excessive packet in from {} on {}, block host for 5 sec",srcMac.toString(),swPort);
  }
}

private void checkPerSourceMacRate ( OFPacketIn pin ) { byte [ ] data = pin . getPacketData ( ) ; byte [ ] mac = Arrays . copyOfRange ( data , 6 , 12 ) ; MACAddress srcMac = MACAddress . valueOf ( mac ) ; short ethType = ( short ) ( ( ( data [ 12 ] & 0xff ) << 8 ) + ( data [ 13 ] & 0xff ) ) ; if ( ethType != Ethernet . TYPE_LLDP && ethType != Ethernet . TYPE_BSN && macCache . update ( srcMac . toLong ( ) ) ) { if ( macBlockedCache . update ( srcMac . toLong ( ) ) ) { return ; } int port = pin . getInPort ( ) ; SwitchPort swPort = new SwitchPort ( getId ( ) , port ) ; ForwardingBase . blockHost ( floodlightProvider , swPort , srcMac . toLong ( ) , ( short ) 5 , AppCookie . makeCookie ( OFSWITCH_APP_ID , 0 ) ) ; floodlightProvider . addSwitchEvent ( this . datapathId , "SWITCH_PORT_BLOCKED_TEMPORARILY " + "OFPort " + port + " mac " + srcMac , false ) ; log . info ( "Excessive packet in from {} on {}, block host for 5 sec" , srcMac . toString ( ) , swPort ) ; } }
check if we have sampled this mac in the last second . since we check every packetinratepermacthreshold packets , the presence of the mac in the maccache means the rate is above the threshold in a statistical sense . take care not to block topology probing packets . also don ' t push blocking flow mod if we have already done so within the last 5 seconds .
