module openconfig-policy-types {

  yang-version "1";

  // namespace
  namespace "http://openconfig.net/yang/policy-types";

  prefix "ptypes";

  // import some basic types
  import ietf-yang-types { prefix yang; }
  import openconfig-extensions { prefix oc-ext; }

  // meta
  organization
    "OpenConfig working group";

  contact
    "OpenConfig working group
    netopenconfig@googlegroups.com";

  description
    "This module contains general data definitions for use in routing
    policy.  It can be imported by modules that contain protocol-
    specific policy conditions and actions.";

  oc-ext:openconfig-version "1.1.0";

  revision "2015-10-09" {
    description
      "Initial OpenConfig public release";
    reference "1.1.0";
  }

  revision "2015-05-15" {
    description
      "Initial revision";
    reference "Pre-release";
  }

  // identity statements

  identity attribute-comparison {
    description
      "base type for supported comparison operators on route
      attributes";
  }

  identity attribute-eq {
    base attribute-comparison;
    description "== comparison";
  }

  identity attribute-ge {
    base attribute-comparison;
    description ">= comparison";
  }

  identity attribute-le {
    base attribute-comparison;
    description "<= comparison";
  }

  typedef match-set-options-type {
    type enumeration {
      enum ANY {
        description "match is true if given value matches any member
        of the defined set";
      }
      enum ALL {
        description "match is true if given value matches all
        members of the defined set";
      }
      enum INVERT {
        description "match is true if given value does not match any
        member of the defined set";
      }
    }
    default ANY;
    description
      "Options that govern the behavior of a match statement.  The
      default behavior is ANY, i.e., the given value matches any
      of the members of the defined set";
  }

  typedef match-set-options-restricted-type {
    type enumeration {
      enum ANY {
        description "match is true if given value matches any member
        of the defined set";
      }
      enum INVERT {
        description "match is true if given value does not match any
        member of the defined set";
      }
    }
    default ANY;
    description
      "Options that govern the behavior of a match statement.  The
      default behavior is ANY, i.e., the given value matches any
      of the members of the defined set.  Note this type is a
      restricted version of the match-set-options-type.";
      //TODO: restriction on enumerated types is only allowed in
      //YANG 1.1.  Until then, we will require this additional type
  }

  grouping attribute-compare-operators {
    description "common definitions for comparison operations in
    condition statements";

    leaf operator {
        type identityref {
          base attribute-comparison;
        }
        description
          "type of comparison to be performed";
      }

    leaf value {
      type uint32;
      description
        "value to compare with the community count";
    }
  }

  typedef tag-type {
    type union {
      type uint32;
      type yang:hex-string;
    }
    description "type for expressing route tags on a local system,
    including IS-IS and OSPF; may be expressed as either decimal or
    hexidecimal integer";
    reference
      "RFC 2178 OSPF Version 2
      RFC 5130 A Policy Control Mechanism in IS-IS Using
      Administrative Tags";
  }

  identity install-protocol-type {
    description
      "Base type for protocols which can install prefixes into the
      RIB";
  }

  identity BGP {
    base install-protocol-type;
    description "BGP";
    reference "RFC 4271";
  }

  identity ISIS {
    base install-protocol-type;
    description "IS-IS";
    reference "ISO/IEC 10589";
  }

  identity OSPF {
    base install-protocol-type;
    description "OSPFv2";
    reference "RFC 2328";
  }

  identity OSPF3 {
    base install-protocol-type;
    description "OSPFv3";
    reference "RFC 5340";
  }

  identity STATIC {
    base install-protocol-type;
    description "Locally-installed static route";
  }

  identity DIRECTLY-CONNECTED {
    base install-protocol-type;
    description "A directly connected route";
  }

  identity LOCAL-AGGREGATE {
    base install-protocol-type;
    description "Locally defined aggregate route";
  }
}