Path: blob/main/sys/netpfil/ipfw/test/test_dn_sched.c
39488 views
/*1*2* library functions for userland testing of dummynet schedulers3*/45#include "dn_test.h"67void8m_freem(struct mbuf *m)9{10printf("free %p\n", m);11}1213int14dn_sched_modevent(module_t mod, int cmd, void *arg)15{16(void)mod;17(void)cmd;18(void)arg;19return 0;20}2122void23dn_free_pkts(struct mbuf *m)24{25struct mbuf *x;26while ( (x = m) ) {27m = m->m_nextpkt;28m_freem(x);29}30}3132int33dn_delete_queue(void *_q, void *do_free)34{35struct dn_queue *q = _q;3637(void)do_free;38if (q->mq.head)39dn_free_pkts(q->mq.head);40free(q);41return 0;42}4344/*45* This is a simplified function for testing purposes, which does46* not implement statistics or random loss.47* Enqueue a packet in q, subject to space and queue management policy48* (whose parameters are in q->fs).49* Update stats for the queue and the scheduler.50* Return 0 on success, 1 on drop. The packet is consumed anyways.51*/52int53dn_enqueue(struct dn_queue *q, struct mbuf* m, int drop)54{55if (drop)56goto drop;57if (q->ni.length >= 200)58goto drop;59mq_append(&q->mq, m);60q->ni.length++;61q->ni.tot_bytes += m->m_pkthdr.len;62q->ni.tot_pkts++;63return 0;6465drop:66q->ni.drops++;67return 1;68}6970int71ipdn_bound_var(int *v, int dflt, int lo, int hi, const char *msg)72{73(void)msg;74if (*v < lo) {75*v = dflt;76} else if (*v > hi) {77*v = hi;78}79return *v;80}8182#ifndef __FreeBSD__83int84fls(int mask)85{86int bit;8788if (mask == 0)89return (0);90for (bit = 1; mask != 1; bit++)91mask = (unsigned int)mask >> 1;92return (bit);93}94#endif959697