简体   繁体   English

使用SNMP4j和Java的多个SNMP代理

[英]Multiple SNMP Agents using SNMP4j and Java

I'm trying to create a snmp agent simulator application, that will create multiple virtual agents with unique ip address and port. 我正在尝试创建一个snmp代理模拟器应用程序,它将创建具有唯一IP地址和端口的多个虚拟代理。 I'm trying to use snmp4jagent. 我正在尝试使用snmp4jagent。 But i've some exceptions can you help me ? 但是我有一些例外,你能帮我吗?

I extend BaseAgent class to my own class then create Multiple Instance of that class. 我将BaseAgent类扩展到自己的类,然后创建该类的Multiple Instance。 But I cannot start More than one agent at a time ie. 但是我不能一次启动多个代理。 if One agent's status is running i cannot start another agent without stopping the running agent (Code is too heavy So i don't specify any code here) code for starting an agent is 如果一个代理的状态为正在运行,那么我不能不停止正在运行的代理而启动另一个代理(代码太重,因此我在此处未指定任何代码),用于启动代理的代码为

public void start() throws IOException
{
    init();
    addShutdownHook();
    getServer().addContext(new OctetString("public"));
    finishInit();
    run();
    sendColdStartNotification(); 
}

then i register Managed objects . 然后我注册托管对象。

Code reference : http://shivasoft.in/blog/java/snmp/creating-snmp-agent-server-in-java-using-snmp4j/ 代码参考: http : //shivasoft.in/blog/java/snmp/creating-snmp-agent-server-in-java-using-snmp4j/

Thanks in advance 提前致谢

Pramod 普拉莫德

It actually does work (as tested). 它确实可以正常工作(经过测试)。 Maybe you did not assign different IP addresses to your different instances. 也许您没有为不同的实例分配不同的IP地址。 Add this to your class: 将此添加到您的班级:

/**
 * The ip address of this agent.
 */
private String ipAddress;

/**
 * Initializes the transport mappings (ports) to be used by the agent.
 * 
 * @throws IOException
 */ 
protected void initTransportMappings() throws IOException {
    transportMappings = new TransportMapping[1];
    transportMappings[0] = new DefaultUdpTransportMapping(new UdpAddress(ipAddress + "/161"));
}

You probably have to add the used ip addresses to your NIC. 您可能必须将使用的IP地址添加到NIC。 Example for Linux: Linux示例:

ip addr add 10.0.0.2/24 dev eth0

Please also provide exception messages and stacktraces if you still can't start asecond agent. 如果您仍然无法启动第二个代理,还请提供异常消息和堆栈跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM