Skip to content
Snippets Groups Projects
Commit 2d940250 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

some renaming, cleanup and linter pleasing

parent 1638b568
No related branches found
No related tags found
3 merge requests!376Add additional example application hostname-checker,!343Add basic application framework and example application to show interaction between events an NBI,!342Resolve "Add an option to send gNMI Subscribe requests via SBI"
Pipeline #108119 failed
...@@ -44,15 +44,15 @@ var coreOnce sync.Once ...@@ -44,15 +44,15 @@ var coreOnce sync.Once
// Core is the representation of the controller's core // Core is the representation of the controller's core
type Core struct { type Core struct {
pndStore networkdomain.PndStore pndStore networkdomain.PndStore
userService rbac.UserService userService rbac.UserService
roleService rbac.RoleService roleService rbac.RoleService
httpServer *http.Server httpServer *http.Server
grpcServer *grpc.Server grpcServer *grpc.Server
nbi *nbi.NorthboundInterface nbi *nbi.NorthboundInterface
eventService eventInterfaces.Service eventService eventInterfaces.Service
stopChan chan os.Signal stopChan chan os.Signal
subToDataPlaneComp *nucleus.SubToDataPlane deviceWatcher *nucleus.DeviceWatcher
csbiClient cpb.CsbiServiceClient csbiClient cpb.CsbiServiceClient
} }
...@@ -79,9 +79,9 @@ func initialize() error { ...@@ -79,9 +79,9 @@ func initialize() error {
stopChan: make(chan os.Signal, 1), stopChan: make(chan os.Signal, 1),
} }
c.subToDataPlaneComp = nucleus.NewSubToDataPlane(c.pndStore) c.deviceWatcher = nucleus.NewDeviceWatcher(c.pndStore)
//TODO: remove this call after testing! //TODO: remove this call after testing!
c.subToDataPlaneComp.SubToDevices() c.deviceWatcher.SubToDevices([][]string{{"system", "config", "hostname"}})
// Setting up signal capturing // Setting up signal capturing
signal.Notify(c.stopChan, os.Interrupt, syscall.SIGTERM) signal.Notify(c.stopChan, os.Interrupt, syscall.SIGTERM)
......
...@@ -21,5 +21,6 @@ type Transport interface { ...@@ -21,5 +21,6 @@ type Transport interface {
} }
type ( type (
// HandleSubscribeResponse is the callback function to handle subcription responses
HandleSubscribeResponse func(*gpb.SubscribeResponse) HandleSubscribeResponse func(*gpb.SubscribeResponse)
) )
...@@ -7,46 +7,58 @@ import ( ...@@ -7,46 +7,58 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/networkdomain"
"code.fbi.h-da.de/danet/gosdn/controller/nucleus/types" "code.fbi.h-da.de/danet/gosdn/controller/nucleus/types"
"code.fbi.h-da.de/danet/gosdn/controller/store"
"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi" gpb "github.com/openconfig/gnmi/proto/gnmi"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
//TODO: rename file and go struct! const (
subscribeSampleInterval uint64 = 1000000000 // 1 second in nanoseconds
// TODO: These gNMI options are adjusted to arista gNMI fork. Change when switching to native gNMI
gNMISubscribeMode string = "stream"
gNMIStreamMode string = "sample"
)
type SubToDataPlane struct { // DeviceWatcher is a component that subscribes to devices via gNMI from within the controller and handles
// responses by triggering the internal event process.
type DeviceWatcher struct {
pndStore networkdomain.PndStore pndStore networkdomain.PndStore
} }
func NewSubToDataPlane(pndStore networkdomain.PndStore) *SubToDataPlane { // NewDeviceWatcher takes a pndStore to subscribe to device paths.
return &SubToDataPlane{ func NewDeviceWatcher(pndStore networkdomain.PndStore) *DeviceWatcher {
return &DeviceWatcher{
pndStore: pndStore, pndStore: pndStore,
} }
} }
func (s *SubToDataPlane) SubToDevices() { // SubToDevices subscribes to every available device in each network domain with fixed gNMI subscription options (streaming in sample mode each second).
// Paths should be provided in the following format [][]string{{"system", "config", "hostname"}}
//TODO: make this configurable and move away from arista stuff?! func (d *DeviceWatcher) SubToDevices(paths [][]string) {
opts := &gnmi.SubscribeOptions{ opts := &gnmi.SubscribeOptions{
Mode: "stream", Mode: gNMISubscribeMode,
StreamMode: "sample", StreamMode: gNMIStreamMode,
Paths: [][]string{{"system", "config", "hostname"}}, Paths: paths,
SampleInterval: 1000000000, SampleInterval: subscribeSampleInterval,
} }
pnd, err := s.pndStore.Get(store.Query{ID: uuid.MustParse("5f20f34b-cbd0-4511-9ddc-c50cf6a3b49d")}) pnds, err := d.pndStore.GetAll()
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
for _, d := range pnd.Devices() { for _, pnd := range pnds {
go s.callSubscribe(d, opts) d.subscribeToPndDevices(pnd, opts)
}
}
func (d *DeviceWatcher) subscribeToPndDevices(pnd networkdomain.NetworkDomain, opts *gnmi.SubscribeOptions) {
for _, device := range pnd.Devices() {
go d.callSubscribe(device, opts)
} }
} }
func (s *SubToDataPlane) callSubscribe(device device.Device, opts *gnmi.SubscribeOptions) { func (d *DeviceWatcher) callSubscribe(device device.Device, opts *gnmi.SubscribeOptions) {
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, types.CtxKeyOpts, opts) ctx = context.WithValue(ctx, types.CtxKeyOpts, opts)
......
...@@ -202,6 +202,8 @@ func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error { ...@@ -202,6 +202,8 @@ func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error {
return g.subscribe(ctx) return g.subscribe(ctx)
} }
// SubscribeInternal is used to subscribe to devices from within the controller. gNMI SubscribeOptions need to be provided in the context,
// the callback function handles the responses received from the subscription.
func (g *Gnmi) SubscribeInternal(ctx context.Context, subscribeCallbackFunc tpInterface.HandleSubscribeResponse) error { func (g *Gnmi) SubscribeInternal(ctx context.Context, subscribeCallbackFunc tpInterface.HandleSubscribeResponse) error {
if g.client == nil { if g.client == nil {
return &errors.ErrNilClient{} return &errors.ErrNilClient{}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment