SNMP4J实现v3的trap消息问题
SNMP4J提供的测试代码似乎不能实现v3事件消息的解析,我用wireshark抓到了这个包。但是snmp4j的代码似乎对它没任何反应
/*_############################################################################
_##
_## SNMP4J 2 - MultiThreadedTrapReceiver.java
_##
_## Copyright (C) 2003-2013 Frank Fock and Jochen Katz (SNMP4J.org)
_##
_## Licensed under the Apache License, Version 2.0 (the "License");
_## you may not use this file except in compliance with the License.
_## You may obtain a copy of the License at
_##
_## http://www.apache.org/licenses/LICENSE-2.0
_##
_## Unless required by applicable law or agreed to in writing, software
_## distributed under the License is distributed on an "AS IS" BASIS,
_## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
_## See the License for the specific language governing permissions and
_## limitations under the License.
_##
_##########################################################################*/
import org.snmp4j.Snmp;
import org.snmp4j.smi.Address;
import org.snmp4j.security.SecurityProtocols;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.security.SecurityModels;
import org.snmp4j.TransportMapping;
import org.snmp4j.smi.OctetString;
import org.snmp4j.transport.DefaultTcpTransportMapping;
import org.snmp4j.mp.MPv3;
import org.snmp4j.transport.DefaultUdpTransportMapping;
import org.snmp4j.security.USM;
import org.snmp4j.smi.GenericAddress;
import java.net.
UnknownHostException;
import
java.io.IOException;
import org.snmp4j.util.MultiThreadedMessageDispatcher;
import org.snmp4j.util.ThreadPool;
import org.snmp4j.version.VersionInfo;
import org.snmp4j.MessageDispatcherImpl;
import org.snmp4j.smi.TcpAddress;
import org.snmp4j.CommandResponder;
import org.snmp4j.CommandResponderEvent;
import org.snmp4j.mp.MPv1;
import org.snmp4j.mp.MPv2c;
import org.snmp4j.mp.StatusInformation;
public class MultiThreadedTrapReceiver implements CommandResponder {
// initialize Log4J logging
/*
static {
LogFactory.setLogFactory(new Log4jLogFactory());
BER.setCheckSequenceLength(false);
}
*/
private MultiThreadedMessageDispatcher dispatcher;
private Snmp snmp = null;
private Address listenAddress;
private ThreadPool threadPool;
private int n = 0;
private long start = -1;
public MultiThreadedTrapReceiver() {
// BasicConfigurator.configure();
}
private void init() throws UnknownHostException,
IOException {
threadPool = ThreadPool.create("Trap", 2);
dispatcher =
new MultiThreadedMessageDispatcher(threadPool,
new MessageDispatcherImpl());
listenAddress =
GenericAddress.parse(System.getProperty("snmp4j.listenAddress",
"udp:127.0.0.1/161"));
TransportMapping transport;
if (listenAddress instanceof UdpAddress) {
transport = new DefaultUdpTransportMapping((UdpAddress)listenAddress);
}
else {
transport = new DefaultTcpTransportMapping((TcpAddress)listenAddress);
}
snmp = new Snmp(dispatcher, transport);
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
USM usm = new USM(SecurityProtocols.getInstance(),