testing gateway as a separate service
This commit is contained in:
parent
960a8e16e8
commit
cfa2485536
8
.env
8
.env
|
@ -1,6 +1,6 @@
|
||||||
# Base params
|
# Base params
|
||||||
BASE_SUBNET=6.6.6
|
BASE_SUBNET=6.6.6
|
||||||
XBEE_INDEX=1
|
XBEE_INDEX=2
|
||||||
|
|
||||||
# Default params
|
# Default params
|
||||||
DEFAULT_GATEWAY=6.6.6.1
|
DEFAULT_GATEWAY=6.6.6.1
|
||||||
|
@ -8,7 +8,7 @@ DEFAULT_IPVLAN_IP=6.6.6.20 # Required only when running ipvlan net (
|
||||||
DEFAULT_MACVLAN_IP=6.6.6.30 # Required only when running macvlan net (look in docker compose)
|
DEFAULT_MACVLAN_IP=6.6.6.30 # Required only when running macvlan net (look in docker compose)
|
||||||
|
|
||||||
# Configuration for xbnet
|
# Configuration for xbnet
|
||||||
XBEE_PORT=/dev/ttyUSB0
|
XBEE_PORT=/dev/ttyUSB1
|
||||||
XBEE_BAUDRATE=230400
|
XBEE_BAUDRATE=230400
|
||||||
XBEE_NET_SRC_IP=6.6.6.201 # Ensure this IP matches the network range
|
XBEE_NET_SRC_IP=6.6.6.202 # Set based on interface type
|
||||||
XBEE_NET_IFACE_NAME=xbnet1
|
XBEE_NET_IFACE_NAME=xbnet_router_2 # Set based on interface type
|
||||||
|
|
|
@ -68,14 +68,14 @@ services:
|
||||||
container_name: xbnet_node
|
container_name: xbnet_node
|
||||||
privileged: true
|
privileged: true
|
||||||
env_file: .env
|
env_file: .env
|
||||||
networks:
|
# networks:
|
||||||
xbee_net:
|
# xbee_net:
|
||||||
ipv4_address: ${XBEE_NET_SRC_IP} # Ensure this IP belongs to the xbee_net subnet
|
# ipv4_address: ${XBEE_NET_SRC_IP} # Ensure this IP belongs to the xbee_net subnet
|
||||||
|
|
||||||
networks:
|
# networks:
|
||||||
xbee_net:
|
# xbee_net:
|
||||||
driver: bridge
|
# driver: bridge
|
||||||
ipam:
|
# ipam:
|
||||||
config:
|
# config:
|
||||||
- subnet: ${BASE_SUBNET}.0/24 # Match the network's subnet
|
# - subnet: ${BASE_SUBNET}.0/24 # Match the network's subnet
|
||||||
gateway: ${DEFAULT_GATEWAY} # Gateway for central router
|
# gateway: ${DEFAULT_GATEWAY} # Gateway for central router
|
|
@ -1,32 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
# run-single.sh
|
# run-single.sh
|
||||||
#
|
#
|
||||||
# This script sets up the environment for running a Docker Compose configuration with XBee networks.
|
# This script sets up the environment for running a Docker Compose configuration with XBee networks.
|
||||||
# It accepts optional --index=<int>, --subnet=<subnet>, --serial-speed=<speed>, and --port=<port> arguments
|
# It accepts optional --index=<int>, --subnet=<subnet>, --serial-speed=<speed>, --port=<port>, and --interface-type=<type> arguments
|
||||||
# to specify the XBEE_INDEX, BASE_SUBNET, XBEE_BAUDRATE, and XBEE_PORT values.
|
# to specify the XBEE_INDEX, BASE_SUBNET, XBEE_BAUDRATE, XBEE_PORT, and XBEE_INTERFACE_TYPE values.
|
||||||
# If no index is provided, it defaults to 1. If no subnet is provided, it defaults to 192.168.1.
|
# If no index is provided, it defaults to 1. If no subnet is provided, it defaults to 192.168.1.
|
||||||
# If no serial-speed is provided, it defaults to 230400. If no port is provided, it defaults to /dev/ttyUSB0.
|
# If no serial-speed is provided, it defaults to 230400. If no port is provided, it defaults to /dev/ttyUSB0.
|
||||||
|
# If no interface-type is provided, it defaults to "router".
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./run-single.sh # Runs with default index (1), default subnet (192.168.1), default speed (230400), and default port (/dev/ttyUSB0)
|
# ./run-single.sh # Runs with default index (1), default subnet (192.168.1), default speed (230400), and default port (/dev/ttyUSB0)
|
||||||
# ./run-single.sh --index=2 # Runs with index 2 and default values for other options
|
# ./run-single.sh --index=2 # Runs with index 2 and default values for other options
|
||||||
# ./run-single.sh --subnet=192.168.50 # Runs with default index (1), specified subnet, and default values for other options
|
# ./run-single.sh --subnet=192.168.50 # Runs with default index (1), specified subnet, and default values for other options
|
||||||
# ./run-single.sh --index=3 --subnet=192.168.50 # Runs with specified index, specified subnet, and default values for speed and port
|
# ./run-single.sh --index=3 --subnet=192.168.50 # Runs with specified index, specified subnet, and default values for speed and port
|
||||||
# ./run-single.sh --serial-speed=115200 --port=/dev/ttyUSB1 # Runs with specified serial-speed and port with default values for other options
|
# ./run-single.sh --serial-speed=115200 --port=/dev/ttyUSB1 # Runs with specified serial-speed and port with default values for other options
|
||||||
|
# ./run-single.sh --interface-type=gateway # Runs with specified interface type as gateway
|
||||||
|
|
||||||
# IPs assigned:
|
# IPs assigned:
|
||||||
# BASE_SUBNET: eg.: 10.10.10
|
# BASE_SUBNET: eg.: 10.10.10
|
||||||
# DEFAULT_GATEWAY: ${BASE_SUBNET}.1, eg.: 10.10.10.1
|
# DEFAULT_GATEWAY: ${BASE_SUBNET}.1, eg.: 10.10.10.1
|
||||||
# DEFAULT_IPVLAN_IP: ${BASE_SUBNET}.20 eg.: 10.10.10.20
|
# DEFAULT_IPVLAN_IP: ${BASE_SUBNET}.20 eg.: 10.10.10.20
|
||||||
# DEFAULT_MACVLAN_IP: ${BASE_SUBNET}.30 eg.: 10.10.10.30
|
# DEFAULT_MACVLAN_IP: ${BASE_SUBNET}.30 eg.: 10.10.10.30
|
||||||
# XBEE_NET_SRC_IP: ${BASE_SUBNET}.20${index} eg.: 10.10.10.201 (all Xbnets will be in the 200+ range)
|
# XBEE_NET_SRC_IP: ${BASE_SUBNET}.20${INDEX} eg.: 10.10.10.201 (all Xbnets will be in the 200+ range)
|
||||||
|
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Default values
|
# Default values
|
||||||
INDEX=1
|
INDEX=1
|
||||||
BASE_SUBNET="10.10.10"
|
BASE_SUBNET="10.10.10"
|
||||||
XBEE_BAUDRATE=230400
|
XBEE_BAUDRATE=230400
|
||||||
XBEE_PORT="/dev/ttyUSB0"
|
XBEE_PORT="/dev/ttyUSB0"
|
||||||
|
XBEE_INTERFACE_TYPE="router" # Options: ["gateway", "router"]
|
||||||
|
|
||||||
# Parse command-line arguments
|
# Parse command-line arguments
|
||||||
for arg in "$@"
|
for arg in "$@"
|
||||||
|
@ -34,25 +37,38 @@ do
|
||||||
case $arg in
|
case $arg in
|
||||||
--index=*)
|
--index=*)
|
||||||
INDEX="${arg#*=}"
|
INDEX="${arg#*=}"
|
||||||
shift # Remove --index=<int> from processing
|
shift
|
||||||
;;
|
;;
|
||||||
--subnet=*)
|
--subnet=*)
|
||||||
BASE_SUBNET="${arg#*=}"
|
BASE_SUBNET="${arg#*=}"
|
||||||
shift # Remove --subnet=<subnet> from processing
|
shift
|
||||||
;;
|
;;
|
||||||
--serial-speed=*)
|
--serial-speed=*)
|
||||||
XBEE_BAUDRATE="${arg#*=}"
|
XBEE_BAUDRATE="${arg#*=}"
|
||||||
shift # Remove --serial-speed=<speed> from processing
|
shift
|
||||||
;;
|
;;
|
||||||
--port=*)
|
--port=*)
|
||||||
XBEE_PORT="${arg#*=}"
|
XBEE_PORT="${arg#*=}"
|
||||||
shift # Remove --port=<port> from processing
|
shift
|
||||||
|
;;
|
||||||
|
--interface-type=*)
|
||||||
|
XBEE_INTERFACE_TYPE="${arg#*=}"
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Determine the source IP based on interface type
|
||||||
|
if [ "$XBEE_INTERFACE_TYPE" = "gateway" ]; then
|
||||||
|
XBEE_NET_SRC_IP="${BASE_SUBNET}.1"
|
||||||
|
XBEE_NET_IFACE_NAME=xbnet_gateway
|
||||||
|
else
|
||||||
|
XBEE_NET_SRC_IP="${BASE_SUBNET}.20${INDEX}"
|
||||||
|
XBEE_NET_IFACE_NAME=xbnet_router_${INDEX}
|
||||||
|
fi
|
||||||
|
|
||||||
# Create a .env file with the specified parameters
|
# Create a .env file with the specified parameters
|
||||||
cat <<EOF > .env
|
cat <<EOF > .env
|
||||||
# Base params
|
# Base params
|
||||||
|
@ -67,8 +83,8 @@ DEFAULT_MACVLAN_IP=${BASE_SUBNET}.30 # Required only when running mac
|
||||||
# Configuration for xbnet
|
# Configuration for xbnet
|
||||||
XBEE_PORT=${XBEE_PORT}
|
XBEE_PORT=${XBEE_PORT}
|
||||||
XBEE_BAUDRATE=${XBEE_BAUDRATE}
|
XBEE_BAUDRATE=${XBEE_BAUDRATE}
|
||||||
XBEE_NET_SRC_IP=${BASE_SUBNET}.20${INDEX} # Ensure this IP matches the network range
|
XBEE_NET_SRC_IP=${XBEE_NET_SRC_IP} # Set based on interface type
|
||||||
XBEE_NET_IFACE_NAME=xbnet${INDEX}
|
XBEE_NET_IFACE_NAME=${XBEE_NET_IFACE_NAME} # Set based on interface type
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Restart Docker Compose services
|
# Restart Docker Compose services
|
||||||
|
|
|
@ -198,6 +198,8 @@ loop() {
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
sleep 0.5
|
||||||
|
|
||||||
# Check if the network interface is up
|
# Check if the network interface is up
|
||||||
check_network_state
|
check_network_state
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
@ -243,6 +245,12 @@ create_tap_interface() {
|
||||||
|
|
||||||
sudo ip addr add $XBEE_NET_SRC_IP/24 dev $XBEE_NET_IFACE_NAME
|
sudo ip addr add $XBEE_NET_SRC_IP/24 dev $XBEE_NET_IFACE_NAME
|
||||||
sudo ip link set $XBEE_NET_IFACE_NAME up
|
sudo ip link set $XBEE_NET_IFACE_NAME up
|
||||||
|
|
||||||
|
echo "Tap interface created."
|
||||||
|
echo "Name: ${XBEE_NET_IFACE_NAME}"
|
||||||
|
echo "IP: ${XBEE_NET_SRC_IP}"
|
||||||
|
echo "Device port: ${XBEE_PORT}"
|
||||||
|
echo "Device baudrate: ${XBEE_BAUDRATE}"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue