From fd7f68b6a50ef1bdce55dfbffe5800da0fd08ca7 Mon Sep 17 00:00:00 2001 From: Hadi Date: Fri, 27 Oct 2017 14:51:42 +0200 Subject: [PATCH] add placement SSM --- son-mano-framework | 2 +- .../Gerneral_placement/Dockerfile | 45 +++++ .../Gerneral_placement/Dockerfile~ | 45 +++++ .../Gerneral_placement/MANIFEST.in | 2 + son-ssm-examples/Gerneral_placement/README.md | 58 ++++++ .../Gerneral_placement/placement/__init__.py | 0 .../Gerneral_placement/placement/__main__.py | 8 + .../Gerneral_placement/placement/placement.py | 185 ++++++++++++++++++ son-ssm-examples/Gerneral_placement/setup.py | 76 +++++++ .../Gerneral_placement/test/fake_smr_place.py | 86 ++++++++ .../test/placementtrigger.py | 99 ++++++++++ .../Gerneral_placement/test/vnfd1.yml | 118 +++++++++++ .../Gerneral_placement/test/vnfd2.yml | 118 +++++++++++ son-ssm-examples/PSA_placement/Dockerfile | 45 +++++ son-ssm-examples/PSA_placement/MANIFEST.in | 2 + son-ssm-examples/PSA_placement/README.md | 58 ++++++ .../PSA_placement/placement/__init__.py | 0 .../PSA_placement/placement/__main__.py | 8 + .../PSA_placement/placement/placement.py | 164 ++++++++++++++++ son-ssm-examples/PSA_placement/setup.py | 76 +++++++ .../PSA_placement/test/fake_smr_place.py | 86 ++++++++ son-ssm-examples/PSA_placement/test/nsd.yml | 123 ++++++++++++ .../PSA_placement/test/placementtrigger.py | 104 ++++++++++ son-ssm-examples/PSA_placement/test/vnfd1.yml | 84 ++++++++ son-ssm-examples/PSA_placement/test/vnfd2.yml | 84 ++++++++ son-ssm-examples/PSA_placement/test/vnfd3.yml | 84 ++++++++ son-ssm-examples/PSA_placement/test/vnfd4.yml | 84 ++++++++ son-ssm-examples/PSA_placement/test/vnfd5.yml | 84 ++++++++ son-ssm-examples/PSA_placement/test/vnfd6.yml | 84 ++++++++ son-ssm-examples/PSA_placement/test/vnfd7.yml | 84 ++++++++ 30 files changed, 2095 insertions(+), 1 deletion(-) create mode 100644 son-ssm-examples/Gerneral_placement/Dockerfile create mode 100644 son-ssm-examples/Gerneral_placement/Dockerfile~ create mode 100644 son-ssm-examples/Gerneral_placement/MANIFEST.in create mode 100644 son-ssm-examples/Gerneral_placement/README.md create mode 100644 son-ssm-examples/Gerneral_placement/placement/__init__.py create mode 100644 son-ssm-examples/Gerneral_placement/placement/__main__.py create mode 100644 son-ssm-examples/Gerneral_placement/placement/placement.py create mode 100644 son-ssm-examples/Gerneral_placement/setup.py create mode 100644 son-ssm-examples/Gerneral_placement/test/fake_smr_place.py create mode 100644 son-ssm-examples/Gerneral_placement/test/placementtrigger.py create mode 100644 son-ssm-examples/Gerneral_placement/test/vnfd1.yml create mode 100644 son-ssm-examples/Gerneral_placement/test/vnfd2.yml create mode 100644 son-ssm-examples/PSA_placement/Dockerfile create mode 100644 son-ssm-examples/PSA_placement/MANIFEST.in create mode 100644 son-ssm-examples/PSA_placement/README.md create mode 100644 son-ssm-examples/PSA_placement/placement/__init__.py create mode 100644 son-ssm-examples/PSA_placement/placement/__main__.py create mode 100644 son-ssm-examples/PSA_placement/placement/placement.py create mode 100644 son-ssm-examples/PSA_placement/setup.py create mode 100644 son-ssm-examples/PSA_placement/test/fake_smr_place.py create mode 100644 son-ssm-examples/PSA_placement/test/nsd.yml create mode 100644 son-ssm-examples/PSA_placement/test/placementtrigger.py create mode 100644 son-ssm-examples/PSA_placement/test/vnfd1.yml create mode 100644 son-ssm-examples/PSA_placement/test/vnfd2.yml create mode 100644 son-ssm-examples/PSA_placement/test/vnfd3.yml create mode 100644 son-ssm-examples/PSA_placement/test/vnfd4.yml create mode 100644 son-ssm-examples/PSA_placement/test/vnfd5.yml create mode 100644 son-ssm-examples/PSA_placement/test/vnfd6.yml create mode 100644 son-ssm-examples/PSA_placement/test/vnfd7.yml diff --git a/son-mano-framework b/son-mano-framework index a698d46..6ba0d6b 160000 --- a/son-mano-framework +++ b/son-mano-framework @@ -1 +1 @@ -Subproject commit a698d4699a5ee00fd4dbbd6eaa3fcc9269780e29 +Subproject commit 6ba0d6beec5e4c91b0e4c2354d6302fa7a3e8cbd diff --git a/son-ssm-examples/Gerneral_placement/Dockerfile b/son-ssm-examples/Gerneral_placement/Dockerfile new file mode 100644 index 0000000..63238bc --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/Dockerfile @@ -0,0 +1,45 @@ +# Copyright (c) 2015 SONATA-NFV +# ALL RIGHTS RESERVED. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +# nor the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# This work has been performed in the framework of the SONATA project, +# funded by the European Commission under Grant number 671517 through +# the Horizon 2020 and 5G-PPP programmes. The authors would like to +# acknowledge the contributions of their colleagues of the SONATA +# partner consortium (www.sonata-nfv.eu). + +FROM python:3.4-slim +MAINTAINER SONATA + +# configrurations +ENV mongo_host mongo +ENV mongo_port 27017 +ENV broker_host amqp://guest:guest@broker:5672/%2F +ENV broker_exchange son-kernel + +ADD son-ssm-examples/General_placement /placement +ADD son-mano-framework/son-mano-base /son-mano-base +ADD son-sm-template /son-sm-template +ADD utils/delayedstart.sh /delayedstart.sh + +WORKDIR /son-mano-base +Run python setup.py install + +WORKDIR /son-sm-template +RUN python setup.py install + +WORKDIR /placement +RUN python setup.py develop + +CMD ["placement"] diff --git a/son-ssm-examples/Gerneral_placement/Dockerfile~ b/son-ssm-examples/Gerneral_placement/Dockerfile~ new file mode 100644 index 0000000..b3256f7 --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/Dockerfile~ @@ -0,0 +1,45 @@ +# Copyright (c) 2015 SONATA-NFV +# ALL RIGHTS RESERVED. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +# nor the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# This work has been performed in the framework of the SONATA project, +# funded by the European Commission under Grant number 671517 through +# the Horizon 2020 and 5G-PPP programmes. The authors would like to +# acknowledge the contributions of their colleagues of the SONATA +# partner consortium (www.sonata-nfv.eu). + +FROM python:3.4-slim +MAINTAINER SONATA + +# configrurations +ENV mongo_host mongo +ENV mongo_port 27017 +ENV broker_host amqp://guest:guest@broker:5672/%2F +ENV broker_exchange son-kernel + +ADD son-ssm-examples/placement /placement +ADD son-mano-framework/son-mano-base /son-mano-base +ADD son-sm-template /son-sm-template +ADD utils/delayedstart.sh /delayedstart.sh + +WORKDIR /son-mano-base +Run python setup.py install + +WORKDIR /son-sm-template +RUN python setup.py install + +WORKDIR /placement +RUN python setup.py develop + +CMD ["placement"] diff --git a/son-ssm-examples/Gerneral_placement/MANIFEST.in b/son-ssm-examples/Gerneral_placement/MANIFEST.in new file mode 100644 index 0000000..892a4d9 --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/MANIFEST.in @@ -0,0 +1,2 @@ +# Include the license file +include ../../LICENSE diff --git a/son-ssm-examples/Gerneral_placement/README.md b/son-ssm-examples/Gerneral_placement/README.md new file mode 100644 index 0000000..6fec098 --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/README.md @@ -0,0 +1,58 @@ +# Placement SSM Example (in progress) +An example of placement SSM taking care of service placement. + +## Requires +* Docker +* Python3.4 +* RabbitMQ + +## Implementation +* Implemented in Python 3.4 +* Dependencies: amqp-storm +* The main implementation can be found in: `son-ssm-examples/placement/placement.py` + +## How to run it + +* To run the placement SSM locally, you need: + * a running RabbitMQ broker (see general README.md of [son-mano framework repository](https://github.com/sonata-nfv/son-mano-framework) for info on how to do this) + * a running Service Specific Registry (SMR) connected to the broker (see general README.md of [SMR repository](https://github.com/sonata-nfv/son-mano-framework) for info on how to do this) + +* Run the placement SSM (in a Docker container): + * (do in `son-sm/`) + * `docker build -t sonssmservice1placement1 -f son-ssm-examples/placement/Dockerfile .` + * `docker run -it --rm --link broker:broker --name sonssmservice1placement1 sonssmservice1placement1` + +* Or: Run the placement SSM (directly in your terminal not in a Docker container): + * (In `son-sm/son-sm-template/`) + * `python3.4 setup.py install` + * (In `son-sm/son-ssm-examples/placement/`) + * `python3.4 setup.py develop` + * (In `son-sm/`) + * `python3.4 son-ssm-examples/placement/placement/placement.py` + +## How to test it +* Do the following; each in a separate terminal. + 1. Run the SMR container + 2. Run the placement container + 3. In son-sm/son-ssm-examples/placement/test run python3.4 placementtrigger.py + +* The expected results are as follows: + + * In the SMR terminal: + + ``` + DEBUG:son-mano-specific-manager-registry:registration request received for: sonssmservice1placement1 + INFO:son-mano-specific-manager-registry:sonssmservice1placement1 status: Placement decision was sent: {'placement': ['from_ssm']} + ``` + + * In placement terminal: + + ``` + INFO:son-sm-base:Starting sonssmservice1placement1 ... + INFO:son-sm-base:sonssmservice1placement1 registered with uuid:d88f37a2-6ca4-47cb-a103-833f5fc29fb9 + DEBUG:ssm-placement-1:Received registration ok event. + INFO:ssm-placement-1:Subscribed to placement.ssm.1234 + WARNING:amqpstorm.channel:Received Basic.Cancel on consumer_tag: q.specific.manager.registry.ssm.registration.2e50cc94-abc8-4663-b1dc-91c12c6a10fa + INFO:ssm-placement-1:Placement request received: {cpu: '20', location: DE, memory: '30'} + INFO:ssm-placement-1:Placement decision was sent: {'placement': ['from_ssm']} + ``` diff --git a/son-ssm-examples/Gerneral_placement/placement/__init__.py b/son-ssm-examples/Gerneral_placement/placement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/son-ssm-examples/Gerneral_placement/placement/__main__.py b/son-ssm-examples/Gerneral_placement/placement/__main__.py new file mode 100644 index 0000000..6813c9a --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/placement/__main__.py @@ -0,0 +1,8 @@ +from placement import placement + + +def main(): + placement.main() + +if __name__ == '__main__': + main() diff --git a/son-ssm-examples/Gerneral_placement/placement/placement.py b/son-ssm-examples/Gerneral_placement/placement/placement.py new file mode 100644 index 0000000..ef864af --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/placement/placement.py @@ -0,0 +1,185 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. + +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +import logging +import yaml +from sonsmbase.smbase import sonSMbase + +logging.basicConfig(level=logging.INFO) +LOG = logging.getLogger("ssm-placement-1") +LOG.setLevel(logging.DEBUG) +logging.getLogger("son-mano-base:messaging").setLevel(logging.INFO) + + +class PlacementSSM(sonSMbase): + + def __init__(self): + + """ + :param specific_manager_type: specifies the type of specific manager that could be either fsm or ssm. + :param service_name: the name of the service that this specific manager belongs to. + :param function_name: the name of the function that this specific manager belongs to, will be null in SSM case + :param specific_manager_name: the actual name of specific manager (e.g., scaling, placement) + :param id_number: the specific manager id number which is used to distinguish between multiple SSM/FSM + that are created for the same objective (e.g., scaling with algorithm 1 and 2) + :param version: version + :param description: description + """ + self.specific_manager_type = 'ssm' + self.service_name = 'service1' + self.specific_manager_name = 'placement' + self.id_number = '1' + self.version = 'v0.1' + self.description = "Placement SSM" + + super(self.__class__, self).__init__(specific_manager_type= self.specific_manager_type, + service_name= self.service_name, + specific_manager_name = self.specific_manager_name, + id_number = self.id_number, + version = self.version, + description = self.description) + + + def on_registration_ok(self): + + LOG.debug("Received registration ok event.") + + # For testing, here we set the service uuid. + # In the actual scenario this should be set by SLM and SMR during the SSM instantiation. + self.sfuuid = '1234' + + # Register to placement topic. + topic = 'placement.ssm.' + self.sfuuid + + self.manoconn.register_async_endpoint(self.on_place,topic= topic) + + LOG.info("Subscribed to {0}".format(topic)) + + def on_place(self, ch, method, properties, payload): + """ + This method organises the placement calculation, and + provides the response for the SLM. + """ + + LOG.info("Placement started") + message = yaml.load(payload) + topology = message['topology'] + nsd = message['nsd'] + functions = message['vnfds'] + nap = message['nap'] + + mapping = self.placement_alg(nsd, functions, topology, nap) + + if mapping is None: + LOG.info("The mapping calculation has failed.") + message = {} + message['error'] = 'Unable to perform placement.' + message['status'] = 'ERROR' + + else: + LOG.info("The mapping calculation has succeeded.") + message = {} + message['error'] = None + message['status'] = "COMPLETED" + message['mapping'] = mapping + + is_dict = isinstance(message, dict) + LOG.info("Type Dict: " + str(is_dict)) + + payload = yaml.dump(message) + self.manoconn.notify('placement.ssm.' + self.sfuuid, + payload, + correlation_id=properties.correlation_id) + + return + + def placement_alg(self, nsd, functions, topology, nap): + """ + This is the default placement algorithm that is used if the SLM + is responsible to perform the placement + """ + LOG.info("Mapping algorithm started.") + mapping = {} + + ingress = nap['ingress'][0]['location'] + egress = nap['egress'][0]['location'] + + for vnfd in functions: + needed_cpu = vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu']['vcpus'] + needed_mem = vnfd['virtual_deployment_units'][0]['resource_requirements']['memory']['size'] + + + #needed_sto = vnfd['virtual_deployment_units'][0]['resource_requirements']['storage']['size'] + + + if vnfd['name'] == 'vnfd1': + + for vim in topology: + + if vim['vim_city'] == ingress: + cpu_req = needed_cpu <= (vim['core_total'] - vim['core_used']) + mem_req = needed_mem <= (vim['memory_total'] - vim['memory_used']) + + + if cpu_req and mem_req: + print('VNF ' + vnfd['name'] + ' mapped on VIM ' + vim['vim_uuid']) + mapping[vnfd['name']] = {} + mapping[vnfd['name']]['vim'] = vim['vim_uuid'] + vim['core_used'] = vim['core_used'] + needed_cpu + vim['memory_used'] = vim['memory_used'] + needed_mem + break + + if vnfd['name'] == 'vnfd2': + + for vim in topology: + + if vim['vim_city'] == egress: + cpu_req = needed_cpu <= (vim['core_total'] - vim['core_used']) + mem_req = needed_mem <= (vim['memory_total'] - vim['memory_used']) + + if cpu_req and mem_req: + print('VNF ' + vnfd['name'] + ' mapped on VIM ' + vim['vim_uuid']) + mapping[vnfd['name']] = {} + mapping[vnfd['name']]['vim'] = vim['vim_uuid'] + vim['core_used'] = vim['core_used'] + needed_cpu + vim['memory_used'] = vim['memory_used'] + needed_mem + break + + + # Check if all VNFs have been mapped + if len(mapping.keys()) == len(functions): + LOG.info("Mapping succeeded: " + str(mapping)) + return mapping + else: + return None + +def main(): + PlacementSSM() + +if __name__ == '__main__': + main() diff --git a/son-ssm-examples/Gerneral_placement/setup.py b/son-ssm-examples/Gerneral_placement/setup.py new file mode 100644 index 0000000..5379955 --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/setup.py @@ -0,0 +1,76 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. + +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +# Always prefer setuptools over distutils +from setuptools import setup, find_packages +# To use a consistent encoding +from codecs import open +from os import path + +here = path.abspath(path.dirname(__file__)) + +# Get the long description from the README file +with open(path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + +setup( + name='placement', + + # Versions should comply with PEP440. For a discussion on single-sourcing + # the version across setup.py and the project code, see + # https://packaging.python.org/en/latest/single_source_version.html + version='0.0.1', + + description='Placement SSM example', + long_description=long_description, + + # The project's main homepage. + url='https://github.com/sonata-nfv/son-mano-framework/tree/master/son-mano-specificmanager', + + # Author details + author='Hadi Razzaghi Kouchaksaraei', + author_email='hadi.razzaghi@upb.de', + + # Choose your license + license='Apache 2.0', + + # What does your project relate to? + keywords='NFV orchestrator', + + packages=find_packages("placement"), + install_requires=['pika', 'pytest'], + setup_requires=['pytest-runner'], + + # To provide executable scripts, use entry points in preference to the + # "scripts" keyword. Entry points provide cross-platform support and allow + # pip to create the appropriate form of executable for the target platform. + entry_points={ + 'console_scripts': ['placement=placement.__main__:main'], + }, +) diff --git a/son-ssm-examples/Gerneral_placement/test/fake_smr_place.py b/son-ssm-examples/Gerneral_placement/test/fake_smr_place.py new file mode 100644 index 0000000..8fc8805 --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/test/fake_smr_place.py @@ -0,0 +1,86 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +import logging +import yaml +import time +from sonmanobase import messaging + +logging.basicConfig(level=logging.INFO) +LOG = logging.getLogger("son-mano-fakesmr") +LOG.setLevel(logging.DEBUG) +logging.getLogger("son-mano-base:messaging").setLevel(logging.INFO) + + +class fakesmr(object): + + def __init__(self): + + self.name = 'fake-smr' + self.version = '0.1-dev' + self.description = 'description' + + LOG.info("Start SMR:...") + + # create and initialize broker connection + self.manoconn = messaging.ManoBrokerRequestResponseConnection(self.name) + + #elf.end = False + + #self.publish_nsd() + + self.declare_subscriptions() + + def declare_subscriptions(self): + """ + Declare topics to which we want to listen and define callback methods. + """ + self.manoconn.register_async_endpoint(self.on_register_receive, 'specific.manager.registry.ssm.registration') + + def on_register_receive(self,ch, method, properties, payload): + + # go into infinity loop + message = yaml.load(payload) + + response = { + "status": "registered", + "specific_manager_type": message['specific_manager_type'], + "service_name": message['service_name'], + "function_name": message['function_name'], + "specific_manager_id": message['specific_manager_id'], + "version": message['version'], + "description": message['description'], + "uuid": '23345', + "sfuuid": None, + "error": None + } + + return yaml.dump(response) + + +def main(): + fakesmr() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/son-ssm-examples/Gerneral_placement/test/placementtrigger.py b/son-ssm-examples/Gerneral_placement/test/placementtrigger.py new file mode 100644 index 0000000..97c8344 --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/test/placementtrigger.py @@ -0,0 +1,99 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +import logging +import yaml +import time +from sonmanobase import messaging + +logging.basicConfig(level=logging.INFO) +LOG = logging.getLogger("placement-trigger") +LOG.setLevel(logging.DEBUG) +logging.getLogger("son-mano-base:messaging").setLevel(logging.INFO) + + +class fakealert(object): + def __init__(self): + + self.name = 'placement-trigger' + self.version = '0.1' + self.description = 'description' + + LOG.info("Starting triggering placement SSM:...") + + # create and initialize broker connection + self.manoconn = messaging.ManoBrokerRequestResponseConnection(self.name) + + self.path_descriptors = 'test/test_descriptors/' + self.end = False + + self.publish_nsd() + + self.run() + + def run(self): + + # go into infinity loop + + while self.end == False: + time.sleep(1) + + def publish_nsd(self): + + LOG.info("Sending placement request") + + vnfd1 = yaml.load(open('vnfd1.yml', 'r')) + vnfd2 = yaml.load(open('vnfd2.yml', 'r')) + + topology = [{"vim_uuid": "1234","vim_city": "Athens","vim_name": "abcd", "vim_endpoint": "12", "memory_total": + 32, "memory_used": 12,"core_total": 43, "core_used": 23}, {"vim_uuid": "1235","vim_city": "Aveiro","vim_name": "abcd", "vim_endpoint": "12", "memory_total": + 50, "memory_used": 10,"core_total": 65, "core_used": 30}] + + nap = {'ingress':[{"location":'Athens',"nap":'1223'}],'egress':[{"location":'Aveiro',"nap":'4321'}]} + + vnfds = [vnfd1,vnfd2] + + nsd = {} + + uuid = "1234" + + message = {"nsd":nsd, "topology": topology, "uuid": uuid, "vnfds":vnfds, "nap":nap} + + + + self.manoconn.call_async(self.on_publish_response, + 'placement.ssm.'+uuid, + yaml.dump(message)) + + def on_publish_response(self, ch, method, props, response): + + response = yaml.load(str(response)) + if type(response) == dict: + print(response) + +def main(): + fakealert() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/son-ssm-examples/Gerneral_placement/test/vnfd1.yml b/son-ssm-examples/Gerneral_placement/test/vnfd1.yml new file mode 100644 index 0000000..5d94a2c --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/test/vnfd1.yml @@ -0,0 +1,118 @@ +## Copyright (c) 2015 SONATA-NFV +## ALL RIGHTS RESERVED. +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## http://www.apache.org/licenses/LICENSE-2.0 +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +## nor the names of its contributors may be used to endorse or promote +## products derived from this software without specific prior written +## permission. +## This work has been performed in the framework of the SONATA project, +## funded by the European Commission under Grant number 671517 through +## the Horizon 2020 and 5G-PPP programmes. The authors would like to +## acknowledge the contributions of their colleagues of the SONATA +## partner consortium (www.sonata-nfv.eu). +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "vnfd-schema-01" + +vendor: "eu.sonata-nfv" +name: "vnfd1" +version: "0.2" +uuid: "645db4fa-a714-4cba-9617-4001477d1281" +author: "Steven van Rossem, iMinds" +description: > + "A first iperf VNF descriptor. The iperf VNF acts as a traffic source." + +## +## Some function specific managers. +## + +## +## Some function specific managers. +## image: Specifies the DockerHub URI (user/image name) to fetch the SSM image from. +## + +function_specific_managers: + + - id: "sonfsmservice1function1dumb1" + description: "An empty FSM example" + image: "hadik3r/sonfsmservice1function1dumb1" + options: + - key: "myKey" + value: "myValue" + +# - id: "sonfsmservice1function1dumb2" +# description: "An empty FSM" +# image: "hadik3r/sonfsmservice1function1dumb2" +# options: +# - key: "myKey" +# value: "myValue" + + + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "vdu01" + vm_image: "file:///docker_files/iperf/Dockerfile" + vm_image_format: "docker" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 2 + size_unit: "GB" + storage: + size: 10 + size_unit: "GB" + connection_points: + - id: "vdu01:cp01" + type: "interface" + - id: "vdu01:cp02" + type: "interface" + - id: "vdu01:cp03" + type: "interface" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "mgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "vdu01:cp01" + - "mgmt" + - id: "input" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:cp02" + - "input" + - id: "output" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:cp03" + - "output" + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "mgmt" + type: "interface" + - id: "input" + type: "interface" + - id: "output" + type: "interface" \ No newline at end of file diff --git a/son-ssm-examples/Gerneral_placement/test/vnfd2.yml b/son-ssm-examples/Gerneral_placement/test/vnfd2.yml new file mode 100644 index 0000000..609ecad --- /dev/null +++ b/son-ssm-examples/Gerneral_placement/test/vnfd2.yml @@ -0,0 +1,118 @@ +## Copyright (c) 2015 SONATA-NFV +## ALL RIGHTS RESERVED. +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## http://www.apache.org/licenses/LICENSE-2.0 +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +## nor the names of its contributors may be used to endorse or promote +## products derived from this software without specific prior written +## permission. +## This work has been performed in the framework of the SONATA project, +## funded by the European Commission under Grant number 671517 through +## the Horizon 2020 and 5G-PPP programmes. The authors would like to +## acknowledge the contributions of their colleagues of the SONATA +## partner consortium (www.sonata-nfv.eu). +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "vnfd-schema-01" + +vendor: "eu.sonata-nfv" +name: "vnfd2" +version: "0.2" +uuid: "645db4fa-a714-4cba-9617-4001477d1281" +author: "Steven van Rossem, iMinds" +description: > + "A first iperf VNF descriptor. The iperf VNF acts as a traffic source." + +## +## Some function specific managers. +## + +## +## Some function specific managers. +## image: Specifies the DockerHub URI (user/image name) to fetch the SSM image from. +## + +function_specific_managers: + + - id: "sonfsmservice1function1dumb1" + description: "An empty FSM example" + image: "hadik3r/sonfsmservice1function1dumb1" + options: + - key: "myKey" + value: "myValue" + +# - id: "sonfsmservice1function1dumb2" +# description: "An empty FSM" +# image: "hadik3r/sonfsmservice1function1dumb2" +# options: +# - key: "myKey" +# value: "myValue" + + + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "vdu01" + vm_image: "file:///docker_files/iperf/Dockerfile" + vm_image_format: "docker" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 2 + size_unit: "GB" + storage: + size: 10 + size_unit: "GB" + connection_points: + - id: "vdu01:cp01" + type: "interface" + - id: "vdu01:cp02" + type: "interface" + - id: "vdu01:cp03" + type: "interface" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "mgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "vdu01:cp01" + - "mgmt" + - id: "input" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:cp02" + - "input" + - id: "output" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:cp03" + - "output" + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "mgmt" + type: "interface" + - id: "input" + type: "interface" + - id: "output" + type: "interface" \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/Dockerfile b/son-ssm-examples/PSA_placement/Dockerfile new file mode 100644 index 0000000..ddbb506 --- /dev/null +++ b/son-ssm-examples/PSA_placement/Dockerfile @@ -0,0 +1,45 @@ +# Copyright (c) 2015 SONATA-NFV +# ALL RIGHTS RESERVED. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +# nor the names of its contributors may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# This work has been performed in the framework of the SONATA project, +# funded by the European Commission under Grant number 671517 through +# the Horizon 2020 and 5G-PPP programmes. The authors would like to +# acknowledge the contributions of their colleagues of the SONATA +# partner consortium (www.sonata-nfv.eu). + +FROM python:3.4-slim +MAINTAINER SONATA + +# configrurations +ENV mongo_host mongo +ENV mongo_port 27017 +ENV broker_host amqp://guest:guest@broker:5672/%2F +ENV broker_exchange son-kernel + +ADD son-ssm-examples/PSA_placement /placement +ADD son-mano-framework/son-mano-base /son-mano-base +ADD son-sm-template /son-sm-template +ADD utils/delayedstart.sh /delayedstart.sh + +WORKDIR /son-mano-base +Run python setup.py install + +WORKDIR /son-sm-template +RUN python setup.py install + +WORKDIR /placement +RUN python setup.py develop + +CMD ["placement"] diff --git a/son-ssm-examples/PSA_placement/MANIFEST.in b/son-ssm-examples/PSA_placement/MANIFEST.in new file mode 100644 index 0000000..892a4d9 --- /dev/null +++ b/son-ssm-examples/PSA_placement/MANIFEST.in @@ -0,0 +1,2 @@ +# Include the license file +include ../../LICENSE diff --git a/son-ssm-examples/PSA_placement/README.md b/son-ssm-examples/PSA_placement/README.md new file mode 100644 index 0000000..6fec098 --- /dev/null +++ b/son-ssm-examples/PSA_placement/README.md @@ -0,0 +1,58 @@ +# Placement SSM Example (in progress) +An example of placement SSM taking care of service placement. + +## Requires +* Docker +* Python3.4 +* RabbitMQ + +## Implementation +* Implemented in Python 3.4 +* Dependencies: amqp-storm +* The main implementation can be found in: `son-ssm-examples/placement/placement.py` + +## How to run it + +* To run the placement SSM locally, you need: + * a running RabbitMQ broker (see general README.md of [son-mano framework repository](https://github.com/sonata-nfv/son-mano-framework) for info on how to do this) + * a running Service Specific Registry (SMR) connected to the broker (see general README.md of [SMR repository](https://github.com/sonata-nfv/son-mano-framework) for info on how to do this) + +* Run the placement SSM (in a Docker container): + * (do in `son-sm/`) + * `docker build -t sonssmservice1placement1 -f son-ssm-examples/placement/Dockerfile .` + * `docker run -it --rm --link broker:broker --name sonssmservice1placement1 sonssmservice1placement1` + +* Or: Run the placement SSM (directly in your terminal not in a Docker container): + * (In `son-sm/son-sm-template/`) + * `python3.4 setup.py install` + * (In `son-sm/son-ssm-examples/placement/`) + * `python3.4 setup.py develop` + * (In `son-sm/`) + * `python3.4 son-ssm-examples/placement/placement/placement.py` + +## How to test it +* Do the following; each in a separate terminal. + 1. Run the SMR container + 2. Run the placement container + 3. In son-sm/son-ssm-examples/placement/test run python3.4 placementtrigger.py + +* The expected results are as follows: + + * In the SMR terminal: + + ``` + DEBUG:son-mano-specific-manager-registry:registration request received for: sonssmservice1placement1 + INFO:son-mano-specific-manager-registry:sonssmservice1placement1 status: Placement decision was sent: {'placement': ['from_ssm']} + ``` + + * In placement terminal: + + ``` + INFO:son-sm-base:Starting sonssmservice1placement1 ... + INFO:son-sm-base:sonssmservice1placement1 registered with uuid:d88f37a2-6ca4-47cb-a103-833f5fc29fb9 + DEBUG:ssm-placement-1:Received registration ok event. + INFO:ssm-placement-1:Subscribed to placement.ssm.1234 + WARNING:amqpstorm.channel:Received Basic.Cancel on consumer_tag: q.specific.manager.registry.ssm.registration.2e50cc94-abc8-4663-b1dc-91c12c6a10fa + INFO:ssm-placement-1:Placement request received: {cpu: '20', location: DE, memory: '30'} + INFO:ssm-placement-1:Placement decision was sent: {'placement': ['from_ssm']} + ``` diff --git a/son-ssm-examples/PSA_placement/placement/__init__.py b/son-ssm-examples/PSA_placement/placement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/son-ssm-examples/PSA_placement/placement/__main__.py b/son-ssm-examples/PSA_placement/placement/__main__.py new file mode 100644 index 0000000..6813c9a --- /dev/null +++ b/son-ssm-examples/PSA_placement/placement/__main__.py @@ -0,0 +1,8 @@ +from placement import placement + + +def main(): + placement.main() + +if __name__ == '__main__': + main() diff --git a/son-ssm-examples/PSA_placement/placement/placement.py b/son-ssm-examples/PSA_placement/placement/placement.py new file mode 100644 index 0000000..dd68b10 --- /dev/null +++ b/son-ssm-examples/PSA_placement/placement/placement.py @@ -0,0 +1,164 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. + +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +import logging +import yaml +from sonsmbase.smbase import sonSMbase + +logging.basicConfig(level=logging.INFO) +LOG = logging.getLogger("PSA-ssm-placement") +LOG.setLevel(logging.DEBUG) +logging.getLogger("son-mano-base:messaging").setLevel(logging.INFO) + + +class PlacementSSM(sonSMbase): + + def __init__(self): + + """ + :param specific_manager_type: specifies the type of specific manager that could be either fsm or ssm. + :param service_name: the name of the service that this specific manager belongs to. + :param function_name: the name of the function that this specific manager belongs to, will be null in SSM case + :param specific_manager_name: the actual name of specific manager (e.g., scaling, placement) + :param id_number: the specific manager id number which is used to distinguish between multiple SSM/FSM + that are created for the same objective (e.g., scaling with algorithm 1 and 2) + :param version: version + :param description: description + """ + self.specific_manager_type = 'ssm' + self.service_name = 'psa' + self.specific_manager_name = 'placement' + self.id_number = '1' + self.version = 'v0.1' + self.description = "Placement SSM" + + super(self.__class__, self).__init__(specific_manager_type= self.specific_manager_type, + service_name= self.service_name, + specific_manager_name = self.specific_manager_name, + id_number = self.id_number, + version = self.version, + description = self.description) + + + def on_registration_ok(self): + + LOG.debug("Received registration ok event.") + + # For testing, here we set the service uuid. + # In the actual scenario this should be set by SLM and SMR during the SSM instantiation. + self.sfuuid = '1234' + + # Register to placement topic. + topic = 'placement.ssm.' + self.sfuuid + + self.manoconn.register_async_endpoint(self.on_place,topic= topic) + + LOG.info("Subscribed to {0}".format(topic)) + + def on_place(self, ch, method, properties, payload): + """ + This method organises the placement calculation, and + provides the response for the SLM. + """ + + LOG.info("Placement started") + message = yaml.load(payload) + topology = message['topology'] + nsd = message['nsd'] + functions = message['vnfds'] + nap = message['nap'] + + mapping = self.placement_alg(nsd, functions, topology, nap) + + if mapping is None: + LOG.info("The mapping calculation has failed.") + message = {} + message['error'] = 'Unable to perform placement.' + message['status'] = 'ERROR' + + else: + LOG.info("The mapping calculation has succeeded.") + message = {} + message['error'] = None + message['status'] = "COMPLETED" + message['mapping'] = mapping + + is_dict = isinstance(message, dict) + LOG.info("Type Dict: " + str(is_dict)) + + payload = yaml.dump(message) + self.manoconn.notify('placement.ssm.' + self.sfuuid, + payload, + correlation_id=properties.correlation_id) + + return + + def placement_alg(self, nsd, functions, topology, nap): + """ + This is the default placement algorithm that is used if the SLM + is responsible to perform the placement + """ + LOG.info("Mapping algorithm started.") + mapping = {} + + ingress = nap['ingress'][0]['location'] + egress = nap['egress'][0]['location'] + + total_core = 0 + total_memory = 0 + + for vnfd in functions: + needed_cpu = vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu']['vcpus'] + needed_mem = vnfd['virtual_deployment_units'][0]['resource_requirements']['memory']['size'] + + total_core += needed_cpu + total_memory += needed_mem + + for vim in topology: + + if total_core <= (vim['core_total'] - vim['core_used']) and total_memory <= (vim['memory_total'] - vim['memory_used']): + + #place all VNF in one POP + for vnfd in functions: + print('VNF ' + vnfd['name'] + ' mapped on VIM ' + vim['vim_uuid']) + mapping[vnfd['name']] = {} + mapping[vnfd['name']]['vim'] = vim['vim_uuid'] + break + + # Check if all VNFs have been mapped + if len(mapping.keys()) == len(functions): + LOG.info("Mapping succeeded: " + str(mapping)) + return mapping + else: + return None + +def main(): + PlacementSSM() + +if __name__ == '__main__': + main() diff --git a/son-ssm-examples/PSA_placement/setup.py b/son-ssm-examples/PSA_placement/setup.py new file mode 100644 index 0000000..5379955 --- /dev/null +++ b/son-ssm-examples/PSA_placement/setup.py @@ -0,0 +1,76 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. + +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +# Always prefer setuptools over distutils +from setuptools import setup, find_packages +# To use a consistent encoding +from codecs import open +from os import path + +here = path.abspath(path.dirname(__file__)) + +# Get the long description from the README file +with open(path.join(here, 'README.md'), encoding='utf-8') as f: + long_description = f.read() + +setup( + name='placement', + + # Versions should comply with PEP440. For a discussion on single-sourcing + # the version across setup.py and the project code, see + # https://packaging.python.org/en/latest/single_source_version.html + version='0.0.1', + + description='Placement SSM example', + long_description=long_description, + + # The project's main homepage. + url='https://github.com/sonata-nfv/son-mano-framework/tree/master/son-mano-specificmanager', + + # Author details + author='Hadi Razzaghi Kouchaksaraei', + author_email='hadi.razzaghi@upb.de', + + # Choose your license + license='Apache 2.0', + + # What does your project relate to? + keywords='NFV orchestrator', + + packages=find_packages("placement"), + install_requires=['pika', 'pytest'], + setup_requires=['pytest-runner'], + + # To provide executable scripts, use entry points in preference to the + # "scripts" keyword. Entry points provide cross-platform support and allow + # pip to create the appropriate form of executable for the target platform. + entry_points={ + 'console_scripts': ['placement=placement.__main__:main'], + }, +) diff --git a/son-ssm-examples/PSA_placement/test/fake_smr_place.py b/son-ssm-examples/PSA_placement/test/fake_smr_place.py new file mode 100644 index 0000000..8fc8805 --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/fake_smr_place.py @@ -0,0 +1,86 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +import logging +import yaml +import time +from sonmanobase import messaging + +logging.basicConfig(level=logging.INFO) +LOG = logging.getLogger("son-mano-fakesmr") +LOG.setLevel(logging.DEBUG) +logging.getLogger("son-mano-base:messaging").setLevel(logging.INFO) + + +class fakesmr(object): + + def __init__(self): + + self.name = 'fake-smr' + self.version = '0.1-dev' + self.description = 'description' + + LOG.info("Start SMR:...") + + # create and initialize broker connection + self.manoconn = messaging.ManoBrokerRequestResponseConnection(self.name) + + #elf.end = False + + #self.publish_nsd() + + self.declare_subscriptions() + + def declare_subscriptions(self): + """ + Declare topics to which we want to listen and define callback methods. + """ + self.manoconn.register_async_endpoint(self.on_register_receive, 'specific.manager.registry.ssm.registration') + + def on_register_receive(self,ch, method, properties, payload): + + # go into infinity loop + message = yaml.load(payload) + + response = { + "status": "registered", + "specific_manager_type": message['specific_manager_type'], + "service_name": message['service_name'], + "function_name": message['function_name'], + "specific_manager_id": message['specific_manager_id'], + "version": message['version'], + "description": message['description'], + "uuid": '23345', + "sfuuid": None, + "error": None + } + + return yaml.dump(response) + + +def main(): + fakesmr() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/nsd.yml b/son-ssm-examples/PSA_placement/test/nsd.yml new file mode 100644 index 0000000..3e4bc85 --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/nsd.yml @@ -0,0 +1,123 @@ +## +## This is the NSD of SONATA's PSA pilot +## +## @author SONATA +## +--- +descriptor_version: "1.0" + +vendor: "eu.sonata-nfv.service-descriptor" +name: "sonata-psa" +version: "0.6" +author: "SONATA Consortium" +description: > + "Reconfigurable personal security appliance." +## +## The various network functions this service +## is composed of. +## +network_functions: + - vnf_id: "vnf_vpn" + vnf_vendor: "eu.sonata-nfv" + vnf_name: "vpn-vnf" + vnf_version: "0.6" + - vnf_id: "vnf_cache" + vnf_vendor: "eu.sonata-nfv" + vnf_name: "cache-vnf" + vnf_version: "0.1" + - vnf_id: "vnf_fw" + vnf_vendor: "eu.sonata-nfv" + vnf_name: "fw-vnf" + vnf_version: "0.6" +# - vnf_id: "vnf_ids" +# vnf_vendor: "eu.sonata-nfv" +# vnf_name: "ids-vnf" +# vnf_version: "0.1" +# - vnf_id: "vnf_tor" +# vnf_vendor: "eu.sonata-nfv" +# vnf_name: "tor-vnf" +# vnf_version: "0.1" + +## +## Some service specific managers. +## image: Specifies the DockerHub URI (user/image name) to fetch the SSM image from. +## + +service_specific_managers: + - id: "sonssmpsaplacement1" + description: "PSA placement SSM." + image: "hadik3r/sonssmpsaplacement1" + options: + - key: "myKey" + value: "myValue" + + +## +## The NS connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "external" + - id: "cpoutput" + interface: "ipv4" + type: "external" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "mgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "vnf_vpn:cpmgmt" + - "vnf_cache:cpmgmt" + - "vnf_fw:cpmgmt" + - "vnf_ids:cpmgmt" + - "vnf_tor:cpmgmt" + - "cpmgmt" + - id: "input-2-vpn" + connectivity_type: "E-Line" + connection_points_reference: + - "cpinput" + - "vnf_vpn:cpinput" + - id: "vpn-2-fw" + connectivity_type: "E-Line" + connection_points_reference: + - "vnf_vpn:cpoutput" + - "vnf_fw:cpinput" + - id: "fw-2-output" + connectivity_type: "E-Line" + connection_points_reference: + - "vnf_fw:cpoutput" + - "cpoutput" +## +## The forwarding graphs. +## +forwarding_graphs: + - fg_id: "ns:fg01" + number_of_endpoints: 2 + number_of_virtual_links: 3 + constituent_vnfs: + - "vnf_vtc" + network_forwarding_paths: + - fp_id: "ns:fg01:fp01" + policy: "none" + connection_points: + - connection_point_ref: "cpinput" + position: 1 + - connection_point_ref: "vnf_vpn:cpinput" + position: 2 + - connection_point_ref: "vnf_vpn:cpoutput" + position: 3 + - connection_point_ref: "vnf_fw:cpinput" + position: 4 + - connection_point_ref: "vnf_fw:cpoutput" + position: 5 + - connection_point_ref: "cpoutput" + position: 6 \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/placementtrigger.py b/son-ssm-examples/PSA_placement/test/placementtrigger.py new file mode 100644 index 0000000..212fb1a --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/placementtrigger.py @@ -0,0 +1,104 @@ +""" +Copyright (c) 2015 SONATA-NFV +ALL RIGHTS RESERVED. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +the Horizon 2020 and 5G-PPP programmes. The authors would like to +acknowledge the contributions of their colleagues of the SONATA +partner consortium (www.sonata-nfv.eu). +""" + +import logging +import yaml +import time +from sonmanobase import messaging + +logging.basicConfig(level=logging.INFO) +LOG = logging.getLogger("placement-trigger") +LOG.setLevel(logging.DEBUG) +logging.getLogger("son-mano-base:messaging").setLevel(logging.INFO) + + +class fakealert(object): + def __init__(self): + + self.name = 'placement-trigger' + self.version = '0.1' + self.description = 'description' + + LOG.info("Starting triggering placement SSM:...") + + # create and initialize broker connection + self.manoconn = messaging.ManoBrokerRequestResponseConnection(self.name) + + self.path_descriptors = 'test/test_descriptors/' + self.end = False + + self.publish_nsd() + + self.run() + + def run(self): + + # go into infinity loop + + while self.end == False: + time.sleep(1) + + def publish_nsd(self): + + LOG.info("Sending placement request") + + vnfd1 = yaml.load(open('vnfd1.yml', 'r')) + vnfd2 = yaml.load(open('vnfd2.yml', 'r')) + vnfd3 = yaml.load(open('vnfd3.yml', 'r')) + vnfd4 = yaml.load(open('vnfd4.yml', 'r')) + vnfd5 = yaml.load(open('vnfd5.yml', 'r')) + vnfd6 = yaml.load(open('vnfd6.yml', 'r')) + vnfd7 = yaml.load(open('vnfd7.yml', 'r')) + + topology = [{"vim_uuid": "1234","vim_city": "Athens","vim_name": "abcd", "vim_endpoint": "12", "memory_total": + 32, "memory_used": 12,"core_total": 43, "core_used": 23}, {"vim_uuid": "1235","vim_city": "Aveiro","vim_name": "abcd", "vim_endpoint": "12", "memory_total": + 50, "memory_used": 10,"core_total": 65, "core_used": 30}] + + nap = {'ingress':[{"location":'',"nap":''}],'egress':[{"location":'',"nap":''}]} + + vnfds = [vnfd1,vnfd2,vnfd3,vnfd4,vnfd5,vnfd6,vnfd7] + + nsd = {} + + uuid = "1234" + + message = {"nsd":nsd, "topology": topology, "uuid": uuid, "vnfds":vnfds, "nap":nap} + + + + self.manoconn.call_async(self.on_publish_response, + 'placement.ssm.'+uuid, + yaml.dump(message)) + + def on_publish_response(self, ch, method, props, response): + + response = yaml.load(str(response)) + if type(response) == dict: + print(response) + +def main(): + fakealert() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/vnfd1.yml b/son-ssm-examples/PSA_placement/test/vnfd1.yml new file mode 100644 index 0000000..61e2eb9 --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/vnfd1.yml @@ -0,0 +1,84 @@ +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "1.0" +vendor: "eu.sonata-nfv" +name: "cache-vnf" +version: "0.1" +author: "Miguel Mesquita, AlticeLabs, mesquita@alticelabs.com" +description: "The Squid HTTP proxy VNF for the PSA pilot" + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-psa-pilot/squid-vnf/squid-3.5.12-img.qcow2" + vm_image_format: "qcow2" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 1 + size_unit: "GB" + storage: + size: 1 + size_unit: "GB" + monitoring_parameters: + - name: "vm_cpu_perc" + unit: "Percentage" + - name: "vm_mem_perc" + unit: "Percentage" + - name: "vm_net_rx_bps" + unit: "bps" + - name: "vm_net_tx_bps" + unit: "bps" + connection_points: + - id: "cpeth0" + interface: "ipv4" + type: "internal" + - id: "cpeth1" + interface: "ipv4" + type: "internal" + - id: "cpeth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "vlmgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:cpeth0" + - "cpmgmt" + - id: "vlinput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth1" + - "cpinput" + - id: "vloutput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth2" + - "cpoutput" + + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "internal" + - id: "cpoutput" + interface: "ipv4" + type: "internal" \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/vnfd2.yml b/son-ssm-examples/PSA_placement/test/vnfd2.yml new file mode 100644 index 0000000..0a5d10a --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/vnfd2.yml @@ -0,0 +1,84 @@ +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "1.0" +vendor: "eu.sonata-nfv" +name: "cache-vnf1" +version: "0.1" +author: "Miguel Mesquita, AlticeLabs, mesquita@alticelabs.com" +description: "The Squid HTTP proxy VNF for the PSA pilot" + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-psa-pilot/squid-vnf/squid-3.5.12-img.qcow2" + vm_image_format: "qcow2" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 1 + size_unit: "GB" + storage: + size: 1 + size_unit: "GB" + monitoring_parameters: + - name: "vm_cpu_perc" + unit: "Percentage" + - name: "vm_mem_perc" + unit: "Percentage" + - name: "vm_net_rx_bps" + unit: "bps" + - name: "vm_net_tx_bps" + unit: "bps" + connection_points: + - id: "cpeth0" + interface: "ipv4" + type: "internal" + - id: "cpeth1" + interface: "ipv4" + type: "internal" + - id: "cpeth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "vlmgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:cpeth0" + - "cpmgmt" + - id: "vlinput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth1" + - "cpinput" + - id: "vloutput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth2" + - "cpoutput" + + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "internal" + - id: "cpoutput" + interface: "ipv4" + type: "internal" \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/vnfd3.yml b/son-ssm-examples/PSA_placement/test/vnfd3.yml new file mode 100644 index 0000000..c12e276 --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/vnfd3.yml @@ -0,0 +1,84 @@ +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "1.0" +vendor: "eu.sonata-nfv" +name: "cache-vnf2" +version: "0.1" +author: "Miguel Mesquita, AlticeLabs, mesquita@alticelabs.com" +description: "The Squid HTTP proxy VNF for the PSA pilot" + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-psa-pilot/squid-vnf/squid-3.5.12-img.qcow2" + vm_image_format: "qcow2" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 1 + size_unit: "GB" + storage: + size: 1 + size_unit: "GB" + monitoring_parameters: + - name: "vm_cpu_perc" + unit: "Percentage" + - name: "vm_mem_perc" + unit: "Percentage" + - name: "vm_net_rx_bps" + unit: "bps" + - name: "vm_net_tx_bps" + unit: "bps" + connection_points: + - id: "cpeth0" + interface: "ipv4" + type: "internal" + - id: "cpeth1" + interface: "ipv4" + type: "internal" + - id: "cpeth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "vlmgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:cpeth0" + - "cpmgmt" + - id: "vlinput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth1" + - "cpinput" + - id: "vloutput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth2" + - "cpoutput" + + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "internal" + - id: "cpoutput" + interface: "ipv4" + type: "internal" \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/vnfd4.yml b/son-ssm-examples/PSA_placement/test/vnfd4.yml new file mode 100644 index 0000000..9a40e5c --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/vnfd4.yml @@ -0,0 +1,84 @@ +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "1.0" +vendor: "eu.sonata-nfv" +name: "cache-vnf3" +version: "0.1" +author: "Miguel Mesquita, AlticeLabs, mesquita@alticelabs.com" +description: "The Squid HTTP proxy VNF for the PSA pilot" + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-psa-pilot/squid-vnf/squid-3.5.12-img.qcow2" + vm_image_format: "qcow2" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 1 + size_unit: "GB" + storage: + size: 1 + size_unit: "GB" + monitoring_parameters: + - name: "vm_cpu_perc" + unit: "Percentage" + - name: "vm_mem_perc" + unit: "Percentage" + - name: "vm_net_rx_bps" + unit: "bps" + - name: "vm_net_tx_bps" + unit: "bps" + connection_points: + - id: "cpeth0" + interface: "ipv4" + type: "internal" + - id: "cpeth1" + interface: "ipv4" + type: "internal" + - id: "cpeth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "vlmgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:cpeth0" + - "cpmgmt" + - id: "vlinput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth1" + - "cpinput" + - id: "vloutput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth2" + - "cpoutput" + + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "internal" + - id: "cpoutput" + interface: "ipv4" + type: "internal" \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/vnfd5.yml b/son-ssm-examples/PSA_placement/test/vnfd5.yml new file mode 100644 index 0000000..9792256 --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/vnfd5.yml @@ -0,0 +1,84 @@ +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "1.0" +vendor: "eu.sonata-nfv" +name: "cache-vnf4" +version: "0.1" +author: "Miguel Mesquita, AlticeLabs, mesquita@alticelabs.com" +description: "The Squid HTTP proxy VNF for the PSA pilot" + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-psa-pilot/squid-vnf/squid-3.5.12-img.qcow2" + vm_image_format: "qcow2" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 1 + size_unit: "GB" + storage: + size: 1 + size_unit: "GB" + monitoring_parameters: + - name: "vm_cpu_perc" + unit: "Percentage" + - name: "vm_mem_perc" + unit: "Percentage" + - name: "vm_net_rx_bps" + unit: "bps" + - name: "vm_net_tx_bps" + unit: "bps" + connection_points: + - id: "cpeth0" + interface: "ipv4" + type: "internal" + - id: "cpeth1" + interface: "ipv4" + type: "internal" + - id: "cpeth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "vlmgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:cpeth0" + - "cpmgmt" + - id: "vlinput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth1" + - "cpinput" + - id: "vloutput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth2" + - "cpoutput" + + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "internal" + - id: "cpoutput" + interface: "ipv4" + type: "internal" \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/vnfd6.yml b/son-ssm-examples/PSA_placement/test/vnfd6.yml new file mode 100644 index 0000000..8d73804 --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/vnfd6.yml @@ -0,0 +1,84 @@ +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "1.0" +vendor: "eu.sonata-nfv" +name: "cache-vnf5" +version: "0.1" +author: "Miguel Mesquita, AlticeLabs, mesquita@alticelabs.com" +description: "The Squid HTTP proxy VNF for the PSA pilot" + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-psa-pilot/squid-vnf/squid-3.5.12-img.qcow2" + vm_image_format: "qcow2" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 1 + size_unit: "GB" + storage: + size: 1 + size_unit: "GB" + monitoring_parameters: + - name: "vm_cpu_perc" + unit: "Percentage" + - name: "vm_mem_perc" + unit: "Percentage" + - name: "vm_net_rx_bps" + unit: "bps" + - name: "vm_net_tx_bps" + unit: "bps" + connection_points: + - id: "cpeth0" + interface: "ipv4" + type: "internal" + - id: "cpeth1" + interface: "ipv4" + type: "internal" + - id: "cpeth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "vlmgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:cpeth0" + - "cpmgmt" + - id: "vlinput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth1" + - "cpinput" + - id: "vloutput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth2" + - "cpoutput" + + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "internal" + - id: "cpoutput" + interface: "ipv4" + type: "internal" \ No newline at end of file diff --git a/son-ssm-examples/PSA_placement/test/vnfd7.yml b/son-ssm-examples/PSA_placement/test/vnfd7.yml new file mode 100644 index 0000000..14d33e1 --- /dev/null +++ b/son-ssm-examples/PSA_placement/test/vnfd7.yml @@ -0,0 +1,84 @@ +--- +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "1.0" +vendor: "eu.sonata-nfv" +name: "cache-vnf6" +version: "0.1" +author: "Miguel Mesquita, AlticeLabs, mesquita@alticelabs.com" +description: "The Squid HTTP proxy VNF for the PSA pilot" + +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-psa-pilot/squid-vnf/squid-3.5.12-img.qcow2" + vm_image_format: "qcow2" + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 1 + size_unit: "GB" + storage: + size: 1 + size_unit: "GB" + monitoring_parameters: + - name: "vm_cpu_perc" + unit: "Percentage" + - name: "vm_mem_perc" + unit: "Percentage" + - name: "vm_net_rx_bps" + unit: "bps" + - name: "vm_net_tx_bps" + unit: "bps" + connection_points: + - id: "cpeth0" + interface: "ipv4" + type: "internal" + - id: "cpeth1" + interface: "ipv4" + type: "internal" + - id: "cpeth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "vlmgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:cpeth0" + - "cpmgmt" + - id: "vlinput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth1" + - "cpinput" + - id: "vloutput" + connectivity_type: "E-Line" + connection_points_reference: + - "1:cpeth2" + - "cpoutput" + + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "cpmgmt" + interface: "ipv4" + type: "management" + - id: "cpinput" + interface: "ipv4" + type: "internal" + - id: "cpoutput" + interface: "ipv4" + type: "internal" \ No newline at end of file