Skip to content

typedef not found when 'include' used in submodule #119

Open
@preetjuniper

Description

I see the following error when referencing a typedef in a submodule where another submodule under the same parent module is explicitly included.

application/application/system/level - typedef log-level not found

When the submodule is not explicitly included, there's no error. Using a prefix makes no difference. I tried to print out which 'node's (not sure what the right terminology is) are crawled to find the typedef in findTypedef in freeconf/yang/meta/compile.go, I see different nodes are traversed with and without the include:

// with "include some-types;"
>> rm -f testfreeconf && go build && ./testfreeconf
searching ident: level               // just fmt.Printf("searching ident: %v\n", p.Ident())
searching ident: log-params
searching ident: system
panic: application/application/system/level - typedef log-level not found

goroutine 1 [running]:
main.main()
	/n/dev/scratch/freeconf/main.go:26 +0x8d

// without "include some-types;"
>> rm -f testfreeconf && go build && ./testfreeconf
searching ident: level
searching ident: log-params
searching ident: application

In RFC 7590 the include is optional, but I believe its mandatory in 6020. From section 5.1:

o For a submodule to reference definitions in a second submodule of
the same module, the first submodule MUST include the second
submodule.

Yang files:

module application {
    namespace "urn:application";
    prefix "app";

    include some-types;
    include system;

    organization "";
    contact "";
    description "";
    revision 2024-01-01 {
        description "";
        reference "";
    }

    container application {
        uses system;
    }
}
submodule some-types {
    belongs-to application {
        prefix app;
    }

    organization "";
    contact "";
    description "";
    revision 2024-01-01 {
        description "";
        reference "";
    }

    typedef log-level {
        type enumeration {
            enum debug;
            enum info;
            enum warn;
            enum error;
        }
    }
    grouping log-params {
        leaf filename {
            type string;
        }
        leaf filesize {
            type int32;
        }
        leaf level {
            type log-level;
        }
    }
}
submodule system {
    belongs-to application {
        prefix app;
    }

    // This include statement causes an error
    include some-types;

    organization "";
    contact "";
    description "";
    revision 2024-01-01 {
        description "";
        reference "";
    }

    grouping system {
        container system {
            uses log-params;
        }
    }
}

Attempt to load the modules

package main

import (
	"github.com/freeconf/yang/parser"
	"github.com/freeconf/yang/source"
	"github.com/freeconf/yang/fc"
)

func main() {
	// enable debug logging
	fc.DebugLog(true)

	// load model
	_, errLdMdl := parser.LoadModule(source.Dir("appyang"), "application")
	if errLdMdl != nil {
		panic(errLdMdl.Error())
	}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions