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
- Variables
- func C_deinit_subs(h unsafe.Pointer)
- func C_init_subs(use_cache bool) unsafe.Pointer
- func ConvertDbEntry(inputData map[string]interface{}) map[string]string
- func DecodeJsonEntry(table map[string]interface{}, entryName string) (map[string]interface{}, error)
- func DecodeJsonField(entry map[string]interface{}, fieldName string) (*string, []interface{}, error)
- func DecodeJsonListItem(list []interface{}, index string) (*string, error)
- func DecodeJsonTable(database map[string]interface{}, tableName string) (map[string]interface{}, error)
- func GetIntervalTicker() func(interval time.Duration) <-chan time.Time
- func GetRedisClientsForDb(target string) map[string]*redis.Client
- func GetTableKeySeparator(target string, ns string) (string, error)
- func InvalidateVersionFileStash()
- func IsTargetDb(target string) (string, bool, string, bool)
- func ParseTarget(target string, paths []*gnmipb.Path) (string, error)
- func PollStats()
- func RunPyCode(text string) error
- func SetIntervalTicker(f func(interval time.Duration) <-chan time.Time)
- func Set_heartbeat(val int)
- func ValToResp(val Value) (*gnmipb.SubscribeResponse, error)
- func WriteStatsToBuffer(stat *linuxproc.Stat)
- type Client
- func NewDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error)
- func NewEventClient(paths []*gnmipb.Path, prefix *gnmipb.Path, logLevel int) (Client, error)
- func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string) (Client, error)
- func NewNonDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error)
- func NewTranslClient(prefix *gnmipb.Path, getpaths []*gnmipb.Path, ctx context.Context, ...) (Client, error)
- type DbClient
- func (c *DbClient) Capabilities() []gnmipb.ModelData
- func (c *DbClient) Close() error
- func (c *DbClient) FailedSend()
- func (c *DbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)
- func (c *DbClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, ...)
- func (c *DbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, ...)
- func (c *DbClient) SentOne(val *Value)
- func (c *DbClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *DbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, ...)
- func (c *DbClient) String() string
- type EventClient
- func (evtc *EventClient) Capabilities() []gnmipb.ModelData
- func (evtc *EventClient) Close() error
- func (c *EventClient) FailedSend()
- func (evtc *EventClient) Get(wg *sync.WaitGroup) ([]*spb.Value, error)
- func (evtc *EventClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, wg *sync.WaitGroup, ...)
- func (evtc *EventClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, wg *sync.WaitGroup, ...)
- func (c *EventClient) SentOne(val *Value)
- func (evtc *EventClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (evtc *EventClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, wg *sync.WaitGroup, ...)
- func (evtc *EventClient) String() string
- type Evt_rcvd
- type JsonClient
- type MixedDbClient
- func (c *MixedDbClient) Capabilities() []gnmipb.ModelData
- func (c *MixedDbClient) Close() error
- func (c *MixedDbClient) ConvertToJsonPatch(prefix *gnmipb.Path, path *gnmipb.Path, t *gnmipb.TypedValue, output *string) error
- func (c *MixedDbClient) DbDelTable(table string, key string) error
- func (c *MixedDbClient) DbSetTable(table string, key string, values map[string]string) error
- func (c *MixedDbClient) FailedSend()
- func (c *MixedDbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)
- func (c *MixedDbClient) GetCheckPoint() ([]*spb.Value, error)
- func (c *MixedDbClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, ...)
- func (c *MixedDbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, ...)
- func (c *MixedDbClient) SentOne(val *Value)
- func (c *MixedDbClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *MixedDbClient) SetConfigDB(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *MixedDbClient) SetDB(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *MixedDbClient) SetFullConfig(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *MixedDbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, ...)
- type Node
- type NonDbClient
- func (c *NonDbClient) Capabilities() []gnmipb.ModelData
- func (c *NonDbClient) Close() error
- func (c *NonDbClient) FailedSend()
- func (c *NonDbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)
- func (c *NonDbClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, ...)
- func (c *NonDbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, ...)
- func (c *NonDbClient) SentOne(val *Value)
- func (c *NonDbClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *NonDbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, ...)
- func (c *NonDbClient) String() string
- type SonicVersionInfo
- type Stream
- type TranslClient
- func (c *TranslClient) Capabilities() []gnmipb.ModelData
- func (c *TranslClient) Close() error
- func (c *TranslClient) FailedSend()
- func (c *TranslClient) Get(w *sync.WaitGroup) ([]*spb.Value, error)
- func (c *TranslClient) OnceRun(q *queue.PriorityQueue, once chan struct{}, w *sync.WaitGroup, ...)
- func (c *TranslClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.WaitGroup, ...)
- func (c *TranslClient) SentOne(val *Value)
- func (c *TranslClient) Set(delete []*gnmipb.Path, replace []*gnmipb.Update, update []*gnmipb.Update) error
- func (c *TranslClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, ...)
- type TranslClientOption
- type TranslWildcardOption
- type Trie
- type Value
Constants ¶
const ( DELETE int = 0 REPLACE int = 1 UPDATE int = 2 )
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
const APPL_DB int = 0
const CHECK_POINT_PATH string = "/etc/sonic"
const DROPPED = "COUNTERS_EVENTS:missed_by_slow_receiver"
const EVENTD_PUBLISHER_SOURCE = "{\"sonic-events-eventd"
const EVENT_BUFFSZ = 4096
const HEARTBEAT_MAX = 600 // 10 mins
const LATENCY = "COUNTERS_EVENTS:latency_in_ms"
const LATENCY_LIST_SIZE = 10 // Size of list of latencies.
const MISSED = "COUNTERS_EVENTS:missed_internal"
STATS counters
const PARAM_HEARTBEAT = "heartbeat"
Path parameter
const PARAM_QSIZE = "qsize"
const PARAM_USE_CACHE = "usecache"
const PQ_DEF_SIZE = 10240 // Def size for pending events in PQ.
const PQ_MAX_SIZE = 102400 // Max size for pending events in PQ.
const PQ_MIN_SIZE = 1024 // Min size for pending events in PQ.
const REDIS_SOCK string = "/var/run/redis/redis.sock"
const STATS_FIELD_NAME = "value"
const SUBSCRIBER_TIMEOUT = (2 * 1000) // 2 seconds
const SWSS_TIMEOUT uint = 0
const (
// SonicVersionFilePath is the path of build version YML file.
SonicVersionFilePath = "/etc/sonic/sonic_version.yml"
)
const TEST_EVENT = "{\"sonic-host:device-test-event"
Variables ¶
var ( // ImplIoutilReadFile points to the implementation of ioutil.ReadFile. Should be overridden by UTs only. ImplIoutilReadFile func(string) ([]byte, error) = ioutil.ReadFile )
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.
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.
var NeedMock bool = false
var PyCodeForYang string = `` /* 343-byte string literal not displayed */
var STATS_ABSOLUTE_KEYS = [...]string{LATENCY}
var STATS_CUMULATIVE_KEYS = [...]string{MISSED, DROPPED}
redis client connected to each DB
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_init_subs ¶
func ConvertDbEntry ¶
func DecodeJsonEntry ¶
func DecodeJsonField ¶
func DecodeJsonListItem ¶
func DecodeJsonTable ¶
func GetIntervalTicker ¶
Define a new function to get the IntervalTicker variable
func InvalidateVersionFileStash ¶
func InvalidateVersionFileStash()
InvalidateVersionFileStash invalidates the cache that keeps version file content.
func IsTargetDb ¶
This function get target present in GNMI Request and returns: 1. DbName (string) 2. Is DbName valid (bool)
- DbNamespace (string) 4. Is DbNamespace present in Target (bool)
func SetIntervalTicker ¶
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 ¶
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 NewEventClient ¶
func NewMixedDbClient ¶
func NewNonDbClient ¶
func NewTranslClient ¶
type DbClient ¶
type DbClient struct {
// contains filtered or unexported fields
}
func (*DbClient) Capabilities ¶
func (*DbClient) FailedSend ¶
func (c *DbClient) FailedSend()
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) StreamRun ¶
func (c *DbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync.WaitGroup, subscribe *gnmipb.SubscriptionList)
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) 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) 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 JsonClient ¶
type JsonClient struct {
// contains filtered or unexported fields
}
func NewJsonClient ¶
func NewJsonClient(fileName string) (*JsonClient, 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 (*MixedDbClient) FailedSend ¶
func (c *MixedDbClient) FailedSend()
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) SetConfigDB ¶
func (*MixedDbClient) SetFullConfig ¶
func (*MixedDbClient) SetIncrementalConfig ¶
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) RemoveChild ¶
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) 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) 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) 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) 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()