1 /*
2 * $FreeBSD$
3 *
4 * library functions for userland testing of dummynet schedulers
5 */
6
7 #include "dn_test.h"
8
9 void
10 m_freem(struct mbuf *m)
11 {
12 printf("free %p\n", m);
13 }
14
15 int
16 dn_sched_modevent(module_t mod, int cmd, void *arg)
17 {
18 (void)mod;
19 (void)cmd;
20 (void)arg;
21 return 0;
22 }
23
24 void
25 dn_free_pkts(struct mbuf *m)
26 {
27 struct mbuf *x;
28 while ( (x = m) ) {
29 m = m->m_nextpkt;
30 m_freem(x);
31 }
32 }
33
34 int
35 dn_delete_queue(void *_q, void *do_free)
36 {
37 struct dn_queue *q = _q;
38
39 (void)do_free;
40 if (q->mq.head)
41 dn_free_pkts(q->mq.head);
42 free(q);
43 return 0;
44 }
45
46 /*
47 * This is a simplified function for testing purposes, which does
48 * not implement statistics or random loss.
49 * Enqueue a packet in q, subject to space and queue management policy
50 * (whose parameters are in q->fs).
51 * Update stats for the queue and the scheduler.
52 * Return 0 on success, 1 on drop. The packet is consumed anyways.
53 */
54 int
55 dn_enqueue(struct dn_queue *q, struct mbuf* m, int drop)
56 {
57 if (drop)
58 goto drop;
59 if (q->ni.length >= 200)
60 goto drop;
61 mq_append(&q->mq, m);
62 q->ni.length++;
63 q->ni.tot_bytes += m->m_pkthdr.len;
64 q->ni.tot_pkts++;
65 return 0;
66
67 drop:
68 q->ni.drops++;
69 return 1;
70 }
71
72 int
73 ipdn_bound_var(int *v, int dflt, int lo, int hi, const char *msg)
74 {
75 (void)msg;
76 if (*v < lo) {
77 *v = dflt;
78 } else if (*v > hi) {
79 *v = hi;
80 }
81 return *v;
82 }
83
84 #ifndef __FreeBSD__
85 int
86 fls(int mask)
87 {
88 int bit;
89
90 if (mask == 0)
91 return (0);
92 for (bit = 1; mask != 1; bit++)
93 mask = (unsigned int)mask >> 1;
94 return (bit);
95 }
96 #endif
Cache object: 8e78d5f8f76a8b9bbc94cd20d057fd53
|