From 11e966d08bfa090f36d9c5427b705518d8e69485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Fri, 3 Dec 2021 23:31:49 +0100 Subject: [PATCH] prepare for simulation fire --- src/bucketresources.py | 4 +++- src/clients.py | 4 ++++ src/main.py | 36 +++++++++++++++++++++++++++--------- src/scenarioplanner.py | 3 ++- src/scheduler.py | 9 +++++++++ src/stats.py | 8 ++++---- 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/bucketresources.py b/src/bucketresources.py index 0a16a46..64cc353 100644 --- a/src/bucketresources.py +++ b/src/bucketresources.py @@ -16,14 +16,16 @@ class BucketResource: if self.capacity == self.currentUsage or resource > self.capacity - self.currentUsage: return False else: + self.currentUsage += resource return True def release(self, resource: int) -> bool: if self.currentUsage == 0 or self.currentUsage - resource < 0: return False else: + self.currentUsage -= resource return True - def releaseAll(self) -> bool: + def releaseall(self) -> bool: self.currentUsage = 0 return True diff --git a/src/clients.py b/src/clients.py index 2f55d48..eb01824 100644 --- a/src/clients.py +++ b/src/clients.py @@ -1,4 +1,5 @@ from apps import Application +from datacentre import Datacentre class Client: @@ -6,3 +7,6 @@ class Client: self.startSlices: list[int] = [] self.lengthOfTransmission: int = 0 self.application: Application = Application() + + def firerequest(self, edge:Datacentre, cloud: Datacentre): + pass diff --git a/src/main.py b/src/main.py index fc11552..ff3619e 100644 --- a/src/main.py +++ b/src/main.py @@ -1,18 +1,36 @@ -from pprint import pprint +import copy +from datacentre import Datacentre from scenarioplanner import Scenarioplanner +from scheduler import Scheduler def preparesimulation() -> Scenarioplanner: - scenarioplanner = Scenarioplanner() - scenarioplanner.simulationLength = 120 - scenarioplanner.createapplications() - scenarioplanner.createclients(1000) - print("Number of Birbnetes clients: " + str(scenarioplanner.statsModule.birbnetesClients)) - print("Number of Videochat clients: " + str(scenarioplanner.statsModule.videochatClients)) - return scenarioplanner + currscenarioplanner = Scenarioplanner() + currscenarioplanner.simulationLength = 120 + currscenarioplanner.createapplications() + currscenarioplanner.createclients(1000) + print("Number of Birbnetes clients: " + str(currscenarioplanner.statsModule.birbnetesClients)) + print("Number of Videochat clients: " + str(currscenarioplanner.statsModule.videochatClients)) + return currscenarioplanner + + +def preparesimulationrunner(currscenarioplanner: Scenarioplanner) -> Scheduler: + currentscheduler = Scheduler() + currentscheduler.simulationLength = currscenarioplanner.simulationLength + currscenarioplanner.clients = copy.deepcopy(currscenarioplanner.clients) + clouddatacentre = Datacentre() + clouddatacentre.processingpower = 10000000 + clouddatacentre.uplink = 10000000 + edgedatacentre = Datacentre() + edgedatacentre.processingpower = 10000 + edgedatacentre.uplink = 10000 + currentscheduler.edge = edgedatacentre + currentscheduler.cloud = clouddatacentre + currentscheduler.statsModule = currscenarioplanner.statsModule + return currentscheduler if __name__ == '__main__': scenarioplanner = preparesimulation() - pprint(scenarioplanner) + currscheduler = preparesimulationrunner(scenarioplanner) diff --git a/src/scenarioplanner.py b/src/scenarioplanner.py index 9cdc995..3d34c8c 100644 --- a/src/scenarioplanner.py +++ b/src/scenarioplanner.py @@ -1,4 +1,5 @@ import random +import copy from clients import Client from stats import Stats from apps import Application, ApplicationModule @@ -56,7 +57,7 @@ class Scenarioplanner: currentclient: Client = Client() currentclient.lengthOfTransmission = random.randint(1, self.maxLengthofTransmission) numoftransmissions: int = random.randint(1, 10) - currentclient.application = self.pickapplicationforclient() + currentclient.application = copy.deepcopy(self.pickapplicationforclient()) for j in range(numoftransmissions): currentclient.startSlices.append( random.randint(1, self.simulationLength - self.maxLengthofTransmission)) diff --git a/src/scheduler.py b/src/scheduler.py index cac7891..959cd4d 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -1,6 +1,7 @@ from clients import Client from apps import Application, ApplicationModule from bucketresources import BucketResource, BucketResource +from stats import Stats from datacentre import Datacentre @@ -9,3 +10,11 @@ class Scheduler: self.clients: list[Client] = [] self.cloud: Datacentre = Datacentre() self.edge: Datacentre = Datacentre() + self.failedClients: list[Client] = [] + self.simulationLength: int = 0 + self.statsModule: Stats = Stats() + + def runsimulation(self): + for i in range(self.simulationLength): + for currclient in self.clients: + pass diff --git a/src/stats.py b/src/stats.py index b681761..08ab5e3 100644 --- a/src/stats.py +++ b/src/stats.py @@ -1,6 +1,6 @@ class Stats: def __init__(self): - self.birbnetesClients:int = 0 - self.videochatClients:int = 0 - self.failedReqsuests:int = 0 - self.failedDetails:dict = {} + self.birbnetesClients: int = 0 + self.videochatClients: int = 0 + self.failedReqsuests: int = 0 + self.failedDetails: dict = {}