Skip to content

Commit

Permalink
Merge pull request #332 from tiiuae/feature/mptcp_v1
Browse files Browse the repository at this point in the history
Include comms.setting support for MPTCP.
  • Loading branch information
govindsi authored Nov 14, 2023
2 parents 6d9c7ef + f6ef9f4 commit 839e2fd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 57 deletions.
111 changes: 65 additions & 46 deletions common/scripts/mesh-11s_nats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ fix_iface_mac_addresses() {
ifconfig "$batman_iface" down
ifconfig "$batman_iface" hw ether "$batif_mac"
ifconfig "$batman_iface" up
ifconfig "$bridge_name" down
ifconfig "$bridge_name" hw ether "$eth0_mac"
ifconfig "$bridge_name" up
if [[ -n $bridge_name ]]; then
ifconfig "$bridge_name" down
ifconfig "$bridge_name" hw ether "$eth0_mac"
ifconfig "$bridge_name" up
fi
}

calculate_network_address() {
Expand Down Expand Up @@ -234,7 +236,7 @@ EOF
sleep 1

if [ "$routing_algo" == "batman-adv" ]; then
batctl if add "$wifidev"
batctl meshif $batman_iface if add "$wifidev"
echo "$batman_iface up.."
ifconfig "$batman_iface" up
echo "$batman_iface ip address.."
Expand All @@ -243,20 +245,28 @@ EOF
ifconfig "$batman_iface" mtu 1460
echo
ifconfig "$batman_iface"
if [[ -n $bridge_name ]]; then
add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces"
ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask"
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"
# 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"
route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name"
iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT
iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE
sleep 5
fi
fix_iface_mac_addresses

elif [ "$routing_algo" == "olsr" ]; then
ifconfig "$wifidev" "$ipaddr" netmask "$nmask"
# Enable debug level as necessary
(olsrd -i "$wifidev" -d 0)&
fi

add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces"
ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask"
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"
fix_iface_mac_addresses

if [ "$routing_algo" == "batman-adv" ]; then
sleep 3
# for visualisation
Expand All @@ -268,15 +278,6 @@ EOF
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"
route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name"
iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT
iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE

sleep 5

# Radio parameters
echo "set radio parameters"
# /usr/local/bin/cli_app set txpwr fixed 23
Expand Down Expand Up @@ -349,7 +350,7 @@ EOF
ip link set "$wifidev" up

if [ "$routing_algo" == "batman-adv" ]; then
batctl if add "$wifidev"
batctl meshif $batman_iface if add "$wifidev"
echo "$batman_iface up.."
ifconfig "$batman_iface" up
echo "$batman_iface ip address.."
Expand All @@ -358,7 +359,21 @@ EOF
ifconfig "$batman_iface" mtu 1460
echo
ifconfig "$batman_iface"

if [[ -n $bridge_name ]]; then
add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces"
ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask"
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"
# 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"
route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name"
iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT
iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE
sleep 5
fi
fix_iface_mac_addresses
elif [ "$routing_algo" == "olsr" ]; then
ifconfig "$wifidev" "$ipaddr" netmask "$nmask"
# Enable debug level as necessary
Expand All @@ -368,13 +383,6 @@ EOF
# Radio parameters
iw dev "$wifidev" set txpower limit "$txpwr"00

add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces"
ifconfig "$bridge_name" "$bridge_ip" netmask "$nmask"
ifconfig "$bridge_name" up
echo
ifconfig "$bridge_name"
fix_iface_mac_addresses

if [ "$routing_algo" == "batman-adv" ]; then
sleep 3
# for visualisation
Expand All @@ -385,14 +393,6 @@ EOF
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"
route add -net "$network" gw "$bridge_ip" netmask "$nmask" dev "$bridge_name"
iptables -A FORWARD --in-interface "$batman_iface" -j ACCEPT
iptables --table nat -A POSTROUTING --out-interface "$bridge_ip" -j MASQUERADE

wpa_supplicant -i "$wifidev" -c /var/run/wpa_supplicant-11s_"$INDEX".conf -D nl80211 -C /var/run/wpa_supplicant_"$INDEX"/ -f /tmp/wpa_supplicant_11s_"$INDEX".log
;;
"ap+mesh_mcc")
Expand Down Expand Up @@ -563,10 +563,6 @@ main () {
# id0_PRIORITY=long_range
# BRIDGE="br-mesh eth1 eth0 lan1"
# ROLE=drone
generate_lan_bridge_ip
# to get bridge_ip warning free
bridge_ip=$bridge_ip

find_ethernet_port
# to get eth_port warning free
eth_port=$eth_port
Expand Down Expand Up @@ -623,7 +619,10 @@ main () {
batman_iface="${!_batman_iface}"

_mptcp="${INDEX}_MPTCP"
mptcp="${!_mptcp}" # enable disable
mptcp="${!_mptcp}"

_bridge="${INDEX}_BRIDGE"
bridge="${!_bridge}"

# shellcheck disable=SC2153
# shellcheck disable=SC2034
Expand All @@ -639,8 +638,8 @@ main () {
fi

# e.g. BRIDGE=br-mesh eth0 eth1 lan1
bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1)
bridge_interfaces=$(echo "$BRIDGE" | cut -d' ' -f2-)
bridge_name=$(echo "$bridge" | cut -d' ' -f1)
bridge_interfaces=$(echo "$bridge" | cut -d' ' -f2-)

if brctl show "$bridge_name" &>/dev/null; then
echo "Bridge $bridge_name already exists."
Expand All @@ -649,9 +648,29 @@ main () {
brctl addbr "$bridge_name" 2>/dev/null
echo "Bridge $bridge_name created."
fi

calculate_network_address "$bridge_ip" "$nmask"
if [[ -n "$bridge_name" ]]; then
generate_lan_bridge_ip
# to get bridge_ip warning free
bridge_ip=$bridge_ip
calculate_network_address "$bridge_ip" "$nmask"
fi
if [ $mptcp == "enable" ]; then
echo "MPTCP enabled"
if ! [ -f /var/run/mptcp.conf ]; then
echo "SUBFLOWS=0" > /var/run/mptcp.conf
fi
if [[ -n $bridge_name ]]; then
source /var/run/mptcp.conf
echo "BRIDGE_IFACE=${bridge_name}" >> /var/run/mptcp.conf
else
source /opt/mptcp.conf
sed -i "s/$SUBFLOWS/$((SUBFLOWS + 1))/" /var/run/mptcp.conf
source /var/run/mptcp.conf
echo "INTERFACE_${SUBFLOWS}=${batman_iface}" >> /var/run/mptcp.conf
fi
fi
mode_execute "$mode"

}

main "$@"
2 changes: 1 addition & 1 deletion common/scripts/mesh-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EOF
generate_lan_bridge_ip() {
local mesh_if_mac

bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1)
bridge_name=$(echo "$bridge" | cut -d' ' -f1)

mesh_if_mac=$(cat /sys/class/net/"$id0_MESH_VIF"/address)
if [ -z "$mesh_if_mac" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def main():
"mode": "mesh", # ap+mesh_scc, mesh, halow
"mesh_vif": "wlp2s0",
"batman_iface": "bat0",
"bridge": "br-lan bat0 eth1 lan1 eth0 usb0",
},
{
"radio_index": "1",
Expand All @@ -46,6 +47,7 @@ async def main():
"mode": "mesh", # ap+mesh_scc, mesh, halow
"mesh_vif": "wlp3s0", # this needs to be correct
"batman_iface": "bat0",
"bridge": "br-lan bat0 eth1 lan1 eth0 usb0",
},
{
"radio_index": "2",
Expand All @@ -64,9 +66,9 @@ async def main():
"mode": "halow", # ap+mesh_scc, mesh, halow
"mesh_vif": "halow1",
"batman_iface": "bat0",
"bridge": "br-lan bat0 eth1 lan1 eth0 usb0",
},
],
"bridge": "br-lan bat0 eth1 lan1 eth0 usb0",
}

cmd = json.dumps(cmd_dict)
Expand Down
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 @@ -39,11 +39,11 @@ def __init__(self, comms_status: [cs.CommsStatus, ...], logger):
self.routing: [str, ...] = []
self.priority: [str, ...] = []
self.role: str = ""
self.mesh_vif: [str, ...] = []
self.mptcp: [str, ...] = []
self.mesh_vif = []
self.mptcp = []
# self.phy = []
self.batman_iface: [str, ...] = []
self.bridge: str = ""
self.batman_iface = []
self.bridge = []
self.msversion: str = ""
self.delay: str = "" # delay for channel change
self.comms_status = comms_status
Expand Down Expand Up @@ -146,6 +146,7 @@ def __clean_all_settings(self) -> None:
self.mptcp: [str, ...] = []
# self.phy = []
self.batman_iface: [str, ...] = []
self.bridge: [str, ...] = []

def handle_mesh_settings_channel_change(
self, msg: str, path="/opt", file="mesh_stored.conf"
Expand Down Expand Up @@ -244,8 +245,7 @@ def handle_mesh_settings(
self.mptcp.append(quote(str(parameters["mptcp"])))
# self.phy.append(quote(str(parameters["phy"])))
self.batman_iface.append(quote(str(parameters["batman_iface"])))

self.bridge = quote(str(parameters_set["bridge"]))
self.bridge.append(str(parameters["bridge"]))

for index in self.radio_index:
self.logger.debug("Mesh settings validation index: %s", str(index))
Expand Down Expand Up @@ -341,7 +341,7 @@ def __save_settings(self, path: str, file: str, index: int) -> (str, str):
mesh_conf.write(
f"id{str(index)}_BATMAN_IFACE={quote(self.batman_iface[index])}\n"
)
mesh_conf.write(f"BRIDGE={self.bridge}\n")
mesh_conf.write(f"id{str(index)}_BRIDGE={quote(self.bridge[index])}\n")

except:
self.comms_status[index].mesh_cfg_status = comms.STATUS.mesh_cfg_not_stored
Expand Down Expand Up @@ -393,13 +393,13 @@ def __read_configs(self, mesh_conf_lines) -> None:
# self.phy.append(match[1])
elif name == "BATMAN_IFACE":
self.batman_iface.append(match[1])
elif name == "BRIDGE":
self.bridge.append(match[1])
else:
self.logger.error("unknown config parameter: %s", name)
else: # global config without index
if match[0] == "MSVERSION":
self.msversion = match[1]
elif match[0] == "BRIDGE":
self.bridge = match[1]
elif match[0] == "ROLE":
self.role = match[1]
else:
Expand Down
Empty file modified modules/sc-mesh-secure-deployment/src/nats/src/validation.py
100644 → 100755
Empty file.

0 comments on commit 839e2fd

Please sign in to comment.