diff options
author | Filip Tehlar <ftehlar@cisco.com> | 2022-12-21 08:59:16 +0100 |
---|---|---|
committer | Filip Tehlar <ftehlar@cisco.com> | 2023-01-09 11:39:06 +0100 |
commit | c204c87c186993704927beffa4d5b1cafaf9a193 (patch) | |
tree | eeb2e5e7a8baad5252df7c8e02c488a2b88432bc /extras/hs-test/actions.go | |
parent | 227660b9969410f29d6b3d14eba16be5f57fbffe (diff) |
hs-test: add nginx test
Type: test
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Change-Id: Idd5352f254df0d1f36c1270e73440c9287247b81
Diffstat (limited to 'extras/hs-test/actions.go')
-rwxr-xr-x | extras/hs-test/actions.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/extras/hs-test/actions.go b/extras/hs-test/actions.go index 34096df27ba..279589b5d41 100755 --- a/extras/hs-test/actions.go +++ b/extras/hs-test/actions.go @@ -15,6 +15,7 @@ import ( "github.com/edwarnicke/govpp/binapi/interface_types" ip_types "github.com/edwarnicke/govpp/binapi/ip_types" "github.com/edwarnicke/govpp/binapi/session" + "github.com/edwarnicke/govpp/binapi/tapv2" "github.com/edwarnicke/govpp/binapi/vlib" "github.com/edwarnicke/vpphelper" ) @@ -347,3 +348,62 @@ func (a *Actions) ConfigureHttpTps(args []string) *ActionResult { <-ctx.Done() return nil } + +func (a *Actions) ConfigureTap(args []string) *ActionResult { + var startup Stanza + startup. + NewStanza("session"). + Append("enable"). + Append("use-app-socket-api").Close() + + ctx, cancel := newVppContext() + defer cancel() + con, vppErrCh := vpphelper.StartAndDialContext(ctx, + vpphelper.WithRootDir(workDir), + vpphelper.WithVppConfig(configTemplate+startup.ToString())) + exitOnErrCh(ctx, cancel, vppErrCh) + ifaceClient := interfaces.NewServiceClient(con) + + pref, err := ip_types.ParseIP4Prefix("10.10.10.2/24") + if err != nil { + return NewActionResult(err, ActionResultWithDesc("failed to parse ip4 address")) + } + createTapReply, err := tapv2.NewServiceClient(con).TapCreateV2(ctx, &tapv2.TapCreateV2{ + HostIfNameSet: true, + HostIfName: "tap0", + HostIP4PrefixSet: true, + HostIP4Prefix: ip_types.IP4AddressWithPrefix(pref), + }) + if err != nil { + return NewActionResult(err, ActionResultWithDesc("failed to configure tap")) + } + ipPrefix, err := ip_types.ParseAddressWithPrefix("10.10.10.1/24") + if err != nil { + return NewActionResult(err, ActionResultWithDesc("parsing ip address failed")) + } + ipAddress := &interfaces.SwInterfaceAddDelAddress{ + IsAdd: true, + SwIfIndex: createTapReply.SwIfIndex, + Prefix: ipPrefix, + } + _, errx := ifaceClient.SwInterfaceAddDelAddress(ctx, ipAddress) + if errx != nil { + return NewActionResult(err, ActionResultWithDesc("configuring ip address failed")) + } + _, err = ifaceClient.SwInterfaceSetFlags(ctx, &interfaces.SwInterfaceSetFlags{ + SwIfIndex: createTapReply.SwIfIndex, + Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP, + }) + if err != nil { + return NewActionResult(err, ActionResultWithDesc("failed to set interface state")) + } + _, err = session.NewServiceClient(con).SessionEnableDisable(ctx, &session.SessionEnableDisable{ + IsEnable: true, + }) + if err != nil { + return NewActionResult(err, ActionResultWithDesc("configuration failed")) + } + writeSyncFile(OkResult()) + <-ctx.Done() + return nil +} |