Routing

Zigbee routing is decentralized, with each node participating in routing packets. The Coordinator does not store a central routing table for all nodes.

Your application need not concern itself with the details of the routing mechanism; all this is handled inside the module. But it's good to know how it all works.

Zigbee uses [Ad hoc On-Demand Distance Vector Routing] to route packets. AODV creates routes only when required; it does not keep a route to all devices in memory. Each router does keep track of their neighbors (or neighbours, if the network is located in the U.K.) and updates their "neighbor list" whenever the router receives a message from a neighbor of any type.

When a router receives a unicast packet:
 * First, it checks whether the destination is one of its direct neighbors. If so then the router sends it to that neighbor and is done.
 * Next, it checks its routing table to see if it has a route to the destination. If so then the router sends it to the next node listed on the routing table.
 * Then, if there's no entry in the routing table (or the message failed) then the router performs a "route discovery" to get a route to the destination, and this is added to the node's routing table.

Only Routers and Coordinators route packets; End Devices do not. When an end device sends a packet the ED's associated parent handles the routing of the packet.

Note that for simplicity we've excluded message retries in this description.

Route Discovery
Route Discovery is when a node tries to find a route (e.g. path of nodes) from it to a destination. Routes are selected based on number of hops and signal strength.

To find a route, the source sends a "Route Request" message to its neighbors. Each neighbor then rebroadcasts the message until the message reaches the destination. At each hop the node adds to the message its signal strength. Eventually one or more Route Request messages arrive at the destination. There are many roads, but all lead to the same destination. The destination device selects the best Route Request and then sends a "Route Reply" message back to the source along the selected route.

Each node along the selected route that passes the "Route Reply" message updates its own routing table with the route information.

Now, the next time that the source sends a message it will follow the new route. If the message doesn't make it to the destination (no MAC ACK received) then the node sends a "Route Error" message to all nodes on the route which tells them to invalidate the route.

Route Maintenance
If a node receives a "Route Error" message then the upstream node will initiate route repair for all routes that use that link, and the next time a message arrives for that route the node will rediscover the route. Routes get re-established automatically by the network.

Route Expiry
If a route is not used for a period of time (e.g. no data packets are sent from the source to the destination in the routing table) then the route is marked as expired and if more space is needed in the routing table then the expired entry is deleted.

The routing table in the module can contain 40 routes. Some of these are used for route repair. The Module can perform up to 8 simultaneous route discoveries. Route expiry time is typical 30 seconds.

For more information see "Z-Stack Developer's Guide", TI document SWRA176.