cvl

package
v0.0.0-...-562cd84 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

README

  1. Install latest version of pyang tool.

  2. Install libyang from https://github.com/CESNET/libyang along with its dependency.

  3. Run 'make' from top level 'cvl' directory.

  4. Refer to top level makefile rules for compiling individual targets.

  5. 'schema' directory should contain all .yin files

  6. On the target the 'schema' directory needs to be present in the same directory where application executable file is present.

Debugging Info:

Below steps need to be done to enable CVL logging.

  1. Find the CVL json config file in mgmt-framework docker in switch at "/usr/sbin/cvl_cfg.json" .

  2. Change the logging flags from "false" to "true" as below:

	{
		"TRACE_CACHE": "true",
		"TRACE_LIBYANG": "true",
		"TRACE_YPARSER": "true", 
		"TRACE_CREATE": "true",
		"TRACE_UPDATE": "true",
		"TRACE_DELETE": "true",
		"TRACE_SEMANTIC": "true",
		"TRACE_SYNTAX": "true",
		"TRACE_ONERROR": "true",
		"__comment1__": "Set LOGTOSTDER to 'true' to log on standard error",
		"LOGTOSTDERR": "false",
		"__comment2__": "Log messages to standard error at or above this severity level",
		"STDERRTHRESHOLD": "ERROR",
		"__comment3__": "Log to /tmp/cvl.log file",
		"LOG_TO_FILE": "true",
		"__comment4__": "Limit log file size in bytes, 0 means no limit, default 10MB",
		"LOG_FILE_SIZE": "10485760",
		"__comment5__": "Set verbosity level(1 to 8) for verbose logs",
		"VERBOSITY": "0",
		"SKIP_VALIDATION": "false",
		"SKIP_SEMANTIC_VALIDATION": "false"
	}
  1. Below environment variables need to be set at the end in /usr/bin/rest-server.sh in mgmt-framework docker.

    export CVL_DEBUG=1 export CVL_CFG_FILE=/usr/sbin/cvl_cfg.json

Note : CVL_CFG_FILE enviroment variable can point to other location also.

  1. CVL Traces can be enabled both with restart and without mgmt-framework docker restart .

    With Restart:

    Restart mgmt-framework docker after which updated cvl_cfg.json file will be read.

    Without Restart:

    Issue SIGUSR2 to rest process(kill -SIGUSR2 , to read changed cvl_cfg.json with logging enabled.

  2. After following above steps, CVL traces can be seen in syslog file in host container at /var/log/syslog.

  3. To disable CVL traces , disable the fields in cvl_cfg.json file and then perform same steps as in Step 4.

Documentation

Index

Constants

View Source
const (
	APPL_DB uint8 = 0 + iota
	ASIC_DB
	COUNTERS_DB
	LOGLEVEL_DB
	CONFIG_DB
	PFC_WD_DB
	FLEX_COUNTER_DB = PFC_WD_DB
	STATE_DB
	SNMP_OVERLAY_DB
	INVALID_DB
)

DB number

View Source
const (
	OP_NONE   CVLOperation = 0      //Used to just validate the config without any operation
	OP_CREATE              = 1 << 0 //For Create operation
	OP_UPDATE              = 1 << 1 //For Update operation
	OP_DELETE              = 1 << 2 //For Delete operation
)
View Source
const (
	CVL_SUCCESS CVLRetCode = iota
	CVL_ERROR
	CVL_NOT_IMPLEMENTED
	CVL_INTERNAL_UNKNOWN
	CVL_FAILURE
	CVL_SYNTAX_ERROR                    = CVLRetCode(yparser.YP_SYNTAX_ERROR)
	CVL_SEMANTIC_ERROR                  = CVLRetCode(yparser.YP_SEMANTIC_ERROR)
	CVL_SYNTAX_MISSING_FIELD            = CVLRetCode(yparser.YP_SYNTAX_MISSING_FIELD)
	CVL_SYNTAX_INVALID_FIELD            = CVLRetCode(yparser.YP_SYNTAX_INVALID_FIELD)            /* Invalid Field  */
	CVL_SYNTAX_INVALID_INPUT_DATA       = CVLRetCode(yparser.YP_SYNTAX_INVALID_INPUT_DATA)       /*Invalid Input Data */
	CVL_SYNTAX_MULTIPLE_INSTANCE        = CVLRetCode(yparser.YP_SYNTAX_MULTIPLE_INSTANCE)        /* Multiple Field Instances */
	CVL_SYNTAX_DUPLICATE                = CVLRetCode(yparser.YP_SYNTAX_DUPLICATE)                /* Duplicate Fields  */
	CVL_SYNTAX_ENUM_INVALID             = CVLRetCode(yparser.YP_SYNTAX_ENUM_INVALID)             /* Invalid enum value */
	CVL_SYNTAX_ENUM_INVALID_NAME        = CVLRetCode(yparser.YP_SYNTAX_ENUM_INVALID_NAME)        /* Invalid enum name  */
	CVL_SYNTAX_ENUM_WHITESPACE          = CVLRetCode(yparser.YP_SYNTAX_ENUM_WHITESPACE)          /* Enum name with leading/trailing whitespaces */
	CVL_SYNTAX_OUT_OF_RANGE             = CVLRetCode(yparser.YP_SYNTAX_OUT_OF_RANGE)             /* Value out of range/length/pattern (data) */
	CVL_SYNTAX_MINIMUM_INVALID          = CVLRetCode(yparser.YP_SYNTAX_MINIMUM_INVALID)          /* min-elements constraint not honored  */
	CVL_SYNTAX_MAXIMUM_INVALID          = CVLRetCode(yparser.YP_SYNTAX_MAXIMUM_INVALID)          /* max-elements constraint not honored */
	CVL_SEMANTIC_DEPENDENT_DATA_MISSING = CVLRetCode(yparser.YP_SEMANTIC_DEPENDENT_DATA_MISSING) /* Dependent Data is missing */
	CVL_SEMANTIC_MANDATORY_DATA_MISSING = CVLRetCode(yparser.YP_SEMANTIC_MANDATORY_DATA_MISSING) /* Mandatory Data is missing */
	CVL_SEMANTIC_KEY_ALREADY_EXIST      = CVLRetCode(yparser.YP_SEMANTIC_KEY_ALREADY_EXIST)      /* Key already existing. */
	CVL_SEMANTIC_KEY_NOT_EXIST          = CVLRetCode(yparser.YP_SEMANTIC_KEY_NOT_EXIST)          /* Key is missing. */
	CVL_SEMANTIC_KEY_DUPLICATE          = CVLRetCode(yparser.YP_SEMANTIC_KEY_DUPLICATE)          /* Duplicate key. */
	CVL_SEMANTIC_KEY_INVALID            = CVLRetCode(yparser.YP_SEMANTIC_KEY_INVALID)
)
View Source
const DEFAULT_CACHE_DURATION uint16 = 300 /* 300 sec */
View Source
const MAX_BULK_ENTRIES_IN_PIPELINE int = 50
View Source
const MAX_DEVICE_METADATA_FETCH_RETRY = 60
View Source
const PLATFORM_SCHEMA_PATH = "platform/"

Variables

This section is empty.

Functions

func CVL_LOG

func CVL_LOG(level CVLLogLevel, fmtStr string, args ...interface{})

func ClearValidationTimeStats

func ClearValidationTimeStats()

Clear global stats

func Debug

func Debug(on bool)

func Finish

func Finish()

func GetErrorString

func GetErrorString(retCode CVLRetCode) string

Fetch the Error Message from CVL Return Code.

func TRACE_LOG

func TRACE_LOG(tracelevel CVLTraceLevel, fmtStr string, args ...interface{})

func ValidationSessOpen

func ValidationSessOpen() (*CVL, CVLRetCode)

Types

type CVL

type CVL struct {
	// contains filtered or unexported fields
}

Struct for CVL session

func (*CVL) GetDepDataForDelete

func (c *CVL) GetDepDataForDelete(redisKey string) ([]string, []string)

Get the dependent (Redis keys) to be deleted or modified for a given entry getting deleted

func (*CVL) GetDepTables

func (c *CVL) GetDepTables(yangModule string, tableName string) ([]string, CVLRetCode)

Get the list of dependent tables for a given table in a YANG module

func (*CVL) GetOrderedTables

func (c *CVL) GetOrderedTables(yangModule string) ([]string, CVLRetCode)

Get the order list(parent then child) of tables in a given YANG module within a single model this is obtained using leafref relation

func (*CVL) SortDepTables

func (c *CVL) SortDepTables(inTableList []string) ([]string, CVLRetCode)

Sort list of given tables as per their dependency

func (*CVL) ValidateConfig

func (c *CVL) ValidateConfig(jsonData string) CVLRetCode

Validate data for operation

func (*CVL) ValidateEditConfig

func (c *CVL) ValidateEditConfig(cfgData []CVLEditConfigData) (cvlErr CVLErrorInfo, ret CVLRetCode)

Validate config data based on edit operation

func (*CVL) ValidateFields

func (c *CVL) ValidateFields(key string, field string, value string) CVLRetCode

Validate key, field and value

func (*CVL) ValidateIncrementalConfig

func (c *CVL) ValidateIncrementalConfig(jsonData string) CVLRetCode

Steps:

Check config data syntax
Fetch the depedent data
Merge config and dependent data
Finally validate

func (*CVL) ValidateKeyData

func (c *CVL) ValidateKeyData(key string, data string) CVLRetCode

Validate key and data

func (*CVL) ValidateKeys

func (c *CVL) ValidateKeys(key []string) CVLRetCode

Validate key only

func (*CVL) ValidateStartupConfig

func (c *CVL) ValidateStartupConfig(jsonData string) CVLRetCode

type CVLEditConfigData

type CVLEditConfigData struct {
	VType CVLValidateType   //Validation type
	VOp   CVLOperation      //Operation type
	Key   string            //Key format : "PORT|Ethernet4"
	Data  map[string]string //Value :  {"alias": "40GE0/28", "mtu" : 9100,  "admin_status":  down}
}

Strcture for key and data in API

type CVLErrorInfo

type CVLErrorInfo struct {
	TableName        string     /* Table having error */
	ErrCode          CVLRetCode /* CVL Error return Code. */
	CVLErrDetails    string     /* CVL Error Message details. */
	Keys             []string   /* Keys of the Table having error. */
	Value            string     /* Field Value throwing error */
	Field            string     /* Field Name throwing error . */
	Msg              string     /* Detailed error message. */
	ConstraintErrMsg string     /* Constraint error message. */
	ErrAppTag        string
}

CVL Error Structure.

type CVLOperation

type CVLOperation uint

type CVLRetCode

type CVLRetCode int

Error code

func Initialize

func Initialize() CVLRetCode

func ValidationSessClose

func ValidationSessClose(c *CVL) CVLRetCode

type CVLValidateType

type CVLValidateType uint
const (
	VALIDATE_NONE      CVLValidateType = iota //Data is used as dependent data
	VALIDATE_SYNTAX                           //Syntax is checked and data is used as dependent data
	VALIDATE_SEMANTICS                        //Semantics is checked
	VALIDATE_ALL                              //Syntax and Semantics are checked
)

type ValidationTimeStats

type ValidationTimeStats struct {
	Hits uint
	Time time.Duration
	Peak time.Duration
}

CVL validations stats Maintain time stats for call to ValidateEditConfig(). Hits : Total number of times ValidateEditConfig() called Time : Total time spent in ValidateEditConfig() Peak : Highest time spent in ValidateEditConfig()

func GetValidationTimeStats

func GetValidationTimeStats() ValidationTimeStats

Retrieve global stats

type YValidator

type YValidator struct {
	// contains filtered or unexported fields
}

YANG Validator used for external semantic validation including custom/platform validation

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL