VOL-2146 Put Lock around flow mgr map. Preventing possible concurrent map write with concurrent onu indications.
Change-Id: I4a0a25fbf1a7e82d662753e8e2e25f8c88dbb8a1
diff --git a/adaptercore/device_handler.go b/adaptercore/device_handler.go
index a9bee44..3053f2a 100644
--- a/adaptercore/device_handler.go
+++ b/adaptercore/device_handler.go
@@ -901,7 +901,7 @@
"openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
if err != nil {
log.Errorw("Failed to send inter-adapter-message", log.Fields{"OnuInd": onuInd,
- "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id})
+ "From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id, "Error": err})
return
}
} else {
diff --git a/adaptercore/openolt_flowmgr.go b/adaptercore/openolt_flowmgr.go
index 0072770..63ee913 100644
--- a/adaptercore/openolt_flowmgr.go
+++ b/adaptercore/openolt_flowmgr.go
@@ -24,6 +24,7 @@
"errors"
"fmt"
"math/big"
+ "sync"
"github.com/opencord/voltha-lib-go/v2/pkg/flows"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
@@ -169,6 +170,7 @@
onuGemPortIds map[gemPortKey]onuInfo //GemPortId -> OnuInfo
packetInGemPort map[packetInInfoKey]uint32 //packet in gem port
storedDeviceFlows []ofp.OfpFlowStats /* Required during deletion to obtain device flows from logical flows */
+ onuIdsLock sync.RWMutex
}
//NewFlowManager creates OpenOltFlowMgr object and initializes the parameters
@@ -186,6 +188,7 @@
flowMgr.onuSerialNumbers = make(map[string]onuInfo)
flowMgr.onuGemPortIds = make(map[gemPortKey]onuInfo)
flowMgr.packetInGemPort = make(map[packetInInfoKey]uint32)
+ flowMgr.onuIdsLock = sync.RWMutex{}
log.Info("Initialization of flow manager success!!")
return &flowMgr
}
@@ -1390,6 +1393,8 @@
func (f *OpenOltFlowMgr) UpdateOnuInfo(intfID uint32, onuID uint32, serialNum string) {
onu := onuInfo{intfID: intfID, onuID: onuID, serialNumber: serialNum}
onuIDkey := onuIDKey{intfID: intfID, onuID: onuID}
+ f.onuIdsLock.Lock()
+ defer f.onuIdsLock.Unlock()
f.onuIds[onuIDkey] = onu
log.Debugw("Updated onuinfo", log.Fields{"intfID": intfID, "onuID": onuID, "serialNum": serialNum})
}
@@ -1397,6 +1402,8 @@
//addGemPortToOnuInfoMap function stores adds GEMport to ONU map
func (f *OpenOltFlowMgr) addGemPortToOnuInfoMap(intfID uint32, onuID uint32, gemPort uint32) {
onuIDkey := onuIDKey{intfID: intfID, onuID: onuID}
+ f.onuIdsLock.RLock()
+ defer f.onuIdsLock.RUnlock()
if val, ok := f.onuIds[onuIDkey]; ok {
onuInf := val
gemportKey := gemPortKey{intfID: intfID, gemPort: gemPort}