Skip to content

Commit

Permalink
Fix visualisation and remove phy from config
Browse files Browse the repository at this point in the history
- Alfred now start with own init.d
- all configs done with based on the wifi interface name and
  phy is detected.

Jira-Id: SCDI-43

Signed-off-by: Mika Joenpera <[email protected]>
  • Loading branch information
joenpera committed Oct 23, 2023
1 parent 4d5f1a0 commit 010138e
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 158 deletions.
25 changes: 11 additions & 14 deletions common/scripts/mesh-11s_nats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ add_network_intf_to_bridge() {
_bridge_name=$1
_interfaces=$2

_lan1=0
if [[ "$_interfaces" == *"lan1"* ]]; then
_lan1=1
fi
# Loop through the interface names and add them to the bridge if available
for _interface in $_interfaces; do
# Check if the interface exists
Expand All @@ -48,6 +52,11 @@ add_network_intf_to_bridge() {
echo "Interface $_interface not found. Skipping."
fi
done

if [ "$_lan1" -eq 1 ]; then
# Add lan1 to bridge
brctl delif "$_bridge_name" eth0 2>/dev/null
fi
}

fix_iface_mac_addresses() {
Expand Down Expand Up @@ -237,17 +246,11 @@ EOF
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"
fix_iface_mac_addresses

if [ "$routing_algo" == "batman-adv" ]; then
sleep 3
# for visualisation
if ps aux | grep -q "[a]lfred -i $bridge_name -m"; then
echo "alfred is already running."
else
(alfred -i "$bridge_name" -m)&
echo "started alfred"
fi

if ps aux | grep -q "[b]atadv-vis -i $batman_iface -s"; then
echo "batadv-vis is already running."
else
Expand Down Expand Up @@ -358,17 +361,11 @@ EOF
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"
fix_iface_mac_addresses

if [ "$routing_algo" == "batman-adv" ]; then
sleep 3
# for visualisation
if ps aux | grep -q "[a]lfred -i $bridge_name -m"; then
echo "alfred is already running."
else
(alfred -i "$bridge_name" -m)&
echo "started alfred"
fi

if ps aux | grep -q "[b]atadv-vis -i $batman_iface -s"; then
echo "batadv-vis is already running."
else
Expand Down
22 changes: 14 additions & 8 deletions modules/sc-mesh-secure-deployment/src/nats/initd/S9011sNatsMesh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ _MODE="${RADIO_INDEX}_MODE"
PIDFILE="/var/run/${DAEMON}_${RADIO_INDEX}.pid"
LOG_FILE=/opt/mesh_11s_${RADIO_INDEX}.log

SYNC_LOCK="/var/run/mesh_start.lock"

# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"

start() {

while [ -f "/var/run/nats.pid" ]; do
random_number=$(( (RANDOM % 5) + 1 ))
sleep $random_number
done

echo $$ > /var/run/nats.pid
if mkdir $SYNC_LOCK 2>/dev/null; then
echo "I have a lock $RADIO_INDEX PID $$"
else
echo "Instance is already running. Waiting..."
# Wait for the lock directory to be removed, indicating the previous instance finished
while [ -d "$SYNC_LOCK" ]; do
sleep $(( (RANDOM % 5) + 1 ))
done
mkdir "$SYNC_LOCK"
echo "I have a lock $$"
fi

printf 'Starting %s: ' "$DAEMON"
if [ "${!_MODE}" == "ap+mesh_scc" ] || [ "${!_MODE}" == "ap+mesh_mcc" ]; then
Expand All @@ -50,7 +56,7 @@ start() {
echo "FAIL"
fi

rm /var/run/nats.pid
rmdir "$SYNC_LOCK"

return "$status"
}
Expand Down
70 changes: 70 additions & 0 deletions modules/sc-mesh-secure-deployment/src/nats/initd/S90Alfred
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: S90Alfred
# Short-Description: alfred
# Description: Starts alfred to provide visualization data
### END INIT INFO

DAEMON="alfred"
DIR="/usr/bin/"
PIDFILE="/var/run/$DAEMON.pid"
# shellcheck source=/dev/null
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
LOG_FILE=/opt/alfred.log

source /opt/mesh-helper.sh
# sources mesh configuration
source_configuration "id0"
bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1)

ARGS="-i $bridge_name -m"

wait_for_bridge() {
while [ ! -d "/sys/class/net/$bridge_name" ]; do
sleep 1
done
}

start() {
echo "$ARGS"
printf 'Starting %s: ' "$DAEMON"
start-stop-daemon -b -m -S -q -p "$PIDFILE" -a /bin/bash -- -c "exec $DIR$DAEMON \
$ARGS > $LOG_FILE 2>&1"
status=$?
if [ "$status" -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
return "$status"
}
stop() {
printf 'Stopping %s: ' "$DAEMON"
start-stop-daemon -K -q -p "$PIDFILE"
status=$?
if [ "$status" -eq 0 ]; then
rm -f "$PIDFILE"
echo "OK"
else
echo "FAIL"
fi
return "$status"
}
restart() {
stop
sleep 1
start
}
case "$1" in
start|stop|restart)
"$1";;
reload)
# Restart, since there is no true "reload" feature.
restart;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac

exit 0

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cryptography==3.4.8
PyKCS11==1.5.11
requests==2.31.0
pycryptodome==3.18.0
pycryptodome==3.18.0
nats-py==2.1.7
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async def main():
"tx_power": "15",
"mode": "mesh", # ap+mesh_scc, mesh, halow
"mesh_vif": "wlp2s0",
"phy": "phy2", # TODO: NOT_USED
"batman_iface": "bat0",
},
{
Expand All @@ -43,7 +42,6 @@ async def main():
"tx_power": "15",
"mode": "mesh", # ap+mesh_scc, mesh, halow
"mesh_vif": "wlp3s0", # this needs to be correct
"phy": "phy0", # TODO: NOT_USED
"batman_iface": "bat0",
},
{
Expand All @@ -61,11 +59,10 @@ async def main():
"tx_power": "30",
"mode": "halow", # ap+mesh_scc, mesh, halow
"mesh_vif": "halow1",
"phy": "phy2", # TODO: NOT_USED
"batman_iface": "bat0",
},
],
"bridge": "br-lan bat0 eth1 lan1"
"bridge": "br-lan bat0 eth1 lan1 eth0 usb0"
}

cmd = json.dumps(cmd_dict)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 9 additions & 9 deletions modules/sc-mesh-secure-deployment/src/nats/src/comms_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, comms_status: [cs.CommsStatus, ...], logger):
self.priority = []
self.role: str = ""
self.mesh_vif = []
self.phy = []
# self.phy = []
self.batman_iface = []
self.bridge: str = ""
self.msversion: str = ""
Expand Down Expand Up @@ -110,9 +110,9 @@ def validate_mesh_settings(self, index: int) -> (str, str):
return "FAIL", "Invalid mesh vif"
self.logger.debug("validate mesh settings mesh vif ok")

if validation.validate_phy(self.phy[index]) is False:
return "FAIL", "Invalid phy"
self.logger.debug("validate mesh settings phy ok")
# if validation.validate_phy(self.phy[index]) is False:
# return "FAIL", "Invalid phy"
# self.logger.debug("validate mesh settings phy ok")

if validation.validate_batman_iface(self.batman_iface[index]) is False:
return "FAIL", "Invalid batman iface"
Expand All @@ -138,7 +138,7 @@ def __clean_all_settings(self) -> None:
self.routing = []
self.priority = []
self.mesh_vif = []
self.phy = []
# self.phy = []
self.batman_iface = []

def handle_mesh_settings(self, msg: str, path="/opt",
Expand Down Expand Up @@ -173,7 +173,7 @@ def handle_mesh_settings(self, msg: str, path="/opt",
self.routing.append(quote(str(parameters["routing"])))
self.priority.append(quote(str(parameters["priority"])))
self.mesh_vif.append(quote(str(parameters["mesh_vif"])))
self.phy.append(quote(str(parameters["phy"])))
# self.phy.append(quote(str(parameters["phy"])))
self.batman_iface.append(quote(str(parameters["batman_iface"])))

self.bridge = quote(str(parameters_set["bridge"]))
Expand Down Expand Up @@ -223,7 +223,7 @@ def __save_settings(self, path: str, file: str, index: int) -> (str, str):
mesh_conf.write(f"id{str(index)}_ROUTING={quote(self.routing[index])}\n")
mesh_conf.write(f"id{str(index)}_PRIORITY={quote(self.priority[index])}\n")
mesh_conf.write(f"id{str(index)}_MESH_VIF={quote(self.mesh_vif[index])}\n")
mesh_conf.write(f"id{str(index)}_PHY={quote(self.phy[index])}\n")
# mesh_conf.write(f"id{str(index)}_PHY={quote(self.phy[index])}\n")
mesh_conf.write(f"id{str(index)}_BATMAN_IFACE={quote(self.batman_iface[index])}\n")
mesh_conf.write(f"BRIDGE={self.bridge}\n")

Expand Down Expand Up @@ -272,8 +272,8 @@ def __read_configs(self, mesh_conf_lines) -> None:
self.priority.append(match[1])
elif name == "MESH_VIF":
self.mesh_vif.append(match[1])
elif name == "PHY":
self.phy.append(match[1])
# elif name == "PHY":
# self.phy.append(match[1])
elif name == "BATMAN_IFACE":
self.batman_iface.append(match[1])
else:
Expand Down
Loading

0 comments on commit 010138e

Please sign in to comment.