Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package csbi
import "github.com/openconfig/ygot/ygen"
var southboundStruct = ygen.GoStructCodeSnippet{
StructName: "Csbi",
StructDef: `type Csbi struct {
schema *ytypes.Schema
id uuid.UUID
}`,
Methods: `
// SetNode injects schema specific model representation to the transport.
// Needed for type assertion.
func (csbi *Csbi) SetNode(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error {
return ytypes.SetNode(schema, root.(*Device), path, val, opts...)
}
// Unmarshal injects schema specific model representation to the transport.
// Needed for type assertion.
func (csbi *Csbi) Unmarshal(bytes []byte, path *gpb.Path, goStruct ygot.ValidatedGoStruct, opt ...ytypes.UnmarshalOpt) error {
return unmarshal(csbi.Schema(), bytes, path, goStruct, opt...)
}
//unmarshal parses a gNMI response to a go struct.
func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygot.ValidatedGoStruct, opt ...ytypes.UnmarshalOpt) error {
defer func() {
if r := recover(); r != nil {
log.Error(r.(error))
}
}()
// Load SBI definition
root, err := ygot.DeepCopy(schema.Root)
if err != nil {
return err
}
validatedDeepCopy, ok := root.(ygot.ValidatedGoStruct)
if !ok {
return &errors.ErrInvalidTypeAssertion{}
}
// returns the node we want to fill with the data contained in 'bytes',
// using the specified 'path'.
createdNode, _, err := ytypes.GetOrCreateNode(schema.RootSchema(), validatedDeepCopy, path)
if err != nil {
return err
}
validatedCreatedNode, ok := createdNode.(ygot.ValidatedGoStruct)
if !ok {
return &errors.ErrInvalidTypeAssertion{}
}
if err := Unmarshal(bytes, validatedCreatedNode, opt...); err != nil {
return err
}
opts := []ygot.MergeOpt{&ygot.MergeOverwriteExistingFields{}}
return ygot.MergeStructInto(goStruct, validatedDeepCopy, opts...)
}
func (csbi *Csbi) Schema() *ytypes.Schema {
schema, err := Schema()
csbi.schema = schema
if err != nil {
log.Fatal(err)
}
return schema
}
func (csbi *Csbi) SchemaTreeGzip() []byte {
return ySchema
}
// SetID sets the ID of the cSBI to the provided UUID
func (csbi *Csbi) SetID(id uuid.UUID) {
csbi.id = id
}
// ID returns the Southbound's UUID
func (csbi *Csbi) ID() uuid.UUID {
return csbi.id
}
`,
}
const southboundStructCsbiAmendmend = `
// Type returns the Southbound's type
func (csbi *Csbi) Type() spb.Type {
return spb.Type_TYPE_CONTAINERISED
}
// Name returns the Name of the Southbound
func (csbi *Csbi) Name() string {
return "csbi"
}
`
const southboundStructPluginAmendmend = `
// Type returns the Southbound's type
func (csbi *Csbi) Type() spb.Type {
return spb.Type_TYPE_PLUGIN
}
// Name returns the Name of the Southbound
func (csbi *Csbi) Name() string {
return "plugin"
}
`
const southboundImportAmendmend = `
"code.fbi.h-da.de/danet/gosdn/controller/nucleus/errors"
spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
)
var PluginSymbol Csbi
`