Developing lightweight computation at the DSG edge

Commit 25bdc3cc authored by p4u's avatar p4u
Browse files

Change the qMp id approach:

 before: last 8bit from MAC address
 now: crc16 from entire MAC address

In case community mode (qmp.node.roaming=0) if the LAN address does not exist
qMp autoconfiguration system generates an IP from this crc16 hash.

It reduces the IP colision and hostname probability.
parent 34877acd
...@@ -256,6 +256,17 @@ qmp_hooks_exec() { ...@@ -256,6 +256,17 @@ qmp_hooks_exec() {
# Other kind of commands # Other kind of commands
######################### #########################
# Returns the crc16 from the mac of the primary mac device
# If no parameter it returns the entire hash
# If parameter = 1 or 2, returns the first/second 8bit module 256
qmp_get_crc16() {
local mac="$(qmp_get_mac_for_dev $(qmp_uci_get node.primary_device))"
local crc16="$(lua /usr/bin/crc16 $mac)"
[ "$1" == "1" ] && echo -e "$crc16" | awk NR==2 && return
[ "$1" == "2" ] && echo -e "$crc16" | awk NR==3 && return
echo -e "$crc16" | awk NR==1
}
# Print the content of the parameters in reverse order (separed by spaces) # Print the content of the parameters in reverse order (separed by spaces)
qmp_reverse_order() { qmp_reverse_order() {
echo "$@" | awk '{for (i=NF; i>0; i--) printf("%s ",$i);print ""}' echo "$@" | awk '{for (i=NF; i>0; i--) printf("%s ",$i);print ""}'
......
...@@ -62,13 +62,18 @@ qmp_get_primary_device() { ...@@ -62,13 +62,18 @@ qmp_get_primary_device() {
echo "$primary_mesh_device" echo "$primary_mesh_device"
} }
# qmp_get_id [dec] # qmp_get_id [8bit]
qmp_get_id() { qmp_get_id() {
community_node_id="$(qmp_uci_get node.community_node_id)" local community_node_id="$(qmp_uci_get node.community_node_id)"
[ -z "$community_node_id" ] && \ [ -z "$community_node_id" ] && \
community_node_id="$(qmp_get_mac_for_dev $(qmp_get_primary_device) | awk -F':' '{print $6}' )" community_node_id="$(qmp_get_crc16)"
[ "$1" == "8bit" ] && echo "$(( 0x$community_node_id % 0x100 ))" || echo "$community_node_id"
}
[ "$1" == "dec" ] && echo "$(( 0x$community_node_id % 0x100 ))" || echo "$community_node_id" # qmp_get_id_ip <1,2>
qmp_get_id_ip() {
[ "$1" == "1" ] && echo "$(qmp_get_crc16 1)"
[ "$1" == "2" ] && echo "$(qmp_get_crc16 2)"
} }
qmp_check_device() { qmp_check_device() {
...@@ -702,7 +707,7 @@ qmp_configure_lan() { ...@@ -702,7 +707,7 @@ qmp_configure_lan() {
local dns="$(qmp_uci_get networks.dns)" local dns="$(qmp_uci_get networks.dns)"
local lan_mask="$(qmp_uci_get networks.lan_netmask)" local lan_mask="$(qmp_uci_get networks.lan_netmask)"
local lan_addr="$(qmp_uci_get networks.lan_address)" local lan_addr="$(qmp_uci_get networks.lan_address)"
# If the lan address is empty in the configuration # If the lan address is empty in the configuration
[ -z "$lan_addr" ] && { [ -z "$lan_addr" ] && {
[ $(qmp_uci_get roaming.ignore) -eq 0 ] && { [ $(qmp_uci_get roaming.ignore) -eq 0 ] && {
...@@ -710,7 +715,7 @@ qmp_configure_lan() { ...@@ -710,7 +715,7 @@ qmp_configure_lan() {
lan_mask="255.255.0.0" lan_mask="255.255.0.0"
qmp_log No LAN ip address configured, roaming mode enabled, autoconfiguring $lan_addr/$lan_mask qmp_log No LAN ip address configured, roaming mode enabled, autoconfiguring $lan_addr/$lan_mask
} || { } || {
lan_addr="10.0.$(qmp_get_id dec).1" lan_addr="10.$(qmp_get_id_ip 1).$(qmp_get_id_ip 2).1"
lan_mask="255.255.255.0" lan_mask="255.255.255.0"
qmp_uci_set networks.bmx6_ipv4_address $lan_addr/24 qmp_uci_set networks.bmx6_ipv4_address $lan_addr/24
qmp_log No LAN ip address configured, community mode enabled, autoconfiguring $lan_addr/$lan_mask qmp_log No LAN ip address configured, community mode enabled, autoconfiguring $lan_addr/$lan_mask
...@@ -1005,7 +1010,7 @@ qmp_configure_bmx6() { ...@@ -1005,7 +1010,7 @@ qmp_configure_bmx6() {
uci set $conf.tmain.tun4Address="$bmx6_ipv4_address/$bmx6_ipv4_netmask" uci set $conf.tmain.tun4Address="$bmx6_ipv4_address/$bmx6_ipv4_netmask"
else else
local ipv4_suffix24="$(qmp_get_id dec)" local ipv4_suffix24="$(qmp_get_id 8bit)"
local ipv4_prefix24="$(qmp_uci_get networks.bmx6_ipv4_prefix24)" local ipv4_prefix24="$(qmp_uci_get networks.bmx6_ipv4_prefix24)"
if [ $(echo -n "$ipv4_prefix24" | tr -d [0-9] | wc -c) -lt 2 ]; then if [ $(echo -n "$ipv4_prefix24" | tr -d [0-9] | wc -c) -lt 2 ]; then
ipv4_prefix24="${ipv4_prefix24}.0" ipv4_prefix24="${ipv4_prefix24}.0"
...@@ -1168,7 +1173,7 @@ qmp_configure_system() { ...@@ -1168,7 +1173,7 @@ qmp_configure_system() {
local community_node_id=$(qmp_get_id) local community_node_id=$(qmp_get_id)
qmp_uci_set node.community_node_id $community_node_id qmp_uci_set node.community_node_id $community_node_id
fi fi
local community_id="$(qmp_uci_get node.community_id)" local community_id="$(qmp_uci_get node.community_id)"
[ -z "$community_id" ] && community_id="qmp" && qmp_uci_set node.community_id $community_id [ -z "$community_id" ] && community_id="qmp" && qmp_uci_set node.community_id $community_id
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment