From 2a17bbec3f01624a3cfde18c4a77285241ec1b0f Mon Sep 17 00:00:00 2001 From: Helena Steck Date: Wed, 13 Jul 2022 17:34:31 -0300 Subject: [PATCH] Make server files become templates for easy configuration --- .gitignore | 4 ++ example.sh | 2 +- fill_templates.py | 15 ++++++ ...{CaddyFilev2QUIC => CaddyFilev2QUIC.jinja} | 4 +- .../{CaddyFilev2TCP => CaddyFilev2TCP.jinja} | 4 +- ...ASHbed.py => hypercorn_goDASHbed.py.jinja} | 6 +-- ...c.py => hypercorn_goDASHbed_quic.py.jinja} | 6 +-- lab.py | 49 +++++++++++++++++-- 8 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 fill_templates.py rename godash_defaults/{CaddyFilev2QUIC => CaddyFilev2QUIC.jinja} (77%) rename godash_defaults/{CaddyFilev2TCP => CaddyFilev2TCP.jinja} (50%) rename godash_defaults/{hypercorn_goDASHbed.py => hypercorn_goDASHbed.py.jinja} (91%) rename godash_defaults/{hypercorn_goDASHbed_quic.py => hypercorn_goDASHbed_quic.py.jinja} (91%) diff --git a/.gitignore b/.gitignore index 0394601..ba935f5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ logs __pycache__/ experiment_results output/ +godash_defaults/hypercorn_goDASHbed_quic.py +godash_defaults/hypercorn_goDASHbed.py +godash_defaults/CaddyFilev2QUIC +godash_defaults/CaddyFilev2TCP diff --git a/example.sh b/example.sh index 56a704d..8f2a910 100755 --- a/example.sh +++ b/example.sh @@ -25,5 +25,5 @@ python3 lab.py \ -d "RazaDatasets/5g/Static/B_2020.02.14_13.21.26.csv" -t5g\ -d "RazaDatasets/5g/Static/B_2020.02.27_18.39.27.csv" -t5g\ --godash-bin "/home/raza/Downloads/goDASH/godash/godash" \ - --godash-config-template "/home/raza/Downloads/goDASHbed/config/configure.json" \ + --dash-files-root "/home/raza/videofiles" \ --types wsgi diff --git a/fill_templates.py b/fill_templates.py new file mode 100644 index 0000000..4669f61 --- /dev/null +++ b/fill_templates.py @@ -0,0 +1,15 @@ +from jinja2 import Template + + +def fill_template( + template_file: str, output_file: str, dash_root: str, defaults_root: str +): + with open(template_file, "r") as f: + template = Template(f.read()) + + template_output = template.render( + root_dash_path=dash_root, godash_defaults_path=defaults_root + ) + + with open(output_file, "w") as f: + f.write(template_output) diff --git a/godash_defaults/CaddyFilev2QUIC b/godash_defaults/CaddyFilev2QUIC.jinja similarity index 77% rename from godash_defaults/CaddyFilev2QUIC rename to godash_defaults/CaddyFilev2QUIC.jinja index 9c679ad..50b2eec 100644 --- a/godash_defaults/CaddyFilev2QUIC +++ b/godash_defaults/CaddyFilev2QUIC.jinja @@ -4,9 +4,9 @@ } www.godashbed.org:4444 { - tls /home/raza/Downloads/goDASH/godash/http/certs/cert.pem /home/raza/Downloads/goDASH/godash/http/certs/key.pem + tls {{godash_defaults_path}}/cert.pem {{godash_defaults_path}}/key.pem encode gzip - root * /home/raza/videofiles + root * {{root_dash_path}} file_server log { output file ./output/caddy_access.log diff --git a/godash_defaults/CaddyFilev2TCP b/godash_defaults/CaddyFilev2TCP.jinja similarity index 50% rename from godash_defaults/CaddyFilev2TCP rename to godash_defaults/CaddyFilev2TCP.jinja index f6a07bd..f0f04c7 100644 --- a/godash_defaults/CaddyFilev2TCP +++ b/godash_defaults/CaddyFilev2TCP.jinja @@ -1,7 +1,7 @@ www.godashbed.org:443 { - tls /home/raza/Downloads/goDASH/godash/http/certs/cert.pem /home/raza/Downloads/goDASH/godash/http/certs/key.pem + tls {{godash_defaults_path}}/cert.pem {{godash_defaults_path}}/key.pem encode gzip - root * /home/raza/videofiles + root * {{root_dash_path}} file_server log { output file ./output/caddy_access.log diff --git a/godash_defaults/hypercorn_goDASHbed.py b/godash_defaults/hypercorn_goDASHbed.py.jinja similarity index 91% rename from godash_defaults/hypercorn_goDASHbed.py rename to godash_defaults/hypercorn_goDASHbed.py.jinja index 0827c9e..b877366 100755 --- a/godash_defaults/hypercorn_goDASHbed.py +++ b/godash_defaults/hypercorn_goDASHbed.py.jinja @@ -7,7 +7,7 @@ from os import path # this defines the root folder containing our DASH dataset -dash_content_path = '/home/raza/videofiles' +dash_content_path = {{root_dash_path}} # define the config setup for our testbed config = Config() @@ -15,8 +15,8 @@ config.insecure_bind = ["10.0.0.1:80"] # port number to use for QUIC # locations for the cert and key -config.certfile = "../goDASH/godash/http/certs/cert.pem" -config.keyfile = "../goDASH/godash/http/certs/key.pem" +config.certfile = "./cert.pem" +config.keyfile = "./key.pem" # this 'root_path' is needed by QuartTrio to point to the DASH video content folder app = QuartTrio(__name__, root_path=dash_content_path) diff --git a/godash_defaults/hypercorn_goDASHbed_quic.py b/godash_defaults/hypercorn_goDASHbed_quic.py.jinja similarity index 91% rename from godash_defaults/hypercorn_goDASHbed_quic.py rename to godash_defaults/hypercorn_goDASHbed_quic.py.jinja index 1f9fd4b..5fe9288 100755 --- a/godash_defaults/hypercorn_goDASHbed_quic.py +++ b/godash_defaults/hypercorn_goDASHbed_quic.py.jinja @@ -7,7 +7,7 @@ from os import path # this defines the root folder containing our DASH dataset -dash_content_path = '/home/raza/videofiles' +dash_content_path = {{root_dash_path}} # define the config setup for our testbed config = Config() @@ -16,8 +16,8 @@ config.insecure_bind = ["10.0.0.1:80"] # port number to use for QUIC # locations for the cert and key -config.certfile = "../goDASH/godash/http/certs/cert.pem" -config.keyfile = "../goDASH/godash/http/certs/key.pem" +config.certfile = "./cert.pem" +config.keyfile = "./key.pem" # this 'root_path' is needed by QuartTrio to point to the DASH video content folder app = QuartTrio(__name__, root_path=dash_content_path) diff --git a/lab.py b/lab.py index 1ba9e63..d52ca87 100755 --- a/lab.py +++ b/lab.py @@ -17,6 +17,7 @@ from mininet.node import Host, Switch from datasets5G import datasets5G +from fill_templates import fill_template from normalize_datasets import NormalizedDataset, get_normalized_datasets from process_results import cleanup_pcap, process_pcap @@ -192,10 +193,14 @@ def get_experiment_checkpoint_file_name(experiment_root_folder: str) -> str: return os.path.join(experiment_root_folder, "checkpoint.txt") +def get_defaults_path() -> pathlib.Path: + return pathlib.Path(__file__).parent.absolute() / "godash_defaults" + + # server settings def server(server: Host, experiment: Experiment): load_experiment_config(experiment) - parent_dir = pathlib.Path(__file__).parent.absolute() / "godash_defaults" + parent_dir = get_defaults_path() print( f"sudo systemctl stop apache2.service && caddy start --config {parent_dir / 'CaddyFilev2QUIC'} --adapter caddyfile" @@ -484,14 +489,14 @@ def parse_command_line_options(): parser.add_argument( "--godash-bin", - help="Path to goDASH executable.", + help=" Path to goDASH executable.", type=str, required=True, ) parser.add_argument( "--godash-config-template", - default=os.path.join(os.path.dirname(__file__), "configure.json"), + default=(get_defaults_path() / "configure.json").as_posix(), help="""Path to goDASH configuration template. This will be the base for the goDASH configuration, the fields 'quic', 'url' 'serveraddr' and 'adapt' will be overwritten for the running experiment. The other fields @@ -509,11 +514,19 @@ def parse_command_line_options(): required=True, ) + parser.add_argument( + "--dash-files-root", + default="/var/www/html", + help="""This is the root to the DASH files to be served by the file + server, i.e. the path where the DASH segments are stored, the mpd paths + are relative to this.""", + ) + parser.add_argument( "-d", "--dataset", action="append", - help=""" System path, relative or absolute, to the dataset + help="""System path, relative or absolute, to the dataset which will be used to simulate the network conditions, can be added multiple times, requires one -t/--dataset-type set for each. E.g.: `-d a/b.csv -t4g -d b/c.csv -t5g`. If not provided defaults to the @@ -524,7 +537,7 @@ def parse_command_line_options(): "-t", "--dataset-type", action="append", - help=""" Type of the dataset. E.g.: 5g, 4g, 3g.""", + help="""Type of the dataset. E.g.: 5g, 4g, 3g.""", ) parser.add_argument( @@ -634,6 +647,32 @@ def parse_command_line_options(): with open(get_experiment_checkpoint_file_name(experiment_root)) as f: done_experiment_hashes = set(f.read().splitlines()) + # fill server templates before starting out: + fill_template( + (get_defaults_path() / "CaddyFilev2QUIC.jinja").as_posix(), + (get_defaults_path() / "CaddyFilev2QUIC").as_posix(), + parsed_commands.dash_files_root, + get_defaults_path().as_posix().rstrip("/"), + ) + fill_template( + (get_defaults_path() / "CaddyFilev2TCP.jinja").as_posix(), + (get_defaults_path() / "CaddyFilev2TCP").as_posix(), + parsed_commands.dash_files_root, + get_defaults_path().as_posix().rstrip("/"), + ) + fill_template( + (get_defaults_path() / "hypercorn_goDASHbed.py.jinja").as_posix(), + (get_defaults_path() / "hypercorn_goDASHbed.py").as_posix(), + parsed_commands.dash_files_root, + get_defaults_path().as_posix().rstrip("/"), + ) + fill_template( + (get_defaults_path() / "hypercorn_goDASHbed_quic.py.jinja").as_posix(), + (get_defaults_path() / "hypercorn_goDASHbed_quic.py").as_posix(), + parsed_commands.dash_files_root, + get_defaults_path().as_posix().rstrip("/"), + ) + for mpd_path in mpd_paths: for dataset, mode in zip(normalized_datasets, dataset_modes): for adaptation_algorithm in algos: