55from leaf .application import Application , SourceTask , ProcessingTask , SinkTask
66from leaf .infrastructure import Node , Link , Infrastructure
77from leaf .orchestrator import Orchestrator
8- from leaf .power import PowerModelNode , PowerModelLink , power_meter
8+ from leaf .power import PowerModelNode , PowerModelLink , PowerMeter
99
1010RANDOM_SEED = 1
1111
@@ -26,41 +26,38 @@ def main():
2626
2727 Log Output:
2828 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).
3232 INFO - DataFlow(bit_rate=1000) on [Link('sensor' -> 'fog', bandwidth=0/30000000.0, latency=10)].
3333 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 )
4747 """
4848 infrastructure = create_infrastructure ()
4949 application = create_application (source_node = infrastructure .node ("sensor" ), sink_node = infrastructure .node ("cloud" ))
5050 orchestrator = SimpleOrchestrator (infrastructure )
5151 orchestrator .place (application )
5252
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 )
5656
5757 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 ))
6461 env .run (until = 5 )
6562
6663
@@ -81,8 +78,8 @@ def create_infrastructure():
8178 sensor = Node ("sensor" , cu = 1 , power_model = PowerModelNode (max_power = 1.8 , static_power = 0.2 ))
8279 fog_node = Node ("fog" , cu = 400 , power_model = PowerModelNode (max_power = 200 , static_power = 30 ))
8380 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 ))
8683
8784 infrastructure .add_link (wifi_link_up )
8885 infrastructure .add_link (wan_link_up )
0 commit comments