# (C) Copyright 2014 Riverbed Technology, Inc.
# All rights reserved.

name: sh.common
version: "1.0"
title: 'SteelHead Common Type Definitions'
description: 'REST API for SteelHead specific common data types'
defaultAuthorization: 'none'
$schema: 'http://support.riverbed.com/apis/service_def/2.2'
id: 'http://support.riverbed.com/apis/sh.common/1.0'
provider: 'riverbed'

###############################################################################
#
# Types
#
# ipv4address, ipv4prefix, ipv6address and ipv6prefix are from
# http://blog.markhatton.co.uk/2011/03/15/regular-expressions-for-ip-addresses-cidr-ranges-and-hostnames/
#
# some types are derived from lumberjack-svc-appflows and steelhead-svc-inpath
#
###############################################################################

types:
    ipv4address:
        description: >
            IPv4 address (x.y.z.k):
            A 32-bit IPv4 address in dotted-decimal format. It is described in
            IETF publication RFC791.
        type: string
        pattern: '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
        minLength: 7
        maxLength: 15

    ipv4prefix:
        description: >
            IPv4 prefix/subnet (x.y.z.k/<0-32>):
            A CIDR notion of IPv4 prefix/subnet representation that consists
            of an IPv4 address along with its routing prefix separated by a
            forward slash character("/").
        type: string
        pattern: '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(\d|[1-2]\d|3[0-2]))$'
        minLength: 9
        maxLength: 18

    ipv6address:
        description: >
            IPv6 address (x:y:z::k):
            A 128-bit IPv6 address described in IETF publication RFC2460,
            RFC4291, RFC5952, RFC6052, RFC6145.
        type: string
        pattern: '^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$'
        minLength: 2
        maxLength: 45

    ipv6prefix:
        description: >
            IPv6 prefix/subnet (x:y:z::k/<0-128>):
            A CIDR notion of IPv6 prefix/subnet representation that consists
            of an IPv6 address along with its routing prefix separated by a
            forward slash character("/").
        type: string
        pattern: '^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*(\/(\d|\d\d|1[0-1]\d|12[0-8]))$'
        minLength: 4
        maxLength: 49

    ipv4ipv6address:
        description: 'IPv4 or IPv6 address (x.y.z.k|x:y:z::k)'
        type: object
        additionalProperties: false
        properties:
            ipv4address: { $ref: '#/types/ipv4address' }
            ipv6address: { $ref: '#/types/ipv6address' }
        oneOf:
        - type: object
          required: [ ipv4address ]
        - type: object
          required: [ ipv6address ]

    ipv4ipv6prefix:
        description: 'IPv4 or IPv6 prefix/subnet (x.y.z.k/<0-32>|x:y:z::k/<0-128>)'
        type: object
        additionalProperties: false
        properties:
            ipv4prefix: { $ref: '#/types/ipv4prefix' }
            ipv6prefix: { $ref: '#/types/ipv6prefix' }
        oneOf:
        - type: object
          required: [ ipv4prefix ]
        - type: object
          required: [ ipv6prefix ]

    port:
        description: 'Valid port number'
        type: integer
        minimum: 0
        maximum: 65535

    portlabel:
        description: >
            A textual name assigned to a range of ports, for example the
            predefined port label "RBT-Proto" refers to ports in range of
            7744, 7800-7801, 7810, 7820, 7850, 7860, 7870.
        type: string

    port_portlabel:
        description: 'Port number or port label'
        type: object
        additionalProperties: false
        properties:
            port: { $ref: '#/types/port' }
            portlabel: { $ref: '#/types/portlabel' }
        oneOf:
        - type: object
          required: [ port ]
        - type: object
          required: [ portlabel ]

    vlan_tag:
        description: 'VLAN tag (all, untagged, tagged - [1-4094])'
        type: object
        additionalProperties: false
        properties:
            state:
                description: 'The state of a VLAN tag.'
                type: string
                enum: [ all, untagged, tagged ]
            tag:
                description: 'The "tag" is valid if "state" == "tagged".'
                type: number
                minimum: 1
                maximum: 4094
        oneOf:
        - type: object
          required: [ state ]
          additionalProperties: false
          properties:
            state:
                type: string
                enum: [ all, untagged ]
        - type: object
          required: [ state, tag ]
          additionalProperties: false
          properties:
            state:
                type: string
                enum: [ tagged ]
            tag:
                type: number