/* 
 * $Source: /b/cvsroot//wu_arl/msr/rp/plugins/delay/delay.h,v $
 * $Author: kenw $
 * $Date: 2004/08/10 17:10:39 $
 * $Revision: 1.7 $
 *
 * Changes:
 * Wed Apr 11 10:42:14 CDT 2001 - Initial version fredk
 *
 */

/* CAVEAT:  You can only create one instance since there is only one queue.
 *		You could generalize to N instances if you modify
 *		pdelay_create_instance.
 */

#include <msr/msr.h>
#include <rp/rp_plugin.h>

#define PDELAY_ID	600	// pkt delay plugin id
#define DELAY_TIME	50	// Initial delay in msec

static int cbPeriod = 500;	// callback period in usec (500 usec, 1 tick)

/* includes here */
struct lkmtp;
struct lkm_table;

/* pdelay instance
 * 	After init:	pkt_count = fwd_count = drop_count = 0
 * 			earliest_depart_time = 0 and delay_time = DELAY_TIME
 * 	After bind:	(pkt_count = fwd_count) and (drop_count = 0)
 * 	After unbind:	(drop_count = qlen) and (qlen = 0)
 */
struct pdelay_instance {
  /* First the base class structure */
  struct rp_instance rootinstance;
  HDRQ_t qhead;			// addr of 1st buffer in delay queue
  int	qlen;			// #pkts in delay queue
  int	pkt_count;		// #pkts handled by instance
  int	drop_count;		// #pkts dropped by instance
  int	fwd_count;		// #pkts forwarded by instance
  int	max_qlen;		// maximum queue length
  int	earliest_depart_time;	// earliest time nxt pkt should be sent (msec)
  int	delay_time;		// amount to delay (msec)
};

/* function prototypes */
void pdelay_init_class(void);
struct rp_class *pdelay_get_class(void);
struct rp_instance *pdelay_create_instance(struct rp_class *, u_int32_t);
void pdelay_handle_packet(struct rp_instance *, void *);
void pdelay_free_instance(struct rp_instance *);
void pdelay_bind_instance(struct rp_instance *);
void pdelay_unbind_instance(struct rp_instance *);
int  pdelay_handle_msg(struct rp_instance *, void *, u_int8_t, u_int8_t, u_int8_t *);
#ifdef PLUGIN_DEBUG
int pdelay(struct lkm_table *, int , int);
#else
int pdelay(struct lkm_table *, int , int, struct kernel_plugin_fct_struct * );
#endif
int pdelay_load(struct lkm_table *, int);
int pdelay_unload(struct lkm_table *, int);

