Newer
Older
"code.fbi.h-da.de/cocsn/gosdn/interfaces/device"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/southbound"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/transport"
"github.com/docker/docker/pkg/namesgenerator"
"github.com/google/uuid"
"github.com/openconfig/ygot/ygot"
// NewDevice creates a Device
func NewDevice(name string, opt *tpb.TransportOption, sbi southbound.SouthboundInterface) (device.Device, error) {
t, err := NewTransport(opt, sbi)
if err != nil {
return nil, err
}
if name == "" {
name = namesgenerator.GetRandomName(0)
}
root, err := ygot.DeepCopy(sbi.Schema().Root)
if err != nil {
return nil, err
}
if opt.Csbi {
return &CsbiDevice{
CommonDevice: CommonDevice{
UUID: uuid.New(),
sbi: sbi,
transport: t,
name: name,
},
}, nil
}
return &CommonDevice{
UUID: uuid.New(),
sbi: sbi,
transport: t,
name: name,
}, nil
// UUID represents the Devices UUID
UUID uuid.UUID
// Device embeds a ygot.GoStruct containing the device details
ygot.GoStruct
// SBI is the device's southbound interface implementation
// Transport is the device's Transport implementation
// Name is the device's human readable name
Manuel Kieweg
committed
}
// ID returns the UUID of the Device
func (d *CommonDevice) Model() ygot.GoStruct {
return d.GoStruct
}
func (d *CommonDevice) Transport() transport.Transport {
func (d *CommonDevice) Name() string {
return d.name
}
func (d *CommonDevice) SBI() southbound.SouthboundInterface {
func (d *CommonDevice) SetTransport(t transport.Transport) {
func (d *CommonDevice) SetName(n string) {
d.name = n
}
func (d *CommonDevice) SetSBI(sbi southbound.SouthboundInterface) {
func (d *CommonDevice) ProcessResponse(resp proto.Message) error {
return d.transport.ProcessResponse(resp, d.GoStruct, d.sbi.Schema())
}
CommonDevice
}
// ID returns the UUID of the Device
func (d *CsbiDevice) Model() ygot.GoStruct {
func (d *CsbiDevice) Transport() transport.Transport {
func (d *CsbiDevice) SBI() southbound.SouthboundInterface {
func (d *CsbiDevice) ProcessResponse(resp proto.Message) error {
return d.transport.ProcessResponse(resp, d.GoStruct, d.sbi.Schema())