forked from my5G/my5G-RANTester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
d5d73f3
commit 1e13109
Showing
9 changed files
with
203 additions
and
415 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.