def main(): if len(sys.argv) < 6: print "Usage:\n{} <interface> <entity_title> <workspace_title> <input port> <output port>".format( sys.argv[0]) sys.exit(1) iface = sys.argv[1] e = dts.Entity(iface, sys.argv[2], True) print 'Entity "{}" registered.'.format(e.title) w = dts.Workspace(iface, sys.argv[3], True, 1500, 'MMstreaming') try: w.attach(e) print 'Attached to workspace "{}".'.format(w.title) except dts.DTSException: # Failed to attach, probably does not exists, # then try to create print 'Failed to attach, trying to create' w.create_on_dts(e) print 'Created workspace "{}" and attached to it.'.format(w.title) def DTSreader_loop(): try: while True: msg = w.recv() sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.sendto(msg, ('127.0.0.1', int(sys.argv[5]))) #sock.sendto(msg, ('10.0.0.5', int(sys.argv[5]))) except gevent.GreenletExit, KeyboardInterrupt: pass
def main(): if len(sys.argv) < 4 or len(sys.argv) > 6: print "Usage:\n{} <interface> <entity_title> <workspace_title> [qosRequired] [bwRequired]".format(sys.argv[0]) sys.exit(1) iface = sys.argv[1] e = dts.Entity(iface, sys.argv[2], True) print 'Entity "{}" registered.'.format(e.title) try: if sys.argv[4] in ['true', 'yes', 'on']: qosRequired = True else: qosRequired = False except IndexError: qosRequired = False try: bwRequired = int(sys.argv[5]) except IndexError: bwRequired = 0 w = dts.Workspace(iface, sys.argv[3], qosRequired, bwRequired) try: w.attach(e) print 'Attached to workspace "{}".'.format(w.title) except dts.DTSException: # Failed to attach, probably does not exists, # then try to create print 'Failed to attach, trying to create' w.create_on_dts(e) print 'Created workspace "{}" and attached to it.'.format(w.title) def reader_loop(): try: while True: msg = w.recv() sys.stdout.write(msg) except gevent.GreenletExit, KeyboardInterrupt: pass
def main(): if len(sys.argv) < 4: print "Usage:\n{} <interface> <entity_title> <workspace_title> <interval in ms>".format( sys.argv[0]) print sys.argv[0] print '\n' print sys.argv[1] print '\n' print sys.argv[2] print '\n' sys.exit(1) iface = sys.argv[1] e = dts.Entity(iface, sys.argv[2], True) print 'Entity "{}" registered.'.format(e.title) resp = hashlib.sha256(sys.argv[3]).digest()[:6] w = dts.Workspace(iface, sys.argv[3]) try: w.attach(e) print 'Attached to workspace "{}".'.format(w.title) except dts.DTSException: # Failed to attach, probably does not exists, # then try to create print 'Failed to attach, trying to create' w.create_on_dts(e) print 'Created workspace "{}" and attached to it.'.format(w.title) def reader_loop(): try: while True: msg = w.recv() sys.stdout.write(msg) except gevent.GreenletExit, KeyboardInterrupt: pass
def __init__(self, max_rate=2500, num_flows=10000, pkt_size=100, flow_size_cdf={ 0.999: 10, 0.9999: 100, 0.99999: 1000, 1.0: 100000, }, num_src_machines=100, num_dst_machines=100, iface="eth0", batch_size=1, entity='e', workspace='w'): ''' Initialize a packet generator instance with the specified parameters: - max_rate: maximum bitrate to gen packets in kbps - num_flows: total num of active flows at any given time - pkt_size: packet size - dst_ports_pdf: a dict mapping cdf -> port num "random" can be used instead of port num. - flow_size_pdf: a dict mapping cdf -> flow sizes in packets - num_src/dst_machines: total number of machines this flow generator will simulate - src/dst_ip_prefix: subnet the machines will use as source and dst addresses format: "x.x.x.x/int" - src/dst_mac_prefix: specify the macs for the machines. format:"xx:xx:xx:xx:xx:xx/int" - src/dst_mac_list: If specified, this will override the prefix - iface: name of interface to send packets on ''' self.batch_size = batch_size self.max_flows = num_flows self.flow_size_cdf = flow_size_cdf self.pkt_size = pkt_size self.cdf_counter = 0 self.workspace = workspace self.entity = entity # Calculate the delay between packets to maintain bitrate self.delay = self.batch_size * pkt_size * 8.0 / max_rate / 1000 #print "Delay: %s ms" % (self.delay*1000) # maintains the active flow set self.flows = [] # what flow should a packet come from? self.next_flow = 0 # socket to use if AS_ROOT: e = dts.Entity(iface, entity, True) print 'Entity "{}" registered.'.format(e.title) w = dts.Workspace(iface, workspace) try: w.attach(e) print 'Attached to workspace "{}".'.format(w.title) except dts.DTSException: # Failed to attach, probably does not exists, # then try to create w.create_on_dts(e) print 'Created workspace "{}" and attached to it.'.format( w.title) super(FlowGenerator, self).__init__() self.total_sent = 0 # cache the creation of a packet self.eth = ImpactPacket.Ethernet() self.ip = ImpactPacket.IP() self.udp = ImpactPacket.UDP() data_len = (pkt_size - self.eth.get_header_size() - self.ip.get_header_size() - self.udp.get_header_size()) data = ImpactPacket.Data() data.set_bytes(array.array('B', [i % 0xff for i in range(data_len)])) self.udp.contains(data) self.ip.contains(self.udp) self.eth.contains(self.ip) self.calibrated = False
def main(): argp = ArgumentParser( version='1.0', description="ETArch's SMART chat with QoS support", ) helpType = 'NC: Network Control | telephony: Telephony | \ MMconferencing: Multimedia Conferencing | RT: Real-Time Interactive | \ MMstreaming: Multimedia Streaming |\ bVideo: Broadcast Video' argp.add_argument('-i', '--iface', metavar='INTERFACE', type=str, help='interface') argp.add_argument('-e', '--entity', type=str, help='entity title') argp.add_argument('-w', '--workspace', required=True, type=str, help='workspace title') argp.add_argument('--interval', type=int, help='interval in ms') argp.add_argument('-q', '--QoS', action='store_const', const=True, help='require Quality of Service aware routing') argp.add_argument('-bw', '--bandwidth', type=int, help='bandwidth allocation required') argp.add_argument('-t', '--type', choices=[ 'NC', 'telephony', 'MMconferencing', 'RT', 'MMstreaming', 'bVideo' ], help=helpType) argp.add_argument('-vs', '--server', metavar='FILE', type=str, help='start a ffmpeg video server on this host') argp.add_argument('-vc', '--client', action='store_const', const=True, help='start a ffmpeg video client on this host') argp.add_argument('-b', '--bitrate', type=int, help='bitrate for the ffmpeg video server (Kbits/s)') args = argp.parse_args() #print vars(args) if args.type and not args.bandwidth: argp.print_usage() print 'chat.py: error: argument -bw/--bandwidth is required' sys.exit(1) if args.bitrate and not args.server: argp.print_usage() print 'chat.py: error: argument -vs/--server is required' sys.exit(1) if args.iface: iface = args.iface else: iface = netifaces.interfaces()[1] if netifaces.interfaces( )[0] == 'lo' else netifaces.interfaces()[0] if args.entity: entity = args.entity else: entity = iface.partition('-')[0] if iface.partition( '-')[0][0] == 'h' else iface.partition('-')[2] e = dts.Entity(iface, entity, True) print 'Entity "{}" registered.'.format(e.title) w = dts.Workspace(iface, args.workspace, args.QoS, args.bandwidth, args.type) try: w.attach(e) print 'Attached to workspace "{}".'.format(w.title) except dts.DTSException: # Failed to attach, probably does not exists, # then try to create print 'Failed to attach, trying to create' w.create_on_dts(e) print 'Created workspace "{}" and attached to it.'.format(w.title) if not args.client: def reader_loop(): try: while True: msg = w.recv() sys.stdout.write(msg) except gevent.GreenletExit, KeyboardInterrupt: pass reader = gevent.spawn(reader_loop)
mode="server" elif opt=="-a": addr=opt_l.pop(0) elif opt=="-d": TR=float(opt_l.pop(0)) elif opt=="-l": PL=int(opt_l.pop(0)) elif opt=="-n": NP=int(opt_l.pop(0)) #s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) iface = 'h2-eth0' e = dts.Entity(iface, entity, True) print 'Entity "{}" registered.'.format(e.title) w = dts.Workspace(iface, workspace) try: w.attach(e) print 'Attached to workspace "{}".'.format(w.title) except dts.DTSException: # Failed to attach, probably does not exists, # then try to create w.create_on_dts(e) print 'Created workspace "{}" and attached to it.'.format(w.title) sleep_delay=PL*8.0/TR PLOVER=8+20+8 # 8 byte seq and stamp, 20 byte IP header, 8 byte UDP header PL2=PL-PLOVER