Date: Thu, 28 Mar 2024 17:41:34 +0000 (UTC) Message-ID: <736328389.97.1711647694526@2997b7dde346> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_96_1352755850.1711647694526" ------=_Part_96_1352755850.1711647694526 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
In AGENT++ prior to 4.3.0, there were many MibEntry relations an= d the usage of the central Mib instance organised by static class members c= alled "instance". Although this reduces code size and makes initialisation = routines easier it makes it impossible to run more than one Mib instance in= a process.
In AGENT++ 4.3.0 this has been refactored by lot of internal changes, wh= ich had two main goals:
If you do not want to use the multi-agent support, you do not have to ch= ange anything in your code. In case, you want to clean-up the API usage and= /or want to use the new features, please follow the steps below in your age= nt application:
=09Snmpx= snmp(status, inaddr); -=09mib =3D new Mib(persistentObjectsPath); +=09mib =3D new Mib(persistentObjectsPath, path(bootCounterFile)); -=09reqList =3D new RequestList(); +=09reqList =3D new RequestList(mib); =09reqList->set_snmp(&snmp); =09mib->set_request_list(reqList); v3MP *v3mp =3D new v3MP(engineId, snmpEngineBoots, stat); + snmp.set_mpv3(v3mp); -=09mib.add(new snmp_community_mib()); +=09mib.add(new snmp_community_mib(&mib)); -=09mib.add(new agentpp_config_mib()); +=09mib.add(new agentpp_config_mib(&mib)); -=09mib.add(new notification_log_mib()); +=09mib.add(new notification_log_mib(&mib)); + snmpCommunityEntry* communityEntry =3D snmpCommunityEntry::get_instance= (mib); + if (communityEntry) { =09OctetStr co("public"); -=09=09MibTableRow* row =3D snmpCommunityEntry::instance->add_row(Oidx::= from_string(co, FALSE)); + =09MibTableRow* row =3D communityEntry->add_row(Oidx::from_string(co= , FALSE)); OctetStr tag("v1v2cPermittedManagers"); -=09=09snmpCommunityEntry::instance->set_row(row, co, co, + communityEntry->set_row(row, co, co, reqList->get_v3mp()->= get_local_engine_id(),"", tag, 3, 1); + } -=09UsmUserTable *uut =3D new UsmUserTable(); + v3MP* v3mp =3D mib.get_request_list()->get_v3mp(); +=09UsmUserTable *uut =3D new UsmUserTable(v3mp); =09// add non persistent USM statistics -=09mib.add(new UsmStats()); +=09mib.add(new UsmStats(v3mp)); =09// add the USM MIB - usm_mib MibGroup is used to =09// make user added entries persistent =09mib.add(new usm_mib(uut)); =09// add non persistent SNMPv3 engine object -=09mib.add(new V3SnmpEngine()); -=09mib.add(new MPDGroup()); +=09mib.add(new V3SnmpEngine(v3mp)); +=09mib.add(new MPDGroup(v3mp));
A complete sample agent C++ code with multiple full featured agents in o= ne process is show below.
It provides per SNMP agent port the following features:=
/*_#####= ####################################################################### _##=20 _## AGENT++ 4.0 - agent.cpp =20 _##=20 _## Copyright (C) 2000-2020 Frank Fock and Jochen Katz (agentpp.com) _## =20 _## Licensed under the Apache License, Version 2.0 (the "License"); _## you may not use this file except in compliance with the License. _## You may obtain a copy of the License at _## =20 _## http://www.apache.org/licenses/LICENSE-2.0 _## =20 _## Unless required by applicable law or agreed to in writing, software _## distributed under the License is distributed on an "AS IS" BASIS, _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impl= ied. _## See the License for the specific language governing permissions and _## limitations under the License. _## =20 _########################################################################= ##*/ #include <stdlib.h> #include <signal.h> #include <agent_pp/agent++.h> #include <agent_pp/snmp_group.h> #include <agent_pp/system_group.h> #include <agent_pp/snmp_target_mib.h> #include <agent_pp/snmp_notification_mib.h> #include <agent_pp/snmp_community_mib.h> #include <agent_pp/notification_originator.h> #include <agent_pp/notification_log_mib.h> #include <agent_pp/agentpp_simulation_mib.h> #include <agent_pp/agentpp_config_mib.h> #include <agent_pp/v3_mib.h> #include <agent_pp/mib_policy.h> #include <agent_pp/vacm.h> #include <agent_pp/threads.h> #include <agent_pp/tools.h> #include <snmp_pp/oid_def.h> #include <snmp_pp/mp_v3.h> #include <snmp_pp/log.h> #include "atm_mib.h" #include "agentpp_notifytest_mib.h" #include "agentpp_test_mib.h" #ifdef SNMP_PP_NAMESPACE using namespace Snmp_pp; #endif #ifdef AGENTPP_NAMESPACE using namespace Agentpp; #endif static const char* loggerModuleName =3D "agent++.multi.agent"; // table size policies // globals: const unsigned int MAX_NUMBER_OF_AGENTS =3D 10; bool go =3D TRUE; unsigned short port[MAX_NUMBER_OF_AGENTS]; #ifdef _SNMPv3 const table_size_def table_sizes[4] =3D { table_size_def(oidUsmUserEntry, 30), table_size_def(oidVacmSecurityToGroupEntry, 30), table_size_def(oidVacmAccessEntry, 30), table_size_def(oidVacmViewTreeFamilyEntry, 30) }; MibTableSizePolicy policy(table_sizes, 4, 5000); #endif static void sig(int signo) { =09if ((signo =3D=3D SIGTERM) || (signo =3D=3D SIGINT) || =09 (signo =3D=3D SIGSEGV)) { =09=09printf ("\n"); =20 =09=09switch (signo) { =09=09case SIGSEGV: { =09=09=09printf ("Segmentation fault, aborting.\n"); =09=09=09exit(1); =09=09} =09=09case SIGTERM:=20 =09=09case SIGINT: { =09=09 if (go) { =09=09=09=09go =3D FALSE; =09=09=09=09printf ("User abort\n"); =09=09=09} =09=09} =09=09} =09} } void init_signals() { =09signal (SIGTERM, sig); =09signal (SIGINT, sig); =09signal (SIGSEGV, sig);=20 }=09 void init(Mib& mib, const NS_SNMP OctetStr& engineID, const UdpAddr= ess& inaddr) { =09OctetStr sysDescr("AGENT++v"); =09sysDescr +=3D AGENTPP_VERSION_STRING; =09sysDescr +=3D " ATM Simulation Agent ("; sysDescr +=3D inaddr.get_printable(); sysDescr +=3D ")"; mib.add(new sysGroup(sysDescr.get_printable(),=20 =09=09=09 "1.3.6.1.4.1.4976", 10)); =09mib.add(new snmpGroup()); =09mib.add(new TestAndIncr(oidSnmpSetSerialNo)); =09mib.add(new atm_mib()); =09mib.add(new agentpp_simulation_mib()); =09mib.add(new agentpp_notifytest_mib(&mib)); =09mib.add(new agentpp_test_mib()); =09mib.add(new snmp_target_mib()); #ifdef _SNMPv3 =09mib.add(new snmp_community_mib(&mib)); #endif =09mib.add(new snmp_notification_mib()); #ifdef _SNMPv3 #ifdef _NO_THREADS =09mib.add(new agentpp_config_mib(&mib)); #else =09mib.add(new agentpp_config_mib(&mib)); #endif =09mib.add(new notification_log_mib(&mib)); =09OctetStr nonDefaultContext("other"); =09mib.add(nonDefaultContext, new atm_mib()); v3MP* v3mp =3D mib.get_request_list()->get_v3mp(); =09UsmUserTable *uut =3D new UsmUserTable(v3mp); =09uut->addNewRow("unsecureUser", =09=09 SNMP_AUTHPROTOCOL_NONE, =09=09 SNMP_PRIVPROTOCOL_NONE, "", "", engineID, false); =09 =09uut->addNewRow("MD5", =09=09 SNMP_AUTHPROTOCOL_HMACMD5, =09=09 SNMP_PRIVPROTOCOL_NONE, =09=09 "MD5UserAuthPassword", "", engineID, false); =09 =09uut->addNewRow("SHA", =09=09 SNMP_AUTHPROTOCOL_HMACSHA, =09=09 SNMP_PRIVPROTOCOL_NONE, =09=09 "SHAUserAuthPassword", "", engineID, false); =09 =09uut->addNewRow("MD5DES", =09=09 SNMP_AUTHPROTOCOL_HMACMD5, =09=09 SNMP_PRIVPROTOCOL_DES, =09=09 "MD5DESUserAuthPassword", =09=09 "MD5DESUserPrivPassword", engineID, false); =09uut->addNewRow("SHADES", =09=09 SNMP_AUTHPROTOCOL_HMACSHA, =09=09 SNMP_PRIVPROTOCOL_DES, =09=09 "SHADESUserAuthPassword", =09=09 "SHADESUserPrivPassword", engineID, false); =09 =09uut->addNewRow("MD53DES", =09=09 SNMP_AUTHPROTOCOL_HMACMD5, =09=09 SNMP_PRIVPROTOCOL_3DESEDE, =09=09 "MD53DESUserAuthPassword", =09=09 "MD53DESUserPrivPassword", engineID, false); =09uut->addNewRow("SHA3DES", =09=09 SNMP_AUTHPROTOCOL_HMACSHA, =09=09 SNMP_PRIVPROTOCOL_3DESEDE, =09=09 "SHA3DESUserAuthPassword", =09=09 "SHA3DESUserPrivPassword", engineID, false); =09 =09uut->addNewRow("MD5IDEA", =09=09 SNMP_AUTHPROTOCOL_HMACMD5, =09=09 SNMP_PRIVPROTOCOL_IDEA, =09=09 "MD5IDEAUserAuthPassword", =09=09 "MD5IDEAUserPrivPassword", engineID, false); =09 =09uut->addNewRow("SHAIDEA", =09=09 SNMP_AUTHPROTOCOL_HMACSHA, =09=09 SNMP_PRIVPROTOCOL_IDEA, =09=09 "SHAIDEAUserAuthPassword", =09=09 "SHAIDEAUserPrivPassword", engineID, false); =09uut->addNewRow("MD5AES128", =09=09 SNMP_AUTHPROTOCOL_HMACMD5, =09=09 SNMP_PRIVPROTOCOL_AES128, =09=09 "MD5AES128UserAuthPassword", =09=09 "MD5AES128UserPrivPassword", engineID, false); =09 =09MibTableRow* r =3D uut->addNewRow("SHAAES128", =09=09 SNMP_AUTHPROTOCOL_HMACSHA, =09=09 SNMP_PRIVPROTOCOL_AES128, =09=09 "SHAAES128UserAuthPassword", =09=09 "SHAAES128UserPrivPassword", engineID, false); if (r) { uut->set_storage_type(r, storageType_permanent); } =20 =09uut->addNewRow("MD5AES192", =09=09 SNMP_AUTHPROTOCOL_HMACMD5, =09=09 SNMP_PRIVPROTOCOL_AES192, =09=09 "MD5AES192UserAuthPassword", =09=09 "MD5AES192UserPrivPassword", engineID, false); =09 =09uut->addNewRow("SHAAES192", =09=09 SNMP_AUTHPROTOCOL_HMACSHA, =09=09 SNMP_PRIVPROTOCOL_AES192, =09=09 "SHAAES192UserAuthPassword", =09=09 "SHAAES192UserPrivPassword", engineID, false); =09r =3D uut->addNewRow("MD5AES256", =09=09 SNMP_AUTHPROTOCOL_HMACMD5, =09=09 SNMP_PRIVPROTOCOL_AES256, =09=09 "MD5AES256UserAuthPassword", =09=09 "MD5AES256UserPrivPassword", engineID, false); if (r) { uut->set_storage_type(r, storageType_readOnly); } =20 =09uut->addNewRow("SHAAES256", =09=09 SNMP_AUTHPROTOCOL_HMACSHA, =09=09 SNMP_PRIVPROTOCOL_AES256, =09=09 "SHAAES256UserAuthPassword", =09=09 "SHAAES256UserPrivPassword", engineID, false); =09uut->addNewRow("SHA512AES256", =09=09 SNMP_AUTHPROTOCOL_HMAC384SHA512, =09=09 SNMP_PRIVPROTOCOL_AES256, =09=09 "SHA512AES256UserAuthPassword", =09=09 "SHA512AES256UserPrivPassword", engineID, false); =09uut->addNewRow("SHA384AES128", =09=09 SNMP_AUTHPROTOCOL_HMAC256SHA384, =09=09 SNMP_PRIVPROTOCOL_AES256, =09=09 "SHA384AES128UserAuthPassword", =09=09 "SHA384AES128UserPrivPassword", engineID, false); uut->addNewRow("SHA256AES128", =09=09 SNMP_AUTHPROTOCOL_HMAC192SHA256, =09=09 SNMP_PRIVPROTOCOL_AES128, =09=09 "SHA256AES128UserAuthPassword", =09=09 "SHA256AES128UserPrivPassword", engineID, false); =09uut->addNewRow("SHA224AES128", =09=09 SNMP_AUTHPROTOCOL_HMAC128SHA224, =09=09 SNMP_PRIVPROTOCOL_AES128, =09=09 "SHA224AES128UserAuthPassword", =09=09 "SHA224AES128UserPrivPassword", engineID, false); =20 =09// add non persistent USM statistics =09mib.add(new UsmStats(v3mp)); =09// add the USM MIB - usm_mib MibGroup is used to =09// make user added entries persistent =09mib.add(new usm_mib(uut)); =09// add non persistent SNMPv3 engine object =09mib.add(new V3SnmpEngine(v3mp)); =09mib.add(new MPDGroup(v3mp)); #endif }=09 class SnmpAgent: public Runnable { public: SnmpAgent(const UdpAddress& address): Runnable() {=20 inaddr =3D address; } virtual ~SnmpAgent() { }=20 virtual void run(); =20 protected: UdpAddress inaddr; };=20 OctetStr& path(OctetStr& path) { for (int i=3D0; i<path.len(); i++) { if (path[i] =3D=3D '/') { path[i] =3D '_'; } } return path; } void SnmpAgent::run() { Mib* mib; RequestList* reqList; =09int status; =09// bind localhost only -> agent will not be reachable from =09// outside =09// UdpAddress inaddr("127.0.0.1"); =09Snmpx snmp(status, inaddr); =09if (status =3D=3D SNMP_CLASS_SUCCESS) { =09=09LOG_BEGIN(loggerModuleName, EVENT_LOG | 1); =09=09LOG("main: SNMP listen address"); =09=09LOG(inaddr.get_printable()); =09=09LOG_END; =09} =09else { =09=09LOG_BEGIN(loggerModuleName, ERROR_LOG | 0); =09=09LOG("main: SNMP port init failed"); =09=09LOG(status); =09=09LOG(Snmp::error_msg(status)); =09=09LOG_END; =09=09exit(1); =09} OctetStr persistentObjectsPath(".config/"); OctetStr bootCounterFile(".config_bc_"); persistentObjectsPath +=3D inaddr.get_printable(); bootCounterFile +=3D inaddr.get_printable(); persistentObjectsPath +=3D "/"; // Make sure persistent objects path exists: if (!AgentTools::make_path(persistentObjectsPath.get_printable())) = { LOG_BEGIN(loggerModuleName, WARNING_LOG | 1); LOG("Directory for storing persistent data could not be created= (dir)"); LOG(persistentObjectsPath.get_printable()); LOG_END; } =09mib =3D new Mib(persistentObjectsPath, path(bootCounterFile)); #ifdef _SNMPv3 unsigned int snmpEngineBoots =3D 0; OctetStr engineId(SnmpEngineID::create_engine_id(inaddr.get_port())= ); // you may use your own methods to load/store this counter status =3D mib->get_boot_counter(engineId, snmpEngineBoots); if ((status !=3D SNMPv3_OK) && (status < SNMPv3_FILEOPEN= _ERROR)) { =09=09LOG_BEGIN(loggerModuleName, ERROR_LOG | 0); =09=09LOG("main: Error loading snmpEngineBoots counter (status)"); =09=09LOG(status); =09=09LOG_END; =09=09exit(1); =09} snmpEngineBoots++; status =3D mib->set_boot_counter(engineId, snmpEngineBoots); if (status !=3D SNMPv3_OK) { =09=09LOG_BEGIN(loggerModuleName, ERROR_LOG | 0); =09=09LOG("main: Error saving snmpEngineBoots counter (status)"); =09=09LOG(status); =09=09LOG_END; =09=09exit(1); =09} =09int stat; v3MP *v3mp =3D new v3MP(engineId, snmpEngineBoots, stat); snmp.set_mpv3(v3mp); #endif =09reqList =3D new RequestList(mib); #ifdef _SNMPv3 =09// register v3MP =09reqList->set_v3mp(v3mp); #endif =09// register requestList for outgoing requests =09mib->set_request_list(reqList); =09// add supported objects =09init(*mib, engineId, inaddr); =09reqList->set_snmp(&snmp); #ifdef _SNMPv3 =09// register VACM =09Vacm* vacm =3D new Vacm(*mib); =09reqList->set_vacm(vacm); =09// initialize security information vacm->addNewContext(""); vacm->addNewContext("other"); // Add new entries to the SecurityToGroupTable. // Used to determine the group a given SecurityName belongs to.=20 // User "new" of the USM belongs to newGroup vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "new", "newGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "test",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_V2, "public",=20 "v1v2group", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_V1, "public",=20 "v1v2group", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "initial",=20 "initial", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "unsecureUser",=20 "newGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "MD5",=20 "testNoPrivGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHA",=20 "testNoPrivGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "MD5DES",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHADES",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "MD53DES",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHA3DES",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "MD5IDEA",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHAIDEA",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "MD5AES128", "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHAAES128",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "MD5AES192", "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHAAES192",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "MD5AES256", "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHAAES256",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHA512AES256",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHA384AES128",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHA256AES128",=20 "testGroup", storageType_nonVolatile); vacm->addNewGroup(SNMP_SECURITY_MODEL_USM, "SHA224AES128",=20 "testGroup", storageType_nonVolatile); =09 // remove a group with: //vacm->deleteGroup(SNMP_SECURITY_MODEL_USM, "neu"); // Set access rights of groups. // The group "newGroup" (when using the USM with a security =09// level >=3D noAuthNoPriv within context "") would have full access = =20 // (read, write, notify) to all objects in view "newView".=20 vacm->addNewAccessEntry("newGroup",=20 =09=09=09=09"other", // context =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV, =09=09=09=09match_exact, // context must mach exactly =09=09=09=09// alternatively: match_prefix =20 =09=09=09=09"newView", // readView =09=09=09=09"newView", // writeView =09=09=09=09"newView", // notifyView =09=09=09=09storageType_nonVolatile); vacm->addNewAccessEntry("testGroup", "", =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_AUTH_PRIV,=20 =09=09=09=09match_prefix, =09=09=09=09"testView", "testView",=20 =09=09=09=09"testView", storageType_nonVolatile); vacm->addNewAccessEntry("testNoPrivGroup", "", =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_AUTH_NOPRIV,=20 =09=09=09=09match_prefix, =09=09=09=09"testView", "testView",=20 =09=09=09=09"testView", storageType_nonVolatile); vacm->addNewAccessEntry("testNoPrivGroup", "", =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV,=20 =09=09=09=09match_prefix, =09=09=09=09"testView", "testView",=20 =09=09=09=09"testView", storageType_nonVolatile); vacm->addNewAccessEntry("testGroup", "", =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV,=20 =09=09=09=09match_prefix, =09=09=09=09"testView", "testView",=20 =09=09=09=09"testView", storageType_nonVolatile); vacm->addNewAccessEntry("v1v2group", "",=20 =09=09=09=09SNMP_SECURITY_MODEL_V2, =09=09=09=09SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV,=20 =09=09=09=09match_exact, =09=09=09=09"v1ReadView", "v1WriteView",=20 =09=09=09=09"v1NotifyView", storageType_nonVolatile); vacm->addNewAccessEntry("v1v2group", "",=20 =09=09=09=09SNMP_SECURITY_MODEL_V1, =09=09=09=09SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV,=20 =09=09=09=09match_exact, =09=09=09=09"v1ReadView", "v1WriteView",=20 =09=09=09=09"v1NotifyView", storageType_nonVolatile); vacm->addNewAccessEntry("initial", "", =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV,=20 =09=09=09=09match_exact, =09=09=09=09"restricted", "",=20 =09=09=09=09"restricted", storageType_nonVolatile); vacm->addNewAccessEntry("initial", "", =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_AUTH_NOPRIV,=20 =09=09=09=09match_exact, =09=09=09=09"internet", "internet",=20 =09=09=09=09"internet", storageType_nonVolatile); vacm->addNewAccessEntry("initial", "", =09=09=09=09SNMP_SECURITY_MODEL_USM, =09=09=09=09SNMP_SECURITY_LEVEL_AUTH_PRIV,=20 =09=09=09=09match_exact, =09=09=09=09"internet", "internet",=20 =09=09=09=09"internet", storageType_nonVolatile); // remove an AccessEntry with: // vacm->deleteAccessEntry("newGroup",=20 =09//=09 =09=09"", =20 =09//=09=09=09SNMP_SECURITY_MODEL_USM,=20 =09//=09=09=09SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV); // Defining Views // View "v1ReadView" includes all objects starting with "1.3". // If the ith bit of the mask is not set (0), then also all objects =09// which have a different subid at position i are included in the=20 =09// view. // For example: Oid "6.5.4.3.2.1", Mask(binary) 110111=20 // Then all objects with Oid with "6.5.<?>.3.2.1= "=20 =09// are included in the view, whereas <?> may be any =09// natural number. vacm->addNewView("v1ReadView",=20 =09=09=09 "1.3", =20 =09=09=09 "", // Mask "" is same as 0xFFFFFFFFFF... =09=09=09 view_included, // alternatively: view_excluded =09=09=09 storageType_nonVolatile); vacm->addNewView("v1WriteView",=20 =09=09=09 "1.3", =20 =09=09=09 "", // Mask "" is same as 0xFFFFFFFFFF... =09=09=09 view_included, // alternatively: view_excluded =09=09=09 storageType_nonVolatile); vacm->addNewView("v1NotifyView",=20 =09=09=09 "1.3", =20 =09=09=09 "", // Mask "" is same as 0xFFFFFFFFFF... =09=09=09 view_included, // alternatively: view_excluded =09=09=09 storageType_nonVolatile); vacm->addNewView("newView", "1.3", "",=20 =09=09=09 view_included, storageType_nonVolatile); vacm->addNewView("testView", "1.3.6", "", =09=09=09 view_included, storageType_nonVolatile); vacm->addNewView("internet", "1.3.6.1","", =09=09=09 view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.2.1.1","", =09=09=09 view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.2.1.11","",=20 =09=09=09 view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.6.3.10.2.1","",=20 =09=09=09 view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.6.3.11.2.1","", =09=09=09 view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.6.3.15.1.1","",=20 =09=09=09 view_included, storageType_nonVolatile); =09// add SNMPv1/v2c community to v3 security name mapping snmpCommunityEntry* communityEntry =3D snmpCommunityEntry::get_instance(mib); if (communityEntry) { OctetStr co("public"); MibTableRow* row =3D communityEntry->add_row(Oidx::from_stri= ng(co, FALSE)); OctetStr tag("v1v2cPermittedManagers"); communityEntry->set_row(row, co, co, reqList->get_v3mp()->get_local_engine_id(), "", tag, 3, 1); } #endif=09=09 #ifdef _SNMPv3 =09// register table size policies =09MibTableSizePolicy::register_policy(mib->get_default_context(),=20 =09=09=09=09=09 &policy); #endif =09// load persistent objects from disk =09mib->init(); =09 =09 =09Vbx* vbs =3D 0; =09coldStartOid coldOid; =09NotificationOriginator no(mib); =09// add an example destination =09UdpAddress dest("127.0.0.1/162"); =09no.add_v1_trap_destination(dest, "defaultV1Trap", "v1trap", "public"); =09// send the notification =09mib->notify("", coldOid, vbs, 0); =09Request* req; =09while (go) {=09 =20 =09=09req =3D reqList->receive(2); =09=09if (req) { =09=09 mib->process_request(req); =09=09} =09=09else { =09=09 mib->cleanup(); =09=09} =09} =09delete reqList; =09delete mib; #ifdef _SNMPv3 =09delete vacm; =09delete v3mp; #endif =20 } int main (int argc, char* argv[]) { int num_agents =3D 0; while (num_agents < MAX_NUMBER_OF_AGENTS && num_agents < = argc - 1) { port[num_agents] =3D atoi(argv[1+num_agents]); num_agents++; } =09if (num_agents =3D=3D 0) { // minimum of two agents if not specified explicitly: port[0] =3D 4700; port[1] =3D 4701; num_agents =3D 2; } #ifndef _NO_LOGGING =09DefaultLog::log()->set_filter(ERROR_LOG, 5); =09DefaultLog::log()->set_filter(WARNING_LOG, 5); =09DefaultLog::log()->set_filter(EVENT_LOG, 5); =09DefaultLog::log()->set_filter(INFO_LOG, 5); =09DefaultLog::log()->set_filter(DEBUG_LOG, 1); #endif =09Snmp::socket_startup(); // Initialize socket subsystem =09init_signals(); =20 ThreadPool agentPool(num_agents); agentPool.set_one_time_execution(TRUE); SnmpAgent* agents[num_agents]; for (int i=3D0; i<num_agents; i++) { UdpAddress inaddr("0.0.0.0"); inaddr.set_port(port[i]); agents[i] =3D new SnmpAgent(inaddr); agentPool.execute(agents[i]); } agentPool.join(); =09Snmp::socket_cleanup(); // Shut down socket subsystem =09return 0; }