Cannot send/response for a snmpSet request with mutiple OIDs and their corresponding values

Hi,

I’m using Agent+±4.6.1 and SNMP+±3.5.1. Is it possiple to send a snmpSet request (using SNMP+±3.5.1) with multiple OIDs and their corresponding values in a single UDP message AND response this snmpSet request (using Agent+±4.6.1)?

It seems like we can send snmpGet request with multiple OIDs and send snmpSet with only 1 OID.
$ ./snmpGet --help
snmpGet IpAddress | DNSName [Oid [Oid…]] [options]
$ ./snmpSet --help
snmpSet IpAddress | DNSName [Oid] [options]

In AGENT++\src\mib.cpp (Mib::do_process_request(Request* req)), AGENT can process multiple subrequest for snmpGet request
int n = req->subrequests();
for (i=0; i<n; i++) {
if (!req->is_done(i))
if (!process_request(req, i)) break;

However, in Mib::process_set_request(Request* req), I did not see any function/method to process multiple OIDs. Are there other ways for agent++ to process and response to snmpSet several OIDs with new values in 1 request?
case (sNMP_PDU_SET): {
process_set_request(req);
int n = req->subrequests();
for (int j=0; j<n; j++)
LOG(req->get_oid(j).get_printable());

Thanks,
Phuoc

Yes, of course you can set multiple variables in a single SET PDU with SNMP++ and AGENT++ from the very first version.on.

I do not know why you think it would not work?
The code snippet you posted is for any PDU type regardless of SET or GET!

The snmpGet request could send multiple OIDs and Agent could response fine
$ ./snmpGet --help
snmpGet IpAddress | DNSName [Oid [Oid…]] [options]
$ ./snmpGet 127.0.0.1 1.3.6.1.4.1.4976.6.3.1.1.0 1.3.6.1.4.1.4976.6.2.1.1.0 -P4700 -v3 -snusr-sha-aes -authSHA -privAES128 -uakey1 -upkey1
VB nr: 0
Oid = 1.3.6.1.4.1.4976.6.3.1.1.0
Value = 0
Syntax = 66


VB nr: 1
Oid = 1.3.6.1.4.1.4976.6.2.1.1.0
Value = 0
Syntax = 2

However, The snmpSet request could send multiple OIDs
$ ./snmpSet --help
snmpSet IpAddress | DNSName [Oid] [options]
$ ./snmpSet 127.0.0.1 1.3.6.1.4.1.4976.6.3.1.1.0 1.3.6.1.4.1.4976.6.2.1.1.0 -P4700 -v3 -snusr-sha-aes -authSHA -privAES128 -uakey1 -upkey1
Error: unknown parameter: 1.3.6.1.4.1.4976.6.2.1.1.0
Usage:
snmpSet IpAddress | DNSName [Oid] [options]

Also in Mib::process_set_request(Request* req), I did not see any function/method to process multiple OIDs. There is no request index for subrequest.

case (sNMP_PDU_SET): {
process_set_request(req);
break;
}
void Mib::process_set_request(Request* req)
{
int n = req->subrequests();

LOG_BEGIN(loggerModuleName, EVENT_LOG | 2);
LOG("Mib: process request: set request (tid)(oid)");
LOG(req->get_transaction_id());

for (int j=0; j<n; j++)
	LOG(req->get_oid(j).get_printable());
LOG_END;
req->phase++; // indicate PHASE_PREPARE
if (process_prepare_set_request(req) == SNMP_ERROR_SUCCESS) {
	req->phase++; // indicate PHASE_COMMIT
	if (process_commit_set_request(req) !=
	    SNMP_ERROR_SUCCESS) {

		req->phase++;

		LOG_BEGIN(loggerModuleName, WARNING_LOG | 2);
		LOG("Mib: commit failed (tid)");
		LOG(req->get_transaction_id());
		LOG_END;

		process_undo_set_request(req);
		return;
	}
}
req->phase = PHASE_CLEANUP;
process_cleanup_set_request(req);

}

You can make use of the PDU’s set_vblist(Vb const *, const int) method to pass multiple OIDS in a single request. This is assumed that the Agent that you are communicating with has been programed to sufficiently respond with vbLists.

Here’s a basic code example that could get you in the right direction.


std::vector<Snmp_pp:Vb> vbList;
Snmp_pp::Vb vb1;
Snmp_pp::Vb vb2;
vb1.set_oid("1.3.6.1.4.1...1.0");
vb2.set_oid("1.3.6.1.4.1...2.0");

unsigned int value1 = 1;
unsigned int value2 = 2;

vb1.set_value(value1);
vb2.set_value(value2);

vbList.pushback(vb1);
vbList.pushback(vb2);

Snmp_pp::Pdu pdu;
int status;
//If ivp6 use true as the constructor's argument
Snmp_pp::Snmp snmp(status, 0, false);
pdu.set_vblist(&vbList[0], static_cast<int>(vbList.size()));

Snmp_pp::UTarget utarget = target;
status = snmp.set(pdu, target);

if(status != SNMP_CLASS_SUCCESS)
{
	std::cout <<"Error: " << snmp.error_msg(status);
}

Hi Steven,

Thanks for your info.

Frank said we can set multiple variables in a single SET PDU with SNMP++ and AGENT++ from the very first version. I’m trying to figure out what is going on with Agent+±4.6.1 and SNMP+±3.5.1.

The snmpSet command sample tool is only a sample and does not implement all features the SNMP++ API has.