From e06f342e913c4edbe9a902623c375d90ab47af15 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Thu, 19 Oct 2023 10:23:25 +0200 Subject: [PATCH] Use ygot.PathToString to create key for the pathAndValues map --- controller/nucleus/networkElementWatcher.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/controller/nucleus/networkElementWatcher.go b/controller/nucleus/networkElementWatcher.go index 672574d90..451f4ab4b 100644 --- a/controller/nucleus/networkElementWatcher.go +++ b/controller/nucleus/networkElementWatcher.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strconv" - "strings" "code.fbi.h-da.de/danet/gosdn/controller/customerrs" "code.fbi.h-da.de/danet/gosdn/controller/event" @@ -15,6 +14,7 @@ import ( "code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi" "github.com/google/uuid" gpb "github.com/openconfig/gnmi/proto/gnmi" + "github.com/openconfig/ygot/ygot" log "github.com/sirupsen/logrus" ) @@ -184,15 +184,22 @@ func (n *NetworkElementWatcher) handleSubscribeResponseUpdate(resp *gpb.Subscrib pathsAndValues := make(map[string]string, len(resp.Update.Update)) for _, update := range resp.Update.Update { - pathString := "" + //pathString := "" - // go through elem to build full path - for _, elem := range update.Path.Elem { - // remove unwanted parts of path string example: "name:\"system\"" -> "system" - filteredElem := elem.String()[strings.Index(elem.String(), ":\"")+2 : len(elem.String())-1] - pathString += filteredElem + "/" + pathString, err := ygot.PathToString(update.Path) + if err != nil { + log.Errorf("Error trying to create a string from path: %v", err) } + log.Info("Generated path string, used as key in pathAndValues map: ", pathString) + + //// go through elem to build full path + //for _, elem := range update.Path.Elem { + // // remove unwanted parts of path string example: "name:\"system\"" -> "system" + // filteredElem := elem.String()[strings.Index(elem.String(), ":\"")+2 : len(elem.String())-1] + // pathString += filteredElem + "/" + //} + pathsAndValues[pathString] = update.Val.GetStringVal() } -- GitLab