
/*
 * 
 *   Copyright 2017 RIFT.IO Inc
 *
 *   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.
 *
 *
 */

module project-nsd
{
  namespace "urn:etsi:osm:yang:project-nsd";
  prefix "project-nsd";

  import mano-types {
    prefix "manotypes";
  }

  import project-vnfd {
    prefix "project-vnfd";
  }

  import nsd-base {
    prefix "nsd-base";
  }

  import osm-project {
    prefix "osm-project";
  }


  revision 2017-02-28 {
    description
      "Initial revision. This YANG file defines
       the Network Service Descriptor (NSD)
       under projects";
    reference
      "Derived from earlier versions of base YANG files";
  }


  grouping nsd-constituent-vnfd {
    list constituent-vnfd {
      description
          "List of VNFDs that are part of this
          network service.";

      key "member-vnf-index";

      leaf member-vnf-index {
        description
          "Identifier/index for the VNFD. This separate id
           is required to ensure that multiple VNFs can be
           part of single NS";
        type string;
      }

      leaf vnfd-id-ref {
        description
          "Identifier for the VNFD.";
        type leafref {
          path "/osm-project:project[osm-project:name = current()/../../../../osm-project:name]" +
            "/project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
        }
      }

      leaf start-by-default {
        description
          "VNFD is started as part of the NS instantiation";
        type boolean;
        default true;
      }
    }
  }

  grouping nsr-nsd-constituent-vnfd {
    list constituent-vnfd {
      description
          "List of VNFDs that are part of this
          network service.";

      key "member-vnf-index";

      leaf member-vnf-index {
        description
          "Identifier/index for the VNFD. This separate id
           is required to ensure that multiple VNFs can be
           part of single NS";
        type string;
      }

      leaf vnfd-id-ref {
        description
          "Identifier for the VNFD.";
        type leafref {
          path "/osm-project:project[osm-project:name = current()/../../../../../osm-project:name]" +
            "/project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
        }
      }

      leaf start-by-default {
        description
          "VNFD is started as part of the NS instantiation";
        type boolean;
        default true;
      }
    }
  }

  grouping nsd-vld {
    list vld {

      key "id";

      uses nsd-base:nsd-vld-common;

      list vnfd-connection-point-ref {
        description
            "A list of references to connection points.";
        key "member-vnf-index-ref vnfd-connection-point-ref";

        leaf member-vnf-index-ref {
          description "Reference to member-vnf within constituent-vnfds";
          type leafref {
            path "../../../constituent-vnfd/member-vnf-index";
          }
        }

        leaf vnfd-id-ref {
          description
              "A reference to a vnfd. This is a
               leafref to path:
                   ../../constituent-vnfd
                   + [id = current()/../id-ref]
                   + /vnfd-id-ref
               NOTE: An issue with confd is preventing the
               use of xpath. Seems to be an issue with leafref
               to leafref, whose target is in a different module.
               Once that is resolved this will switched to use
               leafref";
          //type string;
          type leafref {
            path "../../../constituent-vnfd[member-vnf-index = current()/../member-vnf-index-ref]/vnfd-id-ref";
          }
        }

        leaf vnfd-connection-point-ref {
          description "A reference to a connection point name";
          type leafref {
            path "../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd" +
                 "[project-vnfd:id = current()/../vnfd-id-ref]/" +
                 "project-vnfd:connection-point/project-vnfd:name";
          }
        }
      }
    }
  }

  grouping nsr-nsd-vld {
    list vld {

      key "id";

      uses nsd-base:nsd-vld-common;

      list vnfd-connection-point-ref {
        description
            "A list of references to connection points.";
        key "member-vnf-index-ref vnfd-connection-point-ref";

        leaf member-vnf-index-ref {
          description "Reference to member-vnf within constituent-vnfds";

          type leafref {
            path "../../../constituent-vnfd/member-vnf-index";
          }
        }

        leaf vnfd-id-ref {
          description
              "A reference to a vnfd. This is a
               leafref to path:
                   ../../nsd:constituent-vnfd
                   + [nsd:id = current()/../nsd:id-ref]
                   + /nsd:vnfd-id-ref
               NOTE: An issue with confd is preventing the
               use of xpath. Seems to be an issue with leafref
               to leafref, whose target is in a different module.
               Once that is resolved this will switched to use
               leafref";
          type string;
        }

        leaf vnfd-connection-point-ref {
          description "A reference to a connection point name";
          type leafref {
            path "../../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd" +
                 "[project-vnfd:id = current()/../vnfd-id-ref]/" +
                 "project-vnfd:connection-point/project-vnfd:name";
          }
        }
      }
    }
  }

  grouping nsd-vnf-dependency {
    list vnf-dependency {
      description
          "List of VNF dependencies.";
      key vnf-source-ref;
      leaf vnf-source-ref {
        type leafref {
          path "../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
        }
      }
      leaf vnf-depends-on-ref {
        description
            "Reference to VNF that sorce VNF depends.";
        type leafref {
          path "../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
        }
      }
    }
  }

  grouping nsr-nsd-vnf-dependency {
    list vnf-dependency {
      description
          "List of VNF dependencies.";
      key vnf-source-ref;
      leaf vnf-source-ref {
        type leafref {
          path "../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
        }
      }
      leaf vnf-depends-on-ref {
        description
            "Reference to VNF that sorce VNF depends.";
        type leafref {
          path "../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
        }
      }
    }
  }

  grouping nsd-placement-groups {
    list placement-groups {
      description "List of placement groups at NS level";

      key "name";
      uses manotypes:placement-group-info;

      list member-vnfd {
        description
            "List of VNFDs that are part of this placement group";

        key "member-vnf-index-ref";

        leaf member-vnf-index-ref {
          description "member VNF index of this member VNF";
          type leafref {
            path "../../../constituent-vnfd/member-vnf-index";
          }
        }

        leaf vnfd-id-ref {
          description
              "Identifier for the VNFD.";
          type leafref {
            path "../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
          }
        }
      }
    }
  }

  grouping nsr-nsd-placement-groups {
    list placement-groups {
      description "List of placement groups at NS level";

      key "name";
      uses manotypes:placement-group-info;

      list member-vnfd {
        description
            "List of VNFDs that are part of this placement group";

        key "member-vnf-index-ref";

        leaf member-vnf-index-ref {
          description "member VNF index of this member VNF";
          type leafref {
            path "../../../constituent-vnfd/member-vnf-index";
          }
        }

        leaf vnfd-id-ref {
          description
              "Identifier for the VNFD.";
          type leafref {
            path "../../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd/project-vnfd:id";
          }
        }
      }
    }
  }

  grouping nsd-monitoring-param {

    list monitoring-param {
      key "id";

      uses nsd-base:monitoring-param-common;

      list vnfd-monitoring-param {
        description "A list of VNFD monitoring params";
        key "member-vnf-index-ref vnfd-monitoring-param-ref";

        leaf vnfd-id-ref {
          description
            "A reference to a vnfd. This is a
              leafref to path:
                  ../../../../nsd:constituent-vnfd
                  + [nsd:id = current()/../nsd:id-ref]
                  + /nsd:vnfd-id-ref
              NOTE: An issue with confd is preventing the
              use of xpath. Seems to be an issue with leafref
              to leafref, whose target is in a different module.
              Once that is resolved this will switched to use
              leafref";

          type leafref {
            path "../../../constituent-vnfd" +
              "[member-vnf-index = current()/../member-vnf-index-ref]" +
              "/vnfd-id-ref";
          }
        }

        leaf vnfd-monitoring-param-ref {
          description "A reference to the VNFD monitoring param";
          type leafref {
            path "../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd"
              + "[project-vnfd:id = current()/../vnfd-id-ref]"
              + "/project-vnfd:monitoring-param/project-vnfd:id";
          }
        }

        leaf member-vnf-index-ref {
          description
            "Optional reference to member-vnf within constituent-vnfds";
          type leafref {
            path "../../../constituent-vnfd/member-vnf-index";
          }
        }
      }
    }
  }

  grouping nsr-nsd-monitoring-param {
    list monitoring-param {
      key "id";

      uses nsd-base:monitoring-param-common;

      list vnfd-monitoring-param {
        description "A list of VNFD monitoring params";
        key "member-vnf-index-ref vnfd-monitoring-param-ref";

        leaf vnfd-id-ref {
          description
            "A reference to a vnfd. This is a
              leafref to path:
                  ../../../../nsd:constituent-vnfd
                  + [nsd:id = current()/../nsd:id-ref]
                  + /nsd:vnfd-id-ref
              NOTE: An issue with confd is preventing the
              use of xpath. Seems to be an issue with leafref
              to leafref, whose target is in a different module.
              Once that is resolved this will switched to use
              leafref";

          type string;
        }

        leaf vnfd-monitoring-param-ref {
          description "A reference to the VNFD monitoring param";
          type leafref {
            path "../../../../../../project-vnfd:vnfd-catalog/project-vnfd:vnfd"
              + "[project-vnfd:id = current()/../vnfd-id-ref]"
              + "/project-vnfd:monitoring-param/project-vnfd:id";
          }
        }

        leaf member-vnf-index-ref {
          description
            "Optional reference to member-vnf within constituent-vnfds";
          type leafref {
            path "../../../constituent-vnfd/member-vnf-index";
          }
        }
      }
    }
  }

  grouping nsd-descriptor {
     uses nsd-base:nsd-descriptor-common;

     uses nsd-vld;

     uses nsd-constituent-vnfd;

     uses nsd-placement-groups;

     uses nsd-vnf-dependency;

     uses nsd-monitoring-param;
  }

  augment "/osm-project:project" {
    container nsd-catalog {

      list nsd {
        key id;

        uses nsd-descriptor;
      }
    }
  }
}
