Skip to content
Browse files

New CoDel implementation. The old one had trouble.

  • Loading branch information...
1 parent 3aeaee3 commit 0bcca1696b9344611b6636cf8664be5edeb20d16 @jlouis committed Dec 22, 2012
Showing with 37 additions and 34 deletions.
  1. +37 −34 src/sv_codel.erl
View
71 src/sv_codel.erl
@@ -71,41 +71,44 @@ dodequeue_(Now, Pkt, _Sojourn, #state { first_above_time = FAT } = State) when N
dodequeue_(_Now, Pkt, _Sojourn, State) ->
{nodrop, Pkt, State}.
-dequeue(Now, #state { dropping = Dropping } = State) ->
- case dodequeue(Now, State) of
- {nodrop, empty, NState} ->
- {empty, [], NState#state { dropping = false }};
- {nodrop, Pkt, #state {} = NState} when Dropping ->
- {ok, Pkt, [], NState#state { dropping = false }};
- {drop, Pkt, #state { drop_next = DropNext } = NState} when Now >= DropNext ->
- dequeue_drop_next(Now, Pkt, NState, []);
- {nodrop, Pkt, NState} when not Dropping ->
- {ok, Pkt, [], NState};
- {drop, Pkt, #state { drop_next = DN, interval = I, first_above_time = FirstAbove } = NState}
- when not Dropping, Now - DN < I orelse Now - FirstAbove >= I ->
- dequeue_start_drop(Now, NState, [Pkt]);
- {drop, Pkt, NState} when not Dropping ->
- {ok, Pkt, [], NState}
- end.
+dequeue(Now, State) ->
+ dequeue_(Now, dodequeue(Now, State)).
+
+dequeue_(Now, {nodrop, Pkt, #state { dropping = true } = State}) ->
+ dequeue_drop_next(Now, Pkt, State#state { dropping = false }, []);
+dequeue_(Now, {drop, Pkt, #state { dropping = true } = State}) ->
+ dequeue_drop_next(Now, Pkt, State, []);
+dequeue_(Now, {drop, Pkt, #state { dropping = false } = State}) ->
+ dequeue_start_drop(Now, Pkt, State);
+dequeue_(_Now, {nodrop, Pkt, #state { dropping = false } = State}) ->
+ {Pkt, [], State}.
-
+dequeue_drop_next(Now, Pkt, #state { drop_next = DN, dropping = true } = State, Dropped)
+ when Now >= DN ->
+ dequeue_drop_next_(Now, dodequeue(Now, State), [Pkt | Dropped]);
+dequeue_drop_next(_Now, Pkt, State, Dropped) ->
+ {Pkt, Dropped, State}.
-dequeue_drop_next(Now, Candidate, #state { drop_next = DN, dropping = true, count = C } = State, Dropped) ->
- case dodequeue(Now, State#state { count = C+1 }) of
- {nodrop, Res, NState} ->
- {ok, Res, [Candidate | Dropped], NState#state { dropping = false }};
- {drop, Res, #state { count = NC, interval = I } = NState} ->
- dequeue_drop_next(Now, Res, NState#state { drop_next = control_law(DN, I, NC) }, [Candidate | Dropped])
- end;
-dequeue_drop_next(_Now, Candidate, #state { dropping = false } = State, Dropped) ->
- {ok, Candidate, Dropped, State}.
+dequeue_drop_next_(Now, {nodrop, Pkt, State}, Dropped) ->
+ dequeue_drop_next(Now, Pkt, State#state { dropping = false }, Dropped);
+dequeue_drop_next_(
+ Now,
+ {drop, Pkt, #state { count = C, interval = I, drop_next = DN } = State},
+ Dropped) ->
+ dequeue_drop_next(
+ Now,
+ Pkt,
+ State#state { count = C + 1, drop_next = control_law(DN, I, C + 1) },
+ Dropped).
-dequeue_start_drop(Now, #state { drop_next = DN, interval = Interval, count = Count } = State, Dropped)
- when Now - DN < Interval ->
- {ok, Dropped,
- State#state {
+dequeue_start_drop(Now, Pkt, #state { drop_next = DN, interval = Interval, count = Count } = State)
+ when Now - DN < Interval, Count > 2 ->
+ {drop, [Pkt], State#state {
+ dropping = true,
+ count = Count - 2,
+ drop_next = control_law(Now, Interval, Count - 2) }};
+dequeue_start_drop(Now, Pkt, #state { interval = I } = State) ->
+ {drop, [Pkt], State#state {
dropping = true,
- count = case Count > 2 of true -> Count - 2; false -> 1 end,
- drop_next = control_law(Now, Interval, Count) }};
-dequeue_start_drop(Now, #state { interval = Interval, count = Count } = State, Dropped) ->
- {ok, Dropped, State#state { dropping = true, count = 1, drop_next = control_law(Now, Interval, Count) }}.
+ count = 1,
+ drop_next = control_law(Now, I, 1) }}.

0 comments on commit 0bcca16

Please sign in to comment.
Something went wrong with that request. Please try again.