diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1789344..d1c73c0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: Basic Checks +name: ci on: push: @@ -8,74 +8,52 @@ on: workflow_dispatch: jobs: - build: + docker-build: runs-on: ubuntu-latest - steps: - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: "3.10" - - - name: Checkout repo + - name: Checkout traffic-reproducer uses: actions/checkout@v4 with: + path: traffic-reproducer submodules: recursive - - name: Install dependencies + - name: Build traffic-reproducer container + shell: bash run: | - pip install -r requirements.txt - - - name: Set up loopback interfaces - run: | - sudo ifconfig lo:1 192.168.100.1 up - sudo ifconfig lo:2 192.168.100.2 up + cd traffic-reproducer + docker build -t traffic-reproducer:latest -f docker/Dockerfile . - - name: Start Listener + - name: Save image as artifact + shell: bash run: | - touch nc_output.txt - (nc -u -l -k 9991 | hexdump -C > nc_output.txt & echo $! > listener_pid.txt) & - echo "$!" > listener_pid.txt - sleep 5s - echo "Listener PID:" - cat listener_pid.txt - echo "Listener Output:" - cat nc_output.txt + mkdir -p /tmp/docker/ + docker save -o /tmp/docker/traffic_reproducer_docker_image.tar traffic-reproducer:latest - - name: Debug IP Configuration - run: | - ip a - - - name: Run main.py - run: | - sudo env PATH="$PATH" python main.py -v -t examples/ipfix-traffic.yml + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + retention-days: 7 + name: traffic_reproducer_docker_image + path: /tmp/docker - - name: Stop Listener - run: | - pid=$(cat listener_pid.txt) - sudo kill -SIGINT $pid - sleep 5s - echo "Listener Output:" - cat nc_output.txt +# TODO idea: send all messages from all examples and then do some basic check on collector logs / print files (no warnings, no error, line counts, etc...) - - name: Preprocess Hexdump Output - run: | - awk '{print substr($0, 11, 47)}' nc_output.txt | tr -d ' \n' > nc_output_cleaned.txt - echo "Listener Output Cleaned:" - cat nc_output_cleaned.txt + regression-tests: + runs-on: ubuntu-latest + needs: docker-build + steps: + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + pattern: '*_docker_images' + path: /tmp/docker - - name: Count Packets + - name: Import images in the local registry run: | - packet_count=$(grep -o '000a' nc_output_cleaned.txt | wc -l) - echo $packet_count > packet_count.txt + docker load -i /tmp/docker/traffic_reproducer_docker_image.tar + echo "List Images" + docker images | grep 'traffic-reproducer' - - name: Check Packet Count + - name: Run traffic-reproducer container run: | - packet_count=$(cat packet_count.txt) - echo "Packet Count: $packet_count" - if [ "$packet_count" -eq 6 ]; then - echo "Success: 6 packets received." - else - echo "Error: Expected 6 packets but found $packet_count." - exit 1 - fi \ No newline at end of file + docker run --rm --name traffic-reproducer traffic-reproducer:latest diff --git a/.gitignore b/.gitignore index 462c2bd..d135a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ **/__pycache__/ **/venv/ -docker/* **/__tmp**/ **/tmp** diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..37042cb --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,18 @@ +# TODO: make this variable to select different python versions (and manually set a default one) +FROM python:3.12-bookworm + +# Set the working directory +WORKDIR /app + +# Copy the application files to the container +COPY . /app + +# Create /pcap directory for config and pcap files +RUN mkdir /pcap + +# Install the Python dependencies +RUN pip install -r requirements.txt + +# Set the entry point command +# CMD ["python", "./main.py", "--cfg", "/pcap/traffic-reproducer.conf"] +CMD ["python", "./main.py", "-h"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..b03a0fc --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash +exec > /pcap/run_traffic_reproducer.log +exec 2>&1 + +echo "$( date ) Running traffic reproducer multi" + +pids=() +pcap_folders=( $( ls -d /pcap/*/ ) ) +echo "$( date ) ${#pcap_folders[@]} folders found: ${pcap_folders[@]}" + +for value in ${pcap_folders[@]}; do +# sleep 1 + echo "$( date ) Running ${value}traffic-reproducer.yml" + python3 main.py -t ${value}traffic-reproducer.yml -v > ${value}traffic-reproducer.log 2>&1 & + pid=$! + echo "$( date ) Spawned PID $pid" + pids+=(${pid}) +done + +echo "$( date ) All spawned PIDs: ${pids[@]}" +echo "$( date ) All processes spawned, now waiting" + +for pid in "${pids[@]}"; do + echo "$( date ) Waiting for PID $pid" + wait $pid +done +echo "$( date ) All processes finished"