Skip to content
Snippets Groups Projects
Commit 20c8e382 authored by Malte Bauch's avatar Malte Bauch
Browse files

removed DeviceConfig in Device

since the values from DeviceConfig are only needed in transport they got
moved into the device options. DeviceConfig is therefore redundant.
parent 447999c7
No related branches found
No related tags found
2 merge requests!116Resolve "Transport Tests",!90Develop
...@@ -177,9 +177,9 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs ...@@ -177,9 +177,9 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs
for uuidDevice, device := range pnd.(*pndImplementation).devices { for uuidDevice, device := range pnd.(*pndImplementation).devices {
tmpDevice := pb.Device{ tmpDevice := pb.Device{
Uuid: uuidDevice.String(), Uuid: uuidDevice.String(),
Address: device.Config.Address, Address: device.Transport.GetOptions().GetAddress(),
Username: device.Config.Username, Username: device.Transport.GetOptions().GetUsername(),
Password: device.Config.Password} Password: device.Transport.GetOptions().GetPassword()}
devices = append(devices, &tmpDevice) devices = append(devices, &tmpDevice)
} }
tmpPND := pb.PND{ tmpPND := pb.PND{
...@@ -231,7 +231,7 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad ...@@ -231,7 +231,7 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
return &pb.AddDeviceReply{Message: err.Error()}, err return &pb.AddDeviceReply{Message: err.Error()}, err
} }
return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Uuid.String()}, err
} }
//HandleDeviceGetRequest handles a GET request via pnd.Request() //HandleDeviceGetRequest handles a GET request via pnd.Request()
......
package nucleus package nucleus
import ( import (
"errors"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
) )
type Device struct { type Device struct {
// Uuid represents the Devices UUID
Uuid uuid.UUID
// Device inherits properties of ygot.GoStruct // Device inherits properties of ygot.GoStruct
ygot.GoStruct ygot.GoStruct
// SBI is the device's southbound interface implementation // SBI is the device's southbound interface implementation
SBI SouthboundInterface SBI SouthboundInterface
// Config is the device's config. Under revision
Config DeviceConfig
// Transport is the device's Transport implementation // Transport is the device's Transport implementation
Transport Transport Transport Transport
} }
...@@ -22,29 +24,19 @@ type Device struct { ...@@ -22,29 +24,19 @@ type Device struct {
//NewDevice creates a Device //NewDevice creates a Device
func NewDevice(ttype string, sbi SouthboundInterface, opts TransportOptions) (*Device, error) { func NewDevice(ttype string, sbi SouthboundInterface, opts TransportOptions) (*Device, error) {
var transport Transport var transport Transport
//TODO: change to switch if supported transports increase switch ttype {
if ttype == "gnmi" { case "gnmi":
transport = NewGnmiTransport(opts.(*gnmiTransportOptions)) transport = NewGnmiTransport(opts.(*gnmiTransportOptions))
} else if ttype == "restconf" { case "restconf":
//TODO: implement restconf -> NewRestConfTransport(opts) //TODO: implement restconf -> NewRestConfTransport(opts)
default:
return nil, errors.New("Unknown transport type.")
} }
return &Device{ return &Device{
GoStruct: sbi.Schema().Root, Uuid: uuid.New(),
SBI: sbi, GoStruct: sbi.Schema().Root,
//TODO: needed? maybe change to TransportOptions SBI: sbi,
Config: DeviceConfig{
Uuid: uuid.New(),
Address: opts.GetAddress(),
Username: opts.GetUsername(),
Password: opts.GetPassword(),
},
Transport: transport, Transport: transport,
}, nil }, nil
} }
type DeviceConfig struct {
Uuid uuid.UUID
Address string
Username string
Password string
}
...@@ -15,11 +15,15 @@ import ( ...@@ -15,11 +15,15 @@ import (
type Gnmi struct { type Gnmi struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
RespChan chan *gpb.SubscribeResponse RespChan chan *gpb.SubscribeResponse
options *gnmiTransportOptions
config *gnmi.Config config *gnmi.Config
} }
func NewGnmiTransport(opts *gnmiTransportOptions) *Gnmi { func NewGnmiTransport(opts *gnmiTransportOptions) *Gnmi {
ngt := &Gnmi{SetNode: opts.setNode} ngt := &Gnmi{
SetNode: opts.setNode,
options: opts,
}
config := ngt.CreateConfig(opts) config := ngt.CreateConfig(opts)
ngt.SetConfig(config) ngt.SetConfig(config)
return ngt return ngt
...@@ -35,6 +39,16 @@ func (g *Gnmi) GetConfig() *gnmi.Config { ...@@ -35,6 +39,16 @@ func (g *Gnmi) GetConfig() *gnmi.Config {
return g.config return g.config
} }
//SetConfig sets the config of gnmi
func (g *Gnmi) SetOptions(to TransportOptions) {
g.options = to.(*gnmiTransportOptions)
}
//GetConfig returns the gnmi config
func (g *Gnmi) GetOptions() TransportOptions {
return g.options
}
//CreateConfig creates a new gnmi config based on the given parameters //CreateConfig creates a new gnmi config based on the given parameters
func (g *Gnmi) CreateConfig(opts *gnmiTransportOptions) *gnmi.Config { func (g *Gnmi) CreateConfig(opts *gnmiTransportOptions) *gnmi.Config {
return &gnmi.Config{ return &gnmi.Config{
......
...@@ -110,7 +110,7 @@ func (pnd *pndImplementation) removeSbi(sbiIdentifier string) error { ...@@ -110,7 +110,7 @@ func (pnd *pndImplementation) removeSbi(sbiIdentifier string) error {
} }
func (pnd *pndImplementation) addDevice(device *Device) error { func (pnd *pndImplementation) addDevice(device *Device) error {
pnd.devices[device.Config.Uuid] = device pnd.devices[device.Uuid] = device
return nil return nil
} }
......
...@@ -15,6 +15,7 @@ type Transport interface { ...@@ -15,6 +15,7 @@ type Transport interface {
Set(ctx context.Context, params ...string) (interface{}, error) Set(ctx context.Context, params ...string) (interface{}, error)
Subscribe(ctx context.Context, params ...string) error Subscribe(ctx context.Context, params ...string) error
Type() string Type() string
GetOptions() TransportOptions
ProcessResponse(resp interface{}, root interface{}, models *ytypes.Schema) error ProcessResponse(resp interface{}, root interface{}, models *ytypes.Schema) error
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment