Skip to content

Commit

Permalink
refactor(daisi): Use ns3::Time for time values in scenariofile
Browse files Browse the repository at this point in the history
Related to #55
  • Loading branch information
ltoenning committed Sep 18, 2023
1 parent 9f65cdc commit a2b3c54
Show file tree
Hide file tree
Showing 35 changed files with 263 additions and 247 deletions.
14 changes: 7 additions & 7 deletions daisi/scenarios/cpps/default.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
title: CPPS Default Scenario
version: 0.1
stop_time: 5000
stop_time: 5000s
random_seed: 42
default_delay: 5
default_delay: 5s

# outdated/unused fields
# only present until Manager switches to new scenariofile parser as well
Expand Down Expand Up @@ -104,35 +104,35 @@ scenario_sequence:
- amr:
entity: amr
friendly_name: FPckg
start_time: 0
start_time: 0s
spawn_distribution:
type: absolute
number: 3
- amr:
entity: amr
friendly_name: SPckg
start_time: 0
start_time: 0s
spawn_distribution:
type: absolute
number: 3
- amr:
entity: amr
friendly_name: WEuro
start_time: 0
start_time: 0s
spawn_distribution:
type: absolute
number: 3
- amr:
entity: amr
friendly_name: SEuro
start_time: 0
start_time: 0s
spawn_distribution:
type: absolute
number: 3
- mf:
entity: mf
friendly_name: mf1
start_time: 0
start_time: 0s
spawn_distribution:
type: gaussian
mean: 100
Expand Down
4 changes: 2 additions & 2 deletions daisi/scenarios/entity_search/example.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# required
title: Entity Search example with 10 attributes
version: 0.1
stop_time: 3600000 # 1 hour
stop_time: 1h
random_seed: 2
default_delay: 5000
default_delay: 5000ms

# outdated/unused fields
# only present until Manager switches to new scenariofile parser as well
Expand Down
4 changes: 2 additions & 2 deletions daisi/scenarios/minhton/default.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
title: MINHTON default scenario
version: 0.1
stop_time: 10000000
stop_time: 10000000ms
random_seed: 1
default_delay: 5000
default_delay: 5000ms

# outdated/unused fields
# only present until Manager switches to new scenariofile parser as well
Expand Down
6 changes: 3 additions & 3 deletions daisi/scenarios/natter/default.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
title: Test
version: 0.1
stop_time: 5000
stop_time: 5000s
random_seed: 1
default_delay: 500
default_delay: 500ms

# outdated/unused fields
# only present until Manager switches to new scenariofile parser as well
Expand All @@ -18,6 +18,6 @@ scenario_sequence:
mode: minhton
- type: publish
number: 5
delay: 0
delay: 0s
mode: random # random, sequential
message_size: 100 # in bytes
12 changes: 6 additions & 6 deletions daisi/scenarios/sola/default.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
title: SOLA default scenario
version: 0.1
stop_time: 4294967296
stop_time: 4294967296ms
random_seed: 1
default_delay: 500
default_delay: 500ms

# outdated/unused fields
# only present until Manager switches to new scenariofile parser as well
Expand All @@ -14,14 +14,14 @@ number_nodes: 3

scenario_sequence:
- type: start_sola
delay: 1000
delay: 1000ms
- type: delay
delay: 0
delay: 0s
- type: subscribe_topic
topic: "helloworld"
delay: 1000
delay: 1000ms
- type: delay
delay: 0
delay: 0s
- type: publish
topic: "helloworld"
message_size: 100 # bytes
Expand Down
18 changes: 9 additions & 9 deletions daisi/src/cpps/common/cpps_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void CppsManager::setup() {
void CppsManager::initialSpawn() {
uint32_t previous_index = 0;

while (!spawn_info_.empty() && spawn_info_.top().start_time == 0) {
while (!spawn_info_.empty() && spawn_info_.top().start_time == ns3::Time(0)) {
auto info = spawn_info_.top();
spawn_info_.pop();

Expand Down Expand Up @@ -514,24 +514,24 @@ void CppsManager::scheduleMaterialFlow(const SpawnInfoScenario &info) {

void CppsManager::scheduleEvents() {
Simulator::Schedule(Seconds(1), &CppsManager::clearFinishedMaterialFlows, this);
uint64_t current_time = Simulator::Now().GetSeconds();
uint64_t delay = scenario_.default_delay;
ns3::Time current_time = Simulator::Now();
const ns3::Time delay = scenario_.default_delay;

for (auto i = 0U; i < scenario_.initial_number_of_amrs; i++) {
current_time += delay;
Simulator::ScheduleWithContext(this->amrs_.Get(i)->GetId(), Seconds(current_time),
&CppsManager::initAMR, this, i);
Simulator::ScheduleWithContext(this->amrs_.Get(i)->GetId(), current_time, &CppsManager::initAMR,
this, i);
}

for (auto i = 0U; i < scenario_.initial_number_of_amrs; i++) {
current_time += delay;
Simulator::ScheduleWithContext(this->amrs_.Get(i)->GetId(), Seconds(current_time),
Simulator::ScheduleWithContext(this->amrs_.Get(i)->GetId(), current_time,
&CppsManager::connectAMR, this, i);
}

for (auto i = 0U; i < scenario_.initial_number_of_amrs; i++) {
current_time += delay;
Simulator::ScheduleWithContext(this->amrs_.Get(i)->GetId(), Seconds(current_time),
Simulator::ScheduleWithContext(this->amrs_.Get(i)->GetId(), current_time,
&CppsManager::startAMR, this, i);
}

Expand All @@ -540,8 +540,8 @@ void CppsManager::scheduleEvents() {
auto info = schedule_info_.top();
schedule_info_.pop();
current_time += delay;
Simulator::Schedule(Seconds(current_time + info.start_time), &CppsManager::scheduleMaterialFlow,
this, info);
Simulator::Schedule(current_time + info.start_time, &CppsManager::scheduleMaterialFlow, this,
info);
}
}

Expand Down
1 change: 1 addition & 0 deletions daisi/src/cpps/common/scenariofile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ target_link_libraries(daisi_cpps_common_scenariofile_spawn_info_scenario
INTERFACE
daisi_manager_scenariofile_component
yaml-cpp
ns3::libcore
)
5 changes: 3 additions & 2 deletions daisi/src/cpps/common/scenariofile/spawn_info_scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define DAISI_CPPS_MANAGER_SPAWN_INFO_SCENARIO_H_

#include "manager/scenariofile_component.h"
#include "ns3/core-module.h"

namespace daisi::cpps {

Expand Down Expand Up @@ -57,14 +58,14 @@ struct SpawnDistributionScenario {
struct SpawnInfoScenario {
std::string entity;
std::string friendly_name;
uint64_t start_time;
ns3::Time start_time;

SpawnDistributionScenario spawn_distribution;

void parse(YAML::Node node) {
SERIALIZE_VAR(entity);
SERIALIZE_VAR(friendly_name);
SERIALIZE_VAR(start_time);
SERIALIZE_NS3_TIME(start_time);

SERIALIZE_VAR(spawn_distribution);
}
Expand Down
1 change: 1 addition & 0 deletions daisi/src/manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ target_link_libraries(daisi_manager_general_scenariofile
INTERFACE
daisi_manager_scenariofile_component
yaml-cpp
ns3::libcore
)

add_library(daisi_manager_core_network)
Expand Down
9 changes: 5 additions & 4 deletions daisi/src/manager/general_scenariofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <fstream>
#include <string>

#include "ns3/core-module.h"
#include "scenariofile_component.h"

namespace daisi {
Expand All @@ -35,8 +36,8 @@ struct GeneralScenariofile {

SERIALIZE_VAR(random_seed);

SERIALIZE_VAR(stop_time);
SERIALIZE_VAR(default_delay);
SERIALIZE_NS3_TIME(stop_time);
SERIALIZE_NS3_TIME(default_delay);

SERIALIZE_VAR(output_path);
}
Expand Down Expand Up @@ -69,8 +70,8 @@ struct GeneralScenariofile {
uint64_t random_seed = 0;

// simulation information
uint64_t stop_time = 0;
uint64_t default_delay = 0;
ns3::Time stop_time;
ns3::Time default_delay;

std::optional<std::string> output_path;

Expand Down
1 change: 1 addition & 0 deletions daisi/src/minhton-ns3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ target_sources(daisi_minhton_scenario_steps INTERFACE scenario_steps.h)
target_link_libraries(daisi_minhton_scenario_steps
INTERFACE
daisi_manager_scenariofile_component
ns3::libcore
)
target_include_directories(daisi_minhton_scenario_steps
INTERFACE
Expand Down
Loading

0 comments on commit a2b3c54

Please sign in to comment.