Skip to content
Snippets Groups Projects
Commit 3f177fe3 authored by Sebastian Heiß's avatar Sebastian Heiß
Browse files

Fix event system so it reacts to topics user and mne

parent d50f431f
Branches
No related tags found
No related merge requests found
Pipeline #253614 failed
...@@ -5,17 +5,21 @@ import ( ...@@ -5,17 +5,21 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"strings"
"syscall" "syscall"
"time" "time"
"code.fbi.h-da.de/danet/gosdn/application-framework/event" "code.fbi.h-da.de/danet/gosdn/application-framework/event"
"code.fbi.h-da.de/danet/gosdn/application-framework/registration" "code.fbi.h-da.de/danet/gosdn/application-framework/registration"
"code.fbi.h-da.de/danet/gosdn/controller/api"
uuid "github.com/google/uuid"
//"code.fbi.h-da.de/danet/gosdn/csbi/cmd" //"code.fbi.h-da.de/danet/gosdn/csbi/cmd"
confManPb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/configurationmanagement" confManPb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/configurationmanagement"
pnd "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" pnd "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
topoPb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/topology" topoPb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/topology"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
clabconfig "code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/clab-config" clabconfig "code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/clab-config"
"code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/rtdt-auth" "code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/rtdt-auth"
util "code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/util" util "code.fbi.h-da.de/danet/gosdn/applications/rtdt-manager/util"
...@@ -174,6 +178,26 @@ func (r *RtdtManager) LaunchTwin(twinSubnetIPv4, twinSubnetIPv6, twinName string ...@@ -174,6 +178,26 @@ func (r *RtdtManager) LaunchTwin(twinSubnetIPv4, twinSubnetIPv6, twinName string
} }
// Now run deploy with new config file // Now run deploy with new config file
clabconfig.ClabDeploy(clabConfigFullPath) clabconfig.ClabDeploy(clabConfigFullPath)
// TODO For each switch in the topology, run mne create
for node, val := range r.clabData.Topology.Nodes {
if strings.HasPrefix(node, "gnmi-target-") {
fmt.Println("Found target: ", node)
opt := &tpb.TransportOption{
Address: val.MgmtIPv4,
Username: "admin",
Password: "admin",
TransportOption: &tpb.TransportOption_GnmiTransportOption{
GnmiTransportOption: &tpb.GnmiTransportOption{},
},
}
ctx := r.auth.CreateContextWithAuthorization()
mneUUID, _ := uuid.Parse("d1c269a2-6482-4010-b0d8-679dff73153b")
pid, _ := uuid.Parse(r.Pnd.GetId())
// addListResponse, err := api.AddNetworkElement(ctx, val.MgmtIPv4, node, nil, uuid, opt, r.Pnd.GetId(), []string{"/"})
api.AddNetworkElement(ctx, val.MgmtIPv4, node, "", opt, mneUUID, pid, []string{"/"})
}
}
return nil return nil
} }
...@@ -206,7 +230,7 @@ func (rMan *RtdtManager) manageConfig(op string) error { ...@@ -206,7 +230,7 @@ func (rMan *RtdtManager) manageConfig(op string) error {
func (rMan *RtdtManager) initEventSystem() error { func (rMan *RtdtManager) initEventSystem() error {
ctx := rMan.auth.CreateContextWithAuthorization() ctx := rMan.auth.CreateContextWithAuthorization()
queueCredentials, err := registration.Register(ctx, rMan.auth.GetURL(), "basic-interface-monitoring", "SecurePresharedToken") queueCredentials, err := registration.Register(ctx, rMan.auth.GetURL(), "basic-interface-monitoring", "SecurePresharedToken")
fmt.Println("Acquired queueCredentials: ", queueCredentials) fmt.Println("Acquired queueCredentials: ", queueCredentials)
// TODO: Find out how I can receive the ip address here (it returns rabbitmq) // TODO: Find out how I can receive the ip address here (it returns rabbitmq)
queueCredentials = "amqp://guest:guest@172.100.0.15:5672/" // fix by setting manually queueCredentials = "amqp://guest:guest@172.100.0.15:5672/" // fix by setting manually
if err != nil { if err != nil {
...@@ -226,14 +250,22 @@ func (rMan *RtdtManager) initEventSystem() error { ...@@ -226,14 +250,22 @@ func (rMan *RtdtManager) initEventSystem() error {
// Can have different callback per type per topic (e.g. adding mne or updating mne) // Can have different callback per type per topic (e.g. adding mne or updating mne)
eventServiceMNE.SubscribeToEventType([]event.TypeToCallbackTuple{ eventServiceMNE.SubscribeToEventType([]event.TypeToCallbackTuple{
{Type: event.Type(event.Update), Callback: rMan.updateMNECallback}, {Type: event.Type(event.Update), Callback: rMan.updateMNECallback},
{Type: event.Type(event.Add), Callback: rMan.updateMNECallback},
{Type: event.Type(event.Delete), Callback: rMan.updateMNECallback},
{Type: event.Type(event.Subscribe), Callback: rMan.updateMNECallback},
}) })
eventServiceUser.SubscribeToEventType([]event.TypeToCallbackTuple{ eventServiceUser.SubscribeToEventType([]event.TypeToCallbackTuple{
{Type: event.Type(event.User), Callback: rMan.userEventCallback}, {Type: event.Type(event.Update), Callback: rMan.userEventCallback},
{Type: event.Type(event.Add), Callback: rMan.userEventCallback},
{Type: event.Type(event.Delete), Callback: rMan.userEventCallback},
{Type: event.Type(event.Subscribe), Callback: rMan.userEventCallback},
}) })
// Now iterate over all topics of service and create goRoutines // Now iterate over all topics of service and create goRoutines
// that consumes queue // that consumes queue
// This function is supposed to be removed in the future? // This function is supposed to be removed in the future?
eventServiceMNE.SetupEventReciever(make(chan os.Signal, 1)) // doesn't seem to use stop channel internally.. eventServiceMNE.SetupEventReciever(make(chan os.Signal, 1)) // doesn't seem to use stop channel internally..
eventServiceUser.SetupEventReciever(make(chan os.Signal, 1)) // doesn't seem to use stop channel internally..
fmt.Println("Subscribed to events user and mne")
return nil return nil
} }
...@@ -253,6 +285,7 @@ func (rMan *RtdtManager) userEventCallback(event *event.Event) { ...@@ -253,6 +285,7 @@ func (rMan *RtdtManager) userEventCallback(event *event.Event) {
func (r RtdtManager) GetClabFilename() string { func (r RtdtManager) GetClabFilename() string {
return r.clabFilename return r.clabFilename
} }
func (r RtdtManager) GetClabTwinFilename() string { func (r RtdtManager) GetClabTwinFilename() string {
return r.clabTwinFilename return r.clabTwinFilename
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment