From cf6d28d6b857bedfd0c836db67c4060d3a16f66d Mon Sep 17 00:00:00 2001
From: Alejandro Tjaarda <alexdecb@yahoo.es>
Date: Fri, 20 Sep 2024 16:36:46 +0000
Subject: [PATCH] operator: added overlays CR functionalty

---
 .../internal/nedinterface/nedinterface.go     |  5 +++++
 .../internal/sdnclient/internal_client.go     |  2 +-
 src/kubernetes-api/internal/utils/utils.go    | 21 +++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 src/kubernetes-api/internal/nedinterface/nedinterface.go

diff --git a/src/kubernetes-api/internal/nedinterface/nedinterface.go b/src/kubernetes-api/internal/nedinterface/nedinterface.go
new file mode 100644
index 0000000..be1ba58
--- /dev/null
+++ b/src/kubernetes-api/internal/nedinterface/nedinterface.go
@@ -0,0 +1,5 @@
+package nedinterface
+
+func GetConnectionInfo() (string, string) {
+	return "", ""
+}
diff --git a/src/kubernetes-api/internal/sdnclient/internal_client.go b/src/kubernetes-api/internal/sdnclient/internal_client.go
index ae6e1dd..4feffcd 100644
--- a/src/kubernetes-api/internal/sdnclient/internal_client.go
+++ b/src/kubernetes-api/internal/sdnclient/internal_client.go
@@ -95,7 +95,7 @@ func (c *InternalClient) AttachPodToNetwork(networkType l2smv1.NetworkType, conf
 	if err != nil {
 		return err
 	}
-	response, err := c.Session.Post(fmt.Sprintf("%s/api/port", networkType), jsonData)
+	response, err := c.Session.Post(fmt.Sprintf("/%s/api/port", networkType), jsonData)
 	if err != nil {
 		return err
 	}
diff --git a/src/kubernetes-api/internal/utils/utils.go b/src/kubernetes-api/internal/utils/utils.go
index 566c801..11553e9 100644
--- a/src/kubernetes-api/internal/utils/utils.go
+++ b/src/kubernetes-api/internal/utils/utils.go
@@ -3,6 +3,7 @@ package utils
 import (
 	"bytes"
 	"crypto/sha1"
+	"crypto/sha256"
 	"encoding/hex"
 	"fmt"
 	"strings"
@@ -82,3 +83,23 @@ func GetPortNumberFromNetAttachDef(netAttachName string) (string, error) {
 
 	return portNumber, nil
 }
+
+// generateDatapathID generates a datapath ID from the switch name
+func GenerateDatapathID(switchName string) string {
+	// Create a new SHA256 hash object
+	hash := sha256.New()
+
+	// Write the switch name to the hash object
+	hash.Write([]byte(switchName))
+
+	// Get the hashed bytes
+	hashedBytes := hash.Sum(nil)
+
+	// Take the first 8 bytes of the hash to create a 64-bit ID
+	dpidBytes := hashedBytes[:8]
+
+	// Convert the bytes to a hexadecimal string
+	dpid := hex.EncodeToString(dpidBytes)
+
+	return dpid
+}
-- 
GitLab