Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions beamsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def __init__(self, items):
run_exe_time = None


def run(b="ns3", t="direct", g=10, gv=10, shuffle=False, mpi=False):
def run(b="ns3-direct", t="direct", p="tcp", g=10, gv=10, shuffle=False, mpi=False):
global run_exe_time
exe_time = os.stat(exe).st_mtime
if run_exe_time != exe_time:
run_exe_time = exe_time
run_cache.clear()
key = (b, t, g, gv, shuffle, mpi)
key = (b, t, p, g, gv, shuffle, mpi)
output = run_cache.get(key, None)
if output is None:
cmd = [
Expand All @@ -86,6 +86,8 @@ def run(b="ns3", t="direct", g=10, gv=10, shuffle=False, mpi=False):
b,
"-t",
t,
"-p",
p,
"-g",
str(g),
"-gv",
Expand Down
15 changes: 15 additions & 0 deletions cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <beamsim/example/roles.hpp>
#include <beamsim/gossip/config.hpp>
#include <beamsim/ns3/mpi.hpp>
#include <beamsim/ns3/protocol.hpp>
#include <charconv>
#include <print>

Expand Down Expand Up @@ -349,6 +350,10 @@ struct SimulationConfig {
{Topology::GOSSIP, "gossip"},
{Topology::GRID, "grid"},
}};
const Args::Enum<beamsim::ns3_::Protocol> enum_protocol_{{
{beamsim::ns3_::Protocol::TCP, "tcp"},
{beamsim::ns3_::Protocol::UDP, "udp"},
}};

beamsim::example::RolesConfig roles_config;

Expand All @@ -372,6 +377,13 @@ struct SimulationConfig {
"Communication topology",
enum_topology_,
};
beamsim::ns3_::Protocol protocol = beamsim::ns3_::Protocol::TCP;
Args::FlagEnum<decltype(protocol)> flag_protocol{
{"-p", "--protocol"},
protocol,
"Network protocol (TCP/UDP)",
enum_protocol_,
};
Args::FlagInt<beamsim::example::GroupIndex> flag_group_count{{
{"-g", "--groups"},
roles_config.group_count,
Expand All @@ -394,6 +406,7 @@ struct SimulationConfig {
return f(flag_config_path,
flag_backend,
flag_topology,
flag_protocol,
flag_group_count,
flag_validators_per_group,
flag_shuffle,
Expand Down Expand Up @@ -424,6 +437,7 @@ struct SimulationConfig {
Yaml yaml{YAML::LoadFile(config_path)};
yaml.at({"backend"}).get(backend, enum_backend_);
yaml.at({"topology"}).get(topology, enum_topology_);
yaml.at({"protocol"}).get(protocol, enum_protocol_);
yaml.at({"shuffle"}).get(shuffle);

yaml.at({"roles", "group_count"}).get(roles_config.group_count);
Expand Down Expand Up @@ -466,6 +480,7 @@ struct SimulationConfig {
std::println("Configuration:");
std::println(" Backend: {}", enum_backend_.str(backend));
std::println(" Topology: {}", enum_topology_.str(topology));
std::println(" Protocol: {}", enum_protocol_.str(protocol));
std::println(" Groups: {}", roles_config.group_count);
std::println(" Validators per group: {}",
roles_config.group_validator_count);
Expand Down
1 change: 1 addition & 0 deletions example.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
backend: ns3
topology: direct
protocol: tcp # Use tcp or udp

roles:
group_count: 4
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ void run_simulation(const SimulationConfig &config) {
case SimulationConfig::Backend::NS3_DIRECT: {
#ifdef ns3_FOUND
beamsim::ns3_::Simulator simulator{metrics_ptr};
simulator.setProtocol(config.protocol);
if (config.backend == SimulationConfig::Backend::NS3) {
simulator.routing_.initRouters(routers);
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/beamsim/ns3/protocol.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace beamsim::ns3_ {
enum class Protocol {
TCP,
UDP,
};
} // namespace beamsim::ns3_
Loading