#!/bin/bash # set -xv # General part ------------------------------------------ source /opt/scripts/mesh/freq.sh # get center frequency of channel like this: ${chan2g["1"]} 'OR' ${chan5g["149"]} PHYNAME=$1 DEVNAME=$2 CHANNEL=${chan[$3]} POWER=$4 NOISEFLOOR=$5 phy_number="${1//[!0-9]/}" dev_number="${2//[!0-9]/}" devPath="/sys/class/net/" phyPath="/sys/kernel/debug/ieee80211/" Monitoring=0 MonNode="apu01" # get the hostname host_valid=0 nodename="$(uname -n)" echo "Hostname: $nodename" source /opt/scripts/mesh/node_addresses.sh ALLNODES=${neighbors["all"]} # apply TCP/UDP send/receive socket buffer (rmem/wmem) optimizations sysctl -w net.core.rmem_max=8388608 #-> 8MB sysctl -w net.core.wmem_max=8388608 #-> 8MB sysctl -w net.core.rmem_default=8388608 #-> 8MB sysctl -w net.core.wmem_default=8388608 #-> 8MB sysctl -w net.core.optmem_max=8388608 #-> 8MB sysctl -w net.ipv4.tcp_mem='8388608 8388608 8388608' #-> 8MB 8MB 8MB sysctl -w net.ipv4.tcp_rmem='4096 87380 8388608' #-> 4kB 85kB 8MB sysctl -w net.ipv4.tcp_wmem='4096 65536 8388608' #-> 4kB 64kB 8MB sysctl -w net.ipv4.udp_mem='8388608 8388608 8388608' #-> 8MB 8MB 8MB sysctl -w net.ipv4.udp_rmem_min=4096 #-> 4kB sysctl -w net.ipv4.udp_wmem_min=4096 #-> 4kB sysctl -w net.core.netdev_max_backlog=5000 sysctl -w net.ipv4.tcp_max_syn_backlog=5000 # TCP SYN/SYN-ACK timeout optimizations sysctl -w net.ipv4.tcp_syn_retries=9 # 9 instead of 6 ((0s) 3s 6s 12s 24s 48s 96s 192s 384s 768s -> total 1533s) sysctl -w net.ipv4.tcp_synack_retries=9 # 9 instead of 5 ((0s) 3s 6s 12s 24s 48s 96s 192s 384s 768s -> total 1533s) # deactivate TCP metrics history sysctl -w net.ipv4.tcp_no_metrics_save=1 # clear routing table cache sysctl -w net.ipv4.route.flush=1 # deactivate TCP CUBIC Hystart mechanism echo 0 > /sys/module/tcp_cubic/parameters/hystart echo 0 > /sys/module/tcp_cubic/parameters/hystart_detect # apply ARP cache optimizations sysctl -w net.ipv4.neigh.default.base_reachable_time_ms=1200000 #-> 30 min instead of 30 sec sysctl -w net.ipv4.neigh.default.mcast_solicit=25 #-> 25 instead of 3 multicast attempts sysctl -w net.ipv4.neigh.default.ucast_solicit=25 #-> 25 instead of 3 unicast attempts # check whether the phy exists if [ -e "$phyPath$PHYNAME" ]; then echo "$PHYNAME exists in $phyPath, going on ..." else echo "$PHYNAME do not exist in $phyPath, exit script ..." exit fi systemctl stop systemd-timesyncd.service # check whether the wanted DEVNAME already exists and remove it if [ -e "$devPath$DEVNAME" ]; then # if dev already exists number=$(iw dev "$DEVNAME" info | awk '$1 == "wiphy" {print $2}') echo "Removing existing device $DEVNAME from phy$number" ifconfig $DEVNAME down iw dev $DEVNAME del fi # get current dev on the specified phy # delete any dev on specified phy current_dev_on_phy=$(iw dev | awk -v phy="$phy_number" '$0 ~ "phy#"phy {getline; while ($1 ~ /^Interface/) {print $2; getline}}') if [ ! -z "$current_dev_on_phy" ]; then echo "Removing existing device $current_dev_on_phy from phy$phy_number" ifconfig $current_dev_on_phy down iw dev $current_dev_on_phy del fi # monitor node if [[ "$nodename" == "$MonNode" ]] && [[ $Monitoring -eq 1 ]]; then iw phy0 interface add mon0 type monitor ifconfig mon0 up fi # creating the new dev # mesh_id is set to DEVNAME so that in case of init both phys they are in different mesh`s echo "Creating new mesh device ${DEVNAME} on ${PHYNAME}" iw phy ${PHYNAME} interface add ${DEVNAME} type mp mesh_id ${DEVNAME} ifconfig ${DEVNAME} down # if interface was up iw dev ${DEVNAME} set type mp # set type mesh point iw phy ${PHYNAME} set antenna 3 3 # ath9k/AR9280: OK (TX=3 RX=3) iw phy ${PHYNAME} set retry short 7 long 4 # initialize adapter with default (re-)try limits iw phy ${PHYNAME} set rts off # deactivate RTS/CTS (default) # iw phy ${PHYNAME} set rts 500 # request to send (packet size threshold 500 octets/byte) # iw phy ${PHYNAME} set rts 9999999999 # request to send (packet size threshold 500 octets/byte) # iw phy ${PHYNAME} set retry short 7 long 4 # initialize adapter with default (re-)try limits iw dev ${DEVNAME} set mesh_param mesh_max_peer_links=50 iw dev ${DEVNAME} set power_save off # deactivate power saving mechanism ifconfig ${DEVNAME} up # set interface up iw dev ${DEVNAME} mesh leave iw dev ${DEVNAME} mesh join mesh freq ${CHANNEL} HT40+ basic-rates 54 mcast-rate 54 # iw dev mesh0 mesh join mesh freq 5745 HT40+ basic-rates 54 mcast-rate 54 iw dev ${DEVNAME} set txpower fixed $POWER # set tx power (300 eq 3dBm) # iw dev ${DEVNAME} set rtcts off if [[ $3 -lt 15 ]]; then # set coding scheme and guard interval (set short for 400ns) iw dev ${DEVNAME} set bitrates ht-mcs-2.4 6 sgi-2.4 else iw dev ${DEVNAME} set bitrates ht-mcs-5 6 sgi-5 fi echo 0 > /sys/kernel/debug/ieee80211/${PHYNAME}/ath9k/ani # set fixed noise floor in dBm echo ${NOISEFLOOR} > /sys/kernel/debug/ieee80211/${PHYNAME}/ath9k/nf_override #TODO: overwritten individually below # set mintsrel_ht to fixed rate # - station - # cat /sys/kernel/debug/ieee80211/phy0/netdev:mesh0/stations/04:f0:21:ac:31:bd/rc_stats echo 198 > /sys/kernel/debug/ieee80211/${PHYNAME}/rc/fixed_rate_idx # automatically remove inactive links from station list #iw dev ${DEVNAME} set mesh_param mesh_plink_timeout=20 # timeout in seconds # Node specific part ------------------------------------------ # # get the hostname # host_valid=0 # nodename="$(uname -n)" # echo "Hostname: $nodename" # source /opt/scripts/mesh/node_addresses.sh # ALLNODES=${neighbors["all"]} # check wheather hostname is valid while [[ host_valid -eq 0 ]]; do for i in $ALLNODES; do if [[ $nodename == $i ]]; then host_valid=1 echo "Hostname $nodename is valid" break fi done if [[ host_valid -eq 0 ]]; then sleep 1 nodename="$(uname -n)" fi done # removing all IPs from dev ip addr flush dev ${DEVNAME} # get the dev corresponding IP if [[ "$dev_number" -eq 0 ]]; then NODE_MESH_IP=${phy0IP["$nodename"]} BROADCAST_IP=${phy0IP["broadcast"]} fi if [[ "$dev_number" -eq 1 ]]; then NODE_MESH_IP=${phy1IP["$nodename"]} BROADCAST_IP=${phy1IP["broadcast"]} fi echo "The node mesh ip is: $NODE_MESH_IP" ip -4 addr add ${NODE_MESH_IP}/24 broadcast $BROADCAST_IP dev ${DEVNAME} source /opt/scripts/mesh/block_peer_links.sh set +x