(file) Return to testSnmpHandler.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler / tests / testclient

Diff for /pegasus/src/Pegasus/Handler/snmpIndicationHandler/tests/testclient/testSnmpHandler.cpp between version 1.2.14.1 and 1.19

version 1.2.14.1, 2006/07/27 23:12:03 version 1.19, 2008/12/16 18:56:45
Line 1 
Line 1 
 //%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  
 // of this software and associated documentation files (the "Software"), to  
 // deal in the Software without restriction, including without limitation the  
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  
 // sell copies of the Software, and to permit persons to whom the Software is  
 // furnished to do so, subject to the following conditions:  
 //  
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF 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.  
 // //
 //==============================================================================  // Permission is hereby granted, free of charge, to any person obtaining a
   // copy of this software and associated documentation files (the "Software"),
   // to deal in the Software without restriction, including without limitation
   // the rights to use, copy, modify, merge, publish, distribute, sublicense,
   // and/or sell copies of the Software, and to permit persons to whom the
   // Software is furnished to do so, subject to the following conditions:
 // //
 // Author: Yi Zhou, Hewlett-Packard Company (Yi.Zhou@hp.com)  // The above copyright notice and this permission notice shall be included
   // in all copies or substantial portions of the Software.
 // //
 // Modified By:  // 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.
   //
   //////////////////////////////////////////////////////////////////////////
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 41 
Line 35 
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
 #include <Pegasus/Common/Stopwatch.h> #include <Pegasus/Common/Stopwatch.h>
 #include <Pegasus/Client/CIMClient.h> #include <Pegasus/Client/CIMClient.h>
   #include <Pegasus/Common/HostAddress.h>
  
 PEGASUS_USING_PEGASUS; PEGASUS_USING_PEGASUS;
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 const CIMNamespaceName INTEROP_NAMESPACE = CIMNamespaceName ("root/PG_InterOp");  // Interop namespace used with PEGASUS_NAMESPACENAME_INTEROP in Constants.h
 const CIMNamespaceName SOURCE_NAMESPACE = const CIMNamespaceName SOURCE_NAMESPACE =
     CIMNamespaceName ("root/SampleProvider");      CIMNamespaceName ("test/TestProvider");
  
 const String INDICATION_CLASS_NAME = String ("RT_TestIndication");  const String INDICATION_CLASS_NAME = "Test_IndicationProviderClass";
  
 const String SNMPV1_HANDLER_NAME = String ("SNMPHandler01");  const String SNMPV1_HANDLER_NAME = "SNMPHandler01";
 const String SNMPV2C_HANDLER_NAME = String ("SNMPHandler02");  const String SNMPV2C_HANDLER_NAME = "SNMPHandler02";
 const String FILTER_NAME = String ("IPFilter01");  const String SNMPV2C_IPV6_HANDLER_NAME = "SNMPHandler03";
   const String FILTER_NAME = "SNMPIPFilter01";
  
 enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3}; enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3};
 enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3};  enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4};
  
 #define PORT_NUMBER 2006 #define PORT_NUMBER 2006
  
 Uint32 indicationSendCountTotal = 0;  
   
 AtomicInt errorsEncountered(0); AtomicInt errorsEncountered(0);
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 70 
Line 64 
 // //
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
  
 class T_Parms{  class T_Parms
   {
    public:    public:
     AutoPtr<CIMClient> client;      CIMClient* client;
     Uint32 indicationSendCount;     Uint32 indicationSendCount;
     Uint32 uniqueID;     Uint32 uniqueID;
 }; };
  
 /////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
  
 CIMObjectPath _getFilterObjectPath  CIMObjectPath _getFilterObjectPath(const String & name)
     (const String & name)  
 { {
     Array<CIMKeyBinding> keyBindings;     Array<CIMKeyBinding> keyBindings;
     keyBindings.append (CIMKeyBinding ("SystemCreationClassName",     keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
Line 95 
Line 89 
         PEGASUS_CLASSNAME_INDFILTER, keyBindings));         PEGASUS_CLASSNAME_INDFILTER, keyBindings));
 } }
  
 CIMObjectPath _getHandlerObjectPath  CIMObjectPath _getHandlerObjectPath(const String & name)
     (const String & name)  
 { {
     Array<CIMKeyBinding> keyBindings;     Array<CIMKeyBinding> keyBindings;
     keyBindings.append (CIMKeyBinding ("SystemCreationClassName",     keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
Line 112 
Line 105 
         PEGASUS_CLASSNAME_INDHANDLER_SNMP, keyBindings));         PEGASUS_CLASSNAME_INDHANDLER_SNMP, keyBindings));
 } }
  
 CIMObjectPath _getSubscriptionObjectPath  CIMObjectPath _getSubscriptionObjectPath(
     (const String & filterName,      const String & filterName,
      const String & handlerName)      const String & handlerName)
 { {
     CIMObjectPath filterObjectPath = _getFilterObjectPath(filterName);     CIMObjectPath filterObjectPath = _getFilterObjectPath(filterName);
Line 129 
Line 122 
         PEGASUS_CLASSNAME_INDSUBSCRIPTION, subscriptionKeyBindings));         PEGASUS_CLASSNAME_INDSUBSCRIPTION, subscriptionKeyBindings));
 } }
  
 CIMObjectPath _createHandlerInstance  CIMObjectPath _createHandlerInstance(
     (CIMClient & client,      CIMClient & client,
      const String & name,      const String & name,
      const String & targetHost,      const String & targetHost,
      const String & securityName,      const String & securityName,
Line 156 
Line 149 
     handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"),     handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"),
         CIMValue ((Uint32) PORT_NUMBER)));         CIMValue ((Uint32) PORT_NUMBER)));
  
     return(client.createInstance (INTEROP_NAMESPACE, handlerInstance));      return client.createInstance(
           PEGASUS_NAMESPACENAME_INTEROP, handlerInstance);
 } }
  
 CIMObjectPath _createFilterInstance  CIMObjectPath _createFilterInstance(
     (CIMClient & client,      CIMClient & client,
      const String & name,      const String & name,
      const String & query,      const String & query,
      const String & qlang)      const String & qlang)
Line 179 
Line 173 
     filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),     filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),
         SOURCE_NAMESPACE.getString ()));         SOURCE_NAMESPACE.getString ()));
  
     return(client.createInstance (INTEROP_NAMESPACE, filterInstance));      return client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, filterInstance);
 } }
  
 CIMObjectPath _createSubscriptionInstance  CIMObjectPath _createSubscriptionInstance(
     (CIMClient & client,      CIMClient & client,
      const CIMObjectPath & filterPath,      const CIMObjectPath & filterPath,
      const CIMObjectPath & handlerPath)      const CIMObjectPath & handlerPath)
 { {
Line 195 
Line 189 
     subscriptionInstance.addProperty (CIMProperty     subscriptionInstance.addProperty (CIMProperty
         (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));         (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));
  
     return(client.createInstance (INTEROP_NAMESPACE, subscriptionInstance));      return client.createInstance(
           PEGASUS_NAMESPACENAME_INTEROP, subscriptionInstance);
 } }
  
 void _sendTestIndication(CIMClient* client, const CIMName & methodName,  void _sendTestIndication(
       CIMClient* client,
       const CIMName & methodName,
                          Uint32 indicationSendCount)                          Uint32 indicationSendCount)
 { {
     //     //
Line 210 
Line 207 
     Sint32 result;     Sint32 result;
  
     CIMObjectPath className (String::EMPTY, CIMNamespaceName (),     CIMObjectPath className (String::EMPTY, CIMNamespaceName (),
         CIMName ("RT_TestIndication"), keyBindings);          CIMName ("Test_IndicationProviderClass"), keyBindings);
  
     inParams.append(CIMParamValue(String("indicationSendCount"),     inParams.append(CIMParamValue(String("indicationSendCount"),
         CIMValue(indicationSendCount)));         CIMValue(indicationSendCount)));
Line 226 
Line 223 
     PEGASUS_TEST_ASSERT (result == 0);     PEGASUS_TEST_ASSERT (result == 0);
 } }
  
 void _deleteSubscriptionInstance  void _deleteSubscriptionInstance(
     (CIMClient & client,      CIMClient & client,
      const String & filterName,      const String & filterName,
      const String & handlerName)      const String & handlerName)
 { {
     CIMObjectPath subscriptionObjectPath =     CIMObjectPath subscriptionObjectPath =
        _getSubscriptionObjectPath(filterName, handlerName);        _getSubscriptionObjectPath(filterName, handlerName);
     client.deleteInstance (INTEROP_NAMESPACE, subscriptionObjectPath);      client.deleteInstance(
           PEGASUS_NAMESPACENAME_INTEROP, subscriptionObjectPath);
 } }
  
 void _deleteHandlerInstance  void _deleteHandlerInstance(
     (CIMClient & client,      CIMClient & client,
      const String & name)      const String & name)
 { {
     CIMObjectPath handlerObjectPath = _getHandlerObjectPath(name);     CIMObjectPath handlerObjectPath = _getHandlerObjectPath(name);
     client.deleteInstance (INTEROP_NAMESPACE, handlerObjectPath);      client.deleteInstance (PEGASUS_NAMESPACENAME_INTEROP, handlerObjectPath);
 } }
  
 void _deleteFilterInstance  void _deleteFilterInstance(
     (CIMClient & client,      CIMClient & client,
      const String & name)      const String & name)
 { {
     CIMObjectPath filterObjectPath = _getFilterObjectPath(name);     CIMObjectPath filterObjectPath = _getFilterObjectPath(name);
     client.deleteInstance (INTEROP_NAMESPACE, filterObjectPath);      client.deleteInstance (PEGASUS_NAMESPACENAME_INTEROP, filterObjectPath);
 } }
  
 void _usage () void _usage ()
Line 274 
Line 272 
     CIMObjectPath filterObjectPath;     CIMObjectPath filterObjectPath;
     CIMObjectPath snmpv1HandlerObjectPath;     CIMObjectPath snmpv1HandlerObjectPath;
     CIMObjectPath snmpv2HandlerObjectPath;     CIMObjectPath snmpv2HandlerObjectPath;
       CIMObjectPath snmpv2IPV6HandlerObjectPath;
  
     try     try
     {     {
         filterObjectPath = _createFilterInstance (client, FILTER_NAME,         filterObjectPath = _createFilterInstance (client, FILTER_NAME,
             String ("SELECT * FROM RT_TestIndication"),              String ("SELECT * FROM Test_IndicationProviderClass"),
             qlang);             qlang);
     }     }
     catch (CIMException& e)     catch (CIMException& e)
Line 344 
Line 343 
  
     try     try
     {     {
           String ipAddress;
           int af;
           System::getHostIP(System::getFullyQualifiedHostName (), &af, ipAddress);
         // Create SNMPv2 trap handler         // Create SNMPv2 trap handler
         snmpv2HandlerObjectPath = _createHandlerInstance (client,         snmpv2HandlerObjectPath = _createHandlerInstance (client,
             SNMPV2C_HANDLER_NAME,             SNMPV2C_HANDLER_NAME,
             System::getHostIP(System::getFullyQualifiedHostName ()),              ipAddress,
             "public",             "public",
             _IPV4_ADDRESS,              af == AF_INET ? _IPV4_ADDRESS : _IPV6_ADDRESS,
             _SNMPV2C_TRAP);             _SNMPV2C_TRAP);
     }     }
     catch (CIMException& e)     catch (CIMException& e)
Line 387 
Line 389 
             throw;             throw;
         }         }
     }     }
   
   #if defined(PEGASUS_ENABLE_IPV6)
       // create a subscription with trap destination of IPV6 address format
       try
       {
           // Create SNMPv2 IPV6 trap handler
           snmpv2IPV6HandlerObjectPath = _createHandlerInstance (client,
               SNMPV2C_IPV6_HANDLER_NAME,
               String("::1"),
               "public",
               _IPV6_ADDRESS,
               _SNMPV2C_TRAP);
       }
       catch (CIMException& e)
       {
           if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
           {
               snmpv2IPV6HandlerObjectPath = _getHandlerObjectPath(
                   SNMPV2C_IPV6_HANDLER_NAME);
               cerr << "----- Warning: SNMPv2c IPV6 Trap Handler Instance "
                   "Not Created: " << e.getMessage () << endl;
           }
           else
           {
               cerr << "----- Error: SNMPv2c IPV6 Trap Handler Instance Not "
                   "Created: " << endl;
               throw;
           }
       }
   
       try
       {
           _createSubscriptionInstance (client, filterObjectPath,
                snmpv2IPV6HandlerObjectPath);
       }
       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
 } }
  
 void _cleanup (CIMClient & client) void _cleanup (CIMClient & client)
Line 419 
Line 470 
             throw;             throw;
         }         }
     }     }
   
   #if defined(PEGASUS_ENABLE_IPV6)
       try
       {
           _deleteSubscriptionInstance (client, FILTER_NAME,
               SNMPV2C_IPV6_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);
Line 456 
Line 525 
             throw;             throw;
         }         }
     }     }
   #if defined(PEGASUS_ENABLE_IPV6)
       try
       {
           _deleteHandlerInstance (client, SNMPV2C_IPV6_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)
Line 467 
Line 550 
 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_);
  
Line 489 
Line 572 
         }         }
         catch (Exception & e)         catch (Exception & e)
         {         {
             cerr << "----- sendTestIndication failed: " << e.getMessage () << endl;              cerr << "----- sendTestIndication failed: " << e.getMessage () <<
                   endl;
             exit (-1);             exit (-1);
         }         }
         elapsedTime.stop();         elapsedTime.stop();
Line 499 
Line 583 
     {     {
         cout << e.getMessage() << endl;         cout << e.getMessage() << endl;
     }     }
     my_thread->exit_self((ThreadReturnType)1);  
     return(0);      return ThreadReturnType(0);
 } }
  
 Thread * _runTestThreads( Thread * _runTestThreads(
Line 510 
Line 594 
 { {
     // 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));
Line 518 
Line 602 
     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";
Line 531 
Line 610 
     Uint32 receivedTrap1Count = 0;     Uint32 receivedTrap1Count = 0;
     Uint32 receivedTrap2Count = 0;     Uint32 receivedTrap2Count = 0;
  
     ifstream ifs(_getLogFile().getCString());      ifstream ifs(logFile.getCString());
     if (!ifs)     if (!ifs)
     {     {
         return (0);         return (0);
Line 574 
Line 653 
 // 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;
  
Line 611 
Line 693 
     // 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\"");
  
     // Specify listening address     // Specify listening address
   #if defined(PEGASUS_ENABLE_IPV6)
       snmptrapdCmd.append(" UDP6:");
       snmptrapdCmd.append(portNumberStr);
       snmptrapdCmd.append(",UDP:");
   #else
     snmptrapdCmd.append(" UDP:");     snmptrapdCmd.append(" UDP:");
   #endif
     snmptrapdCmd.append(System::getFullyQualifiedHostName ());     snmptrapdCmd.append(System::getFullyQualifiedHostName ());
  
     snmptrapdCmd.append(":");     snmptrapdCmd.append(":");
Line 633 
Line 724 
  
     Uint32 iterations = 0;     Uint32 iterations = 0;
  
     // Wait until snmptrapd startted      // Wait until snmptrapd started
     while (iterations < MAX_ITERATIONS)     while (iterations < MAX_ITERATIONS)
     {     {
         iterations++;         iterations++;
         if (FileSystem::exists("procIdFile"))          if (FileSystem::exists(processIdFile))
         {         {
             return (true);             return (true);
         }         }
Line 652 
Line 743 
 } }
 #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))
     {     {
Line 663 
Line 752 
     }     }
 } }
  
 void _receiveExpectedTraps(CIMClient& workClient,  void _receiveExpectedTraps(
       CIMClient& workClient,
     Uint32 indicationSendCount,     Uint32 indicationSendCount,
     Uint32 runClientThreadCount)      Uint32 runClientThreadCount,
       const String& logFile)
 { {
       Uint32 indicationTrapV1SendCount = 0;
       Uint32 indicationTrapV2SendCount = 0;
  
     CIMClient * clientConnections = new CIMClient[runClientThreadCount];     CIMClient * clientConnections = new CIMClient[runClientThreadCount];
  
     // determine total number of indication send count     // determine total number of indication send count
     indicationSendCountTotal = indicationSendCount * runClientThreadCount;      indicationTrapV1SendCount =
           indicationSendCount * runClientThreadCount;
   
       // if IPV6 is enabled, an additional SNMPv2c trap is sent to IPV6 address
   #if defined(PEGASUS_ENABLE_IPV6)
       indicationTrapV2SendCount = 2 * indicationTrapV1SendCount;
   #else
       indicationTrapV2SendCount = indicationTrapV1SendCount;
   #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
Line 679 
Line 780 
  
 #define MSG_PER_SEC 4 #define MSG_PER_SEC 4
  
     Uint32 testTimeout = 20000+(indicationSendCountTotal/MSG_PER_SEC)*1000;      Uint32 testTimeout = PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS
                           + (indicationTrapV2SendCount/MSG_PER_SEC)*1000;
  
     // connect the clients     // connect the clients
     for(Uint32 i = 0; i < runClientThreadCount; i++)     for(Uint32 i = 0; i < runClientThreadCount; i++)
Line 704 
Line 806 
     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;
Line 728 
Line 831 
  
     //     //
     // Wait for the trap receiver to receive the expected     // Wait for the trap receiver to receive the expected
     // number of Indication traps, indicationSendCountTotal.      // number of Indication traps, indicationTrapV1SendCount
       // and indicationTrapV2SendCount.
     //     //
     // We will continue to wait until either indicationSendCountTotal      // We will continue to wait until either (indicationTrapV1SendCount
     // Indications have been received by the trap receiver or no new      // and indicationTrapV2SendCount) Indications have been received
       // by the trap receiver or no new
     // Indications have been received in the previous     // Indications have been received in the previous
     // MAX_NO_CHANGE_ITERATIONS.     // MAX_NO_CHANGE_ITERATIONS.
     // iterations.     // iterations.
Line 745 
Line 850 
     {     {
         totalIterations++;         totalIterations++;
  
         currentReceivedTrap1Count = _getReceivedTrapCount(_SNMPV1_TRAP);          currentReceivedTrap1Count =
         currentReceivedTrap2Count = _getReceivedTrapCount(_SNMPV2C_TRAP);              _getReceivedTrapCount(_SNMPV1_TRAP, logFile);
           currentReceivedTrap2Count =
               _getReceivedTrapCount(_SNMPV2C_TRAP, logFile);
  
         if (totalIterations % COUT_TIME_INTERVAL == 1 &&         if (totalIterations % COUT_TIME_INTERVAL == 1 &&
             !(receivedTrapCountComplete))             !(receivedTrapCountComplete))
         {         {
             cout << "++++ The trap receiver has received "             cout << "++++ The trap receiver has received "
             << currentReceivedTrap1Count << " of "             << currentReceivedTrap1Count << " of "
             << indicationSendCountTotal << " SNMPv1 trap."              << indicationTrapV1SendCount << " SNMPv1 trap."
             << endl;             << endl;
             cout << "++++ The trap receiver has received "             cout << "++++ The trap receiver has received "
             << currentReceivedTrap2Count << " of "             << currentReceivedTrap2Count << " of "
             << indicationSendCountTotal << " SNMPv2c trap."              << indicationTrapV2SendCount << " SNMPv2c trap."
             << endl;             << endl;
         }         }
  
         if ((indicationSendCountTotal == currentReceivedTrap1Count) &&          if ((indicationTrapV1SendCount == currentReceivedTrap1Count) &&
             (indicationSendCountTotal == currentReceivedTrap2Count))              (indicationTrapV2SendCount == currentReceivedTrap2Count))
         {         {
              receivedTrapCountComplete = true;              receivedTrapCountComplete = true;
              trapReceiverElapsedTime.stop();              trapReceiverElapsedTime.stop();
Line 783 
Line 890 
         {         {
             cout << "++++ The trap receiver has received "             cout << "++++ The trap receiver has received "
             << currentReceivedTrap1Count << " of "             << currentReceivedTrap1Count << " of "
             << indicationSendCountTotal << " SNMPv1 trap."              << indicationTrapV1SendCount << " SNMPv1 trap."
             << endl;             << endl;
             cout << "++++ The trap receiver has received "             cout << "++++ The trap receiver has received "
             << currentReceivedTrap2Count << " of "             << currentReceivedTrap2Count << " of "
             << indicationSendCountTotal << " SNMPv2c trap."              << indicationTrapV2SendCount << " SNMPv2c trap."
             << endl;             << endl;
  
             break;             break;
Line 810 
Line 917 
     }     }
  
     // assert that all indications sent have been received.     // assert that all indications sent have been received.
     PEGASUS_TEST_ASSERT(indicationSendCountTotal ==      PEGASUS_TEST_ASSERT(indicationTrapV1SendCount ==
        currentReceivedTrap1Count);        currentReceivedTrap1Count);
     PEGASUS_TEST_ASSERT(indicationSendCountTotal ==      PEGASUS_TEST_ASSERT(indicationTrapV2SendCount ==
        currentReceivedTrap2Count);        currentReceivedTrap2Count);
 } }
  
 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)
     {     {
Line 843 
Line 952 
  
     // 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);
  
Line 877 
Line 986 
     {     {
         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;
Line 924 
Line 1039 
             }             }
  
             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"))
Line 950 
Line 1065 
                 return -1;                 return -1;
             }             }
  
             _removeTrapLogFile ();              _removeTrapLogFile(logFile);
             cout << "+++++ removelog completed successfully" << endl;             cout << "+++++ removelog completed successfully" << endl;
             return 0;             return 0;
         }         }
Line 966 
Line 1081 
         cerr << "Error: " << e.getMessage() << endl;         cerr << "Error: " << e.getMessage() << endl;
     }     }
  
     PEGASUS_UNREACHABLE( return 0; )      return -1;
 } }


Legend:
Removed from v.1.2.14.1  
changed lines
  Added in v.1.19

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2