[VOL-5402]-VGC all fixes till date from jan 2024

Change-Id: I2857e0ef9b1829a28c6e3ad04da96b826cb900b6
Signed-off-by: Akash Soni <akash.soni@radisys.com>
diff --git a/internal/pkg/util/envutils/envutils.go b/internal/pkg/util/envutils/envutils.go
index 10a3219..8ef7149 100644
--- a/internal/pkg/util/envutils/envutils.go
+++ b/internal/pkg/util/envutils/envutils.go
@@ -87,14 +87,16 @@
 	MaxFlowRetryDuration      = "MAX_FLOW_RETRY_DURATION"
 	// openonu environment variables
 
-	OmciPacketCapture = "SAVE_OMCI_PACKET_CAPTURE"
+	OmciPacketCapture   = "SAVE_OMCI_PACKET_CAPTURE"
+	Undefined           = " undefined"
+	EnvironmentVariable = "Environment variable "
 )
 
 // ParseStringEnvVariable reads the environment variable and returns env as string
 func ParseStringEnvVariable(envVarName string, defaultVal string) string {
 	envValue := os.Getenv(envVarName)
 	if envValue == "" {
-		fmt.Println("Environment variable " + envVarName + " undefined")
+		fmt.Println(EnvironmentVariable + envVarName + Undefined)
 		return defaultVal
 	}
 	return envValue
@@ -104,7 +106,7 @@
 func ParseIntEnvVariable(envVarName string, defaultVal int64) int64 {
 	envValue := os.Getenv(envVarName)
 	if envValue == "" {
-		fmt.Println("Environment variable "+envVarName+" undefined", envVarName)
+		fmt.Println(EnvironmentVariable+envVarName+Undefined, envVarName)
 		return defaultVal
 	}
 	returnVal, err := strconv.Atoi(envValue)
@@ -119,7 +121,7 @@
 func ParseBoolEnvVariable(envVarName string, defaultVal bool) bool {
 	envValue := os.Getenv(envVarName)
 	if envValue == "" {
-		fmt.Println("Environment variable " + envVarName + " undefined")
+		fmt.Println(EnvironmentVariable + envVarName + Undefined)
 		return defaultVal
 	}
 	if envValue == "true" || envValue == "True" {
diff --git a/internal/pkg/util/utils.go b/internal/pkg/util/utils.go
index 6157413..36aab0b 100644
--- a/internal/pkg/util/utils.go
+++ b/internal/pkg/util/utils.go
@@ -18,6 +18,7 @@
 import (
 	"encoding/binary"
 	"net"
+	"strconv"
 	"strings"
 
 	"voltha-go-controller/internal/pkg/of"
@@ -132,6 +133,34 @@
 	return ipList
 }
 
+// GetUniFromMetadata returns uni port from write metadata of DS flows.
+func GetUniFromMetadata(metadata uint64) uint32 {
+	return uint32(metadata & 0xFFFFFFFF)
+}
+
+// GetUniFromDSDhcpFlow returns uni port from the flow cookie
+func GetUniFromDSDhcpFlow(cookie uint64) uint32 {
+	uniport := uint32(cookie >> 16)
+	uniport = uniport & 0xFFFFFFFF
+	return uniport
+}
+
+// GetUniPortFromFlow returns uni port from the flow data
+func GetUniPortFromFlow(nniPort string, flow *of.VoltSubFlow) uint32 {
+	var portNo uint32
+	if nniPort == strconv.Itoa(int(flow.Match.InPort)) {
+		if of.IPProtocolUDP == flow.Match.L4Protocol {
+			// For DHCP DS flow, uniport is not part of metadata. Hence retrieve it from cookie
+			portNo = GetUniFromDSDhcpFlow(flow.Cookie)
+		} else {
+			portNo = GetUniFromMetadata(flow.Action.Metadata)
+		}
+	} else {
+		portNo = flow.Match.InPort
+	}
+	return portNo
+}
+
 // MacAddrsMatch for comparison of MAC addresses and return true if MAC addresses matches
 func MacAddrsMatch(addr1 net.HardwareAddr, addr2 net.HardwareAddr) bool {
 	if len(addr1) != len(addr2) {