Monday, 18 March 2013

B.A.T.M.A.N. Advanced - A brief intro

B.A.T.M.A.N stands for Better Approach To Mobile Ad-Hoc Networking. B.A.T.M.A.N. Advanced is a layer 2 implementation of the B.A.T.M.A.N. protocol in the form of a Linux kernel module. From here on it will be referred to simply as batman-adv.

Main features of B.A.T.M.A.N.

Not all routes are calculated, only route to the next neighbour So complete topology is not known to any single node, topology and routing decisions are distributed between all the nodes.   Spreading this information reduces the “cost” on each node

 Designed specifically for wireless networks – built for packet loss

Layer 2 vs. Layer 3

Most layer 3 routing protocols operate by sending UDP packets to exchange routing information and manipulate the kernel routing table to effect their routing decision. As packets are retransmitted they must be brought up from layer 2 to layer 3 on each node before being moved back down to layer 2 for retransmission.

Batman-adv operates entirely on layer 2 providing a virtual switch port on each node. A batman-adv network of nodes can be imagined as a large distributed switch where each node has a single switch port to which any other bridge or switch can be connected.

Packet Routing and Transmission

The virtual Ethernet interface (tap) is used to emulate the switch. This switch sends and receives the packets. The packet is retransmitted by each node at layer 2 only; the packet is never brought up to higher levels during transmission. This means any transmission looks like one hop to all the higher layers (layer 3 and up) no matter how many nodes are in the network
At layer 2 the routing protocol must handle the data traffic Batman-adv uses its own Ethernet type 0x0842. These Ethernet-Frames are sent to find the routing information. Each data traffic Ethernet-Frame is encapsulated in a 0x0842 Ethernet frame. 

Node identification

Layer 3 routing protocols also have the problem that to join the network the node must have a unique IP address, however without joining the network how can the node know which IPs are unique? Batman-adv overcomes this problem. Just like a switch batman-adv does not use IP addresses for identification but instead uses MAC addresses. The BATMAN algorithm decides the best neighbour to receive the packet being sent by looking it up in the MAC translation table.

Bridging Interfaces

The use of MAC addresses allows multiple other interfaces to be bridged in easily using bridge tools. The MAC of each participant behind the bridge is collected and transmitted as a list via HNA-messages to all the batman-adv nodes. This makes integration of non-meshed clients very easy and allows the non-meshed clients to roam.

Packet Loss and Encryption

Similarly to Ethernet, batman-adv will leave re-transmission of packets to higher layer mechanisms such as TCP. As batman-adv works at layer 2, it is network-layer agnostic. DHCP, IPv4, IPv6 IPX etc can all be run on top of batman-adv. Batman-adv does not perform any encryption at layer 2, encryption must be performed at a higher layer.

User space Daemon vs. Kernel Module

User space daemons only handles the exchange of routing information setting the routing tables while data traffic is routed by the kernel using the routing tables defined and manipulated by the user space daemon. In user space, packet forwarding usually takes place as follows:

  • select() – wait for a packet
  • read() the packet from the kernel
  • find next hop, update tables
  • write() the packet to the kernel

System calls to copy the message (read and write) takes a long time and the mode must be switched between kernel and userspace. This becomes a problem when the bandwidth usage rises so the peak performance of the network interface card (NIC) can’t be reached
By switching to kernel space the kernel buffer can be reused without having to copy it (read/write) and the Syscalls and mode switches are no longer necessary. Kernel functions can be made asynchronous and pre-emptive so asynchronous packet handling is possible. By implementing batman-adv as a kernel module packet processing becomes almost negligible. 

No comments:

Post a Comment