mirror of
https://gitlab.com/manzerbredes/loosely-coupled-dss.git
synced 2025-04-05 19:16:26 +02:00
Add scenarios tool
This commit is contained in:
parent
66ba2be4ed
commit
8b7b9c9e0a
4 changed files with 92 additions and 30 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ libs/simgrid
|
|||
libs/rapidjson
|
||||
compile_commands.json
|
||||
platform.xml
|
||||
scenarios
|
||||
|
|
11
Makefile
11
Makefile
|
@ -1,14 +1,19 @@
|
|||
EXEC := simulator
|
||||
LIBS := ./libs/simgrid/build/lib
|
||||
INCLUDES := ./libs/simgrid/build/include ./libs/simgrid/include libs/rapidjson/include
|
||||
CC := g++ -lsimgrid $(addprefix -L , $(LIBS)) $(addprefix -I , $(INCLUDES))
|
||||
SCENARIOS := src/scenarios.cc
|
||||
CC := g++ $(addprefix -L , $(LIBS)) $(addprefix -I , $(INCLUDES))
|
||||
|
||||
all: $(EXEC) $(basename $(notdir $(SCENARIOS)))
|
||||
|
||||
$(EXEC): $(wildcard src/*)
|
||||
$(EXEC): $(filter-out $(SCENARIOS), $(wildcard src/*))
|
||||
$(CC) -lsimgrid $^ -o $@
|
||||
|
||||
$(basename $(notdir $(SCENARIOS))): $(SCENARIOS)
|
||||
$(CC) $^ -o $@
|
||||
|
||||
run: $(EXEC)
|
||||
export LD_LIBRARY_PATH=$(addprefix :, $(LIBS)) && ./$(EXEC) 10 --cfg=network/bandwidth-factor:1.05 --cfg=network/model:CM02 -–cfg=network/crosstraffic:0
|
||||
|
||||
clean:
|
||||
-rm $(EXEC)
|
||||
-rm $(EXEC) $(basename $(notdir $(SCENARIOS)))
|
28
inputs.json
28
inputs.json
|
@ -1,27 +1 @@
|
|||
{
|
||||
"extended":true,
|
||||
"nodes":{
|
||||
"on0":{
|
||||
"is_sender": true,
|
||||
"power_off": 0,
|
||||
"power_on": 1,
|
||||
"power_rx": 2,
|
||||
"power_tx": 3,
|
||||
"use_hint": true,
|
||||
"wake_ts": [ 1, 7, 7 ],
|
||||
"wake_duration": [ 5, 1, 2],
|
||||
"data_size": 50
|
||||
},
|
||||
"on1":{
|
||||
"is_sender": false,
|
||||
"power_off": 0,
|
||||
"power_on": 10,
|
||||
"power_tx": 10,
|
||||
"power_rx": 10,
|
||||
"use_hint": false,
|
||||
"wake_ts": [ 1, 7, 8 ],
|
||||
"wake_duration": [ 5, 5, 1],
|
||||
"data_size": 50
|
||||
}
|
||||
}
|
||||
}
|
||||
{"extended":false,"nodes":{"on0":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":true,"data_size":50,"wake_ts":[8.0,18.0,28.0,38.0,48.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0]},"on1":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[5.0,15.0,25.0,35.0,45.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0]},"on2":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[0.0,10.0,20.0,30.0,40.0,50.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]},"on3":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[1.0,11.0,21.0,31.0,41.0,51.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]},"on4":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[2.0,12.0,22.0,32.0,42.0,52.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]},"on5":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[4.0,14.0,24.0,34.0,44.0,54.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]},"on6":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[0.0,10.0,20.0,30.0,40.0,50.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]},"on7":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[0.0,10.0,20.0,30.0,40.0,50.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]},"on8":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[3.0,13.0,23.0,33.0,43.0,53.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]},"on9":{"use_hint":false,"power_off":0,"power_on":10,"power_rx":11,"power_tx":12,"is_sender":false,"data_size":50,"wake_ts":[4.0,14.0,24.0,34.0,44.0,54.0],"wake_duration":[5.0,5.0,5.0,5.0,5.0,5.0]}}}
|
82
src/scenarios.cc
Normal file
82
src/scenarios.cc
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/filewritestream.h>
|
||||
#include <rapidjson/writer.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#define RAND(min,max) (rand()%(max-min)+min)
|
||||
|
||||
using namespace std;
|
||||
using namespace rapidjson;
|
||||
|
||||
#define N_NODE 10
|
||||
#define EXTENDED false
|
||||
#define SIMULATION_DURATION 60
|
||||
#define POWER_OFF 0
|
||||
#define POWER_ON 10
|
||||
#define POWER_RX 11
|
||||
#define POWER_TX 12
|
||||
#define DATA_SIZE 50
|
||||
#define USE_HINT false
|
||||
#define WAKE_UP_EVERY 10
|
||||
#define WAKE_UP_FOR 5
|
||||
#define MAX_STARTUP_DELAY 10
|
||||
|
||||
unsigned int seed = 0;
|
||||
|
||||
int main(int argc, char **argv){
|
||||
// Setup seed
|
||||
if(argc>1){
|
||||
srand( atoi(argv[1]) );
|
||||
}
|
||||
|
||||
// Create document
|
||||
Document d;
|
||||
d.SetObject();
|
||||
d.AddMember("extended",EXTENDED,d.GetAllocator());
|
||||
|
||||
// Create nodes
|
||||
Value nodes(kObjectType);
|
||||
for(int i=0;i<N_NODE;i++){
|
||||
Value node(kObjectType);
|
||||
node.SetObject();
|
||||
node.AddMember("use_hint",USE_HINT,d.GetAllocator());
|
||||
node.AddMember("power_off",POWER_OFF,d.GetAllocator());
|
||||
node.AddMember("power_on",POWER_ON,d.GetAllocator());
|
||||
node.AddMember("power_rx",POWER_RX,d.GetAllocator());
|
||||
node.AddMember("power_tx",POWER_TX,d.GetAllocator());
|
||||
node.AddMember("is_sender",i==0,d.GetAllocator());
|
||||
node.AddMember("data_size",DATA_SIZE,d.GetAllocator());
|
||||
|
||||
// Setup ts and durations
|
||||
Value ts(kArrayType);
|
||||
Value duration(kArrayType);
|
||||
for(unsigned int i=(RAND(0,MAX_STARTUP_DELAY));(i+WAKE_UP_FOR)<SIMULATION_DURATION;i+=WAKE_UP_EVERY){
|
||||
ts.PushBack(Value().SetDouble(i),d.GetAllocator());
|
||||
duration.PushBack(Value().SetDouble(WAKE_UP_FOR),d.GetAllocator());
|
||||
}
|
||||
node.AddMember("wake_ts",ts,d.GetAllocator());
|
||||
node.AddMember("wake_duration",duration,d.GetAllocator());
|
||||
|
||||
|
||||
// Add node to nodes
|
||||
std::ostringstream ss;
|
||||
ss<< "on" <<i;
|
||||
Value key(ss.str().c_str(), d.GetAllocator());
|
||||
nodes.AddMember(key,node,d.GetAllocator());
|
||||
}
|
||||
d.AddMember("nodes",nodes,d.GetAllocator());
|
||||
|
||||
|
||||
// Write to stdout
|
||||
StringBuffer buffer;
|
||||
Writer<StringBuffer> writer(buffer);
|
||||
d.Accept(writer);
|
||||
cout << buffer.GetString();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue