Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help to add new yang file #24

Closed
ngashok opened this issue May 30, 2018 · 12 comments
Closed

Need help to add new yang file #24

ngashok opened this issue May 30, 2018 · 12 comments

Comments

@ngashok
Copy link

ngashok commented May 30, 2018

Wanted to add something similar to interfaces.
Added a new data model similar to interfaces and stored it in example directory.
changed the Makefile.in only to add this new yang file.

After this I was expecting the CLI to atleast show up the new one after i do "set ?"

Anything else I need to do as I dint find anything sepcific for other yang files, If i need to config and display (without any other functionality)

@olofhagsand
Copy link
Member

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?

@ngashok
Copy link
Author

ngashok commented May 31, 2018

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..

@ngashok
Copy link
Author

ngashok commented May 31, 2018

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?

@olofhagsand
Copy link
Member

olofhagsand commented May 31, 2018

^^ 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.

@olofhagsand
Copy link
Member

^^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?

@ngashok
Copy link
Author

ngashok commented Jun 1, 2018

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];
};

@olofhagsand
Copy link
Member

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.

olofhagsand added a commit that referenced this issue Jun 5, 2018
…e 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
@olofhagsand
Copy link
Member

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.

@ngashok
Copy link
Author

ngashok commented Jun 5, 2018

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.

@nagranjeet
Copy link

I was also looking for same changes.

@ngashok
Copy link
Author

ngashok commented Jun 20, 2018

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.

@olofhagsand
Copy link
Member

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants