From ee84a1484b93e8208a95bd38d090ff32c9371c6d Mon Sep 17 00:00:00 2001 From: janton01 Date: Sat, 17 Dec 2016 17:51:59 -0500 Subject: [PATCH] Cloud class defined and test function for the cloud started. --- cloud.py | 60 +++++++++++++++++++++++++++++++++++++++++----------- testCloud.py | 28 ++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 testCloud.py diff --git a/cloud.py b/cloud.py index 1248fb5..a452c6f 100644 --- a/cloud.py +++ b/cloud.py @@ -1,17 +1,53 @@ +import Queue + +# these delays can be seen as the time response time of the server for each game +# being played + +HI_P_CLOUD_DELAY = 10 +MED_P_CLOUD_DELAY = 5 +LOW_P_CLOUD_DELAY = 3 +NUM_PLAYERS = 10 +ks class Cloud(object): - def __init__(self, processor, gpu): - self.processor = processor - self.gpu = gpu + def __init__(self, gameTraffic, location, timeout): + + 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.location = location + self.timeMS = 0 + self.timeout = timeout + + def updateTime(self, time): # is this how it works? + self.timeMS = time + return processResponse(self) + + def processResponse(self): + + if self.timeMS % timeToProcess == 0 and not self.requestList.empty() : + headPacket = self.requestList.get(); + if (time - headPacket.timestamp) > timeout: + return None + else: + responsePackets[] + for i in range(1,NUM_PLAYERS): + newPacket = headPacket - def processData(self, data): - # Determine how much time it takes to process - time = data / gpu + # update packet + newPacket.sendAddress = 0 + newPacket.receiveAddress = i + responsePackets[i].append(newPacket) + return responsePackets + else: + return None -class AmazonWebService(Cloud): - def __init__(self): - super(AmazonWebService, self).__init__(3.5, 780) + def receiveRequest(self, packet): # can this access + self.requestList.put(packet) -clouds = { - "aws" : AmazonWebService() -} \ No newline at end of file diff --git a/testCloud.py b/testCloud.py new file mode 100644 index 0000000..d6f7140 --- /dev/null +++ b/testCloud.py @@ -0,0 +1,28 @@ +import cloud + + +if __name__ == "__main__": + packet1.id = 0 + packet1.sendAddress = 1 + packet1.receiveAddress = 0 + packet1.timestamp = 100 + packet2.id = 1 + packet2.sendAddress = 2 + packet2.receiveAddress = 0 + packet2.timestamp = 0 + + cloud = Cloud(0, 0, 10) + + cloud.receiveRequest(packet1) + cloud.receiveRequest(packet2) + + time = 90 + + for i in range(0,10): + time = time + 1 + packetList = cloud.updateTime(time) + if packetList != None: + print packetList[0].id + + +