/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

#ifndef PM_H_
#define PM_H_

#ifndef BIT_MASK
#define BIT_MASK(n) 				(0x1UL << (n < 32 ? n : (n - 32)))
#endif

typedef uint32_t pmIndex_t;

typedef enum
{
	version0 = 0,
	version1 = 1,
} pduVersion_t;

typedef	uint32_t					bitVector32_t;

typedef enum
{
	none		=1,
	immediate	=2,
	relative	=3,
	fixed		=4
} svcTimeType_t;

typedef enum
{
	proactive	= 1,
	onDemand	= 2
} sessionType_t;

typedef enum
{
	active		= 1,
	notActive	= 2

} sessionStatus_t;

typedef enum
{
	available	= 1,
	unavailable	= 2,
	unknown		= 3
} availabilityType_t;

struct dateAndTime_s
{
	uint16_t	year;
	uint8_t		month;
	uint8_t		day;
	uint8_t		hour;
	uint8_t		min;
	uint8_t		seconds;
	uint8_t		deciSeconds;
	uint8_t		utcDir;
	uint8_t		utcHours;
	uint8_t		utcMinutes;
	uint8_t		pad1b;							// present to make sizeof data struct multiple of 4 bytes
} OS_PACKED_STRUCT;
typedef struct dateAndTime_s dateAndTime_t;		// Stores current date and time in a format compliant with RFC 1514

typedef  uint32_t	timeInterval_t;				// Measures time interval in units of 0.01sec

typedef  uint32_t	gauge32_t;

struct pmConfig_s
{
	pduVersion_t		version;					// indicates the version of the PDUs used to perform Loss/Delay Measurement
	bool				enabled;					// (writable) specifies whether the Loss/Delay Measurement session is enabled
	prio_t				priority;					// specifies the Loss/Delay Measurement OAM message priority as well as the priority of the service/OAM traffic to be monitored
	bool				historyClear;				// (writable) This object when written clears the Loss/Delay Measurement history Table (mefSoamLmHistoryStatsTable)
	bitVector32_t		measurementEnable;			// A vector of bits that indicates the type of SOAM LM/DM counters found in the mefSoamLmMeasuredStatsTable, mefSoamLmCurrentStatsTable, mefSoamLmHistoryStatsTable, mefSoamLmCurrentAvailStatsTable and mefSoamLmHistoryAvailStatsTable that are enabled
	bitVector32_t		measurementEnableUpper;
	uint32_t			messagePeriod;				// resolution 1ms (default = 1000 => 1sec) specifies the interval between Loss/Delay Measurement OAM message transmission.
	uint32_t			measurementInterval;		// resolution 1min (default = 15) specifies the Measurement Interval for FLR statistics, in minutes . A Measurement Interval of 15 minutes needs to be supported, other intervals may be supported
	uint16_t			numIntervalsStored;			//(default = 32)specifies the number of completed Measurement Intervals to store in the history statistic table (mefSoamLmHistoryStatsTable) and the history availability statistic table (mefSoamLmHistoryAvailStatsTable). At least 32 completed Measurement Intervals need to be stored. 96 are recommended
	uint16_t			frameSize;					// specifies the Loss/Delay Measurement frame size between 64 bytes(default) and the maximum transmission unit of the EVC (10,000)
	macAddress_t		destMacAddress;				// The Target or Destination MAC Address Field to be transmitted. Used if destIsMepId = false.
	mepId_t				destMepId;					// The MEPID of another MEP in the same MA to which the SOAM LM/DM frame is to be sent
	bool				destIsMepId;				// true indicates use destMepId as the target mepId, false means use destMacAddress
	bool				testTlvIncluded;			// Indicates whether a Test TLV (true) or Data TLV (false) is included when the size of the LM/DM frame is determined by the frameSize object
	testTlvPattern_t	testTlvPattern;				// specifies the type of test pattern to be sent in the LM/DM frame Test TLV when the size of LM/DM PDU is determined by the frameSize object and testTlvIncluded is 'true'
	dataPattern_t		dataPattern;				// specifies the LM/DM data pattern included in a Data TLV when the size of the LM/DM frame is determined by the frameSize object and testTlvIncluded is 'false'
	dateAndTime_t		fixedStartDateAndTime;		// specifies the fixed start date/time for the SOAM Loss/Delay Measurement session. This object is used only used if startTimeType is 'fixed' and is ignored otherwise. The default value is year 0000, month 01, day 01, time 00:00:00.00
	dateAndTime_t		fixedStopDateAndTime;		// specifies the fixed stop date/time for the SOAM Loss/Delay Measurement session. This object is used only used if stopTimeType is 'fixed' and is ignored otherwise. The default value is year 0000, month 01, day 01, time 00:00:00.00
	uint32_t			relativeStartTime;			// specifies the relative start time, from the current system time, for the SOAM LM/DM session.  This object is used only if mefSoamLmStartTimeType is 'relative
	svcTimeType_t		startTimeType;				// specifies the type of start time of the SOAM LM/DM session. The start time can be disabled (none !!Illegal!!), immediate (default), relative, or fixed
	svcTimeType_t		stopTimeType;				// specifies the type of stop time to terminate the SOAM LM/DM session. The stop time can be forever (none), relative, or fixed. The value of 'none' indicates that the SOAM LM/DM session never ends once it has started unless it the session is disabled
	sessionType_t		sessionType;				// object indicates whether the current session is defined to be 'Proactive' or 'On-Demand'
	sessionStatus_t		sessionStatus;				// Indicates the current status of the LM/DM session
	uint32_t			relativeStopTime;			// specifies the relative stop time, from the session start time, to stop the SOAM LM/DM session
	uint32_t			repetitionTime;				// specifies a configurable repetition time between Measurement Intervals in a Loss/Delay Measurement session, in seconds. If the value is 0 (none)(default), there is no time gap between the end of one Measurement Interval and the start of a new Measurement Interval
	uint32_t			alignMeasurementOffset;		// specifies the offset in minutes from the time of day value if mefSoamLmCfgAlignMeasurementIntervals is 'true' and the repetition time is a factor of 60 minutes. If not, the value of this object is ignored
	bool				alignMeasurementIntervals;	// specifies whether the Measurement Intervals for the Loss/Delay Measurement session are aligned with a zero offset to real time
};

typedef struct
{
	uint32_t		cfmAlarmInterval;				// (default=5) value indicating the shortest time interval in seconds between the generation of the same notification type per PM session to the list of notification destination
	bitVector32_t	cfmAlarmEnable;					// A vector of bits that indicates whether a specific notification is enabled
} notificationCfg_t;

// The bit vectors used to access/modify alarmEnable in notificationCfg_t
#define bAvailabilityChangeAlarm	(0)
#define bLmSessionStartStopAlarm	(1)
#define bDmSessionStartStopAlarm	(2)
#define bPmThresholdAboveAlarm		(3)
#define bPmThresholdSetClearAlarm	(4)


#define	MR_CCM_SVC_MASK	0x01
#define	MR_CLM_SVC_MASK	0x02
#define	MR_LMM_SVC_MASK	0x04
#define	MR_SLM_SVC_MASK	0x08
#define	MR_DMM_SVC_MASK	0x10
#define	MR_IDM_SVC_MASK	0x20

typedef enum
{
	aboveAlarm	= 1,
	setAlarm	= 2,
	clearAlarm	= 3
} crossingType_t;

typedef char objId_t[64];

typedef struct
{
	dateAndTime_t		dateAndtime;		// The time and date at which the notification occurred
	objId_t				thresholdId;		// The object Id on which the notification occurred
	uint32_t			thresholdConfig;	// The configured Threshold value of the object that caused the notification
	uint32_t			thresholdValue;		// The measured value of the object at the time of the notification
	bool				suspect;			// A copy of the suspect value from the LM or DM current stats at the time of notification
	crossingType_t		crossingType;		// The notification crossing type of the object that caused the notification
	macAddress_t		destMepMac;			// The MAC address of the destination MEP for the session that caused the notification
	prio_t				priority;			// The priority of the session that caused the notification
} pmNotificationObj_t;

// Define bit masks for the cfmAlarmEnable parameter in pmNotification_t
#define	bAvailabilityChangeAlarm	(0)
#define	bLmSessionStartStopAlarm	(1)
#define	bDmSessionStartStopAlarm	(2)
#define	bPmThresholdAboveAlarm		(3)
#define	bPmThresholdSetClearAlarm	(4)

#endif /* PM_H_ */
