-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgovpp_test.go
More file actions
executable file
·92 lines (71 loc) · 1.61 KB
/
govpp_test.go
File metadata and controls
executable file
·92 lines (71 loc) · 1.61 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package govpp
import (
"bytes"
"testing"
"vpp-integration-with-etcd/vpp/govpp/api"
"github.com/lunixbochs/struc"
)
type testRequest struct {
SwIfIndex uint32
AdminUpDown uint8
LinkUpDown uint8
Deleted uint8
}
func (*testRequest) GetMessageName() string {
return "test_request"
}
func (*testRequest) GetCrcString() string {
return "c230f9b1"
}
type testReplyWithHeader struct {
VlMsgID uint16
Context uint32
Retval int32
}
type testReply struct {
Retval int32
}
func (*testReply) GetMessageName() string {
return "test_reply"
}
func (*testReply) GetCrcString() string {
return "dfbf3afa"
}
type mockVppAdapter struct {
callback MsgRecvCbFunc
}
func (a *mockVppAdapter) Connect() {
// no op
}
func (a *mockVppAdapter) Disconnect() {
// no op
}
func (a *mockVppAdapter) GetMsgId(msgName string, msgCrc string) uint16 {
return 53
}
func (a *mockVppAdapter) SendMsg(clientId uint32, data []byte) {
buf := new(bytes.Buffer)
struc.Pack(buf, &testReplyWithHeader{})
a.callback(clientId, 54, buf.Bytes())
}
func (a *mockVppAdapter) SetMsgRecvCallback(cb MsgRecvCbFunc) {
a.callback = cb
}
func TestClient(t *testing.T) {
vpp := &mockVppAdapter{}
cli := connectWithAdapter(vpp)
defer cli.Disconnect()
ch := cli.NewApiChannel()
defer ch.Close()
// option 1 - channels
req := &testRequest{SwIfIndex: 0, AdminUpDown: 1}
ch.ReqChan <- &api.VppRequest{Message: req}
vppReply := <-ch.ReplyChan
reply := &testReply{}
ch.Decoder.DecodeMsg(vppReply.Data, reply)
// option 2 - API
req2 := &testRequest{SwIfIndex: 0, AdminUpDown: 1}
ch.SendRequest(req2)
reply2 := &testReply{}
ch.ReceiveReply(reply2)
}