diff options
author | Adrian Villin <avillin@cisco.com> | 2024-05-15 04:33:41 -0400 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2024-05-17 03:11:13 +0000 |
commit | 46d66000fbccaaf782ca0313107355c77768f164 (patch) | |
tree | ed8fe48244b2d459244816ca43d9b832bd3586b6 /extras/hs-test | |
parent | f66702df6bfc24072a40ad39ffa9ff7099e50f32 (diff) |
hs-test: updated api calls
Type: test
Change-Id: I2583ee74426ef154d03d4991b78ab57c5cec436f
Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test')
-rw-r--r-- | extras/hs-test/container.go | 2 | ||||
-rw-r--r-- | extras/hs-test/echo_test.go | 2 | ||||
-rw-r--r-- | extras/hs-test/go.mod | 2 | ||||
-rw-r--r-- | extras/hs-test/hst_suite.go | 8 | ||||
-rw-r--r-- | extras/hs-test/vppinstance.go | 139 |
5 files changed, 106 insertions, 47 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go index 45f41d26a87..3ac5eee3aaa 100644 --- a/extras/hs-test/container.go +++ b/extras/hs-test/container.go @@ -340,7 +340,7 @@ func (c *Container) log(maxLines int) (string, error) { } func (c *Container) stop() error { - if c.vppInstance != nil && c.vppInstance.apiChannel != nil { + if c.vppInstance != nil && c.vppInstance.apiStream != nil { c.vppInstance.saveLogs() c.vppInstance.disconnect() } diff --git a/extras/hs-test/echo_test.go b/extras/hs-test/echo_test.go index 0515b5e0411..33728db6c97 100644 --- a/extras/hs-test/echo_test.go +++ b/extras/hs-test/echo_test.go @@ -45,5 +45,5 @@ func TcpWithLossTest(s *VethsSuite) { serverVeth.ip4AddressString()) s.log(output) s.assertNotEqual(len(output), 0) - s.assertNotContains(output, "failed: timeout", output) + s.assertNotContains(output, "failed", output) } diff --git a/extras/hs-test/go.mod b/extras/hs-test/go.mod index 0f3854d2148..3be9ba20a86 100644 --- a/extras/hs-test/go.mod +++ b/extras/hs-test/go.mod @@ -26,7 +26,7 @@ require ( github.com/onsi/ginkgo/v2 v2.16.0 github.com/onsi/gomega v1.32.0 github.com/pkg/errors v0.9.1 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect + github.com/sirupsen/logrus v1.9.3 github.com/vishvananda/netns v0.0.4 // indirect golang.org/x/sys v0.16.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/extras/hs-test/hst_suite.go b/extras/hs-test/hst_suite.go index 725fee73f24..35553f00ff3 100644 --- a/extras/hs-test/hst_suite.go +++ b/extras/hs-test/hst_suite.go @@ -40,8 +40,8 @@ type HstSuite struct { cpuContexts []*CpuContext cpuPerVpp int pid string - logger *log.Logger - logFile *os.File + logger *log.Logger + logFile *os.File } func (s *HstSuite) SetupSuite() { @@ -196,7 +196,7 @@ func (s *HstSuite) assertNotEmpty(object interface{}, msgAndArgs ...interface{}) Expect(object).ToNot(BeEmpty(), msgAndArgs...) } -func (s *HstSuite) createLogger(){ +func (s *HstSuite) createLogger() { suiteName := CurrentSpecReport().ContainerHierarchyTexts[0] var err error s.logFile, err = os.Create("summary/" + suiteName + ".log") @@ -475,7 +475,7 @@ func (s *HstSuite) startHttpServer(running chan struct{}, done chan struct{}, ad err := cmd.Start() s.log(cmd) if err != nil { - fmt.Println("Failed to start http server: " + fmt.Sprint(err)) + s.log("Failed to start http server: " + fmt.Sprint(err)) return } running <- struct{}{} diff --git a/extras/hs-test/vppinstance.go b/extras/hs-test/vppinstance.go index 9b400cfcb77..11f68a61eac 100644 --- a/extras/hs-test/vppinstance.go +++ b/extras/hs-test/vppinstance.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "io" "os" @@ -11,9 +12,9 @@ import ( "syscall" "time" - "github.com/sirupsen/logrus" "github.com/edwarnicke/exechelper" . "github.com/onsi/ginkgo/v2" + "github.com/sirupsen/logrus" "go.fd.io/govpp" "go.fd.io/govpp/api" @@ -22,7 +23,6 @@ import ( "go.fd.io/govpp/binapi/interface_types" "go.fd.io/govpp/binapi/session" "go.fd.io/govpp/binapi/tapv2" - "go.fd.io/govpp/binapi/vpe" "go.fd.io/govpp/core" ) @@ -83,7 +83,7 @@ type VppInstance struct { container *Container additionalConfig []Stanza connection *core.Connection - apiChannel api.Channel + apiStream api.Stream cpus []int } @@ -169,7 +169,7 @@ func (vpp *VppInstance) start() error { core.DefaultMaxReconnectAttempts, core.DefaultReconnectInterval) if err != nil { - fmt.Println("async connect error: ", err) + vpp.getSuite().log("async connect error: " + fmt.Sprint(err)) return err } vpp.connection = conn @@ -177,24 +177,19 @@ func (vpp *VppInstance) start() error { // ... wait for Connected event e := <-connEv if e.State != core.Connected { - fmt.Println("connecting to VPP failed: ", e.Error) + vpp.getSuite().log("connecting to VPP failed: " + fmt.Sprint(e.Error)) } - // ... check compatibility of used messages - ch, err := conn.NewAPIChannel() + ch, err := conn.NewStream( + context.Background(), + core.WithRequestSize(50), + core.WithReplySize(50), + core.WithReplyTimeout(time.Second*10)) if err != nil { - fmt.Println("creating channel failed: ", err) - return err - } - if err := ch.CheckCompatiblity(vpe.AllMessages()...); err != nil { - fmt.Println("compatibility error: ", err) + vpp.getSuite().log("creating stream failed: " + fmt.Sprint(err)) return err } - if err := ch.CheckCompatiblity(interfaces.AllMessages()...); err != nil { - fmt.Println("compatibility error: ", err) - return err - } - vpp.apiChannel = ch + vpp.apiStream = ch return nil } @@ -242,31 +237,50 @@ func (vpp *VppInstance) waitForApp(appName string, timeout int) { func (vpp *VppInstance) createAfPacket( veth *NetInterface, ) (interface_types.InterfaceIndex, error) { - createReq := &af_packet.AfPacketCreateV2{ + createReq := &af_packet.AfPacketCreateV3{ + Mode: 1, UseRandomHwAddr: true, HostIfName: veth.Name(), + Flags: af_packet.AfPacketFlags(11), } if veth.hwAddress != (MacAddress{}) { createReq.UseRandomHwAddr = false createReq.HwAddr = veth.hwAddress } - createReply := &af_packet.AfPacketCreateV2Reply{} vpp.getSuite().log("create af-packet interface " + veth.Name()) - if err := vpp.apiChannel.SendRequest(createReq).ReceiveReply(createReply); err != nil { + if err := vpp.apiStream.SendMsg(createReq); err != nil { + vpp.getSuite().hstFail() return 0, err } - veth.index = createReply.SwIfIndex + replymsg, err := vpp.apiStream.RecvMsg() + if err != nil { + return 0, err + } + reply := replymsg.(*af_packet.AfPacketCreateV3Reply) + err = api.RetvalToVPPApiError(reply.Retval) + if err != nil { + return 0, err + } + + veth.index = reply.SwIfIndex // Set to up upReq := &interfaces.SwInterfaceSetFlags{ SwIfIndex: veth.index, Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP, } - upReply := &interfaces.SwInterfaceSetFlagsReply{} vpp.getSuite().log("set af-packet interface " + veth.Name() + " up") - if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil { + if err := vpp.apiStream.SendMsg(upReq); err != nil { + return 0, err + } + replymsg, err = vpp.apiStream.RecvMsg() + if err != nil { + return 0, err + } + reply2 := replymsg.(*interfaces.SwInterfaceSetFlagsReply) + if err = api.RetvalToVPPApiError(reply2.Retval); err != nil { return 0, err } @@ -285,10 +299,18 @@ func (vpp *VppInstance) createAfPacket( SwIfIndex: veth.index, Prefix: veth.addressWithPrefix(), } - addressReply := &interfaces.SwInterfaceAddDelAddressReply{} vpp.getSuite().log("af-packet interface " + veth.Name() + " add address " + veth.ip4Address) - if err := vpp.apiChannel.SendRequest(addressReq).ReceiveReply(addressReply); err != nil { + if err := vpp.apiStream.SendMsg(addressReq); err != nil { + return 0, err + } + replymsg, err = vpp.apiStream.RecvMsg() + if err != nil { + return 0, err + } + reply3 := replymsg.(*interfaces.SwInterfaceAddDelAddressReply) + err = api.RetvalToVPPApiError(reply3.Retval) + if err != nil { return 0, err } @@ -300,25 +322,41 @@ func (vpp *VppInstance) addAppNamespace( ifx interface_types.InterfaceIndex, namespaceId string, ) error { - req := &session.AppNamespaceAddDelV2{ + req := &session.AppNamespaceAddDelV4{ + IsAdd: true, Secret: secret, SwIfIndex: ifx, NamespaceID: namespaceId, + SockName: defaultApiSocketFilePath, } - reply := &session.AppNamespaceAddDelV2Reply{} vpp.getSuite().log("add app namespace " + namespaceId) - if err := vpp.apiChannel.SendRequest(req).ReceiveReply(reply); err != nil { + if err := vpp.apiStream.SendMsg(req); err != nil { + return err + } + replymsg, err := vpp.apiStream.RecvMsg() + if err != nil { + return err + } + reply := replymsg.(*session.AppNamespaceAddDelV4Reply) + if err = api.RetvalToVPPApiError(reply.Retval); err != nil { return err } sessionReq := &session.SessionEnableDisable{ IsEnable: true, } - sessionReply := &session.SessionEnableDisableReply{} vpp.getSuite().log("enable app namespace " + namespaceId) - if err := vpp.apiChannel.SendRequest(sessionReq).ReceiveReply(sessionReply); err != nil { + if err := vpp.apiStream.SendMsg(sessionReq); err != nil { + return err + } + replymsg, err = vpp.apiStream.RecvMsg() + if err != nil { + return err + } + reply2 := replymsg.(*session.SessionEnableDisableReply) + if err = api.RetvalToVPPApiError(reply2.Retval); err != nil { return err } @@ -333,43 +371,64 @@ func (vpp *VppInstance) createTap( if len(tapId) > 0 { id = tapId[0] } - createTapReq := &tapv2.TapCreateV2{ + createTapReq := &tapv2.TapCreateV3{ ID: id, HostIfNameSet: true, HostIfName: tap.Name(), HostIP4PrefixSet: true, HostIP4Prefix: tap.ip4AddressWithPrefix(), } - createTapReply := &tapv2.TapCreateV2Reply{} vpp.getSuite().log("create tap interface " + tap.Name()) // Create tap interface - if err := vpp.apiChannel.SendRequest(createTapReq).ReceiveReply(createTapReply); err != nil { + if err := vpp.apiStream.SendMsg(createTapReq); err != nil { + return err + } + replymsg, err := vpp.apiStream.RecvMsg() + if err != nil { + return err + } + reply := replymsg.(*tapv2.TapCreateV3Reply) + if err = api.RetvalToVPPApiError(reply.Retval); err != nil { return err } // Add address addAddressReq := &interfaces.SwInterfaceAddDelAddress{ IsAdd: true, - SwIfIndex: createTapReply.SwIfIndex, + SwIfIndex: reply.SwIfIndex, Prefix: tap.peer.addressWithPrefix(), } - addAddressReply := &interfaces.SwInterfaceAddDelAddressReply{} vpp.getSuite().log("tap interface " + tap.Name() + " add address " + tap.peer.ip4Address) - if err := vpp.apiChannel.SendRequest(addAddressReq).ReceiveReply(addAddressReply); err != nil { + if err := vpp.apiStream.SendMsg(addAddressReq); err != nil { + return err + } + replymsg, err = vpp.apiStream.RecvMsg() + if err != nil { + return err + } + reply2 := replymsg.(*interfaces.SwInterfaceAddDelAddressReply) + if err = api.RetvalToVPPApiError(reply2.Retval); err != nil { return err } // Set interface to up upReq := &interfaces.SwInterfaceSetFlags{ - SwIfIndex: createTapReply.SwIfIndex, + SwIfIndex: reply.SwIfIndex, Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP, } - upReply := &interfaces.SwInterfaceSetFlagsReply{} vpp.getSuite().log("set tap interface " + tap.Name() + " up") - if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil { + if err := vpp.apiStream.SendMsg(upReq); err != nil { + return err + } + replymsg, err = vpp.apiStream.RecvMsg() + if err != nil { + return err + } + reply3 := replymsg.(*interfaces.SwInterfaceSetFlagsReply) + if err = api.RetvalToVPPApiError(reply3.Retval); err != nil { return err } @@ -386,7 +445,7 @@ func (vpp *VppInstance) saveLogs() { func (vpp *VppInstance) disconnect() { vpp.connection.Disconnect() - vpp.apiChannel.Close() + vpp.apiStream.Close() } func (vpp *VppInstance) generateCpuConfig() string { |