Learning on Auto Discovery – Multicast-2

In the previous post I had discussed about multicast protocol in general in this post I shall discuss on implementing Auto Discovery using Multicast. The procedure is as follows:

  • Nodes will be listening at an predetermined multicast address.
  • Discovery agent shall be sending a multicast packet periodically on the network.
  • All nodes listening on this multicast group shall reply back to discovery agent.

You might be wondering how will the multicast packets are received by all nodes and doesn’t it create network flood? To understand these issues more clearly we have to dissect a multicast packet.

Ethernet II, Src: ArkinoHi_01:af:df (00:17:54:01:af:df), Dst: IPv4mcast_00:00:01 (01:00:5e:00:00:01)
    Destination: IPv4mcast_00:00:01 (01:00:5e:00:00:01)
    Source: ArkinoHi_01:af:df (00:17:54:01:af:df)
Internet Protocol Version 4, Src: 0.0.0.0 (0.0.0.0), Dst: 224.0.0.1 (224.0.0.1)
    Version: 4
    Time to live: 1
    Protocol: IGMP (2)
Internet Group Management Protocol
    [IGMP Version: 2]
    Type: Membership Query (0x11)
    Max Response Time: 1.0 sec (0x0a)
    Header checksum: 0xfdcf [correct]
    Multicast Address: 239.192.1.101 (239.192.1.101)

In the above packet capture I omitted unwanted details; Observe the destination MAC, which is a special group “01:00:5e“, all the packets with this prefix in destination address are received by  network interface and are passed to operating system.

Hence when a node joins a multicast group the interface need to be specified separately on which to receive/send these multicast packets.

Notice that the TTL value of this packet is 1, hence the packets are not going to cross first router on the network. This ensures that there is no flood of packets on the network.

Discover Agent

The discover agent will bind on the local IP address on which it wishes to receive replies from Advertiser.

# Create the datagram socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Bind to the server address
sock.bind(("10.0.4.15", 65100))

Send the advertise message, on a multicast address

mcst_grp = ('239.100.100.1', 65100)
sent = sock.sendto(msg, mcst_grp)

Now wait for replies from the nodes

data, addr = sock.recvfrom(1024)

The final code can be found here.

Advertise Agent

Advertising agent will be listening on Multicast address for requests from Discover agent.

mcst_grp = '239.100.100.1'
server_address = (mcst_grp, 65100)

# Create the socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(server_address)

Send the reply to discover agent, on the source IP address of received packet; Notice that we are not using multicast address in reply.

    data, addr = sock.recvfrom(1024)
    print "received %s from %s" % (data, addr)
    sent = sock.sendto(msg, addr)

The complete code for advertise agent can be found here.

Let us see the whole picture on the wire.

Internet Protocol, Src: 10.0.4.15 (10.0.4.15), Dst: 239.100.100.1 (239.100.100.1)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
    Total Length: 47
    Identification: 0x0000 (0)
    Flags: 0x02 (Don't Fragment)
    Fragment offset: 0
    Time to live: 1
    Protocol: UDP (0x11)
    Header checksum: 0x184a [correct]
    Source: 10.0.4.15 (10.0.4.15)
    Destination: 239.100.100.1 (239.100.100.1)
User Datagram Protocol, Src Port: 65100 (65100), Dst Port: 65100 (65100)
Data (19 bytes)

0000  48 65 6c 6c 6f 20 61 6e 79 20 6f 6e 65 20 74 68   Hello any one th
0010  65 72 65                                          ere

The discover request is sent on a Multicast IP address, Please observe the TTL value and the destination address; Advertiser knows the source address of Discovery agent from request and replies back.

Internet Protocol, Src: 10.0.4.15 (10.0.4.15), Dst: 10.0.4.15 (10.0.4.15)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
    Total Length: 39
    Identification: 0x0000 (0)
    Flags: 0x02 (Don't Fragment)
    Fragment offset: 0
    Time to live: 64
    Protocol: UDP (0x11)
    Header checksum: 0x1ea9 [correct]
    Source: 10.0.4.15 (10.0.4.15)
    Destination: 10.0.4.15 (10.0.4.15)
User Datagram Protocol, Src Port: 65100 (65100), Dst Port: 65100 (65100)
Data (11 bytes)

0000  49 20 61 6d 20 68 65 72 65 2e 2e                  I am here..

Can we use Multicast address as a source IP address?

No, the reason being Multicast address as such can never have a standalone existence, It is normally always bound to local interface. Use of multicast address allows the packet to be delivered to multiple nodes at the same time.

Routers will drop the packet even if you spoof source address to be a multicast address. Hope you enjoyed the post.

This entry was posted in IP, Linux and tagged , , . Bookmark the permalink.

Leave a comment