Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New CoDel implementation. The old one had trouble.

  • Loading branch information...
commit 0bcca1696b9344611b6636cf8664be5edeb20d16 1 parent 3aeaee3
Jesper Louis Andersen authored

Showing 1 changed file with 37 additions and 34 deletions. Show diff stats Hide diff stats

  1. +37 34 src/sv_codel.erl
71 src/sv_codel.erl
@@ -71,41 +71,44 @@ dodequeue_(Now, Pkt, _Sojourn, #state { first_above_time = FAT } = State) when N
71 71 dodequeue_(_Now, Pkt, _Sojourn, State) ->
72 72 {nodrop, Pkt, State}.
73 73
74   -dequeue(Now, #state { dropping = Dropping } = State) ->
75   - case dodequeue(Now, State) of
76   - {nodrop, empty, NState} ->
77   - {empty, [], NState#state { dropping = false }};
78   - {nodrop, Pkt, #state {} = NState} when Dropping ->
79   - {ok, Pkt, [], NState#state { dropping = false }};
80   - {drop, Pkt, #state { drop_next = DropNext } = NState} when Now >= DropNext ->
81   - dequeue_drop_next(Now, Pkt, NState, []);
82   - {nodrop, Pkt, NState} when not Dropping ->
83   - {ok, Pkt, [], NState};
84   - {drop, Pkt, #state { drop_next = DN, interval = I, first_above_time = FirstAbove } = NState}
85   - when not Dropping, Now - DN < I orelse Now - FirstAbove >= I ->
86   - dequeue_start_drop(Now, NState, [Pkt]);
87   - {drop, Pkt, NState} when not Dropping ->
88   - {ok, Pkt, [], NState}
89   - end.
  74 +dequeue(Now, State) ->
  75 + dequeue_(Now, dodequeue(Now, State)).
  76 +
  77 +dequeue_(Now, {nodrop, Pkt, #state { dropping = true } = State}) ->
  78 + dequeue_drop_next(Now, Pkt, State#state { dropping = false }, []);
  79 +dequeue_(Now, {drop, Pkt, #state { dropping = true } = State}) ->
  80 + dequeue_drop_next(Now, Pkt, State, []);
  81 +dequeue_(Now, {drop, Pkt, #state { dropping = false } = State}) ->
  82 + dequeue_start_drop(Now, Pkt, State);
  83 +dequeue_(_Now, {nodrop, Pkt, #state { dropping = false } = State}) ->
  84 + {Pkt, [], State}.
90 85
91   -
  86 +dequeue_drop_next(Now, Pkt, #state { drop_next = DN, dropping = true } = State, Dropped)
  87 + when Now >= DN ->
  88 + dequeue_drop_next_(Now, dodequeue(Now, State), [Pkt | Dropped]);
  89 +dequeue_drop_next(_Now, Pkt, State, Dropped) ->
  90 + {Pkt, Dropped, State}.
92 91
93   -dequeue_drop_next(Now, Candidate, #state { drop_next = DN, dropping = true, count = C } = State, Dropped) ->
94   - case dodequeue(Now, State#state { count = C+1 }) of
95   - {nodrop, Res, NState} ->
96   - {ok, Res, [Candidate | Dropped], NState#state { dropping = false }};
97   - {drop, Res, #state { count = NC, interval = I } = NState} ->
98   - dequeue_drop_next(Now, Res, NState#state { drop_next = control_law(DN, I, NC) }, [Candidate | Dropped])
99   - end;
100   -dequeue_drop_next(_Now, Candidate, #state { dropping = false } = State, Dropped) ->
101   - {ok, Candidate, Dropped, State}.
  92 +dequeue_drop_next_(Now, {nodrop, Pkt, State}, Dropped) ->
  93 + dequeue_drop_next(Now, Pkt, State#state { dropping = false }, Dropped);
  94 +dequeue_drop_next_(
  95 + Now,
  96 + {drop, Pkt, #state { count = C, interval = I, drop_next = DN } = State},
  97 + Dropped) ->
  98 + dequeue_drop_next(
  99 + Now,
  100 + Pkt,
  101 + State#state { count = C + 1, drop_next = control_law(DN, I, C + 1) },
  102 + Dropped).
102 103
103   -dequeue_start_drop(Now, #state { drop_next = DN, interval = Interval, count = Count } = State, Dropped)
104   - when Now - DN < Interval ->
105   - {ok, Dropped,
106   - State#state {
  104 +dequeue_start_drop(Now, Pkt, #state { drop_next = DN, interval = Interval, count = Count } = State)
  105 + when Now - DN < Interval, Count > 2 ->
  106 + {drop, [Pkt], State#state {
  107 + dropping = true,
  108 + count = Count - 2,
  109 + drop_next = control_law(Now, Interval, Count - 2) }};
  110 +dequeue_start_drop(Now, Pkt, #state { interval = I } = State) ->
  111 + {drop, [Pkt], State#state {
107 112 dropping = true,
108   - count = case Count > 2 of true -> Count - 2; false -> 1 end,
109   - drop_next = control_law(Now, Interval, Count) }};
110   -dequeue_start_drop(Now, #state { interval = Interval, count = Count } = State, Dropped) ->
111   - {ok, Dropped, State#state { dropping = true, count = 1, drop_next = control_law(Now, Interval, Count) }}.
  113 + count = 1,
  114 + 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.