Commit de78f3ce authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Map entries before the first in packetmap.

The first time we drop, we may already have mapped a number of
packets with the identity mapping.  Insert an identity mapping
in Drop.

Also extend any existing mapping when inserting out-of-order mappings.
parent c86f55c3
...@@ -69,14 +69,7 @@ func (m *Map) reset() { ...@@ -69,14 +69,7 @@ func (m *Map) reset() {
func addMapping(m *Map, seqno, pid uint16, delta, pidDelta uint16) { func addMapping(m *Map, seqno, pid uint16, delta, pidDelta uint16) {
if len(m.entries) == 0 { if len(m.entries) == 0 {
m.entries = []entry{ // this shouldn't happen
entry{
first: seqno,
count: 1,
delta: delta,
pidDelta: pidDelta,
},
}
return return
} }
...@@ -86,9 +79,19 @@ func addMapping(m *Map, seqno, pid uint16, delta, pidDelta uint16) { ...@@ -86,9 +79,19 @@ func addMapping(m *Map, seqno, pid uint16, delta, pidDelta uint16) {
return return
} }
f := seqno
d := m.entries[i].delta - delta
// expand the interval to cover missing values, but make sure the
// targets don't overlap.
if d < 8192 {
ff := m.entries[i].first + m.entries[i].count + d
if compare(ff, seqno) < 0 {
f = ff
}
}
e := entry{ e := entry{
first: seqno, first: f,
count: 1, count: seqno - f + 1,
delta: delta, delta: delta,
pidDelta: pidDelta, pidDelta: pidDelta,
} }
...@@ -106,7 +109,7 @@ func addMapping(m *Map, seqno, pid uint16, delta, pidDelta uint16) { ...@@ -106,7 +109,7 @@ func addMapping(m *Map, seqno, pid uint16, delta, pidDelta uint16) {
// direct maps a seqno to a target seqno. It returns true if the seqno // direct maps a seqno to a target seqno. It returns true if the seqno
// could be mapped, the target seqno, and the pid delta to apply. // could be mapped, the target seqno, and the pid delta to apply.
// Called with the m.mu taken. // Called with m.mu taken.
func (m *Map) direct(seqno uint16) (bool, uint16, uint16) { func (m *Map) direct(seqno uint16) (bool, uint16, uint16) {
if len(m.entries) == 0 { if len(m.entries) == 0 {
return false, 0, 0 return false, 0, 0
...@@ -184,6 +187,17 @@ func (m *Map) Drop(seqno uint16, pid uint16) bool { ...@@ -184,6 +187,17 @@ func (m *Map) Drop(seqno uint16, pid uint16) bool {
return false return false
} }
if len(m.entries) == 0 {
m.entries = []entry{
entry{
first: seqno - 8192,
count: 8192,
delta: 0,
pidDelta: 0,
},
}
}
m.pidDelta += pid - m.nextPid m.pidDelta += pid - m.nextPid
m.nextPid = pid m.nextPid = pid
......
...@@ -33,6 +33,30 @@ func TestNoDrops(t *testing.T) { ...@@ -33,6 +33,30 @@ func TestNoDrops(t *testing.T) {
} }
} }
func TestReorder(t *testing.T) {
m := Map{}
ok, s, p := m.Map(42, 1001)
if !ok || s != 42 || p != 0 {
t.Errorf("Expected 42, 0, got %v, %v, %v", ok, s, p)
}
ok = m.Drop(43, 1002)
if !ok {
t.Errorf("Expected ok")
}
ok, s, p = m.Map(45, 1003)
if !ok || s != 44 || p != 1 {
t.Errorf("Expected 44, 1, got %v, %v, %v", ok, s, p)
}
ok, s, p = m.Map(44, 1003)
if !ok || s != 43 || p != 1 {
t.Errorf("Expected 43, 0, got %v, %v, %v", ok, s, p)
}
}
func TestDrop(t *testing.T) { func TestDrop(t *testing.T) {
m := Map{} m := Map{}
...@@ -82,8 +106,8 @@ func TestDrop(t *testing.T) { ...@@ -82,8 +106,8 @@ func TestDrop(t *testing.T) {
} }
ok, s, p = m.Map(13, 1000) ok, s, p = m.Map(13, 1000)
if ok { if !ok || s != 13 || p != 0 {
t.Errorf("Expected not ok") t.Errorf("Expected 13, 0, got %v, %v, %v", ok, s, p)
} }
ok, s, p = m.Map(44, 1001) ok, s, p = m.Map(44, 1001)
...@@ -107,8 +131,8 @@ func TestDrop(t *testing.T) { ...@@ -107,8 +131,8 @@ func TestDrop(t *testing.T) {
} }
ok, s, p = m.direct(13) ok, s, p = m.direct(13)
if ok { if !ok || s != 13 || p != 0 {
t.Errorf("Expected not ok") t.Errorf("Expected 13, 0, got %v, %v, %v", ok, s, p)
} }
ok, s, p = m.Reverse(44) ok, s, p = m.Reverse(44)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment