diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index e46979d9d9ac68a373f5b64f7c79b903228a1c4a..81a1a697d8cb37a86b1d349549e4ad901448d93e 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -177,9 +177,9 @@ func (s *server) GetAllPNDs(ctx context.Context, in *emptypb.Empty) (*pb.AllPNDs for uuidDevice, device := range pnd.(*pndImplementation).devices { tmpDevice := pb.Device{ Uuid: uuidDevice.String(), - Address: device.Config.Address, - Username: device.Config.Username, - Password: device.Config.Password} + Address: device.Transport.GetOptions().GetAddress(), + Username: device.Transport.GetOptions().GetUsername(), + Password: device.Transport.GetOptions().GetPassword()} devices = append(devices, &tmpDevice) } tmpPND := pb.PND{ @@ -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: "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() diff --git a/nucleus/device.go b/nucleus/device.go index 694a2d0004bd53e06f24b60197a54c1550b1cd57..95a104c46a877843047bfbc0236be3187856ad4e 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -1,20 +1,22 @@ package nucleus import ( + "errors" + "github.com/google/uuid" "github.com/openconfig/ygot/ygot" ) type Device struct { + // Uuid represents the Devices UUID + Uuid uuid.UUID + // Device inherits properties of ygot.GoStruct ygot.GoStruct // SBI is the device's southbound interface implementation SBI SouthboundInterface - // Config is the device's config. Under revision - Config DeviceConfig - // Transport is the device's Transport implementation Transport Transport } @@ -22,29 +24,19 @@ type Device struct { //NewDevice creates a Device func NewDevice(ttype string, sbi SouthboundInterface, opts TransportOptions) (*Device, error) { var transport Transport - //TODO: change to switch if supported transports increase - if ttype == "gnmi" { + switch ttype { + case "gnmi": transport = NewGnmiTransport(opts.(*gnmiTransportOptions)) - } else if ttype == "restconf" { + case "restconf": //TODO: implement restconf -> NewRestConfTransport(opts) + default: + return nil, errors.New("Unknown transport type.") + } return &Device{ - GoStruct: sbi.Schema().Root, - SBI: sbi, - //TODO: needed? maybe change to TransportOptions - Config: DeviceConfig{ - Uuid: uuid.New(), - Address: opts.GetAddress(), - Username: opts.GetUsername(), - Password: opts.GetPassword(), - }, + Uuid: uuid.New(), + GoStruct: sbi.Schema().Root, + SBI: sbi, Transport: transport, }, nil } - -type DeviceConfig struct { - Uuid uuid.UUID - Address string - Username string - Password string -} diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go index c55c8d0974cd0fa6bea390b9655b68e3f52316ff..7285b3f53bbf9a3c9a01027698df311516376562 100644 --- a/nucleus/gnmi_transport.go +++ b/nucleus/gnmi_transport.go @@ -15,11 +15,15 @@ import ( type Gnmi struct { SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error RespChan chan *gpb.SubscribeResponse + options *gnmiTransportOptions config *gnmi.Config } func NewGnmiTransport(opts *gnmiTransportOptions) *Gnmi { - ngt := &Gnmi{SetNode: opts.setNode} + ngt := &Gnmi{ + SetNode: opts.setNode, + options: opts, + } config := ngt.CreateConfig(opts) ngt.SetConfig(config) return ngt @@ -35,6 +39,16 @@ func (g *Gnmi) GetConfig() *gnmi.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 func (g *Gnmi) CreateConfig(opts *gnmiTransportOptions) *gnmi.Config { return &gnmi.Config{ diff --git a/nucleus/principalNetworkDomain.go b/nucleus/principalNetworkDomain.go index bc3307cb580aab6b99ea8a5b425d4d03d834a40d..5cb15f72d4657d34a1eddf3144d29c8acaca3194 100644 --- a/nucleus/principalNetworkDomain.go +++ b/nucleus/principalNetworkDomain.go @@ -110,7 +110,7 @@ func (pnd *pndImplementation) removeSbi(sbiIdentifier string) error { } func (pnd *pndImplementation) addDevice(device *Device) error { - pnd.devices[device.Config.Uuid] = device + pnd.devices[device.Uuid] = device return nil } diff --git a/nucleus/transport.go b/nucleus/transport.go index 814e750f137657943e7fc063d347bbcaaf891c49..ae5d676d44bb56310d75fb48d2696b6c7a3a1929 100644 --- a/nucleus/transport.go +++ b/nucleus/transport.go @@ -15,6 +15,7 @@ type Transport interface { Set(ctx context.Context, params ...string) (interface{}, error) Subscribe(ctx context.Context, params ...string) error Type() string + GetOptions() TransportOptions ProcessResponse(resp interface{}, root interface{}, models *ytypes.Schema) error }