This commit is contained in:
62
src/scenarioplanner.py
Normal file
62
src/scenarioplanner.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user