From e29093efecdfb1af06e450f8b567c107dcf9372d Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Fri, 30 Mar 2018 00:14:22 +0200 Subject: [PATCH 1/7] tests/09-ipv6: add tests for UIP_DS6_NBR_MULTI_IPV6_ADDRS feature --- tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc | 108 ++++++++++++++++++ tests/09-ipv6/code/Makefile | 4 + tests/09-ipv6/js/ping-test-lla-ula.js | 72 ++++++++++++ 6 files changed, 508 insertions(+) create mode 100644 tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc create mode 100644 tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc create mode 100644 tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc create mode 100644 tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc create mode 100644 tests/09-ipv6/js/ping-test-lla-ula.js diff --git a/tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc b/tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc new file mode 100644 index 000000000..66e2a8c9a --- /dev/null +++ b/tests/09-ipv6/09-ping-lla-ula-csma-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_CSMA=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc b/tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc new file mode 100644 index 000000000..e6957af28 --- /dev/null +++ b/tests/09-ipv6/10-ping-lla-ula-tsch-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_TSCH=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc b/tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc new file mode 100644 index 000000000..b95a1ff4b --- /dev/null +++ b/tests/09-ipv6/11-ping-lla-ula-csma-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_NBR_MULTI_IPV6_ADDRS=1 WITH_ULA=1 WITH_CSMA=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc b/tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc new file mode 100644 index 000000000..20f8a12ae --- /dev/null +++ b/tests/09-ipv6/12-ping-lla-ula-tsch-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_NBR_MULTI_IPV6_ADDRS=1 WITH_ULA=1 WITH_TSCH=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/code/Makefile b/tests/09-ipv6/code/Makefile index 2c910f1cd..d8f4cab55 100644 --- a/tests/09-ipv6/code/Makefile +++ b/tests/09-ipv6/code/Makefile @@ -28,6 +28,10 @@ ifeq ($(WITH_TSCH),1) CFLAGS += -DTSCH_CONF_DEFAULT_HOPPING_SEQUENCE=TSCH_HOPPING_SEQUENCE_1_1 endif +ifeq ($(WITH_NBR_MULTI_IPV6_ADDRS),1) + CFLAGS += -DUIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS=1 +endif + PLATFORM_ONLY = cooja TARGET = cooja diff --git a/tests/09-ipv6/js/ping-test-lla-ula.js b/tests/09-ipv6/js/ping-test-lla-ula.js new file mode 100644 index 000000000..c15dcbf15 --- /dev/null +++ b/tests/09-ipv6/js/ping-test-lla-ula.js @@ -0,0 +1,72 @@ +TIMEOUT(20000, log.testFailed()); + +dst_lla = "fe80::202:2:2:2"; +dst_ula = "fd00::202:2:2:2"; +dst_mac = "0002.0002.0002.0002"; +step = 0; +rpl_is_enabled = false; + +while(1) { + YIELD(); + log.log(time + " " + id + " "+ msg + "\n"); + + if(msg.contains("Node ID: ")) { + if(id == 1) { + write(sim.getMoteWithID(1), "rpl-set-root 1"); + } + step += 1; + } + + if(msg.contains("Setting as DAG root")) { + rpl_is_enabled = true; + } + + if(step == 2 && time > 15000000) { + write(sim.getMoteWithID(1), "ping " + dst_lla); + step += 1; + } + + if(step == 4 && time > 15000000) { + write(sim.getMoteWithID(1), "ping " + dst_ula); + step += 1; + } + + if(msg.contains("Received ping reply")) { + if(step == 3) { + step += 1; + } else { + step += 1; + write(sim.getMoteWithID(1), "ip-nbr"); + } + } + + if(step == 6 && rpl_is_enabled) { + /* when RPL is enabled, we skip examining ip-nbr results */ + log.testOK(); + } + + if(msg.contains("<->")) { + re = /-- | <-> |, router|, state /; + nc = msg.split(re); + ip_addr = nc[1]; + ll_addr = nc[2]; + is_router = nc[3]; + state = nc[4].trim(); + if(ll_addr == dst_mac && + state == "Reachable") { + if(step == 6 && ip_addr == dst_lla) { + step += 1; + } else if(step == 7 && ip_addr == dst_ula) { + log.testOK(); + } else { + /* unexpected case */ + log.testFailed(); + } + } else { + log.log(ip_addr + "\n"); + log.log(ll_addr + "\n"); + log.log(state + "\n"); + log.testFailed(); + } + } +} From 8ef5c8b8c68619f89ee14e7fae1f4ddb354c8863 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Sat, 31 Mar 2018 18:35:25 +0200 Subject: [PATCH 2/7] uip-ds6-nbr: make ds6_neighbors a local variable All the nbr_table API calls with ds6_neighbors are replaced with uip_ds6_nbr APIs accordingly. --- .../cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c | 5 +++-- .../zoul/orion/ip64-router/ip64-router.c | 5 +++-- examples/rpl-border-router/webserver/webserver.c | 5 +++-- os/net/ipv6/uip-ds6-nbr.c | 2 +- os/net/ipv6/uip-ds6-nbr.h | 2 -- os/net/routing/rpl-classic/rpl-dag.c | 6 +++--- os/net/routing/rpl-classic/rpl-nbr-policy.c | 10 +++++----- os/net/routing/rpl-classic/rpl.h | 2 +- os/net/routing/rpl-lite/rpl-nbr-policy.c | 8 ++++---- os/net/routing/rpl-lite/rpl-neighbor.c | 4 ++-- 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c index 287452bb3..101b6441b 100644 --- a/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c +++ b/examples/platform-specific/cc26x0-cc13x0/cc26x0-web-demo/httpd-simple.c @@ -38,6 +38,7 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "httpd-simple.h" +#include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-ds6-route.h" #include "batmon-sensor.h" #include "lib/sensors.h" @@ -436,8 +437,8 @@ PT_THREAD(generate_index(struct httpd_state *s)) PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, SECTION_OPEN "Neighbors" CONTENT_OPEN)); - for(s->nbr = nbr_table_head(ds6_neighbors); s->nbr != NULL; - s->nbr = nbr_table_next(ds6_neighbors, s->nbr)) { + for(s->nbr = uip_ds6_nbr_head(); s->nbr != NULL; + s->nbr = uip_ds6_nbr_next(s->nbr)) { PT_WAIT_THREAD(&s->generate_pt, enqueue_chunk(s, 0, "\n")); diff --git a/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c b/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c index 5f2a98e24..4b3279e44 100644 --- a/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c +++ b/examples/platform-specific/zoul/orion/ip64-router/ip64-router.c @@ -45,6 +45,7 @@ #include "contiki-net.h" #include "net/ipv6/uip.h" #include "net/ipv6/uip-ds6.h" +#include "net/ipv6/uip-ds6-nbr.h" #include "net/routing/routing.h" #include "dev/leds.h" #include "ip64/ip64.h" @@ -142,9 +143,9 @@ PT_THREAD(generate_routes(struct httpd_state *s)) #endif ADD("Neighbors
");
 
-  for(nbr = nbr_table_head(ds6_neighbors);
+  for(nbr = uip_ds6_nbr_head();
       nbr != NULL;
-      nbr = nbr_table_next(ds6_neighbors, nbr)) {
+      nbr = uip_ds6_nbr_next(nbr)) {
 
 #if WEBSERVER_CONF_NEIGHBOR_STATUS
 #if BUF_USES_STACK
diff --git a/examples/rpl-border-router/webserver/webserver.c b/examples/rpl-border-router/webserver/webserver.c
index 3658381bf..c4b472837 100644
--- a/examples/rpl-border-router/webserver/webserver.c
+++ b/examples/rpl-border-router/webserver/webserver.c
@@ -32,6 +32,7 @@
 
 #include "contiki.h"
 #include "net/routing/routing.h"
+#include "net/ipv6/uip-ds6-nbr.h"
 #include "net/ipv6/uip-ds6-route.h"
 #include "net/ipv6/uip-sr.h"
 
@@ -90,9 +91,9 @@ PT_THREAD(generate_routes(struct httpd_state *s))
 
   ADD("  Neighbors\n  
    \n"); SEND(&s->sout); - for(nbr = nbr_table_head(ds6_neighbors); + for(nbr = uip_ds6_nbr_head(); nbr != NULL; - nbr = nbr_table_next(ds6_neighbors, nbr)) { + nbr = uip_ds6_nbr_next(nbr)) { ADD("
  • "); ipaddr_add(&nbr->ipaddr); ADD("
  • \n"); diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index f937986b5..619e9c347 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -60,7 +60,7 @@ #define LOG_MODULE "IPv6 Nbr" #define LOG_LEVEL LOG_LEVEL_IPV6 -NBR_TABLE_GLOBAL(uip_ds6_nbr_t, ds6_neighbors); +NBR_TABLE(uip_ds6_nbr_t, ds6_neighbors); /*---------------------------------------------------------------------------*/ void diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index d645ac627..4de17249c 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -63,8 +63,6 @@ #define NBR_DELAY 3 #define NBR_PROBE 4 -NBR_TABLE_DECLARE(ds6_neighbors); - /** \brief An entry in the nbr cache */ typedef struct uip_ds6_nbr { uip_ipaddr_t ipaddr; diff --git a/os/net/routing/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c index cbaee6959..58f758048 100644 --- a/os/net/routing/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -126,7 +126,7 @@ rpl_get_nbr(rpl_parent_t *parent) { const linkaddr_t *lladdr = rpl_get_parent_lladdr(parent); if(lladdr != NULL) { - return nbr_table_get_from_lladdr(ds6_neighbors, lladdr); + return uip_ds6_nbr_ll_lookup((const uip_lladdr_t *)lladdr); } else { return NULL; } @@ -145,9 +145,9 @@ rpl_dag_init(void) } /*---------------------------------------------------------------------------*/ rpl_parent_t * -rpl_get_parent(uip_lladdr_t *addr) +rpl_get_parent(const uip_lladdr_t *addr) { - rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (linkaddr_t *)addr); + rpl_parent_t *p = nbr_table_get_from_lladdr(rpl_parents, (const linkaddr_t *)addr); return p; } /*---------------------------------------------------------------------------*/ diff --git a/os/net/routing/rpl-classic/rpl-nbr-policy.c b/os/net/routing/rpl-classic/rpl-nbr-policy.c index 344840d0e..fc77ba5ed 100644 --- a/os/net/routing/rpl-classic/rpl-nbr-policy.c +++ b/os/net/routing/rpl-classic/rpl-nbr-policy.c @@ -70,7 +70,7 @@ static int num_parents; /* any node that are possible parents */ static int num_children; /* all children that we have as nexthop */ static int num_free; -static linkaddr_t *worst_rank_nbr; /* the parent that has the worst rank */ +static const linkaddr_t *worst_rank_nbr; /* the parent that has the worst rank */ static rpl_rank_t worst_rank; /*---------------------------------------------------------------------------*/ #if LOG_DBG_ENABLED @@ -112,9 +112,9 @@ update_nbr(void) num_parents = 0; num_children = 0; - nbr = nbr_table_head(ds6_neighbors); + nbr = uip_ds6_nbr_head(); while(nbr != NULL) { - linkaddr_t *lladdr = nbr_table_get_lladdr(ds6_neighbors, nbr); + const linkaddr_t *lladdr = (const linkaddr_t *)uip_ds6_nbr_get_ll(nbr); is_used = 0; /* @@ -127,7 +127,7 @@ update_nbr(void) num_children++; } - parent = rpl_get_parent((uip_lladdr_t *)lladdr); + parent = rpl_get_parent((const uip_lladdr_t *)lladdr); if(parent != NULL) { num_parents++; @@ -159,7 +159,7 @@ update_nbr(void) LOG_DBG_("\n"); } - nbr = nbr_table_next(ds6_neighbors, nbr); + nbr = uip_ds6_nbr_next(nbr); num_used++; } /* how many more IP neighbors can be have? */ diff --git a/os/net/routing/rpl-classic/rpl.h b/os/net/routing/rpl-classic/rpl.h index db87cc824..9777be6de 100644 --- a/os/net/routing/rpl-classic/rpl.h +++ b/os/net/routing/rpl-classic/rpl.h @@ -285,7 +285,7 @@ uint16_t rpl_get_parent_link_metric(rpl_parent_t *p); rpl_rank_t rpl_rank_via_parent(rpl_parent_t *p); const linkaddr_t *rpl_get_parent_lladdr(rpl_parent_t *p); uip_ipaddr_t *rpl_parent_get_ipaddr(rpl_parent_t *nbr); -rpl_parent_t *rpl_get_parent(uip_lladdr_t *addr); +rpl_parent_t *rpl_get_parent(const uip_lladdr_t *addr); rpl_rank_t rpl_get_parent_rank(uip_lladdr_t *addr); void rpl_dag_init(void); uip_ds6_nbr_t *rpl_get_nbr(rpl_parent_t *parent); diff --git a/os/net/routing/rpl-lite/rpl-nbr-policy.c b/os/net/routing/rpl-lite/rpl-nbr-policy.c index 9752b1446..e9d256eee 100644 --- a/os/net/routing/rpl-lite/rpl-nbr-policy.c +++ b/os/net/routing/rpl-lite/rpl-nbr-policy.c @@ -63,7 +63,7 @@ static int num_parents; /* all nodes that are possible parents */ static int num_free; -static linkaddr_t *worst_rank_nbr_lladdr; /* lladdr of the the neighbor with the worst rank */ +static const linkaddr_t *worst_rank_nbr_lladdr; /* lladdr of the the neighbor with the worst rank */ static rpl_rank_t worst_rank; /*---------------------------------------------------------------------------*/ @@ -79,10 +79,10 @@ update_state(void) worst_rank_nbr_lladdr = NULL; num_parents = 0; - ds6_nbr = nbr_table_head(ds6_neighbors); + ds6_nbr = uip_ds6_nbr_head(); while(ds6_nbr != NULL) { - linkaddr_t *nbr_lladdr = nbr_table_get_lladdr(ds6_neighbors, ds6_nbr); + const linkaddr_t *nbr_lladdr = (const linkaddr_t *)uip_ds6_nbr_get_ll(ds6_nbr); rpl_nbr = rpl_neighbor_get_from_lladdr((uip_lladdr_t *)nbr_lladdr); if(rpl_nbr != NULL && rpl_neighbor_is_parent(rpl_nbr)) { @@ -98,7 +98,7 @@ update_state(void) worst_rank_nbr_lladdr = nbr_lladdr; } - ds6_nbr = nbr_table_next(ds6_neighbors, ds6_nbr); + ds6_nbr = uip_ds6_nbr_next(ds6_nbr); num_used++; } /* how many more IP neighbors can be have? */ diff --git a/os/net/routing/rpl-lite/rpl-neighbor.c b/os/net/routing/rpl-lite/rpl-neighbor.c index a0f5d95b0..94a26fe75 100644 --- a/os/net/routing/rpl-lite/rpl-neighbor.c +++ b/os/net/routing/rpl-lite/rpl-neighbor.c @@ -181,9 +181,9 @@ rpl_neighbor_count(void) static uip_ds6_nbr_t * rpl_get_ds6_nbr(rpl_nbr_t *nbr) { - const linkaddr_t *lladdr = rpl_neighbor_get_lladdr(nbr); + const uip_lladdr_t *lladdr = (const uip_lladdr_t *)rpl_neighbor_get_lladdr(nbr); if(lladdr != NULL) { - return nbr_table_get_from_lladdr(ds6_neighbors, lladdr); + return uip_ds6_nbr_ll_lookup(lladdr); } else { return NULL; } From ee452b528753c5426355721e001510f4421696eb Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Sun, 1 Apr 2018 12:50:31 +0200 Subject: [PATCH 3/7] uip-ds6-nbr: introduce UIP_DS6_NBR_MULTI_IPV6_ADDRS This feature, which is disabled by default, extends the neighbor cache management in order to have multiple IPv6 address associated with a single link-layer address as neighbor caches. To use this feature, set 1 to UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES. --- os/net/ipv6/uip-ds6-nbr.c | 298 +++++++++++++++++++++++++++++++++++--- os/net/ipv6/uip-ds6-nbr.h | 28 ++++ 2 files changed, 303 insertions(+), 23 deletions(-) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index 619e9c347..f4404e8c8 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -55,19 +55,40 @@ #include "net/ipv6/uip-nd6.h" #include "net/routing/routing.h" +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +#include "lib/memb.h" +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "IPv6 Nbr" #define LOG_LEVEL LOG_LEVEL_IPV6 +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +static void add_uip_ds6_nbr_to_nbr_entry(uip_ds6_nbr_t *nbr, + uip_ds6_nbr_entry_t *nbr_entry); +static void remove_uip_ds6_nbr_from_nbr_entry(uip_ds6_nbr_t *nbr); +static void remove_nbr_entry(uip_ds6_nbr_entry_t *nbr_entry); +static void free_uip_ds6_nbr(uip_ds6_nbr_t *nbr); +static void callback_nbr_entry_removal(uip_ds6_nbr_entry_t *nbr_entry); +NBR_TABLE(uip_ds6_nbr_entry_t, uip_ds6_nbr_entries); +MEMB(uip_ds6_nbr_memb, uip_ds6_nbr_t, UIP_DS6_NBR_MAX_NEIGHBOR_CACHES); +#else NBR_TABLE(uip_ds6_nbr_t, ds6_neighbors); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ /*---------------------------------------------------------------------------*/ void uip_ds6_neighbors_init(void) { link_stats_init(); +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + memb_init(&uip_ds6_nbr_memb); + nbr_table_register(uip_ds6_nbr_entries, + (nbr_table_callback *)callback_nbr_entry_removal); +#else nbr_table_register(ds6_neighbors, (nbr_table_callback *)uip_ds6_nbr_rm); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * @@ -75,8 +96,44 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, uint8_t isrouter, uint8_t state, nbr_table_reason_t reason, void *data) { - uip_ds6_nbr_t *nbr = nbr_table_add_lladdr(ds6_neighbors, (linkaddr_t*)lladdr - , reason, data); + uip_ds6_nbr_t *nbr; + +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + + assert(uip_ds6_nbr_lookup(ipaddr) == NULL); + if(uip_ds6_nbr_lookup(ipaddr)) { + LOG_ERR("%s: uip_ds6_nbr for ", __func__); + LOG_ERR_6ADDR(ipaddr); + LOG_ERR_("has already existed\n"); + return NULL; + } + + nbr_entry = nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + (const linkaddr_t *)lladdr); + if(nbr_entry == NULL) { + if((nbr_entry = + nbr_table_add_lladdr(uip_ds6_nbr_entries, + (linkaddr_t*)lladdr, reason, data)) == NULL) { + LOG_ERR("%s: cannot allocate a new uip_ds6_nbr_entry\n", __func__); + return NULL; + } else { + LIST_STRUCT_INIT(nbr_entry, uip_ds6_nbrs); + } + } + + if((nbr = (uip_ds6_nbr_t *)memb_alloc(&uip_ds6_nbr_memb)) == NULL) { + LOG_ERR("%s: cannot allocate a new uip_ds6_nbr\n", __func__); + if(list_length(nbr_entry->uip_ds6_nbrs) == 0) { + nbr_table_remove(uip_ds6_nbr_entries, nbr_entry); + } + } else { + add_uip_ds6_nbr_to_nbr_entry(nbr, nbr_entry); + } +#else + nbr = nbr_table_add_lladdr(ds6_neighbors, (linkaddr_t*)lladdr, reason, data); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + if(nbr) { uip_ipaddr_copy(&nbr->ipaddr, ipaddr); #if UIP_ND6_SEND_RA || !UIP_CONF_ROUTER @@ -113,10 +170,91 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, } } +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +/*---------------------------------------------------------------------------*/ +static void +add_uip_ds6_nbr_to_nbr_entry(uip_ds6_nbr_t *nbr, + uip_ds6_nbr_entry_t *nbr_entry) +{ + LOG_DBG("%s: add nbr(%p) to nbr_entry (%p)\n", + __func__, nbr, nbr_entry); + nbr->nbr_entry = nbr_entry; + list_add(nbr_entry->uip_ds6_nbrs, nbr); +} +/*---------------------------------------------------------------------------*/ +static void +remove_uip_ds6_nbr_from_nbr_entry(uip_ds6_nbr_t *nbr) +{ + if(nbr == NULL) { + return; + } + LOG_DBG("%s: remove nbr(%p) from nbr_entry (%p)\n", + __func__, nbr, nbr->nbr_entry); + list_remove(nbr->nbr_entry->uip_ds6_nbrs, nbr); +} +/*---------------------------------------------------------------------------*/ +static void +remove_nbr_entry(uip_ds6_nbr_entry_t *nbr_entry) +{ + if(nbr_entry == NULL) { + return; + } + LOG_DBG("%s: remove nbr_entry (%p) from nbr_table\n", + __func__, nbr_entry); + (void)nbr_table_remove(uip_ds6_nbr_entries, nbr_entry); +} +/*---------------------------------------------------------------------------*/ +static void +free_uip_ds6_nbr(uip_ds6_nbr_t *nbr) +{ + if(nbr == NULL) { + return; + } +#if UIP_CONF_IPV6_QUEUE_PKT + uip_packetqueue_free(&nbr->packethandle); +#endif /* UIP_CONF_IPV6_QUEUE_PKT */ + NETSTACK_ROUTING.neighbor_state_changed(nbr); + assert(nbr->nbr_entry != NULL); + if(nbr->nbr_entry == NULL) { + LOG_ERR("%s: unexpected error nbr->nbr_entry is NULL\n", __func__); + } else { + remove_uip_ds6_nbr_from_nbr_entry(nbr); + if(list_length(nbr->nbr_entry->uip_ds6_nbrs) == 0) { + remove_nbr_entry(nbr->nbr_entry); + } + } + LOG_DBG("%s: free memory for nbr(%p)\n", __func__, nbr); + memb_free(&uip_ds6_nbr_memb, nbr); +} +/*---------------------------------------------------------------------------*/ +static void +callback_nbr_entry_removal(uip_ds6_nbr_entry_t *nbr_entry) +{ + uip_ds6_nbr_t *nbr; + uip_ds6_nbr_t *next_nbr; + if(nbr_entry == NULL) { + return; + } + for(nbr = (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); + nbr != NULL; + nbr = next_nbr) { + next_nbr = (uip_ds6_nbr_t *)list_item_next(nbr); + free_uip_ds6_nbr(nbr); + } +} +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ /*---------------------------------------------------------------------------*/ int uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + if(nbr == NULL) { + return 0; + } else { + free_uip_ds6_nbr(nbr); + return 1; + } +#else /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ if(nbr != NULL) { #if UIP_CONF_IPV6_QUEUE_PKT uip_packetqueue_free(&nbr->packethandle); @@ -125,19 +263,52 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr) return nbr_table_remove(ds6_neighbors, nbr); } return 0; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr_pp, const uip_lladdr_t *new_ll_addr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + uip_ds6_nbr_t *nbr; +#else uip_ds6_nbr_t nbr_backup; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ if(nbr_pp == NULL || new_ll_addr == NULL) { LOG_ERR("%s: invalid argument\n", __func__); return -1; } +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + + if((nbr_entry = + nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + (const linkaddr_t *)new_ll_addr)) == NULL) { + if((nbr_entry = + nbr_table_add_lladdr(uip_ds6_nbr_entries, + (const linkaddr_t*)new_ll_addr, + NBR_TABLE_REASON_IPV6_ND, NULL)) == NULL) { + LOG_ERR("%s: cannot allocate a nbr_entry for", __func__); + LOG_ERR_LLADDR((const linkaddr_t *)new_ll_addr); + return -1; + } else { + LIST_STRUCT_INIT(nbr_entry, uip_ds6_nbrs); + } + } + + nbr = *nbr_pp; + + remove_uip_ds6_nbr_from_nbr_entry(nbr); + if(list_length(nbr->nbr_entry->uip_ds6_nbrs) == 0) { + remove_nbr_entry(nbr->nbr_entry); + } + add_uip_ds6_nbr_to_nbr_entry(nbr, nbr_entry); + +#else /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + /* make sure new_ll_addr is not used in some other nbr */ if(uip_ds6_nbr_ll_lookup(new_ll_addr) != NULL) { LOG_ERR("%s: new_ll_addr, ", __func__); @@ -159,6 +330,7 @@ uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr_pp, const uip_lladdr_t *new_ll_addr) return -1; } memcpy(*nbr_pp, &nbr_backup, sizeof(uip_ds6_nbr_t)); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ return 0; } @@ -173,46 +345,88 @@ uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr) const uip_lladdr_t * uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + if(nbr == NULL) { + return NULL; + } + return (const uip_lladdr_t *)nbr_table_get_lladdr(uip_ds6_nbr_entries, + nbr->nbr_entry); +#else return (const uip_lladdr_t *)nbr_table_get_lladdr(ds6_neighbors, nbr); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ int uip_ds6_nbr_num(void) { - uip_ds6_nbr_t *nbr; - int num; + int num = 0; - num = 0; +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + for(nbr_entry = nbr_table_head(uip_ds6_nbr_entries); + nbr_entry != NULL; + nbr_entry = nbr_table_next(uip_ds6_nbr_entries, nbr_entry)) { + num += list_length(nbr_entry->uip_ds6_nbrs); + } +#else + uip_ds6_nbr_t *nbr; for(nbr = nbr_table_head(ds6_neighbors); nbr != NULL; nbr = nbr_table_next(ds6_neighbors, nbr)) { num++; } +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ return num; } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * uip_ds6_nbr_head(void) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + if((nbr_entry = nbr_table_head(uip_ds6_nbr_entries)) == NULL) { + return NULL; + } + assert(list_head(nbr_entry->uip_ds6_nbrs) != NULL); + return (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); +#else return nbr_table_head(ds6_neighbors); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * uip_ds6_nbr_next(uip_ds6_nbr_t *nbr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + if(nbr == NULL) { + return NULL; + } + if(list_item_next(nbr) != NULL) { + return list_item_next(nbr); + } + nbr_entry = nbr_table_next(uip_ds6_nbr_entries, nbr->nbr_entry); + if(nbr_entry == NULL) { + return NULL; + } else { + assert(list_head(nbr_entry->uip_ds6_nbrs) != NULL); + return (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); + } +#else return nbr_table_next(ds6_neighbors, nbr); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ uip_ds6_nbr_t * uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr) { - uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); - if(ipaddr != NULL) { - while(nbr != NULL) { - if(uip_ipaddr_cmp(&nbr->ipaddr, ipaddr)) { - return nbr; - } - nbr = nbr_table_next(ds6_neighbors, nbr); + uip_ds6_nbr_t *nbr; + if(ipaddr == NULL) { + return NULL; + } + for(nbr = uip_ds6_nbr_head(); nbr != NULL; nbr = uip_ds6_nbr_next(nbr)) { + if(uip_ipaddr_cmp(&nbr->ipaddr, ipaddr)) { + return nbr; } } return NULL; @@ -221,7 +435,23 @@ uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr) uip_ds6_nbr_t * uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr) { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + /* + * we cannot determine which entry should return by lladdr alone; + * return the first entry associated with lladdr. + */ + nbr_entry = + (uip_ds6_nbr_entry_t *)nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + (linkaddr_t*)lladdr); + if(nbr_entry == NULL) { + return NULL; + } + assert(list_head(nbr_entry->uip_ds6_nbrs) != NULL); + return (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); +#else return nbr_table_get_from_lladdr(ds6_neighbors, (linkaddr_t*)lladdr); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } /*---------------------------------------------------------------------------*/ @@ -239,6 +469,20 @@ uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr) uip_ds6_nbr_t *nbr = uip_ds6_nbr_lookup(ipaddr); return nbr ? uip_ds6_nbr_get_ll(nbr) : NULL; } +#if UIP_DS6_LL_NUD +/*---------------------------------------------------------------------------*/ +static void +update_nbr_reachable_state_by_ack(uip_ds6_nbr_t *nbr, const linkaddr_t *lladdr) +{ + if(nbr != NULL && nbr->state != NBR_INCOMPLETE) { + nbr->state = NBR_REACHABLE; + stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); + LOG_INFO("received a link layer ACK : "); + LOG_INFO_LLADDR(lladdr); + LOG_INFO_(" is reachable.\n"); + } +} +#endif /* UIP_DS6_LL_NUD */ /*---------------------------------------------------------------------------*/ void uip_ds6_link_callback(int status, int numtx) @@ -266,14 +510,22 @@ uip_ds6_link_callback(int status, int numtx) * acknowledges link packets. */ if(status == MAC_TX_OK) { uip_ds6_nbr_t *nbr; - nbr = uip_ds6_nbr_ll_lookup((uip_lladdr_t *)dest); - if(nbr != NULL && nbr->state != NBR_INCOMPLETE) { - nbr->state = NBR_REACHABLE; - stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); - LOG_INFO("received a link layer ACK : "); - LOG_INFO_LLADDR((uip_lladdr_t *)dest); - LOG_INFO_(" is reachable.\n"); +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + uip_ds6_nbr_entry_t *nbr_entry; + if((nbr_entry = + (uip_ds6_nbr_entry_t *)nbr_table_get_from_lladdr(uip_ds6_nbr_entries, + dest)) == NULL) { + return; } + for(nbr = (uip_ds6_nbr_t *)list_head(nbr_entry->uip_ds6_nbrs); + nbr != NULL; + nbr = (uip_ds6_nbr_t *)list_item_next(nbr)) { + update_nbr_reachable_state_by_ack(nbr, dest); + } +#else /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + nbr = uip_ds6_nbr_ll_lookup((uip_lladdr_t *)dest); + update_nbr_reachable_state_by_ack(nbr, dest); +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ } #endif /* UIP_DS6_LL_NUD */ } @@ -283,7 +535,7 @@ uip_ds6_link_callback(int status, int numtx) void uip_ds6_neighbor_periodic(void) { - uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); + uip_ds6_nbr_t *nbr = uip_ds6_nbr_head(); while(nbr != NULL) { switch(nbr->state) { case NBR_REACHABLE: @@ -354,7 +606,7 @@ uip_ds6_neighbor_periodic(void) default: break; } - nbr = nbr_table_next(ds6_neighbors, nbr); + nbr = uip_ds6_nbr_next(nbr); } } /*---------------------------------------------------------------------------*/ @@ -373,7 +625,7 @@ uip_ds6_nbr_refresh_reachable_state(const uip_ipaddr_t *ipaddr) uip_ds6_nbr_t * uip_ds6_get_least_lifetime_neighbor(void) { - uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); + uip_ds6_nbr_t *nbr = uip_ds6_nbr_head(); uip_ds6_nbr_t *nbr_expiring = NULL; while(nbr != NULL) { if(nbr_expiring != NULL) { @@ -384,7 +636,7 @@ uip_ds6_get_least_lifetime_neighbor(void) } else { nbr_expiring = nbr; } - nbr = nbr_table_next(ds6_neighbors, nbr); + nbr = uip_ds6_nbr_next(nbr); } return nbr_expiring; } diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index 4de17249c..b6b228d2d 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -54,6 +54,10 @@ #if UIP_CONF_IPV6_QUEUE_PKT #include "net/ipv6/uip-packetqueue.h" #endif /*UIP_CONF_QUEUE_PKT */ +#if UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS +#include "lib/assert.h" +#include "lib/list.h" +#endif /*--------------------------------------------------*/ /** \brief Possible states for the nbr cache entries */ @@ -63,8 +67,32 @@ #define NBR_DELAY 3 #define NBR_PROBE 4 +#ifdef UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS +#define UIP_DS6_NBR_MULTI_IPV6_ADDRS UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS +#else +#define UIP_DS6_NBR_MULTI_IPV6_ADDRS 0 +#endif /* UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS */ + +#ifdef UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES +#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES +#else +#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES NBR_TABLE_MAX_NEIGHBORS +#endif /* UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES */ + + +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS +/** \brief An nbr_table entry for neighbor caches */ +typedef struct { + LIST_STRUCT(uip_ds6_nbrs); +} uip_ds6_nbr_entry_t; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ + /** \brief An entry in the nbr cache */ typedef struct uip_ds6_nbr { +#if UIP_DS6_NBR_MULTI_IPV6_ADDRS + struct uip_ds6_nbr *next; + uip_ds6_nbr_entry_t *nbr_entry; +#endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ uip_ipaddr_t ipaddr; uint8_t isrouter; uint8_t state; From 17aa75f0cf6ee00535f3d84e93863b418645c23c Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Mon, 20 Aug 2018 19:26:27 +0200 Subject: [PATCH 4/7] uip-ds6-nbr: add doxygen comments (and re-order some functions) --- os/net/ipv6/uip-ds6-nbr.c | 27 +++++++++ os/net/ipv6/uip-ds6-nbr.h | 124 ++++++++++++++++++++++++++++++++++---- 2 files changed, 139 insertions(+), 12 deletions(-) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index f4404e8c8..c83fa7674 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -65,12 +65,39 @@ #define LOG_LEVEL LOG_LEVEL_IPV6 #if UIP_DS6_NBR_MULTI_IPV6_ADDRS +/** + * Add nbr to the list in nbr_entry. In other words, this function associates an + * IPv6 address in nbr with a link-layer address in nbr_entry. + * \param nbr the neighbor cache entry for an IPv6 address + * \param nbr_entry the nbr_table entry for an link-layer address + */ static void add_uip_ds6_nbr_to_nbr_entry(uip_ds6_nbr_t *nbr, uip_ds6_nbr_entry_t *nbr_entry); + +/** + * Remove nbr from the list of the corresponding nbr_entry + * \param nbr a neighbor cache entry (nbr) to be removed + */ static void remove_uip_ds6_nbr_from_nbr_entry(uip_ds6_nbr_t *nbr); + +/** + * Remove nbr_etnry from nbr_table + * \param nbr_entry a nbr_table entry (nbr_entry) to be removed + */ static void remove_nbr_entry(uip_ds6_nbr_entry_t *nbr_entry); + +/** + * Free memory for a specified neighbor cache entry + * \param nbr a neighbor cache entry to be freed + */ static void free_uip_ds6_nbr(uip_ds6_nbr_t *nbr); + +/** + * Callback function called when a nbr_table entry is removed + * \param nbr_entry a nbr_entry to be removed + */ static void callback_nbr_entry_removal(uip_ds6_nbr_entry_t *nbr_entry); + NBR_TABLE(uip_ds6_nbr_entry_t, uip_ds6_nbr_entries); MEMB(uip_ds6_nbr_memb, uip_ds6_nbr_t, UIP_DS6_NBR_MAX_NEIGHBOR_CACHES); #else diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index b6b228d2d..809f01d2b 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -67,27 +67,33 @@ #define NBR_DELAY 3 #define NBR_PROBE 4 +/** \brief Set non-zero (1) to enable multiple IPv6 addresses to be + * associated with a link-layer address */ #ifdef UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS #define UIP_DS6_NBR_MULTI_IPV6_ADDRS UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS #else #define UIP_DS6_NBR_MULTI_IPV6_ADDRS 0 #endif /* UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS */ +/** \brief Set the maximum number of neighbor cache entries */ #ifdef UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES #define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES #else -#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES NBR_TABLE_MAX_NEIGHBORS +#define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES \ + (NBR_TABLE_MAX_NEIGHBORS * UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) #endif /* UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES */ - #if UIP_DS6_NBR_MULTI_IPV6_ADDRS -/** \brief An nbr_table entry for neighbor caches */ +/** \brief nbr_table entry when UIP_DS6_NBR_MULTI_IPV6_ADDRS is + * enabled. uip_ds6_nbrs is a list of uip_ds6_nbr_t objects */ typedef struct { LIST_STRUCT(uip_ds6_nbrs); } uip_ds6_nbr_entry_t; #endif /* UIP_DS6_NBR_MULTI_IPV6_ADDRS */ -/** \brief An entry in the nbr cache */ +/** \brief The default nbr_table entry (when + * UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr + * cache */ typedef struct uip_ds6_nbr { #if UIP_DS6_NBR_MULTI_IPV6_ADDRS struct uip_ds6_nbr *next; @@ -109,25 +115,119 @@ typedef struct uip_ds6_nbr { void uip_ds6_neighbors_init(void); -/** \brief Neighbor Cache basic routines */ +/** + * Add a neighbor cache for a specified IPv6 address, which is + * associated with a specified link-layer address + * \param ipaddr IPv6 address of a neighbor to add + * \param lladdr Link-layer address to associate with ipaddr + * \param isrouter Set 1 if the neighbor is a router + * \param state Set the initial neighbor cache state (e.g., + * NBR_INCOMPLETE) + * \param reason Set a reason of the addition (e.g., + * NBR_TABLE_REASON_RPL_DIO) + * \param data Set data associated with the nbr cache + * \return the address of a newly added nbr cache on success, NULL on + * failure +*/ uip_ds6_nbr_t *uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, uint8_t isrouter, uint8_t state, nbr_table_reason_t reason, void *data); + +/** + * Remove a neighbor cache + * \param nbr the address of a neighbor cache to remove + * \return 1 on success, 0 on failure (nothing was removed) + */ int uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr); + +/** + * Get the link-layer address associated with a specified nbr cache + * \param nbr the address of a neighbor cache + * \return pointer to the link-layer address on success, NULL on failure + */ const uip_lladdr_t *uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr); -int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr, const uip_lladdr_t *new_ll_addr); -const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr); -uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr); -uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr); -uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr); + +/** + * Get the link-layer address associated with a specified IPv6 address + * \param ipaddr an IPv6 address used as a search key + * \return the pointer to the link-layer address on success, NULL on failure + */ const uip_lladdr_t *uip_ds6_nbr_lladdr_from_ipaddr(const uip_ipaddr_t *ipaddr); -void uip_ds6_link_callback(int status, int numtx); -void uip_ds6_neighbor_periodic(void); + +/** + * Update the link-layer address associated with an IPv6 address + * \param nbr the double pointer to a neighbor cache which has the + * target IPv6 address + * \param new_ll_addr the new link-layer address of the IPv6 address + * return 0 on success, -1 on failure + */ +int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr, const uip_lladdr_t *new_ll_addr); + +/** + * Get an IPv6 address of a neighbor cache + * \param nbr the pointer to a neighbor cache + * \return the pointer to an IPv6 address associated with the neighbor cache + * \note This returns the first IPv6 address found in the neighbor + * cache when UIP_DS6_NBR_MULTI_IPV6_ADDRS is enabled + */ +const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr); + +/** + * Get an IPv6 address associated with a specified link-layer address + * \param lladdr a link-layer address used as a search key + * \return the pointer to an IPv6 address associated with the neighbor cache + * \note This returns the first IPv6 address found in the neighbor + * cache when UIP_DS6_NBR_MULTI_IPV6_ADDRS is enabled + */ +uip_ipaddr_t *uip_ds6_nbr_ipaddr_from_lladdr(const uip_lladdr_t *lladdr); + +/** + * Get the neighbor cache associated with a specified IPv6 address + * \param ipaddr an IPv6 address used as a search key + * \return the pointer to a neighbor cache on success, NULL on failure + */ +uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr); + +/** + * Get the neighbor cache associated with a specified link-layer address + * \param lladdr a link-layer address used as a search key + * \return the pointer to a neighbor cache on success, NULL on failure + */ +uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr); + +/** + * Return the number of neighbor caches + * \return the number of neighbor caches in use + */ int uip_ds6_nbr_num(void); + +/** + * Get the first neighbor cache in nbr_table + * \return the pointer to the first neighbor cache entry + */ uip_ds6_nbr_t *uip_ds6_nbr_head(void); + +/** + * Get the next neighbor cache of a specified one + * \param nbr the pointer to a neighbor cache + * \return the pointer to the next one on success, NULL on failure + */ uip_ds6_nbr_t *uip_ds6_nbr_next(uip_ds6_nbr_t *nbr); +/** + * The callback function to update link-layer stats in a neighbor + * cache + * \param status MAC return value defined in mac.h + * \param numtx the number of transmissions happened for a packet + */ +void uip_ds6_link_callback(int status, int numtx); + +/** + * The housekeeping function called periodically + */ +void uip_ds6_neighbor_periodic(void); + #if UIP_ND6_SEND_NS /** * \brief Refresh the reachable state of a neighbor. This function From 319b70345ab54bf89139190c85c169761f5094a4 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Wed, 29 Aug 2018 17:28:13 +0200 Subject: [PATCH 5/7] uip-ds6-nbr: introduce UIP_DS6_NBR_MAX_6ADDRS_PER_NBR --- os/net/ipv6/uip-ds6-nbr.c | 13 +++++++++++++ os/net/ipv6/uip-ds6-nbr.h | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index c83fa7674..0db8a0f45 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -149,6 +149,19 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, } } + if(list_length(nbr_entry->uip_ds6_nbrs) < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + /* it has room to add another IPv6 address */ + } else { + /* + * it's already had the maximum number of IPv6 addresses; cannot + * add another. + */ + LOG_ERR("%s: no room in nbr_entry for ", __func__); + LOG_ERR_LLADDR((const linkaddr_t *)lladdr); + LOG_ERR_("\n"); + return NULL; + } + if((nbr = (uip_ds6_nbr_t *)memb_alloc(&uip_ds6_nbr_memb)) == NULL) { LOG_ERR("%s: cannot allocate a new uip_ds6_nbr\n", __func__); if(list_length(nbr_entry->uip_ds6_nbrs) == 0) { diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index 809f01d2b..6479c972e 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -75,6 +75,14 @@ #define UIP_DS6_NBR_MULTI_IPV6_ADDRS 0 #endif /* UIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS */ +/** \brief Set the maximum number of IPv6 addresses per link-layer + * address */ +#ifdef UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR +#define UIP_DS6_NBR_MAX_6ADDRS_PER_NBR UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR +#else +#define UIP_DS6_NBR_MAX_6ADDRS_PER_NBR 2 +#endif /* UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR */ + /** \brief Set the maximum number of neighbor cache entries */ #ifdef UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES #define UIP_DS6_NBR_MAX_NEIGHBOR_CACHES UIP_DS6_NBR_CONF_MAX_NEIGHBOR_CACHES From 54a2889614bc2f5121cf506a95e6c6f66e6f51a4 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Wed, 29 Aug 2018 14:20:08 +0200 Subject: [PATCH 6/7] test/10-ipv6-nbr: add 01-test-nbr-multi-addrs --- .travis.yml | 1 + tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh | 21 ++ tests/10-ipv6-nbr/Makefile | 1 + tests/10-ipv6-nbr/nbr-multi-addrs/Makefile | 14 + tests/10-ipv6-nbr/nbr-multi-addrs/test.c | 260 +++++++++++++++++++ 5 files changed, 297 insertions(+) create mode 100755 tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh create mode 100644 tests/10-ipv6-nbr/Makefile create mode 100644 tests/10-ipv6-nbr/nbr-multi-addrs/Makefile create mode 100644 tests/10-ipv6-nbr/nbr-multi-addrs/test.c diff --git a/.travis.yml b/.travis.yml index 60d8db747..d9c98d75d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,3 +68,4 @@ env: - TEST_NAME='compile-tools' - TEST_NAME='native-runs' - TEST_NAME='ipv6' BUILD_COOJA=true + - TEST_NAME='ipv6-nbr' BUILD_COOJA=true diff --git a/tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh b/tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh new file mode 100755 index 000000000..8f73ee237 --- /dev/null +++ b/tests/10-ipv6-nbr/01-test-nbr-multi-addrs.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +TEST_NAME=01-test-nbr-multi-addrs + +if [ $# -eq 1 ]; then + # a (relative) path to CONTIKI_DIR is supposed to be given as $1 + TEST_DIR=$1/tests/10-ipv6-nbr +else + TEST_DIR=.//tests/10-ipv6-nbr +fi +SRC_DIR=${TEST_DIR}/nbr-multi-addrs +EXEC_FILE_NAME=test.native + +make -C ${SRC_DIR} clean + +echo "build the test program"... +make -C ${SRC_DIR} > ${TEST_NAME}.log + +echo "run the test..." +${TEST_DIR}/${SRC_DIR}/${EXEC_FILE_NAME} | tee ${TEST_NAME}.log | \ + grep -vE '^\[' >> ${TEST_NAME}.testlog diff --git a/tests/10-ipv6-nbr/Makefile b/tests/10-ipv6-nbr/Makefile new file mode 100644 index 000000000..c46e5271d --- /dev/null +++ b/tests/10-ipv6-nbr/Makefile @@ -0,0 +1 @@ +include ../Makefile.script-test diff --git a/tests/10-ipv6-nbr/nbr-multi-addrs/Makefile b/tests/10-ipv6-nbr/nbr-multi-addrs/Makefile new file mode 100644 index 000000000..711bf0987 --- /dev/null +++ b/tests/10-ipv6-nbr/nbr-multi-addrs/Makefile @@ -0,0 +1,14 @@ +CONTIKI_PROJECT = test +all: $(CONTIKI_PROJECT) + +CFLAGS += -DUNIT_TEST_PRINT_FUNCTION=my_test_print +CFLAGS += -DLOG_CONF_LEVEL_IPV6=LOG_LEVEL_DBG +CFLAGS += -DNBR_TABLE_FIND_REMOVABLE=my_always_return_null +CFLAGS += -DUIP_DS6_NBR_CONF_MULTI_IPV6_ADDRS=1 + +PLATFORM_ONLY = native +TARGET = native +MODULES += os/sys/log os/services/unit-test + +CONTIKI = ../../../ +include $(CONTIKI)/Makefile.include diff --git a/tests/10-ipv6-nbr/nbr-multi-addrs/test.c b/tests/10-ipv6-nbr/nbr-multi-addrs/test.c new file mode 100644 index 000000000..2cefd7cca --- /dev/null +++ b/tests/10-ipv6-nbr/nbr-multi-addrs/test.c @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2018, Yasuyuki Tanaka + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#define LOG_MODULE "test" +#define LOG_LEVEL LOG_LEVEL_DBG + +/* report function defined in unit-test.c */ +void unit_test_print_report(const unit_test_t *utp); + +static const uint8_t is_router = 1; +static const uint8_t state = NBR_INCOMPLETE; +static const nbr_table_reason_t reason = NBR_TABLE_REASON_UNDEFINED; + +static void remove_all_entries_in_neighbor_cache(void); + +PROCESS(node_process, "Node"); +AUTOSTART_PROCESSES(&node_process); + +void +my_test_print(const unit_test_t *utp) +{ + unit_test_print_report(utp); + if(utp->result == unit_test_failure) { + printf("\nTEST FAILED\n"); + exit(1); /* exit by failure */ + } +} + +/* my_always_return_null() is set to NBR_TABLE_FIND_REMOVABLE */ +const linkaddr_t * +my_always_return_null(nbr_table_reason_t reason, void *data) +{ + return NULL; +} + +void +remove_all_entries_in_neighbor_cache(void) +{ + uip_ds6_nbr_t *nbr, *next_nbr; + for(nbr = uip_ds6_nbr_head(); nbr != NULL; nbr = next_nbr) { + next_nbr = uip_ds6_nbr_next(nbr); + uip_ds6_nbr_rm(nbr); + } + /* + * uip_ds6_nbr_rm() cannot free the memory for an entry in nbr-table. There is + * no API to free or deallocate unused nbr-table entry. Because of that, + * nbr-table has some link-layer addresses even though this function removes + * all the neighbor cache entries. + */ +} + +UNIT_TEST_REGISTER(add_v6addrs_to_neighbor, + "add IPv6 addresses to a single neighbor"); +UNIT_TEST(add_v6addrs_to_neighbor) +{ + uip_ipaddr_t ipaddr; + uip_lladdr_t lladdr; + uip_ds6_nbr_t *nbr; + const uip_lladdr_t *ret_lladdr; + + memset(&ipaddr, 0, sizeof(ipaddr)); + memset(&lladdr, 0, sizeof(lladdr)); + + UNIT_TEST_BEGIN(); + + /* make sure the neighbor cache table is empty */ + remove_all_entries_in_neighbor_cache(); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + + /* prepare a link-layer address */ + LOG_DBG("link-layer addr: "); + LOG_DBG_LLADDR((const linkaddr_t *)&lladdr); + LOG_DBG_("\n"); + + for(int i = 0; i <= UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; i++) { + ipaddr.u8[0] = i; + LOG_DBG("adding ipv6 addr ("); + LOG_DBG_6ADDR(&ipaddr); + LOG_DBG_("[i=%u])\n", i); + + /* add a binding of the IPv6 address and the MAC address */ + nbr = uip_ds6_nbr_add(&ipaddr, &lladdr, is_router, state, reason, NULL); + if(i < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + UNIT_TEST_ASSERT(nbr != NULL); + UNIT_TEST_ASSERT(memcmp(&nbr->ipaddr, &ipaddr, sizeof(ipaddr)) == 0); + UNIT_TEST_ASSERT(nbr->state == state); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == (i + 1)); + /* + * for some reason, nbr->isrouter is not set if both UIP_ND6_SEND_RA and + * !UIP_CONF_ROUTER is 0 (see uip-ds6-nbr.c) + */ + // UNIT_TEST_ASSERT(nbr->isrouter == is_router); + ret_lladdr = uip_ds6_nbr_lladdr_from_ipaddr((const uip_ipaddr_t *)&ipaddr); + UNIT_TEST_ASSERT(ret_lladdr != NULL); + UNIT_TEST_ASSERT(memcmp(ret_lladdr, &lladdr, sizeof(lladdr)) == 0); + + } else { + /* i == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; the address shouldn't be added */ + UNIT_TEST_ASSERT(nbr == NULL); + } + } + + UNIT_TEST_END(); +} + +UNIT_TEST_REGISTER(remove_v6addrs_of_neighbor, + "remove IPv6 addresses associated with a single neighbor"); +UNIT_TEST(remove_v6addrs_of_neighbor) +{ + uip_ipaddr_t ipaddr; + uip_lladdr_t lladdr; + uip_ds6_nbr_t *nbr, *next_nbr; + + memset(&ipaddr, 0, sizeof(ipaddr)); + memset(&lladdr, 0, sizeof(lladdr)); + + UNIT_TEST_BEGIN(); + + /* make sure the neighbor cache table is empty */ + remove_all_entries_in_neighbor_cache(); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + + /* prepare a link-layer address */ + LOG_DBG("link-layer addr: "); + LOG_DBG_LLADDR((const linkaddr_t *)&lladdr); + LOG_DBG_("\n"); + + /* fill the neighbor entry associated with the link-layer address */ + for(int i = 0; i < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; i++) { + ipaddr.u8[0] = i; + nbr = uip_ds6_nbr_add(&ipaddr, &lladdr, is_router, state, reason, NULL); + UNIT_TEST_ASSERT(nbr != NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == (i + 1)); + } + + /* remove IPv6 addresses for the link-layer address one by one */ + for(nbr = uip_ds6_nbr_head(); nbr != NULL; nbr = next_nbr) { + LOG_DBG("removing nbr:%p\n", nbr); + next_nbr = uip_ds6_nbr_next(nbr); + UNIT_TEST_ASSERT(uip_ds6_nbr_rm(nbr) == 1); + } + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + + UNIT_TEST_END(); + +} + +UNIT_TEST_REGISTER(fill_neighbor_cache_table, + "fill the neighbor cache table"); +UNIT_TEST(fill_neighbor_cache_table) +{ + /* + * We should be able to add the same number of link-layer addresses as + * NBR_TABLE_MAX_NEIGHBORS. In addition, we should be add the same number of + * IPv6 addresses per link-layer address as + * UIP_DS6_NBR_CONF_MAX_6ADDRS_PER_NBR. + */ + uip_ipaddr_t ipaddr; + uip_lladdr_t lladdr; + uip_ds6_nbr_t *nbr; + + memset(&ipaddr, 0, sizeof(ipaddr)); + memset(&lladdr, 0, sizeof(lladdr)); + + UNIT_TEST_BEGIN(); + + /* make sure the neighbor cache table is empty */ + remove_all_entries_in_neighbor_cache(); + UNIT_TEST_ASSERT(uip_ds6_nbr_head() == NULL); + UNIT_TEST_ASSERT(uip_ds6_nbr_num() == 0); + + for(int i = 0; i <= NBR_TABLE_MAX_NEIGHBORS; i++) { + lladdr.addr[0] = i & 0xFF; + lladdr.addr[1] = i >> 8; + for(int j = 0; j <= UIP_DS6_NBR_MAX_6ADDRS_PER_NBR; j++) { + ipaddr.u8[0] = i & 0xFF; + ipaddr.u8[1] = i >> 8; + ipaddr.u8[2] = j; + LOG_DBG("adding ipv6 addr ("); + LOG_DBG_6ADDR(&ipaddr); + LOG_DBG_(") to link-layer addr ("); + LOG_DBG_LLADDR((const linkaddr_t *)&lladdr); + LOG_DBG_(") [i=%u,j=%u]\n", i, j); + + nbr = uip_ds6_nbr_add(&ipaddr, &lladdr, is_router, state, reason, NULL); + if((i < NBR_TABLE_MAX_NEIGHBORS) && + (j < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR)) { + UNIT_TEST_ASSERT(nbr != NULL); + } else if(i == NBR_TABLE_MAX_NEIGHBORS) { + /* we should not be able to add a link-layer address any more */ + UNIT_TEST_ASSERT(j == 0); + UNIT_TEST_ASSERT(nbr == NULL); + break; + } else if(j == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + /* we should not be able to add an IPv6 address any more */ + UNIT_TEST_ASSERT(i < NBR_TABLE_MAX_NEIGHBORS); + UNIT_TEST_ASSERT(nbr == NULL); + break; + } else { + /* shouldn't come here */ + UNIT_TEST_ASSERT(false); + } + } + } + + UNIT_TEST_END(); +} + +PROCESS_THREAD(node_process, ev, data) +{ + PROCESS_BEGIN(); + + UNIT_TEST_RUN(add_v6addrs_to_neighbor); + UNIT_TEST_RUN(remove_v6addrs_of_neighbor); + UNIT_TEST_RUN(fill_neighbor_cache_table); + + printf("\nTEST SUCCEEDED\n"); + exit(0); /* success: all the test passed */ + + PROCESS_END(); +} From 4d8bb2f55093eda519e27d2c90d018d29cf1b3f9 Mon Sep 17 00:00:00 2001 From: Yasuyuki Tanaka Date: Wed, 29 Aug 2018 18:27:40 +0200 Subject: [PATCH 7/7] uip-ds6-nbr: check memb availability before adding an nbr_table entry --- os/net/ipv6/uip-ds6-nbr.c | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index 0db8a0f45..b8f8b63d7 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -136,6 +136,13 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, return NULL; } + /* firstly, allocate memory for a new nbr cache entry */ + if((nbr = (uip_ds6_nbr_t *)memb_alloc(&uip_ds6_nbr_memb)) == NULL) { + LOG_ERR("%s: cannot allocate a new uip_ds6_nbr\n", __func__); + return NULL; + } + + /* secondly, get or allocate nbr_entry for the link-layer address */ nbr_entry = nbr_table_get_from_lladdr(uip_ds6_nbr_entries, (const linkaddr_t *)lladdr); if(nbr_entry == NULL) { @@ -143,31 +150,30 @@ uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, nbr_table_add_lladdr(uip_ds6_nbr_entries, (linkaddr_t*)lladdr, reason, data)) == NULL) { LOG_ERR("%s: cannot allocate a new uip_ds6_nbr_entry\n", __func__); - return NULL; + /* return from this function later */ } else { LIST_STRUCT_INIT(nbr_entry, uip_ds6_nbrs); } } - if(list_length(nbr_entry->uip_ds6_nbrs) < UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { - /* it has room to add another IPv6 address */ - } else { - /* - * it's already had the maximum number of IPv6 addresses; cannot - * add another. - */ - LOG_ERR("%s: no room in nbr_entry for ", __func__); - LOG_ERR_LLADDR((const linkaddr_t *)lladdr); - LOG_ERR_("\n"); - return NULL; - } - - if((nbr = (uip_ds6_nbr_t *)memb_alloc(&uip_ds6_nbr_memb)) == NULL) { - LOG_ERR("%s: cannot allocate a new uip_ds6_nbr\n", __func__); - if(list_length(nbr_entry->uip_ds6_nbrs) == 0) { - nbr_table_remove(uip_ds6_nbr_entries, nbr_entry); + /* free nbr and return if nbr_entry is not available */ + if((nbr_entry == NULL) || + (list_length(nbr_entry->uip_ds6_nbrs) == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR)) { + if(list_length(nbr_entry->uip_ds6_nbrs) == UIP_DS6_NBR_MAX_6ADDRS_PER_NBR) { + /* + * it's already had the maximum number of IPv6 addresses; cannot + * add another. + */ + LOG_ERR("%s: no room in nbr_entry for ", __func__); + LOG_ERR_LLADDR((const linkaddr_t *)lladdr); + LOG_ERR_("\n"); } + /* free the newly allocated memory in this function call */ + memb_free(&uip_ds6_nbr_memb, nbr); + return NULL; } else { + /* everything is fine; nbr is ready to be used */ + /* it has room to add another IPv6 address */ add_uip_ds6_nbr_to_nbr_entry(nbr, nbr_entry); } #else