working base

This commit is contained in:
Michal Humpula
2025-03-16 10:20:48 +01:00
parent 0ddf5f1c36
commit 5fbd72b370
19 changed files with 3261 additions and 0 deletions

53
scripts/setup-router.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/sh
set -e
ROUTER_TYPE="$1"
echo "Setting up $ROUTER_TYPE router..."
# fix dns
echo "nameserver 192.168.10.1" > /etc/resolv.conf
apk add --no-cache iputils iptables
# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -w net.ipv4.ip_forward=1
if [ "$ROUTER_TYPE" = "primary" ]; then
echo "Configuring PRIMARY router (192.168.200.11 192.168.202.11 172.17.0.2)"
ip addr show
echo "Routes:"
ip route show
# NAT for traffic from primary network to target network
iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -d 192.168.202.0/24 -j MASQUERADE
iptables -P FORWARD ACCEPT
elif [ "$ROUTER_TYPE" = "secondary" ]; then
echo "Configuring SECONDARY router (192.168.201.11 ↔ 192.168.202.12 ↔ 172.17.0.3)"
ip addr show
echo "Routes:"
ip route show
# NAT for traffic from secondary network to target network
iptables -t nat -A POSTROUTING -s 192.168.201.0/24 -d 192.168.202.0/24 -j MASQUERADE
iptables -P FORWARD ACCEPT
else
echo "Error: Invalid router type. Use 'primary' or 'secondary'"
exit 1
fi
echo "Secondary router setup complete"
echo "NAT rules:"
iptables -t nat -L POSTROUTING -n -v
# Keep container running
echo "Router is running. Monitoring interfaces..."
while true; do
echo "$(date): Router $ROUTER_TYPE status - interfaces up"
sleep 60
done

118
scripts/test-failover.sh Executable file
View File

@@ -0,0 +1,118 @@
#!/bin/bash
set -e
echo "=== Route-Switcher Failover Test Script ==="
echo
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if podman-compose is available
if ! command -v podman-compose &> /dev/null; then
print_error "podman-compose is not installed or not in PATH"
exit 1
fi
# Start the environment
print_status "Starting test environment..."
podman-compose up -d
# Wait for containers to be ready
print_status "Waiting for containers to initialize..."
sleep 10
# Check if all containers are running
print_status "Checking container status..."
podman-compose ps
# Set up initial default route for route-switcher (testing scenario only)
# In production, this would be configured by the network admin
print_status "Setting up initial default route via primary router..."
podman-compose exec route-switcher ip route add default via 192.168.200.11 dev eth0
# Verify network connectivity
print_status "Testing initial connectivity..."
# Test from route-switcher to target (should use default route via primary)
print_status "Testing connectivity via primary router..."
podman-compose exec route-switcher ping -c 3 192.168.202.100 || {
print_error "Primary connectivity test failed"
podman-compose down
exit 1
}
# Test specific interface connectivity
print_status "Testing connectivity via secondary interface..."
podman-compose exec route-switcher ping -c 3 -I eth1 192.168.202.100 || {
print_warning "Secondary interface connectivity test failed (might be expected initially)"
}
print_status "Initial connectivity tests passed!"
# Show current routing table
print_status "Current routing table in route-switcher:"
podman-compose exec route-switcher ip route show
echo
print_warning "=== Starting Failover Test ==="
print_status "Monitoring route-switcher logs (press Ctrl+C to stop monitoring)..."
echo
# Start monitoring logs in background
podman-compose logs -f route-switcher &
LOGS_PID=$!
# Wait a bit for initial logs
sleep 5
print_status "Simulating primary router failure by shutting down eth0..."
podman-compose exec primary-router ip link set eth0 down
print_status "Waiting for failover to occur..."
sleep 15
# Check if failover happened
print_status "Checking routing table after primary failure..."
podman-compose exec route-switcher ip route show
print_status "Testing connectivity after failover..."
podman-compose exec route-switcher ping -c 3 192.168.202.100 || {
print_warning "Connectivity test after failover failed (this might be expected during transition)"
}
print_status "Restoring primary router..."
podman-compose exec primary-router ip link set eth0 up
print_status "Waiting for failback (should take ~60 seconds of stable connection)..."
sleep 70
print_status "Final routing table check:"
podman-compose exec route-switcher ip route show
print_status "Final connectivity test:"
podman-compose exec route-switcher ping -c 3 192.168.202.100
# Stop monitoring logs
kill $LOGS_PID 2>/dev/null || true
echo
print_status "=== Test Complete ==="
print_status "To stop the environment: podman-compose down"
print_status "To view logs: podman-compose logs route-switcher"

35
scripts/verify-setup.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -e
echo "=== Quick Setup Verification ==="
# Start containers
echo "Starting containers..."
podman-compose up -d
# Wait for initialization
echo "Waiting for containers..."
sleep 10
# Check status
echo "Container status:"
podman-compose ps
# Set up initial route
echo "Setting up initial default route..."
podman-compose exec route-switcher ip route add default via 192.168.200.11 dev eth0
# Show routing table
echo "Route-switcher routing table:"
podman-compose exec route-switcher ip route show
# Test basic connectivity
echo "Testing connectivity to target..."
if podman-compose exec route-switcher ping -c 2 192.168.202.100; then
echo "✓ Connectivity test passed"
else
echo "✗ Connectivity test failed"
fi
echo "Setup complete. Use './scripts/test-failover.sh' for full failover testing."