# Copyright (c) ETSI 2017.
# https://forge.etsi.org/etsi-forge-copyright-notice.txt

definitions:
  CreateThresholdRequest:
    description: >
      This type represents a request to create a threshold.
    type: object
    required:
      - objectInstanceId
      - criteria
    properties: 
      objectInstanceId:
        description: >
          Identifier of the VNF instance associated with this threshold.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      criteria:
        description: >
          Criteria that define this threshold.
        $ref: "#/definitions/ThresholdCriteria"

  CreatePmJobRequest:
    description: >
      This type represents a request to create a PM job.
    type: object
    required:
      - criteria
    properties:
      objectInstanceIds:
        description: >
          Identifiers of the VNF instances for which performance information
          is requested to be collected.
        type: array
        items:
          $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      criteria:
        description: >
          Criteria of the collection of performance information.
        $ref: "#/definitions/PmJobCriteria"

  CrossingDirectionType:
    type: string
    enum: 
      - UP
      - DOWN

  PerformanceInformationAvailableNotification:
    description: >
      This notification informs the receiver that performance information is
      available.
      The timing of sending this notification is determined by the capability
      of the producing entity to evaluate the threshold crossing condition.
      The notification shall be triggered by the VNFM when new performance
      information collected by a PM job is available.
    type: object
    required: 
      - id
      - notificationType
      - subscriptionId
      - timeStamp
      - objectInstanceId
      - _links
    properties: 
      id: 
        description: >
          Identifier of this notification. If a notification is sent multiple
          times due to multiple subscriptions, the "id" attribute of all these
          notifications shall have the same value.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      notificationType:
        description: >
          Discriminator for the different notification types. Shall be set to
          "PerformanceInformationAvailableNotification" for this notification
          type.
        type: string
        enum: 
          - PerformanceInformationAvailableNotification
      subscriptionId:
        description: >
          Identifier of the subscription that this notification relates to.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      timeStamp:
        description: >
          Date and time of the generation of the notification.
        $ref: "SOL002SOL003_def.yaml#/definitions/DateTime"
      objectInstanceId:
        description: >
          Identifier that identifies a VNF instance.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      _links:
        description: >
          Links to resources related to this notification.
        type: object
        required: 
          - subscription
          - pmJob
          - performanceReport
        properties:
          subscription:
            description: >
              Link to the related subscription.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"
          objectInstance:
            description: >
              Link to the resource representing the VNF instance to which the
              notified change applies. Shall be present if the VNF instance
              information is accessible as a resource.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"
          pmJob:
            description: >
              Link to the resource that represents the PM job for which
              performance information is available.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"
          performanceReport:
            description: >
              Link from which the available performance information of data
              type "PerformanceReport" can be obtained. This link should point
              to an "Individual performance report" resource.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"

  PmJob:
    description: >
      This type represents a PM job.
    type: object
    required:
      - id
      - objectInstanceIds
      - criteria
    properties:
      id:
        description: >
          Identifier of this PM job.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      objectInstanceIds:
        description: >
          Identifiers of the VNF instances for which performance information
          is collected.
        type: array
        items:
          $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      criteria:
        description: >
          Criteria of the collection of performance information.
        $ref: "#/definitions/PmJobCriteria"
      reports:
        description: >
          Information about available reports collected by this PM job.
        type: object
        required:
          - href
          - readyTime
          - _links
        properties:
          href:
            description: >
              The Uri where the report can be obtained.
            type: string
            format: url
          readyTime:
            description: >
              The time when the report was made available.
            $ref: "SOL002SOL003_def.yaml#/definitions/DateTime"
          expiryTime:
            description: >
              The time when the report will expire.
            $ref: "SOL002SOL003_def.yaml#/definitions/DateTime"
          fileSize:
            description: >
              The size of the report file in bytes, if known.
            type: integer
            # TODO: How to express unsigned int?
          _links:
            description: >
              Links for this resource.
            type: object
            required:
              - self
            properties:
              self:
                description: >
                  URI of this resource.
                $ref: "SOL002SOL003_def.yaml#/definitions/Link"
              objects:
                description: >
                  Links to resources representing the VNF instances for which
                  performance information is collected. Shall be present if
                  the VNF instance information is accessible as a resource.
                type: array
                items: 
                  $ref: "SOL002SOL003_def.yaml#/definitions/Link"

  PmJobCriteria:
    description: >
      Criteria of the collection of performance information.
    type: object
    required:
      - collectionPeriod
      - reportingPeriod
    properties:
      performanceMetric:
        description: >
          This defines the types of performance metrics for the specified
          object instances, as specified in ETSI GS NFV-IFA 027). At least one
          of the two attributes (performance metric or group) shall be
          present.
        type: array
        items: 
          type: string
      performanceMetricGroup:
        description: >
          Group of performance metrics. A metric group is a pre-defined list
          of metrics, known to the producer that it can decompose to
          individual metrics.
          At least one of the two attributes (performance metric or group)
          shall be present.
        type: array
        items: 
          type: string
      collectionPeriod:
        description: >
          Specifies the periodicity at which the producer will collect
          performance information. The unit shall be seconds.
          At the end of each reportingPeriod, the producer will inform the
          consumer about availability of the performance data collected for
          each completed collection period during this reportingPeriod. The
          reportingPeriod should be equal to or a multiple of the
          collectionPeriod. In the latter case, the performance data for the
          collection periods within one reporting period are reported
          together.
        type: integer
        # TODO: How to express unsigned int?
      reportingPeriod:
        description: >
          Specifies the periodicity at which the producer will report to the
          consumer. about performance information. The unit shall be seconds.
          At the end of each reportingPeriod, the producer will inform the
          consumer about availability of the performance data collected for
          each completed collection period during this reportingPeriod. The
          reportingPeriod should be equal to or a multiple of the
          collectionPeriod. In the latter case, the performance data for the
          collection periods within one reporting period are reported
          together.
        type: integer
        # TODO: How to express unsigned int?
      reportingBoundary:
        description: >
          Identifies a time boundary after which the reporting will stop.
          The boundary shall allow a single reporting as well as periodic
          reporting up to the boundary.
        $ref: "SOL002SOL003_def.yaml#/definitions/DateTime"

  PmNotificationsFilter:
    description: >
      This type represents a filter that can be used to subscribe for
      notifications related to performance management events.
    type: object
    properties: 
      vnfInstanceSubscriptionFilter:
        description: >
          Filter criteria to select VNF instances about which to notify.
        $ref: "SOL002SOL003_def.yaml#/definitions/VnfInstanceSubscriptionFilter"
      notificationTypes:
        description: >
          Match particular notification types.
          Permitted values:
          * ThresholdCrossedNotification
          * PerformanceInformationAvailableNotification
          The permitted values of the "notificationTypes" attribute are
          spelled exactly as the names of the notification types to facilitate
          automated code generation systems.
        type: string
        enum: 
          - ThresholdCrossedNotification
          - PerformanceInformationAvailableNotification

  PmSubscription:
    description: >
      This type represents a subscription.
    type: object
    required: 
      - id
      - callbackUri
      - _links
    properties: 
      id:
        description: >
          Identifier that identifies the subscription.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      filter:
        description: >
          Filter settings for this subscription, to define the subset of all
          notifications this subscription relates to. A particular
          notification is sent to the subscriber if the filter matches, or if
          there is no filter.
        $ref: "#/definitions/PmNotificationsFilter"
      callbackUri:
        description: >
          The URI of the endpoint to send the notification to.
        type: string
        format: url
      _links:
        description: >
          Links to resources related to this resource.
        type: object
        required:
          - self
        properties:
          self:
            description: >
              URI of this resource.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"

  PmSubscriptionRequest:
    description: >
      This type represents a subscription request.
    type: object
    required: 
      - callbackUri
    properties:
      filter:
        description: >
          Filter settings for this subscription, to define the subset of all
          notifications this subscription relates to. A particular
          notification is sent to the subscriber if the filter matches, or if
          there is no filter.
        $ref: "#/definitions/PmNotificationsFilter"
      callbackUri:
        description: >
          The URI of the endpoint to send the notification to.
        type: string
        format: url
      authentication:
        description: >
          Authentication parameters to configure the use of Authorization when
          sending notifications corresponding to this subscription.
          This attribute shall only be present if the subscriber requires
          authorization of notifications.
        $ref: "SOL002SOL003_def.yaml#/definitions/SubscriptionAuthentication"

  Threshold:
    description: >
      This type represents a threshold.
    type: object
    required: 
      - id
      - objectInstanceId
      - criteria
      - _links
    properties: 
      id:
        description: >
          Identifier of this threshold resource.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      objectInstanceId:
        description: >
          Identifier of the VNF instance associated with the threshold.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      criteria:
        description: >
          Criteria that define this threshold.
        $ref: "#/definitions/ThresholdCriteria"
      _links:
        description: >
          Links for this resource.
        type: object
        required: 
          - self
        properties: 
          self:
            description: >
              URI of this resource.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"
          object: 
            description: >
              Link to a resource representing the VNF instance for which
              performance information is collected. Shall be present if the
              VNF instance information is accessible as a resource.

  ThresholdCriteria:
    description: >
      This type represents criteria that define a threshold.
    type: object
    required: 
      - performanceMetric
      - thresholdType
    properties: 
      performanceMetric:
        description: >
          Defines the performance metric associated with the
          threshold, as specified in ETSI GS NFV-IFA 027).
        type: string
      thresholdType:
        description: >
          Type of threshold. This attribute determines which other attributes
          are present in the data structure.
          Permitted values:
          * SIMPLE: Single-valued static threshold
          In the present document, simple thresholds are defined. The
          definition of additional threshold types is left for future
          specification.
        type: string
        enum:
          - SIMPLE
      simpleThresholdDetails:
        description: >
          Details of a simple threshold. Shall be present if
          thresholdType="SIMPLE".
        type: object
        required: 
          - thresholdValue
          - hysteresis
        properties: 
          thresholdValue:
            description: >
              The threshold value. Shall be represented as a floating point
              number.
            # TODO: This should be floating.             
            type: integer
          hysteresis:
            description: >
              The hysteresis of the threshold. Shall be represented as a
              non-negative floating point number.
              A notification with crossing direction "UP" will be generated if
              the measured value reaches or exceeds
              "thresholdValue" + "hysteresis". A notification with crossing
              direction "DOWN" will be generated if the measured value reaches
              or undercuts "thresholdValue" - "hysteresis".
              The hysteresis is defined to prevent storms of threshold
              crossing notifications. When processing a request to create a
              threshold, implementations should enforce a suitable minimum
              value for this attribute (e.g. override the value or reject the
              request).
            # TODO: This should be floating. 
            type: integer

  ThresholdCrossedNotification:
    description: >
      This type represents a notification that is sent when a threshold has
      been crossed.
      The notification shall be triggered by the VNFM when a threshold has
      been crossed.
    type: object
    required: 
      - id
      - notificationType
      - subscriptionId
      - timeStamp
      - thresholdId
      - crossingDirection
      - objectInstanceId
      - performanceMetric
      - performanceValue
      - _links
    properties: 
      id: 
        description: >
          Identifier of this notification. If a notification is sent multiple
          times due to multiple subscriptions, the "id" attribute of all these
          notifications shall have the same value.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      notificationType: 
        description: >
          Discriminator for the different notification types. Shall be set to
          "ThresholdCrossedNotification" for this notification type.
        type: string
        enum: 
          - ThresholdCrossedNotification
      subscriptionId:
        description: >
          Identifier of the subscription that this notification relates to.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      timeStamp:
        description: >
          Date and time of the generation of the notification.
        $ref: "SOL002SOL003_def.yaml#/definitions/DateTime"
      thresholdId:
        description: >
          Identifier of the threshold which has been crossed.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      crossingDirection:
        description: >
          An indication of whether the threshold was crossed in upward or
          downward direction.
        $ref: "#/definitions/CrossingDirectionType"
      objectInstanceId:
        description: >
          Identifier that identifies a VNF instance.
        $ref: "SOL002SOL003_def.yaml#/definitions/Identifier"
      performanceMetric:
        description: >
          Performance metric associated with the threshold.
        type: string
      performanceValue:
        description: >
          Value of the metric that resulted in threshold crossing.
          The type of the "performanceValue" attribute (i.e. scalar, structure
          (Object in JSON), or array (of scalars, arrays or
          structures / Objects)) is assumed to be defined in the external
          measurement specification (see ETSI GS NFV-IFA 027).
        type: object
      _links:
        description: >
          Links to resources related to this notification.
        type: object
        required: 
          - subscription
          - threshold
        properties: 
          subscription:
            description: >
              Link to the related subscription.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"
          objectInstance:
            description: >
              Link to the resource representing the VNF instance to which the
              notified change applies. Shall be present if the VNF instance
              information is accessible as a resource.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"
          threshold:
            description: >
              Link to the resource that represents the threshold that was
              crossed.
            $ref: "SOL002SOL003_def.yaml#/definitions/Link"
