ScopedPDU pdu = new ScopedPDU(); pdu.add( new VariableBinding( new OID( Oid ), new OctetString( messageString ) ) ); pdu.setType( PDU.TRAP ); if ( !Utils.isEmpty( engineID ) ) { pdu.setContextEngineID( new OctetString( engineID ) );
/** * Sets context engine ID and context name members on the given PDU if that PDU * is a {@link ScopedPDU}. * * @param pdu * a {@link PDU} instance which is modified if it is a {@link ScopedPDU} instance. * @since 2.5.0 */ protected void applyContextInfoToScopedPDU(PDU pdu) { if (pdu instanceof ScopedPDU) { ScopedPDU scopedPDU = (ScopedPDU)pdu; scopedPDU.setContextEngineID(contextEngineID); scopedPDU.setContextName(contextName); } }
private boolean isEmptyContextEngineID(PDU pdu) { if (pdu instanceof ScopedPDU) { ScopedPDU scopedPDU = (ScopedPDU) pdu; return ((scopedPDU.getContextEngineID() == null) || (scopedPDU.getContextEngineID().length() == 0)); } return false; }
StateReference stateReference, VariableBinding payload) { ScopedPDU reportPDU = new ScopedPDU(); reportPDU.setType(PDU.REPORT); if (pdu != null) { reportPDU.setContextEngineID(pdu.getContextEngineID()); reportPDU.setContextName(pdu.getContextName()); reportPDU.setRequestID(pdu.getRequestID()); reportPDU.add(payload); StatusInformation statusInformation = new StatusInformation(); try {
private void sendUnknownPDUHandlersReport(CommandResponderEvent command) { logger.info("No PDU handler found for request "+command); CounterEvent counter = new CounterEvent(this, SnmpConstants.snmpUnknownPDUHandlers); fireIncrementCounter(counter); if ((command.getMessageProcessingModel() == MessageProcessingModel.MPv3) && (command.getPDU() instanceof ScopedPDU)) { ScopedPDU request = (ScopedPDU) command.getPDU(); ScopedPDU report = new ScopedPDU(); report.setContextEngineID(request.getContextEngineID()); report.setContextName(request.getContextName()); report.setType(PDU.REPORT); report.add(new VariableBinding(counter.getOid(), counter.getCurrentValue())); sendResponse(command, report); } else { PDU resp = (PDU) command.getPDU().clone(); resp.setErrorStatus(PDU.genErr); sendResponse(command, resp); } }
/** * Construct the PDU to perform the SNMP Get request and returns * the result in order to create the flow file. * @return {@link ResponseEvent} */ public ResponseEvent get() { try { PDU pdu = null; if(this.target.getVersion() == SnmpConstants.version3) { pdu = new ScopedPDU(); } else { pdu = new PDU(); } pdu.add(new VariableBinding(this.oid)); pdu.setType(PDU.GET); return this.snmp.get(pdu, this.target); } catch (IOException e) { logger.error("Failed to get information from SNMP agent; " + this, e); throw new ProcessException(e); } }
public PDU createPDU(Target target) { PDU request; if (target.getVersion() == SnmpConstants.version3) { request = new ScopedPDU(); ScopedPDU scopedPDU = (ScopedPDU)request; if (contextEngineID != null) { scopedPDU.setContextEngineID(contextEngineID); } if (contextName != null) { scopedPDU.setContextName(contextName); } } else { if (pduType == PDU.V1TRAP) { request = v1TrapPDU; } else { request = new PDU(); } } request.setType(pduType); return request; }
if (securityEngineID != null) { secEngineID = securityEngineID.getValue(); if (scopedPDU.getContextEngineID().length() == 0) { switch (pdu.getType()) { case PDU.NOTIFICATION: scopedPDU.setContextEngineID(localEngineID); break; scopedPDU.setContextEngineID(new OctetString(secEngineID)); scopedPDU = (ScopedPDU) scopedPDU.clone(); scopedPDU.clear(); else if ((scopedPDU.getContextEngineID() == null) || (scopedPDU.getContextEngineID().length() == 0)) { logger.warn("ScopedPDU with empty context engine ID"); else if (!LOCAL_ENGINE_ID.equals(scopedPDU.getContextEngineID()) && getEngineID(transportAddress) == null) { addEngineID(transportAddress, scopedPDU.getContextEngineID()); if (scopedPDU.getContextEngineID().length() == 0) { if (logger.isDebugEnabled()) { logger.debug("Context engine ID of unconfirmed scoped PDU is empty! "+ "Setting it to local engine ID"); scopedPDU.setContextEngineID(new OctetString(localEngineID));
((ScopedPDU)response).setContextEngineID(((ScopedPDU) pdu).getContextEngineID()); ((ScopedPDU)response).setContextName(((ScopedPDU) pdu).getContextName()); } else if (pdu instanceof PDUv1){ if(pdu.getType() == PDU.GETBULK) {
private void discoverContextEngineID() { MessageProcessingModel mp = messageDispatcher.getMessageProcessingModel(target.getVersion()); if ((mp instanceof MPv3) && (target instanceof SecureTarget)) { MPv3 mpv3 = (MPv3) mp; SecureTarget st = (SecureTarget) target; SecurityModel sm = mpv3.getSecurityModel(st.getSecurityModel()); if ((sm != null) && (!sm.supportsEngineIdDiscovery())) { // Perform context engine ID discovery according to RFC 5343 if (logger.isInfoEnabled()) { logger.info("Performing RFC 5343 contextEngineID discovery on " + target); } ScopedPDU discoverPDU = new ScopedPDU(); discoverPDU.setContextEngineID(MPv3.LOCAL_ENGINE_ID); discoverPDU.add(new VariableBinding(SnmpConstants.snmpEngineID)); insertFirstPDU(discoverPDU); } } }
new byte[0] : targetMIB.getLocalEngineID(); t = new UserTarget(address, secName, authEngineID, secLevel.getValue()); ScopedPDU scopedPdu = new ScopedPDU(); scopedPdu.setContextName(context); if (pdu instanceof ScopedPDU) { localEngineID.setValue(targetMIB.getLocalEngineID()); contextEngineID = ((ScopedPDU)pdu).getContextEngineID();
ScopedPDU scopedPdu = new ScopedPDU(); pdu.setPdu(scopedPdu); BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream); sendPduHandle.setTransactionID(scopedPdu.getRequestID().getValue()); if (((scopedPdu.getContextEngineID() == null) || (scopedPdu.getContextEngineID().length() == 0)) && ((scopedPdu.getType() != PDU.RESPONSE) && (scopedPdu.getType() != PDU.REPORT))) { CounterEvent event = new CounterEvent(this, SnmpConstants. BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream); stateReference.setContextEngineID(scopedPdu.getContextEngineID().getValue()); stateReference.setContextName(scopedPdu.getContextName().getValue()); stateReference.setMaxSizeResponseScopedPDU(maxSizeResponseScopedPDU. getValue()); if ((scopedPdu.getType() == PDU.RESPONSE) || (scopedPdu.getType() == PDU.REPORT)) { StateReference cacheEntry = cache.popEntry(header.getMsgID()); if (cacheEntry != null) {
if (profile.version == SnmpConstants.version3) { pdu = new ScopedPDU(); ((ScopedPDU) pdu).setContextEngineID(profile.engineId); } else {
BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream); sendPduHandle.setTransactionID(scopedPdu.getRequestID().getValue()); if ((securityEngineID.length() > 0) && scopedPdu.isResponsePdu()) { addEngineID(transportAddress, securityEngineID); if (((scopedPdu.getContextEngineID() == null) || (scopedPdu.getContextEngineID().length() == 0)) && ((scopedPdu.getType() != PDU.RESPONSE) && (scopedPdu.getType() != PDU.REPORT))) { CounterEvent event = new CounterEvent(this, SnmpConstants. BERInputStream scopedPduStream = new BERInputStream(scopedPDU.rewind()); scopedPdu.decodeBER(scopedPduStream); securityLevel.getValue(), (scopedPdu == null) ? new byte[0] : scopedPdu.getContextEngineID().getValue(), (scopedPdu == null) ? new byte[0] : scopedPdu.getContextName().getValue(), secStateReference, status); cache.addEntry(cacheEntry); stateReference.setContextEngineID(scopedPdu.getContextEngineID().getValue()); stateReference.setContextName(scopedPdu.getContextName().getValue());
/** * Sets the context engine ID of the scoped PDU to the local engine ID * provided by the <code>targetMIB</code> member. * @param scopedPDU * the scopedPDU to modify. * @param context * the context associated with the notification/inform PDU. * @param notificationID * the notification ID of the notification/inform PDU. * @since 1.2.1 */ protected void setContextEngineID(ScopedPDU scopedPDU, OctetString context, OID notificationID) { scopedPDU.setContextEngineID(new OctetString(targetMIB.getLocalEngineID())); }
ScopedPDU spdu = (ScopedPDU) event.getPDU(); cinfo = new CoexistenceInfo(sname, spdu.getContextEngineID(), spdu.getContextName()); } else if (coexistenceProvider != null) { CoexistenceInfo[] cinfos =
public OctetString getContext() { if (coexistenceInfo != null) { return coexistenceInfo.getContextName(); } else if (source.getPDU() instanceof ScopedPDU) { return ((ScopedPDU)source.getPDU()).getContextName(); } return DEFAULT_CONTEXT; }
StateReference stateReference, VariableBinding payload) { ScopedPDU reportPDU = new ScopedPDU(); reportPDU.setType(PDU.REPORT); if (pdu != null) { reportPDU.setContextEngineID(pdu.getContextEngineID()); reportPDU.setContextName(pdu.getContextName()); reportPDU.setRequestID(pdu.getRequestID()); reportPDU.setContextEngineID(new OctetString(getLocalEngineID())); reportPDU.add(payload); StatusInformation statusInformation = new StatusInformation(); try {