Skip to content

Commit

Permalink
Fix visualisation for multiradio
Browse files Browse the repository at this point in the history
Jira-Id: SCDI-43

Signed-off-by: Mika Joenpera <[email protected]>
  • Loading branch information
joenpera committed Oct 20, 2023
1 parent d236204 commit 4d5f1a0
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 213 deletions.
84 changes: 48 additions & 36 deletions common/scripts/mesh-11s_nats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ add_network_intf_to_bridge() {
}

fix_iface_mac_addresses() {
# handles the case when the mac address of the batman interface the same as the eth0.
# For batman interface, the mac address is set to 00:0Y:XX:XX:XX:XX by utilizing eth0 mac address.
# from 00:0Y:XX:XX:XX:XX Y is the batman interface index

# batman interface is bat0, take the last char for the numbering
batman_iface_index="$(echo "$batman_iface" | cut -b 4)"

#Create static mac addr for Batman if
eth0_mac="$(ip -brief link | grep eth0 | awk '{print $3; exit}')"
batif_mac="00:00:$(echo "$eth0_mac" | cut -b 7-17)"
batif_mac="00:0${batman_iface_index}:$(echo "$eth0_mac" | cut -b 7-17)"
ifconfig "$batman_iface" down
ifconfig "$batman_iface" hw ether "$batif_mac"
ifconfig "$batman_iface" up
Expand Down Expand Up @@ -165,10 +172,7 @@ network={
EOF

if [ "$routing_algo" == "batman-adv" ]; then
mesh_kill "[a]lfred -i $batman_iface -m"
mesh_kill "[b]atadv-vis -i $batman_iface -s"
rm -f /var/run/alfred.sock
#Check if batman_adv is built-in module
echo "batman-adv"
elif [ "$routing_algo" == "olsr" ]; then
mesh_kill "[o]lsrd -i $wifidev -d 0"
fi
Expand Down Expand Up @@ -214,8 +218,6 @@ EOF
if [ "$routing_algo" == "batman-adv" ]; then
batctl if add "$wifidev"
echo "$batman_iface up.."
# Create static mac addr for Batman if and br-lan
fix_iface_mac_addresses
ifconfig "$batman_iface" up
echo "$batman_iface ip address.."
ifconfig "$batman_iface" "$ipaddr" netmask "$nmask"
Expand All @@ -224,16 +226,6 @@ EOF
echo
ifconfig "$batman_iface"

# for visualisation
(alfred -i "$batman_iface" -m)&
echo "started alfred"

if ps aux | grep -q "[b]atadv-vis -i $batman_iface -s"; then
echo "batadv-vis is already running."
else
(batadv-vis -i "$batman_iface" -s) &
echo "batadv-vis started."
fi
elif [ "$routing_algo" == "olsr" ]; then
ifconfig "$wifidev" "$ipaddr" netmask "$nmask"
# Enable debug level as necessary
Expand All @@ -245,6 +237,25 @@ EOF
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"

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
(batadv-vis -i "$batman_iface" -s) &
echo "batadv-vis started."
fi
fi

# Add forwarding rules from AP to "$batman_iface" interface
iptables -P FORWARD ACCEPT
route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name"
Expand Down Expand Up @@ -295,10 +306,7 @@ network={
EOF

if [ "$routing_algo" == "batman-adv" ]; then
mesh_kill "[a]lfred -i $batman_iface -m"
mesh_kill "[b]atadv-vis -i $batman_iface -s"
rm -f /var/run/alfred.sock
#Check if batman_adv is built-in module
echo "batman-adv"
if [[ -d "/sys/module/batman_adv" ]]; then
modprobe batman-adv
fi
Expand Down Expand Up @@ -328,8 +336,6 @@ EOF
if [ "$routing_algo" == "batman-adv" ]; then
batctl if add "$wifidev"
echo "$batman_iface up.."
# Create static mac addr for Batman if and br-lan
fix_iface_mac_addresses
ifconfig "$batman_iface" up
echo "$batman_iface ip address.."
ifconfig "$batman_iface" "$ipaddr" netmask "$nmask"
Expand All @@ -338,18 +344,6 @@ EOF
echo
ifconfig "$batman_iface"

sleep 3

# for visualisation
(alfred -i "$batman_iface" -m)&
echo "started alfred"
if ps aux | grep -q "[b]atadv-vis -i $batman_iface -s"; then
echo "batadv-vis is already running."
else
(batadv-vis -i "$batman_iface" -s) &
echo "batadv-vis started."
fi

elif [ "$routing_algo" == "olsr" ]; then
ifconfig "$wifidev" "$ipaddr" netmask "$nmask"
# Enable debug level as necessary
Expand All @@ -364,6 +358,25 @@ EOF
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"

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
(batadv-vis -i "$batman_iface" -s) &
echo "batadv-vis started."
fi
fi

# Add forwarding rules from AP to "$batman_iface" interface
iptables -P FORWARD ACCEPT
route del -net "$network" gw 0.0.0.0 netmask "$nmask" dev "$bridge_name"
Expand Down Expand Up @@ -626,7 +639,6 @@ main () {
fi

calculate_network_address "$br_lan_ip" "$nmask"

mode_execute "$mode"
}

Expand Down
11 changes: 11 additions & 0 deletions modules/sc-mesh-secure-deployment/src/nats/initd/S9011sNatsMesh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ LOG_FILE=/opt/mesh_11s_${RADIO_INDEX}.log
[ -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

printf 'Starting %s: ' "$DAEMON"
if [ "${!_MODE}" == "ap+mesh_scc" ] || [ "${!_MODE}" == "ap+mesh_mcc" ]; then
mode=mesh
Expand All @@ -41,6 +49,9 @@ start() {
else
echo "FAIL"
fi

rm /var/run/nats.pid

return "$status"
}
stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "APPLY", "radio_index": "1"}
cmd_dict = {"api_version": 1, "cmd": "APPLY", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(
f"comms.command.{config.MODULE_IDENTITY}", cmd.encode(), timeout=10
f"comms.command.{config.MODULE_IDENTITY}", cmd.encode(), timeout=15
)
parameters = json.loads(rep.data)
print(json.dumps(parameters, indent=2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,62 @@ async def main():
nc = await client.connect_nats()
cmd_dict = {
"api_version": 1,
"role": f"{config.MODULE_ROLE}",
"role": f"{config.MODULE_ROLE}", # sleeve, drone, gcs
"radios": [
{
"radio_index": "0",
"ssid": "test_mesh",
"ssid": "test_mesh2",
"key": "1234567890",
"ap_mac": "00:11:22:33:44:55",
"country": "US",
"frequency": "5220",
"frequency_mcc": "2412",
"country": "US", # all radios must have the same country
"frequency": "2412",
"frequency_mcc": "2412", # multiradio not supporting
"routing": "batman-adv",
"priority": "long_range",
"ip": "192.168.1.2",
"ip": "10.20.15.3",
"subnet": "255.255.255.0",
"tx_power": "5",
"mode": "mesh",
"tx_power": "15",
"mode": "mesh", # ap+mesh_scc, mesh, halow
"mesh_vif": "wlp2s0",
"phy": "phy0",
"phy": "phy2", # TODO: NOT_USED
"batman_iface": "bat0",
},
{
"radio_index": "1",
"ssid": "test_mesh2",
"ssid": "test_mesh",
"key": "1234567890",
"ap_mac": "00:11:22:33:44:55",
"country": "US",
"frequency": "2412",
"frequency_mcc": "2412",
"country": "US", # all radios must have the same country
"frequency": "5220",
"frequency_mcc": "2412", # multiradio not supporting
"routing": "batman-adv",
"priority": "long_range",
"ip": "10.20.15.3",
"subnet": "255.255.255.0",
"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",
},
{
"radio_index": "2",
"ssid": "test_mesh3",
"key": "1234567890",
"ap_mac": "00:11:22:33:44:55",
"country": "US", # all radios must have the same country
"frequency": "5190",
"frequency_mcc": "2412", # multiradio not supporting
"routing": "batman-adv",
"priority": "long_range",
"ip": "192.168.1.2",
"ip": "10.20.15.3",
"subnet": "255.255.255.0",
"tx_power": "5",
"mode": "mesh",
"mesh_vif": "wlp3s0",
"phy": "phy2",
"tx_power": "30",
"mode": "halow", # ap+mesh_scc, mesh, halow
"mesh_vif": "halow1",
"phy": "phy2", # TODO: NOT_USED
"batman_iface": "bat0",
},
# {
# "radio_index": "2",
# "ssid": "test_mesh3",
# "key": "1234567890",
# "ap_mac": "00:11:22:33:44:55",
# "country": "US",
# "frequency": "5190",
# "frequency_mcc": "2412",
# "routing": "batman-adv",
# "priority": "long_range",
# "ip": "192.168.1.2",
# "subnet": "255.255.255.0",
# "tx_power": "5",
# "mode": "halow",
# "mesh_vif": "halow1",
# "phy": "phy2",
# "batman_iface": "bat0",
# },
],
"bridge": "br-lan bat0 eth1 lan1"
}
Expand Down
10 changes: 7 additions & 3 deletions modules/sc-mesh-secure-deployment/src/nats/src/batadvvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ class BatAdvVis:
"""
command = 'batadv-vis'

def __init__(self, loop_interval:float = 1.0):
def __init__(self, loop_interval:float = 1.0, batman_interface:str = "bat0" ):
"""
init method
"""
self.__batman_interface = batman_interface
self.latest_topology = "{}"
self.thread_running = False
self.interval = loop_interval
self.__interval = loop_interval

@staticmethod
def remove_interfaces(visual_lines):
Expand Down Expand Up @@ -77,7 +81,7 @@ def run(self):
self.thread_running = True
while self.thread_running:
self.latest_topology = self.get()
time.sleep(self.interval)
time.sleep(self.__interval)


# Real user is mesh_executor
Expand Down
Loading

0 comments on commit 4d5f1a0

Please sign in to comment.