Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
9281c78b
Commit
9281c78b
authored
3 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
attach unmarshal() to sbi struct
parent
c53b5391
No related branches found
No related tags found
1 merge request
!173
Process response overhaul
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nucleus/gnmi_transport.go
+0
-16
0 additions, 16 deletions
nucleus/gnmi_transport.go
nucleus/southbound.go
+21
-11
21 additions, 11 deletions
nucleus/southbound.go
with
21 additions
and
27 deletions
nucleus/gnmi_transport.go
+
0
−
16
View file @
9281c78b
...
@@ -3,7 +3,6 @@ package nucleus
...
@@ -3,7 +3,6 @@ package nucleus
import
(
import
(
"context"
"context"
"reflect"
"reflect"
"strings"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/southbound"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/southbound"
...
@@ -242,21 +241,6 @@ func (g *Gnmi) ProcessResponse(resp interface{}, root interface{}, s *ytypes.Sch
...
@@ -242,21 +241,6 @@ func (g *Gnmi) ProcessResponse(resp interface{}, root interface{}, s *ytypes.Sch
path
:=
update
.
Path
path
:=
update
.
Path
val
,
ok
:=
update
.
Val
.
Value
.
(
*
gpb
.
TypedValue_JsonVal
)
val
,
ok
:=
update
.
Val
.
Value
.
(
*
gpb
.
TypedValue_JsonVal
)
if
ok
{
if
ok
{
buf
:=
strings
.
Builder
{}
for
_
,
e
:=
range
path
.
Elem
{
key
:=
strings
.
Title
(
e
.
Name
)
buf
.
WriteString
(
key
)
buf
.
WriteString
(
"_"
)
}
filter
:=
buf
.
String
()
filter
=
strings
.
TrimSuffix
(
filter
,
"_"
)
keys
:=
make
([]
string
,
0
)
for
k
:=
range
models
{
if
strings
.
Contains
(
k
,
filter
)
{
keys
=
append
(
keys
,
k
)
}
}
//TODO: Fetch field by name
opts
:=
[]
ytypes
.
UnmarshalOpt
{
&
ytypes
.
IgnoreExtraFields
{}}
opts
:=
[]
ytypes
.
UnmarshalOpt
{
&
ytypes
.
IgnoreExtraFields
{}}
return
g
.
Unmarshal
(
val
.
JsonVal
,
pathutils
.
ToStrings
(
path
),
d
,
opts
...
)
return
g
.
Unmarshal
(
val
.
JsonVal
,
pathutils
.
ToStrings
(
path
),
d
,
opts
...
)
}
}
...
...
This diff is collapsed.
Click to expand it.
nucleus/southbound.go
+
21
−
11
View file @
9281c78b
package
nucleus
package
nucleus
import
(
import
(
"code.fbi.h-da.de/cocsn/gosdn/nucleus/errors"
"reflect"
"reflect"
spb
"code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
spb
"code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
...
@@ -67,11 +68,12 @@ func (oc *OpenConfig) SetNode() func(schema *yang.Entry, root interface{}, path
...
@@ -67,11 +68,12 @@ func (oc *OpenConfig) SetNode() func(schema *yang.Entry, root interface{}, path
// Unmarshal injects OpenConfig specific model representation to the transport.
// Unmarshal injects OpenConfig specific model representation to the transport.
// Needed for type assertion.
// Needed for type assertion.
func
(
oc
*
OpenConfig
)
Unmarshal
()
func
([]
byte
,
[]
string
,
ygot
.
ValidatedGoStruct
,
...
ytypes
.
UnmarshalOpt
)
error
{
func
(
oc
*
OpenConfig
)
Unmarshal
()
func
([]
byte
,
[]
string
,
ygot
.
ValidatedGoStruct
,
...
ytypes
.
UnmarshalOpt
)
error
{
return
unmarshal
return
oc
.
unmarshal
}
}
// unmarshal parses a root or 1st level gNMI response to a go struct
// unmarshal parses gNMI response to a go struct. If it's a root level response
func
unmarshal
(
bytes
[]
byte
,
fields
[]
string
,
goStruct
ygot
.
ValidatedGoStruct
,
opt
...
ytypes
.
UnmarshalOpt
)
error
{
// it uses
func
(
oc
*
OpenConfig
)
unmarshal
(
bytes
[]
byte
,
fields
[]
string
,
goStruct
ygot
.
ValidatedGoStruct
,
opt
...
ytypes
.
UnmarshalOpt
)
error
{
defer
func
()
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
if
r
:=
recover
();
r
!=
nil
{
log
.
Error
(
r
.
(
error
))
log
.
Error
(
r
.
(
error
))
...
@@ -85,22 +87,29 @@ func unmarshal(bytes []byte, fields []string, goStruct ygot.ValidatedGoStruct, o
...
@@ -85,22 +87,29 @@ func unmarshal(bytes []byte, fields []string, goStruct ygot.ValidatedGoStruct, o
var
c
ygot
.
ValidatedGoStruct
var
c
ygot
.
ValidatedGoStruct
// Load SBI definition
// Load SBI definition
d
:=
openconfig
.
Device
{}
root
,
err
:=
ygot
.
DeepCopy
(
oc
.
schema
.
Root
)
ygot
.
BuildEmptyTree
(
&
d
)
if
err
!=
nil
{
c
=
getField
(
&
d
,
fields
)
return
err
}
d
,
ok
:=
root
.
(
ygot
.
ValidatedGoStruct
)
if
!
ok
{
return
&
errors
.
ErrInvalidTypeAssertion
{}
}
ygot
.
BuildEmptyTree
(
d
)
c
=
getField
(
d
,
fields
)
if
err
:=
openconfig
.
Unmarshal
(
bytes
,
c
,
opt
...
);
err
!=
nil
{
if
err
:=
openconfig
.
Unmarshal
(
bytes
,
c
,
opt
...
);
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
ygot
.
MergeStructInto
(
goStruct
,
&
d
);
err
!=
nil
{
ygot
.
PruneEmptyBranches
(
d
)
if
err
:=
ygot
.
MergeStructInto
(
goStruct
,
d
);
err
!=
nil
{
return
err
return
err
}
}
return
nil
return
nil
}
}
// iter walks down the provided paths and initializes the ygot.GoStruct. It only works for
// getField traverses the GoStruct and returns the field that represents the
// the root level.
// tail of the path
// TODO(mk): Fix deeper layers
func
getField
(
inStruct
ygot
.
ValidatedGoStruct
,
fields
[]
string
)
ygot
.
ValidatedGoStruct
{
func
getField
(
inStruct
ygot
.
ValidatedGoStruct
,
fields
[]
string
)
ygot
.
ValidatedGoStruct
{
defer
func
()
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
if
r
:=
recover
();
r
!=
nil
{
...
@@ -145,7 +154,8 @@ func (csbi *Csbi) SetNode() func(schema *yang.Entry, root interface{}, path *gpb
...
@@ -145,7 +154,8 @@ func (csbi *Csbi) SetNode() func(schema *yang.Entry, root interface{}, path *gpb
// Unmarshal injects OpenConfig specific model representation to the transport.
// Unmarshal injects OpenConfig specific model representation to the transport.
// Needed for type assertion.
// Needed for type assertion.
func
(
csbi
*
Csbi
)
Unmarshal
()
func
([]
byte
,
[]
string
,
ygot
.
ValidatedGoStruct
,
...
ytypes
.
UnmarshalOpt
)
error
{
func
(
csbi
*
Csbi
)
Unmarshal
()
func
([]
byte
,
[]
string
,
ygot
.
ValidatedGoStruct
,
...
ytypes
.
UnmarshalOpt
)
error
{
return
unmarshal
oc
:=
OpenConfig
{}
return
oc
.
unmarshal
}
}
// Schema is holding the default OpenConfig schema for minimal compatibility
// Schema is holding the default OpenConfig schema for minimal compatibility
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment