diff --git a/nucleus/controller.go b/nucleus/controller.go index e239bca0d3f6e3cc57d948ea8fffb3e10575ec4f..df9752387ef13a4dd73ec7439b1e879ed64b4f77 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 8d721e72eb03e0012d457a9a943a1ae08ddd5347..96a6dd9ee3bb3e4a66ff8377f259e44bb48bca1b 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 f496e67802955ad6fc30dc87f3befb605e89aa19..0f56e38c0c14f2fe12f78fa387e8862f4d8dfa53 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 1d82cacfaaadeb8d1d0356ad3d7399617b2bb10c..4950ef4956516e89e3f334169b6038542161f81f 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 cfab425227534cea87a8d1a139fec97c5e499e42..36dda96300e226ac74de3682d86885e20332191a 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