Skip to content

Commit

Permalink
feat: add larger address space with internal class A IP addresses for…
Browse files Browse the repository at this point in the history
… docker network
  • Loading branch information
anomit committed Oct 10, 2024
1 parent b71b715 commit 9d3f604
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 75 deletions.
43 changes: 3 additions & 40 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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...";
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ networks:
driver: bridge
ipam:
config:
- subnet: ${DOCKER_NETWORK_SUBNET}
- subnet: 10.0.0.0/8
gateway: 10.0.0.1
34 changes: 0 additions & 34 deletions snapshotter/tests/test_docker_subnets.py

This file was deleted.

0 comments on commit 9d3f604

Please sign in to comment.