version 1.20, 2009/05/05 09:01:36
|
version 1.21, 2010/12/22 12:19:07
|
|
|
#include <Pegasus/General/Stopwatch.h> | #include <Pegasus/General/Stopwatch.h> |
#include <Pegasus/Client/CIMClient.h> | #include <Pegasus/Client/CIMClient.h> |
#include <Pegasus/Common/HostAddress.h> | #include <Pegasus/Common/HostAddress.h> |
|
#include <net-snmp/net-snmp-config.h> |
|
#include <net-snmp/net-snmp-includes.h> |
| |
PEGASUS_USING_PEGASUS; | PEGASUS_USING_PEGASUS; |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
|
|
const String SNMPV1_HANDLER_NAME = "SNMPHandler01"; | const String SNMPV1_HANDLER_NAME = "SNMPHandler01"; |
const String SNMPV2C_HANDLER_NAME = "SNMPHandler02"; | const String SNMPV2C_HANDLER_NAME = "SNMPHandler02"; |
const String SNMPV2C_IPV6_HANDLER_NAME = "SNMPHandler03"; | const String SNMPV2C_IPV6_HANDLER_NAME = "SNMPHandler03"; |
|
const String SNMPV3_HANDLER_NAME = "SNMPHandler04"; |
const String FILTER_NAME = "SNMPIPFilter01"; | const String FILTER_NAME = "SNMPIPFilter01"; |
| |
enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3}; |
enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3, _SNMPV3_TRAP=5}; |
enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4}; | enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4}; |
| |
#define PORT_NUMBER 2006 | #define PORT_NUMBER 2006 |
|
|
const String & targetHost, | const String & targetHost, |
const String & securityName, | const String & securityName, |
const Uint16 targetHostFormat, | const Uint16 targetHostFormat, |
const Uint16 snmpVersion) |
const Uint16 snmpVersion, |
|
const String & snmpEngineID, |
|
const Uint8 & snmpSecLevel, |
|
const Uint8 & snmpSecAuthProto, |
|
const String & snmpSecAuthKey, |
|
const Uint8 & snmpSecPrivProto, |
|
const String & snmpSecPrivKey) |
{ | { |
CIMInstance handlerInstance (PEGASUS_CLASSNAME_INDHANDLER_SNMP); | CIMInstance handlerInstance (PEGASUS_CLASSNAME_INDHANDLER_SNMP); |
handlerInstance.addProperty (CIMProperty (CIMName | handlerInstance.addProperty (CIMProperty (CIMName |
|
|
CIMValue ((Uint16) snmpVersion))); | CIMValue ((Uint16) snmpVersion))); |
handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"), | handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"), |
CIMValue ((Uint32) PORT_NUMBER))); | CIMValue ((Uint32) PORT_NUMBER))); |
|
if(snmpVersion == _SNMPV3_TRAP) |
|
{ |
|
|
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPEngineID"),snmpEngineID)); |
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPSecurityLevel"),snmpSecLevel)); //AuthPriv |
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPSecurityAuthProtocol"),snmpSecAuthProto)); |
|
|
|
oid *snmpSecAuthProtoOid; |
|
size_t snmpSecAuthProtoLen=0; |
|
|
|
if(snmpSecAuthKey.size() > 0) |
|
{ |
|
if(snmpSecAuthProto == 1) |
|
{ |
|
snmpSecAuthProtoOid = snmp_duplicate_objid( |
|
usmHMACMD5AuthProtocol, |
|
USM_AUTH_PROTO_MD5_LEN); |
|
snmpSecAuthProtoLen = USM_AUTH_PROTO_MD5_LEN; |
|
} |
|
else if(snmpSecAuthProto == 2) |
|
{ |
|
snmpSecAuthProtoOid = snmp_duplicate_objid( |
|
usmHMACSHA1AuthProtocol, |
|
USM_AUTH_PROTO_SHA_LEN); |
|
snmpSecAuthProtoLen = USM_AUTH_PROTO_SHA_LEN; |
|
} |
|
else |
|
{ |
|
cout << "Invalid authentication protocol specified to " << |
|
"create handler." << endl; |
|
PEGASUS_TEST_ASSERT(false); |
|
} |
|
|
|
CString snmpSecAuthKeyCstr = snmpSecAuthKey.getCString(); |
|
size_t authKeyLen = snmpSecAuthKey.size(); |
|
u_char * snmpSecAuthKeyPtr = (u_char *)malloc(authKeyLen); |
|
u_char * encryptedSecurityAuthKey = (u_char *)malloc(authKeyLen); |
|
size_t securityAuthKeyLen = USM_AUTH_KU_LEN; |
|
memcpy(snmpSecAuthKeyPtr,(const char *)snmpSecAuthKeyCstr, |
|
strlen(snmpSecAuthKeyCstr)); |
|
snmpSecAuthKeyPtr[authKeyLen] = '\0'; |
|
|
|
if(generate_Ku(snmpSecAuthProtoOid, |
|
snmpSecAuthProtoLen, |
|
snmpSecAuthKeyPtr, |
|
strlen(snmpSecAuthKeyCstr), |
|
encryptedSecurityAuthKey, |
|
&securityAuthKeyLen) != SNMPERR_SUCCESS) |
|
{ |
|
cout << "Failed to generate the snmp authentication key" |
|
<< endl; |
|
free(snmpSecAuthKeyPtr); |
|
free(encryptedSecurityAuthKey); |
|
PEGASUS_TEST_ASSERT(false); |
|
} |
|
|
|
Array<Uint8> authKey; |
|
for(Uint32 i=0; i<securityAuthKeyLen; i++) |
|
{ |
|
authKey.append(encryptedSecurityAuthKey[i]); |
|
} |
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPSecurityAuthKey"), |
|
authKey)); |
|
free(snmpSecAuthKeyPtr); |
|
free(encryptedSecurityAuthKey); |
|
} |
|
|
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPSecurityPrivProtocol"),snmpSecPrivProto)); |
|
|
|
if(snmpSecPrivKey.size() > 0 ) |
|
{ |
|
CString snmpSecPrivKeyCstr = snmpSecPrivKey.getCString(); |
|
u_char * snmpSecPrivKeyPtr = (u_char *)malloc(USM_PRIV_KU_LEN); |
|
u_char * encryptedSecurityPrivKey = |
|
(u_char *)malloc(USM_PRIV_KU_LEN); |
|
size_t securityPrivKeyLen = USM_PRIV_KU_LEN; |
|
memcpy(snmpSecPrivKeyPtr,(const char *)snmpSecPrivKeyCstr, |
|
USM_PRIV_KU_LEN); |
|
if(generate_Ku(snmpSecAuthProtoOid, |
|
snmpSecAuthProtoLen, |
|
snmpSecPrivKeyPtr, |
|
strlen(snmpSecPrivKeyCstr), |
|
encryptedSecurityPrivKey, |
|
&securityPrivKeyLen) != SNMPERR_SUCCESS) |
|
{ |
|
cout << "Failed to generate the snmp privacy key" |
|
<< endl; |
|
free(snmpSecPrivKeyPtr); |
|
free(encryptedSecurityPrivKey); |
|
PEGASUS_TEST_ASSERT(false); |
|
} |
|
|
|
Array<Uint8> privKey; |
|
for(Uint32 i=0; i<securityPrivKeyLen; i++) |
|
{ |
|
privKey.append(encryptedSecurityPrivKey[i]); |
|
} |
|
|
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPSecurityPrivKey"), |
|
privKey)); |
|
free(snmpSecPrivKeyPtr); |
|
free(encryptedSecurityPrivKey); |
|
} |
|
} |
| |
return client.createInstance( | return client.createInstance( |
PEGASUS_NAMESPACENAME_INTEROP, handlerInstance); | PEGASUS_NAMESPACENAME_INTEROP, handlerInstance); |
|
|
<< " <threads> is an optional number of client threads to\n" | << " <threads> is an optional number of client threads to\n" |
<< " create, default is one." << endl | << " create, default is one." << endl |
<< " TestSnmpHandler cleanup\n" | << " TestSnmpHandler cleanup\n" |
<< " TestSnmpHandler removelog" |
<< " TestSnmpHandler removelog\n\n" |
|
<< "Note :\n" |
|
<< "For running snmp v3 tests create an user by name \"sahana\" in\n" |
|
<< "smpd.conf and snmptrapd.conf with the following credentials :- \n" |
|
<< "engineId = 0x80001f88808a67e858ee38ec4c \n" |
|
<< "Authentication protocol = MD5 \n" |
|
<< "Privacy Protocol = DES \n" |
|
<< "Authentication key = setup_passphrase \n" |
<< endl << endl; | << endl << endl; |
} | } |
| |
|
|
CIMObjectPath snmpv1HandlerObjectPath; | CIMObjectPath snmpv1HandlerObjectPath; |
CIMObjectPath snmpv2HandlerObjectPath; | CIMObjectPath snmpv2HandlerObjectPath; |
CIMObjectPath snmpv2IPV6HandlerObjectPath; | CIMObjectPath snmpv2IPV6HandlerObjectPath; |
|
CIMObjectPath snmpv3HandlerObjectPath; |
| |
try | try |
{ | { |
|
|
System::getFullyQualifiedHostName(), | System::getFullyQualifiedHostName(), |
"", | "", |
_HOST_NAME, | _HOST_NAME, |
_SNMPV1_TRAP); |
_SNMPV1_TRAP, |
|
String(),0,1,String(),1,String()); |
} | } |
catch (CIMException& e) | catch (CIMException& e) |
{ | { |
|
|
ipAddress, | ipAddress, |
"public", | "public", |
af == AF_INET ? _IPV4_ADDRESS : _IPV6_ADDRESS, | af == AF_INET ? _IPV4_ADDRESS : _IPV6_ADDRESS, |
_SNMPV2C_TRAP); |
_SNMPV2C_TRAP, |
|
String(),0,1,String(),1,String()); |
} | } |
catch (CIMException& e) | catch (CIMException& e) |
{ | { |
|
|
String("::1"), | String("::1"), |
"public", | "public", |
_IPV6_ADDRESS, | _IPV6_ADDRESS, |
_SNMPV2C_TRAP); |
_SNMPV2C_TRAP, |
|
String(),0,1,String(),1,String()); |
} | } |
catch (CIMException& e) | catch (CIMException& e) |
{ | { |
|
|
} | } |
} | } |
#endif | #endif |
|
|
|
// create a snmp V3 trap handler. |
|
try |
|
{ |
|
String ipAddress; |
|
int af; |
|
System::getHostIP(System::getFullyQualifiedHostName (), &af, ipAddress); |
|
// Create SNMPv3 trap handler |
|
snmpv3HandlerObjectPath = _createHandlerInstance (client, |
|
SNMPV3_HANDLER_NAME, |
|
System::getFullyQualifiedHostName(), |
|
"sahana", |
|
_HOST_NAME, |
|
_SNMPV3_TRAP, |
|
"0x80001f88808a67e858ee38ec4c", |
|
3, |
|
1, |
|
"setup_passphrase", |
|
1, |
|
"setup_passphrase"); |
|
|
|
} |
|
catch (CIMException& e) |
|
{ |
|
if (e.getCode() == CIM_ERR_ALREADY_EXISTS) |
|
{ |
|
snmpv3HandlerObjectPath = _getHandlerObjectPath( |
|
SNMPV2C_IPV6_HANDLER_NAME); |
|
cerr << "----- Warning: SNMPv3 Trap Handler Instance " |
|
"Not Created: " << e.getMessage () << endl; |
|
} |
|
else |
|
{ |
|
cerr << "----- Error: SNMPv3 Trap Handler Instance Not " |
|
"Created: " << endl; |
|
throw; |
|
} |
|
} |
|
|
|
try |
|
{ |
|
_createSubscriptionInstance (client, filterObjectPath, |
|
snmpv3HandlerObjectPath); |
|
} |
|
catch (CIMException& e) |
|
{ |
|
if (e.getCode() == CIM_ERR_ALREADY_EXISTS) |
|
{ |
|
cerr << "----- Warning: Client Subscription Instance: " |
|
<< e.getMessage () << endl; |
|
} |
|
else |
|
{ |
|
cerr << "----- Error: Client Subscription Instance: " << endl; |
|
throw; |
|
} |
|
} |
|
# |
} | } |
| |
void _cleanup (CIMClient & client) | void _cleanup (CIMClient & client) |
|
|
| |
try | try |
{ | { |
|
_deleteSubscriptionInstance (client, FILTER_NAME, |
|
SNMPV3_HANDLER_NAME); |
|
} |
|
catch (CIMException& e) |
|
{ |
|
if (e.getCode() != CIM_ERR_NOT_FOUND) |
|
{ |
|
cerr << "----- Error: deleteSubscriptionInstance failure: " |
|
<< endl; |
|
throw; |
|
} |
|
} |
|
|
|
try |
|
{ |
_deleteFilterInstance (client, FILTER_NAME); | _deleteFilterInstance (client, FILTER_NAME); |
} | } |
catch (CIMException& e) | catch (CIMException& e) |
|
|
} | } |
} | } |
#endif | #endif |
|
|
|
try |
|
{ |
|
_deleteHandlerInstance (client, SNMPV3_HANDLER_NAME); |
|
} |
|
catch (CIMException& e) |
|
{ |
|
if (e.getCode() != CIM_ERR_NOT_FOUND) |
|
{ |
|
cerr << "----- Error: deleteHandlerInstance failure: " << endl; |
|
throw; |
|
} |
|
} |
} | } |
| |
static void _testEnd(const String& uniqueID, const double elapsedTime) | static void _testEnd(const String& uniqueID, const double elapsedTime) |
|
|
{ | { |
String trap1 = "Trap Info: TRAP, SNMP v1, community public"; | String trap1 = "Trap Info: TRAP, SNMP v1, community public"; |
String trap2 = "Trap Info: TRAP2, SNMP v2c, community public"; | String trap2 = "Trap Info: TRAP2, SNMP v2c, community public"; |
|
String trap3 = "Trap Info: TRAP2, SNMP v3, user sahana, context "; |
| |
Uint32 receivedTrap1Count = 0; | Uint32 receivedTrap1Count = 0; |
Uint32 receivedTrap2Count = 0; | Uint32 receivedTrap2Count = 0; |
|
Uint32 receivedTrap3Count = 0; |
| |
ifstream ifs(logFile.getCString()); | ifstream ifs(logFile.getCString()); |
if (!ifs) | if (!ifs) |
|
|
{ | { |
receivedTrap2Count++; | receivedTrap2Count++; |
} | } |
|
if (String::compare(line, trap3) == 0) |
|
{ |
|
receivedTrap3Count++; |
|
} |
} | } |
| |
ifs.close(); | ifs.close(); |
|
|
{ | { |
return (receivedTrap2Count); | return (receivedTrap2Count); |
} | } |
|
case _SNMPV3_TRAP: |
|
{ |
|
return (receivedTrap3Count); |
|
} |
default: | default: |
{ | { |
return (0); | return (0); |
|
|
{ | { |
Uint32 indicationTrapV1SendCount = 0; | Uint32 indicationTrapV1SendCount = 0; |
Uint32 indicationTrapV2SendCount = 0; | Uint32 indicationTrapV2SendCount = 0; |
|
Uint32 indicationTrapV3SendCount = 0; |
| |
CIMClient * clientConnections = new CIMClient[runClientThreadCount]; | CIMClient * clientConnections = new CIMClient[runClientThreadCount]; |
| |
|
|
indicationTrapV2SendCount = indicationTrapV1SendCount; | indicationTrapV2SendCount = indicationTrapV1SendCount; |
#endif | #endif |
| |
|
indicationTrapV3SendCount = |
|
indicationSendCount * runClientThreadCount; |
|
|
// calculate the timeout based on the total send count allowing | // calculate the timeout based on the total send count allowing |
// using the MSG_PER_SEC rate | // using the MSG_PER_SEC rate |
// allow 20 seconds of test overhead for very small tests | // allow 20 seconds of test overhead for very small tests |
|
|
Uint32 noChangeIterations = 0; | Uint32 noChangeIterations = 0; |
Uint32 priorReceivedTrap1Count = 0; | Uint32 priorReceivedTrap1Count = 0; |
Uint32 priorReceivedTrap2Count = 0; | Uint32 priorReceivedTrap2Count = 0; |
|
Uint32 priorReceivedTrap3Count = 0; |
Uint32 currentReceivedTrap1Count = 0; | Uint32 currentReceivedTrap1Count = 0; |
Uint32 currentReceivedTrap2Count = 0; | Uint32 currentReceivedTrap2Count = 0; |
|
Uint32 currentReceivedTrap3Count = 0; |
Uint32 totalIterations = 0; | Uint32 totalIterations = 0; |
| |
// | // |
|
|
Boolean receivedTrapCountComplete = false; | Boolean receivedTrapCountComplete = false; |
Boolean receiverTrap1NoChange = true; | Boolean receiverTrap1NoChange = true; |
Boolean receiverTrap2NoChange = true; | Boolean receiverTrap2NoChange = true; |
|
Boolean receiverTrap3NoChange = true; |
| |
while (noChangeIterations <= MAX_NO_CHANGE_ITERATIONS) | while (noChangeIterations <= MAX_NO_CHANGE_ITERATIONS) |
{ | { |
|
|
_getReceivedTrapCount(_SNMPV1_TRAP, logFile); | _getReceivedTrapCount(_SNMPV1_TRAP, logFile); |
currentReceivedTrap2Count = | currentReceivedTrap2Count = |
_getReceivedTrapCount(_SNMPV2C_TRAP, logFile); | _getReceivedTrapCount(_SNMPV2C_TRAP, logFile); |
|
currentReceivedTrap3Count = |
|
_getReceivedTrapCount(_SNMPV3_TRAP,logFile); |
| |
if (totalIterations % COUT_TIME_INTERVAL == 1 && | if (totalIterations % COUT_TIME_INTERVAL == 1 && |
!(receivedTrapCountComplete)) | !(receivedTrapCountComplete)) |
|
|
<< currentReceivedTrap2Count << " of " | << currentReceivedTrap2Count << " of " |
<< indicationTrapV2SendCount << " SNMPv2c trap." | << indicationTrapV2SendCount << " SNMPv2c trap." |
<< endl; | << endl; |
|
cout << "++++ The trap receiver has received " |
|
<< currentReceivedTrap3Count<< " of " |
|
<< indicationTrapV3SendCount << " SNMPv3 trap." |
|
<< endl; |
} | } |
| |
if ((indicationTrapV1SendCount == currentReceivedTrap1Count) && | if ((indicationTrapV1SendCount == currentReceivedTrap1Count) && |
(indicationTrapV2SendCount == currentReceivedTrap2Count)) |
(indicationTrapV2SendCount == currentReceivedTrap2Count) && |
|
(indicationTrapV3SendCount == currentReceivedTrap3Count)) |
{ | { |
receivedTrapCountComplete = true; | receivedTrapCountComplete = true; |
trapReceiverElapsedTime.stop(); | trapReceiverElapsedTime.stop(); |
|
|
{ | { |
priorReceivedTrap2Count = currentReceivedTrap2Count; | priorReceivedTrap2Count = currentReceivedTrap2Count; |
} | } |
|
if (!(receiverTrap3NoChange = |
|
(priorReceivedTrap3Count == currentReceivedTrap3Count))) |
|
{ |
|
priorReceivedTrap3Count = currentReceivedTrap3Count; |
|
} |
| |
if (receivedTrapCountComplete) | if (receivedTrapCountComplete) |
{ | { |
|
|
<< currentReceivedTrap2Count << " of " | << currentReceivedTrap2Count << " of " |
<< indicationTrapV2SendCount << " SNMPv2c trap." | << indicationTrapV2SendCount << " SNMPv2c trap." |
<< endl; | << endl; |
|
cout << "++++ The trap receiver has received " |
|
<< currentReceivedTrap3Count << " of " |
|
<< indicationTrapV3SendCount<< " SNMPv3 trap." |
|
<< endl; |
| |
break; | break; |
} | } |
if (receiverTrap1NoChange || receiverTrap2NoChange) |
if (receiverTrap1NoChange || |
|
receiverTrap2NoChange || |
|
receiverTrap3NoChange) |
{ | { |
noChangeIterations++; | noChangeIterations++; |
} | } |
|
|
currentReceivedTrap1Count); | currentReceivedTrap1Count); |
PEGASUS_TEST_ASSERT(indicationTrapV2SendCount == | PEGASUS_TEST_ASSERT(indicationTrapV2SendCount == |
currentReceivedTrap2Count); | currentReceivedTrap2Count); |
|
PEGASUS_TEST_ASSERT(indicationTrapV3SendCount == |
|
currentReceivedTrap3Count); |
} | } |
| |
int _beginTest(CIMClient& workClient, | int _beginTest(CIMClient& workClient, |