Пример #1
0
static uint32_t sendStateChangeNotificationClms(CLMS_CB * clms_cb,
					     SaNameT node_name,
					     SaUint8T *add_text,
					     SaUint16T majorId,
					     SaUint16T minorId,
					     uint32_t sourceIndicator, SaUint32T stateId, SaUint32T newState)
{
	uint32_t status = NCSCC_RC_FAILURE;
	SaNtfStateChangeNotificationT myStateNotification;

	status = saNtfStateChangeNotificationAllocate(clms_cb->ntf_hdl,	/* handle to Notification Service instance */
						      &myStateNotification,
						      /* number of correlated notifications */
						      0,
						      /* length of additional text */
						      ADDITION_TEXT_LENGTH,
						      /* number of additional info items */
						      0,
						      /* number of state changes */
						      1,
						      /* use default allocation size */
						      0);

	if (status != SA_AIS_OK) {
		/* log the error code here */
		return NCSCC_RC_FAILURE;
	}

	fill_ntf_header_part_clms(&myStateNotification.notificationHeader,
				  SA_NTF_OBJECT_STATE_CHANGE, node_name, add_text, majorId, minorId, CLMS_NTF_SENDER);

	*(myStateNotification.sourceIndicator) = sourceIndicator;
	myStateNotification.changedStates->stateId = stateId;
	myStateNotification.changedStates->oldStatePresent = SA_FALSE;
	myStateNotification.changedStates->newState = newState;

	status = saNtfNotificationSend(myStateNotification.notificationHandle);

	if (status != SA_AIS_OK) {
		saNtfNotificationFree(myStateNotification.notificationHandle);
		/* log the error code here */
		return NCSCC_RC_FAILURE;
	}

	status = saNtfNotificationFree(myStateNotification.notificationHandle);

	if (status != SA_AIS_OK) {
		/* log the error code here */
		return NCSCC_RC_FAILURE;
	}

	return status;

}
/**
 * Provoke a SA_AIS_ERR_BAD_HANDLE reply
 */
void saNtfPtrAllocateTest_03(void)
{
    SaStringT *destPtr;
    SaNtfAlarmNotificationT myAlarmNotification;

    safassert(saNtfInitialize(&ntfHandle, &ntfSendCallbacks, &ntfVersion) , SA_AIS_OK);

    safassert(saNtfAlarmNotificationAllocate(
                  ntfHandle,
                  &myAlarmNotification,
                  0,
                  0,
                  0,
                  0,
                  0,
                  2,
                  SA_NTF_ALLOC_SYSTEM_LIMIT), SA_AIS_OK);

    myAlarmNotification.proposedRepairActions[0].actionValueType = SA_NTF_VALUE_STRING;

    safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK);

    rc = saNtfPtrValAllocate(
             myAlarmNotification.notificationHandle,
             (SaUint16T)(strlen(DEFAULT_ADDITIONAL_TEXT) + 1),
             (void**) &destPtr,
             &(myAlarmNotification.proposedRepairActions[0].actionValue));

    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);

    test_validate(rc, SA_AIS_ERR_BAD_HANDLE);
}
void saNtfStateChangeNotificationAllocate_01(void) {
	SaNtfStateChangeNotificationT  myNotification;
	saNotificationAllocationParamsT myNotificationAllocationParams;
	saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams;
	saNotificationParamsT myNotificationParams;

	fillInDefaultValues(&myNotificationAllocationParams,
			&myNotificationFilterAllocationParams, &myNotificationParams);

	safassert(saNtfInitialize(&ntfHandle, &ntfSendCallbacks, &ntfVersion), SA_AIS_OK);

	rc = saNtfStateChangeNotificationAllocate(
					ntfHandle, /* handle to Notification Service instance */
					&myNotification,
					/* number of correlated notifications */
					myNotificationAllocationParams.numCorrelatedNotifications,
					/* length of additional text */
					myNotificationAllocationParams.lengthAdditionalText,
					/* number of additional info items*/
					myNotificationAllocationParams.numAdditionalInfo,
					/* number of state changes */
					myNotificationAllocationParams.numAttributes,
					/* use default allocation size */
					myNotificationAllocationParams.variableDataSize);

	safassert(saNtfNotificationFree(myNotification.notificationHandle) , SA_AIS_OK);
	safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK);
	test_validate(rc, SA_AIS_OK);
}
/**
 * Provoke a SA_AIS_ERR_INVALID_PARAM reply
 */
void saNtfArrayAllocateTest_05(void)
{
    SaStringT *arrayPtr;
	SaNtfAlarmNotificationT myAlarmNotification;

    safassert(saNtfInitialize(&ntfHandle, &ntfSendCallbacks, &ntfVersion) , SA_AIS_OK);

	safassert(saNtfAlarmNotificationAllocate(
			ntfHandle,
			&myAlarmNotification,
			0,
			0,
			0,
			0,
			0,
			2,
			SA_NTF_ALLOC_SYSTEM_LIMIT), SA_AIS_OK);

    myAlarmNotification.proposedRepairActions[0].actionValueType = SA_NTF_VALUE_ARRAY;
    rc = saNtfArrayValAllocate(
    		myAlarmNotification.notificationHandle,
    		(SaUint16T)5,
    		(SaUint16T)(strlen(DEFAULT_ADDITIONAL_TEXT) + 1),
    		(void**) &arrayPtr,
    		NULL);

    safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK);

    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);

    test_validate(rc, SA_AIS_ERR_INVALID_PARAM);
}
/**
 * Test the content of an SecurityAlarmNotification
 * Strategy: Set up a subscription and send a notification.
 *           Check it.
 */
void securityAlarmNotificationTest(void)
{
    SaNtfSecurityAlarmNotificationFilterT myFilter;

    subscriptionId = 5;

    resetCounters();
    safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK);
    safassert(saNtfSelectionObjectGet(ntfHandle, &selectionObject) , SA_AIS_OK);

    if(!safassertNice((rc = saNtfSecurityAlarmNotificationFilterAllocate(
    		ntfHandle,
    		&myFilter,
    		0, 0, 0, 0, 0,0,0,0,0)), SA_AIS_OK)) {

    	/* Initialize filter handles */
    	myNotificationFilterHandles.alarmFilterHandle = 0;
    	myNotificationFilterHandles.attributeChangeFilterHandle = 0;
    	myNotificationFilterHandles.objectCreateDeleteFilterHandle = 0;
    	myNotificationFilterHandles.securityAlarmFilterHandle =
    		myFilter.notificationFilterHandle;
    	myNotificationFilterHandles.stateChangeFilterHandle = 0;

    	/* subscribe */
    	safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles,
    			subscriptionId),
    			SA_AIS_OK);

    	createSecurityAlarmNotification(ntfHandle, &mySecAlarmNotification);
    	safassert(saNtfNotificationSend(mySecAlarmNotification.notificationHandle), SA_AIS_OK);

    	/* Delay to let the notification slip through */
		poll_until_received(ntfHandle, *mySecAlarmNotification.notificationHeader.notificationId);
    	if(ntfRecieved.alarmFilterHandle != 0 ||
    			ntfRecieved.attributeChangeFilterHandle != 0 ||
    			ntfRecieved.objectCreateDeleteFilterHandle !=0 ||
    			ntfRecieved.securityAlarmFilterHandle != 1 ||
    			ntfRecieved.stateChangeFilterHandle != 0) safassert(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK);

    	safassert(saNtfNotificationFree(mySecAlarmNotification.notificationHandle), SA_AIS_OK);
    	safassert(saNtfNotificationFilterFree(myFilter.notificationFilterHandle), SA_AIS_OK);
    }

	 safassert(saNtfNotificationUnsubscribe(subscriptionId), SA_AIS_OK);		
    safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK);

    if(errors && rc == SA_AIS_OK) rc = SA_AIS_ERR_FAILED_OPERATION;
    test_validate(rc, SA_AIS_OK);
}
/**
 * Test the content of several notifications at once
 * Strategy: Set up a subscription and send a notification.
 *           Check it.
 */
void allNotificationTest(void)
{
    rc = SA_AIS_OK;
    saNotificationFilterAllocationParamsT  myNotificationFilterAllocationParams;

    SaNtfAlarmNotificationFilterT          	   myAlarmFilter;
    SaNtfObjectCreateDeleteNotificationFilterT myObjCrDeFilter;
    SaNtfAttributeChangeNotificationFilterT    myAttrChangeFilter;
    SaNtfStateChangeNotificationFilterT        myStateChangeFilter;
    SaNtfSecurityAlarmNotificationFilterT      mySecAlarmFilter;

    subscriptionId = 7;

    resetCounters();
    fillInDefaultValues(&myNotificationAllocationParams,
                        &myNotificationFilterAllocationParams,
                        &myNotificationParams);

    safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK);

    if(!safassertNice(saNtfAlarmNotificationFilterAllocate(
    		ntfHandle,
    		&myAlarmFilter,
    		myNotificationFilterAllocationParams.numEventTypes,
    		myNotificationFilterAllocationParams.numNotificationObjects,
    		myNotificationFilterAllocationParams.numNotifyingObjects,
    		myNotificationFilterAllocationParams.numNotificationClassIds,
    		myNotificationFilterAllocationParams.numProbableCauses,
    		myNotificationFilterAllocationParams.numPerceivedSeverities,
    		myNotificationFilterAllocationParams.numTrends), SA_AIS_OK)) {

    	/* Set perceived severities */
    	myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING;
    	myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED;


    	if(!safassertNice((rc = saNtfObjectCreateDeleteNotificationFilterAllocate(
    			ntfHandle,
    			&myObjCrDeFilter,
    			myNotificationFilterAllocationParams.numEventTypes,
    			myNotificationFilterAllocationParams.numNotificationObjects,
    			myNotificationFilterAllocationParams.numNotifyingObjects,
    			myNotificationFilterAllocationParams.numNotificationClassIds,
    			myNotificationFilterAllocationParams.numSourceIndicators)), SA_AIS_OK)) {

    		if(!safassertNice((rc = saNtfAttributeChangeNotificationFilterAllocate(
    				ntfHandle,
    				&myAttrChangeFilter,
    				myNotificationFilterAllocationParams.numEventTypes,
    				myNotificationFilterAllocationParams.numNotificationObjects,
    				myNotificationFilterAllocationParams.numNotifyingObjects,
    				myNotificationFilterAllocationParams.numNotificationClassIds,
    				myNotificationFilterAllocationParams.numSourceIndicators)), SA_AIS_OK)) {

    			if(!safassertNice((rc = saNtfSecurityAlarmNotificationFilterAllocate(
    					ntfHandle,
    					&mySecAlarmFilter,
    					myNotificationFilterAllocationParams.numEventTypes,
    					myNotificationFilterAllocationParams.numNotificationObjects,
    					myNotificationFilterAllocationParams.numNotifyingObjects,
    					myNotificationFilterAllocationParams.numNotificationClassIds,
    					myNotificationFilterAllocationParams.numProbableCauses,
    					myNotificationFilterAllocationParams.numSeverities,
    					myNotificationFilterAllocationParams.numSecurityAlarmDetectos,
    					myNotificationFilterAllocationParams.numServiceUsers,
    					myNotificationFilterAllocationParams.numServiceProviders)), SA_AIS_OK)) {

    				if(!safassertNice((rc = saNtfStateChangeNotificationFilterAllocate(
    						ntfHandle,
    						&myStateChangeFilter,
    						myNotificationFilterAllocationParams.numEventTypes,
    						myNotificationFilterAllocationParams.numNotificationObjects,
    						myNotificationFilterAllocationParams.numNotifyingObjects,
    						myNotificationFilterAllocationParams.numNotificationClassIds,
    						myNotificationFilterAllocationParams.numSourceIndicators,
    						myNotificationFilterAllocationParams.numChangedStates)), SA_AIS_OK)) {

    					/* Initialize filter handles */
    					myNotificationFilterHandles.alarmFilterHandle =
    						myAlarmFilter.notificationFilterHandle;
    					myNotificationFilterHandles.attributeChangeFilterHandle =
    						myAttrChangeFilter.notificationFilterHandle;
    					myNotificationFilterHandles.objectCreateDeleteFilterHandle =
    						myObjCrDeFilter.notificationFilterHandle;
    					myNotificationFilterHandles.securityAlarmFilterHandle =
    						mySecAlarmFilter.notificationFilterHandle;
    					myNotificationFilterHandles.stateChangeFilterHandle =
    						myStateChangeFilter.notificationFilterHandle;

    					/* subscribe */
    					safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles,
    							subscriptionId),
    							SA_AIS_OK);

    					/* Create a couple of notifications and send them */
    					createAlarmNotification(ntfHandle, &myAlarmNotification);
    					safassert(saNtfNotificationSend(myAlarmNotification.notificationHandle), SA_AIS_OK);

    					createObjectCreateDeleteNotification(ntfHandle,	&myObjCrDelNotfification);
    					safassert(saNtfNotificationSend(myObjCrDelNotfification.notificationHandle), SA_AIS_OK);

    					createAttributeChangeNotification(ntfHandle, &myAttrChangeNotification);
    					safassert(saNtfNotificationSend(myAttrChangeNotification.notificationHandle), SA_AIS_OK);

    					createStateChangeNotification(ntfHandle, &myStateChangeNotification);
    					safassert(saNtfNotificationSend(myStateChangeNotification.notificationHandle), SA_AIS_OK);

    					createSecurityAlarmNotification(ntfHandle, &mySecAlarmNotification);
    					safassert(saNtfNotificationSend(mySecAlarmNotification.notificationHandle), SA_AIS_OK);

    					/* TODO: add MiscellaneousNotification */
						poll_until_received(ntfHandle, *mySecAlarmNotification.notificationHeader.notificationId);

    					if(ntfRecieved.alarmFilterHandle != 1 ||
    							ntfRecieved.attributeChangeFilterHandle != 1 ||
    							ntfRecieved.objectCreateDeleteFilterHandle !=1 ||
    							ntfRecieved.securityAlarmFilterHandle != 1 ||
    							ntfRecieved.stateChangeFilterHandle != 1){ 
							fprintf(stderr, "ntfreceived fh: a: %llu, att: %llu, o: %llu, se: %llu, st: %llu \n",
								ntfRecieved.alarmFilterHandle,
								ntfRecieved.attributeChangeFilterHandle,
								ntfRecieved.objectCreateDeleteFilterHandle,
								ntfRecieved.securityAlarmFilterHandle,
								ntfRecieved.stateChangeFilterHandle);
								safassertNice(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK);
						}

    					safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK);
    					safassert(saNtfNotificationFree(myObjCrDelNotfification.notificationHandle), SA_AIS_OK);
    					safassert(saNtfNotificationFree(myAttrChangeNotification.notificationHandle), SA_AIS_OK);
    					safassert(saNtfNotificationFree(myStateChangeNotification.notificationHandle), SA_AIS_OK);
    					safassert(saNtfNotificationFree(mySecAlarmNotification.notificationHandle), SA_AIS_OK);

    					/* TODO: add MiscellaneousNotification free */

    					safassert(saNtfNotificationUnsubscribe(subscriptionId),
    							SA_AIS_OK);

    					safassert(saNtfNotificationFilterFree(myStateChangeFilter.notificationFilterHandle), SA_AIS_OK);
    				}
    				safassert(saNtfNotificationFilterFree(mySecAlarmFilter.notificationFilterHandle), SA_AIS_OK);
    			}
    			safassert(saNtfNotificationFilterFree(myAttrChangeFilter.notificationFilterHandle), SA_AIS_OK);
    		}
    		safassert(saNtfNotificationFilterFree(myObjCrDeFilter.notificationFilterHandle), SA_AIS_OK);
    	}
    	safassert(saNtfNotificationFilterFree(myAlarmFilter.notificationFilterHandle), SA_AIS_OK);
    }

    safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK);

    /* Allocated in fillInDefaultValues() */
    free(myNotificationParams.additionalText);
    if(errors && rc == SA_AIS_OK) rc = SA_AIS_ERR_FAILED_OPERATION;
    test_validate(rc, SA_AIS_OK);
}
/**
 * Test the content of an alarm notification
 * Strategy: Set up a subscription and send a notification.
 *           Check it.
 */
void alarmNotificationTest2(void)
{
    SaNtfAlarmNotificationFilterT          myAlarmFilter;
    subscriptionId = 1;
    int i;
    rc = SA_AIS_OK;

    resetCounters();

    safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK);
    safassert(saNtfSelectionObjectGet(ntfHandle, &selectionObject) , SA_AIS_OK);

    /* Set up the filters and subscription */
    safassert(saNtfAlarmNotificationFilterAllocate(
        ntfHandle,
        &myAlarmFilter,
        0,
        0,
        0,
        0,
        0,
        2,
        0), SA_AIS_OK);
    /* Set perceived severities */
    myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING;
    myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED;

    /* Initialize filter handles */
    myNotificationFilterHandles.alarmFilterHandle =
        myAlarmFilter.notificationFilterHandle;
    myNotificationFilterHandles.attributeChangeFilterHandle = 0;
    myNotificationFilterHandles.objectCreateDeleteFilterHandle = 0;
    myNotificationFilterHandles.securityAlarmFilterHandle = 0;
    myNotificationFilterHandles.stateChangeFilterHandle = 0;

    safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles,
                                         subscriptionId),
                                         SA_AIS_OK);

    /* Create a notification and send it */
    myAlarmNotification.notificationHeader.numCorrelatedNotifications = 2;
    myAlarmNotification.notificationHeader.numAdditionalInfo = 5;
	safassert(saNtfAlarmNotificationAllocate(
			ntfHandle,
			&myAlarmNotification,
			myAlarmNotification.notificationHeader.numCorrelatedNotifications,
			(SaUint16T)(strlen(DEFAULT_ADDITIONAL_TEXT) + 1),
			myAlarmNotification.notificationHeader.numAdditionalInfo,
			3, /*  SaUint16T numSpecificProblems,       */
			2, /*  SaUint16T numMonitoredAttributes,    */
			2, /*  SaUint16T numProposedRepairActions,  */
			SA_NTF_ALLOC_SYSTEM_LIMIT), /*  SaInt16T variableDataSize  */
              SA_AIS_OK);

	fillHeader(&myAlarmNotification.notificationHeader);

    /* determine perceived severity */
    *(myAlarmNotification.perceivedSeverity) = SA_NTF_SEVERITY_WARNING;

    /* set probable cause*/
    *(myAlarmNotification.probableCause) = SA_NTF_BANDWIDTH_REDUCED;

    myAlarmNotification.specificProblems[0].problemClassId.vendorId = 23;
    myAlarmNotification.specificProblems[0].problemClassId.majorId = 22;
    myAlarmNotification.specificProblems[0].problemClassId.minorId = 21;

    myAlarmNotification.specificProblems[1].problemClassId.vendorId = 5;
    myAlarmNotification.specificProblems[1].problemClassId.majorId = 4;
    myAlarmNotification.specificProblems[1].problemClassId.minorId = 2;

    myAlarmNotification.specificProblems[2].problemClassId.vendorId = 2;
    myAlarmNotification.specificProblems[2].problemClassId.majorId = 3;
    myAlarmNotification.specificProblems[2].problemClassId.minorId = 4;

    myAlarmNotification.monitoredAttributes[0].attributeId = 1;
    myAlarmNotification.monitoredAttributes[0].attributeType = SA_NTF_VALUE_INT64;
    myAlarmNotification.monitoredAttributes[0].attributeValue.int64Val = 987654321;

    myAlarmNotification.monitoredAttributes[1].attributeId = 2;
    myAlarmNotification.monitoredAttributes[1].attributeType = SA_NTF_VALUE_INT8;
    myAlarmNotification.monitoredAttributes[1].attributeValue.int8Val = 88;

    myAlarmNotification.proposedRepairActions[0].actionId = 3;
    myAlarmNotification.proposedRepairActions[0].actionValueType = SA_NTF_VALUE_INT16;
    myAlarmNotification.proposedRepairActions[0].actionValue.int16Val = 456;

    myAlarmNotification.proposedRepairActions[1].actionId = 4;
    myAlarmNotification.proposedRepairActions[1].actionValueType = SA_NTF_VALUE_INT32;
    myAlarmNotification.proposedRepairActions[1].actionValue.int32Val = 456;

    for (i = 0; i < myAlarmNotification.numSpecificProblems; i++)
    {
        myAlarmNotification.specificProblems[i].problemId = i;
        myAlarmNotification.specificProblems[i].problemClassId.majorId = 1;
        myAlarmNotification.specificProblems[i].problemClassId.minorId = 2;
        myAlarmNotification.specificProblems[i].problemClassId.vendorId = 33;
        myAlarmNotification.specificProblems[i].problemType = SA_NTF_VALUE_UINT32;
        myAlarmNotification.specificProblems[i].problemValue.uint32Val = (SaUint32T)(600+i);
    }

    for (i = 0; i < myAlarmNotification.numProposedRepairActions; i++)
    {
        myAlarmNotification.proposedRepairActions[i].actionId = i;
        myAlarmNotification.proposedRepairActions[i].actionValueType = SA_NTF_VALUE_UINT32;
        myAlarmNotification.proposedRepairActions[i].actionValue.uint32Val = (SaUint32T)(700+i);
    }
    *myAlarmNotification.trend = SA_NTF_TREND_MORE_SEVERE;
    myAlarmNotification.thresholdInformation->thresholdValueType = SA_NTF_VALUE_UINT32;
    myAlarmNotification.thresholdInformation->thresholdValue.uint32Val = 600;
    myAlarmNotification.thresholdInformation->thresholdHysteresis.uint32Val = 100;
    myAlarmNotification.thresholdInformation->observedValue.uint32Val = 567;
    myAlarmNotification.thresholdInformation->armTime = SA_TIME_UNKNOWN;

    myAlarmNotification.notificationHeader.correlatedNotifications[0] = 1999;
    myAlarmNotification.notificationHeader.correlatedNotifications[1] = 1984;

    safassert(saNtfNotificationSend(myAlarmNotification.notificationHandle), SA_AIS_OK);
	 poll_until_received(ntfHandle, *myAlarmNotification.notificationHeader.notificationId);

	 if(ntfRecieved.alarmFilterHandle != 1 ||
    		ntfRecieved.attributeChangeFilterHandle != 0 ||
    		ntfRecieved.objectCreateDeleteFilterHandle !=0 ||
    		ntfRecieved.securityAlarmFilterHandle != 0 ||
    		ntfRecieved.stateChangeFilterHandle != 0) safassert(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK);

    safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK);
    safassert(saNtfNotificationFilterFree(myAlarmFilter.notificationFilterHandle), SA_AIS_OK);

    safassert(saNtfNotificationUnsubscribe(subscriptionId), SA_AIS_OK);
    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);

    /* Allocated in fillInDefaultValues() */
    free(myNotificationParams.additionalText);
    if(errors) rc = SA_AIS_ERR_FAILED_OPERATION;
    test_validate(rc, SA_AIS_OK);
}
/**
 * Test the content of an alarm notification
 * Strategy: Set up a subscription and send a notification.
 *           Check it.
 */
void alarmNotificationTest(void)
{
    SaNtfAlarmNotificationFilterT          myAlarmFilter;
    subscriptionId = 1;

    rc = SA_AIS_OK;

    resetCounters();

    safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK);
    safassert(saNtfSelectionObjectGet(ntfHandle, &selectionObject) , SA_AIS_OK);

    /* Set up the filters and subscription */
    safassert(saNtfAlarmNotificationFilterAllocate(
        ntfHandle,
        &myAlarmFilter,
        0,
        0,
        0,
        0,
        0,
        2,
        0), SA_AIS_OK);
    /* Set perceived severities */
    myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING;
    myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED;

    /* Initialize filter handles */
    myNotificationFilterHandles.alarmFilterHandle =
        myAlarmFilter.notificationFilterHandle;
    myNotificationFilterHandles.attributeChangeFilterHandle = 0;
    myNotificationFilterHandles.objectCreateDeleteFilterHandle = 0;
    myNotificationFilterHandles.securityAlarmFilterHandle = 0;
    myNotificationFilterHandles.stateChangeFilterHandle = 0;

    safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles,
                                         subscriptionId),
                                         SA_AIS_OK);

    /* Create a notification and send it */
	safassert(saNtfAlarmNotificationAllocate(
			ntfHandle,
			&myAlarmNotification,
			0,
			(SaUint16T)(strlen(DEFAULT_ADDITIONAL_TEXT) + 1),
			0,
			0,
			0,
			0,
			SA_NTF_ALLOC_SYSTEM_LIMIT), SA_AIS_OK);

	fillHeader(&myAlarmNotification.notificationHeader);

    /* determine perceived severity */
    *(myAlarmNotification.perceivedSeverity) = SA_NTF_SEVERITY_WARNING;

    /* set probable cause*/
    *(myAlarmNotification.probableCause) = SA_NTF_BANDWIDTH_REDUCED;
    *myAlarmNotification.trend = SA_NTF_TREND_MORE_SEVERE;
    myAlarmNotification.thresholdInformation->thresholdValueType = SA_NTF_VALUE_UINT32;
    myAlarmNotification.thresholdInformation->thresholdValue.uint32Val = 600;
    myAlarmNotification.thresholdInformation->thresholdHysteresis.uint32Val = 100;
    myAlarmNotification.thresholdInformation->observedValue.uint32Val = 567;
    myAlarmNotification.thresholdInformation->armTime = SA_TIME_UNKNOWN;

    safassert(saNtfNotificationSend(myAlarmNotification.notificationHandle), SA_AIS_OK);
	 poll_until_received(ntfHandle, *myAlarmNotification.notificationHeader.notificationId);
    if(ntfRecieved.alarmFilterHandle != 1 ||
    		ntfRecieved.attributeChangeFilterHandle != 0 ||
    		ntfRecieved.objectCreateDeleteFilterHandle !=0 ||
    		ntfRecieved.securityAlarmFilterHandle != 0 ||
    		ntfRecieved.stateChangeFilterHandle != 0) safassert(SA_AIS_ERR_BAD_FLAGS, SA_AIS_OK);

    safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK);
    safassert(saNtfNotificationFilterFree(myAlarmFilter.notificationFilterHandle), SA_AIS_OK);

    safassert(saNtfNotificationUnsubscribe(subscriptionId), SA_AIS_OK);
    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);

    /* Allocated in fillInDefaultValues() */
    free(myNotificationParams.additionalText);
    if(errors) rc = SA_AIS_ERR_FAILED_OPERATION;
    test_validate(rc, SA_AIS_OK);
}
Пример #9
0
static void saNtfNotificationCallback(SaNtfSubscriptionIdT subscriptionId, const SaNtfNotificationsT *notification)
{
	SaInt32T i;
	SaNtfNotificationHandleT notificationHandle;
	const SaNtfNotificationHeaderT *notificationHeader;

	switch (notification->notificationType) {
	case SA_NTF_TYPE_ALARM:
		notificationHandle = notification->notification.alarmNotification.notificationHandle;
		notificationHeader = &notification->notification.alarmNotification.notificationHeader;
		printf("===  %s - Alarm  ===\n", event_time(*notificationHeader->eventTime));
		print_header(notificationHeader, subscriptionId, notification->notificationType);
		print_additional_info(notificationHandle, notificationHeader);
		print_probable_cause(*(notification->notification.alarmNotification.probableCause));
		print_severity(*(notification->notification.alarmNotification.perceivedSeverity));

		break;

	case SA_NTF_TYPE_STATE_CHANGE:
		notificationHandle = notification->notification.stateChangeNotification.notificationHandle;
		notificationHeader = &notification->notification.stateChangeNotification.notificationHeader;
		printf("===  %s - State Change  ===\n", event_time(*notificationHeader->eventTime));
		print_header(notificationHeader, subscriptionId, notification->notificationType);
		print_additional_info(notificationHandle, notificationHeader);
		print_source_indicator(*(notification->notification.stateChangeNotification.sourceIndicator));

		if (verbose)
			printf("Num of StateChanges: %d\n", notification->notification.stateChangeNotification.numStateChanges);

		/* Changed states */
		for (i = 0; i < notification->notification.stateChangeNotification.numStateChanges; i++) {
			print_change_states(notificationHeader->notificationClassId,
				&notification->notification.stateChangeNotification.changedStates[i]);
		}
		break;

	case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
		notificationHandle = notification->notification.objectCreateDeleteNotification.notificationHandle;
		notificationHeader = &notification->notification.objectCreateDeleteNotification.notificationHeader;
		printf("===  %s - Object Create/Delete  ===\n", event_time(*notificationHeader->eventTime));
		print_header(notificationHeader, subscriptionId, notification->notificationType);
		print_source_indicator(*(notification->notification.objectCreateDeleteNotification.sourceIndicator));
		printf("numAttributes: %d\n", notification->notification.objectCreateDeleteNotification.numAttributes);

		/* Object Attributes */
		for (i = 0; i < notification->notification.objectCreateDeleteNotification.numAttributes; i++) {
			print_object_attributes(&notification->notification.
						objectCreateDeleteNotification.objectAttributes[i]);
		}
		break;

	case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
		notificationHandle = notification->notification.attributeChangeNotification.notificationHandle;
		notificationHeader = &notification->notification.attributeChangeNotification.notificationHeader;
		printf("===  %s - Attribute Change  ===\n", event_time(*notificationHeader->eventTime));
		print_header(notificationHeader, subscriptionId, notification->notificationType);
		print_source_indicator(*(notification->notification.attributeChangeNotification.sourceIndicator));
		printf("numAttributes: %d\n", notification->notification.attributeChangeNotification.numAttributes);

		/* Changed Attributes */
		for (i = 0; i < notification->notification.attributeChangeNotification.numAttributes; i++) {
			print_changed_attributes(&notification->notification.
						 attributeChangeNotification.changedAttributes[i]);
		}
		break;

	case SA_NTF_TYPE_SECURITY_ALARM:
		notificationHandle = notification->notification.securityAlarmNotification.notificationHandle;
		notificationHeader = &notification->notification.securityAlarmNotification.notificationHeader;
		printf("===  %s - Security Alarm  ===\n", event_time(*notificationHeader->eventTime));
		print_header(notificationHeader, subscriptionId, notification->notificationType);
		print_probable_cause(*(notification->notification.securityAlarmNotification.probableCause));
		print_severity(*(notification->notification.securityAlarmNotification.severity));
		print_security_alarm_types((SaNtfSecurityAlarmNotificationT *)&notification->notification.
					   securityAlarmNotification);

		break;

	default:
		printf("unknown notification type %d", (int)notification->notificationType);
		break;
	}

	switch (notification->notificationType) {
	case SA_NTF_TYPE_ALARM:
		saNtfNotificationFree(notification->notification.alarmNotification.notificationHandle);
		break;
	case SA_NTF_TYPE_SECURITY_ALARM:
		saNtfNotificationFree(notification->notification.securityAlarmNotification.notificationHandle);
		break;
	case SA_NTF_TYPE_STATE_CHANGE:
		saNtfNotificationFree(notification->notification.stateChangeNotification.notificationHandle);
		break;
	case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
		saNtfNotificationFree(notification->notification.objectCreateDeleteNotification.notificationHandle);
		break;
	case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
		saNtfNotificationFree(notification->notification.attributeChangeNotification.notificationHandle);
		break;

	default:
		printf("wrong type");
		assert(0);
	}
	printf("\n");
}
void saNtfObjectCreateDeleteNotificationAllocate_01(void)
{
    SaNtfObjectCreateDeleteNotificationT myNotification;

    saNotificationAllocationParamsT myNotificationAllocationParams;
    saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams;
    saNotificationParamsT myNotificationParams;

    fillInDefaultValues(&myNotificationAllocationParams,
                        &myNotificationFilterAllocationParams,
                        &myNotificationParams);

    safassert(saNtfInitialize(&ntfHandle, &ntfCallbacks, &ntfVersion), SA_AIS_OK);
    rc = saNtfObjectCreateDeleteNotificationAllocate(
        ntfHandle, /* handle to Notification Service instance */
        &myNotification,
        /* number of correlated notifications */
        myNotificationAllocationParams.numCorrelatedNotifications,
        /* length of additional text */
        myNotificationAllocationParams.lengthAdditionalText,
         /* number of additional info items*/
        myNotificationAllocationParams.numAdditionalInfo,
        /* number of state changes */
        myNotificationAllocationParams.numObjectAttributes,
        /* use default allocation size */
        myNotificationAllocationParams.variableDataSize);

    /* Event type */
    *(myNotification.notificationHeader.eventType) =
        SA_NTF_OBJECT_CREATION;

    /* event time to be set automatically to current
    time by saNtfNotificationSend */
    *(myNotification.notificationHeader.eventTime) =
        myNotificationParams.eventTime;

    /* Set Notification Object */
    myNotification.notificationHeader.notificationObject->length =
        myNotificationParams.notificationObject.length;
    (void)memcpy(myNotification.notificationHeader.notificationObject->value,
                 myNotificationParams.notificationObject.value,
                 myNotificationParams.notificationObject.length);

    /* Set Notifying Object */
    myNotification.notificationHeader.notifyingObject->length =
        myNotificationParams.notifyingObject.length;
    (void)memcpy(myNotification.notificationHeader.notifyingObject->value,
                 myNotificationParams.notifyingObject.value,
                 myNotificationParams.notifyingObject.length);

    /* set Notification Class Identifier */
    /* vendor id 33333 is not an existing SNMP enterprise number.
    Just an example */
    myNotification.notificationHeader.notificationClassId->vendorId =
        myNotificationParams.notificationClassId.vendorId;

    /* sub id of this notification class within "name space" of vendor ID */
    myNotification.notificationHeader.notificationClassId->majorId =
        myNotificationParams.notificationClassId.majorId;
    myNotification.notificationHeader.notificationClassId->minorId =
        myNotificationParams.notificationClassId.minorId;

    /* set additional text and additional info */
    (void)strncpy(myNotification.notificationHeader.additionalText,
                  myNotificationParams.additionalText,
                  myNotificationAllocationParams.lengthAdditionalText);

    /* Set source indicator */
    myNotification.sourceIndicator =
        &myNotificationParams.objectCreateDeleteSourceIndicator;

    /* Set objectAttibutes */
    myNotification.objectAttributes[0].attributeId =
        myNotificationParams.objectAttributes[0].attributeId;
    myNotification.objectAttributes[0].attributeType =
        myNotificationParams.objectAttributes[0].attributeType;
    myNotification.objectAttributes[0].attributeValue.int32Val =
        myNotificationParams.objectAttributes[0].attributeValue.int32Val;

    free(myNotificationParams.additionalText);
    safassert(saNtfNotificationFree(myNotification.notificationHandle), SA_AIS_OK);
    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);
    test_validate(rc, SA_AIS_OK);
}
/* incomming notifications in the MDS thread discarding makes no sense */
void saNtfNotificationDiscardedCallbackT_01(void)
{
    struct pollfd fds[1];
    int ret,i;
    saNotificationAllocationParamsT        myNotificationAllocationParams;
    saNotificationFilterAllocationParamsT  myNotificationFilterAllocationParams;
    saNotificationParamsT                  myNotificationParams;

    AlarmNotificationParams                myAlarmParams;
    SaNtfAlarmNotificationFilterT          myAlarmFilter;
    SaNtfNotificationTypeFilterHandlesT    myNotificationFilterHandles;
    SaNtfIdentifierT                       myNotId[NUM_NOTIF];

    resetCounters();
    fillInDefaultValues(&myNotificationAllocationParams,
                        &myNotificationFilterAllocationParams,
                        &myNotificationParams);
    if(verbose)
    {
        printf("num not to send: %d\n", NUM_NOTIF);
    }

    rc=SA_AIS_ERR_NOT_SUPPORTED; /* Not fully implemented */
    test_validate(rc, SA_AIS_OK);       /* See above             */
    return;                      /*                       */

    safassert(saNtfInitialize(&ntfHandle, &ntfCbTest, &ntfVersion) , SA_AIS_OK);
    safassert(saNtfSelectionObjectGet(ntfHandle, &selectionObject) , SA_AIS_OK);

    safassert(saNtfAlarmNotificationFilterAllocate(
        ntfHandle,
        &myAlarmFilter,
        myNotificationFilterAllocationParams.numEventTypes,
        myNotificationFilterAllocationParams.numNotificationObjects,
        myNotificationFilterAllocationParams.numNotifyingObjects,
        myNotificationFilterAllocationParams.numNotificationClassIds,
        myNotificationFilterAllocationParams.numProbableCauses,
        myNotificationFilterAllocationParams.numPerceivedSeverities,
        myNotificationFilterAllocationParams.numTrends), SA_AIS_OK);
    /* Set perceived severities */
    myAlarmFilter.perceivedSeverities[0] = SA_NTF_SEVERITY_WARNING;
    myAlarmFilter.perceivedSeverities[1] = SA_NTF_SEVERITY_CLEARED;

    /* Initialize filter handles */
    myNotificationFilterHandles.alarmFilterHandle =
        myAlarmFilter.notificationFilterHandle;
    myNotificationFilterHandles.attributeChangeFilterHandle = 0;
    myNotificationFilterHandles.objectCreateDeleteFilterHandle = 0;
    myNotificationFilterHandles.securityAlarmFilterHandle = 0;
    myNotificationFilterHandles.stateChangeFilterHandle = 0;

    safassert(saNtfNotificationSubscribe(&myNotificationFilterHandles,
                                         my_subid),
                                         SA_AIS_OK);

    myAlarmParams.numCorrelatedNotifications =
        myNotificationAllocationParams.numCorrelatedNotifications;
    myAlarmParams.lengthAdditionalText =
        myNotificationAllocationParams.lengthAdditionalText;
    myAlarmParams.numAdditionalInfo =
        myNotificationAllocationParams.numAdditionalInfo;
    myAlarmParams.numSpecificProblems =
        myNotificationAllocationParams.numSpecificProblems;
    myAlarmParams.numMonitoredAttributes =
        myNotificationAllocationParams.numMonitoredAttributes;
    myAlarmParams.numProposedRepairActions =
        myNotificationAllocationParams.numProposedRepairActions;
    myAlarmParams.variableDataSize =
        myNotificationAllocationParams.variableDataSize;

    safassert(saNtfAlarmNotificationAllocate(
        ntfHandle,
        &myAlarmNotification,
        myAlarmParams.numCorrelatedNotifications,
        myAlarmParams.lengthAdditionalText,
        myAlarmParams.numAdditionalInfo,
        myAlarmParams.numSpecificProblems,
        myAlarmParams.numMonitoredAttributes,
        myAlarmParams.numProposedRepairActions,
        myAlarmParams.variableDataSize), SA_AIS_OK);

    myNotificationParams.eventType = myNotificationParams.alarmEventType;
    fill_header_part(
        &myAlarmNotification.notificationHeader,
        (saNotificationParamsT *)&myNotificationParams,
        myAlarmParams.lengthAdditionalText);

    /* determine perceived severity */
    *(myAlarmNotification.perceivedSeverity) =
        myNotificationParams.perceivedSeverity;

    /* set probable cause*/
    *(myAlarmNotification.probableCause) =
        myNotificationParams.probableCause;
    for(i=0; i<NUM_NOTIF;i++)
    {
        if((rc =saNtfNotificationSend(myAlarmNotification.notificationHandle)) != SA_AIS_OK)
        {
            if(verbose)
            {
                printf("send failed rc: %d\n", rc);
            }
            break;
        }
        myNotId[i] = *myAlarmNotification.notificationHeader.notificationId;
    }
    sleep(10);

    fds[0].fd = (int) selectionObject;
    fds[0].events = POLLIN;
    ret = poll(fds, 1, 10000);
    assert(ret > 0);
    safassert(saNtfDispatch(ntfHandle, SA_DISPATCH_ALL) , SA_AIS_OK);

    rc =SA_AIS_ERR_FAILED_OPERATION;
    for(i = 0; i < NUM_NOTIF; i++)
    {
        if(cb_notId[i] != myNotId[i])
        {
            break;
        }
    }

    if(numDiscarded == 0)
    {
        rc =SA_AIS_ERR_FAILED_OPERATION;
    }
    else if(numDiscarded != (NUM_NOTIF - i))
    {
        if(verbose)
        {
            printf("failed num of discarded: %d\n", numDiscarded);
        }
        rc =SA_AIS_ERR_FAILED_OPERATION;
    }
    if(verbose)
    {
        printf("Number of discarded: %d\n", numDiscarded);
        printf("Number of received not: %d\n", cb_index);
    }

    safassert(saNtfNotificationFree(myAlarmNotification.notificationHandle) , SA_AIS_OK);
    safassert(saNtfNotificationUnsubscribe(my_subid),
                                           SA_AIS_OK);
    safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK);
    test_validate(rc, SA_AIS_OK);
}