diff --git a/controller/nucleus/gnmi_transport.go b/controller/nucleus/gnmi_transport.go index eb1ea0e2409808f3a169a62b58ddd292d5b1c3ee..832a19612d8d6c2e6af48ba4f98f6a2f9805e5a6 100644 --- a/controller/nucleus/gnmi_transport.go +++ b/controller/nucleus/gnmi_transport.go @@ -16,7 +16,6 @@ import ( "code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi" gpb "github.com/openconfig/gnmi/proto/gnmi" "github.com/openconfig/goyang/pkg/yang" - "github.com/openconfig/ygot/util" "github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ytypes" log "github.com/sirupsen/logrus" @@ -123,41 +122,25 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb. return customerrs.NoNewChangesError{Original: payload.Original, Modified: payload.Modified} } - var json []byte if op := ctx.Value(types.CtxKeyOperation); op == ppb.ApiOperation_API_OPERATION_UPDATE || op == ppb.ApiOperation_API_OPERATION_REPLACE { - rootCopy, err := ygot.DeepCopy(schema.Root) - if err != nil { - return err - } + filteredUpdates := make([]*gpb.Update, 0) for _, u := range diff.Update { - opts := []ytypes.SetNodeOpt{&ytypes.InitMissingElements{}, &ytypes.TolerateJSONInconsistencies{}} - if err := g.SetNode(schema.RootSchema(), rootCopy, u.GetPath(), u.GetVal(), opts...); err != nil { + rootSchema := schema.RootSchema() + pathString, err := ygot.PathToString(u.GetPath()) + if err != nil { return err } + entry := rootSchema.Find(pathString) + if !entry.ReadOnly() { + filteredUpdates = append(filteredUpdates, u) + } } - ygot.PruneEmptyBranches(rootCopy) - - opts := []ytypes.GetNodeOpt{ - &ytypes.GetHandleWildcards{}, - } - nodes, err := ytypes.GetNode(schema.RootSchema(), rootCopy, path, opts...) - if err != nil { - return err - } - - if len(nodes) == 0 || err != nil || util.IsValueNil(nodes[0].Data) { - return customerrs.PathNotFoundError{Path: path, Err: err} - } - - json, err = ygot.Marshal7951(nodes[0].Data, &ygot.RFC7951JSONConfig{AppendModuleName: true}) - if err != nil { - return err - } + diff.Update = filteredUpdates } - req, err := createSetRequest(ctx, diff, json, path) + req, err := createSetRequest(ctx, diff) if err != nil { return err } @@ -167,25 +150,15 @@ func (g *Gnmi) applyDiff(ctx context.Context, payload change.Payload, path *gpb. return err } -func createSetRequest(ctx context.Context, diff *gpb.Notification, json []byte, path *gpb.Path) (*gpb.SetRequest, error) { +func createSetRequest(ctx context.Context, diff *gpb.Notification) (*gpb.SetRequest, error) { op := ctx.Value(types.CtxKeyOperation) req := &gpb.SetRequest{} if diff.Update != nil { switch op { case ppb.ApiOperation_API_OPERATION_UPDATE: - req.Update = []*gpb.Update{{ - Path: path, - Val: &gpb.TypedValue{ - Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: json}, - }, - }} + req.Update = diff.Update case ppb.ApiOperation_API_OPERATION_REPLACE: - req.Replace = []*gpb.Update{{ - Path: path, - Val: &gpb.TypedValue{ - Value: &gpb.TypedValue_JsonIetfVal{JsonIetfVal: json}, - }, - }} + req.Replace = diff.Update default: return nil, &customerrs.OperationNotSupportedError{Op: op} } diff --git a/controller/nucleus/principalNetworkDomain.go b/controller/nucleus/principalNetworkDomain.go index 944278f71b95c7902858d5bcdcc102c499f507fe..b0de0211db8c7fbd1d2bcf2108d7581ba53dfc8f 100644 --- a/controller/nucleus/principalNetworkDomain.go +++ b/controller/nucleus/principalNetworkDomain.go @@ -354,7 +354,7 @@ func (pnd *pndImplementation) addNetworkElement(mne networkelement.NetworkElemen } if mne.IsTransportValid() { - _, err = pnd.Request(mne.ID(), "/interfaces") + _, err = pnd.Request(mne.ID(), "/") if err != nil { return uuid.Nil, err }