Package spoon :: Package routing :: Module MeshRouter'
[hide private]
[frames] | no frames]

Module MeshRouter'

source code

Mesh Routing, this is the protocol by which an ad-hoc network of nodes can be created and how messages may be passed between them.

Routing in SpoonRPC

Baseline:

Route tracking

Each node tracks -- for every other node in the network -- how many hops it is to that node, and which link is used to get there.

New links

When a node gains a new link, it sends a message to each of its other links announcing the new hop-count for this new link ("Node T, 1 hop"). Each link compares this with any existing route for T, and if the hop count is smaller, the route entry is replaced and a new hop count message is sent to each of its local links (except the one it received the original message from). In this way, the new route will propagate. When such a message loops back on itself around a redundant link, it will be discarded because the hop count will be larger than the one already stored.

If the hop count is larger, but the link making the announcement is the link already in this node's route table, then the route's hop-count is changed and the message is propagated anyway. (It means the node's route is now longer than it was, or possibly infinite.)

An example may help: Node A is linked directly to B and C. It has a route to node X through B, with 4 hops. (All it stores for "X" is "B, 4 hops".) If it receives a message from C saying "X is 2 hops for me" then it will change X's route to "C, 3 hops" and send this new route to its other local links (like B). If, on the other hand, C says "X is 5 hops for me" then A will ignore the message. If A receives a message from B saying "X is 5 hops for me" then A changes its route to "B, 6 hops" and sends this new route to all local links.

Once a new link is established, the two newly connected nodes will each send the other a hopcount update message containing all of the nodes each knows about. In the case of a node with no connections to the network, connecting to a node with connections, this will make the new node aware of all of the nodes that are available. In the case of a link forming between two existing networks (or perhaps fragments of a previous network that got disconnected), these messages will cause the two networks to be made fully aware of eachother.

Dead links

When a node drops a link, it sends out a message to all other links announcing the hop-count for the dead route as "infinity". (This can be represented as 0, -1, maxint, or whatever.) If a link receives an "infinity" route for node X from the link that is its current route to X, then the node must drop that route and propagate the "infinity" route to all its other links. In this way, if that was the only route to X, everyone will eventually drop the route and have X unreachable.

If a node receives an "infinity" route for node X from a link that is not its current route to X, it should immediately propagate its current route to that link. This will end up being propagated as if it were a new link (this is really just good neighbor policy.)

This rerouting mechanism may leave some nodes with inefficient (winding) routes to nodes that move around. So the "good neighbor" policy dictates that when you have a route to X, and a link that is not your route sends you info about a much longer route (at least 2 hops longer than yours), you turn around and tell this link about your route.

Classes [hide private]
  LinkMessage
Link message is the wrapper which will contain messages sent between two directly connected nodes.
  MeshRouter
This class handles LMTYPE_NETWORK messages and LMTYPE_NETWORK_PROTO messages.
  NetMessage
NetMessage is the protocol unit for the networking component of spoon.
  NodeUnreachable
Raised when trying to send to a node that is not currently reachable.
  RoutingProtocolError
  serialprop
When used like a property in a Serial class, it will act as a flag to the serializer that only properties that are of type serialprop or lazyprop are to be serialized.

Functions [hide private]
  decode_netmessage(fd, tag)
  encode_netmessage(fd, obj)

Variables [hide private]
  INFINITY = 2147483647
  LMTYPE_NETWORK = 1
  LMTYPE_NETWORK_PROTO = 2
  NMTYPE_MESSAGING = 0
  __SPOONNETMSG_TAG__ = <ASN.1 Tag(APPLICATION, 8, size=None, container=True)>

Function Details [hide private]

decode_netmessage(fd, tag)

source code 
None

encode_netmessage(fd, obj)

source code 
None

Variables Details [hide private]

INFINITY

None
Value:
2147483647                                                            
      

LMTYPE_NETWORK

None
Value:
1                                                                     
      

LMTYPE_NETWORK_PROTO

None
Value:
2                                                                     
      

NMTYPE_MESSAGING

None
Value:
0                                                                     
      

__SPOONNETMSG_TAG__

None
Value:
<ASN.1 Tag(APPLICATION, 8, size=None, container=True)>