diff --git a/son-sm-template/sonsmbase/smbase.py b/son-sm-template/sonsmbase/smbase.py index 367b04c..bf2242b 100644 --- a/son-sm-template/sonsmbase/smbase.py +++ b/son-sm-template/sonsmbase/smbase.py @@ -77,6 +77,7 @@ def __init__(self, self.update_version = update_version self.uuid = None self.sfuuid = None + self.private_key = None LOG.info("Starting {0} ...".format(self.specific_manager_id)) @@ -117,8 +118,11 @@ def registration(self): if 'sf_uuid' in os.environ: self.sfuuid = os.environ['sf_uuid'] - else: - self.sfuuid = '' + + + if 'PRIVATE_KEY' in os.environ: + self.private_key = os.environ['PRIVATE_KEY'] + message = {'specific_manager_type': self.specific_manager_type, 'service_name': self.service_name, diff --git a/son-ssm-examples/vCDN_placement/Dockerfile b/son-ssm-examples/vCDN_placement/Dockerfile new file mode 100644 index 0000000..a0c12c5 --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_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/vCDN_placement/MANIFEST.in b/son-ssm-examples/vCDN_placement/MANIFEST.in new file mode 100644 index 0000000..892a4d9 --- /dev/null +++ b/son-ssm-examples/vCDN_placement/MANIFEST.in @@ -0,0 +1,2 @@ +# Include the license file +include ../../LICENSE diff --git a/son-ssm-examples/vCDN_placement/README.md b/son-ssm-examples/vCDN_placement/README.md new file mode 100644 index 0000000..9c5f0ac --- /dev/null +++ b/son-ssm-examples/vCDN_placement/README.md @@ -0,0 +1,59 @@ +# vCDN Pilot Placement SSM +Placement SSM to be used for vCDN pilot. + +## Requires +* Docker +* Python3.4 +* RabbitMQ + +## Implementation +* Implemented in Python 3.4 +* Dependencies: amqp-storm +* The main implementation can be found in: `son-ssm-examples/vCDN_placement/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 sonssmvcdnplacement1 -f son-ssm-examples/vCDN_placement/Dockerfile .` + * `docker run --name sonssmvcdnplacement1 --net=sonata --network-alias=sonssmvcdnplacement1 sonssmvcdnplacement1` + +* 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/vCDN_placement/`) + * `python3.4 setup.py develop` + * (In `son-sm/`) + * `python3.4 son-ssm-examples/vCDN_placement/placement/placement.py` + +## How to test it +* Do the following; each in a separate terminal. + 1. Run the fake_SMR + 2. Run the placement container + 3. In son-sm/son-ssm-examples/vCDN_placement/placement/test run python3.4 placementtrigger.py + +* The expected results are as follows: + + * In the placementtrigger terminal: + + ``` + {'status': 'COMPLETED', 'mapping': {'vnfd2': {'vim': '1234'}, 'vnfd1': {'vim': '1234'}}, 'error': None} + ``` + + * In placement terminal: + + ``` + INFO:son-sm-base:Starting sonssmvcdnplacement1 ... + INFO:son-sm-base:Sending registration request... + INFO:son-sm-base:sonssmvcdnplacement1 registered with uuid:23345 + DEBUG:vCDN-ssm-placement:Received registration ok event. + INFO:vCDN-ssm-placement:Subscribed to placement.ssm.1234 + INFO:vCDN-ssm-placement:Placement started + INFO:vCDN-ssm-placement:Mapping algorithm started. + INFO:vCDN-ssm-placement:Mapping succeeded: {'vnfd1': {'vim': '1234'}, 'vnfd2': {'vim': '1234'}} + INFO:vCDN-ssm-placement:The mapping calculation has succeeded. + ``` diff --git a/son-ssm-examples/vCDN_placement/placement/__init__.py b/son-ssm-examples/vCDN_placement/placement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/son-ssm-examples/vCDN_placement/placement/__main__.py b/son-ssm-examples/vCDN_placement/placement/__main__.py new file mode 100644 index 0000000..6813c9a --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_placement/placement/placement.py b/son-ssm-examples/vCDN_placement/placement/placement.py new file mode 100644 index 0000000..289b199 --- /dev/null +++ b/son-ssm-examples/vCDN_placement/placement/placement.py @@ -0,0 +1,237 @@ +""" +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("vCDN-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 = 'vcdn' + 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. + # if self.sfuuid == None: + #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'] + + # Find the sum of demands of vCC and vTC + vtc_vcc_total_core = 0 + vtc_vcc_total_memory = 0 + for vnfd in functions: + if vnfd['intance_uuid'] == 'vtc-vnf' or vnfd['intance_uuid'] == 'vcc-vnf': + vtc_vcc_total_core += vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu']['vcpus'] + vtc_vcc_total_memory += vnfd['virtual_deployment_units'][0]['resource_requirements']['memory']['size'] + + # Find the sum of demands of vCC and vTC + + vtu_total_core = 0 + vtu_total_memory = 0 + for vnfd in functions: + if vnfd['intance_uuid'] == 'vtu-vnf': + vtu_total_core = vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu']['vcpus'] + vtu_total_memory = vnfd['virtual_deployment_units'][0]['resource_requirements']['memory']['size'] + + if ingress == "" and egress == "": + + for vnfd in functions: + if vnfd['name'] == 'vtc-vnf' or vnfd['name'] == 'vcc-vnf': + for vim in topology: + cpu_req = vtc_vcc_total_core <= (vim['core_total'] - vim['core_used']) + mem_req = vtc_vcc_total_memory <= (vim['memory_total'] - vim['memory_used']) + if cpu_req and mem_req: + LOG.debug('VNF ' + vnfd['intance_uuid'] + ' mapped on VIM ' + vim['vim_uuid']) + mapping[vnfd['intance_uuid']] = {} + mapping[vnfd['intance_uuid']]['vim'] = vim['vim_uuid'] + vim['core_used'] = vim['core_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu'][ + 'vcpus'] + vim['memory_used'] = vim['memory_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements'][ + 'memory'][ + 'size'] + break + + if vnfd['name'] == 'vtu-vnf': + for vim in topology: + cpu_req = vtu_total_core <= (vim['core_total'] - vim['core_used']) + mem_req = vtu_total_memory <= (vim['memory_total'] - vim['memory_used']) + + if cpu_req and mem_req: + LOG.debug('VNF ' + vnfd['intance_uuid'] + ' mapped on VIM ' + vim['vim_uuid']) + mapping[vnfd['intance_uuid']] = {} + mapping[vnfd['intance_uuid']]['vim'] = vim['vim_uuid'] + vim['core_used'] = vim['core_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu'][ + 'vcpus'] + vim['memory_used'] = vim['memory_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements'][ + 'memory'][ + 'size'] + break + else: + # Place vTC and vCC on the Egress PoP close to users and + # place vTU on Ingress PoP close to the server + for vnfd in functions: + if vnfd['name'] == 'vtc-vnf' or vnfd['name'] == 'vcc-vnf': + for vim in topology: + if vim['vim_city'] == egress: + cpu_req = vtc_vcc_total_core <= (vim['core_total'] - vim['core_used']) + mem_req = vtc_vcc_total_memory <= (vim['memory_total'] - vim['memory_used']) + if cpu_req and mem_req: + LOG.debug('VNF ' + vnfd['intance_uuid'] + ' mapped on VIM ' + vim['vim_uuid']) + mapping[vnfd['intance_uuid']] = {} + mapping[vnfd['intance_uuid']]['vim'] = vim['vim_uuid'] + vim['core_used'] = vim['core_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu'][ + 'vcpus'] + vim['memory_used'] = vim['memory_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements']['memory'][ + 'size'] + break + + if vnfd['name'] == 'vtu-vnf': + for vim in topology: + if vim['vim_city'] == ingress: + cpu_req = vtu_total_core <= (vim['core_total'] - vim['core_used']) + mem_req = vtu_total_memory <= (vim['memory_total'] - vim['memory_used']) + + if cpu_req and mem_req: + LOG.debug('VNF ' + vnfd['intance_uuid'] + ' mapped on VIM ' + vim['vim_uuid']) + mapping[vnfd['intance_uuid']] = {} + mapping[vnfd['intance_uuid']]['vim'] = vim['vim_uuid'] + vim['core_used'] = vim['core_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements']['cpu'][ + 'vcpus'] + vim['memory_used'] = vim['memory_used'] + \ + vnfd['virtual_deployment_units'][0]['resource_requirements']['memory'][ + 'size'] + 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/vCDN_placement/setup.py b/son-ssm-examples/vCDN_placement/setup.py new file mode 100644 index 0000000..5379955 --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_placement/test/fake_smr_place.py b/son-ssm-examples/vCDN_placement/test/fake_smr_place.py new file mode 100644 index 0000000..8fc8805 --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_placement/test/nsd.yml b/son-ssm-examples/vCDN_placement/test/nsd.yml new file mode 100644 index 0000000..3e4bc85 --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_placement/test/placementtrigger.py b/son-ssm-examples/vCDN_placement/test/placementtrigger.py new file mode 100644 index 0000000..010514f --- /dev/null +++ b/son-ssm-examples/vCDN_placement/test/placementtrigger.py @@ -0,0 +1,100 @@ +""" +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('vCC-vnfd.yml', 'r')) + vnfd2 = yaml.load(open('vtc-nfd.yml', 'r')) + vnfd3 = yaml.load(open('vtu-nfd.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":''}],'egress':[{"location":'Aveiro',"nap":''}]} + + vnfds = [vnfd1,vnfd2,vnfd3] + + 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/vCDN_placement/test/vCC-vnfd.yml b/son-ssm-examples/vCDN_placement/test/vCC-vnfd.yml new file mode 100644 index 0000000..10cac7e --- /dev/null +++ b/son-ssm-examples/vCDN_placement/test/vCC-vnfd.yml @@ -0,0 +1,81 @@ +## +## vCC VNF descriptor. +## +descriptor_version: "vnfd-schema-02" +vendor: "eu.sonata-nfv" +name: "vcc-vnf" +version: "0.1" +author: "Stavros Kolometsos @ Demokritos" +description: "VNF implementing a vCacheContent" +intance_uuid: "937213ae-890b-413c-a11e-45c62c4eee3h" +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-vcdn-pilot/vcc-vnf/sonata-vcc" + vm_image_format: "qcow2" + vm_image_md5: '712e3e02705df6fe6e5fe4d960a283ce' + resource_requirements: + cpu: + vcpus: 1 + memory: + size: 2 + size_unit: "GB" + storage: + size: 20 + 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: "eth0" + interface: "ipv4" + type: "management" + - id: "input" + interface: "ipv4" + type: "internal" + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "mgmt" + interface: "ipv4" + type: "management" + - id: "input" + interface: "ipv4" + type: "external" +## + +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "mgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "1:eth0" + - "mgmt" + - id: "input" + connectivity_type: "E-Line" + connection_points_reference: + - "1:eth1" + - "input" + +monitoring_rules: + - name: "mon:rule:vm_cpu_usage_85_perc" + description: "Trigger events if CPU load is above 85 percent." + duration: 10 + duration_unit: "s" + condition: "1:vm_cpu_perc > 85" + notification: + - name: "notification01" + type: "rabbitmq_message" diff --git a/son-ssm-examples/vCDN_placement/test/vnfd4.yml b/son-ssm-examples/vCDN_placement/test/vnfd4.yml new file mode 100644 index 0000000..9a40e5c --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_placement/test/vnfd5.yml b/son-ssm-examples/vCDN_placement/test/vnfd5.yml new file mode 100644 index 0000000..9792256 --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_placement/test/vnfd6.yml b/son-ssm-examples/vCDN_placement/test/vnfd6.yml new file mode 100644 index 0000000..8d73804 --- /dev/null +++ b/son-ssm-examples/vCDN_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/vCDN_placement/test/vnfd7.yml b/son-ssm-examples/vCDN_placement/test/vnfd7.yml new file mode 100644 index 0000000..14d33e1 --- /dev/null +++ b/son-ssm-examples/vCDN_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 diff --git a/son-ssm-examples/vCDN_placement/test/vtc-nfd.yml b/son-ssm-examples/vCDN_placement/test/vtc-nfd.yml new file mode 100644 index 0000000..6713912 --- /dev/null +++ b/son-ssm-examples/vCDN_placement/test/vtc-nfd.yml @@ -0,0 +1,129 @@ +## +## vTC VNF descriptor. +## +descriptor_version: "vnfd-schema-02" +vendor: "eu.sonata-nfv" +name: "vtc-vnf" +version: "0.1" +author: "George Xilouris, Stavros Kolometsos :@ NCSRD" +description: "VNF implementing a vTC for traffic inspection and classification" +intance_uuid: "937213ae-890b-413c-a11e-45c62c4eee3f" +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "vdu01" + vm_image: "http://files.sonata-nfv.eu/son-vcdn-pilot/vtc-vnf/sonata-vtc.qcow2" + vm_image_format: "qcow2" + vm_image_md5: 'afbf1f25d17f9dcb848a5a72af579c38' + resource_requirements: + cpu: + vcpus: 2 + memory: + size: 4 + size_unit: "GB" + storage: + size: 30 + 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" + - name: "mbits_packets_all" + unit: "bps" + - name: "mbits_packets_apple" + unit: "pps" + - name: "mbits_packets_bittorrent" + unit: "pps" + - name: "mbits_packets_dns" + unit: "pps" + - name: "mbits_packets_dropbox" + unit: "pps" + - name: "mbits_packets_google" + unit: "pps" + - name: "mbits_packets_http" + unit: "pps" + - name: "mbits_packets_icloud" + unit: "pps" + - name: "mbits_packets_skype" + unit: "pps" + - name: "mbits_packets_twitter" + unit: "pps" + - name: "mbits_packets_viber" + unit: "pps" + - name: "mbits_packets_youtube" + unit: "pps" + + + connection_points: + - id: "eth0" + interface: "ipv4" + type: "management" + - id: "input" + interface: "ipv4" + type: "internal" + - id: "output" + interface: "ipv4" + type: "internal" + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "mgmt" + interface: "ipv4" + type: "management" + - id: "input" + interface: "ipv4" + type: "external" + - id: "output" + interface: "ipv4" + type: "external" + + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "mgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "vdu01:eth0" + - "mgmt" + - id: "input" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:input" + - "input" + - id: "output" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:output" + - "output" + + + +monitoring_rules: + - name: "mon:rule:mbits_packets_all" + description: "Trigger events if network load is greater than 1500." + duration: 10 + duration_unit: "s" + condition: "vdu01:mbits_packets_all > 1500" + notification: + - name: "notification01" + type: "rabbitmq_message" + - name: "mon:rule:mbits_packets_http" + description: "Trigger events if HTTP load is more than 10000." + duration: 10 + duration_unit: "s" + condition: "vdu01:mbits_packets_http > 10000" + notification: + - name: "notification02" + type: "rabbitmq_message" diff --git a/son-ssm-examples/vCDN_placement/test/vtu-nfd.yml b/son-ssm-examples/vCDN_placement/test/vtu-nfd.yml new file mode 100644 index 0000000..2b404e5 --- /dev/null +++ b/son-ssm-examples/vCDN_placement/test/vtu-nfd.yml @@ -0,0 +1,93 @@ +## +## Some general information regarding this +## VNF descriptor. +## +descriptor_version: "vnfd-schema-01" +vendor: "eu.sonata-nfv" +name: "vtu-vnf" +version: "0.1" +author: "Javier Fernandez Hidalgo, Einar Meyerson :@ i2CAT" +description: "VNF implementing a vTU (virtual Transcoding Unit)" +intance_uuid: "937213ae-890b-413c-a11e-45c62c4eee3g" +## +## The virtual deployment unit. +## +virtual_deployment_units: + - id: "1" + vm_image: "http://files.sonata-nfv.eu/son-vcdn-pilot/vtu-vnf/sonata-vtu" + vm_image_format: "qcow2" + vm_image_md5: 'bd9beeb8d43c43bf83479277738a8882' + resource_requirements: + cpu: + vcpus: 4 + memory: + size: 8 + size_unit: "GB" + storage: + size: 15 + 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: "vdu01:eth0" + interface: "ipv4" + type: "internal" + - id: "vdu01:eth1" + interface: "ipv4" + type: "internal" + - id: "vdu01:eth2" + interface: "ipv4" + type: "internal" + +## +## The virtual links that interconnect +## the different connections points. +## +virtual_links: + - id: "mgmt" + connectivity_type: "E-LAN" + connection_points_reference: + - "vdu01:eth0" + - "mgmt" + - id: "input" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:eth1" + - "vnf:input" + - id: "output" + connectivity_type: "E-Line" + connection_points_reference: + - "vdu01:eth2" + - "vnf:output" + +## +## The VNF connection points to the +## outside world. +## +connection_points: + - id: "vnf:mgmt" + interface: "ipv4" + type: "management" + - id: "vnf:input" + interface: "ipv4" + type: "external" + - id: "vnf:output" + interface: "ipv4" + type: "external" + +monitoring_rules: + - name: "mon:rule:vm_cpu_usage_85_perc" + description: "Trigger events if CPU load is above 85 percent." + duration: 10 + duration_unit: "s" + condition: "vdu01:vm_cpu_perc > 85" + notification: + - name: "notification01" + type: "rabbitmq_message"