module overlay {
    yang-version 1;
    namespace "urn:opendaylight:params:xml:ns:yang:overlay";
    prefix "southbound";

    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; }

    revision "2015-01-05" {
        description "Initial revision of overlay model";
    }


    identity tunnel-type-base {
        description "Base identity for all tunnel-types";
    }

    identity tunnel-type-vxlan {
        description "Tunnel type for vxlan tunnels";
        base tunnel-type-base;
    }

    identity tunnel-type-vxlan-gpe {
        description "Tunnel type for vxlan tunnels";
        base tunnel-type-base;
    }

    identity tunnel-type-gre {
        description "Tunnel type for gre tunnels";
        base tunnel-type-base;
    }

    grouping ip-port-locator {
      description
        "Data plane-locator: IP address and L4 port";
      leaf ip {
        type inet:ip-address;
        description "Data-plane IP address";
      }
      leaf port {
        type inet:port-number;
        description "Data-plane port number";
      }
    }

    grouping tunnel-type-attributes {
        description "Common leaf for expressing tunnel-type";
        leaf tunnel-type {
            type identityref {
                base tunnel-type-base;
            }
        }
    }

    augment "/topo:network-topology/topo:topology/topo:node" {
        description "Augment topology node with a list of supported-tunnel-entries";
        ext:augment-identifier "supported-tunnels";
        list supported-tunnel-entry {
            uses tunnel-type-attributes;
        }
    }

    augment "/topo:network-topology/topo:topology/topo:node/supported-tunnel-entry" {
        description "Augment additional tunnel-parameters into the supported-tunnel-entry list";
        ext:augment-identifier "supported-tunnels-parameters";
        when "./tunnel-type = 'tunnel-type-gre' or
            ./tunnel-type = 'tunnel-type-vxlan' or 
            ./tunnel-type = 'tunnel-type-vxlan-gre'" {
            description "Augment tunnel types that use ip-port as tunnnel parameters";
        }
        list ip-port-locator-entry {
            uses ip-port-locator;
        }
    }

    augment "/topo:network-topology/topo:topology/topo:link" {
        description "Type of link tunnel";
        ext:augment-identifier "tunnel";
        uses tunnel-type-attributes;
    }
 
    augment "/topo:network-topology/topo:topology/topo:link/topo:source" {
        description "ip-port-locator for the source end of a tunnel link";
        ext:augment-identifier "tunnel-source-parameters";
        when "../tunnel-type = 'tunnel-type-gre' or
            ../tunnel-type = 'tunnel-type-vxlan' or 
            ../tunnel-type = 'tunnel-type-vxlan-gre'" {
            description "Augment tunnel types that use ip-port as tunnnel parameters";
        }
        uses ip-port-locator;
    }

    augment "/topo:network-topology/topo:topology/topo:link/topo:destination" {
        description "ip-port-locator for the source end of a tunnel link";
        ext:augment-identifier "tunnel-dest-parameters";
        when "../tunnel-type = 'tunnel-type-gre' or
            ../tunnel-type = 'tunnel-type-vxlan' or 
            ../tunnel-type = 'tunnel-type-vxlan-gre'" {
            description "Augment tunnel types that use ip-port as tunnnel parameters";
        }
        uses ip-port-locator;
    }

    identity topology-type-base {
        description "Base identity for all topology-types";
    }

    identity topology-type-overlay {
        description "Marker to indicate a topology is of type overlay";
        base topology-type-base;
    }

    grouping topology-type-attributes {
        description "Attributed to indicate the topology type";
        leaf topology-type {
            type identityref {
                base topology-type-base;
            }
        }
    }

    augment "/topo:network-topology/topo:topology/" {
        description "Mark type of topology";
        ext:augment-identifier "topology-type";
        uses topology-type-attributes; 
    }
}