if (!isProtocolVersionSupported(messageProcessingModel)) {
logger.error("MPv2c used with unsupported SNMP version");
return SnmpConstants.SNMP_MP_UNSUPPORTED_SECURITY_MODEL;
}
OctetString community = new OctetString(securityName);
Integer32 version = new Integer32(messageProcessingModel);
// compute total length
int length = pdu.getBERLength();
length += community.getBERLength();
length += version.getBERLength();
ByteBuffer buf = ByteBuffer.allocate(length +
BER.getBERLengthOfLength(length) + 1);
// set the buffer of the outgoing message
outgoingMessage.setBuffer(buf);
// encode the message
BER.encodeHeader(outgoingMessage, BER.SEQUENCE, length);
version.encodeBER(outgoingMessage);
community.encodeBER(outgoingMessage);
pdu.encodeBER(outgoingMessage);
return SnmpConstants.SNMP_MP_OK;
}