Hi!
I have created this patch to add a fixed delay on packet filtered by
netem. Soon I will send the patch to iproute2.
This patch comes from a need I have to delay all packets 50ms, beside
the actual delay setting, like 30ms +- 15 ms. This strike, IMMHO, a
missing point on gap reordering. If I set "gap 5 delay 10ms" every 5th
(10th, 15th, ...) packet to go to be sent immediately and every other
packet to be delayed by 10ms. This  is ok, but I also need a "fixed"
delay of 50ms to be applied to all packets. Since netem can't be
nested with himself (so I can do a fixed delay), I needed this new
feature on netem.
This patch was create with linux kernel version 2.6.24.2.
I hope you like it, and it would be great if it goes shiped with the
next version of the kernel :-))
Regards,
Julio Kriger

-- 
--
>From the moment I picked your book up until I laid it down, I was
convulsed with laughter. Someday I intend reading it.
Groucho Marx
----------------------------
Julio Kriger
mailto:[EMAIL PROTECTED]
diff -Naur linux-2.6.24.2-old/include/linux/pkt_sched.h 
linux-2.6.24.2-new/include/linux/pkt_sched.h
--- linux-2.6.24.2-old/include/linux/pkt_sched.h        2008-02-11 
03:51:11.000000000 -0200
+++ linux-2.6.24.2-new/include/linux/pkt_sched.h        2008-02-24 
11:48:13.000000000 -0200
@@ -452,6 +452,7 @@
        __u32   gap;            /* re-ordering gap (0 for none) */
        __u32   duplicate;      /* random packet dup  (0=none ~0=100%) */
        __u32   jitter;         /* random jitter in latency (us) */
+       __u32   fixed_latency;          /* fixed latency form netem */  
 };
 
 struct tc_netem_corr
diff -Naur linux-2.6.24.2-old/net/sched/sch_netem.c 
linux-2.6.24.2-new/net/sched/sch_netem.c
--- linux-2.6.24.2-old/net/sched/sch_netem.c    2008-02-11 03:51:11.000000000 
-0200
+++ linux-2.6.24.2-new/net/sched/sch_netem.c    2008-02-24 11:47:40.000000000 
-0200
@@ -23,7 +23,7 @@
 #include <net/netlink.h>
 #include <net/pkt_sched.h>
 
-#define VERSION "1.2"
+#define VERSION "1.2.1"
 
 /*     Network Emulation Queuing algorithm.
        ====================================
@@ -65,6 +65,7 @@
        u32 duplicate;
        u32 reorder;
        u32 corrupt;
+       u32 fixed_latency; /* handle fixed delay */
 
        struct crndstate {
                u32 last;
@@ -215,6 +216,13 @@
                delay = tabledist(q->latency, q->jitter,
                                  &q->delay_cor, q->delay_dist);
 
+               /*
+                * Add fixed delay
+                */
+               if(q->fixed_latency > 0) {
+                       delay += tabledist(q->fixed_latency, 0, &q->delay_cor, 
q->delay_dist);
+               }
+
                now = psched_get_time();
                cb->time_to_send = now + delay;
                ++q->counter;
@@ -225,6 +233,18 @@
                 * of the queue.
                 */
                cb->time_to_send = psched_get_time();
+
+               /*
+                * Add fixed delay
+                */
+               if(q->fixed_latency > 0) {
+                       psched_time_t now;
+                       psched_tdiff_t fixed_delay;
+                       fixed_delay = tabledist(q->fixed_latency, 0, 
&q->delay_cor, q->delay_dist);
+                       now = psched_get_time();
+                       cb->time_to_send = now + fixed_delay;
+               }       
+               
                q->counter = 0;
                ret = q->qdisc->ops->requeue(skb, q->qdisc);
        }
@@ -427,6 +447,7 @@
        q->counter = 0;
        q->loss = qopt->loss;
        q->duplicate = qopt->duplicate;
+       q->fixed_latency = qopt->fixed_latency;
 
        /* for compatibility with earlier versions.
         * if gap is set, need to assume 100% probability
@@ -607,6 +628,7 @@
        qopt.loss = q->loss;
        qopt.gap = q->gap;
        qopt.duplicate = q->duplicate;
+       qopt.fixed_latency = q->fixed_latency;
        RTA_PUT(skb, TCA_OPTIONS, sizeof(qopt), &qopt);
 
        cor.delay_corr = q->delay_cor.rho;

Reply via email to