0

I am writing an SNMP agent and plan to write agent to process SNMP request one by one. Means that as when a request arrives at port 161 - will not accept any further request until response / timeout completes.

I am no sure of many SNMP clients - but is it that the SNMP request are sync and sequential - is there any way that they can come in bulk at a single time?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Programmer
  • 8,303
  • 23
  • 78
  • 162

3 Answers3

1

I think SNMP queries can easily come in bursts due to multiple independent managers polling your agent and/or a single anxious manager retrying the same command if your agent is not quick enough to respond.

When it comes to writing SNMP agents, the other consideration would be to estimate the maximum possible time for the agent to gather required data to respond. I believe it should not be the OID-average, but the OID-maximum. In other words, should your agent serve 100 OIDs, out of which querying one "slow" OID would lead to the entire (synchronous) agent to block and stop serving others - this situation might undermine the credibility of your agent on the network...

On top of that, if you happen to hit the same slow OID multiple time in a row (e.g. manager retries), the delay might be accumulating, effectively blocking out other queries.

To summarize: I think high-performance SNMP agent should have the following traits:

  • Support massively concurrent SNMP commands processing
  • Have non-blocking data source access for gathering managed objects data
  • Have some form of caching or rate limiting to protect computationally expensive data sources from cocky SNMP managers

On the other hand, if your SNMP agent is serving a small piece of static data on a low-power hardware and you do not expect too many managers ever talking to you, perhaps you could get away with a simplistic synchronous SNMP agent...

BTW, BSD sockets interface would hold a queue of unprocessed UDP packets so your agent would have a chance to catch up.

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21
1

The premise of your question is flawed, as there is no concept of "coming in bulk at a single time" — no matter in which order the UDP datagrams making up an SNMP packet are received, and no matter how long a duration lies between the receipt of each packet by your network interface, your operating system will present the SNMP packets to you in receipt order, in sequence. You have one listen port, and one read buffer. So this synchronicity is already how network data processing works and you shouldn't worry about it.

I would say though, that if you are waiting for some resource to become available while processing an SNMP request (as suggested by your use of the word "timeout"), you probably ought to get on and start processing your other pending SNMP requests in the meantime, or you risk your whole stack grinding to a halt. It's not fair to make a manager wait some unknown duration for a response to request B just because some other manager made a request A that is experiencing a delay in being serviced. That being said, you probably do want some upper limit on how many requests can be serviced at any one time, to prevent potential DDoSsing — choosing this value can only be done by you, with your knowledge of the use case and the ecosystem.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Thanks for information - to put my question in other way is that after receipt of the UDP SNMP request will the SNMP agent only process next request until the response for the previous one is provided - same in case when multiple request comes - should we ensure to process response for each request and then to take the next request of the agent can send multiple request to the application? – Programmer Jan 03 '19 at 05:53
  • @Programmer My answer hasn't changed - what the SNMP Agent does is up to the SNMP Agent but nothing about SNMP requires it to work in that sequential way (which would be unscalable) – Lightness Races in Orbit Jan 03 '19 at 11:18
-1

Get requests are one OID per request, GetBulk request can ask for several OIDs in one request. Also SNMP client can use async mode sending multiple requests with minimal intervals and waiting for replies. Packets can also arrive out-or-order due to network delays and equal-cost routes. Your can experiment sending requests with snmpget, snmpgetbulk, snmpbulkwalk and use tcpdump to see what is on the wire.

So, in general, your agent has to be ready to accept bursts of requests. For simplicity, if request rate is low and your agent can reply fast enough, you can use one-by-one processing. Some of requests can fail in this case, but clients can retry request and finally get reply from agent.

Yuri Lachin
  • 1,470
  • 7
  • 7
  • But isn't GetBulk a single request in which the agent has to respond with multiple values? – Programmer Dec 28 '18 at 14:55
  • Well, right, it is a single request asking for multiple oids - so agent will block for batch processing once. – Yuri Lachin Dec 28 '18 at 15:05
  • 1
    Out of the nitpickiness: any single SNMP command can carry one **or more** OIDs. The agent is obliged to respond something for each OID imposed in the query. The GETBULK command has an additional feature allowing the agent to respond with more then one "next" OIDs. Interestingly, the agent is not obliged to supply more than one OID, but is not allowed to provide more OIDs than the manager is willing to receive. – Ilya Etingof Dec 28 '18 at 15:52
  • Thanks - but until a response to a request is received the SNMP client will not send any new request - hence SNMP client and agent then works on 1 request/response (no mater if response has multiple OIDs value) - is my understanding correct? – Programmer Dec 28 '18 at 17:39
  • Client can send retry request if no response is received in time - that's the purpose of retry. Number of retries depends on client. In case of slow/blocking agent retries can arrive faster than agent can serve them. – Yuri Lachin Dec 28 '18 at 17:57
  • _"Get requests are one OID per request"_ Simply not true. – Lightness Races in Orbit Dec 29 '18 at 18:16
  • @Programmer: _"Thanks - but until a response to a request is received the SNMP client will not send any new request"_ What do you base this claim on? There's no reason to assume that. A sensible client will parallelise just like anything else: it can do that using _GetBulk_ in some cases but not all. – Lightness Races in Orbit Dec 29 '18 at 18:23