Skip to content

Commit

Permalink
refactored cmd
Browse files Browse the repository at this point in the history
* moved `~/cmd/app.go` to `~/cmd/my5g-RANTester/main.go`
* refactored logging, command declaration
* split into multiple files
* switched to using constants and fmt.Sprintf for formatting stuff
  • Loading branch information
gravestench committed Feb 25, 2022
1 parent d5d73f3 commit 1e13109
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 415 deletions.
108 changes: 0 additions & 108 deletions cmd/app.go

This file was deleted.

48 changes: 48 additions & 0 deletions cmd/my5g-RANTester/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"github.com/urfave/cli/v2"
)

const (
argNumUE = "number-of-ues"
argNumUEDefault = 1

cmdUeName = "ue"
cmdUeUsage = "Testing an UE attached with configuration"

cmdGnbName = "gnb"
cmdGnbUsage = "Testing a GNB attached with configuration"

cmdLoadTestName = "load-test"
cmdLoadTestUsage = `Load endurance stress tests.
Example for testing multiple UEs: load-test -n 5
`
)

func setupCommands(a *cli.App) {
var commands []*cli.Command

loadTestFlags := []cli.Flag{
&cli.IntFlag{Name: argNumUE, Value: argNumUEDefault, Aliases: []string{"n"}},
}

for _, cmd := range []struct {
name, usage string
fn func(c *cli.Context) error
flags []cli.Flag
}{
{cmdUeName, cmdUeUsage, testUE, nil},
{cmdGnbName, cmdGnbUsage, testGNB, nil},
{cmdLoadTestName, cmdLoadTestUsage, testRegisterMultiUE, loadTestFlags},
} {
commands = append(commands, &cli.Command{
Name: cmd.name,
Usage: cmd.usage,
Action: cmd.fn,
Flags: cmd.flags,
})
}

a.Commands = commands
}
10 changes: 10 additions & 0 deletions cmd/my5g-RANTester/logging_constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

const (
logPrefix = "[TESTER]"
logSep = "---------------------------------------"
fmtLog = logPrefix + " %s"
fmtLogUE = logPrefix + "[UE] %s"
fmtLogGNB = logPrefix + "[GNB] %s"
fmtLogAMF = logPrefix + "[GNB] %s"
)
39 changes: 39 additions & 0 deletions cmd/my5g-RANTester/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"os"

"github.com/davecgh/go-spew/spew"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)

const (
version = "0.1"
fmtMsgVersion = "my5G-RANTester version %v"
)

func main() {
initLogger()

log.Infof(fmtMsgVersion, version)

app := &cli.App{}

setupCommands(app)

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}

func initLogger() {
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
log.SetOutput(os.Stdout)

// Only log the warning severity or above.
log.SetLevel(log.WarnLevel)

spew.Config.Indent = "\t"
}
41 changes: 41 additions & 0 deletions cmd/my5g-RANTester/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"

log "github.com/sirupsen/logrus"

"my5G-RANTester/config"
)

func testLogCommonInfo(name string, numUE int) {
const (
fmtStartTest = "Starting test function: %v"
fmtNumUE = "Number of UEs: %v"
fmtIPPort = "%v/%v"
fmtControlInfo = "Control interface IP/Port: " + fmtIPPort
fmtDataInfo = "Data interface IP/Port: " + fmtIPPort
fmtAMFInfo = "AMF IP/Port: " + fmtIPPort
)

cfg := config.Data

log.Info(logSep)

msgStartTest := fmt.Sprintf(fmtStartTest, name)
log.Infof(fmtLog, msgStartTest)

msgNumUE := fmt.Sprintf(fmtNumUE, numUE)
log.Infof(fmtLogUE, msgNumUE)

msgControlInfo := fmt.Sprintf(fmtControlInfo, cfg.GNodeB.ControlIF.Ip, cfg.GNodeB.ControlIF.Port)
log.Infof(fmtLogGNB, msgControlInfo)

msgDataInfo := fmt.Sprintf(fmtDataInfo, cfg.GNodeB.DataIF.Ip, cfg.GNodeB.DataIF.Port)
log.Infof(fmtLogGNB, msgDataInfo)

msgAMFInfo := fmt.Sprintf(fmtAMFInfo, cfg.AMF.Ip, cfg.AMF.Port)
log.Infof(fmtLogAMF, msgAMFInfo)

log.Info(logSep)
}
19 changes: 19 additions & 0 deletions cmd/my5g-RANTester/test_gnb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"github.com/urfave/cli/v2"

"my5G-RANTester/internal/templates"
)

func testGNB(_ *cli.Context) error {
const (
name = "Testing an gnb attached with configuration"
)

testLogCommonInfo(name, argNumUEDefault)

templates.TestAttachGnbWithConfiguration()

return nil
}
27 changes: 27 additions & 0 deletions cmd/my5g-RANTester/test_register_multi_ue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

"my5G-RANTester/internal/templates"
)

func testRegisterMultiUE(c *cli.Context) error {
if !c.IsSet(argNumUE) {
log.Info(c.Command.Usage)

return nil
}

const (
name = "Testing registration of multiple UEs"
)

numUE := c.Int(argNumUE)

testLogCommonInfo(name, numUE)
templates.TestMultiUesInQueue(numUE)

return nil
}
19 changes: 19 additions & 0 deletions cmd/my5g-RANTester/test_ue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"github.com/urfave/cli/v2"

"my5G-RANTester/internal/templates"
)

func testUE(_ *cli.Context) error {
const (
name = "Testing an ue attached with configuration"
)

testLogCommonInfo(name, argNumUEDefault)

templates.TestAttachUeWithConfiguration()

return nil
}
Loading

0 comments on commit 1e13109

Please sign in to comment.