[VOL-4518] remove flowKey and use only flowID for OLT and ONU flow cache since flowID's are unique

Change-Id: I5c9d698ad32d65baf843e7bf1c75ed8e8998261e
diff --git a/VERSION b/VERSION
index 81c871d..4dae298 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.10.0
+1.10.1
diff --git a/internal/bbsim/api/onus_handler.go b/internal/bbsim/api/onus_handler.go
index 2638bf5..e5228cb 100644
--- a/internal/bbsim/api/onus_handler.go
+++ b/internal/bbsim/api/onus_handler.go
@@ -578,7 +578,7 @@
 	res := &bbsim.Flows{}
 
 	if req.SerialNumber == "" {
-		olt.Flows.Range(func(flowKey, flow interface{}) bool {
+		olt.Flows.Range(func(flowId, flow interface{}) bool {
 			flowObj := flow.(openolt.Flow)
 			res.Flows = append(res.Flows, &flowObj)
 			return true
@@ -592,12 +592,12 @@
 			}).Error("Can't get ONU in GetFlows request")
 			return nil, err
 		}
-		for _, flowKey := range onu.Flows {
-			flow, _ := olt.Flows.Load(flowKey)
+		for _, flowId := range onu.FlowIds {
+			flow, _ := olt.Flows.Load(flowId)
 			flowObj := flow.(openolt.Flow)
 			res.Flows = append(res.Flows, &flowObj)
 		}
-		res.FlowCount = uint32(len(onu.Flows))
+		res.FlowCount = uint32(len(onu.FlowIds))
 	}
 	return res, nil
 }
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index 8520bf2..931bd6d 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -1032,10 +1032,8 @@
 		"PortNo":    flow.PortNo,
 	}).Tracef("OLT receives FlowAdd")
 
-	flowKey := FlowKey{}
 	if !o.enablePerf {
-		flowKey = FlowKey{ID: flow.FlowId, Direction: flow.FlowType}
-		olt.Flows.Store(flowKey, *flow)
+		o.Flows.Store(flow.FlowId, *flow)
 	}
 
 	if flow.AccessIntfId == -1 {
@@ -1094,9 +1092,8 @@
 		}
 
 		if !o.enablePerf {
-			onu.Flows = append(onu.Flows, flowKey)
 			// Generate event on first flow for ONU
-			if len(onu.Flows) == 1 {
+			if len(onu.FlowIds) == 0 {
 				publishEvent("Flow-add-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn())
 			}
 		}
@@ -1151,13 +1148,8 @@
 	olt.freeAllocId(flow)
 
 	if !o.enablePerf { // remove only if flow were stored
-		flowKey := FlowKey{
-			ID:        flow.FlowId,
-			Direction: flow.FlowType,
-		}
-
 		// Check if flow exists
-		storedFlowIntf, ok := o.Flows.Load(flowKey)
+		storedFlowIntf, ok := o.Flows.Load(flow.FlowId)
 		if !ok {
 			oltLogger.Errorf("Flow %v not found", flow)
 			return new(openolt.Empty), status.Errorf(codes.NotFound, "Flow not found")
@@ -1186,12 +1178,11 @@
 				}).Error("ONU-not-found")
 				return new(openolt.Empty), nil
 			}
-			onu.DeleteFlow(flowKey)
 			publishEvent("Flow-remove-received", int32(onu.PonPortID), int32(onu.ID), onu.Sn())
 		}
 
 		// delete from olt flows
-		o.Flows.Delete(flowKey)
+		o.Flows.Delete(flow.FlowId)
 	}
 
 	if flow.AccessIntfId == -1 {
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index cfc7099..53f6564 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -93,11 +93,6 @@
 	BbrOnuStateDhcpFlowSent  = "dhcp_flow_sent"
 )
 
-type FlowKey struct {
-	ID        uint64
-	Direction string
-}
-
 type Onu struct {
 	ID                  uint32
 	PonPortID           uint32
@@ -110,7 +105,6 @@
 	// ONU State
 	UniPorts  []UniPortIf
 	PotsPorts []PotsPortIf
-	Flows     []FlowKey
 	FlowIds   []uint64 // keep track of the flows we currently have in the ONU
 
 	OperState    *fsm.FSM
@@ -161,7 +155,7 @@
 		seqNumber:                     0,
 		DoneChannel:                   make(chan bool, 1),
 		DiscoveryRetryDelay:           60 * time.Second, // this is used to send OnuDiscoveryIndications until an activate call is received
-		Flows:                         []FlowKey{},
+		FlowIds:                       []uint64{},
 		DiscoveryDelay:                delay,
 		MibDataSync:                   0,
 		ImageSoftwareExpectedSections: 0, // populated during OMCI StartSoftwareDownloadRequest
@@ -380,7 +374,7 @@
 // cleanupOnuState this method is to clean the local state when the ONU is disabled
 func (o *Onu) cleanupOnuState() {
 	// clean the ONU state
-	o.Flows = []FlowKey{}
+	o.FlowIds = []uint64{}
 	o.PonPort.removeOnuId(o.ID)
 	o.PonPort.removeAllocId(o.SerialNumber)
 	o.PonPort.removeGemPortBySn(o.SerialNumber)
@@ -1748,15 +1742,12 @@
 	}).Info("Sent DHCP Flow")
 }
 
-// DeleteFlow method search and delete flowKey from the onu flows slice
-func (onu *Onu) DeleteFlow(key FlowKey) {
-	for pos, flowKey := range onu.Flows {
-		if flowKey == key {
-			// delete the flowKey by shifting all flowKeys by one
-			onu.Flows = append(onu.Flows[:pos], onu.Flows[pos+1:]...)
-			t := make([]FlowKey, len(onu.Flows))
-			copy(t, onu.Flows)
-			onu.Flows = t
+// DeleteFlow method search and delete flowId from the onu flowIds slice
+func (onu *Onu) DeleteFlow(id uint64) {
+	for pos, flowId := range onu.FlowIds {
+		if flowId == id {
+			// delete the flowId by shifting all flowIds by one
+			onu.FlowIds = append(onu.FlowIds[:pos], onu.FlowIds[pos+1:]...)
 			break
 		}
 	}
diff --git a/internal/bbsim/devices/onu_state_machine_test.go b/internal/bbsim/devices/onu_state_machine_test.go
index c1f6d8e..a324d81 100644
--- a/internal/bbsim/devices/onu_state_machine_test.go
+++ b/internal/bbsim/devices/onu_state_machine_test.go
@@ -40,10 +40,7 @@
 	onu.InternalState.SetState(OnuStateEnabled)
 	assert.Equal(t, onu.InternalState.Current(), OnuStateEnabled)
 
-	onu.Flows = []FlowKey{
-		{ID: 1, Direction: "upstream"},
-		{ID: 2, Direction: "downstream"},
-	}
+	onu.FlowIds = []uint64{1, 2}
 	key := omcilib.OnuAlarmInfoMapKey{
 		MeInstance: 257,
 		MeClassID:  me.PhysicalPathTerminationPointEthernetUniClassID,
@@ -57,7 +54,7 @@
 	assert.Equal(t, onu.InternalState.Current(), OnuStateDisabled)
 
 	assert.Equal(t, len(onu.onuAlarmsInfo), 0)
-	assert.Equal(t, len(onu.Flows), 0)
+	assert.Equal(t, len(onu.FlowIds), 0)
 	assert.Equal(t, len(onu.PonPort.AllocatedOnuIds), 0)
 	assert.Equal(t, len(onu.PonPort.AllocatedAllocIds), 0)
 	assert.Equal(t, len(onu.PonPort.AllocatedGemPorts), 0)