Logo Search packages:      
Sourcecode: airport-utils version File versions  Download package

SNMPVarBindList snmp::SNMPv1CommunicationInterface::retrieveMIBTable ( String[]  baseID  )  throws IOException, SNMPBadValueException, SNMPGetException [inline]

Retrieve all MIB variable values whose OIDs start with the supplied baseIDs. The normal way for this to be used is for the base OID array to consist of the base OIDs of the columns of a table. This method will then retrieve all of the entries of the table corresponding to these columns, one row at a time (i.e., the entries for each row will be retrieved in a single SNMP request). This will retrieve the table data as an SNMPVarBindList object consisting of sequence of SNMPVariablePairs, with the entries for each row grouped together. This may provide a more convenient arrangement of the table data than the simpler retrieveMIBTable method taking a single OID as argument; in addition, it's more efficient, requiring one SNMP request per row rather than one request per entry. Uses SNMPGetNextRequests to retrieve variable values for each row in sequence.

Exceptions:
IOException Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException 
SNMPGetException Thrown if incomplete row retrieved

Definition at line 1039 of file SNMPv1CommunicationInterface.java.

References snmp::SNMPSequence::addSNMPObject(), snmp::SNMPSequence::getBEREncoding(), snmp::SNMPPDU::getErrorIndex(), snmp::SNMPMessage::getPDU(), snmp::SNMPSequence::getSNMPObjectAt(), snmp::SNMPSequence::size(), and snmp::SNMPObjectIdentifier::toString().

      {
            // send GetNextRequests until receive
            // an error message or a repeat of the object identifier we sent out
            SNMPVarBindList retrievedVars = new SNMPVarBindList();
            
            int errorStatus = 0;
            int errorIndex = 0;
            
            SNMPObjectIdentifier[] requestedObjectIdentifier = new SNMPObjectIdentifier[baseID.length];
            for (int i = 0; i < baseID.length; i++)
      {
                  requestedObjectIdentifier[i] = new SNMPObjectIdentifier(baseID[i]);
      }
      

retrievalLoop:
            
            while (errorStatus == 0)
            {
                  
                  SNMPSequence varList = new SNMPSequence();
            
            for (int i = 0; i < requestedObjectIdentifier.length; i++)
            {
                  SNMPVariablePair nextPair = new SNMPVariablePair(requestedObjectIdentifier[i], new SNMPInteger(0));
                  varList.addSNMPObject(nextPair);
            }
            
          SNMPPDU pdu = new SNMPPDU(SNMPBERCodec.SNMPGETNEXTREQUEST, requestID, errorStatus, errorIndex, varList);
            SNMPMessage message = new SNMPMessage(version, community, pdu);
            
            byte[] messageEncoding = message.getBEREncoding();
            
            DatagramPacket outPacket = new DatagramPacket(messageEncoding, messageEncoding.length, hostAddress, SNMPPORT);
            
            /*
            System.out.println("Request bytes:");
            
            for (int i = 0; i < messageEncoding.length; ++i)
            {
                  System.out.print(getHex(messageEncoding[i]) + " ");
            }
            */
            
            dSocket.send(outPacket);
            
            
            DatagramPacket inPacket = new DatagramPacket(new byte[receiveBufferSize], receiveBufferSize);
            
                  dSocket.receive(inPacket);
                  
                  byte[] encodedMessage = inPacket.getData();
                  
                  /*
            System.out.println("Received bytes:");
            
            for (int i = 0; i < 128; ++i)
            {
                  System.out.print(hexByte(encodedMessage[i]) + " ");
            }
            */
            
                  
                  SNMPMessage receivedMessage = new SNMPMessage(SNMPBERCodec.extractNextTLV(encodedMessage,0).value);
                  SNMPPDU receivedPDU = receivedMessage.getPDU();
                  
                  // check request identifier; if incorrect, just ignore packet and continue waiting
                  if (receivedPDU.getRequestID() == requestID)
                  {
                        
                        // check error status; if retrieval problem for error index 1, just break - assume there are no additional OIDs
                        // to retrieve. If index is other than 1, throw exception
                        if (receivedPDU.getErrorStatus() != 0)
                        {
                              int retrievedErrorIndex = receivedPDU.getErrorIndex();
                              
                              if (retrievedErrorIndex == 1)
                              {
                                  break retrievalLoop;
                              }
                              else
                              {
                                  throw new SNMPGetException("OID following " + requestedObjectIdentifier[retrievedErrorIndex - 1] + " not available for retrieval", retrievedErrorIndex, receivedPDU.getErrorStatus());
                              }     
                        }
                        
                        // copy info from retrieved sequence to var bind list
                        varList = receivedPDU.getVarBindList();
                        
                        // make sure got the right number of vars in reply; if not, throw GetException
                        if(varList.size() != requestedObjectIdentifier.length)
                        {
                            throw new SNMPGetException("Incomplete row of table received", 0, SNMPRequestException.FAILED);
                        }
                        
                        // copy the retrieved variable pairs into retrievedVars
                        for (int i = 0; i < varList.size(); i++)
                  {
                        SNMPSequence newPair = (SNMPSequence)(varList.getSNMPObjectAt(i));
                        
                        SNMPObjectIdentifier newObjectIdentifier = (SNMPObjectIdentifier)(newPair.getSNMPObjectAt(0));
                        SNMPObject newValue = newPair.getSNMPObjectAt(1);
                        
                        // now see if retrieved ID starts with table base; if not, done with table - break
                        String newOIDString = (String)newObjectIdentifier.toString();
                        if (!newOIDString.startsWith(baseID[i]))
                        {
                              if (i == 0)
                              {
                                    // it's the first element of the row; just break
                                    break retrievalLoop;
                              }
                              else
                              {
                                  // it's a subsequent row element; throw exception
                                  throw new SNMPGetException("Incomplete row of table received", i+1, SNMPRequestException.FAILED);
                              }
                        }
                              
                        retrievedVars.addSNMPObject(newPair);
                        
                        // set requested identifiers array to current identifiers to do get-next for next row
                      requestedObjectIdentifier[i] = newObjectIdentifier;
                        }
                        
                  
                  requestID++;
                  
                  }
                  
                  
            }
                  
            
            return retrievedVars;
            
      }


Generated by  Doxygen 1.6.0   Back to index