Persistency model

Hello,

I would like to know how persistence model for AGENT++ works?

What I mean here is once when Mib is instantiated providing the persistent object path to a file in disk/flash/etc:

  1. What from user application have to be done to have those files save in the provided path?
  2. Are changes in any leaf saved automatically to the provided file for the module the leaf
    belongs to?

Please, help.

Regards,
Safet

Hello,

to set the path you have to create the Mib using either one of the constructors with persistentObjectsPath parameter or you can set it using the Mib::set_persistent_objects_path() function.

The default is to only save the data when the Mib object is destroyed. Then the files are updated with the current data. You can manually call Mib::save_all() if needed.

Kind regards,
Jochen

Hello Jochen,

How about if the it never happens that Mib object is destroyed? Like if the is a system crash or application terminate abruptly?

I know that I can catch some set of signals and call call Mib::save_all() if needed.
Is there any way to get a global notification that any Leaf has changed and save changes in the files as they happening?

Everything is saved in that virtual database ‘Mib’ and handled by a common Request list. so any SET request would be possible to detect and have callback to do a user required action. Is there something like this implemented already?

Regards,
Safet

Hello Safet,

AGENT++ cannot randomly write objects, but it can write the content of a MibGroup individually.
Unlike in SNMP4J-Agent(-DB) there is no generic mechanism in AGENT++ to persistent changes immediately.

I recommend writing a subclasses of MibLeaf and MibTable to accomplish that in their commit_set_request methods.

Best regards,
Frank

Hello Frank,

Thank you for the help. One more question here: is there any way after processing a request by ‘Mib’ class to know if there where changes done and just simple call save-all if any?

	req = reqList->receive(2);

	if (req) {
	    mib->process_request(req);

-------------> Check for changes and save-all <---------------------------------------------

During the configuring an agent this could be a bit of overhead, but after it during run time mostly will be read request.

Regards,
Safet

Hello,

if you’re using threads, the mib->process_request() function returns while the request is still being executed.

There is no information if something was changed through a request. I would suggest the following in the main loop: If the request req is a set request, remember that you should save the mib and call save_all() after some time.

If you’re just interested in changes of your own mib table / leaf classes, you could set a global flag whenever a set was processed successfully. So in the main loop it could be checked if a save is needed.

Kind regards,
Jochen

Hi Jochen,

That would work for me as for now I am interested only in capturing changes in common SNMP MIBs included in my project.
What would be the best way to check if a request is a set request? Would it be get_type()?

Regards,
Safet

Hello Safet,

yes, the value to check for is sNMP_PDU_SET (from smi.h).

Kind regards,
Jochen

Thank you Frank and Jochen for your help.

Regards,
Safet

In addition to the code you use, you should also make sure that you synchronise your write operation(s) with possible read/write operations of the AGENT++ framework.

See the following FAQ article for details:
https://doc.snmp.app/pages/viewpage.action?pageId=5799965