mibble-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Mibble-users] Reverse usage of mibble


From: Per Cederberg
Subject: Re: [Mibble-users] Reverse usage of mibble
Date: Mon, 15 Mar 2004 09:50:13 +0100

On Mon, 2004-03-15 at 04:13, wshang wrote:
> Hi, thanks for your answer.
> But there is an another question,
> For example , sysDescr -- 1.3.6.1.2.1.1.1, 
> we use 1.3.6.1.2.1.1.1.0 for get,getnext and  other operations. if you pass 
> 1.3.6.1.2.1.1.1.0 to Mib.getSymbolByValue(String), you will get null . you 
> must pass 1.3.6.1.2.1.1.1 to Mib.getSymbolByValue(). 
> but how can I know which oid should I use?
> 1.3.6.1.2.1.1.1 ?
> 1.3.6.1.2.1.1.1.0 ?
> 1.3.6.1.2.1.1?
> ...
>  
> I can't simply cut the ".0" from the oid because it is not fit for the table.

Yes, tables are problematic. As far as I have seen, most of the 
tableEntry symbols in the MIBs are declared to have an oid ending
with .1 (not .0) so that might help in some cases.

In the general case, however, Mibble does not provide any real
intelligence for reverse lookup (oid -> symbol). It might be
possible to implement with something like this:

  MibValueSymbol findSymbolByOid(Mib mib, String oid) {
       MibValueSymbol  sym;
       int             pos;
       int             value;

       sym = mib.getSymbolByValue(oid);
       if (sym == null) {
           pos = oid.lastIndexOf(".");
           if (pos > 0) {
               sym = findSymbolByOid(mib, oid.substring(0, pos));
           }
           if (sym != null) {
               value = Integer.parseInt(oid.substring(pos + 1));
               sym = findSymbolChild(sym, value);
           }
       }
       return sym;
  }

  MibValueSymbol findSymbolChild(MibValueSymbol sym, int value) {
      ObjectIdentifierValue  oid;

      if (!(sym.getValue() instanceof ObjectIdentifierValue)) {
          return null;
      }
      oid = (ObjectIdentifierValue) sym.getValue();
      for (int i = 0; i < oid.getChildCount(); i++) {
          if (oid.getChild(i).getValue() == value) {
              return oid.getChild(i).getSymbol();
          }
      }
      if (oid.getChildCount() == 1) {
          return oid.getChild(0).getSymbol();
      }
      return null;
  }

I haven't had time to test the code above, so it might still 
contain compilation errors (and other errors as well). Please
test and write back and tell me if it worked or not. If it
works I might include it somewhere in the next release.

Cheers,

/Per






reply via email to

[Prev in Thread] Current Thread [Next in Thread]