#!/usr/local/bin/python import socket import struct import sys import os import commands multicast_group = ('224.3.29.71', 8989) cmdinput = '' message = 'Empty Message' basemeship = os.environ['BASEMESHIP'] wlanmesh = os.environ['WLANMESH'] mesh = 'none' #number of nodes to expect on mesh expect = 0 #error messages invalidparam = 'Invalid parameters suppliedi\n' # Create the datagram socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Set a timeout so the socket does not block indefinitely when trying # to receive data. sock.settimeout(0.2) # Set the time-to-live for messages to 1 so they do not go past the # local network segment. ttl = struct.pack('b', 10) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl) # Send data to the multicast group while cmdinput != 'exit': repsonse = '' #open a filename based on testname #close a filename based on testname #store all responses in response and push response into test file print >>sys.stderr, '\n\nCommands:' print >>sys.stderr, 'expect \tiperf \tbatup\tbatdown' print >>sys.stderr, '802up\t802down\tolsrup\tolsrdown\ttraceroute ' print >>sys.stderr, 'start \tstop \tdown ' print >>sys.stderr, '\nStatus:\nexpect='+`expect` print >>sys.stderr, 'meshup='+mesh #expect should be set first to the number of nodes expected cmdinput = raw_input("Command: ") cmd = cmdinput.split(' ') if cmd[0] == 'expect': if cmd[1].isdigit and len(cmd) == 2: expect = int(cmd[1]) if expect == 0: print >>sys.stderr, 'expect must be > 0' continue else: print >>sys.stderr, invalidparam elif cmd[0] == 'iperf': if cmd[1].isdigit and len(cmd) == 2: response = commands.getoutput(cmd[0]+ ' -c '+basemeship+''.join(cmd[1])) print >>sys.stderr, response else: print >>sys.stderr, invalidparam elif cmd[0] == 'batup': if len(cmd) != 1: print >>sys.stderr, invalidparam else: sent = sock.sendto(cmd[0], multicast_group) mesh = 'batman' elif cmd[0] == 'batdown': if len(cmd) != 1: print >>sys.stderr, invalidparam else: sent = sock.sendto(cmd[0], multicast_group) mesh = 'none' elif cmd[0] == '802up': if len(cmd) != 1: print >>sys.stderr, invalidparam else: sent = sock.sendto(cmd[0], multicast_group) mesh = '80211s' elif cmd[0] == '802down': if len(cmd) != 1: print >>sys.stderr, invalidparam else: sent = sock.sendto(cmd[0], multicast_group) mesh = 'none' elif cmd[0] == 'olsrup': if len(cmd) != 1: print >>sys.stderr, invalidparam else: sent = sock.sendto(cmd[0], multicast_group) mesh = 'olsrd' elif cmd[0] == 'olsrdown': if len(cmd) != 1: print >>sys.stderr, invalidparam else: sent = sock.sendto(cmd[0], multicast_group) mesh = 'none' elif cmd[0] == 'traceroute': if cmd[1].isdigit and len(cmd) == 2: response = commands.getoutput(cmd[0]+ ' '+basemeship+cmd[1]) print >>sys.stderr, response else: print >>sys.stderr, invalidparam elif cmd[0] == 'exit': cmdinput = cmd[0] elif cmd[0] == 'down': if len(cmd) == 1: print >>sys.stderr, invalidparam else: sent = sock.sendto(cmdinput, multicast_group) else: print >> sys.stderr, "Unrecognized command\n\n" # cmdlist = message.split(' ') # if cmdlist[0] == 'iperf': # command = cmdlist[0]+" -c 192.168.0.2" # print >>sys.stderr, commands.getoutput(command) # continue # print cmdlist # sent = sock.sendto(message, multicast_group) # count = 0 # while count < 1: # try: # data, server = sock.recvfrom(16) # except socket.timeout: # continue # else: # print >>sys.stderr, 'recevied "%s"' % data # count = count + 1