diff --git a/.gitignore b/.gitignore index 72364f9..473c568 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,30 @@ ENV/ # Rope project settings .ropeproject + +# Mac OS +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/cloud.py b/cloud.py index 82b7878..cdd3013 100644 --- a/cloud.py +++ b/cloud.py @@ -1,52 +1,81 @@ import Queue +if __name__ == "__main__": import packet # these delays can be seen as the time response time of the server for each game -# being played +# being played -HI_P_CLOUD_DELAY = 10 -MED_P_CLOUD_DELAY = 5 -LOW_P_CLOUD_DELAY = 3 +TRAFFIC_DELAY = { 'high' : 10, 'med' : 5, 'low' : 3 } class Cloud(object): def __init__(self, gameTraffic, location, timeout, num_players): - + self.requestList = Queue.Queue() - if gameTraffic == 0: - self.timeToProcess = LOW_P_CLOUD_DELAY - elif gameTraffic == 1: - self.timeToProcess = MED_P_CLOUD_DELAY - else: - self.timeToProcess = HIGH_P_CLOUD_DELAY + self.timeToProcess = TRAFFIC_DELAY(gameTraffic) self.num_players = num_players self.location = location - self.timeMS = 0 self.timeout = timeout - def updateTime(self, time): - self.timeMS = time - return self.processResponse(time) - - def processResponse(self, time): - if self.timeMS % self.timeToProcess == 0 and not self.requestList.empty() : + def responseAt(self, time): + if time % self.timeToProcess == 0 and not self.requestList.empty() : headPacket = self.requestList.get(); - if (time - headPacket.timestamp) > self.timeout: + if (time - headPacket.timestamp) > self.timeout: return None - else: + else: responsePackets = [] for i in range(1,self.num_players): newPacket = headPacket - # update packet - newPacket.sendAddress = 0 - newPacket.receiveAddress = i + # update packet + newPacket.sender = 0 + newPacket.receiver = i + responsePackets.append(newPacket) return responsePackets else: return None - def receiveRequest(self, packet): + def receivePacket(self, packet): self.requestList.put(packet) + +if __name__ == "__main__": + packet1 = packet.Packet(100, 0, 0, 1) + packet2 = packet.Packet( 0, 0, 0, 2) + packet3 = packet.Packet(100, 0, 0, 1) + packet4 = packet.Packet( 100, 0, 0, 2) + + cloud = cloud.Cloud(0, 0, 10, 10) + + cloud.receivePacket(packet1) + cloud.receivePacket(packet4) + cloud.receivePacket(packet3) + cloud.receivePacket(packet2) + + time = 100 + print "\ntest 1: should return 3 packets" + for i in range(0,20): + #print time + packetList = cloud.updateTime(time) + if packetList != None: + print packetList[0].packet_id + time = time + 1 + + cloud.receivePacket(packet1) + cloud.receivePacket(packet2) + cloud.receivePacket(packet3) + cloud.receivePacket(packet4) + + time = 100 + print "\ntest 2: should return 2 packets" + + for i in range(0,20): + #print time + packetList = cloud.updateTime(time) + if packetList != None: + print packetList[0].packet_id + time = time + 1 + print "\n" + diff --git a/data.py b/data.py new file mode 100644 index 0000000..8d5649c --- /dev/null +++ b/data.py @@ -0,0 +1,41 @@ +import statistics +class Data(object): + + def __init__(self): + self.d = {} + + def putSend(self, id, sendTime): + if id not in self.d: + self.d[id] = { 'sendTime' : sendTime, 'receiveTime' : -1 } + else: + self.d[id]['sendTime'] = sendTime + + def putReceive(self, id, receiveTime): + if id not in self.d: + self.d[id] = { 'sendTime' : -1, 'receiveTime' : receiveTime } + else: + self.d[id]['receiveTime'] = receiveTime + + def rawData(self): + return self.d + + def sendTime(self, id): + return self.d[id]['sendTime'] + + def receiveTime(self, id): + return self.d[id]['receiveTime'] + + def latency(self, id): + if self.receiveTime(id) != -1: + return self.d[id]['receiveTime'] - self.d[id]['sendTime'] + else: + return None + + def latencyList(self): + return [self.latency(x) for x in self.d if self.latency(x) is not None] + + def averageLatency(self): + return statistics.median(self.latencyList) + + def numDropped(self): + return len([self.receiveTime(x) for x in self.d if self.receiveTime(x) is None]) diff --git a/device.py b/device.py index b95f47c..92c19ea 100644 --- a/device.py +++ b/device.py @@ -1,5 +1,6 @@ from packet import Packet from random import randint +from data import Data TICKS_PER_EVENT = 20 @@ -9,40 +10,25 @@ def __init__(self, deviceID, fps, ticksPerEvent, location): self.deviceID = deviceID self.fps = fps self.ticksPerEvent = ticksPerEvent + self.firstEventOffset = randint(0, ticksPerEvent - 1) self.location = location - - self.position = (randint(0, 10), randint(5, 20)) - self.timeMS = 0 - self.packetDict = {} - - def updateTime(self, time, packet=None): - if packet is None: - return self.sendPacket(time) - else: - self.receivePacket(time, packet) - + self.data = Data() - def sendPacket(self, time): - if time % self.ticksPerEvent == 0: - self.movePlayer(time) - packet = Packet(time, self.position, 0, self.deviceID) + def responseAt(self, time): + if (time + self.firstEventOffset) % self.ticksPerEvent == 0: + packet = Packet(time, 0, self.deviceID) id = packet.packet_id - self.packetDict[id] = {'sendTime' : time, 'receiveTime' : -1} + self.data.putSend(id, time) print 'Device: %d. Location: %s. Packet sent: %s. Timestamp: %s' % (self.deviceID, self.location, packet.packet_id, packet.timestamp) - return packet - return None - - def receivePacket(self, time, packet): - print 'Device: %d. Location: %s. Packet received: %s. Timestamp: %s' % (self.deviceID, self.location, packet.packet_id, packet.timestamp) - id = packet.packet_id - if id in self.packetDict.keys(): - self.packetDict[id]['receiveTime'] = time + return [packet] else: - # stray packet received - self.packetDict[id] = {'sendTime' : -1, 'receiveTime' : time} + return [] - def movePlayer(self, time): - self.position = (randint(0, 10), randint(5, 50)) + def receivePacket(packet): + id = packet.packet_id + arrival = packet.arriveTime() + self.data.putReceive(id, arrival) + print 'Device: %d. Location: %s. Packet received: %s. Timestamp: %s' % (self.deviceID, self.location, packet.packet_id, packet.timestamp) class OculusRift(Device): @@ -67,4 +53,4 @@ def __init__(self, deviceID, location): class VisusVR(Device): def __init__(self, deviceID, location): - super(VisusVR, self).__init__(deviceID, 60, TICKS_PER_EVENT, location) \ No newline at end of file + super(VisusVR, self).__init__(deviceID, 60, TICKS_PER_EVENT, location) diff --git a/location.py b/location.py index b8b6372..6a20b7f 100644 --- a/location.py +++ b/location.py @@ -1,119 +1,120 @@ import random class Location(object): - + calculator = None - + def __init__(self, location = None): if not Location.calculator: Location.calculator = LocationCalculator() self.city = location if location else random.choice(Location.calculator.locations) - def propogationDelayFrom(self, location): - return Location.calculator.getPropogation(self.city, location.city) + def propagationDelayFrom(self, location): + return Location.calculator.getPropagation(self.city, location.city) class LocationCalculator(object): def __init__(self): - self.propogations = {} - self.createPropogationMatrix() + self.propagations = {} + self.createPropagationMatrix() - def addPropogation(self, c1, c2, delay): + def addPropagation(self, c1, c2, delay): pair = (c1, c2) if c1 < c2 else (c2, c1) - self.propogations[pair] = delay + self.propagations[pair] = delay - def getPropogation(self, c1, c2): + def getPropagation(self, c1, c2): if c1 == c2: return 5 pair = (c1, c2) if c1 < c2 else (c2, c1) - if pair in self.propogations: - return self.propogations[pair] + if pair in self.propagations: + return self.propagations[pair] return None locations = { - "Atlanta" - "Austin", - "Cambridge", - "Chicago", - "Denver", - "New York", - "Orlando", - "Philadelphia", - "San Francisco", - "Seattle", + "Atlanta", + "Austin", + "Cambridge", + "Chicago", + "Denver", + "New York", + "Orlando", + "Philadelphia", + "San Francisco", + "Seattle", "Washington" } - def createPropogationMatrix(self): - self.addPropogation("Atlanta", "Austin", 24) - self.addPropogation("Atlanta", "Cambridge", 29) - self.addPropogation("Atlanta", "Chicago", 26) - self.addPropogation("Atlanta", "Denver", 38) - self.addPropogation("Atlanta", "New York", 24) - self.addPropogation("Atlanta", "Orlando", 11) - self.addPropogation("Atlanta", "Philadelphia", 22) - self.addPropogation("Atlanta", "San Francisco", 60) - self.addPropogation("Atlanta", "Seattle", 72) - self.addPropogation("Atlanta", "Washington", 19) - - self.addPropogation("Austin", "Cambridge", 52) - self.addPropogation("Austin", "Chicago", 33) - self.addPropogation("Austin", "Denver", 25) - self.addPropogation("Austin", "New York", 45) - self.addPropogation("Austin", "Orlando", 28) - self.addPropogation("Austin", "Philadelphia", 46) - self.addPropogation("Austin", "San Francisco", 49) - self.addPropogation("Austin", "Seattle", 58) - self.addPropogation("Austin", "Washington", 40) - - self.addPropogation("Cambridge", "Chicago", 27) - self.addPropogation("Cambridge", "Denver", 47) - self.addPropogation("Cambridge", "New York", 6) - self.addPropogation("Cambridge", "Orlando", 40) - self.addPropogation("Cambridge", "Philadelphia", 9) - self.addPropogation("Cambridge", "San Francisco", 76) - self.addPropogation("Cambridge", "Seattle", 72) - self.addPropogation("Cambridge", "Washington", 11) - - self.addPropogation("Chicago", "Denver", 21) - self.addPropogation("Chicago", "New York", 20) - self.addPropogation("Chicago", "Orlando", 37) - self.addPropogation("Chicago", "Philadelphia", 18) - self.addPropogation("Chicago", "San Francisco", 50) - self.addPropogation("Chicago", "Seattle", 47) - self.addPropogation("Chicago", "Washington", 22) - - self.addPropogation("Denver", "New York", 42) - self.addPropogation("Denver", "Orlando", 46) - self.addPropogation("Denver", "Philadelphia", 39) - self.addPropogation("Denver", "San Francisco", 30) - self.addPropogation("Denver", "Seattle", 34) - self.addPropogation("Denver", "Washington", 42) - - self.addPropogation("New York", "Orlando", 35) - self.addPropogation("New York", "Philadelphia", 4) - self.addPropogation("New York", "San Francisco", 71) - self.addPropogation("New York", "Seattle", 68) - self.addPropogation("New York", "Washington", 5) - - self.addPropogation("Orlando", "Philadelphia", 33) - self.addPropogation("Orlando", "San Francisco", 68) - self.addPropogation("Orlando", "Seattle", 81) - self.addPropogation("Orlando", "Washington", 30) - - self.addPropogation("Philadelphia", "San Francisco", 68) - self.addPropogation("Philadelphia", "Seattle", 64) - self.addPropogation("Philadelphia", "Washington", 30) - - self.addPropogation("San Francsico", "Seattle", 60) - self.addPropogation("San Francsico", "Washington", 41) - - self.addPropogation("Washington", "Seattle", 68) + def createPropagationMatrix(self): + self.addPropagation("Atlanta", "Austin", 24) + self.addPropagation("Atlanta", "Cambridge", 29) + self.addPropagation("Atlanta", "Chicago", 26) + self.addPropagation("Atlanta", "Denver", 38) + self.addPropagation("Atlanta", "New York", 24) + self.addPropagation("Atlanta", "Orlando", 11) + self.addPropagation("Atlanta", "Philadelphia", 22) + self.addPropagation("Atlanta", "San Francisco", 60) + self.addPropagation("Atlanta", "Seattle", 72) + self.addPropagation("Atlanta", "Washington", 19) + + self.addPropagation("Austin", "Cambridge", 52) + self.addPropagation("Austin", "Chicago", 33) + self.addPropagation("Austin", "Denver", 25) + self.addPropagation("Austin", "New York", 45) + self.addPropagation("Austin", "Orlando", 28) + self.addPropagation("Austin", "Philadelphia", 46) + self.addPropagation("Austin", "San Francisco", 49) + self.addPropagation("Austin", "Seattle", 58) + self.addPropagation("Austin", "Washington", 40) + + self.addPropagation("Cambridge", "Chicago", 27) + self.addPropagation("Cambridge", "Denver", 47) + self.addPropagation("Cambridge", "New York", 6) + self.addPropagation("Cambridge", "Orlando", 40) + self.addPropagation("Cambridge", "Philadelphia", 9) + self.addPropagation("Cambridge", "San Francisco", 76) + self.addPropagation("Cambridge", "Seattle", 72) + self.addPropagation("Cambridge", "Washington", 11) + + self.addPropagation("Chicago", "Denver", 21) + self.addPropagation("Chicago", "New York", 20) + self.addPropagation("Chicago", "Orlando", 37) + self.addPropagation("Chicago", "Philadelphia", 18) + self.addPropagation("Chicago", "San Francisco", 50) + self.addPropagation("Chicago", "Seattle", 47) + self.addPropagation("Chicago", "Washington", 22) + + self.addPropagation("Denver", "New York", 42) + self.addPropagation("Denver", "Orlando", 46) + self.addPropagation("Denver", "Philadelphia", 39) + self.addPropagation("Denver", "San Francisco", 30) + self.addPropagation("Denver", "Seattle", 34) + self.addPropagation("Denver", "Washington", 42) + + self.addPropagation("New York", "Orlando", 35) + self.addPropagation("New York", "Philadelphia", 4) + self.addPropagation("New York", "San Francisco", 71) + self.addPropagation("New York", "Seattle", 68) + self.addPropagation("New York", "Washington", 5) + + self.addPropagation("Orlando", "Philadelphia", 33) + self.addPropagation("Orlando", "San Francisco", 68) + self.addPropagation("Orlando", "Seattle", 81) + self.addPropagation("Orlando", "Washington", 30) + + self.addPropagation("Philadelphia", "San Francisco", 68) + self.addPropagation("Philadelphia", "Seattle", 64) + self.addPropagation("Philadelphia", "Washington", 30) + + self.addPropagation("San Francsico", "Seattle", 60) + self.addPropagation("San Francsico", "Washington", 41) + + self.addPropagation("Seattle", "Washington", 68) if __name__ == "__main__": loc1 = Location("Washington") loc2 = Location("Chicago") - print "Delay from " + loc1.city + " to " + loc2.city + " is " + str(loc1.propogationDelayFrom(loc2)) + " ms" \ No newline at end of file + print "Delay from " + loc1.city + " to " + loc2.city + " is + " + str(loc1.propagationDelayFrom(loc2)) + " ms" diff --git a/network.py b/network.py index f1e41b6..2719c45 100644 --- a/network.py +++ b/network.py @@ -7,39 +7,39 @@ def __init__(self, packet_loss_prob): self.packet_loss_prob = packet_loss_prob / 100.0 pass - def sendPacket(self, packet, loc1, loc2): + def networkDelay(self, loc1, loc2): # Check for packet loss if random.random() < self.packet_loss_prob: - return 0 + return -1 - # Otherwise, return propogation delay - return loc1.propogationDelayFrom(loc2) + # Otherwise, return propagation delay + return loc1.propagationDelayFrom(loc2) class TCP(Network): TIMEOUT_RATE = 100 # ms HEADER_PROCESSING = 5 # ms - + def __init__(self, packet_loss_prob): super(TuftsSecure, self).__init__(packet_loss_prob) - def sendPacket(self, packet, loc1, loc2): - propDelay = Network.sendPacket(packet, loc1, loc2) + def networkDelay(self, loc1, loc2): + propDelay = Network.networkDelay(loc1, loc2) propDelay += TCP.HEADER_PROCESSING if propDelay >= TCP.HEADER_PROCESSING: return propDelay * 2 else: - return TCP.TIMEOUT_RATE + self.sendPacket(packet, loc1, loc2) + return TCP.TIMEOUT_RATE + self.networkDelay(loc1, loc2) class UDP(Network): HEADER_PROCESSING = 2 # ms - + def __init__(self, packet_loss_prob): super(TuftsSecure, self).__init__(packet_loss_prob) - def sendPacket(self, packet, loc1, loc2): - propDelay = Network.sendPacket(packet, loc1, loc2) + def networkDelay(self, loc1, loc2): + propDelay = Network.networkDelay(loc1, loc2) propDelay += UDP.HEADER_PROCESSING if propDelay >= UDP.HEADER_PROCESSING: return propDelay @@ -54,6 +54,6 @@ def sendPacket(self, packet, loc1, loc2): # Timeout test network = Network(2) # 2 percent chance to drop packet attempts = 0 - while network.sendPacket(0, loc1, loc2): + while network.networkDelay(loc1, loc2) != -1: attempts += 1 - print "Network dropped packet after " + str(attempts + 1) + " packets sent" \ No newline at end of file + print "Network dropped packet after " + str(attempts + 1) + " packets sent" diff --git a/packet.py b/packet.py index 4a886a3..48ce818 100644 --- a/packet.py +++ b/packet.py @@ -2,12 +2,23 @@ class Packet(object): - def __init__(self, timestamp, position, receiverAddress, senderAddress): + def __init__(self, timestamp, receiver, sender): self._init_packet_id() self.timestamp = timestamp - self.position = position - self.receiverAddress = receiverAddress - self.senderAddress = senderAddress + self.receiver = receiver + self.sender = sender + self.elapsedTime = 0 + self.phase = 'network->cloud' def _init_packet_id(self): - self.packet_id = uuid.uuid4() # generate a random UUID \ No newline at end of file + self.packet_id = uuid.uuid4() # generate a random UUID + + def addLatency(self, elapsedTime): + self.elapsedTime += elapsedTime + + def isReady(self, time): + return timestamp + elapsedTime >= time + + def arriveTime(self): + return timestamp + elapsedTime + diff --git a/simulator.py b/simulator.py index 0c2aee3..ef713dd 100644 --- a/simulator.py +++ b/simulator.py @@ -1,13 +1,88 @@ -import cloud, device, game, network +import cloud, device, network, packet, data +import heapq + +CLOUD = 0 +MAX_PACKETS_PER_STEP = 350 # https://blog.cloudflare.com/how-to-receive-a-million-packets/ class Simulator(object): - def __init__ (cloud, network, device, game): - self.cloud = cloud + def __init__(self, cloud, network, devices, simTime): + self.endpoints = [cloud] + devices self.network = network - self.device = device - self.game = game + self.time = 0 + self.endTime = simTime + + # Priority queue of tuples (timestamp+elapsedtime, packet) + self.activePackets = [] + + def run(self): + for timeStep in xrange(self.endTime): + self.runStep(timeStep) + + def getResults(self): + results = [] + for deviceID in xrange(1, self.numEndpoints()): + results.append(self.endpoints[deviceID].data) + return results + + def numEndpoints(self): + return len(self.endpoints) + + def runStep(self, step): + self.deliverReadyPackets(step) + self.updateActivePackets(step) + + def sendThruNetwork(self, packet): + senderLocation = self.locationOf(packet.sender) + receiverLocation = self.locationOf(packet.receiver) + response = self.network.networkDelay(senderLocation, receiverLocation) + if notDropped(reponse): + delay = response + packet.addLatency(delay) + return packet + else: + return None + + def addActivePacket(self, packet): + toAdd = (packet.arriveTime(), packet) + heapq.heappush(self.activePackets, toAdd) + + def nextActivePacket(self): + return self.activePackets[0][1] + + def hasActivePackets(self): + return len(self.activePackets) > 0 + + def popActivePacket(self): + return heapq.heappop(self.activePackets) + + def deliverReadyPackets(self, step): + self.resetDeliveryCounts() + if self.hasActivePackets() and self.nextActivePacket().isReady(step): + self.deliverPacket(self.popActivePacket()) + + def deliverPacket(self, packet): + dest = packet.receiver + if self.deliveryCounts[dest] <= MAX_PACKETS_PER_STEP: + self.endpoints[dest].receivePacket(packetToDeliver) + self.incrementDeliveryCountFor(dest) + + def incrementDeliveryCountFor(self, deviceID): + self.deliveryCounts[deviceID] += 1 + + def updateActivePackets(self, step): + for endpoint in self.endpoints: + response = endpoint.responseAt(step) + for packet in response: + self.queuePacket(packet) + + def queuePacket(packet): + networkResponse = self.sendThruNetwork(packet) + if isinstance(networkResponse, Packet): + self.addActivePacket(networkResponse) + + def resetDeliveryCounts(self): + self.deliveryCounts = [0] * len(self.endpoints) - def run(): - # TODO: Use the 4 classes to produce meaningful data - pass \ No newline at end of file + def locationOf(self, deviceID): + return self.endpoints[deviceID].location diff --git a/testCloud.py b/testCloud.py index ab68d0e..c1a7d0d 100644 --- a/testCloud.py +++ b/testCloud.py @@ -2,41 +2,41 @@ import packet if __name__ == "__main__": - - packet1 = packet.Packet(100, 0, 0, 1) - packet2 = packet.Packet( 0, 0, 0, 2) - packet3 = packet.Packet(100, 0, 0, 1) - packet4 = packet.Packet( 100, 0, 0, 2) - - cloud = cloud.Cloud(0, 0, 10, 10) - - cloud.receiveRequest(packet1) - cloud.receiveRequest(packet4) - cloud.receiveRequest(packet3) - cloud.receiveRequest(packet2) - - time = 100 - print "\ntest 1: should return 3 packets" - for i in range(0,20): - #print time - packetList = cloud.updateTime(time) - if packetList != None: + + packet1 = packet.Packet(100, 0, 0, 1) + packet2 = packet.Packet( 0, 0, 0, 2) + packet3 = packet.Packet(100, 0, 0, 1) + packet4 = packet.Packet( 100, 0, 0, 2) + + cloud = cloud.Cloud(0, 0, 10, 10) + + cloud.receiveRequest(packet1) + cloud.receiveRequest(packet4) + cloud.receiveRequest(packet3) + cloud.receiveRequest(packet2) + + time = 100 + print "\ntest 1: should return 3 packets" + for i in range(0,20): + #print time + packetList = cloud.updateTime(time) + if packetList != None: print packetList[0].packet_id - time = time + 1 + time = time + 1 - cloud.receiveRequest(packet1) - cloud.receiveRequest(packet2) - cloud.receiveRequest(packet3) - cloud.receiveRequest(packet4) + cloud.receiveRequest(packet1) + cloud.receiveRequest(packet2) + cloud.receiveRequest(packet3) + cloud.receiveRequest(packet4) - time = 100 - print "\ntest 2: should return 2 packets" + time = 100 + print "\ntest 2: should return 2 packets" - for i in range(0,20): - #print time - packetList = cloud.updateTime(time) - if packetList != None: + for i in range(0,20): + #print time + packetList = cloud.updateTime(time) + if packetList != None: print packetList[0].packet_id - time = time + 1 - print "\n" + time = time + 1 + print "\n" diff --git a/visualizer.py b/visualizer.py new file mode 100644 index 0000000..3c15696 --- /dev/null +++ b/visualizer.py @@ -0,0 +1,25 @@ +from plotly.plotly import iplot as plot +from plotly import graph_objs as graph + +import statistics + +class Visualizer(object): + # data should be a list of Data, where each list element corresponds to + # the results of a device + def __init__(self, data, labels): + self.data = data + self.labels = labels + + def visualize(data, labels, file = 'results/tmp'): + data = [graph.Bar( + x = labels, + y = data + )] + plot(data, filename=file) + + def plotAverageLatency(self): + labels = map(str, range(len(self.data))) # "0", "1", "2", ... + data = [device.averageLatency() for device in self.data] + outputFile = 'average_latency' + visualize(data, labels, outputFile) + diff --git a/vr_simulation.py b/vr_simulation.py index 1dbe614..9e3e621 100644 --- a/vr_simulation.py +++ b/vr_simulation.py @@ -1,10 +1,38 @@ -import simulator -from cloud import clouds -from device import devices -from game import games -from network import networks +from simulator import Simulator +from visualizer import Visualizer +from cloud import Cloud +from device import Device +from network import Network +import random print networks print "Tufts download speed is " + str(networks['tufts'].download) + " Mbps." -# TODO: Be run with passed configurations, create simulator, and produce results \ No newline at end of file +# Initialize devices +DEVICE_OPTS = { OculusRift, HTCVive, PlayStationVR, LG360VR, GearVR, VisusVR } +devices = [] +for i in xrange(1, 11): + device = random.choice(DEVICE_OPTS) + loc = Location() # Select at random + devices.append(device(i, loc)) + +# Initialize cloud +traffic_level = 0 +cloud_loc = Location() +timeout = 2000 # 2 seconds +num_players = len(devices) +cloud = Cloud(traffic_level, cloud_loc, timeout, num_players) + +# Initialize network +network = TCP(); + +sim_length = 30 * 60 * 1000 # 30 minutes +sim = Simulator(cloud, network, devices, sim_length) + +sim.run() +results = sim.getResults() + +viz = Visualizer(results, map(str, range(1,11))) +viz.plotAverageLatency() + +# TODO: Be run with passed configurations, create simulator, and produce results