5
5
from leaf .application import Application , SourceTask , ProcessingTask , SinkTask
6
6
from leaf .infrastructure import Node , Link , Infrastructure
7
7
from leaf .orchestrator import Orchestrator
8
- from leaf .power import PowerModelNode , PowerModelLink , power_meter
8
+ from leaf .power import PowerModelNode , PowerModelLink , PowerMeter
9
9
10
10
RANDOM_SEED = 1
11
11
@@ -26,41 +26,38 @@ def main():
26
26
27
27
Log Output:
28
28
INFO Placing Application(tasks=3):
29
- INFO - SourceTask(id=0, cu=100 ) on Node('sensor', cu=0/1000 ).
30
- INFO - ProcessingTask(id=1, cu=5000 ) on Node('fog', cu=0/400000 ).
31
- INFO - SinkTask(id=2, cu=100 ) on Node('cloud', cu=0/inf).
29
+ INFO - SourceTask(id=0, cu=0.1 ) on Node('sensor', cu=0/1 ).
30
+ INFO - ProcessingTask(id=1, cu=5 ) on Node('fog', cu=0/400 ).
31
+ INFO - SinkTask(id=2, cu=0.5 ) on Node('cloud', cu=0/inf).
32
32
INFO - DataFlow(bit_rate=1000) on [Link('sensor' -> 'fog', bandwidth=0/30000000.0, latency=10)].
33
33
INFO - DataFlow(bit_rate=200) on [Link('fog' -> 'cloud', bandwidth=0/1000000000.0, latency=5)].
34
- DEBUG 0: cloud_and_fog_meter: PowerMeasurement(dynamic=70002.125W , static=30W )
35
- DEBUG 0: infrastructure_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
36
- DEBUG 0.5: application_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
37
- DEBUG 1: cloud_and_fog_meter: PowerMeasurement(dynamic=70002.125W , static=30W )
38
- DEBUG 1.5: application_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
39
- DEBUG 2: infrastructure_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
40
- DEBUG 2: cloud_and_fog_meter: PowerMeasurement(dynamic=70002.125W , static=30W )
41
- DEBUG 2.5: application_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
42
- DEBUG 3: cloud_and_fog_meter: PowerMeasurement(dynamic=70002.125W , static=30W )
43
- DEBUG 3.5: application_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
44
- DEBUG 4: infrastructure_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
45
- DEBUG 4: cloud_and_fog_meter: PowerMeasurement(dynamic=70002.125W , static=30W )
46
- DEBUG 4.5: application_meter: PowerMeasurement(dynamic=1570002.2850000001W , static=30.2W )
34
+ DEBUG 0: cloud_and_fog_meter: PowerMeasurement(dynamic=2.38W , static=30.00W )
35
+ DEBUG 0: infrastructure_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
36
+ DEBUG 0.5: application_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
37
+ DEBUG 1: cloud_and_fog_meter: PowerMeasurement(dynamic=2.38W , static=30.00W )
38
+ DEBUG 1.5: application_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
39
+ DEBUG 2: infrastructure_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
40
+ DEBUG 2: cloud_and_fog_meter: PowerMeasurement(dynamic=2.38W , static=30.00W )
41
+ DEBUG 2.5: application_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
42
+ DEBUG 3: cloud_and_fog_meter: PowerMeasurement(dynamic=2.38W , static=30.00W )
43
+ DEBUG 3.5: application_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
44
+ DEBUG 4: infrastructure_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
45
+ DEBUG 4: cloud_and_fog_meter: PowerMeasurement(dynamic=2.38W , static=30.00W )
46
+ DEBUG 4.5: application_meter: PowerMeasurement(dynamic=2.54W , static=30.20W )
47
47
"""
48
48
infrastructure = create_infrastructure ()
49
49
application = create_application (source_node = infrastructure .node ("sensor" ), sink_node = infrastructure .node ("cloud" ))
50
50
orchestrator = SimpleOrchestrator (infrastructure )
51
51
orchestrator .place (application )
52
52
53
- application_measurements = []
54
- cloud_and_fog_measurements = []
55
- infrastructure_measurements = []
53
+ application_pm = PowerMeter ( application , name = "application_meter" )
54
+ cloud_and_fog_pm = PowerMeter ([ infrastructure . node ( "cloud" ), infrastructure . node ( "fog" )], name = "cloud_and_fog_meter" )
55
+ infrastructure_pm = PowerMeter ( infrastructure , name = "infrastructure_meter" , measurement_interval = 2 )
56
56
57
57
env = simpy .Environment ()
58
- env .process (power_meter (env , application , name = "application_meter" , delay = 0.5 ,
59
- callback = lambda m : application_measurements .append (m )))
60
- env .process (power_meter (env , [infrastructure .node ("cloud" ), infrastructure .node ("fog" )], name = "cloud_and_fog_meter" ,
61
- callback = lambda m : cloud_and_fog_measurements .append (m )))
62
- env .process (power_meter (env , infrastructure , name = "infrastructure_meter" , measurement_interval = 2 ,
63
- callback = lambda m : infrastructure_measurements .append (m )))
58
+ env .process (application_pm .run (env , delay = 0.5 ))
59
+ env .process (cloud_and_fog_pm .run (env ))
60
+ env .process (infrastructure_pm .run (env ))
64
61
env .run (until = 5 )
65
62
66
63
@@ -81,8 +78,8 @@ def create_infrastructure():
81
78
sensor = Node ("sensor" , cu = 1 , power_model = PowerModelNode (max_power = 1.8 , static_power = 0.2 ))
82
79
fog_node = Node ("fog" , cu = 400 , power_model = PowerModelNode (max_power = 200 , static_power = 30 ))
83
80
cloud = Node ("cloud" , power_model = PowerModelNode (power_per_cu = 0.5 ))
84
- wifi_link_up = Link (sensor , fog_node , latency = 10 , bandwidth = 30e6 , power_model = PowerModelLink (300 ))
85
- wan_link_up = Link (fog_node , cloud , latency = 5 , bandwidth = 1e9 , power_model = PowerModelLink (6000 ))
81
+ wifi_link_up = Link (sensor , fog_node , latency = 10 , bandwidth = 30e6 , power_model = PowerModelLink (300e-9 ))
82
+ wan_link_up = Link (fog_node , cloud , latency = 5 , bandwidth = 1e9 , power_model = PowerModelLink (6000e-9 ))
86
83
87
84
infrastructure .add_link (wifi_link_up )
88
85
infrastructure .add_link (wan_link_up )
0 commit comments