diff --git a/build.sh b/build.sh index e252d09..091d3e1 100755 --- a/build.sh +++ b/build.sh @@ -45,48 +45,11 @@ fi source .env export DOCKER_NETWORK_NAME="snapshotter-lite-v2-${SLOT_ID}" -SUBNET_SECOND_OCTET=$((16 + (SLOT_ID / 256) % 240)) -SUBNET_THIRD_OCTET=$((SLOT_ID % 256)) -# Always use 0 for the fourth octet to ensure a valid subnet -export DOCKER_NETWORK_SUBNET="172.${SUBNET_SECOND_OCTET}.${SUBNET_THIRD_OCTET}.0/24" +# Clean up any existing network with this name +docker network rm ${DOCKER_NETWORK_NAME} 2>/dev/null echo "Selected DOCKER_NETWORK_NAME: ${DOCKER_NETWORK_NAME}" -echo "Selected DOCKER_NETWORK_SUBNET: ${DOCKER_NETWORK_SUBNET}" - -# Test function for subnet calculation -test_subnet_calculation() { - local test_slot_id=$1 - local expected_second_octet=$2 - local expected_third_octet=$3 - - SLOT_ID=$test_slot_id - SUBNET_SECOND_OCTET=$((16 + (SLOT_ID / 256) % 240)) - SUBNET_THIRD_OCTET=$((SLOT_ID % 256)) - SUBNET="172.${SUBNET_SECOND_OCTET}.${SUBNET_THIRD_OCTET}.0/24" - - if [ $SUBNET_SECOND_OCTET -eq $expected_second_octet ] && - [ $SUBNET_THIRD_OCTET -eq $expected_third_octet ]; then - echo "Test passed for SLOT_ID $test_slot_id: $SUBNET" - else - echo "Test failed for SLOT_ID $test_slot_id: Expected 172.$expected_second_octet.$expected_third_octet.0/24, got $SUBNET" - fi -} - -# Run tests -echo "Running subnet calculation tests..." -test_subnet_calculation 1 16 0 -test_subnet_calculation 255 16 0 -test_subnet_calculation 256 16 1 -test_subnet_calculation 1000 16 3 -test_subnet_calculation 10000 16 39 -test_subnet_calculation 65535 16 255 -test_subnet_calculation 65536 17 0 -test_subnet_calculation 100000 17 134 -test_subnet_calculation 1048575 31 255 -test_subnet_calculation 1048576 16 0 - -# Add this line to run tests before the main script logic -[ "$1" = "--test" ] && exit 0 + if [ -z "$OVERRIDE_DEFAULTS" ]; then echo "setting default values..."; diff --git a/docker-compose.yaml b/docker-compose.yaml index 61c3438..097eed8 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -94,4 +94,5 @@ networks: driver: bridge ipam: config: - - subnet: ${DOCKER_NETWORK_SUBNET} \ No newline at end of file + - subnet: 10.0.0.0/8 + gateway: 10.0.0.1 \ No newline at end of file diff --git a/snapshotter/tests/test_docker_subnets.py b/snapshotter/tests/test_docker_subnets.py deleted file mode 100644 index f3ee11b..0000000 --- a/snapshotter/tests/test_docker_subnets.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python3 - -import time - -def calculate_subnet(slot_id): - second_octet = 16 + (slot_id // 256) % 240 - third_octet = slot_id % 256 - return f"172.{second_octet}.{third_octet}.0/24" - -def test_unique_subnets(): - print("Testing unique subnet assignments for slot IDs 1 to 10000...") - - used_subnets = set() - collisions = 0 - - for slot_id in range(1, 10001): - subnet = calculate_subnet(slot_id) - - if subnet in used_subnets: - print(f"Collision detected: Slot ID {slot_id} maps to existing subnet {subnet}") - collisions += 1 - else: - used_subnets.add(subnet) - - if collisions == 0: - print("Test passed: All 10000 slot IDs have unique subnet assignments.") - else: - print(f"Test failed: {collisions} collisions detected.") - -if __name__ == "__main__": - start_time = time.time() - test_unique_subnets() - end_time = time.time() - print(f"Execution time: {end_time - start_time:.4f} seconds") \ No newline at end of file