transformer

package
v0.0.0-...-5f1191e Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TARGET_NODE xlateNodeType = 1 + iota
	CHILD_NODE
)
View Source
const (
	XPATH_SEP_FWD_SLASH          = "/"
	XFMR_EMPTY_STRING            = ""
	XFMR_NONE_STRING             = "NONE"
	SONIC_TABLE_INDEX            = 2
	SONIC_TBL_CHILD_INDEX        = 3
	SONIC_FIELD_INDEX            = 4
	SONIC_NESTEDLIST_FIELD_INDEX = 5
	SONIC_TOPCONTR_INDEX         = 1
	SONIC_MDL_PFX                = "sonic"
	OC_MDL_PFX                   = "openconfig-"
	IETF_MDL_PFX                 = "ietf-"
	IANA_MDL_PFX                 = "iana-"
	PATH_XFMR_RET_ARGS           = 1
	PATH_XFMR_RET_ERR_INDX       = 0

	YANG_CONTAINER_NM_CONFIG  = "config"
	CONFIG_CNT_SUFFIXED_XPATH = "/config"
	STATE_CNT_SUFFIXED_XPATH  = "/state"
	CONFIG_CNT_WITHIN_XPATH   = "/config/"
	STATE_CNT_WITHIN_XPATH    = "/state/"
)
View Source
const (
	YANG_MODULE yangElementType = iota + 1
	YANG_LIST
	YANG_CONTAINER
	YANG_LEAF
	YANG_LEAF_LIST
	YANG_CHOICE
	YANG_CASE
	YANG_RPC
	YANG_NOTIF
)
View Source
const (
	XFMR_INVALID = iota - 1
	XFMR_DISABLE
	XFMR_ENABLE
	XFMR_DEFAULT_ENABLE
)
View Source
const (
	QUERY_CONTENT_MISMATCH_ERR      = "Query Parameter Content mismatch"
	QUERY_PARAMETER_SBT_PRUNING_ERR = "Query Parameter processing unsuccessful"
)
View Source
const (
	/* sFlow tables */
	SFLOW_GLOBAL_TBL = "SFLOW"
	SFLOW_COL_TBL    = "SFLOW_COLLECTOR"
	SFLOW_SESS_TBL   = "SFLOW_SESSION_TABLE" /* Session table in ApplDb */
	SFLOW_INTF_TBL   = "SFLOW_SESSION"       /* Session table in ConfigDb */

	/* sFlow keys */
	SFLOW_GLOBAL_KEY      = "global"
	SFLOW_ADMIN_KEY       = "admin_state"
	SFLOW_POLLING_INT_KEY = "polling_interval"
	SFLOW_SAMPL_RATE_KEY  = "sample_rate"
	SFLOW_AGENT_KEY       = "agent_id"
	SFLOW_INTF_NAME_KEY   = "name"
	SFLOW_COL_IP_KEY      = "collector_ip"
	SFLOW_COL_PORT_KEY    = "collector_port"
	SFLOW_COL_VRF_KEY     = "collector_vrf"

	/* sFlow default values */
	DEFAULT_POLLING_INT = 20
	DEFAULT_AGENT       = "default"
	DEFAULT_VRF_NAME    = "default"
	DEFAULT_COL_PORT    = "6343"

	/* sFlow URIs */
	SAMPLING                                    = "/openconfig-sampling-sflow:sampling"
	SAMPLING_SFLOW                              = "/openconfig-sampling-sflow:sampling/sflow"
	SAMPLING_SFLOW_CONFIG                       = "/openconfig-sampling-sflow:sampling/sflow/config"
	SAMPLING_SFLOW_CONFIG_ENABLED               = "/openconfig-sampling-sflow:sampling/sflow/config/enabled"
	SAMPLING_SFLOW_CONFIG_POLLING_INT           = "/openconfig-sampling-sflow:sampling/sflow/config/polling-interval"
	SAMPLING_SFLOW_CONFIG_AGENT                 = "/openconfig-sampling-sflow:sampling/sflow/config/agent"
	SAMPLING_SFLOW_STATE                        = "/openconfig-sampling-sflow:sampling/sflow/state"
	SAMPLING_SFLOW_STATE_ENABLED                = "/openconfig-sampling-sflow:sampling/sflow/state/enabled"
	SAMPLING_SFLOW_STATE_POLLING_INT            = "/openconfig-sampling-sflow:sampling/sflow/state/polling-interval"
	SAMPLING_SFLOW_STATE_AGENT                  = "/openconfig-sampling-sflow:sampling/sflow/state/agent"
	SAMPLING_SFLOW_COLS                         = "/openconfig-sampling-sflow:sampling/sflow/collectors"
	SAMPLING_SFLOW_COLS_COL                     = "/openconfig-sampling-sflow:sampling/sflow/collectors/collector"
	SAMPLING_SFLOW_COLS_COL_CONFIG              = "/openconfig-sampling-sflow:sampling/sflow/collectors/collector/config"
	SAMPLING_SFLOW_COLS_COL_STATE               = "/openconfig-sampling-sflow:sampling/sflow/collectors/collector/state"
	SAMPLING_SFLOW_INTFS                        = "/openconfig-sampling-sflow:sampling/sflow/interfaces"
	SAMPLING_SFLOW_INTFS_INTF                   = "/openconfig-sampling-sflow:sampling/sflow/interfaces/interface"
	SAMPLING_SFLOW_INTFS_INTF_CONFIG            = "/openconfig-sampling-sflow:sampling/sflow/interfaces/interface/config"
	SAMPLING_SFLOW_INTFS_INTF_CONFIG_SAMPL_RATE = "/openconfig-sampling-sflow:sampling/sflow/interfaces/interface/config/sampling-rate"
	SAMPLING_SFLOW_INTFS_INTF_CONFIG_ENABLED    = "/openconfig-sampling-sflow:sampling/sflow/interfaces/interface/config/enabled"
	SAMPLING_SFLOW_INTFS_INTF_STATE             = "/openconfig-sampling-sflow:sampling/sflow/interfaces/interface/state"

	/* IPv4/v6 localhost address */
	IPV4_LOCALHOST = "127.0.0.1"
	IPV6_LOCALHOST = "::1"
)
View Source
const DEL_AS_UPDATE = "@DEL_AS_UPDATE"
View Source
const FIELD_CURSOR = "@FIELD_CURSOR"
View Source
const KEY_COMP_CNT = "@KEY_COMP_CNT"

KEY_COMP_CNT - To specify the number of key components for the given key in the RedisDbSubscribeMap map

Variables

View Source
var (
	ErrParamsNotAdapted = errors.New("The number of params is not adapted.")
)
View Source
var ModelsListFile = "models_list"
View Source
var TblInfoJsonFile = "sonic_table_info.json"
View Source
var XlateFuncs = make(map[string]reflect.Value)
View Source
var YangPath = "/usr/models/yang/" // OpenConfig-*.yang and sonic yang models path

Functions

func AddModelCpbltInfo

func AddModelCpbltInfo() map[string]*mdlInfo

func CallRpcMethod

func CallRpcMethod(path string, body []byte, dbs [db.MaxDB]*db.DB) ([]byte, error)

func DbToYangType

func DbToYangType(yngTerminalNdDtType yang.TypeKind, fldXpath string, dbFldVal string, oper Operation) (interface{}, interface{}, error)

func DbValToInt

func DbValToInt(dbFldVal string, base int, size int, isUint bool) (interface{}, error)

func GetAndXlateFromDB

func GetAndXlateFromDB(uri string, ygRoot *ygot.GoStruct, dbs [db.MaxDB]*db.DB,
	txCache interface{}, qParams QueryParams, reqCtxt context.Context, ygSchema *yang.Entry) ([]byte, bool, error)

func GetModuleNmFromPath

func GetModuleNmFromPath(uri string) (string, error)

func GetOrdTblList

func GetOrdTblList(xfmrTbl string, uriModuleNm string) []string

func GetTablesToWatch

func GetTablesToWatch(xfmrTblList []string, uriModuleNm string) []string

func GetXfmrOrdTblList

func GetXfmrOrdTblList(xfmrTbl string) []string

func IsLeafListNode

func IsLeafListNode(uri string) bool

func IsLeafNode

func IsLeafNode(uri string) bool

func IsListNode

func IsListNode(uri string) bool

func IsTerminalNode

func IsTerminalNode(uri string) (bool, error)

func IsXlateFuncBinded

func IsXlateFuncBinded(name string) bool

func NewSubscribeNotfRespXlator

func NewSubscribeNotfRespXlator(ctxID interface{}, gPath *gnmi.Path, dbNum db.DBNum, table *db.TableSpec, key *db.Key,
	entry *db.Value, dbs [db.MaxDB]*db.DB, opaque interface{}) (*subscribeNotfRespXlator, error)

func NewSubscribeReqXlator

func NewSubscribeReqXlator(subReqId interface{}, reqUri string, reqMode NotificationType, dbs [db.MaxDB]*db.DB, txCache interface{}) (*subscribeReqXlator, error)

func SonicUriHasSingletonContainer

func SonicUriHasSingletonContainer(uri string) bool

func SortSncTableDbKeys

func SortSncTableDbKeys(tableName string, dbKeyMap map[string]db.Value) []string

func SplitPath

func SplitPath(path string) []string

SplitPath splits the ygot path into parts.

func TraverseDb

func TraverseDb(dbs [db.MaxDB]*db.DB, spec KeySpec, result *map[db.DBNum]map[string]map[string]db.Value,
	parentKey *db.Key, dbTblKeyGetCache map[db.DBNum]map[string]map[string]bool, reqCtxt context.Context) error

func XfmrRemoveXPATHPredicates

func XfmrRemoveXPATHPredicates(uri string) (string, []string, error)

func XlateFromDb

func XlateFromDb(uri string, ygRoot *ygot.GoStruct, dbs [db.MaxDB]*db.DB, data RedisDbMap, txCache interface{}, inParamsForGet xlateFromDbParams) ([]byte, bool, error)

func XlateFuncBind

func XlateFuncBind(name string, fn interface{}) (err error)

func XlateFuncCall

func XlateFuncCall(name string, params ...interface{}) (result []reflect.Value, err error)

func XlateToDb

func XlateToDb(path string, oper int, d *db.DB, yg *ygot.GoStruct, yt *interface{}, jsonPayload []byte, txCache interface{}, skipOrdTbl *bool) (map[Operation]RedisDbMap, map[string]map[string]db.Value, map[string]map[string]db.Value, error)

func XlateUriToKeySpec

func XlateUriToKeySpec(uri string, requestUri string, ygRoot *ygot.GoStruct, t *interface{}, txCache interface{},
	qParams QueryParams, dbs [db.MaxDB]*db.DB, dbTblKeyCache map[string]tblKeyCache, dbDataMap RedisDbMap) (*[]KeySpec, error)

Types

type ContentType

type ContentType uint8
const (
	QUERY_CONTENT_ALL ContentType = iota
	QUERY_CONTENT_CONFIG
	QUERY_CONTENT_NONCONFIG
	QUERY_CONTENT_OPERATIONAL
)

func (ContentType) String

func (ct ContentType) String() string

type DBKeyYgNodeInfo

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

DBKeyYgNodeInfo holds yang node info for a db key. Can be used as value in RedisDbYgNodeMap.

type DbFldYgPathInfo

type DbFldYgPathInfo struct {
	RltvPath       string
	DbFldYgPathMap map[string]string //db field to leaf / rel. path to leaf
}

type DbToYangXfmrInputArgs

type DbToYangXfmrInputArgs struct {
	InParamsForGet *xlateFromDbParams
	CurUri         string
	DbKey          string
	XfmrFuncName   string
}

type DbYangKeyResolver

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

type DbYgXlateInfo

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

type FieldXfmrDbtoYang

type FieldXfmrDbtoYang func(inParams XfmrParams) (map[string]interface{}, error)

FieldXfmrDbtoYang type is defined to use for conversion of DB field to Yang field Transformer function definition. Param: XfmrParams structure having Database info, operation, DB data in multidimensional map, output param YgotRoot Return: error

type FieldXfmrYangToDb

type FieldXfmrYangToDb func(inParams XfmrParams) (map[string]string, error)

FieldXfmrYangToDb type is defined to use for conversion of yang Field to DB field Transformer function definition. Param: Database info, YgotRoot, operation, Xpath Return: multi dimensional map to hold the DB data, error

type HostResult

type HostResult struct {
	Body []interface{}
	Err  error
}

HostResult contains the body of the response and the error if any, when the endpoint finishes servicing the D-Bus request.

func HostQuery

func HostQuery(endpoint string, args ...interface{}) (result HostResult)

HostQuery calls the corresponding D-Bus endpoint on the host and returns any error and response body

type KeySpec

type KeySpec struct {
	DbNum           db.DBNum
	Ts              db.TableSpec
	Key             db.Key
	Child           []KeySpec
	IgnoreParentKey bool
	IsPartialKey    bool
}

type KeyXfmrDbToYang

type KeyXfmrDbToYang func(inParams XfmrParams) (map[string]interface{}, error)

KeyXfmrDbToYang type is defined to use for conversion of DB key to Yang key, Transformer function definition. Param: XfmrParams structure having Database info, operation, Database keys to access db entry Return: multi dimensional map to hold the yang key attributes of complete xpath, error */

type KeyXfmrYangToDb

type KeyXfmrYangToDb func(inParams XfmrParams) (string, error)

KeyXfmrYangToDb type is defined to use for conversion of Yang key to DB Key, Transformer function definition. Param: XfmrParams structure having Database info, YgotRoot, operation, Xpath Return: Database keys to access db entry, error

type ModProfile

type ModProfile map[string]interface{}

type NotificationType

type NotificationType int
const (
	TargetDefined NotificationType = iota
	Sample
	OnChange
)

type OnchangeMode

type OnchangeMode int
const (
	OnchangeDefault OnchangeMode = iota
	OnchangeEnable
	OnchangeDisable
)

type Operation

type Operation int
const (
	GET Operation = iota + 1
	CREATE
	REPLACE
	UPDATE
	DELETE
	SUBSCRIBE
	MAXOPER
)

func (Operation) String

func (oper Operation) String() string

type PathInfo

type PathInfo struct {
	Path     string
	Template string
	Vars     map[string]string
	YangPath string
}

PathInfo structure contains parsed path information.

func NewPathInfo

func NewPathInfo(path string) *PathInfo

NewPathInfo parses given path string into a PathInfo structure.

func (*PathInfo) HasVar

func (p *PathInfo) HasVar(name string) bool

HasVar checks if the PathInfo contains given variable.

func (*PathInfo) HasWildcard

func (p *PathInfo) HasWildcard() bool

HasWildcard checks if the path contains wildcard variable "*".

func (*PathInfo) StringVar

func (p *PathInfo) StringVar(name, defaultValue string) string

StringVar returns the string value for a path variable if it exists; otherwise returns the specified default value.

func (*PathInfo) Var

func (p *PathInfo) Var(name string) string

Var returns the string value for a path variable. Returns empty string if no such variable exists.

type PathXfmrDbToYangFunc

type PathXfmrDbToYangFunc func(params XfmrDbToYgPathParams) error

PathXfmrDbToYangFunc type is defined to convert the given db table key into the yang key for all the list node in the given yang URI path. ygPathKeys map will be used to store the yang key as value in the map for each yang key leaf node path of the given yang URI. Param : XfmrDbToYgPathParams structure has current yang uri path, subscribe path, table name, table key, db pointer slice, current db pointer, db number, map to hold path and yang keys Return: error

var DbToYangPath_sflow_collector_path_xfmr PathXfmrDbToYangFunc = func(params XfmrDbToYgPathParams) error {
	log.V(3).Info("DbToYangPath_sflow_collector fmr: tbl:", params.tblName)
	sflowCollRoot := "/openconfig-sampling-sflow:sampling/sflow/collectors/collector"

	if params.tblName != SFLOW_COL_TBL {
		oper_err := errors.New("wrong config DB table sent")
		log.Errorf("Sflow collector Path-xfmr: table name %s not in sflow view", params.tblName)
		return oper_err
	} else {
		if len(params.tblKeyComp) > 0 {
			key_parts := strings.Split(params.tblKeyComp[0], "_")
			if len(key_parts) != 3 {
				oper_err := errors.New("Invalid key " + params.tblKeyComp[0])
				log.Errorf("sflow_collector_path_xfmr: Invalid Key  %s", params.tblKeyComp[0])
				return oper_err
			}
			params.ygPathKeys[sflowCollRoot+"/address"] = key_parts[0]
			params.ygPathKeys[sflowCollRoot+"/port"] = key_parts[1]
			params.ygPathKeys[sflowCollRoot+"/network-instance"] = key_parts[2]
		} else {
			oper_err := errors.New("Missing DB key.")
			log.Errorf("Missing DB Key")
			return oper_err
		}
	}
	log.V(3).Info("DbToYangPath sflow_collector  ygPathKeys: ", params.ygPathKeys)

	return nil
}
var DbToYangPath_sflow_interface_path_xfmr PathXfmrDbToYangFunc = func(params XfmrDbToYgPathParams) error {
	log.V(3).Info("DbToYangPath_sflow_interface fmr: tbl:", params.tblName)
	sflowCollRoot := "/openconfig-sampling-sflow:sampling/sflow/interfaces/interface"

	if params.tblName != SFLOW_SESS_TBL {
		oper_err := errors.New("wrong config DB table sent")
		log.Errorf("Sflow interface Path-xfmr: table name %s not in sflow view", params.tblName)
		return oper_err
	} else {
		if len(params.tblKeyComp) > 0 {
			params.ygPathKeys[sflowCollRoot+"/name"] = params.tblKeyComp[0]
		} else {
			oper_err := errors.New("Missing DB key.")
			log.Errorf("Missing DB Key")
			return oper_err
		}
	}
	log.V(3).Info("DbToYangPath sflow_interface  ygPathKeys: ", params.ygPathKeys)

	return nil
}

type PostXfmrFunc

type PostXfmrFunc func(inParams XfmrParams) (map[string]map[string]db.Value, error)

PostXfmrFunc type is defined to use for handling any default handling operations required as part of the CREATE Transformer function definition. Param: XfmrParams structure having database pointers, current db, operation, DB data in multidimensional map, YgotRoot, uri Return: Multi dimensional map to hold the DB data Map (tblName, key and Fields), error

type PreXfmrFunc

type PreXfmrFunc func(inParams XfmrParams) error

PreXfmrFunc type is defined to use for handling any default handling operations required as part of the CREATE, UPDATE, REPLACE, DELETE & GET Transformer function definition. Param: XfmrParams structure having database pointers, current db, operation, DB data in multidimensional map, YgotRoot, uri Return: error

type PruneQPStats

type PruneQPStats struct {
	Hits uint `json:"hits"`

	Time time.Duration `json:"total-time"`
	Peak time.Duration `json:"peak-time"`
	Last time.Duration `json:"last-time"`

	PeakUri string `json:"peak-uri"`
	LastUri string `json:"last-uri"`
}

func GetPruneQPStats

func GetPruneQPStats() *PruneQPStats

func (*PruneQPStats) ClearPruneQPStats

func (pqps *PruneQPStats) ClearPruneQPStats()

func (*PruneQPStats) String

func (pqps *PruneQPStats) String() string

type QueryParams

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

func NewQueryParams

func NewQueryParams(depth uint, content string, fields []string) (QueryParams, error)

func (*QueryParams) IsContentEnabled

func (qp *QueryParams) IsContentEnabled() bool

func (*QueryParams) IsEnabled

func (qp *QueryParams) IsEnabled() bool

IsEnabled : Exported version. translib.common_app needs this.

func (QueryParams) String

func (qp QueryParams) String() string

type RedisDbMap

type RedisDbMap = map[db.DBNum]map[string]map[string]db.Value

type RedisDbSubscribeMap

type RedisDbSubscribeMap = map[db.DBNum]map[string]map[string]map[string]string

type RedisDbYgNodeMap

type RedisDbYgNodeMap = map[db.DBNum]map[string]map[string]interface{}

type RpcCallpoint

type RpcCallpoint func(body []byte, dbs [db.MaxDB]*db.DB) ([]byte, error)

RpcCallpoint is used to invoke a callback for action Param : []byte input payload, dbi indices Return : []byte output payload, error

type Sflow

type Sflow struct {
	Enabled          string
	Polling_Interval string
	Agent            string
}

type SflowCol

type SflowCol struct {
	Ip   string
	Port string
	Vrf  string
}

type SflowIntf

type SflowIntf struct {
	Enabled       string
	Sampling_Rate string
}

type SonicKeyXfmrDbToYang

type SonicKeyXfmrDbToYang func(inParams SonicXfmrParams) (map[string]interface{}, error)

SonicKeyXfmrDbToYang type is defined to use for conversion of DB key to Yang key, Transformer function definition. Param: SonicXfmrParams structure having DB number, table, key and xpath Return: multi dimensional map to hold the yang key attributes, error */

type SonicXfmrParams

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

SonicXfmrParams represents input parameters for key-transformer on sonic-yang

func (SonicXfmrParams) String

func (inPm SonicXfmrParams) String() string

type SubTreeXfmrDbToYang

type SubTreeXfmrDbToYang func(inParams XfmrParams) error

SubTreeXfmrDbToYang type is defined to use for handling the DB to Yang subtree Transformer function definition. Param : XfmrParams structure having Database pointers, current db, operation, DB data in multidimensional map, output param YgotRoot, uri Return : error

var DbToYang_sflow_collector_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error {
	pathInfo := NewPathInfo(inParams.uri)
	log.V(3).Infof("Received GET for sFlow Collector path: %s, vars: %v", pathInfo.Path, pathInfo.Vars)
	log.V(3).Info("inParams.Uri:", inParams.requestUri)
	targetUriPath, _, _ := XfmrRemoveXPATHPredicates(inParams.requestUri)
	return getSflowCol(getSflowRootObject(inParams.ygRoot), targetUriPath, inParams.uri, inParams.dbs[db.ConfigDB])
}
var DbToYang_sflow_interface_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error {
	pathInfo := NewPathInfo(inParams.uri)
	log.V(3).Infof("Received GET for sFlow Interface path: %s, vars: %v", pathInfo.Path, pathInfo.Vars)
	log.V(3).Info("inParams.Uri:", inParams.requestUri)
	targetUriPath, _, _ := XfmrRemoveXPATHPredicates(inParams.requestUri)
	return getSflowIntf(getSflowRootObject(inParams.ygRoot), targetUriPath, inParams.uri, inParams.dbs[db.ApplDB])
}
var DbToYang_sflow_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error {
	pathInfo := NewPathInfo(inParams.uri)
	log.V(3).Infof("Received GET for sFlow path: %s, vars: %v", pathInfo.Path, pathInfo.Vars)

	log.V(3).Info("inParams.Uri:", inParams.requestUri)
	targetUriPath, _, _ := XfmrRemoveXPATHPredicates(inParams.requestUri)
	return getSflow(getSflowRootObject(inParams.ygRoot), targetUriPath, inParams.uri, inParams.dbs[:])
}

type SubTreeXfmrSubscribe

type SubTreeXfmrSubscribe func(inParams XfmrSubscInParams) (XfmrSubscOutParams, error)

SubTreeXfmrSubscribe type is defined to use for handling subscribe(translateSubscribe & processSubscribe) subtree Transformer function definition. Param : XfmrSubscInParams structure having uri, database pointers, subcribe process(translate/processSusbscribe), DB data in multidimensional map Return : XfmrSubscOutParams structure (db data in multiD map, needCache, pType, onChange, minInterval), error

var Subscribe_sflow_collector_xfmr SubTreeXfmrSubscribe = func(inParams XfmrSubscInParams) (XfmrSubscOutParams, error) {

	var err error
	var result XfmrSubscOutParams
	result.dbDataMap = make(RedisDbSubscribeMap)

	pathInfo := NewPathInfo(inParams.uri)
	targetUriPath, _, _ := XfmrRemoveXPATHPredicates(inParams.uri)

	log.V(3).Infof("Subscribe_sflow_collector_xfmr: pathInfo %v targetUri %v ", pathInfo, targetUriPath)

	ip := pathInfo.Var("address")
	if ip == "" {
		ip = "*"
	}

	port := pathInfo.Var("port")
	if port == "" {
		port = "*"
	}
	vrf := pathInfo.Var("network-instance")
	if vrf == "" {
		vrf = "*"
	}
	var name string
	if ip == "*" && port == "*" && vrf == "*" {
		name = "*"
	} else {
		name = ip + "_" + port + "_" + vrf
	}
	log.V(3).Infof("Subscribe_sflow_collector_xfmr: key %s", name)
	result.dbDataMap = RedisDbSubscribeMap{db.ConfigDB: {SFLOW_COL_TBL: {name: {
		"collector_ip": "address", "collector_port": "port", "collector_vrf": "network-instance"}}}}

	return result, err
}
var Subscribe_sflow_interface_xfmr SubTreeXfmrSubscribe = func(inParams XfmrSubscInParams) (XfmrSubscOutParams, error) {
	var err error
	var result XfmrSubscOutParams
	result.dbDataMap = make(RedisDbSubscribeMap)
	key := NewPathInfo(inParams.uri).Var("name")

	if key == "" {
		key = "*"
	}
	log.V(3).Infof("XfmrSubscribe_sflow_interface_xfmr key %s ", key)
	result.dbDataMap = RedisDbSubscribeMap{db.ApplDB: {SFLOW_SESS_TBL: {key: {
		"ifname": "name", "admin_state": "enabled", "sample_rate": "sampling-rate"}}}}

	return result, err
}
var Subscribe_sflow_xfmr SubTreeXfmrSubscribe = func(inParams XfmrSubscInParams) (XfmrSubscOutParams, error) {
	var err error
	var result XfmrSubscOutParams
	if inParams.subscProc != TRANSLATE_SUBSCRIBE {
		result.isVirtualTbl = true
		log.V(3).Info("Subscribe_sflow_xfmr :- result.  isVirtualTbl: ", result.isVirtualTbl)
		return result, nil
	}
	result.dbDataMap = make(RedisDbSubscribeMap)

	targetUriPath, _, _ := XfmrRemoveXPATHPredicates(inParams.uri)

	log.V(3).Infof("Subscribe_sflow_xfmr: targetUri %v ", targetUriPath)

	if targetUriPath == SAMPLING_SFLOW || targetUriPath == SAMPLING_SFLOW_CONFIG ||
		targetUriPath == SAMPLING_SFLOW_STATE {
		result.dbDataMap = RedisDbSubscribeMap{db.ConfigDB: {SFLOW_GLOBAL_TBL: {
			SFLOW_GLOBAL_KEY: {"admin_state": "enabled", "polling_interval": "polling-interval", "agent_id": "agent"}}}}
		result.onChange = OnchangeEnable
		result.nOpts = &notificationOpts{}
		result.nOpts.pType = OnChange
		result.isVirtualTbl = false
	}
	return result, err
}

type SubTreeXfmrYangToDb

type SubTreeXfmrYangToDb func(inParams XfmrParams) (map[string]map[string]db.Value, error)

SubTreeXfmrYangToDb type is defined to use for handling the yang subtree to DB Transformer function definition. Param: XfmrParams structure having Database info, YgotRoot, operation, Xpath Return: multi dimensional map to hold the DB data, error

var YangToDb_sflow_collector_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) {
	var err error
	res_map := make(map[string]map[string]db.Value)

	log.V(3).Info("sFlow Collector YangToDBSubTreeXfmr: ", inParams.uri)
	col_map := make(map[string]db.Value)
	sflowObj := getSflowRootObject(inParams.ygRoot)

	key := makeColKey(inParams.uri)
	if inParams.oper == DELETE {
		if key != "" {
			col_map[key] = db.Value{Field: make(map[string]string)}
		}
		res_map[SFLOW_COL_TBL] = col_map
		return res_map, err
	}

	if key != "" {
		ip := NewPathInfo(inParams.uri).Var("address")
		port := NewPathInfo(inParams.uri).Var("port")
		vrf := NewPathInfo(inParams.uri).Var("network-instance")
		col_map[key] = db.Value{Field: make(map[string]string)}
		col_map[key].Field[SFLOW_COL_IP_KEY] = ip
		col_map[key].Field[SFLOW_COL_PORT_KEY] = port
		col_map[key].Field[SFLOW_COL_VRF_KEY] = vrf
	} else {
		for col := range sflowObj.Sflow.Collectors.Collector {
			port := strconv.FormatUint(uint64(col.Port), 10)
			key = col.Address + "_" + port + "_" + col.NetworkInstance
			col_map[key] = db.Value{Field: make(map[string]string)}
			col_map[key].Field[SFLOW_COL_IP_KEY] = col.Address
			col_map[key].Field[SFLOW_COL_PORT_KEY] = port
			col_map[key].Field[SFLOW_COL_VRF_KEY] = col.NetworkInstance
		}
	}

	res_map[SFLOW_COL_TBL] = col_map
	return res_map, err
}
var YangToDb_sflow_interface_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) {
	var err error
	res_map := make(map[string]map[string]db.Value)

	log.V(3).Info("sFlow Interface YangToDBSubTreeXfmr: ", inParams.uri)
	intf_map := make(map[string]db.Value)
	sflowObj := getSflowRootObject(inParams.ygRoot)
	targetUriPath, _, _ := XfmrRemoveXPATHPredicates(inParams.requestUri)
	log.V(3).Infof("Subscribe_sflow_xfmr: targetUri %v ", targetUriPath)

	if inParams.oper == DELETE {
		if !strings.Contains(targetUriPath, SAMPLING_SFLOW_INTFS_INTF) {
			return res_map, tlerr.NotSupportedError{Format: "DELETE not supported", Path: targetUriPath}
		}

		name := NewPathInfo(inParams.uri).Var("name")
		if name == "" {
			return res_map, tlerr.InvalidArgs("Missing interface name")
		}

		intf_map[name] = db.Value{Field: make(map[string]string)}
		switch targetUriPath {
		case SAMPLING_SFLOW_INTFS_INTF_CONFIG_SAMPL_RATE:
			intf_map[name].Field[SFLOW_SAMPL_RATE_KEY] = ""
		case SAMPLING_SFLOW_INTFS_INTF_CONFIG_ENABLED:
			intf_map[name].Field[SFLOW_ADMIN_KEY] = ""
		case SAMPLING_SFLOW_INTFS_INTF:

		default:
			return res_map, errors.New("DELETE not supported on attribute or container")
		}
	} else {
		for _, intf := range sflowObj.Sflow.Interfaces.Interface {

			if intf.Name == nil {
				return res_map, errors.New("sFlow Interface: No interface name")
			}

			if intf.Config == nil {
				log.V(3).Infof("sFlow Inteface: No configuration")
				continue
			}

			name := *(intf.Name)
			intf_map[name] = db.Value{Field: make(map[string]string)}

			if intf.Config.Enabled != nil {
				if *(intf.Config.Enabled) {
					intf_map[name].Field[SFLOW_ADMIN_KEY] = "up"
				} else {
					intf_map[name].Field[SFLOW_ADMIN_KEY] = "down"
				}
			}

			if intf.Config.SamplingRate != nil {
				intf_map[name].Field[SFLOW_SAMPL_RATE_KEY] =
					strconv.FormatUint(uint64(*(intf.Config.SamplingRate)), 10)
			}
		}
	}

	res_map[SFLOW_INTF_TBL] = intf_map
	return res_map, err
}
var YangToDb_sflow_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) {
	var err error
	res_map := make(map[string]map[string]db.Value)

	log.V(3).Info("sFlow SubTreeXfmr: ", inParams.uri)
	global_map := make(map[string]db.Value)
	sflowObj := getSflowRootObject(inParams.ygRoot)
	targetUriPath, _, _ := XfmrRemoveXPATHPredicates(inParams.requestUri)

	global_map[SFLOW_GLOBAL_KEY] = db.Value{Field: make(map[string]string)}

	if inParams.oper == DELETE {
		switch targetUriPath {
		case SAMPLING_SFLOW_CONFIG_AGENT:
			global_map[SFLOW_GLOBAL_KEY].Field[SFLOW_AGENT_KEY] = ""
		case SAMPLING_SFLOW_CONFIG_POLLING_INT:
			global_map[SFLOW_GLOBAL_KEY].Field[SFLOW_POLLING_INT_KEY] = ""
		default:
			return res_map, errors.New("DELETE not supported on attribute")
		}

		res_map[SFLOW_GLOBAL_TBL] = global_map
		return res_map, err
	}

	if sflowObj.Sflow.Config.Enabled != nil {
		if *(sflowObj.Sflow.Config.Enabled) {
			global_map[SFLOW_GLOBAL_KEY].Field[SFLOW_ADMIN_KEY] = "up"
		} else {
			global_map[SFLOW_GLOBAL_KEY].Field[SFLOW_ADMIN_KEY] = "down"
		}
	}

	if sflowObj.Sflow.Config.PollingInterval != nil {
		global_map[SFLOW_GLOBAL_KEY].Field[SFLOW_POLLING_INT_KEY] =
			strconv.FormatUint(uint64(*(sflowObj.Sflow.Config.PollingInterval)), 10)
	}

	if sflowObj.Sflow.Config.Agent != nil {
		global_map[SFLOW_GLOBAL_KEY].Field[SFLOW_AGENT_KEY] = *(sflowObj.Sflow.Config.Agent)
	}

	res_map[SFLOW_GLOBAL_TBL] = global_map
	return res_map, err
}

type SubscProcType

type SubscProcType int

SubscProcType represents subcription process type identifying the type of subscription request made from translib.

const (
	TRANSLATE_EXISTS SubscProcType = iota
	TRANSLATE_SUBSCRIBE
	PROCESS_SUBSCRIBE
)

type TableXfmrFunc

type TableXfmrFunc func(inParams XfmrParams) ([]string, error)

TableXfmrFunc type is defined to use for table transformer function for dynamic derviation of redis table. Param: XfmrParams structure having database pointers, current db, operation, DB data in multidimensional map, YgotRoot, uri Return: List of table names, error

type ValidateCallpoint

type ValidateCallpoint func(inParams XfmrParams) bool

ValidateCallpoint is used to validate a YANG node during data translation back to YANG as a response to GET Param : XfmrParams structure having Database pointers, current db, operation, DB data in multidimensional map, output param YgotRoot, uri Return : bool

type ValueXfmrFunc

type ValueXfmrFunc func(inParams XfmrDbParams) (string, error)

ValueXfmrFunc type is defined to use for conversion of DB field value from one forma to another Transformer function definition. Param: XfmrDbParams structure having Database info, operation, db-number, table, key, field, value Return: value string, error

type XfmrDbParams

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

XfmrDbParams represents input paraDeters for value-transformer

func (XfmrDbParams) String

func (inPm XfmrDbParams) String() string

type XfmrDbTblCbkMethod

type XfmrDbTblCbkMethod func(inParams XfmrDbTblCbkParams) error

type XfmrDbTblCbkParams

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

func (XfmrDbTblCbkParams) String

func (inPm XfmrDbTblCbkParams) String() string

type XfmrDbToYgPathParams

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

XfmrDbToYgPathParams represents input parameters for path-transformer Fields in the new structs are getting flagged as unused.

type XfmrInterface

type XfmrInterface interface {
	// contains filtered or unexported methods
}

XfmrInterface is a validation interface for validating the callback registration of app modules transformer methods.

type XfmrParams

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

XfmrParams represents input parameters for table-transformer, key-transformer, field-transformer & subtree-transformer

func (XfmrParams) String

func (inPm XfmrParams) String() string

type XfmrSubscInParams

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

XfmrSubscInParams represents input to subscribe subtree callbacks - request uri, DBs info access-pointers, DB info for request uri and subscription process type from translib.

type XfmrSubscOutParams

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

XfmrSubscOutParams represents output from subscribe subtree callback - DB data for request uri, Need cache, OnChange, subscription preference and interval.

type XfmrSubscribePathXlateInfo

type XfmrSubscribePathXlateInfo struct {
	Path *gnmipb.Path // subscribe path

	DbKeyXlateInfo []*dbTableKeyInfo
	MinInterval    int // min interval
	NeedCache      bool
	PType          NotificationType
	OnChange       OnchangeMode
	TrgtNodeChld   bool // to indicate the immediate child level pathXlate info of the target node

	HandlerFunc      apis.ProcessOnChange // if its true, stop traversing the ygXpathNode's child nodes further
	IsDataSrcDynamic bool
	// contains filtered or unexported fields
}

type XfmrSubscribeReqXlateInfo

type XfmrSubscribeReqXlateInfo struct {
	TrgtPathInfo  *XfmrSubscribePathXlateInfo
	ChldPathsInfo []*XfmrSubscribePathXlateInfo
	// contains filtered or unexported fields
}

type XfmrTranslateSubscribeInfo

type XfmrTranslateSubscribeInfo struct {
	DbDataMap   RedisDbMap
	MinInterval int
	NeedCache   bool
	PType       NotificationType
	OnChange    bool
}

Jump to

Keyboard shortcuts

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