Using callback functions

89 views
Skip to first unread message

peter...@gmail.com

unread,
Apr 13, 2015, 11:36:51 PM4/13/15
to neto...@googlegroups.com
Hi,

I am working on a project which my router does some address mapping between internal host's private ip address and global ip address. I want to use Netconf protolcol to manage the router device. I have the structure of the router data defined in the yang file. The code for the actual operations of the router (the actual address mapping, sending/receiving packets etc.) are defined in some other files. Basically the router should manage a mapping table of private/global addresses. I want to get the real-time state of the mapping table from router device.
From previous discussions, I found out that the TransAPI module is needed, and callback functions are required to get the state data from the router device, and I'm working on transforming my yang module into the TransAPi module. I'm a bit confused about how to get the actual state data from the router using callback functions. Do I need to add some functions to the original code of the router? According to the TransAPI tutotial, the callback functions should be added to the .c file generated by lnctool, how do I correlate between the callback functions and the code in the original router operation files?

Thanks,
Peter

Michal Vasko

unread,
Apr 14, 2015, 3:11:31 AM4/14/15
to neto...@googlegroups.com
Hi Peter,

I believe you're talking about NAT, not that it matters actually. Your question, however, is without much details, therefore I can only give a general answer.

Based on what you said you likely want to send a <get> RPC and in it you receive all the state data, which we then want to extend to include your NAT table. If you look into your generated *.c file, you will find a "get_state_data()" function. All you need to do is make this function return an XML document with this table, it should also conform to the format specified in your YANG (all the state data). My guess is that in that function you will build the XML structure step-by-step, while filling the node values using functions from "the original router operation files".

Regards,
Michal

peter...@gmail.com

unread,
Apr 14, 2015, 3:49:23 AM4/14/15
to neto...@googlegroups.com
Hi,

So I believe what you mean is that the original router code should have a function defined to return the mapping table data, this function should be called in the .c file containing the rpc callback function (the one generated using lnctool), and the callback function's purpose is to transform this acquired data into xml document conforming to the format specified in the YANG file.

So the rpc callback function should perform the following functions:

1)calls the function in original router code that returns real-time mapping table data
2)creates XML document according to format specified in the YANG file
3)add the data of the mapping table into the corresponding nodes in the XML document
4)return the XML document

Is my understanding correct?

Best Regards,
Peter

在 2015年4月14日星期二 UTC+8上午11:36:51,peter...@gmail.com写道:

Michal Vasko

unread,
Apr 14, 2015, 6:11:42 AM4/14/15
to neto...@googlegroups.com
Hi Peter

Dňa utorok, 14. apríla 2015 9:49:23 UTC+2 peter...@gmail.com napísal(-a):
Hi,

So I believe what you mean is that the original router code should have a function defined to return the mapping table data, this

I just assumed this, it does not matter how you get the data, for simplification we can imagine a function that returns it.
 
function should be called in the .c file containing the rpc callback function (the one generated using lnctool), and the callback

Careful here, it is a bit more complicated than that. You said that you want to return the table as state data (meaning NETCONF state data, in the YANG model marked with the attribute "config false"). Therefore I referenced you to a particular callback "get_state_data()", whose purpose is to return all the state data of a transAPI module. Then there usually are more calbacks generated based on the paths file used, more about this in the tutorial, but you should know all this now.
 
function's purpose is to transform this acquired data into xml document conforming to the format specified in the YANG file.

As I said, "get_state_data()" should return all the state data, any other callback a particular subtree of the configuration data.
 

So the rpc callback function should perform the following functions:

Now it sounds to me as if you're talking about a custom RPC defined in your YANG model. It can be implemented that way too, but I am talking about something else, so you'll have to explicitly state that you want to use a custom RPC, not the standard NETCONF <get>. Note that almost all the standard NETCONF RPCs (particularly <get> in this case) are handled internally by libnetconf, which will call your "get_state_data()" eventually, so you do not need any custom RPC definition for that.
 

1)calls the function in original router code that returns real-time mapping table data
2)creates XML document according to format specified in the YANG file
3)add the data of the mapping table into the corresponding nodes in the XML document
4)return the XML document

This seems basically fine.
 

Is my understanding correct?

Best Regards,
Peter

Regards,
Michal
Reply all
Reply to author
Forward
0 new messages