65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
import random
|
|
import copy
|
|
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)
|
|
currentclient.application = copy.deepcopy(self.pickapplicationforclient())
|
|
for j in range(numoftransmissions):
|
|
currentclient.startSlices.append(
|
|
random.randint(1, self.simulationLength - self.maxLengthofTransmission))
|
|
self.clients.append(currentclient)
|