[VOL-5535] uni port addition before nni-port fix for multi-nni

Change-Id: I49feeb7cf3812fbbeb4840c3b4d1c3505bdd5ff0
Signed-off-by: Akash Reddy Kankanala <akash.kankanala@radisys.com>
diff --git a/internal/pkg/application/application.go b/internal/pkg/application/application.go
index 9836cea..d424492 100644
--- a/internal/pkg/application/application.go
+++ b/internal/pkg/application/application.go
@@ -396,7 +396,7 @@
 }
 
 // pushFlowsForUnis to send port-up-indication for uni ports.
-func (d *VoltDevice) pushFlowsForUnis(cntx context.Context) {
+func (d *VoltDevice) pushFlowsForUnis(cntx context.Context, nniPort string) {
 	logger.Info(ctx, "NNI Discovered, Sending Port UP Ind for UNIs")
 	d.Ports.Range(func(key, value interface{}) bool {
 		port := key.(string)
@@ -416,7 +416,10 @@
 
 		for _, vpv := range vnets.([]*VoltPortVnet) {
 			vpv.VpvLock.Lock()
-			vpv.PortUpInd(cntx, d, port, "", false)
+			if ok, serviceNni := vpv.IsServiceActivated(cntx); ok && (nniPort == serviceNni) {
+				logger.Infow(cntx, "sending PortUpInd for Unis after nni discovery", log.Fields{"activeNni": serviceNni, "uniport": port})
+				vpv.PortUpInd(cntx, d, port, serviceNni, false)
+			}
 			vpv.VpvLock.Unlock()
 		}
 		return true
@@ -993,9 +996,11 @@
 		p := d.AddPort(portName, id)
 		va.PortsDisc.Store(portName, p)
 		va.portLock.Unlock()
-		nni, _ := va.GetNniPort(device)
-		if nni == portName {
-			d.pushFlowsForUnis(cntx)
+		for _, nniPort := range d.NniPort {
+			if nniPort == portName {
+				logger.Debugw(cntx, "NNI Port discovered. Triggering port up for UNIs", log.Fields{"Device": device, "PortName": portName, "NNIPort": nniPort})
+				d.pushFlowsForUnis(cntx, portName)
+			}
 		}
 	} else {
 		va.portLock.Unlock()
diff --git a/internal/pkg/application/application_test.go b/internal/pkg/application/application_test.go
index 7a3b314..d8a0366 100644
--- a/internal/pkg/application/application_test.go
+++ b/internal/pkg/application/application_test.go
@@ -1112,6 +1112,7 @@
 }
 
 func TestVoltDevice_pushFlowsForUnis(t *testing.T) {
+	NniPort := "nni-16777216"
 	type args struct {
 		cntx context.Context
 	}
@@ -1166,7 +1167,7 @@
 				voltPortVnets = append(voltPortVnets, voltPortVnet)
 				ga.VnetsByPort.Store("16777472", voltPortVnets)
 
-				d.pushFlowsForUnis(tt.args.cntx)
+				d.pushFlowsForUnis(tt.args.cntx, NniPort)
 			case "Negetive_Case_pushFlowsForUnis":
 				voltPort1 := &VoltPort{
 					Name:                     "16777472",
@@ -1177,7 +1178,7 @@
 					Type:                     VoltPortTypeNni,
 				}
 				d.Ports.Store("16777472", voltPort1)
-				d.pushFlowsForUnis(tt.args.cntx)
+				d.pushFlowsForUnis(tt.args.cntx, NniPort)
 			case "Negetive_Case1_pushFlowsForUnis":
 				voltPort2 := &VoltPort{
 					Name:                     "16777472",
@@ -1188,7 +1189,7 @@
 					Type:                     VoltPortTypeNni,
 				}
 				d.Ports.Store("1677747", voltPort2)
-				d.pushFlowsForUnis(tt.args.cntx)
+				d.pushFlowsForUnis(tt.args.cntx, NniPort)
 			}
 		})
 	}
diff --git a/internal/pkg/application/vnets.go b/internal/pkg/application/vnets.go
index 7b70315..734223d 100644
--- a/internal/pkg/application/vnets.go
+++ b/internal/pkg/application/vnets.go
@@ -757,7 +757,7 @@
 // changed. Thus, a reboot of ONT forces the new configuration to get
 // applied.
 func (vpv *VoltPortVnet) PortUpInd(cntx context.Context, device *VoltDevice, port string, nniPort string, skipFlowPushToVoltha bool) {
-	logger.Infow(ctx, "Port UP Ind, pushing flows for the port", log.Fields{"Device": device, "Port": port, "VnetDhcp": vpv.DhcpRelay, "McastService": vpv.McastService})
+	logger.Infow(ctx, "Port UP Ind, pushing flows for the port", log.Fields{"Device": device, "Port": port, "nniPort": nniPort, "VnetDhcp": vpv.DhcpRelay, "McastService": vpv.McastService})
 	if vpv.DeleteInProgress {
 		logger.Warnw(ctx, "Ignoring VPV Port UP Ind, VPV deletion In-Progress", log.Fields{"Device": device, "Port": port, "Vnet": vpv.VnetName})
 		return