aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test/vppinstance.go
diff options
context:
space:
mode:
Diffstat (limited to 'extras/hs-test/vppinstance.go')
-rw-r--r--extras/hs-test/vppinstance.go132
1 files changed, 66 insertions, 66 deletions
diff --git a/extras/hs-test/vppinstance.go b/extras/hs-test/vppinstance.go
index 257798a4f3d..b45ad6028fe 100644
--- a/extras/hs-test/vppinstance.go
+++ b/extras/hs-test/vppinstance.go
@@ -1,9 +1,10 @@
package main
import (
- "encoding/json"
"fmt"
"github.com/edwarnicke/exechelper"
+ "strings"
+ "time"
"go.fd.io/govpp"
"go.fd.io/govpp/api"
@@ -11,6 +12,7 @@ import (
interfaces "go.fd.io/govpp/binapi/interface"
"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"
)
@@ -79,14 +81,6 @@ func (vpp *VppInstance) Suite() *HstSuite {
return vpp.container.suite
}
-func (vpp *VppInstance) setVppProxy() {
- vpp.actionFuncName = "ConfigureVppProxy"
-}
-
-func (vpp *VppInstance) setEnvoyProxy() {
- vpp.actionFuncName = "ConfigureEnvoyProxy"
-}
-
func (vpp *VppInstance) setCliSocket(filePath string) {
vpp.config.CliSocketFilePath = filePath
}
@@ -107,24 +101,7 @@ func (vpp *VppInstance) getEtcDir() string {
return vpp.container.GetContainerWorkDir() + "/etc/vpp"
}
-func (vpp *VppInstance) legacyStart() error {
- serializedConfig, err := serializeVppConfig(vpp.config)
- if err != nil {
- return fmt.Errorf("serialize vpp config: %v", err)
- }
- args := fmt.Sprintf("%s '%s'", vpp.actionFuncName, serializedConfig)
- _, err = vpp.container.execAction(args)
- if err != nil {
- return fmt.Errorf("vpp start failed: %s", err)
- }
- return nil
-}
-
func (vpp *VppInstance) start() error {
- if vpp.actionFuncName != "" {
- return vpp.legacyStart()
- }
-
// Create folders
containerWorkDir := vpp.container.GetContainerWorkDir()
@@ -185,33 +162,15 @@ func (vpp *VppInstance) vppctl(command string, arguments ...any) string {
return string(output)
}
-func NewVppInstance(c *Container) *VppInstance {
- vppConfig := new(VppConfig)
- vppConfig.CliSocketFilePath = defaultCliSocketFilePath
- vpp := new(VppInstance)
- vpp.container = c
- vpp.config = vppConfig
- return vpp
-}
-
-func serializeVppConfig(vppConfig *VppConfig) (string, error) {
- serializedConfig, err := json.Marshal(vppConfig)
- if err != nil {
- return "", fmt.Errorf("vpp start failed: serializing configuration failed: %s", err)
- }
- return string(serializedConfig), nil
-}
-
-func deserializeVppConfig(input string) (VppConfig, error) {
- var vppConfig VppConfig
- err := json.Unmarshal([]byte(input), &vppConfig)
- if err != nil {
- // Since input is not a valid JSON it is going be used as a variant value
- // for compatibility reasons
- vppConfig.Variant = input
- vppConfig.CliSocketFilePath = defaultCliSocketFilePath
+func (vpp *VppInstance) waitForApp(appName string, timeout int) error {
+ for i := 0; i < timeout; i++ {
+ o := vpp.vppctl("show app")
+ if strings.Contains(o, appName) {
+ return nil
+ }
+ time.Sleep(1 * time.Second)
}
- return vppConfig, nil
+ return fmt.Errorf("Timeout while waiting for app '%s'", appName)
}
func (vpp *VppInstance) createAfPacket(
@@ -247,29 +206,26 @@ func (vpp *VppInstance) createAfPacket(
}
// Add address
- if veth.Ip4AddressWithPrefix() == (AddressWithPrefix{}) {
+ if veth.AddressWithPrefix() == (AddressWithPrefix{}) {
+ var err error
+ var ip4Address string
if veth.peerNetworkNamespace != "" {
- ip4Address, err := veth.addresser.
+ ip4Address, err = veth.addresser.
NewIp4AddressWithNamespace(veth.peerNetworkNamespace)
- if err == nil {
- veth.SetAddress(ip4Address)
- } else {
- return 0, err
- }
} else {
- ip4Address, err := veth.addresser.
+ ip4Address, err = veth.addresser.
NewIp4Address()
- if err == nil {
- veth.SetAddress(ip4Address)
- } else {
- return 0, err
- }
+ }
+ if err == nil {
+ veth.SetAddress(ip4Address)
+ } else {
+ return 0, err
}
}
addressReq := &interfaces.SwInterfaceAddDelAddress{
IsAdd: true,
SwIfIndex: veth.Index(),
- Prefix: veth.Ip4AddressWithPrefix(),
+ Prefix: veth.AddressWithPrefix(),
}
addressReply := &interfaces.SwInterfaceAddDelAddressReply{}
@@ -308,6 +264,50 @@ func (vpp *VppInstance) addAppNamespace(
return nil
}
+func (vpp *VppInstance) createTap(
+ hostInterfaceName string,
+ hostIp4Address IP4AddressWithPrefix,
+ vppIp4Address AddressWithPrefix,
+) error {
+ createTapReq := &tapv2.TapCreateV2{
+ HostIfNameSet: true,
+ HostIfName: hostInterfaceName,
+ HostIP4PrefixSet: true,
+ HostIP4Prefix: hostIp4Address,
+ }
+ createTapReply := &tapv2.TapCreateV2Reply{}
+
+ // Create tap interface
+ if err := vpp.apiChannel.SendRequest(createTapReq).ReceiveReply(createTapReply); err != nil {
+ return err
+ }
+
+ // Add address
+ addAddressReq := &interfaces.SwInterfaceAddDelAddress{
+ IsAdd: true,
+ SwIfIndex: createTapReply.SwIfIndex,
+ Prefix: vppIp4Address,
+ }
+ addAddressReply := &interfaces.SwInterfaceAddDelAddressReply{}
+
+ if err := vpp.apiChannel.SendRequest(addAddressReq).ReceiveReply(addAddressReply); err != nil {
+ return err
+ }
+
+ // Set interface to up
+ upReq := &interfaces.SwInterfaceSetFlags{
+ SwIfIndex: createTapReply.SwIfIndex,
+ Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
+ }
+ upReply := &interfaces.SwInterfaceSetFlagsReply{}
+
+ if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil {
+ return err
+ }
+
+ return nil
+}
+
func (vpp *VppInstance) disconnect() {
vpp.connection.Disconnect()
vpp.apiChannel.Close()