/**
* @file icss_stormControl.h
*
* @brief include file for storm prevention implementation
*
* \par
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
* \par
*/
#ifndef _ICSS_STORMCONTROL_H_
#define _ICSS_STORMCONTROL_H_
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "icss_common.h"
#include "icss_switch.h"
/**
* @def DEFAULT_CREDITS
*      (packets per microsec) This is 1% of the bandwidth
*/
#define DEFAULT_CREDITS   2000
/**
* @def DEFAULT_PKT_SIZE
*      default packet size used to compute number of BC/MC packets allowed in a 100ms window
*/
#define DEFAULT_PKT_SIZE  60
/**
* @def MAX_PERCENTAGE
*      Max number of BC/MC packets blocked expressed as a percentage
*/
#define MAX_PERCENTAGE    50

/**
* @brief Storm prevention control variables
*
*/
typedef struct {

	Uint8 suppressionEnabled;	/**enable/disable storm prevention*/
	Uint16 credits;	/**Number of packets allowed in a 100ms*/
	/*At 100mbps number of 60 byte packets per 100ms is 21k
	 * a 1% bandwidth means 210 packets approx, 2% is 420 pkts*/
} stormPrevention;

/**
* @brief Initialize the storm prevention table for both ports
*
* @retval none
*/
void initStormPreventionTable();
/**
* @brief   Disable storm prevention algorithm for broadcast packets on a particular port
*
* @param portnum port number on which storm prevention is to be enabled
*
* @retval none
*/
void disableStormPrevention(Uint8 portnum);

/**
* @brief   Set the credit value for broadcast packets used in storm prevention
*
* @param creditValue number of packets allowed in a given time
* @param portnum port number on which value is to be set
*
* @retval none
*/
void setCreditValue(Uint16 numCredits, Uint8 portnum);

/**
* @brief   Enable storm prevention algorithm on a particular port
*
* @param portnum port number on which storm prevention is to be enabled
*
* @retval none
*/
void enableStormPrevention(Uint8 portnum);

/**
* @brief   Reset the credits at the end of time period, this time period is common to both broadcast and multicast packets
*
* @retval none
*/
void resetStormPreventionCounter();

/**
* @brief   returns true if storm prevention is enabled
*
* @param portNum  0/1
*
* @retval Status. 1 if storm prevention is enabled on any port
*/
inline Uint8 ifStormPreventionEnabled(Uint8 portNum);

#endif /* _ICSS_STORMCONTROL_H_ */
