-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathvnet_test.go
76 lines (61 loc) · 2.17 KB
/
vnet_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
//go:build !js
// +build !js
package webrtc
import (
"testing"
"time"
"github.com/pion/interceptor"
"github.com/pion/logging"
"github.com/pion/transport/v3/vnet"
"github.com/stretchr/testify/assert"
)
func createVNetPair(t *testing.T, interceptorRegistry *interceptor.Registry) (
*PeerConnection,
*PeerConnection,
*vnet.Router,
) {
t.Helper()
// Create a root router
wan, err := vnet.NewRouter(&vnet.RouterConfig{
CIDR: "1.2.3.0/24",
LoggerFactory: logging.NewDefaultLoggerFactory(),
})
assert.NoError(t, err)
// Create a network interface for offerer
offerVNet, err := vnet.NewNet(&vnet.NetConfig{
StaticIPs: []string{"1.2.3.4"},
})
assert.NoError(t, err)
// Add the network interface to the router
assert.NoError(t, wan.AddNet(offerVNet))
offerSettingEngine := SettingEngine{}
offerSettingEngine.SetNet(offerVNet)
offerSettingEngine.SetICETimeouts(time.Second, time.Second, time.Millisecond*200)
// Create a network interface for answerer
answerVNet, err := vnet.NewNet(&vnet.NetConfig{
StaticIPs: []string{"1.2.3.5"},
})
assert.NoError(t, err)
// Add the network interface to the router
assert.NoError(t, wan.AddNet(answerVNet))
answerSettingEngine := SettingEngine{}
answerSettingEngine.SetNet(answerVNet)
answerSettingEngine.SetICETimeouts(time.Second, time.Second, time.Millisecond*200)
// Start the virtual network by calling Start() on the root router
assert.NoError(t, wan.Start())
offerOptions := []func(*API){WithSettingEngine(offerSettingEngine)}
if interceptorRegistry != nil {
offerOptions = append(offerOptions, WithInterceptorRegistry(interceptorRegistry))
}
offerPeerConnection, err := NewAPI(offerOptions...).NewPeerConnection(Configuration{})
assert.NoError(t, err)
answerOptions := []func(*API){WithSettingEngine(answerSettingEngine)}
if interceptorRegistry != nil {
answerOptions = append(answerOptions, WithInterceptorRegistry(interceptorRegistry))
}
answerPeerConnection, err := NewAPI(answerOptions...).NewPeerConnection(Configuration{})
assert.NoError(t, err)
return offerPeerConnection, answerPeerConnection, wan
}