Giter Site home page Giter Site logo

Need help to add new yang file about clixon HOT 12 CLOSED

clicon avatar clicon commented on August 29, 2024
Need help to add new yang file

from clixon.

Comments (12)

nagranjeet avatar nagranjeet commented on August 29, 2024 1

I was also looking for same changes.

from clixon.

olofhagsand avatar olofhagsand commented on August 29, 2024

You need to import it from one of the existing yang modules. The main one or one (transitively) imported by the main module.
Or you set the main module in the configure file, example.xml:
<CLICON_YANG_MODULE_MAIN>example</CLICON_YANG_MODULE_MAIN>
(+You need to reconfigure to regenerate the new Makefile from Makefile.in, but I assumed you knew that)
Please tell if this works?

from clixon.

ngashok avatar ngashok commented on August 29, 2024

Thanks a lot. I forgot to do configure again.
Also is there a way to use the similar yang even for show, or we need to edit the example_cli.cli to add grammar. sometimes these shows also become nested. The reason I am asking is sometimes these show commands also become big and nested. like show module-a cpu1 dpdk-stats. show module-a cpu2 dpdk-stats etc..

from clixon.

ngashok avatar ngashok commented on August 29, 2024

Adding to this is there a simple way to populate the incoming buffer (cvec *cvv) into some autogenerated structures-per-yang. So that user can push only these structures to lower layers for processing?
I think now we need to add logic of populating to user-defined structures for every yang file added?

from clixon.

olofhagsand avatar olofhagsand commented on August 29, 2024

^^ Yes agree, the CLI show commands get big and nested as they are written in example_cli.cli. Should add something like:
show @datamodel:example, cli_show();
similar to the recursive set syntax.
I have to think about this. It would be very useful. Thanks for pointing that out.

from clixon.

olofhagsand avatar olofhagsand commented on August 29, 2024

^^populate incoming buffers. You mean the cli callbacks, such as cli_set()? Can you please elaborate. What kind of data do you want to give - how and where does a user define it?

from clixon.

ngashok avatar ngashok commented on August 29, 2024

Yes assume I get some values in cli_set based on following commands
yang1:
set l2tp tunnel password abc
set l2tp tunnel mtu 1500

yang2:
set ipsec auth_algo sha1
set ipsec encrypt algo aes-gcm

to implement the functionality, assume I have two processes ipsecmgr and l2tpmgr
so I expect these info to be sent to these processes without much effort like

case L2TP_YANG:
get_the_l2tp_info(&structure1)
send/use the structure1 as needed to process1-l2tpmgr.
case IPSEC_YANG:
get_the_ipsec_info(&sturcture2);
send/use the structure2 as needed to process2-ipsecmgr

can the structure and the get function be autogenerated as part of yang parsing?
struct l2tp_info
{
int mtu;
char[256] password;
};

struct ipsec_info
{
char auth_algo[256];
char encrypt_algo[256];
};

from clixon.

olofhagsand avatar olofhagsand commented on August 29, 2024

This is the info that is built in the XML structure using cli_set, as you know, just not in a C-specific struct. This would need a C-struct generating step from Yang, ie to generate struct l2tp_info and struct ipsec_info above from the yang specification.
I have experimented with that before and it is possible to do, and from a C-application perspective may seem natural.
The advantage with XML and YANG structures as they are are that they are interpretated, dynamic and type-self containted.
The way to go with the current approach is that you get an XML struct (cxobj* x) with an associated YANG spec pointer (y=xml_spec(x)).
You have the data in x and the type in y. You will have to dig to get the value and type info out, and the API can surely be improved.
So I see two approaches
(1) Make an effort to actually generate the C-structs from YANG. I dont know a std way to do this(is there some draft somewhere?), and there will be types that dont map. Also structured types, eg lists and containers are difficult, leafs/leaflist are straightforward. I have made this kinds of attempts in the past and would avoid them as part of the general tool. But as a special case for some specific application it might be worth a try.
(2) Make a better way to map the existing xml/yang (x/y) data to an application by improving API/glue code, preferably for a set of languages, not only C, also python and others. I would be interested in this approach to make Clixon more usable. One could start with a usecase such as the one you have above.

from clixon.

olofhagsand avatar olofhagsand commented on August 29, 2024

Added a generated show command as discussed further up the thread.
From README:

  • Added a generated CLI show command that works on the generated parse tree with auto completion.
    • A typical call is: show @datamodel:example, cli_show_auto("candidate", "json");
    • The example contains a more elaborate example.
    • Thanks ngashok for request, see #24

from clixon.

ngashok avatar ngashok commented on August 29, 2024

Awesome! That was quick. Thanks a lot. It will be very useful for me.
Also as you said I am planning to write a parser for yang so that it can convert from yang to .proto. Google protobuf can then be used to make it language independent.
I tried some open source tools but nothing is complete.
Probably once I complete it, I should be able to populate class/struct using the cli_set arguments received.

from clixon.

ngashok avatar ngashok commented on August 29, 2024

I think "No' also should support nested yang just like set. Just a suggestion. If set has configured something. Not sure how we can do "no" of that config, as no doesnt show up that grammar now.

from clixon.

olofhagsand avatar olofhagsand commented on August 29, 2024

@ngashok , I think the example has what you want:
delete("Delete a configuration item") @datamodel:example, cli_del();
Just replace delete -> no would do the trick?

from clixon.

Related Issues (20)

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.