GithubHelp home page GithubHelp logo

yang-central / yangkit Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 3.0 7.69 MB

Yangkit is a toolkit for YANG(RFC7950) data model language including YANG parser,YANG data and other tools.

License: Apache License 2.0

Java 99.96% ANTLR 0.04%
java parser yang

yangkit's Introduction

Yangkit

overview

Yangkit is a toolkit for YANG(RFC7950) data model language including YANG parser,YANG data and other tools.

Yangkit components

Installation

From source

git clone https://github.com/yang-central/yangkit.git

and execute the maven command:

mvn clean install

maven dependency

yangkit-parser

    <dependency>
        <groupId>io.github.yang-central.yangkit</groupId>
        <artifactId>yangkit-parser</artifactId>
        <version>1.0.0</version>
    </dependency>

yangkit-model-api

    <dependency>
        <groupId>io.github.yang-central.yangkit</groupId>
        <artifactId>yangkit-model-api</artifactId>
        <version>1.0.0</version>
    </dependency>

yangkit-model-impl

    <dependency>
        <groupId>io.github.yang-central.yangkit</groupId>
        <artifactId>yangkit-model-impl</artifactId>
        <version>1.0.0</version>
    </dependency>

yangkit-xpath-api

    <dependency>
        <groupId>io.github.yang-central.yangkit</groupId>
        <artifactId>yangkit-xpath-api</artifactId>
        <version>1.0.0</version>
    </dependency>

yangkit-xpath-impl

    <dependency>
        <groupId>io.github.yang-central.yangkit</groupId>
        <artifactId>yangkit-xpath-impl</artifactId>
        <version>1.0.0</version>
    </dependency>

yangkit-data-api

    <dependency>
        <groupId>io.github.yang-central.yangkit</groupId>
        <artifactId>yangkit-data-api</artifactId>
        <version>1.0.0</version>
    </dependency>

Documentation

Please see the java doc in components.

yangkit's People

Contributors

lllyfeng avatar xinghaiquedeng avatar ahassany avatar caowei49 avatar

Stargazers

Chaitanya Sharma avatar andre-r-almeida avatar Taketoday avatar  avatar  avatar  avatar  avatar Felipe avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yangkit's Issues

Enhance the YangYinParser API to work with none file-based yang sources

Currently, the YangYinParser provides 8 public methods for parsing YANG schemas, all of which are File or Directory based. This represents a tight coupling to the filesystem and can limit the usage of this API inside other libraries that don't save the schema on a traditional file system.

Is there any futures plans to refactor this API and decouple YangYinParser from how the yang schemas are stored?

The current, API

  1. public static YangSchemaContext parse(List<File> yangFiles)
  2. public static YangSchemaContext parse(File yangDir)
  3. public static YangSchemaContext parse(File yangDir, YangSchemaContext context)
  4. public static YangSchemaContext parse(String yangDir)
  5. public static YangSchemaContext parse(String yangDir, String dependency, String capabilities)
  6. public static YangSchemaContext parse(String yangDir, String capabilities)
  7. public static YangSchemaContext parse(String yangDir, YangSchemaContext context)
  8. public static YangSchemaContext parse(List<File> files, YangSchemaContext context)

Exception in thread "main" java.lang.RuntimeException: org.yangcentral.yangkit.model.api.codec.YangCodecException: invalid value.

tool:yangkit-data-xml-codec
version:1.4.0

Exception in thread "main" java.lang.RuntimeException: org.yangcentral.yangkit.model.api.codec.YangCodecException: invalid value.
at org.yangcentral.yangkit.data.impl.model.LeafListDataImpl.(LeafListDataImpl.java:23)
at org.yangcentral.yangkit.data.impl.builder.YangDataBuilder.getYangData(YangDataBuilder.java:53)
at org.yangcentral.yangkit.data.codec.xml.LeafListDataXmlCodec.buildData(LeafListDataXmlCodec.java:20)
at org.yangcentral.yangkit.data.codec.xml.LeafListDataXmlCodec.buildData(LeafListDataXmlCodec.java:10)
at org.yangcentral.yangkit.data.codec.xml.YangDataXmlCodec.deserialize(YangDataXmlCodec.java:99)
at org.yangcentral.yangkit.data.codec.xml.YangDataDocumentXmlCodec.buildChildrenData(YangDataDocumentXmlCodec.java:65)
at org.yangcentral.yangkit.data.codec.xml.YangDataDocumentXmlCodec.buildChildrenData(YangDataDocumentXmlCodec.java:93)
at org.yangcentral.yangkit.data.codec.xml.YangDataDocumentXmlCodec.buildChildrenData(YangDataDocumentXmlCodec.java:93)
at org.yangcentral.yangkit.data.codec.xml.YangDataDocumentXmlCodec.buildChildrenData(YangDataDocumentXmlCodec.java:93)
at org.yangcentral.yangkit.data.codec.xml.YangDataDocumentXmlCodec.deserialize(YangDataDocumentXmlCodec.java:109)
at org.yangcentral.yangkit.data.codec.xml.YangDataDocumentXmlCodec.deserialize(YangDataDocumentXmlCodec.java:119)
at org.yangcentral.yangkit.data.codec.xml.YangDataParser.parse(YangDataParser.java:39)
at org.yangcentral.yangkit.data.codec.xml.YangDataParserExecutor.main(YangDataParserExecutor.java:52)
Caused by: org.yangcentral.yangkit.model.api.codec.YangCodecException: invalid value.
at org.yangcentral.yangkit.model.impl.codec.UnionStringValueCodecImpl.serialize(UnionStringValueCodecImpl.java:58)
at org.yangcentral.yangkit.model.impl.codec.UnionStringValueCodecImpl.serialize(UnionStringValueCodecImpl.java:17)
at org.yangcentral.yangkit.data.impl.model.YangDataValueStringImpl.getStringValue(YangDataValueStringImpl.java:54)
at org.yangcentral.yangkit.data.impl.model.LeafListDataImpl.(LeafListDataImpl.java:21)
... 12 more

cause by
LeafList:
3352:3885

yang:
leaf-list community-member {
type community-type;
max-elements 200;
status deprecated;
ext:advised-node "../rtp:community-attributes/rtp:community-attribute";
description
"Configure a community attribute in a BGP community list. There must be at least one community in a list, min-elements 1.";
}

typedef community-type {
type union {
type well-known-community-type;
type std-community-type;
}
description
"Type of the community members.";
}

typedef well-known-community-type {
type enumeration {
enum "internet" {
description
"The basic type of filter.";
}
enum "no-advertise" {
description
"Do not advertise to any peer.";
}
enum "no-export" {
description
"Do not export to external peers.";
}
enum "no-export-subconfed" {
description
"Do not send outside a sub-confederation.";
}
}
description
"Type definition for well-known IETF community attribute values.";
}

typedef std-community-type {
type union {
type string {
length "1..19";
pattern '((6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}|0):(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}|0))';
}
type uint32 {
range "1..4294967040|4294967044..4294967295";
}
}
description
"Type definition for community attributes.";
}

The same error is reported twice.

errorTag='bad-element', severity=Warning, errorPath=source:ieee802-dot1ab-lldp.yang line:390 column:7, badElement=leaf name, errorMessage=invalid xpath:(derived-from-or-self(deref(.)/../if:type, "ianaift:ethernetCsmacd") or derived-from-or-self(deref(.)/../if:type, "ianaift:ieee8023adLag")). the node:lldp:port has no child node:if:type.
errorTag='bad-element', severity=Warning, errorPath=source:ieee802-dot1ab-lldp.yang line:390 column:7, badElement=leaf name, errorMessage=invalid xpath:(derived-from-or-self(deref(.)/../if:type, "ianaift:ethernetCsmacd") or derived-from-or-self(deref(.)/../if:type, "ianaift:ieee8023adLag")). the node:lldp:port has no child node:if:type.

Yang to Json Schema

Hi ,
can you please provide and example to convert yang to a json schema, is it supported? javadoc is not working btw

NullPointerException on typedef declaration in grouping

Hi!

Given the following yang-file null-pointer-example.yang:

module null-pointer-example {
  yang-version 1.1;
  namespace "urn:example:yangkit-bug";
  prefix bug;

  description
    "Demonstrate NullPointerException in io.github.yang-central.yangkit:yangkit-parser:1.3.5";

  revision 2023-07-25 {
  }

  typedef package-version {
    type string {
      pattern '\d+\.\d+([-.](\d+|\w+))*';
    }
  }

  grouping package-meta-data {
    typedef version {
      type package-version;
    }
  }
}

And running code like this:

YangSchemaContext schemaContext = YangYinParser.parse(List.of(new File("null-pointer-example.yang")));
schemaContext.validate();

I get the following exception:

java.lang.NullPointerException: Cannot invoke "org.yangcentral.yangkit.base.YangContext.getTypedef(String)" because "this.yangContext" is null
	at org.yangcentral.yangkit.model.impl.stmt.TypedefContainerImpl.getTypedef(TypedefContainerImpl.java:48)
	at org.yangcentral.yangkit.model.impl.stmt.TypedefContainerImpl.addTypedef(TypedefContainerImpl.java:35)
	at org.yangcentral.yangkit.model.impl.stmt.GroupingImpl.initSelf(GroupingImpl.java:164)
	at org.yangcentral.yangkit.model.impl.stmt.YangStatementImpl.init(YangStatementImpl.java:806)
	at org.yangcentral.yangkit.model.impl.stmt.YangStatementImpl.initChildren(YangStatementImpl.java:741)
	at org.yangcentral.yangkit.model.impl.stmt.YangStatementImpl.init(YangStatementImpl.java:812)
	at org.yangcentral.yangkit.model.impl.schema.YangSchemaContextImpl.validate(YangSchemaContextImpl.java:286)

I've reduced the example to be somewhat minimal to trigger the bug.

Hope there can be an easy fix for this :-)

Cheers!
/Mårten

Yang parser accepts yang schema without proper curly bracket closing

I've tried using the yang parser on the following schema that is missing three closing curly brackets (leaf definition closing, container definition closing, and module closing). Yang parser parses and validate it correctly without throwing any errors?

module a-module {
  yang-version 1.1;
  namespace "urn:example:a-module";
  prefix a;

  organization
    "Test Organization";
  contact
    "Ahmed Elhassany <mailto:[email protected]>";
  description
    "Simple Test module with one typedef and a container of one leaf";
  reference
    "testing";

  revision 2023-02-01 {
    reference
      "first revision";
  }

  typedef aType {
    type int8;
    description
      "Simple int8 type for testing";
  }

  container x {
    description
      "Test container";
    leaf aLeaf {
      type aType;
      description
        "Example leaf";

The test code I used was

package yang.test;

import org.yangcentral.yangkit.common.api.validate.ValidatorResult;
import org.yangcentral.yangkit.model.api.schema.YangSchemaContext;
import org.yangcentral.yangkit.parser.YangYinParser;

public class TestCase {
  public static void main(String[] args) throws Exception{
    YangSchemaContext yang = YangYinParser.parse("~/yangdir");
    ValidatorResult result = yang.validate();
    if (result.isOk()) {
      System.out.println("Yang Schema is valid, number of modules read is: " + yang.getModules().size());
    } else {
      System.out.println("Yang Schema is NOT valid, number of modules read is: " + yang.getModules().size());
    }
  }
}

And the output was Yang Schema is valid, number of modules read is: 1. I don't this is a correct behavior by yangkit: I was expecting this value to be invalid. FYI, pyang and libyang won't accept this schema as a valid one.

javadoc links are not working

Hi all,

I found your project very interesting, I would like to take a look at the documentation to find minimal examples for parsing YANG model, generating YANG instance data, etc.

But the javadoc links are not working, pointing to not found links. Are you planning to fix this issue?

Thanks,
Balazs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.