diff --git a/user_services/owl/.gitignore b/user_services/owl/.gitignore deleted file mode 100644 index b6f5d44a..00000000 --- a/user_services/owl/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.pcap -*.csv -owl-venv/ diff --git a/user_services/owl/Dockerfile b/user_services/owl/Dockerfile deleted file mode 100644 index 2eb53b3e..00000000 --- a/user_services/owl/Dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -# syntax=docker/dockerfile:1 - -FROM python:3.9-slim-buster -EXPOSE 5005 - -RUN apt-get update && \ - apt-get install -y tcpdump git build-essential && \ - apt-get install -y procps && \ - apt-get install -y gcc mono-mcs && \ - apt-get install -y sudo nano vim && \ - rm -rf /var/lib/apt/lists/* - -RUN pip install --upgrade pip -RUN pip install --pre scapy[basic] -RUN pip install influxdb-client -RUN pip install --upgrade psutil -RUN pip install requests -RUN pip install influxdb3-python -RUN pip install pandas - -RUN git clone --branch owl-main https://github.com/fabric-testbed/MeasurementFramework.git -RUN mkdir /owl_output -RUN mkdir /owl_config -RUN gcc -fPIC -shared -o /MeasurementFramework/user_services/owl/owl/sock_ops/ptp_time.so \ - /MeasurementFramework/user_services/owl/owl/sock_ops/ptp_time.c -RUN ls -l / - -WORKDIR /MeasurementFramework/user_services/owl/owl - -### May be needed later -#COPY requirements.txt requirements.txt -#RUN pip3 install -r requirements.txt - - -# For debugging -RUN pwd -RUN ls -lh * - -ENTRYPOINT [ "python3" ] diff --git a/user_services/owl/Playbooks/create_owl.yaml b/user_services/owl/Playbooks/create_owl.yaml deleted file mode 100644 index f48c2c30..00000000 --- a/user_services/owl/Playbooks/create_owl.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -- name: Set up OWL - hosts: Experiment_Nodes - #vars: - # ansible_python_interpreter: /usr/bin/python3.9 - tasks: - - name: Create a directory for owl config file - ansible.builtin.file: - path: /home/mfuser/services/owl/config - state: directory - mode: '0755' - - - name: Create a directory for owl output data - ansible.builtin.file: - path: /home/mfuser/services/owl/output - state: directory - mode: '0755' - - - name: Pull fabrictestbed/owl image from DockerHub - community.general.docker_image: - name: fabrictestbed/owl:0.1.4 - source: pull - - - # Below only for debugging - #- name: Create docker build directory - # ansible.builtin.file: - # path: /home/mfuser/services/owl/docker - # state: directory - # mode: '0755' - - #- name: Copy Dockerfile - # ansible.builtin.copy: - # src: /home/mfuser/services/owl/files/Dockerfile - # dest: /home/mfuser/services/owl/docker/Dockerfile - # mode: '0644' - - #- name: Build owl container image - # community.general.docker_image: - # name: owl:0.1.3 - # build: - # path: /home/mfuser/services/owl/docker - # pull: yes - # network: host - # source: build - diff --git a/user_services/owl/Playbooks/delete_csv_file.yaml b/user_services/owl/Playbooks/delete_csv_file.yaml deleted file mode 100644 index f7636c4d..00000000 --- a/user_services/owl/Playbooks/delete_csv_file.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: Delete csv files on Docker Volume - hosts: Experiment_Nodes - tasks: - - name: Delete saved csv files - community.general.docker_container: - name: owl - image: fabrictestbed/owl:0.1.0 - state: started - restart: yes - command: ["DataProcessManager.py", "delete_csv", "/owl_output"] - privileged: yes - network_mode: host - #ports: - # - "5005:5005" - volumes: - - /home/mfuser/services/owl/output:/owl_output - - /home/mfuser/services/owl/config:/owl_config diff --git a/user_services/owl/Playbooks/delete_pcap_files.yaml b/user_services/owl/Playbooks/delete_pcap_files.yaml deleted file mode 100644 index 9826cf21..00000000 --- a/user_services/owl/Playbooks/delete_pcap_files.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: Process OWL data - hosts: Experiment_Nodes - tasks: - - name: Delete pcap files - community.general.docker_container: - name: owl - image: fabrictestbed/owl:0.1.3 - state: started - restart: yes - command: ["DataProcessManager.py", "delete_pcap", "/owl_output"] - privileged: yes - network_mode: host - #ports: - # - "5005:5005" - volumes: - - /home/mfuser/services/owl/output:/owl_output - - /home/mfuser/services/owl/config:/owl_config diff --git a/user_services/owl/Playbooks/get_owl_status.yaml b/user_services/owl/Playbooks/get_owl_status.yaml deleted file mode 100644 index 6820bd7a..00000000 --- a/user_services/owl/Playbooks/get_owl_status.yaml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Get OWL container status - hosts: Experiment_Nodes - tasks: - - name: Get infos on container - community.general.docker_container_info: - name: owl - register: result - - - name: Does container exist? - ansible.builtin.debug: - msg: "The container {{ 'exists' if result.exists else 'does not exist' }}" - - - name: Print information about container - ansible.builtin.debug: - var: result.container['State'] - when: result.exists diff --git a/user_services/owl/Playbooks/process_owl_data.yaml b/user_services/owl/Playbooks/process_owl_data.yaml deleted file mode 100644 index 83ed055b..00000000 --- a/user_services/owl/Playbooks/process_owl_data.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: Process OWL data - hosts: Experiment_Nodes - tasks: - - name: Extract information from pcap files on a Docker volume and append to a csv file. - community.general.docker_container: - name: owl - image: fabrictestbed/owl:0.1.3 - state: started - restart: yes - command: ["DataProcessManager.py", "process", "/owl_output", "out.csv"] - privileged: yes - network_mode: host - #ports: - # - "5005:5005" - volumes: - - /home/mfuser/services/owl/output:/owl_output - - /home/mfuser/services/owl/config:/owl_config diff --git a/user_services/owl/Playbooks/remove_owl.yaml b/user_services/owl/Playbooks/remove_owl.yaml deleted file mode 100644 index ef4a7092..00000000 --- a/user_services/owl/Playbooks/remove_owl.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Remove OWL (including the output data) - hosts: Experiment_Nodes - tasks: - - name: Remove owl container - community.general.docker_container: - name: owl - state: absent - - - name: Remove owl image - community.general.docker_image: - name: owl - tag: 0.1.2 - state: absent diff --git a/user_services/owl/Playbooks/start_owl.yaml b/user_services/owl/Playbooks/start_owl.yaml deleted file mode 100644 index cc8a8bef..00000000 --- a/user_services/owl/Playbooks/start_owl.yaml +++ /dev/null @@ -1,27 +0,0 @@ ---- -- name: Start OWL - hosts: Experiment_Nodes - tasks: - - name: Copy owl.conf file - ansible.builtin.copy: - src: /home/mfuser/services/owl/files/owl.conf - dest: /home/mfuser/services/owl/config/owl.conf - - - name: Copy owl service request file - ansible.builtin.copy: - src: /home/mfuser/services/owl/files/links.json - dest: /home/mfuser/services/owl/config/links.json - - - name: Start OWL container - community.general.docker_container: - name: owl - image: fabrictestbed/owl:0.1.3 - state: started - restart: yes - command: ["NodeSockManager.py", "/owl_config/owl.conf"] - privileged: yes - network_mode: host - pid_mode: host - volumes: - - /home/mfuser/services/owl/output:/owl_output - - /home/mfuser/services/owl/config:/owl_config diff --git a/user_services/owl/Playbooks/stop_owl.yaml b/user_services/owl/Playbooks/stop_owl.yaml deleted file mode 100644 index 75713c3a..00000000 --- a/user_services/owl/Playbooks/stop_owl.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Stop OWL - hosts: Experiment_Nodes - tasks: - - name: Stop OWL container - community.general.docker_container: - name: owl - state: stopped diff --git a/user_services/owl/README.md b/user_services/owl/README.md deleted file mode 100644 index 897abdcd..00000000 --- a/user_services/owl/README.md +++ /dev/null @@ -1,232 +0,0 @@ -# OWL(One Way Latency) - -Program for measuring one-way latency between nodes. Though it is written -specifically for FABRIC Testbed, it should work in a general setting with -minimal edits, if at all. - -As outlined below, it can be used either within the Measurement Framework -environment or as a stand-alone application possibly running inside a Docker -contaier. - -Under all circumstances, the sender and receiver nodes must have PTP (Precision -time Protocol) service running. To verify this and to look up the PTP clock path, -run the following command: - -``` -px -ef | grep phc2sys -``` - - -# How to Collect OWL data - -## 1. As part of FABRIC Measurement Framework - -Refer to the Jupyter Notebook examples. - - -## 2. Using Docker containers - -### Prerequisites - -- PTP (Precision Time Protocol) service -- Docker daemon (ipv6 enabled if necessary) -- Directory on the host machine for owl config files (owl.conf, links.json) -- Directory on the host machine for owl output files (\*.pcap) - -### Usage - -1. clone the repository and navigate to the `owl` directory. - -``` -git clone -b owl-main https://github.com/fabric-testbed/MeasurementFramework.git -cd MeasurementFramework/user_services/owl -``` - -2. Build a container using the Dockerfile. - -``` -# Example: -$ sudo docker build -t owl-app . -``` - -2. Run the container with the following. - - -#### Using NodeSockManager.py - -Useful when measurements on multiple source-destination pairs are to be recorded -concurrently. Set options in `owl.conf`, list source-destination pairs in `links.json`, -and save them in the same directory (`local/config/dir` below). - -``` -$ sudo docker run --rm -dp : \ ---mount type=bind,source=,target=/owl_config \ ---mount type=bind,source=,target=/owl_output \ ---network="host" \ ---pid="host" \ ---privileged \ -owl-app:latest NodeSockManager.py /owl_config/owl.conf -``` - -##### Example - -``` -# On all nodes - -$ sudo docker run --rm -dp 5005:5005 \ ---mount type=bind,source=/home/me/mydir/owl/config,target=/owl_config \ ---mount type=bind,source=/home/me/mydir/owl/output,target=/owl_output \ ---network="host" \ ---pid="host" \ ---privileged \ -owl-app:latest NodeSockManager.py /owl_config/owl.conf [--sys-clock] - -``` - -#### Using socket operation scripts - -When recording the latency between two endpoints, it may be simpler to run sender -and receiver scripts rather than creating config files and using `NodeSockManager`. - -``` -# sender side -$sudo docker run --rm -d \ ---network="host" \ ---pid="host" \ ---privileged \ -owl-app:latest sock_ops/udp_sender.py [options] - -# receiver -$sudo docker run --rm -d \ ---mount type=bind,source=,target=/owl_output \ ---network="host" \ ---pid="host" ---privileged \ -owl-app sock_ops/udp_capturer.py [options] -``` - -##### Examples - -``` -# On Node 1 - -# sender side -sudo docker run -d \ ---network="host" \ ---pid="host" \ ---privileged \ -owl-app:latest sock_ops/udp_sender.py \ ---ptp-so-file "/MeasurementFramework/user_services/owl/owl/sock_ops/time_ops/ptp_time.so" \ ---dest-ip "10.0.0.2" ---dest-port 5005 \ ---frequency 0.1 \ ---seq-n 5452 \ ---duration 60 - -# On Node 2 - -# receiver -sudo docker run -d \ ---mount type=bind,source=/tmp/owl/,target=/owl_output \ ---network="host" \ ---pid="host" \ ---privileged \ -owl-app sock_ops/udp_capturer.py \ ---ip "10.0.0.2" \ ---port 5005 \ ---outfile /owl_output/owl.pcap \ ---duration 60 -``` - - -## 3. Natively (not recommended: only if strongly desired) - -### Prerequisites -- PTP (Precision Time Protocol) service -- tcpdump -- gcc -- scapy (`pip install --pre scapy[basic]`) -- psutil (`pip install psutil`) -- `ptp_time.so` file placed in the same directory as `ptp_time.c` - -In addition, Python scripts must be run with `sudo` privilege to perform -necessary socket operations. - -### Usage - -The simplest experiment can be performed with - -``` -# clone the repo and navigate to owl -git clone -b owl https://github.com/fabric-testbed/MeasurementFramework.git -cd MeasurementFramework/user_services/owl - -# create a shared object file from ptp_time.c -gcc -fPIC -shared -o owl/sock_ops/time_ops/ptp_time.so owl/sock_ops/time_ops/ptp_time.c - -# Run the sender -sudo python3 owl/sock_ops/udp_sender.py [options] - - -# Run the receiver -sudo python3 owl/sock_ops/udp_capturer.py [options] - -``` - -Alternatively use `NodeSockManager` on multiple nodes with config and links files. - -``` -sudo python3 owl/NodeSockManager.py -``` - -# How to view live OWL data using InfluxDB - -### Prerequisites -- InfluxDB server -- DB information (url, org, token, bucket) - -### Usage -On the receiver node, while `udp_capturer.py` is collecting data (or afterwards) -run `send_data.py` as follows: - -``` -python3 send_data.py [--verbose] - --pcapfile .pcap - --token "" - --org "" - --url "" - --bucket "" -``` - -#### Using Docker image - -``` -docker pull fabrictestbed/owl:0.1.5 - -sudo docker run -d \ ---mount type=bind,source=/tmp/owl/,target=/owl_output \ ---network="host" ---pid="host" \ ---privileged \ -owl:0.1.5 sock_ops/send_data.py \ ---pcapfile .pcap \ ---token "" \ ---org "" \ ---url "" \ ---bucket "" -``` - - -`send_data.py` reads the pcap file, converts it to ASCII, extract the relevant -information for one-way latency measurements, and send it to the InfluxDB server. - -Once stored on InfluxDB, data can be downloaded in several different formats, -including csv. - - - -# Current Limitations -- IPV4 only -- Assumes hosts are (non-routing) endpoints. - - diff --git a/user_services/owl/owl/DataProcessManager.py b/user_services/owl/owl/DataProcessManager.py deleted file mode 100644 index a80295c1..00000000 --- a/user_services/owl/owl/DataProcessManager.py +++ /dev/null @@ -1,84 +0,0 @@ -from data_ops import read_pcap as pcap_reader -import glob -import sys -import os - -class DataProcessManager: - def __init__(self, dir_path, outfile, delete_pcap=False, verbose=True): - - self.data_dir = dir_path - self.pcapfiles = glob.glob(f'{self.data_dir}/*.pcap') - self.outfile = f'{self.data_dir}/{outfile}' - self.delete_pcap = delete_pcap - self.verbose = verbose - - - def process(self): - # Remove zero-bye pcap files - pcapfiles_with_data = [f for f in self.pcapfiles if os.stat(f).st_size > 0] - print("non-zero pcap files to be processed: ", pcapfiles_with_data) - - processor = pcap_reader.PcapProcessor( - pcapfiles_with_data, - self.outfile, - self.delete_pcap, - self.verbose) - processor.process() - - - def delete_csv_files(self): - csv_files = glob.glob(f'{self.data_dir}/*.csv') - - for csv_f in csv_files: - try: - os.remove(csv_f) - print("Removed File: ", csv-f) - except: - print("Error while deleting file: ", csv_f) - - - def delete_pcap_files(self): - - for pcap_f in self.pcapfiles: - try: - os.remove(pcap_f) - print("Removed File: ". pcap_f) - except: - print("Error while deleting file: ", pcap_f) - -if __name__ == "__main__": - ''' - Args: - [1] action (required): 'process' | 'delete_csv' | 'delete_pcap' - [2] directory path (required) - [3] output ccsv file name (optional) - ''' - - if len(sys.argv) < 3: - print("Error: needs action + directory path") - exit(1) - - elif len(sys.argv) == 4: - outfile = sys.argv[3] - - else: - outfile = 'out.csv' - - # Create an instance - data_processor = DataProcessManager(sys.argv[2], outfile) - - # Action! - if sys.argv[1] == 'process': - data_processor.process() - - elif sys.argv[1] == 'delete_csv': - data_processor.delete_csv_files() - - elif sys.argv[1] == 'delete_pcap': - data_processor.delete_pcap_files() - - else: - print("Error: no such action") - exit(1) - - diff --git a/user_services/owl/owl/NodeSockManager.py b/user_services/owl/owl/NodeSockManager.py deleted file mode 100644 index 75353dff..00000000 --- a/user_services/owl/owl/NodeSockManager.py +++ /dev/null @@ -1,180 +0,0 @@ -import json -import argparse -import configparser -import logging -import time -import socket -import subprocess -import sys -import os -from random import randrange -import threading -from pathlib import Path - -# hideous but needed to ues udp_sender from here? - -cwd = os.getcwd() -sys.path.insert(0, f'{cwd}/sock_ops') - -from sock_ops import udp_sender as sender -from sock_ops import udp_capturer as capturer - - -class NodeSockManager(): - def __init__(self, config_file='/owl_config/owl.conf', sys_clock=False): - - config = configparser.ConfigParser() - config.read(config_file) - - self.udp_port = int(config['GENERAL']['UdpPort']) - self.pcap_interval = int(config['receiver']['PcapInterval']) - self.capture_mode = config['receiver']['CaptureMode'] - self.send_interval = float(config['sender']['SendInterval']) - - self.links = Path('/owl_config/links.json') - self.output_dir = Path('/owl_output') - self.ptp_so_file = Path('sock_ops/time_ops/ptp_time.so') - self.sys_clock = sys_clock - - logging.basicConfig(filename=f'{self.output_dir}/owl.log', - level=logging.DEBUG, - format='%(created)f %(message)s') - self.logger = logging.getLogger('owl-log') - - self.sender_instances = {} - self.listen_instance = None - - # Find all the IPV4 addresses on the node - self.host_ipv4s = self._find_IPs() - self.logger.info(f"IP addresses on this node: {self.host_ipv4s}") - - # Go ahead and start - self.start() - - - def start(self): - _listen_ip, _dests = self._read_links() - - - capturer_thread = threading.Thread(target=self._start_capturer, args=(_listen_ip,)) - capturer_thread.start() - sender_thread = threading.Thread(target=self._start_sender, args=(_dests,)) - sender_thread.start() - - - #self._start_capturer(_listen_ip) - #self._start_sender(_dests) - - - def stop(self): - # Clean up! - if self.listen_instance: - self.logger.info("stopping tcpdump") - self.listen_instance.stop() - time.sleep(1) - self.listen_instance = None - - if len(self.sender_instances) > 0: - for dest_ip, instance in self.sender_instances.items(): - self.logger.info("stopping send to: ", dest_ip) - instance.stop() - time.sleep(1) - self.sender_instances[dest_ip] = None - - sleep(2) - - assert self.listen_instance is None - assert len(self.sender_instances) == 0 - - - - def _find_IPs(self): - ''' - Find IP addresses on the host interfaces - ''' - - s = subprocess.check_output(["hostname", "-I"]) - return s.decode('UTF-8').split() - - - def _read_links(self): - ''' - Returns: - listener(str): either "UP" or "DOWN" (for the host node) - dests([str,]): destination IPs (for the host node) - ''' - - listen_ip = None # Default - dests = [] - - try: - f = open(self.links) - data = json.load(f) - - for link in data["links"]: - if link["src"] in self.host_ipv4s: - dests.append(link["dst"]) - - if link["dst"] in self.host_ipv4s: - listen_ip = link["dst"] - - except FileNotFoundError: - self.logger.error(f"No service request file {self.links} found.") - # Will return None for receiver status, an empty list for dests - - finally: - self.logger.info(f"read_links: {listen_ip}, {dests}") - - return listen_ip, dests - - - def _start_capturer(self, listen_ip): - - if listen_ip: - # If - self.listen_instance = capturer.TcpdumpOps(listen_ip, self.udp_port) - - if self.capture_mode == "live": - self.logger.info("Starting live capture") - self.listen_instance.start_live_capture() - else: - self.logger.info(f"Starting capture. Pcap files in {self.output_dir}") - self.listen_instance.start_capture(self.output_dir, self.pcap_interval) - - else: # no need to capture packets - pass - - - def _start_sender(self, dests): - seq_n = randrange(10000) - - for dest_ip in dests: - if dest_ip not in self.sender_instances.keys(): - self.logger.info(f"new destination IP found: {str(dest_ip)} ") - self.sender_instances[dest_ip] = sender.UDP_sender( - self.send_interval, - dest_ip, - self.udp_port, - seq_n, - self.ptp_so_file, - sys_clock=self.sys_clock) - - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser() - parser.add_argument('conf', type=str, help='path to config file') - parser.add_argument('--sys-clock', action=argparse.BooleanOptionalAction, - help='uses Python time module (mostly for debugging)') - parser.add_argument('--duration', type=int, default=0, help='number of seconds to run') - args = parser.parse_args() - - manager = NodeSockManager(args.conf, sys_clock=args.sys_clock) - - # Stop the program at a certain interval only if the arg is given. - if args.duration: - time.sleep(args.duration) - manager.stop() - self.logger.info("finished") - diff --git a/user_services/owl/owl/data_ops/pcap_to_csv.py b/user_services/owl/owl/data_ops/pcap_to_csv.py deleted file mode 100644 index d7c7e399..00000000 --- a/user_services/owl/owl/data_ops/pcap_to_csv.py +++ /dev/null @@ -1,67 +0,0 @@ -from scapy.all import * -import os -import csv -import sys -from decimal import Decimal -import datetime -import argparse - - -def convert_pcap_to_csv(pcapfile, outfile="owl_output.csv", verbose=False): - - pkts=rdpcap(pcapfile) - print(f"reading... {pcapfile}") - - for pkt in pkts: - # Fields are - # latency_nano is in nano-seconds - - fields=[] - - # Field: linkid - linkid = 0 # for now - fields.append(str(linkid)) - - # Field: src-ip - fields.append(str(pkt[IP].src)) - - # Field: send-t - send_t, seq_n = pkt[Raw].load.decode().split(",") - send_t = Decimal(send_t) # To prevent floating point issues - fields.append(str(send_t)) - - # Field: dst-ip - fields.append(str(pkt[IP].dst)) - - # Field: dst-t - fields.append(str(pkt.time)) # pkt.time is type Decimal - - # Field: seq-n - fields.append(seq_n) - - # Field: latency - latency_nano = (pkt.time-send_t)*1000000000 - fields.append(str(int(latency_nano))) - - if verbose: - print(fields) - - with open(outfile, 'a') as f: - writer = csv.writer(f) - writer.writerow(fields) - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser() - - parser.add_argument("--pcapfile", type=str, help="path/to/a/pcap/file") - parser.add_argument("--outfile", type=str, default="owl_output.csv") - parser.add_argument("--verbose", "-v", action='store_true', default=False) - - args = parser.parse_args() - - convert_pcap_to_csv(args.pcapfile, outfile=args.outfile, verbose=args.verbose) - - diff --git a/user_services/owl/owl/sock_ops/owl_capturer.py b/user_services/owl/owl/sock_ops/owl_capturer.py deleted file mode 100644 index 9722f0c4..00000000 --- a/user_services/owl/owl/sock_ops/owl_capturer.py +++ /dev/null @@ -1,94 +0,0 @@ -import subprocess -import time -import argparse -import psutil - - -class TcpdumpOps: - def __init__(self, ip_addr, port): - ''' - ip_addr(str): - port(int): - ''' - - self.interface = self.find_interface(ip_addr) - self.port = port - self.p = None - - - def start_capture(self, outfile=None, pcap_interval=None): - - if not outfile: - outfile=f"~/{int(time.time())}.pcap" - - rollover_sec=f"-G {str(pcap_interval)}" if pcap_interval else " " - - cmd = f"sudo tcpdump -U -vfn -XX -tt \ - -i {self.interface} --direction in \ - -j adapter_unsynced \ - --time-stamp-precision nano \ - port {str(self.port)} \ - -w {outfile} \ - {rollover_sec}" - - print("Starting tcpdump session: ", cmd) - print("pcap file: ", outfile) - - self.p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) - - print("Pid: ", self.p.pid) - - # without this, capturer may exit (when sender is not running) - self.p.wait() - - - def stop(self): - self.p.terminate() - - - def find_interface(self, ip): - ''' - find the interface for a given ip address - Returns: - str: os interface name ('eth0' etc.) - ''' - - addrs = psutil.net_if_addrs() - - for interface in addrs.keys(): - for nic in addrs[interface]: - if nic.address == ip: - return interface - - return 'any' - -if __name__ == "__main__": - - parser = argparse.ArgumentParser() - - parser.add_argument("--ip", type=str, default='10.0.0.1', help="destination IP") - parser.add_argument("--port", type=int, default=5005, - help="listening port number") - parser.add_argument("--pcap-sec", type=int, default=None, - help="number of capture seconds for each pcap file") - parser.add_argument("--outfile", type=str, default="/owl_output/owl.pcap", - help="path/to/output/file") - parser.add_argument("--duration", type=int, default=None, - help="number of seconds to run capture") - - - args = parser.parse_args() - ip_addr = args.ip - port = args.port - interval_pcap = args.pcap_sec - outfile = args.outfile - - session = TcpdumpOps(ip_addr, port) - session.start_capture(outfile, interval_pcap) - - if args.duration: - sec = args.duration - - time.sleep(sec) - session.stop() - diff --git a/user_services/owl/owl/sock_ops/owl_sender.py b/user_services/owl/owl/sock_ops/owl_sender.py deleted file mode 100644 index 5d9e66c4..00000000 --- a/user_services/owl/owl/sock_ops/owl_sender.py +++ /dev/null @@ -1,125 +0,0 @@ -import os -import sys -import socket -import time -import argparse -from threading import Timer -import ptp - -####### -# Timer part: -# https://stackoverflow.com/questions/3393612/run-certain-code-every-n-seconds -# By https://github.com/MestreLion -####### - - -class OwlSender(): - def __init__(self, interval, dst_ip, dst_port, start_num, - ptp_so_file="ptp_time.so", sys_clock=False): - - if sys_clock: - self.ptp_device = None - print("Using system clock") - else: - self.ptp_device = self.find_ptp_device_name() - self.ptp_so_file = ptp_so_file - print("Using PTP device") - - self._timer = None - self.interval = interval - self.is_running = False - - self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Internet, UDP - self.dst_ip = dst_ip - self.dst_port = dst_port - self.seq_n = start_num - - self.start() - - - def find_ptp_device_name(self): - result=os.popen("sudo ps -ef |grep phc2sys").read() - start="-s" - end=" -c CLOCK_REALTIME" - - if end in result: - sindex= result.rfind(start) - eindex= result.rfind(end) - device = result[sindex+3:eindex].strip() - return device - - # else - sys.exit("Cannot find running ptp device") - - - def _run(self): - self.is_running = False - self.start() - - if not self.ptp_device: - # Use Python system library - current_timestamp = time.time_ns()/1000000000 - - else: - # Get it directly from PTP device - current_timestamp = ptp.get_ptp_timestamp( - device_name = self.ptp_device, - so_file=self.ptp_so_file) - - create_timestamp = f"{current_timestamp},{str(self.seq_n)}" - self.sock.sendto(create_timestamp.encode(), (self.dst_ip, self.dst_port)) - self.seq_n = self.seq_n + 1 - - - def start(self): - if not self.is_running: - self._timer = Timer(self.interval, self._run) - self._timer.start() - self.is_running = True - - - def stop(self): - self._timer.cancel() - self.is_running = False - self.sock.close() - - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser() - - parser.add_argument("--dest-ip", type=str, default="10.10.1.1", - help='destination IP') - parser.add_argument("--dest-port", type=int, default=5005, - help='destination port') - parser.add_argument("--frequency", type=float, default=0.5, - help="second interval at which probe packet will be sent") - parser.add_argument("--seq-n", type=int, default=1234, - help="initial sequence number") - parser.add_argument("--duration", type=int, default=None, - help="number of seconds to run") - parser.add_argument("--ptp-so-file", type=str, default="ptp_time.so", - help='path to ptp_time.so file.') - parser.add_argument("--sys-clock", action=argparse.BooleanOptionalAction, - help='uses Python time module (mostly for debugging)') - - args = parser.parse_args() - - send_interval = args.frequency - dest_ip = args.dest_ip - dest_port = args.dest_port - seq_n = args.seq_n - ptp_so_file = args.ptp_so_file - sys_clock = args.sys_clock - - owl_sender = OwlSender(send_interval, dest_ip, dest_port, seq_n, - ptp_so_file, sys_clock) - - if args.duration: - duration = args.duration - - try: - time.sleep(duration) # function should run during this time - finally: - owl_sender.stop() diff --git a/user_services/owl/owl/sock_ops/ptp.py b/user_services/owl/owl/sock_ops/ptp.py deleted file mode 100644 index 3cd3431e..00000000 --- a/user_services/owl/owl/sock_ops/ptp.py +++ /dev/null @@ -1,36 +0,0 @@ -################# -## To use this file, run the following command first -## $ cc -fPIC -shared -o ptp_time.so ptp_time.c -## -## Usage: -## python3 ptp.py -## -##(to get the device name with "ps -ef | grep phc2sys") -################ - -import sys -from ctypes import * - -class TIMESPEC(Structure): - _fields_ = [ - ('tv_sec', c_long), - ('tv_nsec', c_long) - ] - -def get_ptp_timestamp(device_name="/dev/ptp1", so_file="./ptp_time.so"): - func = CDLL(so_file) - func.get_ptp_time.restype = type(TIMESPEC()) - test=func.get_ptp_time(bytes(device_name, encoding='utf-8')) - timestamp_str=f"{test.tv_sec}.{test.tv_nsec:09}" - return timestamp_str - - - -if __name__ == "__main__": - - if len(sys.argv) != 3: - print("Usage: python3 pyp.py '' ''") - exit(1) - - else: - print(get_ptp_timestamp(device_name=sys.argv[1], so_file=sys.argv[2])) diff --git a/user_services/owl/owl/sock_ops/ptp_time.c b/user_services/owl/owl/sock_ops/ptp_time.c deleted file mode 100644 index 77027415..00000000 --- a/user_services/owl/owl/sock_ops/ptp_time.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -struct timespec get_ptp_time(char *DEVICE) -{ - #define CLOCKFD 3 - #define FD_TO_CLOCKID(fd) ((~(clockid_t) (fd) << 3) | CLOCKFD) - #define CLOCKID_TO_FD(clk) ((unsigned int) ~((clk) >> 3)) - char *device = DEVICE; - int fd; - struct timespec ts; - clockid_t clkid; - fd = open(device, O_RDWR); - if (fd < 0) { - fprintf(stderr, "opening %s: %s\n", device, strerror(errno)); - exit(0); - } - clkid = FD_TO_CLOCKID(fd); - if (clock_gettime(clkid, &ts)) { - perror("clock_gettime"); - exit(0); - } - else { - return ts; - } -} - -int main(int argc, char *argv[] ) { - struct timespec ts; - - ts = get_ptp_time(argv[1]); - printf("%ld.%09ld \n", ts.tv_sec, ts.tv_nsec); -} diff --git a/user_services/owl/owl/sock_ops/send_data.py b/user_services/owl/owl/sock_ops/send_data.py deleted file mode 100644 index 1be3b348..00000000 --- a/user_services/owl/owl/sock_ops/send_data.py +++ /dev/null @@ -1,157 +0,0 @@ -from subprocess import Popen, PIPE -from shlex import split -import re -from decimal import * -import argparse - -from influxdb_client import InfluxDBClient, Point, WritePrecision -from influxdb_client.client.write_api import SYNCHRONOUS - -import influxdb_client_3 - -''' -Script for reading/tailing a pcap file, convert the relevant contents to ASCII, -and send data to InfluxDB. Intended for live-monitoring of OWL data. - -For more information on InfluxDB, go to https://www.influxdata.com/ -InfluxDB Python client: - https://docs.influxdata.com/influxdb/cloud/api-guide/client-libraries/python/ -''' - - -def parse_and_send(pcap_file, verbose=False, influxdb_token=None, - influxdb_org=None, influxdb_url=None, influxdb_bucket=None, - influxdb_desttype="meas_node"): - - # InfluxDB set up - if influxdb_desttype == "cloud": - write_client = influxdb_client_3.InfluxDBClient3(host=influxdb_url, - token=influxdb_token, org=influxdb_org) - - elif influxdb_desttype == "meas_node": - write_client = InfluxDBClient(url=influxdb_url, - token=influxdb_token, org=influxdb_org) - write_api = write_client.write_api(write_options=SYNCHRONOUS) - - # Continuously read the end of a pcap file - cmd = f'tail -c +1 -f {pcap_file} | tcpdump -A -tt -n -l -r -' - - if verbose: - print(f"Starting tcpdump session: {cmd}") - - p1 = Popen(split(f"tail -c +1 -f {pcap_file}"), stdout=PIPE) - p2 = Popen(split("tcpdump -A -tt -n -l -r -"), stdin=p1.stdout, stdout=PIPE) - - - while True: - line = p2.stdout.readline() - if not line: - break - - newline = line.rstrip().decode() - IP_pos = newline.find(" IP ") - - # Find a line that looks like - # "1661899028.527932821 IP 10.10.2.1.40634 > 10.10.1.1.5005: UDP, length 23" - if IP_pos != -1: - packet_data = {} - - time_dst = newline[:IP_pos] - IPs = re.findall(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', newline) - - try: - packet_data["sender"] = IPs[0] - packet_data["receiver"] = IPs[1] - packet_data["received"] = time_dst - - except Exception as e: - print(e) - - # Find a line that looks like ".........F1661899028.5274663,1877" - elif re.search(r'\d{10}.\d{,9},\d{1,}$', newline): - parts = re.split(",", newline) - timestamp = re.findall('\d{10}\.\d{,9}', parts[0]) - - try: - seq_n = parts[1] - t_delta = (Decimal(time_dst) - Decimal(timestamp[0]))*1000000000 - - packet_data["sent"] = timestamp[0] - packet_data["latency"] = t_delta - packet_data["seq"] = seq_n - packet_data["sent_ns"] = Decimal(timestamp[0])*1000000000 - - except Exception as e: - print(e) - - - # Check if all keys have non-empty values - all_non_empty = all(value is not None and value != '' for value - in packet_data.values()) - - if all_non_empty: - # If all values are there, push the data to InfluxDB - - # Cloud push requires different InfluxDB client module. - # The try/except block ensures that any prev failure in forming - # packet_data causes program to not write out data. - try: - if influxdb_desttype == "meas_node": - point = (Point("owl") - .tag("sender", packet_data["sender"]) - .tag("receiver", packet_data["receiver"]) - .field("received", float(packet_data["received"])) - .field("latency", int(packet_data["latency"])) - .field("seq_n", int(packet_data["seq"])) - .time(int(packet_data["sent_ns"]), - write_precision=WritePrecision.NS) - ) - write_api.write(bucket=influxdb_bucket, org=influxdb_org, record=point) - elif influxdb_desttype == "cloud": - point = (influxdb_client_3.Point("owl") - .tag("sender", packet_data["sender"]) - .tag("receiver", packet_data["receiver"]) - .field("received", float(packet_data["received"])) - .field("latency", int(packet_data["latency"])) - .field("seq_n", int(packet_data["seq"])) - .time(int(packet_data["sent_ns"]) - )) - write_client.write(database=influxdb_bucket, record=point) - except Exception as e: - print(e) - - else: - # Do not send incomplete entries to InfluxDB - pass - - if verbose: - print(packet_data) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - - parser.add_argument("--pcapfile", type=str, default="/owl_output/owl.pcap", - help="path/to/the/pcap/file") - parser.add_argument("--verbose", "-v", action='store_true', - help="verbose(print packet info)") - parser.add_argument("--token", type=str, help="InfluxDB token (str)") - parser.add_argument("--org", type=str, help="InfluxDB organization name (str)") - parser.add_argument("--url", type=str, help="InfluxDB URL (str)") - parser.add_argument("--desttype", type=str, help="Destination for InfluxDB \ - data. Either 'cloud' for the Cloud instance, or \ - 'meas_node' for the Measurement Node (str)") - parser.add_argument("--bucket", type=str, help="InfluxDB bucket name (str)") - - args = parser.parse_args() - - pcap_file=args.pcapfile - verbose=args.verbose - token = args.token - org = args.org - url = args.url - bucket = args.bucket - desttype = args.desttype - - parse_and_send(pcap_file, verbose=verbose, influxdb_token=token, influxdb_org=org, - influxdb_url=url, influxdb_bucket=bucket, influxdb_desttype=desttype) diff --git a/user_services/owl/requirements.txt b/user_services/owl/requirements.txt deleted file mode 100644 index 0ef4dfce..00000000 --- a/user_services/owl/requirements.txt +++ /dev/null @@ -1,27 +0,0 @@ -ansible-base==2.10.17 -ansible-core==2.16.3 -astroid==3.0.1 -certifi==2024.7.4 -cffi==1.15.0 -cryptography==42.0.4 -dill==0.3.7 -influxdb-client==1.40.0 -isort==5.12.0 -Jinja2==3.1.4 -MarkupSafe==2.1.1 -mccabe==0.7.0 -packaging==21.3 -platformdirs==4.1.0 -psutil==5.9.8 -pycparser==2.21 -pylint==3.0.3 -pyparsing==3.0.7 -python-dateutil==2.8.2 -PyYAML==6.0 -reactivex==4.0.4 -resolvelib==0.8.1 -scapy==2.5.0 -six==1.16.0 -tomlkit==0.12.3 -typing_extensions==4.7.1 -urllib3==2.2.2 diff --git a/user_services/owl/sample_owl_config/links.json b/user_services/owl/sample_owl_config/links.json deleted file mode 100644 index 10f42e0d..00000000 --- a/user_services/owl/sample_owl_config/links.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "links":[ - { - "src": "10.130.2.2", - "dst": "10.130.3.2" - }, - { - "src": "10.130.3.2", - "dst": "10.130.2.2" - } - ] -} diff --git a/user_services/owl/sample_owl_config/owl.conf b/user_services/owl/sample_owl_config/owl.conf deleted file mode 100644 index 886de54b..00000000 --- a/user_services/owl/sample_owl_config/owl.conf +++ /dev/null @@ -1,11 +0,0 @@ -[GENERAL] -UdpPort = 5005 - -[receiver] -CaptureMode = save -# For live capture use CaptureMode=live (not yet fully implemented) -PcapInterval = 30 - -[sender] -SendInterval=1.0 - diff --git a/user_services/owl/service_commands/create.py b/user_services/owl/service_commands/create.py deleted file mode 100644 index 4ffd8487..00000000 --- a/user_services/owl/service_commands/create.py +++ /dev/null @@ -1,54 +0,0 @@ -###### -# Build OWL container on experimenters' nodes by running -# create_owl.yaml script -####### - -from datetime import datetime -import os -from pathlib import Path -import json -import subprocess - -def main(): - - #Path("/home/mfuser/services/owl/config").mkdir(parents=True, exist_ok=True) - - ret_val = {} - - playbook_exe = "/home/mfuser/.local/bin/ansible-playbook" - ansible_hosts_file = "/home/mfuser/services/common/hosts.ini" - playbook = "/home/mfuser/mf_git/user_services/owl/Playbooks/create_owl.yaml" - keyfile = "/home/mfuser/.ssh/mfuser_private_key" - - # For GENI testing only - #playbook_exe = "/home/mfuser/MeasurementFramework/user_services/owl/owl-venv/bin/ansible-playbook" - #ansible_hosts_file = "/etc/ansible/hosts" - #playbook = "/home/mfuser/MeasurementFramework/user_services/owl/Playbooks/create_owl.yaml" - #keyfile = "/home/mfuser/.ssh/id_rsa" - - - # For some reason the local ansible.cfg file is not being used - os.environ["ANSIBLE_HOST_KEY_CHECKING"] = "False" - - cmd = [playbook_exe, "-i", ansible_hosts_file, "--key-file", keyfile, '-b', playbook] - print(cmd) - - r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - decoded_out = r.stdout.decode("utf-8") - play_recap = decoded_out[decoded_out.find("PLAY RECAP"):] - decoded_err = r.stderr.decode("utf-8") - - if r.returncode == 0: - ret_val["success"] = True - ret_val["msg"] = "create_owl.yaml script ran successfully." - else: - ret_val["success"] = False - ret_val["msg"] = "create_owl.yaml script run FAILED." - - ret_val["play_recap"] = play_recap - print(json.dumps(ret_val)) - - -if __name__ == "__main__": - main() diff --git a/user_services/owl/service_commands/info.py b/user_services/owl/service_commands/info.py deleted file mode 100644 index 9b63bd30..00000000 --- a/user_services/owl/service_commands/info.py +++ /dev/null @@ -1,34 +0,0 @@ -###### -# Get contents of owl.conf and link.json stored on the meas_node -####### - -import json -import configparser - - -def get_owl_files(): - config = configparser.ConfigParser() - - conf_path = '/home/mfuser/services/owl/files/owl.conf' - links_path = '/home/mfuser/services/owl/files/links.json' - - config.read(conf_path) - - conf_file = {} - for section in config.sections(): - conf_file[section] = {} - for option in config.options(section): - conf_file[section][option] = config.get(section, option) - - links_file = {} - with open(links_path) as json_file: - links_file = json.load(json_file) - - # Add links info to config file dictionary - conf_file.update(links_file) - - print(json.dumps(conf_file)) - - -if __name__ == "__main__": - get_owl_files() diff --git a/user_services/owl/service_commands/remove.py b/user_services/owl/service_commands/remove.py deleted file mode 100644 index 8376b463..00000000 --- a/user_services/owl/service_commands/remove.py +++ /dev/null @@ -1,50 +0,0 @@ -###### -# Remove OWL container on experimenters' nodes by running -# remove_owl.yaml script -####### - - -from datetime import datetime -import os -import json -import subprocess - -def main(): - ret_val = {} - - playbook_exe = "/home/mfuser/.local/bin/ansible-playbook" - ansible_hosts_file = "/home/mfuser/services/common/hosts.ini" - playbook = "/home/mfuser/mf_git/user_services/owl/Playbooks/remove_owl.yaml" - keyfile = "/home/mfuser/.ssh/mfuser_private_key" - - ### For GENI testing - #playbook_exe = "/home/mfuser/MeasurementFramework/user_services/owl/owl-venv/bin/ansible-playbook" - #ansible_hosts_file = "/etc/ansible/hosts" - #playbook = "/home/mfuser/MeasurementFramework/user_services/owl/Playbooks/remove_owl.yaml" - #keyfile = "/home/mfuser/.ssh/id_rsa" - - # For some reason the local ansible.cfg file is not being used - os.environ["ANSIBLE_HOST_KEY_CHECKING"] = "False" - - cmd = [playbook_exe, "-i", ansible_hosts_file, "--key-file", keyfile, '-b', playbook] - print(cmd) - - r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - decoded_out = r.stdout.decode("utf-8") - play_recap = decoded_out[decoded_out.find("PLAY RECAP"):] - decoded_err = r.stderr.decode("utf-8") - - if r.returncode == 0: - ret_val["success"] = True - ret_val["msg"] = "remove_owl.yaml ran. OWL conatiner and image successfully removed." - else: - ret_val["success"] = False - ret_val["msg"] = "remove_owl.yaml playbook failed. OWL container and image not \ - removed from hosts" - - ret_val["play_recap"] = play_recap - print(json.dumps(ret_val)) - -if __name__ == "__main__": - main() diff --git a/user_services/owl/service_commands/start.py b/user_services/owl/service_commands/start.py deleted file mode 100644 index 806286a2..00000000 --- a/user_services/owl/service_commands/start.py +++ /dev/null @@ -1,48 +0,0 @@ -###### -# Start OWL container on experiments' nodes running -# start_owl.yaml script -####### - -import os -from datetime import datetime -import subprocess -import json - -def start_owl(): - ret_val = {} - - # For GENI Testing only - #playbook_exe = "/home/mfuser/MeasurementFramework/user_services/owl/owl-venv/bin/ansible-playbook" - #ansible_hosts_file = "/etc/ansible/hosts" - #playbook = "/home/mfuser/MeasurementFramework/user_services/owl/Playbooks/start_owl.yaml" - #keyfile = "/home/mfuser/.ssh/id_rsa" - - playbook_exe = "/home/mfuser/.local/bin/ansible-playbook" - ansible_hosts_file = "/home/mfuser/services/common/hosts.ini" - playbook = "/home/mfuser/mf_git/user_services/owl/Playbooks/start_owl.yaml" - keyfile = "/home/mfuser/.ssh/mfuser_private_key" - - # For some reason the local ansible.cfg file is not being used - os.environ["ANSIBLE_HOST_KEY_CHECKING"] = "False" - - cmd = [playbook_exe, "-i", ansible_hosts_file, "--key-file", keyfile, '-b', playbook] - - r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - decoded_out = r.stdout.decode("utf-8") - play_recap = decoded_out[decoded_out.find("PLAY RECAP"):] - decoded_err = r.stderr.decode("utf-8") - - if r.returncode == 0: - ret_val["success"] = True - ret_val["msg"] = "start_owl.yaml script ran successfully." - else: - ret_val["success"] = False - ret_val["msg"] = "start_owl.yaml script run FAILED." - - ret_val["play_recap"] = play_recap - print(json.dumps(ret_val)) - -if __name__ == "__main__": - start_owl() - diff --git a/user_services/owl/service_commands/stop.py b/user_services/owl/service_commands/stop.py deleted file mode 100644 index b9bc9a10..00000000 --- a/user_services/owl/service_commands/stop.py +++ /dev/null @@ -1,49 +0,0 @@ -###### -# Stop OWL container on experimenters' nodes by running -# stop_owl.yaml script -####### - -from datetime import datetime -import os -import json -import subprocess - -def main(): - ret_val = {} - - # For GENI testing - #playbook_exe = "/home/mfuser/MeasurementFramework/user_services/owl/owl-venv/bin/ansible-playbook" - #ansible_hosts_file = "/etc/ansible/hosts" - #playbook = "/home/mfuser/MeasurementFramework/user_services/owl/Playbooks/stop_owl.yaml" - #keyfile = "/home/mfuser/.ssh/id_rsa" - - playbook_exe = "/home/mfuser/.local/bin/ansible-playbook" - ansible_hosts_file = "/home/mfuser/services/common/hosts.ini" - playbook = "/home/mfuser/mf_git/user_services/owl/Playbooks/stop_owl.yaml" - keyfile = "/home/mfuser/.ssh/mfuser_private_key" - - - # For some reason the local ansible.cfg file is not being used - os.environ["ANSIBLE_HOST_KEY_CHECKING"] = "False" - - cmd = [playbook_exe, "-i", ansible_hosts_file, "--key-file", keyfile, '-b', playbook] - - r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - decoded_out = r.stdout.decode("utf-8") - play_recap = decoded_out[decoded_out.find("PLAY RECAP"):] - decoded_err = r.stderr.decode("utf-8") - - if r.returncode == 0: - ret_val["success"] = True - ret_val["msg"] = "stop_owl.yaml script ran successfully." - else: - ret_val["success"] = False - ret_val["msg"] = "stop_owl.yaml script run FAILED." - - ret_val["play_recap"] = play_recap - print(json.dumps(ret_val)) - - -if __name__ == "__main__": - main() diff --git a/user_services/owl/service_commands/update.py b/user_services/owl/service_commands/update.py deleted file mode 100644 index 5e167985..00000000 --- a/user_services/owl/service_commands/update.py +++ /dev/null @@ -1,37 +0,0 @@ -###### -# Get contents of owl.conf and link.json stored on the meas_node -####### - -import json -import configparser - - -def get_owl_files(): - config = configparser.ConfigParser() - - conf_path = '/home/mfuser/services/owl/files/owl.conf' - links_path = '/home/mfuser/services/owl/files/links.json' - - config.read(conf_path) - - conf_file = {} - for section in config.sections(): - conf_file[section] = {} - for option in config.options(section): - conf_file[section][option] = config.get(section, option) - - links_file = {} - with open(links_path) as json_file: - links_file = json.load(json_file) - - # Add links info to config file dictionary - conf_file.update(links_file) - - print(json.dumps(conf_file)) - - -if __name__ == "__main__": - get_owl_files() - - - diff --git a/user_services/owl/service_commands/write_config.py b/user_services/owl/service_commands/write_config.py deleted file mode 100644 index be76a7b2..00000000 --- a/user_services/owl/service_commands/write_config.py +++ /dev/null @@ -1,65 +0,0 @@ -###### -# Generate master owl.conf and links.json files for meas_node -# This script should run before start.py -####### - -import argparse -from configparser import ConfigParser -import json -from pathlib import Path - -def generate_owl_config(port=5005, links_file="/owl_config/links.json", send_intvl = 1.0, - capture_mode = 'save', pcap_intvl = 30, output_dir='/owl_output'): - config = ConfigParser() - config.optionxform = str - - config['GENERAL'] = {} - config['GENERAL']['UdpPort'] = str(port) - config['GENERAL']['LinksFile'] = links_file - - config['sender'] = {} - config['sender']['SendInterval'] = str(send_intvl) - - config['receiver'] = {} - config['receiver']['CaptureMode'] = capture_mode - config['receiver']['PcapInterval'] = str(pcap_intvl) - config['receiver']['OutputDir'] = output_dir - - with open ('/home/mfuser/services/owl/config/owl.conf', 'w') as configfile: - config.write(configfile) - - -def generate_links(links): - ''' - Generate /home/mfuser/services/owl/config/links.json file - Args: - links: JSON formatted string - ''' - - # TODO: Not exactly needed - jsonified_links = json.dumps(links, indent=4) - - with open ('/home/mfuser/services/owl/config/links.json', 'w') as json_out: - json_out.write(jsonified_links) - #json_out.write(links) - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - - parser.add_argument('--port', type=int, default=5005) - parser.add_argument('--links-file', type=str, default='/owl_config/links.json') - parser.add_argument('--send-int', type=float, default = 1.0) - parser.add_argument('--cap-mode', type=str, default = 'save', help='"save" or "live"') - parser.add_argument('--pcap-int', type=int, default = 30) - parser.add_argument('--output-dir', type=str, default = '/owl_output') - parser.add_argument('--links', type=json.loads, default = '{"links": [{"src": "10.0.0.1","dst": "10.0.0.2"}]}', - help='{"links": [{"src": "10.0.0.1","dst": "10.0.0.2"}]}') - - args = parser.parse_args() - - Path("/home/mfuser/services/owl/config").mkdir(parents=True, exist_ok=True) - - generate_owl_config(port=args.port, links_file=args.links_file, send_intvl=args.send_int, - capture_mode=args.cap_mode, pcap_intvl=args.pcap_int, output_dir=args.output_dir) - - generate_links(args.links)