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

SNMPVarBindList snmp::SNMPv1CommunicationInterface::setMIBEntry ( String[]  itemID,
SNMPObject[]  newValue 
) throws IOException, SNMPBadValueException, SNMPSetException [inline]

Set the MIB variable values of the supplied object identifiers given in the itemID array (in dotted-integer notation). Return SNMPVarBindList returned by device in its response; can be used to check that setting was successful. Uses SNMPGetNextRequests to retrieve variable values in sequence.

Exceptions:
IOException Thrown when timeout experienced while waiting for response to request.
SNMPBadValueException 

Definition at line 787 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().

      {
            // check that OID and value arrays have same size
            if (itemID.length != newValue.length)
            {
                throw new SNMPSetException("OID and value arrays must have same size", 0, SNMPRequestException.FAILED);
            }
            
            
            // send SetRequest to specified host to set values of specified object identifiers
            
            SNMPVarBindList retrievedVars = new SNMPVarBindList();
            SNMPSequence varList = new SNMPSequence();
            
            int errorStatus = 0;
            int errorIndex = 0;
            
            
            for (int i = 0; i < itemID.length; i++)
            {
            SNMPObjectIdentifier requestedObjectIdentifier = new SNMPObjectIdentifier(itemID[i]);
            SNMPVariablePair nextPair = new SNMPVariablePair(requestedObjectIdentifier, newValue[i]);
            varList.addSNMPObject(nextPair);
            }
            
            SNMPPDU pdu = new SNMPPDU(SNMPBERCodec.SNMPSETREQUEST, requestID, errorStatus, errorIndex, varList);
            SNMPMessage message = new SNMPMessage(version, community, pdu);
            
            byte[] messageEncoding = message.getBEREncoding();
            
            /*
            System.out.println("Message bytes:");
            
            for (int i = 0; i < messageEncoding.length; ++i)
            {
                  System.out.print(getHex(messageEncoding[i]) + " ");
            }
            */
            
            
            DatagramPacket outPacket = new DatagramPacket(messageEncoding, messageEncoding.length, hostAddress, SNMPPORT);
            
            dSocket.send(outPacket);
            
            
            while (true)      // wait until receive reply for correct OID (or error)
            {
                  
                  DatagramPacket inPacket = new DatagramPacket(new byte[receiveBufferSize], receiveBufferSize);
                  
                  dSocket.receive(inPacket);
                  
                  byte[] encodedMessage = inPacket.getData();
                  
                  /*
                  System.out.println("Message bytes:");
                  
                  for (int i = 0; i < encodedMessage.length; ++i)
                  {
                        System.out.print((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, throw SNMPGetException
                        if (receivedPDU.getErrorStatus() != 0)
                        {
                              errorIndex = receivedPDU.getErrorIndex();
                              
                              switch (receivedPDU.getErrorStatus())
                              {
                                    case 1:
                                          throw new SNMPSetException("Value supplied for OID " + itemID[errorIndex - 1] + " too big.", receivedPDU.getErrorIndex(), receivedPDU.getErrorStatus());
                                    
                                    case 2:
                                          throw new SNMPSetException("OID " + itemID[errorIndex - 1] + " not available for setting.", receivedPDU.getErrorIndex(), receivedPDU.getErrorStatus());
                                    
                                    case 3:
                                          throw new SNMPSetException("Bad value supplied for OID " + itemID[errorIndex - 1] + ".", receivedPDU.getErrorIndex(), receivedPDU.getErrorStatus());
                                          
                                    case 4:
                                          throw new SNMPSetException("OID " + itemID[errorIndex - 1] + " read-only.", receivedPDU.getErrorIndex(), receivedPDU.getErrorStatus());
                                          
                                    default:
                                          throw new SNMPSetException("Error setting OID " + itemID[errorIndex - 1] + ".", receivedPDU.getErrorIndex(), receivedPDU.getErrorStatus());
                                          
                              }
                        }
                        
                        
                        // copy info from retrieved sequence to var bind list
                        varList = receivedPDU.getVarBindList();
                        
                        for (int i = 0; i < varList.size(); i++)
                  {
                        SNMPSequence newPair = (SNMPSequence)(varList.getSNMPObjectAt(i));
                        
                        SNMPObjectIdentifier newObjectIdentifier = (SNMPObjectIdentifier)(newPair.getSNMPObjectAt(0));
                        //SNMPObject receivedValue = newPair.getSNMPObjectAt(1);
                        
                        if (newObjectIdentifier.toString().equals(itemID[i]))
                        {
                            retrievedVars.addSNMPObject(newPair);
                        }
                        else
                        {
                              // wrong OID; throw GetException
                              throw new SNMPSetException("OID " + itemID[i] + " expected at index " + i + ", OID " + newObjectIdentifier + " received", i+1, SNMPRequestException.FAILED);
                        }
                        }
                        
                        break;
                  
                  }
                  
            }
            
            
            requestID++;
      
            
            return retrievedVars;
            
      }


Generated by  Doxygen 1.6.0   Back to index