"testing"
"time"
- "git.fd.io/govpp.git/adapter/mock"
- "git.fd.io/govpp.git/examples/bin_api/interfaces"
- "git.fd.io/govpp.git/examples/bin_api/memif"
- "git.fd.io/govpp.git/examples/bin_api/tap"
- "git.fd.io/govpp.git/examples/binapi/vpe"
+ . "github.com/onsi/gomega"
+ "git.fd.io/govpp.git/adapter/mock"
"git.fd.io/govpp.git/api"
- . "github.com/onsi/gomega"
+ "git.fd.io/govpp.git/examples/binapi/interface_types"
+ "git.fd.io/govpp.git/examples/binapi/interfaces"
+ "git.fd.io/govpp.git/examples/binapi/memif"
+ "git.fd.io/govpp.git/examples/binapi/vpe"
)
type testCtx struct {
ctx.conn.Disconnect()
}
-func TestRequestReplyTapConnect(t *testing.T) {
- ctx := setupTest(t)
- defer ctx.teardownTest()
-
- // mock reply
- ctx.mockVpp.MockReply(&tap.TapConnectReply{
- SwIfIndex: 1,
- })
-
- request := &tap.TapConnect{
- TapName: []byte("test-tap-name"),
- UseRandomMac: 1,
- }
- reply := &tap.TapConnectReply{}
-
- err := ctx.ch.SendRequest(request).ReceiveReply(reply)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(reply.Retval).To(BeEquivalentTo(0),
- "Incorrect Retval value for TapConnectReply")
- Expect(reply.SwIfIndex).To(BeEquivalentTo(1),
- "Incorrect SwIfIndex value for TapConnectReply")
-}
-
-func TestRequestReplyTapModify(t *testing.T) {
- ctx := setupTest(t)
- defer ctx.teardownTest()
-
- // mock reply
- ctx.mockVpp.MockReply(&tap.TapModifyReply{
- SwIfIndex: 2,
- })
-
- request := &tap.TapModify{
- TapName: []byte("test-tap-modify"),
- UseRandomMac: 1,
- CustomDevInstance: 1,
- }
- reply := &tap.TapModifyReply{}
-
- err := ctx.ch.SendRequest(request).ReceiveReply(reply)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(reply.Retval).To(BeEquivalentTo(0),
- "Incorrect Retval value for TapModifyReply")
- Expect(reply.SwIfIndex).To(BeEquivalentTo(2),
- "Incorrect SwIfIndex value for TapModifyReply")
-}
-
-func TestRequestReplyTapDelete(t *testing.T) {
- ctx := setupTest(t)
- defer ctx.teardownTest()
-
- // mock reply
- ctx.mockVpp.MockReply(&tap.TapDeleteReply{})
-
- request := &tap.TapDelete{
- SwIfIndex: 3,
- }
- reply := &tap.TapDeleteReply{}
-
- err := ctx.ch.SendRequest(request).ReceiveReply(reply)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(reply.Retval).To(BeEquivalentTo(0),
- "Incorrect Retval value for TapDeleteReply")
-}
-
-func TestRequestReplySwInterfaceTapDump(t *testing.T) {
- ctx := setupTest(t)
- defer ctx.teardownTest()
-
- // mock reply
- byteName := []byte("dev-name-test")
- ctx.mockVpp.MockReply(&tap.SwInterfaceTapDetails{
- SwIfIndex: 25,
- DevName: byteName,
- })
-
- request := &tap.SwInterfaceTapDump{}
- reply := &tap.SwInterfaceTapDetails{}
-
- err := ctx.ch.SendRequest(request).ReceiveReply(reply)
- Expect(err).ShouldNot(HaveOccurred())
- Expect(reply.SwIfIndex).To(BeEquivalentTo(25),
- "Incorrect SwIfIndex value for SwInterfaceTapDetails")
- Expect(reply.DevName).ToNot(BeEquivalentTo(byteName),
- "Incorrect DevName value for SwInterfaceTapDetails")
-}
-
func TestRequestReplyMemifCreate(t *testing.T) {
ctx := setupTest(t)
defer ctx.teardownTest()
// mock reply
ctx.mockVpp.MockReply(&memif.MemifDetails{
SwIfIndex: 25,
- IfName: []byte("memif-name"),
+ IfName: "memif-name",
Role: 0,
})
"Incorrect Role value for MemifDetails")
}
-func TestMultiRequestReplySwInterfaceTapDump(t *testing.T) {
- ctx := setupTest(t)
- defer ctx.teardownTest()
-
- // mock reply
- var msgs []api.Message
- for i := 1; i <= 10; i++ {
- msgs = append(msgs, &tap.SwInterfaceTapDetails{
- SwIfIndex: uint32(i),
- DevName: []byte("dev-name-test"),
- })
- }
- ctx.mockVpp.MockReply(msgs...)
- ctx.mockVpp.MockReply(&ControlPingReply{})
-
- reqCtx := ctx.ch.SendMultiRequest(&tap.SwInterfaceTapDump{})
- cnt := 0
- for {
- msg := &tap.SwInterfaceTapDetails{}
- stop, err := reqCtx.ReceiveReply(msg)
- if stop {
- break
- }
- Expect(err).ShouldNot(HaveOccurred())
- cnt++
- }
- Expect(cnt).To(BeEquivalentTo(10))
-}
-
func TestMultiRequestReplySwInterfaceMemifDump(t *testing.T) {
ctx := setupTest(t)
defer ctx.teardownTest()
var msgs []api.Message
for i := 1; i <= 10; i++ {
msgs = append(msgs, &memif.MemifDetails{
- SwIfIndex: uint32(i),
+ SwIfIndex: interface_types.InterfaceIndex(i),
})
}
ctx.mockVpp.MockReply(msgs...)
// mock event and force its delivery
ctx.mockVpp.MockReply(&interfaces.SwInterfaceEvent{
- SwIfIndex: 2,
- LinkUpDown: 1,
+ SwIfIndex: 2,
+ Flags: interface_types.IF_STATUS_API_FLAG_LINK_UP,
})
ctx.mockVpp.SendMsg(0, []byte(""))
// verify the received notifications
Expect(notif.SwIfIndex).To(BeEquivalentTo(2), "Incorrect SwIfIndex value for SwInterfaceSetFlags")
- Expect(notif.LinkUpDown).To(BeEquivalentTo(1), "Incorrect LinkUpDown value for SwInterfaceSetFlags")
+ Expect(notif.Flags).To(BeEquivalentTo(interface_types.IF_STATUS_API_FLAG_LINK_UP), "Incorrect LinkUpDown value for SwInterfaceSetFlags")
err = sub.Unsubscribe()
Expect(err).ShouldNot(HaveOccurred())
ctx.mockVpp.MockReply(
&interfaces.SwInterfaceDetails{
SwIfIndex: 1,
- InterfaceName: []byte("if-name-test"),
+ InterfaceName: "if-name-test",
},
&interfaces.SwInterfaceDetails{
SwIfIndex: 2,
- InterfaceName: []byte("if-name-test"),
+ InterfaceName: "if-name-test",
},
&interfaces.SwInterfaceDetails{
SwIfIndex: 3,
- InterfaceName: []byte("if-name-test"),
+ InterfaceName: "if-name-test",
},
)
ctx.mockVpp.MockReply(&ControlPingReply{})
for i := 1; i <= 3; i++ {
msgs = append(msgs, mock.MsgWithContext{
Msg: &interfaces.SwInterfaceDetails{
- SwIfIndex: uint32(i),
- InterfaceName: []byte("if-name-test"),
+ SwIfIndex: interface_types.InterfaceIndex(i),
+ InterfaceName: "if-name-test",
},
Multipart: true,
SeqNum: 1,
msgs = append(msgs,
mock.MsgWithContext{
Msg: &interfaces.SwInterfaceDetails{
- SwIfIndex: uint32(i),
- InterfaceName: []byte("if-name-test"),
+ SwIfIndex: interface_types.InterfaceIndex(i),
+ InterfaceName: "if-name-test",
},
Multipart: true,
SeqNum: 2,
},
// normal reply for next request
mock.MsgWithContext{
- Msg: &tap.TapConnectReply{},
+ Msg: &interfaces.SwInterfaceSetFlagsReply{},
SeqNum: 3,
},
)
- req := &tap.TapConnect{
- TapName: []byte("test-tap-name"),
- UseRandomMac: 1,
+ req := &interfaces.SwInterfaceSetFlags{
+ SwIfIndex: 1,
+ Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
}
- reply := &tap.TapConnectReply{}
+ reply := &interfaces.SwInterfaceSetFlagsReply{}
// should succeed
err = ctx.ch.SendRequest(req).ReceiveReply(reply)
for i := 1; i <= 3; i++ {
msgs = append(msgs, mock.MsgWithContext{
Msg: &interfaces.SwInterfaceDetails{
- SwIfIndex: uint32(i),
- InterfaceName: []byte("if-name-test"),
+ SwIfIndex: interface_types.InterfaceIndex(i),
+ InterfaceName: "if-name-test",
},
Multipart: true,
SeqNum: 2,
ctx.mockVpp.MockReplyWithContext(msgs...)
// normal reply for next request
- ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &tap.TapConnectReply{}, SeqNum: 3})
+ ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &interfaces.SwInterfaceSetFlagsReply{}, SeqNum: 3})
- req := &tap.TapConnect{
- TapName: []byte("test-tap-name"),
- UseRandomMac: 1,
+ req := &interfaces.SwInterfaceSetFlags{
+ SwIfIndex: 1,
+ Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
}
- reply := &tap.TapConnectReply{}
+ reply := &interfaces.SwInterfaceSetFlagsReply{}
// should succeed
err = ctx.ch.SendRequest(req).ReceiveReply(reply)
// second should fail with error invalid message ID
err = ctx.ch.SendRequest(&ControlPing{}).ReceiveReply(&ControlPingReply{})
Expect(err).Should(HaveOccurred())
- Expect(err.Error()).To(ContainSubstring("invalid message ID"))
+ Expect(err.Error()).To(ContainSubstring("unexpected message"))
}