From 02228812d98aa7e3da387c2e3a5dfb090898dd7a Mon Sep 17 00:00:00 2001
From: Fabian Seidl <fabian.seidl@h-da.de>
Date: Thu, 2 Feb 2023 10:32:21 +0000
Subject: [PATCH] add missing option to retrieve pndID from MNE

---
 .../networkelement/networkElement.go          |  1 +
 controller/nucleus/networkElement.go          | 21 ++++++++++++++-----
 .../nucleus/networkElementService_test.go     |  2 +-
 controller/nucleus/networkElementWatcher.go   |  3 +--
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/controller/interfaces/networkelement/networkElement.go b/controller/interfaces/networkelement/networkElement.go
index 18b5b6b4b..f51d0e8a4 100644
--- a/controller/interfaces/networkelement/networkElement.go
+++ b/controller/interfaces/networkelement/networkElement.go
@@ -25,6 +25,7 @@ type NetworkElement interface {
 	GetModelAsString() (string, error)
 	TransportAddress() string
 	GetMetadata() conflict.Metadata
+	PndID() uuid.UUID
 }
 
 // Details contains details of a network element used by the cSBI mechanism.
diff --git a/controller/nucleus/networkElement.go b/controller/nucleus/networkElement.go
index 848260ae6..215714b78 100644
--- a/controller/nucleus/networkElement.go
+++ b/controller/nucleus/networkElement.go
@@ -66,6 +66,7 @@ func NewNetworkElement(
 				name:             name,
 				transportOptions: opt,
 				Metadata:         metadata,
+				pndID:            pndID,
 			},
 		}, nil
 	}
@@ -77,7 +78,7 @@ func NewNetworkElement(
 		transport:        t,
 		name:             name,
 		transportOptions: opt,
-		PndID:            pndID,
+		pndID:            pndID,
 		Metadata:         metadata,
 	}, nil
 }
@@ -104,7 +105,7 @@ type CommonNetworkElement struct {
 	Metadata conflict.Metadata
 
 	// ID of the PND this network element is associated with.
-	PndID uuid.UUID
+	pndID uuid.UUID
 }
 
 // ID returns the UUID of the Network Element.
@@ -176,6 +177,11 @@ func (n *CommonNetworkElement) GetMetadata() conflict.Metadata {
 	return n.Metadata
 }
 
+// PndID returns the ID of the associated PND.
+func (n *CommonNetworkElement) PndID() uuid.UUID {
+	return n.pndID
+}
+
 // CsbiNetworkElement is used for the cSBI functionality.
 type CsbiNetworkElement struct {
 	CommonNetworkElement
@@ -216,6 +222,11 @@ func (n *CsbiNetworkElement) GetMetadata() conflict.Metadata {
 	return n.Metadata
 }
 
+// PndID returns the ID of the associated PND.
+func (n *CsbiNetworkElement) PndID() uuid.UUID {
+	return n.pndID
+}
+
 // ProcessResponse processes a response for the Network Element.
 func (n *CsbiNetworkElement) ProcessResponse(resp proto.Message) error {
 	// TODO: callback to send response to caller
@@ -284,10 +295,10 @@ func (n *CommonNetworkElement) MarshalJSON() ([]byte, error) {
 
 	var pndUUID uuid.UUID
 
-	if n.PndID == uuid.Nil {
+	if n.pndID == uuid.Nil {
 		pndUUID = uuid.UUID{}
 	} else {
-		pndUUID = n.PndID
+		pndUUID = n.pndID
 	}
 
 	modelAsString, err := ygot.EmitJSON(n.Model, n.getYgotEmitJSONConfig())
@@ -371,7 +382,7 @@ func (n *CommonNetworkElement) MarshalBSON() ([]byte, error) {
 		TransportOptionType: transportOptionType,
 		SBI:                 n.sbi.ID().String(),
 		Model:               modelAsString,
-		PndID:               n.PndID.String(),
+		PndID:               n.pndID.String(),
 	})
 }
 
diff --git a/controller/nucleus/networkElementService_test.go b/controller/nucleus/networkElementService_test.go
index 771b33f59..49cc7e705 100644
--- a/controller/nucleus/networkElementService_test.go
+++ b/controller/nucleus/networkElementService_test.go
@@ -19,7 +19,7 @@ func getMockNetworkElement(mneID uuid.UUID, sbi southbound.SouthboundInterface)
 		Model:     sbi.Schema().Root,
 		sbi:       sbi,
 		transport: &mocks.Transport{},
-		PndID:     uuid.New(),
+		pndID:     uuid.New(),
 	}
 }
 
diff --git a/controller/nucleus/networkElementWatcher.go b/controller/nucleus/networkElementWatcher.go
index 19d12969a..eaed87fcb 100644
--- a/controller/nucleus/networkElementWatcher.go
+++ b/controller/nucleus/networkElementWatcher.go
@@ -91,8 +91,7 @@ func (n *NetworkElementWatcher) callSubscribe(stopContext context.Context, mne n
 	// SubscriptionInformation contains pnd ID, network element ID and name to be used in the internal subscribe to check
 	// from which network element a response was sent
 	if err := mne.Transport().ControlPlaneSubscribe(gNMIOptionsCtx, n.handleSubscribeResponse, &transport.SubscriptionInformation{
-		//TODO(PND): add pndID here, when adding pndID as reference to MNE!
-		//PndID:              pndID,
+		PndID:              mne.PndID().String(),
 		NetworkElementID:   mne.ID().String(),
 		NetworkElementName: mne.Name(),
 		StopContext:        stopContext,
-- 
GitLab