version 1.9, 2007/09/07 18:43:08
|
version 1.23.10.1, 2013/10/23 03:46:13
|
|
|
//%2006//////////////////////////////////////////////////////////////////////// |
//%LICENSE//////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Licensed to The Open Group (TOG) under one or more contributor license |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with |
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; |
// this work for additional information regarding copyright ownership. |
// IBM Corp.; EMC Corporation, The Open Group. |
// Each contributor licenses this file to you under the OpenPegasus Open |
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; |
// Source License; you may not use this file except in compliance with the |
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// License. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
|
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// Permission is hereby granted, free of charge, to any person obtaining a |
// of this software and associated documentation files (the "Software"), to |
// copy of this software and associated documentation files (the "Software"), |
// deal in the Software without restriction, including without limitation the |
// to deal in the Software without restriction, including without limitation |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// sell copies of the Software, and to permit persons to whom the Software is |
// and/or sell copies of the Software, and to permit persons to whom the |
// furnished to do so, subject to the following conditions: |
// Software is furnished to do so, subject to the following conditions: |
// | // |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// The above copyright notice and this permission notice shall be included |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// in all copies or substantial portions of the Software. |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
|
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
|
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
// | // |
//============================================================================== |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
// |
|
////////////////////////////////////////////////////////////////////////// |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
#include <Pegasus/Common/Thread.h> | #include <Pegasus/Common/Thread.h> |
#include <Pegasus/Common/Constants.h> | #include <Pegasus/Common/Constants.h> |
#include <Pegasus/Common/FileSystem.h> | #include <Pegasus/Common/FileSystem.h> |
#include <Pegasus/Common/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> |
|
#ifdef PEGASUS_USE_NET_SNMP |
|
# include <net-snmp/net-snmp-config.h> |
|
# include <net-snmp/net-snmp-includes.h> |
|
#endif |
| |
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 FILTER_NAME = "IPFilter01"; |
const String SNMPV3_HANDLER_NAME = "SNMPHandler04"; |
|
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 |
|
|
class T_Parms | class T_Parms |
{ | { |
public: | public: |
AutoPtr<CIMClient> client; |
CIMClient* client; |
Uint32 indicationSendCount; | Uint32 indicationSendCount; |
Uint32 uniqueID; | Uint32 uniqueID; |
}; | }; |
|
|
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 |
|
|
handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"), | handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"), |
CIMValue ((Uint32) PORT_NUMBER))); | CIMValue ((Uint32) PORT_NUMBER))); |
| |
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
if(snmpVersion == _SNMPV3_TRAP) |
|
{ |
|
|
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPEngineID"),snmpEngineID)); |
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPSecurityLevel"),snmpSecLevel)); //AuthPriv |
|
handlerInstance.addProperty (CIMProperty ( |
|
CIMName ("SNMPSecurityAuthProtocol"),snmpSecAuthProto)); |
|
|
|
size_t snmpSecAuthProtoLen=0; |
|
|
|
oid *snmpSecAuthProtoOid = NULL; |
|
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); |
|
} |
|
} |
|
#endif // ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
|
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 |
|
|
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
// 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; |
|
} |
|
} |
|
#endif // ifdef PEGASUS_ENABLE_NET_SNMPV3 |
} | } |
| |
void _cleanup (CIMClient & client) | void _cleanup (CIMClient & client) |
|
|
} | } |
#endif | #endif |
| |
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
try |
|
{ |
|
_deleteSubscriptionInstance (client, FILTER_NAME, |
|
SNMPV3_HANDLER_NAME); |
|
} |
|
catch (CIMException& e) |
|
{ |
|
if (e.getCode() != CIM_ERR_NOT_FOUND) |
|
{ |
|
cerr << "----- Error: deleteSubscriptionInstance failure: " |
|
<< endl; |
|
throw; |
|
} |
|
} |
|
#endif |
|
|
try | try |
{ | { |
_deleteFilterInstance (client, FILTER_NAME); | _deleteFilterInstance (client, FILTER_NAME); |
|
|
} | } |
} | } |
#endif | #endif |
|
|
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
try |
|
{ |
|
_deleteHandlerInstance (client, SNMPV3_HANDLER_NAME); |
|
} |
|
catch (CIMException& e) |
|
{ |
|
if (e.getCode() != CIM_ERR_NOT_FOUND) |
|
{ |
|
cerr << "----- Error: deleteHandlerInstance failure: " << endl; |
|
throw; |
|
} |
|
} |
|
#endif |
} | } |
| |
static void _testEnd(const String& uniqueID, const double elapsedTime) | static void _testEnd(const String& uniqueID, const double elapsedTime) |
|
|
ThreadReturnType PEGASUS_THREAD_CDECL _executeTests(void *parm) | ThreadReturnType PEGASUS_THREAD_CDECL _executeTests(void *parm) |
{ | { |
Thread *my_thread = (Thread *)parm; | Thread *my_thread = (Thread *)parm; |
T_Parms *parms = (T_Parms *)my_thread->get_parm(); |
AutoPtr<T_Parms> parms((T_Parms *)my_thread->get_parm()); |
CIMClient *client = parms->client.get(); |
CIMClient* client = parms->client; |
Uint32 indicationSendCount = parms->indicationSendCount; | Uint32 indicationSendCount = parms->indicationSendCount; |
Uint32 id = parms->uniqueID; | Uint32 id = parms->uniqueID; |
char id_[4]; | char id_[4]; |
memset(id_,0x00,sizeof(id_)); | memset(id_,0x00,sizeof(id_)); |
sprintf(id_,"%i",id); |
sprintf(id_,"%u",id); |
String uniqueID = "_"; | String uniqueID = "_"; |
uniqueID.append(id_); | uniqueID.append(id_); |
| |
|
|
{ | { |
cout << e.getMessage() << endl; | cout << e.getMessage() << endl; |
} | } |
my_thread->exit_self((ThreadReturnType)1); |
|
return(0); |
return ThreadReturnType(0); |
} | } |
| |
Thread * _runTestThreads( | Thread * _runTestThreads( |
|
|
{ | { |
// package parameters, create thread and run... | // package parameters, create thread and run... |
AutoPtr<T_Parms> parms(new T_Parms()); | AutoPtr<T_Parms> parms(new T_Parms()); |
parms->client.reset(client); |
parms->client = client; |
parms->indicationSendCount = indicationSendCount; | parms->indicationSendCount = indicationSendCount; |
parms->uniqueID = uniqueID; | parms->uniqueID = uniqueID; |
AutoPtr<Thread> t(new Thread(_executeTests, (void*)parms.release(), false)); | AutoPtr<Thread> t(new Thread(_executeTests, (void*)parms.release(), false)); |
|
|
return t.release(); | return t.release(); |
} | } |
| |
String _getLogFile() |
Uint32 _getReceivedTrapCount(Uint16 snmpVersion, const String& logFile) |
{ |
|
return("trapLogFile"); |
|
} |
|
|
|
Uint32 _getReceivedTrapCount(Uint16 snmpVersion) |
|
{ | { |
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; |
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
Uint32 receivedTrap3Count = 0; |
|
#endif |
| |
ifstream ifs(_getLogFile().getCString()); |
ifstream ifs(logFile.getCString()); |
if (!ifs) | if (!ifs) |
{ | { |
return (0); | return (0); |
|
|
{ | { |
receivedTrap2Count++; | receivedTrap2Count++; |
} | } |
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
if (String::compare(line, trap3) == 0) |
|
{ |
|
receivedTrap3Count++; |
|
} |
|
#endif |
} | } |
| |
ifs.close(); | ifs.close(); |
|
|
{ | { |
return (receivedTrap2Count); | return (receivedTrap2Count); |
} | } |
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
case _SNMPV3_TRAP: |
|
{ |
|
return (receivedTrap3Count); |
|
} |
|
#endif |
default: | default: |
{ | { |
return (0); | return (0); |
|
|
// Stop snmptrapd process if it is running and remove | // Stop snmptrapd process if it is running and remove |
// procIdFile file if it exists | // procIdFile file if it exists |
// | // |
void _stopSnmptrapd() |
void _stopSnmptrapd(const String& processIdFile) |
{ | { |
String procIdFileName = "procIdFile"; |
|
|
|
Uint32 receiverPid; | Uint32 receiverPid; |
FILE *fd; | FILE *fd; |
if ((fd = fopen(procIdFileName.getCString(), "r")) != NULL) |
if ((fd = fopen(processIdFile.getCString(), "r")) != NULL) |
{ | { |
fscanf(fd, "%d\n", &receiverPid); |
if (fscanf(fd, "%d\n", &receiverPid) != 1) |
|
{ |
|
throw Exception("Failed to read trapd pid from procIdFile."); |
|
} |
| |
kill(receiverPid, SIGTERM); | kill(receiverPid, SIGTERM); |
| |
fclose(fd); | fclose(fd); |
} | } |
| |
if (FileSystem::exists(procIdFileName)) |
if (FileSystem::exists(processIdFile)) |
{ | { |
FileSystem::removeFile(procIdFileName); |
FileSystem::removeFile(processIdFile); |
} | } |
} | } |
| |
static Boolean _startSnmptrapd( | static Boolean _startSnmptrapd( |
FILE **trapInfo) |
FILE **trapInfo, |
|
const String& processIdFile, |
|
const String& logFile) |
{ | { |
String snmptrapdCmd; | String snmptrapdCmd; |
| |
|
|
// Specify logging incoming traps to trapLogFile | // Specify logging incoming traps to trapLogFile |
// Save the process ID of the snmptrapd in procIdFile | // Save the process ID of the snmptrapd in procIdFile |
snmptrapdCmd.append( | snmptrapdCmd.append( |
"/usr/sbin/snmptrapd -f -Lf trapLogFile -p procIdFile"); |
"/usr/sbin/snmptrapd -f -Lf "); |
|
snmptrapdCmd.append(logFile); |
|
snmptrapdCmd.append(" -p "); |
|
snmptrapdCmd.append(processIdFile); |
| |
// Specify incoming trap format | // Specify incoming trap format |
snmptrapdCmd.append( " -F \"\nTrap Info: %P\nVariable: %v\n\""); | snmptrapdCmd.append( " -F \"\nTrap Info: %P\nVariable: %v\n\""); |
|
|
while (iterations < MAX_ITERATIONS) | while (iterations < MAX_ITERATIONS) |
{ | { |
iterations++; | iterations++; |
if (FileSystem::exists("procIdFile")) |
if (FileSystem::exists(processIdFile)) |
{ | { |
return (true); | return (true); |
} | } |
|
|
} | } |
#endif | #endif |
| |
void _removeTrapLogFile () |
void _removeTrapLogFile(const String& logFile) |
{ | { |
String logFile = _getLogFile(); |
|
|
|
// if trapLogFile exists, remove it | // if trapLogFile exists, remove it |
if (FileSystem::exists(logFile)) | if (FileSystem::exists(logFile)) |
{ | { |
|
|
void _receiveExpectedTraps( | void _receiveExpectedTraps( |
CIMClient& workClient, | CIMClient& workClient, |
Uint32 indicationSendCount, | Uint32 indicationSendCount, |
Uint32 runClientThreadCount) |
Uint32 runClientThreadCount, |
|
const String& logFile) |
{ | { |
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 |
| |
|
#ifdef PEGASUS_ENABLE_NET_SNMPV3 |
|
indicationTrapV3SendCount = |
|
indicationSendCount * runClientThreadCount; |
|
#endif |
|
|
// 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 |
|
|
for(Uint32 i=0; i< runClientThreadCount; i++) | for(Uint32 i=0; i< runClientThreadCount; i++) |
{ | { |
clientThreads[i]->join(); | clientThreads[i]->join(); |
|
delete clientThreads[i]; |
} | } |
| |
delete[] clientConnections; | delete[] clientConnections; |
|
|
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) |
{ | { |
totalIterations++; | totalIterations++; |
| |
currentReceivedTrap1Count = _getReceivedTrapCount(_SNMPV1_TRAP); |
currentReceivedTrap1Count = |
currentReceivedTrap2Count = _getReceivedTrapCount(_SNMPV2C_TRAP); |
_getReceivedTrapCount(_SNMPV1_TRAP, logFile); |
|
currentReceivedTrap2Count = |
|
_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, |
Uint32 indicationSendCount, | Uint32 indicationSendCount, |
Uint32 runClientThreadCount) |
Uint32 runClientThreadCount, |
|
const String& processIdFile, |
|
const String& logFile) |
{ | { |
| |
#ifdef PEGASUS_USE_NET_SNMP | #ifdef PEGASUS_USE_NET_SNMP |
| |
// Stop snmptrapd process if it is running | // Stop snmptrapd process if it is running |
_stopSnmptrapd(); |
_stopSnmptrapd(processIdFile); |
| |
// if trapLogFile exists, remove it | // if trapLogFile exists, remove it |
_removeTrapLogFile(); |
_removeTrapLogFile(logFile); |
| |
FILE * trapInfo; | FILE * trapInfo; |
| |
try | try |
{ | { |
_startSnmptrapd(&trapInfo); |
_startSnmptrapd(&trapInfo, processIdFile, logFile); |
} | } |
catch (Exception & e) | catch (Exception & e) |
{ | { |
|
|
| |
// Extended for all snmp implementation | // Extended for all snmp implementation |
_receiveExpectedTraps(workClient, indicationSendCount, | _receiveExpectedTraps(workClient, indicationSendCount, |
runClientThreadCount); |
runClientThreadCount, logFile); |
| |
// Stop snmptrapd process if it is running and remove procIdFile | // Stop snmptrapd process if it is running and remove procIdFile |
_stopSnmptrapd(); |
_stopSnmptrapd(processIdFile); |
| |
pclose(trapInfo); | pclose(trapInfo); |
| |
|
|
{ | { |
workClient.connectLocal(); | workClient.connectLocal(); |
| |
|
String processIdFile = TRAP_DIR; |
|
processIdFile.append("/procIdFile"); |
|
|
|
String logFile = TRAP_DIR; |
|
logFile.append("/trapLogFile"); |
|
|
if (argc <= 1 || argc > 4) | if (argc <= 1 || argc > 4) |
{ | { |
cerr << "Invalid argument count: " << argc << endl; | cerr << "Invalid argument count: " << argc << endl; |
|
|
} | } |
| |
int rc = _beginTest(workClient, indicationSendCount, | int rc = _beginTest(workClient, indicationSendCount, |
runClientThreadCount); |
runClientThreadCount, processIdFile, logFile); |
return rc; | return rc; |
} | } |
else if (String::equalNoCase(argv[1], "cleanup")) | else if (String::equalNoCase(argv[1], "cleanup")) |
|
|
return -1; | return -1; |
} | } |
| |
_removeTrapLogFile (); |
_removeTrapLogFile(logFile); |
cout << "+++++ removelog completed successfully" << endl; | cout << "+++++ removelog completed successfully" << endl; |
return 0; | return 0; |
} | } |
|
|
cerr << "Error: " << e.getMessage() << endl; | cerr << "Error: " << e.getMessage() << endl; |
} | } |
| |
PEGASUS_UNREACHABLE( return 0; ) |
return -1; |
} | } |