Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added VNF resource consumption functions #78

Merged
merged 11 commits into from
Aug 22, 2019
Prev Previous commit
Next Next commit
The available SFs are now also constructed from the initial placement
  • Loading branch information
ldklenner committed Aug 21, 2019
commit 0f2bebab66d6abe2a4560c5f18186287850c158f
9 changes: 5 additions & 4 deletions src/coordsim/reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def load_resource_function(name, path):
spec = importlib.util.spec_from_file_location(name, path + '/' + name + '.py')
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
except Exception as ex:
except Exception:
raise Exception(f'Cannot load file "{name}.py" from specified location "{path}".')

try:
return getattr(module, 'resource_function')
except Exception as ex:
except Exception:
raise Exception(f'There is no "resource_function" defined in file "{name}.py."')


Expand All @@ -66,7 +66,7 @@ def get_sf(sf_file, resource_functions_path):
# Configureable default mean and stdev defaults
default_processing_delay_mean = 1.0
default_processing_delay_stdev = 1.0
default_resource_function = lambda x: x
def default_resource_function(x): return x
sf_list = defaultdict(None)
for sf_name, sf_details in sf_data['sf_list'].items():
sf_list[sf_name] = sf_details
Expand All @@ -86,7 +86,8 @@ def get_sf(sf_file, resource_functions_path):
else:
sf_list[sf_name]["resource_function_id"] = 'default'
sf_list[sf_name]["resource_function"] = default_resource_function
log.info(f'No resource function specified for SF {sf_name}. Default resource function will be used instead.')
log.info(
f'No resource function specified for SF {sf_name}. Default resource function will be used instead.')
return sf_list


Expand Down
12 changes: 6 additions & 6 deletions src/coordsim/simulation/flowsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def process_flow(self, flow, sfc):

# Calculate the demanded capacity when the flow is processed at this node
demanded_total_capacity = 0.0
for sf_i, sf_data in self.params.network.nodes[current_node_id]["available_sf"].items():
for sf_i, sf_data in self.params.network.nodes[current_node_id]['available_sf'].items():
if sf == sf_i:
# Include flows data rate in requested sf capacity calculation
demanded_total_capacity += self.params.sf_list[sf]['resource_function'](sf_data['load'] + flow.dr)
Expand All @@ -210,9 +210,9 @@ def process_flow(self, flow, sfc):
processing_delay))

# Add load to sf
self.params.network.nodes[current_node_id]["available_sf"][sf]['load'] += flow.dr
self.params.network.nodes[current_node_id]['available_sf'][sf]['load'] += flow.dr
# Set remaining node capacity
self.params.network.nodes[current_node_id]["remaining_cap"] = node_cap - demanded_total_capacity
self.params.network.nodes[current_node_id]['remaining_cap'] = node_cap - demanded_total_capacity
# Just for the sake of keeping lines small, the node_remaining_cap is updated again.
node_remaining_cap = self.params.network.nodes[current_node_id]["remaining_cap"]

Expand All @@ -238,13 +238,13 @@ def process_flow(self, flow, sfc):
metrics.remove_active_flow(flow, current_node_id, current_sf)

# Remove load from sf
self.params.network.nodes[current_node_id]["available_sf"][sf]['load'] -= flow.dr
self.params.network.nodes[current_node_id]['available_sf'][sf]['load'] -= flow.dr
stefanbschneider marked this conversation as resolved.
Show resolved Hide resolved
# Recalculation is necessary because other flows could have already arrived or departed at the node
used_total_capacitiy = 0.0
for sf_i, sf_data in self.params.network.nodes[current_node_id]["available_sf"].items():
for sf_i, sf_data in self.params.network.nodes[current_node_id]['available_sf'].items():
used_total_capacitiy += self.params.sf_list[sf_i]['resource_function'](sf_data['load'])
# Set remaining node capacity
self.params.network.nodes[current_node_id]["remaining_cap"] = node_cap - used_total_capacitiy
self.params.network.nodes[current_node_id]['remaining_cap'] = node_cap - used_total_capacitiy
# Just for the sake of keeping lines small, the node_remaining_cap is updated again.
node_remaining_cap = self.params.network.nodes[current_node_id]["remaining_cap"]

Expand Down
7 changes: 7 additions & 0 deletions src/coordsim/simulation/simulatorparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def __init__(self, network, ing_nodes, sfc_list, sf_list, config, seed, schedule
self.schedule = schedule
# Placement of SFs in each node: defaultdict(list)
self.sf_placement = sf_placement
# Update which sf is available at which node
for node_id, placed_sf_list in sf_placement.items():
available_sf = {}
for sf in placed_sf_list:
available_sf[sf] = self.network.nodes[node_id]['available_sf'].get(sf, {'load': 0.0})
self.network.nodes[node_id]['available_sf'] = available_sf


# Flow interarrival exponential distribution mean: float
self.inter_arr_mean = config['inter_arrival_mean']
Expand Down