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

fixed building errors for telemetry.go and gnmi.go

parent 20c8e382
Branches
No related tags found
2 merge requests!116Resolve "Transport Tests",!90Develop
Pipeline #64663 passed with warnings
......@@ -5,7 +5,6 @@ import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"context"
"fmt"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
"os"
......@@ -18,32 +17,23 @@ func main() {
log.SetLevel(log.DebugLevel)
sbi := &nucleus.AristaOC{}
device := nucleus.Device{
GoStruct: sbi.Schema().Root,
SBI: sbi,
Config: nucleus.DeviceConfig{
Uuid: uuid.New(),
},
device, err := nucleus.NewDevice("gnmi", sbi,
&nucleus.GnmiTransportOptions{
Addr: "portainer.danet.fbi.h-da.de:6030",
Username: "admin",
Password: "arista",
SetNode: sbi.SetNode(),
RespChan: make(chan *gpb.SubscribeResponse),
Encoding: gpb.Encoding_JSON_IETF,
})
if err != nil {
log.Debug(err)
}
pnd := nucleus.NewPND("openconfig", "a simple openconfig PND", sbi)
if err := pnd.AddDevice(&device); err != nil {
if err := pnd.AddDevice(device); err != nil {
log.Fatal(err)
}
transport := &nucleus.Gnmi{
SetNode: sbi.SetNode(),
RespChan: make(chan *gpb.SubscribeResponse),
}
cfg := &gnmi.Config{
Addr: "portainer.danet.fbi.h-da.de:6030",
Username: "admin",
Password: "arista",
Encoding: gpb.Encoding_JSON_IETF,
}
transport.SetConfig(cfg)
device.Transport = transport
paths := []string{"/interfaces/interface/name"}
opts := &gnmi.SubscribeOptions{
......@@ -56,13 +46,13 @@ func main() {
HeartbeatInterval: uint64(time.Second.Nanoseconds()),
Paths: gnmi.SplitPaths(paths),
Origin: "",
Target: device.Config.Address,
Target: device.Transport.GetOptions().GetAddress(),
}
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGILL, syscall.SIGTERM)
ctx := context.WithValue(context.Background(), "opts", opts)
go func() {
if err := transport.Subscribe(ctx); err != nil {
if err := device.Transport.Subscribe(ctx); err != nil {
log.Fatal(err)
}
}()
......
package main
import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus"
)
......@@ -16,29 +14,22 @@ import (
func main() {
log.SetLevel(log.DebugLevel)
sbi := &nucleus.AristaOC{}
device := &nucleus.Device{
GoStruct: sbi.Schema().Root,
SBI: sbi,
Config: nucleus.DeviceConfig{
Uuid: uuid.New(),
},
device, err := nucleus.NewDevice("gnmi", sbi,
&nucleus.GnmiTransportOptions{
Addr: "portainer.danet.fbi.h-da.de:6030",
Username: "admin",
Password: "arista",
SetNode: sbi.SetNode(),
Encoding: gpb.Encoding_JSON_IETF,
})
if err != nil {
log.Debug(err)
}
pnd := nucleus.NewPND("openconfig", "test description", sbi)
if err := pnd.AddDevice(device); err != nil {
log.Fatal(err)
}
transport := &nucleus.Gnmi{SetNode: sbi.SetNode()}
cfg := &gnmi.Config{
Addr: "portainer.danet.fbi.h-da.de:6030",
Username: "admin",
Password: "arista",
Encoding: gpb.Encoding_JSON_IETF,
}
transport.SetConfig(cfg)
device.Transport = transport
p := []string{"/interfaces/interface[name=*]/state/name"}
errors := 0
for _, path := range p {
......
......@@ -218,8 +218,8 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad
}
sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"]
newDevice, err := NewDevice("gnmi", sbi, &gnmiTransportOptions{in.Device.Address, in.Device.Username,
in.Device.Password, sbi.SetNode(), gpb.Encoding_JSON_IETF})
newDevice, err := NewDevice("gnmi", sbi, &GnmiTransportOptions{in.Device.Address, in.Device.Username,
in.Device.Password, sbi.SetNode(), nil, gpb.Encoding_JSON_IETF})
if err != nil {
log.Info(err)
return &pb.AddDeviceReply{Message: err.Error()}, err
......
......@@ -26,7 +26,7 @@ func NewDevice(ttype string, sbi SouthboundInterface, opts TransportOptions) (*D
var transport Transport
switch ttype {
case "gnmi":
transport = NewGnmiTransport(opts.(*gnmiTransportOptions))
transport = NewGnmiTransport(opts.(*GnmiTransportOptions))
case "restconf":
//TODO: implement restconf -> NewRestConfTransport(opts)
default:
......
......@@ -15,14 +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
Options *GnmiTransportOptions
config *gnmi.Config
}
func NewGnmiTransport(opts *gnmiTransportOptions) *Gnmi {
func NewGnmiTransport(opts *GnmiTransportOptions) *Gnmi {
ngt := &Gnmi{
SetNode: opts.setNode,
options: opts,
SetNode: opts.SetNode,
RespChan: opts.RespChan,
Options: opts,
}
config := ngt.CreateConfig(opts)
ngt.SetConfig(config)
......@@ -41,21 +42,21 @@ func (g *Gnmi) GetConfig() *gnmi.Config {
//SetConfig sets the config of gnmi
func (g *Gnmi) SetOptions(to TransportOptions) {
g.options = to.(*gnmiTransportOptions)
g.Options = to.(*GnmiTransportOptions)
}
//GetConfig returns the gnmi config
func (g *Gnmi) GetOptions() TransportOptions {
return g.options
return g.Options
}
//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{
Addr: opts.addr,
Username: opts.username,
Password: opts.password,
Encoding: opts.encoding,
Addr: opts.Addr,
Username: opts.Username,
Password: opts.Password,
Encoding: opts.Encoding,
}
}
......@@ -206,24 +207,25 @@ func (g *Gnmi) Close() error {
return nil
}
type gnmiTransportOptions struct {
type GnmiTransportOptions struct {
// all needed gnmi transport parameters
addr string
username string
password string
setNode func(schema *yang.Entry, root interface{}, path *gpb.Path,
Addr string
Username string
Password string
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path,
val interface{}, opts ...ytypes.SetNodeOpt) error
encoding gpb.Encoding
RespChan chan *gpb.SubscribeResponse
Encoding gpb.Encoding
}
func (gto *gnmiTransportOptions) GetAddress() string {
return gto.addr
func (gto *GnmiTransportOptions) GetAddress() string {
return gto.Addr
}
func (gto *gnmiTransportOptions) GetUsername() string {
return gto.username
func (gto *GnmiTransportOptions) GetUsername() string {
return gto.Username
}
func (gto *gnmiTransportOptions) GetPassword() string {
return gto.password
func (gto *GnmiTransportOptions) GetPassword() string {
return gto.Password
}
func (gto *gnmiTransportOptions) IsTransportOption() {}
func (gto *GnmiTransportOptions) IsTransportOption() {}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment