使用 SNMP4j 和 Java 的多个 SNMP 代理

发布于 2024-11-16 17:04:35 字数 698 浏览 6 评论 0原文

我正在尝试创建一个 snmp 代理模拟器应用程序,它将创建多个具有唯一 IP 地址和端口的虚拟代理。我正在尝试使用 snmp4jagent。但我有一些例外,你能帮我吗?

我将 BaseAgent 类扩展为我自己的类,然后创建该类的多个实例。但我无法一次启动多个代理,即。如果一个代理的状态正在运行,我无法在不停止正在运行的代理的情况下启动另一个代理(代码太重,所以我在这里不指定任何代码)启动代理的代码是

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

然后我注册托管对象。

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

提前感谢

Pramod

I'm trying to create a snmp agent simulator application, that will create multiple virtual agents with unique ip address and port. I'm trying to use 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. 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/

Thanks in advance

Pramod

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高速公鹿 2024-11-23 17:04:35

它确实有效(经测试)。也许您没有为不同的实例分配不同的 IP 地址。将其添加到您的类中:

/**
 * 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"));
}

您可能必须将使用的 IP 地址添加到您的 NIC 中。 Linux 示例:

ip addr add 10.0.0.2/24 dev eth0

如果您仍然无法启动第二个代理,还请提供异常消息和堆栈跟踪。

It actually does work (as tested). Maybe you did not assign different IP addresses to your different instances. 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. Example for 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文