Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored ~/cmd #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ jobs:

- name: Install Go Deps
run: go mod download

- name: Build my5g-RANTester
run: go build ./cmd/my5g-RANTester
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
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
Expand Down Expand Up @@ -151,7 +150,6 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down