

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.net-snmp.org/wiki/index.php?action=history&amp;feed=atom&amp;title=MFD%3AifXTable%3AData_Access</id>
		<title>MFD:ifXTable:Data Access - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.net-snmp.org/wiki/index.php?action=history&amp;feed=atom&amp;title=MFD%3AifXTable%3AData_Access"/>
		<link rel="alternate" type="text/html" href="http://www.net-snmp.org/wiki/index.php?title=MFD:ifXTable:Data_Access&amp;action=history"/>
		<updated>2026-05-04T21:19:29Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.3</generator>

	<entry>
		<id>http://www.net-snmp.org/wiki/index.php?title=MFD:ifXTable:Data_Access&amp;diff=5178&amp;oldid=prev</id>
		<title>Wes: Created page with &quot;{{MFDTutorial}}      == MFD : ifXTable data access ==      The net-snmp access routine returns a container of &#039;&#039;netsnmp_interface_entry&#039;&#039; pointers that contain a snapshot of the ...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.net-snmp.org/wiki/index.php?title=MFD:ifXTable:Data_Access&amp;diff=5178&amp;oldid=prev"/>
				<updated>2011-07-13T21:56:48Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{MFDTutorial}}      == MFD : ifXTable data access ==      The net-snmp access routine returns a container of &amp;#039;&amp;#039;netsnmp_interface_entry&amp;#039;&amp;#039; pointers that contain a snapshot of the ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{MFDTutorial}}&lt;br /&gt;
    &lt;br /&gt;
== MFD : ifXTable data access ==&lt;br /&gt;
    &lt;br /&gt;
The net-snmp access routine returns a container of&lt;br /&gt;
&amp;#039;&amp;#039;netsnmp_interface_entry&amp;#039;&amp;#039; pointers that contain a snapshot&lt;br /&gt;
of the current data. However, as I mentioned before, this structure&lt;br /&gt;
does not contain all the data we need for ifXTable mib. For example,&lt;br /&gt;
the Linux kernel doesn&amp;#039;t report the last time an interface was&lt;br /&gt;
changed. We have to periodically poll for the interfaces, and check&lt;br /&gt;
to see if each entry has changed. This polling has the added&lt;br /&gt;
benefit of always keeping our cache current.&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
=== Initialization ===&lt;br /&gt;
    &lt;br /&gt;
When the agent starts up and initializes, the&lt;br /&gt;
&amp;#039;&amp;#039;ifXTable_init_data&amp;#039;&amp;#039; function will be called to allow us to&lt;br /&gt;
do any initilization for our data access functions. We don&amp;#039;t have any,&lt;br /&gt;
so we&amp;#039;ll just leave the function body empty.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;cached-container&amp;#039;&amp;#039; access method also has it&amp;#039;s own&lt;br /&gt;
initilization routine, &amp;#039;&amp;#039;ifXTable_container_init&amp;#039;&amp;#039;. This&lt;br /&gt;
allow you to use a custom container or tweak the cache parameters.&lt;br /&gt;
We&amp;#039;ll cover both of these more advanced topic in a later tutorial.&lt;br /&gt;
For now, we&amp;#039;ll leave the function body alone, using the default&lt;br /&gt;
container and default cache parameters.&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
=== Loading the cache ===&lt;br /&gt;
    &lt;br /&gt;
      &lt;br /&gt;
    &lt;br /&gt;
    &amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td width=20&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td bgcolor=CCCCCC&amp;gt;&lt;br /&gt;
 int&lt;br /&gt;
 ifXTable_cache_load(netsnmp_container * container)&lt;br /&gt;
 {&amp;lt;font color=blue&amp;gt;&lt;br /&gt;
     netsnmp_container * ifcontainer;&amp;lt;/font&amp;gt;&lt;br /&gt;
     ifXTable_rowreq_ctx *rowreq_ctx;&lt;br /&gt;
 &lt;br /&gt;
     DEBUGMSGTL((&amp;quot;verbose:ifXTable_cache_load&amp;quot;, &amp;quot;called\n&amp;quot;));&lt;br /&gt;
 &lt;br /&gt;
     /*&lt;br /&gt;
      * TODO: update container&lt;br /&gt;
      *&lt;br /&gt;
      * loop over your data, allocate, set index, insert into the container&lt;br /&gt;
      */&amp;lt;font color=blue&amp;gt;&lt;br /&gt;
     /*&lt;br /&gt;
      * get a container of netsnmp_interface_entry pointers from&lt;br /&gt;
      * the data access routine.&lt;br /&gt;
      */&lt;br /&gt;
     ifcontainer =&lt;br /&gt;
         netsnmp_access_interface_container_load(NULL,&lt;br /&gt;
                                                 NETSNMP_ACCESS_INTERFACE_INIT_NOFLAGS);&lt;br /&gt;
 &lt;br /&gt;
     /*&lt;br /&gt;
      * netsnmp_containers don&amp;#039;t have efficient iterators yet, so use the&lt;br /&gt;
      * foreach macro to get a callback for each interface.&lt;br /&gt;
      */&lt;br /&gt;
     CONTAINER_FOR_EACH(ifcontainer,&lt;br /&gt;
                        (netsnmp_container_obj_func*)_check_interface_entry_for_updates,&lt;br /&gt;
                        container);&lt;br /&gt;
 &lt;br /&gt;
     /*&lt;br /&gt;
      * free the container. we&amp;#039;ve either claimed each ifentry, or released it,&lt;br /&gt;
      * so the dal function doesn&amp;#039;t need to clear the container.&lt;br /&gt;
      */&lt;br /&gt;
     netsnmp_access_interface_container_free(ifcontainer,&lt;br /&gt;
                                             NETSNMP_ACCESS_INTERFACE_FREE_DONT_CLEAR );&lt;br /&gt;
               &amp;lt;/font&amp;gt;&lt;br /&gt;
     return MFD_SUCCESS;&lt;br /&gt;
 }&lt;br /&gt;
     while (1) {&lt;br /&gt;
         /*&lt;br /&gt;
          * TODO: check for end of data&lt;br /&gt;
          *&lt;br /&gt;
          * bail out if there is no more data&lt;br /&gt;
          */&lt;br /&gt;
         if (ifXTable_OUT_OF_DATA())&lt;br /&gt;
             break;&lt;br /&gt;
 &lt;br /&gt;
         /*&lt;br /&gt;
          * allocate an row context and set the index(es)&lt;br /&gt;
          */&lt;br /&gt;
         rowreq_ctx = ifXTable_allocate_rowreq_ctx(NULL);&lt;br /&gt;
         if (MFD_SUCCESS != ifXTable_indexes_set(rowreq_ctx, ifIndex)) {&lt;br /&gt;
             snmp_log(LOG_ERR, &amp;quot;error setting index while loading &amp;quot;&lt;br /&gt;
                      &amp;quot;ifXTable cache.\n&amp;quot;);&lt;br /&gt;
             ifXTable_release_rowreq_ctx(rowreq_ctx);&lt;br /&gt;
             continue;&lt;br /&gt;
         }&lt;br /&gt;
 &lt;br /&gt;
         /*&lt;br /&gt;
          * TODO: populate data context&lt;br /&gt;
          */&lt;br /&gt;
         /*&lt;br /&gt;
          * TRANSIENT or semi-TRANSIENT data:&lt;br /&gt;
          * can copy data in row_prep or here, depending on when you&lt;br /&gt;
          * want to take the hit. Either copy the data now, or save&lt;br /&gt;
          * any info needed and do it in row_prep.&lt;br /&gt;
          */&lt;br /&gt;
 &lt;br /&gt;
         /*&lt;br /&gt;
          * insert into table container&lt;br /&gt;
          */&lt;br /&gt;
         CONTAINER_INSERT(container, rowreq_ctx);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     return MFD_SUCCESS;&lt;br /&gt;
&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wes</name></author>	</entry>

	</feed>