CESNET / libnetconf

C NETCONF library
Other
113 stars 83 forks source link

Adding Custom Yang file using TransAPI #213

Closed virajmistry closed 8 years ago

virajmistry commented 8 years ago

Hi,

I am trying to add new yang file having only one leaf in file using transAPI. I have followed all the steps mentioned in https://rawgit.com/CESNET/libnetconf/master/doc/doxygen/html/d9/d25/transapi.html

I am successfully getting capability of my yang file when i start netopeer-server.

But when i do get on particular leaf i am not able to get reply from server.

Also i have observed that in datastore.xml file only following lines are there which should be more once the server is started.

<?xml version="1.0" encoding="UTF-8"?>

Please suggest am i missing any steps when adding custom yang steps.

Thanks Viraj

michalvasko commented 8 years ago

Hi Viraj, how did you install your module? What do you mean by "get on a particular leaf", get with a filter? Can you execute a standard get successfully? The content of datastore.xml is usually different, there should be empty elements of 3 datastores, just delete this file to reset it.

Regards, Michal

virajmistry commented 8 years ago

Hi Michal,

Below is my command to install yang file, 1.lnctool --model mymodule.yang transapi --paths paths_mymodule 2.Then i am copying all the required files (.yin,.rng,.xsl ) to /usr/local/etc/netopeer/mymodule 3./usr/local/bin/netopeer-manager add --name mymodule --model /usr/local/etc/netopeer/mymodule/mymodule.yin --transapi //usr/local/lib/mymodule.so --datastore /usr/local/etc/netopeer//mymodule/datastore.xml; 4../mymodule-init /usr/local/etc/netopeer/mumodule/datastore.xml

What do you mean by "get on a particular leaf", get with a filter? Yes i am doing get of that leaf with filter Request and Reply are attached.Also Standard Get Reply is attached for your reference. Data store element is also there with three empty elements. Reply.txt Request.txt Standard_Get_Command_reply.txt

Please share your review for the same.

Thanks Viraj

michalvasko commented 8 years ago

Hi Viraj, I am not sure I see any problem, it seems it is all working fine. You have an empty datastore (which was generated by your mymodule-init), so the reply includes only the container. You need to change the datastore to get a different data in the reply.

By the way, what does that mymodule-init utility do? Some of our transAPI modules have these, but they are there for quite specific reasons, you definitely do not need them for testing.

Regards, Michal

virajmistry commented 8 years ago

Hi Michal,

Yes You are correct i am using mymodule-init is same as cfgsystem-init but with my module name. Actually the leafname is same as hostname and mymodule is just same as cfgsystem with only one name called leafname. I just want to know the flow of the whole code so i tried to add one node in my Yang file which is same as hostname. so thats why i have also used mymodule-init. Also my mymodule.c file having same code as cfgsystem.c with only hostname leaf.

You need to change the datastore to get a different data in the reply. Can you please tell me how to change datastore ?datastore.xml is there and it can be changed but as per my knowledge some module my change datastore.xml automatically. But in my case datastore.xml is not updated.

Please share your view.

Thanks Viraj

michalvasko commented 8 years ago

Hi Viraj, I am nor sure you have taken a right approach when you decided to modify cfgsystem, but I don't see the final module and code. Provided they are correct, you change the configuration using some NETCONF RPCs, most commonly edit-config. Afterwards, the changes made should be seen in the datastore.xml file as well.

Regards, Michal

virajmistry commented 8 years ago

Hi Michal, Yes your are correct by edit-config i can see changes in datastore.xml file. Also i am able to see get reply of the same leaf for which i have done edit-config.

But my question is when i start my netopeer-server i can not see any running configuration in datastore.xml and thats why i can not see get reply of my leaf. I have kept the same code in as cfgsystem.c . But in cfgsystem when i start netopeer-server i can see running configuration for very first time while in my module case it is not there.

Can you please suggest me how can i generate running configuration very first time datastore.xml for my module and can get reply of that leaf without doing edit-config initially?

I have also attached mymodule.txt file for your reference of my module. mymodule.txt

Regards, Viraj

michalvasko commented 8 years ago

Hi Viraj, you do not have any running configuration because you do not have any startup configuration set. Among the first things performed during server startup is copying startup configuration into running.

You see running configuration of cfgsystem simply because there is some startup configruation set. It is set during this module installation when cfgsystem-init is called. But we are talking about a system module that manages core system configuration, that is why we created that small init utility, I do not think you need it for your pruposes.

Regards, Michal

virajmistry commented 8 years ago

Hi Michal,

Yes i got your point. But in my case i need this startup configuration for my module leafs(which are going to add latter). So i want to know from where this startup configuration in created and then written into datastore.xml. I can see the function transapi_init which is called in cfgystem-init.c but i have kept same API and its code and also have called this transapi_init into mymodule-init.c file but in my case startup configuration is null.

So how can i write this startup configuration into datastore.xml which is latter be copied to running configuration once server is started.

FYI: This system configuration leaf in my module is just for test purpose latter i will add my custom leafs which are different from this.

Please share your view.

Regards, Viraj

michalvasko commented 8 years ago

Hi Viraj, fine, I am going to explain this one more time even though I already did it several times.

transapi_init function, in any transAPI module, is there for you to have a chance to react to changes made outside your transAPI module to the configuration you manage. Example, you manage system users (one of the things cfgsystem does). You have certain configuration and you terminate netopeer-server. Now someone else comes along and adds a user. When you start netopeer-server again, it will not know about this change. So you maybe try to add a user with the same name and, to netopeer-server surprise, it will fail. transapi_init is there to prevent these inconsistencies by giving you the chance to analyze the current system state and create a correct running configuration, so that replacing it with startup configuration does not break anything and the changes are detected correctly.

All cfgsystem-init does is calling this function from cfgsystem.c, thus getting the current machine system configuration, and storing it in the startup configuration. This way, when you start netopeer-server (startup is copied into running) no changes are detected so your system configuration is kept as it was and no undesired changes to the system are made.

Now I hope you understand what is happening there and my guess is that you did not implement transapi_init in your module, that is why you cannot see anything in your startup provided you really copied the functionality of cfgsystem-init.

Regards, Michal