tosca_definitions_version: tosca_simple_yaml_1_0
metadata:
  template_name: vCPE_vgw
  template_version: "1.0"
  template_author: onap
  VNFD_SCHEMA_VERSION: "2.5.1+1"
  descriptor_id: b1bb0ce7-2222-4fa7-95ed-4840d70a1177
description: vCPE_vgw

imports:
  - onap_dm.yaml

topology_template:
  #substitution_mappings:
  #  node_type: onap.vcpe_vgw
  #  requirements:
  #    virtual_link: [ Cp_vgw_public, virtual_link ] # expose as external CP
  #    virtual_link: [ Cp_vgw_onap_private, virtual_link ] # expose as external CP

  inputs:
    vcpe_image_name:
      type: string
      description: image name for vcpe in openstack glance
      default: ubuntu_16.04
    public_net_id:
      type: string
      description: public network id used during onap installation
      default: external
    onap_private_net_id:
      type: string
      description: onap OAM network id
      default: oam_onap
    onap_private_net_cidr:
      type: string
      description: oanp OAM network cidr
      default: 10.0.0.0/16
    mux_gw_private_net_id:
      type: string
      description: Private network that connects vGMUX to vGWs
      default: zdfw1muxgw01_private
    mux_gw_private_net_cidr:
      type: string
      description: he CIDR of the vGMUX private network
      default: 10.5.0.0/24
    cpe_public_net_id:
      type: string
      description: cpe public net name
      default: zdfw1cpe01_public
    cpe_public_net_cidr:
      type: string
      description: cpe public net cidr
      default: 10.2.0.0/24
    vgw_private_ip_0:
      type: string
      description: Private IP address that is assigned to the vGW to communicate with vGMUX
      default: 10.5.0.21
    vgw_private_ip_1:
      type: string
      description: Private IP address that is assigned to the vGW to communicate with ONAP components
      default: 10.0.101.30
    vgw_private_ip_2:
      type: string
      description: Private IP address that is assigned to the vGW to communicate with vCPE public network
      default: 10.2.0.3
    vgw_name_0:
      type: string
      description: Name of the vGW
      default: zdcpe1cpe01gw01
    dcae_collector_ip:
      type: string
      description: dcae collector ip
      default: 10.0.4.102
    dcae_collector_port:
      type: string
      description: dcae collector port
      default: "8080"
    pub_key:
      type: string
      description: ssh public key
      default: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGx6SKrAuCz1V8KGevZueksLdWoPWJP6z3r29Z7TmPVEOjM+7PIPeSs2BVRx3rnHZBAlasMrZ+fJBS25ts9vfC+ItezQah/hr9vrkmwxCR54Lb84poW+sToPeF6i5eZY7W+jWJfLaFSFx9d2vp4zes/fOlT3NvYCXbn/3QdryQoGl7VFI8oemZypVcikZXElJeeKgAVdSwnrzuqtO/tmbXcAeSbYvVjki8ywYcsWMVMYWUWhh+1BAB6kXnTsIWqzrq0Pfvy+81WDwtiqsqmd93HY8hE0scBrXFBZzQS/AYfIFBlEuFNdLczchntjbZ0n7dmDXk8zHtCZYNk7kwb8k/
    nexus_artifact_repo:
      type: string
      description: Root URL for the Nexus repository for Maven artifacts
      default: https://nexus.onap.org
    demo_artifacts_version:
      type: string
      description: artifacts version used in demo vnfs
      default: 1.2.0
    install_script_version:
      type: string
      description: install script version number
      default: 1.2.0-SNAPSHOT
    cloud_env:
      type: string
      description: cloud environment(openstack or rackspace)
      default: openstack
    mux_ip_addr:
      type: string
      description: IP address of vGMUX
      default: 10.5.0.20
    vg_vgmux_tunnel_vni:
      type: string
      description: vni value of vG-vGMUX vxlan tunnel
      default: "100"
    vnf_id:
      type: string
      description: The VNF ID is provided by ONAP
      default: vCPE_Infrastructure_GW_demo_app
    vf_module_id:
      type: string
      description: The vCPE Module ID is provided by ONAP
      default: vCPE_Customer_GW

  node_templates:
    LLU_VNF:
      type: tosca.nodes.nfv.VNF
      properties:
        descriptor_id: b1bb0ce7-2222-4fa7-95ed-4840d70a1177
        provider: onap
        product_name: vcpe_vgw
        software_version: '1.0'
        descriptor_version: '1.0'
        flavour_id: simple
        flavour_description: simple
        vnfm_info: ['gvnfm']

    #onap public net
#    VL_public:
#      type: tosca.nodes.nfv.VnfVirtualLink
#      properties:
#        connectivity_type:
#          layer_protocols: [ipv4]
#        vl_profile:
#          max_bitrate_requirements:
#            root: 10000000
#            leaf: 10000000
#          min_bitrate_requirements:
#            root: 10000000
#            leaf: 10000000
#          virtual_link_protocol_data:
#            - associated_layer_protocol: ipv4
#              l3_protocol_data:
#                ip_version: ipv4
#                name: { get_input: public_net_id }
#
#    #onap oam net
#    VL_onap_private:
#      type: tosca.nodes.nfv.VnfVirtualLink
#      properties:
#        connectivity_type:
#          layer_protocols: [ipv4]
#        vl_profile:
#          max_bitrate_requirements:
#            root: 10000000
#            leaf: 10000000
#          min_bitrate_requirements:
#            root: 10000000
#            leaf: 10000000
#          virtual_link_protocol_data:
#            - associated_layer_protocol: ipv4
#              l3_protocol_data:
#                ip_version: ipv4
#                name: { get_input: onap_private_net_id }
#                cidr: { get_input: onap_private_net_cidr }

    #Private network that connects vGMUX to vGWs
    VL_mux_gw_private_net:
      type: tosca.nodes.nfv.VnfVirtualLink
      properties:
        connectivity_type:
          layer_protocols: [ipv4]
        vl_profile:
          max_bitrate_requirements:
            root: 10000000
            leaf: 10000000
          min_bitrate_requirements:
            root: 10000000
            leaf: 10000000
          virtual_link_protocol_data:
            - associated_layer_protocol: ipv4
              l3_protocol_data:
                name: { get_input: mux_gw_private_net_id }
                ip_version: ipv4
                cidr: { get_input: mux_gw_private_net_cidr }
                dhcp_enabled: false

    #cpe public network
    VL_cpe_public:
      type: tosca.nodes.nfv.VnfVirtualLink
      properties:
        connectivity_type:
          layer_protocols: [ipv4]
        vl_profile:
          max_bitrate_requirements:
            root: 10000000
            leaf: 10000000
          min_bitrate_requirements:
            root: 10000000
            leaf: 10000000
          virtual_link_protocol_data:
            - associated_layer_protocol: ipv4
              l3_protocol_data:
                name: { get_input: cpe_public_net_id }
                ip_version: ipv4
                cidr: { get_input: cpe_public_net_cidr }
                dhcp_enabled: false

    # vgw related
    Cp_vgw_public:
      type: tosca.nodes.nfv.VduCp
      properties:
        layer_protocols: [ipv4]
        trunk_mode: false
        protocol:
          - associated_layer_protocol: ipv4
            address_data:
              - address_type: ip_address
                l3_address_data:
                  ip_address_assignment: false
                  floating_ip_activated: false
      requirements:
        - virtual_binding: VDU_vgw_0
        #- virtual_link: VL_public

    Cp_vgw_onap_private:
      type: tosca.nodes.nfv.VduCp
      properties:
        layer_protocols: [ipv4]
        trunk_mode: false
        protocol:
          - associated_layer_protocol: ipv4
            address_data:
              - address_type: ip_address
                l3_address_data:
                  ip_address_assignment: false
                  floating_ip_activated: false
                  fixed_ip_address:
                    - { get_input: vgw_private_ip_1 }
      requirements:
        - virtual_binding: VDU_vgw_0
        #- virtual_link: VL_onap_private

    Cp_vgw_mux_gw_private_net:
      type: tosca.nodes.nfv.VduCp
      properties:
        layer_protocols: [ipv4]
        trunk_mode: false
        protocol:
          - associated_layer_protocol: ipv4
            address_data:
              - address_type: ip_address
                l3_address_data:
                  ip_address_assignment: false
                  floating_ip_activated: false
                  fixed_ip_address:
                    - { get_input: vgw_private_ip_0 }
        virtual_network_interface_requirements:
          - name: dpdk support
            support_mandatory: true
            network_interface_requirements:
              dataProcessingAccelerationLibrary: '{"schemaVersion": "0", "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", "configurationValue": "DPDK"}'
      requirements:
        - virtual_binding: VDU_vgw_0
        - virtual_link: VL_mux_gw_private_net

    Cp_vgw_cpe_public:
      type: tosca.nodes.nfv.VduCp
      properties:
        layer_protocols: [ipv4]
        trunk_mode: false
        protocol:
          - associated_layer_protocol: ipv4
            address_data:
              - address_type: ip_address
                l3_address_data:
                  ip_address_assignment: false
                  floating_ip_activated: false
                  fixed_ip_address:
                    - { get_input: vgw_private_ip_2 }
      requirements:
        - virtual_binding: VDU_vgw_0
        - virtual_link: VL_cpe_public

    VDU_vgw_0:
      type: tosca.nodes.nfv.Vdu.Compute
      properties:
        name: { get_input: vgw_name_0 }
        description: vgw
        vdu_profile:
          min_number_of_instances: 1
          max_number_of_instances: 1
          watchdog: none
        inject_files: # TODO SDC BUG
          source_path: ../Artifacts/Deployment/OTHER/authorized_keys #SSH authorized_keys
          dest_path: /home/ubuntu/.ssh/authorized_keys
        meta_data:
          vnf_id: { get_input: vnf_id }
          vf_module_id: { get_input: vf_module_id }
          mux_gw_private_net_ipaddr: { get_input: vgw_private_ip_0 }
          oam_ipaddr: { get_input: vgw_private_ip_1 }
          oam_cidr: { get_input: onap_private_net_cidr }
          cpe_public_net_cidr: { get_input: cpe_public_net_cidr }
          mux_gw_private_net_cidr: { get_input: mux_gw_private_net_cidr }
          mux_ip_addr: { get_input: mux_ip_addr }
          vg_vgmux_tunnel_vni: { get_input: vg_vgmux_tunnel_vni }
          install_script_version: { get_input: install_script_version }
          cloud_env: { get_input: cloud_env }
          nexus_artifact_repo: { get_input: nexus_artifact_repo }
        boot_data: |
          #!/bin/bash
          METADATA=`curl -s http://169.254.169.254/openstack/2012-08-10/meta_data.json`
          apt-get -y install jq

          get_metadata () {
            echo $METADATA | jq -r ".meta.$1"
          }

          # Create configuration files
          mkdir /opt/config
          echo "$(get_metadata oam_ipaddr)" > /opt/config/oam_ipaddr.txt
          echo "$(get_metadata oam_cidr)" > /opt/config/oam_cidr.txt
          echo "$(get_metadata cpe_public_net_cidr)" > /opt/config/cpe_public_net_cidr.txt
          echo "$(get_metadata mux_gw_private_net_ipaddr)" > /opt/config/mux_gw_private_net_ipaddr.txt
          echo "$(get_metadata mux_gw_private_net_cidr)" > /opt/config/mux_gw_private_net_cidr.txt
          echo "$(get_metadata install_script_version)" > /opt/config/install_script_version.txt
          echo "$(get_metadata cloud_env)" > /opt/config/cloud_env.txt
          echo "$(get_metadata mux_ip_addr)" > /opt/config/mux_ip_addr.txt
          echo "$(get_metadata vg_vgmux_tunnel_vni)" > /opt/config/vg_vgmux_tunnel_vni.txt
          echo "$(get_metadata nexus_artifact_repo)" > /opt/config/nexus_artifact_repo.txt

          # Download and run install script
          apt-get -y install unzip
          INSTALL_SCRIPT_VERSION=$(get_metadata install_script_version)
          NEXUS_ARTIFACT_REPO=$(get_metadata nexus_artifact_repo)
          if [[ "${INSTALL_SCRIPT_VERSION}" =~ "SNAPSHOT" ]]; then REPO=snapshots; else REPO=releases; fi
          curl -k -L "${NEXUS_ARTIFACT_REPO}/service/local/artifact/maven/redirect?r=${REPO}&g=org.onap.demo.vnf.vcpe&a=vcpe-scripts&e=zip&v=${INSTALL_SCRIPT_VERSION}" -o /opt/vcpe-scripts-${INSTALL_SCRIPT_VERSION}.zip
          unzip -j /opt/vcpe-scripts-${INSTALL_SCRIPT_VERSION}.zip -d /opt v_gw_install.sh
          cd /opt
          chmod +x v_gw_install.sh
          ./v_gw_install.sh
      capabilities:
        virtual_compute:
          properties:
            virtual_memory:
              virtual_mem_size: 4096 MB
              vdu_mem_requirements:
                memoryPageSize: '{"schemaVersion": "0", "schemaSelector": "", "hardwarePlatform": "generic", "mandatory": "true", "configurationValue": "2 MB"}'
                numberOfPages: '{"schemaVersion": "0","schemaSelector": "","hardwarePlatform": "generic","mandatory": "true", "configurationValue": "1024"}'
            virtual_cpu:
              num_virtual_cpu: 2
              cpu_architecture: generic
            virtual_local_storage:
              - size_of_storage: 40 GB
      artifacts:
        sw_image: #TODO need to put glance image name here
          #file: { get_input: vcpe_image_name }
          file: ../Artifacts/Deployment/OTHER/image
          type: tosca.artifacts.nfv.SwImage
