everything random simulation done
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
11e966d08b
commit
c9397ff604
@ -7,10 +7,10 @@ class BucketResourceType(Enum):
|
|||||||
|
|
||||||
|
|
||||||
class BucketResource:
|
class BucketResource:
|
||||||
def __init__(self):
|
def __init__(self, capacity: int = 0, resourcetype: BucketResourceType = BucketResourceType.NetworkLink):
|
||||||
self.type: BucketResourceType = BucketResourceType.NetworkLink
|
self.type: BucketResourceType = resourcetype
|
||||||
self.currentUsage: int = 0
|
self.currentUsage: int = 0
|
||||||
self.capacity: int = 0
|
self.capacity: int = capacity
|
||||||
|
|
||||||
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:
|
||||||
|
@ -8,5 +8,10 @@ class Client:
|
|||||||
self.lengthOfTransmission: int = 0
|
self.lengthOfTransmission: int = 0
|
||||||
self.application: Application = Application()
|
self.application: Application = Application()
|
||||||
|
|
||||||
def firerequest(self, edge:Datacentre, cloud: Datacentre):
|
def firerequest(self, edge: Datacentre, cloud: Datacentre, currentSlice: int) -> bool:
|
||||||
pass
|
for i in self.startSlices:
|
||||||
|
if i <= currentSlice <= i+self.lengthOfTransmission:
|
||||||
|
return edge.fireapplicationmodule(
|
||||||
|
applicationmodule=self.application.modules[0]) and cloud.fireapplicationmodule(
|
||||||
|
applicationmodule=self.application.modules[1])
|
||||||
|
return True
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
from bucketresources import BucketResource
|
from bucketresources import BucketResource
|
||||||
|
from apps import ApplicationModule
|
||||||
|
|
||||||
|
|
||||||
class Datacentre:
|
class Datacentre:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.processingpower: BucketResource = BucketResource()
|
self.processingpower: BucketResource = BucketResource()
|
||||||
self.uplink: BucketResource = BucketResource()
|
self.uplink: BucketResource = BucketResource()
|
||||||
|
|
||||||
|
def fireapplicationmodule(self, applicationmodule: ApplicationModule) -> bool:
|
||||||
|
return self.processingpower.reserve(applicationmodule.cpuRequirement) and self.uplink.reserve(
|
||||||
|
applicationmodule.bwRequirement)
|
||||||
|
|
||||||
|
def releaseall(self) -> None:
|
||||||
|
self.processingpower.releaseall()
|
||||||
|
self.uplink.releaseall()
|
||||||
|
15
src/main.py
15
src/main.py
@ -1,6 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
|
from pprint import pprint
|
||||||
from datacentre import Datacentre
|
from datacentre import Datacentre
|
||||||
|
from bucketresources import BucketResource, BucketResourceType
|
||||||
from scenarioplanner import Scenarioplanner
|
from scenarioplanner import Scenarioplanner
|
||||||
from scheduler import Scheduler
|
from scheduler import Scheduler
|
||||||
|
|
||||||
@ -18,13 +19,13 @@ def preparesimulation() -> Scenarioplanner:
|
|||||||
def preparesimulationrunner(currscenarioplanner: Scenarioplanner) -> Scheduler:
|
def preparesimulationrunner(currscenarioplanner: Scenarioplanner) -> Scheduler:
|
||||||
currentscheduler = Scheduler()
|
currentscheduler = Scheduler()
|
||||||
currentscheduler.simulationLength = currscenarioplanner.simulationLength
|
currentscheduler.simulationLength = currscenarioplanner.simulationLength
|
||||||
currscenarioplanner.clients = copy.deepcopy(currscenarioplanner.clients)
|
currentscheduler.clients = copy.deepcopy(currscenarioplanner.clients)
|
||||||
clouddatacentre = Datacentre()
|
clouddatacentre = Datacentre()
|
||||||
clouddatacentre.processingpower = 10000000
|
clouddatacentre.processingpower = BucketResource(100000000000, BucketResourceType.CpuResource)
|
||||||
clouddatacentre.uplink = 10000000
|
clouddatacentre.uplink = BucketResource(100000000000)
|
||||||
edgedatacentre = Datacentre()
|
edgedatacentre = Datacentre()
|
||||||
edgedatacentre.processingpower = 10000
|
edgedatacentre.processingpower = BucketResource(100000, BucketResourceType.CpuResource)
|
||||||
edgedatacentre.uplink = 10000
|
edgedatacentre.uplink = BucketResource(100000)
|
||||||
currentscheduler.edge = edgedatacentre
|
currentscheduler.edge = edgedatacentre
|
||||||
currentscheduler.cloud = clouddatacentre
|
currentscheduler.cloud = clouddatacentre
|
||||||
currentscheduler.statsModule = currscenarioplanner.statsModule
|
currentscheduler.statsModule = currscenarioplanner.statsModule
|
||||||
@ -34,3 +35,5 @@ def preparesimulationrunner(currscenarioplanner: Scenarioplanner) -> Scheduler:
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
scenarioplanner = preparesimulation()
|
scenarioplanner = preparesimulation()
|
||||||
currscheduler = preparesimulationrunner(scenarioplanner)
|
currscheduler = preparesimulationrunner(scenarioplanner)
|
||||||
|
currscheduler.runsimulation()
|
||||||
|
pprint(currscheduler.statsModule.failedDetails)
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
from clients import Client
|
from clients import Client
|
||||||
from apps import Application, ApplicationModule
|
|
||||||
from bucketresources import BucketResource, BucketResource
|
|
||||||
from stats import Stats
|
from stats import Stats
|
||||||
from datacentre import Datacentre
|
from datacentre import Datacentre
|
||||||
|
|
||||||
@ -17,4 +15,15 @@ class Scheduler:
|
|||||||
def runsimulation(self):
|
def runsimulation(self):
|
||||||
for i in range(self.simulationLength):
|
for i in range(self.simulationLength):
|
||||||
for currclient in self.clients:
|
for currclient in self.clients:
|
||||||
pass
|
print(f"Edge status: CPU used: {self.edge.processingpower.currentUsage}\
|
||||||
|
BW used: {self.edge.uplink.currentUsage}")
|
||||||
|
print(f"Cloud status: CPU used: {self.cloud.processingpower.currentUsage}\
|
||||||
|
BW used: {self.cloud.uplink.currentUsage}")
|
||||||
|
if not currclient.firerequest(self.edge, self.cloud, i):
|
||||||
|
self.failedClients.append(currclient)
|
||||||
|
if i not in self.statsModule.failedDetails:
|
||||||
|
self.statsModule.failedDetails[i] = 1
|
||||||
|
else:
|
||||||
|
self.statsModule.failedDetails[i] += 1
|
||||||
|
self.cloud.releaseall()
|
||||||
|
self.edge.releaseall()
|
||||||
|
Loading…
Reference in New Issue
Block a user