Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: SNMP3 Problem: System.ArgumentException for multiple requests
renu

From: Eschborn, Germany
Posts: 16
Member Since: 02/17/09
posted May 6, 2009 9:41 AM

I retrieve values from an SNMPv3 MIB as follows:

DartManager.GetResponseAsync(dartRequest, AgentAddress);

where:
- RequestMessage dartRequest is set with Security and
- AgentAddress = 172.16.4.90.

note: there is no agent port given in GetResponseAsync!

Problem:
works ok for just 1 request, when I try to retrieve 2 values from the same IP address I get the following error:

System.ArgumentException: Item has already been added. Key in dictionary: '0172.16.4.90161' Key being added: '0172.16.4.90161'
at Dart.PowerSNMP.Manager.a(RequestMessage A_0, IPEndPoint A_1, Boolean A_2)
at Dart.PowerSNMP.Manager.GetResponseAsync(RequestMessage request, String remoteHost)
at .... (my method)

... obviously, the agent port is somehow added?

What can I do to get multiple requests of the same IP address working?

By the way: the problem can be reproduced in the Manager example, class MessageOptions, method SendSingleRequest - just duplicate the following line:
          m_Manager.GetResponseAsync(request, txtAddress.Text);
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted May 6, 2009 5:20 PM

Hi,

1. If a method is used that lacks a port parameter, the standard agent port 161 is used.

2. This should work if you create a new request message for each call.
You cannot re-use the same GetMessage with modifications, because the object cannot be changed before its corresponding response is received.
Also, you may want to explicitly set the GetMessage.Id property; I'm not sure why 0 is used for both your requests.

Hope it helps,
-ken
renu

From: Eschborn, Germany
Posts: 16
Member Since: 02/17/09
posted May 8, 2009 8:16 AM

Hi ken,

sorry to have mislead you by my proposal to try it out with the Manager example, of course I create a new message for each call.

The Id is usually automatically incremented for every call, there is no need to set it explicitly - for snmpv1/2. In v3, setting the Security object resets the internal id to 0.

I now set the id explicitly (after setting Security) and now I get the exception only the first time for the second call (which is decidedly an improvement!!).

This is the little test method to give to try it out:

// prerequisite: DartManager was opened

// note that in the code the following previously set variables are used:
// community, username, securityLevel, authPassword, privPassword

void xxx()
{
int id = 0;
 
for (int i = 0; i < 4; i++)
{
RequestMessage dartRequest = new GetMessage();
dartRequest.Community = community;
dartRequest.Version = SnmpVersion.Three;

Security security = new Security();
security.Username = username;

if (securityLevel == "AuthNoPriv" || securityLevel == "AuthPriv")
{
security.AuthenticationProtocol = AuthenticationProtocol.Md5;
security.AuthenticationPassword = authPassword;
}

if (securityLevel == "AuthPriv")
{
// note:
// PrivacyProtocol is Des by default,
// PrivacyPassword has to be string.Empty if no privacy wanted

security.PrivacyProtocol = PrivacyProtocol.Des;
security.PrivacyPassword = privPassword;
}
    
// ##### this resets the previously set Id to 0!!!
dartRequest.Security = security;

dartRequest.Variables.Add(new Variable("1.3.6.1.2.1.1.5.0")); // sysName

// id, is not automatically incremented for snmpv3!
id++;
dartRequest.Id = id;

int bytesSent = DartManager.GetResponseAsync(dartRequest, agentAddress);

} // for loop
}



K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted May 8, 2009 1:15 PM

Hi,
Ok, thanks for the clarification.
I tried with v2 and it worked ok, but I see that v3 does not.

I will write a report up for this issue.
However, I am going to recommend a different approach than using GetResponseAsync.

Instead, spawn your own worker threads and use the high-performance static GetResponse call.
The static overload is the one with six parameters.

It is easy to use and it should work correctly for this scenario.
Just make the call and a ResponseMessage is returned.

We do have an example of its use; it is called the "SNMP Poll" sample.


Another option would be to upgrade your app to use the latest PowerSNMP 4.0 release.
However, this would take more coding changes than going to the static GetResponse call.


Hope it helps,
-ken
renu

From: Eschborn, Germany
Posts: 16
Member Since: 02/17/09
posted May 11, 2009 7:14 AM

Hi ken,

thanks a lot, I'll try the worker thread idea.

renu
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX