diff --git a/src/apps.py b/src/apps.py index 92ea1c8..646302c 100644 --- a/src/apps.py +++ b/src/apps.py @@ -1,8 +1,10 @@ class ApplicationModule: - bwRequirement: int = 0 - cpuRequirement: int = 0 + def __init__(self): + self.bwRequirement: int = 0 + self.cpuRequirement: int = 0 class Application: - name: str = "" - modules: list[ApplicationModule] = [] + def __init__(self): + self.name: str = "" + self.modules: list[ApplicationModule] = [] diff --git a/src/bucketresources.py b/src/bucketresources.py index 00e4e65..0a16a46 100644 --- a/src/bucketresources.py +++ b/src/bucketresources.py @@ -7,9 +7,10 @@ class BucketResourceType(Enum): class BucketResource: - type: BucketResourceType = BucketResourceType.NetworkLink - currentUsage: int = 0 - capacity: int = 0 + def __init__(self): + self.type: BucketResourceType = BucketResourceType.NetworkLink + self.currentUsage: int = 0 + self.capacity: int = 0 def reserve(self, resource: int) -> bool: if self.capacity == self.currentUsage or resource > self.capacity - self.currentUsage: diff --git a/src/clients.py b/src/clients.py index 6995b0a..2326836 100644 --- a/src/clients.py +++ b/src/clients.py @@ -2,6 +2,7 @@ from apps import Application class Client: - startSlices: list[int] = [] - lengthOfTransmission: int = 0 - application: Application = Application() + def __init__(self): + self.startSlices: list[int] = [] + self.lengthOfTransmission:int = 0 + self.application: Application = Application() \ No newline at end of file diff --git a/src/datacentre.py b/src/datacentre.py index b17cd1a..e096d1b 100644 --- a/src/datacentre.py +++ b/src/datacentre.py @@ -2,5 +2,6 @@ from bucketresources import BucketResource class Datacentre: - processingpower: BucketResource = BucketResource() - uplink: BucketResource = BucketResource() + def __init__(self): + self.processingpower: BucketResource = BucketResource() + self.uplink: BucketResource = BucketResource() diff --git a/src/main.py b/src/main.py index 5596b44..b416c1b 100644 --- a/src/main.py +++ b/src/main.py @@ -1,16 +1,17 @@ -# This is a sample Python script. +from pprint import pprint -# Press Shift+F10 to execute it or replace it with your code. -# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. +from scenarioplanner import Scenarioplanner +from src import scenarioplanner -def print_hi(name): - # Use a breakpoint in the code line below to debug your script. - print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. +def preparesimulation() -> Scenarioplanner: + scenarioplanner = Scenarioplanner() + scenarioplanner.simulationLength = 120 + scenarioplanner.createapplications() + scenarioplanner.createclients(1000) + return scenarioplanner -# Press the green button in the gutter to run the script. if __name__ == '__main__': - print_hi('PyCharm') - -# See PyCharm help at https://www.jetbrains.com/help/pycharm/ + scenarioplanner = preparesimulation() + pprint(scenarioplanner) diff --git a/src/scenarioplanner.py b/src/scenarioplanner.py new file mode 100644 index 0000000..2a5bbaf --- /dev/null +++ b/src/scenarioplanner.py @@ -0,0 +1,62 @@ +import random +from clients import Client +from stats import Stats +from apps import Application, ApplicationModule + + +class Scenarioplanner: + def __init__(self): + self.clients: list[Client] = [] + self.applications: list[Application] = [] + self.statsModule: Stats = Stats() + self.simulationLength: int = 0 + self.maxLengthofTransmission: int = 60 + + def createbirbnetes(self) -> Application: + birbnetes = Application() + birbnetes.name = 'birbnetes' + edgemodule = ApplicationModule() + edgemodule.bwRequirement = 8800 + edgemodule.cpuRequirement = 1000 + cloudmodule = ApplicationModule() + cloudmodule.bwRequirement = 10000 + cloudmodule.cpuRequirement = 10000 + birbnetes.modules.append(edgemodule) + birbnetes.modules.append(cloudmodule) + return birbnetes + + def createvideoChat(self) -> Application: + videochat = Application() + videochat.name = 'videochat' + edgemodule = ApplicationModule() + edgemodule.bwRequirement = 90000 + edgemodule.cpuRequirement = 10 + cloudmodule = ApplicationModule() + cloudmodule.bwRequirement = 90000 + cloudmodule.cpuRequirement = 10 + videochat.modules.append(edgemodule) + videochat.modules.append(cloudmodule) + return videochat + + def createapplications(self) -> None: + self.applications.append(self.createbirbnetes()) + self.applications.append(self.createvideoChat()) + + def pickapplicationforclient(self) -> Application: + chosenapplication = random.choice(self.applications) + if chosenapplication.name == 'birbnetes': + self.statsModule.birbnetesClients += 1 + else: + if chosenapplication.name == 'videochat': + self.statsModule.videochatClients += 1 + return chosenapplication + + def createclients(self, numofclients: int = 1) -> None: + for i in range(numofclients): + currentclient: Client = Client() + currentclient.lengthOfTransmission = random.randint(1, self.maxLengthofTransmission) + numoftransmissions: int = random.randint(1, 10) + for j in range(numoftransmissions): + currentclient.startSlices.append( + random.randint(1, self.simulationLength - self.maxLengthofTransmission)) + self.clients.append(currentclient) diff --git a/src/scheduler.py b/src/scheduler.py index ac7656a..cac7891 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -5,9 +5,7 @@ from datacentre import Datacentre class Scheduler: - clients: list[Client] = [] - cloud: Datacentre = Datacentre() - edge: Datacentre = Datacentre() - - def createClients(self, numofClients: int = 1): - pass + def __init__(self): + self.clients: list[Client] = [] + self.cloud: Datacentre = Datacentre() + self.edge: Datacentre = Datacentre() diff --git a/src/stats.py b/src/stats.py new file mode 100644 index 0000000..b681761 --- /dev/null +++ b/src/stats.py @@ -0,0 +1,6 @@ +class Stats: + def __init__(self): + self.birbnetesClients:int = 0 + self.videochatClients:int = 0 + self.failedReqsuests:int = 0 + self.failedDetails:dict = {}