1#!/usr/bin/python
2#
3# multicast_send.py
4#
5# Multicast test with PicoTCP sending and Linux receiving
6#
7# (sender)                         (Receiver)
8# PicoTCP ------------------------ Linux
9#            mcast to 224.7.7.7
10#
11
12from  topology import *
13import socket, random, string, struct
14
15IF_ADDR = '172.16.1.1'
16LINK_ADDR = '172.16.1.2'
17MCAST_ADDR = '224.7.7.7'
18LISTEN_PORT = 6667
19SENDTO_PORT = 6667
20MCASTSEND = "mcastsend:" + str(LINK_ADDR) + ":" + str(MCAST_ADDR) + ":" + str(SENDTO_PORT) + ":" + str(LISTEN_PORT)
21
22print MCASTSEND
23
24T = Topology()
25net1 = Network(T, "pyt0")
26h1 = Host(T, net1, args=MCASTSEND)
27
28s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
29s_udp.bind((MCAST_ADDR, LISTEN_PORT))
30s_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
31s_udp.settimeout(5);
32
33mreq = struct.pack("=4s4s", socket.inet_aton(str(MCAST_ADDR)), socket.inet_aton(str(IF_ADDR)))
34s_udp.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
35
36raw_input("Press enter to continue ...")
37start(T)
38sleep(1)
39
40while True:
41  data = s_udp.recv(4096)
42  #print data
43  if 'end' in data:
44    print '\n\n'
45    print '+++++++++++++++++++++++++++++++++++++++++++++'
46    print '+++++ multicast_send test IS successful +++++'
47    print '+++++++++++++++++++++++++++++++++++++++++++++'
48    print '\n\n'
49    cleanup()
50    exit(0)
51
52print '\n\n'
53print '+++++++++++++++++++++++++++++++++++++++++++++'
54print '+++++ multicast_send test NOT successful ++++'
55print '+++++++++++++++++++++++++++++++++++++++++++++'
56print '\n\n'
57cleanup()
58exit(1)
59