Search code examples
c++snmpgoogletestnet-snmp

SNMP Agent Disconnects During Unit-test


I've created a unit test for my SNMPv3 subagent, and I seem to be running into issues. When it work's, it work's great. However, every few times I run the unit-test the master disconnects the subagent session. Also, I would definitely prefer not to use SNMP, but it is a requirement.

I am running Fedora 28 with net-snmp 5.7.3

Here is a description of the unit test:

  1. Start SNMPv3 subagent (works every time)
  2. Create a client session and connect to SNMP master at localhost
  3. Set integer or string value for each OID registered by subagent (typically fails here)
  4. Get integer or string value for each OID registered by subagent and EXPECT_TRUE(value == TEST_VALUE)

I see the following behaviors:

  1. Everything works as expected
  2. Client sometimes hangs forever on GET or SET
  3. Just this error: "AgentX master disconnected us, reconnecting in 15"
  4. Both of these error messages: "AgentX master disconnected us, reconnecting in 15" "transport->sock got negative fd value -1"
  5. These three messages: "received broken packet. closing session" "AgentX master disconnected us, reconnecting in 15" "AgentX master disconnected us, reconnecting in 15"

After looking through net-snmp source the best I can tell is that sometimes packets are malformed for some reason, but I don't think that cover's all of the different issues I am having.

I also have a C# SNMP Client that never runs into any of these issues, so I can't see how it would be server related.


Solution

  • For anyone who might run across this:

    The solution is simply to run the subagent and client in different processes. I was running the subagent and client in the same googletest process, and it caused a lot of conflicts. I guess I should have realized it wouldn't be safe to do so with a library like net-snmp.