The multiple_agent is configuring port[0] = 4700; port[1] = 4701;
In agent.cpp and void SnmpAgent::run(), I saw
while (go) {
req = reqList->receive(2);
if (req) {
mib->process_request(req);
} else {
mib->cleanup();
}
}
In request.cpp and Request *RequestList::receive(int sec), I saw #ifdef _SNMPv3
UTarget target;
int status = snmp->receive(tvptr, pdu, target); #else
In snmp_pp_ext.cpp and int Snmpx::receive(struct timeval *tvptr, Pdux& pdu, UTarget& target)
I also saw req went to “true”. It means Agent received SNMP requests. How can I know the incoming SNMP request from port 4700 or port 4701. Where I can find the function/logic/method to handle the port mapping in agent.cpp? I’m creating more than 2 agents therefore I’m trying to figure out which agent receive different SNMP requests so I can process all agents correctly.
in this example agent, each SnmpAgent object has its own Snmpx and RequestList objects amd Mib instance. The Snmpx object of each agent listens on the SnmpAgent::inaddr address, so you can check this member to find out which port is used.
Thank you very much for your information. I could use SnmpAgent::inaddr address to figure out the ports.
I have another questions. Using Agent++ example, I need to add some Scalar ASN_INTEGER (2)/ ASN_OCTET_STR (4)/ ASN_UINTEGER (66) ReadOnly access Oid. I think the manager only can request snmpget and cannot request snmpset.
Error:
Set Status = SNMP: Cannot create/set variable, Not Writable
How is about the Agent? Can Agent update data values of those ReadOnly access Oid? If yes, what are the function/method to do it? Can multi_agent example update some ReadOnly Oid somehow (using command or some section codes)?
If both manager and Agent cannot update ReadOnly Oid, how/who can do it? Sorry, I could not find any documents or information online.
Example1:
MibLeaf(id, READONLY, new Gauge32()){…}
MibLeaf(id, READONLY, new SnmpInt32()){…}
Example2 in sim_mib.cpp:
add(new SimMibLeaf(“1.3.6.1.2.1.1.7.0”, READONLY,
new SnmpInt32(0), FALSE));
if you add the MibLeaf with READONLY, the manager cannot write/set the value. But inside the agent, the value can be updated. You can either remember the pointers to the MibLeaf objects during construction of the Mib, then you can lock the object (start_synch()), update its value (set_value()) and unlock the object (end_synch()).
Or you could use Mib::get() to get the MibLeaf object from the Mib and then update its value as written above.
Thank you very much for your information. I could use Mib::get() to get the MibLeaf object from the Mib and then lock the object (start_synch()), update its value (set_value()) and unlock the object (end_synch()) to update the READONLY Oid. However, It updated the Oid value of all agents together. Is there a way to update the READONLY Oid value for single agent just like we request the “snmpset” to a single port? I would like to control all agents independently.
the example code adds all objects to the Mib using new. So each simulated agent has its own Mib and modifying the value of a MibLeaf in one Mib should not change the value of the other agents.
Are you adding your own MibLeaf objects to the Mib? How do you do this?