[ONOS-4842] Leafref implementation for augment and uses
Change-Id: I919553a64d683aff65a8f16e2de783702dd5a45f
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/iffeatuinleafref/featurebymultileafref/SelfFileLinkingWithFeatureReferredByMultiLeafref.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/iffeatuinleafref/featurebymultileafref/SelfFileLinkingWithFeatureReferredByMultiLeafref.yang
new file mode 100644
index 0000000..f57fa6b
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/iffeatuinleafref/featurebymultileafref/SelfFileLinkingWithFeatureReferredByMultiLeafref.yang
@@ -0,0 +1,40 @@
+module syslog {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix "sys";
+    feature local-storage {
+        description
+            "This feature means the device supports local
+             storage (memory, flash or disk) that can be used to
+             store syslog messages.";
+    }
+    feature main-storage {
+        description
+            "This feature means the device supports main
+             storage that can be used to
+             store syslog messages.";
+    }
+
+    container speed {
+        leaf local-storage-limit {
+             if-feature local-storage;
+             type leafref {
+                 path "/value";
+             }
+             units "kilobyte";
+             config false;
+             description
+                  "The amount of local storage that can be
+                   used to hold syslog messages.";
+        }
+    }
+    leaf storage-value {
+        type leafref {
+            path "/speed/local-storage-limit";
+        }
+    }
+    leaf value {
+        if-feature main-storage;
+        type uint64;
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/iffeatuinleafref/simpleleafrefwithiffeature/SelfFileLinkingWithFeatureReferredByLeafref.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/iffeatuinleafref/simpleleafrefwithiffeature/SelfFileLinkingWithFeatureReferredByLeafref.yang
new file mode 100644
index 0000000..941b56b
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/iffeatuinleafref/simpleleafrefwithiffeature/SelfFileLinkingWithFeatureReferredByLeafref.yang
@@ -0,0 +1,28 @@
+module syslog {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix "sys";
+    feature local-storage {
+        description
+            "This feature means the device supports local
+             storage (memory, flash or disk) that can be used to
+             store syslog messages.";
+    }
+
+    container speed {
+        leaf local-storage-limit {
+             if-feature local-storage;
+             type uint64;
+             units "kilobyte";
+             config false;
+             description
+                  "The amount of local storage that can be
+                   used to hold syslog messages.";
+         }
+     }
+     leaf storage-value {
+         type leafref {
+             path "/speed/local-storage-limit";
+         }
+     }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile/module1.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile/module1.yang
new file mode 100644
index 0000000..b8a5d98
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile/module1.yang
@@ -0,0 +1,28 @@
+module module1 {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
+    prefix "tet";
+    import module2 {
+        prefix "nt";
+    }
+    container te-node-tunnel-termination-capability {
+        description
+        "Termination capability of a tunnel termination point on a
+        TE node.";
+        list termination-capability {
+            key "link-tp";
+            description
+            "The termination capabilities between
+            tunnel-termination-point and link termination-point.
+            The capability information can be used to compute
+            the tunnel path.";
+            leaf link-tp {
+                type leafref {
+                    path "/nt:termination-point/nt:tp-id";
+                }
+                description
+                "Link termination point.";
+            }
+        } // termination-capability
+    } // te-node-tunnel-termination-capability
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile/module2.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile/module2.yang
new file mode 100644
index 0000000..822d90b
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile/module2.yang
@@ -0,0 +1,11 @@
+module module2 {
+    yang-version 1;
+    namespace
+      "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+    prefix inet;
+    container termination-point {
+        leaf tp-id {
+            type string;
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ieft-inet-types.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ieft-inet-types.yang
new file mode 100644
index 0000000..c393dbf
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ieft-inet-types.yang
@@ -0,0 +1,11 @@
+module ietf-inet-types {
+    yang-version 1;
+    namespace
+      "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+    prefix inet;
+    typedef tp-ref {
+        type leafref {
+            path "/nwtp:value";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ietf-network-topology.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ietf-network-topology.yang
new file mode 100644
index 0000000..b488f46
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ietf-network-topology.yang
@@ -0,0 +1,28 @@
+module ietf-network-topology {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-te-topology";
+    prefix "tet";
+    import ietf-network {
+        prefix "nt";
+    }
+    container te-node-tunnel-termination-capability {
+        description
+        "Termination capability of a tunnel termination point on a
+        TE node.";
+        list termination-capability {
+            key "link-tp";
+            description
+            "The termination capabilities between
+            tunnel-termination-point and link termination-point.
+            The capability information can be used to compute
+            the tunnel path.";
+            leaf link-tp {
+                type leafref {
+                    path "/nt:termination-point/nt:tp-id";
+                }
+                description
+                "Link termination point.";
+            }
+        } // termination-capability
+    } // te-node-tunnel-termination-capability
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ietf-network.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ietf-network.yang
new file mode 100644
index 0000000..49a6a04
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefreferstomultipleleafrefinmultiplefiles/ietf-network.yang
@@ -0,0 +1,14 @@
+module ietf-network {
+    yang-version 1;
+    namespace
+      "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+    prefix nw;
+    import ietf-inet-types {
+       prefix inet;
+    }
+    container termination-point {
+        leaf tp-id {
+            type string;
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefwithimport/module1.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefwithimport/module1.yang
new file mode 100644
index 0000000..d33cf1e
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefwithimport/module1.yang
@@ -0,0 +1,16 @@
+module module1 {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    import module2 {
+        prefix p;
+    }
+    leaf invalid-interval {
+        type leafref {
+            path "/p:hello";
+        }
+    }
+    leaf hello {
+        type string;
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefwithimport/module2.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefwithimport/module2.yang
new file mode 100644
index 0000000..28a869b
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/interfileleafrefwithimport/module2.yang
@@ -0,0 +1,8 @@
+module module2 {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant2;
+    leaf hello {
+        type string;
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix/GroupingCopiedInModule2.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix/GroupingCopiedInModule2.yang
new file mode 100644
index 0000000..dae2db2
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix/GroupingCopiedInModule2.yang
@@ -0,0 +1,12 @@
+module GroupingCopiedInModule2 {
+    yang-version 1;
+    namespace "onos-yang-19:level1:newlevel";
+    prefix test;
+    import LeafrefInGroupingOfModule1 {
+        prefix module1;
+    }
+    description "leaf scenario";
+    container value {
+        uses "module1:network-ref";
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix/LeafrefInGroupingOfModule1.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix/LeafrefInGroupingOfModule1.yang
new file mode 100644
index 0000000..0753619
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix/LeafrefInGroupingOfModule1.yang
@@ -0,0 +1,40 @@
+module LeafrefInGroupingOfModule1 {
+    yang-version 1;
+    namespace "onos-yang-19:level1:newlevel";
+    prefix test2;
+    description "leaf scenario";
+    container networks {
+        list network {
+            key "network-id";
+            description
+                "Describes a network.
+                A network typically contains an inventory of nodes,
+                topological information (augmented through
+                network-topology model), as well as layering
+                information.";
+            container network-types {
+                description
+                    "Serves as an augmentation target.
+                    The network type is indicated through corresponding
+                    presence containers augmented into this container.";
+            }
+            leaf network-id {
+                type string;
+                description
+                "Identifies a network.";
+            }
+        }
+        leaf network-ip {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    grouping network-ref {
+        leaf network-ref {
+            type leafref {
+                path "/test2:networks/test2:network/test2:network-id";
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference/GroupingCopiedInModule2.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference/GroupingCopiedInModule2.yang
new file mode 100644
index 0000000..d988a3a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference/GroupingCopiedInModule2.yang
@@ -0,0 +1,37 @@
+module ietf-te-topology {
+    yang-version 1;
+    namespace "onos-yang-19:level1:newlevel";
+    prefix test;
+     import ietf-network {
+       prefix "nw";
+     }
+    description "leaf scenario";
+         typedef te-topology-event-type {
+           type enumeration {
+             enum "add" {
+               value 0;
+               description
+                 "A TE node or te-link has been added.";
+             }
+             enum "remove" {
+               value 1;
+               description
+                 "A TE node or te-link has been removed.";
+             }
+             enum "update" {
+               value 2;
+               description
+                 "A TE node or te-link has been updated.";
+             }
+           }
+           description "TE  Event type for notifications";
+         } // te-topology-event-type
+     container te-node-event {
+       leaf event-type {
+         type te-topology-event-type;
+         description "Event type.";
+       }
+       description "Notification event for TE node.";
+       uses nw:node-ref;
+     }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference/LeafrefInGroupingOfModule1.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference/LeafrefInGroupingOfModule1.yang
new file mode 100644
index 0000000..f2b7591
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference/LeafrefInGroupingOfModule1.yang
@@ -0,0 +1,212 @@
+   module ietf-network {
+     yang-version 1;
+     namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+     prefix nd;
+
+     organization
+       "IETF I2RS (Interface to the Routing System) Working Group";
+
+     contact
+       "WG Web:    <http://tools.ietf.org/wg/i2rs/>
+        WG List:   <mailto:i2rs@ietf.org>
+
+        WG Chair:  Susan Hares
+                   <mailto:shares@ndzh.com>
+
+        WG Chair:  Jeffrey Haas
+                   <mailto:jhaas@pfrc.org>
+
+        Editor:    Alexander Clemm
+                   <mailto:alex@cisco.com>
+
+        Editor:    Jan Medved
+                   <mailto:jmedved@cisco.com>
+
+        Editor:    Robert Varga
+                   <mailto:rovarga@cisco.com>
+
+        Editor:    Tony Tkacik
+                   <mailto:ttkacik@cisco.com>
+
+        Editor:    Nitin Bahadur
+                   <mailto:nitin_bahadur@yahoo.com>
+
+        Editor:    Hariharan Ananthakrishnan
+                   <mailto:hari@packetdesign.com>";
+
+     description
+       "This module defines a common base model for a collection
+        of nodes in a network. Node definitions are further used
+        in network topologies and inventories.
+
+        Copyright (c) 2015 IETF Trust and the persons identified as
+        authors of the code.  All rights reserved.
+
+        Redistribution and use in source and binary forms, with or
+        without modification, is permitted pursuant to, and subject
+        to the license terms contained in, the Simplified BSD License
+        set forth in Section 4.c of the IETF Trust's Legal Provisions
+        Relating to IETF Documents
+        (http://trustee.ietf.org/license-info).
+
+        This version of this YANG module is part of
+        draft-ietf-i2rs-yang-network-topo-02;
+        see the RFC itself for full legal notices.
+
+        NOTE TO RFC EDITOR: Please replace above reference to
+        draft-ietf-i2rs-yang-network-topo-02 with RFC
+        number when published (i.e. RFC xxxx).";
+
+     revision 2015-12-08 {
+       description
+         "Initial revision.
+          NOTE TO RFC EDITOR: Please replace the following reference
+          to draft-ietf-i2rs-yang-network-topo-02 with
+          RFC number when published (i.e. RFC xxxx).";
+       reference
+         "draft-ietf-i2rs-yang-network-topo-02";
+     }
+
+     typedef node-id {
+       type string;
+       description
+         "Identifier for a node.";
+     }
+
+     typedef network-id {
+       type string;
+       description
+         "Identifier for a network.";
+     }
+     grouping network-ref {
+       description
+         "Contains the information necessary to reference a network,
+          for example an underlay network.";
+       leaf network-ref {
+         type leafref {
+           path "/nd:networks/nd:network/nd:network-id";
+         require-instance false;
+         }
+         description
+           "Used to reference a network, for example an underlay
+            network.";
+       }
+     }
+
+     grouping node-ref {
+       description
+         "Contains the information necessary to reference a node.";
+       leaf node-ref {
+         type leafref {
+           path "/nd:networks/nd:network[nd:network-id=current()/../"+
+             "network-ref]/nd:node/nd:node-id";
+           require-instance false;
+         }
+         description
+           "Used to reference a node.
+            Nodes are identified relative to the network they are
+            contained in.";
+       }
+       uses network-ref;
+     }
+
+     container networks {
+       description
+         "Serves as top-level container for a list of networks.";
+       list network {
+         key "network-id";
+         description
+           "Describes a network.
+            A network typically contains an inventory of nodes,
+            topological information (augmented through
+            network-topology model), as well as layering
+            information.";
+         container network-types {
+           description
+             "Serves as an augmentation target.
+              The network type is indicated through corresponding
+              presence containers augmented into this container.";
+         }
+         leaf network-id {
+           type network-id;
+           description
+             "Identifies a network.";
+         }
+         list supporting-network {
+           key "network-ref";
+           description
+             "An underlay network, used to represent layered network
+              topologies.";
+           leaf network-ref {
+             type leafref {
+               path "/networks/network/network-id";
+             require-instance false;
+             }
+             description
+               "References the underlay network.";
+           }
+         }
+         list node {
+           key "node-id";
+           description
+             "The inventory of nodes of this network.";
+           leaf node-id {
+             type node-id;
+             description
+               "Identifies a node uniquely within the containing
+                network.";
+           }
+           list supporting-node {
+             key "network-ref node-ref";
+             description
+               "Represents another node, in an underlay network, that
+                this node is supported by.  Used to represent layering
+                structure.";
+             leaf network-ref {
+               type leafref {
+                 path "../../../supporting-network/network-ref";
+               require-instance false;
+               }
+               description
+                 "References the underlay network that the
+                  underlay node is part of.";
+             }
+             leaf node-ref {
+               type leafref {
+                 path "/networks/network/node/node-id";
+               require-instance false;
+               }
+               description
+                 "References the underlay node itself.";
+             }
+           }
+         }
+       }
+     }
+     container networks-state {
+       config false;
+       description
+         "Serves as top-level container for a list of state information
+          for networks";
+       list network {
+         key "network-ref";
+         description
+           "Data nodes representing operational data and state of
+            networks.
+            An instance is automatically created for every network
+            in the corresponding list under the networks container.";
+         uses network-ref;
+         leaf server-provided {
+           type boolean;
+           description
+             "Indicates whether the information concerning this
+              particular network is populated by the server
+              (server-provided true, the general case for network
+              information discovered from the server),
+              or whether it is configured by a client
+              (server-provided true, possible e.g. for
+              service overlays managed through a controller).";
+         }
+       }
+     }
+   }
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidscenerioforgrouping/SelfResolutionWhenLeafrefInModuleReferToGroupingInModule.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidscenerioforgrouping/SelfResolutionWhenLeafrefInModuleReferToGroupingInModule.yang
new file mode 100644
index 0000000..a0bd03b
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidscenerioforgrouping/SelfResolutionWhenLeafrefInModuleReferToGroupingInModule.yang
@@ -0,0 +1,19 @@
+module SelfResolutionWhenLeafrefInModuleReferToGroupingInModule {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    grouping networks {
+        leaf network-id {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    container current {
+        leaf network-ref {
+            type leafref {
+            path "/networks/network-id";
+            }
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidsceneriowithinvalidnode/SelfResolutionWhenLeafrefInModuleReferToInvalidNode.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidsceneriowithinvalidnode/SelfResolutionWhenLeafrefInModuleReferToInvalidNode.yang
new file mode 100644
index 0000000..c10ba2b
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidsceneriowithinvalidnode/SelfResolutionWhenLeafrefInModuleReferToInvalidNode.yang
@@ -0,0 +1,19 @@
+module SelfResolutionWhenLeafrefInModuleReferToInvalidNode {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    leaf network-ref {
+            type leafref {
+            path "/define/network-id";
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidsceneriowithnorefleaf/SelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidsceneriowithnorefleaf/SelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList.yang
new file mode 100644
index 0000000..e5de10b
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/invalidsceneriowithnorefleaf/SelfResolutionWhenLeafrefDoesNotReferToLeafOrLeafList.yang
@@ -0,0 +1,22 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type status;
+            description
+            "Identifies a network.";
+        }
+    }
+    typedef status {
+        type uint8;
+    }
+    leaf network-ref {
+        type leafref {
+            path "/networks";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefInAugment/SelfResolutionIfLeafrefInGroupingIsCopiedToAugment.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefInAugment/SelfResolutionIfLeafrefInGroupingIsCopiedToAugment.yang
new file mode 100644
index 0000000..a208903
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefInAugment/SelfResolutionIfLeafrefInGroupingIsCopiedToAugment.yang
@@ -0,0 +1,64 @@
+module topology {
+    yang-version 1;
+    namespace "onos-yang-19:level1:newlevel";
+    prefix test;
+    organization "huawei";
+    contact "adarsh.m@huawei.com";
+    description "leaf scenario";
+    container networks {
+        list network {
+            key "network-id";
+            description
+                "Describes a network.
+                A network typically contains an inventory of nodes,
+                topological information (augmented through
+                network-topology model), as well as layering
+                information.";
+            container network-types {
+                description
+                    "Serves as an augmentation target.
+                    The network type is indicated through corresponding
+                    presence containers augmented into this container.";
+            }
+            leaf network-id {
+                type string;
+                description
+                "Identifies a network.";
+            }
+        }
+        leaf network-ip {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    augment "/networks/network" {
+        container config {
+            description
+                "Configuration data.";
+            choice bundle-stack-level {
+                description
+                    "The TE link can be partitioned into bundled
+                    links, or component links.";
+                case bundle {
+                    container bundled-links {
+                        description
+                            "A set of bundled links.";
+                        reference
+                            "RFC4201: Link Bundling in MPLS Traffic Engineering
+                            (TE).";
+                        list bundled-link {
+                            key "src-tp-ref";
+                            leaf src-tp-ref {
+                                type leafref {
+                                    path "../../../../../network-ip";
+                                    require-instance true;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefingroupingonly/SelfResolutionWithLeafrefInGrouping.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefingroupingonly/SelfResolutionWithLeafrefInGrouping.yang
new file mode 100644
index 0000000..80b6ab0
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefingroupingonly/SelfResolutionWithLeafrefInGrouping.yang
@@ -0,0 +1,37 @@
+module ietf-network {
+     yang-version 1;
+     namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+     prefix nd;
+
+     import ietf-inet-types {
+       prefix inet;
+     }
+     typedef node-id {
+       type inet:uri;
+       description
+         "Identifier for a node.";
+     }
+
+     leaf xyz {
+         type string;
+     }
+     typedef network-id {
+       type inet:uri;
+       description
+         "Identifier for a network.";
+     }
+     grouping network-ref {
+       description
+         "Contains the information necessary to reference a network,
+          for example an underlay network.";
+       leaf network-ref {
+         type leafref {
+           path "/nd:xyz";
+         require-instance false;
+         }
+         description
+           "Used to reference a network, for example an underlay
+            network.";
+       }
+     }
+   }
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefintypedef/SelfResolutionWhenLeafrefInTypedefReferToContainer.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefintypedef/SelfResolutionWhenLeafrefInTypedefReferToContainer.yang
new file mode 100644
index 0000000..ae42100
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefintypedef/SelfResolutionWhenLeafrefInTypedefReferToContainer.yang
@@ -0,0 +1,22 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type network-ref;
+            description
+            "Identifies a network.";
+        }
+        leaf id {
+            type uint8;
+        }
+    }
+    typedef network-ref {
+        type leafref {
+            path "/networks/id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping/ietf-network.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping/ietf-network.yang
new file mode 100644
index 0000000..4eaa2bf
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping/ietf-network.yang
@@ -0,0 +1,33 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    import network {
+       prefix "nw";
+    }
+    grouping xyz {
+        leaf network-id-ref {
+            type leafref {
+                path "/nw:networks/nw:network/nw:network-id";
+                require-instance false;
+            }
+            description
+                "A reference to a network-id in base ietf-network module.";
+        }
+    }
+    grouping yzx {
+        container hi {
+        uses xyz;
+        }
+    }
+    container fine {
+        uses yzx;
+    }
+    container networks {
+        leaf network {
+            type string;
+        }
+    }
+}
+
+
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping/network.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping/network.yang
new file mode 100644
index 0000000..30e8b80
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping/network.yang
@@ -0,0 +1,212 @@
+   module network {
+     yang-version 1;
+     namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+     prefix nd;
+
+     organization
+       "IETF I2RS (Interface to the Routing System) Working Group";
+
+     contact
+       "WG Web:    <http://tools.ietf.org/wg/i2rs/>
+        WG List:   <mailto:i2rs@ietf.org>
+
+        WG Chair:  Susan Hares
+                   <mailto:shares@ndzh.com>
+
+        WG Chair:  Jeffrey Haas
+                   <mailto:jhaas@pfrc.org>
+
+        Editor:    Alexander Clemm
+                   <mailto:alex@cisco.com>
+
+        Editor:    Jan Medved
+                   <mailto:jmedved@cisco.com>
+
+        Editor:    Robert Varga
+                   <mailto:rovarga@cisco.com>
+
+        Editor:    Tony Tkacik
+                   <mailto:ttkacik@cisco.com>
+
+        Editor:    Nitin Bahadur
+                   <mailto:nitin_bahadur@yahoo.com>
+
+        Editor:    Hariharan Ananthakrishnan
+                   <mailto:hari@packetdesign.com>";
+
+     description
+       "This module defines a common base model for a collection
+        of nodes in a network. Node definitions are further used
+        in network topologies and inventories.
+
+        Copyright (c) 2015 IETF Trust and the persons identified as
+        authors of the code.  All rights reserved.
+
+        Redistribution and use in source and binary forms, with or
+        without modification, is permitted pursuant to, and subject
+        to the license terms contained in, the Simplified BSD License
+        set forth in Section 4.c of the IETF Trust's Legal Provisions
+        Relating to IETF Documents
+        (http://trustee.ietf.org/license-info).
+
+        This version of this YANG module is part of
+        draft-ietf-i2rs-yang-network-topo-02;
+        see the RFC itself for full legal notices.
+
+        NOTE TO RFC EDITOR: Please replace above reference to
+        draft-ietf-i2rs-yang-network-topo-02 with RFC
+        number when published (i.e. RFC xxxx).";
+
+     revision 2015-12-08 {
+       description
+         "Initial revision.
+          NOTE TO RFC EDITOR: Please replace the following reference
+          to draft-ietf-i2rs-yang-network-topo-02 with
+          RFC number when published (i.e. RFC xxxx).";
+       reference
+         "draft-ietf-i2rs-yang-network-topo-02";
+     }
+
+     typedef node-id {
+       type string;
+       description
+         "Identifier for a node.";
+     }
+
+     typedef network-id {
+       type string;
+       description
+         "Identifier for a network.";
+     }
+     grouping network-ref {
+       description
+         "Contains the information necessary to reference a network,
+          for example an underlay network.";
+       leaf network-ref {
+         type leafref {
+           path "/nd:networks/nd:network/nd:network-id";
+         require-instance false;
+         }
+         description
+           "Used to reference a network, for example an underlay
+            network.";
+       }
+     }
+
+     grouping node-ref {
+       description
+         "Contains the information necessary to reference a node.";
+       leaf node-ref {
+         type leafref {
+           path "/nd:networks/nd:network[nd:network-id=current()/../"+
+             "network-ref]/nd:node/nd:node-id";
+           require-instance false;
+         }
+         description
+           "Used to reference a node.
+            Nodes are identified relative to the network they are
+            contained in.";
+       }
+       uses network-ref;
+     }
+
+     container networks {
+       description
+         "Serves as top-level container for a list of networks.";
+       list network {
+         key "network-id";
+         description
+           "Describes a network.
+            A network typically contains an inventory of nodes,
+            topological information (augmented through
+            network-topology model), as well as layering
+            information.";
+         container network-types {
+           description
+             "Serves as an augmentation target.
+              The network type is indicated through corresponding
+              presence containers augmented into this container.";
+         }
+         leaf network-id {
+           type network-id;
+           description
+             "Identifies a network.";
+         }
+         list supporting-network {
+           key "network-ref";
+           description
+             "An underlay network, used to represent layered network
+              topologies.";
+           leaf network-ref {
+             type leafref {
+               path "/networks/network/network-id";
+             require-instance false;
+             }
+             description
+               "References the underlay network.";
+           }
+         }
+         list node {
+           key "node-id";
+           description
+             "The inventory of nodes of this network.";
+           leaf node-id {
+             type node-id;
+             description
+               "Identifies a node uniquely within the containing
+                network.";
+           }
+           list supporting-node {
+             key "network-ref node-ref";
+             description
+               "Represents another node, in an underlay network, that
+                this node is supported by.  Used to represent layering
+                structure.";
+             leaf network-ref {
+               type leafref {
+                 path "../../../supporting-network/network-ref";
+               require-instance false;
+               }
+               description
+                 "References the underlay network that the
+                  underlay node is part of.";
+             }
+             leaf node-ref {
+               type leafref {
+                 path "/networks/network/node/node-id";
+               require-instance false;
+               }
+               description
+                 "References the underlay node itself.";
+             }
+           }
+         }
+       }
+     }
+     container networks-state {
+       config false;
+       description
+         "Serves as top-level container for a list of state information
+          for networks";
+       list network {
+         key "network-ref";
+         description
+           "Data nodes representing operational data and state of
+            networks.
+            An instance is automatically created for every network
+            in the corresponding list under the networks container.";
+         uses network-ref;
+         leaf server-provided {
+           type boolean;
+           description
+             "Indicates whether the information concerning this
+              particular network is populated by the server
+              (server-provided true, the general case for network
+              information discovered from the server),
+              or whether it is configured by a client
+              (server-provided true, possible e.g. for
+              service overlays managed through a controller).";
+         }
+       }
+     }
+   }
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreflinking/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreflinking/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion.yang
new file mode 100644
index 0000000..edf6bfa
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreflinking/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafIsInModuleWithReferredTypeUnion.yang
@@ -0,0 +1,28 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            container present {
+                leaf name {
+                    type leafref {
+                        path "/invalid-interval";
+                    }
+                }
+            }
+        }
+    }
+    leaf invalid-interval {
+        type union {
+            type int32;
+            type enumeration {
+                enum "unbounded";
+            }
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefreferingtoleaflist/SelfResolutionWhenLeafrefReferToContainerLeafList.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefreferingtoleaflist/SelfResolutionWhenLeafrefReferToContainerLeafList.yang
new file mode 100644
index 0000000..ec9a6d3
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefreferingtoleaflist/SelfResolutionWhenLeafrefReferToContainerLeafList.yang
@@ -0,0 +1,19 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    leaf-list network-ref {
+        type leafref {
+        path "/networks/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoderivedtype/SelfResolutionWhenLeafrefReferToAnotherDerivedType.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoderivedtype/SelfResolutionWhenLeafrefReferToAnotherDerivedType.yang
new file mode 100644
index 0000000..eb2668e
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoderivedtype/SelfResolutionWhenLeafrefReferToAnotherDerivedType.yang
@@ -0,0 +1,22 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type status;
+            description
+            "Identifies a network.";
+        }
+    }
+    typedef status {
+        type uint8;
+    }
+    leaf network-ref {
+        type leafref {
+            path "/networks/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoinputinrpc/SelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoinputinrpc/SelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc.yang
new file mode 100644
index 0000000..917c434
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoinputinrpc/SelfResolutionWhenLeafrefInModuleReferToLeafListInInputOfRpc.yang
@@ -0,0 +1,23 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    rpc networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        input {
+            leaf-list network-id {
+                type uint8;
+                description
+                "Identifies a network.";
+            }
+        }
+        output {
+        }
+    }
+    leaf-list network-ref {
+        type leafref {
+        path "/networks/input/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoleafref/SelfResolutionWhenLeafrefReferToAnotherLeafref.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoleafref/SelfResolutionWhenLeafrefReferToAnotherLeafref.yang
new file mode 100644
index 0000000..26ccd1f
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoleafref/SelfResolutionWhenLeafrefReferToAnotherLeafref.yang
@@ -0,0 +1,26 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type leafref {
+                path "/status/current";
+            }
+            description
+            "Identifies a network.";
+        }
+    }
+    container status {
+        leaf current {
+            type uint8;
+        }
+    }
+    leaf network-ref {
+        type leafref {
+            path "/networks/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoleafrefwithtypedef/SelfResolutionWhenLeafrefInTypedefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoleafrefwithtypedef/SelfResolutionWhenLeafrefInTypedefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang
new file mode 100644
index 0000000..b61be6a
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftoleafrefwithtypedef/SelfResolutionWhenLeafrefInTypedefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang
@@ -0,0 +1,33 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            typedef node {
+                type leafref {
+                    path "/invalid-interval";
+                }
+            }
+            container present {
+                typedef name {
+                    type node;
+                }
+                leaf interval {
+                    type name;
+                }
+            }
+        }
+    }
+    leaf-list invalid-interval {
+        type enumeration {
+            enum 10m;
+            enum 100m;
+            enum auto;
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftomultileafref/SelfResolutionWhenLeafrefReferToMultipleLeafref.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftomultileafref/SelfResolutionWhenLeafrefReferToMultipleLeafref.yang
new file mode 100644
index 0000000..fd75d32
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftomultileafref/SelfResolutionWhenLeafrefReferToMultipleLeafref.yang
@@ -0,0 +1,50 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            container present {
+                leaf-list name {
+                    type leafref {
+                        path "/transmitter/send";
+                    }
+                }
+            }
+        }
+    }
+    container reference {
+        list found {
+            key "define";
+            leaf define {
+                type string;
+            }
+            container reciever {
+                leaf remove {
+                    type leafref {
+                        path "/valid/standard/present/name";
+                    }
+                }
+            }
+        }
+    }
+    list transmitter {
+        key "send";
+        leaf send {
+            type leafref {
+                path "/invalid-interval";
+            }
+        }
+    }
+    leaf-list invalid-interval {
+        type enumeration {
+            enum 10m;
+            enum 100m;
+            enum auto;
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftomultitypedef/SelfResolutionWhenLeafrefReferToMultipleTypedef.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftomultitypedef/SelfResolutionWhenLeafrefReferToMultipleTypedef.yang
new file mode 100644
index 0000000..4b286d2
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftomultitypedef/SelfResolutionWhenLeafrefReferToMultipleTypedef.yang
@@ -0,0 +1,43 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            container present {
+                leaf-list name {
+                    type transmitter;
+                }
+            }
+        }
+    }
+    container reference {
+        list found {
+            key "define";
+            leaf define {
+                type string;
+            }
+            container reciever {
+                leaf remove {
+                    type leafref {
+                        path "/valid/standard/present/name";
+                    }
+                }
+            }
+        }
+    }
+    typedef transmitter {
+        type invalid-interval;
+    }
+    typedef invalid-interval {
+        type enumeration {
+            enum 10m;
+            enum 100m;
+            enum auto;
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftorpcinputleaflist/SelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftorpcinputleaflist/SelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc.yang
new file mode 100644
index 0000000..59e7a98
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftorpcinputleaflist/SelfResolutionWhenLeafrefInTypedefModuleReferToLeafListInInputOfRpc.yang
@@ -0,0 +1,26 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    rpc networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        input {
+            leaf-list network-id {
+                type network-ref;
+                description
+                "Identifies a network.";
+            }
+            leaf id {
+                type uint8;
+            }
+        }
+        output {
+        }
+    }
+    typedef network-ref {
+        type leafref {
+            path "/networks/input/id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftotypedefwithleafref/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftotypedefwithleafref/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref.yang
new file mode 100644
index 0000000..1bf423d
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafreftotypedefwithleafref/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafref.yang
@@ -0,0 +1,45 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            container present {
+                leaf-list name {
+                    type transmitter;
+                }
+            }
+        }
+    }
+    container reference {
+        list found {
+            key "define";
+            leaf define {
+                type string;
+            }
+            container reciever {
+                leaf remove {
+                    type leafref {
+                        path "/valid/standard/present/name";
+                    }
+                }
+            }
+        }
+    }
+    typedef transmitter {
+        type leafref {
+            path "/invalid-interval";
+        }
+    }
+    leaf invalid-interval {
+        type enumeration {
+            enum 10m;
+            enum 100m;
+            enum auto;
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefundernodeingrouping/ietf-network.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefundernodeingrouping/ietf-network.yang
new file mode 100644
index 0000000..3db511e
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefundernodeingrouping/ietf-network.yang
@@ -0,0 +1,95 @@
+module ietf-network {
+     yang-version 1;
+     namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+     prefix nd;
+
+     organization
+       "IETF I2RS (Interface to the Routing System) Working Group";     
+    grouping node-ref {
+       description
+         "Contains the information necessary to reference a node.";
+       container node-from-grouping {
+             leaf node-ref {
+                type leafref {
+                 path "/networks/network/node/node-id";
+                   require-instance false;
+                  }
+              }
+         }
+     }
+     container networks {
+       description
+         "Serves as top-level container for a list of networks.";
+       list network {
+         key "network-id";
+         description
+           "Describes a network.
+            A network typically contains an inventory of nodes,
+            topological information (augmented through
+            network-topology model), as well as layering
+            information.";
+         container network-types {
+           description
+             "Serves as an augmentation target.
+              The network type is indicated through corresponding
+              presence containers augmented into this container.";
+         }
+         leaf network-id {
+           type string;
+           description
+             "Identifies a network.";
+         }
+         list supporting-network {
+           key "network-ref";
+           description
+             "An underlay network, used to represent layered network
+              topologies.";
+           leaf network-ref {
+             type leafref {
+               path "/networks/network/network-id";
+             require-instance false;
+             }
+             description
+               "References the underlay network.";
+           }
+         }
+         list node {
+           key "node-id";
+           description
+             "The inventory of nodes of this network.";
+           leaf node-id {
+             type uint8;
+             description
+               "Identifies a node uniquely within the containing
+                network.";
+           }
+           list supporting-node {
+             key "network-ref node-ref";
+             description
+               "Represents another node, in an underlay network, that
+                this node is supported by.  Used to represent layering
+                structure.";
+             leaf network-ref {
+               type leafref {
+                 path "../../../supporting-network/network-ref";
+               require-instance false;
+               }
+               description
+                 "References the underlay network that the
+                  underlay node is part of.";
+             }
+             leaf node-ref {
+               type leafref {
+                 path "/networks/network/node/node-id";
+               require-instance false;
+               }
+               description
+                 "References the underlay node itself.";
+             }
+           }
+         }
+       }
+       uses node-ref;
+     }
+
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrefleafderived/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrefleafderived/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang
new file mode 100644
index 0000000..a3e0f29
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrefleafderived/SelfResolutionWhenLeafrefIsInDeepTreeAndLeafListIsInModuleWithReferredTypeEnumeration.yang
@@ -0,0 +1,27 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            container present {
+                leaf-list name {
+                    type leafref {
+                        path "/invalid-interval";
+                    }
+                }
+            }
+        }
+    }
+    leaf-list invalid-interval {
+        type enumeration {
+            enum 10m;
+            enum 100m;
+            enum auto;
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrpc/SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrpc/SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc.yang
new file mode 100644
index 0000000..3dce93e
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrpc/SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc.yang
@@ -0,0 +1,23 @@
+module SelfResolutionWhenLeafrefInModuleReferToLeafInInputOfRpc {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    rpc networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        input {
+            leaf network-id {
+                type uint8;
+                description
+                "Identifies a network.";
+            }
+        }
+        output {
+        }
+    }
+    leaf network-ref {
+        type leafref {
+        path "/networks/input/network-id";
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrpcandgrouping/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrpcandgrouping/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc.yang
new file mode 100644
index 0000000..e8debbd
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/leafrefwithrpcandgrouping/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc.yang
@@ -0,0 +1,28 @@
+module SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpc {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    rpc networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        grouping input {
+            leaf network-id {
+                type string;
+                description
+                "Identifies a network.";
+            }
+        }
+        input {
+            leaf network-id {
+                type uint8;
+                description
+                "Identifies a network.";
+            }
+        }
+    }
+    leaf network-ref {
+        type leafref {
+        path "/networks/input/network-id";
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/invalidnode/SelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/invalidnode/SelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath.yang
new file mode 100644
index 0000000..9681d76
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/invalidnode/SelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath.yang
@@ -0,0 +1,19 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    leaf network-ref {
+            type leafref {
+            path "../define/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/invalidrelativeancestoraccess/SelfResolutionWhenLeafrefInModuleReferToInvalidRootNodeRelPath.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/invalidrelativeancestoraccess/SelfResolutionWhenLeafrefInModuleReferToInvalidRootNodeRelPath.yang
new file mode 100644
index 0000000..7e3d216
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/invalidrelativeancestoraccess/SelfResolutionWhenLeafrefInModuleReferToInvalidRootNodeRelPath.yang
@@ -0,0 +1,19 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    leaf network-ref {
+            type leafref {
+            path "../../../define/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafrefintypedef/SelfResolutionWhenLeafrefInTypedefReferToContainerRelPath.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafrefintypedef/SelfResolutionWhenLeafrefInTypedefReferToContainerRelPath.yang
new file mode 100644
index 0000000..93d8e94
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafrefintypedef/SelfResolutionWhenLeafrefInTypedefReferToContainerRelPath.yang
@@ -0,0 +1,22 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type network-ref;
+            description
+            "Identifies a network.";
+        }
+        leaf id {
+            type uint8;
+        }
+    }
+    typedef network-ref {
+        type leafref {
+            path "../id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftoinputwithgroupinginrpc/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftoinputwithgroupinginrpc/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath.yang
new file mode 100644
index 0000000..477832d
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftoinputwithgroupinginrpc/SelfResolutionWhenLeafrefInModuleReferToGroupingWithInputInRpcRelPath.yang
@@ -0,0 +1,28 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    rpc networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        grouping input {
+            leaf network-id {
+                type string;
+                description
+                "Identifies a network.";
+            }
+        }
+        input {
+            leaf network-id {
+                type uint8;
+                description
+                "Identifies a network.";
+            }
+        }
+    }
+    leaf network-ref {
+        type leafref {
+            path "../networks/input/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftomultileafref/SelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftomultileafref/SelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath.yang
new file mode 100644
index 0000000..890bbaa
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftomultileafref/SelfResolutionWhenLeafrefReferToMultipleLeafrefRelPath.yang
@@ -0,0 +1,50 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            container present {
+                leaf-list name {
+                    type leafref {
+                        path "../../../../transmitter/send";
+                    }
+                }
+            }
+        }
+    }
+    container reference {
+        list found {
+            key "define";
+            leaf define {
+                type string;
+            }
+            container reciever {
+                leaf remove {
+                    type leafref {
+                        path "../../../../valid/standard/present/name";
+                    }
+                }
+            }
+        }
+    }
+    list transmitter {
+        key "send";
+        leaf send {
+            type leafref {
+                path "../../invalid-interval";
+            }
+        }
+    }
+    leaf-list invalid-interval {
+        type enumeration {
+            enum 10m;
+            enum 100m;
+            enum auto;
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftotypedef/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftotypedef/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType.yang
new file mode 100644
index 0000000..5570f38
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/leafreftotypedef/SelfResolutionWhenLeafrefReferToDerivedTypeReferringToLeafWithLeafrefRelType.yang
@@ -0,0 +1,45 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    list valid {
+        key "define";
+        leaf define {
+            type string;
+        }
+        container standard {
+            container present {
+                leaf-list name {
+                    type transmitter;
+                }
+            }
+        }
+    }
+    container reference {
+        list found {
+            key "define";
+            leaf define {
+                type string;
+            }
+            container reciever {
+                leaf remove {
+                    type leafref {
+                        path "../../../../valid/standard/present/name";
+                    }
+                }
+            }
+        }
+    }
+    typedef transmitter {
+        type leafref {
+            path "../../../../invalid-interval";
+        }
+    }
+    leaf invalid-interval {
+        type enumeration {
+            enum 10m;
+            enum 100m;
+            enum auto;
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/pathlistener/PathListener.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/pathlistener/PathListener.yang
new file mode 100644
index 0000000..c4dae28
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/pathlistener/PathListener.yang
@@ -0,0 +1,31 @@
+module PathListener {
+    namespace "test";
+    prefix test;
+     list interface {
+         key "name";
+         leaf name {
+             type string;
+         }
+         leaf admin-status {
+             type string;
+         }
+         list address {
+             key "ip";
+             leaf ip {
+                 type string;
+             }
+         }
+     }
+     container default-address {
+         leaf ifname {
+             type leafref {
+                 path "../../test:interface/test:name";
+             }
+         }
+         leaf status {
+             type leafref {
+                 path "/test:interface[name = current()/../ifname]/test:admin-status";
+             }
+         }
+     }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/simpleleafref/SelfResolutionWhenLeafrefReferToContainerLeafRelPath.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/simpleleafref/SelfResolutionWhenLeafrefReferToContainerLeafRelPath.yang
new file mode 100644
index 0000000..05ef0d2
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/relativepath/simpleleafref/SelfResolutionWhenLeafrefReferToContainerLeafRelPath.yang
@@ -0,0 +1,19 @@
+module ietf-network {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    leaf network-ref {
+        type leafref {
+            path "../networks/network-id";
+        }
+    }
+}
\ No newline at end of file
diff --git a/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/simpleleafref/SelfResolutionWhenLeafrefReferToContainerLeaf.yang b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/simpleleafref/SelfResolutionWhenLeafrefReferToContainerLeaf.yang
new file mode 100644
index 0000000..375cace
--- /dev/null
+++ b/utils/yangutils/plugin/src/test/resources/leafreflinker/intrafile/simpleleafref/SelfResolutionWhenLeafrefReferToContainerLeaf.yang
@@ -0,0 +1,19 @@
+module SelfResolutionWhenLeafrefReferToContainerLeaf {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:ietf-network";
+    prefix nd;
+    container networks {
+        description
+        "Serves as top-level container for a list of networks.";
+        leaf network-id {
+            type uint8;
+            description
+            "Identifies a network.";
+        }
+    }
+    leaf network-ref {
+        type leafref {
+        path "/networks/network-id";
+        }
+    }
+}