$schema: http://json-schema.org/draft-07/schema#
definitions:
  autonomousSystem:
    type: integer
    minimum: 1
    maximum: 65534
  ip4Address:
    type: string
    pattern: ^([0-9]{1,3}\.){3}[0-9]{1,3}$
  ip6Address:
    type: string
    pattern: ^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$
  ipAddress:
    oneOf:
    - $ref: "#/definitions/ip4Address"
    - $ref: "#/definitions/ip6Address"
  ip4AddressCidr:
    type: string
    pattern: ^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}$
  ip6AddressCidr:
    type: string
    pattern: ^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}/[0-9]{1,3}$
  ipAddressCidr:
    oneOf:
    - $ref: "#/definitions/ip4AddressCidr"
    - $ref: "#/definitions/ip6AddressCidr"
  ipAddressCidrList:
    type: array
    items:
      $ref: "#/definitions/ipAddressCidr"
  interfaceRoutes:
    type: object
    patternProperties:
      ^(([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2})|(([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}/[0-9]{1,3})$:
        $ref: "#/definitions/ipAddress"
    additionalProperties: False
  interfaceVlan:
    type: object
    properties:
      vlanid:
        type: integer
        minimum: 1
        maximum: 4094
      parent:
        type: string
        pattern: ^[a-z0-9\-\.]+$
    additionalProperties: False
    required:
    - parent
    - vlanid
  interfaceConfig:
    type: object
    patternProperties:
      ^[a-z0-9\-\.]+$:
        type: object
        properties:
          addrs:
            $ref: "#/definitions/ipAddressCidrList"
          routes:
            $ref: "#/definitions/interfaceRoutes"
          vlan:
            $ref: "#/definitions/interfaceVlan"
        additionalProperties: False
        required:
        - addrs
        - routes
    additionalProperties": False
  pubkeyTunnelConfig:
    properties:
      local:
        type: object
        properties:
          cert:
            type: string
          id:
            type: string
          subnets:
            $ref: "#/definitions/ipAddressCidrList"
        additionalProperties: False
        required:
        - cert
        - id
        - subnets
      remote:
        type: object
        properties:
          ca:
            type: string
          subnets:
            $ref: "#/definitions/ipAddressCidrList"
        additionalProperties: False
        required:
        - ca
        - subnets
    additionalProperties: False
  pskTunnelConfig:
    properties:
      local:
        type: object
        properties:
          id:
            type: string
          psk:
            type: string
          subnets:
            $ref: "#/definitions/ipAddressCidrList"
        additionalProperties: False
        required:
        - id
        - psk
        - subnets
      remote:
        type: object
        properties:
           subnets:
             $ref: "#/definitions/ipAddressCidrList"
        additionalProperties: False
        required:
        - subnets
    additionalProperties: False
  tunnelConfig:
    type: object
    patternProperties:
      ^[a-zA-Z0-9\-\.]+$:
        type: object
        oneOf:
        - $ref: "#/definitions/pubkeyTunnelConfig"
        - $ref: "#/definitions/pskTunnelConfig"
    additionalProperties: False
  bgpConfig:
    type: object
    properties:
      as:
        $ref: "#/definitions/autonomousSystem"
      router-id:
        $ref: "#/definitions/ipAddress"
      neighbours:
        type: array
        items:
          type: object
          properties:
            addr:
              $ref: "#/definitions/ipAddress"
            as:
              $ref: "#/definitions/autonomousSystem"
          additionalProperties: False
          required:
          - addr
    additionalProperties: False
    required:
    - as
    - router-id
    - neighbours
  firewall4Address:
    oneOf:
    - $ref: "#/definitions/ip4Address"
    - $ref: "#/definitions/ip4AddressCidr"
  firewall6Address:
    oneOf:
    - $ref: "#/definitions/ip6Address"
    - $ref: "#/definitions/ip6AddressCidr"
  firewallProto:
    oneOf:
    - type: string
    - type: integer
  firewallMatches:
    type: object
    patternProperties:
      ^(tcp|udp|comment)$:
        type: object
    additionalProperties: False
  firewallTarget:
    type: object
    patternProperties:
      ^(ACCEPT|REJECT|DROP)$:
        type: object
    additionalProperties: False
  firewallConfig:
    type: object
    properties:
      input:
        type: array
        items:
          type: object
          properties:
            src:
              $ref: "#/definitions/firewall4Address"
            dst:
              $ref: "#/definitions/firewall4Address"
            proto:
              $ref: "#/definitions/firewallProto"
            matches:
              $ref: "#/definitions/firewallMatches"
            target:
              $ref: "#/definitions/firewallTarget"
          additionalProperties: False
      input6:
        type: array
        items:
          type: object
          properties:
            src:
              $ref: "#/definitions/firewall6Address"
            dst:
              $ref: "#/definitions/firewall6Address"
            proto:
              $ref: "#/definitions/firewallProto"
            matches:
              $ref: "#/definitions/firewallMatches"
            target:
              $ref: "#/definitions/firewallTarget"
          additionalProperties: False
    additionalProperties: False
  vrfConfig:
    type: object
    patternProperties:
      ^[a-zA-Z0-9\-\.]+$:
        type: object
        properties:
          vrf:
            type: integer
            minimum: 1
            maximum: 65535
          isolate:
            type: boolean
          interfaces:
            $ref: "#/definitions/interfaceConfig"
          tunnels:
            $ref: "#/definitions/tunnelConfig"
          bgp:
            $ref: "#/definitions/bgpConfig"
        additionalProperties: False
        required:
        - vrf
        - tunnels
    additionalProperties: False
  externalBgpConfig:
    type: object
    properties:
      interface:
        type: string
      addrs:
        $ref: "#/definitions/ipAddressCidrList"
      as:
        $ref: "#/definitions/autonomousSystem"
      router-id:
        $ref: "#/definitions/ipAddress"
      role:
        enum:
        - master
        - backup
      neighbours:
        type: array
        items:
          type: object
          properties:
            addr:
              $ref: "#/definitions/ipAddress"
            as:
              $ref: "#/definitions/autonomousSystem"
          additionalProperties: False
          required:
          - addr
      check:
        type: object
        patternProperties:
          ^[a-zA-Z0-9\-\.]+$:
            properties:
              script:
                type: string
              interval:
                type: integer
                minimum: 1
              timeout:
                type: integer
                minimum: 1
              fall:
                type: integer
                minimum: 1
              rise:
                type: integer
                minimum: 1
            additionalProperties: False
            required:
            - script
            - interval
        additionalProperties: False
    additionalProperties: False
    required:
    - interface
    - addrs
    - as
    - router-id
    - role
    - neighbours
  vrrpConfig:
    type: object
    properties:
      interface:
        type: string
    additionalProperties: False
    required:
    - interface
  postReloadConfig:
    type: array
    items:
      type: string
type: object
properties:
  firewall:
    $ref: "#/definitions/firewallConfig"
  vrfs:
    $ref: "#/definitions/vrfConfig"
  bgp:
    $ref: "#/definitions/externalBgpConfig"
  vrrp:
    $ref: "#/definitions/vrrpConfig"
  post-reload:
    $ref: "#/definitions/postReloadConfig"
additionalProperties: False
