Skip to content

Commit

Permalink
Get origin from prefix (#149)
Browse files Browse the repository at this point in the history
Why I did it
Follow GNMI spec to get origin from prefix.

How I did it
If prefix exists, get origin from prefix.

How to verify it
Run sonic-gnmi unit test.
  • Loading branch information
ganglyu authored Sep 6, 2023
1 parent 7a1b7cd commit 6fd461c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
23 changes: 16 additions & 7 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
}

target := ""
origin := ""
prefix := req.GetPrefix()
if prefix != nil {
target = prefix.GetTarget()
origin = prefix.Origin
}

paths := req.GetPath()
Expand All @@ -348,10 +350,11 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
} else if _, ok, _, _ := sdc.IsTargetDb(target); ok {
dc, err = sdc.NewDbClient(paths, prefix)
} else {
origin := ""
origin, err = ParseOrigin(paths)
if err != nil {
return nil, err
if origin == "" {
origin, err = ParseOrigin(paths)
if err != nil {
return nil, err
}
}
if check := IsNativeOrigin(origin); check {
dc, err = sdc.NewMixedDbClient(paths, prefix, origin, encoding, s.config.ZmqAddress)
Expand Down Expand Up @@ -407,6 +410,10 @@ func (s *Server) Set(ctx context.Context, req *gnmipb.SetRequest) (*gnmipb.SetRe

/* Fetch the prefix. */
prefix := req.GetPrefix()
origin := ""
if prefix != nil {
origin = prefix.Origin
}
extensions := req.GetExtension()
encoding := gnmipb.Encoding_JSON_IETF

Expand All @@ -418,9 +425,11 @@ func (s *Server) Set(ctx context.Context, req *gnmipb.SetRequest) (*gnmipb.SetRe
for _, path := range req.GetUpdate() {
paths = append(paths, path.GetPath())
}
origin, err := ParseOrigin(paths)
if err != nil {
return nil, err
if origin == "" {
origin, err = ParseOrigin(paths)
if err != nil {
return nil, err
}
}
if check := IsNativeOrigin(origin); check {
if s.config.EnableNativeWrite == false {
Expand Down
10 changes: 8 additions & 2 deletions sonic_data_client/mixed_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,14 @@ func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string,

// gnmiFullPath builds the full path from the prefix and path.
func (c *MixedDbClient) gnmiFullPath(prefix, path *gnmipb.Path) *gnmipb.Path {

fullPath := &gnmipb.Path{Origin: path.Origin}
origin := ""
if prefix != nil {
origin = prefix.Origin
}
if origin == "" {
origin = path.Origin
}
fullPath := &gnmipb.Path{Origin: origin}
if path.GetElement() != nil {
elements := path.GetElement()
if prefix != nil {
Expand Down

0 comments on commit 6fd461c

Please sign in to comment.