From 67b80b3b8cefb2fa8764b56814a2fa42fd99b36b Mon Sep 17 00:00:00 2001
From: Fabian Seidl <fabian.seidl@h-da.de>
Date: Fri, 5 Apr 2024 08:36:41 +0000
Subject: [PATCH] added missing parameters to route session

See merge request danet/quant!83
---
 ekms/handlers/danet/assignForwardingHandler.go   |  1 +
 ekms/handlers/danet/keyRoutingSessionsHandler.go | 14 ++++++++++++++
 ekms/handlers/danet/peerHandler.go               |  2 ++
 ekms/internal/kms/kms.go                         |  1 +
 4 files changed, 18 insertions(+)

diff --git a/ekms/handlers/danet/assignForwardingHandler.go b/ekms/handlers/danet/assignForwardingHandler.go
index 4817e421..bc0b1881 100644
--- a/ekms/handlers/danet/assignForwardingHandler.go
+++ b/ekms/handlers/danet/assignForwardingHandler.go
@@ -81,6 +81,7 @@ func (yh *AssignForwardingHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnmi
 		initKMS = &kms.RemoteKMS{
 			Id:      initiatingKmsAddress.GetNodeId(),
 			Address: initiatingKmsAddressString,
+			Port:    initiatingKmsAddress.GetPort(),
 		}
 	}
 
diff --git a/ekms/handlers/danet/keyRoutingSessionsHandler.go b/ekms/handlers/danet/keyRoutingSessionsHandler.go
index c73d8802..68073274 100644
--- a/ekms/handlers/danet/keyRoutingSessionsHandler.go
+++ b/ekms/handlers/danet/keyRoutingSessionsHandler.go
@@ -2,6 +2,7 @@ package danet
 
 import (
 	"fmt"
+	"strings"
 
 	"code.fbi.h-da.de/danet/quant/ekms/etsiqkdnclient"
 	"code.fbi.h-da.de/danet/quant/ekms/internal/kms"
@@ -119,6 +120,7 @@ func (yh *KeyRoutingSessionHandler) Update(c ygot.ValidatedGoStruct, jobs []*gnm
 			initKMS = &kms.RemoteKMS{
 				Id:      initiatingKmsAddress.GetNodeId(),
 				Address: initiatingKmsAddressString,
+				Port:    initiatingKmsAddress.GetPort(),
 			}
 		}
 
@@ -151,6 +153,18 @@ func updateOrCreateKeyRoutingSessions(confKMS *gnmitargetygot.Temp_KeyRoutingSes
 			confNextHop.Port = ygot.Uint16(route.Next.Address().AddrPort().Port())
 		}
 
+		if route.RemoteKMS != nil {
+			confTempRoutingSessionInitAddress := confTempRoutingSession.GetOrCreateInitiatingKmsAddress()
+			if route.RemoteKMS.Address != "" {
+				confTempRoutingSessionInitAddress.IpAddress = ygot.String(strings.Split(route.RemoteKMS.Address, ":")[0]) // TODO: maybe split address in remote kms and not in one string?
+				confTempRoutingSessionInitAddress.Port = ygot.Uint16(route.RemoteKMS.Port)
+				confTempRoutingSessionInitAddress.Hostname = ygot.String(strings.Split(route.RemoteKMS.Address, ":")[0]) // TODO: maybe split address in remote kms and not in one string?
+			}
+			if route.RemoteKMS.Id != "" {
+				confTempRoutingSessionInitAddress.NodeId = ygot.String(route.RemoteKMS.Id)
+			}
+		}
+
 		// TODO: add key properties
 		// confKeyProperties := confTempRoutingSession.GetOrCreateKeyProperties()
 
diff --git a/ekms/handlers/danet/peerHandler.go b/ekms/handlers/danet/peerHandler.go
index f0f17572..1a22e275 100644
--- a/ekms/handlers/danet/peerHandler.go
+++ b/ekms/handlers/danet/peerHandler.go
@@ -90,6 +90,8 @@ func updateOrCreatePeerTable(confKMS *gnmitargetygot.Temp_KmsPeerTable, ekmsClie
 
 		confTempPeerAddress.IpAddress = ygot.String(peer.Address().IP.String())
 		confTempPeerAddress.Port = ygot.Uint16(uint16(peer.Address().Port))
+		confTempPeerAddress.Hostname = ygot.String(peer.Address().String()) // TODO: get real hostname here
+		confTempPeerAddress.NodeId = ygot.String(peer.GetKmsPeerId().String())
 
 		// TODO: implement for kms, curently hardcoded
 		confInterKmsProtocol := confTempPeerInformation.GetOrCreateInterKmsProtocol()
diff --git a/ekms/internal/kms/kms.go b/ekms/internal/kms/kms.go
index c153679d..62f0937f 100644
--- a/ekms/internal/kms/kms.go
+++ b/ekms/internal/kms/kms.go
@@ -38,6 +38,7 @@ type Route struct {
 type RemoteKMS struct {
 	Id      string
 	Address string
+	Port    uint16
 }
 
 type BitKeyLength string
-- 
GitLab