From bc9c93f9c9777e48f10f3c478c437ac018cd31bd Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Thu, 25 Mar 2021 17:44:13 +0100 Subject: [PATCH] lint error fixes (mainly commenting) --- nucleus/controller.go | 1 + nucleus/device.go | 5 ++++- nucleus/gnmi_transport.go | 30 +++++++++++++++++++++++------- nucleus/southbound.go | 3 +++ nucleus/transport.go | 2 ++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/nucleus/controller.go b/nucleus/controller.go index e239bca0d..df9752387 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -61,6 +61,7 @@ func createSouthboundInterfaces() error { return nil } +// Run calls initialize to start the controller func Run(ctx context.Context) error { if err := initialize(ctx); err != nil { log.WithFields(log.Fields{}).Error(err) diff --git a/nucleus/device.go b/nucleus/device.go index 8d721e72e..96a6dd9ee 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -5,6 +5,8 @@ import ( "github.com/openconfig/ygot/ygot" ) +// Device represents an Orchestrated Network Device (OND) which is managed by +// nucleus type Device struct { // Uuid represents the Devices UUID Uuid uuid.UUID @@ -19,7 +21,7 @@ type Device struct { Transport Transport } -//NewDevice creates a Device +// NewDevice creates a Device func NewDevice(sbi SouthboundInterface, opts TransportOptions) (*Device, error) { var transport Transport var err error @@ -41,6 +43,7 @@ func NewDevice(sbi SouthboundInterface, opts TransportOptions) (*Device, error) }, nil } +// Id returns the uuid of the Device func (d *Device) Id() uuid.UUID { return d.Uuid } diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go index f496e6780..0f56e38c0 100644 --- a/nucleus/gnmi_transport.go +++ b/nucleus/gnmi_transport.go @@ -19,6 +19,8 @@ type Gnmi struct { client gpb.GNMIClient } +// NewGnmiTransport takes a struct of GnmiTransportOptions and returns a Gnmi +// transport based on the values of it. func NewGnmiTransport(opts *GnmiTransportOptions) (*Gnmi, error) { c, err := gnmi.Dial(&opts.Config) if err != nil { @@ -37,18 +39,18 @@ func NewGnmiTransport(opts *GnmiTransportOptions) (*Gnmi, error) { }, nil } -//SetConfig sets the config of gnmi +//SetOptions sets Gnmi Options func (g *Gnmi) SetOptions(to TransportOptions) { g.Options = to.(*GnmiTransportOptions) } -//GetConfig returns the gnmi config +//GetOptions returns the Gnmi options func (g *Gnmi) GetOptions() interface{} { return g.Options } -// interface satisfaction for now -// TODO: Convert to meaningfiul calls +// Get takes a slice of gnmi paths, splits them and calls a GNMI get for +//each one of them. func (g *Gnmi) Get(ctx context.Context, params ...string) (interface{}, error) { if g.client == nil { return nil, &ErrNilClient{} @@ -107,6 +109,7 @@ func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error { return g.subscribe(ctx) } +// Type returns the gNMI transport type func (g *Gnmi) Type() string { return "gnmi" } @@ -238,6 +241,9 @@ func (g *Gnmi) Close() error { return nil } +// GnmiTransportOptions implements the TransportOptions interface. +// GnmiTransportOptions contains all needed information to setup a Gnmi +// Transport and therefore inherits gnmi.Config. type GnmiTransportOptions struct { // all needed gnmi transport parameters gnmi.Config @@ -248,14 +254,24 @@ type GnmiTransportOptions struct { RespChan chan *gpb.SubscribeResponse } +// GetAddress returns the address used by the transport to connect to a +// gRPC endpoint. func (gto *GnmiTransportOptions) GetAddress() string { - return gto.Addr + return gto.Config.Addr } + +// GetUsername returns the username used by the transport to connect to a +// gRPC endpoint. func (gto *GnmiTransportOptions) GetUsername() string { - return gto.Username + return gto.Config.Username } + +// GetPassword returns the password used by the transport to connect to a +// gRPC endpoint. func (gto *GnmiTransportOptions) GetPassword() string { - return gto.Password + return gto.Config.Password } +// IsTransportOption is needed to fulfill the requirements of the +// TransportOptions interface. It does not need any further implementation. func (gto *GnmiTransportOptions) IsTransportOption() {} diff --git a/nucleus/southbound.go b/nucleus/southbound.go index 1d82cacfa..4950ef495 100644 --- a/nucleus/southbound.go +++ b/nucleus/southbound.go @@ -26,6 +26,7 @@ type SouthboundInterface interface { Id() uuid.UUID } +// Tapi is the implementation of an TAPI SBI. type Tapi struct { } @@ -44,6 +45,7 @@ func (oc *OpenConfig) SbiIdentifier() string { return "openconfig" } +// Schema returns a ygot generated openconfig Schema as ytypes.Schema func (oc *OpenConfig) Schema() *ytypes.Schema { schema, err := openconfig.Schema() oc.schema = schema @@ -145,6 +147,7 @@ func iter(a ygot.GoStruct, fields []string) (b ygot.GoStruct, f string, err erro return } +// Id returns the Id of the OpenConfig SBI func (oc *OpenConfig) Id() uuid.UUID { return oc.id } diff --git a/nucleus/transport.go b/nucleus/transport.go index cfab42522..36dda9630 100644 --- a/nucleus/transport.go +++ b/nucleus/transport.go @@ -31,6 +31,8 @@ func (yc YANGConsumer) Consume(reader io.Reader, _ interface{}) error { return err } +// TransportOptions provides an interface for TransportOptions implementations +// for Transports like RESTCONF or gNMI type TransportOptions interface { GetAddress() string GetUsername() string -- GitLab