Skip to content

Commit

Permalink
[all] added -no-logfile option and activate it for stress tests (to s…
Browse files Browse the repository at this point in the history
…peed up); removed RADIO_RANGE in some tests
  • Loading branch information
EskoDijk committed Sep 11, 2023
1 parent 6efbcbb commit a2d18d8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 25 deletions.
3 changes: 3 additions & 0 deletions otns_main/otns_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type MainArgs struct {
DumpPackets bool
NoPcap bool
NoReplay bool
NoLogFile bool
}

var (
Expand Down Expand Up @@ -103,6 +104,7 @@ func parseArgs() {
flag.BoolVar(&args.DumpPackets, "dump-packets", false, "dump packets")
flag.BoolVar(&args.NoPcap, "no-pcap", false, "do not generate PCAP file (named \"current.pcap\")")
flag.BoolVar(&args.NoReplay, "no-replay", false, "do not generate Replay file (named \"otns_?.replay\")")
flag.BoolVar(&args.NoLogFile, "no-logfile", false, "do not generate node log files (named \"tmp/?_?.log\")")

flag.Parse()
}
Expand Down Expand Up @@ -249,6 +251,7 @@ func createSimulation(ctx *progctx.ProgCtx) *simulation.Simulation {
simcfg.ExeConfig.Ftd = args.OtCliPath
simcfg.ExeConfig.Mtd = args.OtCliMtdPath
simcfg.NewNodeConfig.InitScript = simulation.DefaultNodeInitScript
simcfg.NewNodeConfig.NodeLogFile = !args.NoLogFile
args.Speed = strings.ToLower(args.Speed)
if args.Speed == "max" {
speed = dispatcher.MaxSimulateSpeed
Expand Down
2 changes: 1 addition & 1 deletion pylibs/stress_tests/BaseStressTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run_wrapper(self: 'BaseStressTest', report=True):
class BaseStressTest(object, metaclass=StressTestMetaclass):
def __init__(self, name, headers, raw=False, web=True, interactive=False):
self.name = name
self._otns_args = ['-log','info'] # use ['-log', 'debug'] for more debug messages
self._otns_args = ['-log','info','-no-logfile'] # use ['-log', 'debug'] for more debug messages
if raw:
self._otns_args.append('-raw')
self.ns = OTNS(otns_args=self._otns_args, is_interactive=interactive)
Expand Down
7 changes: 3 additions & 4 deletions pylibs/stress_tests/network_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@

PARENT_X = 500
PARENT_Y = 500
MAX_DISTANCE = 300
RADIO_RANGE = int(MAX_DISTANCE * 1.5)
MAX_DISTANCE = 250
CHILDREN_N = 10


Expand All @@ -62,7 +61,7 @@ def run(self):

def test(self, child_type: str):
self.reset()
self.ns.add("router", PARENT_X, PARENT_Y, radio_range=RADIO_RANGE)
self.ns.add("router", PARENT_X, PARENT_Y)
self.ns.go(7)

time_limit = StressTest.TIME_LIMIT[child_type]
Expand All @@ -73,7 +72,7 @@ def test(self, child_type: str):
d = random.randint(0, MAX_DISTANCE * MAX_DISTANCE) ** 0.5
child_x = int(PARENT_X + d * math.cos(angle))
child_y = int(PARENT_Y + d * math.sin(angle))
child = self.ns.add(child_type, child_x, child_y, radio_range=RADIO_RANGE)
child = self.ns.add(child_type, child_x, child_y)
all_children.append(child)
self.ns.go(random.uniform(0.001, 0.1))

Expand Down
7 changes: 3 additions & 4 deletions pylibs/stress_tests/otns_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@

from BaseStressTest import BaseStressTest

XGAP = 100
YGAP = 100
RADIO_RANGE = int(XGAP * 1.5)
XGAP = 200
YGAP = 200

ROWS, COLS = 4, 8
assert ROWS * COLS <= 32
Expand All @@ -65,7 +64,7 @@ def run(self):

for r in range(ROWS):
for c in range(COLS):
nid = ns.add("router", 100 + XGAP * c, 100 + YGAP * r, radio_range=RADIO_RANGE)
nid = ns.add("router", 100 + XGAP * c, 100 + YGAP * r)
# make sure every node become Router
ns.node_cmd(nid, "routerupgradethreshold 32")
ns.node_cmd(nid, 'routerdowngradethreshold 33')
Expand Down
35 changes: 20 additions & 15 deletions simulation/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,19 @@ type Node struct {
func newNode(s *Simulation, nodeid NodeId, cfg *NodeConfig) (*Node, error) {
var err error
logFileName := fmt.Sprintf("tmp/%d_%d.log", s.cfg.Id, nodeid)
var logFile *os.File

if !cfg.Restore {
flashFile := fmt.Sprintf("tmp/%d_%d.flash", s.cfg.Id, nodeid)
if err = os.RemoveAll(flashFile); err != nil {
simplelogger.Errorf("Remove flash file %s failed: %+v", flashFile, err)
return nil, err
}
if err = os.RemoveAll(logFileName); err != nil {
simplelogger.Errorf("Remove node log file %s failed: %+v", logFileName, err)
return nil, err
if cfg.NodeLogFile {
if err = os.RemoveAll(logFileName); err != nil {
simplelogger.Errorf("Remove node log file %s failed: %+v", logFileName, err)
return nil, err
}
}
}

Expand Down Expand Up @@ -126,19 +130,20 @@ func newNode(s *Simulation, nodeid NodeId, cfg *NodeConfig) (*Node, error) {
}

// open log file for node's OT output
logFile, err := os.OpenFile(logFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
if err != nil {
simplelogger.Errorf("Opening node log file %s failed: %+v", logFileName, err)
return nil, err
if cfg.NodeLogFile {
logFile, err = os.OpenFile(logFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
if err != nil {
simplelogger.Errorf("Opening node log file %s failed: %+v", logFileName, err)
return nil, err
}
node.logFile = logFile
header := fmt.Sprintf("# OpenThread node log for %s Created %s\n", GetNodeName(nodeid),
time.Now().Format(time.RFC3339)) +
fmt.Sprintf("# Executable: %s\n", cfg.ExecutablePath) +
"# SimTimeUs NodeTime Lev LogModule Message"
_ = node.writeToLogFile(header)
simplelogger.Debugf("Node log file '%s' opened.", logFileName)
}
node.logFile = logFile

header := fmt.Sprintf("# OpenThread node log for %s Created %s\n", GetNodeName(nodeid),
time.Now().Format(time.RFC3339)) +
fmt.Sprintf("# Executable: %s\n", cfg.ExecutablePath) +
"# SimTimeUs NodeTime Lev LogModule Message"
_ = node.writeToLogFile(header)
simplelogger.Debugf("Node log file '%s' opened.", logFileName)

if err = cmd.Start(); err != nil {
if logFile != nil {
Expand Down
3 changes: 2 additions & 1 deletion simulation/simulation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ type Config struct {
RawMode bool
Real bool
AutoGo bool
DumpPackets bool
DispatcherHost string
DispatcherPort int
DumpPackets bool
RadioModel string
Id int
Channel ChannelId
Expand All @@ -80,6 +80,7 @@ func DefaultConfig() *Config {
RawMode: false,
Real: false,
AutoGo: true,
DumpPackets: false,
DispatcherHost: "localhost",
DispatcherPort: InitialDispatcherPort,
RadioModel: "MutualInterference",
Expand Down
2 changes: 2 additions & 0 deletions types/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type NodeConfig struct {
IsRouter bool
IsBorderRouter bool
RxOffWhenIdle bool
NodeLogFile bool
RadioRange int
ExecutablePath string
Restore bool
Expand All @@ -52,6 +53,7 @@ func DefaultNodeConfig() NodeConfig {
IsMtd: false,
IsBorderRouter: false,
RxOffWhenIdle: false,
NodeLogFile: true,
RadioRange: 220,
ExecutablePath: "",
Restore: false,
Expand Down

0 comments on commit a2d18d8

Please sign in to comment.