FreeBSD/sys/netpfil/ipfw/dn_sched_fq_pie.c
/*
 * Enqueue a packet into an appropriate queue according to
 * FQ-CoDe; algorithm.
 */
Enqueue a packet into an appropriate queue according to
FQ-CoDe; algorithm.
Enqueue a packet into an appropriate queue according to FQ - CoDe ; algorithm .
static int 
fq_pie_enqueue(struct dn_sch_inst *_si, struct dn_queue *_q, 
	struct mbuf *m)
{ 
	struct fq_pie_si *si;
	struct fq_pie_schk *schk;
	struct dn_sch_fq_pie_parms *param;
	struct dn_queue *mainq;
	struct fq_pie_flow *flows;
	int idx, drop, i, maxidx;
	mainq = (struct dn_queue *)(_si + 1);
	si = (struct fq_pie_si *)_si;
	flows = si->si_extra->flows;
	schk = (struct fq_pie_schk *)(si->_si.sched+1);
	param = &schk->cfg;
	idx = fq_pie_classify_flow(m, param->flows_cnt, si);
	drop = pie_enqueue(&flows[idx], m, si);
	if (drop)
		return 1;
	if (!flows[idx].active) {
		STAILQ_INSERT_TAIL(&si->newflows, &flows[idx], flowchain);
		flows[idx].deficit = param->quantum;
		fq_activate_pie(&flows[idx]);
		flows[idx].active = 1;
	}
	if (mainq->ni.length > schk->cfg.limit) {
		for (maxidx = 0; maxidx < schk->cfg.flows_cnt; maxidx++)
			if (flows[maxidx].active)
				break;
		if (maxidx < schk->cfg.flows_cnt) {
			for (i = maxidx + 1; i < schk->cfg.flows_cnt; i++) 
				if (flows[i].active && flows[i].stats.length >
					flows[maxidx].stats.length)
					maxidx = i;
			pie_drop_head(&flows[maxidx], si);
			drop = 1;
		}
	}
	return drop;
}
static int fq_pie_enqueue ( struct dn_sch_inst * _si , struct dn_queue * _q , struct mbuf * m ) { struct fq_pie_si * si ; struct fq_pie_schk * schk ; struct dn_sch_fq_pie_parms * param ; struct dn_queue * mainq ; struct fq_pie_flow * flows ; int idx , drop , i , maxidx ; mainq = ( struct dn_queue * ) ( _si + 1 ) ; si = ( struct fq_pie_si * ) _si ; flows = si -> si_extra -> flows ; schk = ( struct fq_pie_schk * ) ( si -> _si . sched + 1 ) ; param = & schk -> cfg ; idx = fq_pie_classify_flow ( m , param -> flows_cnt , si ) ; drop = pie_enqueue ( & flows [ idx ] , m , si ) ; if ( drop ) return 1 ; if ( ! flows [ idx ] . active ) { STAILQ_INSERT_TAIL ( & si -> newflows , & flows [ idx ] , flowchain ) ; flows [ idx ] . deficit = param -> quantum ; fq_activate_pie ( & flows [ idx ] ) ; flows [ idx ] . active = 1 ; } if ( mainq -> ni . length > schk -> cfg . limit ) { for ( maxidx = 0 ; maxidx < schk -> cfg . flows_cnt ; maxidx ++ ) if ( flows [ maxidx ] . active ) break ; if ( maxidx < schk -> cfg . flows_cnt ) { for ( i = maxidx + 1 ; i < schk -> cfg . flows_cnt ; i ++ ) if ( flows [ i ] . active && flows [ i ] . stats . length > flows [ maxidx ] . stats . length ) maxidx = i ; pie_drop_head ( & flows [ maxidx ] , si ) ; drop = 1 ; } } return drop ; }
Enqueue a packet into an appropriate queue according to
 FQ-CoDe; algorithm.
Enqueue a packet into an appropriate queue according to FQ - CoDe ; algorithm .
/* classify a packet to queue number*/ /* enqueue packet into appropriate queue using PIE AQM.
	 * Note: 'pie_enqueue' function returns 1 only when it unable to 
	 * add timestamp to packet (no limit check)*/ /* pie unable to timestamp a packet */ /* If the flow (sub-queue) is not active ,then add it to tail of
	 * new flows list, initialize and activate it.
	 */ /* check the limit for all queues and remove a packet from the
	 * largest one 
	 */ /* find first active flow */ /* find the largest sub- queue */