Kommunikationsprotokoll
Router fragt neuer nach Adresse "asknew MAC" -> Alle antworten "usethis ASSIGNER MAC IP" ---> Router nutzt die erste msg die rein ploppt [Filter]
Router fragt ob er Adresse noch nutzen darf "canusethis MAC ASSIGNER IP" -> Vergeber antwortet "MAC ack ASSIGNER IP" --> Router nutzt Adresse weiter [Prüfscript] (dies muss alle 5 Minuten erledigt werden)
-> Vergeber antwortet "MAC nack ASSIGNER IP" --> Router frag neuer nach Adresse (Line 1)
-> Vergeber antwortet gar nicht --> Router frag neuer nach Adresse (Line 1)
Vergeber gibt Adresse frei wenn kein "canusethis" mehr kommt, er kann frei entscheiden wann er sie freigeben will, es sollte jedoch mindestens 1h sein um nicht ständig neue Adressen durch kurze Downtimes zu triggern (bei genug Adressen auch gerne deutlich mehr).
MAC => eindeutige Identifikation des Routers ASSIGNER => eindeutige Identifikation des mqtt Clients der IP Adressen vergibt
[Prüfscript] Prüfscript ob die Adresse funktioniert: Sie funktioniert: -> Vote positiv Sie funktioniert nicht -> Vote negativ --> Router frag neuer nach Adresse (Line 1)
[Filter] - Frage alle /ipv6/vote ab, mehr negativ als positiv filter out (mosquitto_sub -T '/ipv6/usethis/#/$ASSIGNER') - Manueller Filter für User (mosquitto_sub -T '/ipv6/usethis/#/$ASSIGNER') $ASSIGNER IST USERINPUT
/ipv6/asknew $MAC
/ipv6/usethis/$MAC/$ASSIGNER (wir brauchen $ASSIGNER da oben für [Filter]) { "assigner":"$ASSIGNER", "ip":"$IP" }
/ipv6/canusethis/$ASSIGNER { "mac":"$MAC", "ip":"$IP" }
/ipv6/canusethisanswer/$MAC ack
/ipv6/vote/$MACADDR/$ASSIGNER (retain) ack/nack
/etc/config/autol3 config ipv6 option ipv6 'ADRESSE' option assigner 'ASSIGNER
- !/bin/sh
. /usr/share/libubox/jshn.sh
MACADDR=$(cat /sys/class/net/br-mesh/address | /bin/sed 's/://g') MQTTSERVER=$(uci -q get mqtt.mqtt.server) ASSIGNEROWN=$(uci -q get fff.autol3.assigner) IPOWN=$(uci -q get fff.autol3.address) asknew() {
mosquitto_pub -h $MQTTSERVER -p 1883 -t '/ipv6/asknew' -m "$MACADDR" # use the first income message # cancel after 5 second, after this time we don't get any IP address autol3config=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t '/ipv6/usethis/#' -C 1) if [ -z "$autol3config" ] ; then echo "No IP get" exit 1; fi json_load "$autol3config" json_get_var assigner assigner json_get_var ip ip uci set fff.autol3.address=$ip uci set fff.autol3.assigner=$assigner uci commit fff uci del gateway.@client[0].ip6addr uci add_list gateway.@client[0].ip6addr=$ip uci commit gateway yes | configure-layer3 -c configure-layer3 -a exit;
}
canusethis() {
mosquitto_pub -h "$(uci get mqtt.mqtt.server)" -p 1883 -t /ipv6/canusethis/$ASSIGNEROWN -m "{ \"mac\":\"$MACADDR\", \"ip\":\"$IPOWN\" }" canusethisanswer=$(mosquitto_sub -h $MQTTSERVER -p 1883 -t /ipv6/canusethisanswer/$MACADDR -C 1 -W 5) # check if we get answer, if no load asknew again and get new ip address if [ -z $canusethisanswer ] ; then uci del fff.autol3.address uci del fff.autol3.assigner uci commit fff asknew fi
}
if [ -z $(uci -q get fff.autol3) ] ; then
uci set fff.autol3=autol3
fi
if [ -n $(uci -q get fff.autol3) ] && [ -z $(uci -q get fff.autol3.address) ] ; then
asknew
fi
if [ -n $(uci -q get fff.autol3.address) ] ; then
canusethis
fi
[{"id":"5905c477.c0bfcc","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3cea78ba.466448","type":"sqlitedb","db":"/root/sqlite","mode":"RWC"},{"id":"17130a36.eafe1e","type":"mqtt-broker","name":"","broker":"2a01:4f8:221:2d08::130","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"27a8556d.f51752","type":"sqlite","z":"5905c477.c0bfcc","mydb":"3cea78ba.466448","sqlquery":"fixed","sql":"select * from ipv6 ORDER BY last_set LIMIT 1;","name":"test","x":530,"y":40,"wires":"c2fe7d64.a45378","1d41dec2.696c31"},{"id":"a65b7940.cc5438","type":"mqtt in","z":"5905c477.c0bfcc","name":"","topic":"/ipv6/asknew","qos":"2","datatype":"auto","broker":"17130a36.eafe1e","x":90,"y":40,"wires":"98854e2b.ff3ae"},{"id":"98854e2b.ff3ae","type":"change","z":"5905c477.c0bfcc","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"mac","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":40,"wires":"27a8556d.f51752"},{"id":"5914e7a6.6b61a","type":"mqtt out","z":"5905c477.c0bfcc","name":"","topic":"","qos":"","retain":"","broker":"17130a36.eafe1e","x":1270,"y":40,"wires":[]},{"id":"c2fe7d64.a45378","type":"function","z":"5905c477.c0bfcc","name":"","func":"msg.topic=\"/ipv6/usethis/\"+ msg.mac +\"/ChrisD1\"\nmsg.payload=\"{ \\\"assigner\\\": \\\"ChrisD1\\\", \\\"ip\\\": \\\"\" + msg.payload[0].ipv6 + \"\\\"}\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":40,"wires":"6eed601e.6d4d7"},{"id":"1d41dec2.696c31","type":"function","z":"5905c477.c0bfcc","name":"","func":"msg.payload=msg.payload[0].ipv6\nmsg.topic=\"UPDATE ipv6 SET last_set='\"+ Date.now() +\"', mac='\"+ msg.mac +\"' WHERE ipv6 = '\"+ msg.payload +\"';\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":140,"wires":"1d7b1791.8dc45"},{"id":"1d7b1791.8dc45","type":"sqlite","z":"5905c477.c0bfcc","mydb":"3cea78ba.466448","sqlquery":"msg.topic","sql":"","name":"write","x":1010,"y":140,"wires":[[]]},{"id":"802fa4e1.f998f","type":"mqtt in","z":"5905c477.c0bfcc","name":"","topic":"/ipv6/canusethis/ChrisD1","qos":"2","datatype":"auto","broker":"17130a36.eafe1e","x":130,"y":320,"wires":"3ead3411.3d6a74"},{"id":"3ead3411.3d6a74","type":"json","z":"5905c477.c0bfcc","name":"","property":"payload","action":"obj","pretty":false,"x":310,"y":320,"wires":"2812b6bb.5bfd9a"},{"id":"2812b6bb.5bfd9a","type":"function","z":"5905c477.c0bfcc","name":"","func":"msg.topic=\"SELECT * from ipv6 WHERE ipv6 = '\"+ msg.payload.ip +\"' AND mac = '\"+ msg.payload.mac +\"';\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":320,"wires":"f2b38217.0b3de"},{"id":"f2b38217.0b3de","type":"sqlite","z":"5905c477.c0bfcc","mydb":"3cea78ba.466448","sqlquery":"msg.topic","sql":"","name":"test","x":570,"y":320,"wires":"28b95a6c.c80396"},{"id":"28b95a6c.c80396","type":"switch","z":"5905c477.c0bfcc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":690,"y":320,"wires":"26b03c02.afa4f4","fea954bb.f8a04"},{"id":"3a8da02c.14941","type":"mqtt out","z":"5905c477.c0bfcc","name":"","topic":"","qos":"","retain":"","broker":"17130a36.eafe1e","x":1330,"y":320,"wires":[]},{"id":"26b03c02.afa4f4","type":"function","z":"5905c477.c0bfcc","name":"","func":"msg.topic=\"/ipv6/canusethisanswer/\"+ msg.payload[0].mac\nmsg.payload=\"ack\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":920,"y":320,"wires":"1e92a158.a32f7f"},{"id":"fea954bb.f8a04","type":"function","z":"5905c477.c0bfcc","name":"","func":"msg.topic=\"UPDATE ipv6 SET last_set='\"+ Date.now() +\"' WHERE ipv6 = '\"+ msg.payload[0].ipv6 +\"' AND mac='\"+ msg.payload[0].mac +\"';\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1080,"y":400,"wires":"578d9c16.b401ac"},{"id":"578d9c16.b401ac","type":"sqlite","z":"5905c477.c0bfcc","mydb":"3cea78ba.466448","sqlquery":"msg.topic","sql":"","name":"write","x":1290,"y":400,"wires":[[]]},{"id":"6eed601e.6d4d7","type":"delay","z":"5905c477.c0bfcc","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":960,"y":40,"wires":"5914e7a6.6b61a"},{"id":"1e92a158.a32f7f","type":"delay","z":"5905c477.c0bfcc","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1120,"y":320,"wires":"3a8da02c.14941"}]