Skip to content

Commit

Permalink
a commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wisaaco committed Mar 5, 2018
1 parent d50ee3b commit 9d38f92
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 59 deletions.
8 changes: 4 additions & 4 deletions src/examples/Tutorial/main1.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def main(simulated_time):

s.run(stop_time,show_progress_monitor=False)

s.draw_allocated_topology() # for debugging
# s.draw_allocated_topology() # for debugging

if __name__ == '__main__':
import logging.config
Expand All @@ -166,6 +166,6 @@ def main(simulated_time):
time_loops = [["M.A", "M.B"]]
m.showResults2(1000, time_loops=time_loops)
print "\t- Network saturation -"
print "\t\tAverage number of messages no transmitted: %i" %m.average_messages_not_transmitted()
print "\t\tTotal number of messages no transmitted: %i" %m.messages_not_transmitted()
print "\t\tPeak number of m. no transmitted: %i" %m.peak_messages_not_transmitted()
print "\t\tAverage waiting messages : %i" % m.average_messages_not_transmitted()
print "\t\tPeak of waiting messages : %i" % m.peak_messages_not_transmitted()
print "\t\tTOTAL messages not transmitted: %i" % m.messages_not_transmitted()
10 changes: 4 additions & 6 deletions src/examples/Tutorial/main2.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def main(simulated_time):
PLACEMENT algorithm
"""
placement = CloudPlacement("onCloud") # it defines the deployed rules: module-device

### THERE ARE MORE SERVICES of a specified type
placement.scaleService({"ServiceA": 4}) # Optional: you can specify the number of deployed modules in each device (by default 1)
placement.scaleService({"ServiceA": 4})

"""
POPULATION algorithm
Expand Down Expand Up @@ -168,9 +166,9 @@ def main(simulated_time):
time_loops = [["M.A", "M.B"]]
m.showResults2(1000, time_loops=time_loops)
print "\t- Network saturation -"
print "\t\tAverage number of messages no transmitted: %i" %m.average_messages_not_transmitted()
print "\t\tTotal number of messages no transmitted: %i" %m.messages_not_transmitted()
print "\t\tPeak number of m. no transmitted: %i" %m.peak_messages_not_transmitted()
print "\t\tAverage waiting messages : %i" % m.average_messages_not_transmitted()
print "\t\tPeak of waiting messages : %i" % m.peak_messages_not_transmitted()
print "\t\tTOTAL messages not transmitted: %i" % m.messages_not_transmitted()

print "\n\t- Stats of each service deployed -"
print m.get_df_modules()
Expand Down
43 changes: 43 additions & 0 deletions src/examples/VRGameFog-IFogSim-WL/analyse_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from yafs.stats import Stats
import numpy as np

# for size in [100,1000,10000,100000,1000000]:
time_loops = [["M.EGG", "M.Sensor", "M.Concentration"]]


#### ANALYSE FILES YAFS

police = "cloud"
police = "edge"

# print depth
# for idx1, depth in enumerate([4, 8, 12, 16]):
for idx1, depth in enumerate([2]):
# 1000, 10000,
for idx2,size in enumerate([1000,10000,100000]):
# size = 100000
print "DEPTH: %i | TIME: %s" %(depth , size)
s = Stats(defaultPath="Results_%s_%s_%s"%(police,size,depth))

#Network
s.showResults2(size, time_loops=time_loops)

print "\t Bytes transmitted: " ,s.bytes_transmitted()
print "\t Messages transmitted: ",s.count_messages()

print "\t- Network saturation -"
print "\t\tAverage waiting messages : %i" % s.average_messages_not_transmitted()
print "\t\tPeak of waiting messages : %i" % s.peak_messages_not_transmitted()
print "\t\tTOTAL messages not transmitted: %i" % s.messages_not_transmitted()

#LOOPS
# res = s.showLoops(time_loops)
# loopstime[depth][idx2]=res[0]
#
# #Print the execution delay
# print s.times("time_total_response")
#
# print "Latency Acc: ", s.df_link["latency"].sum()
print "*"*40


28 changes: 16 additions & 12 deletions src/examples/VRGameFog-IFogSim-WL/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from yafs.population import *
from yafs.topology import Topology

from selection_multipleDeploys import BroadPath
from selection_multipleDeploys import BroadPath,CloudPath_RR
from placement_Cluster_Edge import CloudPlacement,FogPlacement
from yafs.utils import *
import time
Expand Down Expand Up @@ -59,7 +59,7 @@ def create_application():
# MODULE SOURCES: only periodic messages
a.add_service_source("Calculator", next_time_periodic, m_player_game_state, time_shift=100.0) #According with the comments on VRGameFog.java, the period is 100ms
a.add_service_source("Coordinator", next_time_periodic, m_global_game_state, time_shift=100.0)
# MODULE SERVICES
# # MODULE SERVICES
a.add_service_module("Client", m_egg, m_sensor, fractional_selectivity, threshold=0.9)
a.add_service_module("Client", m_concentration, m_self_state_update, fractional_selectivity, threshold=1.0)
a.add_service_module("Client", m_global_game_state, m_global_state_update, fractional_selectivity, threshold=1.0)
Expand Down Expand Up @@ -91,15 +91,15 @@ def create_json_topology(numOfDepts,numOfMobilesPerDept):
proxy_dev = {"id":id, "model": "Proxy-server", "IPT": 2800* 10 ^ 6, "RAM": 4000,
"COST": 3,"WATT":40.0}

topology_json = {"entity": [cloud_dev, proxy_dev], "link": [{"s": 0, "d": 1, "BW": 10000, "PR": 100}]}
topology_json = {"entity": [cloud_dev, proxy_dev], "link": [{"s": 0, "d": 1, "BW": 10000, "PR": 14}]}
id += 1

for idx in range(numOfDepts):
#GATEWAY DEVICE
gw = id
topology_json["entity"].append(
{"id": id, "model": "d-", "IPT": 2800 * 10 ^ 6, "RAM": 4000, "COST": 3,"WATT":40.0})
topology_json["link"].append({"s": 1, "d": id, "BW": 100, "PR": 4})
topology_json["link"].append({"s": 1, "d": id, "BW": 100, "PR": 10})
id += 1

for idm in range(numOfMobilesPerDept):
Expand All @@ -112,7 +112,7 @@ def create_json_topology(numOfDepts,numOfMobilesPerDept):
# SENSOR
topology_json["entity"].append(
{"id": id, "model": "s", "COST": 0,"WATT":0.0})
topology_json["link"].append({"s": id - 1, "d": id, "BW": 100, "PR": 6})
topology_json["link"].append({"s": id - 1, "d": id, "BW": 100, "PR": 4})
id += 1
# ACTUATOR
topology_json["entity"].append(
Expand Down Expand Up @@ -158,12 +158,13 @@ def main(simulated_time,depth,police):
if police == "cloud":
print "cloud"
placement = CloudPlacement("onCloud")
placement.scaleService(
{"Calculator": numOfDepts * numOfMobilesPerDept, "Coordinator": 1})
else:
print "EDGE"
placement = FogPlacement("onProxies")

placement.scaleService(
{"Calculator": numOfMobilesPerDept, "Coordinator": numOfDepts * numOfMobilesPerDept})
placement.scaleService(
{"Calculator": numOfMobilesPerDept, "Coordinator": 1})

# placement = ClusterPlacement("onCluster", activation_dist=next_time_periodic, time_shift=600)
"""
Expand All @@ -181,14 +182,17 @@ def main(simulated_time,depth,police):
pop.set_sink_control({"model": "a","number":1,"module":app.get_sink_modules()})

#In addition, a source includes a distribution function:
pop.set_src_control({"model": "s", "number":1,"message": app.get_message("M.EGG"), "distribution": deterministicDistribution,"param": {"time_shift": 40}})#5.1}})
pop.set_src_control({"model": "s", "number":1,"message": app.get_message("M.EGG"), "distribution": deterministicDistribution,"param": {"time_shift": 100}})

"""--
SELECTOR algorithm
"""
#Their "selector" is actually the shortest way, there is not type of orchestration algorithm.
#This implementation is already created in selector.class,called: First_ShortestPath
selectorPath = BroadPath(numOfMobilesPerDept,police)
if police == "cloud":
selectorPath = CloudPath_RR()
else:
selectorPath = BroadPath(numOfMobilesPerDept)

"""
SIMULATION ENGINE
Expand All @@ -214,13 +218,13 @@ def main(simulated_time,depth,police):
args = parser.parse_args()

if not args.time:
stop_time = 10000
stop_time = 1000
else:
stop_time = int(args.time)

start_time = time.time()
if not args.depth:
dep = 4
dep = 2
else:
dep = int(args.depth)

Expand Down
122 changes: 86 additions & 36 deletions src/examples/VRGameFog-IFogSim-WL/selection_multipleDeploys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,70 @@
from yafs.selection import Selection
import networkx as nx

class CloudPath_RR(Selection):


def __init__(self):
self.rr = {} # for a each type of service, we have a mod-counter

def get_path(self, sim, app_name, message, topology_src, alloc_DES, alloc_module, traffic):

node_src = topology_src
DES_dst = alloc_module[app_name][message.dst] # returns an array with all DES process serving

if message.dst not in self.rr.keys():
self.rr[message.dst] = 0

# print "GET PATH"
# print "\tNode _ src (id_topology): %i" % node_src
# print "\tRequest service: %s " % (message.dst)
# print "\tProcess serving that service: %s (pos ID: %i)" % (DES_dst, self.rr[message.dst])

bestPath = []
bestDES = []

if message.name == "M.Sensor" or message.name == "M.Player_Game_State": # both messages are adressed to modules deployed in cloud
for ix, des in enumerate(DES_dst):
if self.rr[message.dst] == ix:
dst_node = alloc_DES[des]
path = list(nx.shortest_path(sim.topology.G, source=node_src, target=dst_node))
bestPath = [path]
bestDES = [des]
self.rr[message.dst] = (self.rr[message.dst] + 1) % len(DES_dst)
return bestPath, bestDES

if message.name == "M.Concentration":
DES_dst = [message.last_idDes[0]]

best_path = []
best_DES = []
min_path = int("inf")
for des in DES_dst:
dst_node = alloc_DES[des]
path = list(nx.shortest_path(sim.topology.G, source=node_src, target=dst_node)) ###
if message.broadcasting:
best_path.append(path)
best_DES.append(des)
else:
if len(path) <= min_path:
min_path = len(path)
best_path = [path]
best_DES = [des]

return best_path, best_DES




class BroadPath(Selection):

def __init__(self,numOfMobilesPerDept,cloud=True):
def __init__(self,numOfMobilesPerDept):
super(BroadPath, self).__init__()
self.numOfMobilesPerDept = numOfMobilesPerDept
self.cloud = True
self.round_robin_module_calculator = {}
self.round_robin_module_coordinator = -1
self.round_robin_module_coordinator_cloud = -1

self.rr = {}

self.most_near_calculator_to_client = {}
self.running_services={}

Expand All @@ -22,7 +77,7 @@ def compute_most_near(self,node_src,alloc_DES,sim,DES_dst):
#By Placement policy we know that:
value = {"model": "d-"}
topoDST = sim.topology.find_IDs(value)
minLenPath = 99999999999
min_path = int("inf")
minPath = []
for dev in topoDST:
path = list(nx.shortest_path(sim.topology.G, source=node_src, target=dev))
Expand All @@ -40,7 +95,7 @@ def compute_most_near(self,node_src,alloc_DES,sim,DES_dst):
run_service.append(des)
self.running_services[last_dest_topo] = run_service

print self.running_services[last_dest_topo]
# print self.running_services[last_dest_topo]

if last_dest_topo not in self.round_robin_module_calculator:
self.round_robin_module_calculator[last_dest_topo]=0
Expand All @@ -63,42 +118,37 @@ def get_path(self, sim, app_name,message, topology_src, alloc_DES, alloc_module,
# print "DES DST: %s" % DES_dst

## SENSOR enrouting works with ca
if not self.cloud:
if message.name == "M.Sensor":
## CACHING ROUTE - Between NODE_SRC and MESSAGE.DST - MOST NEAR
# Warning. In this example, our topology is constant
if node_src not in self.most_near_calculator_to_client.keys():
self.most_near_calculator_to_client[node_src] = self.compute_most_near(
node_src,alloc_DES, sim,DES_dst)

path,des = self.most_near_calculator_to_client[node_src]
#
# print "PATH ",path
# print "DES ",des
return [path],[des]
else:
if message.dst == "Coordinator" and len(DES_dst) > 1: # ALL OF THEM ARE IN THE SAME ELEMENT - CLOUD
if self.round_robin_module_coordinator_cloud < 0:
self.round_robin_module_coordinator_cloud = 0
else:
self.round_robin_module_coordinator_cloud = (self.round_robin_module_coordinator_cloud + 1) % len(DES_dst)
DES_dst = [DES_dst[self.round_robin_module_coordinator_cloud]]



if message.dst == "Coordinator" and len(DES_dst)>1: # ALL OF THEM ARE IN THE SAME ELEMENT - CLOUD
if self.round_robin_module_coordinator<0:
self.round_robin_module_coordinator = 0
else:
self.round_robin_module_coordinator = (self.round_robin_module_coordinator+1)%len(DES_dst)
DES_dst = [DES_dst[self.round_robin_module_coordinator]]
if message.name == "M.Sensor":
## CACHING ROUTE - Between NODE_SRC and MESSAGE.DST - MOST NEAR
# Warning. In this example, our topology is constant
if node_src not in self.most_near_calculator_to_client.keys():
self.most_near_calculator_to_client[node_src] = self.compute_most_near(
node_src,alloc_DES, sim,DES_dst)

path,des = self.most_near_calculator_to_client[node_src]

# print "PATH ",path
# print "DES ",des
return [path],[des]

if message.dst == "Coordinator": # ALL OF THEM ARE IN THE SAME ELEMENT - CLOUD
if message.dst not in self.rr.keys():
self.rr[message.dst] = 0
for ix, des in enumerate(DES_dst):
if self.rr[message.dst] == ix:
dst_node = alloc_DES[des]
path = list(nx.shortest_path(sim.topology.G, source=node_src, target=dst_node))
bestPath = [path]
bestDES = [des]
self.rr[message.dst] = (self.rr[message.dst] + 1) % len(DES_dst)
return bestPath, bestDES

if message.name == "M.Concentration" :
DES_dst = [message.last_idDes[0]]

best_path = []
best_DES = []
min_path = 99999999999 ## Not so good
min_path = int("inf")
for des in DES_dst:
dst_node = alloc_DES[des]
path = list(nx.shortest_path(sim.topology.G, source=node_src, target=dst_node)) ###
Expand Down
5 changes: 4 additions & 1 deletion src/yafs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def __add_source_population(self, idDES, name_app, message, next_event, param):
msg = copy.copy(message)
msg.timestamp = self.env.now


self.__send_message(name_app, msg, idDES, self.SOURCE_METRIC)

self.logger.debug("STOP_Process - Module Pure Source\t#DES:%i" % idDES)
Expand Down Expand Up @@ -429,15 +430,17 @@ def __add_source_module(self, idDES, app_name, module, message, next_event, **pa
It generates a DES process associated to a compute module for the generation of messages
"""
self.logger.debug("Added_Process - Module Source: %s\t#DES:%i" % (module, idDES))
while not self.stop and self.source_id_running[idDES]:
while (not self.stop) and self.source_id_running[idDES]:
yield self.env.timeout(next_event(**param))
self.logger.debug(
"(App:%s#DES:%i#%s)\tModule - Generating Message:\t%s" % (app_name, idDES, module, message.name))
msg = copy.copy(message)
msg.timestamp = self.env.now



self.__send_message(app_name, msg, idDES,self.SOURCE_METRIC)

self.logger.debug("STOP_Process - Module Source: %s\t#DES:%i" % (module, idDES))


Expand Down

0 comments on commit 9d38f92

Please sign in to comment.