diff --git a/Dockerfile b/Dockerfile index 723184f..3a6fe59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Usage: -# + # docker build -t pcesapps-dev:latest -t pcesapps:latest . # docker run -it --rm -v ~/pcesapps/extern:/tmp/extern ghcr.io/iti/pcesapps-dev # docker run -it --rm -v ~/pcesapps/extern:/tmp/extern ghcr.io/iti/pcesapps @@ -19,4 +19,4 @@ RUN cd simulator/sim-dir && go mod tidy && go build -o /bin/sim sim.go exp.go # remember to use "-v" to map in /tmp/extern WORKDIR /pcesapps/simulator/sim-dir -RUN sim -is /tmp/extern/input/args-sim +#RUN sim -is /tmp/extern/input/args-sim diff --git a/simulator/args-run b/simulator/args-run index ddd8efb..3b53014 100644 --- a/simulator/args-run +++ b/simulator/args-run @@ -1,5 +1,4 @@ -template ./template --args ./args -input ./input -output ./output -sim ./sim-dir diff --git a/simulator/args/args-sim-template b/simulator/args/args-sim-template index 88bcf32..49bbd1d 100644 --- a/simulator/args/args-sim-template +++ b/simulator/args/args-sim-template @@ -12,4 +12,3 @@ -msr msr.yaml -rngseed 234545 -tunits msec -#-container diff --git a/simulator/output/results.yaml b/simulator/output/results.yaml new file mode 100644 index 0000000..06bc057 --- /dev/null +++ b/simulator/output/results.yaml @@ -0,0 +1,21 @@ +experiment set run at time 2024-12-14 07:20:35.382921 +- exprmnt: exp-1 + measurements: + - latency: 1.0840000000007421 (msec) + measurename: end2end + waypoints: [] +- exprmnt: exp-2 + measurements: + - latency: 24.84399999999914 (msec) + measurename: end2end + waypoints: [] +- exprmnt: exp-3 + measurements: + - latency: 1.0790000000015425 (msec) + measurename: end2end + waypoints: [] +- exprmnt: exp-4 + measurements: + - latency: 24.838999999999942 (msec) + measurename: end2end + waypoints: [] diff --git a/simulator/output/trace.yaml b/simulator/output/trace.yaml new file mode 100644 index 0000000..1df292d --- /dev/null +++ b/simulator/output/trace.yaml @@ -0,0 +1,671 @@ +inuse: true +expname: exp-4 +namebyid: + 1: + name: hub + type: switch + 2: + name: hmiDev + type: endpt + 3: + name: embeddedDev + type: endpt + 4: + name: sslDev + type: endpt + 5: + name: central + type: network + 6: + name: intrfc@hmiDev-hub + type: interface + 7: + name: intrfc@embeddedDev-hub + type: interface + 8: + name: intrfc@sslDev-hub + type: interface + 9: + name: intrfc@hub-hmiDev + type: interface + 10: + name: intrfc@hub-sslDev + type: interface + 11: + name: intrfc@hub-embeddedDev + type: interface + 24: + name: HMI:generatePckt + type: application + 25: + name: HMI:accelEncrypt + type: application + 27: + name: HMI:accelDecrypt + type: application +traces: + 2: + - tracetime: "0" + tracetype: CP + tracestr: | + time: 0 + ticks: 0 + priority: 1 + execid: 2 + objid: 2 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: measure + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10" + tracetype: CP + tracestr: | + time: 10 + ticks: 10000000 + priority: 3 + execid: 2 + objid: 2 + op: exit + cpm: | + execid: 2 + nxtlabel: "" + msgtype: measure + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.000032" + tracetype: CP + tracestr: | + time: 10.000032 + ticks: 10000032 + priority: 8 + execid: 2 + objid: 24 + op: exit + cpm: | + execid: 2 + nxtlabel: "" + msgtype: encrypt + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.000033" + tracetype: CP + tracestr: | + time: 10.000033 + ticks: 10000033 + priority: 12 + execid: 2 + objid: 25 + op: exit + cpm: | + execid: 2 + nxtlabel: "" + msgtype: compute + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.000033" + tracetype: interface + tracestr: | + time: 10.000033 + objid: 6 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.001233" + tracetype: interface + tracestr: | + time: 10.001233 + objid: 6 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.001238" + tracetype: interface + tracestr: | + time: 10.001238 + objid: 9 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.002501" + tracetype: interface + tracestr: | + time: 10.002501 + objid: 7 + execid: 2 + op: enterIngress + cq: "" + - tracetime: "10.002501" + tracetype: CP + tracestr: | + time: 10.002501 + ticks: 10002501 + priority: 18 + execid: 2 + objid: 3 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: auth + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.002501" + tracetype: interface + tracestr: | + time: 10.002501 + objid: 7 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.003701" + tracetype: interface + tracestr: | + time: 10.003701 + objid: 7 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.003706" + tracetype: interface + tracestr: | + time: 10.003706 + objid: 11 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.004969" + tracetype: interface + tracestr: | + time: 10.004969 + objid: 6 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.004969" + tracetype: CP + tracestr: | + time: 10.004969 + ticks: 10004969 + priority: 25 + execid: 2 + objid: 2 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: auth + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.004973" + tracetype: interface + tracestr: | + time: 10.004973 + objid: 6 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.006173" + tracetype: interface + tracestr: | + time: 10.006173 + objid: 6 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.006178" + tracetype: interface + tracestr: | + time: 10.006178 + objid: 9 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.007441" + tracetype: interface + tracestr: | + time: 10.007441 + objid: 7 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.007441" + tracetype: CP + tracestr: | + time: 10.007441 + ticks: 10007441 + priority: 32 + execid: 2 + objid: 3 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: return-auth + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.007441" + tracetype: CP + tracestr: | + time: 10.007441 + ticks: 10007441 + priority: 34 + execid: 2 + objid: 3 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: decrypt-AES-128-CBC + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.007441" + tracetype: interface + tracestr: | + time: 10.007441 + objid: 7 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.008641" + tracetype: interface + tracestr: | + time: 10.008641 + objid: 7 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.008646" + tracetype: interface + tracestr: | + time: 10.008646 + objid: 11 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.009909" + tracetype: interface + tracestr: | + time: 10.009909 + objid: 8 + execid: 2 + op: enterIngress + cq: "" + - tracetime: "10.009909" + tracetype: CP + tracestr: | + time: 10.009909 + ticks: 10009909 + priority: 41 + execid: 2 + objid: 4 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: decrypt-AES-128-CBC + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.009912" + tracetype: interface + tracestr: | + time: 10.009912 + objid: 8 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.011112" + tracetype: interface + tracestr: | + time: 10.011112 + objid: 8 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.011117" + tracetype: interface + tracestr: | + time: 10.011117 + objid: 10 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.01238" + tracetype: interface + tracestr: | + time: 10.01238 + objid: 7 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.01238" + tracetype: CP + tracestr: | + time: 10.01238 + ticks: 10012380 + priority: 48 + execid: 2 + objid: 3 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: return-decrypt-AES-128-CBC + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.01248" + tracetype: CP + tracestr: | + time: 10.01248 + ticks: 10012480 + priority: 54 + execid: 2 + objid: 3 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: encrypt-AES-128-CBC + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.01248" + tracetype: interface + tracestr: | + time: 10.01248 + objid: 7 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.01368" + tracetype: interface + tracestr: | + time: 10.01368 + objid: 7 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.013685" + tracetype: interface + tracestr: | + time: 10.013685 + objid: 11 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.014948" + tracetype: interface + tracestr: | + time: 10.014948 + objid: 8 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.014948" + tracetype: CP + tracestr: | + time: 10.014948 + ticks: 10014948 + priority: 61 + execid: 2 + objid: 4 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: encrypt-AES-128-CBC + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.014952" + tracetype: interface + tracestr: | + time: 10.014952 + objid: 8 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.016152" + tracetype: interface + tracestr: | + time: 10.016152 + objid: 8 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.016157" + tracetype: interface + tracestr: | + time: 10.016157 + objid: 10 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.01742" + tracetype: interface + tracestr: | + time: 10.01742 + objid: 7 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.01742" + tracetype: CP + tracestr: | + time: 10.01742 + ticks: 10017420 + priority: 68 + execid: 2 + objid: 3 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: return-encrypt-AES-128-CBC + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.01742" + tracetype: interface + tracestr: | + time: 10.01742 + objid: 7 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.01862" + tracetype: interface + tracestr: | + time: 10.01862 + objid: 7 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.018625" + tracetype: interface + tracestr: | + time: 10.018625 + objid: 11 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.019888" + tracetype: interface + tracestr: | + time: 10.019888 + objid: 6 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.019888" + tracetype: CP + tracestr: | + time: 10.019888 + ticks: 10019888 + priority: 75 + execid: 2 + objid: 2 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: auth + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.019888" + tracetype: interface + tracestr: | + time: 10.019888 + objid: 6 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.021088" + tracetype: interface + tracestr: | + time: 10.021088 + objid: 6 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.021093" + tracetype: interface + tracestr: | + time: 10.021093 + objid: 9 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.022356" + tracetype: interface + tracestr: | + time: 10.022356 + objid: 7 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.022356" + tracetype: CP + tracestr: | + time: 10.022356 + ticks: 10022356 + priority: 82 + execid: 2 + objid: 3 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: auth + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.02236" + tracetype: interface + tracestr: | + time: 10.02236 + objid: 7 + execid: 2 + op: arriveEgress + cq: egress_0 % 0 + - tracetime: "10.02356" + tracetype: interface + tracestr: | + time: 10.02356 + objid: 7 + execid: 2 + op: exitEgress + cq: egress_0 % 0 + - tracetime: "10.023565" + tracetype: interface + tracestr: | + time: 10.023565 + objid: 11 + execid: 2 + op: arriveSimpleDev + cq: "" + - tracetime: "10.024828" + tracetype: interface + tracestr: | + time: 10.024828 + objid: 6 + execid: 2 + op: enterIngress + cq: egress_0 % 0 + - tracetime: "10.024828" + tracetype: CP + tracestr: | + time: 10.024828 + ticks: 10024828 + priority: 89 + execid: 2 + objid: 2 + op: enter + cpm: | + execid: 2 + nxtlabel: "" + msgtype: return-auth + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.024829" + tracetype: CP + tracestr: | + time: 10.024829 + ticks: 10024829 + priority: 94 + execid: 2 + objid: 27 + op: exit + cpm: | + execid: 2 + nxtlabel: "" + msgtype: process + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.024839" + tracetype: CP + tracestr: | + time: 10.024839 + ticks: 10024839 + priority: 99 + execid: 2 + objid: 2 + op: exit + cpm: | + execid: 2 + nxtlabel: "" + msgtype: measure + msglen: 1500 + pcktlen: 0 + flowstate: "" + - tracetime: "10.024839" + tracetype: CP + tracestr: | + time: 10.024839 + ticks: 10024839 + priority: 101 + execid: 2 + objid: 2 + op: exit + cpm: | + execid: 2 + nxtlabel: "" + msgtype: finish + msglen: 1500 + pcktlen: 0 + flowstate: "" diff --git a/simulator/run.py b/simulator/run.py index 671670e..6172e54 100755 --- a/simulator/run.py +++ b/simulator/run.py @@ -17,17 +17,19 @@ sheetNames = ('cp', 'topo', 'execTime', 'netParams', 'mapping') def main(): - global workingDir, full_csvDir + global workingDir, csvDir parser = argparse.ArgumentParser() parser.add_argument(u'-template', metavar = u'directory with experiment templates', dest=u'template', required=True) parser.add_argument(u'-input', metavar = u'directory where transformed files reside', dest=u'input', required=True) parser.add_argument(u'-output', metavar = u'directory where simulation output is written', dest=u'output', required=True) - parser.add_argument(u'-args', metavar = u'directory where argument files are stored', - dest=u'argsDir', required=True) parser.add_argument(u'-sim', metavar = u'directory where simulation executatable and argument file reside', dest=u'sim', required=True) + parser.add_argument(u'-extern', metavar = u'if non-empty, container directory where shared input and output directories reside', + dest=u'extern', required=False) + parser.add_argument(u'-container', metavar = u'tag to be applied to a container that is run', + dest=u'container', required=False) cmdline = sys.argv[1:] cmdline = [] @@ -40,19 +42,23 @@ def main(): args = parser.parse_args(cmdline) + # remember that path names are relative to current working directory templateDir = args.template - inputDir = args.input - outputDir = args.output + externDir = args.extern + + if externDir is None: + inputDir = args.input + outputDir = args.output + else: + inputDir = os.path.join(externDir,'input') + outputDir = os.path.join(externDir,'output') + simDir = args.sim - argsDir = args.argsDir + argsDir = './args' - full_templateDir = os.path.abspath(templateDir) - full_inputDir = os.path.abspath(inputDir) - full_outputDir = os.path.abspath(outputDir) - full_simDir = os.path.abspath(simDir) - full_argsDir = os.path.abspath(argsDir) + containerTag = args.container - commonDir = (full_templateDir, full_inputDir, full_outputDir, full_simDir, full_argsDir) + commonDir = (templateDir, inputDir, outputDir, simDir, argsDir) # ensure that these directories exist and are accessible errs = 0 @@ -75,7 +81,7 @@ def main(): for _, fList in sheet2Files.items(): for fileName in fList: - filePath = os.path.join(full_templateDir, fileName) + filePath = os.path.join(templateDir, fileName) if not os.path.isfile(filePath): print('expected file {} does not exist'.format(filePath)) errs += 1 @@ -84,21 +90,21 @@ def main(): exit(1) # get the dictionary describing the experiments - experiment_input_file = os.path.join(full_templateDir, 'experiments.yaml') + experiment_input_file = os.path.join(templateDir, 'experiments.yaml') with open(experiment_input_file, 'r') as rf: exprmnts = yaml.safe_load(rf) # copy over everything - directory_path = full_templateDir + directory_path = templateDir file_pattern = '*.yaml' filenames = glob.glob(f'{directory_path}/{file_pattern}') for filePath in filenames: basename = os.path.basename(filePath) - input_file = os.path.join(full_inputDir, basename) + input_file = os.path.join(inputDir, basename) shutil.copyfile(filePath, input_file) - aggOutFile = os.path.join(full_outputDir, 'results.yaml') + aggOutFile = os.path.join(outputDir, 'results.yaml') with open(aggOutFile, 'w') as wf: print('experiment set run at time {}'.format(datetime.datetime.now()), file=wf) @@ -107,8 +113,13 @@ def main(): for exprmnt in exprmnts: exprmntName = exprmnt['name'] - with open(os.path.join(full_argsDir,'args-sim-template'), 'r') as tf, open(os.path.join(full_argsDir,'args-sim'), 'w') as wf: + # write the name of the experiment into the args-sim file used to run the simulation + with open(os.path.join(argsDir,'args-sim-template'), 'r') as tf, open(os.path.join(argsDir,'args-sim'), 'w') as wf: wf.write('-exprmnt {}\n'.format(exprmntName)) + + if containerTag is not None: + wf.write('-container\n') + for line in tf: wf.write(line) @@ -129,8 +140,8 @@ def main(): # copy the files to be modified for sheet in sheetFlag: for file in sheet2Files[sheet]: - templateFile = os.path.join(full_templateDir, file) - inputFile = os.path.join(full_inputDir, file) + templateFile = os.path.join(templateDir, file) + inputFile = os.path.join(inputDir, file) shutil.copyfile(templateFile, inputFile) # make the modifications @@ -146,8 +157,8 @@ def main(): for sheet in sheets: for file in sheet2Files[sheet]: - inputFile = os.path.join(full_inputDir, file) - tmpFile = os.path.join(full_inputDir, 'tmp-'+file) + inputFile = os.path.join(inputDir, file) + tmpFile = os.path.join(inputDir, 'tmp-'+file) with open(inputFile, 'r') as rf: with open(tmpFile, 'w') as wf: for line in rf: @@ -158,13 +169,28 @@ def main(): # run the simulation - simExec = os.path.join(full_simDir,"sim") - simArgs = os.path.join(full_argsDir, "args-sim") - - process = subprocess.Popen([simExec, "-is", simArgs], - stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + simArgs = os.path.join(argsDir, "args-sim") + + # if containerTag is not None, run the container to execute the simulation + if containerTag is not None: + cwd = os.getcwd() + paths = os.path.split(os.getcwd()) + outsideDir = os.path.join(paths[:len(paths)-1]) + mountCmd = '{}:{}'.format(outsideDir, externDir) + #cTag = "ghcr.io/iti/pcesapps-dev" + cTag = "pces/sim" + simExecArgs = ["docker","run","-it", "--rm" "-v", mountCmd, cTag] + + process = subprocess.Popen(simExecArgs, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + else: + simExec = os.path.join(simDir,"sim") + process = subprocess.Popen([simExec, "-is", simArgs], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + stdout, stderr = process.communicate() - + if process.returncode != 0: print("Error from simulation run") else: @@ -172,11 +198,13 @@ def main(): print(stderr) # append the msr file in output to output/aggMsr - outputMsr = os.path.join(full_outputDir, 'msr.yaml') + outputMsr = os.path.join(outputDir, 'msr.yaml') with open(outputMsr, 'r') as fsrc: nxtMsr = yaml.safe_load(fsrc) allMsr.append(nxtMsr) + + os.remove(outputMsr) with open(aggOutFile, 'a') as fdst: yaml.dump(allMsr, fdst) diff --git a/simulator/sim-dir/sim b/simulator/sim-dir/sim deleted file mode 100755 index e3fbcb9..0000000 Binary files a/simulator/sim-dir/sim and /dev/null differ