diff --git a/controller/nucleus/southbound.go b/controller/nucleus/southbound.go index 65b38433556139db1ac9454440cf2b05bcd5019b..18284c6d2ef76a0e56a29d711a98c96c211c67bf 100644 --- a/controller/nucleus/southbound.go +++ b/controller/nucleus/southbound.go @@ -2,6 +2,7 @@ package nucleus import ( "encoding/json" + "fmt" "path/filepath" "code.fbi.h-da.de/danet/gosdn/controller/customerrs" @@ -153,6 +154,27 @@ func generateEmptyValidatedStructs(schema *ytypes.Schema, path *gpb.Path) (ygot. return validatedDeepCopy, validatedCreatedNode, nil } +func removeReadOnlyFields(validatedGoStruct ygot.ValidatedGoStruct, emptyValidatedGoStruct ygot.ValidatedGoStruct, schema *ytypes.Schema) error { + diff, err := ygot.Diff(emptyValidatedGoStruct, validatedGoStruct) + if err != nil { + return err + } + filteredUpdates := make([]*gpb.Update, 0) + for _, u := range diff.Update { + 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) + } + } + + return nil +} + // unmarshal parses a gNMI response to a go struct. func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygot.GoStruct, opt ...ytypes.UnmarshalOpt) error { defer func() { @@ -161,20 +183,31 @@ func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygo } }() - validatedDeepCopy, emptyValidatedCreatedNode, err := generateEmptyValidatedStructs(schema, path) + ygot + validatedDeepCopy, validatedCreatedNode, err := generateEmptyValidatedStructs(schema, path) if err != nil { return err } - _, emptyValidatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path) + validatedDeepCopyForDiff, validatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path) if err != nil { return err } - if err := openconfig.Unmarshal(bytes, emptyValidatedCreatedNode, opt...); err != nil { + fmt.Println(validatedDeepCopyForDiff) + fmt.Println(validatedCreatedNodeForDiff) + + if err := openconfig.Unmarshal(bytes, validatedCreatedNode, opt...); err != nil { return err } + validatedCreatedNode. + + //err = removeReadOnlyFields(validatedCreatedNode, validatedCreatedNodeForDiff, schema) + //if err != nil { + // return err + //} + opts := []ygot.MergeOpt{&ygot.MergeOverwriteExistingFields{}} return ygot.MergeStructInto(goStruct, validatedDeepCopy, opts...) }