module ietf-te-service-mapping {

    namespace "urn:ietf:params:xml:ns:yang:ietf-te-service-mapping";

    prefix "tm";

    import ietf-l3vpn-svc {
        prefix "l3";
    }

    import ietf-l2vpn-svc {
        prefix "l2";
    }

    import ietf-l1csm {
        prefix "l1";
    }

    import ietf-te-types {
        prefix "te-types";
    }

    import ietf-network {
        prefix "nw";
    }

    import ietf-te {
        prefix "te";
    }

    import ietf-actn-vn {
        prefix "vn";
    }

    organization
        "IETF Traffic Engineering Architecture and Signaling (TEAS)
        Working Group";

    contact
        "Editor: Young Lee <leeyoung@huawei.com>
                 Dhruv Dhody <dhruv.ietf@gmail.com>";
    description
        "This module contains a YANG module for the mapping of
        service (e.g. L3VPN) to the TE tunnels or ACTN VN.";
    revision 2018-04-05 {
        description
            "initial version.";
        reference
            "TBD";
    }

    /*
     * Identities
     */
    identity service-type {
        description
            "Base identity from which specific service types are
            derived.";
    }

    identity l3vpn-service {
        base service-type;
        description
            "L3VPN service type.";
    }

    identity l2vpn-service {
        base service-type;
        description
            "L2VPN service type.";
    }

    identity l1vpn-service {
        base service-type;
        description
            "L1VPN connectivity service type.";
    }
    /*
     * Enum
     */
    typedef map-type {
        type enumeration {
            enum "new" {
                description
                    "The new VN/tunnels are binded to the service";
            }
            enum "select" {
                description
                    "The VPN service selects an existing tunnel with no
modification";
               }
               enum "modify" {
                   description
                       "The VPN service selects an existing tunnel and allows
to modify the properties of the tunnel (e.g., b/w) ";
                  }
           }
           description
               "The map-type";
       }

       /*
        * Groupings
        */
       grouping service-ref{
           description
               "The reference to the service.";
            choice service {
               description
                   "The service";
               case l3vpn {
                   leaf l3vpn-ref {
                       type leafref {
                           path "/l3:l3vpn-svc/l3:vpn-services/"
                           + "l3:vpn-service/l3:vpn-id";
                       }
                       description
                           "The reference to L3VPN Service Yang Model";
                   }
               }
               case l2vpn {
                   leaf l2vpn-ref {
                       type leafref {
                           path "/l2:l2vpn-svc/l2:vpn-services/"
                           + "l2:vpn-service/l2:vpn-id";
                       }
                       description
                           "The reference to L2VPN Service Yang Model";
                   }

               }
               case l1vpn {
                   leaf l1vpn-ref {
                       type leafref {
                           path "/l1:l1cs/l1:service/"
                           + "l1:service-list/l1:subscriber-l1vc-id";
                       }
                       description
                           "The reference to L1VPN Service Yang Model";
                   }

               }
            }
       }

       grouping site-ref {
           description
               "The reference to the site.";
            choice service {
               description
                   "The service choice";
               case l3vpn {
                   leaf l3vpn-ref{
                       type leafref {
                           path "/l3:l3vpn-svc/l3:sites/l3:site/"
                           + "l3:site-id";
                       }
                       description
                           "The reference to L3VPN Service Yang Model";
                   }
               }
               case l2vpn {
                   leaf l2vpn-ref{
                       type leafref {
                           path "/l2:l2vpn-svc/l2:sites/l2:site/"
                           + "l2:site-id";
                       }
                       description
                           "The reference to L2VPN Service Yang Model";
                   }

               }
               case l1vpn {
                   leaf l1vpn-ref{
                       type leafref {
                           path "/l1:l1cs/l1:access/l1:uni-list/"
                           + "l1:UNI-ID";
                       }
                       description
                           "The reference to L1VPN Connectivity Service Yang
Model";
                   }

               }

            }
       }

       grouping te-ref {
           description
               "The reference to TE.";
           choice te {
               description
                   "The TE";
               case actn-vn {
                   leaf actn-vn-ref {
                       type leafref {
                           path "/vn:actn/vn:vn/vn:vn-list/vn:vn-id";
                       }
                       description
                           "The reference to ACTN VN";
                   }
               }
               case te-topo {
                  leaf vn-topology-id{
                      type te-types:te-topology-id;
                      description
                          "An identifier to the TE Topology Model
                           where the abstract nodes and links of
                           the Topology can be found for Type 2
                           VNS";
                  }
                  leaf abstract-node {
                    type leafref {
                      path "/nw:networks/nw:network/nw:node/"
                      + "nw:node-id";
                    }
                    description
                      "a reference to the abstract node in TE
                      Topology";
                  }
               }
               case te-tunnel {
                   leaf-list te-tunnel-list {
                       type te:tunnel-ref;
                       description
                           "Reference to TE Tunnels";
                   }

               }

           }

       }

       grouping te-endpoint-ref {
           description
               "The reference to TE endpoints.";
           choice te {
               description
                   "The TE";
               case actn-vn {
                   leaf actn-vn-ref {
                       type leafref {
                           path "/vn:actn/vn:ap/vn:access-point-list"
                           + "/vn:access-point-id";
                       }
                       description
                           "The reference to ACTN VN";
                   }
               }
               case te {
                  leaf ltp {
                      type te-types:te-tp-id;
                      description
                          "Reference LTP in the TE-topology";
                  }
               }
           }

       }

       grouping service-mapping {
           description
               "Mapping between Services and TE";
           container service-mapping {
               description
                   "Mapping between Services and TE";
               list mapping-list {
                   key "map-id";
                   description
                       "Mapping identified via a map-id";
                   leaf map-id {
                       type uint32;
                       description
                           "a unique mapping identifier";
                   }
                   leaf map-type {
                       type map-type;
                       description
                           "Tunnel Bind or Tunnel Selection";
                   }
                   uses service-ref;

                   uses te-ref;
               }
           }
       }
       grouping site-mapping {
           description
               "Mapping between VPN access site and TE
               endpoints or AP";
           container site-mapping {
               description
                   "Mapping between VPN access site and TE
                   endpoints or AP";
               list mapping-list {
                   key "map-id";
                   description
                       "Mapping identified via a map-id";
                   leaf map-id {
                       type uint32;
                       description
                           "a unique mapping identifier";
                   }
                   uses site-ref;

                   uses te-endpoint-ref;
               }

           }
       }
       /*
        * Configuration data nodes
        */
       container te-service-mapping {
           description
               "Mapping between Services and TE";

           uses service-mapping;

           uses site-mapping;
       }

   }
