
{#
Copyright 2017-present Open Networking Foundation

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.
#}


tosca_definitions_version: tosca_simple_yaml_1_0

description: Just enough Tosca to get the vSG slice running on the CORD POD, created by platform-install

imports:
   - custom_types/xos.yaml
   - custom_types/vtr.yaml
   - custom_types/addressmanager.yaml

topology_template:
  node_templates:

# site, image, fully created in deployment.yaml
    {{ site_name }}:
      type: tosca.nodes.Site

    image#vsg-1.1:
      type: tosca.nodes.Image

# management networks, fully created in management-net.yaml
    management:
      type: tosca.nodes.network.Network.XOS
      properties:
        no-create: true
        no-delete: true
        no-update: true

{% if use_management_hosts %}
    management_hosts:
      type: tosca.nodes.network.Network.XOS
      properties:
        no-create: true
        no-delete: true
        no-update: true
{% endif %}

    service#rcord:
      type: tosca.nodes.Service

# ONOS_CORD, fully created in vtn.yaml
    service#ONOS_CORD:
      type: tosca.nodes.ONOSService
      properties:
        no-delete: true
        no-create: true
        no-update: true

# ONOS_Fabric, fully created in fabric.yaml
    service#ONOS_Fabric:
      type: tosca.nodes.ONOSService
      properties:
        no-delete: true
        no-create: true
        no-update: true

# CORD Services
    service#vtr:
      type: tosca.nodes.VTRService
      properties:
        view_url: /admin/vtr/vtrservice/$id$/
        kind: vTR
        replaces: service_vtr

    service#volt:
      type: tosca.nodes.VOLTService
      requirements:
        - vsg_tenant:
            node: service#vsg
            relationship: tosca.relationships.TenantOfService
      properties:
        view_url: /admin/volt/voltservice/$id$/
        kind: vOLT
        replaces: service_volt
        public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
        private_key_fn: /opt/xos/services/volt/keys/volt_rsa
      artifacts:
        pubkey: /opt/cord_profile/key_import/volt_rsa.pub

    addresses_vsg:
      type: tosca.nodes.AddressPool
      properties:
        addresses: 10.7.1.0/24
        gateway_ip: 10.7.1.1
        gateway_mac: a4:23:05:06:01:01

    addresses_public:
      type: tosca.nodes.AddressPool
      properties:
        addresses: 10.8.1.0/24
        gateway_ip: 10.8.1.1
        gateway_mac: a4:23:05:06:01:01

    label_vsg:
      type: tosca.nodes.NodeLabel

    service#vsg:
      type: tosca.nodes.VSGService
      requirements:
        - addressing_tenant:
            node: service#addressmanager
            relationship: tosca.relationships.TenantOfService
        - vrouter_tenant:
            node: service#vrouter
            relationship: tosca.relationships.TenantOfService
      properties:
        view_url: /admin/vsg/vsgservice/$id$/
        backend_network_label: hpc_client
        public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
        private_key_fn: /opt/xos/services/vsg/keys/vsg_rsa
#       node_label: label_vsg
        replaces: service_vsg
      artifacts:
        pubkey: /opt/cord_profile/key_import/vsg_rsa.pub

    service#addressmanager:
      type: tosca.nodes.AddressManagerService
      requirements:
        - addresses_vsg:
            node: addresses_vsg
            relationship: tosca.relationships.ProvidesAddresses
        - addresses_public:
            node: addresses_public
            relationship: tosca.relationships.ProvidesAddresses

    service#vrouter:
      type: tosca.nodes.VRouterService
      properties:
        view_url: /admin/vrouter/vrouterservice/$id$/
        replaces: service_vrouter

    vRouter_ONOS_app:
      type: tosca.nodes.ONOSvRouterApp
      requirements:
        - onos_tenant:
            node: service#ONOS_Fabric
            relationship: tosca.relationships.TenantOfService
        - vrouter_service:
            node: service#vrouter
            relationship: tosca.relationships.UsedByService
      properties:
        dependencies: org.onosproject.fpm
        autogenerate: vrouter-network-cfg

    template#vsg:
      type: tosca.nodes.NetworkTemplate
      properties:
        visibility: private
        translation: none
        vtn_kind: VSG

    # Networks required by the CORD setup
    {{ site_name }}_vsg-access:
      type: tosca.nodes.network.Network
      properties:
        ip_version: 4
      requirements:
        - network_template:
            node: template#vsg
            relationship: tosca.relationships.UsesNetworkTemplate
        - owner:
            node: {{ site_name }}_vsg
            relationship: tosca.relationships.MemberOfSlice
        - connection:
            node: {{ site_name }}_vsg
            relationship: tosca.relationships.ConnectsToSlice

    # CORD Slices
    {{ site_name }}_vsg:
      description: vSG Controller Slice
      type: tosca.nodes.Slice
      properties:
        network: noauto
      requirements:
        - vsg_service:
            node: service#vsg
            relationship: tosca.relationships.MemberOfService
        - site:
            node: {{ site_name }}
            relationship: tosca.relationships.MemberOfSite
        - management:
            node: management
            relationship: tosca.relationships.ConnectsToNetwork
{% if use_management_hosts %}
        - management_hosts:
            node: management_hosts
            relationship: tosca.relationships.ConnectsToNetwork
{% endif %}
        - image:
            node: image#vsg-1.1
            relationship: tosca.relationships.DefaultImage

    in#lanside:
      type: tosca.nodes.InterfaceType
      properties:
         direction: in

    out#lanside:
      type: tosca.nodes.InterfaceType
      properties:
         direction: out

    in#wanside:
      type: tosca.nodes.InterfaceType
      properties:
         direction: in

    out#wanside:
      type: tosca.nodes.InterfaceType
      properties:
         direction: out

    volt_lanside:
      type: tosca.nodes.ServiceInterface
      requirements:
        - service:
            node: service#volt
            relationship: tosca.relationships.MemberOfService
        - interface:
            node: out#lanside
            relationship: tosca.relationships.IsType

    vsg_lanside:
      type: tosca.nodes.ServiceInterface
      requirements:
        - service:
            node: service#vsg
            relationship: tosca.relationships.MemberOfService
        - interface:
            node: in#lanside
            relationship: tosca.relationships.IsType

    vsg_wanside:
      type: tosca.nodes.ServiceInterface
      requirements:
        - service:
            node: service#vsg
            relationship: tosca.relationships.MemberOfService
        - interface:
            node: out#wanside
            relationship: tosca.relationships.IsType

    addressmanager_wanside:
      type: tosca.nodes.ServiceInterface
      requirements:
        - service:
            node: service#addressmanager
            relationship: tosca.relationships.MemberOfService
        - interface:
            node: in#wanside
            relationship: tosca.relationships.IsType