-
Notifications
You must be signed in to change notification settings - Fork 7
Simulation Code Example
jfuruness edited this page Sep 16, 2024
·
9 revisions
Next is the simulation object. This controls all aspects of the simulation, such as the number of trials, CPUs, etc. You can see here that we've chosen to see what happens when 10% of ASes adopt the defensive policy, 20% of ASes, etc. The scenarios listed here are testing what happens when a subprefix hijack is set up against ROV, and a second scenario is a subprefix hijack against PeerROV. This is the actual code that was used to generate those graphs earlier.
You can see the code here, but I've also copied it into the documentation for ease of viewing
from multiprocessing import cpu_count
from pathlib import Path
from peer_rov import PeerROV
from rov import ROV
from subprefix_hijack import SubprefixHijack
from bgpy.shared.enums import SpecialPercentAdoptions
from bgpy.simulation_framework import ScenarioConfig, Simulation
def main():
"""Runs the defaults"""
# Simulation for the paper
sim = Simulation(
percent_adoptions=(
SpecialPercentAdoptions.ONLY_ONE,
0.1,
0.2,
0.4,
0.8,
0.99, # SpecialPercentAdoptions.ALL_BUT_ONE,
),
scenario_configs=(
ScenarioConfig(ScenarioCls=SubprefixHijack, AdoptPolicyCls=ROV),
ScenarioConfig(ScenarioCls=SubprefixHijack, AdoptPolicyCls=PeerROV),
),
output_dir=Path("~/Desktop/tutorial_ex").expanduser(),
num_trials=100,
parse_cpus=cpu_count(),
)
sim.run()
if __name__ == "__main__":
print("This takes about 6 minutes with PyPy")
main()