module hwvtep {
    yang-version 1;
    namespace "urn:opendaylight:params:xml:ns:yang:ovsdb:hwvtep";
    prefix "hwvtepsb";

    import network-topology {prefix "topo"; revision-date "2013-10-21"; }
    import yang-ext { prefix "ext"; }
    import ietf-inet-types { prefix inet; revision-date 2013-07-15; }
    import ietf-yang-types { prefix yang; revision-date "2013-07-15";}
    import opendaylight-l2-types { prefix ethertype; revision-date "2013-08-27";}

    revision "2015-09-01" {
        description "1st revision of southbound model for hwvtep";
    }

    typedef hwvtep-physical-switch-ref {
        description "A reference to a hwvtep based physical switch";
        type instance-identifier;
    }

    typedef hwvtep-logical-switch-ref {
        description "A reference to a logical switch in hwvtep based switches";
        type instance-identifier;
    }

    typedef hwvtep-physical-locator-ref {
        description "A reference to an endpoint to which logical switch traffic may be encapsulated and forwarded";
        type instance-identifier;
    }

    typedef hwvtep-global-ref {
        description "A reference to an hwvtep global node";
        type instance-identifier;
    }

    typedef hwvtep-node-name {
        type string;
    }

    typedef ietf-acl-entry-ref {
        description "A reference to an ietf-acl-entry";
        type instance-identifier;
    }

    typedef hwvtep-acl-ref {
        description "A reference to an acl";
        type instance-identifier;
    }

    typedef hwvtep-logical-binding-stats-ref {
        description "A reference to a logical-binding-stats";
        type instance-identifier;
    }

    grouping hwvtep-node-identification {
        leaf hwvtep-node-name {
            description "The name of the node";
            type hwvtep-node-name;
        }
        leaf hwvtep-node-description {
            description "The description of the node";
            type string;
        }
    }

    grouping hwvtep-mac-table-generic-attributes {
        leaf mac-entry-key {
            description "MAC address entry";
            type yang:mac-address;
        }
        leaf mac-entry-uuid {
            description "The unique identifier of the mac-entry";
            type yang:uuid;
        }
        leaf logical-switch-ref {
            description "The logical switch to which this mapping applies";
            type hwvtep-logical-switch-ref;
        }
    }

    grouping hwvtep-ucast-mac-table-attributes {
        description "Unicast mac table attributes";
        leaf ipaddr {
            description "Optional IP address associated with the mac";
            type inet:ip-address;
        }
        leaf locator-ref {
            description "Reference to the physical locator to reach this entry";
            type hwvtep-physical-locator-ref;
        }
    }

    grouping hwvtep-mcast-mac-table-attributes {
        description "Multicast mac table attributes";
        leaf ipaddr {
            description "Optional IP address associated with the mac";
            type inet:ip-address;
        }
        uses hwvtep-physical-locator-set-attributes;
    }

    grouping hwvtep-tunnel-attributes {
        leaf tunnel-uuid {
            description "The unique identifier of the tunnel";
            type yang:uuid;
        }
        leaf local-locator-ref {
            description "Reference to the physical locator to reach this entry";
            type hwvtep-physical-locator-ref;
        }
        leaf remote-locator-ref {
            description "Reference to the physical locator to reach this entry";
            type hwvtep-physical-locator-ref;
        }
        list bfd-local-configs {
            description "Local configuation attributes for BFD";

            key "bfd-local-config-key";
            leaf bfd-local-config-key {
                description "bfd-local-config name/key";
                type string;
            }
            leaf bfd-local-config-value {
                description "bfd-local-config value";
                type string;
            }
        }
        list bfd-remote-configs {
            description "Remote configuration attributes for BFD";

            key "bfd-remote-config-key";
            leaf bfd-remote-config-key {
                description "bfd-remote-config name/key";
                type string;
            }
            leaf bfd-remote-config-value {
                description "bfd-remote-config value";
                type string;
            }
        }
        list bfd-params {
            description "Parameters to configure and enable BFD";

            key "bfd-param-key";
            leaf bfd-param-key {
                description "bfd-param name/key";
                type string;
            }
            leaf bfd-param-value {
                description "bfd-param value";
                type string;
            }
        }
        list bfd-status {
            description "runtime status of BFD on this tunnel";

            config false;
            key "bfd-status-key";
            leaf bfd-status-key {
                description "bfd-status name/key";
                type string;
            }
            leaf bfd-status-value {
                description "bfd-status value";
                type string;
            }
        }
    }

    grouping hwvtep-physical-switch-attributes {
        uses hwvtep-node-identification;
        leaf physical-switch-uuid {
            description "The unique identifier of the physical-switch";
            type yang:uuid;
        }
        list management-ips {
            key "management-ips-key";
            leaf management-ips-key {
               description "Management IP address of the switch";
               type inet:ip-address;
            }
        }
        leaf managed-by {
            description "The hwvtep global node to which this physical switch belongs to";
            type hwvtep-global-ref;
        }
        list tunnel-ips {
            key "tunnel-ips-key";
            leaf tunnel-ips-key {
               description "Management IP address of the switch";
               type inet:ip-address;
            }
        }
        list tunnels {
            key "local-locator-ref remote-locator-ref";
            uses hwvtep-tunnel-attributes ;
        }
        list switch-fault-status {
            config false;
            key "switch-fault-status-key";
            leaf switch-fault-status-key {
                description "switch-fault-status name/key";
                type string;
            }
            leaf switch-fault-status-value {
                description "switch-fault-status value";
                type string;
            }
        }
    }

    grouping hwvtep-connection-info-attributes {
        leaf remote-ip {
            type inet:ip-address;
            description "Hwvtep Connection Remote IP";
        }
        leaf remote-port {
            type inet:port-number;
            description "Hwvtep Connection Remote Port Number";
        }
        leaf local-ip {
            type inet:ip-address;
            description "Hwvtep Connection Local IP";
        }
        leaf local-port {
            type inet:port-number;
            description "Hwvtep Connection Local Port Number IP";
        }
    }

    grouping hwvtep-global-attributes {
        description "global node for the hwvtep";
        container connection-info {
            uses hwvtep-connection-info-attributes;
        }
        leaf db-version {
            description "The database schema version";
            type string;
        }
        list managers {
            description "";
            key "target";
            leaf target {
                description "Uri indicating connection method to the Manager";
                type inet:uri;
            }
            leaf manager-uuid {
                description "The unique identifier of the manager";
                type yang:uuid;
            }
            leaf is-connected {
                type boolean;
            }
            list manager-other-configs {
                description "Key-value pairs for configuring rarely used features.
                    other_config : dscp : optional string
                    contains an integer, in the range 0 - 63. DSCP value to be used when establishing a connection to the switch. Default value of 48 if none specified.";
                key "other-config-key";
                leaf other-config-key {
                    description "other-config name/key";
                    type string;
                }
                leaf other-config-value {
                    description "other-config value";
                    type string;
                }
            }
        }
        list switches {
            description "List of physical switches managed by this node";
            key "switch-ref";
            leaf switch-ref {
                type hwvtep-physical-switch-ref;
            }
        }
        list logical-switches {
            key "hwvtep-node-name";
            uses hwvtep-logical-switch-attributes;
        }
        list local-ucast-macs {
            key "mac-entry-key logical-switch-ref";
            uses hwvtep-mac-table-generic-attributes;
            uses hwvtep-ucast-mac-table-attributes;
        }
        list remote-ucast-macs {
            key "mac-entry-key logical-switch-ref";
            uses hwvtep-mac-table-generic-attributes;
            uses hwvtep-ucast-mac-table-attributes;
        }
        list local-mcast-macs {
            key "mac-entry-key logical-switch-ref";
            uses hwvtep-mac-table-generic-attributes;
            uses hwvtep-mcast-mac-table-attributes;
        }
        list remote-mcast-macs{
            key "mac-entry-key logical-switch-ref";
            uses hwvtep-mac-table-generic-attributes;
            uses hwvtep-mcast-mac-table-attributes;
        }
        list logical-routers {
            key "hwvtep-node-name";
            uses hwvtep-logical-router-attributes;
        }
        list local-arp-sources {
            key "src-mac";
            uses hwvtep-arp-sources-attributes;
        }
        list remote-arp-sources {
            key "src-mac";
            uses hwvtep-arp-sources-attributes;
        }
        list acls {
            key "acl-name";
            uses hwvtep-acl-attributes;
        }
        list logical-binding-stats {
            config false;
            key "logical-binding-stats-uuid";
            uses hwvtep-logical-binding-stats-attributes;
        }
    }

    identity encapsulation-type-base {
        description "Base Encapsulation type";
    }

    identity encapsulation-type-vxlan-over-ipv4 {
        base encapsulation-type-base;
        description "Encapsulation type vxlan-over-ipv4";
    }

    typedef encapsulation-type {
        type identityref {
            base encapsulation-type-base;
        }
        description "This type is used to refer to an Encapsulation Type.";
    }

    grouping hwvtep-physical-locator-attributes {
        leaf physical-locator-uuid {
            description "The unique identifier of the physical-locator";
            type yang:uuid;
        }
        leaf encapsulation-type {
            type encapsulation-type;
            description "Encapsulation type used by this locator";
        }
        leaf dst-ip {
            type inet:ip-address;
            description "IP address of the locator";
        }
    }

    grouping hwvtep-physical-locator-set-attributes {
        list locator-set {
            leaf locator-ref {
                type hwvtep-physical-locator-ref;
            }
        }
    }

    grouping hwvtep-logical-switch-attributes {
        uses hwvtep-node-identification;
        leaf logical-switch-uuid {
            description "A unique identifier of the logical switch";
            type yang:uuid;
        }
        leaf tunnel-key {
            description "Per Logical Switch tunnel key";
            type string;
        }
        leaf replication-mode {
            description "Per Logical Switch replication mode";
            type string;
        }
    }

    grouping hwvtep-physical-port-attributes {
        uses hwvtep-node-identification;
        leaf physical-port-uuid {
            description "The unique identifier of the physical-port";
            type yang:uuid;
        }
        list vlan-bindings {
            description "A map of vlan ID to logical switch pairs";
            key "vlan-id-key";
            leaf vlan-id-key {
                description "vlan ids in the range 0 - 4095";
                type ethertype:vlan-id;
            }
            leaf logical-switch-ref {
                description "Reference to logical switch for the vlan";
                type hwvtep-logical-switch-ref;
            }
        }
        list acl-bindings {
            key "acl-binding-vlan-id";
            leaf acl-binding-vlan-id {
                description "vlan ids in the range 0 - 4095";
                type ethertype:vlan-id;
            }
            leaf acl-ref {
                description "reference to ACL to be applied to this port";
                type hwvtep-acl-ref;
            }
        }
        list vlan-stats {
            key "vlan-stats-key";
            leaf vlan-stats-key {
                description "vlan ids in the range 0 - 4095";
                type ethertype:vlan-id;
            }
            leaf vlan-stats-ref {
                description "reference to logical binding stats for this port";
                type hwvtep-logical-binding-stats-ref;
            }
        }
        list port-fault-status {
            config false;
            key "port-fault-status-key";
            leaf port-fault-status-key {
                description "port-fault-status name/key";
                type string;
            }
            leaf port-fault-status-value {
                description "port-fault-status value";
                type string;
            }
        }
    }

    grouping hwvtep-logical-router-attributes {
        uses hwvtep-node-identification;
        leaf logical-router-uuid {
            description "A unique identifier of the logical router";
            type yang:uuid;
        }
        list switch-bindings {
            description "A map of IPv4 or IPv6 address prefix in CIDR
                         notation to logical switch. Multiple prefixes
                         may map to the same switch. By writing a 32-bit
                         (or 128-bit for v6) address with a /N prefix
                         length, both the router's interface address and the
                         subnet  prefix  can be configured. For example,
                         192.68.1.1/24 creates a /24 subnet for the logical
                         switch  attached to the interface and assigns the
                         address 192.68.1.1 to the router interface.";
            leaf destination-address {
                description "IPv4 or IPv6 address prefix in CIDR notation";
                type inet:ip-prefix;
            }
            leaf logical-switch-ref {
                description "reference to logical switch";
                type hwvtep-logical-switch-ref;
            }
        }
        list static-routes {
            description "map of string-string pairs. One or more static routes,
                         mapping IP prefixes to next hop IP addresses.";
            leaf destination-address {
                description "IPv4 or IPv6 address prefix in CIDR notation";
                type inet:ip-prefix;
            }
            leaf nexthop-address {
                description "IP address of next hop";
                type inet:ip-address;
            }
        }
        list acl-bindings {
            description "map of string-ACL pairs. Maps ACLs to logical router
                         interfaces. The router interfaces are indicated
                         using IP address notation, and must be the same
                         interfaces created in the switch_binding column.
                         For example, an ACL could be associated with the
                         logical router interface with an address of
                         192.68.1.1 as defined in the example above.";
            key "router-interface";
            leaf router-interface {
                description "IPv4 or IPv6 address prefix in CIDR notation";
                type inet:ip-prefix;
            }
            leaf acl-ref {
                description "reference to ACL to be applied to this router";
                type hwvtep-acl-ref;
            }
        }
    }

    grouping hwvtep-arp-sources-attributes {
        description "AP Sources table attributes";
        leaf arp-sources-uuid {
            description "The unique identifier of the arp-source";
            type yang:uuid;
        }
        leaf src-mac {
            description "Source mac to be used by given tep";
            type yang:mac-address;
        }
        uses hwvtep-physical-locator-attributes;
    }

    grouping hwvtep-acl-entry-attributes {
        description "ACL Entry attributes";
        leaf sequence {
            description "integer. Sequence number for ACL entry";
            type uint32 {
                range "0..max";
            }
        }
        leaf acl-entry-uuid {
            description "The unique identifier of the acl-entry";
            type yang:uuid;
        }
        leaf acl-entry-ref {
            type ietf-acl-entry-ref;
        }
        list acle-fault-status {
            config false;
            key "acle-fault-status-key";
            leaf acle-fault-status-key {
                description "acle-fault-status name/key";
                type string;
            }
            leaf acle-fault-status-value {
                description "acle-fault-status value: can be empty/None";
                type string;
            }
        }
    }

    grouping hwvtep-acl-attributes {
        description "ACL attributes";
        leaf acl-name {
            description "Name of the ACL";
            type string;
        }
        leaf acl-uuid {
            description "The unique identifier of the acl";
            type yang:uuid;
        }
        list acl-entries {
            uses hwvtep-acl-entry-attributes;
        }
        list acl-fault-status {
            config false;
            key "acl-fault-status-key";
            leaf acl-fault-status-key {
                description "acl-fault-status name/key";
                type string;
            }
            leaf acl-fault-status-value {
                description "acl-fault-status value: can be empty/None";
                type hwvtep-acl-ref;
            }
        }
    }

    grouping hwvtep-logical-binding-stats-attributes {
        leaf logical-binding-stats-uuid {
            description "A unique identifier of the logical binding stats";
            type yang:uuid;
        }
        leaf packets-from-local {
            description "integer";
            type uint32;
        }
        leaf bytes-from-local {
            description "integer";
            type uint32;
        }
        leaf packets-to-local {
            description "integer";
            type uint32;
        }
        leaf bytes-to-local {
            description "integer";
            type uint32;
        }
    }

    augment "/topo:network-topology/topo:topology/topo:node" {
        description "Augmentation for physical switch nodes managed by hwvtep";
        ext:augment-identifier "physical-switch-augmentation";
        uses hwvtep-physical-switch-attributes;
    }

    augment "/topo:network-topology/topo:topology/topo:node" {
        description "Augment topology node for a hwvtep node";
        ext:augment-identifier "hwvtep-global-augmentation";
        uses hwvtep-global-attributes;
    }

    augment "/topo:network-topology/topo:topology/topo:node/topo:termination-point" {
        description "Augment topology node termination-point for a hwvtep physical-locator";
        ext:augment-identifier "hwvtep-physical-locator-augmentation";
        uses hwvtep-physical-locator-attributes;
    }

    augment "/topo:network-topology/topo:topology/topo:node/topo:termination-point" {
        description "Augment topology node termination-point for a hwvtep physical-port";
        ext:augment-identifier "hwvtep-physical-port-augmentation";
        uses hwvtep-physical-port-attributes;
    }
}