cetic / 6lbr

A deployment-ready 6LoWPAN Border Router solution based on Contiki
github.com/cetic/6lbr/wiki
Other
337 stars 194 forks source link

slip_set_mac and slip_reboot #55

Closed g-oikonomou closed 10 years ago

g-oikonomou commented 10 years ago

I've been looking at implementing missing features (getting / setting RF channel and MAC address) in Contiki's slip-radio. It's relatively straightforward with the new RF API (assuming the radio implements it).

For 6lbr's slip_set_mac we can start with something as simple as this on the firmware:

NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, &data[2], 8);
memcpy(&linkaddr_node_addr, &data[2], LINKADDR_SIZE);
memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr));

I see that, when shutting down, 6lbr emits a slip_set_mac(&linkaddr_null); When starting it emits a slip_reboot(). This would normally be enough to restore the slip radio to the original MAC. But...

Use case:

Problem: If we actually reboot upon reception of a slip_reboot, /dev/ttyACMx will disappear while 6lbr is trying to use it. This crashes my BeagleBone pretty badly (hard reset required). Ubuntu on a normal PC doesn't crash, but 6lbr enters a state whereby it blocks waiting for the device to re-appear, until it eventually gets restarted by the 6lbr watchdog. Upon restarting, 6lbr reboots the radio again, rinse-repeat like so:

********************************************************************************
[...]
2014-08-14 15:25:36.499057: INFO: TAP: Eth MAC address : 08:00:27:ca:34:88
2014-08-14 15:25:36.499057: INFO: BR-RDC: Reset SLIP Radio
2014-08-14 15:25:36.499074: INFO: BR-RDC: Fetching MAC address
2014-08-14 15:25:37.499156: INFO: BR-RDC: Fetching MAC address
2014-08-14 15:25:37.556806: FATAL: SLIP: read() : Success
2014-08-14 15:25:37.557064: INFO: TAP: Running 6lbr-ifdown script '/usr/lib/6lbr/6lbr-ifdown'
2014-08-14 15:25:37.590834: INFO: BR-RDC: Set MAC: 00:00:00:00:00:00:00:00
2014-08-14 15:25:37.590969: FATAL: SLIP: slip_flushbuf::write() : Input/output error
Waiting for /dev/ttyACM0
********************************************************************************
Sun Sep 14 15:25:48 BST 2014 : Starting 6LBR
/usr/lib/6lbr/bin/cetic_6lbr_router -c /etc/6lbr/nvm.dat -s /dev/ttyACM0 -t eth0 -r -B 115200 -U /usr/lib/6lbr/6lbr-ifup -D /usr/lib/6lbr/6lbr-ifdown -w /usr/lib/6lbr/www -L 3  -W /var/log/6lbr.timestamp -P 60 -C /var/log/6lbr.ip  -m /usr/lib/6lbr/plugins  
Contiki-6lbr-1.3.2 started with IPV6, RPL
[...]
2014-08-14 15:25:48.656981: INFO: TAP: Eth MAC address : 08:00:27:ca:34:88
2014-08-14 15:25:48.657044: INFO: BR-RDC: Reset SLIP Radio
2014-08-14 15:25:48.657107: INFO: BR-RDC: Fetching MAC address
2014-08-14 15:25:49.657208: INFO: BR-RDC: Fetching MAC address
2014-08-14 15:25:49.722007: FATAL: SLIP: read() : Success
2014-08-14 15:25:49.722265: INFO: TAP: Running 6lbr-ifdown script '/usr/lib/6lbr/6lbr-ifdown'
2014-08-14 15:25:49.773728: INFO: BR-RDC: Set MAC: 00:00:00:00:00:00:00:00
2014-08-14 15:25:49.774547: FATAL: SLIP: slip_flushbuf::write() : Input/output error
Waiting for /dev/ttyACM0
(repeats)

The error log has the respective watchdog-related entries:

********************************************************************************
Sun Sep 14 15:25:36 BST 2014 : Starting 6LBR
/usr/lib/6lbr/6lbr: line 206:  4277 Terminated              application_watchdog
Sun Sep 14 15:25:37 BST 2014 : /usr/lib/6lbr/bin/cetic_6lbr_router failed, exit code: 1
(repeats)

We can't really ignore the reset command, because we end up with a MAC of all zeros, so it's really either both or neither.

My current workaround:

But this isn't really ideal:

Thanks

(and yes @sdawans , there will be docs! :smile: )

laurentderu commented 10 years ago

Hi George,

The driver USB controller of the BeagleBone black has some issues with usb device hot plugin, usually leading to kernel freeze or panic :( (It seems to be more stable with kernel 3.12 and 3.14 though)

We have to set the mac address to all zeros when 6LBR is stopped or the slip-radio will continue to ack incoming packets. When you are in a multi-br configuration, this prevent the nodes to switch over to an other BR as the link quality won't be degraded.

Now setting the mac to all zeros is more of a workaround than a good solution, but we choose that in order to not deviate too much from the vanilla slip-radio. But it seems this introduce more problems than we expected. We should have instead a start radio and a stop radio commands, which would store the original mac address and properly shutdown the radio instead of using a bogus mac to stop acking incoming packets.

Btw, someone has written a detailed guide on how to setup 6lbr on beaglebone black on the TI wiki : http://processors.wiki.ti.com/index.php/Contiki-6LOWPAN-BBB

g-oikonomou commented 10 years ago

Hi Laurent, thanks for the reply

The driver USB controller of the BeagleBone black has some issues with usb device hot plugin, usually leading to kernel freeze or panic :( (It seems to be more stable with kernel 3.12 and 3.14 though)

Hmm not sure what kernel mine is running, but that will be it. I also had a kernel oops when I plugged the debug cable on the dongle while it was running. I'll have a look at upgrading the kernel, thanks.

We have to set the mac address to all zeros when 6LBR is stopped or the slip-radio will continue to ack incoming packets.

That is a very good reason!

Now setting the mac to all zeros is more of a workaround than a good solution, but we choose that in order to not deviate too much from the vanilla slip-radio.

... which needs a bit of love and attention IMHO. Parts of it should be re-written to support the new RF API rather than platform-specific calls. But this of course is a Contiki discussion

We should have instead a start radio and a stop radio commands, which would store the original mac address and properly shutdown the radio

Which can be as simple as a 'cross-platform' NETSTACK_RADIO.set_value(RADIO_PARAM_POWER_MODE, RADIO_POWER_MODE_OFF) and _ON.

How about something like this on the 6lbr side:

Btw, someone has written a detailed guide on how to setup 6lbr on beaglebone black on the TI wiki : http://processors.wiki.ti.com/index.php/Contiki-6LOWPAN-BBB

Yes, familiar with it. Particularly interesting section on Jool / NAT64

laurentderu commented 10 years ago

Now setting the mac to all zeros is more of a workaround than a good solution, but we choose that in order to not deviate too much from the vanilla slip-radio.

... which needs a bit of love and attention IMHO. Parts of it should be re-written to support the new RF API rather than platform-specific calls. But this of course is a Contiki discussion

This is on my todo-list, I don't want to write another platform specific slip-radio module :)

How about something like this on the 6lbr side:

Send RF off cmd
If command returns "unknown"
    fall back to MAC workaround
Else
    query RF state
    If still on, fall back to MAC workaround

That should do the trick. Maybe I'll move the check at startup so we know if e have a legacy slip-radio or a "new api" aware slip-radio.

g-oikonomou commented 10 years ago

I'll get back with more news when I have them. I'm also pondering a !p command to change PAN ID for outgoing frames, but all in due course.

Thanks for the support here.

aniketdali commented 7 years ago

Hello, I am new to this forum,

Could you please explain the workaround to restrain 6LBR from "FATAL: SLIP: slip_flushbuf::write()".

Where shall I make changes for the following

" Save h/w MAC in a variable at slip-radio startup Implement slip_set_mac For slip_reboot, we don't really reboot, we just re-set RF registers and data structures to the h/w MAC. "