diff --git a/docs/build/doctrees/api_reference/yafs.application.doctree b/docs/build/doctrees/api_reference/yafs.application.doctree index 31606f43..679df558 100644 Binary files a/docs/build/doctrees/api_reference/yafs.application.doctree and b/docs/build/doctrees/api_reference/yafs.application.doctree differ diff --git a/docs/build/doctrees/api_reference/yafs.core.doctree b/docs/build/doctrees/api_reference/yafs.core.doctree index 4bf87598..42873220 100644 Binary files a/docs/build/doctrees/api_reference/yafs.core.doctree and b/docs/build/doctrees/api_reference/yafs.core.doctree differ diff --git a/docs/build/doctrees/api_reference/yafs.doctree b/docs/build/doctrees/api_reference/yafs.doctree index 6f5c297e..0746a172 100644 Binary files a/docs/build/doctrees/api_reference/yafs.doctree and b/docs/build/doctrees/api_reference/yafs.doctree differ diff --git a/docs/build/doctrees/api_reference/yafs.selection.doctree b/docs/build/doctrees/api_reference/yafs.selection.doctree index 0560ae9c..205b9488 100644 Binary files a/docs/build/doctrees/api_reference/yafs.selection.doctree and b/docs/build/doctrees/api_reference/yafs.selection.doctree differ diff --git a/docs/build/doctrees/environment.pickle b/docs/build/doctrees/environment.pickle index e2bd5216..c607939c 100644 Binary files a/docs/build/doctrees/environment.pickle and b/docs/build/doctrees/environment.pickle differ diff --git a/docs/build/doctrees/index.doctree b/docs/build/doctrees/index.doctree index d039c4ca..b8d54086 100644 Binary files a/docs/build/doctrees/index.doctree and b/docs/build/doctrees/index.doctree differ diff --git a/docs/build/doctrees/introduction/basic.doctree b/docs/build/doctrees/introduction/basic.doctree index 3abb8532..0abdb75e 100644 Binary files a/docs/build/doctrees/introduction/basic.doctree and b/docs/build/doctrees/introduction/basic.doctree differ diff --git a/docs/build/html/_modules/yafs/core.html b/docs/build/html/_modules/yafs/core.html index d07679c0..efd806b7 100644 --- a/docs/build/html/_modules/yafs/core.html +++ b/docs/build/html/_modules/yafs/core.html @@ -51,7 +51,9 @@
import copy
import simpy
+import scipy.spatial
from tqdm import tqdm
+import networkx as nx
from yafs.topology import Topology
from yafs.application import Application
@@ -59,7 +61,11 @@ Source code for yafs.core
from yafs.distribution import *
from yafs import utils
+from trackanimation.animation import AnimationTrack
+
import numpy as np
+import smopy
+from PIL import Image as pimg
EVENT_UP_ENTITY = "node_up"
EVENT_DOWN_ENTITY = "node_down"
@@ -206,10 +212,25 @@ Source code for yafs.core
+
+ """
+ MOBILE ADAPTATIONS
+ """
+ self.service_coverage = {}
+ self.tolerance = 0.0001
+ self.user_tracks = None
+
+ #v2
+ self.endpoints = []
+ self.user_tracks = None
+ self.map = None
+ self.coverage = None
+ self.control_movement_class = None
+
# self.__send_message(app_name, message, idDES, self.SOURCE_METRIC)
def __send_message(self, app_name, message, idDES, type):
"""
- Any exchange of messages is done with this function. It is responsible for updating the metrics
+ Any exchange of messages between modules is done with this function and updates the metrics when the message achieves the destination module
Args:
app_name (string)º
@@ -221,12 +242,21 @@ Source code for yafs.core
"""
#TODO IMPROVE asignation of topo = alloc_DES(IdDES) , It has to move to the get_path process
try:
- paths,DES_dst = self.selector_path[app_name].get_path(self,app_name, message, self.alloc_DES[idDES], self.alloc_DES, self.alloc_module, self.last_busy_time)
+ paths,DES_dst = self.selector_path[app_name].get_path(self,app_name, message, self.alloc_DES[idDES], self.alloc_DES, self.alloc_module, self.last_busy_time,from_des=idDES)
if DES_dst == [None] or DES_dst==[[]]:
self.logger.warning(
"(#DES:%i)\t--- Unreacheable DST:\t%s: PATH:%s " % (idDES, message.name, paths))
- self.print_debug_assignaments()
+
+ if self.logger.isEnabledFor("Debug"):
+ self.logger.debug("From __send_message function: ")
+ # self.print_debug_assignaments()
+ # print "NODES (%i): %s"%(len(self.topology.G.nodes()),self.topology.G.nodes())
+ self.logger.debug("NODES (%i)" % len(self.topology.G.nodes()))
+
+ if self.control_movement_class is not None:
+ self.logger.debug("STEP : ",self.control_movement_class.current_step)
+
else:
self.logger.debug("(#DES:%i)\t--- SENDING Message:\t%s: PATH:%s DES:%s" % (idDES, message.name,paths,DES_dst))
@@ -243,6 +273,7 @@ Source code for yafs.core
except KeyError:
self.logger.warning("(#DES:%i)\t--- Unreacheable DST:\t%s " % (idDES, message.name))
+
def __network_process(self):
"""
This is an internal DES-process who manages the latency of messages sent in the network.
@@ -250,7 +281,8 @@ Source code for yafs.core
In this way, the message has a transmission latency.
"""
edges = self.topology.get_edges().keys()
- self.last_busy_time = {} # dict(zip(edges, [0.0] * len(edges)))
+ self.last_busy_time = {} # dict(zip(edges, [0.0] * len(edges)))
+
while not self.stop:
message = yield self.network_ctrl_pipe.get()
@@ -323,9 +355,9 @@ Source code for yafs.core
self.env.process(self.__wait_message(message, latency_msg_link, shift_time))
except:
#This fact is produced when a node or edge the topology is changed or disappeared
- self.logger.warning("The initial path assigned is unreachabled. Link: (%i,%i). Routing a new one. "%(link[0],link[1]))
+ self.logger.warning("The initial path assigned is unreachabled. Link: (%i,%i). Routing a new one. %i"%(link[0],link[1],self.env.now))
- paths, DES_dst = self.selector_path[message.app_name].get_path_from_failure(self, message, link, self.alloc_DES,self.alloc_module, self.last_busy_time,self.env.now)
+ paths, DES_dst = self.selector_path[message.app_name].get_path_from_failure(self, message, link, self.alloc_DES,self.alloc_module, self.last_busy_time,self.env.now,from_des=message.idDES)
if DES_dst == [] and paths==[]:
#Message communication ending:
@@ -427,7 +459,6 @@ Source code for yafs.core
def __update_node_metrics(self, app, module, message, des, type):
try:
-
"""
It computes the service time in processing a message and record this event
"""
@@ -443,7 +474,9 @@ Source code for yafs.core
"""
id_node = self.alloc_DES[des]
- att_node = self.topology.get_nodes_att()[id_node]
+ # att_node = self.topology.get_nodes_att()[id_node] # WARNING DEPRECATED from V1.0
+ att_node = self.topology.G.nodes[id_node]
+
time_service = message.inst / float(att_node["IPT"])
@@ -454,21 +487,24 @@ Source code for yafs.core
# from_id_source = id_node # same src like dst
# else:
# from_id_source = message.path[0]
-
- # print "-"*50
- # print "Module: ",module # module that receives the request (RtR)
- # print "DES ",des # DES process who RtR
- # print "ID MODULE: ",id_node #Topology entity who RtR
- # print "Message.name ",message.name # Message name
- # print "Message.id ", message.id #Message generator id
- # print "Message.path ",message.path #enrouting path
- # print "Message src ",message.src #module source who send the request
- # print "Message dst ",message.dst #module dst (the entity that RtR)
- # print "Message idDEs ",message.idDES #DES intermediate process that process the request
- # print "TOPO.src ", message.path[0] #entity that RtR
- # print "TOPO.dst ", int(self.alloc_DES[des]) #DES process that RtR
-
#
+ # # if message.id == 1072:
+ # print "-"*50
+ # print "Module: ",module # module that receives the request (RtR)
+ # print "DES ",des # DES process who RtR
+ # print "ID MODULE: ",id_node #Topology entity who RtR
+ # print "Message.name ",message.name # Message name
+ # print "Message.id ", message.id #Message generator id
+ # print "Message.path ",message.path #enrouting path
+ # print "Message src ",message.src #module source who send the request
+ # print "Message dst ",message.dst #module dst (the entity that RtR)
+ # print "Message idDEs ",message.idDES #DES intermediate process that process the request
+ # print "TOPO.src ", message.path[0] #entity that RtR
+ # print "TOPO.dst ", int(self.alloc_DES[des]) #DES process that RtR
+ # print "time service ",time_service
+ # exit()
+
+ #
# # print "MODULE: ",self.alloc_module[app][module]
# # tmp = []
# # for it in self.alloc_module[app][module]:
@@ -507,8 +543,10 @@ Source code for yafs.core
return time_service
except KeyError:
# The node can be removed
- self.logger.debug("Updating node metrics - Node removed: DES:%i" % des)
+ self.logger.critical("Make sure that this node has been removed or it has all mandatory attributes - Node: DES:%i" % des)
return 0
+
+
# self.logger.debug("TS[%s] - DES: %i - %d"%(module,des,time_service))
# except:
# self.logger.warning("This module has been removed previously to the arrival time of this message. DES: %i"%des)
@@ -585,23 +623,27 @@ Source code for yafs.core
"""
Processing the message
"""
-
- # print "Consumer Message: %d " % self.env.now
- # print "MODULE DES: ",ides
- # print "id ",msg.id
- # print "name ",msg.name
- # print msg.path
- # print msg.dst_int
- # print msg.timestamp
- # print msg.dst
+ # if ides == 3:
+ # print "Consumer Message: %d " % self.env.now
+ # print "MODULE DES: ",ides
+ # print "id ",msg.id
+ # print "name ",msg.name
+ # print msg.path
+ # print msg.dst_int
+ # print msg.timestamp
+ # print msg.dst
#
- # print "-" * 30
+ # print "-" * 30
#The module only computes this type of message one time.
#It records once
if not doBefore:
+ self.logger.debug(
+ "(App:%s#DES:%i#%s)\tModule - Recording the message:\t%s" % (app_name, ides, module, msg.name))
type = self.NODE_METRIC
+
service_time = self.__update_node_metrics(app_name, module, msg, ides, type)
+
yield self.env.timeout(service_time)
doBefore = True
@@ -662,10 +704,11 @@ Source code for yafs.core
Processing the message
"""
self.logger.debug(
- "(App:%s#DES:%i#%s)\tModule - Sink Message:\t%s" % (app_name, ides, module, msg.name))
+ "(App:%s#DES:%i#%s)\tModule Pure - Sink Message:\t%s" % (app_name, ides, module, msg.name))
type = self.SINK_METRIC
service_time = self.__update_node_metrics(app_name, module, msg, ides, type)
yield self.env.timeout(service_time) # service time is 0
+
self.logger.debug("STOP_Process - Module Pure Sink: %s\t#DES:%i" % (module, ides))
@@ -857,6 +900,7 @@ Source code for yafs.core
Add a DES process for deploy pure SINK modules (actuators)
This function its used by (:mod:`Placement`): algorithm
Internatlly, there is not a DES PROCESS for this type of behaviour
+
Args:
app_name (str): application name
@@ -936,11 +980,17 @@ Source code for yafs.core
# Add Selection control to the App
self.selector_path[app.name] = selector
- def get_alloc_entities(self):
+
+[docs] def get_alloc_entities(self):
+ """ It returns a dictionary of deployed services
+ key : id-node
+ value: a list of deployed services
+ """
alloc_entities = {}
- for key in self.topology.nodeAttributes.keys():
+ for key in self.topology.G.nodes:
alloc_entities[key] = []
+
for id_des_process in self.alloc_source:
src_deployed = self.alloc_source[id_des_process]
# print "Module (SRC): %s(%s) - deployed at entity.id: %s" %(src_deployed["module"],src_deployed["app"],src_deployed["id"])
@@ -952,7 +1002,7 @@ Source code for yafs.core
for idDES in self.alloc_module[app][module]:
alloc_entities[self.alloc_DES[idDES]].append(app+"#"+module)
- return alloc_entities
+ return alloc_entities
def deploy_module(self,app_name,module, services,ids):
@@ -991,6 +1041,25 @@ Source code for yafs.core
return id_DES
+
+[docs] def undeploy_module(self, app_name,service_name, idtopo):
+ """ removes all modules deployed in a node
+ modules with the same name = service_name
+ from app_name
+ deployed in id_topo
+ """
+ all_des = []
+ for k, v in self.alloc_DES.items():
+ if v == idtopo:
+ all_des.append(k)
+
+ # Clearing related structures
+ for des in self.alloc_module[app_name][service_name]:
+ if des in all_des:
+ self.alloc_module[app_name][service_name].remove(des)
+ self.stop_process(des)
+ del self.alloc_DES[des]
+
def remove_node(self, id_node_topology):
# Stopping related processes deployed in the module and clearing main structure: alloc_DES
des_tmp=[]
@@ -1053,8 +1122,150 @@ Source code for yafs.core
print "-" * 40
# exit()
+ #
+ # ### MOBILE ADAPTATION SECTION
+ # def update_service_coverage(self):
+ # if self.street_network is not None:
+ # points = utils.create_points(self.topology.G)
+ # point_streets = utils.create_points(self.street_network)
+ #
+ # tree = scipy.spatial.KDTree(points.values())
+ # points_within_tolerance = tree.query_ball_point(point_streets.values(), self.tolerance)
+ #
+ # # key = node network
+ # # value = id - module SW
+ #
+ # self.service_coverage = {}
+ # for idx, pt in enumerate(points_within_tolerance):
+ # ## MODULE SW
+ # key2 = point_streets.keys()[idx]
+ # nG2 = self.street_network.nodes[key2]
+ # # print "%s is close to " % nG2["model"]
+ # ## Street coverage
+ # for p in pt:
+ # key = points.keys()[p]
+ # # service_coverage[(G.nodes[key]['x'],G.nodes[key]['y'])]=nG2["model"]
+ # self.service_coverage[key] = nG2["id"]
+
+
+
+ # def setMobilityUserBehaviour(self,dataPopulation):
+ # self.user_behaviour = dataPopulation #TODO CHECK SYNTAX
+
+ def __add_mobile_agent(self,ides, gme):
+ #The mobile starts
+
+ yield self.env.timeout(gme.start)
+ self.logger.info("(#DES:%i)\t--- Mobile Entity STARTS :\t%s " % (ides, gme._id))
+ while (len(gme.path) - 1 > gme.current_position) and not self.stop and self.des_process_running[ides]:
+ e = (gme.path[gme.current_position], gme.path[gme.current_position + 1])
+ data = self.street_network.get_edge_data(*e)
+ try:
+ next_time = int(utils.toMeters(data[0]["geometry"]) / gme.speed)
+ except KeyError:
+ next_time = 1 # default time by roundabout or other Spatial THINGS
+
+ # take an action?
+ gme.next_time = next_time
+
+ self.logger.info("(#DES:%i)\t--- DO ACTION :\t%s " % (ides, gme._id))
+ gme.do.action(gme)
+
+ #TODO Can the MA wait more time in that node?
+
+ yield self.env.timeout(next_time)
+ gme.current_position += 1
+
+ # Last movement
+ if self.des_process_running[ides] and not self.stop:
+ gme.do.action(gme)
+
+ self.logger.info("(#DES:%i)\t--- Mobile Entity ENDS :\t%s " % (ides, gme._id))
+ # print "Mobile agent: %s ends " % gme.plate
+
+
+
+ def add_mobile_agent(self,gme):
+ ides = self.__get_id_process()
+ self.des_process_running[ides] = True
+ self.env.process(self.__add_mobile_agent(ides, gme))
+
+ ### ATENCION COONTROLAR VAR: INTERNAS
+ #self.alloc_DES[ides] = id_node
+
+ return ides
+
+ def load_user_tracks(self,tracks):
+ self.user_tracks = tracks
+
+ # self.user_tracks = AnimationTrack(df_points=tracks, dpi=300, bg_map=False, map_transparency=0.5)
+
+ # for i, (point, nextpoint) in enumerate(fig.compute_points()):
+ # print i, point, nextpoint
+ # if i == 2: break
+ # exit()
+
+ def generate_animation(self,pathFile):
+ if len(self.endpoints)==0: self.__update_connection_points()
+ if self.map == None: self.__load_map()
+
+ #map_endpoints = [self.map.to_pixels(i[0], i[1]) for i in self.endpoints]
+ #map_endpoints = np.array(map_endpoints)
+ self.map.img.save(pathFile+"_map_background.png")
-[docs] def run(self, until,test_initial_deploy=False,show_progress_monitor=True):
+ animation = AnimationTrack(self, dpi=100, bg_map=True, aspect='equal')
+ animation.make_video(output_file=pathFile, framerate=10, linewidth=1.0,G=self.topology.G)
+
+
+ # def generate_snapshot(self, pathFile,event):
+ # if len(self.endpoints) == 0: self.__update_connection_points()
+ # if self.map == None: self.__load_map()
+ #
+ # #map_endpoints = [self.map.to_pixels(i[0], i[1]) for i in self.endpoints]
+ # #map_endpoints = np.array(map_endpoints)
+ #
+ # animation = AnimationTrack(self, dpi=100, bg_map=True, aspect='equal')
+ # animation.make_video(output_file=pathFile, framerate=10, linewidth=1.0)
+
+ def __load_map(self):
+ trk_bounds = self.user_tracks.get_bounds()
+ min_lat = trk_bounds.min_latitude
+ max_lat = trk_bounds.max_latitude
+ min_lng = trk_bounds.min_longitude
+ max_lng = trk_bounds.max_longitude
+
+ self.map = smopy.Map((min_lat, min_lng, max_lat, max_lng), z=12)
+
+
+ def __update_connection_points(self):
+ level = nx.get_node_attributes(self.topology.G, 'level')
+ lat = nx.get_node_attributes(self.topology.G, 'lat')
+ lng = nx.get_node_attributes(self.topology.G, 'lng')
+
+ self.endpoints = []
+ self.name_endpoints = {}
+ pos = 0
+ for n in level:
+ if level[n] == 0:
+ self.endpoints.append([lat[n], lng[n]])
+ self.name_endpoints[pos]=n
+ pos +=1
+ self.endpoints = np.array(self.endpoints)
+
+
+ def set_coverage_class(self, class_name,**kwargs):
+ if len(self.endpoints)==0: self.__update_connection_points()
+ if self.map == None: self.__load_map()
+
+ self.coverage = class_name(self.map,self.endpoints,**kwargs)
+
+ def set_mobile_fog_entities(self,mobile_fog_entities):
+ self.mobile_fog_entities = mobile_fog_entities
+
+ def set_movement_control(self,evol):
+ self.control_movement_class = evol
+
+[docs] def run(self, until,test_initial_deploy=False,show_progress_monitor=True,mobile_behaviour=False):
"""
Start the simulation
@@ -1074,17 +1285,24 @@ Source code for yafs.core
Creating initial deploy of services
"""
for place in self.placement_policy.itervalues():
- place["placement_policy"].initial_allocation(self, app_name) # internally consideres the apps in charge
+ for app_name in place["apps"]:
+
+ print "APP_NAME ",app_name
+ place["placement_policy"].initial_allocation(self, app_name) # internally consideres the apps in charge
"""
- A internal DES process to stop the simulation,
+ A internal DES process will stop the simulation,
*Simpy.run.until* wait to all pipers are empty. So, hundreds of messages should be service... We force with the stop
"""
time_shift = 200
- distribution = deterministicDistribution(name="Deterministic", time=time_shift)
+ distribution = deterministic_distribution(name="SIM_Deterministic", time=time_shift)
self.env.process(self.__add_stop_monitor("Stop_Control_Monitor",self.__ctrl_progress_monitor,distribution,show_progress_monitor,time_shift=time_shift))
-
+ # if mobile_behaviour:
+ # """
+ # Updating control variables of mobile environment
+ # """
+ # self.update_service_coverage()
self.print_debug_assignaments()
diff --git a/docs/build/html/_modules/yafs/placement.html b/docs/build/html/_modules/yafs/placement.html
index 3e913948..af7531b4 100644
--- a/docs/build/html/_modules/yafs/placement.html
+++ b/docs/build/html/_modules/yafs/placement.html
@@ -112,18 +112,14 @@ Source code for yafs.placement
self.data = json
def initial_allocation(self, sim, app_name):
-
for item in self.data["initialAllocation"]:
- #print item
- app_name = item["app"]
- module = item["module_name"]
- idtopo = item["id_resource"]
-
- app = sim.apps[app_name]
- services = app.services
- #print services[module]
- idDES = sim.deploy_module(app_name, module, services[module],[idtopo])
-
+ if app_name == item["app"]:
+ # app_name = item["app"]
+ module = item["module_name"]
+ idtopo = item["id_resource"]
+ app = sim.apps[app_name]
+ services = app.services
+ idDES = sim.deploy_module(app_name, module, services[module],[idtopo])
class JSONPlacementOnCloud(Placement):
@@ -135,12 +131,13 @@ Source code for yafs.placement
def initial_allocation(self, sim, app_name):
for item in self.data["initialAllocation"]:
- app_name = item["app"]
- module = item["module_name"]
+ if app_name == item["app"]:
+ app_name = item["app"]
+ module = item["module_name"]
- app = sim.apps[app_name]
- services = app.services
- idDES = sim.deploy_module(app_name, module, services[module],[self.idCloud])
+ app = sim.apps[app_name]
+ services = app.services
+ idDES = sim.deploy_module(app_name, module, services[module],[self.idCloud])
diff --git a/docs/build/html/_modules/yafs/selection.html b/docs/build/html/_modules/yafs/selection.html
index e0e6f00b..a2131f2e 100644
--- a/docs/build/html/_modules/yafs/selection.html
+++ b/docs/build/html/_modules/yafs/selection.html
@@ -65,19 +65,21 @@ Source code for yafs.selection
self.lat_acc = 0.0
self.propagation = 0.0
-[docs] def get_path(self, sim, app_name, message, topology_src,alloc_DES, alloc_module, traffic):
+[docs] def get_path(self, sim, app_name, message, topology_src,alloc_DES, alloc_module, traffic, from_des):
+
"""
Args:
- sim (yafs.core.Sim)
-
- src (int): the node source
-
- dst (dst): the node destiny
-
- message (yafs.application.Message)
-
- traffic (dict): the current occupation of the network
+ :param sim:
+ :param message:
+ :param link:
+ :param alloc_DES:
+ :param alloc_module:
+ :param traffic:
+ :param ctime:
+ :param from_des
+ :return:
+ both empty arrays implies that the message will not send to the destination.
Returns:
@@ -96,7 +98,7 @@ Source code for yafs.selection
""" END Selection """
return path,ids
-[docs] def get_path_from_failure(self, sim, message, link, alloc_DES, alloc_module, traffic, ctime):
+[docs] def get_path_from_failure(self, sim, message, link, alloc_DES, alloc_module, traffic, ctime, from_des):
"""
This function is call when some link of a message path is broken or unavailable. A new one from that point should be calculated.
@@ -107,6 +109,7 @@ Source code for yafs.selection
:param alloc_module:
:param traffic:
:param ctime:
+ :param from_des
:return:
both empty arrays implies that the message will not send to the destination.
@@ -124,7 +127,7 @@ Source code for yafs.selection
Among all the possible options, it returns a random path.
"""
- def get_path(self, sim, app_name, message, topology_src,alloc_DES, alloc_module, traffic):
+ def get_path(self, sim, app_name, message, topology_src,alloc_DES, alloc_module, traffic,from_des):
paths = []
dst_idDES = []
src_node = topology_src
@@ -142,7 +145,7 @@ Source code for yafs.selection
[docs]class First_ShortestPath(Selection):
"""Among all possible shorter paths, returns the first."""
- def get_path(self, sim, app_name,message, topology_src, alloc_DES, alloc_module, traffic):
+ def get_path(self, sim, app_name,message, topology_src, alloc_DES, alloc_module, traffic,from_des):
paths = []
dst_idDES = []
diff --git a/docs/build/html/_modules/yafs/topology.html b/docs/build/html/_modules/yafs/topology.html
index c4dd532c..c003f47e 100644
--- a/docs/build/html/_modules/yafs/topology.html
+++ b/docs/build/html/_modules/yafs/topology.html
@@ -44,8 +44,8 @@ Source code for yafs.topology
import networkx as nx
-
-
+import matplotlib.pyplot as plt
+import warnings
[docs]class Topology:
@@ -70,15 +70,26 @@ Source code for yafs.topology
def __init__(self, logger=None):
self.__idNode = -1
+ # G is a nx.networkx graph
self.G = None
- #G is a networkx graph
+
+ # TODO VERSION 2. THIS VALUE SHOULD BE REMOVED
+ # INSTEAD USE NX.G. attributes
self.nodeAttributes = {}
+
+
+ # A simple *cache* to have all cloud nodes
+ # TODO VERSION 2. THIS VALUE SHOULD BE REMOVED
self.cloudNodes = []
- #A simple *cache* to have all cloud nodes
+
+
self.logger = logger or logging.getLogger(__name__)
+
+
+
def __init_uptimes(self):
for key in self.nodeAttributes:
self.nodeAttributes[key]["uptime"] = (0, None)
@@ -167,7 +178,35 @@ Source code for yafs.topology
self.__idNode = len(self.G.nodes)
self.__init_uptimes()
+ def load_all_node_attr(self,data):
+ self.G = nx.Graph()
+ for edge in data["link"]:
+ self.G.add_edge(edge["s"], edge["d"], BW=edge[self.LINK_BW], PR=edge[self.LINK_PR])
+
+ dc = {str(x): {} for x in data["entity"][0].keys()}
+ for ent in data["entity"]:
+ for key in ent.keys():
+ dc[key][ent["id"]] = ent[key]
+ for x in data["entity"][0].keys():
+ nx.set_node_attributes(self.G, values=dc[x], name=str(x))
+
+ for node in data["entity"]:
+ self.nodeAttributes[node["id"]] = node
+
+ self.__idNode = len(self.G.nodes)
+ self.__init_uptimes()
+
+
+
+
def load_graphml(self,filename):
+ warnings.warn("The load_graphml function is deprecated and "
+ "will be removed in version 2.0.0. "
+ "Use NX.READ_GRAPHML function instead.",
+ FutureWarning,
+ stacklevel=8
+ )
+
self.G = nx.read_graphml(filename)
attEdges = {}
for k in self.G.edges():
@@ -244,7 +283,16 @@ Source code for yafs.topology
def write(self,path):
- nx.write_gexf(self.G, path)
+ nx.write_gexf(self.G, path)
+
+
+ def draw_png(self,path_file):
+ fig, ax = plt.subplots(nrows=1, ncols=1)
+ pos = nx.spring_layout(self.G)
+ nx.draw(self.G, pos)
+ labels = nx.draw_networkx_labels(self.G, pos)
+ fig.savefig(path_file) # save the figure to file
+ plt.close(fig) # close the figure
diff --git a/docs/build/html/api_reference/yafs.core.html b/docs/build/html/api_reference/yafs.core.html
index b1f9a5f4..6785d0fc 100644
--- a/docs/build/html/api_reference/yafs.core.html
+++ b/docs/build/html/api_reference/yafs.core.html
@@ -122,13 +122,14 @@
deploy_sink
(app_name, node, module)[source]¶
Add a DES process for deploy pure SINK modules (actuators)
This function its used by (Placement
): algorithm
-Internatlly, there is not a DES PROCESS for this type of behaviour
-Args:
-
-app_name (str): application name
+Internatlly, there is not a DES PROCESS for this type of behaviour
+
+- Args:
+app_name (str): application name
node (int): entity.id of the topology who will create the messages
-module (str): module
-
+module (str): module
+
+
@@ -161,6 +162,20 @@
the discrete-event simulator (aka DES)
+
+-
+
get_alloc_entities
()[source]¶
+It returns a dictionary of deployed services
+key : id-node
+value: a list of deployed services
+
+
+
+-
+
last_busy_time
= None¶
+MOBILE ADAPTATIONS
+
+
-
print_debug_assignaments
()[source]¶
@@ -175,7 +190,7 @@
-
-
run
(until, test_initial_deploy=False, show_progress_monitor=True)[source]¶
+run
(until, test_initial_deploy=False, show_progress_monitor=True, mobile_behaviour=False)[source]¶
Start the simulation
- Args:
@@ -211,6 +226,15 @@
+
+-
+
undeploy_module
(app_name, service_name, idtopo)[source]¶
+removes all modules deployed in a node
+modules with the same name = service_name
+from app_name
+deployed in id_topo
+
+
-
unreachabled_links
= None¶
diff --git a/docs/build/html/api_reference/yafs.html b/docs/build/html/api_reference/yafs.html
index 6f9794da..ea70dc1c 100644
--- a/docs/build/html/api_reference/yafs.html
+++ b/docs/build/html/api_reference/yafs.html
@@ -157,6 +157,26 @@ Metrics
+Distribution¶
+
+
+
+
+
+
+Distribution
(name)
+Abstract class
+
+deterministic_distribution
(time, **kwargs)
+
+
+exponential_distribution
(lambd[, seed])
+
+
+
+
+
@@ -181,6 +201,7 @@ Table Of Contents
Placement
Selection
Metrics
+Distribution
yafs.core
— Simulator engine
diff --git a/docs/build/html/api_reference/yafs.selection.html b/docs/build/html/api_reference/yafs.selection.html
index 7e40c327..c5d3ee03 100644
--- a/docs/build/html/api_reference/yafs.selection.html
+++ b/docs/build/html/api_reference/yafs.selection.html
@@ -55,15 +55,29 @@
-
-
get_path
(sim, app_name, message, topology_src, alloc_DES, alloc_module, traffic)[source]¶
+get_path
(sim, app_name, message, topology_src, alloc_DES, alloc_module, traffic, from_des)[source]¶
Args:
+
+
+
+
+Parameters:
+- sim –
+- message –
+- link –
+- alloc_DES –
+- alloc_module –
+- traffic –
+- ctime –
+
+
+
+
+
+:param from_des
+:return:
-sim (yafs.core.Sim)
-src (int): the node source
-dst (dst): the node destiny
-message (yafs.application.Message)
-traffic (dict): the current occupation of the network
-
+both empty arrays implies that the message will not send to the destination.
Returns:
a path among nodes
@@ -77,13 +91,13 @@
-
-
get_path_from_failure
(sim, message, link, alloc_DES, alloc_module, traffic, ctime)[source]¶
+get_path_from_failure
(sim, message, link, alloc_DES, alloc_module, traffic, ctime, from_des)[source]¶
This function is call when some link of a message path is broken or unavailable. A new one from that point should be calculated.
-Parameters:
+Parameters:
- sim –
- message –
- link –
@@ -94,11 +108,12 @@
-Returns: both empty arrays implies that the message will not send to the destination.
-
-
+:param from_des
+:return:
+
+both empty arrays implies that the message will not send to the destination.
Attention
this function is optional
diff --git a/docs/build/html/api_reference/yafs.topology.html b/docs/build/html/api_reference/yafs.topology.html
index dddc3893..219393dc 100644
--- a/docs/build/html/api_reference/yafs.topology.html
+++ b/docs/build/html/api_reference/yafs.topology.html
@@ -23,8 +23,8 @@
-
-
+
+
@@ -207,15 +207,15 @@ Table Of Contents
- Examples
- API REFERENCE
@@ -226,8 +226,8 @@ Related Topics
- Documentation overview
- API REFERENCE
- - Previous:
yafs.core
— Simulator engine
- - Next:
yafs.application
+ - Previous:
core
— Simulator engine
+ - Next:
application
diff --git a/docs/build/html/api_reference/yafs.utils.html b/docs/build/html/api_reference/yafs.utils.html
index 53f12cbb..0adf59af 100644
--- a/docs/build/html/api_reference/yafs.utils.html
+++ b/docs/build/html/api_reference/yafs.utils.html
@@ -24,7 +24,7 @@
-
+
@@ -60,15 +60,15 @@ Table Of Contents
- Examples
- API REFERENCE
@@ -79,7 +79,7 @@ Related Topics
- Documentation overview
- API REFERENCE
- - Previous:
yafs.metrics
+ - Previous:
metrics
- Next: ABOUT
diff --git a/docs/build/html/contents.html b/docs/build/html/contents.html
index 62ed9bd3..287d7d52 100644
--- a/docs/build/html/contents.html
+++ b/docs/build/html/contents.html
@@ -85,6 +85,7 @@ Documentation for YAFSPlacement
- Selection
- Metrics
+- Distribution
yafs.core
— Simulator engine
diff --git a/docs/build/html/genindex.html b/docs/build/html/genindex.html
index f6e38979..2dc1a677 100644
--- a/docs/build/html/genindex.html
+++ b/docs/build/html/genindex.html
@@ -157,6 +157,8 @@ F
G
+ - get_alloc_entities() (yafs.core.Sim method)
+
- get_df_service_utilization() (yafs.stats.Stats method)
- get_edge() (yafs.topology.Topology method)
@@ -205,6 +207,8 @@
I
L
@@ -331,10 +335,12 @@ T
U
diff --git a/docs/build/html/index.html b/docs/build/html/index.html
index 2b0565f1..ae9ea772 100644
--- a/docs/build/html/index.html
+++ b/docs/build/html/index.html
@@ -43,8 +43,6 @@
-PyPI
-