## Instructions for running this demo

Demo description: this demo shows how an Hybrid NS can be launched and operated from OSM, as well as some other features like monitoring and auto-scaling.
The elements are:
- A client VM and a VyOS router (pre-existing before the NS is launched)
- An Hybrid Network Service containing:
	- A PNF which will represent the existing VyOS router (PDU)
	- A VNF which implements an HAPRoxy load balanced and an Apache Web Server

Once the Network Service is launched, end customers (client VM, for example) should be able to visit the web server at the external IP of the VyOS router.
A 'day-1' proxy charm is used to create a DNAT rule in the VyOS router, so that it redirects all HTTP traffic to the HAProxy LB.

### Preparation

1. Take a look at the following diagram to familiarize with the demo:
https://osm-download.etsi.org/ftp/osm-5.0-five/6th-hackfest/other/zta2019-demo/zta2019_demo_diagram.png

2. Make sure you've got the following images uploaded to your OpenStack VIM:
https://osm-download.etsi.org/ftp/osm-4.0-four/4th-hackfest/images/apache_ubuntu.qcow2
https://osm-download.etsi.org/ftp/osm-4.0-four/4th-hackfest/images/haproxy_ubuntu.qcow2
https://osm-download.etsi.org/ftp/osm-4.0-four/4th-hackfest/images/client_ubuntu.qcow2
https://osm-download.etsi.org/ftp/osm-5.0-five/6th-hackfest/images/vyos-1.1.7-cloudinit.qcow2.tgz

3. Pre-create the following elements:

a) External network: it should be available already in your VIM, in the example we use 172.21.7.x, which corresponds to a specific VIM in ETSI Hive.
Make sure this network is reachable from your OSM system, as it will be used to manage the PNF.

b) Internal network: this will be the interface between the VyOS Router (PDU) and the HAProxy Load Balancer.  To simplify things, you can use the name 'vnf-network' and prefix '10.0.0.0/24'

c) Client VM: use the client-ubuntu.qcow2 image to instantiate it in the external network, along with your SSH key.

d) VyOS Router: this will be our PDU.  It needs to be pre-configured with some basic networking commands.  First you need to prepare:

** A flavor for the router with at least 2G RAM, 2GB disk and 2 vCPUs.
** Create the ports for VyOS, with two fixed IP addresses (external and internal):
openstack port create --fixed-ip ip-address=[external-IP] --enable --disable-port-security --network [external-network-name] VyOS-eth0
openstack port create --fixed-ip ip-address=[internal-IP] --enable --disable-port-security --network [internal-network-name] VyOS-eth1
** Prepare the userdata to pre-configure the VyOS router. For this, download and populate (with the right IP addresses) the userdata file from the following location:
https://osm-download.etsi.org/ftp/osm-5.0-five/6th-hackfest/other/zta2019-demo/vyos-userdata

Finally, create the VyOS router, which will be used as our PDU:
openstack server create --key-name [your-optional-ssh-key] --flavor [flavor] --image vyos-1.1.7-cloudinit.qcow2 --nic port-id=VyOS-eth0 --nic port-id=VyOS-eth1 --config-drive True --user-data [userdata file location] [vyos hostname]

### Demo execution

1. Create the PDU so that the system is aware of it.

a) Download the PDU template from here and make sure you update the VyOS IP addresses accordingly:
https://osm-download.etsi.org/ftp/osm-5.0-five/6th-hackfest/other/zta2019-demo/PDU_router.yaml

b) Create the PDU in OSM:
osm pdu-create --descriptor_file PDU_router.yaml
 
2. Onboard the VNF and NS descriptors from the following location:
https://osm-download.etsi.org/ftp/osm-5.0-five/6th-hackfest/other/zta2019-demo/descriptors
You will find the following descriptors:
a) VNF descriptor (webserver_vimmetric_autoscale_vnfd.tar.gz) : contains HAProxy and Apache Web Server VDUs, with monitoring parameters and an auto-scaling descriptor.
b) PNF descriptor (vyos_pnf_charmed.tar.gz): contains the PNF, requesting a PDU with type 'gateway' and containing a proxy-charm that will auto-configure a NAT rule for this particular Network Service through an Ansible Playbook.
c) Hybrid NS descriptor (hybrid_lbwebvnf_gwpnf_nsd.tar.gz) : contains both VNF and PNF.

3. Launch the Hybrid Network Service and make sure you pass an static IP address which corresponds to your internal network, so that the HAProxy is configured accordingly, as well as the NAT rule configured at the PDU by the Ansible playbook contained in the proxy charm (in the example, 10.0.0.100)

osm ns-create --ns_name [name-of-your-ns] --nsd_name hybrid_lbwebvnf_gwpnf_ns --vim_account [name-of-your-VIM] --config "{vld: [{name: public_vld,vnfd-connection-point-ref: [{ vnfd-connection-point-ref: haproxy_public, member-vnf-index-ref: '1', ip-address: '10.0.0.100'}]}], additionalParamsForVnf: [{member-vnf-index: '2', additionalParams:{dest-ip: '10.0.0.100'}}]}"

4. Soon after the NS has been launched, the proxy charm should have configured the VyOS router with a destination NAT rule. You can check it by accessing the VyOS router using SSH and port 2222 (osm/osm2019)

4. Visit the external IP address of your VyOS router and you will see the Apache Web server sample page.  You should also start seeing CPU and Memory metrics for the Apache Web Server in OSM's Prometheus/Grafana.

5. Access the client VM (osm/osm2018) and run the following command in order to stress the web server's CPU.  According to the original descriptor, 35%+ CPU will trigger a scale out.

ab -n 5000000 -c 2 http://[externa-VyOS-IP]/test.php
