(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.6 and 1.8

version 1.6, 2007/06/26 20:26:16 version 1.8, 2007/08/09 17:05:34
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Yi Zhou, Hewlett-Packard Company (Yi.Zhou@hp.com)  
 //  
 // Modified By:  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/PegasusAssert.h> #include <Pegasus/Common/PegasusAssert.h>
Line 54 
Line 50 
  
 const String SNMPV1_HANDLER_NAME = String ("SNMPHandler01"); const String SNMPV1_HANDLER_NAME = String ("SNMPHandler01");
 const String SNMPV2C_HANDLER_NAME = String ("SNMPHandler02"); const String SNMPV2C_HANDLER_NAME = String ("SNMPHandler02");
   const String SNMPV2C_IPV6_HANDLER_NAME = String ("SNMPHandler03");
 const String FILTER_NAME = String ("IPFilter01"); const String FILTER_NAME = String ("IPFilter01");
  
 enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3}; enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3};
Line 61 
Line 58 
  
 #define PORT_NUMBER 2006 #define PORT_NUMBER 2006
  
 Uint32 indicationSendCountTotal = 0;  
   
 AtomicInt errorsEncountered(0); AtomicInt errorsEncountered(0);
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 71 
Line 66 
 // //
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
  
 class T_Parms{  class T_Parms
   {
    public:    public:
     AutoPtr<CIMClient> client;     AutoPtr<CIMClient> client;
     Uint32 indicationSendCount;     Uint32 indicationSendCount;
Line 80 
Line 76 
  
 /////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
  
 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 96 
Line 91 
         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 113 
Line 107 
         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 130 
Line 124 
         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 157 
Line 151 
     handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"),     handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"),
         CIMValue ((Uint32) PORT_NUMBER)));         CIMValue ((Uint32) PORT_NUMBER)));
  
     return(client.createInstance (PEGASUS_NAMESPACENAME_INTEROP, 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 180 
Line 175 
     filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),     filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),
         SOURCE_NAMESPACE.getString ()));         SOURCE_NAMESPACE.getString ()));
  
     return(client.createInstance (PEGASUS_NAMESPACENAME_INTEROP, 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 196 
Line 191 
     subscriptionInstance.addProperty (CIMProperty     subscriptionInstance.addProperty (CIMProperty
         (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));         (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));
  
     return(client.createInstance (PEGASUS_NAMESPACENAME_INTEROP, 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 227 
Line 225 
     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 (PEGASUS_NAMESPACENAME_INTEROP, 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 (PEGASUS_NAMESPACENAME_INTEROP, 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);
Line 275 
Line 274 
     CIMObjectPath filterObjectPath;     CIMObjectPath filterObjectPath;
     CIMObjectPath snmpv1HandlerObjectPath;     CIMObjectPath snmpv1HandlerObjectPath;
     CIMObjectPath snmpv2HandlerObjectPath;     CIMObjectPath snmpv2HandlerObjectPath;
       CIMObjectPath snmpv2IPV6HandlerObjectPath;
  
     try     try
     {     {
Line 391 
Line 391 
             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 423 
Line 472 
             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 460 
Line 527 
             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 493 
Line 574 
         }         }
         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 621 
Line 703 
     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 637 
Line 725 
  
     Uint32 iterations = 0;     Uint32 iterations = 0;
  
     // Wait until snmptrapd startted      // Wait until snmptrapd started
     while (iterations < MAX_ITERATIONS)     while (iterations < MAX_ITERATIONS)
     {     {
         iterations++;         iterations++;
Line 667 
Line 755 
     }     }
 } }
  
 void _receiveExpectedTraps(CIMClient& workClient,  void _receiveExpectedTraps(
       CIMClient& workClient,
     Uint32 indicationSendCount,     Uint32 indicationSendCount,
     Uint32 runClientThreadCount)     Uint32 runClientThreadCount)
 { {
       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 684 
Line 783 
 #define MSG_PER_SEC 4 #define MSG_PER_SEC 4
  
     Uint32 testTimeout = PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS     Uint32 testTimeout = PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS
                         + (indicationSendCountTotal/MSG_PER_SEC)*1000;                          + (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 733 
Line 832 
  
     //     //
     // 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 758 
Line 859 
         {         {
             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 788 
Line 889 
         {         {
             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 815 
Line 916 
     }     }
  
     // 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);
 } }
  


Legend:
Removed from v.1.6  
changed lines
  Added in v.1.8

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2