client

package
v0.0.0-...-1510907 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package client provides a generic access layer for data available in system

Package client provides a generic access layer for data available in system

Index

Constants

View Source
const (
	DELETE  int = 0
	REPLACE int = 1
	UPDATE  int = 2
)
View Source
const (
	DbIdx    uint = iota // DB name is the first element (no. 0) in path slice.
	TblIdx               // Table name is the second element (no. 1) in path slice.
	KeyIdx               // Key name is the first element (no. 2) in path slice.
	FieldIdx             // Field name is the first element (no. 3) in path slice.
)

For virtual db path

View Source
const APPL_DB int = 0
View Source
const CHECK_POINT_PATH string = "/etc/sonic"
View Source
const DROPPED = "COUNTERS_EVENTS:missed_by_slow_receiver"
View Source
const EVENTD_PUBLISHER_SOURCE = "{\"sonic-events-eventd"
View Source
const EVENT_BUFFSZ = 4096
View Source
const HEARTBEAT_MAX = 600 // 10 mins
View Source
const LATENCY = "COUNTERS_EVENTS:latency_in_ms"
View Source
const LATENCY_LIST_SIZE = 10 // Size of list of latencies.
View Source
const MISSED = "COUNTERS_EVENTS:missed_internal"

STATS counters

View Source
const PARAM_HEARTBEAT = "heartbeat"

Path parameter

View Source
const PARAM_QSIZE = "qsize"
View Source
const PARAM_USE_CACHE = "usecache"
View Source
const PQ_DEF_SIZE = 10240 // Def size for pending events in PQ.
View Source
const PQ_MAX_SIZE = 102400 // Max size for pending events in PQ.
View Source
const PQ_MIN_SIZE = 1024 // Min size for pending events in PQ.
View Source
const REDIS_SOCK string = "/var/run/redis/redis.sock"
View Source
const STATS_FIELD_NAME = "value"
View Source
const SUBSCRIBER_TIMEOUT = (2 * 1000) // 2 seconds
View Source
const SWSS_TIMEOUT uint = 0
View Source
const (

	// SonicVersionFilePath is the path of build version YML file.
	SonicVersionFilePath = "/etc/sonic/sonic_version.yml"
)
View Source
const TEST_EVENT = "{\"sonic-host:device-test-event"

Variables

View Source
var (

	// ImplIoutilReadFile points to the implementation of ioutil.ReadFile. Should be overridden by UTs only.
	ImplIoutilReadFile func(string) ([]byte, error) = ioutil.ReadFile
)
View Source
var IntervalTicker = func(interval time.Duration) <-chan time.Time {
	return time.After(interval)
}

IntervalTicker is a factory method to implement interval ticking. Exposed for UT purposes.

View Source
var MinSampleInterval = time.Second

MinSampleInterval is the lowest sampling interval for streaming subscriptions. Any non-zero value that less than this threshold is considered invalid argument.

View Source
var NeedMock bool = false
View Source
var PyCodeForYang string = `` /* 343-byte string literal not displayed */
View Source
var STATS_ABSOLUTE_KEYS = [...]string{LATENCY}
View Source
var STATS_CUMULATIVE_KEYS = [...]string{MISSED, DROPPED}
View Source
var Target2RedisDb = make(map[string]map[string]*redis.Client)

redis client connected to each DB

View Source
var UseRedisLocalTcpPort bool = false

Let it be variable visible to other packages for now. May add an interface function for it.

Functions

func C_deinit_subs

func C_deinit_subs(h unsafe.Pointer)

func C_init_subs

func C_init_subs(use_cache bool) unsafe.Pointer

func ConvertDbEntry

func ConvertDbEntry(inputData map[string]interface{}) map[string]string

func DecodeJsonEntry

func DecodeJsonEntry(table map[string]interface{}, entryName string) (map[string]interface{}, error)

func DecodeJsonField

func DecodeJsonField(entry map[string]interface{}, fieldName string) (*string, []interface{}, error)

func DecodeJsonListItem

func DecodeJsonListItem(list []interface{}, index string) (*string, error)

func DecodeJsonTable

func DecodeJsonTable(database map[string]interface{}, tableName string) (map[string]interface{}, error)

func GetIntervalTicker

func GetIntervalTicker() func(interval time.Duration) <-chan time.Time

Define a new function to get the IntervalTicker variable

func GetRedisClientsForDb

func GetRedisClientsForDb(target string) map[string]*redis.Client

func GetTableKeySeparator

func GetTableKeySeparator(target string, ns string) (string, error)

func InvalidateVersionFileStash

func InvalidateVersionFileStash()

InvalidateVersionFileStash invalidates the cache that keeps version file content.

func IsTargetDb

func IsTargetDb(target string) (string, bool, string, bool)

This function get target present in GNMI Request and returns: 1. DbName (string) 2. Is DbName valid (bool)

  1. DbNamespace (string) 4. Is DbNamespace present in Target (bool)

func ParseTarget

func ParseTarget(target string, paths []*gnmipb.Path) (string, error)

func PollStats

func PollStats()

func RunPyCode

func RunPyCode(text string) error

func SetIntervalTicker

func SetIntervalTicker(f func(interval time.Duration) <-chan time.Time)

Define a new function to set the IntervalTicker variable

func Set_heartbeat

func Set_heartbeat(val int)

func ValToResp

func ValToResp(val Value) (*gnmipb.SubscribeResponse, error)

Convert from SONiC Value to its corresponding gNMI proto stream response type.

func WriteStatsToBuffer

func WriteStatsToBuffer(stat *linuxproc.Stat)

Types

type Client

type Client interface {
	// StreamRun will start watching service on data source
	// and enqueue data change to the priority queue.
	// It stops all activities upon receiving signal on stop channel
	// It should run as a go routine
	StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)
	// Poll will  start service to respond poll signal received on poll channel.
	// data read from data source will be enqueued on to the priority queue
	// The service will stop upon detection of poll channel closing.
	// It should run as a go routine
	PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)
	OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)
	// Get return data from the data source in format of *spb.Value
	Get(w *sync.WaitGroup) ([]*spb.Value, error)
	// Set data based on path and value
	Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
	// Capabilities of the switch
	Capabilities() []gnmipb.ModelData

	// Close provides implemenation for explicit cleanup of Client
	Close() error

	// callbacks on send failed
	FailedSend()

	// callback on sent
	SentOne(*Value)
}

Client defines a set of methods which every client must implement. This package provides one implmentation for now: the DbClient

func NewDbClient

func NewDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error)

func NewEventClient

func NewEventClient(paths []*gnmipb.Path, prefix *gnmipb.Path, logLevel int) (Client, error)

func NewMixedDbClient

func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string) (Client, error)

func NewNonDbClient

func NewNonDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error)

func NewTranslClient

func NewTranslClient(prefix *gnmipb.Path, getpaths []*gnmipb.Path, ctx context.Context, extensions []*gnmi_extpb.Extension, opts ...TranslClientOption) (Client, error)

type DbClient

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

func (*DbClient) Capabilities

func (c *DbClient) Capabilities() []gnmipb.ModelData

func (*DbClient) Close

func (c *DbClient) Close() error

TODO: Log data related to this session

func (*DbClient) FailedSend

func (c *DbClient) FailedSend()

func (*DbClient) Get

func (c *DbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)

func (*DbClient) OnceRun

func (c *DbClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*DbClient) PollRun

func (c *DbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*DbClient) SentOne

func (c *DbClient) SentOne(val *Value)

func (*DbClient) Set

func (c *DbClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*DbClient) StreamRun

func (c *DbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*DbClient) String

func (c *DbClient) String() string

String returns the target the client is querying.

type EventClient

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

func (*EventClient) Capabilities

func (evtc *EventClient) Capabilities() []gnmipb.ModelData

func (*EventClient) Close

func (evtc *EventClient) Close() error

func (*EventClient) FailedSend

func (c *EventClient) FailedSend()

func (*EventClient) Get

func (evtc *EventClient) Get(wg *sync.WaitGroup) ([]*spb.Value, error)

func (*EventClient) OnceRun

func (evtc *EventClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, wg *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*EventClient) PollRun

func (evtc *EventClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, wg *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*EventClient) SentOne

func (c *EventClient) SentOne(val *Value)

func (*EventClient) Set

func (evtc *EventClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*EventClient) StreamRun

func (evtc *EventClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, wg *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*EventClient) String

func (evtc *EventClient) String() string

String returns the target the client is querying.

type Evt_rcvd

type Evt_rcvd struct {
	Event_str        string
	Missed_cnt       uint32
	Publish_epoch_ms int64
}

func C_recv_evt

func C_recv_evt(h unsafe.Pointer) (int, Evt_rcvd)

type JsonClient

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

func NewJsonClient

func NewJsonClient(fileName string) (*JsonClient, error)

func (*JsonClient) Add

func (c *JsonClient) Add(path []string, value string) error

func (*JsonClient) Get

func (c *JsonClient) Get(path []string) ([]byte, error)

func (*JsonClient) Remove

func (c *JsonClient) Remove(path []string) error

type MixedDbClient

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

func (*MixedDbClient) Capabilities

func (c *MixedDbClient) Capabilities() []gnmipb.ModelData

func (*MixedDbClient) Close

func (c *MixedDbClient) Close() error

func (*MixedDbClient) ConvertToJsonPatch

func (c *MixedDbClient) ConvertToJsonPatch(prefix *gnmipb.Path, path *gnmipb.Path, t *gnmipb.TypedValue, output *string) error

Populate the JsonPatch corresponding each GNMI operation.

func (*MixedDbClient) DbDelTable

func (c *MixedDbClient) DbDelTable(table string, key string) error

func (*MixedDbClient) DbSetTable

func (c *MixedDbClient) DbSetTable(table string, key string, values map[string]string) error

func (*MixedDbClient) FailedSend

func (c *MixedDbClient) FailedSend()

func (*MixedDbClient) Get

func (c *MixedDbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)

func (*MixedDbClient) GetCheckPoint

func (c *MixedDbClient) GetCheckPoint() ([]*spb.Value, error)

func (*MixedDbClient) OnceRun

func (c *MixedDbClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*MixedDbClient) PollRun

func (c *MixedDbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*MixedDbClient) SentOne

func (c *MixedDbClient) SentOne(val *Value)

func (*MixedDbClient) Set

func (c *MixedDbClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*MixedDbClient) SetConfigDB

func (c *MixedDbClient) SetConfigDB(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*MixedDbClient) SetDB

func (c *MixedDbClient) SetDB(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*MixedDbClient) SetFullConfig

func (c *MixedDbClient) SetFullConfig(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*MixedDbClient) SetIncrementalConfig

func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*MixedDbClient) StreamRun

func (c *MixedDbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

type Node

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

Trie implmentation is adpated from https://github.com/derekparker/trie/blob/master/trie.go

func (Node) Children

func (n Node) Children() map[string]*Node

Returns the children of this node.

func (Node) Meta

func (n Node) Meta() interface{}

Returns the meta information of this node.

func (*Node) NewChild

func (n *Node) NewChild(val string, meta interface{}, term bool) *Node

Creates and returns a pointer to a new child for the node.

func (Node) Parent

func (n Node) Parent() *Node

Returns the parent of this node.

func (*Node) RemoveChild

func (n *Node) RemoveChild(r string)

func (Node) Val

func (n Node) Val() string

type NonDbClient

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

func (*NonDbClient) Capabilities

func (c *NonDbClient) Capabilities() []gnmipb.ModelData

func (*NonDbClient) Close

func (c *NonDbClient) Close() error

TODO: Log data related to this session

func (*NonDbClient) FailedSend

func (c *NonDbClient) FailedSend()

func (*NonDbClient) Get

func (c *NonDbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)

func (*NonDbClient) OnceRun

func (c *NonDbClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*NonDbClient) PollRun

func (c *NonDbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*NonDbClient) SentOne

func (c *NonDbClient) SentOne(val *Value)

func (*NonDbClient) Set

func (c *NonDbClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*NonDbClient) StreamRun

func (c *NonDbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

StreamRun implements stream subscription for non-DB queries. It supports SAMPLE mode only.

func (*NonDbClient) String

func (c *NonDbClient) String() string

String returns the target the client is querying.

type SonicVersionInfo

type SonicVersionInfo struct {
	BuildVersion string `yaml:"build_version" json:"build_version"`
	Error        string `json:"error"` // Applicable only when there is a failure while reading the file.
}

SonicVersionInfo is a data model to serialize '/etc/sonic/sonic_version.yml'

type Stream

type Stream interface {
	Send(m *gnmipb.SubscribeResponse) error
}

type TranslClient

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

func (*TranslClient) Capabilities

func (c *TranslClient) Capabilities() []gnmipb.ModelData

func (*TranslClient) Close

func (c *TranslClient) Close() error

func (*TranslClient) FailedSend

func (c *TranslClient) FailedSend()

func (*TranslClient) Get

func (c *TranslClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)

func (*TranslClient) OnceRun

func (c *TranslClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*TranslClient) PollRun

func (c *TranslClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

func (*TranslClient) SentOne

func (c *TranslClient) SentOne(val *Value)

func (*TranslClient) Set

func (c *TranslClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error

func (*TranslClient) StreamRun

func (c *TranslClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)

type TranslClientOption

type TranslClientOption interface {
	IsTranslClientOption()
}

type TranslWildcardOption

type TranslWildcardOption struct{}

func (TranslWildcardOption) IsTranslClientOption

func (t TranslWildcardOption) IsTranslClientOption()

type Trie

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

func NewTrie

func NewTrie() *Trie

Creates a new v2r Trie with an initialized root Node.

func (*Trie) Add

func (t *Trie) Add(keys []string, meta interface{}) *Node

Adds the key to the Trie, including meta data. Meta data is stored as `interface{}` and must be type cast by the caller.

func (*Trie) Find

func (t *Trie) Find(keys []string) (*Node, bool)

Finds and returns node associated with `key`.

func (*Trie) Remove

func (t *Trie) Remove(keys []string)

Removes a key from the trie

func (*Trie) Root

func (t *Trie) Root() *Node

Returns the root node for the Trie.

type Value

type Value struct {
	*spb.Value
}

func (Value) Compare

func (val Value) Compare(other queue.Item) int

Implement Compare method for priority queue

func (Value) GetTimestamp

func (val Value) GetTimestamp() int64

Jump to

Keyboard shortcuts

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