Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions local/system.json.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"network": {
"device_intf": "enx123456789123",
"internet_intf": "enx123456789124"
},
"log_level": "INFO",
"startup_timeout": 60,
"monitor_period": 300,
"runtime": 1200
{
"network": {
"device_intf": "enx123456789123",
"internet_intf": "enx123456789124"
},
"log_level": "INFO",
"startup_timeout": 60,
"monitor_period": 300,
"runtime": 1200
}
4 changes: 4 additions & 0 deletions modules/network/base/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ FROM ubuntu:jammy

ARG MODULE_NAME=base
ARG MODULE_DIR=modules/network/$MODULE_NAME
ARG COMMON_DIR=framework/python/src/common

# Install common software
RUN apt-get update && apt-get install -y net-tools iputils-ping tcpdump iproute2 jq python3 python3-pip dos2unix

# Install common python modules
COPY $COMMON_DIR/ /testrun/python/src/common

# Setup the base python requirements
COPY $MODULE_DIR/python /testrun/python

Expand Down
25 changes: 25 additions & 0 deletions modules/network/base/bin/setup_python_path
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

ROOT_DIRECTORY="/testrun/python/src"

# Function to recursively add subdirectories to PYTHONPATH
add_subdirectories_to_pythonpath() {
local directory=$1
local subdirectories=( "$directory"/* )
local subdirectory

for subdirectory in "${subdirectories[@]}"; do
if [[ -d "$subdirectory" && ! "$subdirectory" = *'__pycache__' ]]; then
export PYTHONPATH="$PYTHONPATH:$subdirectory"
add_subdirectories_to_pythonpath "$subdirectory"
fi
done
}

# Set PYTHONPATH initially to an empty string
export PYTHONPATH="$ROOT_DIRECTORY"

# Add all subdirectories to PYTHONPATH
add_subdirectories_to_pythonpath "$ROOT_DIRECTORY"

echo "$PYTHONPATH"
6 changes: 3 additions & 3 deletions modules/network/base/bin/start_grpc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

GRPC_DIR="/testrun/python/src/grpc"
GRPC_DIR="/testrun/python/src/grpc_server"
GRPC_PROTO_DIR="proto"
GRPC_PROTO_FILE="grpc.proto"

#Move into the grpc directory
pushd $GRPC_DIR >/dev/null 2>&1

#Build the grpc proto file every time before starting server
python3 -m grpc_tools.protoc --proto_path=. ./$GRPC_PROTO_DIR/$GRPC_PROTO_FILE --python_out=. --grpc_python_out=.
python3 -u -m grpc_tools.protoc --proto_path=. ./$GRPC_PROTO_DIR/$GRPC_PROTO_FILE --python_out=. --grpc_python_out=.

popd >/dev/null 2>&1

#Start the grpc server
python3 -u $GRPC_DIR/start_server.py $@
python3 -u $GRPC_DIR/start_server.py $@ &

12 changes: 9 additions & 3 deletions modules/network/base/bin/start_module
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ else
INTF=$DEFINED_IFACE
fi

echo "Starting module $MODULE_NAME on local interface $INTF..."
# Setup the PYTHONPATH so all imports work as expected
echo "Setting up PYTHONPATH..."
export PYTHONPATH=$($BIN_DIR/setup_python_path)
echo "PYTHONPATH: $PYTHONPATH"

echo "Configuring binary files..."
$BIN_DIR/setup_binaries $BIN_DIR

echo "Starting module $MODULE_NAME on local interface $INTF..."

# Wait for interface to become ready
$BIN_DIR/wait_for_interface $INTF

Expand All @@ -80,9 +86,9 @@ then
if [[ ! -z $GRPC_PORT && ! $GRPC_PORT == "null" ]]
then
echo "gRPC port resolved from config: $GRPC_PORT"
$BIN_DIR/start_grpc "-p $GRPC_PORT" &
$BIN_DIR/start_grpc "-p $GRPC_PORT"
else
$BIN_DIR/start_grpc &
$BIN_DIR/start_grpc
fi
fi

Expand Down
3 changes: 2 additions & 1 deletion modules/network/base/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
grpcio
grpcio-tools
grpcio-tools
netifaces
2 changes: 1 addition & 1 deletion modules/network/base/python/src/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
log_level = logging.getLevelName(log_level_str)
except OSError:
# TODO: Print out warning that log level is incorrect or missing
LOG_LEVEL = _DEFAULT_LEVEL
log_level = _DEFAULT_LEVEL

log_format = logging.Formatter(fmt=_LOG_FORMAT, datefmt=_DATE_FORMAT)

Expand Down
55 changes: 55 additions & 0 deletions modules/network/dhcp-1/bin/radvd-service
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

RA_PID_FILE=/var/run/radvd/radvd.pid
RA_LOG_FILE=/runtime/network/dhcp1-radvd.log

stop_radvd(){
# Directly kill by PID file reference
if [ -f "$RA_PID_FILE" ]; then
kill -9 $(cat $RA_PID_FILE) || true
rm -f $RA_PID_FILE
fi
}

start_radvd(){
/usr/sbin/radvd -m logfile -l $RA_LOG_FILE -p $RA_PID_FILE
}

case "$1" in
start)
start_radvd
;;
stop)
stop_radvd
;;
restart)
stop_radvd
sleep 1
start_radvd
;;
status)
if [ -f "$RA_PID_FILE" ]; then
echo "radvd service is running."
else
echo "radvd service is not running."
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
58 changes: 9 additions & 49 deletions modules/network/dhcp-1/bin/start_network_service
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DHCP_LOG_FILE=/runtime/network/dhcp1-dhcpd.log
RA_PID_FILE=/var/run/radvd/radvd.pid
RA_LOG_FILE=/runtime/network/dhcp1-radvd.log

echo "Starrting Network Service..."
echo "Starting Network Service..."

#Enable IPv6 Forwarding
sysctl net.ipv6.conf.all.forwarding=1
Expand All @@ -29,63 +29,23 @@ sysctl -p
# Create leases file if needed
touch /var/lib/dhcp/dhcpd.leases

#Create directory for radvd
# Create directory for radvd
mkdir /var/run/radvd

#Create and set permissions on the log files
# Create and set permissions on the log files
touch $DHCP_LOG_FILE
touch $RA_LOG_FILE
chown $HOST_USER $DHCP_LOG_FILE
chown $HOST_USER $RA_LOG_FILE


#Move the config files to the correct location
# Move the config files to the correct location
cp /testrun/conf/isc-dhcp-server /etc/default/
cp /testrun/conf/dhcpd.conf /etc/dhcp/dhcpd.conf
cp /testrun/conf/radvd.conf /etc/radvd.conf

# Restart dhcp server when config changes
while true; do
# Move the radvd-sevice file to the correct location
cp /testrun/bin/radvd-service /usr/local/bin/

new_checksum=$(md5sum $CONFIG_FILE)

if [ "$checksum" == "$new_checksum" ]; then
sleep 2
continue
fi

echo Config changed. Restarting dhcp server at $(date)..

if [ -f $DHCP_PID_FILE ]; then
kill -9 $(cat $DHCP_PID_FILE) || true
rm -f $DHCP_PID_FILE
fi

if [ -f $RA_PID_FILE ]; then
kill -9 $(cat $RA_PID_FILE) || true
rm -f $RA_PID_FILE
fi

checksum=$new_checksum

echo Starting isc-dhcp-server at $(date)

radvd -m logfile -l $RA_LOG_FILE -p $RA_PID_FILE
dhcpd -d &> $DHCP_LOG_FILE &

while [ ! -f $DHCP_PID_FILE ]; do
echo Waiting for $DHCP_PID_FILE...
sleep 2
done

echo $DHCP_PID_FILE now available

while [ ! -f $RA_PID_FILE ]; do
echo Waiting for $RA_PID_FILE...
sleep 2
done

echo $RA_PID_FILE now available

echo Server now stable

done
# Start the DHCP Server
python3 -u /testrun/python/src/grpc_server/dhcp_server.py
54 changes: 28 additions & 26 deletions modules/network/dhcp-1/conf/dhcpd.conf
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
default-lease-time 300;

failover peer "failover-peer" {
primary;
address 10.10.10.2;
port 847;
peer address 10.10.10.3;
peer port 647;
max-response-delay 60;
max-unacked-updates 10;
mclt 3600;
split 128;
load balance max seconds 3;
}

subnet 10.10.10.0 netmask 255.255.255.0 {
option ntp-servers 10.10.10.5;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.10.255;
option routers 10.10.10.1;
option domain-name-servers 10.10.10.4;
pool {
failover peer "failover-peer";
range 10.10.10.10 10.10.10.20;
}
}
default-lease-time 300;

failover peer "failover-peer" {
primary;
address 10.10.10.2;
port 847;
peer address 10.10.10.3;
peer port 647;
max-response-delay 60;
max-unacked-updates 10;
mclt 3600;
split 128;
load balance max seconds 3;
}

subnet 10.10.10.0 netmask 255.255.255.0 {
option ntp-servers 10.10.10.5;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.10.255;
option routers 10.10.10.1;
option domain-name-servers 10.10.10.4;
interface veth0;
authoritative;
pool {
failover peer "failover-peer";
range 10.10.10.10 10.10.10.20;
}
}
4 changes: 4 additions & 0 deletions modules/network/dhcp-1/conf/isc-dhcp-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="veth0"
#INTERFACESv6="veth0"
10 changes: 8 additions & 2 deletions modules/network/dhcp-1/dhcp-1.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ FROM test-run/base:latest
ARG MODULE_NAME=dhcp-1
ARG MODULE_DIR=modules/network/$MODULE_NAME

# Install all necessary packages
RUN apt-get install -y wget

#Update the oui.txt file from ieee
RUN wget http://standards-oui.ieee.org/oui.txt -P /usr/local/etc/

# Install dhcp server
RUN apt-get install -y isc-dhcp-server radvd
RUN apt-get install -y isc-dhcp-server radvd systemd

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf
Expand All @@ -28,4 +34,4 @@ COPY $MODULE_DIR/conf /testrun/conf
COPY $MODULE_DIR/bin /testrun/bin

# Copy over all python files
COPY $MODULE_DIR/python /testrun/python
COPY $MODULE_DIR/python /testrun/python
Loading