This commit is contained in:
parent
35a68fe549
commit
a9f473e2d9
10
src/apps.py
10
src/apps.py
@ -1,8 +1,10 @@
|
|||||||
class ApplicationModule:
|
class ApplicationModule:
|
||||||
bwRequirement: int = 0
|
def __init__(self):
|
||||||
cpuRequirement: int = 0
|
self.bwRequirement: int = 0
|
||||||
|
self.cpuRequirement: int = 0
|
||||||
|
|
||||||
|
|
||||||
class Application:
|
class Application:
|
||||||
name: str = ""
|
def __init__(self):
|
||||||
modules: list[ApplicationModule] = []
|
self.name: str = ""
|
||||||
|
self.modules: list[ApplicationModule] = []
|
||||||
|
@ -7,9 +7,10 @@ class BucketResourceType(Enum):
|
|||||||
|
|
||||||
|
|
||||||
class BucketResource:
|
class BucketResource:
|
||||||
type: BucketResourceType = BucketResourceType.NetworkLink
|
def __init__(self):
|
||||||
currentUsage: int = 0
|
self.type: BucketResourceType = BucketResourceType.NetworkLink
|
||||||
capacity: int = 0
|
self.currentUsage: int = 0
|
||||||
|
self.capacity: int = 0
|
||||||
|
|
||||||
def reserve(self, resource: int) -> bool:
|
def reserve(self, resource: int) -> bool:
|
||||||
if self.capacity == self.currentUsage or resource > self.capacity - self.currentUsage:
|
if self.capacity == self.currentUsage or resource > self.capacity - self.currentUsage:
|
||||||
|
@ -2,6 +2,7 @@ from apps import Application
|
|||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
startSlices: list[int] = []
|
def __init__(self):
|
||||||
lengthOfTransmission: int = 0
|
self.startSlices: list[int] = []
|
||||||
application: Application = Application()
|
self.lengthOfTransmission:int = 0
|
||||||
|
self.application: Application = Application()
|
@ -2,5 +2,6 @@ from bucketresources import BucketResource
|
|||||||
|
|
||||||
|
|
||||||
class Datacentre:
|
class Datacentre:
|
||||||
processingpower: BucketResource = BucketResource()
|
def __init__(self):
|
||||||
uplink: BucketResource = BucketResource()
|
self.processingpower: BucketResource = BucketResource()
|
||||||
|
self.uplink: BucketResource = BucketResource()
|
||||||
|
21
src/main.py
21
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.
|
from scenarioplanner import Scenarioplanner
|
||||||
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
from src import scenarioplanner
|
||||||
|
|
||||||
|
|
||||||
def print_hi(name):
|
def preparesimulation() -> Scenarioplanner:
|
||||||
# Use a breakpoint in the code line below to debug your script.
|
scenarioplanner = Scenarioplanner()
|
||||||
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
scenarioplanner.simulationLength = 120
|
||||||
|
scenarioplanner.createapplications()
|
||||||
|
scenarioplanner.createclients(1000)
|
||||||
|
return scenarioplanner
|
||||||
|
|
||||||
|
|
||||||
# Press the green button in the gutter to run the script.
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print_hi('PyCharm')
|
scenarioplanner = preparesimulation()
|
||||||
|
pprint(scenarioplanner)
|
||||||
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
|
||||||
|
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)
|
@ -5,9 +5,7 @@ from datacentre import Datacentre
|
|||||||
|
|
||||||
|
|
||||||
class Scheduler:
|
class Scheduler:
|
||||||
clients: list[Client] = []
|
def __init__(self):
|
||||||
cloud: Datacentre = Datacentre()
|
self.clients: list[Client] = []
|
||||||
edge: Datacentre = Datacentre()
|
self.cloud: Datacentre = Datacentre()
|
||||||
|
self.edge: Datacentre = Datacentre()
|
||||||
def createClients(self, numofClients: int = 1):
|
|
||||||
pass
|
|
||||||
|
6
src/stats.py
Normal file
6
src/stats.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class Stats:
|
||||||
|
def __init__(self):
|
||||||
|
self.birbnetesClients:int = 0
|
||||||
|
self.videochatClients:int = 0
|
||||||
|
self.failedReqsuests:int = 0
|
||||||
|
self.failedDetails:dict = {}
|
Loading…
Reference in New Issue
Block a user