// vi: set smarttab et sw=4 tabstop=4:
module pmsi-tunnel {
    yang-version 1;
    namespace "urn:opendaylight:params:xml:ns:yang:pmsi-tunnel";
    prefix "pmsi-tunnel";

    import bgp-types { prefix bgp-t; revision-date 2020-01-20; }
    import bgp-message { prefix bgp-msg; revision-date 2020-01-20; }
    import ietf-inet-types { prefix inet; revision-date 2013-07-15; }
    import network-concepts { prefix netc; revision-date 2013-11-25; }
    import ietf-yang-types { prefix yang; }
    import bgp-rib { prefix bgp-rib; revision-date 2018-03-29; }
    import yang-ext { prefix ext; revision-date 2013-07-09; }

    organization "AT&T Services, Inc.";

    contact "Bruce Brandon <bb2697@att.com>";

    description
        "This module contains the data model of a BGP attribute called the
        P-Multicast Service Interface Tunnel (PMSI Tunnel), defined
        in RFC6514, Section 5.

        Copyright (c)2016 AT&T Services, Inc. All rights reserved.;

        This program and the accompanying materials are made available
        under the terms of the Eclipse Public License v1.0 which
        accompanies this distribution, and is available at
        http://www.eclipse.org/legal/epl-v10.html";

    revision 2020-01-20 {
        description "Update to use -no-zone-adresses";
    }

    revision "2018-03-29" {
        description "Add RFC6514 Extended communities under bgp type.";
    }

    revision "2016-08-12" {
        description "Initial revision";
        reference "https://tools.ietf.org/html/rfc6514#section-5";
    }

    typedef pmsi-tunnel-type {
        type enumeration {
            enum rsvp-te-p2mp-lsp {
                value 1;
            }
            enum mldp-p2mp-lsp {
                value 2;
            }
            enum pim-ssm-tree {
                value 3;
            }
            enum pim-sm-tree {
                value 4;
            }
            enum bidir-pim-tree {
                value 5;
            }
            enum ingress-replication {
                value 6;
            }
            enum mldp-mp2mp-lsp {
                value 7;
            }
        }
    }

    grouping opaque {
        leaf opaque-type {
            mandatory true;
            type uint8;
        }
        leaf opaque-extended-type {
            type uint16;
        }
        leaf opaque {
            mandatory true;
            type yang:hex-string;
        }
    }

    grouping p-address-p-multicast-group {
        leaf p-address {
            mandatory true;
            type inet:ip-address-no-zone;
        }
        leaf p-multicast-group {
            mandatory true;
            type inet:ip-address-no-zone;
        }
    }

    grouping pmsi-tunnel {
        container pmsi-tunnel {
            presence "PMSI Attribute";
            description "P-Multicast Service Interface Tunnel (PMSI Tunnel) attribute";
            reference "https://tools.ietf.org/html/rfc6514#section-5";

            leaf leaf-information-required {
                type boolean;
                mandatory true;
            }
            leaf mpls-label {
                type netc:mpls-label;
            }
            choice tunnel-identifier {
                case rsvp-te-p2mp-lsp {
                    container rsvp-te-p2mp-lsp {
                        reference "https://tools.ietf.org/html/rfc4875#section-19.1.1";
                        leaf p2mp-id {
                            mandatory true;
                            type uint32;
                        }
                        leaf tunnel-id {
                            mandatory true;
                            type uint16;
                        }
                        leaf extended-tunnel-id {
                            mandatory true;
                            type inet:ip-address-no-zone;
                        }
                    }
                }
                case mldp-p2mp-lsp {
                    container mldp-p2mp-lsp {
                        reference "https://tools.ietf.org/html/rfc6388#section-2.2";
                        leaf address-family {
                            mandatory true;
                            type identityref {
                                base bgp-t:address-family;
                            }
                        }
                        leaf root-node-address {
                            mandatory true;
                            type inet:ip-address-no-zone;
                        }
                        list opaque-value {
                            uses opaque;
                        }
                    }
                }
                case pim-ssm-tree {
                    container pim-ssm-tree {
                        reference "https://tools.ietf.org/html/rfc6514#section-5";
                        uses p-address-p-multicast-group;
                    }
                }
                case pim-sm-tree {
                    container pim-sm-tree {
                        reference "https://tools.ietf.org/html/rfc6514#section-5";
                        uses p-address-p-multicast-group;
                    }
                }
                case bidir-pim-tree {
                    container bidir-pim-tree {
                        reference "https://tools.ietf.org/html/rfc6514#section-5";
                        uses p-address-p-multicast-group;
                    }
                }
                case ingress-replication {
                    container ingress-replication {
                        leaf receiving-endpoint-address {
                            type inet:ip-address-no-zone;
                        }
                    }
                }
                case mldp-mp2mp-lsp {
                    container mldp-mp2mp-lsp {
                        uses opaque;
                    }
                }
            }
        }
    }

    augment "/bgp-msg:update/bgp-msg:attributes" {
        uses pmsi-tunnel;
    }

    grouping bgp-rib-route {
        uses bgp-rib:route {
            augment "attributes" {
                ext:augment-identifier pmsi-tunnel-augmentation;
                uses pmsi-tunnel;
            }
        }
    }
}