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

#ifndef PM_TYPES_H_
#define PM_TYPES_H_

#include <api_oam_sdk/common/types/inc/linked_list.h>
#include <api_oam_sdk/performance_monitoring/src/dm.h>
#include <api_oam_sdk/performance_monitoring/src/lm.h>
#include <api_oam_sdk/performance_monitoring/src/pm_config.h>
#include "egl_types.h"
#include "egl_log.h"

#define MAX_UINT_32				(0xFFFFFFFF)
#define PM_TASK_STACKSIZE		(2048)
#define MIN_TO_MILLI_SECONDS	(60000)
#define BINS_PER_FTD			(4)
#define BINS_PER_FDV			(4)

//typedef int16_t	pmNum_t;

typedef struct
{
	pmIndex_t	pmIndex;			// The MIB index for the SLM/DMM Session
	bool		inUse;				// Used to indicate that the PM entry is in use
	lMepNum_t	parentLMepNum;		// Hardware index associated with this PM 's parent remote MEP
} subCtxt_t;

typedef struct
{
	subCtxt_t	lmCtxt;
	subCtxt_t	dmCtxt;
	pmNum_t		pmNum;				// Hardware index associated with the LM portion of the PM session
} pmCtxt_t;


struct pmEntry_s
{
	pmCtxt_t			pmCtxt;

	TAILQ_ENTRY(struct pmEntry_s,) 	lossll;
	lmCfg_t				lmCfg;
	lmStatsEntry_t		lmMeasStats;			// This is used to hold the raw Stats read from HW (counters accumulate forever)
	//lmAvailStats_t		lmCurrAvailStats;	// *** NOT SUPPORTED IN THIS VERSION *** This holds the Availability Stats since the start of the current measurement interval.
	lmStats_t			lmCurrStats;			// This holds the Loss Stats since the start of the current measurement interval.
	//lmAvailStats_t	lmHistAvailStats;		// *** NOT SUPPORTED IN THIS VERSION ***
	lmThresholdCfg_t	lmThresholdCfg;

	TAILQ_ENTRY(struct pmEntry_s,) 	delayll;
	dmCfg_t				dmCfg;
	dmCfgMeasBin_t		dmCfgMeasBin;			// This is used to hold the raw Stats read from HW
	dmStats_t			dmCurrStats;			// This holds the Delay Stats since the start of the current measurement interval.
	dmStatsBins_t		dmCurrStatsBins;		// This holds the Delay Bins Stats since the start of the current measurement interval.
	dmThresholdCfg_t	dmThresholdCfg;

	notificationCfg_t	notificationCfg;
};
typedef struct pmEntry_s pmEntry_t;

void pmInit(void);

void setPmLogLevel(log_level_t logLevel);

void pmUpdatePrimaryVlan(
	mdIndex_t		mdIndex,
	maIndex_t		maIndex,
	mepId_t			lMepId,
	uint16_t 		vLan,
	tagType_t		tagType,
	iFace_t			iFace,
	bool			enable);

struct pmStatsLogList_s
{
	TAILQ_ENTRY(struct pmStatsLogList_s,) 	ll;
	pmNum_t									pmNum;
	bool									saveLoss;
	bool									saveDelay;
	uint16_t								delayInterval;
	uint16_t								lossInterval;
	uint16_t								delayElapsedMin;
	uint16_t								lossElapsedMin;
};

typedef struct pmStatsLogList_s pmStatsLogEntry_t;

typedef enum {
	lossSession = 1,
	delaySession = 2
} localPmType_t;

bool isLmWaitingForMac(mdIndex_t mdIndex, maIndex_t maIndex, mepId_t lMepId, pmIndex_t lmIndex);
bool isDmWaitingForMac(mdIndex_t mdIndex, maIndex_t maIndex, mepId_t lMepId, pmIndex_t dmIndex);
#endif /* PM_TYPES_H_ */
