@@ -3,7 +3,6 @@ package awl
33import (
44 "fmt"
55 "os"
6- "sync/atomic"
76 "testing"
87 "time"
98
@@ -40,15 +39,26 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
4039 bandwidthMbps int
4140 }{
4241 {
43- name : "Fiber_300Mbps_1ms " ,
42+ name : "Fiber_200Mbps_1ms " ,
4443 latency : 1 * time .Millisecond ,
45- bandwidthMbps : 300 * Mbps ,
44+ bandwidthMbps : 200 * Mbps ,
4645 },
4746 {
48- name : "LongDistFiber_300Mbps_200ms " ,
47+ name : "LongDistFiber_200Mbps_200ms " ,
4948 latency : 200 * time .Millisecond ,
50- bandwidthMbps : 300 * Mbps ,
49+ bandwidthMbps : 200 * Mbps ,
5150 },
51+ {
52+ name : "Fiber_100Mbps_1ms" ,
53+ latency : 1 * time .Millisecond ,
54+ bandwidthMbps : 100 * Mbps ,
55+ },
56+ {
57+ name : "LongDistFiber_100Mbps_200ms" ,
58+ latency : 200 * time .Millisecond ,
59+ bandwidthMbps : 100 * Mbps ,
60+ },
61+
5262 {
5363 name : "Cable_10Mbps_1ms" ,
5464 latency : 1 * time .Millisecond ,
@@ -74,6 +84,7 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
7484 latency : 300 * time .Millisecond ,
7585 bandwidthMbps : 10 * Mbps ,
7686 },
87+
7788 {
7889 name : "Cable_50Mbps_1ms" ,
7990 latency : 1 * time .Millisecond ,
@@ -99,6 +110,7 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
99110 latency : 300 * time .Millisecond ,
100111 bandwidthMbps : 50 * Mbps ,
101112 },
113+
102114 {
103115 name : "DSL_20Mbps_25ms" ,
104116 latency : 25 * time .Millisecond ,
@@ -126,7 +138,7 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
126138 // TODO: try with different packet sizes
127139 // we probably should aim for one packet per UDP datagram
128140 const packetSize = 3500 // Typical VPN packet size
129- const testDuration = 10 * time .Second
141+ const testDuration = 30 * time .Second
130142
131143 // Setup link properties for the simulation
132144 // We simulate a symmetric link between the two peers
@@ -136,6 +148,8 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
136148 }
137149
138150 // Create two peers
151+ // uncomment to debug QUIC events
152+ // t.Setenv("QLOGDIR", "./test-simnet")
139153 ctx := t .Context ()
140154 extraLibp2pOpts := []libp2p.Option {
141155 simlibp2p .QUICSimnet (net , linkSettings ),
@@ -156,10 +170,14 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
156170 peer2 .tun .ClearInboundCount ()
157171
158172 // Send packets
159- var packetsSent int64
160173 done := make (chan struct {})
161174 startTime := time .Now ()
162175
176+ packetsBatch := make ([][]byte , TestTUNBatchSize * 10 )
177+ for i := range packetsBatch {
178+ packetsBatch [i ] = packet
179+ }
180+
163181 go func () {
164182 defer close (done )
165183 timer := time .NewTimer (testDuration )
@@ -171,22 +189,11 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
171189 return
172190 case <- ctx .Done ():
173191 return
174- default :
192+ case peer1 . tun . Outbound <- packetsBatch :
175193 // ok
176194 }
177195
178- // Send with "batches" to minimize runtime overhead for select
179- for range 10 {
180- peer1 .tun .Outbound <- packet
181- atomic .AddInt64 (& packetsSent , 1 )
182- }
183-
184- // TODO:
185- // Slight throttle to keep drops lower
186- // const sleepEvery = 200
187- // if newCount != 0 && newCount%sleepEvery == 0 {
188- // time.Sleep(1 * time.Millisecond)
189- // }
196+ // TODO: add ratelimit for TestTUN to remove busyloop
190197 }
191198 }()
192199
@@ -199,7 +206,7 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
199206
200207 // Collect metrics
201208 received := peer2 .tun .InboundCount ()
202- sent := atomic . LoadInt64 ( & packetsSent )
209+ sent := peer1 . tun . OutboundCount ( )
203210
204211 packetLoss := (float64 (1 ) - float64 (received )/ float64 (sent )) * 100
205212
@@ -219,6 +226,9 @@ func TestSimulatedTunnelPerformance(t *testing.T) {
219226 // TODO: calculate p50/p95/p99 latency, jitter
220227 })
221228 })
229+
230+ // cool down a bit
231+ time .Sleep (time .Second )
222232 }
223233
224234 table .Render ()
0 commit comments