Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

RMLeakyBucketControl.c

Go to the documentation of this file.
00001 /* This file was generated by mib2c and is intended for use as a mib module
00002    for the ucd-snmp snmpd agent. */
00003 
00004 #include <netinet/in.h>
00005 
00006 #ifdef IN_UCD_SNMP_SOURCE
00007 /* If we're compiling this file inside the ucd-snmp source tree */
00008 
00009 
00010 /* This should always be included first before anything else */
00011 #include <config.h>
00012 
00013 
00014 /* minimal include directives */
00015 #include "mibincl.h"
00016 #include "util_funcs.h"
00017 
00018 
00019 #else /* !IN_UCD_SNMP_SOURCE */
00020 
00021 
00022 #include <ucd-snmp/ucd-snmp-config.h>
00023 #include <ucd-snmp/ucd-snmp-includes.h>
00024 #include <ucd-snmp/ucd-snmp-agent-includes.h>
00025 
00026 
00027 #endif /* !IN_UCD_SNMP_SOURCE */
00028 
00029 
00030 #include "RMLeakyBucketControl.h"
00031 
00032 #include "rmClient.h"
00033 #include "utility.h"    
00034  
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <ucd-snmp/util_funcs.h>
00038 
00039 
00040 /* 
00041  * RMLeakyBucketControl_variables_oid:
00042  *   this is the top level oid that we want to register under.  This
00043  *   is essentially a prefix, with the suffix appearing in the
00044  *   variable below.
00045  */
00046 
00047 
00048 oid RMLeakyBucketControl_variables_oid[] = { 1,3,6,1,4,1,343,2,15,1,2,3,4 };
00049 
00050 
00051 /* 
00052  * variable4 RMLeakyBucketControl_variables:
00053  *   this variable defines function callbacks and type return information 
00054  *   for the RMLeakyBucketControl mib section 
00055  */
00056 
00057 
00058 struct variable4 RMLeakyBucketControl_variables[] = {
00059 /*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
00060 #define   LEAKYBUCKETCONTROLNEXTINDEX  1
00061   { LEAKYBUCKETCONTROLNEXTINDEX, ASN_UNSIGNED  , RONLY , var_RMLeakyBucketControl, 1, { 1 } },
00062 #define   LEAKYBUCKETLOGGINGRATE  5
00063   { LEAKYBUCKETLOGGINGRATE, ASN_TIMETICKS , RWRITE, var_LeakyBucketControlTable, 3, { 2,1,2 } },
00064 #define   LEAKYBUCKETCONTROLREFCOUNT  6
00065   { LEAKYBUCKETCONTROLREFCOUNT, ASN_INTEGER   , RONLY , var_LeakyBucketControlTable, 3, { 2,1,3 } },
00066 #define   LEAKYBUCKETCONTROLSTATUS  7
00067   { LEAKYBUCKETCONTROLSTATUS, ASN_INTEGER   , RWRITE, var_LeakyBucketControlTable, 3, { 2,1,4 } },
00068 
00069 };
00070 /*    (L = length of the oidsuffix) */
00071 
00072 
00073 /*
00074  * init_RMLeakyBucketControl():
00075  *   Initialization routine.  This is called when the agent starts up.
00076  *   At a minimum, registration of your variables should take place here.
00077  */
00078 void init_RMLeakyBucketControl(void) {
00079 
00080 
00081   /* register ourselves with the agent to handle our mib tree */
00082   REGISTER_MIB("RMLeakyBucketControl", RMLeakyBucketControl_variables, variable4,
00083                RMLeakyBucketControl_variables_oid);
00084 
00085 
00086   /* place any other initialization junk you need here */
00087 }
00088 
00089 
00090 /*
00091  * var_RMLeakyBucketControl():
00092  *   This function is called every time the agent gets a request for
00093  *   a scalar variable that might be found within your mib section
00094  *   registered above.  It is up to you to do the right thing and
00095  *   return the correct value.
00096  *     You should also correct the value of "var_len" if necessary.
00097  *
00098  *   Please see the documentation for more information about writing
00099  *   module extensions, and check out the examples in the examples
00100  *   and mibII directories.
00101  */
00102 unsigned char *
00103 var_RMLeakyBucketControl(struct variable *vp, 
00104                 oid     *name, 
00105                 size_t  *length, 
00106                 int     exact, 
00107                 size_t  *var_len, 
00108                 WriteMethod **write_method)
00109 {
00110 
00111 
00112   /* variables we may use later */
00113   static u_long ulong_ret;
00114 
00115   if (header_generic(vp,name,length,exact,var_len,write_method)
00116                                   == MATCH_FAILED )
00117     return NULL;
00118 
00119 
00120   /* 
00121    * this is where we do the value assignments for the mib results.
00122    */
00123   switch(vp->magic) {
00124 
00125 
00126     case LEAKYBUCKETCONTROLNEXTINDEX:
00127         
00128         ulong_ret = getNewId(LEAKYBUCKETCONTROL);
00129         return (unsigned char *) &ulong_ret;
00130 
00131 
00132     default:
00133       ERROR_MSG("");
00134   }
00135   return NULL;
00136 }
00137 
00138 
00139 /*
00140  * var_LeakyBucketControlTable():
00141  *   Handle this table separately from the scalar value case.
00142  *   The workings of this are basically the same as for var_RMLeakyBucketControl above.
00143  */
00144 unsigned char *
00145 var_LeakyBucketControlTable(struct variable *vp,
00146             oid     *name,
00147             size_t  *length,
00148             int     exact,
00149             size_t  *var_len,
00150             WriteMethod **write_method)
00151 {
00152 
00153 
00154   /* variables we may use later */
00155   static long long_ret;
00156 
00157   unsigned long id;
00158 
00159   id = header_MyGeneric(vp,name,length,exact,var_len,write_method, LEAKYBUCKETCONTROL);
00160   if(id == 0) {
00161     switch(vp->magic) {
00162 
00163       case LEAKYBUCKETLOGGINGRATE:
00164           *write_method = write_leakyBucketLoggingRate;
00165           break;
00166 
00167       case LEAKYBUCKETCONTROLSTATUS:
00168           *write_method = write_leakyBucketControlStatus;
00169           break;
00170 
00171 
00172       default:
00173         ERROR_MSG("");
00174     }
00175     return NULL;
00176   }
00177 
00178 
00179   /* 
00180    * this is where we do the value assignments for the mib results.
00181    */
00182   switch(vp->magic) {
00183 
00184 
00185     case LEAKYBUCKETLOGGINGRATE:
00186         *write_method = write_leakyBucketLoggingRate;
00187         long_ret = 0;
00188         getInteger32(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_LOGGINGRATE, id, &long_ret);
00189         return (unsigned char *) &long_ret;
00190 
00191     case LEAKYBUCKETCONTROLREFCOUNT:
00192         
00193         long_ret = 0;
00194         getInteger32(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_REFCOUNT, id, &long_ret);
00195         return (unsigned char *) &long_ret;
00196 
00197     case LEAKYBUCKETCONTROLSTATUS:
00198         *write_method = write_leakyBucketControlStatus;
00199         long_ret = 0;
00200         getInteger32(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_STATUS, id, &long_ret);
00201         return (unsigned char *) &long_ret;
00202 
00203 
00204     default:
00205       ERROR_MSG("");
00206   }
00207   return NULL;
00208 }
00209 
00210 
00211 
00212 
00213 int
00214 write_leakyBucketLoggingRate(int      action,
00215             u_char   *var_val,
00216             u_char   var_val_type,
00217             size_t   var_val_len,
00218             u_char   *statP,
00219             oid      *name,
00220             size_t   name_len)
00221 {
00222   static long *long_ret;
00223   int size;
00224 
00225   int createNew, ret;
00226   unsigned long id;
00227   size_t prefix_len;
00228 
00229   static unsigned long oldVal;
00230 
00231   oid suffix[] = { 2, 1, 2 };
00232   createNew = 0;
00233   prefix_len = sizeof(RMLeakyBucketControl_variables_oid)/sizeof(oid);
00234 
00235   id = header_writeGeneric(name, name_len, RMLeakyBucketControl_variables_oid, prefix_len, suffix, 3, LEAKYBUCKETCONTROL, &createNew);
00236 
00237   if(id == 0 || (createNew && action == ACTION))
00238     return SNMP_ERR_NOSUCHNAME;
00239 
00240 
00241 
00242   switch ( action ) {
00243         case RESERVE1:
00244           if (var_val_type != ASN_TIMETICKS){
00245               fprintf(stderr, "write to leakyBucketLoggingRate not ASN_TIMETICKS\n");
00246               return SNMP_ERR_WRONGTYPE;
00247           }
00248           if (var_val_len > sizeof(long_ret)){
00249               fprintf(stderr,"write to leakyBucketLoggingRate: bad length\n");
00250               return SNMP_ERR_WRONGLENGTH;
00251           }
00252           break;
00253 
00254 
00255         case RESERVE2:
00256           size = var_val_len;
00257           long_ret = (long *) var_val;
00258 
00259           if(!createNew) {
00260             ret = getUnsigned(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_LOGGINGRATE, id, &oldVal);
00261             if(ret)
00262               return SNMP_ERR_INCONSISTENTVALUE;
00263           }
00264 
00265 
00266           break;
00267 
00268 
00269         case FREE:
00270              /* Release any resources that have been allocated */
00271           break;
00272 
00273 
00274         case ACTION:
00275              /* The variable has been stored in long_ret for
00276              you to use, and you have just been asked to do something with
00277              it.  Note that anything done here must be reversable in the UNDO case */
00278           ret = setUnsigned(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_LOGGINGRATE, id, ( (unsigned long) *long_ret )/ 100);
00279           if(ret)
00280             return SNMP_ERR_INCONSISTENTVALUE;
00281 
00282           break;
00283 
00284 
00285         case UNDO:
00286              /* Back out any changes made in the ACTION case */
00287           setUnsigned(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_LOGGINGRATE, id, oldVal);
00288           break;
00289 
00290 
00291         case COMMIT:
00292              /* Things are working well, so it's now safe to make the change
00293              permanently.  Make sure that anything done here can't fail! */
00294           break;
00295   }
00296   return SNMP_ERR_NOERROR;
00297 }
00298 
00299 
00300 
00301 
00302 int
00303 write_leakyBucketControlStatus(int      action,
00304             u_char   *var_val,
00305             u_char   var_val_type,
00306             size_t   var_val_len,
00307             u_char   *statP,
00308             oid      *name,
00309             size_t   name_len)
00310 {
00311   static long *long_ret;
00312   int size;
00313 
00314   int createNew, ret;
00315   unsigned long id;
00316   size_t prefix_len;
00317 
00318   static long oldStatus;
00319   static int rowCreated;
00320 
00321   oid suffix[] = { 2, 1, 4 };
00322   createNew = 0;
00323   prefix_len = sizeof(RMLeakyBucketControl_variables_oid)/sizeof(oid);
00324 
00325   id = header_writeGeneric(name, name_len, RMLeakyBucketControl_variables_oid, prefix_len, suffix, 3, LEAKYBUCKETCONTROL, &createNew);
00326 
00327 
00328   switch ( action ) {
00329         case RESERVE1:
00330           if (var_val_type != ASN_INTEGER){
00331               fprintf(stderr, "write to leakyBucketControlStatus not ASN_INTEGER\n");
00332               return SNMP_ERR_WRONGTYPE;
00333           }
00334           if (var_val_len > sizeof(long_ret)){
00335               fprintf(stderr,"write to leakyBucketControlStatus: bad length\n");
00336               return SNMP_ERR_WRONGLENGTH;
00337           }
00338           break;
00339 
00340 
00341         case RESERVE2:
00342           size = var_val_len;
00343           long_ret = (long *) var_val;
00344 
00345           rowCreated = 0;
00346           oldStatus = 0;
00347           if (*long_ret < ACTIVE || *long_ret > DESTROY ||
00348                *long_ret == NOTREADY)
00349             return SNMP_ERR_INCONSISTENTVALUE;
00350 
00351           if(createNew &&
00352               (*long_ret != CREATEANDWAIT && *long_ret != CREATEANDGO))
00353             return SNMP_ERR_INCONSISTENTVALUE;
00354 
00355           if (*long_ret == NOTINSERVICE || *long_ret == ACTIVE) {
00356             ret = getInteger32(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_STATUS, id, &oldStatus);
00357             if(ret)
00358               return SNMP_ERR_INCONSISTENTVALUE;
00359           }
00360 
00361 
00362           break;
00363 
00364 
00365         case FREE:
00366              /* Release any resources that have been allocated */
00367           break;
00368 
00369 
00370         case ACTION:
00371              /* The variable has been stored in long_ret for
00372              you to use, and you have just been asked to do something with
00373              it.  Note that anything done here must be reversable in the UNDO case */
00374           if(*long_ret == CREATEANDWAIT || *long_ret == CREATEANDGO) {
00375             ret = newEntry(LEAKYBUCKETCONTROL, id);
00376             if(ret)
00377               return SNMP_ERR_INCONSISTENTVALUE;
00378 
00379             rowCreated = 1;
00380           }
00381           else if (*long_ret == NOTINSERVICE || *long_ret == ACTIVE) {
00382             ret = setInteger32(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_STATUS, id, *long_ret);
00383             if(ret)
00384               return SNMP_ERR_INCONSISTENTVALUE;
00385           }
00386           else if(*long_ret == DESTROY) {
00387             ret = deleteEntry(LEAKYBUCKETCONTROL, id);
00388             if(ret)
00389               return SNMP_ERR_INCONSISTENTVALUE;
00390           }
00391           break;
00392 
00393 
00394         case UNDO:
00395              /* Back out any changes made in the ACTION case */
00396           if(rowCreated) {
00397             deleteEntry(LEAKYBUCKETCONTROL, id);
00398           }
00399           else if(*long_ret == NOTINSERVICE || *long_ret == ACTIVE) {
00400             if(oldStatus != 0)
00401               setInteger32(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_STATUS, id, oldStatus);
00402           }
00403           else if((*long_ret == DESTROY)) {
00404 
00405             // note: don't know how to do this yet. need to be fixed.
00406 
00407           }
00408 
00409           break;
00410 
00411 
00412         case COMMIT:
00413              /* Things are working well, so it's now safe to make the change
00414              permanently.  Make sure that anything done here can't fail! */
00415           if(*long_ret == CREATEANDGO) {
00416             ret = setInteger32(LEAKYBUCKETCONTROL, LEAKYBUCKETCONTROL_STATUS, id, ACTIVE);
00417             if(ret) {
00418               deleteEntry(LEAKYBUCKETCONTROL, id);
00419               return SNMP_ERR_COMMITFAILED;
00420             }
00421           }
00422           break;
00423   }
00424   return SNMP_ERR_NOERROR;
00425 }
00426 
00427 
00428 
00429 
00430 
00431 

Generated on Tue Sep 10 16:46:33 2002 for ResourceMonitorSNMPSubagent by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002