From 58bc4a9814b52daed0c2d9ba13cc711af45d44b6 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@extern.h-da.de> Date: Tue, 12 Jul 2022 18:28:18 +0200 Subject: [PATCH] Removed multiple calls of pnd.GetDevice for a NBI request of all devices --- controller/northbound/server/pnd.go | 36 ++++++++++++-------- controller/nucleus/principalNetworkDomain.go | 1 + 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/controller/northbound/server/pnd.go b/controller/northbound/server/pnd.go index 5124730e4..20133de7c 100644 --- a/controller/northbound/server/pnd.go +++ b/controller/northbound/server/pnd.go @@ -8,6 +8,7 @@ import ( ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound" + "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/metrics" "code.fbi.h-da.de/danet/gosdn/controller/nucleus" @@ -52,7 +53,13 @@ func (p PndServer) GetOnd(ctx context.Context, request *ppb.GetOndRequest) (*ppb return nil, status.Errorf(codes.Aborted, "%v", err) } - ond, err := fillOndBySpecificPath(pnd, request.Did, "/") + device, err := pnd.GetDevice(request.Did) + if err != nil { + log.Error(err) + return nil, status.Errorf(codes.Aborted, "%v", err) + } + + ond, err := fillOndBySpecificPath(pnd, device, "/") if err != nil { log.Error(err) return nil, status.Errorf(codes.Aborted, "%v", err) @@ -85,14 +92,15 @@ func (p PndServer) GetOndList(ctx context.Context, request *ppb.GetOndListReques return nil, status.Errorf(codes.Aborted, "%v", err) } - onds := make([]*ppb.OrchestratedNetworkingDevice, len(pnd.Devices())) - for i, ond := range pnd.Devices() { - ond, err := fillOndBySpecificPath(pnd, ond.ID().String(), "/") + onds := pnd.Devices() + ondsBySpecificPath := make([]*ppb.OrchestratedNetworkingDevice, len(onds)) + for i, ond := range onds { + ond, err := fillOndBySpecificPath(pnd, ond, "/") if err != nil { log.Error(err) return nil, status.Errorf(codes.Aborted, "%v", err) } - onds[i] = ond + ondsBySpecificPath[i] = ond } return &ppb.GetOndListResponse{ @@ -102,17 +110,11 @@ func (p PndServer) GetOndList(ctx context.Context, request *ppb.GetOndListReques Name: pnd.GetName(), Description: pnd.GetDescription(), }, - Ond: onds, + Ond: ondsBySpecificPath, }, nil } -func fillOndBySpecificPath(pnd networkdomain.NetworkDomain, did string, path string) (*ppb.OrchestratedNetworkingDevice, error) { - d, err := pnd.GetDevice(did) - if err != nil { - log.Error(err) - return nil, status.Errorf(codes.Aborted, "%v", err) - } - +func fillOndBySpecificPath(pnd networkdomain.NetworkDomain, d device.Device, path string) (*ppb.OrchestratedNetworkingDevice, error) { gnmiPath, err := ygot.StringToStructuredPath(path) if err != nil { log.Error(err) @@ -294,6 +296,12 @@ func (p PndServer) GetPath(ctx context.Context, request *ppb.GetPathRequest) (*p log.Error(err) return nil, status.Errorf(codes.Aborted, "%v", err) } + + device, err := pnd.GetDevice(request.Did) + if err != nil { + log.Error(err) + return nil, status.Errorf(codes.Aborted, "%v", err) + } duid, err := uuid.Parse(request.Did) if err != nil { log.Error(err) @@ -309,7 +317,7 @@ func (p PndServer) GetPath(ctx context.Context, request *ppb.GetPathRequest) (*p return nil, status.Errorf(codes.Aborted, "%v", err) } - ond, err := fillOndBySpecificPath(pnd, request.Did, path) + ond, err := fillOndBySpecificPath(pnd, device, path) if err != nil { log.Error(err) return nil, status.Errorf(codes.Aborted, "%v", err) diff --git a/controller/nucleus/principalNetworkDomain.go b/controller/nucleus/principalNetworkDomain.go index 21dff9696..ff14e327e 100644 --- a/controller/nucleus/principalNetworkDomain.go +++ b/controller/nucleus/principalNetworkDomain.go @@ -260,6 +260,7 @@ func (pnd *pndImplementation) AddDevice(name string, opt *tpb.TransportOption, s return pnd.addDevice(d) } +// TODO: (maba): This should be changed to UUID func (pnd *pndImplementation) GetDevice(identifier string) (device.Device, error) { id, err := uuid.Parse(identifier) if err != nil { -- GitLab