Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Add Virtual Database Client + Unit Tests #18

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
43a8fcd
Add feature to support query for PFC watchdog
chaliu Sep 5, 2018
3908994
fix typos;rewrite log messeages; replace hard-coded : with database s…
chaliu Sep 5, 2018
cca4c30
replace hardcoded table separator |
chaliu Sep 6, 2018
750133e
Implement new virtual path for pfcwd
chaliu Sep 26, 2018
b2c6c5e
Unit tests for virtual database target SONiC, rename new_sonic_data_c…
randygaulmsft Mar 25, 2019
9ea0465
Merge branch 'master' into new-pfcwd
randygaulmsft Mar 26, 2019
0fcf9a5
remove testing directory imports
randygaulmsft Mar 26, 2019
f0e0fdb
silence unnecessary printfs
randygaulmsft Apr 10, 2019
bd4af90
remove more debug printf's
randygaulmsft Apr 10, 2019
da43c69
Attempt to fixup import paths and remove old unnecessary debug format…
randygaulmsft Apr 25, 2019
6dbe27c
Merge branch 'new-pfcwd' of https://github.com/randygaulmsft/sonic-te…
randygaulmsft Apr 25, 2019
d16da4c
get tests in a good state
randygaulmsft May 5, 2019
b414595
Got a basic subscribe test working.
randygaulmsft May 6, 2019
e29cfa5
Figured out way to subscribe to target SONiC_DB
randygaulmsft May 6, 2019
e597358
Wrapped up stream queries.
randygaulmsft May 7, 2019
90d4437
gofmt on all code under folder.
randygaulmsft May 15, 2019
ede7a94
Remove dead code (comments).
randygaulmsft May 15, 2019
f01f39c
SONiC_DB to SONIC_DB
randygaulmsft May 15, 2019
d33fca6
Removed dead code.
randygaulmsft May 17, 2019
9f94324
Remove more dead code.
randygaulmsft May 17, 2019
6f2b220
sdc to vdc (use correct path for setting TCP redis settings)
randygaulmsft May 17, 2019
53c0e70
Remove dead code from sonic_data_client.
randygaulmsft May 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
}

var target string
fmt.Printf("Subscribe Prefix: %v\n", target)
//fmt.Printf("Subscribe Prefix: %v\n", target)
prefix := c.subscribe.GetPrefix()
if prefix == nil {
return grpc.Errorf(codes.Unimplemented, "No target specified in prefix")
Expand Down
4 changes: 2 additions & 2 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"

sdc "test/sonic-telemetry-new-pfcwd/sonic_data_client"
vdc "test/sonic-telemetry-new-pfcwd/virtual_database_client"
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
vdc "github.com/Azure/sonic-telemetry/virtual_database_client"

gnmipb "github.com/openconfig/gnmi/proto/gnmi"
)
Expand Down
3 changes: 1 addition & 2 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import (

// Register supported client types.
spb "github.com/Azure/sonic-telemetry/proto"
//sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
sdc "test/sonic-telemetry-pfcwd/sonic_data_client"
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"

gclient "github.com/jipanyang/gnmi/client/gnmi"
)
Expand Down
80 changes: 40 additions & 40 deletions sonic_data_client/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
const (
// indentString represents the default indentation string used for
// JSON. Two spaces are used here.
indentString string = " "
Default_REDIS_UNIXSOCKET string = "/var/run/redis/redis.sock"
indentString string = " "
Default_REDIS_UNIXSOCKET string = "/var/run/redis/redis.sock"
Default_REDIS_LOCAL_TCP_PORT string = "localhost:6379"
)

Expand Down Expand Up @@ -60,19 +60,19 @@ var UseRedisLocalTcpPort bool = false
var Target2RedisDb = make(map[string]*redis.Client)

type tablePath struct {
dbName string
dbName string
tableName string
tableKey string
delimitor string
field string
field string
// path name to be used in json data which may be different
// from the real data path. Ex. in Counters table, real tableKey
// is oid:0x####, while key name like Ethernet## may be put
// in json data. They are to be filled in populateDbtablePath()
jsonTableName string
jsonTableKey string
jsonDelimitor string
jsonField string
jsonField string
}

type Value struct {
Expand All @@ -91,19 +91,19 @@ func (val Value) Compare(other queue.Item) int {
}

type DbClient struct {
prefix *gnmipb.Path
prefix *gnmipb.Path
pathG2S map[*gnmipb.Path][]tablePath

q *queue.PriorityQueue
randygaulmsft marked this conversation as resolved.
Show resolved Hide resolved
q *queue.PriorityQueue
channel chan struct{}

synced sync.WaitGroup // Control when to send gNMI sync_response
w *sync.WaitGroup // wait for all sub go routines to finish
mu sync.RWMutex // Mutex for data protection among routines for DbClient
w *sync.WaitGroup // wait for all sub go routines to finish
mu sync.RWMutex // Mutex for data protection among routines for DbClient

sendMsg int64
recvMsg int64
errors int64
errors int64
}

func NewDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error) {
Expand All @@ -115,11 +115,11 @@ func NewDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path) (Client, error) {
}

// TODO: Remove debug log
for _, _path := range paths {
fmt.Printf("single path: %v\n", _path)
}

fmt.Printf("prefix: %v\n", prefix)
//for _, _path := range paths {
// fmt.Printf("single path: %v\n", _path)
//}
//
//fmt.Printf("prefix: %v\n", prefix)

if prefix.GetTarget() == "COUNTERS_DB" {
err = initCountersPortNameMap()
Expand Down Expand Up @@ -187,7 +187,7 @@ func (c *DbClient) StreamRun(q *queue.PriorityQueue, stop chan struct{}, w *sync
// Inject sync message
c.q.Put(Value{
&spb.Value{
Timestamp: time.Now().UnixNano(),
Timestamp: time.Now().UnixNano(),
SyncResponse: true,
},
})
Expand Down Expand Up @@ -223,11 +223,11 @@ func (c *DbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.W
}

spbv := &spb.Value{
Prefix: c.prefix,
Path: gnmiPath,
Timestamp: time.Now().UnixNano(),
Prefix: c.prefix,
Path: gnmiPath,
Timestamp: time.Now().UnixNano(),
SyncResponse: false,
Val: val,
Val: val,
}

c.q.Put(Value{spbv})
Expand All @@ -236,7 +236,7 @@ func (c *DbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.W

c.q.Put(Value{
&spb.Value{
Timestamp: time.Now().UnixNano(),
Timestamp: time.Now().UnixNano(),
SyncResponse: true,
},
})
Expand All @@ -259,9 +259,9 @@ func (c *DbClient) Get(w *sync.WaitGroup) ([]*spb.Value, error) {

values = append(values, &spb.Value{
Prefix: c.prefix,
Path: gnmiPath,
Path: gnmiPath,
Timestamp: ts.UnixNano(),
Val: val,
Val: val,
})
}
log.V(6).Infof("Getting #%v", values)
Expand Down Expand Up @@ -334,10 +334,10 @@ func useRedisTcpClient() {
var redisDb *redis.Client
if UseRedisLocalTcpPort {
redisDb = redis.NewClient(&redis.Options{
Network: "tcp",
Addr: Default_REDIS_LOCAL_TCP_PORT,
Password: "", // no password set
DB: int(dbn),
Network: "tcp",
Addr: Default_REDIS_LOCAL_TCP_PORT,
Password: "", // no password set
DB: int(dbn),
DialTimeout: 0,
})
}
Expand All @@ -354,10 +354,10 @@ func init() {
var redisDb *redis.Client

redisDb = redis.NewClient(&redis.Options{
Network: "unix",
Addr: Default_REDIS_UNIXSOCKET,
Password: "", // no password set
DB: int(dbn),
Network: "unix",
Addr: Default_REDIS_UNIXSOCKET,
Password: "", // no password set
DB: int(dbn),
DialTimeout: 0,
})
Target2RedisDb[dbName] = redisDb
Expand Down Expand Up @@ -683,7 +683,7 @@ func enqueFatalMsg(c *DbClient, msg string) {
c.q.Put(Value{
&spb.Value{
Timestamp: time.Now().UnixNano(),
Fatal: msg,
Fatal: msg,
},
})
}
Expand Down Expand Up @@ -751,9 +751,9 @@ func dbFieldMultiSubscribe(gnmiPath *gnmipb.Path, c *DbClient) {

spbv := &spb.Value{
Prefix: c.prefix,
Path: gnmiPath,
Path: gnmiPath,
Timestamp: time.Now().UnixNano(),
Val: val,
Val: val,
}

if err = c.q.Put(Value{spbv}); err != nil {
Expand Down Expand Up @@ -810,7 +810,7 @@ func dbFieldSubscribe(gnmiPath *gnmipb.Path, c *DbClient) {
if newVal != val {
spbv := &spb.Value{
Prefix: c.prefix,
Path: gnmiPath,
Path: gnmiPath,
Timestamp: time.Now().UnixNano(),
Val: &gnmipb.TypedValue{
Value: &gnmipb.TypedValue_StringVal{
Expand All @@ -837,7 +837,7 @@ func dbFieldSubscribe(gnmiPath *gnmipb.Path, c *DbClient) {

type redisSubData struct {
tblPath tablePath
pubsub *redis.PubSub
pubsub *redis.PubSub
prefixLen int
}

Expand Down Expand Up @@ -985,9 +985,9 @@ func dbTableKeySubscribe(gnmiPath *gnmipb.Path, c *DbClient) {
var spbv *spb.Value
spbv = &spb.Value{
Prefix: c.prefix,
Path: gnmiPath,
Path: gnmiPath,
Timestamp: time.Now().UnixNano(),
Val: val,
Val: val,
}
if err = c.q.Put(Value{spbv}); err != nil {
log.V(1).Infof("Queue error: %v", err)
Expand Down Expand Up @@ -1017,9 +1017,9 @@ func dbTableKeySubscribe(gnmiPath *gnmipb.Path, c *DbClient) {
}
if val != nil {
spbv = &spb.Value{
Path: gnmiPath,
Path: gnmiPath,
Timestamp: time.Now().UnixNano(),
Val: val,
Val: val,
}

log.V(5).Infof("dbTableKeySubscribe enque: %v", spbv)
Expand Down