Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get origin from prefix #149

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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