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

#ifndef SVC_BWP_H_
#define SVC_BWP_H_

#include <api_oam_sdk/common/types/inc/mr_api_types.h>
#include <api_oam_sdk/service_cos/inc/svc_cos.h>
#include "egl_types.h"

typedef uint32_t	bwpGrpIndex_t;
typedef uint32_t	bwpIndex_t;

typedef enum {
	colorBlind	= 1,	/* A bandwidth profile property where ingress Service Frames are not pre-colored for either green or
						yellow, and if present, is ignored when determining the level of compliance for each Service Frame */
	colorAware	= 2,	/* A bandwidth profile property were a pre-determined level of Bandwidth Profile compliance for each
						Service Frame is taken into account when determining the level of compliance for each Service Frame.
						Each service frame can be colored red (discarded), yellow (conditional delivery), or green (unconditional delivery. */
} colourMode_t;

typedef enum {
	couplingYellowEirOnly		= 0,	// (default) The long term average bit rate of Service Frames that are declared Yellow is bounded by EIR.
	couplingYellowEirPlusCir	= 1,	/* The long term average bit rate of Service Frames that are declared Yellow is bounded
											by CIR + EIR depending on the volume of the offered Service Frames that are declared Green.*/
} couplingFlag_t;

typedef struct svcBwpCfg_s {
	// char		identifier[45];		// Not supported.
	uint32_t		cir;			// (default= 1000000)Indicates the Committed Information Rate (CIR) in kbits/s and defines the average rate in kbits/sec up to which the network delivers Service Frames.
	uint32_t		eir;			// (default=0) Indicates the Excess Information Rate (EIR) in kbits/s and defines the average rate in kbits/sec of Service Frames up to which the network may deliver Service Frames but without performance objectives.
	uint32_t		cbs;			// (default=12)Indicates the Committed Burst Size (CBS) in bytes. It limits the maximum number of bytes available for a burst of Service Frames sent at interface speed to remain CIR-conformant.
	uint32_t		ebs;			// (default=0)indicates the Excess Burst Size (EBS) in bytes. It limits the maximum number of bytes available for a burst of Service Frames sent at the interface speed to remain EIR-conformant.
	cosIndex_t		cosIndex;		// (default = 0) The index number of the CoS ID profile associated with the current bandwidth profile (BWP). A value of 0 indicates that no CoS ID profile is associated with the BWP and the BWP applies to all CoS IDs.
	colourMode_t	cm;				// (default = 0) Configures the bandwidth profile color mode.
	couplingFlag_t	cf;				// (default = 1) Configures the bandwidth profile coupling flag and has the effect of controlling the volume of the Service Frames that are declared Yellow.
	//bool			performanceEnable;	// Not Supported
} svcBwpCfg_t;

typedef enum {
	bwpParam_cosIndex = 1
	//bwpParam_performanceEnable = 1	// Not Supported.
} bwpWrParam_t;

/**
 * @brief Returns the next available BWP GRP index
 *
 * @return The next available BWP GRP index.
 */
bwpGrpIndex_t	svcBwpGrpGetNextIndex(void);


/**
 * @brief Read the next entry in the list of configured BWP GRPs.
 *
 * Read the next entry in the list of configured BWP GRPs. If bwpGrpIndex is 0 it
 * returns the bwpGrpIndex of the first BWP GRP entry or 0 if there are
 * no BWP GRP entries. If a valid bwpGrpIndex is provided it returns
 * the bwpGrpIndex of the next BWP GRP in the list.
 *
 * @param[in] nextBwpGrpIdx The BWP GRP Index from a previous call to this function or 0.
 * @return	bwpGrpIndex of the next entry or 0 if no more entries.
 *
 */
bwpGrpIndex_t svcBwpGrpReadList(bwpGrpIndex_t nextBwpGrpIdx);

/**
 * @brief Create a new service BWP GRP .
 *
 * Create a new service BWP GRP using the configuration
 * parameters provided.
 *
 * @param[in] bwpGrpIndex the index value of the BWP GRP to create. Usually obtained by calling svcBwpGrpGetNextIndex()
 * @return
 * \li -1: Operation rejected due to insufficient resources
 * \li  1: Operation rejected due to invalid or nonexistent BWP GRP index.
 * \li  2: Operation accepted.
 */
int svcBwpGrpCreate(bwpGrpIndex_t bwpGrpIndex);

/**
 * @brief	Delete the BWP GRP with the supplied bwpGrpIndex.
 *
 * This will delete the selected BWP GRP and its associations with all EVCs.
 *
 * @param[in] bwpGrpIndex the index value of BWP GRP to delete.
 * @returns
 * \li 1: Operation rejected due to invalid or nonexistent BWP GRP index.
 * \li 2: Operation rejected because the BWP group is in use by an Interface or EVC
 * \li 3: Operation accepted
 *
 */
int svcBwpGrpDelete(bwpGrpIndex_t bwpGrpIndex);

// ========================================================================

/**
 * @brief Returns the next available BWP GRP index
 *
 * @param[in] bwpGrpIndex The BWP GRP Index for which the 'next BWP' is required.
 * @return The next available BWP Index for the specified BWP GRP index.
 */
bwpIndex_t	svcBwpGetNextBwpIndex(bwpGrpIndex_t bwpGrpIndex);

/**
 * @brief Read the next entry in the list of configured BWPs.
 *
 * Read the next entry in the list of configured BWPs. If bwpIndex is 0 it
 * returns the bwpIndex of the first BWP entry or 0 if there are
 * no BWP GRP entries. If a valid bwpIndex is provided it returns
 * the mdIndex of the next MD in the list.
 *
 * @param[in] bwpGrpIndex Selects the index of BWP GRP to read the BWPs from.
 * @param[in] prevBwpIdx The BWP Index from a previous call to this function or 0.
 * @return	bwpIndex of the next entry or 0 if no more entries.
 *
 */
bwpIndex_t svcBwpReadList(bwpGrpIndex_t bwpGrpIndex, bwpIndex_t prevBwpIdx);

/**
 * @brief Create a new service BWP in the specified BWP GRP.
 *
 * Create a new service BWP in the specified BWP GRP using the configuration
 * parameters provided.
 *
 * @param[in] bwpGrpIndex Selects the index of BWP GRP to create the new BWPs on.
 * @param[in] bwpIndex the index value of the BWP to create. Usually obtained by calling svcBwpGetNextIndex()
 * @param[in] svcBwpCfg A pointer to a svcBwpCfg_t data type containing configuration values.
 * @return
 * \li -2: Operation rejected due to insufficient resources
 * \li -1: Operation rejected due to invalid/NULL svcBwpCfg pointer
 * \li  1: Operation rejected due to invalid or nonexistent BWP or BWP GRP index.
 * \li  2: Operation accepted.
 */
int svcBwpCreate(bwpGrpIndex_t bwpGrpIndex, bwpIndex_t bwpIndex, svcBwpCfg_t *svcBwpCfg);

/**
 * @brief	Delete the BWP with the supplied bwpGrpIndex and bwpIndex.
 *
 * This will delete the selected BWP and its associations with all EVCs and Ifaces.
 *
 * @param[in] bwpGrpIndex Selects the index of BWP GRP to delete the BWPs from.
 * @param[in] bwpIndex the index value of BWP to delete.
 * @returns
 * \li 1: Operation rejected due to invalid or nonexistent BWP or BWP GRP index.
 * \li 2: Operation rejected because the BWP is in use by an EVC or Interface
 * \li 3: Operation accepted
 *
 */
int svcBwpDelete(bwpGrpIndex_t bwpGrpIndex, bwpIndex_t bwpIndex);

/**
 * @brief Read the service BWP configuration.
 *
 * Read information related to this service BWP. If a NULL pointer is supplied for
 * svcBwpCfg then no information is returned for that parameter.
 * Information is only valid if the return value is 2.
 *
 * @param[in] bwpGrpIndex Selects the index of BWP GRP to which the BWP belongs.
 * @param[in] bwpIndex the index value of BWP to read from.
 * @param[out] svcBwpCfg A pointer to a svcBwpCfg_t data type or NULL. If not NULL its values will be updated.
 * @return
 * \li 1: Operation rejected due to invalid or nonexistent BWP index.
 * \li 2: Operation accepted.
 */
int svcBwpRead(bwpGrpIndex_t bwpGrpIndex, bwpIndex_t bwpIndex, svcBwpCfg_t *svcBwpCfg);

/**
 * @brief	Write a new value to the selected service BWP parameter.
 *
 * The writable parameters for an service BWP and the associated data type are:
 *	bwpParam_cosIndex		cosIndex_t
 *
 * Write a new value to a writable parameter of the service BWP. The wrParam value
 * is used to select one of the valid writable parameters (listed above) and the paramValue
 * is a pointer to the new value. The data type of the parameter (also listed above)
 * must be valid for the parameter or errors/misconfigurations may occur.
 *
 * @param[in] bwpGrpIndex Selects the index of BWP GRP to which the BWP belongs.
 * @param[in] bwpIndex the index value of BWP to write to.
 * @param[in] wrParam is an enum value that identifies the service UNI parameter to write to.
 * @param[in] paramValue Is a pointer to the new value for the selected parameter
 * @returns
 * \li 1: Operation rejected due to invalid or nonexistent BWP index.
 * \li 2: Operation rejected due to the selected managed object being Read-Only
 * \li 3: Operation rejected due to invalid value for parameter
 * \li 4: Operation accepted
 */
int svcBwpWrite(bwpGrpIndex_t bwpGrpIndex, bwpIndex_t bwpIndex, bwpWrParam_t wrParam, void *paramValue);

#endif /* SVC_BWP_H_ */
