Skip to content

Commit

Permalink
made run-dgs script fully configurable. removed a debug print. config…
Browse files Browse the repository at this point in the history
…uration option changes.
  • Loading branch information
lh70 committed Aug 12, 2024
1 parent d3e9ae1 commit 9a923d6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
30 changes: 15 additions & 15 deletions Modules/DTN/jvm/src/main/scala/dtn/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import rdt.Client
if args.isEmpty || Set("-?", "-h", "--h", "help", "--help").contains(args(0)) || args.length % 2 != 0 then {
println("""
commandline options:
-m => method (mandatory) | available options: monitoring, routing.direct, routing.epidemic, routing.rdt, routing.rdt2, client.addwins.listen, client.addwins.active, print.received, print.forwarded, print.statedev
-a => host address | default: 0.0.0.0 (for monitoring), 127.0.0.1 (everything else)
-p => host port | default: 5000 (for monitoring), 3000 (for everything else)
-ma => monitoring address | default: 127.0.0.1
-mp => monitoring port | default: 5000
-mid => monitoring creation client id | default: dtn://n2/rdt/testapp
-awa => add-wins rdt number of additions | default: 1000
-awt => add-wins rdt sleep time seconds | default: 0.5
-m => method (mandatory) | available options: monitoring, routing.direct, routing.epidemic, routing.rdt, routing.rdt2, client.addwins.listen, client.addwins.active, print.received, print.forwarded, print.statedev
-a => host address | default: 0.0.0.0 (for monitoring), 127.0.0.1 (everything else)
-p => host port | default: 5000 (for monitoring), 3000 (for everything else)
-ma => monitoring address | default: 127.0.0.1
-mp => monitoring port | default: 5000
-mid => monitoring creation client id | default: dtn://n2/rdt/testapp
-awa => add-wins rdt number of additions | default: 1000
-awt => add-wins rdt sleep time milliseconds | default: 500
""")
} else {
var keyword_args: Map[String, String] = Map()
Expand All @@ -37,11 +37,11 @@ commandline options:
val host_address: String =
keyword_args.getOrElse("-a", if method.equals("monitoring") then "0.0.0.0" else "127.0.0.1")
val host_port: Int = keyword_args.getOrElse("-p", if method.equals("monitoring") then "5000" else "3000").toInt
val monitoring_address: String = keyword_args.getOrElse("-ma", "127.0.0.1")
val monitoring_port: Int = keyword_args.getOrElse("-mp", "5000").toInt
val creation_client_id: String = keyword_args.getOrElse("-mid", "dtn://n2/rdt/testapp")
val add_wins_rdt_number_of_additions: Int = keyword_args.getOrElse("-awa", "1000").toInt
val add_wins_rdt_sleep_time_seconds: Double = keyword_args.getOrElse("-awt", "0.5").toDouble
val monitoring_address: String = keyword_args.getOrElse("-ma", "127.0.0.1")
val monitoring_port: Int = keyword_args.getOrElse("-mp", "5000").toInt
val creation_client_id: String = keyword_args.getOrElse("-mid", "dtn://n2/rdt/testapp")
val add_wins_rdt_number_of_additions: Int = keyword_args.getOrElse("-awa", "1000").toInt
val add_wins_rdt_sleep_time_milliseconds: Long = keyword_args.getOrElse("-awt", "500").toLong

method match
case "monitoring" => start_monitoring_server(host_address, host_port)
Expand All @@ -58,14 +58,14 @@ commandline options:
host_address,
host_port,
MonitoringClient(monitoring_address, monitoring_port),
AddWinsSetRDT(add_wins_rdt_number_of_additions, add_wins_rdt_sleep_time_seconds)
AddWinsSetRDT(add_wins_rdt_number_of_additions, add_wins_rdt_sleep_time_milliseconds)
)
case "client.addwins.active" =>
addwins_case_study_active(
host_address,
host_port,
MonitoringClient(monitoring_address, monitoring_port),
AddWinsSetRDT(add_wins_rdt_number_of_additions, add_wins_rdt_sleep_time_seconds)
AddWinsSetRDT(add_wins_rdt_number_of_additions, add_wins_rdt_sleep_time_milliseconds)
)
case "print.received" =>
MonitoringBundlesReceivedPrinter().run()
Expand Down
2 changes: 1 addition & 1 deletion Modules/DTN/jvm/src/main/scala/dtn/Monitoring.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MonitoringServer(server: TCPReadonlyServer, paths: MonitoringPaths = Monit

val now: ZonedDateTime = ZonedDateTime.now(ZoneId.of("UTC"))

println(s"trying to decode data: ${String(data, StandardCharsets.UTF_8)}")
// println(s"trying to decode data: ${String(data, StandardCharsets.UTF_8)}")

Json.decode(data).to[MonitoringMessage].value match
case m: MonitoringMessage.BundleReceivedAtRouter =>
Expand Down
4 changes: 1 addition & 3 deletions Modules/DTN/shared/src/main/scala/dtn/RdtCreation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait CaseStudyRdt {
def caseStudyActive(): Unit
}

class AddWinsSetRDT(number_of_additions: Int, sleep_time_seconds: Double) extends CaseStudyRdt {
class AddWinsSetRDT(number_of_additions: Int, sleep_time_milliseconds: Long) extends CaseStudyRdt {
type RdtType = Set[String]

given JsonValueCodec[RdtType] = JsonCodecMaker.make(CodecMakerConfig.withMapAsArray(true))
Expand Down Expand Up @@ -42,8 +42,6 @@ class AddWinsSetRDT(number_of_additions: Int, sleep_time_seconds: Double) extend
}

def caseStudyActive(): Unit = {
val sleep_time_milliseconds: Long = (sleep_time_seconds * 1000).toLong

println("started active add-wins rdt.")
println(s"\nnumber of additions: ${number_of_additions}\nsleep-time milliseconds: ${sleep_time_milliseconds}")

Expand Down
46 changes: 38 additions & 8 deletions Modules/DTN/simulation/shared/run-dgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@

cutoff_after_x_steps = 100
wait_time_per_step_seconds = 5.0
janitor_interval_seconds = 2.0
discovery_interval_seconds = 0.5
janitor_interval_milliseconds = 1500
discovery_interval_milliseconds = 300

monitoring_creation_client_id = "dtn://n2/rdt/app1"

addwins_rdt_number_of_additions = 1000
addwins_rdt_sleep_time_milliseconds = 500
addwins_clients = {
"n2": "active",
"n3": "listen"
}

# WARNING
# this script is custom tailored for my simulation use case and other simulations might use parts of this script because it works,
Expand All @@ -42,7 +51,7 @@
# this script automatically adds the control network: 172.16.0.0/24
#
# special case: control node
# this script automatically adds a control node of type "CHECKER" outside the grid
# this script automatically adds a control node of type "MONITORING" outside the grid
#
# special case: step 0
# step 0 must exist and we accept only 'an' add-node instructions in that step
Expand Down Expand Up @@ -112,8 +121,8 @@ def _substitute_config_file(self, node_id):
file_contents = self.configs[node_id]

file_contents = re.sub(r'strategy = "epidemic"', 'strategy = "external"', file_contents, 1)
file_contents = re.sub(r'interval = "2s"', f'interval = "{discovery_interval_seconds}s"', file_contents, 1)
file_contents = re.sub(r'janitor = "10s"', f'janitor = "{janitor_interval_seconds}s"', file_contents, 1)
file_contents = re.sub(r'interval = "2s"', f'interval = "{discovery_interval_milliseconds}ms"', file_contents, 1)
file_contents = re.sub(r'janitor = "10s"', f'janitor = "{janitor_interval_milliseconds}ms"', file_contents, 1)

discovery_string = "[discovery_destinations]\n"
for idx, address in enumerate(self.discovery_addresses[node_id]):
Expand Down Expand Up @@ -169,11 +178,11 @@ def get_substituted_config_files(self):
core.set_session_options(session_id, {'controlnet': '172.16.0.0/24'})
print("added control network 172.16.0.0/24")


core.add_node(session_id, Node(id=global_node_counter.next(), name="control", type=NodeType.DEFAULT, model="MONITORING", position=Position(x=50, y=50)))
monitoring_node_id = global_node_counter.next()
core.add_node(session_id, Node(id=monitoring_node_id, name="control", type=NodeType.DEFAULT, model="MONITORING", position=Position(x=50, y=50)))
core.set_node_service(session_id, monitoring_node_id, "rdtmonitoring", startup=(f"bash -c '/root/.coregui/scripts/rdt_tool -m monitoring -mid {monitoring_creation_client_id} &> monitoring.log'",))
print ("added control node")


print("running setup")

line = dgs_lines.pop(0)
Expand All @@ -194,6 +203,14 @@ def get_substituted_config_files(self):
node_map[node_name] = global_node_counter.next()
position = Position(x=100+(grid_node_id%10)*50, y=100+int(grid_node_id/10)*50)

if node_name in addwins_clients:
if addwins_clients[node_name] == "active":
service_defaults["DTN"].append("addwinsclientactive")
core.set_service_defaults(session_id, service_defaults)
else:
service_defaults["DTN"].append("addwinsclientlisten")
core.set_service_defaults(session_id, service_defaults)

core.add_node(session_id, Node(
id=node_map[node_name],
name=node_name,
Expand All @@ -202,6 +219,19 @@ def get_substituted_config_files(self):
position=position
))

if node_name in addwins_clients:
if addwins_clients[node_name] == "active":
service_defaults["DTN"].remove("addwinsclientactive")
core.set_service_defaults(session_id, service_defaults)
print(f"adding active client to node {node_name} (id: {node_map[node_name]})")
core.set_node_service(session_id, node_map[node_name], "addwinsclientactive", startup=(f"bash -c '/root/.coregui/scripts/rdt_tool -m client.addwins.active -ma 172.16.0.1 -awa {addwins_rdt_number_of_additions} -awt {addwins_rdt_sleep_time_milliseconds} &> client.log'",))
else:
service_defaults["DTN"].remove("addwinsclientlisten")
core.set_service_defaults(session_id, service_defaults)
print(f"adding listen client to node {node_name} (id: {node_map[node_name]})")
core.set_node_service(session_id, node_map[node_name], "addwinsclientlisten", startup=(f"bash -c '/root/.coregui/scripts/rdt_tool -m client.addwins.listen -ma 172.16.0.1 &> client.log'",))


dtnd_toml_contents = core.get_node_service_file(session_id, node_map[node_name], "dtnd", "dtnd.toml").data
dtnd_configfile_helper.add_node(node_map[node_name], dtnd_toml_contents)
print(f"added node '{node_name}'")
Expand Down

0 comments on commit 9a923d6

Please sign in to comment.