"github.com/edwarnicke/vpphelper"
)
-func RegisterActions() {
- cfgTable = make(map[string]func([]string) *ActionResult)
- reg("echo-srv-internal", Configure2Veths)
- reg("echo-cln-internal", Configure2Veths)
- reg("echo-client", RunEchoClient)
- reg("echo-server", RunEchoServer)
- reg("vpp-proxy", ConfigureVppProxy)
- reg("vpp-envoy", ConfigureEnvoyProxy)
- reg("http-tps", ConfigureHttpTps)
- reg("2veths", Configure2Veths)
- reg("vcl-test-server", RunVclEchoServer)
- reg("vcl-test-client", RunVclEchoClient)
- reg("http-cli-srv", RunHttpCliSrv)
- reg("http-cli-cln", RunHttpCliCln)
+type ConfFn func(context.Context, api.Connection) error
+
+type Actions struct {
}
func configureProxyTcp(ifName0, ipAddr0, ifName1, ipAddr1 string) ConfFn {
}
}
-func RunHttpCliSrv(args []string) *ActionResult {
+func (a *Actions) RunHttpCliSrv(args []string) *ActionResult {
cmd := fmt.Sprintf("http cli server")
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func RunHttpCliCln(args []string) *ActionResult {
+func (a *Actions) RunHttpCliCln(args []string) *ActionResult {
cmd := fmt.Sprintf("http cli client uri http://10.10.10.1/80 query %s", getArgs())
fmt.Println(cmd)
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func ConfigureVppProxy(args []string) *ActionResult {
+func (a *Actions) ConfigureVppProxy(args []string) *ActionResult {
ctx, cancel := newVppContext()
defer cancel()
return nil
}
-func ConfigureEnvoyProxy(args []string) *ActionResult {
+func (a *Actions) ConfigureEnvoyProxy(args []string) *ActionResult {
var startup Stanza
startup.
NewStanza("session").
return NewActionResult(err, ActionResultWithStdout(cliInbandReply.Reply))
}
-func RunEchoClient(args []string) *ActionResult {
+func (a *Actions) RunEchoClient(args []string) *ActionResult {
outBuff := bytes.NewBuffer([]byte{})
errBuff := bytes.NewBuffer([]byte{})
ActionResultWithStderr(string(errBuff.String())))
}
-func RunEchoServer(args []string) *ActionResult {
+func (a *Actions) RunEchoServer(args []string) *ActionResult {
cmd := fmt.Sprintf("vpp_echo server TX=RX socket-name /tmp/echo-srv/var/run/app_ns_sockets/1 use-app-socket-api uri %s://10.10.10.1/12344", args[2])
errCh := exechelper.Start(cmd)
select {
return nil
}
-func RunEchoSrvInternal() *ActionResult {
+func (a *Actions) RunEchoSrvInternal(args []string) *ActionResult {
cmd := fmt.Sprintf("test echo server %s uri tcp://10.10.10.1/1234", getArgs())
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func RunEchoClnInternal() *ActionResult {
+func (a *Actions) RunEchoClnInternal(args []string) *ActionResult {
cmd := fmt.Sprintf("test echo client %s uri tcp://10.10.10.1/1234", getArgs())
- return ApiCliInband("/tmp/2veths", cmd)
+ return ApiCliInband("/tmp/Configure2Veths", cmd)
}
-func RunVclEchoServer(args []string) *ActionResult {
+func (a *Actions) RunVclEchoServer(args []string) *ActionResult {
f, err := os.Create("vcl_1.conf")
if err != nil {
return NewActionResult(err, ActionResultWithStderr(("create vcl config: ")))
return nil
}
-func RunVclEchoClient(args []string) *ActionResult {
+func (a *Actions) RunVclEchoClient(args []string) *ActionResult {
outBuff := bytes.NewBuffer([]byte{})
errBuff := bytes.NewBuffer([]byte{})
}
}
-func Configure2Veths(args []string) *ActionResult {
+func (a *Actions) Configure2Veths(args []string) *ActionResult {
var startup Stanza
startup.
NewStanza("session").
return afPacketCreateRsp.SwIfIndex, nil
}
-func ConfigureHttpTps(args []string) *ActionResult {
+func (a *Actions) ConfigureHttpTps(args []string) *ActionResult {
ctx, cancel := newVppContext()
defer cancel()
con, vppErrCh := vpphelper.StartAndDialContext(ctx,
}
defer func() { exechelper.Run("docker stop " + clnInstance) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("echo-srv-internal private-segment-size 1g fifo-size 4 no-echo", srvInstance)
+ _, err = hstExec("RunEchoSrvInternal private-segment-size 1g fifo-size 4 no-echo", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- o, err := hstExec("echo-cln-internal nclients 10000 bytes 1 syn-timeout 100 test-timeout 100 no-return private-segment-size 1g fifo-size 4", clnInstance)
+ o, err := hstExec("RunEchoClnInternal nclients 10000 bytes 1 syn-timeout 100 test-timeout 100 no-return private-segment-size 1g fifo-size 4", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
func TestVeths2(t *testing.T) {
var m Veths2Suite
suite.Run(t, &m)
-
}
defer func() { exechelper.Run("docker stop " + dockerInstance) }()
// start & configure vpp in the container
- _, err = hstExec(dockerInstance, dockerInstance)
+ _, err = hstExec("ConfigureHttpTps", dockerInstance)
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + clnInstance) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
t.Log("configured IPs...")
- _, err = hstExec("http-cli-srv", srvInstance)
+ _, err = hstExec("RunHttpCliSrv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
t.Log("configured http server")
- o, err := hstExec("http-cli-cln /show/version", clnInstance)
+ o, err := hstExec("RunHttpCliCln /show/version", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + clnInstance) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
Append("app-scope-local").
Append("app-scope-global").
Append("use-mq-eventfd").
- Append(fmt.Sprintf("app-socket-api /tmp/%s/2veths/var/run/app_ns_sockets/2", clnInstance)).Close().
+ Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/2", clnInstance)).Close().
SaveToFile(clnVcl)
if err != nil {
t.Errorf("%v", err)
Append("app-scope-local").
Append("app-scope-global").
Append("use-mq-eventfd").
- Append(fmt.Sprintf("app-socket-api /tmp/%s/2veths/var/run/app_ns_sockets/1", srvInstance)).Close().
+ Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/1", srvInstance)).Close().
SaveToFile(srvVcl)
if err != nil {
t.Errorf("%v", err)
"os"
"os/exec"
"os/signal"
-
- "git.fd.io/govpp.git/api"
+ "reflect"
)
-type CfgTable map[string]func([]string) *ActionResult
-
-var cfgTable CfgTable
-
-type ConfFn func(context.Context, api.Connection) error
+var actions Actions
func newVppContext() (context.Context, context.CancelFunc) {
ctx, cancel := signal.NotifyContext(
return NewActionResult(nil)
}
-func reg(key string, fn func([]string) *ActionResult) {
- cfgTable[key] = fn
-}
-
func processArgs() *ActionResult {
- fn := cfgTable[os.Args[1]]
- if fn == nil {
- return NewActionResult(fmt.Errorf("internal: no config found for %s", os.Args[1]))
+ nArgs := len(os.Args) - 1 // skip program name
+ if nArgs < 1 {
+ return NewActionResult(fmt.Errorf("internal: no action specified!"))
+ }
+ action := os.Args[1]
+ methodValue := reflect.ValueOf(&actions).MethodByName(action)
+ if !methodValue.IsValid() {
+ return NewActionResult(fmt.Errorf("internal unknown action %s!", action))
}
+ methodIface := methodValue.Interface()
+ fn := methodIface.(func([]string) *ActionResult)
return fn(os.Args)
}
os.Exit(0)
}
- RegisterActions()
-
var err error
res := processArgs()
err = writeSyncFile(res)
"github.com/edwarnicke/exechelper"
)
-func testProxyHttpTcp(t *testing.T, dockerInstance string, proxySetup func() error) error {
+func testProxyHttpTcp(t *testing.T, dockerInstance, action string, proxySetup func() error) error {
const outputFile = "test.data"
const srcFile = "10M"
stopServer := make(chan struct{}, 1)
defer func() { exechelper.Run("docker stop " + dockerInstance) }()
// start & configure vpp in the container
- _, err = hstExec(dockerInstance, dockerInstance)
+ _, err = hstExec(action, dockerInstance)
if err != nil {
return fmt.Errorf("error starting vpp in container: %v", err)
}
func (s *NsSuite) TestVppProxyHttpTcp() {
t := s.T()
dockerInstance := "vpp-proxy"
- err := testProxyHttpTcp(t, dockerInstance, configureVppProxy)
+ err := testProxyHttpTcp(t, dockerInstance, "ConfigureVppProxy", configureVppProxy)
if err != nil {
t.Errorf("%v", err)
}
ctx, cancel := context.WithCancel(context.Background())
dockerInstance := "vpp-envoy"
- err := testProxyHttpTcp(t, dockerInstance, func() error {
+ err := testProxyHttpTcp(t, dockerInstance, "ConfigureEnvoyProxy", func() error {
return setupEnvoy(t, ctx, dockerInstance)
})
if err != nil {
echoSrv := "echo-srv"
echoCln := "echo-cln"
- err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/2veths")
+ err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + srvInstance) }()
- err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/2veths")
+ err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + echoCln) }()
- _, err = hstExec("2veths srv", srvInstance)
+ _, err = hstExec("Configure2Veths srv", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
}
// run server app
- _, err = hstExec("echo-server "+proto, echoSrv)
+ _, err = hstExec("RunEchoServer "+proto, echoSrv)
if err != nil {
t.Errorf("echo server: %v", err)
return
}
- o, err := hstExec("echo-client "+proto, echoCln)
+ o, err := hstExec("RunEchoClient "+proto, echoCln)
if err != nil {
t.Errorf("echo client: %v", err)
}
echoSrv := "echo-srv"
echoCln := "echo-cln"
- err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/2veths")
+ err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + srvInstance) }()
- err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/2veths")
+ err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths")
if err != nil {
t.Errorf("%v", err)
return
}
defer func() { exechelper.Run("docker stop " + echoCln) }()
- _, err = hstExec("2veths srv-with-preset-hw-addr", srvInstance)
+ _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("2veths cln", clnInstance)
+ _, err = hstExec("Configure2Veths cln", clnInstance)
if err != nil {
t.Errorf("%v", err)
return
}
- _, err = hstExec("vcl-test-server "+proto, echoSrv)
+ _, err = hstExec("RunVclEchoServer "+proto, echoSrv)
if err != nil {
t.Errorf("vcl test server: %v", err)
return
fmt.Println("This whole test case can take around 3 minutes to run. Please be patient.")
fmt.Println("... Running first echo client test, before disconnect.")
- _, err = hstExec("vcl-test-client "+proto, echoCln)
+ _, err = hstExec("RunVclEchoClient "+proto, echoCln)
if err != nil {
t.Errorf("vcl test client: %v", err)
return
t.Errorf("error while stopping hs-test: %v", err)
return
}
- _, err = hstExec("2veths srv-with-preset-hw-addr", srvInstance)
+ _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
if err != nil {
t.Errorf("%v", err)
return
time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
fmt.Println("... Running second echo client test, after disconnect and re-attachment.")
- _, err = hstExec("vcl-test-client "+proto, echoCln)
+ _, err = hstExec("RunVclEchoClient "+proto, echoCln)
if err != nil {
t.Errorf("vcl test client: %v", err)
}