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
Next Next commit
Modified simulator interface to accept resource function path and rea…
…der now attempts to load functions
  • Loading branch information
ldklenner committed Aug 20, 2019
commit 952a518bebe83dcab9246fcde0437f8b8981b9b3
2 changes: 2 additions & 0 deletions params/services/abc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ sf_list:
a:
processing_delay_mean: 5.0
processing_delay_stdev: 0.0
resource_function_id: A
b:
processing_delay_mean: 5.0
processing_delay_stdev: 0.0
resource_function_id: B
c:
processing_delay_mean: 5.0
processing_delay_stdev: 0.0
28 changes: 27 additions & 1 deletion src/coordsim/reader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import yaml
import math
from collections import defaultdict
import importlib


# Disclaimer: Some snippets of the following file were imported/modified from B-JointSP on GitHub.
Expand Down Expand Up @@ -40,7 +41,21 @@ def get_sfc(sfc_file):
return sfc_list


def get_sf(sf_file):
def load_resource_function(name, path):
try:
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:
raise Exception(f'Cannot load file {name}.py located at {path}.')

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


def get_sf(sf_file, resource_functions_path):
"""
Get the list of SFs and their properties from the yaml data.
"""
Expand All @@ -58,6 +73,17 @@ def get_sf(sf_file):
default_processing_delay_mean)
sf_list[sf_name]["processing_delay_stdev"] = sf_list[sf_name].get("processing_delay_stdev",
default_processing_delay_stdev)
if 'resource_function_id' in sf_list[sf_name]:
try:
sf_list[sf_name]["resource_function"] = load_resource_function(sf_list[sf_name]['resource_function_id'],
resource_functions_path)
except Exception as ex:
sf_list[sf_name]["resource_function_id"] = 'default'
sf_list[sf_name]["resource_function"] = lambda x: x
log.warning(f'{repr(ex)} Default resource function will be used instead.')
else:
sf_list[sf_name]["resource_function_id"] = 'default'
sf_list[sf_name]["resource_function"] = lambda x: x
return sf_list


Expand Down
4 changes: 2 additions & 2 deletions src/siminterface/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, test_mode=False):
# Create CSV writer
self.writer = ResultWriter(self.test_mode)

def init(self, network_file, service_functions_file, config_file, seed):
def init(self, network_file, service_functions_file, config_file, seed, resource_functions_path):

# Initialize metrics, record start time
metrics.reset()
Expand All @@ -31,7 +31,7 @@ def init(self, network_file, service_functions_file, config_file, seed):
# Parse network and SFC + SF file
self.network, self.ing_nodes = reader.read_network(network_file, node_cap=10, link_cap=10)
self.sfc_list = reader.get_sfc(service_functions_file)
self.sf_list = reader.get_sf(service_functions_file)
self.sf_list = reader.get_sf(service_functions_file, resource_functions_path)
self.config = reader.get_config(config_file)

# Generate SimPy simulation environment
Expand Down